Changeset 527 for trunk/src/nc2struct.m
- Timestamp:
- Aug 20, 2012, 11:12:46 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/nc2struct.m
r517 r527 96 96 97 97 %% -------- read all global attributes (constants)----------- 98 att_key={};%default99 % iatt_g=0;100 98 Data.ListGlobalAttribute={};%default 99 att_key=cell(1,ngatts);%default 101 100 for iatt=1:ngatts 102 101 keystr= netcdf.inqAttName(nc,netcdf.getConstant('NC_GLOBAL'),iatt-1); … … 117 116 catch ME 118 117 att_key{iatt}=['attr_' num2str(iatt)]; 119 eval(['Data.' att_key{iatt} '=[];'])118 Data.(att_key{iatt})=[]; 120 119 end 121 120 end … … 123 122 124 123 %% -------- read dimension names----------- 125 ListDimNameNetcdf= {};126 dim_value= [];124 ListDimNameNetcdf=cell(1,ndims); 125 dim_value=zeros(1,ndims); 127 126 for idim=1:ndims %loop on the dimensions of the netcdf file 128 127 [ListDimNameNetcdf{idim},dim_value(idim)] = netcdf.inqDim(nc,idim-1);%get name and value of each dimension … … 133 132 134 133 %% -------- read names of variables ----------- 135 ListVarNameNetcdf= {}; %default136 dimids= {};137 nbatt= [];134 ListVarNameNetcdf=cell(1,nvars); %default 135 dimids=cell(1,nvars); 136 nbatt=zeros(1,nvars); 138 137 for ncvar=1:nvars %loop on the variables of the netcdf file 139 138 %get name, type, dimensions and attribute numbers of each variable … … 146 145 else %select input variables, if requested by the input ListVarName 147 146 ind_remove=[]; 148 for ivar=1:numel(ListVarName) % check redondancy 149 if ~isempty(find(strcmp(ListVarName{ivar},ListVarName(1:ivar-1)))) 150 ind_remove=[ind_remove ivar]; 151 end 152 end 153 if ~isempty(ind_remove) 154 ListVarName(ind_remove)=[]; 155 end 147 check_keep=ones(1,size(ListVarName,2)); 148 for ivar=1:size(ListVarName,2) % check redondancy of variable names 149 if ~isempty(find(strcmp(ListVarName{1,ivar},ListVarName(1:ivar-1)), 1)) 150 check_keep(ivar)=0;% the variable #ivar is already in the list 151 end 152 end 153 ListVarName=ListVarName(:,logical(check_keep)); 156 154 sizvar=size(ListVarName); 157 155 testmulti=(sizvar(1)>1);%test for multiple choice of variable ranked by order of priority
Note: See TracChangeset
for help on using the changeset viewer.