Changeset 1045 for trunk/src/read_field.m
 Timestamp:
 May 21, 2018, 7:06:45 PM (6 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/read_field.m
r1041 r1045 8 8 % .FieldName; field name 9 9 % .VelType 10 % .CivStage: stage of civx processing (=0, not Civx, =1 (civ1), =2 (fix1).... 10 % .CivStage: stage of civx processing (=0, not Civx, =1 (civ1), =2 (fix1).... 11 11 % .Npx,.Npy: for images, nbre of pixels in x and y 12 12 % errormsg: error message, ='' by default … … 20 20 % .ColorVar: variable used for vector color 21 21 % .Npx, .Npy: nbre of pixels along x and y (used for .vol input files) 22 % .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'num' 22 % .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'num' 23 23 % num: frame number for movies 24 24 % … … 94 94 ParamOut.CivStage=Field.CivStage; 95 95 case 'netcdf'% general netcdf file (not recognized as civ) 96 ListVar ={};96 ListVarName={}; 97 97 Role={}; 98 98 ProjModeRequest={}; 99 ListInputField={}; 100 ListOperator={}; 101 checkU=0; 102 checkV=0; 99 %ListInputField={}; 100 %checkU=0; 101 %checkV=0; 103 102 % scan the list InputField 103 Operator=cell(1,numel(InputField)); 104 InputVar=cell(1,numel(InputField)); 104 105 for ilist=1:numel(InputField) 105 106 % look for input variables to read 106 107 r=regexp(InputField{ilist},'(?<Operator>(^vec^norm))\((?<UName>.+),(?<VName>.+)\)$','names'); 107 108 if isempty(r)% no operator used 108 if isempty(find(strcmp(InputField{ilist},ListVar),1)) 109 ListVar=[ListVar InputField(ilist)];%append the variable name if not already in the list 110 ListInputField=[ListInputField InputField(ilist)]; 111 ListOperator=[ListOperator {''}]; 112 end 113 if check_colorvar(ilist) 114 if isempty(find(strcmp(InputField{ilist},ListVar),1)) 115 Role{numel(ListVar)}='ancillary';% not projected with interpolation 116 ProjModeRequest{numel(ListVar)}=''; 109 ListVarName=[ListVarName InputField(ilist)];%append the variable name 110 %InputVar{ilist}=InputField(ilist); 111 %ListInputField=[ListInputField InputField(ilist)]; 112 if check_colorvar(ilist)% case of field used for vector color 113 Role{numel(ListVarName)}='ancillary';% not projected with interpolation 114 ProjModeRequest{numel(ListVarName)}=''; 115 else 116 Role{numel(ListVarName)}='scalar'; 117 ProjModeRequest{numel(ListVarName)}='interp_lin';%scalar field (requires interpolation for plot) 118 end 119 Operator{numel(ListVarName)}=''; 120 else % an operator 'vec' or 'norm' is used 121 ListVarName=[ListVarName {r.UName}]; % append the variable in the list if not previously listed 122 if strcmp(r.Operator,'norm') 123 if check_colorvar(ilist) 124 Role=[Role {'ancillary'}]; 125 else 126 Role=[Role {'scalar'}]; 117 127 end 118 128 else 119 Role{numel(ListVar)}='scalar'; 120 ProjModeRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot) 121 end 122 if isfield(ParamIn,'Coord_y') 123 if ~isempty(strcmp(InputField{ilist},ParamIn.Coord_y)) 124 Role{numel(ListVar)}='coord_y'; 125 end 126 end 127 else % an operator 'vec' or 'norm' is used 129 Role=[Role {'vector_x'}]; 130 end 131 %ListInputField=[ListInputField InputField(ilist)]; 132 ListVarName=[ListVarName {r.VName}];% append the variable in the list if not previously listed 133 Role=[Role {'vector_y'}]; 134 %ListInputField=[ListInputField InputField(ilist)]; 135 Operator{numel(ListVarName)1}=r.Operator; 136 Operator{numel(ListVarName)}=''; 128 137 if ~check_colorvar(ilist) && strcmp(r.Operator,'norm') 129 ProjModeRequestVar='interp_lin';%scalar field (requires interpolation for plot) 138 ProjModeRequest{numel(ListVarName)}='interp_lin';%scalar field (requires interpolation for plot) 139 ProjModeRequest{numel(ListVarName)1}='interp_lin';%scalar field (requires interpolation for plot) 130 140 else 131 ProjModeRequestVar=''; 132 end 133 ind_var_U=find(strcmp(r.UName,ListVar));%check previous listing of variable r.UName 134 ind_var_V=find(strcmp(r.VName,ListVar));%check previous listing of variable r.VName 135 if isempty(ind_var_U) 136 ListVar=[ListVar {r.UName}]; % append the variable in the list if not previously listed 137 Role=[Role {'vector_x'}]; 138 ProjModeRequest=[ProjModeRequest {ProjModeRequestVar}]; 139 ListInputField=[ListInputField InputField(ilist)]; 140 else 141 checkU=1; 142 end 143 if isempty(ind_var_V) 144 ListVar=[ListVar {r.VName}];% append the variable in the list if not previously listed 145 Role=[Role {'vector_y'}]; 146 ProjModeRequest=[ProjModeRequest {ProjModeRequestVar}]; 147 ListInputField=[ListInputField InputField(ilist)]; 148 else 149 checkV=1; 141 ProjModeRequest{numel(ListVarName)}=''; 142 ProjModeRequest{numel(ListVarName)1}=''; 150 143 end 151 144 end … … 156 149 NbCoord=~isempty(ParamIn.Coord_x)+~isempty(ParamIn.Coord_y)+~isempty(ParamIn.Coord_z); 157 150 if isfield(ParamIn,'TimeDimName')% case of reading of a single time index in a multidimensional array 158 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar ]);151 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]); 159 152 elseif isfield(ParamIn,'TimeVarName')% case of reading of a single time in a multidimensional array 160 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar ]);153 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]); 161 154 if numel(num)~=1 162 155 NbCoord=NbCoord+1;% adds time coordinate, except if a single time has been selected 163 156 end 164 157 else 165 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar ]);158 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]); 166 159 end 167 160 if ~isempty(errormsg) … … 169 162 end 170 163 CheckStructured=1; 171 %scan all the variables beyond the two first NbCoord ones describing the coordinates. 172 for ilist=NbCoord+1:numel(Field.VarDimName) 173 if isequal(Field.VarDimName{1},Field.VarDimName{ilist}) % if a variable has the same dimension as the coordinate, it denotes a field with unstructured coordinates 174 Field.VarAttribute{1}.Role='coord_x';%unstructured coordinates 175 Field.VarAttribute{2}.Role='coord_y'; 176 if NbCoord>=3 177 Field.VarAttribute{3}.Role='coord_z'; 178 end 179 CheckUnstructured=0; 180 break 181 end 182 end 183 if CheckStructured 184 for ilist=NbCoord+1:numel(Field.VarDimName) 185 if numel(Field.VarDimName{ilist})==NbCoord 186 rank(1)=find(strcmp(ParamIn.Coord_x,Field.VarDimName{ilist})); 187 rank(2)=find(strcmp(ParamIn.Coord_y,Field.VarDimName{ilist})); 188 if NbCoord==3 189 rank(3)=find(strcmp(ParamIn.Coord_z,Field.VarDimName{ilist})); 190 end 191 rank=rank(end:1:1); 192 VarName=Field.ListVarName{ilist}; 193 Field.(VarName)=permute(Field.(VarName),rank); 194 Field.VarDimName{ilist}=Field.VarDimName{ilist}(rank);% permute the order of dimensions 195 end 196 end 164 %scan all the variables 165 NbCoord=0; 166 if ~isempty(ParamIn.Coord_x) 167 index_Coord_x=find(strcmp(ParamIn.Coord_x,Field.ListVarName)); 168 Field.VarAttribute{index_Coord_x}.Role='coord_x';% 169 NbCoord=NbCoord+1; 170 end 171 if ~isempty(ParamIn.Coord_y) 172 if ischar(ParamIn.Coord_y) 173 index_Coord_y=find(strcmp(ParamIn.Coord_y,Field.ListVarName)); 174 Field.VarAttribute{index_Coord_y}.Role='coord_y';% 175 NbCoord=NbCoord+1; 176 else 177 for icoord_y=1:numel(ParamIn.Coord_y) 178 index_Coord_y=find(strcmp(ParamIn.Coord_y{icoord_y},Field.ListVarName)); 179 Field.VarAttribute{index_Coord_y}.Role='coord_y';% 180 NbCoord=NbCoord+1; 181 end 182 end 183 end 184 NbDim=1; 185 if ~isempty(ParamIn.Coord_z) 186 index_Coord_z=find(strcmp(ParamIn.Coord_z,Field.ListVarName)); 187 Field.VarAttribute{index_Coord_z}.Role='coord_z';% 188 NbCoord=NbCoord+1; 189 NbDim=3; 190 elseif ~isempty(ParamIn.FieldName) 191 NbDim=2; 197 192 end 198 193 NormName=''; 199 194 UName=''; 200 195 VName=''; 201 if numel(Field.ListVarName)>NbCoord % if there are variables beyond coord (1 D plots) 202 for ilist=1:numel(ListVar) 203 Field.VarAttribute{ilist+NbCoord}.Role=Role{ilist}; 204 Field.VarAttribute{ilist+NbCoord}.ProjModeRequest=ProjModeRequest{ilist}; 196 if numel(Field.ListVarName)>NbCoord % if there are variables beyond coord (exclude 1 D plots) 197 VarAttribute=cell(1,numel(ListVarName)); 198 for ilist=1:numel(ListVarName) 199 index_var=find(strcmp(ListVarName{ilist},Field.ListVarName),1); 200 VarDimName{ilist}=Field.VarDimName{index_var}; 201 DimOrder=[]; 202 if NbDim ==2 203 DimOrder=[find(strcmp(ParamIn.Coord_y,VarDimName{ilist})) find(strcmp(ParamIn.Coord_x,VarDimName{ilist}))]; 204 elseif NbDim ==3 205 DimOrder=[find(strcmp(ParamIn.Coord_z,VarDimName{ilist}))... 206 find(strcmp(ParamIn.Coord_y,VarDimName{ilist}))... 207 find(strcmp(ParamIn.Coord_x,VarDimName{ilist}))]; 208 end 209 if ~isempty(DimOrder) 210 Field.(ListVarName{ilist})=permute(Field.(ListVarName{ilist}),DimOrder); 211 VarDimName{ilist}=VarDimName{ilist}(DimOrder); 212 end 213 if numel(Field.VarAttribute)>=index_var 214 VarAttribute{ilist}=Field.VarAttribute{index_var};% read var attributes from input if exist 215 end 216 end 217 check_remove=false(1,numel(Field.ListVarName)); 218 for ilist=1:numel(ListVarName) 219 VarAttribute{ilist}.Role=Role{ilist}; 220 VarAttribute{ilist}.ProjModeRequest=ProjModeRequest{ilist}; 205 221 if isfield(ParamIn,'FieldName') 206 Field.VarAttribute{ilist+NbCoord}.FieldName=ListInputField{ilist}; 207 end 208 r=regexp(ListInputField{ilist},'(?<Operator>(^vec^norm))\((?<UName>.+),(?<VName>.+)\)$','names'); 209 if ~isempty(r)&& strcmp(r.Operator,'norm') 210 NormName='norm'; 211 if ~isempty(find(strcmp(ListVar,'norm'))) 212 NormName='norm_1'; 213 end 214 Field.ListVarName=[Field.ListVarName {NormName}]; 215 ilistmax=numel(Field.ListVarName); 216 Field.VarDimName{ilistmax}=Field.VarDimName{ilist+2}; 217 Field.VarAttribute{ilistmax}.Role='scalar'; 218 Field.(NormName)=Field.(r.UName).*Field.(r.UName)+Field.(r.VName).*Field.(r.VName); 219 Field.(NormName)=sqrt(Field.(NormName)); 220 UName=r.UName; 221 VName=r.VName; 222 end 223 end 224 225 if ~isempty(NormName)% remove U and V if norm has been calculated and U and V are not needed as variables 226 ind_var_U=find(strcmp(UName,ListVar));%check previous listing of variable r.UName 227 ind_var_V=find(strcmp(VName,ListVar));%check previous listing of variable r.VName 228 if ~checkU && ~checkV 229 Field.ListVarName([ind_var_U+2 ind_var_V+2])=[]; 230 Field.VarDimName([ind_var_U+2 ind_var_V+2])=[]; 231 Field.VarAttribute([ind_var_U+2 ind_var_V+2])=[]; 232 elseif ~checkU 233 Field.ListVarName(ind_var_U+2)=[]; 234 Field.VarDimName(ind_var_U+2)=[]; 235 Field.VarAttribute(ind_var_U+2 )=[]; 236 elseif ~checkV 237 Field.ListVarName(ind_var_V+2)=[]; 238 Field.VarDimName(ind_var_V+2)=[]; 239 Field.VarAttribute(ind_var_V+2 )=[]; 240 end 241 end 242 % insert coordinates as indices in case of plots vs matrix index 243 if isfield(ParamIn,'CheckCoordIndex') && ParamIn.CheckCoordIndex 244 Field.ListVarName=[Field.ListDimName Field.ListVarName]; 245 Field.VarDimName=[Field.ListDimName Field.VarDimName]; 246 for idim=1:numel(Field.ListDimName) 247 CoordName=Field.ListDimName{idim}; 248 Field.(CoordName)=1:Field.DimValue(idim); 249 end 250 Field.VarAttribute=[cell(1,numel(Field.ListDimName)) Field.VarAttribute]; 251 end 252 253 end 222 VarAttribute{ilist}.Operator=Operator{ilist}; 223 end 224 if strcmp(Operator{ilist},'norm') 225 UName=ListVarName{ilist}; 226 VName=ListVarName{ilist+1}; 227 ListVarName{ilist}='norm'; 228 Field.norm=Field.(UName).*Field.(UName)+Field.(VName).*Field.(VName); 229 Field.norm=sqrt(Field.norm); 230 check_remove(ilist+1)=true; 231 VarAttribute{ilist}.Operator=''; 232 end 233 end 234 ListVarName(check_remove)=[]; 235 VarDimName(check_remove)=[]; 236 VarAttribute(check_remove)=[]; 237 Field.ListVarName=[Field.ListVarName(1:NbCoord) ListVarName];% complement the list of vqriables, which may be listed twice 238 Field.VarDimName=[Field.VarDimName(1:NbCoord) VarDimName]; 239 Field.VarAttribute=[Field.VarAttribute(1:NbCoord) VarAttribute]; 240 end 241 254 242 case 'video' 255 243 if strcmp(class(ParamIn),'VideoReader') … … 286 274 for ilist=1:numel(Input.Frames{1}.Attributes) 287 275 if strcmp(Input.Frames{1}.Attributes{ilist}.Name,'AcqTimeSeries') 288 timestamps=str2num(Input.Frames{1}.Attributes{ilist}.Value(1:end3))/1000000;289 break276 timestamps=str2num(Input.Frames{1}.Attributes{ilist}.Value(1:end3))/1000000; 277 break 290 278 end 291 279 end … … 294 282 otherwise 295 283 errormsg=[ FileType ': invalid input file type for uvmat']; 284 296 285 end 297 286 … … 311 300 Field.VarAttribute{1}.Unit='pixel'; 312 301 Field.VarAttribute{2}.Unit='pixel'; 302 Field.VarAttribute{1}.Role='coord_y'; 303 Field.VarAttribute{2}.Role='coord_x'; 313 304 Field.VarAttribute{3}.Role='scalar'; 314 305 if ndims(A)==3
Note: See TracChangeset
for help on using the changeset viewer.