1 |
function []=process2nctiles(dirModel,fileModel,fldModel); |
function []=process2nctiles(dirModel,fileModel,fldModel,tileSize); |
2 |
%process2nctiles(dirModel); |
%process2nctiles(dirModel); |
3 |
%object : convert MITgcm binary output to netcdf files (tiled) |
%object : convert MITgcm binary output to netcdf files (tiled) |
4 |
%inputs : dirModel is the MITgcm run directory |
%inputs : dirModel is the MITgcm run directory |
9 |
% By default : all variables in e.g. 'state_2d_set1*' |
% By default : all variables in e.g. 'state_2d_set1*' |
10 |
% files will be processed, and writen individually to |
% files will be processed, and writen individually to |
11 |
% nctiles (tiled netcdf) that will be located in 'nctiles/' |
% nctiles (tiled netcdf) that will be located in 'nctiles/' |
12 |
% fldModel (optional) can be specifiec as e.g. 'ETAN' |
% fldModel (by default []) can be specified (as e.g. 'ETAN') |
13 |
|
% when fldModel is empty, all fields are processed |
14 |
|
% tileSize (optional) is e.g. [90 90] (by default tiles=faces) |
15 |
%output : (netcdf files) |
%output : (netcdf files) |
16 |
|
|
17 |
gcmfaces_global; |
gcmfaces_global; |
39 |
end; |
end; |
40 |
|
|
41 |
%set list of variables to process |
%set list of variables to process |
42 |
if ~isempty(who('fldModel')); |
if ~isempty(fldModel); |
43 |
if ischar(fldModel); listFlds={fldModel}; |
if ischar(fldModel); listFlds={fldModel}; |
44 |
else; listFlds=fldModel; |
else; listFlds=fldModel; |
45 |
end; |
end; |
48 |
listFlds=meta.fldList; |
listFlds=meta.fldList; |
49 |
end; |
end; |
50 |
|
|
51 |
|
%determine map of tile indices (by default tiles=faces) |
52 |
|
if isempty(whos('tileSize')); |
53 |
|
tileNo=mygrid.XC; |
54 |
|
for ff=1:mygrid.nFaces; tileNo{ff}(:)=ff; end; |
55 |
|
else; |
56 |
|
tileNo=gcmfaces_loc_tile(tileSize(1),tileSize(2)); |
57 |
|
end; |
58 |
|
|
59 |
%now do the actual processing |
%now do the actual processing |
60 |
for vv=1:length(listFlds); |
for vv=1:length(listFlds); |
61 |
nameDiag=deblank(listFlds{vv}) |
nameDiag=deblank(listFlds{vv}) |
81 |
disp(rdm'); |
disp(rdm'); |
82 |
|
|
83 |
%convert to MITgcm format (90x1170 array) |
%convert to MITgcm format (90x1170 array) |
84 |
myFile=[dirOut nameDiag]; |
myFile=[dirOut nameDiag];%first instance is for subdirectory name |
85 |
|
if ~isdir(myFile); mkdir(myFile); end; |
86 |
|
myFile=[myFile '/' nameDiag];%second instance is for file name base |
87 |
|
|
88 |
%get grid params |
%get grid params |
89 |
[grid_diag]=set_grid_diag(avail_diag); |
[grid_diag]=set_grid_diag(avail_diag); |
90 |
|
|
91 |
%create netcdf file using write2nctiles (works only with old matlab, thus far ...) |
%create netcdf file using write2nctiles (works only with old matlab, thus far ...) |
92 |
doCreate=1; |
doCreate=1; |
93 |
dimOut=write2nctiles(myFile,myDiag,doCreate,... |
dimlist=write2nctiles(myFile,myDiag,doCreate,{'tileNo',tileNo},... |
94 |
{'fldName',nameDiag},{'longName',avail_diag.longNameDiag},... |
{'fldName',nameDiag},{'longName',avail_diag.longNameDiag},... |
95 |
{'units',avail_diag.units},{'descr',descr},{'rdm',rdm}); |
{'units',avail_diag.units},{'descr',descr},{'rdm',rdm}); |
96 |
|
|
97 |
%prepare to add fields |
%determine relevant dimensions |
98 |
doCreate=0; |
for ff=1:length(dimlist); |
99 |
|
dim.tim{ff}={dimlist{ff}{1}}; |
100 |
%determine relevant dimensions (note the reverse order) |
dim.twoD{ff}={dimlist{ff}{end-1:end}}; |
101 |
for ff=1:mygrid.nFaces; |
if avail_diag.nr~=1; |
102 |
dimtim{ff}={dimOut{ff}{1}}; |
dim.threeD{ff}={dimlist{ff}{end-2:end}}; |
103 |
dim2d{ff}={dimOut{ff}{end-1:end}}; |
dim.dep{ff}={dimlist{ff}{end-2}}; |
|
if avail_diag.nr~=1; |
|
|
dimmsk{ff}={dimOut{ff}{end-2:end}}; |
|
|
dimdep{ff}={dimOut{ff}{end-2}}; |
|
104 |
else; |
else; |
105 |
dimmsk{ff}=dim2d{ff}; |
dim.threeD{ff}=dim.twoD{ff}; |
106 |
dimdep{ff}=[]; |
dim.dep{ff}=[]; |
107 |
end; |
end; |
108 |
end; |
end; |
109 |
|
|
110 |
|
%prepare to add fields |
111 |
|
doCreate=0; |
112 |
|
|
113 |
%now add fields |
%now add fields |
114 |
write2nctiles(myFile,tim,doCreate,{'fldName','month'},... |
write2nctiles(myFile,tim,doCreate,{'tileNo',tileNo},... |
115 |
{'longName','month index starting Jan. 1992'},... |
{'fldName','month'},{'longName','month index starting Jan. 1992'},... |
116 |
{'units',''},{'dimIn',dimtim}); |
{'units',''},{'dimIn',dim.tim}); |
117 |
write2nctiles(myFile,grid_diag.lon,doCreate,... |
write2nctiles(myFile,grid_diag.lon,doCreate,{'tileNo',tileNo},... |
118 |
{'fldName','longitude'},{'units',''},{'dimIn',dim2d}); |
{'fldName','longitude'},{'units',''},{'dimIn',dim.twoD}); |
119 |
write2nctiles(myFile,grid_diag.lat,doCreate,... |
write2nctiles(myFile,grid_diag.lat,doCreate,{'tileNo',tileNo},... |
120 |
{'fldName','latitude'},{'units',''},{'dimIn',dim2d}); |
{'fldName','latitude'},{'units',''},{'dimIn',dim.twoD}); |
121 |
write2nctiles(myFile,grid_diag.msk,doCreate,... |
write2nctiles(myFile,grid_diag.msk,doCreate,{'tileNo',tileNo},... |
122 |
{'fldName','landmask'},{'units',''},... |
{'fldName','landmask'},{'units',''},... |
123 |
{'longName','land mask'},{'dimIn',dimmsk}); |
{'longName','land mask'},{'dimIn',dim.threeD}); |
124 |
write2nctiles(myFile,grid_diag.RAC,doCreate,... |
write2nctiles(myFile,grid_diag.RAC,doCreate,{'tileNo',tileNo},... |
125 |
{'fldName','cellarea'},{'units','m^2'},... |
{'fldName','cellarea'},{'units','m^2'},... |
126 |
{'longName','grid cell area'},{'dimIn',dim2d}); |
{'longName','grid cell area'},{'dimIn',dim.twoD}); |
127 |
if isfield(grid_diag,'dep'); |
if isfield(grid_diag,'dep'); |
128 |
write2nctiles(myFile,grid_diag.dep,doCreate,... |
write2nctiles(myFile,grid_diag.dep,doCreate,{'tileNo',tileNo},... |
129 |
{'fldName','depth'},{'units','m'},{'dimIn',dimdep}); |
{'fldName','depth'},{'units','m'},{'dimIn',dim.dep}); |
130 |
write2nctiles(myFile,grid_diag.dz,doCreate,... |
write2nctiles(myFile,grid_diag.dz,doCreate,{'tileNo',tileNo},... |
131 |
{'fldName','cellthick'},{'units','m'},{'dimIn',dimdep}); |
{'fldName','cellthick'},{'units','m'},{'dimIn',dim.dep}); |
132 |
end; |
end; |
133 |
|
|
134 |
end;%for vv=1:length(listFlds); |
end;%for vv=1:length(listFlds); |