20 |
%listFiles={'trsp_3d_set1','trsp_3d_set2','trsp_3d_set3'}; |
%listFiles={'trsp_3d_set1','trsp_3d_set2','trsp_3d_set3'}; |
21 |
%for ff=1:length(listFiles); process2nctiles('iter12/',listFiles{ff},[],[90 90]); end; |
%for ff=1:length(listFiles); process2nctiles('iter12/',listFiles{ff},[],[90 90]); end; |
22 |
|
|
23 |
|
%replace time series with monthly climatology? |
24 |
|
doClim=0; |
25 |
|
|
26 |
%directory names |
%directory names |
27 |
listDirs={'STATE/','TRSP/'}; |
listDirs={'STATE/','TRSP/'};%BUDG? |
28 |
filAvailDiag=[dirModel 'available_diagnostics.log']; |
filAvailDiag=[dirModel 'available_diagnostics.log']; |
29 |
filReadme=[dirModel 'README']; |
filReadme=[dirModel 'README']; |
30 |
dirOut=[dirModel 'nctiles/']; |
dirOut=[dirModel 'nctiles_tmp/']; |
31 |
if ~isdir(dirOut); mkdir(dirOut); end; |
if ~isdir(dirOut); mkdir(dirOut); end; |
32 |
|
|
33 |
%seacrh in subdirectories |
%search in subdirectories |
34 |
subDir=[]; |
subDir=[]; |
35 |
for ff=1:length(listDirs); |
for ff=1:length(listDirs); |
36 |
tmp1=dir([dirModel 'diags/' listDirs{ff} fileModel '*']); |
tmp1=dir([dirModel 'diags/' listDirs{ff} fileModel '*']); |
75 |
%read time series |
%read time series |
76 |
myDiag=rdmds2gcmfaces([dirIn fileModel '*'],NaN,'rec',irec); |
myDiag=rdmds2gcmfaces([dirIn fileModel '*'],NaN,'rec',irec); |
77 |
|
|
78 |
|
%replace time series with monthly climatology |
79 |
|
if doClim; myDiag=compClim(myDiag); end; |
80 |
|
|
81 |
%set ancilliary time variable |
%set ancilliary time variable |
82 |
nn=length(size(myDiag{1})); |
nn=length(size(myDiag{1})); |
83 |
nn=size(myDiag{1},nn); |
nn=size(myDiag{1},nn); |
87 |
timUnits='days since 1992-1-1 0:0:0'; |
timUnits='days since 1992-1-1 0:0:0'; |
88 |
|
|
89 |
%get time step axis |
%get time step axis |
90 |
[listTimes]=diags_list_times({[dirModel 'diags/STATE/']},{'state_2d_set1'}); |
[listTimes]=diags_list_times({dirIn},{fileModel}); |
91 |
|
|
92 |
%get units and long name from available_diagnostics.log |
%get units and long name from available_diagnostics.log |
93 |
[avail_diag]=read_avail_diag(filAvailDiag,nameDiag); |
[avail_diag]=read_avail_diag(filAvailDiag,nameDiag); |
107 |
%apply mask, and convert to land mask |
%apply mask, and convert to land mask |
108 |
msk=grid_diag.msk; |
msk=grid_diag.msk; |
109 |
if length(size(myDiag{1}))==3; |
if length(size(myDiag{1}))==3; |
110 |
msk=repmat(msk,[1 1 size(myDiag{1},3)]); |
msk=repmat(msk(:,:,1),[1 1 size(myDiag{1},3)]); |
111 |
end; |
end; |
112 |
for kk=1:size(myDiag{1},4); |
for kk=1:size(myDiag{1},4); |
113 |
myDiag(:,:,:,kk)=myDiag(:,:,:,kk).*msk; |
myDiag(:,:,:,kk)=myDiag(:,:,:,kk).*msk; |
123 |
coord='lon lat tim'; |
coord='lon lat tim'; |
124 |
end; |
end; |
125 |
|
|
126 |
|
%replace time series with monthly climatology |
127 |
|
if doClim; |
128 |
|
listTimes=listTimes(1:12); |
129 |
|
timUnits='days since year-1-1 0:0:0'; |
130 |
|
avail_diag.longNameDiag=[avail_diag.longNameDiag ' (climatology) ']; |
131 |
|
end; |
132 |
|
|
133 |
%create netcdf file using write2nctiles (works only with old matlab, thus far ...) |
%create netcdf file using write2nctiles (works only with old matlab, thus far ...) |
134 |
doCreate=1; |
doCreate=1; |
135 |
dimlist=write2nctiles(myFile,myDiag,doCreate,{'tileNo',tileNo},... |
dimlist=write2nctiles(myFile,myDiag,doCreate,{'tileNo',tileNo},... |
291 |
grid_diag.dep=reshape(grid_diag.dep,[1 1 avail_diag.nr]); |
grid_diag.dep=reshape(grid_diag.dep,[1 1 avail_diag.nr]); |
292 |
grid_diag.dz=reshape(grid_diag.dz,[1 1 avail_diag.nr]); |
grid_diag.dz=reshape(grid_diag.dz,[1 1 avail_diag.nr]); |
293 |
end; |
end; |
294 |
|
|
295 |
|
%%replace time series with monthly climatology |
296 |
|
function [FLD]=compClim(fld); |
297 |
|
|
298 |
|
gcmfaces_global; |
299 |
|
|
300 |
|
ndim=length(size(fld{1})); |
301 |
|
nyear=size(fld{1},ndim)/12; |
302 |
|
|
303 |
|
if ndim==3; FLD=NaN*fld(:,:,1:12); end; |
304 |
|
if ndim==4; FLD=NaN*fld(:,:,:,1:12); end; |
305 |
|
|
306 |
|
for mm=1:12; |
307 |
|
if ndim==3; FLD(:,:,mm)=mean(fld(:,:,mm:12:12*nyear),ndim); end; |
308 |
|
if ndim==4; FLD(:,:,:,mm)=mean(fld(:,:,:,mm:12:12*nyear),ndim); end; |
309 |
|
end; |
310 |
|
|