source: trunk/src/series/time_series.m @ 874

Last change on this file since 874 was 874, checked in by sommeria, 9 years ago

merge_proj corrected + various bugs

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