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