Changeset 855


Ignore:
Timestamp:
Jan 23, 2015, 9:48:26 AM (6 years ago)
Author:
sommeria
Message:

testcivadded

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mouse_down.m

    r809 r855  
    246246end
    247247
    248 if isempty(huvmat)%further options require the uvmat GUI
    249     return
    250 end
    251 
    252 %% ruler has second priority
    253 if test_ruler && ~isempty(xy)
    254     AxeData.RulerCoord(1,1:2)=xy(1,1:2);
    255     AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
    256     AxeData.Drawing='ruler';
    257     set(hchild,'UserData',AxeData);
    258     return
    259 end
    260 
    261248%% PIV test
    262249if test_piv
     
    268255    copyobj(AxeData.TitleHandle,newaxes)
    269256    colorbar
    270 end
     257    % export image correlation matrix and local U,V values in the work space
     258    global DataCorrImage
     259    DataCorrImage.Corr=get(AxeData.CurrentCorrImage,'CData');
     260    Uvec=get(AxeData.CurrentVector,'XData');
     261    DataCorrImage.U=Uvec(2);
     262    Vvec=get(AxeData.CurrentVector,'YData');
     263    DataCorrImage.V=Vvec(2);
     264    evalin('base','global DataCorrImage')%make CurData global in the workspace
     265    evalin('base','DataCorrImage') %display CurData in the workspace
     266    commandwindow; %brings the Matlab command window to the front
     267end
     268
     269if isempty(huvmat)%further options require the uvmat GUI
     270    return
     271end
     272
     273%% ruler has second priority
     274if test_ruler && ~isempty(xy)
     275    AxeData.RulerCoord(1,1:2)=xy(1,1:2);
     276    AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
     277    AxeData.Drawing='ruler';
     278    set(hchild,'UserData',AxeData);
     279    return
     280end
     281
    271282
    272283%% desable  object creation and vector editing if NbDim different from 2
  • trunk/src/mouse_motion.m

    r837 r855  
    240240                xround=Field.X(ind_pt);
    241241                yround=Field.Y(ind_pt);
    242                 %                         par.Grid=[xround size(Field.A,1)-yround+1];
    243242                par.Grid=[xround yround];
    244243                % mark the correlation box with a rectangle
     
    247246                par.ImageHeight=size(par.ImageA,1);
    248247                par.ImageWidth=size(par.ImageA,2);
    249                 Param.Civ1=par;
     248                Param.ActionInput.Civ1=par;
    250249                ibx2=floor((par.CorrBoxSize(1)-1)/2);
    251250                iby2=floor((par.CorrBoxSize(2)-1)/2);
     
    269268                    set(hhhh,'Position',[xround-isx2+shiftx yround-isy2+shifty 2*isx2 2*isy2])
    270269                end
    271                 [Data,errormsg,result_conv]= civ_matlab(Param);
     270                Param.Action.RUN=1;
     271                Param.ActionInput.ListCompareMode='PIV';
     272                [Data,errormsg,result_conv]= civ_series(Param);
    272273                if ~isempty(errormsg)
    273274                    text_displ_5=errormsg;
  • trunk/src/series.m

    r852 r855  
    14601460        if strcmp(ActionExt,'.m')% case of Matlab function (uncompiled)
    14611461            NbCore=1;% one core used only (limitation of Matlab licences)
    1462             msgbox_uvmat('WARNING','Number of cores =1: select the compiled version civ_matlab.sh for multi-core processing');
     1462            msgbox_uvmat('WARNING','Number of cores =1: select the compiled version .sh for multi-core processing');
    14631463            extra_oar='';
    14641464        else
  • trunk/src/series/civ_input.m

    r854 r855  
    8383    set(handles.CheckThreshold,'Visible','on')
    8484    set(handles.CheckDeformation,'Value',0)% desactivate (work in progress)
    85     set(handles.CheckDecimal,'Value',0)% desactivate (work in progress)
     85    %set(handles.CheckDecimal,'Value',0)% desactivate (work in progress)
    8686end
    8787switch Param.Action.ActionName
     
    169169
    170170%% display the min and max indices for the whole file series
     171if isempty(Param.IndexRange.MaxIndex_i)|| isempty(Param.IndexRange.MinIndex_i)
     172    msgbox_uvmat('ERROR','REFRESH the input files in the GUI series')
     173     return
     174end
    171175MaxIndex_i=Param.IndexRange.MaxIndex_i(iview_image);
    172176MinIndex_i=Param.IndexRange.MinIndex_i(iview_image);
     
    281285    end
    282286else  %case of netcdf file opening, start with the stage read in the file if the input file is being refreshed
    283     if isequal(get(hhseries.REFRESH,'BackgroundColor'),[1 1 0]) && ~isfield(Param.ActionInput,'ConfigSource')
    284         answer=msgbox_uvmat('INPUT_Y-N',['import the civ parameters from the netcdf file']);
    285         if strcmp(answer,'Yes')
     287    if isequal(get(hhseries.REFRESH,'BackgroundColor'),[1 1 0]) &&...
     288            ~(isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ConfigSource'))
     289%         answer=msgbox_uvmat('INPUT_Y-N',['import the civ parameters from the netcdf file']);
     290%         if strcmp(answer,'Yes')
    286291            for index = 1:min(ind_opening,5)
    287292                set(handles.(ListOptions{index}),'value',0)
     
    294299            end
    295300            checkrefresh=1;
    296         end
     301%         end
    297302    end
    298303    if ind_opening>=3
    299         set(handles.iterate,'Visible','on')% make visible the switch 'iterate/repet' for Civ2.
     304        set(handles.CheckCiv3,'Visible','on')% make visible the switch 'iterate/repet' for Civ2.
    300305    else
    301         set(handles.iterate,'Visible','off')
     306        set(handles.CheckCiv3,'Visible','off')
    302307    end
    303308end
     
    493498end
    494499if max(checkbox(1:3))==0 && get(handles.CheckCiv2,'UserData')==6,% no operation asked before Civ2 and input file ready for civ3
    495     set(handles.iterate,'Visible','on')
    496 else
    497     set(handles.iterate,'Visible','off')
     500    set(handles.CheckCiv3,'Visible','on')
     501else
     502    set(handles.CheckCiv3,'Visible','off')
    498503end
    499504
     
    513518%------------------------------------------------------------------------
    514519
    515 ActionInput=read_GUI(handles.civ_input);
    516 
    517 %% correct inpput inconsistencies
     520ActionInput=read_GUI(handles.civ_input);% read the infos on the GUI civ_input
     521
     522%% correct input inconsistencies
    518523if isfield(ActionInput,'Civ1')
    519524    checkeven=(mod(ActionInput.Civ1.CorrBoxSize,2)==0);
     
    531536end
    532537
     538%% correct mask or grid name for Windows system (replace '\' by '/')
     539if isfield(ActionInput,'Civ1')
     540    if isfield(ActionInput.Civ1,'Mask')
     541        ActionInput.Civ1.Mask=regexprep(ActionInput.Civ1.Mask,'\','/');
     542    end
     543    if isfield(ActionInput.Civ1,'Grid')
     544        ActionInput.Civ1.Grid=regexprep(ActionInput.Civ1.Grid,'\','/');
     545    end
     546end
     547if isfield(ActionInput,'Civ2')
     548    if isfield(ActionInput.Civ2,'Mask')
     549        ActionInput.Civ2.Mask=regexprep(ActionInput.Civ2.Mask,'\','/');
     550    end
     551    if isfield(ActionInput.Civ2,'Grid')
     552        ActionInput.Civ2.Grid=regexprep(ActionInput.Civ2.Grid,'\','/');
     553    end
     554end
     555
     556%% exit the GUI and close it
    533557handles.output.ActionInput=ActionInput;
    534 % correct mask or grid name for Windows system (replace '\' by '/')
    535 if isfield(handles.output.ActionInput,'Civ1')
    536     if isfield(handles.output.ActionInput.Civ1,'Mask')
    537         handles.output.ActionInput.Civ1.Mask=regexprep(handles.output.ActionInput.Civ1.Mask,'\','/');
    538     end
    539     if isfield(handles.output.ActionInput.Civ1,'Grid')
    540         handles.output.ActionInput.Civ1.Grid=regexprep(handles.output.ActionInput.Civ1.Grid,'\','/');
    541     end
    542 end
    543 if isfield(handles.output.ActionInput,'Civ2')
    544     if isfield(handles.output.ActionInput.Civ2,'Mask')
    545         handles.output.ActionInput.Civ2.Mask=regexprep(handles.output.ActionInput.Civ2.Mask,'\','/');
    546     end
    547     if isfield(handles.output.ActionInput.Civ2,'Grid')
    548         handles.output.ActionInput.Civ2.Grid=regexprep(handles.output.ActionInput.Civ2.Grid,'\','/');
    549     end
    550 end
    551558guidata(hObject, handles);% Update handles structure
    552559uiresume(handles.civ_input);
     
    16891696drawnow
    16901697if get(handles.TestCiv1,'Value')
    1691     set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch
    1692     [Data,Param.Civ1]=get_param_civ1(handles);
    1693     Grid=civ_matlab(Param);% get the grid of x, y positions set for PIV
    1694     hview_field=view_field(Data); %view the image in the GUI view_field
     1698    set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch 
     1699    %Param.Action.RUN=1;
     1700    Param.ActionInput=read_GUI(handles.civ_input);
     1701    par_civ=Param.ActionInput.Civ1;
     1702    [Data,ImageName_B]=get_param_civ1(handles);
     1703
     1704    %% create the figure view_field for image visualization
     1705    hview_field=view_field(Data); %view the image in the GUI view_field
    16951706    set(0,'CurrentFigure',hview_field)
    16961707    hhview_field=guihandles(hview_field);
     
    16981709    ViewData=get(hview_field,'UserData');
    16991710    ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
    1700     ViewData.PlotAxes.B=imread(Param.Civ1.ImageName_B);%store the second image in the UserData of the GUI view_field
    1701     ViewData.PlotAxes.X=Grid.Civ1_X; %keep the set of points in memeory
    1702     ViewData.PlotAxes.Y=Grid.Civ1_Y;
    1703     set(hview_field,'UserData',ViewData)
    1704     corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
     1711    ViewData.PlotAxes.B=imread(ImageName_B);%store the second image in the UserData of the GUI view_field
     1712   
     1713    %% prepare measurement grid
     1714    if isfield(par_civ,'Grid')% grid points set as input
     1715            par_civ.Grid=dlmread(par_civ.Grid);
     1716            par_civ.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
     1717    else% automatic grid
     1718        minix=floor(par_civ.Dx/2)-0.5;
     1719        maxix=minix+par_civ.Dx*floor((size(Data.A,2)-1)/par_civ.Dx);
     1720        miniy=floor(par_civ.Dy/2)-0.5;
     1721        maxiy=minix+par_civ.Dy*floor((size(Data.A,1)-1)/par_civ.Dy);
     1722        [GridX,GridY]=meshgrid(minix:par_civ.Dx:maxix,miniy:par_civ.Dy:maxiy);
     1723        ViewData.PlotAxes.X=reshape(GridX,[],1);
     1724        ViewData.PlotAxes.Y=reshape(GridY,[],1);
     1725    end
     1726
     1727    set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
     1728   
     1729    %% look for a current figure for image correlation display
     1730    corrfig=findobj(allchild(0),'tag','corrfig');
    17051731    if isempty(corrfig)
    17061732        corrfig=figure;
     
    17081734        set(corrfig,'name','image correlation')
    17091735        set(corrfig,'DeleteFcn',{@closeview_field})%
    1710         % end
    17111736        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
    17121737    else
     
    17331758function TestPatch1_Callback(hObject, eventdata, handles)
    17341759
    1735 if get(handles.TestPatch1,'Value')
    1736     if get(handles.CheckCiv1,'Value')
    1737         if ~get(handles.CheckFix1,'Value')
    1738             msgbox_uvmat('ERROR','perform FIX1 before testing Patch1')
    1739             return
    1740         end
    1741         set(handles.TestPatch1,'BackgroundColor',[1 1 0])
    1742         drawnow
    1743         [Data,Param.Civ1]=get_param_civ1(handles);
    1744         Param.Fix1=read_GUI(handles.Fix1);
    1745         [Data,errormsg]=civ_matlab(Param);% get the civ1 results
    1746         errormsg=struct2nc('test_civ1.nc',Data);
    1747         InputFile='test_civ1.nc';
    1748         if ~isempty(errormsg)
    1749             msgbox_uvmat('ERROR',['error in temporary file writing: ' errormsg])
    1750             return
    1751         end
    1752     else
    1753         hseries=findobj(allchild(0),'Tag','series');
    1754         hhseries=guidata(hseries);
    1755         InputTable=get(hhseries.InputTable,'Data');
    1756         if ~strcmp(InputTable{1,5},'.nc');
    1757             msgbox_uvmat('ERROR', 'To test patch, first perform Civ1 and Fix1, then open the resulting netcdf file with ''series''')
    1758             return
    1759         end
    1760         set(handles.TestPatch1,'BackgroundColor',[1 1 0])
    1761         drawnow       
    1762         ref_i=str2double(get(handles.ref_i,'String'));
    1763         if strcmp(get(handles.ref_j,'Visible'),'on')
    1764             ref_j=str2double(get(handles.ref_j,'String'));
    1765         else
    1766             ref_j=1;%default
    1767         end
    1768         PairString=get(hhseries.PairString,'Data');
    1769         [i1,i2,j1,j2] = get_file_index(ref_i,ref_j,PairString{1});
    1770         InputFile=fullfile_uvmat(InputTable{1,1},InputTable{1,2},InputTable{1,3},InputTable{1,5},InputTable{1,4},...
    1771             i1,i2,j1,j2);
    1772     end
    1773     Param=[];
    1774     Param.Patch1=read_GUI(handles.Patch1);
    1775     Param.Patch1.CivFile=InputFile;
    1776     SmoothingParam=(Param.Patch1.FieldSmooth/10)*2.^(1:7);%scan the smoothing param from 1/10 to 12.8 current value
    1777     Data=nc2struct(InputFile);
     1760if get(handles.TestPatch1,'Value')% if TestPatch1 is activated
     1761     set(handles.TestPatch1,'BackgroundColor',[1 1 0])%paint TestPatch1 button in yellow to induicate activation
     1762     hseries=findobj(allchild(0),'Tag','series');
     1763     Param=read_GUI(hseries);
     1764     Param.Action.RUN=1;
     1765     Param.ActionInput=read_GUI(handles.civ_input);
     1766     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
     1767     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
     1768     
     1769     %% prepare Param for iterative Patch processing without input file reading
     1770     Param.Civ1_X=Data.Civ1_X;
     1771     Param.Civ1_Y=Data.Civ1_Y;
     1772     Param.Civ1_U=Data.Civ1_U;
     1773     Param.Civ1_V=Data.Civ1_V;
     1774     Param.Civ1_FF=Data.Civ1_FF;
     1775     Param=rmfield(Param,'InputTable');%desactivate input file reading
     1776    if isfield(Param.ActionInput,'Civ1')
     1777        Param.ActionInput=rmfield(Param.ActionInput,'Civ1');%desactivate civ1: remove civ1 input param if relevant
     1778    end
     1779    if isfield(Param.ActionInput,'Fix1')
     1780        Param.ActionInput=rmfield(Param.ActionInput,'Fix1');%desactivate fix1:remove fix1 input param if relevant
     1781    end
     1782    SmoothingParam=(Param.ActionInput.Patch1.FieldSmooth/10)*2.^(1:7);%scan the smoothing param from 1/10 to 12.8 current value
    17781783    NbGood=numel(find(Data.Civ1_FF==0));
    17791784    for irho=1:7
    1780         Param.Patch1.FieldSmooth=SmoothingParam(irho);
    1781         [Data,errormsg]=civ_matlab(Param);% get the grid of x, y positions set for PIV
     1785        Param.ActionInput.Patch1.FieldSmooth=SmoothingParam(irho);
     1786        [Data,errormsg]= civ_series(Param);%apply the processing fct
    17821787        if ~isempty(errormsg)
    17831788            msgbox_uvmat('ERROR',errormsg)
     
    17941799    grid on
    17951800    legend('rms velocity diff. Patch1-Civ1 (pixels)','proportion of excluded vectors (between 0 to 1)')
    1796     XLabel('smoothing parameter')
    1797     YLabel('smoothing effect')
     1801    xlabel('smoothing parameter')
     1802    ylabel('smoothing effect')
    17981803    set(handles.TestPatch1,'BackgroundColor',[1 0 0])
    17991804else
     
    20202025
    20212026%------------------------------------------------------------------------
    2022 function [Data,par_civ1]=get_param_civ1(handles)
     2027function [Data,ImageName_B]=get_param_civ1(handles)
    20232028
    20242029 ref_i=str2double(get(handles.ref_i,'String'));% read reference i index
     
    20682073 Data.nx=[1 size(Data.A,2)];
    20692074 Data.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
    2070  par_civ1=read_GUI(handles.Civ1);
    2071  FileInfo=get_file_info(ImageName_A);
    2072  par_civ1.FileTypeA=FileInfo.FileType;
    2073  par_civ1.ImageWidth=size(Data.A,2);
    2074  par_civ1.ImageHeight=size(Data.A,1);
    2075  par_civ1.Mask='all';% will provide only the grid set for PIV, no image correlation
    2076  par_civ1.FrameIndexA=num2str(i1);
    2077  par_civ1.FrameIndexB=num2str(i2);
    2078  par_civ1.ImageName_B=ImageName_B;
     2075% par_civ1=read_GUI(handles.Civ1);
     2076% FileInfo=get_file_info(ImageName_A);
     2077% par_civ1.FileTypeA=FileInfo.FileType;
     2078% par_civ1.ImageWidth=size(Data.A,2);
     2079% par_civ1.ImageHeight=size(Data.A,1);
     2080% par_civ1.Mask='all';% will provide only the grid set for PIV, no image correlation
     2081% par_civ1.FrameIndexA=num2str(i1);
     2082% par_civ1.FrameIndexB=num2str(i2);
     2083% par_civ1.ImageName_B=ImageName_B;
    20792084
    20802085%------------------------------------------------------------------------
     
    21222127end
    21232128
    2124 % --- Executes on selection change in iterate.
    2125 function iterate_Callback(hObject, eventdata, handles)
     2129% --- Executes on selection change in CheckCiv3.
     2130function CheckCiv3_Callback(hObject, eventdata, handles)
    21262131   
    21272132%------------------------------------------------------------------------
  • trunk/src/series/civ_series.m

    r854 r855  
    55%   filter_tps: make interpolation-smoothing
    66%------------------------------------------------------------------------
    7 % function [Data,errormsg,result_conv]= civ_series(Param,ncfile)
     7% function [Data,errormsg,result_conv]= civ_series(Param)
    88%
    99%OUTPUT
     
    1313%
    1414%INPUT:
    15 % Param: input images and processing parameters
    16 %     .Civ1: for civ1
    17 %     .Fix1:
    18 %     .Patch1:
    19 %     .Civ2: for civ2
    20 %     .Fix2:
    21 %     .Patch2:
    22 % ncfile: name of a netcdf file to be created for the result (extension .nc)
    23 %
     15% Param: Matlab structure of input  parameters
     16%     Param contains info of the GUI series using the fct read_GUI.
     17%     Param.Action.RUN = 0 (to set the status of the GUI series) or =1 to RUN the computation
     18%     Param.InputTable: sets the input file(s)
     19%           if absent, the fct looks for input data in Param.ActionInput     (test mode)
     20%     Param.OutputSubDir: sets the folder name of output file(s,
     21%           if absent no file is produced, result in the output structure Data (test mode)
     22%     Param.ActionInput: substructure with the parameters provided by the GUI civ_input
     23%                      .Civ1: parameters for civ1
     24%                      .Fix1: parameters for fix1
     25%                      .Patch1:
     26%                      .Civ2: for civ2
     27%                      .Fix2:
     28%                      .Patch2:
     29
    2430%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    2531%  Copyright 2011-2014, LEGI / CNRS UJF G-INP, Joel.Sommeria@legi.grenoble-inp.fr
     
    7379    checkrun=0;
    7480end
     81
     82%% test input
    7583if ~isfield(Param,'ActionInput')
    7684     disp_uvmat('ERROR','no parameter set for PIV',checkrun)
    7785        return
    7886end
    79 hseries=findobj(allchild(0),'Tag','series');
    80 RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
    81 WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
    82 
    83 %% input files and indexing
    84 % NbField=1;
    85 MaxIndex_i=Param.IndexRange.MaxIndex_i;
    86 MinIndex_i=Param.IndexRange.MinIndex_i;
    87 MaxIndex_j=ones(size(MaxIndex_i));MinIndex_j=ones(size(MinIndex_i));
    88 if isfield(Param.IndexRange,'MaxIndex_j')&& isfield(Param.IndexRange,'MinIndex_j')
    89     MaxIndex_j=Param.IndexRange.MaxIndex_j;
    90     MinIndex_j=Param.IndexRange.MinIndex_j;
    91 end
    92 if isfield(Param,'InputTable')
    93    [tild,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);   
    94     % iview_nc=0;% series index (iview) for an input nc file (for civ2 or patch2)
    95     iview_A=0;% series index (iview) for the first image series
    96     iview_B=0;% series index (iview) for the second image series (only non zero for option 'shift' comparing two image series )
    97     if Param.ActionInput.CheckCiv1
    98         iview_A=1;% usual PIV, the image series is on the first line of the table
    99     elseif Param.ActionInput.CheckCiv2 % civ2 is performed without Civ1, a netcdf file series is needed in the first table line
    100         iview_A=2;% the second line is used for the input images of Civ2
    101     end
    102     if strcmp(Param.ActionInput.ListCompareMode,'shift')
    103         iview_B=iview_A+1; % the second image series is on the next line of the input table
    104     end
    105     if iview_A~=0
    106         RootPath_A=Param.InputTable{iview_A,1};
    107         RootFile_A=Param.InputTable{iview_A,3};
    108         SubDir_A=Param.InputTable{iview_A,2};
    109         NomType_A=Param.InputTable{iview_A,4};
    110         FileExt_A=Param.InputTable{iview_A,5};
    111         if iview_B==0
    112             iview_B=iview_A;% the second image series is the same as the first
    113         end
    114         RootPath_B=Param.InputTable{iview_B,1};
    115         RootFile_B=Param.InputTable{iview_B,3};
    116         SubDir_B=Param.InputTable{iview_B,2};
    117         NomType_B=Param.InputTable{iview_B,4};
    118         FileExt_B=Param.InputTable{iview_B,5};
    119     end
    120    
    121     PairCiv2='';
    122     switch Param.ActionInput.ListCompareMode
    123         case 'PIV'
    124             PairCiv1=Param.ActionInput.PairIndices.ListPairCiv1;
    125             if isfield(Param.ActionInput.PairIndices,'ListPairCiv2')
    126                 PairCiv2=Param.ActionInput.PairIndices.ListPairCiv2;%string which determines the civ2 pair
    127             end
    128             if iview_A==1% if Civ1 is performed
    129                 [i1_series_Civ1,i2_series_Civ1,j1_series_Civ1,j2_series_Civ1,check_bounds,NomTypeNc]=...
    130                     find_pair_indices(PairCiv1,i1_series{1},j1_series{1},MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j);
    131                 if ~isempty(PairCiv2)
    132                     [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds_Civ2]=...
    133                         find_pair_indices(PairCiv2,i1_series{1},j1_series{1},MinIndex_i(1),MaxIndex_i(1),MinIndex_j(1),MaxIndex_j(1));
    134                     check_bounds=check_bounds | check_bounds_Civ2;
     87iview_A=0;%default values
     88NbField=1;
     89RUNHandle=[];
     90CheckInputFile=isfield(Param,'InputTable');%= 1 in test use for TestCiv (no nc file involved)
     91CheckOutputFile=isfield(Param,'OutputSubDir');%= 1 in test use for TestPatch (no nc file produced)
     92
     93%% input files and indexing (skipped in Test mode)
     94if CheckInputFile
     95    hseries=findobj(allchild(0),'Tag','series');
     96    RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
     97    WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
     98    MaxIndex_i=Param.IndexRange.MaxIndex_i;
     99    MinIndex_i=Param.IndexRange.MinIndex_i;
     100    MaxIndex_j=ones(size(MaxIndex_i));MinIndex_j=ones(size(MinIndex_i));
     101    if isfield(Param.IndexRange,'MaxIndex_j')&& isfield(Param.IndexRange,'MinIndex_j')
     102        MaxIndex_j=Param.IndexRange.MaxIndex_j;
     103        MinIndex_j=Param.IndexRange.MinIndex_j;
     104    end
     105    if isfield(Param,'InputTable')
     106        [tild,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     107        % iview_nc=0;% series index (iview) for an input nc file (for civ2 or patch2)
     108        iview_A=0;% series index (iview) for the first image series
     109        iview_B=0;% series index (iview) for the second image series (only non zero for option 'shift' comparing two image series )
     110        if Param.ActionInput.CheckCiv1
     111            iview_A=1;% usual PIV, the image series is on the first line of the table
     112        elseif Param.ActionInput.CheckCiv2 % civ2 is performed without Civ1, a netcdf file series is needed in the first table line
     113            iview_A=2;% the second line is used for the input images of Civ2
     114        end
     115        if strcmp(Param.ActionInput.ListCompareMode,'shift')
     116            iview_B=iview_A+1; % the second image series is on the next line of the input table
     117        end
     118        if iview_A~=0
     119            RootPath_A=Param.InputTable{iview_A,1};
     120            RootFile_A=Param.InputTable{iview_A,3};
     121            SubDir_A=Param.InputTable{iview_A,2};
     122            NomType_A=Param.InputTable{iview_A,4};
     123            FileExt_A=Param.InputTable{iview_A,5};
     124            if iview_B==0
     125                iview_B=iview_A;% the second image series is the same as the first
     126            end
     127            RootPath_B=Param.InputTable{iview_B,1};
     128            RootFile_B=Param.InputTable{iview_B,3};
     129            SubDir_B=Param.InputTable{iview_B,2};
     130            NomType_B=Param.InputTable{iview_B,4};
     131            FileExt_B=Param.InputTable{iview_B,5};
     132        end
     133       
     134        PairCiv2='';
     135        switch Param.ActionInput.ListCompareMode
     136            case 'PIV'
     137                PairCiv1=Param.ActionInput.PairIndices.ListPairCiv1;
     138                if isfield(Param.ActionInput.PairIndices,'ListPairCiv2')
     139                    PairCiv2=Param.ActionInput.PairIndices.ListPairCiv2;%string which determines the civ2 pair
    135140                end
    136             else% we start from an existing Civ1 file
    137                 i1_series_Civ1=i1_series{1};
    138                 i2_series_Civ1=i2_series{1};
    139                 j1_series_Civ1=j1_series{1};
    140                 j2_series_Civ1=j2_series{1};
    141                 NomTypeNc=Param.InputTable{1,4};
    142                 if ~isempty(PairCiv2)
    143                     [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds,NomTypeNc]=...
    144                         find_pair_indices(PairCiv2,i1_series{2},j1_series{2},MinIndex_i(2),MaxIndex_i(2),MinIndex_j(2),MaxIndex_j(2));
     141                if iview_A==1% if Civ1 is performed
     142                    [i1_series_Civ1,i2_series_Civ1,j1_series_Civ1,j2_series_Civ1,check_bounds,NomTypeNc]=...
     143                        find_pair_indices(PairCiv1,i1_series{1},j1_series{1},MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j);
     144                    if ~isempty(PairCiv2)
     145                        [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds_Civ2]=...
     146                            find_pair_indices(PairCiv2,i1_series{1},j1_series{1},MinIndex_i(1),MaxIndex_i(1),MinIndex_j(1),MaxIndex_j(1));
     147                        check_bounds=check_bounds | check_bounds_Civ2;
     148                    end
     149                else% we start from an existing Civ1 file
     150                    i1_series_Civ1=i1_series{1};
     151                    i2_series_Civ1=i2_series{1};
     152                    j1_series_Civ1=j1_series{1};
     153                    j2_series_Civ1=j2_series{1};
     154                    NomTypeNc=Param.InputTable{1,4};
     155                    if ~isempty(PairCiv2)
     156                        [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds,NomTypeNc]=...
     157                            find_pair_indices(PairCiv2,i1_series{2},j1_series{2},MinIndex_i(2),MaxIndex_i(2),MinIndex_j(2),MaxIndex_j(2));
     158                    end
    145159                end
    146             end
    147 %             i1_series_Civ1=i1_series_Civ1(~check_bounds);
    148 %             i2_series_Civ1=i2_series_Civ1(~check_bounds);
    149 %             j1_series_Civ1=j1_series_Civ1(~check_bounds);
    150 %             j2_series_Civ1=j2_series_Civ1(~check_bounds);
    151         case 'displacement'
    152             i1_series_Civ1=Param.ActionInput.OriginIndex*ones(size(i1_series{1}));
    153             i2_series_Civ1=i1_series{1};i2_series_Civ2=i1_series{1};
    154             j1_series_Civ1=ones(size(i1_series{1}));% first j index is 1
    155             if isempty(j1_series_Civ1)
    156                 j2_series_Civ1=ones(size(i1_series{1}));
    157             else
    158                 j2_series_Civ1=j1_series_Civ1;
    159             end
    160             i1_series_Civ2=i1_series_Civ1;
    161             j1_series_Civ2=j1_series_Civ1;
    162             j2_series_Civ2=j2_series_Civ1;
    163             NomTypeNc=NomType;
    164         case 'shift'
    165             i1_series_Civ1=i1_series{1};i1_series_Civ2=i1_series{1};
    166             i2_series_Civ1=i1_series{2};i2_series_Civ2=i1_series{2};
    167             if isempty(j1_series{1})
    168                 j1_series_Civ1=ones(size(i1_series{1}));
    169                 j2_series_Civ1=ones(size(i1_series{2}));
    170             else
    171                 j1_series_Civ1=j1_series{1};
    172                 j2_series_Civ1=j1_series{2};
    173             end
    174             j1_series_Civ2=j1_series_Civ1;
    175             j2_series_Civ2=j2_series_Civ1;
    176             NomTypeNc=NomType_A;
    177     end
    178     if isempty(j1_series_Civ1)
    179         FrameIndex_A_Civ1=i1_series_Civ1;
    180         FrameIndex_B_Civ1=i2_series_Civ1;
    181         j1_series_Civ1=ones(size(i1_series_Civ1));
    182         j2_series_Civ1=ones(size(i1_series_Civ1));
    183     else
    184         FrameIndex_A_Civ1=j1_series_Civ1;
    185         FrameIndex_B_Civ1=j2_series_Civ1;
    186     end
    187     if isempty(PairCiv2)
     160                %             i1_series_Civ1=i1_series_Civ1(~check_bounds);
     161                %             i2_series_Civ1=i2_series_Civ1(~check_bounds);
     162                %             j1_series_Civ1=j1_series_Civ1(~check_bounds);
     163                %             j2_series_Civ1=j2_series_Civ1(~check_bounds);
     164            case 'displacement'
     165                i1_series_Civ1=Param.ActionInput.OriginIndex*ones(size(i1_series{1}));
     166                i2_series_Civ1=i1_series{1};i2_series_Civ2=i1_series{1};
     167                j1_series_Civ1=ones(size(i1_series{1}));% first j index is 1
     168                if isempty(j1_series_Civ1)
     169                    j2_series_Civ1=ones(size(i1_series{1}));
     170                else
     171                    j2_series_Civ1=j1_series_Civ1;
     172                end
     173                i1_series_Civ2=i1_series_Civ1;
     174                j1_series_Civ2=j1_series_Civ1;
     175                j2_series_Civ2=j2_series_Civ1;
     176                NomTypeNc=NomType;
     177            case 'PIV volume'
     178                % TODO, TODO
     179        end
     180        if isempty(j1_series_Civ1)
     181            FrameIndex_A_Civ1=i1_series_Civ1;
     182            FrameIndex_B_Civ1=i2_series_Civ1;
     183            j1_series_Civ1=ones(size(i1_series_Civ1));
     184            j2_series_Civ1=ones(size(i1_series_Civ1));
     185        else
     186            FrameIndex_A_Civ1=j1_series_Civ1;
     187            FrameIndex_B_Civ1=j2_series_Civ1;
     188        end
     189        if isempty(PairCiv2)
    188190            FrameIndex_A_Civ2=FrameIndex_A_Civ1;
    189191            FrameIndex_B_Civ2=FrameIndex_B_Civ1;
    190     else
    191         if isempty(j1_series_Civ2)
    192             FrameIndex_A_Civ2=i1_series_Civ2;
    193             FrameIndex_B_Civ2=i2_series_Civ2;
    194             j1_series_Civ2=ones(size(i1_series_Civ2));
    195             j2_series_Civ2=ones(size(i1_series_Civ2));
    196         else
    197             FrameIndex_A_Civ2=j1_series_Civ2;
    198             FrameIndex_B_Civ2=j2_series_Civ2;
    199         end
    200     end
    201     if isempty(i1_series_Civ1)||(~isempty(PairCiv2) && isempty(i1_series_Civ2))
    202         disp_uvmat('ERROR','no image pair fo civ in the input file index range',checkrun)
    203         return
    204     end
    205 end
    206 
    207 %% check the first image pair
    208 try
    209     if Param.ActionInput.CheckCiv1% Civ1 is performed
    210         ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1),[],j1_series_Civ1(1));
    211         if ~exist(ImageName_A,'file')
    212             disp_uvmat('ERROR',['first input image ' ImageName_A ' does not exist'],checkrun)
     192        else
     193            if isempty(j1_series_Civ2)
     194                FrameIndex_A_Civ2=i1_series_Civ2;
     195                FrameIndex_B_Civ2=i2_series_Civ2;
     196                j1_series_Civ2=ones(size(i1_series_Civ2));
     197                j2_series_Civ2=ones(size(i1_series_Civ2));
     198            else
     199                FrameIndex_A_Civ2=j1_series_Civ2;
     200                FrameIndex_B_Civ2=j2_series_Civ2;
     201            end
     202        end
     203        if isempty(i1_series_Civ1)||(~isempty(PairCiv2) && isempty(i1_series_Civ2))
     204            disp_uvmat('ERROR','no image pair fo civ in the input file index range',checkrun)
    213205            return
    214206        end
    215         [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A);
    216         FileType_A=FileInfo_A.FileType;
    217         if strcmp(FileInfo_A.FileType,'netcdf')
    218             FieldName_A=Param.InputFields.FieldName;
    219             [DataIn,tild,tild,errormsg]=nc2struct(ImageName_A,{FieldName_A});
    220             par_civ1.ImageA=DataIn.(FieldName_A);
    221         else
    222             [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileType_A,VideoObject_A,FrameIndex_A_Civ1(1));
    223         end
    224         ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(1),[],j2_series_Civ1(1));
    225         if ~exist(ImageName_B,'file')
    226             disp_uvmat('ERROR',['first input image ' ImageName_B ' does not exist'],checkrun)
     207    end
     208   
     209    %% check the first image pair
     210    try
     211        if Param.ActionInput.CheckCiv1% Civ1 is performed
     212            ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(1),[],j1_series_Civ1(1));
     213            if ~exist(ImageName_A,'file')
     214                disp_uvmat('ERROR',['first input image ' ImageName_A ' does not exist'],checkrun)
     215                return
     216            end
     217            [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A);
     218            FileType_A=FileInfo_A.FileType;
     219            if strcmp(FileInfo_A.FileType,'netcdf')
     220                FieldName_A=Param.InputFields.FieldName;
     221                [DataIn,tild,tild,errormsg]=nc2struct(ImageName_A,{FieldName_A});
     222                par_civ1.ImageA=DataIn.(FieldName_A);
     223            else
     224                [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileType_A,VideoObject_A,FrameIndex_A_Civ1(1));
     225            end
     226            ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(1),[],j2_series_Civ1(1));
     227            if ~exist(ImageName_B,'file')
     228                disp_uvmat('ERROR',['first input image ' ImageName_B ' does not exist'],checkrun)
     229                return
     230            end
     231            [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
     232            FileType_B=FileInfo_B.FileType;
     233            if strcmp(FileInfo_B.FileType,'netcdf')
     234                FieldName_B=Param.InputFields.FieldName;
     235                [DataIn,tild,tild,errormsg]=nc2struct(ImageName_B,{FieldName_B});
     236                par_civ1.ImageB=DataIn.(FieldName_B);
     237            else
     238                [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(1));
     239            end
     240            NbField=numel(i1_series_Civ1);
     241        elseif Param.ActionInput.CheckCiv2 % Civ2 is performed without Civ1
     242            ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ2(1),[],j1_series_Civ2(1));
     243            if ~exist(ImageName_A,'file')
     244                disp_uvmat('ERROR',['first input image ' ImageName_A ' does not exist'],checkrun)
     245                return
     246            end
     247            [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A);
     248            FileType_A=FileInfo_A.FileType;
     249            [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileInfo_A.FileType,VideoObject_A,FrameIndex_A_Civ2(1));
     250            ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ2(1),[],j2_series_Civ2(1));
     251            if ~exist(ImageName_B,'file')
     252                disp_uvmat('ERROR',['first input image ' ImageName_B ' does not exist'],checkrun)
     253                return
     254            end
     255            [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
     256            FileType_B=FileInfo_B.FileType;
     257            [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ2(1));
     258            NbField=numel(i1_series_Civ2);
     259        else
     260            NbField=numel(i1_series_Civ1);% no image used (only fix or patch) TO CHECK
     261        end
     262    catch ME
     263        if ~isempty(ME.message)
     264            disp_uvmat('ERROR', ['error reading input image: ' ME.message],checkrun)
    227265            return
    228266        end
    229         [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
    230         FileType_B=FileInfo_B.FileType;
    231         if strcmp(FileInfo_B.FileType,'netcdf')
    232             FieldName_B=Param.InputFields.FieldName;
    233             [DataIn,tild,tild,errormsg]=nc2struct(ImageName_B,{FieldName_B});
    234             par_civ1.ImageB=DataIn.(FieldName_B);
    235         else
    236             [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(1));
    237         end
    238         NbField=numel(i1_series_Civ1);
    239     elseif Param.ActionInput.CheckCiv2 % Civ2 is performed without Civ1
    240         ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ2(1),[],j1_series_Civ2(1));
    241         if ~exist(ImageName_A,'file')
    242             disp_uvmat('ERROR',['first input image ' ImageName_A ' does not exist'],checkrun)
    243             return
    244         end
    245         [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A);
    246         FileType_A=FileInfo_A.FileType;
    247         [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileInfo_A.FileType,VideoObject_A,FrameIndex_A_Civ2(1));
    248         ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ2(1),[],j2_series_Civ2(1));
    249         if ~exist(ImageName_B,'file')
    250             disp_uvmat('ERROR',['first input image ' ImageName_B ' does not exist'],checkrun)
    251             return
    252         end
    253         [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
    254         FileType_B=FileInfo_B.FileType;
    255         [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ2(1));
    256         NbField=numel(i1_series_Civ2);
    257     else
    258         NbField=numel(i1_series_Civ1);% no image used (only fix or patch) TO CHECK
    259     end
    260 catch ME
    261     if ~isempty(ME.message)
    262         disp_uvmat('ERROR', ['error reading input image: ' ME.message],checkrun)
    263         return
    264     end
    265 end
    266 
    267 
    268 %% Output directory
    269 OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    270 
     267    end
     268   
     269   
     270    %% Output directory
     271    OutputDir='';
     272    if CheckOutputFile
     273    OutputDir=[Param.OutputSubDir Param.OutputDirExt];
     274    end
     275end
     276
     277%% prepare output Data
    271278Data.ListGlobalAttribute={'Conventions','Program','CivStage'};
    272279Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes
     
    323330%%%%% MAIN LOOP %%%%%%
    324331for ifield=1:NbField
    325     update_waitbar(WaitbarHandle,ifield/NbField)
    326     if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
    327         disp('program stopped by user')
    328         break
    329     end
    330     if iview_A==0
    331         ncfile=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},Param.InputTable{1,5},...
    332             NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),j1_series_Civ1(ifield),j2_series_Civ1(ifield));
    333     else
    334         if iview_A==1% if Civ1 is performed
    335             Civ1Dir=OutputDir;
    336         else
    337             Civ1Dir=Param.InputTable{1,2};
    338         end
    339         if strcmp(Param.ActionInput.ListCompareMode,'PIV')
    340             ncfile=fullfile_uvmat(RootPath_A,Civ1Dir,RootFile_A,'.nc',NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),...
    341                 j1_series_Civ1(ifield),j2_series_Civ1(ifield));
    342         else
    343             ncfile=fullfile_uvmat(RootPath_A,Civ1Dir,RootFile_A,'.nc',NomTypeNc,i2_series_Civ1(ifield),[],...
    344                 j1_series_Civ1(ifield),j2_series_Civ1(ifield));
     332    if ~isempty(RUNHandle)% update the waitbar in interactive mode with GUI series  (checkrun=1)
     333        update_waitbar(WaitbarHandle,ifield/NbField)
     334        if  get(RUNHandle,'Value')&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
     335            disp('program stopped by user')
     336            break
     337        end
     338    end
     339    if CheckInputFile
     340        if iview_A==0 % no nc file has been entered
     341            ncfile=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},Param.InputTable{1,5},...
     342                NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),j1_series_Civ1(ifield),j2_series_Civ1(ifield));
     343        else% an existing nc file has been entered
     344            if iview_A==1% if Civ1 is performed
     345                Civ1Dir=OutputDir;
     346            else
     347                Civ1Dir=Param.InputTable{1,2};
     348            end
     349            if strcmp(Param.ActionInput.ListCompareMode,'PIV')
     350                ncfile=fullfile_uvmat(RootPath_A,Civ1Dir,RootFile_A,'.nc',NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),...
     351                    j1_series_Civ1(ifield),j2_series_Civ1(ifield));
     352            else
     353                ncfile=fullfile_uvmat(RootPath_A,Civ1Dir,RootFile_A,'.nc',NomTypeNc,i2_series_Civ1(ifield),[],...
     354                    j1_series_Civ1(ifield),j2_series_Civ1(ifield));
     355            end
    345356        end
    346357    end
     
    349360    if isfield (Param.ActionInput,'Civ1')
    350361        par_civ1=Param.ActionInput.Civ1;
    351         try
    352             ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield));
    353             if strcmp(FileInfo_A.FileType,'netcdf')
    354                 FieldName_A=Param.InputFields.FieldName;
    355                 [DataIn,tild,tild,errormsg]=nc2struct(ImageName_A,{FieldName_A});
    356                 par_civ1.ImageA=DataIn.(FieldName_A);
    357             else
    358                 [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileType_A,VideoObject_A,FrameIndex_A_Civ1(ifield));
    359             end
    360             ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(ifield),[],j2_series_Civ1(ifield));
    361             if strcmp(FileInfo_B.FileType,'netcdf')
    362                 FieldName_B=Param.InputFields.FieldName;
    363                 [DataIn,tild,tild,errormsg]=nc2struct(ImageName_B,{FieldName_B});
    364                 par_civ1.ImageB=DataIn.(FieldName_B);
    365             else
    366                 [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(ifield));
    367             end
    368         catch ME
    369             if ~isempty(ME.message)
    370                 disp_uvmat('ERROR', ['error reading input image: ' ME.message],checkrun)
    371                 return
    372             end
    373         end
    374         par_civ1.ImageWidth=size(par_civ1.ImageA,2);%FileInfo_A.Width;
    375         par_civ1.ImageHeight=size(par_civ1.ImageA,1);%FileInfo_A.Height;
    376         list_param=(fieldnames(Param.ActionInput.Civ1))';
    377         ind_remove=find(strcmp('TestCiv1',list_param));
    378         list_param(ind_remove)=[];
    379         Civ1_param=regexprep(list_param,'^.+','Civ1_$0');% insert 'Civ1_' before  each string in list_param
    380         Civ1_param=[{'Civ1_ImageA','Civ1_ImageB','Civ1_Time','Civ1_Dt'} Civ1_param]; %insert the names of the two input images
    381         %indicate the values of all the global attributes in the output data
    382         Data.Civ1_ImageA=ImageName_A;
    383         Data.Civ1_ImageB=ImageName_B;
    384         i1=i1_series_Civ1(ifield);
    385         i2=i1;
    386         if ~isempty(i2_series_Civ1)
    387             i2=i2_series_Civ1(ifield);
    388         end
    389         j1=1;
    390         if ~isempty(j1_series_Civ1)
    391             j1=j1_series_Civ1(ifield);
    392         end
    393         j2=j1;
    394         if ~isempty(j2_series_Civ1)
    395             j2=j2_series_Civ1(ifield);
    396         end
    397         Data.Civ1_Time=(time(i2+1,j2+1)+time(i1+1,j1+1))/2;
    398         Data.Civ1_Dt=time(i2+1,j2+1)-time(i1+1,j1+1);
    399         for ilist=1:length(list_param)
    400             Data.(Civ1_param{4+ilist})=Param.ActionInput.Civ1.(list_param{ilist});
    401         end
    402         Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ1_param];
    403         Data.CivStage=1;
    404        
     362        if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1)
     363            try
     364                ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield));
     365                if strcmp(FileInfo_A.FileType,'netcdf')% case of input images in format netcdf
     366                    FieldName_A=Param.InputFields.FieldName;
     367                    [DataIn,tild,tild,errormsg]=nc2struct(ImageName_A,{FieldName_A});
     368                    par_civ1.ImageA=DataIn.(FieldName_A);
     369                else % usual image formats for image A
     370                    [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileType_A,VideoObject_A,FrameIndex_A_Civ1(ifield));
     371                end
     372                ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(ifield),[],j2_series_Civ1(ifield));
     373                if strcmp(FileInfo_B.FileType,'netcdf') % case of input images in format netcdf
     374                    FieldName_B=Param.InputFields.FieldName;
     375                    [DataIn,tild,tild,errormsg]=nc2struct(ImageName_B,{FieldName_B});
     376                    par_civ1.ImageB=DataIn.(FieldName_B);
     377                else % usual image formats for image B
     378                    [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(ifield));
     379                end
     380            catch ME % display errors in reading input images
     381                if ~isempty(ME.message)
     382                    disp_uvmat('ERROR', ['error reading input image: ' ME.message],checkrun)
     383                    return
     384                end
     385            end
     386            par_civ1.ImageWidth=size(par_civ1.ImageA,2);%FileInfo_A.Width;
     387            par_civ1.ImageHeight=size(par_civ1.ImageA,1);%FileInfo_A.Height;
     388            list_param=(fieldnames(Param.ActionInput.Civ1))';
     389            list_param(strcmp('TestCiv1',list_param))=[];% remove the parameter TestCiv1 from the list
     390            Civ1_param=regexprep(list_param,'^.+','Civ1_$0');% insert 'Civ1_' before  each string in list_param
     391            Civ1_param=[{'Civ1_ImageA','Civ1_ImageB','Civ1_Time','Civ1_Dt'} Civ1_param]; %insert the names of the two input images
     392            %indicate the values of all the global attributes in the output data
     393            Data.Civ1_ImageA=ImageName_A;
     394            Data.Civ1_ImageB=ImageName_B;
     395            i1=i1_series_Civ1(ifield);
     396            i2=i1;
     397            if ~isempty(i2_series_Civ1)
     398                i2=i2_series_Civ1(ifield);
     399            end
     400            j1=1;
     401            if ~isempty(j1_series_Civ1)
     402                j1=j1_series_Civ1(ifield);
     403            end
     404            j2=j1;
     405            if ~isempty(j2_series_Civ1)
     406                j2=j2_series_Civ1(ifield);
     407            end
     408            Data.Civ1_Time=(time(i2+1,j2+1)+time(i1+1,j1+1))/2;
     409            Data.Civ1_Dt=time(i2+1,j2+1)-time(i1+1,j1+1);
     410            for ilist=1:length(list_param)
     411                Data.(Civ1_param{4+ilist})=Param.ActionInput.Civ1.(list_param{ilist});
     412            end
     413            Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ1_param];
     414            Data.CivStage=1;
     415        end
    405416        % set the list of variables
    406417        Data.ListVarName={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_F','Civ1_C'};%  cell array containing the names of the fields to record
     
    448459        if exist('ncfile','var')
    449460            CivFile=ncfile;
    450         elseif isfield(Param.Patch1,'CivFile')
    451             CivFile=Param.Patch1.CivFile;
    452         end
    453         [Data,tild,tild,errormsg]=nc2struct(CivFile,'ListGlobalAttribute','absolut_time_T0'); %look for the constant 'absolut_time_T0' to detect old civx data format
    454         if ~isempty(errormsg)
    455             disp_uvmat('ERROR',errormsg,checkrun)
    456             return
    457         end
    458         if ~isempty(Data.absolut_time_T0')%read civx file
    459             check_civx=1;% test for old civx data format
    460             [Data,vardetect,ichoice]=nc2struct(CivFile);%read the variables in the netcdf file
    461         else
    462             [Data,tild,tild,errormsg]=nc2struct(CivFile);%read civ1 and fix1 data in the existing netcdf file
     461            %         elseif isfield(Param.Patch1,'CivFile')
     462            %             CivFile=Param.Patch1.CivFile;
     463            %         end
     464            [Data,tild,tild,errormsg]=nc2struct(CivFile,'ListGlobalAttribute','absolut_time_T0'); %look for the constant 'absolut_time_T0' to detect old civx data format
     465            if ~isempty(errormsg)
     466                disp_uvmat('ERROR',errormsg,checkrun)
     467                return
     468            end
     469            if ~isempty(Data.absolut_time_T0')%read civx file
     470                check_civx=1;% test for old civx data format
     471                [Data,vardetect,ichoice]=nc2struct(CivFile);%read the variables in the netcdf file
     472            else
     473                [Data,tild,tild,errormsg]=nc2struct(CivFile);%read civ1 and fix1 data in the existing netcdf file
     474            end
     475        else
     476            Data.ListGlobalAttribute={};
     477            Data.ListVarName={};
     478            Data.VarDimName={};
     479            Data.Civ1_X=Param.Civ1_X;
     480            Data.Civ1_Y=Param.Civ1_Y;
     481            Data.Civ1_U=Param.Civ1_U;
     482            Data.Civ1_V=Param.Civ1_V;
     483            Data.Civ1_FF=Param.Civ1_FF;         
    463484        end
    464485    end
     
    511532            return
    512533        end
     534       
     535        % record the processing parameters of Patch1 as global attributes in the result nc file
    513536        list_param=fieldnames(Param.ActionInput.Patch1)';
    514                    ind_remove=find(strcmp('TestPatch1',list_param));
    515         list_param(ind_remove)=[];
    516         Patch1_param=regexprep(list_param,'^.+','Patch1_$0');% insert 'Fix1_' before  each string in ListFixParam
    517         %indicate the values of all the global attributes in the output data
     537        list_param(strcmp('TestPatch1',list_param))=[];% remove 'TestPatch1' from the list of parameters
     538        Patch1_param=regexprep(list_param,'^.+','Patch1_$0');% insert 'Patch1_' before  each parameter name
    518539        for ilist=1:length(list_param)
    519540            Data.(Patch1_param{ilist})=Param.ActionInput.Patch1.(list_param{ilist});
    520541        end
     542        Data.CivStage=3;% record the new state of processing
    521543        Data.ListGlobalAttribute=[Data.ListGlobalAttribute Patch1_param];
    522544       
    523 %         Data.ListGlobalAttribute=[Data.ListGlobalAttribute {'Patch1_FieldSmooth','Patch1_MaxDiff','Patch1_SubDomainSize'}];
    524 %         Data.Patch1_FieldSmooth=Param.ActionInput.Patch1.FieldSmooth;
    525 %         Data.Patch1_MaxDiff=Param.ActionInput.Patch1.MaxDiff;
    526 %         Data.Patch1_SubDomainSize=Param.ActionInput.Patch1.SubDomainSize;
     545        % list the variables to record
    527546        nbvar=length(Data.ListVarName);
    528547        Data.ListVarName=[Data.ListVarName {'Civ1_U_smooth','Civ1_V_smooth','Civ1_SubRange','Civ1_NbCentres','Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps'}];
     
    534553        Data.VarAttribute{nbvar+6}.Role='vector_x';
    535554        Data.VarAttribute{nbvar+7}.Role='vector_y';
    536         Data.Civ1_U_smooth=zeros(size(Data.Civ1_X));
    537         Data.Civ1_V_smooth=zeros(size(Data.Civ1_X));
     555        Data.Civ1_U_smooth=Data.Civ1_U; % zeros(size(Data.Civ1_X));
     556        Data.Civ1_V_smooth=Data.Civ1_V; %zeros(size(Data.Civ1_X));
    538557        if isfield(Data,'Civ1_FF')
    539558            ind_good=find(Data.Civ1_FF==0);
     
    541560            ind_good=1:numel(Data.Civ1_X);
    542561        end
     562       
     563       % perform Patch calculation using the UVMAT fct 'filter_tps'
    543564        [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,tild,Ures, Vres,tild,FFres]=...
    544565            filter_tps([Data.Civ1_X(ind_good) Data.Civ1_Y(ind_good)],Data.Civ1_U(ind_good),Data.Civ1_V(ind_good),[],Data.Patch1_SubDomainSize,Data.Patch1_FieldSmooth,Data.Patch1_MaxDiff);
    545         Data.Civ1_U_smooth(ind_good)=Ures;
     566        Data.Civ1_U_smooth(ind_good)=Ures;% take the interpolated (smoothed) velocity values for good vectors, keep 0 for the others
    546567        Data.Civ1_V_smooth(ind_good)=Vres;
    547568        Data.Civ1_FF(ind_good)=FFres;
    548         Data.CivStage=3;
    549569    end
    550570   
     
    554574        par_civ2.ImageA=[];
    555575        par_civ2.ImageB=[];
    556         %         if ~isfield(Param.Civ1,'ImageA')
    557          i1=i1_series_Civ2(ifield);
     576        i1=i1_series_Civ2(ifield);
    558577        i2=i1;
    559578        if ~isempty(i2_series_Civ2)
     
    610629        end
    611630       
    612          % get the guess from patch1 or patch2 (case 'iterate')
    613         if isfield (par_civ2,'iterate') && strcmp(par_civ2.iterate,'civ3')
     631         % get the guess from patch1 or patch2 (case 'CheckCiv3')
     632        if isfield (par_civ2,'CheckCiv3') && par_civ2.CheckCiv3 %get the guess from  patch2
    614633           SubRange= Data.Civ2_SubRange;
    615634           NbCentres=Data.Civ2_NbCentres;
     
    626645           Data.ListVarName={};
    627646           Data.VarDimName={};
    628         else
     647        else % get the guess from patch1
    629648           SubRange= Data.Civ1_SubRange;
    630649           NbCentres=Data.Civ1_NbCentres;
     
    781800   
    782801    %% write result in a netcdf file if requested
    783     if exist('ncfile','var')
     802    if CheckOutputFile
    784803        errormsg=struct2nc(ncfile,Data);
    785804        if isempty(errormsg)
     
    824843% mask: =[] for no mask
    825844% roi: 4 element vector defining a region of interest: x position, y position, width, height, (in image indices), for the whole image, roi=[];
    826 function [xtable ytable utable vtable ctable F result_conv errormsg] = civ (par_civ)
    827 %this funtion performs the DCC PIV analysis. Recent window-deformation
    828 %methods perform better and will maybe be implemented in the future.
     845function [xtable,ytable,utable,vtable,ctable,F,result_conv,errormsg] = civ (par_civ)
    829846
    830847%% prepare measurement grid
     
    866883result_conv=[];
    867884errormsg='';
    868 
     885   
    869886%% prepare mask
    870887if isfield(par_civ,'Mask') && ~isempty(par_civ.Mask)
Note: See TracChangeset for help on using the changeset viewer.