Ignore:
Timestamp:
Jun 11, 2012, 9:35:38 AM (12 years ago)
Author:
sommeria
Message:

aver_stat modified in the new rationalized form.
OTHER series FCTS NOT OPERATIONAL

File:
1 edited

Legend:

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

    r442 r447  
    33% function GUI_input=aver_stat(Param)
    44%
     5%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
    56%OUTPUT
    67% GUI_input=list of options in the GUI series.fig needed for the function
    78%
    89%INPUT:
    9 % Param: structure containing all the parameters read on the GUI series
    10 %  or name of the xml file containing these parameters (BATCH case)
     10% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
     11% In batch mode, Param is the name of the corresponding xml file containing the same information
     12% In the absence of input (as activated when the current Action is selected
     13% in series), the function ouput GUI_input set the activation of the needed GUI elements
    1114%
     15% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     16%    .InputTable: cell of input file names, (several lines for multiple input)
     17%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
     18%    .OutputSubDir: name of the subdirectory for data outputs
     19%    .OutputDir: directory for data outputs, including path
     20%    .Action: .ActionName: name of the current activated function
     21%             .ActionPath:   path of the current activated function
     22%    .IndexRange: set the file or frame indices on which the action must be performed
     23%    .FieldTransform: .TransformName: name of the selected transform function
     24%                     .TransformPath:   path  of the selected transform function
     25%                     .TransformHandle: corresponding function handle
     26%    .InputFields: sub structure describing the input fields withfields
     27%              .FieldName: name of the field
     28%              .VelType: velocity type
     29%              .FieldName_1: name of the second field in case of two input series
     30%              .VelType_1: velocity type of the second field in case of two input series
     31%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
     32%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     33
    1234function GUI_input=aver_stat(Param)
    13 %----------------------------------------------------------------------
    14 % --- make average on a series of files
    15 %----------------------------------------------------------------------
    16 %INPUT:
    17 %i1_series: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
    18 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
    19 %j1_series: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
    20 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
    21 %OTHER INPUTS given by the structure Series
    22 %  Series.Time:
    23 %  Series.GeometryCalib:%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
    24 if ~exist('Param','var')
    25     GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
    26         'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
    27         'RootFile';'on';... %root input file name ('on' by default)
    28         'FileExt';'on';... %input file extension ('on' by default)
    29         'NomType';'on';...%type of file indexing ('on' by default)
     35
     36%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
     37if ~exist('Param','var') % case with no input parameter
     38    GUI_input={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
     39        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    3040        'NbSlice';'on'; ...%nbre of slices ('off' by default)
    31         'VelTypeMenu';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
    32         'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
    33         'CoordType'; 'on';...%can use a transform function
    34         'GetObject';'on';...%can use projection object(option 'off'/'one'/'two',
    35         %'GetMask';'on'...%can use mask option   
    36         %'PARAMETER'; %options: name of the user defined parameter',repeat a line for each parameter
     41        'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     42        'FieldName';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     43        'FieldTransform'; 'on';...%can use a transform function
     44        'ProjObject';'on';...%can use projection object(option 'off'/'on',
     45        'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
     46        'OutputDirExt';'.stat';...%set the output dir extension
    3747               ''};
    3848        return
    3949end
    4050
    41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    42 
    43 %% input parameters
    44 % read the xml file for batch case
     51%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     52%% get input parameters, file names and indices
     53% BATCH  case: read the xml file for batch case
    4554if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
    4655    Param=xml2struct(Param);
    4756    checkrun=0;
    48 else %  RUN case: parameters introduced as the input structure Param
     57% RUN case: parameters introduced as the input structure Param 
     58else
    4959    hseries=guidata(Param.hseries);%handles of the GUI series
    50     WaitbarPos=get(hseries.waitbar_frame,'Position');
    51     checkrun=1;
    52 end
     60    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
     61    checkrun=1; % indicate the RUN option is used
     62end
     63% get the set of input file names (cell array filecell), and the lists of
     64% input file or frame indices i1_series,i2_series,j1_series,j2_series
    5365[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    54 
    55 %% projection object
    56 test_object=get(hseries.GetObject,'Value');
    57 if test_object%isfield(Series,'sethandles')
    58     hset_object=findobj(allchild(0),'tag','set_object');
    59     ProjObject=read_GUI(hset_object);
    60     answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Type ' before averaging']);
    61     if ~isequal(answeryes,'Yes')
    62         return
    63     end
    64 end
    65 
    66 %% root input file and type
    67     RootPath=Param.InputTable(:,1);
    68     RootFile=Param.InputTable(:,3);
    69     SubDir=Param.InputTable(:,2);
    70     NomType=Param.InputTable(:,4);
    71     FileExt=Param.InputTable(:,5);
    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')||isequal(lower(ext),'.vol')
    76     testima(1)=1;
    77 end
    78 if length(FileExt)>=2
    79     ext_1=FileExt{2};
    80     form=imformats(ext_1([2:end]));%test valid Matlab image formats
    81     if ~isempty(form)||isequal(lower(ext_1),'.avi')||isequal(lower(ext_1),'.vol')
    82         testima(2)=1;
    83     end
    84     if testima(2)~=testima(1)
    85         msgbox_uvmat('ERROR','images and netcdf files cannot be compared')
    86         return
    87     end
    88 end
    89 
    90 
    91 %% Number of input series: this function  accepts two input file series at most (then it operates on the difference of fields)
    92 nbview=length(RootPath);
    93 if nbview>2 
    94     RootPath=RootPath(1:2);
    95     set(hseries.RootPath,'String',RootPath)
    96     SubDir=SubDir(1:2);
    97     set(hseries.SubDir,'String',SubDir)
    98     RootFile=RootFile(1:2);
    99     set(hseries.RootFile,'String',RootFile)
    100     NomType=NomType(1:2);
    101     FileExt=FileExt(1:2);
    102     set(hseries.FileExt,'String',FileExt)
    103     nbview=2;
    104 end
    105 
    106 %% determine image type
    107 hhh=which('mmreader');
     66% filecell{iview,fileindex}: cell array representing the list of file names
     67%        iview: line in the table corresponding to a given file series
     68%        fileindex: file index within  the file series,
     69% 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
     70% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
     71% set of frame indices used for movie or multimage input
     72if ~isempty(j1_series)
     73    frame_index=j1_series;
     74else
     75    frame_index=i1_series;
     76end
     77
     78%% root input file(s) and type
     79RootPath=Param.InputTable(:,1);
     80RootFile=Param.InputTable(:,3);
     81SubDir=Param.InputTable(:,2);
     82NomType=Param.InputTable(:,4);
     83FileExt=Param.InputTable(:,5);
     84
     85% numbers of slices and file indices
     86NbSlice=1;%default
     87if isfield(Param.IndexRange,'NbSlice')
     88    NbSlice=Param.IndexRange.NbSlice;
     89end
     90nbview=size(i1_series,1);%number of input file series (lines in InputTable)
     91nbfield_j=size(i1_series,2); %nb of consecutive fields at each level(burst
     92nbfield=nbfield_j*size(i1_series,3); %total number of files or frames
     93nbfield_i=floor(nbfield/NbSlice);%total number of i indexes (adjusted to an integer number of slices)
     94nbfield=nbfield_i*nbfield_j; %total number of fields after adjustement
     95
     96%determine the file type on each line from the first input file
     97ImageTypeOptions={'image','multimage','mmreader','video'};
     98NcTypeOptions={'netcdf','civx','civdata'};
    10899for iview=1:nbview
    109     if isequal(FileExt{iview},'.nc')||isequal(FileExt{iview},'.cdf')
    110         FileType{iview}='netcdf';
    111     elseif isequal(lower(FileExt{iview}),'.avi')
    112         if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
    113             MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
    114             FileType{iview}='movie';
    115         else
    116             FileType{iview}='avi';
    117         end
    118     elseif isequal(lower(FileExt{iview}),'.vol')
    119         FileType{iview}='vol';
    120     else
    121        form=imformats(FileExt{iview}(2:end));
    122        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
    123            if isequal(NomType{iview},'*');
    124                FileType{iview}='multimage';
    125            else
    126                FileType{iview}='image';
    127            end
    128        end
    129     end
    130 end
    131 
    132 %% number of slices
    133 NbSlice=Param.IndexRange.NbSlice;
    134 
    135 %% Field and velocity type (the same for the two views)
    136 Field_str=get(hseries.FieldMenu,'String');
    137 FieldName=[]; %default
    138 testfield=get(hseries.FieldMenu,'Visible');
    139 if isequal(testfield,'on')
    140     val=get(hseries.FieldMenu,'Value');
    141     FieldName=Field_str(val);%the same set of fields for all views
    142     if isequal(FieldName,{'get_field...'})
    143         hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
    144         if length(hget_field)>1
    145             delete(hget_field(2:end))
    146         elseif isempty(hget_field)
    147            filename=...
    148                  name_generator(fullfile(RootPath{1},RootFile{1}),i1_series{1}(1),j1_series{1}(1),FileExt{1},NomType{1},1,i2_series{1}(1),num_j2{1}(1),SubDir{1});
    149            get_field(filename);
    150            return
    151         end
    152         SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
    153     end
    154 end
    155 
    156 %% get the velocity type
    157 testcivx=0;
    158 if ~isequal(FieldName,{'get_field...'})
    159     testcivx=isequal(FileType{1},'netcdf');
    160 end
    161 if testcivx
    162     VelType_str=get(hseries.VelTypeMenu,'String');
    163     VelType_val=get(hseries.VelTypeMenu,'Value');
    164     VelType{1}=VelType_str{VelType_val};
    165     if nbview==2
    166         VelType_str=get(hseries.VelTypeMenu_1,'String');
    167         VelType_val=get(hseries.VelTypeMenu_1,'Value');
    168         VelType{2}=VelType_str{VelType_val};
    169     end
     100    [FileType{iview},FileInfo{iview},Object{iview}]=get_file_type(filecell{iview,1});
     101    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
     102    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
    170103end
    171104
     
    237170    diff_time=max(max(diff(time)));
    238171    if diff_time>0
    239         msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
     172        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
    240173    end   
    241174end
    242 if size(time,2) < i2_series{1}(end) || size(time,3) < num_j2{1}(end)% time array absent or too short in ImaDoc xml file'
     175if size(time,2) < i2_series(1,end) || size(time,3) < j2_series(1,end)% time array absent or too short in ImaDoc xml file'
    243176    time=[];
    244 end
    245 
    246 %% Name(s) of output file(s)
    247 filebase_out=filebase{1};% the result file has the same root name as the input file series (and the first one is chosen in case of two input series)
    248 %file extension of the result 
    249 if testima %case of images
    250     ext_out='.png';
    251 else
    252     ext_out='.nc';
    253 end
    254 subdir_result=[SubDir{1} '.stat'];%subdirectory for the results
    255 pathdir=RootPath{1};% full subdirectory name, including path
    256 checkdetect=1;
    257 while checkdetect %create a new subdir if the netcdf files already exist
    258     checkdetect=exist(fullfile(pathdir,subdir_result));
    259     if checkdetect% if a nesult dir already exists
    260         r=regexp(subdir_result,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
    261         if isempty(r)
    262             r(1).root=[subdir_result '_'];
    263             r(1).num1='0';
    264         end
    265         subdir_result=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
    266     end
    267 end
    268 NomTypeOut='_1-2';
    269 fileresult{1}=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},ext_out,NomTypeOut,i1_series{1}(1),i1_series{1}(end),[],[]);
    270 
    271 % A REPRNDRE CAS MULTI-NIVEAU:
    272 %     pathdir=fullfile(RootPath{1},subdir_result);% full subdirectory name, including path
    273 %     if NbSlice==1% keep track of the first and lsat indices of the input files
    274 %         %NomTypeOut=nomtype2pair(Param.InputTable{1,4},i2_series{end}(end)-i1_series{1}(1),j2_series{end}(end)-j1_series{1}(1));
    275 %         NomTypeOut='_1-2';
    276 %         fileresult{1}=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},ext_out,NomTypeOut,i1_series{1}(1),i1_series{1}(end),[],[]);
    277 %         testexist=exist(fileresult{1},'file');
    278 %     else % simplified indexing with i_slice for multiple slices
    279 %         testexist=0;
    280 %         for i_slice=1:NbSlice
    281 %             fileresult{1}=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},ext_out,NomTypeOut,i_slice,[],[],[]);
    282 %             if exist(fileresult{i_slice},'file')
    283 %                 testexist=1;
    284 %                 break
    285 %             end
    286 %         end
    287 %     end
    288 %     if testexist
    289 %         subdir_result=[subdir_result '.0'];
    290 %     end
    291 % end
    292 % create result directory if needed
    293 if ~exist(fullfile(RootPath{1},subdir_result),'dir')
    294     [m1,m2,m3]=mkdir(fullfile(RootPath{1},subdir_result));
    295     if ~isequal(m2,'')
    296         msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation
    297     end
    298 end
    299 [xx,msg2] = fileattrib(fullfile(RootPath{1},subdir_result),'+w','g'); %yield writing access (+w) to user group (g)
    300 if ~strcmp(msg2,'')
    301     msgbox_uvmat('ERROR',['pb of permission for ' fullfile(RootPath{1},subdir_result) ': ' msg2])%error message for writting access
    302     return
    303177end
    304178
    305179%% coordinate transform or other user defined transform
    306180transform_fct='';%default
    307 if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'fct_handle')
    308     transform_fct=Param.FieldTransform.fct_handle;
    309 end
    310 
    311 %% main loop
    312 siz=size(i1_series{1});
    313 nbfield2=siz(1); %nb of consecutive fields at each level(burst
    314 nbfield=siz(1)*siz(2);
    315 nbfield=floor(nbfield/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
    316 
    317 % loop on slices
     181if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle')
     182    transform_fct=Param.FieldTransform.TransformHandle;
     183end
     184%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
     185 % EDIT FROM HERE
     186
     187%% check the validity of  input file types
     188if CheckImage{1}
     189    FileExtOut='.png'; % write result as .png images for image inputs
     190elseif CheckNc{1}
     191    FileExtOut='.nc';% write result as .nc files for netcdf inputs
     192else
     193    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
     194    return
     195end
     196if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
     197        msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
     198    return
     199end
     200NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
     201if NbSlice~=nbfield_j
     202    answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
     203    if ~strcmp(answer,'Yes')
     204        return
     205    end
     206end
     207
     208%% Set field names and velocity types
     209InputFields{1}=[];%default (case of images)
     210if isfield(Param,'InputFields')
     211    InputFields{1}=Param.InputFields;
     212end
     213if nbview==2
     214    InputFields{2}=[];%default (case of images)
     215    if isfield(Param,'InputFields')
     216        InputFields{2}=Param.InputFields{1};%default
     217        if isfield(Param.InputFields,'FieldName_1')
     218            InputFields{2}.FieldName=Param.InputFields.FieldName_1;
     219            if isfield(Param.InputFields,'VelType_1')
     220                InputFields{2}.VelType=Param.InputFields.VelType_1;
     221            end
     222        end
     223    end
     224end
     225
     226%% Initiate output fields
     227%initiate the output structure as a copy of the first input one (reproduce fields)
     228[DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
     229if ~isempty(errormsg)
     230    msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
     231    return
     232end
     233time_1=[];
     234if isfield(DataOut,'Time')
     235    time_1=DataOut.Time(1);
     236end
     237if CheckNc{iview}
     238    if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
     239        DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
     240    end
     241    DataOut.Conventions='uvmat';
     242    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
     243    ActionKey='Action';
     244    while isfield(DataOut,ActionKey)
     245        ActionKey=[ActionKey '_1'];
     246    end
     247    DataOut.(ActionKey)=Param.Action;
     248    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
     249    if isfield(DataOut,'Time')
     250        DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
     251    end
     252end
     253
     254%% MAIN LOOP ON SLICES
     255%%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
    318256for i_slice=1:NbSlice
    319     for ifield=1:nbfield
    320          indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice
    321     end
    322     S=0; %initiate the image sum S
     257    index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice
    323258    nbfiles=0;
    324259    nbmissing=0;
    325     % averaging loop
    326     for index=1:nbfield*nbfield2
    327  %       stopstate=get(hseries.RUN,'BusyAction');
    328  %       if isequal(stopstate,'queue') % enable STOP command
    329          %   update_waitbar(hseries.waitbar,WaitbarPos,index/(nbfield*nbfield2))
    330          if checkrun
    331              update_waitbar(hseries.waitbar_frame,WaitbarPos,index/(nbfield*nbfield2))
    332              stopstate=get(hseries.RUN,'BusyAction');
    333          else
    334              stopstate='queue';
    335          end
    336             ifile=indselect(index);
     260   
     261   %initiate result fields
     262   for ivar=1:length(DataOut.ListVarName)
     263       DataOut.(DataOut.ListVarName{ivar})=0; % initialise all fields to zero
     264   end
     265
     266    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
     267    for index=index_slice
     268        if checkrun
     269            update_waitbar(hseries.waitbar_frame,WaitbarPos,index/(nbfield))
     270            stopstate=get(hseries.RUN,'BusyAction');
     271        else
     272            stopstate='queue';
     273        end
     274       
     275        %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
     276        for iview=1:nbview
    337277            % reading input file(s)
    338             for iview=1:nbview
    339                     filename=filecell{iview,index};
    340                     if ~isequal(FileType{iview},'netcdf')
    341                     Data{iview}.ListVarName={'A'};
    342                     Data{iview}.AName='image';
    343                     switch FileType{iview}
    344                         case 'movie'
    345                             A=read(MovieObject{iview},i1_series{iview}(ifile));
    346                         case 'avi'
    347                             mov=aviread(filename,i1_series{iview}(ifile));
    348                             A=frame2im(mov(1));
    349                         case 'vol'
    350                             A=imread(filename);
    351                         case 'multimage'
    352                             A=imread(filename,i1_series{iview}(ifile));
    353                         case 'image'
    354                             A=imread(filename);
    355                     end
    356                     Data{iview}.ListVarName={'AY','AX','A'}; %
    357                     Atype{iview}=class(A);
    358                     npy=size(A,1);
    359                     npx=size(A,2);
    360                     nbcolor=size(A,3);
    361                     if nbcolor==3
    362                         Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}};
    363                     else
    364                         Data{iview}.VarDimName={'AY','AX',{'AY','AX'}};
    365                     end
    366                     Data{iview}.AY=[npy-0.5 0.5];
    367                     Data{iview}.AX=[0.5 npx-0.5];
    368                     Data{iview}.A=double(A);
    369                     Data{iview}.CoordUnit='pixel';
    370                 elseif testcivx
    371                     [Data{iview},VelTypeOut,errormsg]=read_civxdata(filename,FieldName,VelType);
    372                     if ~isempty(errormsg)
    373                           msgbox_uvmat('ERROR',['error of input reading: ' errormsg])
    374                     return
    375                     end
    376                 else
    377                     [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data
    378                     Data{iview}.VarAttribute=SubField.VarAttribute;
    379                 end
    380                 if isfield(Data{iview},'Txt')
    381                     msgbox_uvmat('ERROR',['error of input reading: ' Data{iview}.Txt])
    382                     return
    383                 end
    384             end
    385            
     278            [Data{iview},ParamOut,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index(iview,index));
     279            if ~isempty(errormsg)
     280                errormsg=['error of input reading: ' errormsg];
     281                break
     282            end
     283            if ~isempty(NbSlice_calib)
     284                Data{iview}.ZIndex=mod(i1_series(iview,index)-1,NbSlice_calib{1})+1;%Zindex for phys transform
     285            end
     286        end
     287        Field=[]; % initiate the current input field structure
     288        %%%%%%%%%%%%%%%% end loop on views (input lines) %%%%%%%%%%%%%%%%
     289        %%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
     290        % EDIT FROM HERE
     291
     292        if isempty(errormsg)     
    386293            % coordinate transform (or other user defined transform)
    387294            if ~isempty(transform_fct)
    388                 if ~isempty(NbSlice_calib)
    389                     Data{iview}.ZIndex=mod(i1_series{iview}(ifile)-1,NbSlice_calib{1})+1;%Zindex for phys transform
    390                 end
    391295                if nbview==2
    392296                    [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
     
    400304           
    401305            % field calculation (vort, div...)
    402             if testcivx
    403                 Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
     306            if strcmp(FileType{1},'civx')||strcmp(FileType{1},'civ')
     307                Data{1}=calc_field(InputFields{1}.FieldName,Data{1});%calculate field (vort..)
    404308            end
    405309           
    406310            % field substration (for two input file series)
    407311            if length(Data)==2
     312                if strcmp(FileType{2},'civx')||strcmp(FileType{2},'civ')
     313                    Data{2}=calc_field(InputFields{2}.FieldName,Data{2});%calculate field (vort..)
     314                end
    408315                [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
    409316                if ~isempty(errormsg)
     
    414321                Field=Data{1};
    415322            end
    416             if test_object
     323            if Param.CheckObject
    417324                [Field,errormsg]=proj_field(Field,ProjObject);
    418325                if ~isempty(errormsg)
     
    422329            end
    423330            nbfiles=nbfiles+1;
    424             if nbfiles==1 %first field
    425                 time_1=[];
    426                 if isfield(Field,'Time')
    427                     time_1=Field.Time(1);
     331           
     332            %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
     333            %update sum
     334            for ivar=1:length(Field.ListVarName)
     335                VarName=Field.ListVarName{ivar};
     336                sizmean=size(DataOut.(VarName));
     337                siz=size(Field.(VarName));
     338                if ~isequal(DataOut.(VarName),0)&& ~isequal(siz,sizmean)
     339                    msgbox_uvmat('ERROR',['unequal size of input field ' VarName ', need to project  on a grid'])
     340                    return
     341                else
     342                    DataOut.(VarName)=DataOut.(VarName)+ double(Field.(VarName)); % update the sum
    428343                end
    429                 DataMean=Field;%default
    430             else
    431                 for ivar=1:length(Field.ListVarName)
    432                     VarName=Field.ListVarName{ivar};
    433                     eval(['sizmean=size(DataMean.' VarName ');']);
    434                     eval(['siz=size(Field.' VarName ');']);
    435                     if ~isequal(siz,sizmean)
    436                         msgbox_uvmat('ERROR',['unequal size of input field ' VarName ', need to project  on a grid'])
    437                         return
    438                     else
    439                         eval(['DataMean.' VarName '=DataMean.' VarName '+ Field.' VarName ';']); % update the sum
    440                     end
    441                 end
    442             end
    443 %         end
    444     end
    445     %end averaging loop
     344            end
     345            %%%%%%%%%%%%   END MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
     346        else
     347            display(errormsg) 
     348        end
     349    end
     350    %%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%%
     351   
    446352    for ivar=1:length(Field.ListVarName)
    447353        VarName=Field.ListVarName{ivar};
    448         eval(['DataMean.' VarName '=DataMean.' VarName '/nbfiles;']); % normalize the mean
     354        DataOut.(VarName)=DataOut.(VarName)/nbfiles; % normalize the mean
    449355    end
    450356    if nbmissing~=0
     
    455361            time_end=Field.Time(1);%last time read
    456362            if ~isempty(time_1)
    457                 DataMean.Time=time_1;
    458                 DataMean.Time_end=time_end;
     363                DataOut.Time=time_1;
     364                DataOut.Time_end=time_end;
    459365            end
    460366        end
    461367    else  % time from ImaDoc prevails
    462         DataMean.Time=time(1,i1_series{1}(1),j1_series{1}(1));
    463         DataMean.Time_end=time(end,i1_series{end}(end),j1_series{end}(end));
     368        DataOut.Time=time(1,i1_series(1,1),j1_series(1,1));
     369        DataOut.Time_end=time(end,i1_series(end,end),j1_series(end,end));
    464370    end
    465371   
    466372    %writing the result file
    467     if testima %case of images
    468         if isequal(Atype{1},'uint16')
    469             imwrite(uint16(DataMean.A),fileresult{i_slice},'BitDepth',16); % case of 16 bit images
     373    OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,1),i1_series(1,end),i_slice,[]);
     374    if CheckImage{1} %case of images
     375        if isequal(FileInfo{1}.BitDepth,16)||(numel(FileInfo)==2 &&isequal(FileInfo{2}.BitDepth,16))
     376            DataOut.A=uint16(DataOut.A);
     377            imwrite(DataOut.A,OutputFile,'BitDepth',16); % case of 16 bit images
    470378        else
    471             imwrite(uint8(DataMean.A),fileresult{i_slice},'BitDepth',8); % case of 8 bit images
    472         end
    473         display([fileresult{i_slice} ' written']);
     379            DataOut.A=uint8(DataOut.A);
     380            imwrite(DataOut.A,OutputFile,'BitDepth',8); % case of 16 bit images
     381        end
     382        display([OutputFile ' written']);
    474383    else %case of netcdf input file , determine global attributes
    475         if isempty(strcmp('Conventions',DataMean.ListGlobalAttribute))
    476             DataMean.ListGlobalAttribute=['Conventions' DataMean.ListGlobalAttribute];
    477         end
    478         DataMean.Conventions='uvmat';
    479         DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {Param.Action}];
    480         ActionKey='Action';
    481         while isfield(DataMean,ActionKey)
    482             ActionKey=[ActionKey '_1'];
    483         end
    484         DataMean.(ActionKey)=Param.Action;
    485         DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {ActionKey}];
    486         if isfield(DataMean,'Time')
    487             DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {'Time','Time_end'}];
    488         end
    489         errormsg=struct2nc(fileresult{i_slice},DataMean); %save result file
     384        errormsg=struct2nc(OutputFile,DataOut); %save result file
    490385        if isempty(errormsg)
    491             display([fileresult{i_slice} ' written']);
     386            display([OutputFile ' written']);
    492387        else
    493388            msgbox_uvmat('ERROR',['error in writting result file: ' errormsg])
     
    495390        end
    496391    end  % end averaging  loop
    497 end % end loop on slices
     392end
     393%%%%%%%%%%%%%%%% end loop on slices %%%%%%%%%%%%%%%%
    498394
    499395%% reproduce ImaDoc/GeometryCalib for image series
    500 if isfield(XmlData{1},'GeometryCalib') && ~isempty(XmlData{1}.GeometryCalib)
    501     [tild,RootFile]=fileparts(filebase_out);
    502     outputxml=fullfile(pathdir,[RootFile '.xml']);
    503     errormsg=update_imadoc(XmlData{1}.GeometryCalib,outputxml);% introduce the calibration data in the xml file
    504     if strcmp(errormsg,'')
    505         display(['GeometryCalib transferred to ' outputxml])
    506     else
    507         msgbox_uvmat('ERROR',errormsg);
    508     end
    509 end
     396% if isfield(XmlData{1},'GeometryCalib') && ~isempty(XmlData{1}.GeometryCalib)
     397%     [tild,RootFile]=fileparts(filebase_out);
     398%     outputxml=fullfile(pathdir,[RootFile '.xml']);
     399%     errormsg=update_imadoc(XmlData{1}.GeometryCalib,outputxml);% introduce the calibration data in the xml file
     400%     if strcmp(errormsg,'')
     401%         display(['GeometryCalib transferred to ' outputxml])
     402%     else
     403%         msgbox_uvmat('ERROR',errormsg);
     404%     end
     405% end
    510406
    511407%% open the result file with uvmat
    512408hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
    513409delete(hget_field)
    514 uvmat(fileresult{end})
     410uvmat(OutputFile)% open the last result file with uvmat
Note: See TracChangeset for help on using the changeset viewer.