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

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

various bug fix

File size: 26.1 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    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)
222end
223
224%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
225% EDIT FROM HERE
226
227%% check the validity of  the input file types
228if ~CheckImage{1}&&~CheckNc{1}
229    disp_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun)
230    return
231end
232if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
233    disp_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun)
234    return
235end
236
237%% settings for the output file
238FileExtOut='.nc';% write result as .nc files for netcdf inputs
239NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file
240first_i=i1_series{1}(1);
241last_i=i1_series{1}(end);
242if isempty(j1_series{1})% if there is no second index j
243    first_j=1;last_j=1;
244else
245    first_j=j1_series{1}(1);
246    last_j=j1_series{1}(end);
247end
248
249%% Set field names and velocity types
250InputFields{1}=[];%default (case of images)
251if nbview==2
252    InputFields{2}=[];%default (case of images)
253end
254if isfield(Param,'InputFields')
255    InputFields{1}=Param.InputFields;
256    if nbview==2
257        InputFields{2}=Param.InputFields;%default
258        if isfield(Param.InputFields,'FieldName_1')
259            InputFields{2}.FieldName=Param.InputFields.FieldName_1;
260            if isfield(Param.InputFields,'VelType_1')
261                InputFields{2}.VelType=Param.InputFields.VelType_1;
262            end
263        end
264    end
265end
266
267%% Initiate output fields
268%initiate the output structure as a copy of the first input one (reproduce fields)
269[DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
270if ~isempty(errormsg)
271    disp_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg],checkrun)
272    return
273end
274time_1=[];
275if isfield(DataOut,'Time')
276    time_1=DataOut.Time(1);
277end
278if CheckNc{iview}
279    if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
280        DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
281    end
282    DataOut.Conventions='uvmat';
283    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
284    ActionKey='Action';
285    while isfield(DataOut,ActionKey)
286        ActionKey=[ActionKey '_1'];
287    end
288    DataOut.(ActionKey)=Param.Action;
289    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
290    if isfield(DataOut,'Time')
291        DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
292    end
293end
294
295nbfile=0;% not used , to check
296nbmissing=0;
297VarMesh=[];
298checkhisto=0;
299if isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'})
300    checkhisto=1;
301    if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'VarMesh')%case of histograms
302        VarMesh=Param.ActionInput.VarMesh;
303    end
304end
305
306%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
307for index=1:nbfield
308    update_waitbar(WaitbarHandle,index/nbfield)
309    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
310        disp('program stopped by user')
311        break % leave the loop if stop is ordered
312    end
313    Data=cell(1,nbview);%initiate the set Data;
314    nbtime=0;
315    dt=[];
316    %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
317    for iview=1:nbview
318        % reading input file(s)
319        [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
320        if ~isempty(errormsg)
321            errormsg=['time_series / read_field / ' errormsg];
322            disp(errormsg)
323            break% exit the loop on iview
324        end
325        if ~isempty(NbSlice_calib)
326            Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
327        end
328    end
329    if ~isempty(errormsg)
330        continue %in case of input error skip the current input field, go to next index
331    end
332    Field=Data{1}; % default input field structure
333    % coordinate transform (or other user defined transform)
334    if ~isempty(transform_fct)
335        switch nargin(transform_fct)
336            case 4
337                if length(Data)==2
338                    Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
339                else
340                    Field=transform_fct(Data{1},XmlData{1});
341                end
342            case 3
343                if length(Data)==2
344                    Field=transform_fct(Data{1},XmlData{1},Data{2});
345                else
346                    Field=transform_fct(Data{1},XmlData{1});
347                end
348            case 2
349                Field=transform_fct(Data{1},XmlData{1});
350            case 1
351                Field=transform_fct(Data{1});
352        end
353    end
354   
355    %field projection on an object
356    if Param.CheckObject
357        % calculate tps coefficients if needed
358        if isfield(Param.ProjObject,'ProjMode')&& strcmp(Param.ProjObject.ProjMode,'interp_tps')
359            Field=tps_coeff_field(Field,check_proj_tps);
360        end
361        [Field,errormsg]=proj_field(Field,Param.ProjObject,VarMesh);
362        if ~isempty(errormsg)
363            disp_uvmat('ERROR',['time_series / proj_field / ' errormsg],checkrun)
364            return
365        end
366    end
367    %         nbfile=nbfile+1;
368   
369    % initiate the time series at the first iteration
370    if index==1
371        % stop program if the first field reading is in error
372        if ~isempty(errormsg)
373            disp_uvmat('ERROR',['time_series / sub_field / ' errormsg],checkrun)
374            return
375        end
376        if ~isfield(Field,'ListVarName')
377            disp_uvmat('ERROR','no variable in the projected field',checkrun)
378            return
379        end
380        DataOut=Field;%output reproduced the first projected field by default
381        nbvar=length(Field.ListVarName);
382        if nbvar==0
383            disp_uvmat('ERROR','no input variable selected',checkrun)
384            return
385        end
386        if checkhisto%case of histograms
387            testsum=zeros(1,nbvar);%initiate flag for action on each variable
388            for ivar=1:numel(Field.ListVarName)% list of variable names before projection (histogram)
389                VarName=Field.ListVarName{ivar};
390                if isfield(Data{1},VarName)
391                    DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Histo']}];
392                    DataOut.VarDimName=[DataOut.VarDimName {{'Time',VarName}}];
393%                     if isfield(DataOut.VarAttribute{ivar},'Role')
394%                     DataOut.VarAttribute{ivar}=rmfield(DataOut.VarAttribute{ivar},'Role');
395%                     end
396                    StatName=pdf2stat;% get the names of statistical quantities to calcuilate at each time
397                    for istat=1:numel(StatName)
398                        DataOut.ListVarName=[DataOut.ListVarName {[VarName StatName{istat}]}];
399                        DataOut.VarDimName=[DataOut.VarDimName {'Time'}];
400                    end
401                    testsum(ivar)=1;
402                    DataOut.(VarName)=Field.(VarName);
403                    DataOut.([VarName 'Histo'])=zeros([nbfield numel(DataOut.(VarName))]);
404                    VarMesh=Field.(VarName)(2)-Field.(VarName)(1);
405                end
406            end
407            disp(['mesh for histogram = ' num2str(VarMesh)])
408        else
409            testsum=2*ones(1,nbvar);%initiate flag for action on each variable
410            if isfield(Field,'VarAttribute') % look for coordinate and flag variables
411                for ivar=1:nbvar
412                    if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
413                        var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
414                        if isequal(var_role,'errorflag')
415                            disp_uvmat('ERROR','do not handle error flags in time series',checkrun)
416                            return
417                        end
418                        if isequal(var_role,'warnflag')
419                            testsum(ivar)=0;  % not recorded variable
420                            eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable
421                        end
422                        if strcmp(var_role,'coord_x')||strcmp(var_role,'coord_y')||strcmp(var_role,'coord_z')||strcmp(var_role,'coord')
423                            testsum(ivar)=1; %constant coordinates, record without time evolution
424                        end
425                    end
426                    % check whether the variable ivar is a dimension variable
427                    DimCell=Field.VarDimName{ivar};
428                    if ischar(DimCell)
429                        DimCell={DimCell};
430                    end
431                    if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
432                        testsum(ivar)=1;
433                    end
434                end
435            end
436            for ivar=1:nbvar
437                if testsum(ivar)==2
438                    VarName=Field.ListVarName{ivar};
439                    siz=size(Field.(VarName));
440                    DataOut.(VarName)=zeros([nbfield siz]);
441                end
442            end
443        end
444        DataOut.ListVarName=[{'Time'} DataOut.ListVarName];
445    end
446    % end initialisation for index==1
447   
448    % append data from the current field
449
450    if checkhisto % case of histogram (projection mode=inside or outside)
451        for ivar=1:length(Field.ListVarName)
452            VarName=Field.ListVarName{ivar};
453            if isfield(Data{1},VarName)
454                MaxValue=max(DataOut.(VarName));% current max of histogram absissa
455                MinValue=min(DataOut.(VarName));% current min of histogram absissa
456                MaxIndex=round(MaxValue/VarMesh);
457                MinIndex=round(MinValue/VarMesh);
458                MaxIndex_new=round(max(Field.(VarName)/VarMesh));% max of the current field
459                MinIndex_new=round(min(Field.(VarName)/VarMesh));
460                if MaxIndex_new>MaxIndex% the variable max for the current field exceeds the previous one
461                    DataOut.(VarName)=[DataOut.(VarName) VarMesh*(MaxIndex+1:MaxIndex_new)];% append the new variable values
462                    DataOut.([VarName 'Histo'])=[DataOut.([VarName 'Histo']) zeros(nbfield,MaxIndex_new-MaxIndex)]; % append the new histo values
463                end
464                if MinIndex_new <= MinIndex-1
465                    DataOut.(VarName)=[VarMesh*(MinIndex_new:MinIndex-1) DataOut.(VarName)];% insert the new variable values
466                    DataOut.([VarName 'Histo'])=[zeros(nbfield,MinIndex-MinIndex_new) DataOut.([VarName 'Histo'])];% insert the new histo values
467                    ind_start=1;
468                else
469                    ind_start=MinIndex_new-MinIndex+1;
470                end
471                DataOut.([VarName 'Histo'])(index,ind_start:ind_start+MaxIndex_new-MinIndex_new)=...
472                    DataOut.([VarName 'Histo'])(index,ind_start:ind_start+MaxIndex_new-MinIndex_new)+Field.([VarName 'Histo']);
473                VarVal=pdf2stat((Field.(VarName))',(Field.([VarName 'Histo']))');% max of the current field
474                for istat=1:numel(VarVal)
475                    DataOut.([VarName StatName{istat}])(index)=VarVal(istat);
476                end
477            end
478        end
479    else % not histogram
480        for ivar=1:length(Field.ListVarName)
481            VarName=Field.ListVarName{ivar};
482            VarVal=Field.(VarName);
483            if testsum(ivar)==2% test for recorded variable
484                if isempty(errormsg)
485                    VarVal=shiftdim(VarVal,-1); %shift dimension
486                    DataOut.(VarName)(index,:,:)=VarVal;%concanete the current field to the time series
487                end
488            elseif testsum(ivar)==1% variable representing fixed coordinates
489                VarInit=DataOut.(VarName);
490                if isempty(errormsg) && ~isequal(VarVal,VarInit)
491                    disp_uvmat('ERROR',['time series requires constant coordinates ' VarName ': use projection mode interp'],checkrun)
492                    return
493                end
494            end
495        end
496    end
497   
498    % record the time:
499    if isempty(time)% time not set by xml filer(s)
500        if isfield(Data{1},'Time')
501            DataOut.Time(index,1)=Field.Time;
502        else
503            DataOut.Time(index,1)=index;%default
504        end
505    else % time from ImaDoc prevails  TODO: correct
506        DataOut.Time(index,1)=time(index);%
507    end
508    index
509    % record the number of missing input fields
510    if ~isempty(errormsg)
511        nbmissing=nbmissing+1;
512        display(['index=' num2str(index) ':' errormsg])
513    end
514end
515
516%%%%%%% END OF LOOP WITHIN A SLICE
517
518%remove time for global attributes if exists
519Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute));
520if ~isempty(Time_index)
521    DataOut.ListGlobalAttribute(Time_index)=[];
522end
523DataOut.Conventions='uvmat';
524for ivar=1:numel(DataOut.ListVarName)
525    VarName=DataOut.ListVarName{ivar};
526    eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons
527end
528
529% add time dimension
530for ivar=1:length(Field.ListVarName)
531    DimCell=Field.VarDimName{ivar};
532    if ischar(DimCell),DimCell={DimCell};end
533    if testsum(ivar)==2% variable for which time series is calculated
534        DataOut.VarDimName{ivar}=[{'Time'} DimCell];
535    elseif testsum(ivar)==1 % variable represneting a fixed coordinate
536        DataOut.VarDimName{ivar}=DimCell;
537    end
538end
539indexremove=find(~testsum);
540if ~isempty(indexremove)
541    DataOut.ListVarName(1+indexremove)=[];
542    DataOut.VarDimName(indexremove)=[];
543    if isfield(DataOut,'Role') && ~isempty(DataOut.Role{1})%generaliser aus autres attributs
544        DataOut.Role(1+indexremove)=[];
545    end
546end
547
548%shift variable attributes
549if isfield(DataOut,'VarAttribute')
550    DataOut.VarAttribute=[{[]} DataOut.VarAttribute];
551end
552DataOut.VarDimName=[{'Time'} DataOut.VarDimName];
553DataOut.Action=Param.Action;%name of the processing programme
554test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant)
555if ~test_time
556    DataOut.Time=1:nbfield;
557end
558
559% %case of histograms
560% if checkhisto
561%     for ivar=1:numel(Field.ListVarName)
562%         VarName=Field.ListVarName{ivar};
563%         if isfield(Data{1},VarName)
564%             DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Histo']}];
565%             DataOut.VarDimName=[DataOut.VarDimName {{'Time',VarName}}];
566%         end
567%     end
568% end
569% display nbmissing
570if ~isequal(nbmissing,0)
571    disp_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun)
572end
573
574%% name of result file
575OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j);
576errormsg=struct2nc(OutputFile,DataOut); %save result file
577if isempty(errormsg)
578    display([OutputFile ' written'])
579else
580    disp_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun)
581end
582
583%% plot the time series for  (the last one in case of multislices)
584if checkrun %&& isfield(Param,'ProjObject') && strcmp(Param.ProjObject.Type,'points')
585    %% open the result file with uvmat (in RUN mode)
586    uvmat(OutputFile)% open the last result file with uvmat
587end
588%     figure
589%     haxes=axes;
590%     plot_field(DataOut,haxes)
591%     
592%     %% display the result file using the GUI get_field
593%     hget_field=findobj(allchild(0),'name','get_field');
594%     if ~isempty(hget_field)
595%         delete(hget_field)
596%     end
597%     get_field(OutputFile,DataOut)
598% end
599
600
Note: See TracBrowser for help on using the repository browser.