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

Last change on this file since 912 was 908, checked in by g7moreau, 10 years ago
  • Update Copyright to 2015
File size: 26.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-2015, 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    hhseries=guidata(hseries);
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
86   
87    % introduce bin size for histograms
88    if isfield(Param,'CheckObject') &&Param.CheckObject
89        SeriesData=get(hseries,'UserData');
90        if ismember(SeriesData.ProjObject.ProjMode,{'inside','outside'})
91            answer=msgbox_uvmat('INPUT_TXT','set bin size for histograms (or keep ''auto'' by default)?','auto');
92            ParamOut.ActionInput.VarMesh=str2num(answer);
93        end
94    end
95   
96    % test for subtraction
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,:))
108        end
109    end
110   
111    % check the existence of the first and last file in the series
112    first_j=[];
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'])
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
130    end
131    return
132end
133
134%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
135ParamOut=[]; %default output
136%% read input parameters from an xml file if input is a file name (batch mode)
137checkrun=1;
138if ischar(Param)
139    Param=xml2struct(Param);% read Param as input file (batch case)
140    checkrun=0;
141end
142hseries=findobj(allchild(0),'Tag','series');
143RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
144WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
145
146%% define the directory for result file (with path=RootPath{1})
147OutputDir=[Param.OutputSubDir Param.OutputDirExt];
148
149%% root input file(s) name, type and index series
150RootPath=Param.InputTable(:,1);
151RootFile=Param.InputTable(:,3);
152SubDir=Param.InputTable(:,2);
153NomType=Param.InputTable(:,4);
154FileExt=Param.InputTable(:,5);
155hdisp=disp_uvmat('WAITING...','checking the file series',checkrun);
156[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
157if ~isempty(hdisp),delete(hdisp),end;
158%%%%%%%%%%%%
159% The cell array filecell is the list of input file names, while
160% filecell{iview,fileindex}:
161%        iview: line in the table corresponding to a given file series
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
164% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
165%%%%%%%%%%%%
166nbview=numel(i1_series);%number of input file series (lines in InputTable)
167nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
168nbfield_i=size(i1_series{1},2); %nb of fields for the i index
169nbfield=nbfield_j*nbfield_i; %total number of fields
170
171%% determine the file type on each line from the first input file
172ImageTypeOptions={'image','multimage','mmreader','video'};
173NcTypeOptions={'netcdf','civx','civdata'};
174FileType=cell(1,nbview);
175FileInfo=cell(1,nbview);
176MovieObject=cell(1,nbview);
177CheckImage=cell(1,nbview);
178CheckNc=cell(1,nbview);
179frame_index=cell(1,nbview);
180
181for iview=1:nbview
182    if ~exist(filecell{iview,1}','file')
183        disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
184        return
185    end
186    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
187    FileType{iview}=FileInfo{iview}.FileType;
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
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
195    if isempty(j1_series{iview})
196        frame_index{iview}=i1_series{iview};
197    else
198        frame_index{iview}=j1_series{iview};
199    end
200end
201
202%% calibration data and timing: read the ImaDoc files
203[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
204if ~isempty(errormsg)
205    disp_uvmat('ERROR',['error in reading xmlfile: ' errormsg],checkrun)
206    return
207end
208if size(time,1)>1
209    diff_time=max(max(diff(time)));
210    if diff_time>0
211        disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
212    end
213    time=time(1,:);% choose the time data from the first sequence
214end
215
216%% coordinate transform or other user defined transform
217transform_fct=[];%default
218if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
219    addpath(Param.FieldTransform.TransformPath)
220    transform_fct=str2func(Param.FieldTransform.TransformName);
221    rmpath(Param.FieldTransform.TransformPath)
222    if isfield(Param,'TransformInput')
223        XmlData{1}.TransformInput=Param.TransformInput;
224    end
225end
226
227%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
228% EDIT FROM HERE
229
230%% check the validity of  the input file types
231if ~CheckImage{1}&&~CheckNc{1}
232    disp_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun)
233    return
234end
235if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
236    disp_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun)
237    return
238end
239
240%% settings for the output file
241FileExtOut='.nc';% write result as .nc files for netcdf inputs
242NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file
243first_i=i1_series{1}(1);
244last_i=i1_series{1}(end);
245if isempty(j1_series{1})% if there is no second index j
246    first_j=1;last_j=1;
247else
248    first_j=j1_series{1}(1);
249    last_j=j1_series{1}(end);
250end
251
252%% Set field names and velocity types
253InputFields{1}=[];%default (case of images)
254if nbview==2
255    InputFields{2}=[];%default (case of images)
256end
257if isfield(Param,'InputFields')
258    InputFields{1}=Param.InputFields;
259    if nbview==2
260        InputFields{2}=Param.InputFields;%default
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
268end
269
270%% Initiate output fields
271%initiate the output structure as a copy of the first input one (reproduce fields)
272[DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
273if ~isempty(errormsg)
274    disp_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg],checkrun)
275    return
276end
277time_1=[];
278if isfield(DataOut,'Time')
279    time_1=DataOut.Time(1);
280end
281if 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
296end
297
298nbfile=0;% not used , to check
299nbmissing=0;
300VarMesh=[];
301checkhisto=0;
302if isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'})
303    checkhisto=1;
304    if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'VarMesh')%case of histograms
305        VarMesh=Param.ActionInput.VarMesh;
306    else
307        VarMesh=[];
308        disp_uvmat('WARNING','automatic bin size for histograms, select time_series again to set the value',checkrun)
309    end
310end
311
312%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
313for index=1:nbfield
314    update_waitbar(WaitbarHandle,index/nbfield)
315    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
316        disp('program stopped by user')
317        break % leave the loop if stop is ordered
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];
328            disp(errormsg)
329            break% exit the loop on iview
330        end
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
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
346                    Field=transform_fct(Data{1},XmlData{1});
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});
358        end
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);
366        end
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'}];
406                    end
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);
411                end
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
423                        end
424                        if isequal(var_role,'warnflag')
425                            testsum(ivar)=0;  % not recorded variable
426                            eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable
427                        end
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
430                        end
431                    end
432                    % check whether the variable ivar is a dimension variable
433                    DimCell=Field.VarDimName{ivar};
434                    if ischar(DimCell)
435                        DimCell={DimCell};
436                    end
437                    if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
438                        testsum(ivar)=1;
439                    end
440                end
441            end
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]);
447                end
448            end
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
469                end
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']);
479                VarVal=pdf2stat((Field.(VarName))',(Field.([VarName 'Histo']))');% max of the current field
480                for istat=1:numel(VarVal)
481                    DataOut.([VarName StatName{istat}])(index)=VarVal(istat);
482                end
483            end
484        end
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
500            end
501        end
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
510        end
511    else % time from ImaDoc prevails  TODO: correct
512        DataOut.Time(index,1)=time(index);%
513    end
514    index
515    % record the number of missing input fields
516    if ~isempty(errormsg)
517        nbmissing=nbmissing+1;
518        display(['index=' num2str(index) ':' errormsg])
519    end
520end
521
522%%%%%%% END OF LOOP WITHIN A SLICE
523
524%remove time for global attributes if exists
525Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute));
526if ~isempty(Time_index)
527    DataOut.ListGlobalAttribute(Time_index)=[];
528end
529DataOut.Conventions='uvmat';
530for ivar=1:numel(DataOut.ListVarName)
531    VarName=DataOut.ListVarName{ivar};
532    eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons
533end
534
535% add time dimension
536for ivar=1:length(Field.ListVarName)
537    DimCell=Field.VarDimName{ivar};
538    if ischar(DimCell),DimCell={DimCell};end
539    if testsum(ivar)==2% variable for which time series is calculated
540        DataOut.VarDimName{ivar}=[{'Time'} DimCell];
541    elseif testsum(ivar)==1 % variable represneting a fixed coordinate
542        DataOut.VarDimName{ivar}=DimCell;
543    end
544end
545indexremove=find(~testsum);
546if ~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)=[];
551    end
552end
553
554%shift variable attributes
555if isfield(DataOut,'VarAttribute')
556    DataOut.VarAttribute=[{[]} DataOut.VarAttribute];
557end
558DataOut.VarDimName=[{'Time'} DataOut.VarDimName];
559DataOut.Action=Param.Action;%name of the processing programme
560test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant)
561if ~test_time
562    DataOut.Time=1:nbfield;
563end
564
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
575% display nbmissing
576if ~isequal(nbmissing,0)
577    disp_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun)
578end
579
580%% name of result file
581OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j);
582errormsg=struct2nc(OutputFile,DataOut); %save result file
583if isempty(errormsg)
584    display([OutputFile ' written'])
585else
586    disp_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun)
587end
588
589%% plot the time series for  (the last one in case of multislices)
590if 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
593end
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
605
606
Note: See TracBrowser for help on using the repository browser.