Changeset 693 for trunk/src/nc2struct.m
- Timestamp:
- Oct 29, 2013, 12:28:57 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/nc2struct.m
r648 r693 13 13 % .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells) 14 14 % .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName 15 % ListDimName=list of dimension (added information, not requested for field description) 16 % DimValue= vlalues of dimensions (added information, not requested for field description) 15 % .ListDimName=list of dimension (added information, not requested for field description) 16 % .DimValue= vlalues of dimensions (added information, not requested for field description) 17 % .VarType= integers giving the type of variable as coded by netcdf= 2 for char, =4 for single,=( for double 17 18 % .Txt: error message 18 19 % var_detect: vector with same length as the cell array ListVarName, = 1 for each detected variable and 0 else. … … 166 167 for ncvar=1:nvars %loop on the variables of the netcdf file 167 168 %get name, type, dimensions and attribute numbers of each variable 168 [ListVarNameNetcdf{ncvar},xtype ,dimids{ncvar},nbatt(ncvar)] = netcdf.inqVar(nc,ncvar-1);169 [ListVarNameNetcdf{ncvar},xtype(ncvar),dimids{ncvar},nbatt(ncvar)] = netcdf.inqVar(nc,ncvar-1); 169 170 end 170 171 testmulti=0; … … 221 222 end 222 223 try 223 if ischar(valuestr) 224 % valuestr=regexprep(valuestr,{'\\','\/','\.','\-',' '},{'_','_','_','_','_'});%remove '\','.' or '-' if exists 225 eval(['Data.VarAttribute{ivar}.' attname '=''' valuestr ''';']) 226 elseif isempty(valuestr) 227 eval(['Data.VarAttribute{ivar}.' attname '=[];']) 228 elseif isnumeric(valuestr) 229 eval(['Data.VarAttribute{ivar}.' attname '=valuestr;']) 224 if isempty(valuestr) 225 Data.VarAttribute{ivar}.(attname)=valuestr; 230 226 end 231 227 catch ME … … 233 229 display(valuestr) 234 230 display(ME.message) 235 eval(['Data.VarAttribute{ivar}.atrr_' num2str(iatt) '=''not read'';'])231 Data.VarAttribute{ivar}.(['atrr_' num2str(iatt)])='not read'; 236 232 end 237 233 end … … 255 251 if var_dim{ivar}(end)==TimeDimIndex% if the last dim of the variable is the time 256 252 slice_length=prod(var_dim{ivar}(1:end-1)); 257 Data.(VarName)=double(netcdf.getVar(nc,var_index(ivar)-1 ),TimeIndex*slice_length,slice_length); %read the variable data253 Data.(VarName)=double(netcdf.getVar(nc,var_index(ivar)-1,TimeIndex*slice_length,slice_length)); %read the variable data 258 254 CheckSub=1; 259 255 end 260 256 end 261 257 if ~CheckSub 262 Data.(VarName)=double(netcdf.getVar(nc,var_index(ivar)-1)); %read the whole variable data 263 end 264 end 265 end 258 Data.(VarName)=netcdf.getVar(nc,var_index(ivar)-1); %read the whole variable data 259 if xtype(var_index(ivar))==5 260 Data.(VarName)=double(Data.(VarName)); %transform to double for single pecision 261 end 262 end 263 end 264 end 265 Data.VarType=xtype(var_index); 266 266 267 267 %% -------- close fle-----------
Note: See TracChangeset
for help on using the changeset viewer.