Changeset 474 for trunk/src


Ignore:
Timestamp:
Jun 25, 2012, 12:14:16 AM (13 years ago)
Author:
sommeria
Message:

functions adpated to mode background

Location:
trunk/src/series
Files:
4 edited

Legend:

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

    r470 r474  
    3131%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
    3232%    .OutputSubDir: name of the subdirectory for data outputs
    33 %    .OutputDir: directory for data outputs, including path
     33%    .OutputDirExt: directory extension for data outputs
    3434%    .Action: .ActionName: name of the current activated function
    3535%             .ActionPath:   path of the current activated function
     
    5050%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    5151if ~exist('Param','var') % case with no input parameter
    52     ParamOut={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
    53         'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     52    ParamOut={'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    5453        'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    5554        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     
    6463end
    6564
    66 %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     65%%%%%%%%%%%%  STANDARD PART %%%%%%%%%%%%
    6766%% select different modes,  RUN, parameter input, BATCH
    6867% BATCH  case: read the xml file for batch case
     
    8180end
    8281ParamOut=Param; %default output
    83 
     82OutputDir=[Param.OutputSubDir Param.OutputDirExt];
     83   
    8484%% root input file(s) and type
    8585RootPath=Param.InputTable(:,1);
     
    8888NomType=Param.InputTable(:,4);
    8989FileExt=Param.InputTable(:,5);
    90 
    91 % get the set of input file names (cell array filecell), and the lists of
    92 % input file or frame indices i1_series,i2_series,j1_series,j2_series
    9390[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    94 % filecell{iview,fileindex}: cell array representing the list of file names
     91%%%%%%%%%%%%
     92% The cell array filecell is the list of input file names, while
     93% filecell{iview,fileindex}:
    9594%        iview: line in the table corresponding to a given file series
    9695%        fileindex: file index within  the file series,
    9796% 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
    9897% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    99 % set of frame indices used for movie or multimage input
    100 % numbers of slices and file indices
    101 
     98%%%%%%%%%%%%
    10299NbSlice=1;%default
    103100if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
     
    140137%% coordinate transform or other user defined transform
    141138transform_fct='';%default
    142 if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle')
    143     transform_fct=Param.FieldTransform.TransformHandle;
    144 end
     139if isfield(Param,'FieldTransform')
     140    addpath(Param.FieldTransform.TransformPath)
     141    transform_fct=str2func(Param.FieldTransform.TransformName);
     142    rmpath(Param.FieldTransform.TransformPath)
     143end
     144
    145145%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
    146146 % EDIT FROM HERE
     
    160160end
    161161NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
    162 if NbSlice~=nbfield_j
    163     answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
    164     if ~strcmp(answer,'Yes')
    165         return
    166     end
     162if checkrun==1
     163    return % stop here for input checks
    167164end
    168165
     
    185182end
    186183
    187 %% Initiate output fields
    188 % %initiate the output structure as a copy of the first input one (reproduce fields)
    189 % [DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
    190 % if ~isempty(errormsg)
    191 %     msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
    192 %     return
    193 % end
    194 % time_1=[];
    195 % if isfield(DataOut,'Time')
    196 %     time_1=DataOut.Time(1);
    197 % end
    198 % if CheckNc{iview}
    199 %     if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
    200 %         DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
    201 %     end
    202 %     DataOut.Conventions='uvmat';
    203 %     DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
    204 %     ActionKey='Action';
    205 %     while isfield(DataOut,ActionKey)
    206 %         ActionKey=[ActionKey '_1'];
    207 %     end
    208 %     DataOut.(ActionKey)=Param.Action;
    209 %     DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
    210 %     if isfield(DataOut,'Time')
    211 %         DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
    212 %     end
    213 % end
    214 
    215184%% MAIN LOOP ON SLICES
    216185%%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     
    219188    nbfiles=0;
    220189    nbmissing=0;
    221    
    222     %initiate result fields
    223 %     for ivar=1:length(DataOut.ListVarName)
    224 %         DataOut.(DataOut.ListVarName{ivar})=0; % initialise all fields to zero
    225 %     end
    226    
     190
    227191    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
    228192    for index=index_slice
     
    350314   
    351315    %writing the result file
    352     OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]);
     316    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]);
    353317    if CheckImage{1} %case of images
    354318        if isequal(FileInfo{1}.BitDepth,16)||(numel(FileInfo)==2 &&isequal(FileInfo{2}.BitDepth,16))
  • trunk/src/series/merge_proj.m

    r470 r474  
    1 %'merge_proj': project and concatene fieldsmerge_proj
    2 % can be used as a template for applying an operation (here projection and concateantion) on each field of an input series
     1%'merge_proj': project and concatene fields
     2% can be used as a template for applying an operation (here projection and concatenation) on each field of an input series
    33%------------------------------------------------------------------------
    44% function ParamOut=merge_proj(Param)
     
    3232%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
    3333%    .OutputSubDir: name of the subdirectory for data outputs
    34 %    .OutputDir: directory for data outputs, including path
     34%    .OutputDirExt: directory extension for data outputs
    3535%    .Action: .ActionName: name of the current activated function
    3636%             .ActionPath:   path of the current activated function
     
    5151%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    5252if ~exist('Param','var') % case with no input parameter
    53     ParamOut={'NbViewMax';'';...% max nbre of input file series (default='' , no limitation)
    54         'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     53    ParamOut={'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    5554        'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    5655        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     
    8281end
    8382ParamOut=Param; %default output
     83OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];
    8484
    8585%% root input file(s) and type
     
    8989NomType=Param.InputTable(:,4);
    9090FileExt=Param.InputTable(:,5);
    91 
    92 % get the set of input file names (cell array filecell), and the lists of
    93 % input file or frame indices i1_series,i2_series,j1_series,j2_series
    9491[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    95 % filecell{iview,fileindex}: cell array representing the list of file names
     92%%%%%%%%%%%%
     93% The cell array filecell is the list of input file names, while
     94% filecell{iview,fileindex}:
    9695%        iview: line in the table corresponding to a given file series
    9796%        fileindex: file index within  the file series,
    9897% 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
    9998% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    100 % set of frame indices used for movie or multimage input
    101 % numbers of slices and file indices
    102 
     99%%%%%%%%%%%%
    103100NbSlice=1;%default
    104101if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
     
    117114for iview=1:nbview
    118115    if ~exist(filecell{iview,1}','file')
    119         msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
     116        displ_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
    120117        return
    121118    end
     
    135132if size(time,1)>1
    136133    diff_time=max(max(diff(time)));
    137     if diff_time>0
    138         msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
     134    if diff_time>0 
     135        displ_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
    139136    end   
    140137end
    141 
    142138
    143139%% coordinate transform or other user defined transform
    144140transform_fct='';%default
    145 if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle')
    146     transform_fct=Param.FieldTransform.TransformHandle;
    147 end
     141if isfield(Param,'FieldTransform')
     142    addpath(Param.FieldTransform.TransformPath)
     143    transform_fct=str2func(Param.FieldTransform.TransformName);
     144    rmpath(Param.FieldTransform.TransformPath)
     145end
     146
    148147%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
    149148 % EDIT FROM HERE
     
    154153elseif CheckNc{1}
    155154    FileExtOut='.nc';% write result as .nc files for netcdf inputs
    156 else 
    157     msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
     155else
     156    displ_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun)
    158157    return
    159158end
    160159for iview=1:nbview
    161160        if ~isequal(CheckImage{iview},CheckImage{1})||~isequal(CheckNc{iview},CheckNc{1})
    162         msgbox_uvmat('ERROR','input set of input series: need  either netcdf either image series')
     161        displ_uvmat('ERROR','input set of input series: need  either netcdf either image series',checkrun)
    163162    return
    164163    end
    165164end
    166165NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series
     166if checkrun==1
     167    ParamOut.Specific=[];%no specific parameter
     168    return %stop here for interactive input (option Param.Specific='?')
     169end
    167170
    168171%% Set field names and velocity types
    169172%use Param.InputFields for all views
    170 
    171 %% Initiate output fields
    172 %initiate the output structure as a copy of the first input one (reproduce fields)
    173 [DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},Param.InputFields,1);
    174 if ~isempty(errormsg)
    175     msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
    176     return
    177 end
    178 time_1=[];
    179 if isfield(DataOut,'Time')
    180     time_1=DataOut.Time(1);
    181 end
    182 if CheckNc{iview}
    183     if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
    184         DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
    185     end
    186     DataOut.Conventions='uvmat';
    187     DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
    188     ActionKey='Action';
    189     while isfield(DataOut,ActionKey)
    190         ActionKey=[ActionKey '_1'];
    191     end
    192     DataOut.(ActionKey)=Param.Action;
    193     DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
    194     if isfield(DataOut,'Time')
    195         DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
    196     end
    197 end
    198173
    199174%% MAIN LOOP ON SLICES
     
    203178    nbfiles=0;
    204179    nbmissing=0;
    205    
    206     %initiate result fields
    207    
    208     for ivar=1:length(DataOut.ListVarName)
    209         DataOut.(DataOut.ListVarName{ivar})=0; % initialise all fields to zero
    210     end
    211    
     180
    212181    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
    213182    for index=index_slice
     
    227196            [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index));
    228197            if ~isempty(errormsg)
    229                 errormsg=['error of input reading: ' errormsg];
     198                errormsg=['merge_proj/read_field/' errormsg];
     199                display(errormsg)
    230200                break
    231201            end
     
    251221                [Data{iview},errormsg]=proj_field(Data{iview},Param.ProjObject);
    252222                if ~isempty(errormsg)
    253                     msgbox_uvmat('ERROR',['error in merge_proge/proj_field: ' errormsg])
     223                    displ_uvmat('ERROR',['error in merge_proge/proj_field: ' errormsg],checkrun)
    254224                    return
    255225                end
     
    261231        MergeData=merge_field(Data);
    262232        if isfield(MergeData,'Txt')
    263             msgbox_uvmat('ERROR',MergeData.Txt)
     233            displ_uvmat('ERROR',MergeData.Txt,checkrun)
    264234            return
    265235        end
     
    288258            end
    289259        end
    290         OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomType{1},i1,i2,j1,j2);
     260        OutputFile=fullfile_uvmat(RootPath{1},OutputSubDir,RootFile{1},FileExtOut,NomType{1},i1,i2,j1,j2);
    291261       
    292262        % recording the merged field
     
    387357    else
    388358        if length(ivar_Y)~=1
    389                 msgbox_uvmat('ERROR','y coordinate missing in proj_field.m')
     359                displ_uvmat('ERROR','y coordinate missing in proj_field.m',checkrun)
    390360                return
    391361        end
  • trunk/src/series/sub_background.m

    r462 r474  
    3838%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
    3939%    .OutputSubDir: name of the subdirectory for data outputs
    40 %    .OutputDir: directory for data outputs, including path
     40%    .OutputDirExt: extension for the directory for data outputs
    4141%    .Action: .ActionName: name of the current activated function
    4242%             .ActionPath:   path of the current activated function
     
    5858%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    5959if ~exist('Param','var') % case with no input parameter
    60     ParamOut={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
    61         'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     60    ParamOut={'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    6261        'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    6362        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     
    8988end
    9089ParamOut=Param; %default output
     90OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    9191
    9292%% root input file(s) and type
     
    9696NomType=Param.InputTable(:,4);
    9797FileExt=Param.InputTable(:,5);
    98 
    99 % get the set of input file names (cell array filecell), and the lists of
    100 % input file or frame indices i1_series,i2_series,j1_series,j2_series
    10198[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    102 % filecell{iview,fileindex}: cell array representing the list of file names
     99%%%%%%%%%%%%
     100% The cell array filecell is the list of input file names, while
     101% filecell{iview,fileindex}:
    103102%        iview: line in the table corresponding to a given file series
    104103%        fileindex: file index within  the file series,
    105104% 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
    106105% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    107 % set of frame indices used for movie or multimage input
    108 % numbers of slices and file indices
    109 
     106%%%%%%%%%%%%
    110107NbSlice=1;%default
    111108if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
     
    340337            j1=j1_series{1}(ifile);
    341338        end
    342         newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     339        newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    343340       
    344341        %write result file
     
    390387                        j1=j1_series{1}(ifile);
    391388                    end
    392                     newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     389                    newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    393390                    %write result file
    394391                    if ParamOut.Specific.CheckLevelTransform
     
    424421            j1=j1_series{1}(ifile);
    425422        end
    426         newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     423        newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    427424       
    428425        %write result file
  • trunk/src/series/time_series.m

    r470 r474  
    3131%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
    3232%    .OutputSubDir: name of the subdirectory for data outputs
    33 %    .OutputDir: directory for data outputs, including path
     33%    .OutputDirExt: directory extension for data outputs
    3434%    .Action: .ActionName: name of the current activated function
    3535%             .ActionPath:   path of the current activated function
     
    5050%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    5151if ~exist('Param','var') % case with no input parameter
    52     ParamOut={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
    53         'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     52    ParamOut={'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    5453        'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    5554        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     
    8180end
    8281ParamOut=Param; %default output
     82OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    8383
    8484%% root input file(s) and type
     
    116116for iview=1:nbview
    117117    if ~exist(filecell{iview,1}','file')
    118         msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
     118        displ_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
    119119        return
    120120    end
     
    134134    diff_time=max(max(diff(time)));
    135135    if diff_time>0
    136         msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
     136        displ_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
    137137    end   
    138138end
     
    140140%% coordinate transform or other user defined transform
    141141transform_fct='';%default
    142 if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle')
    143     transform_fct=Param.FieldTransform.TransformHandle;
    144 end
     142if isfield(Param,'FieldTransform')
     143    addpath(Param.FieldTransform.TransformPath)
     144    transform_fct=str2func(Param.FieldTransform.TransformName);
     145    rmpath(Param.FieldTransform.TransformPath)
     146end
     147
    145148%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
    146149 % EDIT FROM HERE
     
    152155    FileExtOut='.nc';% write result as .nc files for netcdf inputs
    153156else
    154     msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
     157    displ_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun)
    155158    return
    156159end
    157160if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
    158         msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
     161        displ_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun)
    159162    return
    160163end
    161164NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
    162 if NbSlice~=nbfield_j
    163     answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
    164     if ~strcmp(answer,'Yes')
    165         return
    166     end
    167 end
     165% if NbSlice~=nbfield_j
     166%     answer=_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
     167%     if ~strcmp(answer,'Yes')
     168%         return
     169%     end
     170% end
    168171
    169172%% Set field names and velocity types
     
    211214[DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
    212215if ~isempty(errormsg)
    213     msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
     216    displ_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg],checkrun)
    214217    return
    215218end
     
    238241nbmissing=0; %number of undetected files
    239242for i_slice=1:NbSlice
    240     dt=[];
    241     %%%%%%%%%%%%%%%%%%%%%%%%%%%%  LOOP ON FIELDS WITHIN  A SLICE
    242     filecounter=0;
    243     for ifile=i_slice:NbSlice:nbfield
     243    index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice
     244    nbfiles=0;
     245    nbmissing=0;
     246   
     247    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
     248    for index=index_slice       
    244249        if checkrun
    245             update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield)
     250            update_waitbar(hseries.waitbar_frame,WaitbarPos,index/(nbfield))
    246251            stopstate=get(hseries.RUN,'BusyAction');
    247252        else
    248253            stopstate='queue';
    249254        end
    250         errormsg='';
     255       
     256        %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
     257        Data=cell(1,nbview);%initiate the set Data
     258        nbtime=0;
     259        dt=[];
    251260        if isequal(stopstate,'queue')% enable STOP command
    252261            % loop on views (in case of multiple input series)
    253262            for iview=1:nbview
    254                 filename=filecell{iview,ifile};
    255                % filename=name_generator(filebase{iview},...
    256                 %    i1_series{iview}(ifile),j1_series{iview}(ifile),FileExt{iview},NomType{iview},1,i2_series{iview}(ifile),j2_series{iview}(ifile),SubDir{iview});
    257                 if exist(filename,'file')
    258                     try
    259                         Data{iview}=[]; %default
    260                         if ~isequal(FileType{iview},'netcdf')
    261                             Data{iview}.ListVarName={'A'};
    262                             Data{iview}.AName='image';
    263                             switch FileType{iview}
    264                                 case 'movie'
    265                                     A=read(MovieObject{iview},i1_series{iview}(ifile));
    266                                 case 'avi'
    267                                     mov=aviread(filename,i1_series{iview}(ifile));
    268                                     A=frame2im(mov(1));
    269                                 case 'vol'
    270                                     A=imread(filename);
    271                                 case 'multimage'
    272                                     A=imread(filename,i1_series{iview}(ifile));
    273                                 case 'image'
    274                                     A=imread(filename);
    275                             end
    276                             Data{iview}.ListVarName={'AY','AX','A'}; %
    277                             npy=size(A,1);
    278                             npx=size(A,2);
    279                             nbcolor=size(A,3);
    280                             if nbcolor==3
    281                                 Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}};
    282                             else
    283                                 Data{iview}.VarDimName={'AY','AX',{'AY','AX'}};
    284                             end
    285                             Data{iview}.AY=[npy-0.5 0.5];
    286                             Data{iview}.AX=[0.5 npx-0.5];
    287                             Data{iview}.A=double(A);
    288                             Data{iview}.CoordUnit='pixel';
    289                         elseif testcivx
    290                             [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
    291                             if ~isequal(FieldName,{''})
    292                                 Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
    293                             end
    294                         else
    295                             [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data
    296                             Data{iview}.VarAttribute=SubField.VarAttribute;
    297                         end
    298                         if ~isempty(NbSlice_calib)  % z index
    299                             Data{iview}.ZIndex=mod(i1_series{iview}(ifile)-1,NbSlice_calib{1})+1;
    300                         end
    301                     catch ME
    302                         errormsg=ME.message;
     263                % reading input file(s)
     264                [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index));
     265                if ~isempty(errormsg)
     266                    errormsg=['time_series/read_field/' errormsg];
     267                    display(errormsg)
     268                    break
     269                end
     270                timeread(iview)=0;
     271                if isfield(Data{iview},'Time')
     272                    timeread(iview)=Data{iview}.Time;
     273                    nbtime=nbtime+1;
     274                end
     275                if ~isempty(NbSlice_calib)
     276                    Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
     277                end
     278            end
     279            % coordinate transform (or other user defined transform)
     280            if ~isempty(transform_fct)
     281                if nbview==2
     282                    [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
     283                    if isempty(Data{2})
     284                        Data(2)=[];
    303285                    end
    304286                else
    305                     errormsg=[filename ' is missing'];
    306                 end
    307                 if isempty(errormsg)
    308                     % coordinate transform (or other user defined transform)
    309                     if ~isempty(transform_fct)
    310                         if nbview==2
    311                             [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
    312                             if isempty(Data{2})
    313                                 Data(2)=[];
     287                    Data{1}=transform_fct(Data{1},XmlData{1});
     288                end
     289            end
     290            if length(Data)==2
     291                [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
     292            else
     293                Field=Data{1};
     294            end
     295            if Param.CheckObject
     296                [Field,errormsg]=proj_field(Field,Param.ProjObject);
     297            end
     298            nbtime=nbtime+1;
     299           
     300            % initiate the time series at the first iteration
     301            if nbtime==1
     302                % stop program if the first field reading is in error
     303                if ~isempty(errormsg)
     304                    displ_uvmat('ERROR',['error in time_series/sub_field:' errormsg],checkrun)
     305                    return
     306                end
     307                DataOut=Field;%default
     308                DataOut.NbDim=Field.NbDim+1; %add the time dimension for plots
     309                nbvar=length(Field.ListVarName);
     310                if nbvar==0
     311                    displ_uvmat('ERROR','no input variable selected in get_field',checkrun)
     312                    return
     313                end
     314                testsum=2*ones(1,nbvar);%initiate flag for action on each variable
     315                if isfield(Field,'VarAttribute') % look for coordinate and flag variables
     316                    for ivar=1:nbvar
     317                        if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
     318                            var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
     319                            if isequal(var_role,'errorflag')
     320                                displ_uvmat('ERROR','do not handle error flags in time series',checkrun)
     321                                return
    314322                            end
    315                         else
    316                             Data{1}=transform_fct(Data{1},XmlData{1});
     323                            if isequal(var_role,'warnflag')
     324                                testsum(ivar)=0;  % not recorded variable
     325                                eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable
     326                            end
     327                            if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|...
     328                                    isequal(var_role,'coord_z')|isequal(var_role,'coord')
     329                                testsum(ivar)=1; %constant coordinates, record without time evolution
     330                            end
     331                        end
     332                        % check whether the variable ivar is a dimension variable
     333                        DimCell=Field.VarDimName{ivar};
     334                        if ischar(DimCell)
     335                            DimCell={DimCell};
     336                        end
     337                        if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
     338                            testsum(ivar)=1;
    317339                        end
    318340                    end
    319                     if length(Data)==2
    320                         [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
     341                end
     342                for ivar=1:nbvar
     343                    if testsum(ivar)==2
     344                        eval(['DataOut.' Field.ListVarName{ivar} '=[];'])
     345                    end
     346                end
     347                DataOut.ListVarName=[{'Time'} DataOut.ListVarName];
     348            end
     349           
     350            % add data to the current field
     351            for ivar=1:length(Field.ListVarName)
     352                VarName=Field.ListVarName{ivar};
     353                VarVal=Field.(VarName);
     354                if testsum(ivar)==2% test for recorded variable
     355                    if isempty(errormsg)
     356                        if isequal(Param.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
     357                            if isempty(VarVal)
     358                                displ_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(ifile))],checkrun)
     359                                return
     360                            end
     361                            VarVal=mean(VarVal,1);
     362                        end
     363                        VarVal=shiftdim(VarVal,-1); %shift dimension
     364                        DataOut.(VarName)=cat(1,DataOut.(VarName),VarVal);%concanete the current field to the time series
    321365                    else
    322                         Field=Data{1};
     366                        DataOut.(VarName)=cat(1,DataOut.(VarName),0);% put each variable to 0 in case of input reading error
    323367                    end
    324                     if Param.CheckObject
    325                         [Field,errormsg]=proj_field(Field,Param.ProjObject);
    326                     end
    327                 end
    328                 filecounter=filecounter+1;
    329                
    330                 % initiate the time series at the first iteration
    331                 if filecounter==1
    332                     % stop program if the first field reading is in error
    333                     if ~isempty(errormsg)
    334                         msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg])
     368                elseif testsum(ivar)==1% variable representing fixed coordinates
     369                    eval(['VarInit=DataOut.' VarName ';']);
     370                    if isempty(errormsg) && ~isequal(VarVal,VarInit)
     371                        displ_uvmat('ERROR',['time series requires constant coordinates ' VarName],checkrun)
    335372                        return
    336373                    end
    337                     DataOut=Field;%default
    338                     DataOut.NbDim=Field.NbDim+1; %add the time dimension for plots
    339                     nbvar=length(Field.ListVarName);
    340                     if nbvar==0
    341                         msgbox_uvmat('ERROR','no input variable selected in get_field')
    342                         return
    343                     end
    344                     testsum=2*ones(1,nbvar);%initiate flag for action on each variable
    345                     if isfield(Field,'VarAttribute') % look for coordinate and flag variables
    346                         for ivar=1:nbvar
    347                             if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
    348                                 var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
    349                                 if isequal(var_role,'errorflag')
    350                                     msgbox_uvmat('ERROR','do not handle error flags in time series')
    351                                     return
    352                                 end
    353                                 if isequal(var_role,'warnflag')
    354                                     testsum(ivar)=0;  % not recorded variable
    355                                     eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable
    356                                 end
    357                                 if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|...
    358                                         isequal(var_role,'coord_z')|isequal(var_role,'coord')
    359                                     testsum(ivar)=1; %constant coordinates, record without time evolution
    360                                 end
    361                             end
    362                             % check whether the variable ivar is a dimension variable
    363                             DimCell=Field.VarDimName{ivar};
    364                             if ischar(DimCell)
    365                                 DimCell={DimCell};
    366                             end
    367                             if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
    368                                 testsum(ivar)=1;
    369                             end
    370                         end
    371                     end
    372                     for ivar=1:nbvar
    373                         if testsum(ivar)==2
    374                             eval(['DataOut.' Field.ListVarName{ivar} '=[];'])
    375                         end
    376                     end
    377                     DataOut.ListVarName=[{'Time'} DataOut.ListVarName];
    378                 end
    379                
    380                 % add data to the current field
    381                 for ivar=1:length(Field.ListVarName)
    382                     VarName=Field.ListVarName{ivar};
    383                     VarVal=Field.(VarName);
    384                     if testsum(ivar)==2% test for recorded variable
    385                         if isempty(errormsg)
    386                             if isequal(Param.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
    387                                 if isempty(VarVal)
    388                                     msgbox_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(ifile))])
    389                                     return
    390                                 end
    391                                 VarVal=mean(VarVal,1);
    392                             end
    393                             VarVal=shiftdim(VarVal,-1); %shift dimension
    394                             DataOut.(VarName)=cat(1,DataOut.(VarName),VarVal);%concanete the current field to the time series
    395                         else
    396                             DataOut.(VarName)=cat(1,DataOut.(VarName),0);% put each variable to 0 in case of input reading error
    397                         end
    398                     elseif testsum(ivar)==1% variable representing fixed coordinates
    399                         eval(['VarInit=DataOut.' VarName ';']);
    400                         if isempty(errormsg) && ~isequal(VarVal,VarInit)
    401                             msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName])
    402                             return
    403                         end
    404                     end
    405                 end
    406                
    407                 % record the time:
    408                 if isempty(time)% time read in ncfiles
    409                     if isfield(Field,'Time')
    410                         DataOut.Time(filecounter,1)=Field.Time;
    411                     else
    412                         DataOut.Time(filecounter,1)=ifile;%default
    413                     end
    414                 else % time from ImaDoc prevails  TODO: correct
    415                   %  DataOut.Time(filecounter,1)=time{1}(i1_series{1})(ifile),j1_series{1}(ifile))+time(end,i2_series{end}(ifile),j2_series{end}(ifile)))/2;
    416                   DataOut.Time(filecounter,1)=i1_series{1}(ifile);% TODO : generalise
    417                 end
    418                
    419                 % record the number of missing input fields
    420                 if ~isempty(errormsg)
    421                     nbmissing=nbmissing+1;
    422                     display(['ifile=' num2str(ifile) ':' errormsg])
    423                 end
     374                end
     375            end
     376           
     377            % record the time:
     378            if isempty(time)% time read in ncfiles
     379                if isfield(Field,'Time')
     380                    DataOut.Time(filecounter,1)=Field.Time;
     381                else
     382                    DataOut.Time(filecounter,1)=ifile;%default
     383                end
     384            else % time from ImaDoc prevails  TODO: correct
     385                %  DataOut.Time(filecounter,1)=time{1}(i1_series{1})(ifile),j1_series{1}(ifile))+time(end,i2_series{end}(ifile),j2_series{end}(ifile)))/2;
     386                DataOut.Time(filecounter,1)=i1_series{1}(ifile);% TODO : generalise
     387            end
     388           
     389            % record the number of missing input fields
     390            if ~isempty(errormsg)
     391                nbmissing=nbmissing+1;
     392                display(['ifile=' num2str(ifile) ':' errormsg])
    424393            end
    425394        end
    426395    end
    427396    %%%%%%% END OF LOOP WITHIN A SLICE
    428    
     397    
    429398    %remove time for global attributes if exists
    430399    Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute));
     
    438407    end
    439408   
    440     % add time dimension 
     409    % add time dimension
    441410    for ivar=1:length(Field.ListVarName)
    442411        DimCell=Field.VarDimName(ivar);
     
    469438    % display nbmissing
    470439    if ~isequal(nbmissing,0)
    471         msgbox_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'])
     440        displ_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun)
    472441    end
    473442   
    474443    %name of result file
    475 %     filemean=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},'.nc','_1',i1_series{1}(i_slice));
    476     OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]);
     444    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]);
    477445    errormsg=struct2nc(OutputFile,DataOut); %save result file
    478446    if isempty(errormsg)
    479447        display([OutputFile ' written'])
    480448    else
    481         msgbox_uvmat('ERROR',['error in Series/struct2nc: ' errormsg])
     449        displ_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun)
    482450    end
    483451end
     
    486454figure
    487455haxes=axes;
     456if checkrun
    488457plot_field(DataOut,haxes)
     458end
    489459
    490460%% display the result file using the GUI get_field
Note: See TracChangeset for help on using the changeset viewer.