1 |
gforget |
1.5 |
function []=cost_xx(dirModel,dirMat,doComp,dirTex,nameTex); |
2 |
gforget |
1.1 |
%object: compute cost function term for atmospheric controls |
3 |
|
|
%inputs: dirModel is the model directory |
4 |
gforget |
1.3 |
% 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.3 |
%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.5 |
% nameTex is the tex file name (default : 'myPlots') |
10 |
gforget |
1.1 |
|
11 |
gforget |
1.3 |
if isempty(dirMat); dirMat=[dirModel 'mat/']; else; dirMat=[dirMat '/']; end; |
12 |
gforget |
1.4 |
if isempty(dir(dirMat)); eval(['!mkdir ' dirMat ';']); end; |
13 |
gforget |
1.3 |
|
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.5 |
addToTex=1; |
21 |
|
|
if isempty(who('nameTex')); nameTex='myPlots'; end; |
22 |
|
|
fileTex=[dirTex nameTex '.tex']; |
23 |
gforget |
1.3 |
end; |
24 |
gforget |
1.1 |
|
25 |
|
|
for ii=1:6; |
26 |
|
|
switch ii; |
27 |
|
|
case 1; xxName='atemp'; sigName='cap_sigma_tmp2m_degC_eccollc.bin'; cc=2; uni='K'; |
28 |
|
|
case 2; xxName='aqh'; sigName='cap_sigma_spfh2m_eccollc.bin'; cc=2; uni='g/kg'; |
29 |
|
|
case 3; xxName='tauu'; sigName='cap_sigma_ustr_eccollc.bin'; cc=0.04; uni='N/m2'; |
30 |
|
|
case 4; xxName='tauv'; sigName='cap_sigma_vstr_eccollc.bin'; cc=0.04; uni='N/m2'; |
31 |
|
|
case 5; xxName='lwdown'; sigName='cap_sigma_dlw_eccollc.bin'; cc=20; uni='W/m2'; |
32 |
|
|
case 6; xxName='swdown'; sigName='cap_sigma_dsw_eccollc.bin'; cc=40; uni='W/m2'; |
33 |
|
|
end; |
34 |
|
|
|
35 |
|
|
if doComp; |
36 |
|
|
|
37 |
|
|
%load grid |
38 |
gforget |
1.2 |
gcmfaces_global; |
39 |
|
|
if ~isfield(mygrid,'XC'); grid_load('./GRID/',5,'compact'); end; |
40 |
|
|
if ~isfield(mygrid,'LATS_MASKS'); gcmfaces_lines_zonal; end; |
41 |
|
|
|
42 |
gforget |
1.6 |
dirSig='/net/nares/raid11/ecco-shared/ecco-version-4/input/input_all_from_pleiades/'; |
43 |
gforget |
1.1 |
|
44 |
|
|
%read model cost output |
45 |
gforget |
1.4 |
tmp1=dir([dirModel 'ADXXfiles/xx_' xxName '.effective.*data']); |
46 |
|
|
tmp2=size(convert2gcmfaces(mygrid.XC)); |
47 |
|
|
fld_xx=read2memory([dirModel 'ADXXfiles/' tmp1.name],[tmp2 tmp1.bytes/tmp2(1)/tmp2(2)/4]); |
48 |
|
|
fld_xx=convert2gcmfaces(fld_xx); |
49 |
|
|
%does not work when adjoint overwrites xx*effective*meta fld_xx=rdmds2gcmfaces([dirModel 'ADXXfiles/xx_' xxName '.effective.*']); |
50 |
|
|
|
51 |
gforget |
1.8 |
fld_sig=read_bin([dirSig sigName],1,0); |
52 |
gforget |
1.1 |
if strcmp(xxName,'aqh'); fld_xx=fld_xx*1000; fld_sig=fld_sig*1000; end; |
53 |
|
|
|
54 |
|
|
%compute xx stats |
55 |
|
|
fld_rms=sqrt(mean(fld_xx.^2,3)); |
56 |
|
|
fld_mean=mean(fld_xx,3); |
57 |
|
|
fld_std=std(fld_xx,[],3); |
58 |
|
|
|
59 |
|
|
%mask |
60 |
|
|
fld_rms=fld_rms.*mygrid.mskC(:,:,1); |
61 |
|
|
fld_sig=fld_sig.*mygrid.mskC(:,:,1); |
62 |
|
|
fld_mean=fld_mean.*mygrid.mskC(:,:,1); |
63 |
|
|
fld_std=fld_std.*mygrid.mskC(:,:,1); |
64 |
|
|
|
65 |
|
|
clear fld_xx; |
66 |
|
|
|
67 |
gforget |
1.7 |
if ~isdir([dirMat 'cost/']); mkdir([dirMat 'cost/']); end; |
68 |
|
|
eval(['save ' dirMat '/cost/cost_xx_' xxName '.mat fld_* cc uni;']); |
69 |
gforget |
1.1 |
|
70 |
|
|
else;%display previously computed results |
71 |
|
|
|
72 |
|
|
global mygrid; |
73 |
|
|
|
74 |
gforget |
1.7 |
if ~isdir([dirMat 'cost/']); dirMat=[dirMat 'cost/']; end; |
75 |
|
|
|
76 |
gforget |
1.3 |
eval(['load ' dirMat '/cost_xx_' xxName '.mat;']); |
77 |
gforget |
1.1 |
|
78 |
|
|
figure; |
79 |
|
|
m_map_gcmfaces(fld_sig,0,{'myCaxis',[0:0.05:0.5 0.6:0.1:1 1.25]*cc}); |
80 |
|
|
myCaption={['prior uncertainty -- ' xxName ' (' uni ')']}; |
81 |
gforget |
1.3 |
if addToTex; write2tex(fileTex,2,myCaption,gcf); end; |
82 |
gforget |
1.1 |
|
83 |
|
|
figure; |
84 |
|
|
m_map_gcmfaces(fld_rms,0,{'myCaxis',[0:0.05:0.5 0.6:0.1:1 1.25]*cc}); |
85 |
|
|
myCaption={['rms adjustment -- ' xxName ' (' uni ')']}; |
86 |
gforget |
1.3 |
if addToTex; write2tex(fileTex,2,myCaption,gcf); end; |
87 |
gforget |
1.1 |
|
88 |
|
|
figure; |
89 |
|
|
m_map_gcmfaces(fld_std,0,{'myCaxis',[0:0.05:0.5 0.6:0.1:1 1.25]*cc}); |
90 |
|
|
myCaption={['std adjustment -- ' xxName ' (' uni ')']}; |
91 |
gforget |
1.3 |
if addToTex; write2tex(fileTex,2,myCaption,gcf); end; |
92 |
gforget |
1.1 |
|
93 |
|
|
figure; |
94 |
|
|
m_map_gcmfaces(fld_mean,0,{'myCaxis',[-0.5:0.05:0.5]*cc}); |
95 |
|
|
myCaption={['mean adjustment -- ' xxName ' (' uni ')']}; |
96 |
gforget |
1.3 |
if addToTex; write2tex(fileTex,2,myCaption,gcf); end; |
97 |
gforget |
1.1 |
|
98 |
|
|
end; |
99 |
|
|
|
100 |
|
|
end;%for ii=1:6; |
101 |
|
|
|