1 |
gforget |
1.2 |
function []=cost_seaicearea(dirModel,dirMat,doComp,dirTex,nameTex); |
2 |
heimbach |
1.1 |
%object: compute cost function term for sea ice data |
3 |
|
|
%inputs: dimodel is the model directory |
4 |
|
|
% dirMat is the directory where diagnozed .mat files will be saved |
5 |
|
|
% -> set it to '' to use the default [dirModel 'mat/'] |
6 |
|
|
% doComp is a switch (1->compute; 0->display) |
7 |
|
|
%optional: dirTex is the directory where tex and figures files are created |
8 |
|
|
% (if not specified then display all results to screen instead) |
9 |
gforget |
1.2 |
% nameTex is the tex file name (default : 'myPlots') |
10 |
heimbach |
1.1 |
|
11 |
|
|
if isempty(dirMat); dirMat=[dirModel 'mat/']; else; dirMat=[dirMat '/']; end; |
12 |
|
|
if isempty(dir(dirMat)); eval(['!mkdir ' dirMat ';']); end; |
13 |
|
|
|
14 |
|
|
%determine if and where to create tex and figures files |
15 |
|
|
dirMat=[dirMat '/']; |
16 |
|
|
if isempty(who('dirTex')); |
17 |
|
|
addToTex=0; |
18 |
|
|
else; |
19 |
|
|
if ~ischar(dirTex); error('mis-specified dirTex'); end; |
20 |
gforget |
1.2 |
addToTex=1; |
21 |
|
|
if isempty(who('nameTex')); nameTex='myPlots'; end; |
22 |
|
|
fileTex=[dirTex nameTex '.tex']; |
23 |
heimbach |
1.1 |
end; |
24 |
|
|
|
25 |
|
|
if doComp; |
26 |
|
|
|
27 |
|
|
%load grid |
28 |
|
|
gcmfaces_global; |
29 |
|
|
if ~isfield(mygrid,'XC'); grid_load('./GRID/',5,'compact'); end; |
30 |
|
|
if ~isfield(mygrid,'LATS_MASKS'); gcmfaces_lines_zonal; end; |
31 |
|
|
|
32 |
|
|
fld_err=ones(90,1170); |
33 |
|
|
fld_err=convert2gcmfaces(fld_err); |
34 |
|
|
fld_w=fld_err.^-2; |
35 |
|
|
|
36 |
|
|
%%%dirData='/net/weddell/raid3/gforget/ecco_v4/input_files/'; |
37 |
|
|
dirData='/net/nares/raid11/ecco-shared/ecco-version-4/input//'; |
38 |
|
|
|
39 |
|
|
fileModel=dir([dirModel 'barfiles/gbar_area*data']); |
40 |
|
|
fileModel=['barfiles/' fileModel.name]; |
41 |
|
|
|
42 |
|
|
fld_dif=convert2gcmfaces(NaN*ones(90,1170,12*19)); |
43 |
|
|
|
44 |
|
|
IceAreaNorthMod=zeros(1,228); |
45 |
|
|
IceAreaSouthMod=zeros(1,228); |
46 |
|
|
IceAreaNorthObs=zeros(1,228); |
47 |
|
|
IceAreaSouthObs=zeros(1,228); |
48 |
|
|
|
49 |
|
|
for ycur=1992:2010; |
50 |
|
|
tic; |
51 |
|
|
for mcur=1:12; |
52 |
|
|
%%% fld_dat=v4_read_bin([dirData 'gael_quick_interp/g_SST_monthly_r2_' num2str(ycur)],mcur,0); |
53 |
|
|
%%% fld_dat=v4_read_bin([dirData 'input_nsidc_postproc/NSIDC0079_v4_gael_' num2str(ycur)],mcur,0); |
54 |
|
|
fld_dat=v4_read_bin([dirData 'input_nsidc_all/nsidc79_monthly_' num2str(ycur)],mcur,0); |
55 |
|
|
|
56 |
|
|
fld_dat(find(fld_dat==0))=NaN; |
57 |
|
|
fld_dat(find(fld_dat<-99))=NaN; |
58 |
|
|
|
59 |
|
|
mm=(ycur-1992)*12+mcur; |
60 |
|
|
fld_mod=v4_read_bin([dirModel fileModel],mm,1).*mygrid.mskC(:,:,1); |
61 |
|
|
|
62 |
|
|
fld_dif(:,:,mm)=fld_mod-fld_dat; |
63 |
|
|
|
64 |
|
|
fld=fld_mod.*mygrid.RAC.*(mygrid.YC>0); IceAreaNorthMod(mm)=nansum(fld); |
65 |
|
|
fld=fld_mod.*mygrid.RAC.*(mygrid.YC<0); IceAreaSouthMod(mm)=nansum(fld); |
66 |
|
|
fld=fld_dat.*mygrid.RAC.*(mygrid.YC>0); IceAreaNorthObs(mm)=nansum(fld); |
67 |
|
|
fld=fld_dat.*mygrid.RAC.*(mygrid.YC<0); IceAreaSouthObs(mm)=nansum(fld); |
68 |
|
|
|
69 |
|
|
end; |
70 |
|
|
toc; |
71 |
|
|
end; |
72 |
|
|
|
73 |
|
|
fld_rms=sqrt(nanmean(fld_dif.^2,3)); |
74 |
|
|
fld_cost=fld_rms.^2.*fld_w; |
75 |
|
|
|
76 |
|
|
eval(['save ' dirMat '/cost_seaicearea.mat fld_err fld_rms fld_cost IceAreaNorthMod IceAreaSouthMod IceAreaNorthObs IceAreaSouthObs;']); |
77 |
|
|
|
78 |
|
|
else;%display previously computed results |
79 |
|
|
|
80 |
|
|
global mygrid; |
81 |
|
|
|
82 |
|
|
eval(['load ' dirMat '/cost_seaicearea.mat;']); |
83 |
|
|
|
84 |
|
|
%figure; m_map_gcmfaces(fld_cost,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]}); |
85 |
|
|
%figure; m_map_gcmfaces(fld_err,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]/2}); |
86 |
|
|
|
87 |
|
|
figure; m_map_gcmfaces(fld_rms,0,{'myCaxis',[0:0.1:1.]}); |
88 |
|
|
myCaption={'modeled-observed rms -- sea ice area (K)'}; |
89 |
|
|
|
90 |
|
|
if addToTex; write2tex(fileTex,2,myCaption,gcf); end; |
91 |
|
|
|
92 |
|
|
end; |
93 |
|
|
|
94 |
|
|
|