Changeset 330


Ignore:
Timestamp:
Dec 10, 2011, 2:27:11 PM (12 years ago)
Author:
sommeria
Message:

time_series debugged: better dealing with missing files. check_files;m renamed into check_data_files (confusion with the function check_fiels introduced in the uvmat directory)

Location:
trunk/src/series
Files:
1 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series/time_series.m

    r259 r330  
    1515function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series)
    1616
    17 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
     17%% requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
    1818if ~exist('num_i1','var')
    1919    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
     
    4242    hset_object=findobj(allchild(0),'tag','set_object');
    4343    ProjObject=read_set_object(guidata(hset_object));
    44     %answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]});
    4544    answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Style]);
    4645    if ~isequal(answeryes,'Yes')
     
    5251end
    5352
    54 %% root names
    55 if iscell(Series.RootPath)
    56     RootPath=Series.RootPath;
    57     RootFile=Series.RootFile;
    58     SubDir=Series.SubDir;
    59     FileExt=Series.FileExt;
    60     NomType=Series.NomType;
    61 else
    62     RootPath={Series.RootPath};
    63     RootFile={Series.RootFile};
    64     SubDir={Series.SubDir};
    65     FileExt={Series.FileExt};
    66     NomType={Series.NomType};
     53%% root names: transform input to cell in case of a single input series
     54if ischar(Series.RootPath)
     55    Series.RootPath={Series.RootPath};
     56    Series.RootFile={Series.RootFile};
     57    Series.SubDir={Series.SubDir};
     58    Series.FileExt={Series.FileExt};
     59    Series.NomType={Series.NomType};
    6760    num_i1={num_i1};
    6861    num_i2={num_i2};
     
    7063    num_j2={num_j2};
    7164end
    72 ext=FileExt{1};
    73 form=imformats(ext([2:end]));%test valid Matlab image formats
    74 testima=0;
    75 if ~isempty(form)||isequal(lower(ext),'.avi')
    76     testima=1;
    77 end
    78 nbview=length(RootPath);%number of series (1 or 2)
     65ext=Series.FileExt{1};
     66form=imformats(ext(2:end));%test valid Matlab image formats
    7967nbfield=size(num_i1{1},1)*size(num_i1{1},2); %number of fields in the time series
    8068
    81 %Number of input series: this function  accepts only one or two input file series (sub_field is used in the latter case)
    82 nbview=length(RootPath);
    83 
    84 %determine image type
     69%% determine image type
    8570hhh=which('mmreader');
    8671testnetcdf=0;
     72nbview=length(Series.RootPath);%Number of input series: this function  accepts only one or two input file series (sub_field is used in the latter case)
    8773for iview=1:nbview
    88     if isequal(FileExt{iview},'.nc')||isequal(FileExt{iview},'.cdf')
     74    if isequal(Series.FileExt{iview},'.nc')||isequal(Series.FileExt{iview},'.cdf')
    8975        FileType{iview}='netcdf';
    9076        testnetcdf=1;
    91     elseif isequal(lower(FileExt{iview}),'.avi')
    92         if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
    93             MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
     77    elseif isequal(lower(Series.FileExt{iview}),'.avi')
     78        if ~isequal(hhh,'')%&& mmreader.isPlatformSupported()
     79            MovieObject{iview}=mmreader(fullfile(Series.RootPath{iview},[Series.RootFile{iview} Series.FileExt{iview}]));
    9480            FileType{iview}='movie';
    9581        else
    9682            FileType{iview}='avi';
    9783        end
    98     elseif isequal(lower(FileExt{iview}),'.vol')
     84    elseif isequal(lower(Series.FileExt{iview}),'.vol')
    9985        FileType{iview}='vol';
    10086    else
    101        form=imformats(FileExt{iview}(2:end));
     87       form=imformats(Series.FileExt{iview}(2:end));
    10288       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
    103            if isequal(NomType{iview},'*');
     89           if isequal(Series.NomType{iview},'*');
    10490               FileType{iview}='multimage';
    10591           else
     
    10995    end
    11096end
    111 filebase{1}=fullfile(RootPath{1},RootFile{1});
    112 
    113 % number of slices
    114 NbSlice=str2num(get(hseries.NbSlice,'String'));
    115 if isempty(NbSlice)
     97filebase{1}=fullfile(Series.RootPath{1},Series.RootFile{1});
     98
     99%% number of slices
     100NbSlice=str2double(get(hseries.NbSlice,'String'));
     101if isnan(NbSlice)
    116102    NbSlice=1;
    117103end
    118 NbSlice_name=num2str(NbSlice);
    119 
    120 % Field and velocity type (the same for the two views)
     104
     105%% Field and velocity type (the same for the two views)
    121106if isfield(Series,'Field')
    122107    FieldName=Series.Field;%the same set of fields for all views
     
    133118        delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld
    134119    elseif isempty(hget_field)
    135        filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1});
     120       filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),Series.FileExt{1},Series.NomType{1},1,num_i2{1}(1),num_j2{1}(1),Series.SubDir{1});
    136121       idetect(iview)=exist(filename,'file');
    137122       hget_field=get_field(filename);
     
    141126    if isempty(SubField)
    142127        delete(hget_field)
    143        filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1});
     128       filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),Series.FileExt{1},Series.NomType{1},1,num_i2{1}(1),num_j2{1}(1),Series.SubDir{1});
    144129        hget_field=get_field(filename);
    145130        SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
     
    147132end
    148133
    149 %detect whether the two files are 'images' or 'netcdf'
    150 
     134%% detect whether the two files are 'images' or 'netcdf'
    151135testcivx=0;
    152 FileExt=get(hseries.FileExt,'String');
     136% FileExt=get(hseries.FileExt,'String');
    153137if ~isequal(FieldName,{'get_field...'})
    154138    testcivx=isequal(FileType{1},'netcdf');
    155139end
    156 
    157140VelType_str=get(hseries.VelTypeMenu,'String');
    158141VelType_val=get(hseries.VelTypeMenu,'Value');
     
    165148
    166149%% Calibration data and timing: read the ImaDoc files
    167 mode=''; %default
     150% mode=''; %default
    168151timecell={};
    169152XmlData={};
     
    172155for iview=1:nbview%Loop on views
    173156    XmlData{iview}=[];%default
    174     filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
     157    filebase{iview}=fullfile(Series.RootPath{iview},Series.RootFile{iview});
    175158    if exist([filebase{iview} '.xml'],'file')
    176159        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
     
    185168            end
    186169        end
    187     elseif exist([filebase{iview} '.civ'],'file')
     170    elseif exist([filebase{iview} '.civ'],'file')%old convention .civ text file
    188171        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
    189172        itime=itime+1;
     
    208191    end
    209192end
     193time=[];%default
     194if ~isempty(timecell)
     195    if numel(timecell{1})<nbfield
     196       msgbox_uvmat('WARNING','time array from ImaDoc to short')
     197    else
     198        time=timecell{1}; %time defined from ImaDoc file (image series)
     199    end
     200end
    210201
    211202%% check coincidence in time
    212 multitime=0;
    213 if isempty(timecell)
    214     time=[];
    215 elseif length(timecell)==1
    216     time=timecell{1};
    217 elseif length(timecell)>1
    218     multitime=1;
    219     for icell=1:length(timecell)
    220         if ~isequal(size(timecell{icell}),size(timecell{1}))
     203if length(timecell)>1
     204    for icell=2:length(timecell)
     205        if isequal(size(timecell{icell}),size(time))
     206            diff_time=max(abs(timecell{icell}-time));
     207            if diff_time>0
     208                msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
     209                break
     210            end
     211        else
    221212            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
    222             time=timecell{1};
    223             multitime=0;
    224213            break
    225214        end
    226215    end
    227216end
    228 if multitime
    229     for icell=1:length(timecell)
    230         time(icell,:,:)=timecell{icell};
    231     end
    232     diff_time=max(max(diff(time)));
    233     if diff_time>0
    234         msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
    235     end   
    236 end
    237 if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file'
    238     time=[];
     217if ~isempty(time)
     218    display(['time is read from ' filebase{iview} '.xml'])
    239219end
    240220
    241221%%  Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
    242222subdir_result='time_series';
    243 pathdir=fullfile(RootPath{1},subdir_result);
     223pathdir=fullfile(Series.RootPath{1},subdir_result);
    244224while exist(pathdir,'dir')
    245225    subdir_result=[subdir_result '.0'];
    246     pathdir=fullfile(RootPath{1},subdir_result);
     226    pathdir=fullfile(Series.RootPath{1},subdir_result);
    247227end
    248228[m1,m2,m3]=mkdir(pathdir);
     
    255235    return
    256236end
    257 
    258237filebase_out=filebase{1};
    259 NomTypeOut=nomtype2pair(NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1));
     238NomTypeOut=nomtype2pair(Series.NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1));
    260239
    261240%% coordinate transform or other user defined transform
     
    276255
    277256%% LOOP ON SLICES
     257nbmissing=0; %number of undetected files
    278258for i_slice=1:NbSlice
    279      dt=[];
    280      nbmissing=0; %number of undetected files
    281      nbfiles=0;
    282     %%%%%%%%%%%%%%%%%%%%%%%%%%%%LOOP ON FIELDS IN  A SLICE
    283     for ifile=i_slice:NbSlice:nbfield 
     259    dt=[];
     260    %%%%%%%%%%%%%%%%%%%%%%%%%%%%  LOOP ON FIELDS WITHIN  A SLICE
     261    filecounter=0;
     262    for ifile=i_slice:NbSlice:nbfield
    284263        stopstate=get(hseries.RUN,'BusyAction');
     264        errormsg='';
    285265        if isequal(stopstate,'queue')% enable STOP command
    286              update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
    287              for iview=1:nbview
    288                 filename=...
    289                            name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
    290                 idetect(iview)=exist(filename,'file');
    291                 Data{iview}=[]; %default     
    292                 if ~isequal(FileType{iview},'netcdf')               
    293                     Data{iview}.ListVarName={'A'};
    294                     Data{iview}.AName='image';
    295                     switch FileType{iview}
    296                         case 'movie'
    297                             A=read(MovieObject{iview},num_i1{iview}(ifile));
    298                         case 'avi'
    299                             mov=aviread(filename,num_i1{iview}(ifile));
    300                             A=frame2im(mov(1));
    301                         case 'vol'
    302                             A=imread(filename);
    303                         case 'multimage'
    304                             A=imread(filename,num_i1{iview}(ifile));
    305                         case 'image'
    306                             A=imread(filename);
    307                     end
    308                     Data{iview}.ListVarName={'AY','AX','A'}; %
    309                     npy=size(A,1);
    310                     npx=size(A,2);
    311                     nbcolor=size(A,3);
    312                     if nbcolor==3
    313                          Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}};
     266            update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield) % update the waitbar
     267            % loop on views (in case of multiple input series)
     268            for iview=1:nbview
     269                filename=name_generator(filebase{iview},...
     270                    num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),Series.SubDir{iview});
     271                if exist(filename,'file')
     272                    try
     273                        Data{iview}=[]; %default
     274                        if ~isequal(FileType{iview},'netcdf')
     275                            Data{iview}.ListVarName={'A'};
     276                            Data{iview}.AName='image';
     277                            switch FileType{iview}
     278                                case 'movie'
     279                                    A=read(MovieObject{iview},num_i1{iview}(ifile));
     280                                case 'avi'
     281                                    mov=aviread(filename,num_i1{iview}(ifile));
     282                                    A=frame2im(mov(1));
     283                                case 'vol'
     284                                    A=imread(filename);
     285                                case 'multimage'
     286                                    A=imread(filename,num_i1{iview}(ifile));
     287                                case 'image'
     288                                    A=imread(filename);
     289                            end
     290                            Data{iview}.ListVarName={'AY','AX','A'}; %
     291                            npy=size(A,1);
     292                            npx=size(A,2);
     293                            nbcolor=size(A,3);
     294                            if nbcolor==3
     295                                Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}};
     296                            else
     297                                Data{iview}.VarDimName={'AY','AX',{'AY','AX'}};
     298                            end
     299                            Data{iview}.AY=[npy-0.5 0.5];
     300                            Data{iview}.AX=[0.5 npx-0.5];
     301                            Data{iview}.A=double(A);
     302                            Data{iview}.CoordUnit='pixel';
     303                        elseif testcivx
     304                            [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
     305                            if ~isequal(FieldName,{''})
     306                                Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
     307                            end
     308                        else
     309                            [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data
     310                            Data{iview}.VarAttribute=SubField.VarAttribute;
     311                        end
     312                        if ~isempty(NbSlice_calib)  % z index
     313                            Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
     314                        end
     315                    catch ME
     316                        errormsg=ME.message;
     317                    end
     318                else
     319                    errormsg=[filename ' is missing'];
     320                end
     321                if isempty(errormsg)
     322                    % coordinate transform (or other user defined transform)
     323                    if ~isempty(transform_fct)
     324                        if nbview==2
     325                            [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
     326                            if isempty(Data{2})
     327                                Data(2)=[];
     328                            end
     329                        else
     330                            Data{1}=transform_fct(Data{1},XmlData{1});
     331                        end
     332                    end
     333                    if length(Data)==2
     334                        [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
    314335                    else
    315                          Data{iview}.VarDimName={'AY','AX',{'AY','AX'}};
    316                     end 
    317                     Data{iview}.AY=[npy-0.5 0.5];
    318                     Data{iview}.AX=[0.5 npx-0.5];
    319                     Data{iview}.A=double(A);
    320                     Data{iview}.CoordUnit='pixel';
    321                 elseif testcivx
    322                     [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
    323                 else
    324                     [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data               
    325                     Data{iview}.VarAttribute=SubField.VarAttribute;
     336                        Field=Data{1};
     337                    end
     338                    if test_object
     339                        [Field,errormsg]=proj_field(Field,ProjObject);
     340                    end
    326341                end
    327                 if ~isempty(NbSlice_calib)  % z index
    328                     Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
    329                 end
    330              end
    331              
    332              % coordinate transform (or other user defined transform)
    333             if ~isempty(transform_fct)
    334                  % z index
    335                 if ~isempty(NbSlice_calib)
    336                     Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;%Zindex for phys transform
    337                 end
    338                 if nbview==2
    339                     [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
    340                     if isempty(Data{2})
    341                         Data(2)=[];
    342                     end
    343                 else
    344                     Data{1}=transform_fct(Data{1},XmlData{1});
    345                 end
    346             end     
    347             if testcivx && ~isequal(FieldName,{''})
    348                     Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
    349             end
    350             if length(Data)==2
    351                 [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
    352                 if ~isempty(errormsg)
    353                     msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg])
    354                     return
    355                 end
    356             else
    357                 Field=Data{1};
    358             end
    359             if test_object
    360                 [Field,errormsg]=proj_field(Field,ProjObject);
    361                 if ~isempty(errormsg)
    362                     msgbox_uvmat('ERROR',['error in time_series/proj_field:' errormsg])
    363                     return
    364                 end
    365             end
    366             if min(idetect)>=1% the input file(s) have been detected         
    367                 nbfiles=nbfiles+1;
    368                 if nbfiles==1 %first field: initiate the time series
     342                filecounter=filecounter+1;
     343               
     344                % initiate the time series at the first iteration
     345                if filecounter==1
     346                    % stop program if the first field reading is in error
     347                    if ~isempty(errormsg)
     348                        msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg])
     349                        return
     350                    end
    369351                    RecordData=Field;%default
    370                     RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots         
     352                    RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots
    371353                    nbvar=length(Field.ListVarName);
    372354                    if nbvar==0
     
    375357                    end
    376358                    testsum=2*ones(1,nbvar);%initiate flag for action on each variable
    377                     indexfalse=0;
    378                     CoordName={};
    379                     indexremove=[];
    380                     if isfield(Field,'VarAttribute') % look for coordinate and flag variables   
     359                    if isfield(Field,'VarAttribute') % look for coordinate and flag variables
    381360                        for ivar=1:nbvar
    382361                            if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
    383                                %Field.ListVarName{ivar}
    384362                                var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
    385363                                if isequal(var_role,'errorflag')
    386364                                    msgbox_uvmat('ERROR','do not handle error flags in time series')
    387                                     return                                               
     365                                    return
    388366                                end
    389                                 if isequal(var_role,'warnflag')                       
    390                                     testsum(ivar)=0;  % not recorded variable 
     367                                if isequal(var_role,'warnflag')
     368                                    testsum(ivar)=0;  % not recorded variable
    391369                                    eval(['RecordData=rmfield(RecordData,''' Field.ListVarName{ivar} ''');']);%remove variable
    392                                 end                 
     370                                end
    393371                                if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|...
    394                                     isequal(var_role,'coord_z')|isequal(var_role,'coord')
     372                                        isequal(var_role,'coord_z')|isequal(var_role,'coord')
    395373                                    testsum(ivar)=1; %constant coordinates, record without time evolution
    396374                                end
     
    402380                            end
    403381                            if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
    404                                testsum(ivar)=1;
     382                                testsum(ivar)=1;
    405383                            end
    406384                        end
    407385                    end
    408386                    for ivar=1:nbvar
    409                         if testsum(ivar)==2                     
     387                        if testsum(ivar)==2
    410388                            eval(['RecordData.' Field.ListVarName{ivar} '=[];'])
    411389                        end
     
    413391                    RecordData.ListVarName=[{'Time'} RecordData.ListVarName];
    414392                end
     393               
     394                % add data to the current field
    415395                for ivar=1:length(Field.ListVarName)
    416396                    VarName=Field.ListVarName{ivar};
    417                     eval(['VarVal=Field.' VarName ';']);
    418                     if testsum(ivar)==2% test for recorded variable
    419                         eval(['VarVal=Field.' VarName ';']);
    420                         if isequal(ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
    421                             if isempty(VarVal)
    422                                 msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))])
    423                                 return                             
    424                             end
    425                             VarVal=mean(VarVal,1);
    426                         end
    427                         VarVal=shiftdim(VarVal,-1); %shift dimension
    428                         eval(['RecordData.' VarName '=cat(1,RecordData.' VarName ',VarVal);']);%concanete the current field to the time series   
     397                    VarVal=Field.(VarName);
     398                    if testsum(ivar)==2% test for recorded variable
     399                        if isempty(errormsg)
     400                            if isequal(ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
     401                                if isempty(VarVal)
     402                                    msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))])
     403                                    return
     404                                end
     405                                VarVal=mean(VarVal,1);
     406                            end
     407                            VarVal=shiftdim(VarVal,-1); %shift dimension
     408                            RecordData.(VarName)=cat(1,RecordData.(VarName),VarVal);%concanete the current field to the time series
     409                        else
     410                            RecordData.(VarName)=cat(1,RecordData.(VarName),0);% put each variable to 0 in case of input reading error
     411                        end
    429412                    elseif testsum(ivar)==1% variable representing fixed coordinates
    430413                        eval(['VarInit=RecordData.' VarName ';']);
    431                         if ~isequal(VarVal,VarInit)
     414                        if isempty(errormsg) && ~isequal(VarVal,VarInit)
    432415                            msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName])
    433416                            return
    434417                        end
    435                     end                 
     418                    end
    436419                end
    437                 % time:
     420               
     421                % record the time:
    438422                if isempty(time)% time read in ncfiles
    439                    if isfield(Field,'Time')
    440                        RecordData.Time(nbfiles,1)=Field.Time;
    441                    else
    442                        RecordData.Time(nbfiles,1)=nbfiles;%default
    443                    end
     423                    if isfield(Field,'Time')
     424                        RecordData.Time(filecounter,1)=Field.Time;
     425                    else
     426                        RecordData.Time(filecounter,1)=ifile;%default
     427                    end
    444428                else % time from ImaDoc prevails
    445                     RecordData.Time(nbfiles,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2;
     429                    RecordData.Time(filecounter,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2;
    446430                end
    447             else
    448                 nbmissing=nbmissing+1;
     431               
     432                % record the number of missing input fields
     433                if ~isempty(errormsg)
     434                    nbmissing=nbmissing+1;
     435                    display(['ifile=' num2str(ifile) ':' errormsg])
     436                end
    449437            end
    450438        end
    451439    end
     440    %%%%%%% END OF LOOP WITHIN A SLICE
     441   
    452442    %remove time for global attributes if exists
    453     for iattr=1:numel(RecordData.ListGlobalAttribute) 
     443    for iattr=1:numel(RecordData.ListGlobalAttribute)
    454444        if strcmp(RecordData.ListGlobalAttribute{iattr},'Time')
    455445            RecordData.ListGlobalAttribute(iattr)=[];
     
    461451        eval(['RecordData.' VarName '=squeeze(RecordData.' VarName ');']) %remove singletons
    462452    end
    463         % add time dimension and update VarDimIndex:
    464         for ivar=1:length(Field.ListVarName)
    465              DimCell=Field.VarDimName(ivar);
    466              if testsum(ivar)==2%variable used as time series
    467                   RecordData.VarDimName{ivar}=[{'Time'} DimCell];
    468              elseif testsum(ivar)==1
    469                  RecordData.VarDimName{ivar}=DimCell;
    470              end
    471         end
     453   
     454    % add time dimension
     455    for ivar=1:length(Field.ListVarName)
     456        DimCell=Field.VarDimName(ivar);
     457        if testsum(ivar)==2%variable used as time series
     458            RecordData.VarDimName{ivar}=[{'Time'} DimCell];
     459        elseif testsum(ivar)==1
     460            RecordData.VarDimName{ivar}=DimCell;
     461        end
     462    end
    472463    indexremove=find(~testsum);
    473464    if ~isempty(indexremove)
    474465        RecordData.ListVarName(1+indexremove)=[];
    475466        RecordData.VarDimName(indexremove)=[];
    476         if isfield(RecordData,'Role')&~isempty(RecordData.Role{1})%generaliser aus autres attributs
     467        if isfield(RecordData,'Role') && ~isempty(RecordData.Role{1})%generaliser aus autres attributs
    477468            RecordData.Role(1+indexremove)=[];
    478469        end
    479470    end
    480 
     471   
    481472    %shift variable attributes
    482473    if isfield(RecordData,'VarAttribute')
    483474        RecordData.VarAttribute=[{[]} RecordData.VarAttribute];
    484     end 
     475    end
    485476    RecordData.VarDimName=[{'Time'} RecordData.VarDimName];
    486477    RecordData.Action=Series.Action;%name of the processing programme
     478    test_time=diff(RecordData.Time)>0;% test that the readed time is increasing (not constant)
     479    if ~test_time
     480        RecordData.Time=[1:filecounter];
     481    end
     482   
     483    % display nbmissing
     484    if ~isequal(nbmissing,0)
     485        msgbox_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'])
     486    end
    487487   
    488488    %name of result file
    489 %     RecordData
    490 %     RecordData.VarDimName{1}
    491 %     RecordData.VarDimName{2}
    492 %     RecordData.VarDimName{3}
    493 %     RecordData.VarDimName{4}
    494 %     RecordData.VarDimName{5}
    495 %     RecordData.VarDimName{6}
    496489    [filemean]=...
    497                name_generator(filebase_out,num_i1{1}(i_slice),num_j1{1}(i_slice),'.nc','_i1-i2_j1-j2',1,num_i2{end}(ifile),num_j2{end}(ifile),subdir_result);
     490        name_generator(filebase_out,num_i1{1}(i_slice),num_j1{1}(i_slice),'.nc','_i1-i2_j1-j2',1,num_i2{end}(ifile),num_j2{end}(ifile),subdir_result);
    498491    errormsg=struct2nc(filemean,RecordData); %save result file
    499492    if isempty(errormsg)
     
    504497end
    505498
     499%% plot the time series (the last one in case of multislices)
    506500figure
    507501haxes=axes;
    508 
    509502plot_field(RecordData,haxes)
     503
     504%% display the result file using the GUI get_field
    510505hget_field=findobj(allchild(0),'name','get_field');
    511506if ~isempty(hget_field)
    512507    delete(hget_field)
    513508end
    514 
    515509get_field(filemean,RecordData)
    516510   
    517 %-----------------------------------------------------------------------
     511%------------------------------------------------------------------------
    518512% --- Executes on selection change in CoordType.
    519513function CoordType_Callback(hObject, eventdata, handles)
     514%------------------------------------------------------------------------
    520515menu_str=get(handles.CoordType,'String');
    521516ind_coord=get(handles.CoordType,'Value');
Note: See TracChangeset for help on using the changeset viewer.