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