/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_IO/prep2nctiles.m
ViewVC logotype

Diff of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/prep2nctiles.m

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

revision 1.2 by gforget, Tue Feb 3 13:43:26 2015 UTC revision 1.7 by gforget, Wed Feb 4 14:08:34 2015 UTC
# Line 1  Line 1 
1    
2  choiceStruct=3;  choiceStruct=2;
3    
4  %===============  %===============
5    
# Line 41  end; Line 41  end;
41  %===============  %===============
42    
43  if choiceStruct==2;  if choiceStruct==2;
44      budgName='budgHo'  
45          listBudgs={'budgMo','budgHo','budgSo','budgMi','budgHi','budgSi'};
46    
47      %directories and snapshot
48      dirIn='r4it11.c65i/';
49      dirMat='mat_budg3d/';
50      fldName='snapshot';
51      timName='0000000732'; suff='initial';
52    % timName='0000174564'; suff='final';
53      t0Name=num2str(3600*str2num(timName));
54    
55      %load myparms
56      eval(['load ' dirIn dirMat 'diags_grid_parms.mat myparms;']);
57    
58      %read THETA, SALT
59      diagName=['budg3d_snap_set1.' timName];
60      diagName=fullfile(dirIn,'diags',filesep,'BUDG',filesep,diagName);
61      THETA=rdmds2gcmfaces(diagName,'rec',1);
62      SALT=rdmds2gcmfaces(diagName,'rec',2);
63      ONE=1*(SALT>0);
64    
65      %compute cell thickness
66      etanName=['budg2d_snap_set1.' timName];
67      etanName=fullfile(dirIn,'diags',filesep,'BUDG',filesep,etanName);
68      etan=rdmds2gcmfaces(etanName,'rec',1);
69      %compute time variable thickness
70      tmp1=mk3D(mygrid.DRF,mygrid.hFacC).*mygrid.hFacC;
71      tmp2=tmp1./mk3D(mygrid.Depth,tmp1);
72      tmp2=tmp2.*mk3D(etan,tmp1);
73      tmp3=mk3D(mygrid.RAC,tmp1);
74      vol=tmp3.*(tmp1+tmp2);
75    
76      %load ice and snow volume/m2
77      SIheff=rdmds2gcmfaces(etanName,'rec',2);
78      SIsnow=rdmds2gcmfaces(etanName,'rec',3);
79    
80      for ii=1:length(listBudgs);
81        budgName=listBudgs{ii};
82        [budgName ' -- ' fldName ' -- ' timName]
83    
84        %directories and snapshot
85        dirOut=fullfile(dirIn,'nctiles_budg',filesep);
86        if ~isdir(dirOut); mkdir(dirOut); end;
87        dirOut=fullfile(dirOut,budgName,filesep);
88        if ~isdir(dirOut); mkdir(dirOut); end;
89    
90        switch budgName;
91        case 'budgMo'; fld=ONE; fac=myparms.rhoconst;
92        case 'budgHo'; fld=THETA; fac=myparms.rcp;
93        case 'budgSo'; fld=SALT; fac=myparms.rhoconst;
94        case 'budgMi'; FACheff=myparms.rhoi; FACsnow=myparms.rhosn;
95        case 'budgHi'; FACheff=-myparms.flami*myparms.rhoi; FACsnow=-myparms.flami*myparms.rhosn;
96        case 'budgSi'; FACheff=myparms.SIsal0*myparms.rhoi; FACsnow=0;
97        end;
98    
99        %compute extensive snapshot
100      structIn=[];      structIn=[];
101      %      if budgName(end)=='o';
102      load release1/mat/diags_grid_parms.mat myparms;        structIn.vars.snapshot=fac*fld.*vol;
103      dirMat=['release1/mat/diags_set_' budgName '/'];      else;
104      fileMat=[budgName '_*.mat'];        structIn.vars.snapshot=mygrid.RAC.*(FACheff*SIheff+FACsnow*SIsnow);
105      structIn.vars=diags_read_from_mat(dirMat,fileMat);      end;
106    
107      %vector of time increment      %general description
108      [listTimes]=diags_list_times({'release1/diags/BUDG/'},{'budg2d_hflux_set1'});      specs=[];
109      structIn.vars.dt=diff(listTimes);      if strcmp(budgName(5),'H');
     structIn.vars.dt=3600*structIn.vars.dt(1:end-1)';      
     %  
     specs=structIn.vars.specs(1);  
     if strcmp(specs.units,'W');  
110          structIn.descr={'Heat budget in extensive form (in Watt, on C-Grid)'};          structIn.descr={'Heat budget in extensive form (in Watt, on C-Grid)'};
111      elseif strcmp(specs.units,'kg/s');          specs.units='J';
112            specs.name='heat content';
113        elseif strcmp(budgName(5),'M');
114          structIn.descr={'Mass budget in extensive form (in kg/s, on C-Grid)'};          structIn.descr={'Mass budget in extensive form (in kg/s, on C-Grid)'};
115      elseif strcmp(specs.units,'g/s');          specs.units='kg';
116            specs.name='mass content';
117        elseif strcmp(budgName(5),'S');
118          structIn.descr={'Salt budget in extensive form (in g/s, on C-Grid)'};          structIn.descr={'Salt budget in extensive form (in g/s, on C-Grid)'};
119      else;          specs.units='g';
120          error('unknown budget');          specs.name='salt content';
121      end;      end;
122      structIn.descr={structIn.descr{:},'between',specs.top,'(top) and',specs.bottom,'(bottom)'};  
123      %      %variables description
124      vars=[]; nv=length(vars)+1;      vars=[]; nv=length(vars)+1;
125      vars(nv).fldName='tend'; vars(nv).longName='tendency term'; vars(nv).units=specs.units; nv=length(vars)+1;      vars(nv).fldName=fldName; vars(nv).units=specs.units;
126      vars(nv).fldName='trU'; vars(nv).longName='horizontal transport'; vars(nv).units=specs.units; nv=length(vars)+1;      if strcmp(budgName(6),'o'); vars(nv).longName=['ocean ' specs.name ' snapshot'];
127      vars(nv).fldName='trV'; vars(nv).longName='horizontal transport'; vars(nv).units=specs.units; nv=length(vars)+1;      elseif strcmp(budgName(6),'i'); vars(nv).longName=['ice+snow ' specs.name ' snapshot'];
128      vars(nv).fldName='trWtop'; vars(nv).longName='vertical transport'; vars(nv).units=specs.units; nv=length(vars)+1;      end;
129      vars(nv).fldName='trWbot'; vars(nv).longName='vertical transport'; vars(nv).units=specs.units; nv=length(vars)+1;      vars(nv).longName=[vars(nv).longName ' at ' suff ' time=' t0Name 's'];
     vars(nv).fldName='dt'; vars(nv).longName='time increment'; vars(nv).units='s'; nv=length(vars)+1;  
130      %      %
131      structIn.defs=vars;      structIn.defs=vars;
132      %  
133      struct2nctiles('release1/',budgName,structIn,[90 90]);      %create file
134            tic; struct2nctiles(dirIn,fldName,structIn,[90 90]); toc;
135        eval(['!mv ' pwd filesep dirIn filesep 'tmp_nctiles' filesep fldName ' ' pwd filesep dirOut suff]);
136    
137      end;%for ii=1:length(listBudgs);
138    
139  end;  end;
140    
141  %===============  %===============
142    
143  if choiceStruct==3;  if choiceStruct==3;
144    
145      budgName='budgHo';    %budgName='budgHo';
146      fldName='trU';  
147      if budgName(end)=='o'; listFlds={'tend','trU','trV','trWtop'};
148      else; listFlds={'tend','trU','trV','trWtop','trWbot'};
149      end;
150    
151      for ii=1:length(listFlds);
152        fldName=listFlds{ii};
153        %fldName='trWtop';
154      [budgName ' -- ' fldName]      [budgName ' -- ' fldName]
155    
156      %directories      %directories
# Line 97  if choiceStruct==3; Line 161  if choiceStruct==3;
161      dirOut=fullfile(dirOut,budgName,filesep);      dirOut=fullfile(dirOut,budgName,filesep);
162      if ~isdir(dirOut); mkdir(dirOut); end;      if ~isdir(dirOut); mkdir(dirOut); end;
163    
     %time vectors  
     [listTimes]=diags_list_times({[dirIn 'diags/BUDG/']},{'budg2d_hflux_set1'});  
     structIn.vars.t0=3600*listTimes(1:end-2);  
     structIn.vars.t1=3600*listTimes(2:end-1);  
   
164      %load variable      %load variable
165      eval(['load ' dirIn dirMat 'diags_grid_parms.mat myparms;']);      eval(['load ' dirIn dirMat 'diags_grid_parms.mat myparms;']);
166      dirMat=[dirIn dirMat 'diags_set_' budgName '/'];      dirMat=[dirIn dirMat 'diags_set_' budgName '/'];
167      fileMat=[budgName '_*.mat'];      fileMat=[budgName '_*.mat'];
168      tic; structIn.vars=diags_read_from_mat(dirMat,fileMat,fldName); toc;      tic; structIn.vars=diags_read_from_mat(dirMat,fileMat,fldName); toc;
169    
170        %time vectors
171        [listTimes]=diags_list_times({[dirIn 'diags/BUDG/']},{'budg2d_hflux_set1'});
172        structIn.vars.t0=3600*listTimes(1:end-2);
173        structIn.vars.t1=3600*listTimes(2:end-1);
174    
175      %rename trWtop as trW if adequate      %rename trWtop as trW if adequate
176      if strcmp(fldName,'trWtop');      if strcmp(fldName,'trWtop')&(budgName(end)=='o');
177        structIn.vars=setfield(structIn.vars,'trW',structIn.vars.trWtop);        structIn.vars=setfield(structIn.vars,'trW',structIn.vars.trWtop);
178        structIn.vars=rmfield(structIn.vars,'trWtop');        structIn.vars=rmfield(structIn.vars,'trWtop');
179        structIn.vars.listDiags={'trW'};        structIn.vars.listDiags={'trW'};
180        fldName='trW';        fldName='trW';
181      end;      end;
182    
183        %switch back to upward convention
184        if strcmp(fldName(1:3),'trW');
185          tmp1=getfield(structIn.vars,fldName);
186          structIn.vars=setfield(structIn.vars,fldName,-tmp1);
187        end;
188    
189      %general description      %general description
190      tmp1=diags_read_from_mat(dirMat,fileMat,'specs',1);      tmp1=diags_read_from_mat(dirMat,fileMat,'specs',1);
191      specs=tmp1.specs;      specs=tmp1.specs;
# Line 136  if choiceStruct==3; Line 206  if choiceStruct==3;
206      case 'tend'; vars(nv).longName='tendency term';      case 'tend'; vars(nv).longName='tendency term';
207      case 'trU'; vars(nv).longName='horizontal transport (U)';      case 'trU'; vars(nv).longName='horizontal transport (U)';
208      case 'trV'; vars(nv).longName='horizontal transport (V)';      case 'trV'; vars(nv).longName='horizontal transport (V)';
209      case 'trW'; vars(nv).longName='vertical transport (W)';      case 'trW'; vars(nv).longName='upward vertical transport (W)';
210        case 'trWtop'; vars(nv).longName='upward vertical transport (W)';
211        case 'trWbot'; vars(nv).longName='upward vertical transport (W)';
212      end;      end;
213      nv=length(vars)+1;      nv=length(vars)+1;
214      vars(nv).fldName='t0'; vars(nv).longName='initial time'; vars(nv).units='s'; nv=length(vars)+1;      vars(nv).fldName='t0'; vars(nv).longName='initial time'; vars(nv).units='s'; nv=length(vars)+1;
# Line 148  if choiceStruct==3; Line 220  if choiceStruct==3;
220      tic; struct2nctiles(dirIn,fldName,structIn,[90 90]); toc;      tic; struct2nctiles(dirIn,fldName,structIn,[90 90]); toc;
221      eval(['!mv ' pwd filesep dirIn filesep 'tmp_nctiles' filesep fldName ' ' pwd filesep dirOut]);      eval(['!mv ' pwd filesep dirIn filesep 'tmp_nctiles' filesep fldName ' ' pwd filesep dirOut]);
222    
223      end;%for fldName=listFlds;
224    
225  end;  end;
226    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.22