- Timestamp:
- Aug 20, 2012, 11:12:46 PM (12 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/find_field_cells.m
r525 r527 225 225 % look for coordinates variables 226 226 coord=zeros(1,numel(DimCell));%default 227 % if NbDim(icell)==0 && ~isempty(VarDimName)% no unstructured coordinate found228 227 if ~test_coord && ~isempty(VarDimName) 229 228 for idim=1:numel(DimCell) %loop on the dimensions of the variables in cell #icell -
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 -
trunk/src/read_civxdata.m
r498 r527 53 53 DataTest=nc2struct(filename,'ListGlobalAttribute','Conventions','CivStage'); 54 54 if isfield(DataTest,'Txt') 55 errormsg=['nc2struct :' DataTest.Txt];55 errormsg=['nc2struct / ' DataTest.Txt]; 56 56 return 57 57 elseif isequal(DataTest.Conventions,'uvmat/civdata')%test for new civ format 58 58 [Field,VelTypeOut,errormsg]=read_civdata(filename,FieldNames,VelType,DataTest.CivStage); 59 if ~isempty(errormsg),errormsg=['read_civdata :' errormsg];end59 if ~isempty(errormsg),errormsg=['read_civdata / ' errormsg];end 60 60 return 61 61 end … … 77 77 [Field,vardetect,ichoice]=nc2struct(filename,var);%read the variables in the netcdf file 78 78 if isfield(Field,'Txt') 79 errormsg=['nc2struct :' Field.Txt];79 errormsg=['nc2struct / ' Field.Txt]; 80 80 return 81 81 end … … 97 97 if isfield(Field,'DjUi') 98 98 Field.ListVarName{end-3}='DjUi'; 99 Field.VarDimName{end-3}=[Field.VarDimName{end-3} {'nb_coord'} {'nb -coord'}];99 Field.VarDimName{end-3}=[Field.VarDimName{end-3} {'nb_coord'} {'nb_coord'}]; 100 100 Field.ListVarName(end-2:end)=[]; 101 101 Field.VarDimName(end-2:end)=[]; … … 186 186 %INPUT: 187 187 % FieldNames =cell of field names to get, which can contain the strings: 188 % ' ima_cor': image correlation, vec_c or vec2_C189 % ' vort','div','strain': requires velocity derivatives DUDX...188 % 'C': image correlation, vec_c or vec2_C 189 % 'curl','div','strain': requires velocity derivatives DUDX... 190 190 % 'error': error estimate (vec_E or vec2_E) 191 191 % … … 199 199 if ~exist('vel_type','var'),vel_type=[];end; 200 200 if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed 201 if ~exist('FieldNames','var'),FieldNames={' ima_cor'};end;%default scalar201 if ~exist('FieldNames','var'),FieldNames={'C'};end;%default scalar 202 202 if ischar(FieldNames), FieldNames={FieldNames}; end; 203 203 … … 205 205 testder=0; 206 206 for ilist=1:length(FieldNames) 207 if ~isempty(FieldNames{ilist}) 208 switch FieldNames{ilist} 209 case {'vort','div','strain'} 210 testder=1; 211 end 212 end 207 testder=~isempty(regexp(FieldNames{ilist},'(^curl|^div|strain)', 'once'));%test need for derivatives 208 if testder, break;end 213 209 end 214 210 if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...) … … 261 257 if ~isempty(FieldNames{ilist}) 262 258 switch FieldNames{ilist} 263 case ' ima_cor' %image correlation corresponding to a vel vector259 case 'C' %image correlation corresponding to a vel vector 264 260 C1='vec_C'; 265 261 C2='vec2_C'; … … 267 263 C1='vec_E'; 268 264 C2='vec2_E'; 269 case {'vort','div','strain'}270 testder=1;265 otherwise 266 testder=~isempty(regexp(FieldNames{ilist},'(^curl|^div|strain)', 'once'));%test need for derivatives 271 267 end 272 268 end -
trunk/src/read_field.m
r526 r527 35 35 ParamOut=ParamIn;%default 36 36 errormsg=''; 37 % if isfield(ParamIn,'VelType')38 % VelType=ParamIn.VelType;39 % end40 37 A=[]; 41 38 if isstruct(ParamIn) … … 52 49 end 53 50 %% distingush different input file types 54 try 55 switch FileType 56 case 'civdata' 57 [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType); 58 if ~isempty(errormsg),errormsg=['read_civdata:' errormsg];return,end 59 ParamOut.CivStage=Field.CivStage; 60 case 'civx' 61 ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default 62 [Field,ParamOut.VelType]=read_civxdata(FileName,InputField,ParamIn.VelType); 63 if ~isempty(errormsg),errormsg=['read_civxdata:' errormsg];return,end 64 ParamOut.CivStage=Field.CivStage; 65 case 'netcdf' 66 ListVar={}; 67 for ilist=1:numel(InputField) 68 r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names'); 69 if isempty(r) 70 ListVar=[ListVar InputField(ilist)]; 71 Role{numel(ListVar)}='scalar'; 72 % FieldRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot) 73 else 74 ListVar=[ListVar {r.UName,r.VName}]; 75 Role{numel(ListVar)}='vector_y'; 76 Role{numel(ListVar)-1}='vector_x'; 77 % TODO; introduce that for unstructured coordinates 78 % switch r.Operator TODO; introduce that for unstructured coordinates 79 % case 'norm' 80 % FieldRequest{numel(ListVar)-1}='interp_lin';%scalar field (requires interpolation for plot) 81 % FieldRequest{numel(ListVar)}='interp_lin'; 82 % otherwise 83 % FieldRequest{numel(ListVar)-1}=''; 84 % end 85 end 51 switch FileType 52 case 'civdata' 53 [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType); 54 if ~isempty(errormsg),errormsg=['read_civdata / ' errormsg];return,end 55 ParamOut.CivStage=Field.CivStage; 56 case 'civx' 57 ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default 58 [Field,ParamOut.VelType,errormsg]=read_civxdata(FileName,InputField,ParamIn.VelType); 59 if ~isempty(errormsg),errormsg=['read_civxdata / ' errormsg];return,end 60 ParamOut.CivStage=Field.CivStage; 61 case 'netcdf' 62 ListVar={}; 63 for ilist=1:numel(InputField) 64 r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names'); 65 if isempty(r) 66 ListVar=[ListVar InputField(ilist)]; 67 Role{numel(ListVar)}='scalar'; 68 % FieldRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot) 69 else 70 ListVar=[ListVar {r.UName,r.VName}]; 71 Role{numel(ListVar)}='vector_y'; 72 Role{numel(ListVar)-1}='vector_x'; 73 % TODO; introduce that for unstructured coordinates 74 % switch r.Operator TODO; introduce that for unstructured coordinates 75 % case 'norm' 76 % FieldRequest{numel(ListVar)-1}='interp_lin';%scalar field (requires interpolation for plot) 77 % FieldRequest{numel(ListVar)}='interp_lin'; 78 % otherwise 79 % FieldRequest{numel(ListVar)-1}=''; 80 % end 86 81 end 87 if check_colorvar 88 Role{numel(ListVar)}='ancillary';% scalar used for color vector (not projected) 89 end 90 [Field,var_detect,ichoice]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ListVar]); 91 for ivar=1:numel(ListVar) 92 Field.VarAttribute{ivar+2}.Role=Role{ivar}; 93 % Field.VarAttribute{ivar+2}.FieldRequest=FieldRequest{ivar}; 94 end 95 96 case 'video' 97 if strcmp(class(ParamIn),'VideoReader') 98 A=read(ParamIn,num); 99 else 100 ParamOut=VideoReader(FileName); 101 A=read(ParamOut,num); 102 end 103 case 'mmreader' 104 if strcmp(class(ParamIn),'mmreader') 105 A=read(ParamIn,num); 106 else 107 ParamOut=mmreader(FileName); 108 A=read(ParamOut,num); 109 end 110 case 'vol' 111 A=imread(FileName); 112 Npz=size(A,1)/ParamIn.Npy; 113 A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz); 114 A=permute(A,[3 2 1]); 115 case 'multimage' 116 warning 'off' 117 A=imread(FileName,num); 118 case 'image' 119 A=imread(FileName); 120 end 121 catch ME 122 errormsg=[FileType ' input: ' ME.message]; 82 end 83 if check_colorvar 84 Role{numel(ListVar)}='ancillary';% scalar used for color vector (not projected) 85 end 86 [Field,var_detect,ichoice]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ListVar]); 87 for ivar=1:numel(ListVar) 88 Field.VarAttribute{ivar+2}.Role=Role{ivar}; 89 % Field.VarAttribute{ivar+2}.FieldRequest=FieldRequest{ivar}; 90 end 91 92 case 'video' 93 if strcmp(class(ParamIn),'VideoReader') 94 A=read(ParamIn,num); 95 else 96 ParamOut=VideoReader(FileName); 97 A=read(ParamOut,num); 98 end 99 case 'mmreader' 100 if strcmp(class(ParamIn),'mmreader') 101 A=read(ParamIn,num); 102 else 103 ParamOut=mmreader(FileName); 104 A=read(ParamOut,num); 105 end 106 case 'vol' 107 A=imread(FileName); 108 Npz=size(A,1)/ParamIn.Npy; 109 A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz); 110 A=permute(A,[3 2 1]); 111 case 'multimage' 112 warning 'off' 113 A=imread(FileName,num); 114 case 'image' 115 A=imread(FileName); 116 end 117 if ~isempty(errormsg) 118 errormsg=[FileType ' input: ' errormsg]; 123 119 return 124 120 end -
trunk/src/uvmat.m
r526 r527 2063 2063 [Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index); 2064 2064 if ~isempty(errormsg) 2065 errormsg=['uvmat /refresh_field/read_field: ' FileName ':' errormsg];2065 errormsg=['uvmat / refresh_field / read_field( ' FileName ') / ' errormsg]; 2066 2066 return 2067 2067 end … … 2396 2396 [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(UvData.Field);% analyse the input field structure 2397 2397 if ~isempty(errormsg) 2398 errormsg=[' error in uvmat/refresh_field/find_field_cells:' errormsg];% display error2398 errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg];% display error 2399 2399 return 2400 2400 end … … 2404 2404 end 2405 2405 2406 %% get bounds and mesh (needed for mouse action and to open set_object)2406 %% get bounds and mesh (needed to propose default options for projection objects) 2407 2407 if NbDim>1 2408 2408 XName=''; %default … … 2412 2412 XName=UvData.Field.ListVarName{VarType{imax}.coord_x}; 2413 2413 YName=UvData.Field.ListVarName{VarType{imax}.coord_y}; 2414 %nbvec=length(UvData.Field.(XName));%nbre of measurement points (e.g. vectors)2415 2414 test_x=1;%test for unstructured coordinates 2416 2415 if ~isempty(VarType{imax}.coord_z) … … 2425 2424 YName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim-1)}; %structured coordinates 2426 2425 end 2427 % VarIndex=CellVarIndex{imax}; % list of variable indices2428 2426 DimIndex=VarDimIndex{CellVarIndex{imax}(1)}; %list of dim indices for the variable 2429 2427 nbpoints_x=DimValue(DimIndex(NbDim));
Note: See TracChangeset
for help on using the changeset viewer.