[169] | 1 | %'time_series': extract a time series, used with series.fig |
---|
[457] | 2 | % this function can be used as a template for applying a global operation on a series of input fields |
---|
[169] | 3 | %------------------------------------------------------------------------ |
---|
[374] | 4 | % function GUI_input=time_series(Param) |
---|
[169] | 5 | % |
---|
[457] | 6 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 7 | % |
---|
| 8 | % This function is used in four modes by the GUI series: |
---|
| 9 | % 1) config GUI: with no input argument, the function determine the suitable GUI configuration |
---|
| 10 | % 2) interactive input: the function is used to interactively introduce input parameters, and then stops |
---|
| 11 | % 3) RUN: the function itself runs, when an appropriate input structure Param has been introduced. |
---|
| 12 | % 4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input. |
---|
| 13 | % |
---|
| 14 | % This function is used in four modes by the GUI series: |
---|
| 15 | % 1) config GUI: with no input argument, the function determine the suitable GUI configuration |
---|
| 16 | % 2) interactive input: the function is used to interactively introduce input parameters, and then stops |
---|
| 17 | % 3) RUN: the function itself runs, when an appropriate input structure Param has been introduced. |
---|
| 18 | % 4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input. |
---|
| 19 | % |
---|
[169] | 20 | %OUTPUT |
---|
| 21 | % GUI_input=list of options in the GUI series.fig needed for the function |
---|
| 22 | % |
---|
| 23 | %INPUT: |
---|
[457] | 24 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
| 25 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
| 26 | % In the absence of input (as activated when the current Action is selected |
---|
| 27 | % in series), the function ouput GUI_input set the activation of the needed GUI elements |
---|
[169] | 28 | % |
---|
[457] | 29 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param) |
---|
| 30 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
| 31 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
| 32 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
| 33 | % .OutputDir: directory for data outputs, including path |
---|
| 34 | % .Action: .ActionName: name of the current activated function |
---|
| 35 | % .ActionPath: path of the current activated function |
---|
| 36 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
| 37 | % .FieldTransform: .TransformName: name of the selected transform function |
---|
| 38 | % .TransformPath: path of the selected transform function |
---|
| 39 | % .TransformHandle: corresponding function handle |
---|
| 40 | % .InputFields: sub structure describing the input fields withfields |
---|
| 41 | % .FieldName: name of the field |
---|
| 42 | % .VelType: velocity type |
---|
| 43 | % .FieldName_1: name of the second field in case of two input series |
---|
| 44 | % .VelType_1: velocity type of the second field in case of two input series |
---|
| 45 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
| 46 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 47 | % |
---|
| 48 | function ParamOut=time_series(Param) |
---|
[27] | 49 | |
---|
[459] | 50 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName |
---|
| 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) |
---|
| 54 | 'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
[27] | 55 | 'NbSlice';'on'; ...%nbre of slices ('off' by default) |
---|
[459] | 56 | 'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
| 57 | 'FieldName';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
| 58 | 'FieldTransform'; 'on';...%can use a transform function |
---|
| 59 | 'ProjObject';'on';...%can use projection object(option 'off'/'on', |
---|
| 60 | 'Mask';'off';...%can use mask option (option 'off'/'on', 'off' by default) |
---|
| 61 | 'OutputDirExt';'.tseries';...%set the output dir extension |
---|
[27] | 62 | ''}; |
---|
[459] | 63 | return |
---|
[27] | 64 | end |
---|
| 65 | |
---|
[457] | 66 | %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%% |
---|
| 67 | %% select different modes, RUN, parameter input, BATCH |
---|
| 68 | % BATCH case: read the xml file for batch case |
---|
| 69 | ParamOut=Param; %default output |
---|
| 70 | if ischar(Param) |
---|
| 71 | if strcmp(Param,'input?') |
---|
| 72 | checkrun=1;% will inly search input parameters (preparation of BATCH mode) |
---|
| 73 | else |
---|
| 74 | Param=xml2struct(Param); |
---|
| 75 | checkrun=0; |
---|
| 76 | end |
---|
| 77 | % RUN case: parameters introduced as the input structure Param |
---|
| 78 | else |
---|
[374] | 79 | hseries=guidata(Param.hseries);%handles of the GUI series |
---|
[457] | 80 | WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series |
---|
| 81 | checkrun=2; % indicate the RUN option is used |
---|
[374] | 82 | end |
---|
[457] | 83 | |
---|
| 84 | %% root input file(s) and type |
---|
| 85 | RootPath=Param.InputTable(:,1); |
---|
| 86 | RootFile=Param.InputTable(:,3); |
---|
| 87 | SubDir=Param.InputTable(:,2); |
---|
| 88 | NomType=Param.InputTable(:,4); |
---|
| 89 | FileExt=Param.InputTable(:,5); |
---|
| 90 | |
---|
| 91 | % get the set of input file names (cell array filecell), and the lists of |
---|
| 92 | % input file or frame indices i1_series,i2_series,j1_series,j2_series |
---|
[374] | 93 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
[457] | 94 | % filecell{iview,fileindex}: cell array representing the list of file names |
---|
| 95 | % iview: line in the table corresponding to a given file series |
---|
| 96 | % fileindex: file index within the file series, |
---|
| 97 | % i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j |
---|
| 98 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
| 99 | % set of frame indices used for movie or multimage input |
---|
| 100 | % numbers of slices and file indices |
---|
[27] | 101 | |
---|
[457] | 102 | NbSlice=1;%default |
---|
| 103 | if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice) |
---|
| 104 | NbSlice=Param.IndexRange.NbSlice; |
---|
[374] | 105 | end |
---|
[457] | 106 | nbview=numel(i1_series);%number of input file series (lines in InputTable) |
---|
| 107 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 108 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 109 | nbfield=nbfield_j*nbfield_i; %total number of fields |
---|
| 110 | nbfield_i=floor(nbfield/NbSlice);%total number of indexes in a slice (adjusted to an integer number of slices) |
---|
| 111 | nbfield=nbfield_i*NbSlice; %total number of fields after adjustement |
---|
[374] | 112 | |
---|
[457] | 113 | %determine the file type on each line from the first input file |
---|
| 114 | ImageTypeOptions={'image','multimage','mmreader','video'}; |
---|
| 115 | NcTypeOptions={'netcdf','civx','civdata'}; |
---|
| 116 | for iview=1:nbview |
---|
| 117 | if ~exist(filecell{iview,1}','file') |
---|
| 118 | msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist']) |
---|
[27] | 119 | return |
---|
| 120 | end |
---|
[457] | 121 | [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1}); |
---|
| 122 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
| 123 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
| 124 | if ~isempty(j1_series{iview}) |
---|
| 125 | frame_index{iview}=j1_series{iview}; |
---|
| 126 | else |
---|
| 127 | frame_index{iview}=i1_series{iview}; |
---|
| 128 | end |
---|
[27] | 129 | end |
---|
| 130 | |
---|
[457] | 131 | %% calibration data and timing: read the ImaDoc files |
---|
| 132 | mode=''; %default |
---|
| 133 | timecell={}; |
---|
| 134 | itime=0; |
---|
| 135 | NbSlice_calib={}; |
---|
| 136 | XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing) |
---|
| 137 | for iview=1:nbview%Loop on views |
---|
| 138 | SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.' |
---|
| 139 | filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder |
---|
| 140 | if ~exist(filexml,'file') |
---|
| 141 | filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder |
---|
| 142 | if ~exist(filexml,'file') |
---|
| 143 | filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file |
---|
| 144 | if ~exist(filexml,'file') |
---|
| 145 | filexml=''; |
---|
| 146 | end |
---|
| 147 | end |
---|
| 148 | end |
---|
| 149 | if ~isempty(filexml) |
---|
| 150 | [XmlData{iview},error]=imadoc2struct(filexml); |
---|
| 151 | end |
---|
| 152 | if isfield(XmlData{iview},'Time') |
---|
| 153 | itime=itime+1; |
---|
| 154 | timecell{itime}=XmlData{iview}.Time; |
---|
| 155 | end |
---|
| 156 | if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') |
---|
| 157 | NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform |
---|
| 158 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
---|
| 159 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); |
---|
| 160 | end |
---|
| 161 | end |
---|
| 162 | end |
---|
[27] | 163 | |
---|
[457] | 164 | %% check coincidence in time for several input file series |
---|
| 165 | multitime=0; |
---|
| 166 | if isempty(timecell) |
---|
| 167 | time=[]; |
---|
| 168 | elseif length(timecell)==1 |
---|
| 169 | time=timecell{1}; |
---|
| 170 | elseif length(timecell)>1 |
---|
| 171 | multitime=1; |
---|
| 172 | for icell=1:length(timecell) |
---|
| 173 | if ~isequal(size(timecell{icell}),size(timecell{1})) |
---|
| 174 | msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used') |
---|
| 175 | time=timecell{1}; |
---|
| 176 | multitime=0; |
---|
| 177 | break |
---|
[27] | 178 | end |
---|
[44] | 179 | end |
---|
[27] | 180 | end |
---|
[457] | 181 | if multitime |
---|
| 182 | for icell=1:length(timecell) |
---|
| 183 | time(icell,:,:)=timecell{icell}; |
---|
| 184 | end |
---|
| 185 | diff_time=max(max(diff(time))); |
---|
| 186 | if diff_time>0 |
---|
| 187 | msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) |
---|
| 188 | end |
---|
| 189 | end |
---|
| 190 | if size(time,2) < i2_series{1}(end) ||( ~isempty(j2_series{1}) && size(time,3) < j2_series{1}(end))% time array absent or too short in ImaDoc xml file' |
---|
| 191 | time=[]; |
---|
| 192 | end |
---|
[27] | 193 | |
---|
[457] | 194 | %% coordinate transform or other user defined transform |
---|
| 195 | transform_fct='';%default |
---|
| 196 | if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle') |
---|
| 197 | transform_fct=Param.FieldTransform.TransformHandle; |
---|
| 198 | end |
---|
| 199 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
| 200 | % EDIT FROM HERE |
---|
[27] | 201 | |
---|
[457] | 202 | %% check the validity of input file types |
---|
| 203 | if CheckImage{1} |
---|
| 204 | FileExtOut='.png'; % write result as .png images for image inputs |
---|
| 205 | elseif CheckNc{1} |
---|
| 206 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
---|
| 207 | else |
---|
| 208 | msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}]) |
---|
| 209 | return |
---|
[27] | 210 | end |
---|
[457] | 211 | if nbview==2 && ~isequal(CheckImage{1},CheckImage{2}) |
---|
| 212 | msgbox_uvmat('ERROR','input must be two image series or two netcdf file series') |
---|
[259] | 213 | return |
---|
| 214 | end |
---|
[457] | 215 | NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series |
---|
| 216 | if NbSlice~=nbfield_j |
---|
| 217 | answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]); |
---|
| 218 | if ~strcmp(answer,'Yes') |
---|
| 219 | return |
---|
| 220 | end |
---|
| 221 | end |
---|
| 222 | |
---|
| 223 | %% Set field names and velocity types |
---|
| 224 | InputFields{1}=[];%default (case of images) |
---|
| 225 | if isfield(Param,'InputFields') |
---|
| 226 | InputFields{1}=Param.InputFields; |
---|
| 227 | end |
---|
| 228 | if nbview==2 |
---|
| 229 | InputFields{2}=[];%default (case of images) |
---|
| 230 | if isfield(Param,'InputFields') |
---|
| 231 | InputFields{2}=Param.InputFields{1};%default |
---|
| 232 | if isfield(Param.InputFields,'FieldName_1') |
---|
| 233 | InputFields{2}.FieldName=Param.InputFields.FieldName_1; |
---|
| 234 | if isfield(Param.InputFields,'VelType_1') |
---|
| 235 | InputFields{2}.VelType=Param.InputFields.VelType_1; |
---|
| 236 | end |
---|
| 237 | end |
---|
| 238 | end |
---|
| 239 | end |
---|
| 240 | %%% TO UPDATE |
---|
[459] | 241 | if isequal(InputFields{1},'get_field...') |
---|
[27] | 242 | hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI |
---|
| 243 | if numel(hget_field)>1 |
---|
| 244 | delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld |
---|
| 245 | elseif isempty(hget_field) |
---|
[374] | 246 | filename=filecell{1,1}; |
---|
| 247 | % filename=name_generator(filebase{1},i1_series{1}(1),j1_series{1}(1),FileExt{1},NomType{1},1,i2_series{1}(1),num_j2{1}(1),SubDir{1}); |
---|
[27] | 248 | idetect(iview)=exist(filename,'file'); |
---|
| 249 | hget_field=get_field(filename); |
---|
| 250 | return |
---|
| 251 | end |
---|
[102] | 252 | SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI |
---|
[27] | 253 | if isempty(SubField) |
---|
| 254 | delete(hget_field) |
---|
[374] | 255 | filename=filecell{1,1}; |
---|
| 256 | %filename=name_generator(filebase{1},i1_series{1}(1),j1_series{1}(1),FileExt{1},NomType{1},1,i2_series{1}(1),j2_series{1}(1),SubDir{1}); |
---|
[27] | 257 | hget_field=get_field(filename); |
---|
| 258 | SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI |
---|
| 259 | end |
---|
| 260 | end |
---|
[457] | 261 | %%%%%%% |
---|
[27] | 262 | |
---|
[457] | 263 | %% Initiate output fields |
---|
| 264 | %initiate the output structure as a copy of the first input one (reproduce fields) |
---|
| 265 | [DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1); |
---|
| 266 | if ~isempty(errormsg) |
---|
| 267 | msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg]) |
---|
| 268 | return |
---|
| 269 | end |
---|
| 270 | time_1=[]; |
---|
| 271 | if isfield(DataOut,'Time') |
---|
| 272 | time_1=DataOut.Time(1); |
---|
| 273 | end |
---|
| 274 | if CheckNc{iview} |
---|
| 275 | if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute)) |
---|
| 276 | DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute]; |
---|
| 277 | end |
---|
| 278 | DataOut.Conventions='uvmat'; |
---|
| 279 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}]; |
---|
| 280 | ActionKey='Action'; |
---|
| 281 | while isfield(DataOut,ActionKey) |
---|
| 282 | ActionKey=[ActionKey '_1']; |
---|
| 283 | end |
---|
| 284 | DataOut.(ActionKey)=Param.Action; |
---|
| 285 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}]; |
---|
| 286 | if isfield(DataOut,'Time') |
---|
| 287 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}]; |
---|
| 288 | end |
---|
| 289 | end |
---|
| 290 | |
---|
[190] | 291 | %% LOOP ON SLICES |
---|
[330] | 292 | nbmissing=0; %number of undetected files |
---|
[27] | 293 | for i_slice=1:NbSlice |
---|
[330] | 294 | dt=[]; |
---|
| 295 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% LOOP ON FIELDS WITHIN A SLICE |
---|
| 296 | filecounter=0; |
---|
| 297 | for ifile=i_slice:NbSlice:nbfield |
---|
[442] | 298 | if checkrun |
---|
| 299 | update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield) |
---|
| 300 | stopstate=get(hseries.RUN,'BusyAction'); |
---|
| 301 | else |
---|
| 302 | stopstate='queue'; |
---|
| 303 | end |
---|
[330] | 304 | errormsg=''; |
---|
[27] | 305 | if isequal(stopstate,'queue')% enable STOP command |
---|
[330] | 306 | % loop on views (in case of multiple input series) |
---|
| 307 | for iview=1:nbview |
---|
[374] | 308 | filename=filecell{iview,ifile}; |
---|
| 309 | % filename=name_generator(filebase{iview},... |
---|
| 310 | % i1_series{iview}(ifile),j1_series{iview}(ifile),FileExt{iview},NomType{iview},1,i2_series{iview}(ifile),j2_series{iview}(ifile),SubDir{iview}); |
---|
[330] | 311 | if exist(filename,'file') |
---|
| 312 | try |
---|
| 313 | Data{iview}=[]; %default |
---|
| 314 | if ~isequal(FileType{iview},'netcdf') |
---|
| 315 | Data{iview}.ListVarName={'A'}; |
---|
| 316 | Data{iview}.AName='image'; |
---|
| 317 | switch FileType{iview} |
---|
| 318 | case 'movie' |
---|
[374] | 319 | A=read(MovieObject{iview},i1_series{iview}(ifile)); |
---|
[330] | 320 | case 'avi' |
---|
[374] | 321 | mov=aviread(filename,i1_series{iview}(ifile)); |
---|
[330] | 322 | A=frame2im(mov(1)); |
---|
| 323 | case 'vol' |
---|
| 324 | A=imread(filename); |
---|
| 325 | case 'multimage' |
---|
[374] | 326 | A=imread(filename,i1_series{iview}(ifile)); |
---|
[330] | 327 | case 'image' |
---|
| 328 | A=imread(filename); |
---|
| 329 | end |
---|
| 330 | Data{iview}.ListVarName={'AY','AX','A'}; % |
---|
| 331 | npy=size(A,1); |
---|
| 332 | npx=size(A,2); |
---|
| 333 | nbcolor=size(A,3); |
---|
| 334 | if nbcolor==3 |
---|
| 335 | Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; |
---|
| 336 | else |
---|
| 337 | Data{iview}.VarDimName={'AY','AX',{'AY','AX'}}; |
---|
| 338 | end |
---|
| 339 | Data{iview}.AY=[npy-0.5 0.5]; |
---|
| 340 | Data{iview}.AX=[0.5 npx-0.5]; |
---|
| 341 | Data{iview}.A=double(A); |
---|
| 342 | Data{iview}.CoordUnit='pixel'; |
---|
| 343 | elseif testcivx |
---|
| 344 | [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType); |
---|
| 345 | if ~isequal(FieldName,{''}) |
---|
| 346 | Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..) |
---|
| 347 | end |
---|
| 348 | else |
---|
| 349 | [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data |
---|
| 350 | Data{iview}.VarAttribute=SubField.VarAttribute; |
---|
| 351 | end |
---|
| 352 | if ~isempty(NbSlice_calib) % z index |
---|
[374] | 353 | Data{iview}.ZIndex=mod(i1_series{iview}(ifile)-1,NbSlice_calib{1})+1; |
---|
[330] | 354 | end |
---|
| 355 | catch ME |
---|
| 356 | errormsg=ME.message; |
---|
| 357 | end |
---|
[27] | 358 | else |
---|
[330] | 359 | errormsg=[filename ' is missing']; |
---|
[27] | 360 | end |
---|
[330] | 361 | if isempty(errormsg) |
---|
| 362 | % coordinate transform (or other user defined transform) |
---|
| 363 | if ~isempty(transform_fct) |
---|
| 364 | if nbview==2 |
---|
| 365 | [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); |
---|
| 366 | if isempty(Data{2}) |
---|
| 367 | Data(2)=[]; |
---|
| 368 | end |
---|
| 369 | else |
---|
| 370 | Data{1}=transform_fct(Data{1},XmlData{1}); |
---|
| 371 | end |
---|
| 372 | end |
---|
| 373 | if length(Data)==2 |
---|
| 374 | [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields |
---|
| 375 | else |
---|
| 376 | Field=Data{1}; |
---|
| 377 | end |
---|
[459] | 378 | if Param.CheckObject |
---|
| 379 | [Field,errormsg]=proj_field(Field,Param.ProjObject); |
---|
[330] | 380 | end |
---|
[27] | 381 | end |
---|
[330] | 382 | filecounter=filecounter+1; |
---|
| 383 | |
---|
| 384 | % initiate the time series at the first iteration |
---|
| 385 | if filecounter==1 |
---|
| 386 | % stop program if the first field reading is in error |
---|
| 387 | if ~isempty(errormsg) |
---|
| 388 | msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg]) |
---|
| 389 | return |
---|
[27] | 390 | end |
---|
[459] | 391 | DataOut=Field;%default |
---|
| 392 | DataOut.NbDim=Field.NbDim+1; %add the time dimension for plots |
---|
[27] | 393 | nbvar=length(Field.ListVarName); |
---|
| 394 | if nbvar==0 |
---|
| 395 | msgbox_uvmat('ERROR','no input variable selected in get_field') |
---|
| 396 | return |
---|
| 397 | end |
---|
| 398 | testsum=2*ones(1,nbvar);%initiate flag for action on each variable |
---|
[330] | 399 | if isfield(Field,'VarAttribute') % look for coordinate and flag variables |
---|
[27] | 400 | for ivar=1:nbvar |
---|
| 401 | if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') |
---|
| 402 | var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable |
---|
| 403 | if isequal(var_role,'errorflag') |
---|
| 404 | msgbox_uvmat('ERROR','do not handle error flags in time series') |
---|
[330] | 405 | return |
---|
[27] | 406 | end |
---|
[330] | 407 | if isequal(var_role,'warnflag') |
---|
| 408 | testsum(ivar)=0; % not recorded variable |
---|
[459] | 409 | eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable |
---|
[330] | 410 | end |
---|
[27] | 411 | if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|... |
---|
[330] | 412 | isequal(var_role,'coord_z')|isequal(var_role,'coord') |
---|
[27] | 413 | testsum(ivar)=1; %constant coordinates, record without time evolution |
---|
| 414 | end |
---|
| 415 | end |
---|
[107] | 416 | % check whether the variable ivar is a dimension variable |
---|
| 417 | DimCell=Field.VarDimName{ivar}; |
---|
| 418 | if ischar(DimCell) |
---|
| 419 | DimCell={DimCell}; |
---|
| 420 | end |
---|
| 421 | if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables |
---|
[330] | 422 | testsum(ivar)=1; |
---|
[107] | 423 | end |
---|
[27] | 424 | end |
---|
| 425 | end |
---|
| 426 | for ivar=1:nbvar |
---|
[330] | 427 | if testsum(ivar)==2 |
---|
[459] | 428 | eval(['DataOut.' Field.ListVarName{ivar} '=[];']) |
---|
[27] | 429 | end |
---|
| 430 | end |
---|
[459] | 431 | DataOut.ListVarName=[{'Time'} DataOut.ListVarName]; |
---|
[27] | 432 | end |
---|
[330] | 433 | |
---|
| 434 | % add data to the current field |
---|
[27] | 435 | for ivar=1:length(Field.ListVarName) |
---|
| 436 | VarName=Field.ListVarName{ivar}; |
---|
[330] | 437 | VarVal=Field.(VarName); |
---|
| 438 | if testsum(ivar)==2% test for recorded variable |
---|
| 439 | if isempty(errormsg) |
---|
[459] | 440 | if isequal(Param.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode |
---|
[330] | 441 | if isempty(VarVal) |
---|
[374] | 442 | msgbox_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(ifile))]) |
---|
[330] | 443 | return |
---|
| 444 | end |
---|
| 445 | VarVal=mean(VarVal,1); |
---|
[27] | 446 | end |
---|
[330] | 447 | VarVal=shiftdim(VarVal,-1); %shift dimension |
---|
[459] | 448 | DataOut.(VarName)=cat(1,DataOut.(VarName),VarVal);%concanete the current field to the time series |
---|
[330] | 449 | else |
---|
[459] | 450 | DataOut.(VarName)=cat(1,DataOut.(VarName),0);% put each variable to 0 in case of input reading error |
---|
[27] | 451 | end |
---|
| 452 | elseif testsum(ivar)==1% variable representing fixed coordinates |
---|
[459] | 453 | eval(['VarInit=DataOut.' VarName ';']); |
---|
[330] | 454 | if isempty(errormsg) && ~isequal(VarVal,VarInit) |
---|
[27] | 455 | msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName]) |
---|
| 456 | return |
---|
| 457 | end |
---|
[330] | 458 | end |
---|
[27] | 459 | end |
---|
[330] | 460 | |
---|
| 461 | % record the time: |
---|
[27] | 462 | if isempty(time)% time read in ncfiles |
---|
[330] | 463 | if isfield(Field,'Time') |
---|
[459] | 464 | DataOut.Time(filecounter,1)=Field.Time; |
---|
[330] | 465 | else |
---|
[459] | 466 | DataOut.Time(filecounter,1)=ifile;%default |
---|
[330] | 467 | end |
---|
[374] | 468 | else % time from ImaDoc prevails TODO: correct |
---|
[459] | 469 | % 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; |
---|
| 470 | DataOut.Time(filecounter,1)=i1_series{1}(ifile);% TODO : generalise |
---|
[27] | 471 | end |
---|
[330] | 472 | |
---|
| 473 | % record the number of missing input fields |
---|
| 474 | if ~isempty(errormsg) |
---|
| 475 | nbmissing=nbmissing+1; |
---|
| 476 | display(['ifile=' num2str(ifile) ':' errormsg]) |
---|
| 477 | end |
---|
[27] | 478 | end |
---|
| 479 | end |
---|
| 480 | end |
---|
[330] | 481 | %%%%%%% END OF LOOP WITHIN A SLICE |
---|
| 482 | |
---|
[27] | 483 | %remove time for global attributes if exists |
---|
[459] | 484 | Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute)); |
---|
[447] | 485 | if ~isempty(Time_index) |
---|
[459] | 486 | DataOut.ListGlobalAttribute(Time_index)=[]; |
---|
[27] | 487 | end |
---|
[459] | 488 | DataOut.Conventions='uvmat'; |
---|
| 489 | for ivar=1:numel(DataOut.ListVarName) |
---|
| 490 | VarName=DataOut.ListVarName{ivar}; |
---|
| 491 | eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons |
---|
[27] | 492 | end |
---|
[330] | 493 | |
---|
| 494 | % add time dimension |
---|
| 495 | for ivar=1:length(Field.ListVarName) |
---|
| 496 | DimCell=Field.VarDimName(ivar); |
---|
| 497 | if testsum(ivar)==2%variable used as time series |
---|
[459] | 498 | DataOut.VarDimName{ivar}=[{'Time'} DimCell]; |
---|
[330] | 499 | elseif testsum(ivar)==1 |
---|
[459] | 500 | DataOut.VarDimName{ivar}=DimCell; |
---|
[27] | 501 | end |
---|
[330] | 502 | end |
---|
[27] | 503 | indexremove=find(~testsum); |
---|
| 504 | if ~isempty(indexremove) |
---|
[459] | 505 | DataOut.ListVarName(1+indexremove)=[]; |
---|
| 506 | DataOut.VarDimName(indexremove)=[]; |
---|
| 507 | if isfield(DataOut,'Role') && ~isempty(DataOut.Role{1})%generaliser aus autres attributs |
---|
| 508 | DataOut.Role(1+indexremove)=[]; |
---|
[27] | 509 | end |
---|
| 510 | end |
---|
[330] | 511 | |
---|
[27] | 512 | %shift variable attributes |
---|
[459] | 513 | if isfield(DataOut,'VarAttribute') |
---|
| 514 | DataOut.VarAttribute=[{[]} DataOut.VarAttribute]; |
---|
[330] | 515 | end |
---|
[459] | 516 | DataOut.VarDimName=[{'Time'} DataOut.VarDimName]; |
---|
| 517 | DataOut.Action=Param.Action;%name of the processing programme |
---|
| 518 | test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant) |
---|
[330] | 519 | if ~test_time |
---|
[459] | 520 | DataOut.Time=[1:filecounter]; |
---|
[330] | 521 | end |
---|
[107] | 522 | |
---|
[330] | 523 | % display nbmissing |
---|
| 524 | if ~isequal(nbmissing,0) |
---|
| 525 | msgbox_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display']) |
---|
| 526 | end |
---|
| 527 | |
---|
[27] | 528 | %name of result file |
---|
[459] | 529 | % filemean=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},'.nc','_1',i1_series{1}(i_slice)); |
---|
| 530 | OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]); |
---|
| 531 | errormsg=struct2nc(OutputFile,DataOut); %save result file |
---|
[27] | 532 | if isempty(errormsg) |
---|
[459] | 533 | display([OutputFile ' written']) |
---|
[27] | 534 | else |
---|
[259] | 535 | msgbox_uvmat('ERROR',['error in Series/struct2nc: ' errormsg]) |
---|
[27] | 536 | end |
---|
| 537 | end |
---|
[107] | 538 | |
---|
[330] | 539 | %% plot the time series (the last one in case of multislices) |
---|
[27] | 540 | figure |
---|
| 541 | haxes=axes; |
---|
[459] | 542 | plot_field(DataOut,haxes) |
---|
[27] | 543 | |
---|
[330] | 544 | %% display the result file using the GUI get_field |
---|
[27] | 545 | hget_field=findobj(allchild(0),'name','get_field'); |
---|
| 546 | if ~isempty(hget_field) |
---|
| 547 | delete(hget_field) |
---|
| 548 | end |
---|
[459] | 549 | get_field(OutputFile,DataOut) |
---|
[27] | 550 | |
---|
| 551 | |
---|
| 552 | |
---|