/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_IO/write2nctiles.m
ViewVC logotype

Diff of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/write2nctiles.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.4 by gforget, Mon Feb 3 14:28:52 2014 UTC revision 1.6 by gforget, Sun Jan 18 14:07:15 2015 UTC
# Line 14  function [dimOut]=write2nctiles(fileOut, Line 14  function [dimOut]=write2nctiles(fileOut,
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    
# Line 26  rdm=''; Line 30  rdm='';
30  fldName=inputname(2); longName='';  fldName=inputname(2); longName='';
31  units='(unknown)'; missval=NaN; fillval=NaN; dimIn=[];  units='(unknown)'; missval=NaN; fillval=NaN; dimIn=[];
32  tileNo=mygrid.XC; for ff=1:mygrid.nFaces; tileNo{ff}(:)=ff; end;  tileNo=mygrid.XC; for ff=1:mygrid.nFaces; tileNo{ff}(:)=ff; end;
33    coord='';
34    
35  %set more optional paramaters to user defined values  %set more optional paramaters to user defined values
36  for ii=1:nargin-3;  for ii=1:nargin-3;
# Line 51  for ii=1:nargin-3; Line 56  for ii=1:nargin-3;
56                  strcmp(varargin{ii}{1},'missval')|...                  strcmp(varargin{ii}{1},'missval')|...
57                  strcmp(varargin{ii}{1},'fillval')|...                  strcmp(varargin{ii}{1},'fillval')|...
58                  strcmp(varargin{ii}{1},'tileNo')|...                  strcmp(varargin{ii}{1},'tileNo')|...
59                    strcmp(varargin{ii}{1},'coord')|...
60                  strcmp(varargin{ii}{1},'dimIn');                  strcmp(varargin{ii}{1},'dimIn');
61              eval([varargin{ii}{1} '=varargin{ii}{2};']);              eval([varargin{ii}{1} '=varargin{ii}{2};']);
62          else;          else;
# Line 134  if doCreate; Line 140  if doCreate;
140    %-------------------    %-------------------
141  % ncid=nccreate(fileTile,'NETCDF4');%to allow for big files  % ncid=nccreate(fileTile,'NETCDF4');%to allow for big files
142    ncid=nccreate(fileTile,'clobber');    ncid=nccreate(fileTile,'clobber');
143      nc_global=netcdf.getConstant('NC_GLOBAL');
144    
145    if ~isempty(rdm);    if ~isempty(rdm);
146      descr2=[descr ' -- ' rdm{1}];      descr2=[descr ' -- ' rdm{1}];
# Line 149  if doCreate; Line 156  if doCreate;
156    pp=length(rdm)+1;    pp=length(rdm)+1;
157    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');
158    ncputAtt(ncid,'','date',date);    ncputAtt(ncid,'','date',date);
159      netcdf.putAtt(ncid,nc_global,'Conventions','CF-1.6')  
160    
161      ncputAtt(ncid,'','_FillValue',fillval);
162      ncputAtt(ncid,'','missing_value',missval);
163    
164    ncdefDim(ncid,'itxt',30);    ncdefDim(ncid,'itxt',30);
165    for dd=1:length(dimlist); ncdefDim(ncid,dimlist{dd},dimsize(dd)); end;    for dd=1:length(dimlist); ncdefDim(ncid,dimlist{dd},dimsize(dd)); end;
# Line 156  if doCreate; Line 167  if doCreate;
167    for dd=1:length(dimlist);    for dd=1:length(dimlist);
168      ncdefVar(ncid,dimlist{dd},'double',{dimlist{dd}});      ncdefVar(ncid,dimlist{dd},'double',{dimlist{dd}});
169      ncputAtt(ncid,dimlist{dd},'long_name',dimName{dd});      ncputAtt(ncid,dimlist{dd},'long_name',dimName{dd});
170        ncputAtt(ncid,dimlist{dd},'units','1');
171    end;    end;
172    ncclose(ncid);    ncclose(ncid);
173    
# Line 174  if ~isempty(dimIn); dimlist=dimIn{ff}; e Line 186  if ~isempty(dimIn); dimlist=dimIn{ff}; e
186  %define and fill field:  %define and fill field:
187  %----------------------  %----------------------
188  ncid=ncopen(fileTile,'write');  ncid=ncopen(fileTile,'write');
189  if (myenv.useNativeMatlabNetcdf); netcdf.reDef(ncid); end;  %
190    netcdf.reDef(ncid);
191  ncdefVar(ncid,fldName,'double',flipdim(dimlist,2));%note the direction flip  ncdefVar(ncid,fldName,'double',flipdim(dimlist,2));%note the direction flip
192  if ~isempty(longName); ncputAtt(ncid,fldName,'long_name',longName); end;  if ~isempty(longName); ncputAtt(ncid,fldName,'long_name',longName); end;
193  if ~isempty(units); ncputAtt(ncid,fldName,'units',units); end;  if ~isempty(units); ncputAtt(ncid,fldName,'units',units); end;
194  ncputAtt(ncid,fldName,'missing_value',missval);  if ~isempty(coord); ncputAtt(ncid,fldName,'coordinates',coord); end;
195  if (myenv.useNativeMatlabNetcdf); netcdf.endDef(ncid); end;  if strcmp(fldName,'lon'); ncputAtt(ncid,fldName,'standard_name','longitude'); end;
196    if strcmp(fldName,'lat'); ncputAtt(ncid,fldName,'standard_name','latitude'); end;
197    if strcmp(fldName,'dep'); ncputAtt(ncid,fldName,'standard_name','depth'); end;
198    if strcmp(fldName,'tim'); ncputAtt(ncid,fldName,'standard_name','time'); end;
199    if strcmp(fldName,'land'); ncputAtt(ncid,fldName,'standard_name','land_binary_mask'); end;
200    if strcmp(fldName,'area'); ncputAtt(ncid,fldName,'standard_name','cell_area'); end;
201    if strcmp(fldName,'thic'); ncputAtt(ncid,fldName,'standard_name','cell_thickness'); end;
202    netcdf.endDef(ncid);
203    %
204  ncputvar(ncid,fldName,fldTile);  ncputvar(ncid,fldName,fldTile);
205  ncclose(ncid);  ncclose(ncid);
206    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.22