/[MITgcm]/MITgcm_contrib/gael/matlab_class/ecco_v4/cost_bp.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/ecco_v4/cost_bp.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (hide annotations) (download)
Mon Jul 28 20:36:09 2014 UTC (11 years ago) by gforget
Branch: MAIN
Changes since 1.9: +1 -1 lines
- fix windows PC compatibility (contributed by D.Spiegel).

1 gforget 1.6 function []=cost_bp(dirModel,dirMat,doComp,dirTex,nameTex);
2 gforget 1.1 %object: compute cost function term for grace data
3     %inputs: dimodel is the model directory
4 gforget 1.4 % dirMat is the directory where diagnozed .mat files will be saved
5     % -> set it to '' to use the default [dirModel 'mat/']
6 gforget 1.1 % doComp is a switch (1->compute; 0->display)
7 gforget 1.4 %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.6 % nameTex is the tex file name (default : 'myPlots')
10 gforget 1.1
11 gforget 1.4 if isempty(dirMat); dirMat=[dirModel 'mat/']; else; dirMat=[dirMat '/']; end;
12 gforget 1.10 if isempty(dir(dirMat)); mkdir([dirMat]); end;
13 gforget 1.4
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.6 addToTex=1;
21     if isempty(who('nameTex')); nameTex='myPlots'; end;
22     fileTex=[dirTex nameTex '.tex'];
23 gforget 1.4 end;
24 gforget 1.1
25     if doComp;
26    
27     %load grid
28 gforget 1.3 gcmfaces_global;
29     if ~isfield(mygrid,'XC'); grid_load('./GRID/',5,'compact'); end;
30     if ~isfield(mygrid,'LATS_MASKS'); gcmfaces_lines_zonal; end;
31 gforget 1.1
32     %read model cost output
33     fld_dat=rdmds2gcmfaces([dirModel 'barfiles/bpdatanom_smooth']);
34     fld_dif=rdmds2gcmfaces([dirModel 'barfiles/bpdifanom_smooth']);
35    
36     %mask:
37     fld_msk=rdmds2gcmfaces([dirModel 'barfiles/bpdatanom_raw']);
38     fld_msk(find(fld_msk~=0))=1;
39     fld_msk(find(fld_msk==0))=NaN;
40    
41     fld_dif=fld_dif.*fld_msk;
42     fld_dat=fld_dat.*fld_msk;
43     fld_mod=fld_dat+fld_dif;%compute model values
44    
45     %read uncertainty fields
46 gforget 1.7 fld_err=read2memory('/net/nares/raid11/ecco-shared/ecco-version-4/input/input_grace/GRACE_CSR_withland_err',[90 1170]);
47 gforget 1.1 fld_err=convert2gcmfaces(fld_err);
48     fld_err(find(fld_err==0))=NaN;
49    
50     %compute weight
51     fld_w=fld_err.^-2;
52    
53     %compute cost
54 gforget 1.9 fld_cost=mk3D(fld_w,fld_dif).*(fld_dif.^2);
55 gforget 1.1 fld_cost=nanmean(fld_cost,3);
56    
57     fld_dif=nanstd(fld_dif,[],3);
58     fld_mod=nanstd(fld_mod,[],3);
59     fld_dat=nanstd(fld_dat,[],3);
60    
61 gforget 1.9 if ~isdir([dirMat 'cost/']); mkdir([dirMat 'cost/']); end;
62     eval(['save ' dirMat '/cost/cost_bp.mat fld_err fld_dif fld_mod fld_dat fld_cost;']);
63 gforget 1.1
64     else;%display previously computed results
65    
66     global mygrid;
67    
68 gforget 1.8 if isdir([dirMat 'cost/']); dirMat=[dirMat 'cost/']; end;
69    
70 gforget 1.4 eval(['load ' dirMat '/cost_bp.mat;']);
71 gforget 1.1
72     %figure; m_map_gcmfaces(fld_cost,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
73     figure; m_map_gcmfaces(fld_dif,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
74 gforget 1.2 myCaption={'modeled-observed rms -- bottom pressure (cm)'};
75 gforget 1.4 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
76 gforget 1.1
77     figure; m_map_gcmfaces(fld_mod,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
78     myCaption={'rms modeled -- bottom pressure (cm)'};
79 gforget 1.4 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
80 gforget 1.1
81     figure; m_map_gcmfaces(fld_dat,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
82     myCaption={'rms observed -- bottom pressure (cm)'};
83 gforget 1.4 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
84 gforget 1.1
85 gforget 1.7 figure; m_map_gcmfaces(fld_cost,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
86     myCaption={'Cost function'};
87     if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
88    
89 gforget 1.1 end;
90    

  ViewVC Help
Powered by ViewVC 1.1.22