Changeset 960


Ignore:
Timestamp:
Jun 25, 2016, 11:20:40 AM (5 years ago)
Author:
sommeria
Message:

aver_stat modified to deal with volume slices

Location:
trunk/src/series
Files:
3 edited

Legend:

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

    r959 r960  
    1414% in series), the function ouput paramOut set the activation of the needed GUI elements
    1515%
    16 % Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
     16% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
    1717% see the current structure Param)
    1818%    .InputTable: cell of input file names, (several lines for multiple input)
     
    2525%             .RUN =0 for GUI input, =1 for function activation
    2626%             .RunMode='local','background', 'cluster': type of function  use
    27 %             
     27%
    2828%    .IndexRange: set the file or frame indices on which the action must be performed
    2929%    .FieldTransform: .TransformName: name of the selected transform function
     
    7070    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
    7171    ParamOut.OutputDirExt='.stat';%set the output dir extension
    72     ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
    73      % check for selection of a projection object
     72    ParamOut.OutputFileMode='NbSlice';% '=NbInput': one output file per input file index, '=NbInput_i': one file per input file index i, '=NbSlice': one file per slice
     73    % check for selection of a projection object
    7474    hseries=findobj(allchild(0),'Tag','series');% handles of the GUI series
    7575    if  ~isfield(Param,'ProjObject')
     
    106106        [i1,i2,j1,j2] = get_file_index(Param.IndexRange.last_i,last_j,PairString);
    107107        LastFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
    108         Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
     108            Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
    109109        if ~exist(LastFileName,'file')
    110              msgbox_uvmat('WARNING',['the last input file ' LastFileName ' does not exist'])
     110            msgbox_uvmat('WARNING',['the last input file ' LastFileName ' does not exist'])
    111111        end
    112112    end
    113113    % determine volume scan mode
    114         prompt = {'volume scan mode (Yes/No)'};
     114    prompt = {'volume scan mode (Yes/No)'};
    115115    dlg_title = 'determine volume scan';
    116116    num_lines= 1;
    117117    def     = { 'No'};
    118      answer=msgbox_uvmat('INPUT_Y-N','volume scan mode (OK/No)?');
    119 %     answer = inputdlg(prompt,dlg_title,num_lines,def);
     118    answer=msgbox_uvmat('INPUT_Y-N','volume scan mode (OK/No)?');
     119    %     answer = inputdlg(prompt,dlg_title,num_lines,def);
    120120    if isempty(answer)
    121121        return
    122122    end
    123123    %check input consistency
    124     if strcmp(answer,'Yes') 
    125             ParamOut.NbSlice=1;% set NbSlice to 1 ( for i index)
    126             ParamOut.ActionInput.CheckVolume=1;
     124    if strcmp(answer,'Yes')
     125        ParamOut.NbSlice=1;% set NbSlice to 1 ( for i index)
     126        ParamOut.ActionInput.CheckVolume=1;
    127127    end
    128128    return
     
    143143%% define the directory for result file (with path=RootPath{1})
    144144OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    145    
     145
    146146%% root input file(s) name, type and index series
    147147RootPath=Param.InputTable(:,1);
     
    150150NomType=Param.InputTable(:,4);
    151151FileExt=Param.InputTable(:,5);
     152
    152153hdisp=disp_uvmat('WAITING...','checking the file series',checkrun);
     154% gives the series of input file names and indices set by the input parameters:
    153155[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    154 if ~isempty(hdisp),delete(hdisp),end;
    155 %%%%%%%%%%%%
    156 % The cell array filecell is the list of input file names, while
    157156% filecell{iview,fileindex}:
    158157%        iview: line in the table corresponding to a given file series
    159 %        fileindex: file index within  the file series,
    160 % 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 
     158%        fileindex: file index with i and j reshaped as a 1D array
     159% 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
    161160% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    162 %%%%%%%%%%%%
     161if ~isempty(hdisp),delete(hdisp),end;%end the waiting display
     162
    163163NbView=numel(i1_series);%number of input file series (lines in InputTable)
    164164NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     
    166166NbField=NbField_j*NbField_i; %total number of fields
    167167
    168 %% determine the file type on each line from the first input file 
     168%% determine the file type on each line from the first input file
    169169ImageTypeOptions={'image','multimage','mmreader','video'};
    170170NcTypeOptions={'netcdf','civx','civdata'};
     
    191191    if diff_time>0
    192192        disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
    193     end   
     193    end
    194194end
    195195
     
    201201    rmpath(Param.FieldTransform.TransformPath)
    202202    if isfield(Param,'TransformInput')
    203             XmlData{1}.TransformInput=Param.TransformInput;
    204     end     
     203        XmlData{1}.TransformInput=Param.TransformInput;
     204    end
    205205end
    206206
    207207%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
    208  % EDIT FROM HERE
     208% EDIT FROM HERE
    209209
    210210%% check the validity of  input file types and set the output file type
     
    222222end
    223223if isfield(Param,'ProjObject') && ~strcmp(Param.ProjObject.Type,'plane')
    224       FileExtOut='.nc';% write result as .nc files (even for image input)
     224    FileExtOut='.nc';% write result as .nc files (even for image input)
    225225end
    226226
     
    253253    end
    254254end
    255 nbfiles=0;%counter of the successfully read files (bad files are skipped)
     255
    256256VarMesh=[];
    257257if isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'})
    258     if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'VarMesh')%case of histograms 
    259      VarMesh=Param.ActionInput.VarMesh;
     258    if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'VarMesh')%case of histograms
     259        VarMesh=Param.ActionInput.VarMesh;
    260260    else
    261        VarMesh=[];
    262        disp_uvmat('WARNING','automatic bin size for histograms, select aver_stat again to set the value',checkrun)
    263     end
    264 end
    265 
    266 %% set volume scan
    267 NbSlice_j=1;
     261        VarMesh=[];
     262        disp_uvmat('WARNING','automatic bin size for histograms, select aver_stat again to set the value',checkrun)
     263    end
     264end
     265
     266NbSlice_j=1;% number of j slices =1 except fo volume scan
    268267index_series=1:size(filecell,2);
    269 first_j_out=first_j;
    270 last_j_out=last_j;
     268index_j=1;
     269
     270%% set volume scan if requested
     271first_j_out=first_j;%first j index to use  for the output file name
     272last_j_out=last_j;%last j index to use for the output file name
    271273if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'CheckVolume') ...
    272274        && Param.ActionInput.CheckVolume
    273    index_j=Param.IndexRange.first_j:Param.IndexRange.incr_j:Param.IndexRange.last_j;
    274    NbSlice_j=numel(index_j);
    275    index_i=index_series(1:NbSlice_j:end);
    276 end
    277 
    278 %%% loop on slices (volume scan)
     275    index_j=Param.IndexRange.first_j:Param.IndexRange.incr_j:Param.IndexRange.last_j;
     276    NbSlice_j=numel(index_j);
     277    index_series=1:NbSlice_j:size(filecell,2);
     278end
     279
     280%% loop on j slices (volume scan)
    279281for islice=index_j
     282    nbfiles=0;%counter of the successfully read files (bad files are skipped)
    280283    if NbSlice_j>1
    281     first_j_out=islice;
    282     last_j_out=islice;
    283    
     284        first_j_out=islice;%first and last  j index to use  for the output file name are the current j index
     285        last_j_out=islice;
    284286    end
    285287    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    286288    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
    287     for index=index_i+index_j(islice)
     289    for index=index_series+index_j(islice)-index_j(1)
    288290        update_waitbar(WaitbarHandle,index/NbField)
    289291        if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
     
    295297        for iview=1:NbView
    296298            % reading input file(s)
    297             %InputFile=fullfile_uvmat(RootPath{iview},SubDir{iview},RootFile{iview},FileExt{iview},NomType{iview},first_i,last_i,first_j_out,last_j_out);
    298299            [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
    299300            if ~isempty(errormsg)
    300301                errormsg=['error of input reading: ' errormsg];
    301                 break
     302                break% leave the loop on views in case of error
    302303            end
    303304            if ~isempty(NbSlice_calib)
     
    307308        %%%%%%%%%%%%%%%% end loop on views (input lines) %%%%%%%%%%%%%%%%
    308309       
    309         if isempty(errormsg)
    310             Field=Data{1}; % default input field structure
    311             nbfiles=nbfiles+1; %increment the file counter
    312             %% coordinate transform (or other user defined transform)
    313             if ~isempty(transform_fct)
    314                 switch nargin(transform_fct)
    315                     case 4
    316                         if length(Data)==2
    317                             Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
    318                         else
    319                             Field=transform_fct(Data{1},XmlData{1});
    320                         end
    321                     case 3
    322                         if length(Data)==2
    323                             Field=transform_fct(Data{1},XmlData{1},Data{2});
    324                         else
    325                             Field=transform_fct(Data{1},XmlData{1});
    326                         end
    327                     case 2
     310        if ~isempty(errormsg)
     311            disp(errormsg)
     312            continue % go to next input field in case of error (file skipped in the average)
     313        end
     314        Field=Data{1}; % default input field structure
     315        nbfiles=nbfiles+1; %increment the file counter
     316       
     317        %% coordinate transform (or other user defined transform)
     318        if ~isempty(transform_fct)
     319            switch nargin(transform_fct)
     320                case 4
     321                    if length(Data)==2
     322                        Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
     323                    else
    328324                        Field=transform_fct(Data{1},XmlData{1});
    329                     case 1
    330                         Field=transform_fct(Data{1});
     325                    end
     326                case 3
     327                    if length(Data)==2
     328                        Field=transform_fct(Data{1},XmlData{1},Data{2});
     329                    else
     330                        Field=transform_fct(Data{1},XmlData{1});
     331                    end
     332                case 2
     333                    Field=transform_fct(Data{1},XmlData{1});
     334                case 1
     335                    Field=transform_fct(Data{1});
     336            end
     337        end
     338       
     339        %% field projection on an object
     340        if Param.CheckObject
     341            if strcmp(Param.ProjObject.ProjMode,'interp_tps')
     342                Field=tps_coeff_field(Field,check_proj_tps);% calculate tps coefficients if needed
     343            end
     344            [Field,errormsg]=proj_field(Field,Param.ProjObject,VarMesh);
     345            if ~isempty(errormsg)
     346                disp_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg],checkrun)
     347                return
     348            end
     349        end
     350       
     351        %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
     352        if nbfiles==1 %first field
     353            time_1=[];
     354            if isfield(Field,'Time')
     355                time_1=Field.Time(1);
     356            end
     357            DataOut=Field;%outcome reproduces the first (projected) field by default
     358            DataOut.Conventions='uvmat'; %suppress Conventions='uvmat/civdata' for civ input files
     359            if isfield(Param,'ProjObject')&& ismember(Param.ProjObject.ProjMode,{'inside','outside'})%case of histograms
     360                for ivar=1:numel(Field.ListVarName)% list of variable names before projection (histogram)
     361                    VarName=Field.ListVarName{ivar};
     362                    if isfield(Data{1},VarName)
     363                        DataOut.(VarName)=Field.(VarName);
     364                        DataOut.([VarName 'Histo'])=zeros(size(DataOut.(VarName)));
     365                        VarMesh=DataOut.(VarName)(2)-DataOut.(VarName)(1);
     366                    end
    331367                end
    332             end
    333            
    334             %% field projection on an object
    335             if Param.CheckObject
    336                 if strcmp(Param.ProjObject.ProjMode,'interp_tps')
    337                     Field=tps_coeff_field(Field,check_proj_tps);% calculate tps coefficients if needed
    338                 end
    339                 [Field,errormsg]=proj_field(Field,Param.ProjObject,VarMesh);
    340                 if ~isempty(errormsg)
    341                     disp_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg],checkrun)
    342                     return
    343                 end
    344             end
    345            
    346             %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
    347             if nbfiles==1 %first field
    348                 time_1=[];
    349                 if isfield(Field,'Time')
    350                     time_1=Field.Time(1);
    351                 end
    352                 DataOut=Field;%outcome reproduces the first (projected) field by default
    353                 DataOut.Conventions='uvmat'; %suppress Conventions='uvmat/civdata' for civ input files
    354                 if isfield(Param,'ProjObject')&& ismember(Param.ProjObject.ProjMode,{'inside','outside'})%case of histograms
    355                     for ivar=1:numel(Field.ListVarName)% list of variable names before projection (histogram)
     368                disp(['mesh for histogram = ' num2str(VarMesh)])
     369            else
     370                errorvar=zeros(numel(Field.ListVarName));%index of errorflag associated to each variable
     371                if isfield(Field,'VarAttribute')
     372                    for ivar=1:numel(Field.ListVarName)
    356373                        VarName=Field.ListVarName{ivar};
    357                         if isfield(Data{1},VarName)
    358                             DataOut.(VarName)=Field.(VarName);
    359                             DataOut.([VarName 'Histo'])=zeros(size(DataOut.(VarName)));
    360                             VarMesh=DataOut.(VarName)(2)-DataOut.(VarName)(1);
    361                         end
    362                     end
    363                     disp(['mesh for histogram = ' num2str(VarMesh)])
    364                 else
    365                     errorvar=zeros(numel(Field.ListVarName));%index of errorflag associated to each variable
    366                     if isfield(Field,'VarAttribute')
    367                         for ivar=1:numel(Field.ListVarName)
    368                             VarName=Field.ListVarName{ivar};
    369                             DataOut.(VarName)=zeros(size(DataOut.(VarName)));% initiate each field to zero
    370                             NbData.(VarName)=zeros(size(DataOut.(VarName)));% initiate the nbre of good data to zero
    371                            
    372                             for iivar=1:length(Field.VarAttribute)
    373                                 if isequal(Field.VarDimName{iivar},Field.VarDimName{ivar})&& isfield(Field.VarAttribute{iivar},'Role')...
    374                                         && strcmp(Field.VarAttribute{iivar}.Role,'errorflag')
    375                                     errorvar(ivar)=iivar; % index of the errorflag variable corresponding to ivar
    376                                 end
     374                        DataOut.(VarName)=zeros(size(DataOut.(VarName)));% initiate each field to zero
     375                        NbData.(VarName)=zeros(size(DataOut.(VarName)));% initiate the nbre of good data to zero
     376                       
     377                        for iivar=1:length(Field.VarAttribute)
     378                            if isequal(Field.VarDimName{iivar},Field.VarDimName{ivar})&& isfield(Field.VarAttribute{iivar},'Role')...
     379                                    && strcmp(Field.VarAttribute{iivar}.Role,'errorflag')
     380                                errorvar(ivar)=iivar; % index of the errorflag variable corresponding to ivar
    377381                            end
    378382                        end
    379                         DataOut.ListVarName(errorvar(errorvar~=0))=[]; %remove errorflag from result
    380                         DataOut.VarDimName(errorvar(errorvar~=0))=[]; %remove errorflag from result
    381                         DataOut.VarAttribute(errorvar(errorvar~=0))=[]; %remove errorflag from result
     383                    end
     384                    DataOut.ListVarName(errorvar(errorvar~=0))=[]; %remove errorflag from result
     385                    DataOut.VarDimName(errorvar(errorvar~=0))=[]; %remove errorflag from result
     386                    DataOut.VarAttribute(errorvar(errorvar~=0))=[]; %remove errorflag from result
     387                else
     388                    for ivar=1:numel(Field.ListVarName)
     389                        VarName=Field.ListVarName{ivar};
     390                        DataOut.(VarName)=zeros(size(DataOut.(VarName)));% initiate each field to zero
     391                        NbData.(VarName)=zeros(size(DataOut.(VarName)));% initiate the nbre of good data to zero
     392                    end
     393                end
     394               
     395            end
     396        end   %current field
     397        for ivar=1:length(DataOut.ListVarName)
     398            VarName=DataOut.ListVarName{ivar};
     399            sizmean=size(DataOut.(VarName));
     400            siz=size(Field.(VarName));
     401            if isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'})
     402                if isfield(Data{1},VarName)
     403                    MaxValue=max(DataOut.(VarName));% current max of histogram absissa
     404                    MinValue=min(DataOut.(VarName));% current min of histogram absissa
     405                    %                     VarMesh=Field.VarAttribute{ivar}.Mesh;
     406                    MaxIndex=round(MaxValue/VarMesh);
     407                    MinIndex=round(MinValue/VarMesh);
     408                    MaxIndex_new=round(max(Field.(VarName)/VarMesh));% max of the current field
     409                    MinIndex_new=round(min(Field.(VarName)/VarMesh));
     410                    if MaxIndex_new>MaxIndex% the variable max for the current field exceeds the previous one
     411                        DataOut.(VarName)=[DataOut.(VarName) VarMesh*(MaxIndex+1:MaxIndex_new)];% append the new variable values
     412                        DataOut.([VarName 'Histo'])=[DataOut.([VarName 'Histo']) zeros(1,MaxIndex_new-MaxIndex)]; % append the new histo values
     413                    end
     414                    if MinIndex_new <= MinIndex-1
     415                        DataOut.(VarName)=[VarMesh*(MinIndex_new:MinIndex-1) DataOut.(VarName)];% insert the new variable values
     416                        DataOut.([VarName 'Histo'])=[zeros(1,MinIndex-MinIndex_new) DataOut.([VarName 'Histo'])];% insert the new histo values
     417                        ind_start=1;
    382418                    else
    383                         for ivar=1:numel(Field.ListVarName)
    384                             VarName=Field.ListVarName{ivar};
    385                             DataOut.(VarName)=zeros(size(DataOut.(VarName)));% initiate each field to zero
    386                             NbData.(VarName)=zeros(size(DataOut.(VarName)));% initiate the nbre of good data to zero
    387                         end
    388                     end
    389                    
     419                        ind_start=MinIndex_new-MinIndex+1;
     420                    end
     421                    DataOut.([VarName 'Histo'])(ind_start:ind_start+MaxIndex_new-MinIndex_new)=...
     422                        DataOut.([VarName 'Histo'])(ind_start:ind_start+MaxIndex_new-MinIndex_new)+Field.([VarName 'Histo']);
    390423                end
    391             end   %current field
    392             for ivar=1:length(DataOut.ListVarName)
    393                 VarName=DataOut.ListVarName{ivar};
    394                 sizmean=size(DataOut.(VarName));
    395                 siz=size(Field.(VarName));
    396                 if isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'})
    397                     if isfield(Data{1},VarName)
    398                         MaxValue=max(DataOut.(VarName));% current max of histogram absissa
    399                         MinValue=min(DataOut.(VarName));% current min of histogram absissa
    400                         %                     VarMesh=Field.VarAttribute{ivar}.Mesh;
    401                         MaxIndex=round(MaxValue/VarMesh);
    402                         MinIndex=round(MinValue/VarMesh);
    403                         MaxIndex_new=round(max(Field.(VarName)/VarMesh));% max of the current field
    404                         MinIndex_new=round(min(Field.(VarName)/VarMesh));
    405                         if MaxIndex_new>MaxIndex% the variable max for the current field exceeds the previous one
    406                             DataOut.(VarName)=[DataOut.(VarName) VarMesh*(MaxIndex+1:MaxIndex_new)];% append the new variable values
    407                             DataOut.([VarName 'Histo'])=[DataOut.([VarName 'Histo']) zeros(1,MaxIndex_new-MaxIndex)]; % append the new histo values
    408                         end
    409                         if MinIndex_new <= MinIndex-1
    410                             DataOut.(VarName)=[VarMesh*(MinIndex_new:MinIndex-1) DataOut.(VarName)];% insert the new variable values
    411                             DataOut.([VarName 'Histo'])=[zeros(1,MinIndex-MinIndex_new) DataOut.([VarName 'Histo'])];% insert the new histo values
    412                             ind_start=1;
    413                         else
    414                             ind_start=MinIndex_new-MinIndex+1;
    415                         end
    416                         DataOut.([VarName 'Histo'])(ind_start:ind_start+MaxIndex_new-MinIndex_new)=...
    417                             DataOut.([VarName 'Histo'])(ind_start:ind_start+MaxIndex_new-MinIndex_new)+Field.([VarName 'Histo']);
    418                     end
    419                 elseif ~isequal(DataOut.(VarName),0)&& ~isequal(siz,sizmean)
    420                     disp_uvmat('ERROR',['unequal size of input field ' VarName ', need to project  on a grid'],checkrun)
    421                     return
     424            elseif ~isequal(DataOut.(VarName),0)&& ~isequal(siz,sizmean)
     425                disp_uvmat('ERROR',['unequal size of input field ' VarName ', need to project  on a grid'],checkrun)
     426                return
     427            else
     428                if errorvar(ivar)==0
     429                    check_bad=isnan(Field.(VarName));%=0 for NaN data values, 1 else
    422430                else
    423                     if errorvar(ivar)==0
    424                         check_bad=isnan(Field.(VarName));%=0 for NaN data values, 1 else
    425                     else
    426                         check_bad=isnan(Field.(VarName)) | Field.(Field.ListVarName{errorvar(ivar)})~=0;%=0 for NaN or error flagged data values, 1 else
    427                     end
    428                     Field.(VarName)(check_bad)=0; %set to zero NaN or data marked by error flag
    429                     DataOut.(VarName)=DataOut.(VarName)+ double(Field.(VarName)); % update the sum
    430                     NbData.(VarName)=NbData.(VarName)+ ~check_bad;% records the number of data for each point
     431                    check_bad=isnan(Field.(VarName)) | Field.(Field.ListVarName{errorvar(ivar)})~=0;%=0 for NaN or error flagged data values, 1 else
    431432                end
    432             end
    433             %%%%%%%%%%%%   END MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
     433                Field.(VarName)(check_bad)=0; %set to zero NaN or data marked by error flag
     434                DataOut.(VarName)=DataOut.(VarName)+ double(Field.(VarName)); % update the sum
     435                NbData.(VarName)=NbData.(VarName)+ ~check_bad;% records the number of data for each point
     436            end
     437        end
     438        %%%%%%%%%%%%   END MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
     439    end
     440    %%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%%
     441   
     442    if ~(isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'}))
     443        for ivar=1:length(Field.ListVarName)
     444            VarName=Field.ListVarName{ivar};
     445            DataOut.(VarName)=DataOut.(VarName)./NbData.(VarName); % normalize the mean
     446        end
     447    end
     448    nbmissing=numel(index_series+index_j(islice)-index_j(1))-nbfiles;
     449    if nbmissing~=0
     450        if NbSlice_j==1
     451        disp_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipped'],checkrun)
    434452        else
    435             disp(errormsg)
    436         end
    437     end
    438     %%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%%
    439 
    440 if ~(isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'}))
    441     for ivar=1:length(Field.ListVarName)
    442         VarName=Field.ListVarName{ivar};
    443         DataOut.(VarName)=DataOut.(VarName)./NbData.(VarName); % normalize the mean
    444     end
    445 end
    446 nbmissing=NbField-nbfiles;
    447 if nbmissing~=0
    448     disp_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipped'],checkrun)
    449 end
    450 if isempty(time) % time is read from files
    451     if isfield(Field,'Time')
    452         time_end=Field.Time(1);%last time read
    453         if ~isempty(time_1)
    454             DataOut.Time=time_1;
    455             DataOut.Time_end=time_end;
    456         end
    457     end
    458 else  % time from ImaDoc prevails if it exists
    459     DataOut.Time=time(1);
    460     DataOut.Time_end=time(end);
    461 end
    462 
    463 %% writing the result file
    464 OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j_out,last_j_out);
    465 if strcmp(FileExtOut,'.png') %case of images
    466     if isequal(FileInfo{1}.BitDepth,16)||(numel(FileInfo)==2 &&isequal(FileInfo{2}.BitDepth,16))
    467         DataOut.A=uint16(DataOut.A);
    468         imwrite(DataOut.A,OutputFile,'BitDepth',16); % case of 16 bit images
    469     else
    470         DataOut.A=uint8(DataOut.A);
    471         imwrite(DataOut.A,OutputFile,'BitDepth',8); % case of 16 bit images
    472     end
    473     disp([OutputFile ' written']);
    474 else %case of netcdf  file , determine global attributes
    475     errormsg=struct2nc(OutputFile,DataOut); %save result file
    476     if isempty(errormsg)
     453            disp(['WARNING: ' num2str(nbmissing) ' input files are missing or skipped in slice ' num2str(islice)])
     454        end
     455    end
     456    if isempty(time) % time is read from files
     457        if isfield(Field,'Time')
     458            time_end=Field.Time(1);%last time read
     459            if ~isempty(time_1)
     460                DataOut.Time=time_1;
     461                DataOut.Time_end=time_end;
     462            end
     463        end
     464    else  % time from ImaDoc prevails if it exists
     465        DataOut.Time=time(1);
     466        DataOut.Time_end=time(end);
     467    end
     468   
     469    %% writing the result file
     470    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j_out,last_j_out);
     471    if strcmp(FileExtOut,'.png') %case of images
     472        if isequal(FileInfo{1}.BitDepth,16)||(numel(FileInfo)==2 &&isequal(FileInfo{2}.BitDepth,16))
     473            DataOut.A=uint16(DataOut.A);
     474            imwrite(DataOut.A,OutputFile,'BitDepth',16); % case of 16 bit images
     475        else
     476            DataOut.A=uint8(DataOut.A);
     477            imwrite(DataOut.A,OutputFile,'BitDepth',8); % case of 16 bit images
     478        end
    477479        disp([OutputFile ' written']);
    478     else
    479         disp(['error in writting result file: ' errormsg])
    480     end
    481 end  % end averaging  loop
     480    else %case of netcdf  file , determine global attributes
     481        errormsg=struct2nc(OutputFile,DataOut); %save result file
     482        if isempty(errormsg)
     483            disp([OutputFile ' written']);
     484        else
     485            disp(['error in writting result file: ' errormsg])
     486        end
     487    end  % end averaging  loop
    482488end
    483489
  • trunk/src/series/merge_proj.m

    r959 r960  
    111111end
    112112
    113 %% root input file type
     113%% root input file(s) name, type and index series
    114114RootPath=Param.InputTable(:,1);
    115115RootFile=Param.InputTable(:,3);
     
    117117NomType=Param.InputTable(:,4);
    118118FileExt=Param.InputTable(:,5);
     119
     120hdisp=disp_uvmat('WAITING...','checking the file series',checkrun);
     121% gives the series of input file names and indices set by the input parameters:
    119122[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    120 %%%%%%%%%%%%
    121 % The cell array filecell is the list of input file names, while
    122123% filecell{iview,fileindex}:
    123124%        iview: line in the table corresponding to a given file series
    124 %        fileindex: file index within  the file series,
     125%        fileindex: file index with i and j reshaped as a 1D array
    125126% 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
    126127% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    127 %%%%%%%%%%%%
    128 % NbSlice=1;%default
    129 % if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
    130 %     NbSlice=Param.IndexRange.NbSlice;
    131 % end
     128if ~isempty(hdisp),delete(hdisp),end;%end the waiting display
     129
    132130NbView=numel(i1_series);%number of input file series (lines in InputTable)
    133131NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
  • trunk/src/series/time_series.m

    r924 r960  
    153153NomType=Param.InputTable(:,4);
    154154FileExt=Param.InputTable(:,5);
     155
    155156hdisp=disp_uvmat('WAITING...','checking the file series',checkrun);
     157% gives the series of input file names and indices set by the input parameters:
    156158[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    157 if ~isempty(hdisp),delete(hdisp),end;
    158 %%%%%%%%%%%%
    159 % The cell array filecell is the list of input file names, while
    160159% filecell{iview,fileindex}:
    161160%        iview: line in the table corresponding to a given file series
    162 %        fileindex: file index within  the file series,
    163 % i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
     161%        fileindex: file index with i and j reshaped as a 1D array
     162% 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 
    164163% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    165 %%%%%%%%%%%%
    166 nbview=numel(i1_series);%number of input file series (lines in InputTable)
    167 nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
    168 nbfield_i=size(i1_series{1},2); %nb of fields for the i index
    169 nbfield=nbfield_j*nbfield_i; %total number of fields
     164if ~isempty(hdisp),delete(hdisp),end;%end the waiting display
     165
     166NbView=numel(i1_series);%number of input file series (lines in InputTable)
     167NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     168NbField_i=size(i1_series{1},2); %nb of fields for the i index
     169NbField=NbField_j*NbField_i; %total number of fields
    170170
    171171%% determine the file type on each line from the first input file
Note: See TracChangeset for help on using the changeset viewer.