Changeset 930 for trunk/src/struct2nc.m


Ignore:
Timestamp:
Mar 10, 2016, 9:40:57 PM (8 years ago)
Author:
sommeria
Message:

extract functions updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/struct2nc.m

    r924 r930  
    3535%=======================================================================
    3636
    37 function errormsg=struct2nc(flname,Data)
    38 if ~ischar(flname)
    39     errormsg='invalid input for the netcf file name';
    40     return
    41 end
     37function [errormsg,nc]=struct2nc(flname,Data,action)
     38nc=[];
     39% if ~ischar(flname)
     40%     errormsg='invalid input for the netcf file name';
     41%     return
     42% end
    4243if ~exist('Data','var')
    4344     errormsg='no data  input for the netcdf file';
    4445    return
    4546end
    46 FilePath=fileparts(flname);
    47 if ~strcmp(FilePath,'') && ~exist(FilePath,'dir')
    48     errormsg=['directory ' FilePath ' needs to be created'];
    49     return
    50 end
     47if ~exist('action','var')
     48    action='one_input'; %fill the file with data and close it
     49end
     50
    5151
    5252%% check the validity of the input field structure
     
    5959
    6060%% create the netcdf file with name flname in format NETCDF4
    61 cmode = netcdf.getConstant('NETCDF4');
    62 cmode = bitor(cmode, netcdf.getConstant('CLASSIC_MODEL'));
    63 cmode = bitor(cmode, netcdf.getConstant('CLOBBER'));
    64 nc = netcdf.create(flname, cmode);
     61if ischar(flname)
     62    FilePath=fileparts(flname);
     63    if ~strcmp(FilePath,'') && ~exist(FilePath,'dir')
     64        errormsg=['directory ' FilePath ' needs to be created'];
     65        return
     66    end
     67    cmode = netcdf.getConstant('NETCDF4');
     68    cmode = bitor(cmode, netcdf.getConstant('CLASSIC_MODEL'));
     69    cmode = bitor(cmode, netcdf.getConstant('CLOBBER'));
     70    nc = netcdf.create(flname, cmode);
     71else
     72    nc=flname;
     73end
    6574
    6675%% write global constants
     
    159168    end
    160169end
     170if strcmp(action,'one_input')
    161171netcdf.close(nc)
    162 
     172end
    163173
    164174%'check_field_structure': check the validity of the field struture representation consistant with the netcdf format
Note: See TracChangeset for help on using the changeset viewer.