/[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.9 by gforget, Thu Feb 23 18:13:42 2017 UTC revision 1.10 by gforget, Thu Mar 16 13:15:39 2017 UTC
# Line 1  Line 1 
1  function [dimOut]=write2nctiles(fileOut,fldIn,doCreate,varargin);  function [dimOut]=write2nctiles(fileOut,fldIn,doCreate,varargin);
2  %object : write gcmfaces object to netcdf files (tiled)  % WRITE2NCTILES writes a gcmfaces object to nctiles, tiled netcdf, files
3  %inputs : fileOut is the name of the file to be created  %
4  %         fldIn is the array to write to disk  % inputs :
5  %         doCreate is a 0/1 switch; 1 => create file ; 0 => append to file.  %    - fileOut is the name of the file to be created
6  %optional paramaters :  %    - fldIn is the array to write to disk
7  %         can be provided in the form {'name',value}  %    - doCreate: if 1 (default) then create file ; if 0 then append to file.
8  %         those that are currently active are  %
9  %               'descr' is the file description (default '').  % additional paramaters can be provided afterwards in the {'name',value} form:
10  %               'rdm' is the extended estimate description (default '').  %         'fldName' is the nc variable name for fld (see "notes" regarding default)
11  %               'fldName' is the nc variable name for fld (default : the outside name of fldIn).  %         'longName' is the corresponding long name ('' by default).
12  %               'longName' is the corresponding long name (default : '').  %         'units' is the unit of fld ('(unknown)' by default).
13  %               'units' is the unit of fld (default : '(unknown)').  %         'missval' is the missing value (NaN by default).
14  %               'missval' is the missing value (default : NaN).  %         'fillval' is the fill value (NaN by default).
15  %               'fillval' is the fill value (default : NaN).  %         'tileNo' is a map of tile indices (face # by default)
16  %               'tileNo' is a map of tile indices (default is face number)  %         'coord' is auxilliary coordinates attribute (e.g. 'lon lat dep')
17  %               'coord' is auxilliary coordinates attribute (e.g. 'lon lat dep')  %         'dimsize' is the array size associated with 'coord'
18  %               'dimsize' is the array size associated with 'coord'  %         'xtype' is the variable ('double' by default)
19  %               'xtype' is 'double' by default  %         'rdm' is the extended estimate description ('' by default).
20  %netcdf dimensions : array dimensions are simply set to 'i1,i2,...'  %         'descr' is the file description ('' by default).
21    %
22    % notes:
23    %    - if fldName is not explicitly specified then the input variable
24    %      name (if ok) or file name (otherwise) is used as fldName.
25    %    - netcdf dimensions are simply set to 'i1,i2,...'
26    %
27    % examples:
28    %
29    %    write2nctiles('test1',mygrid.RAC,1,{'fldName','RAC'});
30    %    RAC=read_nctiles('test1','RAC');
31    %
32    %    write2nctiles('test2',mygrid.RAC);
33    %    RAC=read_nctiles('test2','test2');
34    %    RAC=read_nctiles('test2');
35    
36  gcmfaces_global;  gcmfaces_global;
37  if ~(myenv.useNativeMatlabNetcdf);  if ~(myenv.useNativeMatlabNetcdf);
# Line 26  end; Line 40  end;
40    
41  doCheck=0;%set to one to print stuff to screen  doCheck=0;%set to one to print stuff to screen
42    
43  fldInIsaGcmfaces=isa(fldIn,'gcmfaces');  if isempty(whos('fileOut')); error('fileOut must be specified'); end;
44    if isempty(whos('fldIn')); error('fldIn must be specified'); end;
45    if isempty(whos('doCreate')); doCreate=1; end;
46    
47    fldInIsaGcmfaces=isa(fldIn,'gcmfaces');
48  if fldInIsaGcmfaces;  if fldInIsaGcmfaces;
49    fldInIsEmpty=isempty(fldIn{1});    fldInIsEmpty=isempty(fldIn{1});
50  else;  else;
51    fldInIsEmpty=isempty(fldIn);    fldInIsEmpty=isempty(fldIn);
52  end;  end;
53        
54  %set more optional paramaters to default values  %set more optional paramaters to default values
55  descr='';  fldName=inputname(2);
56  rdm='';  if isempty(fldName);
57  fldName=inputname(2); longName='';      [tmp1,fldName,tmp2] = fileparts(fileOut);
58  units='(unknown)'; missval=NaN; fillval=NaN; dimIn=[];  end;
59    longName=''; units='(unknown)'; missval=NaN; fillval=NaN; dimIn=[];
60  tileNo=mygrid.XC; for ff=1:mygrid.nFaces; tileNo{ff}(:)=ff; end;  tileNo=mygrid.XC; for ff=1:mygrid.nFaces; tileNo{ff}(:)=ff; end;
61  coord=''; dimsize=[]; xtype='double';  coord=''; dimsize=[]; xtype='double'; descr=''; rdm='';
62    
63  %set more optional paramaters to user defined values  %set more optional paramaters to user defined values
64  for ii=1:nargin-3;  for ii=1:nargin-3;
# Line 182  if doCreate; Line 200  if doCreate;
200    netcdf.putAtt(ncid,nc_global,tmp1,rdm{pp});    netcdf.putAtt(ncid,nc_global,tmp1,rdm{pp});
201    end;    end;
202    %append readme    %append readme
203    pp=length(rdm)+1;    if length(rdm)>0; pp=length(rdm)+1; tmp1=char(pp+63); else; tmp1='A'; end;
204    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');
205    ncputAtt(ncid,'','date',date);    ncputAtt(ncid,'','date',date);
206    netcdf.putAtt(ncid,nc_global,'Conventions','CF-1.6')      netcdf.putAtt(ncid,nc_global,'Conventions','CF-1.6')  

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.22