/[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.5 - (hide annotations) (download)
Mon Apr 23 14:39:19 2012 UTC (13 years, 3 months ago) by gforget
Branch: MAIN
Changes since 1.4: +1 -1 lines
- replace mkdir with !mkdir to avoid error in case directory already exists.
- basic_diags_ecco : move potential directory creations up.

1 gforget 1.4 function []=cost_bp(dirModel,dirMat,doComp,dirTex);
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.1
10 gforget 1.4 if isempty(dirMat); dirMat=[dirModel 'mat/']; else; dirMat=[dirMat '/']; end;
11 gforget 1.5 if isempty(dir(dirMat)); eval(['!mkdir ' dirMat ';']); end;
12 gforget 1.4
13     %determine if and where to create tex and figures files
14     dirMat=[dirMat '/'];
15     if isempty(who('dirTex'));
16     addToTex=0;
17     else;
18     if ~ischar(dirTex); error('mis-specified dirTex'); end;
19     addToTex=1; fileTex=[dirTex 'myPlots.tex'];
20     end;
21 gforget 1.1
22     if doComp;
23    
24     %load grid
25 gforget 1.3 gcmfaces_global;
26     if ~isfield(mygrid,'XC'); grid_load('./GRID/',5,'compact'); end;
27     if ~isfield(mygrid,'LATS_MASKS'); gcmfaces_lines_zonal; end;
28 gforget 1.1
29     %read model cost output
30     fld_dat=rdmds2gcmfaces([dirModel 'barfiles/bpdatanom_smooth']);
31     fld_dif=rdmds2gcmfaces([dirModel 'barfiles/bpdifanom_smooth']);
32    
33     %mask:
34     fld_msk=rdmds2gcmfaces([dirModel 'barfiles/bpdatanom_raw']);
35     fld_msk(find(fld_msk~=0))=1;
36     fld_msk(find(fld_msk==0))=NaN;
37    
38     fld_dif=fld_dif.*fld_msk;
39     fld_dat=fld_dat.*fld_msk;
40     fld_mod=fld_dat+fld_dif;%compute model values
41    
42     %read uncertainty fields
43 gforget 1.4 fld_err=read2memory('/net/weddell/raid3/gforget/ecco_v4/input_files/GRACE/GRACE_CSR_v4.err',[90 1170]);
44 gforget 1.1 fld_err=convert2gcmfaces(fld_err);
45     fld_err(find(fld_err==0))=NaN;
46    
47     %compute weight
48     fld_w=fld_err.^-2;
49    
50     %compute cost
51     fld_cost=mk3d(fld_w,fld_dif).*(fld_dif.^2);
52     fld_cost=nanmean(fld_cost,3);
53    
54     fld_dif=nanstd(fld_dif,[],3);
55     fld_mod=nanstd(fld_mod,[],3);
56     fld_dat=nanstd(fld_dat,[],3);
57    
58 gforget 1.4 eval(['save ' dirMat '/cost_bp.mat fld_err fld_dif fld_mod fld_dat fld_cost;']);
59 gforget 1.1
60     else;%display previously computed results
61    
62     global mygrid;
63    
64 gforget 1.4 eval(['load ' dirMat '/cost_bp.mat;']);
65 gforget 1.1
66     %figure; m_map_gcmfaces(fld_cost,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
67     figure; m_map_gcmfaces(fld_dif,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
68 gforget 1.2 myCaption={'modeled-observed rms -- bottom pressure (cm)'};
69 gforget 1.4 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
70 gforget 1.1
71     figure; m_map_gcmfaces(fld_mod,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
72     myCaption={'rms modeled -- bottom pressure (cm)'};
73 gforget 1.4 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
74 gforget 1.1
75     figure; m_map_gcmfaces(fld_dat,0,{'myCaxis',[0:0.2:1.2 1.5:0.5:3 4:1:6 8 10]});
76     myCaption={'rms observed -- bottom pressure (cm)'};
77 gforget 1.4 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
78 gforget 1.1
79     end;
80    

  ViewVC Help
Powered by ViewVC 1.1.22