Skip to content

Commit 37e397d

Browse files
authored
Nctilesdev (#3)
* - add dirDiags as input argument (interp2nctiles.m, process2interp.m) - add dimlist, dimname, and clmbnds optional arguments (write2nctiles.m) - revise handling of directories and time loop (process2interp.m, process2nctiles.m) - rename dirModel,fileModel,fldModel as dirDiags,fileDiags,selectFld (process2nctiles.m) - revise handling of doClim option and time axis using clmbnds (process2nctiles.m, write2nctiles.m) - add possibility to rename variables on the fly using filRename (process2nctiles.m) - rename coordinates as 't','k','j','i' (previously 'i1','i2','i3','i4') via dimlist, dimname being passed as arguments to write2nctiles.m (process2nctiles.m). - set 'xtype' to 'float' for main variable to reduce file sizes (process2nctiles.m). - revise handling of dimension, file, and variable names (write2nctiles.m). * Changes in grid_load.m (XW etc.), gcmfaces_loc_tile.m (tile numbering), nctiles I/O (dimensions etc.). - grid_load.m: (re)assign RF(nr+1) and DRC(nr+1) if needed; compute XW/YW, XS/YS from XC/YC. - gcmfaces_loc_tile.m: switch to ordering convention that is consistent with MITgcm/pkg/exch2. - read_nctiles.m: add nctiles_old_tile_order switch so that the user can revert to the old ordering if needed (only matters for smaller tile sizes). - gcmfaces_IO/write2nctiles.m: add itile, ntile attributes (their presence will notably indicate that the new tile ordering convention was used); revisit the handling of dimlist in the doCreate 1/0 phases (needed after previous commit). - process2nctiles.m: fix bug introduced in previous commit (tim in doClim case & handling of filRename); revisit set_grid_diag function to use predefined dimension names that distinguish C,W,S and C,L,U points (e.g., {'t','kc','jc','ic'} for tracer fields) and set the longitude/latitude variables accordingly (e.g., use XW/YW for velocity components). - interp2nctiles.m: comment out adhoc DRC, DRF, mskC definitions to avoid putting these in the netcdf files. - write2nctiles.m: add itile, mtile attributes; clean up the two stage handling of dimlist, dimname, dimvec. * - interp2nctiles.m : update to match revised process2nctiles.m argument handling. - process2interp.m : go directly from mds output to interpolation (rather than via nctiles first); revise handling of input arguments (see help section for detail). - process2nctiles.m : revise handling of input arguments (see help section for detail); use rdmds_meta.m in place of embeded duplicate (read_meta function). - rdmds_search_subdirs.m (new) : searches for fileDiags within the subdirectories of dirDiags (now used in process2interp.m and process2nctiles.m) * - process2UVSTAR.m (new) computes bolus velocity from GM_PsiX,Y - process2UEVN.m get dirDiags,fileDiags via function arguments (as now done in process*.m), use rdmds_search_subdirs (to identify subDir), and calc_UV_zonmer (no masking unlike before). * changes related to rdmds_meta.m and process2interp.m - deal with adding '*' to file name within rdmds_meta.m (not in caller) - add possibility to rely on interp_precomputed.mat in process2interp.m * improve treatment of missing_value, _FillValue, scale_factor (new), and add_offset (new)
1 parent b381644 commit 37e397d

File tree

13 files changed

+459
-274
lines changed

13 files changed

+459
-274
lines changed

gcmfaces_IO/grid_load.m

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@
149149
end;
150150
end;
151151

152+
%if needed then (re)set RF(nr+1) and DRC(nr+1):
153+
nr=length(mygrid.RC);
154+
if isnan(mygrid.RF(nr+1)); mygrid.RF(nr+1)=mygrid.RC(nr)-1/2*mygrid.DRF(nr); end;
155+
if length(mygrid.DRC)==nr||isnan(mygrid.DRC(nr+1)); mygrid.DRC(nr+1)=mygrid.DRC(nr)/2; end;
156+
152157
%grid orientation
153158
if mygrid.memoryLimit<2;
154159
list0={'AngleCS','AngleSN'};
@@ -198,13 +203,50 @@
198203
%grid masks
199204
if mygrid.memoryLimit<1;
200205
mygrid.hFacCsurf=mygrid.hFacC;
201-
for ff=1:mygrid.hFacC.nFaces; mygrid.hFacCsurf{ff}=mygrid.hFacC{ff}(:,:,1); end;
206+
for ff=1:mygrid.nFaces; mygrid.hFacCsurf{ff}=mygrid.hFacC{ff}(:,:,1); end;
202207

203208
mskC=mygrid.hFacC; mskC(mskC==0)=NaN; mskC(mskC>0)=1; mygrid.mskC=mskC;
204209
mskW=mygrid.hFacW; mskW(mskW==0)=NaN; mskW(mskW>0)=1; mygrid.mskW=mskW;
205210
mskS=mygrid.hFacS; mskS(mskS==0)=NaN; mskS(mskS>0)=1; mygrid.mskS=mskS;
206211
end;
207212

213+
%missing velocity point locations
214+
if mygrid.memoryLimit<2;
215+
%1) average C point locations
216+
tmpXC=exch_T_N(mygrid.XC); tmpYC=exch_T_N(mygrid.YC);
217+
mygrid.XW=NaN*mygrid.XC; mygrid.YW=NaN*mygrid.YC;
218+
mygrid.XS=NaN*mygrid.XC; mygrid.YS=NaN*mygrid.YC;
219+
for ff=1:mygrid.nFaces;
220+
tmp1=tmpXC{ff}(1:end-2,2:end-1);
221+
tmp2=tmpXC{ff}(2:end-1,2:end-1);
222+
tmp2(tmp2-tmp1>180)=tmp2(tmp2-tmp1>180)-360;
223+
tmp2(tmp1-tmp2>180)=tmp2(tmp1-tmp2>180)+360;
224+
mygrid.XW{ff}=(tmp1+tmp2)/2;
225+
%
226+
tmp1=tmpXC{ff}(2:end-1,1:end-2);
227+
tmp2=tmpXC{ff}(2:end-1,2:end-1);
228+
tmp2(tmp2-tmp1>180)=tmp2(tmp2-tmp1>180)-360;
229+
tmp2(tmp1-tmp2>180)=tmp2(tmp1-tmp2>180)+360;
230+
mygrid.XS{ff}=(tmp1+tmp2)/2;
231+
%
232+
tmp1=tmpYC{ff}(1:end-2,2:end-1);
233+
tmp2=tmpYC{ff}(2:end-1,2:end-1);
234+
mygrid.YW{ff}=(tmp1+tmp2)/2;
235+
%
236+
tmp1=tmpYC{ff}(2:end-1,1:end-2);
237+
tmp2=tmpYC{ff}(2:end-1,2:end-1);
238+
mygrid.YS{ff}=(tmp1+tmp2)/2;
239+
end;
240+
%2) fix lonitude range:
241+
tmp1=convert2gcmfaces(mygrid.XC);
242+
test1=~isempty(find(tmp1(:)<0));
243+
if test1; Xmax=180; Xmin=-180; else; Xmax=360; Xmin=0; end;
244+
mygrid.XS(mygrid.XS<Xmin)=mygrid.XS(mygrid.XS<Xmin)+360;
245+
mygrid.XS(mygrid.XS>Xmax)=mygrid.XS(mygrid.XS>Xmax)-360;
246+
mygrid.XW(mygrid.XW<Xmin)=mygrid.XW(mygrid.XW<Xmin)+360;
247+
mygrid.XW(mygrid.XW>Xmax)=mygrid.XW(mygrid.XW>Xmax)-360;
248+
end;
249+
208250
%zonal mean and sections needed for transport computations
209251
% if mygrid.memoryLimit<1;
210252
% if ~isfield(mygrid,'mygrid.LATS_MASKS');

gcmfaces_IO/interp2nctiles.m

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function []=interp2nctiles(indFiles);
2-
% INTERP2CNTILES creates netcdf files from interpolated
1+
function []=interp2nctiles(dirDiags,listDo);
2+
% INTERP2CNTILES(dirDiags,listDo);
3+
% creates netcdf files from interpolated
34
% fields that were created by process2interp. The
45
% input vector process2interp specifies the file subset
56
% to be processed (1:length(listInterp) by default).
@@ -9,11 +10,7 @@
910

1011
gcmfaces_global; global mygrid_orig;
1112

12-
dirModel='./';
13-
if isempty(mygrid_orig);
14-
grid_load; mygrid_orig=mygrid;
15-
cd(dirModel);
16-
end;
13+
if isempty(mygrid_orig); mygrid_orig=mygrid; end;
1714

1815
lon=[-179.75:0.5:179.75]; lat=[-89.75:0.5:89.75];
1916
[lat,lon] = meshgrid(lat,lon);
@@ -26,22 +23,16 @@
2623
mygrid_latlon.YC=gcmfaces({lat});
2724
mygrid_latlon.RC=mygrid.RC;
2825
mygrid_latlon.RF=mygrid.RF;
29-
mygrid_latlon.DRC=mygrid.DRC;
30-
mygrid_latlon.DRF=mygrid.DRF;
31-
mygrid_latlon.mskC=1+0*repmat(mygrid_latlon.XC,[1 1 length(mygrid.RC)]);
32-
mygrid_latlon.RAC=[];
26+
%mygrid_latlon.DRC=mygrid.DRC;
27+
%mygrid_latlon.DRF=mygrid.DRF;
28+
%mygrid_latlon.mskC=1+0*repmat(mygrid_latlon.XC,[1 1 length(mygrid.RC)]);
3329
mygrid_latlon.gcm2facesFast=0;
3430
mygrid_latlon.facesExpand=[];
3531

36-
[listInterp,listNot]=process2interp;
37-
if isempty(who('indFiles'));
38-
indFiles=[1:length(listInterp)];
39-
end;
40-
4132
mygrid=mygrid_latlon;
42-
for ii=indFiles;
43-
tic; process2nctiles(dirModel,listInterp{ii},[]);
44-
fprintf(['DONE: ' listInterp{ii} ' (in ' num2str(toc) 's)\n']);
33+
for ii=1:length(listDo);
34+
tic; process2nctiles(dirDiags,listDo{ii},listDo{ii});
35+
fprintf(['DONE: ' listDo{ii} ' (in ' num2str(toc) 's)\n']);
4536
end;
4637
mygrid=mygrid_orig;
4738

gcmfaces_IO/ncload.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@
2525
bb=length(size(aa)); aa=permute(aa,[bb:-1:1]);
2626
%replace missing value with NaN
2727
[atts]=ncatts(f,varid);
28-
if strcmp(atts,'missing_value')&isreal(aa);
28+
if sum(strcmp(atts,'scale_factor'));
29+
scale_factor=double(netcdf.getAtt(f,varid,'scale_factor'));
30+
aa=scale_factor*double(aa);
31+
end;
32+
if sum(strcmp(atts,'add_offset'));
33+
add_offset=double(netcdf.getAtt(f,varid,'add_offset'));
34+
aa=aa+add_offset;
35+
end;
36+
if sum(strcmp(atts,'missing_value'))&isreal(aa);
2937
spval = double(netcdf.getAtt(f,varid,'missing_value'));
30-
elseif strcmp(atts,'_FillValue')&isreal(aa);
38+
elseif sum(strcmp(atts,'_FillValue'))&isreal(aa);
3139
spval = double(netcdf.getAtt(f,varid,'_FillValue'));
3240
else;
3341
spval=[];

gcmfaces_IO/process2UEVN.m

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,67 @@
1-
function []=process2UEVN(ff);
2-
% PROCESS2UEVN(ff) computes eastward/northward vector components
3-
% and output result to 'diags_post_tmp/'
1+
function []=process2UEVN(dirDiags,fileDiags);
2+
% PROCESS2UEVN(dirDiags,fileDiags) computes eastward/northward vector components
3+
% for vector fields in fileDiags and output result to 'diags_UEVN_tmp/'
44

55
gcmfaces_global;
66

7-
%ff=1;
8-
dir0=[pwd filesep];
9-
dirIn=[dir0 'diags/'];
10-
dirOut=[dir0 'diags_post_tmp/'];
11-
if ~isdir(dirOut); mkdir(dirOut); end;
7+
gcmfaces_global;
8+
dirOut=[dirDiags filesep 'diags_UEVN_tmp' filesep];
129

13-
if ff==1;
14-
dirIn = [dirIn 'TRSP/'];
15-
dirOut = [dirOut 'TRSP/'];
16-
fil = 'trsp_3d_set1';
10+
if strcmp(fileDiags,'trsp_3d_set1');
1711
pairsIn={{'UVELMASS','VVELMASS'}};
1812
pairsOut={{'EVELMASS','NVELMASS'}};
19-
elseif ff==2;
20-
dirIn = [dirIn 'TRSP/'];
21-
dirOut = [dirOut 'TRSP/'];
22-
fil = 'trsp_3d_set2';
13+
elseif strcmp(fileDiags,'trsp_3d_set2');
2314
pairsIn={{'DFxE_TH ','DFyE_TH '},{'DFxE_SLT','DFyE_SLT'}};
2415
pairsOut={{'DFeE_TH ','DFnE_TH '},{'DFeE_SLT','DFnE_SLT'}};
2516
pairsIn={pairsIn{:},{'ADVx_TH ','ADVy_TH '},{'ADVx_SLT','ADVy_SLT'}};
2617
pairsOut={pairsOut{:},{'ADVe_TH ','ADVn_TH '},{'ADVe_SLT','ADVn_SLT'}};
27-
elseif ff==3;
28-
dirIn = [dirIn 'STATE/'];
29-
dirOut = [dirOut 'STATE/'];
30-
fil= 'state_2d_set1';
18+
elseif strcmp(fileDiags,'state_2d_set1');
3119
pairsIn={{'DFxEHEFF','DFyEHEFF'},{'DFxESNOW','DFyESNOW'}};
3220
pairsOut={{'DFeEHEFF','DFnEHEFF'},{'DFeESNOW','DFnESNOW'}};
3321
pairsIn={pairsIn{:},{'ADVxHEFF','ADVyHEFF'},{'ADVxSNOW','ADVySNOW'}};
3422
pairsOut={pairsOut{:},{'ADVeHEFF','ADVnHEFF'},{'ADVeSNOW','ADVnSNOW'}};
3523
pairsIn={pairsIn{:},{'oceTAUX ','oceTAUY '},{'SIuice ','SIvice '}};
3624
pairsOut={pairsOut{:},{'oceTAUE ','oceTAUN '},{'EVELice ','NVELice '}};
25+
elseif strcmp(fileDiags,'star_trsp_3d_set1');
26+
pairsIn={{'UVELSTAR','VVELSTAR'}};
27+
pairsOut={{'EVELSTAR','NVELSTAR'}};
28+
else;
29+
error('unknown fileDiags');
3730
end;
3831

39-
listIn=dir([dirIn fil '*meta']);
32+
%% ======== PART 1 =======
33+
34+
%search for fileDiags in subdirectories
35+
[subDir]=rdmds_search_subdirs(dirDiags,fileDiags);
36+
%read meta file to get list of variables
37+
[meta]=rdmds_meta([dirDiags subDir fileDiags]);
38+
39+
%% ======== PART 2 =======
40+
41+
listIn=dir([dirDiags subDir fileDiags '*meta']);
4042
for tt=1:length(listIn);
4143
disp([tt length(listIn)]);
4244
fldsOut=gcmfaces;
4345
listOut={};
4446
for pp=1:length(pairsIn);
4547
pIn=pairsIn{pp}; pOut=pairsOut{pp};
4648
filIn=listIn(tt).name(1:end-5);
47-
metaIn=rdmds_meta([dirIn filIn]);
49+
metaIn=rdmds_meta([dirDiags subDir filIn]);
4850
i1=find(strcmp(metaIn.fldList,pIn{1}));
4951
i2=find(strcmp(metaIn.fldList,pIn{2}));
5052
%[i1 i2]
5153
%
52-
UX=rdmds2gcmfaces([dirIn filIn],'rec',i1);
53-
VY=rdmds2gcmfaces([dirIn filIn],'rec',i2);
54-
[UE,VN]=calc_UEVNfromUXVY(UX,VY);
54+
UX=rdmds2gcmfaces([dirDiags subDir filIn],'rec',i1);
55+
VY=rdmds2gcmfaces([dirDiags subDir filIn],'rec',i2);
56+
[UE,VN]=calc_UV_zonmer(UX,VY);
57+
% [UE,VN]=calc_UEVNfromUXVY(UX,VY);
5558
%store binary
5659
fldsOut=cat(3,fldsOut,UE);
5760
fldsOut=cat(3,fldsOut,VN);
5861
listOut={listOut{:},pOut{:}};
5962
end;
6063
%output binary file
61-
filOut=['post_' filIn];
64+
filOut=['zonmer_' filIn];
6265
tmp1=convert2gcmfaces(fldsOut);
6366
tmp1(isnan(tmp1))=0;
6467
if ~isdir(dirOut); mkdir(dirOut); end;

gcmfaces_IO/process2UVSTAR.m

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
function []=process2UVSTAR(dirDiags,fileDiags);
2+
% PROCESS2UVstar computes bolus velocity vector components (U,V,WVELSTAR) from
3+
% GM_PsiX,Y in fileDiags (trsp_3d_set1) and output result to 'diags_post_tmp/'
4+
5+
gcmfaces_global;
6+
7+
dirOut=[dirDiags filesep 'diags_UVstar_tmp' filesep];
8+
if ~isdir(dirOut); mkdir(dirOut); end;
9+
10+
pairsIn={{'GM_PsiX ' 'GM_PsiY '}};
11+
pairsOut={{'UVELSTAR','VVELSTAR','WVELSTAR'}};
12+
13+
%% ======== PART 1 =======
14+
15+
%search for fileDiags in subdirectories
16+
[subDir]=rdmds_search_subdirs(dirDiags,fileDiags);
17+
%read meta file to get list of variables
18+
[meta]=rdmds_meta([dirDiags subDir fileDiags]);
19+
20+
listIn=dir([dirDiags subDir fileDiags '*meta']);
21+
for tt=1:length(listIn);
22+
disp([tt length(listIn)]);
23+
fldsOut=gcmfaces;
24+
listOut={};
25+
for pp=1:length(pairsIn);
26+
pIn=pairsIn{pp}; pOut=pairsOut{pp};
27+
filIn=listIn(tt).name(1:end-5);
28+
metaIn=rdmds_meta([dirDiags subDir filIn]);
29+
i1=find(strcmp(metaIn.fldList,pIn{1}));
30+
i2=find(strcmp(metaIn.fldList,pIn{2}));
31+
%[i1 i2]
32+
%
33+
GM_PsiX=rdmds2gcmfaces([dirDiags subDir filIn],'rec',i1);
34+
GM_PsiY=rdmds2gcmfaces([dirDiags subDir filIn],'rec',i2);
35+
[fldUbolus,fldVbolus,fldWbolus]=calc_bolus(GM_PsiX,GM_PsiY);
36+
%store binary
37+
fldsOut=cat(3,fldsOut,fldUbolus);
38+
fldsOut=cat(3,fldsOut,fldVbolus);
39+
fldsOut=cat(3,fldsOut,fldWbolus);
40+
listOut={listOut{:},pOut{:}};
41+
end;
42+
%output binary file
43+
filOut=['star_' filIn];
44+
tmp1=convert2gcmfaces(fldsOut);
45+
tmp1(isnan(tmp1))=0;
46+
if ~isdir(dirOut); mkdir(dirOut); end;
47+
write2file([dirOut filOut '.data'],tmp1,32);
48+
%create meta file
49+
tmp2=size(tmp1); tmp2(end)=tmp2(end)/3;
50+
write2meta([dirOut filOut '.data'],tmp2,32,listOut);
51+
end;
52+
53+

0 commit comments

Comments
 (0)