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

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

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


Revision 1.1 - (hide annotations) (download)
Thu Aug 25 22:37:24 2011 UTC (13 years, 11 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65r, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
- added routines for ecco setup diagnostics:

comp_driver.m :   compute the various cost and physics
cost_summary.m :  display summary of the various cost terms from costfunction0??? file
extend_xx.m :     extend atmospheric controls to additional years
v4_basin.m :      obtain the mask of an ocean basin
v4_read_data.m :  'fast' read of 2D fields no irec in all [fileName '*.data']

1 gforget 1.1 function []=cost_summary(dir0,file0,cost0);
2     %object: display summary of the various cost terms from costfunction0??? file
3     %input: dir0 is the model run directory name
4     % file0 is the costfunction0??? file name (if '' then it will
5     % be detected -- assuming there is only one in dir0)
6     % cost0 is a reference value that will be used for normalization (1e8 by default)
7     %note: hard coded ... mainly because multipliers are not in costfunction0??? file
8    
9     if isempty(cost0); cost0=1e8; end;
10    
11     %take care of file name:
12     dir0=[dir0 '/'];
13     if isempty(file0);
14     file0=dir([dir0 'costfunction0*']);
15     if length(file0)>1&nargin>1;
16     fprintf('several costfunction0??? files were found:\n');
17     {file0(:).name}'
18     error('please be more specific');
19     end;
20     file0=file0.name;
21     end;
22     file0=[dir0 file0];
23    
24     %read costfunction0??? file:
25     fid=fopen(file0); tmp2='';
26     while 1;
27     tline = fgetl(fid);
28     if ~ischar(tline), break, end
29     if isempty(tmp2); tmp2=[tline ' ; ']; else; tmp2=[tmp2 ' ' tline ' ; ']; end;
30     end
31     fclose(fid);
32    
33     %list of cost function terms and multipliers: (after apr1alpha/part2)
34     mylist={'fc','f_temp','f_salt','f_sst','f_tmi',...
35     'argo_pacific_MITprof_latest_4mygridprof_T','argo_pacific_MITprof_latest_4mygridprof_S',...
36     'argo_atlantic_MITprof_latest_4mygridprof_T','argo_atlantic_MITprof_latest_4mygridprof_S',...
37     'argo_indian_MITprof_latest_4mygridprof_T','argo_indian_MITprof_latest_4mygridprof_S',...
38     'seals_MITprof_latest_4mygridprof_T','seals_MITprof_latest_4mygridprof_S',...
39     'WOD09_CTD_4mygridprof_T','WOD09_CTD_4mygridprof_S','WOD09_XBT_4mygridprof_T',...
40     'area','area2sst','sshv4-mdt','sshv4-lsc',...
41     'sshv4-tp','sshv4-ers','sshv4-gfo',...
42     'sstv4-amsre-lsc','sstv4-amsre'};
43     mymult=[[0 0.15 0.15 2 2] [2 2 2 2 2 2 1 1 2 2 2] [0 50 200 40] 0.25*[1 1 1] 25 1];
44    
45     %before apr1alpha part 2
46     %mylist={'fc','f_temp','f_salt','f_sst','f_tmi',...
47     % 'argo_pacific_MITprof_latest_4mygridprof_T','argo_pacific_MITprof_latest_4mygridprof_S',...
48     % 'argo_atlantic_MITprof_latest_4mygridprof_T','argo_atlantic_MITprof_latest_4mygridprof_S',...
49     % 'argo_indian_MITprof_latest_4mygridprof_T','argo_indian_MITprof_latest_4mygridprof_S',...
50     % 'seals_MITprof_latest_4mygridprof_T','seals_MITprof_latest_4mygridprof_S','XBT_v5_4mygridprof_T',...
51     % 'area','area2sst','sshv4-mdt','sshv4-lsc','sstv4-amsre-lsc',...
52     % 'sshv4-tp','sshv4-ers','sshv4-gfo','sstv4-amsre'};
53     %mymult0=[[0 0.5 0.5 1 1] [2 2 2 2 2 2 1 1 2] [2 50 10 10 10] [1 1 1 1]];%during no1beta part 4
54     %mymult1=[[0 0.15 0.15 1 1] [2 2 2 2 2 2 1 1 2] [1 50 100 20 50] 0.25*[1 1 1 1]];%during nov1beta part 5
55     %mymult=[[0 0.15 0.15 1 1] [2 2 2 2 2 2 1 1 2] [1 50 100 20 50] 0.25*[1 1 1 1]];%during apr1alpha/part1
56    
57     %get cost from file (already in text form in memory):
58     mycost=[]; mycost2=[]; kk=0;
59     tmp1=[-3 strfind(tmp2,' ; ')];
60     for ii=1:length(tmp1)-1;
61     tmp3=tmp2(tmp1(ii)+4:tmp1(ii+1));
62     jj=strfind(tmp3,'='); jj=jj(end)+1;
63     tmp_name=tmp3(1:jj-2); tmp_val=tmp3(jj:end-1);
64     %
65     jj=strfind(tmp_name,'gencost'); if ~isempty(jj); tmp_name=deblank(tmp_name(1:jj-2)); end;
66     jj=find(~isspace(tmp_name)); tmp_name=tmp_name(jj);
67     %if isempty(strfind(tmp_name,' prof_')); tmp_name=deblank(tmp_name); end;
68     %
69     tmp_val(strfind(tmp_val,'D'))='e'; tmp_val(strfind(tmp_val,'+'))='';
70     eval(['tmp_val=[ ' tmp_val ' ];']); tmp_val(tmp_val==0)=NaN;
71     %
72     if ~isnan(tmp_val(1))&sum(strcmp(tmp_name,mylist))>0;
73     tmp_mult=mymult(find(strcmp(tmp_name,mylist)));
74     kk=kk+1;
75     if kk==1;
76     mycost.name={tmp_name}; mycost.fc=tmp_val(1); mycost.no=tmp_val(2); mycost.mult=tmp_mult;
77     mycost2.name=tmp_name; mycost2.fc=tmp_val(1); mycost2.no=tmp_val(2); mycost2.mult=tmp_mult;
78     else;
79     mycost.name(kk)={tmp_name}; mycost.fc(kk)=tmp_val(1); mycost.no(kk)=tmp_val(2); mycost.mult(kk)=tmp_mult;
80     mycost2(kk).name=tmp_name; mycost2(kk).fc=tmp_val(1); mycost2(kk).no=tmp_val(2); mycost2(kk).mult=tmp_mult;
81     end;
82     end;
83     end;
84    
85     %check that I recover the total:
86     tmp1=100*sum(mycost.fc.*mycost.mult/mycost.fc(1));
87     fprintf('offline/online cost ratio is %3.3f%%\n',tmp1);
88    
89     %share for each cost term:
90     myshare=mycost.fc.*mycost.mult; myshare=100*myshare/sum(myshare);
91     %groups of cost terms:
92     %myshare2=[sum(myshare(2:3)) sum(myshare([4 5 21 22])) sum(myshare(14:15)) sum(myshare([16:20])) sum(myshare(6:13))]';
93     fprintf('%15s contributes %3.2f%% \n','T/S atlas',sum(myshare(2:3)));
94     fprintf('%15s contributes %3.2f%% \n','SST',sum(myshare([4 5 24 25])));
95     fprintf('%15s contributes %3.2f%% \n','ice conc',sum(myshare(17:18)));
96     fprintf('%15s contributes %3.2f%% \n','SSH',sum(myshare(19:23)));
97     fprintf('%15s contributes %3.2f%% \n','in situ',sum(myshare(6:16)));
98    
99     %plot the various contributions:
100     % myplot=myshare; aa=[0 1.5 0 length(myplot)+1];
101     % figure; barh(myshare); axis(aa); grid on; hold on; title('cost terms contribution in %');
102     myplot=mycost.fc.*mycost.mult/cost0; aa=[0 10 0 length(myplot)+1];
103     myplot(1)=mycost.fc(1)/cost0; %to plot fc despite mult=0
104     figure; barh(myplot); axis(aa); grid on; hold on; title(sprintf('cost terms divided by %0.3g',cost0));
105     for ii=1:length(myplot); xx=myplot(ii)+0.01; yy=ii-0.4; text(xx,yy,mycost.name(ii),'Interpreter','none'); end;
106    

  ViewVC Help
Powered by ViewVC 1.1.22