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

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

bugs corrected in series, transform functions with input parameters introduced, civ/deformation corrected (sign)

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