Changeset 1162 for trunk/src/read_field.m
- Timestamp:
- Jul 20, 2024, 9:33:32 AM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/read_field.m
r1137 r1162 1 1 %'read_field': read the fields from files in different formats (netcdf files, images, video) 2 2 %-------------------------------------------------------------------------- 3 % function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn, num)3 % function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn,frame_index) 4 4 % 5 5 % OUTPUT: … … 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'23 % num: frame number for movies22 % .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'frame_index' 23 % frame_index: frame number for movies or multidimensional netcdf files with dim >2 24 24 % 25 25 % see also read_image.m,read_civxdata.m,read_civdata.m, … … 43 43 %======================================================================= 44 44 45 function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn, num)45 function [Field,ParamOut,errormsg] = read_field(FileName,FileType,ParamIn,frame_index) 46 46 %% default output and check input 47 47 Field=[]; 48 if ~exist(' num','var')49 num=1;50 end 51 if isempty( num)52 num=1;48 if ~exist('frame_index','var') 49 frame_index=1; 50 end 51 if isempty(frame_index) 52 frame_index=1; 53 53 end 54 54 if ~exist('ParamIn','var') … … 57 57 ParamOut=ParamIn;%default 58 58 errormsg=''; 59 if isempty(regexp(FileName,'^http://' ))&& ~exist(FileName,'file')59 if isempty(regexp(FileName,'^http://', 'once'))&& ~exist(FileName,'file') 60 60 errormsg=['input file ' FileName ' does not exist']; 61 61 return … … 81 81 %% distingush different input file types 82 82 switch FileType 83 case 'civdata'% new format for civ results84 [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType );83 case {'civdata','civdata_3D'}% new format for civ results 84 [Field,ParamOut.VelType,errormsg]=read_civdata(FileName,InputField,ParamIn.VelType,frame_index); 85 85 if ~isempty(errormsg),errormsg=['read_civdata / ' errormsg];return,end 86 86 ParamOut.CivStage=Field.CivStage; … … 102 102 % scan the list InputField 103 103 Operator=cell(1,numel(InputField)); 104 InputVar=cell(1,numel(InputField));104 %InputVar=cell(1,numel(InputField)); 105 105 for ilist=1:numel(InputField) 106 106 % look for input variables to read … … 145 145 NbCoord=~isempty(ParamIn.Coord_x)+~isempty(ParamIn.Coord_y)+~isempty(ParamIn.Coord_z); 146 146 if isfield(ParamIn,'TimeDimName')% case of reading of a single time index in a multidimensional array 147 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName, num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]);147 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,frame_index,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]); 148 148 elseif isfield(ParamIn,'TimeVarName')% case of reading of a single time in a multidimensional array 149 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName, num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]);150 if numel( num)~=1149 [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,frame_index,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]); 150 if numel(frame_index)~=1 151 151 NbCoord=NbCoord+1;% adds time coordinate, except if a single time has been selected 152 152 end … … 157 157 return 158 158 end 159 CheckStructured=1;159 % CheckStructured=1; 160 160 %scan all the variables 161 161 NbCoord=0; 162 162 if ~isempty(ParamIn.Coord_x) 163 index_Coord_x= find(strcmp(ParamIn.Coord_x,Field.ListVarName));163 index_Coord_x=strcmp(ParamIn.Coord_x,Field.ListVarName); 164 164 Field.VarAttribute{index_Coord_x}.Role='coord_x';% 165 165 NbCoord=NbCoord+1; … … 167 167 if ~isempty(ParamIn.Coord_y) 168 168 if ischar(ParamIn.Coord_y) 169 index_Coord_y= find(strcmp(ParamIn.Coord_y,Field.ListVarName));169 index_Coord_y=strcmp(ParamIn.Coord_y,Field.ListVarName); 170 170 Field.VarAttribute{index_Coord_y}.Role='coord_y';% 171 171 NbCoord=NbCoord+1; 172 172 else 173 173 for icoord_y=1:numel(ParamIn.Coord_y) 174 index_Coord_y= find(strcmp(ParamIn.Coord_y{icoord_y},Field.ListVarName));174 index_Coord_y=strcmp(ParamIn.Coord_y{icoord_y},Field.ListVarName); 175 175 Field.VarAttribute{index_Coord_y}.Role='coord_y';% 176 176 NbCoord=NbCoord+1; … … 180 180 NbDim=1; 181 181 if ~isempty(ParamIn.Coord_z) 182 index_Coord_z= find(strcmp(ParamIn.Coord_z,Field.ListVarName));182 index_Coord_z=strcmp(ParamIn.Coord_z,Field.ListVarName); 183 183 Field.VarAttribute{index_Coord_z}.Role='coord_z';% 184 184 NbCoord=NbCoord+1; … … 187 187 NbDim=2; 188 188 end 189 NormName='';190 UName='';191 VName='';192 189 if numel(Field.ListVarName)>NbCoord % if there are variables beyond coord (exclude 1 D plots) 193 190 VarAttribute=cell(1,numel(ListVarName)); … … 236 233 end 237 234 case 'video' 238 if strcmp(class(ParamIn),'VideoReader')239 A=read(ParamIn, num);235 if isa(ParamIn,'VideoReader') 236 A=read(ParamIn,frame_index); 240 237 else 241 238 ParamOut=VideoReader(FileName); 242 A=read(ParamOut, num);239 A=read(ParamOut,frame_index); 243 240 end 244 241 case 'mmreader' 245 if strcmp(class(ParamIn),'mmreader')246 A=read(ParamIn, num);242 if isa(ParamIn,'mmreader') 243 A=read(ParamIn,frame_index); 247 244 else 248 245 ParamOut=mmreader(FileName); 249 A=read(ParamOut, num);246 A=read(ParamOut,frame_index); 250 247 end 251 248 case 'vol' … … 255 252 A=permute(A,[3 2 1]); 256 253 case 'multimage' 257 % warning 'off' 258 A=imread(FileName,num); 254 A=imread(FileName,frame_index); 259 255 case 'image' 260 256 A=imread(FileName); 261 257 case 'rdvision' 262 [A,FileInfo,timestamps,errormsg]=read_rdvision(FileName, num);258 [A,FileInfo,timestamps,errormsg]=read_rdvision(FileName,frame_index); 263 259 case 'image_DaVis' 264 260 Input=readimx(FileName); 265 261 if numel(Input.Frames)==1 266 num=1;267 end 268 A=Input.Frames{ num}.Components{1}.Planes{1}';262 frame_index=1; 263 end 264 A=Input.Frames{frame_index}.Components{1}.Planes{1}'; 269 265 for ilist=1:numel(Input.Frames{1}.Attributes) 270 266 if strcmp(Input.Frames{1}.Attributes{ilist}.Name,'AcqTimeSeries') … … 274 270 end 275 271 case 'cine_phantom' 276 [A,FileInfo] = read_cine_phantom(FileName, num);272 [A,FileInfo] = read_cine_phantom(FileName,frame_index ); 277 273 otherwise 278 274 errormsg=[ FileType ': invalid input file type for uvmat']; … … 299 295 Field.VarAttribute{3}.Role='scalar'; 300 296 if ndims(A)==3 301 if Npz==1 ;%color297 if Npz==1%color 302 298 Field.VarDimName={'Coord_y','Coord_x',{'Coord_y','Coord_x','rgb'}}; % 303 299 Field.Coord_y=[npxy(1)-0.5 0.5];
Note: See TracChangeset
for help on using the changeset viewer.