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

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

time serie input messages improved

File size: 25.2 KB
RevLine 
[572]1%'time_series': extract a time series after projection on an object (points , line..)
[457]2% this function can be used as a template for applying a global operation on a series of input fields
[169]3%------------------------------------------------------------------------
[374]4% function GUI_input=time_series(Param)
[169]5%
[457]6%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
7%
[169]8%OUTPUT
[596]9% ParamOut: sets options in the GUI series.fig needed for the function
[169]10%
11%INPUT:
[457]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
[596]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
[169]16%
[596]17% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
18% see the current structure Param)
[457]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
[474]22%    .OutputDirExt: directory extension for data outputs
[457]23%    .Action: .ActionName: name of the current activated function
24%             .ActionPath:   path of the current activated function
[596]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%             
[457]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
[596]33%              .FieldName: name(s) of the field
[457]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
[596]37%              .Coord_y: name of y coordinate variable
38%              .Coord_x: name of x coordinate variable
[457]39%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[596]41
[810]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
[457]60function ParamOut=time_series(Param)
[27]61
[606]62%% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed
[875]63if isstruct(Param) && isequal(Param.Action.RUN,0)% function activated from the GUI series but not RUN
[605]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
[606]70    ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only)
[605]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
[871]75    % check for selection of a projection object
76    hseries=findobj(allchild(0),'Tag','series');% handles of the GUI series
[875]77    hhseries=guidata(hseries);
[871]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
[875]86   
[871]87    % introduce bin size for histograms
[872]88    if isfield(Param,'CheckObject') &&Param.CheckObject
[871]89        SeriesData=get(hseries,'UserData');
[872]90        if ismember(SeriesData.ProjObject.ProjMode,{'inside','outside'})
[875]91            answer=msgbox_uvmat('INPUT_TXT','set bin size for histograms (or keep ''auto'' by default)?','auto');
[871]92            ParamOut.ActionInput.VarMesh=str2double(answer);
93        end
94    end
[875]95   
[874]96    % test for subtraction
[875]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,:))
[874]108        end
[875]109    end
110   
[871]111    % check the existence of the first and last file in the series
[875]112    first_j=[];
[716]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'])
[871]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
[605]130    end
[599]131    return
[27]132end
133
[526]134%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
[624]135ParamOut=[]; %default output
[592]136%% read input parameters from an xml file if input is a file name (batch mode)
137checkrun=1;
[457]138if ischar(Param)
[592]139    Param=xml2struct(Param);% read Param as input file (batch case)
140    checkrun=0;
[374]141end
[624]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
[592]145
[624]146%% define the directory for result file (with path=RootPath{1})
[474]147OutputDir=[Param.OutputSubDir Param.OutputDirExt];
[457]148
[609]149%% root input file(s) name, type and index series
[457]150RootPath=Param.InputTable(:,1);
151RootFile=Param.InputTable(:,3);
152SubDir=Param.InputTable(:,2);
153NomType=Param.InputTable(:,4);
154FileExt=Param.InputTable(:,5);
[751]155hdisp=disp_uvmat('WAITING...','checking the file series',checkrun);
[374]156[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
[751]157if ~isempty(hdisp),delete(hdisp),end;
[526]158%%%%%%%%%%%%
159% The cell array filecell is the list of input file names, while
160% filecell{iview,fileindex}:
[457]161%        iview: line in the table corresponding to a given file series
[599]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
[457]164% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
[526]165%%%%%%%%%%%%
[457]166nbview=numel(i1_series);%number of input file series (lines in InputTable)
[647]167nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
[457]168nbfield_i=size(i1_series{1},2); %nb of fields for the i index
169nbfield=nbfield_j*nbfield_i; %total number of fields
[374]170
[609]171%% determine the file type on each line from the first input file
[457]172ImageTypeOptions={'image','multimage','mmreader','video'};
173NcTypeOptions={'netcdf','civx','civdata'};
[768]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);
[874]180
[457]181for iview=1:nbview
182    if ~exist(filecell{iview,1}','file')
[668]183        disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
[27]184        return
185    end
[784]186    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
[783]187    FileType{iview}=FileInfo{iview}.FileType;
[768]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
[457]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
[768]195    if isempty(j1_series{iview})
196        frame_index{iview}=i1_series{iview};
197    else
[457]198        frame_index{iview}=j1_series{iview};
199    end
[27]200end
201
[457]202%% calibration data and timing: read the ImaDoc files
[470]203[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
[768]204if ~isempty(errormsg)
205    disp_uvmat('ERROR',['error in reading xmlfile: ' errormsg],checkrun)
206    return
207end
[470]208if size(time,1)>1
[457]209    diff_time=max(max(diff(time)));
210    if diff_time>0
[668]211        disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
[599]212    end
[531]213    time=time(1,:);% choose the time data from the first sequence
[457]214end
[27]215
[457]216%% coordinate transform or other user defined transform
[526]217transform_fct=[];%default
[478]218if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
[474]219    addpath(Param.FieldTransform.TransformPath)
220    transform_fct=str2func(Param.FieldTransform.TransformName);
221    rmpath(Param.FieldTransform.TransformPath)
[457]222end
[474]223
[457]224%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
[599]225% EDIT FROM HERE
[27]226
[656]227%% check the validity of  the input file types
228if ~CheckImage{1}&&~CheckNc{1}
[668]229    disp_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun)
[457]230    return
[27]231end
[457]232if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
[668]233    disp_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun)
[259]234    return
235end
[635]236
237%% settings for the output file
[656]238FileExtOut='.nc';% write result as .nc files for netcdf inputs
[609]239NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file
[635]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
[457]248
249%% Set field names and velocity types
250InputFields{1}=[];%default (case of images)
[867]251if nbview==2
252    InputFields{2}=[];%default (case of images)
253end
[457]254if isfield(Param,'InputFields')
255    InputFields{1}=Param.InputFields;
[867]256    if nbview==2
257        InputFields{2}=Param.InputFields;%default
[457]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
[27]266
[457]267%% Initiate output fields
268%initiate the output structure as a copy of the first input one (reproduce fields)
[464]269[DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
[457]270if ~isempty(errormsg)
[668]271    disp_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg],checkrun)
[457]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
[871]295nbfile=0;% not used , to check
[599]296nbmissing=0;
[871]297VarMesh=NaN;
298checkhisto=0;
299if isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'})
300    checkhisto=1;
301    if isfield(Param.ActionInput,'VarMesh')%case of histograms
302    VarMesh=Param.ActionInput.VarMesh;
303    end
304end
[875]305
[599]306%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
307for index=1:nbfield
[871]308    update_waitbar(WaitbarHandle,index/nbfield)
[635]309    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
[624]310        disp('program stopped by user')
311        break % leave the loop if stop is ordered
[599]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            display(errormsg)
323            break
[442]324        end
[599]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        Field=Data{1}; % default input field structure
331        % coordinate transform (or other user defined transform)
332        if ~isempty(transform_fct)
[875]333            switch nargin(transform_fct)
334                case 4
335                    if length(Data)==2
336                        Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
337                    else
[526]338                        Field=transform_fct(Data{1},XmlData{1});
[599]339                    end
[875]340                case 3
341                    if length(Data)==2
342                        Field=transform_fct(Data{1},XmlData{1},Data{2});
343                    else
344                        Field=transform_fct(Data{1},XmlData{1});
[599]345                    end
[875]346                case 2
347                    Field=transform_fct(Data{1},XmlData{1});
348                case 1
349                    Field=transform_fct(Data{1});
[474]350            end
[599]351        end
352       
[871]353        %field projection on an object
[599]354        if Param.CheckObject
[751]355            % calculate tps coefficients if needed
356            if isfield(Param.ProjObject,'ProjMode')&& strcmp(Param.ProjObject.ProjMode,'interp_tps')
357                Field=tps_coeff_field(Field,check_proj_tps);
358            end
[871]359            [Field,errormsg]=proj_field(Field,Param.ProjObject,VarMesh);
[599]360            if ~isempty(errormsg)
361                msgbox_uvmat('ERROR',['time_series / proj_field / ' errormsg])
362                return
[474]363            end
[599]364        end
[874]365        %         nbfile=nbfile+1;
[599]366       
367        % initiate the time series at the first iteration
[871]368        if index==1
[599]369            % stop program if the first field reading is in error
370            if ~isempty(errormsg)
[668]371                disp_uvmat('ERROR',['time_series / sub_field / ' errormsg],checkrun)
[599]372                return
[474]373            end
[599]374            DataOut=Field;%default
375            nbvar=length(Field.ListVarName);
376            if nbvar==0
[668]377                disp_uvmat('ERROR','no input variable selected',checkrun)
[599]378                return
379            end
[871]380            if checkhisto%case of histograms
381                testsum=zeros(1,nbvar);%initiate flag for action on each variable
382                for ivar=1:numel(Field.ListVarName)% list of variable names before projection (histogram)
383                    VarName=Field.ListVarName{ivar};
384                    if isfield(Data{1},VarName)
385                        testsum(ivar)=1;
386                        DataOut.(VarName)=Field.(VarName);
387                        DataOut.([VarName 'Histo'])=zeros([nbfield numel(DataOut.(VarName))]);
388                        VarMesh=Field.(VarName)(2)-Field.(VarName)(1);
389                    end
390                end
391                disp(['mesh for histogram = ' num2str(VarMesh)])
392            else
393                testsum=2*ones(1,nbvar);%initiate flag for action on each variable
394                if isfield(Field,'VarAttribute') % look for coordinate and flag variables
395                    for ivar=1:nbvar
396                        if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
397                            var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
398                            if isequal(var_role,'errorflag')
399                                disp_uvmat('ERROR','do not handle error flags in time series',checkrun)
400                                return
401                            end
402                            if isequal(var_role,'warnflag')
403                                testsum(ivar)=0;  % not recorded variable
404                                eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable
405                            end
406                            if strcmp(var_role,'coord_x')||strcmp(var_role,'coord_y')||strcmp(var_role,'coord_z')||strcmp(var_role,'coord')
407                                testsum(ivar)=1; %constant coordinates, record without time evolution
408                            end
[27]409                        end
[871]410                        % check whether the variable ivar is a dimension variable
411                        DimCell=Field.VarDimName{ivar};
412                        if ischar(DimCell)
413                            DimCell={DimCell};
[27]414                        end
[871]415                        if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
416                            testsum(ivar)=1;
[474]417                        end
[27]418                    end
[871]419                end
420                for ivar=1:nbvar
421                    if testsum(ivar)==2
422                        VarName=Field.ListVarName{ivar};
423                        siz=size(Field.(VarName));
424                        DataOut.(VarName)=zeros([nbfield siz]);
[474]425                    end
426                end
427            end
[599]428            DataOut.ListVarName=[{'Time'} DataOut.ListVarName];
429        end
430       
431        % add data to the current field
[871]432        if checkhisto
433            for ivar=1:length(Field.ListVarName)
434                VarName=Field.ListVarName{ivar};
435                if isfield(Data{1},VarName)
436                    MaxValue=max(DataOut.(VarName));% current max of histogram absissa
437                    MinValue=min(DataOut.(VarName));% current min of histogram absissa
438                    MaxIndex=round(MaxValue/VarMesh);
439                    MinIndex=round(MinValue/VarMesh);
440                    MaxIndex_new=round(max(Field.(VarName)/VarMesh));% max of the current field
441                    MinIndex_new=round(min(Field.(VarName)/VarMesh));
442                    if MaxIndex_new>MaxIndex% the variable max for the current field exceeds the previous one
443                        DataOut.(VarName)=[DataOut.(VarName) VarMesh*(MaxIndex+1:MaxIndex_new)];% append the new variable values
444                        DataOut.([VarName 'Histo'])=[DataOut.([VarName 'Histo']) zeros(nbfield,MaxIndex_new-MaxIndex)]; % append the new histo values
[330]445                    end
[871]446                    if MinIndex_new <= MinIndex-1
447                        DataOut.(VarName)=[VarMesh*(MinIndex_new:MinIndex-1) DataOut.(VarName)];% insert the new variable values
448                        DataOut.([VarName 'Histo'])=[zeros(nbfield,MinIndex-MinIndex_new) DataOut.([VarName 'Histo'])];% insert the new histo values
449                        ind_start=1;
450                    else
451                        ind_start=MinIndex_new-MinIndex+1;
452                    end
453                    DataOut.([VarName 'Histo'])(index,ind_start:ind_start+MaxIndex_new-MinIndex_new)=...
454                        DataOut.([VarName 'Histo'])(index,ind_start:ind_start+MaxIndex_new-MinIndex_new)+Field.([VarName 'Histo']);
[330]455                end
[871]456            end
457        else
458            for ivar=1:length(Field.ListVarName)
459                VarName=Field.ListVarName{ivar};
460                VarVal=Field.(VarName);
461                if testsum(ivar)==2% test for recorded variable
[874]462                    if isempty(errormsg)
[871]463                        VarVal=shiftdim(VarVal,-1); %shift dimension
464                        DataOut.(VarName)(index,:,:)=VarVal;%concanete the current field to the time series
465                    end
466                elseif testsum(ivar)==1% variable representing fixed coordinates
467                    VarInit=DataOut.(VarName);
468                    if isempty(errormsg) && ~isequal(VarVal,VarInit)
469                        disp_uvmat('ERROR',['time series requires constant coordinates ' VarName ': use projection mode interp'],checkrun)
470                        return
471                    end
[599]472                end
[27]473            end
[599]474        end
475       
476        % record the time:
477        if isempty(time)% time not set by xml filer(s)
478            if isfield(Data{1},'Time')
[871]479                DataOut.Time(index,1)=Field.Time;
[599]480            else
[871]481                DataOut.Time(index,1)=index;%default
[474]482            end
[599]483        else % time from ImaDoc prevails  TODO: correct
[871]484            DataOut.Time(index,1)=time(index);%
[27]485        end
[599]486       
487        % record the number of missing input fields
488        if ~isempty(errormsg)
489            nbmissing=nbmissing+1;
490            display(['index=' num2str(index) ':' errormsg])
[27]491        end
[330]492    end
[599]493end
494%%%%%%% END OF LOOP WITHIN A SLICE
495
496%remove time for global attributes if exists
497Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute));
498if ~isempty(Time_index)
499    DataOut.ListGlobalAttribute(Time_index)=[];
500end
501DataOut.Conventions='uvmat';
502for ivar=1:numel(DataOut.ListVarName)
503    VarName=DataOut.ListVarName{ivar};
504    eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons
505end
506
507% add time dimension
508for ivar=1:length(Field.ListVarName)
[751]509    DimCell=Field.VarDimName{ivar};
510    if ischar(DimCell),DimCell={DimCell};end
511    if testsum(ivar)==2% variable for which time series is calculated
[599]512        DataOut.VarDimName{ivar}=[{'Time'} DimCell];
[751]513    elseif testsum(ivar)==1 % variable represneting a fixed coordinate
[599]514        DataOut.VarDimName{ivar}=DimCell;
[330]515    end
[599]516end
517indexremove=find(~testsum);
518if ~isempty(indexremove)
519    DataOut.ListVarName(1+indexremove)=[];
520    DataOut.VarDimName(indexremove)=[];
521    if isfield(DataOut,'Role') && ~isempty(DataOut.Role{1})%generaliser aus autres attributs
522        DataOut.Role(1+indexremove)=[];
[330]523    end
[27]524end
[107]525
[599]526%shift variable attributes
527if isfield(DataOut,'VarAttribute')
528    DataOut.VarAttribute=[{[]} DataOut.VarAttribute];
529end
530DataOut.VarDimName=[{'Time'} DataOut.VarDimName];
531DataOut.Action=Param.Action;%name of the processing programme
532test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant)
533if ~test_time
[645]534    DataOut.Time=1:nbfield;
[599]535end
536
[871]537%case of histograms
538if checkhisto
539    for ivar=1:numel(Field.ListVarName)
540        VarName=Field.ListVarName{ivar};
541        if isfield(Data{1},VarName)
542            DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Histo']}];
543            DataOut.VarDimName=[DataOut.VarDimName {{'Time',VarName}}];
544        end
545    end
546end
[599]547% display nbmissing
548if ~isequal(nbmissing,0)
[668]549    disp_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun)
[599]550end
551
[609]552%% name of result file
553OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j);
[599]554errormsg=struct2nc(OutputFile,DataOut); %save result file
555if isempty(errormsg)
556    display([OutputFile ' written'])
557else
[668]558    disp_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun)
[599]559end
560
[330]561%% plot the time series (the last one in case of multislices)
[474]562if checkrun
[478]563    figure
564    haxes=axes;
565    plot_field(DataOut,haxes)
[599]566   
[478]567    %% display the result file using the GUI get_field
568    hget_field=findobj(allchild(0),'name','get_field');
569    if ~isempty(hget_field)
570        delete(hget_field)
571    end
572    get_field(OutputFile,DataOut)
[474]573end
[27]574
575
Note: See TracBrowser for help on using the repository browser.