[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 | |
---|
[330] | 50 | %% requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) |
---|
[374] | 51 | if ~exist('Param','var') |
---|
[457] | 52 | ParamOut={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one') |
---|
[27] | 53 | 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default) |
---|
| 54 | 'RootFile';'on';... %root input file name ('on' by default) |
---|
| 55 | 'FileExt';'on';... %input file extension ('on' by default) |
---|
| 56 | 'NomType';'on';...%type of file indexing ('on' by default) |
---|
| 57 | 'NbSlice';'on'; ...%nbre of slices ('off' by default) |
---|
| 58 | 'VelTypeMenu';'two';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default) |
---|
| 59 | 'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
| 60 | 'CoordType';'on';...%can use a transform function 'off' by default |
---|
| 61 | 'GetObject';'on';...%can use projection object ,'off' by default |
---|
[447] | 62 | 'OutputDirExt';'.series'... |
---|
[27] | 63 | %'GetMask';'on'...%can use mask option ,'off' by default |
---|
| 64 | %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter |
---|
| 65 | ''}; |
---|
| 66 | return %exit the function |
---|
| 67 | end |
---|
| 68 | |
---|
[457] | 69 | %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%% |
---|
| 70 | %% select different modes, RUN, parameter input, BATCH |
---|
| 71 | % BATCH case: read the xml file for batch case |
---|
| 72 | ParamOut=Param; %default output |
---|
| 73 | if ischar(Param) |
---|
| 74 | if strcmp(Param,'input?') |
---|
| 75 | checkrun=1;% will inly search input parameters (preparation of BATCH mode) |
---|
| 76 | else |
---|
| 77 | Param=xml2struct(Param); |
---|
| 78 | checkrun=0; |
---|
| 79 | end |
---|
| 80 | % RUN case: parameters introduced as the input structure Param |
---|
| 81 | else |
---|
[374] | 82 | hseries=guidata(Param.hseries);%handles of the GUI series |
---|
[457] | 83 | WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series |
---|
| 84 | checkrun=2; % indicate the RUN option is used |
---|
[374] | 85 | end |
---|
[457] | 86 | |
---|
| 87 | %% root input file(s) and type |
---|
| 88 | RootPath=Param.InputTable(:,1); |
---|
| 89 | RootFile=Param.InputTable(:,3); |
---|
| 90 | SubDir=Param.InputTable(:,2); |
---|
| 91 | NomType=Param.InputTable(:,4); |
---|
| 92 | FileExt=Param.InputTable(:,5); |
---|
| 93 | |
---|
| 94 | % get the set of input file names (cell array filecell), and the lists of |
---|
| 95 | % input file or frame indices i1_series,i2_series,j1_series,j2_series |
---|
[374] | 96 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
[457] | 97 | % filecell{iview,fileindex}: cell array representing the list of file names |
---|
| 98 | % iview: line in the table corresponding to a given file series |
---|
| 99 | % fileindex: file index within the file series, |
---|
| 100 | % 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 |
---|
| 101 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
| 102 | % set of frame indices used for movie or multimage input |
---|
| 103 | % numbers of slices and file indices |
---|
[27] | 104 | |
---|
[457] | 105 | NbSlice=1;%default |
---|
| 106 | if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice) |
---|
| 107 | NbSlice=Param.IndexRange.NbSlice; |
---|
[374] | 108 | end |
---|
[457] | 109 | nbview=numel(i1_series);%number of input file series (lines in InputTable) |
---|
| 110 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 111 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 112 | nbfield=nbfield_j*nbfield_i; %total number of fields |
---|
| 113 | nbfield_i=floor(nbfield/NbSlice);%total number of indexes in a slice (adjusted to an integer number of slices) |
---|
| 114 | nbfield=nbfield_i*NbSlice; %total number of fields after adjustement |
---|
[374] | 115 | |
---|
[457] | 116 | %determine the file type on each line from the first input file |
---|
| 117 | ImageTypeOptions={'image','multimage','mmreader','video'}; |
---|
| 118 | NcTypeOptions={'netcdf','civx','civdata'}; |
---|
| 119 | for iview=1:nbview |
---|
| 120 | if ~exist(filecell{iview,1}','file') |
---|
| 121 | msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist']) |
---|
[27] | 122 | return |
---|
| 123 | end |
---|
[457] | 124 | [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1}); |
---|
| 125 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
| 126 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
| 127 | if ~isempty(j1_series{iview}) |
---|
| 128 | frame_index{iview}=j1_series{iview}; |
---|
| 129 | else |
---|
| 130 | frame_index{iview}=i1_series{iview}; |
---|
| 131 | end |
---|
[27] | 132 | end |
---|
| 133 | |
---|
[457] | 134 | %% calibration data and timing: read the ImaDoc files |
---|
| 135 | mode=''; %default |
---|
| 136 | timecell={}; |
---|
| 137 | itime=0; |
---|
| 138 | NbSlice_calib={}; |
---|
| 139 | XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing) |
---|
| 140 | for iview=1:nbview%Loop on views |
---|
| 141 | SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.' |
---|
| 142 | filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder |
---|
| 143 | if ~exist(filexml,'file') |
---|
| 144 | filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder |
---|
| 145 | if ~exist(filexml,'file') |
---|
| 146 | filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file |
---|
| 147 | if ~exist(filexml,'file') |
---|
| 148 | filexml=''; |
---|
| 149 | end |
---|
| 150 | end |
---|
| 151 | end |
---|
| 152 | if ~isempty(filexml) |
---|
| 153 | [XmlData{iview},error]=imadoc2struct(filexml); |
---|
| 154 | end |
---|
| 155 | if isfield(XmlData{iview},'Time') |
---|
| 156 | itime=itime+1; |
---|
| 157 | timecell{itime}=XmlData{iview}.Time; |
---|
| 158 | end |
---|
| 159 | if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') |
---|
| 160 | NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform |
---|
| 161 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
---|
| 162 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); |
---|
| 163 | end |
---|
| 164 | end |
---|
| 165 | end |
---|
[27] | 166 | |
---|
[457] | 167 | %% check coincidence in time for several input file series |
---|
| 168 | multitime=0; |
---|
| 169 | if isempty(timecell) |
---|
| 170 | time=[]; |
---|
| 171 | elseif length(timecell)==1 |
---|
| 172 | time=timecell{1}; |
---|
| 173 | elseif length(timecell)>1 |
---|
| 174 | multitime=1; |
---|
| 175 | for icell=1:length(timecell) |
---|
| 176 | if ~isequal(size(timecell{icell}),size(timecell{1})) |
---|
| 177 | msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used') |
---|
| 178 | time=timecell{1}; |
---|
| 179 | multitime=0; |
---|
| 180 | break |
---|
[27] | 181 | end |
---|
[44] | 182 | end |
---|
[27] | 183 | end |
---|
[457] | 184 | if multitime |
---|
| 185 | for icell=1:length(timecell) |
---|
| 186 | time(icell,:,:)=timecell{icell}; |
---|
| 187 | end |
---|
| 188 | diff_time=max(max(diff(time))); |
---|
| 189 | if diff_time>0 |
---|
| 190 | msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) |
---|
| 191 | end |
---|
| 192 | end |
---|
| 193 | 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' |
---|
| 194 | time=[]; |
---|
| 195 | end |
---|
[27] | 196 | |
---|
[457] | 197 | %% coordinate transform or other user defined transform |
---|
| 198 | transform_fct='';%default |
---|
| 199 | if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle') |
---|
| 200 | transform_fct=Param.FieldTransform.TransformHandle; |
---|
| 201 | end |
---|
| 202 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
| 203 | % EDIT FROM HERE |
---|
[27] | 204 | |
---|
[457] | 205 | %% check the validity of input file types |
---|
| 206 | if CheckImage{1} |
---|
| 207 | FileExtOut='.png'; % write result as .png images for image inputs |
---|
| 208 | elseif CheckNc{1} |
---|
| 209 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
---|
| 210 | else |
---|
| 211 | msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}]) |
---|
| 212 | return |
---|
[27] | 213 | end |
---|
[457] | 214 | if nbview==2 && ~isequal(CheckImage{1},CheckImage{2}) |
---|
| 215 | msgbox_uvmat('ERROR','input must be two image series or two netcdf file series') |
---|
[259] | 216 | return |
---|
| 217 | end |
---|
[457] | 218 | NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series |
---|
| 219 | if NbSlice~=nbfield_j |
---|
| 220 | answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]); |
---|
| 221 | if ~strcmp(answer,'Yes') |
---|
| 222 | return |
---|
| 223 | end |
---|
| 224 | end |
---|
| 225 | |
---|
| 226 | %% Set field names and velocity types |
---|
| 227 | InputFields{1}=[];%default (case of images) |
---|
| 228 | if isfield(Param,'InputFields') |
---|
| 229 | InputFields{1}=Param.InputFields; |
---|
| 230 | end |
---|
| 231 | if nbview==2 |
---|
| 232 | InputFields{2}=[];%default (case of images) |
---|
| 233 | if isfield(Param,'InputFields') |
---|
| 234 | InputFields{2}=Param.InputFields{1};%default |
---|
| 235 | if isfield(Param.InputFields,'FieldName_1') |
---|
| 236 | InputFields{2}.FieldName=Param.InputFields.FieldName_1; |
---|
| 237 | if isfield(Param.InputFields,'VelType_1') |
---|
| 238 | InputFields{2}.VelType=Param.InputFields.VelType_1; |
---|
| 239 | end |
---|
| 240 | end |
---|
| 241 | end |
---|
| 242 | end |
---|
| 243 | %%% TO UPDATE |
---|
[374] | 244 | if isequal(FieldName,'get_field...') |
---|
[27] | 245 | hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI |
---|
| 246 | if numel(hget_field)>1 |
---|
| 247 | delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld |
---|
| 248 | elseif isempty(hget_field) |
---|
[374] | 249 | filename=filecell{1,1}; |
---|
| 250 | % 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] | 251 | idetect(iview)=exist(filename,'file'); |
---|
| 252 | hget_field=get_field(filename); |
---|
| 253 | return |
---|
| 254 | end |
---|
[102] | 255 | SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI |
---|
[27] | 256 | if isempty(SubField) |
---|
| 257 | delete(hget_field) |
---|
[374] | 258 | filename=filecell{1,1}; |
---|
| 259 | %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] | 260 | hget_field=get_field(filename); |
---|
| 261 | SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI |
---|
| 262 | end |
---|
| 263 | end |
---|
[457] | 264 | %%%%%%% |
---|
[27] | 265 | |
---|
[457] | 266 | %% Initiate output fields |
---|
| 267 | %initiate the output structure as a copy of the first input one (reproduce fields) |
---|
| 268 | [DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1); |
---|
| 269 | if ~isempty(errormsg) |
---|
| 270 | msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg]) |
---|
| 271 | return |
---|
| 272 | end |
---|
| 273 | time_1=[]; |
---|
| 274 | if isfield(DataOut,'Time') |
---|
| 275 | time_1=DataOut.Time(1); |
---|
| 276 | end |
---|
| 277 | if CheckNc{iview} |
---|
| 278 | if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute)) |
---|
| 279 | DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute]; |
---|
| 280 | end |
---|
| 281 | DataOut.Conventions='uvmat'; |
---|
| 282 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}]; |
---|
| 283 | ActionKey='Action'; |
---|
| 284 | while isfield(DataOut,ActionKey) |
---|
| 285 | ActionKey=[ActionKey '_1']; |
---|
| 286 | end |
---|
| 287 | DataOut.(ActionKey)=Param.Action; |
---|
| 288 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}]; |
---|
| 289 | if isfield(DataOut,'Time') |
---|
| 290 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}]; |
---|
| 291 | end |
---|
| 292 | end |
---|
| 293 | |
---|
| 294 | |
---|
| 295 | |
---|
| 296 | |
---|
[330] | 297 | %% detect whether the two files are 'images' or 'netcdf' |
---|
[27] | 298 | testcivx=0; |
---|
[330] | 299 | % FileExt=get(hseries.FileExt,'String'); |
---|
[27] | 300 | if ~isequal(FieldName,{'get_field...'}) |
---|
[44] | 301 | testcivx=isequal(FileType{1},'netcdf'); |
---|
[27] | 302 | end |
---|
[374] | 303 | % VelType_str=get(hseries.VelTypeMenu,'String'); |
---|
| 304 | % VelType_val=get(hseries.VelTypeMenu,'Value'); |
---|
| 305 | % VelType{1}=VelType_str{VelType_val}; |
---|
| 306 | % if nbview==2 |
---|
| 307 | % VelType_str=get(hseries.VelTypeMenu_1,'String'); |
---|
| 308 | % VelType_val=get(hseries.VelTypeMenu_1,'Value'); |
---|
| 309 | % VelType{2}=VelType_str{VelType_val}; |
---|
| 310 | % end |
---|
[27] | 311 | |
---|
[190] | 312 | %% LOOP ON SLICES |
---|
[330] | 313 | nbmissing=0; %number of undetected files |
---|
[27] | 314 | for i_slice=1:NbSlice |
---|
[330] | 315 | dt=[]; |
---|
| 316 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% LOOP ON FIELDS WITHIN A SLICE |
---|
| 317 | filecounter=0; |
---|
| 318 | for ifile=i_slice:NbSlice:nbfield |
---|
[442] | 319 | if checkrun |
---|
| 320 | update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield) |
---|
| 321 | stopstate=get(hseries.RUN,'BusyAction'); |
---|
| 322 | else |
---|
| 323 | stopstate='queue'; |
---|
| 324 | end |
---|
[330] | 325 | errormsg=''; |
---|
[27] | 326 | if isequal(stopstate,'queue')% enable STOP command |
---|
[330] | 327 | % loop on views (in case of multiple input series) |
---|
| 328 | for iview=1:nbview |
---|
[374] | 329 | filename=filecell{iview,ifile}; |
---|
| 330 | % filename=name_generator(filebase{iview},... |
---|
| 331 | % i1_series{iview}(ifile),j1_series{iview}(ifile),FileExt{iview},NomType{iview},1,i2_series{iview}(ifile),j2_series{iview}(ifile),SubDir{iview}); |
---|
[330] | 332 | if exist(filename,'file') |
---|
| 333 | try |
---|
| 334 | Data{iview}=[]; %default |
---|
| 335 | if ~isequal(FileType{iview},'netcdf') |
---|
| 336 | Data{iview}.ListVarName={'A'}; |
---|
| 337 | Data{iview}.AName='image'; |
---|
| 338 | switch FileType{iview} |
---|
| 339 | case 'movie' |
---|
[374] | 340 | A=read(MovieObject{iview},i1_series{iview}(ifile)); |
---|
[330] | 341 | case 'avi' |
---|
[374] | 342 | mov=aviread(filename,i1_series{iview}(ifile)); |
---|
[330] | 343 | A=frame2im(mov(1)); |
---|
| 344 | case 'vol' |
---|
| 345 | A=imread(filename); |
---|
| 346 | case 'multimage' |
---|
[374] | 347 | A=imread(filename,i1_series{iview}(ifile)); |
---|
[330] | 348 | case 'image' |
---|
| 349 | A=imread(filename); |
---|
| 350 | end |
---|
| 351 | Data{iview}.ListVarName={'AY','AX','A'}; % |
---|
| 352 | npy=size(A,1); |
---|
| 353 | npx=size(A,2); |
---|
| 354 | nbcolor=size(A,3); |
---|
| 355 | if nbcolor==3 |
---|
| 356 | Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; |
---|
| 357 | else |
---|
| 358 | Data{iview}.VarDimName={'AY','AX',{'AY','AX'}}; |
---|
| 359 | end |
---|
| 360 | Data{iview}.AY=[npy-0.5 0.5]; |
---|
| 361 | Data{iview}.AX=[0.5 npx-0.5]; |
---|
| 362 | Data{iview}.A=double(A); |
---|
| 363 | Data{iview}.CoordUnit='pixel'; |
---|
| 364 | elseif testcivx |
---|
| 365 | [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType); |
---|
| 366 | if ~isequal(FieldName,{''}) |
---|
| 367 | Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..) |
---|
| 368 | end |
---|
| 369 | else |
---|
| 370 | [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data |
---|
| 371 | Data{iview}.VarAttribute=SubField.VarAttribute; |
---|
| 372 | end |
---|
| 373 | if ~isempty(NbSlice_calib) % z index |
---|
[374] | 374 | Data{iview}.ZIndex=mod(i1_series{iview}(ifile)-1,NbSlice_calib{1})+1; |
---|
[330] | 375 | end |
---|
| 376 | catch ME |
---|
| 377 | errormsg=ME.message; |
---|
| 378 | end |
---|
[27] | 379 | else |
---|
[330] | 380 | errormsg=[filename ' is missing']; |
---|
[27] | 381 | end |
---|
[330] | 382 | if isempty(errormsg) |
---|
| 383 | % coordinate transform (or other user defined transform) |
---|
| 384 | if ~isempty(transform_fct) |
---|
| 385 | if nbview==2 |
---|
| 386 | [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); |
---|
| 387 | if isempty(Data{2}) |
---|
| 388 | Data(2)=[]; |
---|
| 389 | end |
---|
| 390 | else |
---|
| 391 | Data{1}=transform_fct(Data{1},XmlData{1}); |
---|
| 392 | end |
---|
| 393 | end |
---|
| 394 | if length(Data)==2 |
---|
| 395 | [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields |
---|
| 396 | else |
---|
| 397 | Field=Data{1}; |
---|
| 398 | end |
---|
| 399 | if test_object |
---|
| 400 | [Field,errormsg]=proj_field(Field,ProjObject); |
---|
| 401 | end |
---|
[27] | 402 | end |
---|
[330] | 403 | filecounter=filecounter+1; |
---|
| 404 | |
---|
| 405 | % initiate the time series at the first iteration |
---|
| 406 | if filecounter==1 |
---|
| 407 | % stop program if the first field reading is in error |
---|
| 408 | if ~isempty(errormsg) |
---|
| 409 | msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg]) |
---|
| 410 | return |
---|
[27] | 411 | end |
---|
| 412 | RecordData=Field;%default |
---|
[330] | 413 | RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots |
---|
[27] | 414 | nbvar=length(Field.ListVarName); |
---|
| 415 | if nbvar==0 |
---|
| 416 | msgbox_uvmat('ERROR','no input variable selected in get_field') |
---|
| 417 | return |
---|
| 418 | end |
---|
| 419 | testsum=2*ones(1,nbvar);%initiate flag for action on each variable |
---|
[330] | 420 | if isfield(Field,'VarAttribute') % look for coordinate and flag variables |
---|
[27] | 421 | for ivar=1:nbvar |
---|
| 422 | if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') |
---|
| 423 | var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable |
---|
| 424 | if isequal(var_role,'errorflag') |
---|
| 425 | msgbox_uvmat('ERROR','do not handle error flags in time series') |
---|
[330] | 426 | return |
---|
[27] | 427 | end |
---|
[330] | 428 | if isequal(var_role,'warnflag') |
---|
| 429 | testsum(ivar)=0; % not recorded variable |
---|
[27] | 430 | eval(['RecordData=rmfield(RecordData,''' Field.ListVarName{ivar} ''');']);%remove variable |
---|
[330] | 431 | end |
---|
[27] | 432 | if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|... |
---|
[330] | 433 | isequal(var_role,'coord_z')|isequal(var_role,'coord') |
---|
[27] | 434 | testsum(ivar)=1; %constant coordinates, record without time evolution |
---|
| 435 | end |
---|
| 436 | end |
---|
[107] | 437 | % check whether the variable ivar is a dimension variable |
---|
| 438 | DimCell=Field.VarDimName{ivar}; |
---|
| 439 | if ischar(DimCell) |
---|
| 440 | DimCell={DimCell}; |
---|
| 441 | end |
---|
| 442 | if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables |
---|
[330] | 443 | testsum(ivar)=1; |
---|
[107] | 444 | end |
---|
[27] | 445 | end |
---|
| 446 | end |
---|
| 447 | for ivar=1:nbvar |
---|
[330] | 448 | if testsum(ivar)==2 |
---|
[27] | 449 | eval(['RecordData.' Field.ListVarName{ivar} '=[];']) |
---|
| 450 | end |
---|
| 451 | end |
---|
| 452 | RecordData.ListVarName=[{'Time'} RecordData.ListVarName]; |
---|
| 453 | end |
---|
[330] | 454 | |
---|
| 455 | % add data to the current field |
---|
[27] | 456 | for ivar=1:length(Field.ListVarName) |
---|
| 457 | VarName=Field.ListVarName{ivar}; |
---|
[330] | 458 | VarVal=Field.(VarName); |
---|
| 459 | if testsum(ivar)==2% test for recorded variable |
---|
| 460 | if isempty(errormsg) |
---|
| 461 | if isequal(ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode |
---|
| 462 | if isempty(VarVal) |
---|
[374] | 463 | msgbox_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(ifile))]) |
---|
[330] | 464 | return |
---|
| 465 | end |
---|
| 466 | VarVal=mean(VarVal,1); |
---|
[27] | 467 | end |
---|
[330] | 468 | VarVal=shiftdim(VarVal,-1); %shift dimension |
---|
| 469 | RecordData.(VarName)=cat(1,RecordData.(VarName),VarVal);%concanete the current field to the time series |
---|
| 470 | else |
---|
| 471 | RecordData.(VarName)=cat(1,RecordData.(VarName),0);% put each variable to 0 in case of input reading error |
---|
[27] | 472 | end |
---|
| 473 | elseif testsum(ivar)==1% variable representing fixed coordinates |
---|
| 474 | eval(['VarInit=RecordData.' VarName ';']); |
---|
[330] | 475 | if isempty(errormsg) && ~isequal(VarVal,VarInit) |
---|
[27] | 476 | msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName]) |
---|
| 477 | return |
---|
| 478 | end |
---|
[330] | 479 | end |
---|
[27] | 480 | end |
---|
[330] | 481 | |
---|
| 482 | % record the time: |
---|
[27] | 483 | if isempty(time)% time read in ncfiles |
---|
[330] | 484 | if isfield(Field,'Time') |
---|
| 485 | RecordData.Time(filecounter,1)=Field.Time; |
---|
| 486 | else |
---|
| 487 | RecordData.Time(filecounter,1)=ifile;%default |
---|
| 488 | end |
---|
[374] | 489 | else % time from ImaDoc prevails TODO: correct |
---|
| 490 | % RecordData.Time(filecounter,1)=time{1}(i1_series{1})(ifile),j1_series{1}(ifile))+time(end,i2_series{end}(ifile),j2_series{end}(ifile)))/2; |
---|
| 491 | RecordData.Time(filecounter,1)=i1_series{1}(ifile);% TODO : generalise |
---|
[27] | 492 | end |
---|
[330] | 493 | |
---|
| 494 | % record the number of missing input fields |
---|
| 495 | if ~isempty(errormsg) |
---|
| 496 | nbmissing=nbmissing+1; |
---|
| 497 | display(['ifile=' num2str(ifile) ':' errormsg]) |
---|
| 498 | end |
---|
[27] | 499 | end |
---|
| 500 | end |
---|
| 501 | end |
---|
[330] | 502 | %%%%%%% END OF LOOP WITHIN A SLICE |
---|
| 503 | |
---|
[27] | 504 | %remove time for global attributes if exists |
---|
[422] | 505 | Time_index=find(strcmp('Time',RecordData.ListGlobalAttribute)); |
---|
[447] | 506 | if ~isempty(Time_index) |
---|
[422] | 507 | RecordData.ListGlobalAttribute(Time_index)=[]; |
---|
[27] | 508 | end |
---|
[422] | 509 | RecordData.Conventions='uvmat'; |
---|
[27] | 510 | for ivar=1:numel(RecordData.ListVarName) |
---|
| 511 | VarName=RecordData.ListVarName{ivar}; |
---|
| 512 | eval(['RecordData.' VarName '=squeeze(RecordData.' VarName ');']) %remove singletons |
---|
| 513 | end |
---|
[330] | 514 | |
---|
| 515 | % add time dimension |
---|
| 516 | for ivar=1:length(Field.ListVarName) |
---|
| 517 | DimCell=Field.VarDimName(ivar); |
---|
| 518 | if testsum(ivar)==2%variable used as time series |
---|
| 519 | RecordData.VarDimName{ivar}=[{'Time'} DimCell]; |
---|
| 520 | elseif testsum(ivar)==1 |
---|
| 521 | RecordData.VarDimName{ivar}=DimCell; |
---|
[27] | 522 | end |
---|
[330] | 523 | end |
---|
[27] | 524 | indexremove=find(~testsum); |
---|
| 525 | if ~isempty(indexremove) |
---|
| 526 | RecordData.ListVarName(1+indexremove)=[]; |
---|
| 527 | RecordData.VarDimName(indexremove)=[]; |
---|
[330] | 528 | if isfield(RecordData,'Role') && ~isempty(RecordData.Role{1})%generaliser aus autres attributs |
---|
[27] | 529 | RecordData.Role(1+indexremove)=[]; |
---|
| 530 | end |
---|
| 531 | end |
---|
[330] | 532 | |
---|
[27] | 533 | %shift variable attributes |
---|
| 534 | if isfield(RecordData,'VarAttribute') |
---|
| 535 | RecordData.VarAttribute=[{[]} RecordData.VarAttribute]; |
---|
[330] | 536 | end |
---|
[27] | 537 | RecordData.VarDimName=[{'Time'} RecordData.VarDimName]; |
---|
[374] | 538 | RecordData.Action=Param.Action;%name of the processing programme |
---|
[330] | 539 | test_time=diff(RecordData.Time)>0;% test that the readed time is increasing (not constant) |
---|
| 540 | if ~test_time |
---|
| 541 | RecordData.Time=[1:filecounter]; |
---|
| 542 | end |
---|
[107] | 543 | |
---|
[330] | 544 | % display nbmissing |
---|
| 545 | if ~isequal(nbmissing,0) |
---|
| 546 | msgbox_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display']) |
---|
| 547 | end |
---|
| 548 | |
---|
[27] | 549 | %name of result file |
---|
[374] | 550 | % [filemean]=... |
---|
| 551 | % name_generator(filebase_out,i1_series{1}(i_slice),j1_series{1}(i_slice),'.nc','_i1-i2_j1-j2',1,i2_series{end}(ifile),j2_series{end}(ifile),subdir_result); |
---|
| 552 | filemean=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},'.nc','_1',i1_series{1}(i_slice)); |
---|
[27] | 553 | errormsg=struct2nc(filemean,RecordData); %save result file |
---|
| 554 | if isempty(errormsg) |
---|
| 555 | display([filemean ' written']) |
---|
| 556 | else |
---|
[259] | 557 | msgbox_uvmat('ERROR',['error in Series/struct2nc: ' errormsg]) |
---|
[27] | 558 | end |
---|
| 559 | end |
---|
[107] | 560 | |
---|
[330] | 561 | %% plot the time series (the last one in case of multislices) |
---|
[27] | 562 | figure |
---|
| 563 | haxes=axes; |
---|
[330] | 564 | plot_field(RecordData,haxes) |
---|
[27] | 565 | |
---|
[330] | 566 | %% display the result file using the GUI get_field |
---|
[27] | 567 | hget_field=findobj(allchild(0),'name','get_field'); |
---|
| 568 | if ~isempty(hget_field) |
---|
| 569 | delete(hget_field) |
---|
| 570 | end |
---|
| 571 | get_field(filemean,RecordData) |
---|
| 572 | |
---|
[330] | 573 | %------------------------------------------------------------------------ |
---|
[27] | 574 | % --- Executes on selection change in CoordType. |
---|
| 575 | function CoordType_Callback(hObject, eventdata, handles) |
---|
[330] | 576 | %------------------------------------------------------------------------ |
---|
[27] | 577 | menu_str=get(handles.CoordType,'String'); |
---|
| 578 | ind_coord=get(handles.CoordType,'Value'); |
---|
| 579 | coord_option=menu_str{ind_coord}; |
---|
| 580 | if isequal(coord_option,'more...'); |
---|
| 581 | fct_name=''; |
---|
| 582 | if exist('./TMP/current_usr_fct.mat','file')% if a file is found |
---|
| 583 | h=load('./TMP/current_usr_fct.mat'); |
---|
| 584 | if isfield(h,'fct_name'); |
---|
| 585 | fct_name=h.fct_name; |
---|
| 586 | end |
---|
| 587 | end |
---|
| 588 | prompt = {'Enter the name of the transform function'}; |
---|
| 589 | dlg_title = 'user defined transform'; |
---|
| 590 | num_lines= 1; |
---|
| 591 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
| 592 | {'*.m', ' (*.m)'; |
---|
| 593 | '*.m', '.m files '; ... |
---|
| 594 | '*.*', 'All Files (*.*)'}, ... |
---|
| 595 | 'Pick a file', fct_name); |
---|
| 596 | fct_name=fullfile(PathName,FileName); |
---|
| 597 | addpath(PathName);%add the path to the selected fct |
---|
| 598 | [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER |
---|
| 599 | if ~exist(fct_name,'file') |
---|
| 600 | warndlg(['image procesing fct ' fct_name ' not found']) |
---|
| 601 | else |
---|
| 602 | transform=FileName(1:end-2);% |
---|
| 603 | update_menu(handles.CoordType,transform)%add the selected fct to the menu |
---|
| 604 | % set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu |
---|
| 605 | %save ('./TMP/current_usr_fct.mat','fct_name'); |
---|
| 606 | end |
---|
| 607 | end |
---|
| 608 | ind_coord=get(handles.CoordType,'Value'); |
---|
| 609 | |
---|
| 610 | %--------------------------------------------------------------------- |
---|
[44] | 611 | % % --- Executes on selection change in ProjObject. |
---|
| 612 | % function ProjObject_Callback(hObject, eventdata, handles) |
---|
| 613 | % |
---|
| 614 | % list_object=get(handles.ProjObject,'String'); |
---|
| 615 | % index=get(handles.ProjObject,'Value'); |
---|
| 616 | % hseries=get(handles.ProjObject,'Parent'); |
---|
| 617 | % SeriesData=get(hseries,'UserData'); |
---|
| 618 | % Obj=SeriesData.ProjObject{index}; |
---|
| 619 | % [SeriesData.hset_object,SeriesData.sethandles]=set_object(SeriesData.ProjObject{index}); |
---|
| 620 | % set(hseries,'UserData',SeriesData); |
---|
[27] | 621 | |
---|