15 |
% 'fillval' is the fill value (default : NaN). |
% 'fillval' is the fill value (default : NaN). |
16 |
% 'tileNo' is a map of tile indices (default is face number) |
% 'tileNo' is a map of tile indices (default is face number) |
17 |
% 'coord' is auxilliary coordinates attribute (e.g. 'lon lat dep') |
% 'coord' is auxilliary coordinates attribute (e.g. 'lon lat dep') |
18 |
|
% 'dimsize' is the array size associated with 'coord' |
19 |
|
% 'xtype' is 'double' by default |
20 |
%netcdf dimensions : array dimensions are simply set to 'i1,i2,...' |
%netcdf dimensions : array dimensions are simply set to 'i1,i2,...' |
21 |
|
|
22 |
gcmfaces_global; |
gcmfaces_global; |
26 |
|
|
27 |
doCheck=0;%set to one to print stuff to screen |
doCheck=0;%set to one to print stuff to screen |
28 |
|
|
29 |
|
fldInIsaGcmfaces=isa(fldIn,'gcmfaces'); |
30 |
|
|
31 |
|
if fldInIsaGcmfaces; |
32 |
|
fldInIsEmpty=isempty(fldIn{1}); |
33 |
|
else; |
34 |
|
fldInIsEmpty=isempty(fldIn); |
35 |
|
end; |
36 |
|
|
37 |
%set more optional paramaters to default values |
%set more optional paramaters to default values |
38 |
descr=''; |
descr=''; |
39 |
rdm=''; |
rdm=''; |
40 |
fldName=inputname(2); longName=''; |
fldName=inputname(2); longName=''; |
41 |
units='(unknown)'; missval=NaN; fillval=NaN; dimIn=[]; |
units='(unknown)'; missval=NaN; fillval=NaN; dimIn=[]; |
42 |
tileNo=mygrid.XC; for ff=1:mygrid.nFaces; tileNo{ff}(:)=ff; end; |
tileNo=mygrid.XC; for ff=1:mygrid.nFaces; tileNo{ff}(:)=ff; end; |
43 |
coord=''; |
coord=''; dimsize=[]; xtype='double'; |
44 |
|
|
45 |
%set more optional paramaters to user defined values |
%set more optional paramaters to user defined values |
46 |
for ii=1:nargin-3; |
for ii=1:nargin-3; |
67 |
strcmp(varargin{ii}{1},'fillval')|... |
strcmp(varargin{ii}{1},'fillval')|... |
68 |
strcmp(varargin{ii}{1},'tileNo')|... |
strcmp(varargin{ii}{1},'tileNo')|... |
69 |
strcmp(varargin{ii}{1},'coord')|... |
strcmp(varargin{ii}{1},'coord')|... |
70 |
|
strcmp(varargin{ii}{1},'dimsize')|... |
71 |
|
strcmp(varargin{ii}{1},'xtype')|... |
72 |
strcmp(varargin{ii}{1},'dimIn'); |
strcmp(varargin{ii}{1},'dimIn'); |
73 |
eval([varargin{ii}{1} '=varargin{ii}{2};']); |
eval([varargin{ii}{1} '=varargin{ii}{2};']); |
74 |
else; |
else; |
83 |
tileList=tileList(~isnan(tileList)); |
tileList=tileList(~isnan(tileList)); |
84 |
ntile=length(tileList); |
ntile=length(tileList); |
85 |
% |
% |
86 |
if isa(fldIn,'gcmfaces'); |
if fldInIsaGcmfaces&~fldInIsEmpty; |
87 |
for ff=1:ntile; |
for ff=1:ntile; |
88 |
tmp1=[]; |
tmp1=[]; |
89 |
for gg=1:mygrid.nFaces; |
for gg=1:mygrid.nFaces; |
96 |
end; |
end; |
97 |
fldTiles{ff}=tmp1; |
fldTiles{ff}=tmp1; |
98 |
end; |
end; |
99 |
|
clear fldIn; |
100 |
|
elseif fldInIsaGcmfaces; |
101 |
|
for ff=1:ntile; |
102 |
|
fldTiles{ff}=[]; |
103 |
|
end; |
104 |
end; |
end; |
105 |
|
|
106 |
%start processing loop |
%start processing loop |
107 |
for ff=1:ntile; |
for ff=1:ntile; |
108 |
|
|
109 |
if isa(fldIn,'gcmfaces'); |
if fldInIsaGcmfaces; |
110 |
fldTile=fldTiles{ff}; |
fldTile=fldTiles{ff}; |
111 |
%reverse order of dimensions |
%reverse order of dimensions |
112 |
nn=length(size(fldTile)); |
nn=length(size(fldTile)); |
113 |
fldTile=permute(fldTile,[nn:-1:1]); |
fldTile=permute(fldTile,[nn:-1:1]); |
114 |
|
if ntile==1; clear fldTiles; end; |
115 |
else; |
else; |
116 |
fldTile=fldIn; |
fldTile=fldIn; |
117 |
end; |
end; |
118 |
fileTile=[fileOut sprintf('.%04d.nc',ff)]; |
fileTile=[fileOut sprintf('.%04d.nc',ff)]; |
119 |
|
|
120 |
%select dimensions of relevance: |
%select dimensions of relevance: |
121 |
nDim=length(size(fldTile)); |
if ~fldInIsEmpty; |
122 |
dimsize=size(fldTile); |
nDim=length(size(fldTile)); |
123 |
|
dimsize=size(fldTile); |
124 |
|
elseif ~isempty(dimsize); |
125 |
|
nDim=length(dimsize); |
126 |
|
else; |
127 |
|
error('undertermined array size'); |
128 |
|
end; |
129 |
|
|
130 |
for iDim=1:nDim; |
for iDim=1:nDim; |
131 |
if size(fldTile,iDim)~=1; |
if dimsize(iDim)~=1; |
132 |
dimlist{iDim}=['i' num2str(iDim)]; |
dimlist{iDim}=['i' num2str(iDim)]; |
133 |
dimName{iDim}=['array index ' num2str(iDim)]; |
dimName{iDim}=['array index ' num2str(iDim)]; |
134 |
eval(['dimvec.i' num2str(iDim) '=[1:size(fldTile,iDim)];']); |
eval(['dimvec.i' num2str(iDim) '=[1:dimsize(iDim)];']); |
135 |
end; |
end; |
136 |
end; |
end; |
137 |
|
|
163 |
if doCreate; |
if doCreate; |
164 |
%create netcdf file: |
%create netcdf file: |
165 |
%------------------- |
%------------------- |
166 |
% ncid=nccreate(fileTile,'NETCDF4');%to allow for big files |
if prod(dimsize)*4/1e9<1.5;%use (always available) basic netcdf: |
167 |
ncid=nccreate(fileTile,'clobber'); |
mode='clobber'; |
168 |
|
else;%to allow for large file: |
169 |
|
mode='NETCDF4'; |
170 |
|
end; |
171 |
|
ncid=nccreate(fileTile,mode); |
172 |
nc_global=netcdf.getConstant('NC_GLOBAL'); |
nc_global=netcdf.getConstant('NC_GLOBAL'); |
173 |
|
|
174 |
if ~isempty(rdm); |
if ~isempty(rdm); |
217 |
ncid=ncopen(fileTile,'write'); |
ncid=ncopen(fileTile,'write'); |
218 |
% |
% |
219 |
netcdf.reDef(ncid); |
netcdf.reDef(ncid); |
220 |
ncdefVar(ncid,fldName,'double',flipdim(dimlist,2));%note the direction flip |
ncdefVar(ncid,fldName,xtype,flipdim(dimlist,2));%note the direction flip |
221 |
if ~isempty(longName); ncputAtt(ncid,fldName,'long_name',longName); end; |
if ~isempty(longName); ncputAtt(ncid,fldName,'long_name',longName); end; |
222 |
if ~isempty(units); ncputAtt(ncid,fldName,'units',units); end; |
if ~isempty(units); ncputAtt(ncid,fldName,'units',units); end; |
223 |
if ~isempty(coord); ncputAtt(ncid,fldName,'coordinates',coord); end; |
if ~isempty(coord); ncputAtt(ncid,fldName,'coordinates',coord); end; |
230 |
if strcmp(fldName,'thic'); ncputAtt(ncid,fldName,'standard_name','cell_thickness'); end; |
if strcmp(fldName,'thic'); ncputAtt(ncid,fldName,'standard_name','cell_thickness'); end; |
231 |
netcdf.endDef(ncid); |
netcdf.endDef(ncid); |
232 |
% |
% |
233 |
ncputvar(ncid,fldName,fldTile); |
if ~fldInIsEmpty; ncputvar(ncid,fldName,fldTile); end; |
234 |
|
% |
235 |
ncclose(ncid); |
ncclose(ncid); |
236 |
|
|
237 |
end;%for ff=1:ntile; |
end;%for ff=1:ntile; |