/[MITgcm]/MITgcm_contrib/gael/matlab_class/sample_analysis/example_budget.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/sample_analysis/example_budget.m

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


Revision 1.3 - (hide annotations) (download)
Thu Feb 12 21:37:27 2015 UTC (10 years, 5 months ago) by gforget
Branch: MAIN
Changes since 1.2: +1 -1 lines
- bug fix.

1 gforget 1.1 function []=example_budget(choiceV3orV4);
2     %object: illustrates budget analysis
3     %inputs: choiceV3orV4 ('v3' or 'v4') selects the sample GRID
4    
5     gcmfaces_global;
6     if myenv.verbose>0;
7     gcmfaces_msg('===============================================');
8     gcmfaces_msg(['*** entering example_budget ' ...
9     'that will load a set of budget terms from file ' ...
10     'and compute a series of derived diagnostics '],'');
11     end;
12    
13     %%%%%%%%%%%%%%%%%
14     %load parameters:
15     %%%%%%%%%%%%%%%%%
16    
17     if myenv.verbose>0;
18     gcmfaces_msg('* set grid files path and format, and number of faces for this grid');
19     end;
20     myenv.nctiles=1;
21     if strcmp(choiceV3orV4,'v4');
22     nF=5;
23     fileFormat='compact';
24     dir0=fullfile([myenv.gcmfaces_dir '../']);
25     dirGrid=fullfile(dir0,'GRID/');
26     myenv.nctilesdir=fullfile(dir0,'release1/nctiles_budget/');
27     else;
28     error('files are missing');
29     nF=1;
30     dir0=fullfile(myenv.gcmfaces_dir,'sample_input/');
31     fileFormat='straight';
32     dirGrid=fullfile(dir0,'grid_occa/');
33     myenv.nctilesdir=fullfile(dir0,'nctiles_occa/');
34     end;
35     if myenv.verbose>0;
36     gcmfaces_msg('* call grid_load : load grid to memory (mygrid) according to');
37     gcmfaces_msg(['dirGrid = ' dirGrid],' ');
38     gcmfaces_msg(['nFaces = ' num2str(nF)],' ');
39     gcmfaces_msg(['fileFormat = ' fileFormat],' ');
40     % fprintf([' > dirGrid = ' dirGrid '\n']);
41     end;
42    
43 gforget 1.2 dirName=fullfile(myenv.nctilesdir,filesep,'budgMo',filesep);
44     if ~isdir(dirName);
45     warning(['skipping example_budget (missing ' dirName ')']);
46     return;
47     end;
48    
49 gforget 1.3 if isempty(which('ncload'));
50 gforget 1.2 warning(['skipping example_budget (missing ncload that is part of MITprof)']);
51     return;
52     end;
53    
54     % warning('skipping grid_load\n');
55     grid_load(dirGrid,nF,fileFormat);
56    
57 gforget 1.1 %%%%%%%%%%%%%%%%%%
58     %main computation:
59     %%%%%%%%%%%%%%%%%%
60    
61     %select budget of interest
62     nameBudg='budgMo';
63    
64     %load budget terms
65     fileName=[myenv.nctilesdir nameBudg filesep nameBudg(1:6)];
66     tend=read_nctiles(fileName,'tend');
67     trU=read_nctiles(fileName,'trU');
68     trV=read_nctiles(fileName,'trV');
69     trWtop=read_nctiles(fileName,'trWtop');
70     trWbot=read_nctiles(fileName,'trWbot');
71    
72     %load dt (time increments) vector (not a gcmfaces object)
73     ncload([fileName '.0001.nc'],'dt');
74    
75     %get budget descitption and units
76     ncid = netcdf.open([fileName '.0001.nc'],'NC_NOWRITE');
77     descr = netcdf.getAtt(ncid,netcdf.getConstant('NC_GLOBAL'),'description');
78     varid = netcdf.inqVarID(ncid,'tend');
79     units = netcdf.getAtt(ncid,varid,'units');
80     netcdf.close(ncid);
81    
82     %define northern hemisphere as domain of integration
83     nameMask='Northern Hemisphere';
84     mask=mygrid.mskC(:,:,1).*(mygrid.YC>0);
85     areaMask=mygrid.RAC.*mask;
86    
87     %edit plot title accordingly
88     tmp1=strfind(descr,'-- ECCO v4');
89     descr=[descr(1:tmp1-1) 'for: ' nameMask];
90    
91     %compute northern hemisphere integrals
92     budg.tend=NaN*dt;
93     budg.hconv=NaN*dt;
94     budg.zconv=NaN*dt;
95     for tt=1:length(dt);
96     %compute flux convergence
97     hconv=calc_UV_conv(trU(:,:,tt),trV(:,:,tt));
98     zconv=trWtop(:,:,tt)-trWbot(:,:,tt);
99     %compute sum over domain
100     budg.tend(tt)=nansum(tend(:,:,tt).*mask)/nansum(areaMask);
101     budg.hconv(tt)=nansum(hconv.*mask)/nansum(areaMask);
102     budg.zconv(tt)=nansum(zconv.*mask)/nansum(areaMask);
103     end;
104    
105     %display result
106     figureL;
107     subplot(3,1,1); set(gca,'FontSize',12);
108     plot(cumsum(dt.*budg.tend));
109     grid on; xlabel('month'); ylabel([units '.s']);
110     legend('content anomaly'); title(descr);
111     subplot(3,1,2); set(gca,'FontSize',12);
112     plot(cumsum(dt.*budg.tend)); hold on;
113     plot(cumsum(dt.*budg.hconv),'r');
114     plot(cumsum(dt.*budg.zconv),'g');
115     grid on; xlabel('month'); ylabel([units '.s']);
116     legend('content anomaly','horizontal convergence','vertical convergence');
117     subplot(3,1,3); set(gca,'FontSize',12);
118     plot(cumsum(dt.*(budg.tend-budg.hconv-budg.zconv)));
119     grid on; xlabel('month'); ylabel([units '.s']);
120     legend('budget residual');
121    

  ViewVC Help
Powered by ViewVC 1.1.22