Changeset 474 for trunk/src/series/time_series.m
- Timestamp:
- Jun 25, 2012, 12:14:16 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series/time_series.m
r470 r474 31 31 % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} 32 32 % .OutputSubDir: name of the subdirectory for data outputs 33 % .OutputDir : directory for data outputs, including path33 % .OutputDirExt: directory extension for data outputs 34 34 % .Action: .ActionName: name of the current activated function 35 35 % .ActionPath: path of the current activated function … … 50 50 %% set the input elements needed on the GUI series when the action is selected in the menu ActionName 51 51 if ~exist('Param','var') % case with no input parameter 52 ParamOut={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation) 53 'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default) 52 ParamOut={'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default) 54 53 'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) 55 54 'NbSlice';'on'; ...%nbre of slices ('off' by default) … … 81 80 end 82 81 ParamOut=Param; %default output 82 OutputDir=[Param.OutputSubDir Param.OutputDirExt]; 83 83 84 84 %% root input file(s) and type … … 116 116 for iview=1:nbview 117 117 if ~exist(filecell{iview,1}','file') 118 msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])118 displ_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun) 119 119 return 120 120 end … … 134 134 diff_time=max(max(diff(time))); 135 135 if diff_time>0 136 msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])136 displ_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun) 137 137 end 138 138 end … … 140 140 %% coordinate transform or other user defined transform 141 141 transform_fct='';%default 142 if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle') 143 transform_fct=Param.FieldTransform.TransformHandle; 144 end 142 if isfield(Param,'FieldTransform') 143 addpath(Param.FieldTransform.TransformPath) 144 transform_fct=str2func(Param.FieldTransform.TransformName); 145 rmpath(Param.FieldTransform.TransformPath) 146 end 147 145 148 %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% 146 149 % EDIT FROM HERE … … 152 155 FileExtOut='.nc';% write result as .nc files for netcdf inputs 153 156 else 154 msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])157 displ_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun) 155 158 return 156 159 end 157 160 if nbview==2 && ~isequal(CheckImage{1},CheckImage{2}) 158 msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')161 displ_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun) 159 162 return 160 163 end 161 164 NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series 162 if NbSlice~=nbfield_j163 answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);164 if ~strcmp(answer,'Yes')165 return166 end167 end165 % if NbSlice~=nbfield_j 166 % answer=_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]); 167 % if ~strcmp(answer,'Yes') 168 % return 169 % end 170 % end 168 171 169 172 %% Set field names and velocity types … … 211 214 [DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1); 212 215 if ~isempty(errormsg) 213 msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])216 displ_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg],checkrun) 214 217 return 215 218 end … … 238 241 nbmissing=0; %number of undetected files 239 242 for i_slice=1:NbSlice 240 dt=[]; 241 %%%%%%%%%%%%%%%%%%%%%%%%%%%% LOOP ON FIELDS WITHIN A SLICE 242 filecounter=0; 243 for ifile=i_slice:NbSlice:nbfield 243 index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice 244 nbfiles=0; 245 nbmissing=0; 246 247 %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% 248 for index=index_slice 244 249 if checkrun 245 update_waitbar(hseries.waitbar_frame,WaitbarPos,i file/nbfield)250 update_waitbar(hseries.waitbar_frame,WaitbarPos,index/(nbfield)) 246 251 stopstate=get(hseries.RUN,'BusyAction'); 247 252 else 248 253 stopstate='queue'; 249 254 end 250 errormsg=''; 255 256 %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%% 257 Data=cell(1,nbview);%initiate the set Data 258 nbtime=0; 259 dt=[]; 251 260 if isequal(stopstate,'queue')% enable STOP command 252 261 % loop on views (in case of multiple input series) 253 262 for iview=1:nbview 254 filename=filecell{iview,ifile}; 255 % filename=name_generator(filebase{iview},... 256 % i1_series{iview}(ifile),j1_series{iview}(ifile),FileExt{iview},NomType{iview},1,i2_series{iview}(ifile),j2_series{iview}(ifile),SubDir{iview}); 257 if exist(filename,'file') 258 try 259 Data{iview}=[]; %default 260 if ~isequal(FileType{iview},'netcdf') 261 Data{iview}.ListVarName={'A'}; 262 Data{iview}.AName='image'; 263 switch FileType{iview} 264 case 'movie' 265 A=read(MovieObject{iview},i1_series{iview}(ifile)); 266 case 'avi' 267 mov=aviread(filename,i1_series{iview}(ifile)); 268 A=frame2im(mov(1)); 269 case 'vol' 270 A=imread(filename); 271 case 'multimage' 272 A=imread(filename,i1_series{iview}(ifile)); 273 case 'image' 274 A=imread(filename); 275 end 276 Data{iview}.ListVarName={'AY','AX','A'}; % 277 npy=size(A,1); 278 npx=size(A,2); 279 nbcolor=size(A,3); 280 if nbcolor==3 281 Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; 282 else 283 Data{iview}.VarDimName={'AY','AX',{'AY','AX'}}; 284 end 285 Data{iview}.AY=[npy-0.5 0.5]; 286 Data{iview}.AX=[0.5 npx-0.5]; 287 Data{iview}.A=double(A); 288 Data{iview}.CoordUnit='pixel'; 289 elseif testcivx 290 [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType); 291 if ~isequal(FieldName,{''}) 292 Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..) 293 end 294 else 295 [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data 296 Data{iview}.VarAttribute=SubField.VarAttribute; 297 end 298 if ~isempty(NbSlice_calib) % z index 299 Data{iview}.ZIndex=mod(i1_series{iview}(ifile)-1,NbSlice_calib{1})+1; 300 end 301 catch ME 302 errormsg=ME.message; 263 % reading input file(s) 264 [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index)); 265 if ~isempty(errormsg) 266 errormsg=['time_series/read_field/' errormsg]; 267 display(errormsg) 268 break 269 end 270 timeread(iview)=0; 271 if isfield(Data{iview},'Time') 272 timeread(iview)=Data{iview}.Time; 273 nbtime=nbtime+1; 274 end 275 if ~isempty(NbSlice_calib) 276 Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform 277 end 278 end 279 % coordinate transform (or other user defined transform) 280 if ~isempty(transform_fct) 281 if nbview==2 282 [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); 283 if isempty(Data{2}) 284 Data(2)=[]; 303 285 end 304 286 else 305 errormsg=[filename ' is missing']; 306 end 307 if isempty(errormsg) 308 % coordinate transform (or other user defined transform) 309 if ~isempty(transform_fct) 310 if nbview==2 311 [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); 312 if isempty(Data{2}) 313 Data(2)=[]; 287 Data{1}=transform_fct(Data{1},XmlData{1}); 288 end 289 end 290 if length(Data)==2 291 [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields 292 else 293 Field=Data{1}; 294 end 295 if Param.CheckObject 296 [Field,errormsg]=proj_field(Field,Param.ProjObject); 297 end 298 nbtime=nbtime+1; 299 300 % initiate the time series at the first iteration 301 if nbtime==1 302 % stop program if the first field reading is in error 303 if ~isempty(errormsg) 304 displ_uvmat('ERROR',['error in time_series/sub_field:' errormsg],checkrun) 305 return 306 end 307 DataOut=Field;%default 308 DataOut.NbDim=Field.NbDim+1; %add the time dimension for plots 309 nbvar=length(Field.ListVarName); 310 if nbvar==0 311 displ_uvmat('ERROR','no input variable selected in get_field',checkrun) 312 return 313 end 314 testsum=2*ones(1,nbvar);%initiate flag for action on each variable 315 if isfield(Field,'VarAttribute') % look for coordinate and flag variables 316 for ivar=1:nbvar 317 if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') 318 var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable 319 if isequal(var_role,'errorflag') 320 displ_uvmat('ERROR','do not handle error flags in time series',checkrun) 321 return 314 322 end 315 else 316 Data{1}=transform_fct(Data{1},XmlData{1}); 323 if isequal(var_role,'warnflag') 324 testsum(ivar)=0; % not recorded variable 325 eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable 326 end 327 if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|... 328 isequal(var_role,'coord_z')|isequal(var_role,'coord') 329 testsum(ivar)=1; %constant coordinates, record without time evolution 330 end 331 end 332 % check whether the variable ivar is a dimension variable 333 DimCell=Field.VarDimName{ivar}; 334 if ischar(DimCell) 335 DimCell={DimCell}; 336 end 337 if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables 338 testsum(ivar)=1; 317 339 end 318 340 end 319 if length(Data)==2 320 [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields 341 end 342 for ivar=1:nbvar 343 if testsum(ivar)==2 344 eval(['DataOut.' Field.ListVarName{ivar} '=[];']) 345 end 346 end 347 DataOut.ListVarName=[{'Time'} DataOut.ListVarName]; 348 end 349 350 % add data to the current field 351 for ivar=1:length(Field.ListVarName) 352 VarName=Field.ListVarName{ivar}; 353 VarVal=Field.(VarName); 354 if testsum(ivar)==2% test for recorded variable 355 if isempty(errormsg) 356 if isequal(Param.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode 357 if isempty(VarVal) 358 displ_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(ifile))],checkrun) 359 return 360 end 361 VarVal=mean(VarVal,1); 362 end 363 VarVal=shiftdim(VarVal,-1); %shift dimension 364 DataOut.(VarName)=cat(1,DataOut.(VarName),VarVal);%concanete the current field to the time series 321 365 else 322 Field=Data{1};366 DataOut.(VarName)=cat(1,DataOut.(VarName),0);% put each variable to 0 in case of input reading error 323 367 end 324 if Param.CheckObject 325 [Field,errormsg]=proj_field(Field,Param.ProjObject); 326 end 327 end 328 filecounter=filecounter+1; 329 330 % initiate the time series at the first iteration 331 if filecounter==1 332 % stop program if the first field reading is in error 333 if ~isempty(errormsg) 334 msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg]) 368 elseif testsum(ivar)==1% variable representing fixed coordinates 369 eval(['VarInit=DataOut.' VarName ';']); 370 if isempty(errormsg) && ~isequal(VarVal,VarInit) 371 displ_uvmat('ERROR',['time series requires constant coordinates ' VarName],checkrun) 335 372 return 336 373 end 337 DataOut=Field;%default 338 DataOut.NbDim=Field.NbDim+1; %add the time dimension for plots 339 nbvar=length(Field.ListVarName); 340 if nbvar==0 341 msgbox_uvmat('ERROR','no input variable selected in get_field') 342 return 343 end 344 testsum=2*ones(1,nbvar);%initiate flag for action on each variable 345 if isfield(Field,'VarAttribute') % look for coordinate and flag variables 346 for ivar=1:nbvar 347 if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') 348 var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable 349 if isequal(var_role,'errorflag') 350 msgbox_uvmat('ERROR','do not handle error flags in time series') 351 return 352 end 353 if isequal(var_role,'warnflag') 354 testsum(ivar)=0; % not recorded variable 355 eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable 356 end 357 if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|... 358 isequal(var_role,'coord_z')|isequal(var_role,'coord') 359 testsum(ivar)=1; %constant coordinates, record without time evolution 360 end 361 end 362 % check whether the variable ivar is a dimension variable 363 DimCell=Field.VarDimName{ivar}; 364 if ischar(DimCell) 365 DimCell={DimCell}; 366 end 367 if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables 368 testsum(ivar)=1; 369 end 370 end 371 end 372 for ivar=1:nbvar 373 if testsum(ivar)==2 374 eval(['DataOut.' Field.ListVarName{ivar} '=[];']) 375 end 376 end 377 DataOut.ListVarName=[{'Time'} DataOut.ListVarName]; 378 end 379 380 % add data to the current field 381 for ivar=1:length(Field.ListVarName) 382 VarName=Field.ListVarName{ivar}; 383 VarVal=Field.(VarName); 384 if testsum(ivar)==2% test for recorded variable 385 if isempty(errormsg) 386 if isequal(Param.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode 387 if isempty(VarVal) 388 msgbox_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(ifile))]) 389 return 390 end 391 VarVal=mean(VarVal,1); 392 end 393 VarVal=shiftdim(VarVal,-1); %shift dimension 394 DataOut.(VarName)=cat(1,DataOut.(VarName),VarVal);%concanete the current field to the time series 395 else 396 DataOut.(VarName)=cat(1,DataOut.(VarName),0);% put each variable to 0 in case of input reading error 397 end 398 elseif testsum(ivar)==1% variable representing fixed coordinates 399 eval(['VarInit=DataOut.' VarName ';']); 400 if isempty(errormsg) && ~isequal(VarVal,VarInit) 401 msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName]) 402 return 403 end 404 end 405 end 406 407 % record the time: 408 if isempty(time)% time read in ncfiles 409 if isfield(Field,'Time') 410 DataOut.Time(filecounter,1)=Field.Time; 411 else 412 DataOut.Time(filecounter,1)=ifile;%default 413 end 414 else % time from ImaDoc prevails TODO: correct 415 % DataOut.Time(filecounter,1)=time{1}(i1_series{1})(ifile),j1_series{1}(ifile))+time(end,i2_series{end}(ifile),j2_series{end}(ifile)))/2; 416 DataOut.Time(filecounter,1)=i1_series{1}(ifile);% TODO : generalise 417 end 418 419 % record the number of missing input fields 420 if ~isempty(errormsg) 421 nbmissing=nbmissing+1; 422 display(['ifile=' num2str(ifile) ':' errormsg]) 423 end 374 end 375 end 376 377 % record the time: 378 if isempty(time)% time read in ncfiles 379 if isfield(Field,'Time') 380 DataOut.Time(filecounter,1)=Field.Time; 381 else 382 DataOut.Time(filecounter,1)=ifile;%default 383 end 384 else % time from ImaDoc prevails TODO: correct 385 % DataOut.Time(filecounter,1)=time{1}(i1_series{1})(ifile),j1_series{1}(ifile))+time(end,i2_series{end}(ifile),j2_series{end}(ifile)))/2; 386 DataOut.Time(filecounter,1)=i1_series{1}(ifile);% TODO : generalise 387 end 388 389 % record the number of missing input fields 390 if ~isempty(errormsg) 391 nbmissing=nbmissing+1; 392 display(['ifile=' num2str(ifile) ':' errormsg]) 424 393 end 425 394 end 426 395 end 427 396 %%%%%%% END OF LOOP WITHIN A SLICE 428 397 429 398 %remove time for global attributes if exists 430 399 Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute)); … … 438 407 end 439 408 440 % add time dimension 409 % add time dimension 441 410 for ivar=1:length(Field.ListVarName) 442 411 DimCell=Field.VarDimName(ivar); … … 469 438 % display nbmissing 470 439 if ~isequal(nbmissing,0) 471 msgbox_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'])440 displ_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun) 472 441 end 473 442 474 443 %name of result file 475 % filemean=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},'.nc','_1',i1_series{1}(i_slice)); 476 OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]); 444 OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]); 477 445 errormsg=struct2nc(OutputFile,DataOut); %save result file 478 446 if isempty(errormsg) 479 447 display([OutputFile ' written']) 480 448 else 481 msgbox_uvmat('ERROR',['error in Series/struct2nc: ' errormsg])449 displ_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun) 482 450 end 483 451 end … … 486 454 figure 487 455 haxes=axes; 456 if checkrun 488 457 plot_field(DataOut,haxes) 458 end 489 459 490 460 %% display the result file using the GUI get_field
Note: See TracChangeset
for help on using the changeset viewer.