Changeset 693 for trunk/src/nc2struct.m


Ignore:
Timestamp:
Oct 29, 2013, 12:28:57 PM (11 years ago)
Author:
sommeria
Message:

bug repaired geometry_calib/Detect grid, + corrections in get_field

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/nc2struct.m

    r648 r693  
    1313%                    .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)                         
    1414%                    .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
    1718%         .Txt: error message
    1819%  var_detect: vector with same length as the cell array ListVarName, = 1 for each detected variable and 0 else.
     
    166167    for ncvar=1:nvars %loop on the variables of the netcdf file
    167168        %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);
    169170    end 
    170171    testmulti=0;
     
    221222            end
    222223            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;
    230226            end
    231227            catch ME
     
    233229                display(valuestr)
    234230                display(ME.message)         
    235                 eval(['Data.VarAttribute{ivar}.atrr_' num2str(iatt) '=''not read'';'])
     231                Data.VarAttribute{ivar}.(['atrr_' num2str(iatt)])='not read';
    236232            end
    237233        end
     
    255251                if var_dim{ivar}(end)==TimeDimIndex% if the last dim of the variable is the time
    256252                    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 data
     253                    Data.(VarName)=double(netcdf.getVar(nc,var_index(ivar)-1,TimeIndex*slice_length,slice_length)); %read the variable data
    258254                    CheckSub=1;
    259255                end
    260256            end
    261257            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);
    266266   
    267267    %%  -------- close fle-----------
Note: See TracChangeset for help on using the changeset viewer.