[572] | 1 | %'time_series': extract a time series after projection on an object (points , line..) |
---|
[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 | % |
---|
[169] | 8 | %OUTPUT |
---|
[596] | 9 | % ParamOut: sets options in the GUI series.fig needed for the function |
---|
[169] | 10 | % |
---|
| 11 | %INPUT: |
---|
[457] | 12 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
| 13 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
[596] | 14 | % when Param.Action.RUN=0 (as activated when the current Action is selected |
---|
| 15 | % in series), the function ouput paramOut set the activation of the needed GUI elements |
---|
[169] | 16 | % |
---|
[596] | 17 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
---|
| 18 | % see the current structure Param) |
---|
[457] | 19 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
| 20 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
| 21 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
[474] | 22 | % .OutputDirExt: directory extension for data outputs |
---|
[457] | 23 | % .Action: .ActionName: name of the current activated function |
---|
| 24 | % .ActionPath: path of the current activated function |
---|
[596] | 25 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct |
---|
| 26 | % .RUN =0 for GUI input, =1 for function activation |
---|
| 27 | % .RunMode='local','background', 'cluster': type of function use |
---|
| 28 | % |
---|
[457] | 29 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
| 30 | % .FieldTransform: .TransformName: name of the selected transform function |
---|
| 31 | % .TransformPath: path of the selected transform function |
---|
| 32 | % .InputFields: sub structure describing the input fields withfields |
---|
[596] | 33 | % .FieldName: name(s) of the field |
---|
[457] | 34 | % .VelType: velocity type |
---|
| 35 | % .FieldName_1: name of the second field in case of two input series |
---|
| 36 | % .VelType_1: velocity type of the second field in case of two input series |
---|
[596] | 37 | % .Coord_y: name of y coordinate variable |
---|
| 38 | % .Coord_x: name of x coordinate variable |
---|
[457] | 39 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
| 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
[596] | 41 | |
---|
[810] | 42 | %======================================================================= |
---|
[1071] | 43 | % Copyright 2008-2020, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[810] | 44 | % http://www.legi.grenoble-inp.fr |
---|
| 45 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 46 | % |
---|
| 47 | % This file is part of the toolbox UVMAT. |
---|
| 48 | % |
---|
| 49 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 50 | % it under the terms of the GNU General Public License as published |
---|
| 51 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 52 | % or (at your option) any later version. |
---|
| 53 | % |
---|
| 54 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 55 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 56 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 57 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 58 | %======================================================================= |
---|
| 59 | |
---|
[457] | 60 | function ParamOut=time_series(Param) |
---|
[27] | 61 | |
---|
[606] | 62 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed |
---|
[875] | 63 | if isstruct(Param) && isequal(Param.Action.RUN,0)% function activated from the GUI series but not RUN |
---|
[605] | 64 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
---|
| 65 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
| 66 | ParamOut.NbSlice='on'; %nbre of slices ('off' by default) |
---|
| 67 | ParamOut.VelType='two';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
| 68 | ParamOut.FieldName='two';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
[1001] | 69 | ParamOut.FieldTransform = {'phys','phys_polar'};%can use a transform function, proposed list (needed for compilation) |
---|
| 70 | ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only) |
---|
| 71 | if 1==2 % loop used to enforce compilation of transform fct, never entered. |
---|
| 72 | phys |
---|
| 73 | phys_polar |
---|
| 74 | end |
---|
[605] | 75 | ParamOut.ProjObject='on';%can use projection object(option 'off'/'on', |
---|
| 76 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
---|
| 77 | ParamOut.OutputDirExt='.tseries';%set the output dir extension |
---|
| 78 | ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice |
---|
[871] | 79 | % check for selection of a projection object |
---|
| 80 | hseries=findobj(allchild(0),'Tag','series');% handles of the GUI series |
---|
[875] | 81 | hhseries=guidata(hseries); |
---|
[871] | 82 | if ~isfield(Param,'ProjObject') |
---|
| 83 | answer=msgbox_uvmat('INPUT_Y-N','use a projection object for the time_series?'); |
---|
| 84 | if strcmp(answer,'Yes') |
---|
| 85 | set(hhseries.CheckObject,'Visible','on') |
---|
| 86 | set(hhseries.CheckObject,'Value',1) |
---|
| 87 | series('CheckObject_Callback',hseries,[],hhseries); %file input with xml reading in uvmat, show the image in phys coordinates |
---|
| 88 | end |
---|
| 89 | end |
---|
[875] | 90 | |
---|
[871] | 91 | % introduce bin size for histograms |
---|
[872] | 92 | if isfield(Param,'CheckObject') &&Param.CheckObject |
---|
[871] | 93 | SeriesData=get(hseries,'UserData'); |
---|
[872] | 94 | if ismember(SeriesData.ProjObject.ProjMode,{'inside','outside'}) |
---|
[875] | 95 | answer=msgbox_uvmat('INPUT_TXT','set bin size for histograms (or keep ''auto'' by default)?','auto'); |
---|
[880] | 96 | ParamOut.ActionInput.VarMesh=str2num(answer); |
---|
[871] | 97 | end |
---|
| 98 | end |
---|
[875] | 99 | |
---|
[874] | 100 | % test for subtraction |
---|
[875] | 101 | if size(Param.InputTable,1)>2 |
---|
| 102 | msgbox_uvmat('WARNING','''time_series'' uses only one or two input lines (two for substraction). To concatene fields first use ''merge_proj'''); |
---|
| 103 | end |
---|
| 104 | if size(Param.InputTable,1)>=2 |
---|
| 105 | answer=msgbox_uvmat('INPUT_Y-N','substract the two input file series?'); |
---|
| 106 | if strcmp(answer,'Yes') |
---|
| 107 | if isempty(Param.FieldTransform.TransformName) |
---|
| 108 | set(hhseries.TransformName,'value',2) %select sub_field |
---|
| 109 | end |
---|
| 110 | else |
---|
| 111 | set(hhseries.InputTable,'Data',Param.InputTable(1,:)) |
---|
[874] | 112 | end |
---|
[875] | 113 | end |
---|
| 114 | |
---|
[871] | 115 | % check the existence of the first and last file in the series |
---|
[875] | 116 | first_j=[]; |
---|
[716] | 117 | if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end |
---|
| 118 | last_j=[]; |
---|
| 119 | if isfield(Param.IndexRange,'last_j'); last_j=Param.IndexRange.last_j; end |
---|
| 120 | PairString=''; |
---|
| 121 | if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end |
---|
| 122 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString); |
---|
| 123 | FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},... |
---|
| 124 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2); |
---|
| 125 | if ~exist(FirstFileName,'file') |
---|
| 126 | msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist']) |
---|
[871] | 127 | else |
---|
| 128 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.last_i,last_j,PairString); |
---|
| 129 | LastFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},... |
---|
| 130 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2); |
---|
| 131 | if ~exist(LastFileName,'file') |
---|
| 132 | msgbox_uvmat('WARNING',['the last input file ' LastFileName ' does not exist']) |
---|
| 133 | end |
---|
[605] | 134 | end |
---|
[599] | 135 | return |
---|
[27] | 136 | end |
---|
| 137 | |
---|
[526] | 138 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
---|
[624] | 139 | ParamOut=[]; %default output |
---|
[592] | 140 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
| 141 | checkrun=1; |
---|
[457] | 142 | if ischar(Param) |
---|
[592] | 143 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
| 144 | checkrun=0; |
---|
[374] | 145 | end |
---|
[624] | 146 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 147 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
| 148 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
[592] | 149 | |
---|
[624] | 150 | %% define the directory for result file (with path=RootPath{1}) |
---|
[474] | 151 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
[457] | 152 | |
---|
[609] | 153 | %% root input file(s) name, type and index series |
---|
[457] | 154 | RootPath=Param.InputTable(:,1); |
---|
| 155 | RootFile=Param.InputTable(:,3); |
---|
| 156 | SubDir=Param.InputTable(:,2); |
---|
| 157 | NomType=Param.InputTable(:,4); |
---|
| 158 | FileExt=Param.InputTable(:,5); |
---|
[960] | 159 | |
---|
[751] | 160 | hdisp=disp_uvmat('WAITING...','checking the file series',checkrun); |
---|
[960] | 161 | % gives the series of input file names and indices set by the input parameters: |
---|
[374] | 162 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
[526] | 163 | % filecell{iview,fileindex}: |
---|
[457] | 164 | % iview: line in the table corresponding to a given file series |
---|
[960] | 165 | % fileindex: file index with i and j reshaped as a 1D array |
---|
| 166 | % 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 |
---|
[457] | 167 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
[960] | 168 | if ~isempty(hdisp),delete(hdisp),end;%end the waiting display |
---|
[374] | 169 | |
---|
[960] | 170 | NbView=numel(i1_series);%number of input file series (lines in InputTable) |
---|
| 171 | NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 172 | NbField_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 173 | NbField=NbField_j*NbField_i; %total number of fields |
---|
| 174 | |
---|
[609] | 175 | %% determine the file type on each line from the first input file |
---|
[984] | 176 | ImageTypeOptions={'image','multimage','mmreader','video','cine_phantom'}; |
---|
[457] | 177 | NcTypeOptions={'netcdf','civx','civdata'}; |
---|
[970] | 178 | FileType=cell(1,NbView); |
---|
| 179 | FileInfo=cell(1,NbView); |
---|
| 180 | MovieObject=cell(1,NbView); |
---|
| 181 | CheckImage=cell(1,NbView); |
---|
| 182 | CheckNc=cell(1,NbView); |
---|
| 183 | frame_index=cell(1,NbView); |
---|
[874] | 184 | |
---|
[970] | 185 | for iview=1:NbView |
---|
[457] | 186 | if ~exist(filecell{iview,1}','file') |
---|
[668] | 187 | disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun) |
---|
[27] | 188 | return |
---|
| 189 | end |
---|
[784] | 190 | [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1}); |
---|
[783] | 191 | FileType{iview}=FileInfo{iview}.FileType; |
---|
[768] | 192 | if strcmp(FileType{iview},'civdata')||strcmp(FileType{iview},'civx') |
---|
| 193 | if ~isfield(Param.InputFields,'VelType') |
---|
| 194 | FileType{iview}='netcdf';% civ data read as usual netcdf files |
---|
| 195 | end |
---|
| 196 | end |
---|
[457] | 197 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
| 198 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
[768] | 199 | if isempty(j1_series{iview}) |
---|
| 200 | frame_index{iview}=i1_series{iview}; |
---|
| 201 | else |
---|
[457] | 202 | frame_index{iview}=j1_series{iview}; |
---|
| 203 | end |
---|
[27] | 204 | end |
---|
| 205 | |
---|
[457] | 206 | %% calibration data and timing: read the ImaDoc files |
---|
[470] | 207 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
[768] | 208 | if ~isempty(errormsg) |
---|
| 209 | disp_uvmat('ERROR',['error in reading xmlfile: ' errormsg],checkrun) |
---|
| 210 | return |
---|
| 211 | end |
---|
[470] | 212 | if size(time,1)>1 |
---|
[457] | 213 | diff_time=max(max(diff(time))); |
---|
| 214 | if diff_time>0 |
---|
[668] | 215 | disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun) |
---|
[599] | 216 | end |
---|
[531] | 217 | time=time(1,:);% choose the time data from the first sequence |
---|
[457] | 218 | end |
---|
[27] | 219 | |
---|
[457] | 220 | %% coordinate transform or other user defined transform |
---|
[526] | 221 | transform_fct=[];%default |
---|
[478] | 222 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
[1001] | 223 | %addpath(Param.FieldTransform.TransformPath) |
---|
[474] | 224 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
[1001] | 225 | %rmpath(Param.FieldTransform.TransformPath) |
---|
[883] | 226 | if isfield(Param,'TransformInput') |
---|
| 227 | XmlData{1}.TransformInput=Param.TransformInput; |
---|
| 228 | end |
---|
[457] | 229 | end |
---|
[474] | 230 | |
---|
[457] | 231 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
[599] | 232 | % EDIT FROM HERE |
---|
[27] | 233 | |
---|
[656] | 234 | %% check the validity of the input file types |
---|
| 235 | if ~CheckImage{1}&&~CheckNc{1} |
---|
[668] | 236 | disp_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun) |
---|
[457] | 237 | return |
---|
[27] | 238 | end |
---|
[970] | 239 | if NbView==2 && ~isequal(CheckImage{1},CheckImage{2}) |
---|
[668] | 240 | disp_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun) |
---|
[259] | 241 | return |
---|
| 242 | end |
---|
[635] | 243 | |
---|
| 244 | %% settings for the output file |
---|
[656] | 245 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
---|
[609] | 246 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file |
---|
[635] | 247 | first_i=i1_series{1}(1); |
---|
| 248 | last_i=i1_series{1}(end); |
---|
| 249 | if isempty(j1_series{1})% if there is no second index j |
---|
| 250 | first_j=1;last_j=1; |
---|
| 251 | else |
---|
| 252 | first_j=j1_series{1}(1); |
---|
| 253 | last_j=j1_series{1}(end); |
---|
| 254 | end |
---|
[457] | 255 | |
---|
| 256 | %% Set field names and velocity types |
---|
| 257 | InputFields{1}=[];%default (case of images) |
---|
[970] | 258 | if NbView==2 |
---|
[867] | 259 | InputFields{2}=[];%default (case of images) |
---|
| 260 | end |
---|
[457] | 261 | if isfield(Param,'InputFields') |
---|
| 262 | InputFields{1}=Param.InputFields; |
---|
[970] | 263 | if NbView==2 |
---|
[867] | 264 | InputFields{2}=Param.InputFields;%default |
---|
[457] | 265 | if isfield(Param.InputFields,'FieldName_1') |
---|
| 266 | InputFields{2}.FieldName=Param.InputFields.FieldName_1; |
---|
| 267 | if isfield(Param.InputFields,'VelType_1') |
---|
| 268 | InputFields{2}.VelType=Param.InputFields.VelType_1; |
---|
| 269 | end |
---|
| 270 | end |
---|
| 271 | end |
---|
| 272 | end |
---|
[27] | 273 | |
---|
[457] | 274 | %% Initiate output fields |
---|
| 275 | %initiate the output structure as a copy of the first input one (reproduce fields) |
---|
[464] | 276 | [DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1); |
---|
[457] | 277 | if ~isempty(errormsg) |
---|
[668] | 278 | disp_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg],checkrun) |
---|
[457] | 279 | return |
---|
| 280 | end |
---|
| 281 | time_1=[]; |
---|
| 282 | if isfield(DataOut,'Time') |
---|
| 283 | time_1=DataOut.Time(1); |
---|
| 284 | end |
---|
| 285 | if CheckNc{iview} |
---|
| 286 | if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute)) |
---|
| 287 | DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute]; |
---|
| 288 | end |
---|
| 289 | DataOut.Conventions='uvmat'; |
---|
| 290 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}]; |
---|
| 291 | ActionKey='Action'; |
---|
| 292 | while isfield(DataOut,ActionKey) |
---|
| 293 | ActionKey=[ActionKey '_1']; |
---|
| 294 | end |
---|
| 295 | DataOut.(ActionKey)=Param.Action; |
---|
| 296 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}]; |
---|
| 297 | if isfield(DataOut,'Time') |
---|
| 298 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}]; |
---|
| 299 | end |
---|
| 300 | end |
---|
| 301 | |
---|
[871] | 302 | nbfile=0;% not used , to check |
---|
[599] | 303 | nbmissing=0; |
---|
[880] | 304 | VarMesh=[]; |
---|
[871] | 305 | checkhisto=0; |
---|
[1069] | 306 | checkline=0; |
---|
| 307 | if isfield(Param,'ProjObject') |
---|
| 308 | if ismember(Param.ProjObject.ProjMode,{'inside','outside'}) |
---|
[871] | 309 | checkhisto=1; |
---|
[880] | 310 | if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'VarMesh')%case of histograms |
---|
| 311 | VarMesh=Param.ActionInput.VarMesh; |
---|
[884] | 312 | else |
---|
| 313 | VarMesh=[]; |
---|
| 314 | disp_uvmat('WARNING','automatic bin size for histograms, select time_series again to set the value',checkrun) |
---|
[871] | 315 | end |
---|
[1069] | 316 | elseif ismember(Param.ProjObject.Type,{'line'}) |
---|
| 317 | checkline=1; |
---|
| 318 | end |
---|
[871] | 319 | end |
---|
[875] | 320 | |
---|
[599] | 321 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
[970] | 322 | for index=1:NbField |
---|
| 323 | update_waitbar(WaitbarHandle,index/NbField) |
---|
[635] | 324 | if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
[624] | 325 | disp('program stopped by user') |
---|
| 326 | break % leave the loop if stop is ordered |
---|
[599] | 327 | end |
---|
[970] | 328 | Data=cell(1,NbView);%initiate the set Data; |
---|
[599] | 329 | nbtime=0; |
---|
| 330 | dt=[]; |
---|
| 331 | %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%% |
---|
[970] | 332 | for iview=1:NbView |
---|
[599] | 333 | % reading input file(s) |
---|
| 334 | [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index)); |
---|
| 335 | if ~isempty(errormsg) |
---|
| 336 | errormsg=['time_series / read_field / ' errormsg]; |
---|
[880] | 337 | disp(errormsg) |
---|
| 338 | break% exit the loop on iview |
---|
[442] | 339 | end |
---|
[599] | 340 | if ~isempty(NbSlice_calib) |
---|
| 341 | Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform |
---|
| 342 | end |
---|
| 343 | end |
---|
[880] | 344 | if ~isempty(errormsg) |
---|
| 345 | continue %in case of input error skip the current input field, go to next index |
---|
| 346 | end |
---|
| 347 | Field=Data{1}; % default input field structure |
---|
| 348 | % coordinate transform (or other user defined transform) |
---|
| 349 | if ~isempty(transform_fct) |
---|
| 350 | switch nargin(transform_fct) |
---|
| 351 | case 4 |
---|
| 352 | if length(Data)==2 |
---|
| 353 | Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); |
---|
| 354 | else |
---|
[875] | 355 | Field=transform_fct(Data{1},XmlData{1}); |
---|
[880] | 356 | end |
---|
| 357 | case 3 |
---|
| 358 | if length(Data)==2 |
---|
| 359 | Field=transform_fct(Data{1},XmlData{1},Data{2}); |
---|
| 360 | else |
---|
| 361 | Field=transform_fct(Data{1},XmlData{1}); |
---|
| 362 | end |
---|
| 363 | case 2 |
---|
| 364 | Field=transform_fct(Data{1},XmlData{1}); |
---|
| 365 | case 1 |
---|
| 366 | Field=transform_fct(Data{1}); |
---|
[599] | 367 | end |
---|
[880] | 368 | end |
---|
| 369 | |
---|
| 370 | %field projection on an object |
---|
| 371 | if Param.CheckObject |
---|
| 372 | % calculate tps coefficients if needed |
---|
| 373 | if isfield(Param.ProjObject,'ProjMode')&& strcmp(Param.ProjObject.ProjMode,'interp_tps') |
---|
| 374 | Field=tps_coeff_field(Field,check_proj_tps); |
---|
[599] | 375 | end |
---|
[880] | 376 | [Field,errormsg]=proj_field(Field,Param.ProjObject,VarMesh); |
---|
| 377 | if ~isempty(errormsg) |
---|
| 378 | disp_uvmat('ERROR',['time_series / proj_field / ' errormsg],checkrun) |
---|
| 379 | return |
---|
| 380 | end |
---|
| 381 | end |
---|
| 382 | % nbfile=nbfile+1; |
---|
| 383 | |
---|
| 384 | % initiate the time series at the first iteration |
---|
| 385 | if index==1 |
---|
| 386 | % stop program if the first field reading is in error |
---|
| 387 | if ~isempty(errormsg) |
---|
| 388 | disp_uvmat('ERROR',['time_series / sub_field / ' errormsg],checkrun) |
---|
| 389 | return |
---|
| 390 | end |
---|
| 391 | if ~isfield(Field,'ListVarName') |
---|
| 392 | disp_uvmat('ERROR','no variable in the projected field',checkrun) |
---|
| 393 | return |
---|
| 394 | end |
---|
| 395 | DataOut=Field;%output reproduced the first projected field by default |
---|
| 396 | nbvar=length(Field.ListVarName); |
---|
| 397 | if nbvar==0 |
---|
| 398 | disp_uvmat('ERROR','no input variable selected',checkrun) |
---|
| 399 | return |
---|
| 400 | end |
---|
| 401 | if checkhisto%case of histograms |
---|
| 402 | testsum=zeros(1,nbvar);%initiate flag for action on each variable |
---|
| 403 | for ivar=1:numel(Field.ListVarName)% list of variable names before projection (histogram) |
---|
| 404 | VarName=Field.ListVarName{ivar}; |
---|
| 405 | if isfield(Data{1},VarName) |
---|
| 406 | DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Histo']}]; |
---|
| 407 | DataOut.VarDimName=[DataOut.VarDimName {{'Time',VarName}}]; |
---|
| 408 | StatName=pdf2stat;% get the names of statistical quantities to calcuilate at each time |
---|
| 409 | for istat=1:numel(StatName) |
---|
| 410 | DataOut.ListVarName=[DataOut.ListVarName {[VarName StatName{istat}]}]; |
---|
| 411 | DataOut.VarDimName=[DataOut.VarDimName {'Time'}]; |
---|
[871] | 412 | end |
---|
[880] | 413 | testsum(ivar)=1; |
---|
| 414 | DataOut.(VarName)=Field.(VarName); |
---|
[970] | 415 | DataOut.([VarName 'Histo'])=zeros([NbField numel(DataOut.(VarName))]); |
---|
[880] | 416 | VarMesh=Field.(VarName)(2)-Field.(VarName)(1); |
---|
[871] | 417 | end |
---|
[880] | 418 | end |
---|
| 419 | disp(['mesh for histogram = ' num2str(VarMesh)]) |
---|
| 420 | else |
---|
| 421 | testsum=2*ones(1,nbvar);%initiate flag for action on each variable |
---|
| 422 | if isfield(Field,'VarAttribute') % look for coordinate and flag variables |
---|
| 423 | for ivar=1:nbvar |
---|
| 424 | if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') |
---|
| 425 | var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable |
---|
| 426 | if isequal(var_role,'errorflag') |
---|
| 427 | disp_uvmat('ERROR','do not handle error flags in time series',checkrun) |
---|
| 428 | return |
---|
[27] | 429 | end |
---|
[880] | 430 | if isequal(var_role,'warnflag') |
---|
| 431 | testsum(ivar)=0; % not recorded variable |
---|
| 432 | eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable |
---|
[27] | 433 | end |
---|
[1069] | 434 | if strcmp(var_role,'coord_x')||strcmp(var_role,'coord_z')||strcmp(var_role,'coord') |
---|
[880] | 435 | testsum(ivar)=1; %constant coordinates, record without time evolution |
---|
[474] | 436 | end |
---|
[1069] | 437 | if strcmp(var_role,'coord_y')&& ~checkline |
---|
| 438 | testsum(ivar)=1; |
---|
| 439 | end |
---|
[27] | 440 | end |
---|
[880] | 441 | % check whether the variable ivar is a dimension variable |
---|
| 442 | DimCell=Field.VarDimName{ivar}; |
---|
| 443 | if ischar(DimCell) |
---|
| 444 | DimCell={DimCell}; |
---|
[474] | 445 | end |
---|
[880] | 446 | if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables |
---|
| 447 | testsum(ivar)=1; |
---|
| 448 | end |
---|
[474] | 449 | end |
---|
| 450 | end |
---|
[880] | 451 | for ivar=1:nbvar |
---|
| 452 | if testsum(ivar)==2 |
---|
| 453 | VarName=Field.ListVarName{ivar}; |
---|
| 454 | siz=size(Field.(VarName)); |
---|
[970] | 455 | DataOut.(VarName)=zeros([NbField siz]); |
---|
[330] | 456 | end |
---|
[871] | 457 | end |
---|
[880] | 458 | end |
---|
| 459 | DataOut.ListVarName=[{'Time'} DataOut.ListVarName]; |
---|
| 460 | end |
---|
| 461 | % end initialisation for index==1 |
---|
| 462 | |
---|
| 463 | % append data from the current field |
---|
| 464 | |
---|
| 465 | if checkhisto % case of histogram (projection mode=inside or outside) |
---|
| 466 | for ivar=1:length(Field.ListVarName) |
---|
| 467 | VarName=Field.ListVarName{ivar}; |
---|
| 468 | if isfield(Data{1},VarName) |
---|
| 469 | MaxValue=max(DataOut.(VarName));% current max of histogram absissa |
---|
| 470 | MinValue=min(DataOut.(VarName));% current min of histogram absissa |
---|
| 471 | MaxIndex=round(MaxValue/VarMesh); |
---|
| 472 | MinIndex=round(MinValue/VarMesh); |
---|
| 473 | MaxIndex_new=round(max(Field.(VarName)/VarMesh));% max of the current field |
---|
| 474 | MinIndex_new=round(min(Field.(VarName)/VarMesh)); |
---|
| 475 | if MaxIndex_new>MaxIndex% the variable max for the current field exceeds the previous one |
---|
| 476 | DataOut.(VarName)=[DataOut.(VarName) VarMesh*(MaxIndex+1:MaxIndex_new)];% append the new variable values |
---|
[970] | 477 | DataOut.([VarName 'Histo'])=[DataOut.([VarName 'Histo']) zeros(NbField,MaxIndex_new-MaxIndex)]; % append the new histo values |
---|
[599] | 478 | end |
---|
[880] | 479 | if MinIndex_new <= MinIndex-1 |
---|
| 480 | DataOut.(VarName)=[VarMesh*(MinIndex_new:MinIndex-1) DataOut.(VarName)];% insert the new variable values |
---|
[970] | 481 | DataOut.([VarName 'Histo'])=[zeros(NbField,MinIndex-MinIndex_new) DataOut.([VarName 'Histo'])];% insert the new histo values |
---|
[880] | 482 | ind_start=1; |
---|
| 483 | else |
---|
| 484 | ind_start=MinIndex_new-MinIndex+1; |
---|
| 485 | end |
---|
| 486 | DataOut.([VarName 'Histo'])(index,ind_start:ind_start+MaxIndex_new-MinIndex_new)=... |
---|
| 487 | DataOut.([VarName 'Histo'])(index,ind_start:ind_start+MaxIndex_new-MinIndex_new)+Field.([VarName 'Histo']); |
---|
[881] | 488 | VarVal=pdf2stat((Field.(VarName))',(Field.([VarName 'Histo']))');% max of the current field |
---|
[880] | 489 | for istat=1:numel(VarVal) |
---|
| 490 | DataOut.([VarName StatName{istat}])(index)=VarVal(istat); |
---|
| 491 | end |
---|
[27] | 492 | end |
---|
[599] | 493 | end |
---|
[880] | 494 | else % not histogram |
---|
| 495 | for ivar=1:length(Field.ListVarName) |
---|
| 496 | VarName=Field.ListVarName{ivar}; |
---|
| 497 | VarVal=Field.(VarName); |
---|
| 498 | if testsum(ivar)==2% test for recorded variable |
---|
| 499 | if isempty(errormsg) |
---|
| 500 | VarVal=shiftdim(VarVal,-1); %shift dimension |
---|
| 501 | DataOut.(VarName)(index,:,:)=VarVal;%concanete the current field to the time series |
---|
| 502 | end |
---|
| 503 | elseif testsum(ivar)==1% variable representing fixed coordinates |
---|
| 504 | VarInit=DataOut.(VarName); |
---|
| 505 | if isempty(errormsg) && ~isequal(VarVal,VarInit) |
---|
| 506 | disp_uvmat('ERROR',['time series requires constant coordinates ' VarName ': use projection mode interp'],checkrun) |
---|
| 507 | return |
---|
| 508 | end |
---|
[474] | 509 | end |
---|
[27] | 510 | end |
---|
[880] | 511 | end |
---|
| 512 | |
---|
| 513 | % record the time: |
---|
| 514 | if isempty(time)% time not set by xml filer(s) |
---|
| 515 | if isfield(Data{1},'Time') |
---|
| 516 | DataOut.Time(index,1)=Field.Time; |
---|
| 517 | else |
---|
| 518 | DataOut.Time(index,1)=index;%default |
---|
[27] | 519 | end |
---|
[880] | 520 | else % time from ImaDoc prevails TODO: correct |
---|
| 521 | DataOut.Time(index,1)=time(index);% |
---|
[330] | 522 | end |
---|
[881] | 523 | index |
---|
[880] | 524 | % record the number of missing input fields |
---|
| 525 | if ~isempty(errormsg) |
---|
| 526 | nbmissing=nbmissing+1; |
---|
| 527 | display(['index=' num2str(index) ':' errormsg]) |
---|
| 528 | end |
---|
[599] | 529 | end |
---|
[880] | 530 | |
---|
[599] | 531 | %%%%%%% END OF LOOP WITHIN A SLICE |
---|
| 532 | |
---|
| 533 | %remove time for global attributes if exists |
---|
| 534 | Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute)); |
---|
| 535 | if ~isempty(Time_index) |
---|
| 536 | DataOut.ListGlobalAttribute(Time_index)=[]; |
---|
| 537 | end |
---|
| 538 | DataOut.Conventions='uvmat'; |
---|
| 539 | for ivar=1:numel(DataOut.ListVarName) |
---|
| 540 | VarName=DataOut.ListVarName{ivar}; |
---|
| 541 | eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons |
---|
| 542 | end |
---|
| 543 | |
---|
| 544 | % add time dimension |
---|
| 545 | for ivar=1:length(Field.ListVarName) |
---|
[751] | 546 | DimCell=Field.VarDimName{ivar}; |
---|
| 547 | if ischar(DimCell),DimCell={DimCell};end |
---|
| 548 | if testsum(ivar)==2% variable for which time series is calculated |
---|
[599] | 549 | DataOut.VarDimName{ivar}=[{'Time'} DimCell]; |
---|
[751] | 550 | elseif testsum(ivar)==1 % variable represneting a fixed coordinate |
---|
[599] | 551 | DataOut.VarDimName{ivar}=DimCell; |
---|
[330] | 552 | end |
---|
[599] | 553 | end |
---|
| 554 | indexremove=find(~testsum); |
---|
| 555 | if ~isempty(indexremove) |
---|
| 556 | DataOut.ListVarName(1+indexremove)=[]; |
---|
| 557 | DataOut.VarDimName(indexremove)=[]; |
---|
| 558 | if isfield(DataOut,'Role') && ~isempty(DataOut.Role{1})%generaliser aus autres attributs |
---|
| 559 | DataOut.Role(1+indexremove)=[]; |
---|
[330] | 560 | end |
---|
[27] | 561 | end |
---|
[107] | 562 | |
---|
[599] | 563 | %shift variable attributes |
---|
| 564 | if isfield(DataOut,'VarAttribute') |
---|
| 565 | DataOut.VarAttribute=[{[]} DataOut.VarAttribute]; |
---|
| 566 | end |
---|
| 567 | DataOut.VarDimName=[{'Time'} DataOut.VarDimName]; |
---|
| 568 | DataOut.Action=Param.Action;%name of the processing programme |
---|
| 569 | test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant) |
---|
| 570 | if ~test_time |
---|
[970] | 571 | DataOut.Time=1:NbField; |
---|
[599] | 572 | end |
---|
| 573 | |
---|
| 574 | if ~isequal(nbmissing,0) |
---|
[668] | 575 | disp_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun) |
---|
[599] | 576 | end |
---|
| 577 | |
---|
[609] | 578 | %% name of result file |
---|
| 579 | OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j); |
---|
[599] | 580 | errormsg=struct2nc(OutputFile,DataOut); %save result file |
---|
| 581 | if isempty(errormsg) |
---|
| 582 | display([OutputFile ' written']) |
---|
| 583 | else |
---|
[668] | 584 | disp_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun) |
---|
[599] | 585 | end |
---|
| 586 | |
---|
[880] | 587 | %% plot the time series for (the last one in case of multislices) |
---|
| 588 | if checkrun %&& isfield(Param,'ProjObject') && strcmp(Param.ProjObject.Type,'points') |
---|
| 589 | %% open the result file with uvmat (in RUN mode) |
---|
| 590 | uvmat(OutputFile)% open the last result file with uvmat |
---|
[474] | 591 | end |
---|
[880] | 592 | % figure |
---|
| 593 | % haxes=axes; |
---|
| 594 | % plot_field(DataOut,haxes) |
---|
| 595 | % |
---|
| 596 | % %% display the result file using the GUI get_field |
---|
| 597 | % hget_field=findobj(allchild(0),'name','get_field'); |
---|
| 598 | % if ~isempty(hget_field) |
---|
| 599 | % delete(hget_field) |
---|
| 600 | % end |
---|
| 601 | % get_field(OutputFile,DataOut) |
---|
| 602 | % end |
---|
[27] | 603 | |
---|
| 604 | |
---|