| 1 | %'time_series': extract a time series after projection on an object (points , line..) |
|---|
| 2 | % this function can be used as a template for applying a global operation on a series of input fields |
|---|
| 3 | %------------------------------------------------------------------------ |
|---|
| 4 | % function GUI_input=time_series(Param) |
|---|
| 5 | % |
|---|
| 6 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 7 | % |
|---|
| 8 | %OUTPUT |
|---|
| 9 | % ParamOut: sets options in the GUI series.fig needed for the function |
|---|
| 10 | % |
|---|
| 11 | %INPUT: |
|---|
| 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 |
|---|
| 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 |
|---|
| 16 | % |
|---|
| 17 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
|---|
| 18 | % see the current structure Param) |
|---|
| 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 |
|---|
| 22 | % .OutputDirExt: directory extension for data outputs |
|---|
| 23 | % .Action: .ActionName: name of the current activated function |
|---|
| 24 | % .ActionPath: path of the current activated function |
|---|
| 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 | % |
|---|
| 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 |
|---|
| 33 | % .FieldName: name(s) of the field |
|---|
| 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 |
|---|
| 37 | % .Coord_y: name of y coordinate variable |
|---|
| 38 | % .Coord_x: name of x coordinate variable |
|---|
| 39 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
|---|
| 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 41 | |
|---|
| 42 | function ParamOut=time_series(Param) |
|---|
| 43 | |
|---|
| 44 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed |
|---|
| 45 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
|---|
| 46 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
|---|
| 47 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
|---|
| 48 | ParamOut.NbSlice='on'; %nbre of slices ('off' by default) |
|---|
| 49 | ParamOut.VelType='two';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
|---|
| 50 | ParamOut.FieldName='two';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
|---|
| 51 | ParamOut.FieldTransform = 'on';%can use a transform function |
|---|
| 52 | ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only) |
|---|
| 53 | ParamOut.ProjObject='on';%can use projection object(option 'off'/'on', |
|---|
| 54 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
|---|
| 55 | ParamOut.OutputDirExt='.tseries';%set the output dir extension |
|---|
| 56 | 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 |
|---|
| 57 | filecell=get_file_series(Param);%check existence of the first input file |
|---|
| 58 | if ~exist(filecell{1,1},'file') |
|---|
| 59 | msgbox_uvmat('WARNING','the first input file does not exist') |
|---|
| 60 | elseif isequal(size(Param.InputTable,1),1) && ~isfield(Param,'ProjObject') |
|---|
| 61 | msgbox_uvmat('WARNING','a projection object needs to be introduced for time_series') |
|---|
| 62 | end |
|---|
| 63 | return |
|---|
| 64 | end |
|---|
| 65 | |
|---|
| 66 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
|---|
| 67 | ParamOut=[]; %default output |
|---|
| 68 | %% read input parameters from an xml file if input is a file name (batch mode) |
|---|
| 69 | checkrun=1; |
|---|
| 70 | if ischar(Param) |
|---|
| 71 | Param=xml2struct(Param);% read Param as input file (batch case) |
|---|
| 72 | checkrun=0; |
|---|
| 73 | end |
|---|
| 74 | hseries=findobj(allchild(0),'Tag','series'); |
|---|
| 75 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
|---|
| 76 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
|---|
| 77 | |
|---|
| 78 | %% define the directory for result file (with path=RootPath{1}) |
|---|
| 79 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
|---|
| 80 | |
|---|
| 81 | %% root input file(s) name, type and index series |
|---|
| 82 | RootPath=Param.InputTable(:,1); |
|---|
| 83 | RootFile=Param.InputTable(:,3); |
|---|
| 84 | SubDir=Param.InputTable(:,2); |
|---|
| 85 | NomType=Param.InputTable(:,4); |
|---|
| 86 | FileExt=Param.InputTable(:,5); |
|---|
| 87 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
|---|
| 88 | %%%%%%%%%%%% |
|---|
| 89 | % The cell array filecell is the list of input file names, while |
|---|
| 90 | % filecell{iview,fileindex}: |
|---|
| 91 | % iview: line in the table corresponding to a given file series |
|---|
| 92 | % fileindex: file index within the file series, |
|---|
| 93 | % 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 |
|---|
| 94 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
|---|
| 95 | %%%%%%%%%%%% |
|---|
| 96 | nbview=numel(i1_series);%number of input file series (lines in InputTable) |
|---|
| 97 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
|---|
| 98 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
|---|
| 99 | nbfield=nbfield_j*nbfield_i; %total number of fields |
|---|
| 100 | |
|---|
| 101 | %% determine the file type on each line from the first input file |
|---|
| 102 | ImageTypeOptions={'image','multimage','mmreader','video'}; |
|---|
| 103 | NcTypeOptions={'netcdf','civx','civdata'}; |
|---|
| 104 | for iview=1:nbview |
|---|
| 105 | if ~exist(filecell{iview,1}','file') |
|---|
| 106 | displ_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun) |
|---|
| 107 | return |
|---|
| 108 | end |
|---|
| 109 | [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1}); |
|---|
| 110 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
|---|
| 111 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
|---|
| 112 | if ~isempty(j1_series{iview}) |
|---|
| 113 | frame_index{iview}=j1_series{iview}; |
|---|
| 114 | else |
|---|
| 115 | frame_index{iview}=i1_series{iview}; |
|---|
| 116 | end |
|---|
| 117 | end |
|---|
| 118 | |
|---|
| 119 | %% calibration data and timing: read the ImaDoc files |
|---|
| 120 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
|---|
| 121 | if size(time,1)>1 |
|---|
| 122 | diff_time=max(max(diff(time))); |
|---|
| 123 | if diff_time>0 |
|---|
| 124 | displ_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun) |
|---|
| 125 | end |
|---|
| 126 | time=time(1,:);% choose the time data from the first sequence |
|---|
| 127 | end |
|---|
| 128 | |
|---|
| 129 | %% coordinate transform or other user defined transform |
|---|
| 130 | transform_fct=[];%default |
|---|
| 131 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
|---|
| 132 | addpath(Param.FieldTransform.TransformPath) |
|---|
| 133 | transform_fct=str2func(Param.FieldTransform.TransformName); |
|---|
| 134 | rmpath(Param.FieldTransform.TransformPath) |
|---|
| 135 | end |
|---|
| 136 | |
|---|
| 137 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
|---|
| 138 | % EDIT FROM HERE |
|---|
| 139 | |
|---|
| 140 | %% check the validity of ctinput file types |
|---|
| 141 | if CheckImage{1} |
|---|
| 142 | FileExtOut='.png'; % write result as .png images for image inputs |
|---|
| 143 | elseif CheckNc{1} |
|---|
| 144 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
|---|
| 145 | else |
|---|
| 146 | displ_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun) |
|---|
| 147 | return |
|---|
| 148 | end |
|---|
| 149 | if nbview==2 && ~isequal(CheckImage{1},CheckImage{2}) |
|---|
| 150 | displ_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun) |
|---|
| 151 | return |
|---|
| 152 | end |
|---|
| 153 | |
|---|
| 154 | %% settings for the output file |
|---|
| 155 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file |
|---|
| 156 | first_i=i1_series{1}(1); |
|---|
| 157 | last_i=i1_series{1}(end); |
|---|
| 158 | if isempty(j1_series{1})% if there is no second index j |
|---|
| 159 | first_j=1;last_j=1; |
|---|
| 160 | else |
|---|
| 161 | first_j=j1_series{1}(1); |
|---|
| 162 | last_j=j1_series{1}(end); |
|---|
| 163 | end |
|---|
| 164 | |
|---|
| 165 | %% Set field names and velocity types |
|---|
| 166 | InputFields{1}=[];%default (case of images) |
|---|
| 167 | if isfield(Param,'InputFields') |
|---|
| 168 | InputFields{1}=Param.InputFields; |
|---|
| 169 | end |
|---|
| 170 | if nbview==2 |
|---|
| 171 | InputFields{2}=[];%default (case of images) |
|---|
| 172 | if isfield(Param,'InputFields') |
|---|
| 173 | InputFields{2}=Param.InputFields{1};%default |
|---|
| 174 | if isfield(Param.InputFields,'FieldName_1') |
|---|
| 175 | InputFields{2}.FieldName=Param.InputFields.FieldName_1; |
|---|
| 176 | if isfield(Param.InputFields,'VelType_1') |
|---|
| 177 | InputFields{2}.VelType=Param.InputFields.VelType_1; |
|---|
| 178 | end |
|---|
| 179 | end |
|---|
| 180 | end |
|---|
| 181 | end |
|---|
| 182 | |
|---|
| 183 | %% Initiate output fields |
|---|
| 184 | %initiate the output structure as a copy of the first input one (reproduce fields) |
|---|
| 185 | [DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1); |
|---|
| 186 | if ~isempty(errormsg) |
|---|
| 187 | displ_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg],checkrun) |
|---|
| 188 | return |
|---|
| 189 | end |
|---|
| 190 | time_1=[]; |
|---|
| 191 | if isfield(DataOut,'Time') |
|---|
| 192 | time_1=DataOut.Time(1); |
|---|
| 193 | end |
|---|
| 194 | if CheckNc{iview} |
|---|
| 195 | if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute)) |
|---|
| 196 | DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute]; |
|---|
| 197 | end |
|---|
| 198 | DataOut.Conventions='uvmat'; |
|---|
| 199 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}]; |
|---|
| 200 | ActionKey='Action'; |
|---|
| 201 | while isfield(DataOut,ActionKey) |
|---|
| 202 | ActionKey=[ActionKey '_1']; |
|---|
| 203 | end |
|---|
| 204 | DataOut.(ActionKey)=Param.Action; |
|---|
| 205 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}]; |
|---|
| 206 | if isfield(DataOut,'Time') |
|---|
| 207 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}]; |
|---|
| 208 | end |
|---|
| 209 | end |
|---|
| 210 | |
|---|
| 211 | nbmissing=0; %number of undetected files |
|---|
| 212 | % for i_slice=1:NbSlice |
|---|
| 213 | %index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice |
|---|
| 214 | nbfile=0; |
|---|
| 215 | nbmissing=0; |
|---|
| 216 | |
|---|
| 217 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
|---|
| 218 | for index=1:nbfield |
|---|
| 219 | update_waitbar(WaitbarHandle,index/nbfield) |
|---|
| 220 | if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
|---|
| 221 | disp('program stopped by user') |
|---|
| 222 | break % leave the loop if stop is ordered |
|---|
| 223 | end |
|---|
| 224 | Data=cell(1,nbview);%initiate the set Data; |
|---|
| 225 | nbtime=0; |
|---|
| 226 | dt=[]; |
|---|
| 227 | %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%% |
|---|
| 228 | for iview=1:nbview |
|---|
| 229 | % reading input file(s) |
|---|
| 230 | [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index)); |
|---|
| 231 | if ~isempty(errormsg) |
|---|
| 232 | errormsg=['time_series / read_field / ' errormsg]; |
|---|
| 233 | display(errormsg) |
|---|
| 234 | break |
|---|
| 235 | end |
|---|
| 236 | if ~isempty(NbSlice_calib) |
|---|
| 237 | Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform |
|---|
| 238 | end |
|---|
| 239 | end |
|---|
| 240 | if isempty(errormsg) |
|---|
| 241 | Field=Data{1}; % default input field structure |
|---|
| 242 | % coordinate transform (or other user defined transform) |
|---|
| 243 | if ~isempty(transform_fct) |
|---|
| 244 | switch nargin(transform_fct) |
|---|
| 245 | case 4 |
|---|
| 246 | if length(Data)==2 |
|---|
| 247 | Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); |
|---|
| 248 | else |
|---|
| 249 | Field=transform_fct(Data{1},XmlData{1}); |
|---|
| 250 | end |
|---|
| 251 | case 3 |
|---|
| 252 | if length(Data)==2 |
|---|
| 253 | Field=transform_fct(Data{1},XmlData{1},Data{2}); |
|---|
| 254 | else |
|---|
| 255 | Field=transform_fct(Data{1},XmlData{1}); |
|---|
| 256 | end |
|---|
| 257 | case 2 |
|---|
| 258 | Field=transform_fct(Data{1},XmlData{1}); |
|---|
| 259 | case 1 |
|---|
| 260 | Field=transform_fct(Data{1}); |
|---|
| 261 | end |
|---|
| 262 | end |
|---|
| 263 | |
|---|
| 264 | % calculate tps coefficients if needed |
|---|
| 265 | if isfield(Param.ProjObject,'ProjMode')&& strcmp(Param.ProjObject.ProjMode,'interp_tps') |
|---|
| 266 | Field=tps_coeff_field(Field,check_proj_tps); |
|---|
| 267 | end |
|---|
| 268 | |
|---|
| 269 | %field projection on an object |
|---|
| 270 | if Param.CheckObject |
|---|
| 271 | [Field,errormsg]=proj_field(Field,Param.ProjObject); |
|---|
| 272 | if ~isempty(errormsg) |
|---|
| 273 | msgbox_uvmat('ERROR',['time_series / proj_field / ' errormsg]) |
|---|
| 274 | return |
|---|
| 275 | end |
|---|
| 276 | end |
|---|
| 277 | nbfile=nbfile+1; |
|---|
| 278 | |
|---|
| 279 | % initiate the time series at the first iteration |
|---|
| 280 | if nbfile==1 |
|---|
| 281 | % stop program if the first field reading is in error |
|---|
| 282 | if ~isempty(errormsg) |
|---|
| 283 | displ_uvmat('ERROR',['time_series / sub_field / ' errormsg],checkrun) |
|---|
| 284 | return |
|---|
| 285 | end |
|---|
| 286 | DataOut=Field;%default |
|---|
| 287 | DataOut.NbDim=Field.NbDim+1; %add the time dimension for plots |
|---|
| 288 | nbvar=length(Field.ListVarName); |
|---|
| 289 | if nbvar==0 |
|---|
| 290 | displ_uvmat('ERROR','no input variable selected',checkrun) |
|---|
| 291 | return |
|---|
| 292 | end |
|---|
| 293 | testsum=2*ones(1,nbvar);%initiate flag for action on each variable |
|---|
| 294 | if isfield(Field,'VarAttribute') % look for coordinate and flag variables |
|---|
| 295 | for ivar=1:nbvar |
|---|
| 296 | if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') |
|---|
| 297 | var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable |
|---|
| 298 | if isequal(var_role,'errorflag') |
|---|
| 299 | displ_uvmat('ERROR','do not handle error flags in time series',checkrun) |
|---|
| 300 | return |
|---|
| 301 | end |
|---|
| 302 | if isequal(var_role,'warnflag') |
|---|
| 303 | testsum(ivar)=0; % not recorded variable |
|---|
| 304 | eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable |
|---|
| 305 | end |
|---|
| 306 | if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|... |
|---|
| 307 | isequal(var_role,'coord_z')|isequal(var_role,'coord') |
|---|
| 308 | testsum(ivar)=1; %constant coordinates, record without time evolution |
|---|
| 309 | end |
|---|
| 310 | end |
|---|
| 311 | % check whether the variable ivar is a dimension variable |
|---|
| 312 | DimCell=Field.VarDimName{ivar}; |
|---|
| 313 | if ischar(DimCell) |
|---|
| 314 | DimCell={DimCell}; |
|---|
| 315 | end |
|---|
| 316 | if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables |
|---|
| 317 | testsum(ivar)=1; |
|---|
| 318 | end |
|---|
| 319 | end |
|---|
| 320 | end |
|---|
| 321 | for ivar=1:nbvar |
|---|
| 322 | if testsum(ivar)==2 |
|---|
| 323 | eval(['DataOut.' Field.ListVarName{ivar} '=[];']) |
|---|
| 324 | end |
|---|
| 325 | end |
|---|
| 326 | DataOut.ListVarName=[{'Time'} DataOut.ListVarName]; |
|---|
| 327 | end |
|---|
| 328 | |
|---|
| 329 | % add data to the current field |
|---|
| 330 | for ivar=1:length(Field.ListVarName) |
|---|
| 331 | VarName=Field.ListVarName{ivar}; |
|---|
| 332 | VarVal=Field.(VarName); |
|---|
| 333 | if testsum(ivar)==2% test for recorded variable |
|---|
| 334 | if isempty(errormsg) |
|---|
| 335 | if isequal(Param.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode |
|---|
| 336 | if isempty(VarVal) |
|---|
| 337 | displ_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(index))],checkrun) |
|---|
| 338 | return |
|---|
| 339 | end |
|---|
| 340 | VarVal=mean(VarVal,1); |
|---|
| 341 | end |
|---|
| 342 | VarVal=shiftdim(VarVal,-1); %shift dimension |
|---|
| 343 | DataOut.(VarName)=cat(1,DataOut.(VarName),VarVal);%concanete the current field to the time series |
|---|
| 344 | else |
|---|
| 345 | DataOut.(VarName)=cat(1,DataOut.(VarName),0);% put each variable to 0 in case of input reading error |
|---|
| 346 | end |
|---|
| 347 | elseif testsum(ivar)==1% variable representing fixed coordinates |
|---|
| 348 | VarInit=DataOut.(VarName); |
|---|
| 349 | if isempty(errormsg) && ~isequal(VarVal,VarInit) |
|---|
| 350 | displ_uvmat('ERROR',['time series requires constant coordinates ' VarName ': use projection mode interp'],checkrun) |
|---|
| 351 | return |
|---|
| 352 | end |
|---|
| 353 | end |
|---|
| 354 | end |
|---|
| 355 | |
|---|
| 356 | % record the time: |
|---|
| 357 | if isempty(time)% time not set by xml filer(s) |
|---|
| 358 | if isfield(Data{1},'Time') |
|---|
| 359 | DataOut.Time(nbfile,1)=Field.Time; |
|---|
| 360 | else |
|---|
| 361 | DataOut.Time(nbfile,1)=index;%default |
|---|
| 362 | end |
|---|
| 363 | else % time from ImaDoc prevails TODO: correct |
|---|
| 364 | DataOut.Time(nbfile,1)=time(index);% |
|---|
| 365 | end |
|---|
| 366 | |
|---|
| 367 | % record the number of missing input fields |
|---|
| 368 | if ~isempty(errormsg) |
|---|
| 369 | nbmissing=nbmissing+1; |
|---|
| 370 | display(['index=' num2str(index) ':' errormsg]) |
|---|
| 371 | end |
|---|
| 372 | end |
|---|
| 373 | |
|---|
| 374 | end |
|---|
| 375 | %%%%%%% END OF LOOP WITHIN A SLICE |
|---|
| 376 | |
|---|
| 377 | %remove time for global attributes if exists |
|---|
| 378 | Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute)); |
|---|
| 379 | if ~isempty(Time_index) |
|---|
| 380 | DataOut.ListGlobalAttribute(Time_index)=[]; |
|---|
| 381 | end |
|---|
| 382 | DataOut.Conventions='uvmat'; |
|---|
| 383 | for ivar=1:numel(DataOut.ListVarName) |
|---|
| 384 | VarName=DataOut.ListVarName{ivar}; |
|---|
| 385 | eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons |
|---|
| 386 | end |
|---|
| 387 | |
|---|
| 388 | % add time dimension |
|---|
| 389 | for ivar=1:length(Field.ListVarName) |
|---|
| 390 | DimCell=Field.VarDimName(ivar); |
|---|
| 391 | if testsum(ivar)==2%variable used as time series |
|---|
| 392 | DataOut.VarDimName{ivar}=[{'Time'} DimCell]; |
|---|
| 393 | elseif testsum(ivar)==1 |
|---|
| 394 | DataOut.VarDimName{ivar}=DimCell; |
|---|
| 395 | end |
|---|
| 396 | end |
|---|
| 397 | indexremove=find(~testsum); |
|---|
| 398 | if ~isempty(indexremove) |
|---|
| 399 | DataOut.ListVarName(1+indexremove)=[]; |
|---|
| 400 | DataOut.VarDimName(indexremove)=[]; |
|---|
| 401 | if isfield(DataOut,'Role') && ~isempty(DataOut.Role{1})%generaliser aus autres attributs |
|---|
| 402 | DataOut.Role(1+indexremove)=[]; |
|---|
| 403 | end |
|---|
| 404 | end |
|---|
| 405 | |
|---|
| 406 | %shift variable attributes |
|---|
| 407 | if isfield(DataOut,'VarAttribute') |
|---|
| 408 | DataOut.VarAttribute=[{[]} DataOut.VarAttribute]; |
|---|
| 409 | end |
|---|
| 410 | DataOut.VarDimName=[{'Time'} DataOut.VarDimName]; |
|---|
| 411 | DataOut.Action=Param.Action;%name of the processing programme |
|---|
| 412 | test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant) |
|---|
| 413 | if ~test_time |
|---|
| 414 | DataOut.Time=1:nbfield; |
|---|
| 415 | end |
|---|
| 416 | |
|---|
| 417 | % display nbmissing |
|---|
| 418 | if ~isequal(nbmissing,0) |
|---|
| 419 | displ_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun) |
|---|
| 420 | end |
|---|
| 421 | |
|---|
| 422 | %% name of result file |
|---|
| 423 | OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j); |
|---|
| 424 | errormsg=struct2nc(OutputFile,DataOut); %save result file |
|---|
| 425 | if isempty(errormsg) |
|---|
| 426 | display([OutputFile ' written']) |
|---|
| 427 | else |
|---|
| 428 | displ_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun) |
|---|
| 429 | end |
|---|
| 430 | |
|---|
| 431 | %% plot the time series (the last one in case of multislices) |
|---|
| 432 | if checkrun |
|---|
| 433 | figure |
|---|
| 434 | haxes=axes; |
|---|
| 435 | plot_field(DataOut,haxes) |
|---|
| 436 | |
|---|
| 437 | %% display the result file using the GUI get_field |
|---|
| 438 | hget_field=findobj(allchild(0),'name','get_field'); |
|---|
| 439 | if ~isempty(hget_field) |
|---|
| 440 | delete(hget_field) |
|---|
| 441 | end |
|---|
| 442 | get_field(OutputFile,DataOut) |
|---|
| 443 | end |
|---|
| 444 | |
|---|
| 445 | |
|---|