Changeset 930 for trunk/src/struct2nc.m
- Timestamp:
- Mar 10, 2016, 9:40:57 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/struct2nc.m
r924 r930 35 35 %======================================================================= 36 36 37 function errormsg=struct2nc(flname,Data) 38 if ~ischar(flname) 39 errormsg='invalid input for the netcf file name'; 40 return 41 end 37 function [errormsg,nc]=struct2nc(flname,Data,action) 38 nc=[]; 39 % if ~ischar(flname) 40 % errormsg='invalid input for the netcf file name'; 41 % return 42 % end 42 43 if ~exist('Data','var') 43 44 errormsg='no data input for the netcdf file'; 44 45 return 45 46 end 46 FilePath=fileparts(flname); 47 if ~strcmp(FilePath,'') && ~exist(FilePath,'dir') 48 errormsg=['directory ' FilePath ' needs to be created']; 49 return 50 end 47 if ~exist('action','var') 48 action='one_input'; %fill the file with data and close it 49 end 50 51 51 52 52 %% check the validity of the input field structure … … 59 59 60 60 %% 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); 61 if 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); 71 else 72 nc=flname; 73 end 65 74 66 75 %% write global constants … … 159 168 end 160 169 end 170 if strcmp(action,'one_input') 161 171 netcdf.close(nc) 162 172 end 163 173 164 174 %'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.