14 |
% 'missval' is the missing value (default : NaN). |
% 'missval' is the missing value (default : NaN). |
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') |
18 |
%netcdf dimensions : array dimensions are simply set to 'i1,i2,...' |
%netcdf dimensions : array dimensions are simply set to 'i1,i2,...' |
19 |
|
|
20 |
gcmfaces_global; |
gcmfaces_global; |
21 |
|
if ~(myenv.useNativeMatlabNetcdf); |
22 |
|
error('only native matlab nectdf is supported in write2nctiles'); |
23 |
|
end; |
24 |
|
|
25 |
doCheck=0;%set to one to print stuff to screen |
doCheck=0;%set to one to print stuff to screen |
26 |
|
|
27 |
|
fldInIsaGcmfaces=isa(fldIn,'gcmfaces'); |
28 |
|
|
29 |
%set more optional paramaters to default values |
%set more optional paramaters to default values |
30 |
descr=''; |
descr=''; |
31 |
rdm=''; |
rdm=''; |
32 |
fldName=inputname(2); longName=''; |
fldName=inputname(2); longName=''; |
33 |
units='(unknown)'; missval=NaN; fillval=NaN; dimIn=[]; |
units='(unknown)'; missval=NaN; fillval=NaN; dimIn=[]; |
34 |
tileNo=mygrid.XC; for ff=1:mygrid.nFaces; tileNo{ff}(:)=ff; end; |
tileNo=mygrid.XC; for ff=1:mygrid.nFaces; tileNo{ff}(:)=ff; end; |
35 |
|
coord=''; |
36 |
|
|
37 |
%set more optional paramaters to user defined values |
%set more optional paramaters to user defined values |
38 |
for ii=1:nargin-3; |
for ii=1:nargin-3; |
58 |
strcmp(varargin{ii}{1},'missval')|... |
strcmp(varargin{ii}{1},'missval')|... |
59 |
strcmp(varargin{ii}{1},'fillval')|... |
strcmp(varargin{ii}{1},'fillval')|... |
60 |
strcmp(varargin{ii}{1},'tileNo')|... |
strcmp(varargin{ii}{1},'tileNo')|... |
61 |
|
strcmp(varargin{ii}{1},'coord')|... |
62 |
strcmp(varargin{ii}{1},'dimIn'); |
strcmp(varargin{ii}{1},'dimIn'); |
63 |
eval([varargin{ii}{1} '=varargin{ii}{2};']); |
eval([varargin{ii}{1} '=varargin{ii}{2};']); |
64 |
else; |
else; |
73 |
tileList=tileList(~isnan(tileList)); |
tileList=tileList(~isnan(tileList)); |
74 |
ntile=length(tileList); |
ntile=length(tileList); |
75 |
% |
% |
76 |
if isa(fldIn,'gcmfaces'); |
if fldInIsaGcmfaces; |
77 |
for ff=1:ntile; |
for ff=1:ntile; |
78 |
tmp1=[]; |
tmp1=[]; |
79 |
for gg=1:mygrid.nFaces; |
for gg=1:mygrid.nFaces; |
86 |
end; |
end; |
87 |
fldTiles{ff}=tmp1; |
fldTiles{ff}=tmp1; |
88 |
end; |
end; |
89 |
|
clear fldIn; |
90 |
end; |
end; |
91 |
|
|
92 |
%start processing loop |
%start processing loop |
93 |
for ff=1:ntile; |
for ff=1:ntile; |
94 |
|
|
95 |
if isa(fldIn,'gcmfaces'); |
if fldInIsaGcmfaces; |
96 |
fldTile=fldTiles{ff}; |
fldTile=fldTiles{ff}; |
97 |
%reverse order of dimensions |
%reverse order of dimensions |
98 |
nn=length(size(fldTile)); |
nn=length(size(fldTile)); |
99 |
fldTile=permute(fldTile,[nn:-1:1]); |
fldTile=permute(fldTile,[nn:-1:1]); |
100 |
|
if ntile==1; clear fldTiles; end; |
101 |
else; |
else; |
102 |
fldTile=fldIn; |
fldTile=fldIn; |
103 |
end; |
end; |
142 |
if doCreate; |
if doCreate; |
143 |
%create netcdf file: |
%create netcdf file: |
144 |
%------------------- |
%------------------- |
145 |
% ncid=nccreate(fileTile,'NETCDF4');%to allow for big files |
if prod(size(fldTile))*4/1e9<1.5;%use (always available) basic ncetcf: |
146 |
ncid=nccreate(fileTile,'clobber'); |
mode='clobber'; |
147 |
|
else;%to allow for large file: |
148 |
|
mode='NETCDF4'; |
149 |
|
end; |
150 |
|
ncid=nccreate(fileTile,mode); |
151 |
|
nc_global=netcdf.getConstant('NC_GLOBAL'); |
152 |
|
|
153 |
if ~isempty(rdm); |
if ~isempty(rdm); |
154 |
descr2=[descr ' -- ' rdm{1}]; |
descr2=[descr ' -- ' rdm{1}]; |
164 |
pp=length(rdm)+1; |
pp=length(rdm)+1; |
165 |
netcdf.putAtt(ncid,nc_global,tmp1,'file created using gcmfaces_IO/write2nctiles.m'); |
netcdf.putAtt(ncid,nc_global,tmp1,'file created using gcmfaces_IO/write2nctiles.m'); |
166 |
ncputAtt(ncid,'','date',date); |
ncputAtt(ncid,'','date',date); |
167 |
|
netcdf.putAtt(ncid,nc_global,'Conventions','CF-1.6') |
168 |
|
|
169 |
|
ncputAtt(ncid,'','_FillValue',fillval); |
170 |
|
ncputAtt(ncid,'','missing_value',missval); |
171 |
|
|
172 |
ncdefDim(ncid,'itxt',30); |
ncdefDim(ncid,'itxt',30); |
173 |
for dd=1:length(dimlist); ncdefDim(ncid,dimlist{dd},dimsize(dd)); end; |
for dd=1:length(dimlist); ncdefDim(ncid,dimlist{dd},dimsize(dd)); end; |
175 |
for dd=1:length(dimlist); |
for dd=1:length(dimlist); |
176 |
ncdefVar(ncid,dimlist{dd},'double',{dimlist{dd}}); |
ncdefVar(ncid,dimlist{dd},'double',{dimlist{dd}}); |
177 |
ncputAtt(ncid,dimlist{dd},'long_name',dimName{dd}); |
ncputAtt(ncid,dimlist{dd},'long_name',dimName{dd}); |
178 |
|
ncputAtt(ncid,dimlist{dd},'units','1'); |
179 |
end; |
end; |
180 |
ncclose(ncid); |
ncclose(ncid); |
181 |
|
|
194 |
%define and fill field: |
%define and fill field: |
195 |
%---------------------- |
%---------------------- |
196 |
ncid=ncopen(fileTile,'write'); |
ncid=ncopen(fileTile,'write'); |
197 |
if (myenv.useNativeMatlabNetcdf); netcdf.reDef(ncid); end; |
% |
198 |
|
netcdf.reDef(ncid); |
199 |
ncdefVar(ncid,fldName,'double',flipdim(dimlist,2));%note the direction flip |
ncdefVar(ncid,fldName,'double',flipdim(dimlist,2));%note the direction flip |
200 |
if ~isempty(longName); ncputAtt(ncid,fldName,'long_name',longName); end; |
if ~isempty(longName); ncputAtt(ncid,fldName,'long_name',longName); end; |
201 |
if ~isempty(units); ncputAtt(ncid,fldName,'units',units); end; |
if ~isempty(units); ncputAtt(ncid,fldName,'units',units); end; |
202 |
ncputAtt(ncid,fldName,'missing_value',missval); |
if ~isempty(coord); ncputAtt(ncid,fldName,'coordinates',coord); end; |
203 |
if (myenv.useNativeMatlabNetcdf); netcdf.endDef(ncid); end; |
if strcmp(fldName,'lon'); ncputAtt(ncid,fldName,'standard_name','longitude'); end; |
204 |
|
if strcmp(fldName,'lat'); ncputAtt(ncid,fldName,'standard_name','latitude'); end; |
205 |
|
if strcmp(fldName,'dep'); ncputAtt(ncid,fldName,'standard_name','depth'); end; |
206 |
|
if strcmp(fldName,'tim'); ncputAtt(ncid,fldName,'standard_name','time'); end; |
207 |
|
if strcmp(fldName,'land'); ncputAtt(ncid,fldName,'standard_name','land_binary_mask'); end; |
208 |
|
if strcmp(fldName,'area'); ncputAtt(ncid,fldName,'standard_name','cell_area'); end; |
209 |
|
if strcmp(fldName,'thic'); ncputAtt(ncid,fldName,'standard_name','cell_thickness'); end; |
210 |
|
netcdf.endDef(ncid); |
211 |
|
% |
212 |
ncputvar(ncid,fldName,fldTile); |
ncputvar(ncid,fldName,fldTile); |
213 |
ncclose(ncid); |
ncclose(ncid); |
214 |
|
|