source: trunk/src/series/civ_input.m @ 1016

Last change on this file since 1016 was 1016, checked in by sommeria, 7 years ago

bugs repaired for multilevel series

File size: 100.2 KB
RevLine 
[647]1%'civ_input': function associated with the GUI 'civ_input.fig' to set the input parameters for civ_series
[597]2%------------------------------------------------------------------------
[647]3% function ParamOut = civ_input(Param)
[597]4%
[647]5% OUPUT:
6% ParamOut: Matlab structure containing the parameters set by the GUI civ_input
7%
8% INPUT:
9% Param: Matlab structure containing the input parameters set by the GUI
[810]10
11%=======================================================================
[977]12% Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[810]13%   http://www.legi.grenoble-inp.fr
14%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
[647]15%
[597]16%     This file is part of the toolbox UVMAT.
17%
18%     UVMAT is free software; you can redistribute it and/or modify
[810]19%     it under the terms of the GNU General Public License as published
20%     by the Free Software Foundation; either version 2 of the license,
21%     or (at your option) any later version.
[597]22%
23%     UVMAT is distributed in the hope that it will be useful,
24%     but WITHOUT ANY WARRANTY; without even the implied warranty of
25%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
[810]26%     GNU General Public License (see LICENSE.txt) for more details.
27%=======================================================================
28
[597]29function varargout = civ_input(varargin)
30
31gui_Singleton = 1;
32gui_State = struct('gui_Name',       mfilename, ...
33    'gui_Singleton',  gui_Singleton, ...
34    'gui_OpeningFcn', @civ_input_OpeningFcn, ...
35    'gui_OutputFcn',  @civ_input_OutputFcn, ...
36    'gui_LayoutFcn',  [] , ...
37    'gui_Callback',   []);
38
[598]39if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback$','once'))
[597]40        gui_State.gui_Callback = str2func(varargin{1});
41end
42
43if nargout
44    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
45else
46    gui_mainfcn(gui_State, varargin{:});
47end
48
49% End initialization code - DO NOT EDIT
50
51%------------------------------------------------------------------------
52% --- Executes just before civ_input is made visible.
53function civ_input_OpeningFcn(hObject, eventdata, handles, Param)
54%------------------------------------------------------------------------
55% This function has no output args, see OutputFcn.
56
57%% General settings
58handles.output = Param;
59guidata(hObject, handles); % Update handles structure
60set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
[774]61set(hObject,'WindowKeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
[851]62%set(hObject,'KeyPressFcn',{@KeyPressFcn,handles})%set keyboard action function
[774]63set(handles.ref_i,'KeyPressFcn',{@ref_i_KeyPressFcn,handles})%set keyboard action function
[851]64set(handles.ref_j,'KeyPressFcn',{@ref_i_KeyPressFcn,handles})%set keyboard action function
[774]65%set(hObject,'WindowKeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
66hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
67hhseries=guidata(hseries); %handles of the elements in 'series'
68SeriesData=get(hseries,'UserData');% info stored in the GUI series
[597]69
[833]70%% set visibility options depending on the calling function (Param.Action.ActionName):
71if strcmp(Param.Action.ActionName,'civ_series')||strcmp(Param.Action.ActionName,'stereo_civ')
72     set(handles.num_MaxDiff,'Visible','on')
[774]73    set(handles.num_MaxVel,'Visible','on')
74    set(handles.title_MaxVel,'Visible','on')
75    set(handles.title_MaxDiff,'Visible','on')
76    set(handles.num_Nx,'Visible','off')
77    set(handles.num_Ny,'Visible','off')
78    set(handles.title_Nx,'Visible','off')
79    set(handles.title_Ny,'Visible','off')
80    set(handles.num_CorrSmooth,'Style','popupmenu')
81    set(handles.num_CorrSmooth,'Value',1)
82    set(handles.num_CorrSmooth,'String',{'1';'2'})
83    set(handles.CheckThreshold,'Visible','on')
84    set(handles.CheckDeformation,'Value',0)% desactivate (work in progress)
[599]85end
[833]86switch Param.Action.ActionName
87    case 'stereo_civ'
88        set(handles.ListCompareMode,'Visible','off')
89        set(handles.PairIndices,'Visible','off')
90    case 'civ_series'
91        set(handles.ListCompareMode,'Visible','on')
92        set(handles.PairIndices,'Visible','on')
93end
[599]94
95%% input file info
96NomTypeInput=Param.InputTable{1,4};
[716]97FileType='image';%fdefault
98FileInfo=[];
[951]99if isfield(SeriesData,'FileType')&&isfield(SeriesData,'FileInfo')...
100        &&numel(SeriesData.FileType)>=1&&numel(SeriesData.FileInfo)>=1
[711]101    FileType=SeriesData.FileType{1};%type of the first input file series
[774]102    FileInfo=SeriesData.FileInfo{1};% info on the first input file series
[711]103else
[774]104    set(hhseries.REFRESH,'BackgroundColor',[1 0 1])% indicate that the file input in series needs to be refreshed
[711]105end
[599]106
[774]107%% case of netcdf file as input, read the processing stage and look for corresponding images
[599]108ind_opening=0;%default
109NomTypeNc='';
[851]110NomTypeImaA=NomTypeInput;
111iview_image=1;%line # for the input images
[599]112switch FileType
[1007]113    case {'image','image_DaVis','multimage','video','mmreader','cine_phantom','netcdf'}
[851]114%         NomTypeImaA=NomTypeInput;
115%         iview_image=1;%line # for the input images
[599]116    case 'civdata'
[603]117        if ~strcmp(Param.Action.ActionName,'civ_series')
118            msgbox_uvmat('ERROR','bad input data file: open an image or a nc file from civ_series')
[851]119            return
[603]120        end
[599]121        NomTypeNc=NomTypeInput;
122        ind_opening=FileInfo.CivStage;
123        if isempty(regexp(NomTypeInput,'[ab|AB|-]', 'once'))
124            set(handles.ListCompareMode,'Value',2) %mode displacement advised if the nomencalture does not involve index pairs
125        else
126            set(handles.ListCompareMode,'Value',1)
127        end
[774]128        [Data,tild,tild,errormsg]=nc2struct(FileInfo.FileName,[]);
129        if ~isempty(errormsg)
130            msgbox_uvmat('ERROR',['error in netcdf input file: ' errormsg])
131            return
132        end
[910]133        if isfield(Data,'.Civ1_ImageA')
[851]134        [PathCiv1_ImageA,Civ1_ImageA,FileExtA]=fileparts(Data.Civ1_ImageA);%look for the source image A
135        [PathCiv1_ImageB,Civ1_ImageB,FileExtA]=fileparts(Data.Civ1_ImageB);%look for the source image B
[910]136        end
[774]137        if isfield(Data,'Civ2_ImageA')
[642]138            [PathCiv2_ImageA,Civ2_ImageA,FileExtA]=fileparts(Data.Civ2_ImageA);
139            [PathCiv2_ImageB,Civ2_ImageB,FileExtA]=fileparts(Data.Civ2_ImageB);
[637]140        end
141        if size(Param.InputTable,1)==1
[910]142             if isfield(Data,'.Civ1_ImageA')
[661]143            series('display_file_name',hhseries,Data.Civ1_ImageA,'append');%append the image series to the input list
[910]144                    [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaA]=fileparts_uvmat(Data.Civ1_ImageA);
145        [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaB]=fileparts_uvmat(Data.Civ1_ImageB);
146             else
147                 series('display_file_name',hhseries,Data.Civ2_ImageA,'append');%append the image series to the input list
148                         [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaA]=fileparts_uvmat(Data.Civ2_ImageA);
149        [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaB]=fileparts_uvmat(Data.Civ2_ImageB);
150             end
[637]151        end
[910]152
[642]153        iview_image=2;%line # for the input images
[599]154    case 'civxdata'% case of  civx data,
155        msgbox_uvmat('ERROR','old civX convention, use the GUI civ')
156        return
[761]157    otherwise
[781]158        msgbox_uvmat('ERROR','civ_series needs images, scalar fields in netcdf format, or civ data as input')
[761]159        return
[599]160end
161
162%% reinitialise menus
163set(handles.ListPairMode,'Value',1)
164set(handles.ListPairMode,'String',{''})
165set(handles.ListPairCiv1,'Value',1)
166set(handles.ListPairCiv1,'String',{''})
167set(handles.ListPairCiv2,'Value',1)
168set(handles.ListPairCiv2,'String',{''})
[598]169       
170%% prepare the GUI with input parameters
[833]171%
[599]172set(handles.ref_i,'String',num2str(Param.IndexRange.first_i))
173if isfield(Param.IndexRange,'first_j')
[603]174    set(handles.ref_j,'String',num2str(Param.IndexRange.first_j))
[597]175end
[856]176set(handles.ConfigSource,'String','\default')
[599]177
[774]178%%  set the menus of image pairs and default selection for civ_input   %%%%%%%%%%%%%%%%%%%
179
180%% display the min and max indices for the whole file series
[855]181if isempty(Param.IndexRange.MaxIndex_i)|| isempty(Param.IndexRange.MinIndex_i)
182    msgbox_uvmat('ERROR','REFRESH the input files in the GUI series')
183     return
184end
[776]185MaxIndex_i=Param.IndexRange.MaxIndex_i(iview_image);
186MinIndex_i=Param.IndexRange.MinIndex_i(iview_image);
187MaxIndex_j=1;%default
188MinIndex_j=1;
189if isfield(Param.IndexRange,'MaxIndex_j')&&isfield(Param.IndexRange,'MinIndex_j')...
190        && numel(Param.IndexRange.MaxIndex_j')>=iview_image &&numel(Param.IndexRange.MinIndex_j')>=iview_image
191    MaxIndex_j=Param.IndexRange.MaxIndex_j(iview_image);
192    MinIndex_j=Param.IndexRange.MinIndex_j(iview_image);
[597]193end
[776]194%update the bounds if possible
195if isfield(SeriesData,'i1_series')&&numel(SeriesData.i1_series)>=iview_image
196    if size(SeriesData.i1_series{iview_image},2)==2 && min(min(SeriesData.i1_series{iview_image}(:,1,:)))==0
197        MinIndex_j=1;% index j set to 1 by default
198        MaxIndex_j=1;
199        MinIndex_i=find(SeriesData.i1_series{iview_image}(1,2,:), 1 )-1;% min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index)
200        MaxIndex_i=find(SeriesData.i1_series{iview_image}(1,2,:),1,'last' )-1;%max ref index i detected in the series (corresponding to the last non-zero value of i1_series)
201    else
202        ref_i=squeeze(max(SeriesData.i1_series{iview_image}(1,:,:),[],2));% select ref_j index for each ref_i
203        ref_j=squeeze(max(SeriesData.j1_series{iview_image}(1,:,:),[],3));% select ref_i index for each ref_j
204        MinIndex_i=min(find(ref_i))-1;
205        MaxIndex_i=max(find(ref_i))-1;
206        MaxIndex_j=max(find(ref_j))-1;
207        MinIndex_j=min(find(ref_j))-1;
208    end
209end
[599]210
[918]211
[599]212%%  transfer the time from the GUI series, or use file index by default
213time=[];
214TimeUnit='frame'; %default
215CoordUnit='';%default
216pxcm_search=1;
[951]217if isfield(SeriesData,'Time') &&numel(SeriesData.Time')>=1 && ~isempty(SeriesData.Time{1})
[599]218    time=SeriesData.Time{1};
219end
[609]220if isfield(Param.IndexRange,'TimeUnit')&&~isempty(Param.IndexRange.TimeUnit)
221    TimeUnit=Param.IndexRange.TimeUnit;
[599]222end
[851]223% if isfield(SeriesData,'TimeSource')
224%     set(handles.TimeSource,'String',SeriesData.TimeSource)
225% end 
[599]226if isfield(SeriesData,'GeometryCalib')
227    tsai=SeriesData.GeometryCalib;
228    if isfield(tsai,'fx_fy')
229        pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
230    end
231    if isfield(tsai,'CoordUnit')
232        CoordUnit=tsai.CoordUnit;
233    end
234end
235
236%% timing display
237%show the reference image edit box if relevant (not needed for movies or in the absence of time information
238if numel(time)>=2 % if there are at least two time values to define dt
239    if size(time,1)<MaxIndex_i;
240        msgbox_uvmat('WARNING','maximum i index restricted by the timing of the xml file');
241    elseif size(time,2)<MaxIndex_j
242        msgbox_uvmat('WARNING','maximum j index restricted by the timing of the xml file');
243    end
244    MaxIndex_i=min(size(time,1),MaxIndex_i);%possibly adjust the max index according to time data
245    MaxIndex_j=min(size(time,2),MaxIndex_j);
[851]246    set(handles.TimeSource,'String',Param.IndexRange.TimeSource);
[599]247else
[851]248    set(handles.TimeSource,'String',''); %xml file not used for timing
[599]249    TimeUnit='frame';
250    time=ones(MaxIndex_j-MinIndex_j+1,1)*(MinIndex_i:MaxIndex_i);
251    time=time+0.001*(MinIndex_j:MaxIndex_j)'*ones(1,MaxIndex_i-MinIndex_i+1);
252end
253CivInputData.Time=time;
[637]254CivInputData.NomTypeIma=NomTypeImaA;
[599]255set(handles.civ_input,'UserData',CivInputData)
256set(handles.dt_unit,'String',['dt in m' TimeUnit]);%display dt in unit 10-3 of the time (e.g ms)
257set(handles.TimeUnit,'String',TimeUnit);
[854]258%set(handles.CoordUnit,'String',CoordUnit)
[599]259set(handles.SearchRange,'UserData', pxcm_search);
260
[668]261
[774]262%% set the civ_input options, depending on the input file content if a nc file has been opened
263ListOptions={'CheckCiv1', 'CheckFix1' 'CheckPatch1', 'CheckCiv2', 'CheckFix2', 'CheckPatch2'};
264checkbox=zeros(size(ListOptions));%default
[851]265checkrefresh=0;
[774]266if ind_opening==0  %case of image opening, start with Civ1
267    for index=1:numel(ListOptions)
268        checkbox(index)=get(handles.(ListOptions{index}),'Value');
269    end
270    index_max=find(checkbox, 1, 'last' );
271    if isempty(index_max),index_max=1;end
272    for index=1:index_max
273        set(handles.(ListOptions{index}),'Value',1)% select all operations starting from CIV1
274    end
[851]275else  %case of netcdf file opening, start with the stage read in the file if the input file is being refreshed
[855]276    if isequal(get(hhseries.REFRESH,'BackgroundColor'),[1 1 0]) &&...
277            ~(isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ConfigSource'))
[851]278            for index = 1:min(ind_opening,5)
279                set(handles.(ListOptions{index}),'value',0)
280                fill_civ_input(Data,handles); %fill civ_input with the parameters retrieved from an input Civ file
281            end
282            set(handles.ConfigSource,'String',FileInfo.FileName);
283            set(handles.(ListOptions{min(ind_opening+1,6)}),'value',1)
284            for index = ind_opening+2:6
285                set(handles.(ListOptions{index}),'value',0)
286            end
287            checkrefresh=1;
[774]288    end
[851]289    if ind_opening>=3
[855]290        set(handles.CheckCiv3,'Visible','on')% make visible the switch 'iterate/repet' for Civ2.
[851]291    else
[855]292        set(handles.CheckCiv3,'Visible','off')
[774]293    end
294end
295
[851]296%% introduce the stored Civ parameters  if available (from previous input or ImportConfig in series)
297if ~checkrefresh && isfield(Param,'ActionInput')&& strcmp(Param.ActionInput.Program,Param.Action.ActionName)% the program fits with the stored data
298    fill_GUI(Param.ActionInput,hObject);%fill the GUI with the parameters retrieved from the input Param
299    hcheckgrid=findobj(handles.civ_input,'Tag','CheckGrid');
300    for ilist=1:numel(hcheckgrid)
301        if get(hcheckgrid(ilist),'Value')% if a grid is used, do not show Dx and Dy for an automatic grid
302            hparent=get(hcheckgrid(ilist),'parent');%handles of the parent panel
303            hchildren=get(hparent,'children');
304            handle_dx=findobj(hchildren,'tag','num_Dx');
305            handle_dy=findobj(hchildren,'tag','num_Dy');
306            handle_title_dx=findobj(hchildren,'tag','title_Dx');
307            handle_title_dy=findobj(hchildren,'tag','title_Dy');
308            set(handle_dx,'Visible','off');
309            set(handle_dy,'Visible','off');
310            set(handle_title_dy,'Visible','off');
311            set(handle_title_dx,'Visible','off');
312        end
313    end
[885]314    if isfield(Param.ActionInput,'Civ2')
315       CheckDeformation_Callback(hObject, eventdata, handles)
316    end
[851]317end
318
[918]319%% set the menu and default choice of civ pairs
320if ~isfield(Param.IndexRange,'first_j')||isequal(MaxIndex_j,MinIndex_j)% no possibility of j pairs
321    set(handles.ListPairMode,'Value',1)
[1016]322    PairMenu={'series(Di)'};
[918]323elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
[1016]324    PairMenu={'pair j1-j2';'series(Dj)'};
[918]325    if  MaxIndex_j <= 10
326        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
327    end
328else
[1016]329    PairMenu={'pair j1-j2';'series(Dj)';'series(Di)'};%multiple choice
[918]330    if strcmp(NomTypeNc,'_1-2_1')
331        set(handles.ListPairMode,'Value',3)% advise 'series(Di)'
332    elseif  MaxIndex_j <= 10
333        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
334    end
335end
[1016]336set(handles.ListPairMode,'String',PairMenu)
[918]337
[1016]338%% set default choice of pair mode
339PairIndex=[];
340if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'PairIndices')
341    PairIndex=find(strcmp(Param.ActionInput.PairIndices.ListPairMode,PairMenu));
342end
343if isempty(PairIndex)
344    if ~isfield(Param.IndexRange,'first_j')||isequal(MaxIndex_j,MinIndex_j)% no possibility of j pairs
345        PairIndex=1;
346    elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
347        if  MaxIndex_j <= 10
348            PairIndex=1;% advice 'pair j1-j2' except in MaxIndex_j is large
349        end
350    else
351        if strcmp(NomTypeNc,'_1-2_1')
352            PairIndex=3;% advise 'series(Di)'
353        elseif  MaxIndex_j <= 10
354            PairIndex=1;% advice 'pair j1-j2' except in MaxIndex_j is large
355        end
356    end
357end
358set(handles.ListPairMode,'Value',PairIndex); 
359
[918]360%% indicate the min and max indices i and j on the GUI
361set(handles.MinIndex_i,'String',num2str(MinIndex_i))
362set(handles.MaxIndex_i,'String',num2str(MaxIndex_i))
363set(handles.MinIndex_j,'String',num2str(MinIndex_j))
364set(handles.MaxIndex_j,'String',num2str(MaxIndex_j))
365
[774]366%% set the reference indices from the input file indices
[852]367if ~(isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ConfigSource'))
[774]368update_CivOptions(handles,ind_opening)% fill the menu of possible pairs
[851]369end
[774]370
371%% list the possible index pairs, depending on the option set in ListPairMode
372ListPairMode_Callback([], [], handles)
[881]373%ListPairCiv1_Callback(hObject, eventdata, handles)
[774]374
[599]375%% set the GUI to modal: wait for OK to close
[598]376set(handles.civ_input,'WindowStyle','modal')% Make the GUI modal
[597]377drawnow
[856]378uiwait(handles.civ_input);% wait for OK action to end the function
[597]379
[599]380
[597]381%------------------------------------------------------------------------
382% --- Outputs from this function are returned to the command line.
383function varargout = civ_input_OutputFcn(hObject, eventdata, handles)
384%------------------------------------------------------------------------
385% Get default command line output from handles structure
[668]386varargout{1}=[];% default output when civ_input is canceled (no 'OK')
387if ~isempty(handles)
388    varargout{1} = handles.output;
389    delete(handles.civ_input)
390end
[597]391
392% --- Executes when user attempts to close get_field.
[598]393function civ_input_CloseRequestFcn(hObject, eventdata, handles)
[597]394if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
395    % The GUI is still in UIWAIT, us UIRESUME
[598]396    uiresume(handles.civ_input);
[597]397else
398    % The GUI is no longer waiting, just close it
[598]399    delete(handles.civ_input);
[597]400end
401
[851]402%------------------------------------------------------------------------
403% --- Executes on button press in SetDefaultParam.
404%------------------------------------------------------------------------
405function SetDefaultParam_Callback(hObject, eventdata, handles)
406
[856]407Param.ConfigSource='\default';
408
409%% Civ1 parameters
[874]410%Param.CheckCiv1=1;
[856]411Param.Civ1.CorrBoxSize=[25 25];
412Param.Civ1.SearchBoxSize=[55 55];
413Param.Civ1.SearchBoxShift=[0 0];
414Param.Civ1.CorrSmooth=1;
415Param.Civ1.Dx=20;
416Param.Civ1.Dy=20;
417Param.Civ1.CheckGrid=0;
418Param.Civ1.CheckMask=0;
[873]419Param.Civ1.Mask='';
[856]420Param.Civ1.CheckThreshold=0;
421Param.Civ1.TestCiv1=0;
422
423%% Fix1 parameters
[874]424%Param.CheckFix1=1;
[856]425Param.Fix1.CheckFmin2=1;
426Param.Fix1.CheckF3=1;
427Param.Fix1.MinCorr=0.2000;
428
429%% Patch1 parameters
[874]430%Param.CheckPatch1=1;
[856]431Param.Patch1.FieldSmooth=10;
432Param.Patch1.MaxDiff=1.5000;
433Param.Patch1.SubDomainSize=1000;
434Param.Patch1.TestPatch1=0;
435
436%% Civ2 parameters
[874]437%Param.CheckCiv2=1;
[856]438Param.Civ2.CorrBoxSize=[21 21];
[862]439Param.Civ2.SearchBoxSize=[27 27];
[856]440Param.Civ2.CorrSmooth=1;
441Param.Civ2.Dx=10;
442Param.Civ2.Dy=10;
443Param.Civ2.CheckGrid=0;
444Param.Civ2.CheckMask=0;
[873]445Param.Civ2.Mask='';
[856]446Param.Civ2.CheckThreshold=0;
447Param.Civ2.TestCiv2=0;
448
449%% Fix2 parameters
[874]450%Param.CheckFix2=1;
[856]451Param.Fix2.CheckFmin2=1;
452Param.Fix2.CheckF4=1;
453Param.Fix2.CheckF3=1;
454Param.Fix2.MinCorr=0.2000;
455
456%% Patch2 parameters
[874]457%Param.CheckPatch2=1;
[856]458Param.Patch2.FieldSmooth=2;
459Param.Patch2.MaxDiff=1.5000;
460Param.Patch2.SubDomainSize=1000;
461Param.Patch2.TestPatch2=0;
462
463fill_GUI(Param,handles.civ_input)% fill the elements of the GUI series with the input parameters
[873]464update_CivOptions(handles,0)
[856]465
[597]466% -----------------------------------------------------------------------
467% -----------------------------------------------------------------------
468% --- Open the help html file
469function MenuHelp_Callback(hObject, eventdata, handles)
470% -----------------------------------------------------------------------
[774]471web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#Civ')
[597]472
473%------------------------------------------------------------------------
474% --- Executes on carriage return on the subdir checkciv1 edit window
[604]475function Civ1_ImageB_Callback(hObject, eventdata, handles)
[597]476%------------------------------------------------------------------------
[604]477SubDir=get(handles.Civ1_ImageB,'String');
[597]478menu_str=get(handles.ListSubdirCiv1,'String');% read the list of subdirectories for update
479ichoice=find(strcmp(SubDir,menu_str),1);
480if isempty(ichoice)
481    ilist=numel(menu_str); %select 'new...' in the menu
482else
483    ilist=ichoice;
484end
485set(handles.ListSubdirCiv1,'Value',ilist)% select the selected subdir in the menu
486if get(handles.CheckCiv1,'Value')% if Civ1 is performed
[604]487    set(handles.Civ2_ImageA,'String',SubDir);% set by default civ2 directory the same as civ1
[597]488%     set(handles.ListSubdirCiv2,'Value',ilist)
489else % if Civ1 data already exist
[774]490    errormsg=find_netcpair_civ(handles,1); %update the list of available index pairs in the new directory
[597]491    if ~isempty(errormsg)
492    msgbox_uvmat('ERROR',errormsg)
493    end
494end
495
496%------------------------------------------------------------------------
497% --- Executes on carriage return on the SubDir checkciv1 edit window
[604]498function Civ2_ImageA_Callback(hObject, eventdata, handles)
[597]499%------------------------------------------------------------------------
[604]500SubDir=get(handles.Civ1_ImageB,'String');
[597]501menu_str=get(handles.ListSubdirCiv2,'String');% read the list of subdirectories for update
502ichoice=find(strcmp(SubDir,menu_str),1);
503if isempty(ichoice)
504    ilist=numel(menu_str); %select 'new...' in the menu
505else
506    ilist=ichoice;
507end
508set(handles.ListSubdirCiv2,'Value',ilist)% select the selected subdir in the menu
509%update the list of available pairs from netcdf files in the new directory
510if ~get(handles.CheckCiv2,'Value') && ~get(handles.CheckCiv1,'Value') && ~get(handles.CheckFix1,'Value') && ~get(handles.CheckPatch1,'Value')
511    errormsg=find_netcpair_civ(handles,2);
512        if ~isempty(errormsg)
513    msgbox_uvmat('ERROR',errormsg)
514    end
515end
516
517%------------------------------------------------------------------------
518% --- Executes on button press in CheckCiv1.
519function CheckCiv1_Callback(hObject, eventdata, handles)
520%------------------------------------------------------------------------
521update_CivOptions(handles,0)
522
523%------------------------------------------------------------------------
524% --- Executes on button press in CheckFix1.
525function CheckFix1_Callback(hObject, eventdata, handles)
526%------------------------------------------------------------------------
527update_CivOptions(handles,0)
528
529%------------------------------------------------------------------------
530% --- Executes on button press in CheckPatch1.
531function CheckPatch1_Callback(hObject, eventdata, handles)
532%------------------------------------------------------------------------
533update_CivOptions(handles,0)
534
535%------------------------------------------------------------------------
536% --- Executes on button press in CheckCiv2.
537function CheckCiv2_Callback(hObject, eventdata, handles)
538%------------------------------------------------------------------------
539update_CivOptions(handles,0)
540
541%------------------------------------------------------------------------
542% --- Executes on button press in CheckFix2.
543function CheckFix2_Callback(hObject, eventdata, handles)
544%------------------------------------------------------------------------
545update_CivOptions(handles,0)
546
547%------------------------------------------------------------------------
548% --- Executes on button press in CheckPatch2.
549function CheckPatch2_Callback(hObject, eventdata, handles)
550%------------------------------------------------------------------------
551update_CivOptions(handles,0)
552
553%------------------------------------------------------------------------
554% --- activated by any checkbox controling the selection of Civ1,Fix1,Patch1,Civ2,Fix2,Patch2
555function update_CivOptions(handles,opening)
556%------------------------------------------------------------------------
[851]557if opening>0
558    set(handles.CheckCiv2,'UserData',opening)% store the info on the current status of the civ processing
559end
[597]560checkbox=zeros(1,6);
561checkbox(1)=get(handles.CheckCiv1,'Value');
562checkbox(2)=get(handles.CheckFix1,'Value');
563checkbox(3)=get(handles.CheckPatch1,'Value');
564checkbox(4)=get(handles.CheckCiv2,'Value');
565checkbox(5)=get(handles.CheckFix2,'Value');
566checkbox(6)=get(handles.CheckPatch2,'Value');
567if opening==0
568    errormsg=find_netcpair_civ(handles,1); % select the available netcdf files
569    if ~isempty(errormsg)
570        msgbox_uvmat('ERROR',errormsg)
571    end
572end
[851]573if max(checkbox(4:6))>0% case of civ2 pair choice needed
[597]574    set(handles.TitlePairCiv2,'Visible','on')
575    set(handles.ListPairCiv2,'Visible','on')
576    if ~opening
577        errormsg=find_netcpair_civ(handles,2); % select the available netcdf files
578        if ~isempty(errormsg)
579            msgbox_uvmat('ERROR',errormsg)
580        end
581    end
582else
583    set(handles.ListPairCiv2,'Visible','off')
584end
[862]585hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
586hhseries=guidata(hseries); %handles of the elements in 'series'
587InputTable=get(hhseries.InputTable,'Data');
588if size(InputTable,1)>=1 && strcmp(InputTable{1,5},'.nc') && max(checkbox(1:3))==0 %&& get(handles.CheckCiv2,'UserData')==6,% no operation asked before Civ2 and input file ready for civ3
[855]589    set(handles.CheckCiv3,'Visible','on')
[851]590else
[855]591    set(handles.CheckCiv3,'Visible','off')
[851]592end
593
594%% set the visibility of the different panels
[597]595options={'Civ1','Fix1','Patch1','Civ2','Fix2','Patch2'};
596for ilist=1:length(options)
597    if checkbox(ilist)
598        set(handles.(options{ilist}),'Visible','on')
599    else
600        set(handles.(options{ilist}),'Visible','off')
601    end
602end
603
604%------------------------------------------------------------------------
605% --- Executes on button press in OK: processing on local computer
606function OK_Callback(hObject, eventdata, handles)
607%------------------------------------------------------------------------
608
[855]609ActionInput=read_GUI(handles.civ_input);% read the infos on the GUI civ_input
[851]610
[855]611%% correct input inconsistencies
[851]612if isfield(ActionInput,'Civ1')
613    checkeven=(mod(ActionInput.Civ1.CorrBoxSize,2)==0);
614    ActionInput.Civ1.CorrBoxSize(checkeven)=ActionInput.Civ1.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
[853]615    ActionInput.Civ1.SearchBoxSize=max(ActionInput.Civ1.SearchBoxSize,ActionInput.Civ1.CorrBoxSize+8);% insure that the search box size is large enough
[851]616    checkeven=(mod(ActionInput.Civ1.SearchBoxSize,2)==0);
617    ActionInput.Civ1.SearchBoxSize(checkeven)=ActionInput.Civ1.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
618end
619if isfield(ActionInput,'Civ2')
620    checkeven=(mod(ActionInput.Civ2.CorrBoxSize,2)==0);
621    ActionInput.Civ2.CorrBoxSize(checkeven)=ActionInput.Civ2.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
[862]622    ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+4);
[851]623    checkeven=(mod(ActionInput.Civ2.SearchBoxSize,2)==0);
624    ActionInput.Civ2.SearchBoxSize(checkeven)=ActionInput.Civ2.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
625end
626
[855]627%% correct mask or grid name for Windows system (replace '\' by '/')
628if isfield(ActionInput,'Civ1')
629    if isfield(ActionInput.Civ1,'Mask')
630        ActionInput.Civ1.Mask=regexprep(ActionInput.Civ1.Mask,'\','/');
[822]631    end
[855]632    if isfield(ActionInput.Civ1,'Grid')
633        ActionInput.Civ1.Grid=regexprep(ActionInput.Civ1.Grid,'\','/');
[822]634    end
635end
[855]636if isfield(ActionInput,'Civ2')
637    if isfield(ActionInput.Civ2,'Mask')
638        ActionInput.Civ2.Mask=regexprep(ActionInput.Civ2.Mask,'\','/');
[822]639    end
[855]640    if isfield(ActionInput.Civ2,'Grid')
641        ActionInput.Civ2.Grid=regexprep(ActionInput.Civ2.Grid,'\','/');
[822]642    end
643end
[855]644
645%% exit the GUI and close it
646handles.output.ActionInput=ActionInput;
[597]647guidata(hObject, handles);% Update handles structure
[598]648uiresume(handles.civ_input);
[597]649
650
651%------------------------------------------------------------------------
652% --- Executes on button press in ListCompareMode.
653function ListCompareMode_Callback(hObject, eventdata, handles)
654%------------------------------------------------------------------------
655ListCompareMode=get(handles.ListCompareMode,'String');
656option=ListCompareMode{get(handles.ListCompareMode,'Value')};
[645]657hseries=findobj(allchild(0),'Tag','series');
658SeriesData=get(hseries,'UserData');
659check_nc=strcmp(SeriesData.FileType{1},'.nc');
660ImageType=SeriesData.FileType(2:end);
661if check_nc
662    ImageType=SeriesData.FileType(2:end);
663else
664    ImageType=SeriesData.FileType;
665end
666hhseries=guidata(hseries);
667InputTable=get(hhseries.InputTable,'Data');
668OriginIndex='off';
669PairIndices='off';
670DoubleInputSeries='off';
[597]671switch option
672    case 'PIV'
[645]673        PairIndices='on';% needs to define index pairs for PIV
674       
675    case 'PIV volume'
676        PairIndices='on';% needs to define index pairs for PIV
[597]677        set(handles.ListPairMode,'Value',1)
678        set(handles.ListPairMode,'String',{'series(Di)'})
[645]679        ListPairMode_Callback(hObject, eventdata, handles)
680    case 'displacement'
681        OriginIndex='on';%define a frame origin for displacement
[833]682%     case 'shift'
683%         if numel(ImageType)==1
684%             fileinput=uigetfile_uvmat('pick a second file series for synchronous shift',InputTable{check_nc+1});
685%             if ~isempty(fileinput)
686%                 series( 'display_file_name',hhseries,fileinput,'append')
687%             end
688%             
689%             
690%         end
[597]691end
[645]692set(handles.num_OriginIndex,'Visible',OriginIndex)
693set(handles.OriginIndex_title,'Visible',OriginIndex)
694set(handles.PairIndices,'Visible',PairIndices)
[597]695ListPairMode_Callback(hObject, eventdata, handles)
[645]696       
[597]697
698
699%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
700% Callbacks in the uipanel Pair Indices
701%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
702%------------------------------------------------------------------------
703% --- Executes on button press in ListPairMode.
704function ListPairMode_Callback(hObject, eventdata, handles)
705%------------------------------------------------------------------------
706compare_list=get(handles.ListCompareMode,'String');
707val=get(handles.ListCompareMode,'Value');
708compare=compare_list{val};
709if strcmp(compare,'displacement')||strcmp(compare,'shift')
710    mode='displacement';
711else
712    mode_list=get(handles.ListPairMode,'String');
713    if ischar(mode_list)
714        mode_list={mode_list};
715    end
716    mode_value=get(handles.ListPairMode,'Value');
717    mode=mode_list{mode_value};
718end
[609]719% displ_num=[];%default
[597]720ref_i=str2double(get(handles.ref_i,'String'));
721% last_i=str2num(get(handles.last_i,'String'));
[599]722CivInputData=get(handles.civ_input,'UserData');
[597]723TimeUnit=get(handles.TimeUnit,'String');
724checkframe=strcmp(TimeUnit,'frame');
[599]725time=CivInputData.Time;
726siztime=size(CivInputData.Time);
[609]727nbfield=siztime(1)-1;
728nbfield2=siztime(2)-1;
[883]729%indchosen=1;  %%first pair selected by default
[597]730%displ_num used to define the indices of the civ_input pairs
731% in mode 'pair j1-j2', j1 and j2 are the file indices, else the indices
732% are relative to the reference indices ref_i and ref_j respectively.
[880]733if isequal(mode,'pair j1-j2')
[597]734    dt=1;
735    displ='';
736    index=0;
737    numlist_a=[];
738    numlist_B=[];
739    %get all the time intervals in bursts
740    displ_dt=1;%default
741    nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
742    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
743        for numod_b=(numod_a+1):nbfield2
744            index=index+1;
745            numlist_a(index)=numod_a;
746            numlist_b(index)=numod_b;
[932]747            if size(time,2)>1 && ~checkframe && size(CivInputData.Time,1)>ref_i && size(CivInputData.Time,2)>numod_b
[599]748                dt(numod_a,numod_b)=CivInputData.Time(ref_i+1,numod_b+1)-CivInputData.Time(ref_i+1,numod_a+1);%first time interval dt
[597]749                displ_dt(index)=dt(numod_a,numod_b);
750            else
751                displ_dt(index)=1;
752            end
753        end
754    end
755    [dtsort,indsort]=sort(displ_dt);
756    if ~isempty(numlist_a)
757        displ_num(1,:)=numlist_a(indsort);
758        displ_num(2,:)=numlist_b(indsort);
759    end
760    displ_num(3,:)=0;
761    displ_num(4,:)=0;
762    enable_j(handles, 'off')
763elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)')
764    index=1:200;
765    displ_num(1,index)=-floor(index/2);
766    displ_num(2,index)=ceil(index/2);
767    displ_num(3:4,index)=zeros(2,200);
768    enable_j(handles, 'on')
769elseif isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
[609]770%     index=1:200;
771%     displ_num(1:2,index)=zeros(2,200);
772%     displ_num(3,index)=-floor(index/2);
773%     displ_num(4,index)=ceil(index/2);
[597]774    enable_i(handles, 'on')
775    if nbfield2 > 1
776        enable_j(handles, 'on')
777    else
778        enable_j(handles, 'off')
779    end
780elseif isequal(mode,'displacement')%the pairs have the same indices
781    displ_num(1,1)=0;
782    displ_num(2,1)=0;
783    displ_num(3,1)=0;
784    displ_num(4,1)=0;
785    if nbfield > 1 || nbfield==0
786        enable_i(handles, 'on')
787    else
788        enable_j(handles, 'off')
789    end
790    if nbfield2 > 1
791        enable_j(handles, 'on')
792    else
793        enable_j(handles, 'off')
794    end
795end
[609]796%set(handles.ListPairCiv1,'UserData',displ_num);
[597]797errormsg=find_netcpair_civ( handles,1);
798    if ~isempty(errormsg)
799    msgbox_uvmat('ERROR',errormsg)
800    end
801% find_netcpair_civ2(handles)
802
803function enable_i(handles, state)
804set(handles.itext,'Visible',state)
[645]805% set(handles.MinIndex_i,'Visible',state)
[603]806% set(handles.last_i,'Visible',state)
807% set(handles.incr_i,'Visible',state)
[645]808set(handles.MaxIndex_i,'Visible',state)
[597]809set(handles.ref_i,'Visible',state)
810
811function enable_j(handles, state)
812set(handles.jtext,'Visible',state)
[645]813% set(handles.MinIndex_j,'Visible',state)
[603]814% set(handles.last_j,'Visible',state)
815% set(handles.incr_j,'Visible',state)
[645]816set(handles.MinIndex_j,'Visible',state)
817set(handles.MaxIndex_j,'Visible',state)
[597]818set(handles.ref_j,'Visible',state)
[645]819%hseries=findobj(allchild(0),'Tag','series');
820%hhseries=guidata(hseries);
821%series('enable_j',hhseries,state); %file input with xml reading  in uvmat, show the image in phys coordinates
[597]822
823
[645]824
[597]825%------------------------------------------------------------------------
826% --- Executes on selection change in ListPairCiv1.
827function ListPairCiv1_Callback(hObject, eventdata, handles)
828%------------------------------------------------------------------------
829%reproduce by default the chosen pair in the checkciv2 menu
830list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
[645]831PairString=list_pair{get(handles.ListPairCiv1,'Value')};
[597]832
[645]833[ind1,ind2]=...
834    find_pair_indices(PairString);
835hseries=findobj(allchild(0),'Tag','series');
836hhseries=guidata(hseries);
837set(hhseries.num_first_j,'String',num2str(ind1));
838set(hhseries.num_last_j,'String',num2str(ind2));
839set(hhseries.num_incr_j,'String',num2str(ind2-ind1));
[668]840set(handles.ListPairCiv2,'Value',get(handles.ListPairCiv1,'Value'))%civ2 selection the same as civ& by default
[645]841
842
[597]843%------------------------------------------------------------------------
844% --- Executes on selection change in ListPairCiv2.
845function ListPairCiv2_Callback(hObject, eventdata, handles)
846%------------------------------------------------------------------------
847
[851]848
[597]849%------------------------------------------------------------------------
850function ref_i_Callback(hObject, eventdata, handles)
851%------------------------------------------------------------------------
852mode_list=get(handles.ListPairMode,'String');
853mode_value=get(handles.ListPairMode,'Value');
854mode=mode_list{mode_value};
855errormsg=find_netcpair_civ(handles,1);% update the menu of pairs depending on the available netcdf files
856if isequal(mode,'series(Di)') || ...% we do patch2 only
857        (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
858    errormsg=find_netcpair_civ( handles,2);
859end
[851]860if isempty(errormsg)
861    set(handles.ref_i,'BackgroundColor',[1 1 1])
[856]862    set(handles.ref_j,'BackgroundColor',[1 1 1])
[851]863else
[597]864    msgbox_uvmat('ERROR',errormsg)
865end
866
[851]867function ref_i_KeyPressFcn(hObject, eventdata, handles)
868set(hObject,'BackgroundColor',[1 0 1])
869       
870% %------------------------------------------------------------------------
871% function ref_j_Callback(hObject, eventdata, handles)
872% %------------------------------------------------------------------------
873% mode_list=get(handles.ListPairMode,'String');
874% mode_value=get(handles.ListPairMode,'Value');
875% mode=mode_list{mode_value};
876% errormsg='';
877% if isequal(get(handles.CheckCiv1,'Value'),0)|| isequal(mode,'series(Dj)')
878%     errormsg=find_netcpair_civ(handles,1);% update the menu of pairs depending on the available netcdf files
879% end
880% if isequal(mode,'series(Dj)') || ...
881%         (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
882%     errormsg=find_netcpair_civ(handles,2);
883% end
884% if ~isempty(errormsg)
885%     msgbox_uvmat('ERROR',errormsg)
886% end
887%
888% function ref_j_KeyPressFcn(hObject, eventdata, handles)
889% set(handles.ref_j,'BackgroundColor',[1 0 1])
[597]890%------------------------------------------------------------------------
891% determine the menu for checkciv1 pairs depending on existing netcdf file at the middle of
[645]892% the field series set by MinIndex_i, incr, last_i
[597]893% index=1: look for pairs for civ1
894% index=2: look for pairs for civ2
895function errormsg=find_netcpair_civ(handles,index)
896%------------------------------------------------------------------------
897set(gcf,'Pointer','watch')% set the mouse pointer to 'watch' (clock)
898
899%% initialisation
900errormsg='';
[603]901CivInputData=get(handles.civ_input,'UserData');
[599]902%browse=get(handles.RootPath,'UserData');
[597]903compare_list=get(handles.ListCompareMode,'String');
904val=get(handles.ListCompareMode,'Value');
905compare=compare_list{val};
[880]906if ~strcmp(compare,'displacement')%||strcmp(compare,'shift')
907 
[597]908    mode_list=get(handles.ListPairMode,'String');
909    mode_value=get(handles.ListPairMode,'Value');
910    if isempty(mode_list)
911        return
912    end
913    mode=mode_list{mode_value};
914end
[603]915nom_type_ima=CivInputData.NomTypeIma;
[881]916menu_pair=get(handles.ListPairCiv1,'String');%previous menu of ListPairCiv1
917PairCiv1Init=menu_pair{get(handles.ListPairCiv1,'Value')};%previous choice of pair
918menu_pair=get(handles.ListPairCiv2,'String');%previous menu of ListPairCiv1
919PairCiv2Init=menu_pair{get(handles.ListPairCiv2,'Value')};%previous choice of pair
[597]920
921%% determine nom_type_nc, nomenclature type of the .nc files:
[856]922%[nom_type_nc]=nomtype2pair(nom_type_ima,mode);
[597]923
924%% reads .nc subdirectoy and image numbers from the interface
[637]925%SubDirImages=get(handles.Civ1_ImageA,'String');
[609]926%TODO: determine
[637]927%subdir_civ1=[SubDirImages get(handles.Civ1_ImageB,'String')];%subdirectory subdir_civ1 for the netcdf data
928%subdir_civ2=[SubDirImages get(handles.Civ2_ImageA,'String')];%subdirectory subdir_civ2 for the netcdf data
[597]929ref_i=str2double(get(handles.ref_i,'String'));
930ref_j=[];
931if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
932    ref_j=0;
933elseif strcmp(get(handles.ref_j,'Visible'),'on')
934    ref_j=str2double(get(handles.ref_j,'String'));
935end
936if isempty(ref_j)
937    ref_j=1;
938end
[609]939CivInputData=get(handles.civ_input,'UserData');
[597]940TimeUnit=get(handles.TimeUnit,'String');
[633]941Time=CivInputData.Time;
[597]942checkframe=strcmp(TimeUnit,'frame');
943
944%% case with no Civ1 operation, netcdf files need to exist for reading
945displ_pair={''};
[609]946nbpair=200;%default
[597]947select=ones(size(1:nbpair));%flag for displayed pairs =1 for display
[883]948%nbpair=200; %default
[597]949
950%% determine the menu display in .ListPairCiv1
[774]951switch mode
952    case 'series(Di)'
[597]953        for ipair=1:nbpair
954            if select(ipair)
955                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
[883]956                displ_pair_dt{ipair}=displ_pair{ipair};
[774]957                if ~checkframe
958                    if size(Time,1)>=ref_i+1+ceil(ipair/2) && size(Time,2)>=ref_j+1&& ref_i-floor(ipair/2)>=0 && ref_j>=0
959                        dt=Time(ref_i+1+ceil(ipair/2),ref_j+1)-Time(ref_i+1-floor(ipair/2),ref_j+1);%Time interval dtref_j+1
[883]960                        displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(dt*1000)];
[774]961                    end
[597]962                else
[635]963                    dt=ipair/1000;
[883]964                    displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(ipair)];
[774]965                end
[597]966            else
[883]967                displ_pair{ipair}='...';
968                displ_pair_dt{ipair}='...'; %pair not displayed in the menu
[597]969            end
970        end
[774]971    case 'series(Dj)'
[597]972        for ipair=1:nbpair
973            if select(ipair)
974                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
[883]975                displ_pair_dt{ipair}=displ_pair{ipair};
[774]976                if ~checkframe
977                    if size(Time,2)>=ref_j+1+ceil(ipair/2) && size(Time,1)>=ref_i+1 && ref_j-floor(ipair/2)>=0 && ref_i>=0
978                        dt=Time(ref_i+1,ref_j+1+ceil(ipair/2))-Time(ref_i+1,ref_j+1-floor(ipair/2));%Time interval dtref_j+1
[883]979                        displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(dt*1000)];
[774]980                    end
[635]981                else
982                    dt=ipair/1000;
[883]983                    displ_pair_dt{ipair}=[displ_pair_dt{ipair} ' :dt= ' num2str(dt*1000)];
[774]984                end
[597]985            else
986                displ_pair{ipair}='...'; %pair not displayed in the menu
[883]987                displ_pair_dt{ipair}='...'; %pair not displayed in the menu
[597]988            end
989        end
[774]990    case 'pair j1-j2'%case of pairs
[776]991%         MinIndex_j=CivInputData.MinIndex_j;
992%         MaxIndex_j=min(CivInputData.MaxIndex_j,10);%limitate the number of pairs to 10x10
993        MinIndex_j=str2num(get(handles.MinIndex_j,'String'));
994        MaxIndex_j=str2num(get(handles.MaxIndex_j,'String'));
[774]995        index_pair=0;
996        %get all the Time intervals in bursts
[918]997        displ_pair_dt='';
[774]998        for numod_a=MinIndex_j:MaxIndex_j-1 %nbfield2 always >=2 for 'pair j1-j2' mode
999            for numod_b=(numod_a+1):MaxIndex_j
1000                index_pair=index_pair+1;
1001                displ_pair{index_pair}=['j= ' num2stra(numod_a,nom_type_ima) '-' num2stra(numod_b,nom_type_ima)];
[884]1002                displ_pair_dt{index_pair}=displ_pair{index_pair};
[774]1003                dt(index_pair)=numod_b-numod_a;%default dt
1004                if size(Time,1)>ref_i && size(Time,2)>numod_b  % && ~checkframe
1005                    dt(index_pair)=Time(ref_i+1,numod_b+1)-Time(ref_i+1,numod_a+1);% Time interval dt
[883]1006                    displ_pair_dt{index_pair}=[displ_pair_dt{index_pair} ' :dt= ' num2str(dt(index_pair)*1000)];
[774]1007                end
[597]1008            end
[774]1009           
[597]1010        end
[918]1011        if index_pair ~=0
[774]1012        [tild,indsort]=sort(dt);
1013        displ_pair=displ_pair(indsort);
[883]1014        displ_pair_dt=displ_pair_dt(indsort);
[918]1015        end
[774]1016    case 'displacement'
1017        displ_pair={'Di=Dj=0'};
[883]1018        displ_pair_dt={'Di=Dj=0'};
[597]1019end
1020if index==1
[883]1021    set(handles.ListPairCiv1,'String',displ_pair_dt');
[597]1022end
1023
[758]1024%% determine the default selection in the pair menu for Civ1
[881]1025%ichoice=find(select,1);% index of first selected pair
1026%if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
[883]1027end_pair=regexp(PairCiv1Init,' :dt=');
1028if ~isempty(end_pair)
1029    PairCiv1Init=PairCiv1Init(1:end_pair-1);
1030end
[881]1031ichoice=find(strcmp(PairCiv1Init,displ_pair'),1);
[880]1032if ~isempty(ichoice)
[597]1033    set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
[880]1034else
1035   set(handles.ListPairCiv1,'Value',1)
[597]1036end
[880]1037% if initial>nbpair || (numel(select)>=initial && ~isequal(select(initial),1))
1038%     set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
1039% end
[758]1040
1041%% determine the default selection in the pair menu for Civ2
1042if strcmp(get(handles.ListPairCiv2,'Visible'),'on')
[883]1043    end_pair=regexp(PairCiv2Init,' :dt=');
1044    if ~isempty(end_pair)
1045        PairCiv2Init=PairCiv2Init(1:end_pair-1);
1046    end
[881]1047    ichoice=find(strcmp(PairCiv2Init,displ_pair'),1);
1048    if ~isempty(ichoice)
1049        set(handles.ListPairCiv2,'Value',ichoice);% first valid pair proposed by default in the menu
1050    else
1051        set(handles.ListPairCiv2,'Value',1)
[597]1052    end
[758]1053else
1054    set(handles.ListPairCiv2,'Value',get(handles.ListPairCiv1,'Value'))% initiate the choice of Civ2 as a reproduction of if civ1
[597]1055end
[883]1056set(handles.ListPairCiv2,'String',displ_pair_dt');
[758]1057set(gcf,'Pointer','arrow')% Indicate that the process is finished
[597]1058
1059
1060%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1061% Callbacks in the uipanel Reference Indices
1062%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1063%------------------------------------------------------------------------
[645]1064function MinIndex_i_Callback(hObject, eventdata, handles)
[597]1065%------------------------------------------------------------------------
[645]1066first_i=str2double(get(handles.MinIndex_i,'String'));
[597]1067set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
1068ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
1069
[776]1070% %------------------------------------------------------------------------
1071% function MinIndex_j_Callback(hObject, eventdata, handles)
1072% %------------------------------------------------------------------------
1073% first_j=str2num(get(handles.MinIndex_j,'String'));
1074% set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
1075% ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[597]1076
1077%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1078% Callbacks in the uipanel Civ1
1079%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1080%------------------------------------------------------------------------
1081% --- Executes on button press in SearchRange: determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2
1082function SearchRange_Callback(hObject, eventdata, handles)
1083%------------------------------------------------------------------------
1084%determine pair numbers
1085if strcmp(get(handles.num_UMin,'Visible'),'off')
1086    set(handles.u_title,'Visible','on')
1087    set(handles.v_title,'Visible','on')
1088    set(handles.num_UMin,'Visible','on')
1089    set(handles.num_UMax,'Visible','on')
1090    set(handles.num_VMin,'Visible','on')
1091    set(handles.num_VMax,'Visible','on')
[854]1092    %set(handles.CoordUnit,'Visible','on')
1093    %set(handles.TimeUnit,'Visible','on')
1094    %set(handles.slash_title,'Visible','on')
[597]1095    set(handles.min_title,'Visible','on')
1096    set(handles.max_title,'Visible','on')
1097    set(handles.unit_title,'Visible','on')
1098else
1099    get_search_range(hObject, eventdata, handles)
1100end
1101
1102%------------------------------------------------------------------------
1103% ---  determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2 and shift
1104function get_search_range(hObject, eventdata, handles)
1105%------------------------------------------------------------------------
1106param_civ1=read_GUI(handles.Civ1);
1107umin=param_civ1.UMin;
1108umax=param_civ1.UMax;
1109vmin=param_civ1.VMin;
1110vmax=param_civ1.VMax;
1111%switch min_title and max_title in case of error
1112if umax<=umin
1113    umin_old=umin;
1114    umin=umax;
1115    umax=umin_old;
1116    set(handles.num_UMin,'String', num2str(umin))
1117    set(handles.num_UMax,'String', num2str(umax))
1118end
1119if vmax<=vmin
1120    vmin_old=vmin;
1121    vmin=vmax;
1122    vmax=vmin_old;
1123    set(handles.num_VMin,'String', num2str(vmin))
1124    set(handles.num_VMax,'String', num2str(vmax))
1125end   
1126if ~(isempty(umin)||isempty(umax)||isempty(vmin)||isempty(vmax))
[854]1127%     list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
1128%     index=get(handles.ListPairCiv1,'Value');
1129%     pair_string=list_pair{index};
1130%     time=get(handles.TimeSource,'UserData'); %get the set of times
1131%     pxcm=get(handles.SearchRange,'UserData');
1132%     mode_list=get(handles.ListPairMode,'String');
1133%     mode_value=get(handles.ListPairMode,'Value');
1134%     mode=mode_list{mode_value};     
1135%     if isequal (mode, 'series(Di)' )
1136%         ref_i=str2double(get(handles.ref_i,'String'));
1137%         num1=ref_i-floor(index/2);%  first image numbers
1138%         num2=ref_i+ceil(index/2);
1139%         num_a=1;
1140%         num_b=1;
1141%     elseif isequal (mode, 'series(Dj)')
1142%         num1=1;
1143%         num2=1;
1144%         ref_j=str2double(get(handles.ref_j,'String'));
1145%         num_a=ref_j-floor(index/2);%  first image numbers
1146%         num_b=ref_j+ceil(index/2);
1147%     elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)     
1148%         ref_i=str2double(get(handles.ref_i,'String'));
1149%         num1=ref_i;
1150%         num2=ref_i;
1151%                 r=regexp(pair_string,'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
1152%         if isempty(r)
1153%             r=regexp(pair_string,'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
1154%         end 
1155%         num_a=str2num(r.num1);
1156%         num_b=str2num(r.num2);
1157%     end
1158%     dt=time(num2+1,num_b+1)-time(num1+1,num_a+1);
1159%     ibx=str2double(get(handles.num_CorrBoxSize_1,'String'));
1160%     iby=str2double(get(handles.num_CorrBoxSize_2,'String'));
1161%     umin=dt*pxcm*umin;
1162%     umax=dt*pxcm*umax;
1163%     vmin=dt*pxcm*vmin;
1164%     vmax=dt*pxcm*vmax;
[597]1165    shiftx=round((umin+umax)/2);
1166    shifty=round((vmin+vmax)/2);
[854]1167    isx=(umax+2-shiftx)*2+param_civ1.CorrBoxSize(1);
[597]1168    isx=2*ceil(isx/2)+1;
[854]1169    isy=(vmax+2-shifty)*2+param_civ1.CorrBoxSize(2);
[597]1170    isy=2*ceil(isy/2)+1;
1171    set(handles.num_SearchBoxShift_1,'String',num2str(shiftx));
1172    set(handles.num_SearchBoxShift_2,'String',num2str(shifty));
1173    set(handles.num_SearchBoxSize_1,'String',num2str(isx));
1174    set(handles.num_SearchBoxSize_2,'String',num2str(isy));
1175end
1176
[851]1177%------------------------------------------------------------------------
[856]1178% --- Executes on selection in menu CorrSmooth.
[851]1179function num_CorrSmooth_Callback(hObject, eventdata, handles)
[873]1180set(handles.ConfigSource,'String','NEW')
[856]1181set(handles.OK,'BackgroundColor',[1 0 1])
[851]1182%------------------------------------------------------------------------
1183
[859]1184% --- Executes on button press in CheckDeformation.
1185function CheckDeformation_Callback(hObject, eventdata, handles)
[862]1186set(handles.ConfigSource,'String','NEW')
[859]1187set(handles.OK,'BackgroundColor',[1 0 1])
[885]1188handles_CoorSmooth=findobj(get(handles.Civ2,'children'),'Tag','num_CorrSmooth');
1189if get(handles.CheckDeformation,'Value')   
1190    set(handles_CoorSmooth,'Visible','off')
[883]1191else
[885]1192    set(handles_CoorSmooth,'Visible','on')
[883]1193end
[859]1194
[597]1195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1196% Callbacks in the uipanel Fix1
1197%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1198%------------------------------------------------------------------------
[851]1199% % --- Executes on button press in CheckMask.
1200% function get_mask_fix1_Callback(hObject, eventdata, handles)
1201% %------------------------------------------------------------------------
1202% maskval=get(handles.CheckMask,'Value');
1203% if isequal(maskval,0)
1204%     set(handles.Mask,'String','')
1205% else
1206%     mask_displ='no mask'; %default
1207%     filebase=get(handles.RootPath,'String');
1208%     [nbslice, flag_mask]=get_mask(filebase,handles);
1209%     if isequal(flag_mask,1)
1210%         mask_displ=[num2str(nbslice) 'mask'];
1211%     elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1212%         filebase_a=get(handles.RootFile_1,'String');
1213%         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1214%         if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1215%             mask_displ='no mask';
1216%         end
1217%     end
1218%     if isequal(mask_displ,'no mask')
1219%         [FileName, PathName, filterindex] = uigetfile( ...
1220%             {'*.png', ' (*.png)';
1221%             '*.png',  '.png files '; ...
1222%             '*.*', 'All Files (*.*)'}, ...
1223%             'Pick a mask file *.png',filebase);
1224%         mask_displ=fullfile(PathName,FileName);
1225%         if ~exist(mask_displ,'file')
1226%             mask_displ='no mask';
1227%         end
1228%     end
1229%     if isequal(mask_displ,'no mask')
1230%         set(handles.CheckMask,'Value',0)
1231%         set(handles.CheckMask,'Value',0)
1232%         set(handles.CheckMask,'Value',0)
1233%     else
1234%         %set(handles.CheckMask,'Value',1)
1235%         set(handles.CheckMask,'Value',1)
1236%     end
1237%     set(handles.Mask,'String',mask_displ)
1238%     set(handles.Mask,'String',mask_displ)
1239%     set(handles.Mask,'String',mask_displ)
1240% end
[597]1241
[851]1242%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1243% Callbacks in the uipanel Civ2
1244%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[597]1245%------------------------------------------------------------------------
1246% --- Executes on button press in CheckMask: select box for mask option
1247function get_mask_civ2_Callback(hObject, eventdata, handles)
1248%------------------------------------------------------------------------
1249maskval=get(handles.CheckMask,'Value');
1250if isequal(maskval,0)
1251    set(handles.Mask,'String','')
1252else
1253    mask_displ='no mask'; %default
1254    filebase=get(handles.RootPath,'String');
1255    [nbslice, flag_mask]=get_mask(filebase,handles);
1256    if isequal(flag_mask,1)
1257        mask_displ=[num2str(nbslice) 'mask'];
1258    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1259        filebase_a=get(handles.RootFile_1,'String');
1260        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1261        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1262            mask_displ='no mask';
1263        end
1264    end
1265    if isequal(mask_displ,'no mask')
1266        [FileName, PathName, filterindex] = uigetfile( ...
1267            {'*.png', ' (*.png)';
1268            '*.png',  '.png files '; ...
1269            '*.*', 'All Files (*.*)'}, ...
1270            'Pick a mask file *.png',filebase);
1271        mask_displ=fullfile(PathName,FileName);
1272        if ~exist(mask_displ,'file')
1273            mask_displ='no mask';
1274        end
1275    end
1276    if isequal(mask_displ,'no mask')
1277        set(handles.CheckMask,'Value',0)
1278        set(handles.CheckMask,'Value',0)
1279    else
1280        set(handles.CheckMask,'Value',1)
1281    end
1282    set(handles.Mask,'String',mask_displ)
1283end
1284
[851]1285% %------------------------------------------------------------------------
1286% % --- Executes on button press in CheckMask.
1287% function get_mask_fix2_Callback(hObject, eventdata, handles)
1288% %------------------------------------------------------------------------
1289% maskval=get(handles.CheckMask,'Value');
1290% if isequal(maskval,0)
1291%     set(handles.Mask,'String','')
1292% else
1293%     mask_displ='no mask'; %default
1294%     filebase=get(handles.RootPath,'String');
1295%     [nbslice, flag_mask]=get_mask(filebase,handles);
1296%     if isequal(flag_mask,1)
1297%         mask_displ=[num2str(nbslice) 'mask'];
1298%     elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1299%         filebase_a=get(handles.RootFile_1,'String');
1300%         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1301%         if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1302%             mask_displ='no mask';
1303%         end
1304%     end
1305%     if isequal(mask_displ,'no mask')
1306%         [FileName, PathName, filterindex] = uigetfile( ...
1307%             {'*.png', ' (*.png)';
1308%             '*.png',  '.png files '; ...
1309%             '*.*', 'All Files (*.*)'}, ...
1310%             'Pick a mask file *.png',filebase);
1311%         mask_displ=fullfile(PathName,FileName);
1312%         if ~exist(mask_displ,'file')
1313%             mask_displ='no mask';
1314%         end
1315%     end
1316%     if isequal(mask_displ,'no mask')
1317%         set(handles.CheckMask,'Value',0)
1318%     end
1319%     set(handles.Mask,'String',mask_displ)
1320% end
[597]1321
1322%------------------------------------------------------------------------
1323% --- function called to look for mask files
1324function [nbslice, flag_mask]=get_mask(filebase,handles)
1325%------------------------------------------------------------------------
1326%detect mask files, images with appropriate file base
1327%[filebase '_' xx 'mask'], xx=nbslice
1328%flag_mask=1 indicates detection
1329
1330flag_mask=0;%default
1331nbslice=1;
1332
[604]1333% subdir=get(handles.Civ1_ImageB,'String');
[597]1334[Path,Name]=fileparts(filebase);
1335if ~isdir(Path)
1336    msgbox_uvmat('ERROR','no path for input files')
1337    return
1338end
1339% currentdir=pwd;
1340% cd(Path);%move in the dir of the root name filebase
1341maskfiles=dir(fullfile(Path,[Name '_*mask_*.png']));%look for mask files
1342% cd(currentdir);%come back to the current working directory
1343if ~isempty(maskfiles)
1344    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
1345    % else
1346    flag_mask=1;
1347    maskname=maskfiles(1).name;% take the first mask file in the list
1348    [Path2,Name,ext]=fileparts(maskname);
1349    Namedouble=double(Name);
1350    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1351    ind_mask=findstr('mask',Name);
1352    i=ind_mask-1;
1353    while val(i)==0 && i>0
1354        i=i-1;
1355    end
1356    nbslice=str2double(Name(i+1:ind_mask-1));
1357    if ~isnan(nbslice) && Name(i)=='_'
1358        flag_mask=1;
1359    else
1360        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
1361        return
1362        nbslice=1;
1363    end
1364end
1365
1366%------------------------------------------------------------------------
1367% --- function called to look for grid files
1368function [nbslice, flag_grid]=get_grid(filebase,handles)
1369%------------------------------------------------------------------------
1370flag_grid=0;%default
1371nbslice=1;
1372[Path,Name]=fileparts(filebase);
1373currentdir=pwd;
1374cd(Path);%move in the dir of the root name filebase
1375gridfiles=dir([Name '_*grid_*.grid']);%look for grid files
1376cd(currentdir);%come back to the current working directory
1377if ~isempty(gridfiles)
1378    flag_grid=1;
1379    gridname=gridfiles(1).name;% take the first grid file in the list
1380    [Path2,Name,ext]=fileparts(gridname);
1381    Namedouble=double(Name);
1382    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1383    ind_grid=findstr('grid',Name);
1384    i=ind_grid-1;
1385    while val(i)==0 && i>0
1386        i=i-1;
1387    end
1388    nbslice=str2double(Name(i+1:ind_grid-1));
1389    if ~isnan(nbslice) && Name(i)=='_'
1390        flag_grid=1;
1391    else
1392        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
1393        return
1394        nbslice=1;
1395    end
1396end
1397
1398%------------------------------------------------------------------------
1399% --- transform numbers to letters
1400function str=num2stra(num,nom_type)
1401%------------------------------------------------------------------------
1402if isempty(nom_type)
1403    str='';
1404elseif strcmp(nom_type(end),'a')
1405    str=char(96+num);
1406elseif strcmp(nom_type(end),'A')
1407    str=char(96+num);
1408elseif isempty(nom_type(2:end))%a single index
1409    str='';
1410else
1411    str=num2str(num);
1412end
1413
1414% %------------------------------------------------------------------------
1415% % --- Executes on button press in ListSubdirCiv1.
1416% function ListSubdirCiv1_Callback(hObject, eventdata, handles)
1417% %------------------------------------------------------------------------
1418% list_subdir_civ1=get(handles.ListSubdirCiv1,'String');
1419% val=get(handles.ListSubdirCiv1,'Value');
1420% SubDir=list_subdir_civ1{val};
1421% if strcmp(SubDir,'new...')
1422%     if get(handles.CheckCiv1,'Value')
1423%         SubDir='CIV_INPUT'; %default subdirectory
1424%     else
1425%         msgbox_uvmat('ERROR','select CheckCiv1 to perform a new civ_input operation')
1426%         return
1427%     end   
1428% end
[604]1429% set(handles.Civ1_ImageB,'String',SubDir);
[597]1430% errormsg=find_netcpair_civ(handles,1);
1431% if ~isempty(errormsg)
1432%     msgbox_uvmat('ERROR',errormsg)
1433% end
1434%     
1435%------------------------------------------------------------------------
1436% % --- Executes on button press in ListSubdirCiv2.
1437% function ListSubdirCiv2_Callback(hObject, eventdata, handles)
1438% %------------------------------------------------------------------------
1439% list_subdir_civ2=get(handles.ListSubdirCiv2,'String');
1440% val=get(handles.ListSubdirCiv2,'Value');
1441% SubDir=list_subdir_civ2{val};
1442% if strcmp(SubDir,'new...')
1443%     if get(handles.CheckCiv2,'Value')
1444%         SubDir='CIV_INPUT'; %default subdirectory
1445%     else
1446%         msgbox_uvmat('ERROR','select CheckCiv2 to perform a new civ_input operation')
1447%         return
1448%     end
1449% end
[604]1450% set(handles.Civ2_ImageA,'String',SubDir);
[597]1451
1452%------------------------------------------------------------------------
1453% --- Executes on button press in CheckGrid.
1454function CheckGrid_Callback(hObject, eventdata, handles)
1455%------------------------------------------------------------------------
1456value=get(hObject,'Value');
1457hparent=get(hObject,'parent');%handles of the parent panel
1458hchildren=get(hparent,'children');
1459handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel
1460handle_dx=findobj(hchildren,'tag','num_Dx');
1461handle_dy=findobj(hchildren,'tag','num_Dy');
1462handle_title_dx=findobj(hchildren,'tag','title_Dx');
1463handle_title_dy=findobj(hchildren,'tag','title_Dy');
1464testgrid=0;
1465filegrid='';
1466if value
[665]1467        hseries=findobj(allchild(0),'Tag','series');
1468    hhseries=guidata(hseries);
1469    InputTable=get(hhseries.InputTable,'Data');
1470     ind_A=1;% line index of the (first) image series
1471    if strcmp(InputTable{1,5},'.nc');
1472        ind_A=2;
1473    end
1474    filebase=InputTable{ind_A,1};
[597]1475    [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name
1476    if isequal(flag_grid,1)
1477        filegrid=[num2str(nbslice) 'grid'];
1478        testgrid=1;
1479    else % browse for a grid
1480        filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData
1481        if exist(filegrid,'file')
1482            filebase=filegrid;
1483        end
[665]1484       filegrid = uigetfile_uvmat('pick a grid file .grid:',filebase,'.grid');
[597]1485        set(hObject,'UserData',filegrid);%store for future use
[665]1486        if ~isempty(filegrid)
[597]1487            testgrid=1;
[665]1488        end
1489        set(hObject,'UserData',filegrid);%store for future use
[597]1490    end
1491end
1492if testgrid
1493    set(handle_dx,'Visible','off');
1494    set(handle_dy,'Visible','off');
1495    set(handle_title_dy,'Visible','off');
1496    set(handle_title_dx,'Visible','off');
1497    set(handle_txtbox,'Visible','on')
1498    set(handle_txtbox,'String',filegrid)
1499else
1500    set(hObject,'Value',0);
1501    set(handle_dx,'Visible','on');
1502    set(handle_dy,'Visible','on');
1503    set(handle_title_dy,'Visible','on');
1504    set(handle_title_dx,'Visible','on');
1505    set(handle_txtbox,'Visible','off')
1506end
1507
1508%% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
1509PanelName=get(hparent,'tag');
1510if strcmp(PanelName,'Civ1')
1511    hchildren=get(handles.Civ2,'children');
1512    handle_checkbox=findobj(hchildren,'tag','CheckGrid');
1513    handle_txtbox=findobj(hchildren,'tag','Grid');
1514    handle_dx=findobj(hchildren,'tag','num_Dx');
1515    handle_dy=findobj(hchildren,'tag','num_Dy');
1516    handle_title_dx=findobj(hchildren,'tag','title_Dx');
1517    handle_title_dy=findobj(hchildren,'tag','title_Dy');
1518    set(handle_checkbox,'UserData',filegrid);%store for future use
1519    if testgrid
1520        set(handle_checkbox,'Value',1);
1521        set(handle_dx,'Visible','off');
1522        set(handle_dy,'Visible','off');
1523        set(handle_title_dx,'Visible','off');
1524        set(handle_title_dy,'Visible','off');
1525        set(handle_txtbox,'Visible','on')
1526        set(handle_txtbox,'String',filegrid)
1527    end
1528end
[873]1529set(handles.ConfigSource,'String','NEW')
[856]1530set(handles.OK,'BackgroundColor',[1 0 1])
[918]1531
[597]1532%------------------------------------------------------------------------
1533% --- Executes on button press in CheckMask: common to all panels (civ1, Civ2..)
1534function CheckMask_Callback(hObject, eventdata, handles)
1535%------------------------------------------------------------------------
1536value=get(hObject,'Value');
1537hparent=get(hObject,'parent');
1538parent_tag=get(hparent,'Tag');
1539hchildren=get(hparent,'children');
1540handle_txtbox=findobj(hchildren,'tag','Mask');% look for the mask name box in the same panel
[1010]1541handle_NbSlice=findobj(hchildren,'tag','num_NbSlice');% look for the mask name box in the same panel
[597]1542testmask=0;
1543if value
[665]1544    hseries=findobj(allchild(0),'Tag','series');
1545    hhseries=guidata(hseries);
1546    InputTable=get(hhseries.InputTable,'Data');
[851]1547    ind_A=1;% line index of the (first) image series
[665]1548    if strcmp(InputTable{1,5},'.nc');
1549        ind_A=2;
1550    end
[1010]1551%     [nbslice, flag_mask]=get_mask(InputTable{ind_A,1},handles);% look for a mask with appropriate name
1552%     if isequal(flag_mask,1)
1553%         filemask=[num2str(nbslice) 'mask'];
1554%         testmask=1;
1555%     else % browse for a mask
[851]1556        filemask= uigetfile_uvmat('pick a mask image file:',InputTable{ind_A,1},'image');
[1010]1557        [FilePath,FileName,Ext]=fileparts(filemask);   
1558        [RootPath,SubDir,RootFile,i1_series,i2,j1,j2,NomType]=find_file_series(FilePath,[FileName,Ext]);
1559        if strcmp(NomType,'_1')
1560           NbSlice=i1_series(1,2,end);
1561           set(handle_NbSlice,'String',num2str(NbSlice))
1562        end
[597]1563        set(hObject,'UserData',filemask);%store for future use
[665]1564        if ~isempty(filemask)
[597]1565            testmask=1;
[1010]1566         end
1567%     end
[597]1568end
1569if testmask
[851]1570    set(handles.Mask,'Visible','on')
1571    set(handles.Mask,'String',filemask)
[597]1572    set(handles.CheckMask,'Value',1)
[1010]1573    if strcmp(NomType,'_1')
1574        set(handles.num_NbSlice,'Visible','on')
1575    end
[597]1576else
1577    set(hObject,'Value',0);
1578    set(handle_txtbox,'Visible','off')
[1010]1579    set(handles.num_NbSlice,'Visible','off')
[597]1580end
[873]1581set(handles.ConfigSource,'String','NEW')
1582set(handles.ConfigSource,'BackgroundColor',[1 0 1])
[597]1583
[851]1584% %------------------------------------------------------------------------
1585% % --- Executes on button press in get_gridpatch1.
1586% function get_gridpatch1_Callback(hObject, eventdata, handles)
1587% %------------------------------------------------------------------------
1588% filebase=get(handles.RootPath,'String');
1589% [FileName, PathName, filterindex] = uigetfile( ...
1590%     {'*.grid', ' (*.grid)';
1591%     '*.grid',  '.grid files '; ...
1592%     '*.*', 'All Files (*.*)'}, ...
1593%     'Pick a file',filebase);
1594% filegrid=fullfile(PathName,FileName);
1595% set(handles.grid_patch1,'string',filegrid);
1596% set(hObject,'BackgroundColor',[1 0 1])
[597]1597
1598%------------------------------------------------------------------------
1599% --- STEREO Interp
1600function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
1601%------------------------------------------------------------------------
1602namelog=[filename_nc(1:end-3) '_stinterp.log'];
1603cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
1604    ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ' -c1 ' xmlA ' -c2 ' xmlB '  -xy  x -Nfy 1024 > ' namelog ' 2>&1']; % redirect standard output to the log file
1605
1606% %------------------------------------------------------------------------
1607% %--read images and convert them to the uint16 format used for PIV
1608% function A=read_image(filename,type_ima,num,movieobject)
1609% %------------------------------------------------------------------------
1610% %num is the view number needed for an avi movie
1611% switch type_ima
1612%     case 'movie'
1613%         A=read(movieobject,num);
1614%     case 'avi'
1615%         mov=aviread(filename,num);
1616%         A=frame2im(mov(1));
1617%     case 'multimage'
1618%         A=imread(filename,num);
1619%     case 'image'
1620%         A=imread(filename);
1621% end
1622% siz=size(A);
1623% if length(siz)==3;%color images
1624%     A=sum(double(A),3);
1625%     A=uint16(A);
1626% end
1627
1628
1629%------------------------------------------------------------------------
1630% --- Executes on button press in get_ref_fix1.
1631function get_ref_fix1_Callback(hObject, eventdata, handles)
1632%------------------------------------------------------------------------
1633filebase=get(handles.RootPath,'String');
1634[FileName, PathName, filterindex] = uigetfile( ...
1635    {'*.nc', ' (*.nc)';
1636    '*.nc',  'netcdf files '; ...
1637    '*.*', 'All Files (*.*)'}, ...
1638    'Pick a file',filebase);
1639
1640fileinput=[PathName FileName];
1641sizf=size(fileinput);
1642if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1643%[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1644[Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1645ref.filebase=fullfile(Path,File);
1646% ref.num_a=stra2num(str_a);
1647% ref.num_b=stra2num(str_b);
1648% ref.num1=str2double(field_count);
1649% ref.num2=str2double(str2);
1650browse=[];%initialisation
1651if ~isequal(ref.ext,'.nc')
1652    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1653    return
1654end
1655set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
1656set(handles.ref_fix1,'UserData',ref)
1657menu_field{1}='civ1';
1658Data=nc2struct(fileinput,[]);
1659if isfield(Data,'patch') && isequal(Data.patch,1)
1660    menu_field{2}='filter1';
1661end
1662if isfield(Data,'civ2') && isequal(Data.civ2,1)
1663    menu_field{3}='civ2';
1664end
1665if isfield(Data,'patch2') && isequal(Data.patch2,1)
1666    menu_field{4}='filter2';
1667end
1668set(handles.field_ref1,'String',menu_field);
1669set(handles.field_ref1,'Value',length(menu_field));
1670set(handles.num_MinVel,'Value',2);
1671set(handles.num_MinVel,'String','1');%default threshold
1672set(handles.ref_fix1,'Enable','on')
1673
1674%------------------------------------------------------------------------
1675% --- Executes on button press in get_ref_fix2.
1676function get_ref_fix2_Callback(hObject, eventdata, handles)
1677%------------------------------------------------------------------------
1678if isequal(get(handles.get_ref_fix2,'Value'),1)
1679    filebase=get(handles.RootPath,'String');
1680    [FileName, PathName, filterindex] = uigetfile( ...
1681        {'*.nc', ' (*.nc)';
1682        '*.nc',  'netcdf files '; ...
1683        '*.*', 'All Files (*.*)'}, ...
1684        'Pick a file',filebase);
1685    fileinput=[PathName FileName];
1686    sizf=size(fileinput);
1687    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1688    %[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1689    [Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1690    ref.filebase=fullfile(Path,File);
[692]1691    %     ref.num_a=stra2num(str_a);
1692    %     ref.num_b=stra2num(str_b);
1693    %     ref.num1=str2num(field_count);
1694    %     ref.num2=str2num(str2);
[597]1695    browse=[];%initialisation
1696    if ~isequal(ref.ext,'.nc')
1697        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1698        return
1699    end
1700    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
1701    set(handles.ref_fix2,'UserData',ref)
1702    menu_field{1}='civ1';
1703    Data=nc2struct(fileinput,[]);
1704    if isfield(Data,'patch') && isequal(Data.patch,1)
1705        menu_field{2}='filter1';
1706    end
1707    if isfield(Data,'civ2') && isequal(Data.civ2,1)
1708        menu_field{3}='civ2';
1709    end
1710    if isfield(Data,'patch2') && isequal(Data.patch2,1)
1711        menu_field{4}='filter2';
1712    end
1713    set(handles.field_ref2,'String',menu_field);
1714    set(handles.field_ref2,'Value',length(menu_field));
1715    set(handles.num_MinVel,'Value',2);
1716    set(handles.num_MinVel,'String','1');%default threshold
1717    set(handles.ref_fix2,'Enable','on')
1718    set(handles.ref_fix2,'Visible','on')
1719    set(handles.field_ref2,'Visible','on')
1720else
1721    set(handles.ref_fix2,'Visible','off')
1722    set(handles.field_ref2,'Visible','off')
1723end
1724
1725%------------------------------------------------------------------------
1726function ref_fix1_Callback(hObject, eventdata, handles)
1727%------------------------------------------------------------------------
1728set(handles.num_MinVel,'Value',1);
1729set(handles.field_ref1,'Value',1)
1730set(handles.field_ref1,'String',{' '})
1731set(handles.ref_fix1,'UserData',[]);
1732set(handles.ref_fix1,'String','');
1733set(handles.thresh_vel1,'String','0');
1734
1735%------------------------------------------------------------------------
1736function ref_fix2_Callback(hObject, eventdata, handles)
1737%------------------------------------------------------------------------
1738set(handles.num_MinVel,'Value',1);
1739set(handles.field_ref2,'Value',1)
1740set(handles.field_ref2,'String',{' '})
1741set(handles.ref_fix2,'UserData',[]);
1742set(handles.ref_fix2,'String','');
1743set(handles.num_MinVel,'String','0');
1744
1745%------------------------------------------------------------------------
1746% --- TO ABANDON Executes on button press in test_stereo1.
1747function CheckStereo_Callback(hObject, eventdata, handles)
1748%------------------------------------------------------------------------
1749hparent=get(hObject,'parent');
1750parent_tag=get(hparent,'Tag');
1751hchildren=get(hparent,'children');
1752handle_txtbox=findobj(hchildren,'tag','txt_Mask');
1753if isequal(get(hObject,'Value'),0)
1754    set(handles.num_SubDomainSize,'Visible','on')
1755    set(handles.num_FieldSmooth,'Visible','on')
1756else
1757    set(handles.num_SubDomainSize,'Visible','off')
1758    set(handles.num_FieldSmooth,'Visible','off')
1759end
1760
1761% %------------------------------------------------------------------------
1762% % --- Executes on button press in CheckStereo.
1763% function StereoCheck_Callback(hObject, eventdata, handles)
1764% %------------------------------------------------------------------------
1765% if isequal(get(handles.CheckStereo,'Value'),0)
1766%     set(handles.num_subdomainsize,'Visible','on')
1767%     set(handles.num_FieldSmooth,'Visible','on')
1768% else
[651]1769
[597]1770%     set(handles.num_subdomainsize,'Visible','off')
1771%     set(handles.num_FieldSmooth,'Visible','off')
1772% end
1773
[774]1774
1775
1776%------------------------------------------------------------------------
1777%----function introduced for the correlation window figure, activated by deleting this window
1778function closeview_field(gcbo,eventdata)
[597]1779%------------------------------------------------------------------------
[774]1780hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1781if ~isempty(hview_field)
1782    delete(hview_field)
1783end
1784
1785%------------------------------------------------------------------------
1786% --- Executes on button press in CheckThreshold.
1787function CheckThreshold_Callback(hObject, eventdata, handles)
1788%------------------------------------------------------------------------
1789huipanel=get(hObject,'parent');
1790obj(1)=findobj(huipanel,'Tag','num_MinIma');
1791obj(2)=findobj(huipanel,'Tag','num_MaxIma');
1792obj(3)=findobj(huipanel,'Tag','title_Threshold');
1793if get(hObject,'Value')
1794    set(obj,'Visible','on')
1795else
1796    set(obj,'Visible','off')
1797end
[873]1798set(handles.ConfigSource,'String','NEW')
[856]1799set(handles.OK,'BackgroundColor',[1 0 1])
[774]1800%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1801%%%%%%%%%%%%%%   TEST functions
1802%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1803%------------------------------------------------------------------------
[597]1804% --- Executes on button press in TestCiv1: prepare the image correlation function
[774]1805%     activated by mouse motion
[597]1806function TestCiv1_Callback(hObject, eventdata, handles)
1807%------------------------------------------------------------------------
1808drawnow
1809if get(handles.TestCiv1,'Value')
[855]1810    set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch 
[873]1811    set(handles.CheckFix1,'value',0)% desactivate next step
1812    set(handles.CheckPatch1,'value',0)% desactivate next step
1813    set(handles.CheckCiv2,'value',0)% desactivate next step
1814    set(handles.CheckFix2,'value',0)% desactivate next step
1815    set(handles.CheckPatch2,'value',0)% desactivate next step
1816    update_CivOptions(handles,0)
[860]1817      hseries=findobj(allchild(0),'Tag','series');
1818     Param=read_GUI(hseries);
1819     Param.Action.RUN=1;
1820     Param.ActionInput=read_GUI(handles.civ_input);
[862]1821     if isfield(Param.ActionInput,'Fix1')
1822         Param.ActionInput=rmfield(Param.ActionInput,'Fix1');
1823     end
1824     if isfield(Param.ActionInput,'Patch1')
1825         Param.ActionInput=rmfield(Param.ActionInput,'Patch1');
1826     end
1827     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
1828         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
1829     end
1830     if isfield(Param.ActionInput,'Fix2')
1831         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
1832     end
1833     if isfield(Param.ActionInput,'Patch2')
1834         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
1835     end
[860]1836     if isfield(Param,'OutputSubDir')
1837     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1838     end
1839     Param.ActionInput.Civ1.CorrSmooth=0;% launch Civ1 with no data point (to get the image names for A and B)
[897]1840     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
1841     Param.IndexRange.last_i=str2num(get(handles.ref_i,'String'));
1842     if strcmp(get(handles.ref_j,'Visible'),'on')
1843         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
1844         Param.IndexRange.last_j=Param.IndexRange.first_j;
1845     else
1846         Param.IndexRange.first_j=1;
1847         Param.IndexRange.last_j=1;
1848     end
[860]1849     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
[861]1850     if ~isempty(errormsg), return, end % rmq: error msg displayed in civ_series
1851     
[860]1852 %% create image data ImageData for display
1853     ImageData.ListVarName={'ny','nx','A'};
1854     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
1855     ImageData.A=imread(Data.Civ1_ImageA); % read the first image
1856     if ndims(ImageData.A)==3 %case of color image
1857         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
1858     end
1859     ImageData.ny=[size(ImageData.A,1) 1];
1860     ImageData.nx=[1 size(ImageData.A,2)];
1861     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
[855]1862
[860]1863     %% create the figure view_field for image visualization
1864     hview_field=view_field(ImageData); %view the image in the GUI view_field
1865     set(0,'CurrentFigure',hview_field)
1866     hhview_field=guihandles(hview_field);
1867     set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
1868     ViewData=get(hview_field,'UserData');
1869     ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
1870     ViewData.PlotAxes.X=Data.Civ1_X';
1871     ViewData.PlotAxes.Y=Data.Civ1_Y';
1872     ViewData.PlotAxes.B=imread(Data.Civ1_ImageB);%store the second image in the UserData of the GUI view_field
1873     set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
[855]1874   
1875    %% look for a current figure for image correlation display
1876    corrfig=findobj(allchild(0),'tag','corrfig');
[597]1877    if isempty(corrfig)
1878        corrfig=figure;
1879        set(corrfig,'tag','corrfig')
1880        set(corrfig,'name','image correlation')
1881        set(corrfig,'DeleteFcn',{@closeview_field})%
[692]1882        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
1883    else
1884        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
1885        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1886        if ~isempty(corrfig)
1887            delete(corrfig)
1888        end
1889        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1890        if ~isempty(hview_field)
1891            delete(hview_field)
1892        end
[597]1893    end
[774]1894else
1895    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
1896    if ~isempty(hview_field)
1897        delete(hview_field)
1898    end     
[597]1899end
1900
[774]1901% --------------------------------------------------------------------
1902% --- Executes on button press in TestPatch1.
1903% --------------------------------------------------------------------
1904function TestPatch1_Callback(hObject, eventdata, handles)
[597]1905
[855]1906if get(handles.TestPatch1,'Value')% if TestPatch1 is activated
[860]1907     set(handles.TestPatch1,'BackgroundColor',[1 1 0])%paint TestPatch1 button in yellow to indicate activation
1908     set(handles.Civ1,'BackgroundColor',[1 1 0])% indicate civ1 calculation is performed
[855]1909     hseries=findobj(allchild(0),'Tag','series');
1910     Param=read_GUI(hseries);
1911     Param.Action.RUN=1;
1912     Param.ActionInput=read_GUI(handles.civ_input);
[862]1913     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
1914         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
1915     end
1916     if isfield(Param.ActionInput,'Fix2')
1917         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
1918     end
1919     if isfield(Param.ActionInput,'Patch2')
1920         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
1921     end
[860]1922     if isfield(Param,'OutputSubDir')
[876]1923         Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
[860]1924     end
1925     ParamPatch1=Param.ActionInput.Patch1; %store the patch1 parameters
1926     Param.ActionInput=rmfield(Param.ActionInput,'Patch1');% does not execute Patch
[876]1927     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
1928     Param.IndexRange.last_i=Param.IndexRange.first_i;
1929     if strcmp(get(handles.ref_j,'Visible'),'on')
1930         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
1931         Param.IndexRange.last_j=Param.IndexRange.first_j;
1932     else
1933         Param.IndexRange.first_j=1;
1934         Param.IndexRange.last_j=1;
1935     end
[855]1936     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
[860]1937     bckcolor=get(handles.civ_input,'Color');
1938     set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calculation is finished
[855]1939     
1940     %% prepare Param for iterative Patch processing without input file reading
1941     Param.Civ1_X=Data.Civ1_X;
1942     Param.Civ1_Y=Data.Civ1_Y;
1943     Param.Civ1_U=Data.Civ1_U;
1944     Param.Civ1_V=Data.Civ1_V;
1945     Param.Civ1_FF=Data.Civ1_FF;
1946     Param=rmfield(Param,'InputTable');%desactivate input file reading
1947    if isfield(Param.ActionInput,'Civ1')
1948        Param.ActionInput=rmfield(Param.ActionInput,'Civ1');%desactivate civ1: remove civ1 input param if relevant
[774]1949    end
[855]1950    if isfield(Param.ActionInput,'Fix1')
1951        Param.ActionInput=rmfield(Param.ActionInput,'Fix1');%desactivate fix1:remove fix1 input param if relevant
1952    end
[860]1953    SmoothingParam=(ParamPatch1.FieldSmooth/10)*2.^(1:7);%scan the smoothing param from 1/10 to 12.8 current value
[774]1954    NbGood=numel(find(Data.Civ1_FF==0));
[860]1955    NbExclude=zeros(1,7);% initialize the set of smoothing parameters
1956    DiffVel=zeros(1,7);% initialize the rms difference between patch and civ
1957    Param.ActionInput.Patch1=ParamPatch1;% retrieve Patch1 parameters
[774]1958    for irho=1:7
[855]1959        Param.ActionInput.Patch1.FieldSmooth=SmoothingParam(irho);
1960        [Data,errormsg]= civ_series(Param);%apply the processing fct
[774]1961        if ~isempty(errormsg)
1962            msgbox_uvmat('ERROR',errormsg)
1963            return
1964        end
1965        ind_good=find(Data.Civ1_FF==0);
1966        Civ1_U_Diff=Data.Civ1_U(ind_good)-Data.Civ1_U_smooth(ind_good);
1967        Civ1_V_Diff=Data.Civ1_V(ind_good)-Data.Civ1_V_smooth(ind_good);
1968        DiffVel(irho)=sqrt(mean(Civ1_U_Diff.*Civ1_U_Diff+Civ1_V_Diff.*Civ1_V_Diff));
1969        NbExclude(irho)=(NbGood-numel(ind_good))/NbGood;
1970    end
[860]1971    figure(1)
[873]1972    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r',SmoothingParam,0.2*ones(size(SmoothingParam)),'m')
[774]1973    grid on
[873]1974    legend('rms velocity diff. Patch1-Civ1 (pixels)','proportion of excluded vectors (between 0 to 1)','recommended diff Patch1-Civ1')
[855]1975    xlabel('smoothing parameter')
1976    ylabel('smoothing effect')
[860]1977    set(handles.TestPatch1,'BackgroundColor',[0 1 0])
[597]1978else
[774]1979    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1980    if ~isempty(corrfig)
1981        delete(corrfig)
1982    end
1983    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1984    if ~isempty(hview_field)
1985        delete(hview_field)
1986    end
[597]1987end
1988
[851]1989%------------------------------------------------------------------------
[774]1990% --- Executes on button press in TestCiv2.
[851]1991%------------------------------------------------------------------------
[774]1992function TestCiv2_Callback(hObject, eventdata, handles)
[851]1993drawnow
1994if get(handles.TestCiv2,'Value')
1995    set(handles.TestCiv2,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch
[873]1996    set(handles.CheckFix2,'value',0)% desactivate next step
1997    set(handles.CheckPatch2,'value',0)% desactivate next step
1998    update_CivOptions(handles,0)
[856]1999      hseries=findobj(allchild(0),'Tag','series');
2000     Param=read_GUI(hseries);
2001     Param.Action.RUN=1;
2002     Param.ActionInput=read_GUI(handles.civ_input);
[859]2003     if isfield(Param,'OutputSubDir')
[856]2004     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
[859]2005     end
2006     Param.ActionInput.Civ2.CorrSmooth=0;% launch Civ2 with no data point (to get the image names for A and B)
[858]2007     set(handles.Civ1,'BackgroundColor',[1 1 0])
[859]2008     set(handles.Fix1,'BackgroundColor',[1 1 0])
2009     set(handles.Patch1,'BackgroundColor',[1 1 0])
[876]2010     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
2011     Param.IndexRange.last_i=Param.IndexRange.first_i;
2012     if strcmp(get(handles.ref_j,'Visible'),'on')
2013         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
2014         Param.IndexRange.last_j=Param.IndexRange.first_j;
2015     else
2016         Param.IndexRange.first_j=1;
2017         Param.IndexRange.last_j=1;
2018     end
[856]2019     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
2020     
2021     %% create image data ImageData for display
2022     ImageData.ListVarName={'ny','nx','A'};
2023     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
2024     ImageData.A=imread(Data.Civ2_ImageA); % read the first image
2025     if ndims(ImageData.A)==3 %case of color image
2026         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
2027     end
2028     ImageData.ny=[size(ImageData.A,1) 1];
2029     ImageData.nx=[1 size(ImageData.A,2)];
2030     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
2031
2032     %% create the figure view_field for image visualization
2033    hview_field=view_field(ImageData); %view the image in the GUI view_field
[851]2034    set(0,'CurrentFigure',hview_field)
[858]2035    % plot the boundaries of the subdomains used for patch
[856]2036    for isub=1:size(Data.Civ1_SubRange,3);
2037        pos_x=Data.Civ1_SubRange(1,1,isub);
2038        pos_y=Data.Civ1_SubRange(2,1,isub);
2039        width=Data.Civ1_SubRange(1,2,isub)-Data.Civ1_SubRange(1,1,isub);
2040        height=Data.Civ1_SubRange(2,2,isub)-Data.Civ1_SubRange(2,1,isub);
2041        rectangle('Position',[pos_x pos_y width height],'EdgeColor',[0 0 1])
2042    end
[858]2043    hhview_field=guihandles(hview_field);%
[851]2044    set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
[859]2045    ViewData=get(hview_field,'UserData'); % get the currently plotted field (the image A)
[858]2046    % store info in the UserData of view-field
[851]2047    ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
[856]2048    ViewData.PlotAxes.B=imread(Data.Civ2_ImageB);%store the second image in the UserData of the GUI view_field
2049    ViewData.PlotAxes.X=Data.Civ2_X';
2050    ViewData.PlotAxes.Y=Data.Civ2_Y';
[862]2051    ViewData.PlotAxes.ShiftX=Data.Civ2_U';% shift at each point (from patch1) estimated by the preliminary run of civ2
[856]2052    ViewData.PlotAxes.ShiftY=Data.Civ2_V';
2053    ViewData.PlotAxes.Civ1_SubRange=Data.Civ1_SubRange;
2054    ViewData.PlotAxes.Civ1_NbCentres=Data.Civ1_NbCentres;
2055    ViewData.PlotAxes.Civ1_Coord_tps=Data.Civ1_Coord_tps;
2056    ViewData.PlotAxes.Civ1_U_tps=Data.Civ1_U_tps;
2057    ViewData.PlotAxes.Civ1_V_tps=Data.Civ1_V_tps;
2058    ViewData.PlotAxes.Civ1_Dt=Data.Civ1_Dt;
[858]2059    ViewData.PlotAxes.Civ2_Dt=Data.Civ2_Dt;
[856]2060    set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
[859]2061    bckcolor=get(handles.civ_input,'Color');
2062    set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calmculation is finished
2063    set(handles.Fix1,'BackgroundColor',bckcolor)
2064    set(handles.Patch1,'BackgroundColor',bckcolor)
2065    drawnow
[856]2066   
2067    %% look for a current figure for image correlation display
2068    corrfig=findobj(allchild(0),'tag','corrfig');
[851]2069    if isempty(corrfig)
2070        corrfig=figure;
2071        set(corrfig,'tag','corrfig')
2072        set(corrfig,'name','image correlation')
2073        set(corrfig,'DeleteFcn',{@closeview_field})%
2074        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
2075    else
2076        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
2077        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
2078        if ~isempty(corrfig)
2079            delete(corrfig)
2080        end
2081        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
2082        if ~isempty(hview_field)
2083            delete(hview_field)
2084        end
[856]2085    end   
[851]2086else
2087    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
2088    if ~isempty(hview_field)
2089        delete(hview_field)
2090    end     
2091end
[597]2092
2093
[860]2094% --- Executes on button press in TestPatch2.
2095function TestPatch2_Callback(hObject, eventdata, handles)
2096if get(handles.TestPatch2,'Value')% if TestPatch2 is activated
2097     set(handles.TestPatch2,'BackgroundColor',[1 1 0])%paint TestPatch2 button in yellow to indicate activation
2098     set(handles.Civ1,'BackgroundColor',[1 1 0])% indicate civ1 calculation is activated
2099     set(handles.Fix1,'BackgroundColor',[1 1 0])% indicate fix1 calculation is activated
2100     set(handles.Patch1,'BackgroundColor',[1 1 0])% indicate Patch1 calculation is activated
2101     set(handles.Civ2,'BackgroundColor',[1 1 0])% indicate civ2 calculation is activated
2102     set(handles.Fix2,'BackgroundColor',[1 1 0])% indicate fix2 calculation is activated
2103     hseries=findobj(allchild(0),'Tag','series');
2104     Param=read_GUI(hseries);
2105     Param.Action.RUN=1;
2106     Param.ActionInput=read_GUI(handles.civ_input);
2107     if isfield(Param,'OutputSubDir')
2108     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
2109     end
2110     ParamPatch2=Param.ActionInput.Patch2; %store the patch1 parameters
2111     Param.ActionInput=rmfield(Param.ActionInput,'Patch2');% does not execute Patch
[876]2112     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
2113     Param.IndexRange.last_i=Param.IndexRange.first_i;
2114     if strcmp(get(handles.ref_j,'Visible'),'on')
2115         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
2116         Param.IndexRange.last_j=Param.IndexRange.first_j;
2117     else
2118         Param.IndexRange.first_j=1;
2119         Param.IndexRange.last_j=1;
2120     end
[860]2121     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
2122     bckcolor=get(handles.civ_input,'Color');
2123     set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calculation is finished
2124     set(handles.Fix1,'BackgroundColor',bckcolor)% indicate fix1 calculation is finished
2125     set(handles.Patch1,'BackgroundColor',bckcolor)% indicate Patch1 calculation is finished
2126     set(handles.Civ2,'BackgroundColor',bckcolor)% indicate civ2 calculation is finished
2127     set(handles.Fix2,'BackgroundColor',bckcolor)% indicate fix2 calculation is finished
2128     
2129     %% prepare Param for iterative Patch processing without input file reading
2130     Param.Civ2_X=Data.Civ2_X;
2131     Param.Civ2_Y=Data.Civ2_Y;
2132     Param.Civ2_U=Data.Civ2_U;
2133     Param.Civ2_V=Data.Civ2_V;
2134     Param.Civ2_FF=Data.Civ2_FF;
2135     Param=rmfield(Param,'InputTable');%desactivate input file reading
2136    if isfield(Param.ActionInput,'Civ1')
2137        Param.ActionInput=rmfield(Param.ActionInput,'Civ1');%desactivate civ1: remove civ1 input param if relevant
2138    end
2139    if isfield(Param.ActionInput,'Fix1')
2140        Param.ActionInput=rmfield(Param.ActionInput,'Fix1');%desactivate fix1:remove fix1 input param if relevant
2141    end
2142    if isfield(Param.ActionInput,'Patch1')
2143        Param.ActionInput=rmfield(Param.ActionInput,'Patch1');%desactivate fix1:remove fix1 input param if relevant
2144    end
2145    if isfield(Param.ActionInput,'Civ2')
2146        Param.ActionInput=rmfield(Param.ActionInput,'Civ2');%desactivate civ2: remove civ2 input param if relevant
2147    end
2148    if isfield(Param.ActionInput,'Fix2')
2149        Param.ActionInput=rmfield(Param.ActionInput,'Fix2');%desactivate fix1:remove fix1 input param if relevant
2150    end
2151    SmoothingParam=(ParamPatch2.FieldSmooth/10)*2.^(1:7);%scan the smoothing param from 1/10 to 12.8 current value
2152    NbGood=numel(find(Data.Civ2_FF==0));
2153    NbExclude=zeros(1,7);% initialize the set of smoothing parameters
2154    DiffVel=zeros(1,7);% initialize the rms difference between patch and civ
2155    Param.ActionInput.Patch2=ParamPatch2;% retrieve Patch2 parameters
2156    for irho=1:7
2157        Param.ActionInput.Patch2.FieldSmooth=SmoothingParam(irho);
2158        [Data,errormsg]= civ_series(Param);%apply the processing fct
2159        if ~isempty(errormsg)
2160            msgbox_uvmat('ERROR',errormsg)
2161            return
2162        end
2163        ind_good=find(Data.Civ2_FF==0);
2164        Civ2_U_Diff=Data.Civ2_U(ind_good)-Data.Civ2_U_smooth(ind_good);
2165        Civ2_V_Diff=Data.Civ2_V(ind_good)-Data.Civ2_V_smooth(ind_good);
2166        DiffVel(irho)=sqrt(mean(Civ2_U_Diff.*Civ2_U_Diff+Civ2_V_Diff.*Civ2_V_Diff));
2167        NbExclude(irho)=(NbGood-numel(ind_good))/NbGood;
2168    end
2169    figure(1)
[873]2170    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r',SmoothingParam,0.1*ones(size(SmoothingParam)),'m')
[860]2171    grid on
[873]2172    legend('rms velocity diff. Patch2-Civ2 (pixels)','proportion of excluded vectors (between 0 to 1)','recommended value diff. Patch2-Civ2')
[860]2173    xlabel('smoothing parameter')
2174    ylabel('smoothing effect')
2175    set(handles.TestPatch2,'BackgroundColor',[0 1 0])
2176else
2177    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
2178    if ~isempty(corrfig)
2179        delete(corrfig)
2180    end
2181    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
2182    if ~isempty(hview_field)
2183        delete(hview_field)
2184    end
2185end
2186   
2187
[597]2188%'nomtype2pair': creates nomencalture for index pairs knowing the image nomenclature
2189%---------------------------------------------------------------------
2190function NomTypeNc=nomtype2pair(NomTypeIma,mode)
2191%---------------------------------------------------------------------           
2192% OUTPUT:
2193% NomTypeNc
2194%---------------------------------------------------------------------
2195% INPUT:
2196% 'NomTypeIma': string defining the kind of nomenclature used for images
2197
2198NomTypeNc=NomTypeIma;%default
2199switch mode
2200    case 'pair j1-j2'     
2201    if ~isempty(regexp(NomTypeIma,'a$'))
2202        NomTypeNc=[NomTypeIma 'b'];
2203    elseif ~isempty(regexp(NomTypeIma,'A$'))
2204        NomTypeNc=[NomTypeIma 'B'];
2205    else
2206        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2207        if ~isempty(r)
2208            NomTypeNc='_1_1-2';
2209        end
2210    end
2211    case 'series(Dj)' 
2212%         r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2213%         if ~isempty(r)
2214            NomTypeNc='_1_1-2';
2215%         end
2216   case 'series(Di)'
2217        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2218        if ~isempty(r)
2219            NomTypeNc='_1-2_1';
2220        else
2221            NomTypeNc='_1-2';
2222        end
2223end
2224
2225
[645]2226%------------------------------------------------------------------------
2227% --- determine the list of index pairs of processing file
[692]2228function [ind1,ind2,mode]=...
[645]2229    find_pair_indices(str_civ,i_series,j_series,MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j)
2230%------------------------------------------------------------------------
2231ind1='';
2232ind2='';
2233r=regexp(str_civ,'^\D(?<ind>[i|j])=( -| )(?<num1>\d+)\|(?<num2>\d+)','names');
2234if ~isempty(r)
2235    mode=['D' r.ind];
2236    ind1=stra2num(r.num1);
2237    ind2=stra2num(r.num2);
2238else
2239    mode='burst';
2240    r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names');
2241    if ~isempty(r)
2242        NomTypeNc='_1ab';
2243    else
2244        r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names');
2245        if ~isempty(r)
2246            NomTypeNc='_1AB';
2247        else
2248            r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names');
2249            if ~isempty(r)
2250                NomTypeNc='_1_1-2';
2251            end           
2252        end
2253    end
2254    if isempty(r)
2255        display('wrong pair mode input option')
2256    else
2257    ind1=stra2num(r.num1);
2258    ind2=stra2num(r.num2);
2259    end
2260end
[774]2261
2262%------------------------------------------------------------------------
2263% --- fill civ_input with the parameters retrieved from an input Civ file
2264%------------------------------------------------------------------------
2265function fill_civ_input(Data,handles)
2266
2267%% Civ param
2268% lists of parameters to enter
2269ListParamNum={'CorrBoxSize','SearchBoxSize','SearchBoxShift','Dx','Dy','Dz','MinIma','MaxIma'};% list of numerical values (to transform in strings)
2270ListParamValue={'CorrSmooth','CheckGrid','CheckMask','CheckThreshold'};
2271ListParamString={'Grid','Mask'};
2272% CorrSmooth ??
2273option={'Civ1','Civ2'};
2274for ichoice=1:2
2275    if isfield(Data,[option{ichoice} '_CorrBoxSize'])
2276        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2277    end
2278end
2279
2280%% Fix param
2281option={'Fix1','Fix2'};
2282for ichoice=1:2
2283    if isfield(Data,[option{ichoice} '_CheckFmin2'])
2284        ListParamNum={'MinVel','MaxVel','MinCorr'};% list of numerical values (to transform in strings)
2285        ListParamValue={'CheckFmin2','CheckF3','CheckF4'};
2286        ListParamString={'ref_fix_1'};
2287        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2288    end
2289end
2290
2291%% Patch param
2292option={'Patch1','Patch2'};
2293for ichoice=1:2
2294    if isfield(Data,[option{ichoice} '_FieldSmooth'])
2295        ListParamNum={'FieldSmooth','MaxDiff','SubDomainSize'};% list of numerical values (to transform in strings)
2296        ListParamValue={};
2297        ListParamString={};
2298        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2299    end
2300end
2301%------------------------------------------------------------------------
2302% --- fill a panel of civ_input with the parameters retrieved from an input Civ file
2303%------------------------------------------------------------------------
2304function fill_panel(Data,handles,panel,ListParamNum,ListParamValue,ListParamString)
2305children=get(handles.(panel),'children');%handles of the children of the input GUI with handle 'GUI_handle'
2306handles_panel=[];
2307for ichild=1:numel(children)
2308    if ~isempty(get(children(ichild),'tag'))
2309        handles_panel.(get(children(ichild),'tag'))=children(ichild);
2310    end
2311end
2312for ilist=1:numel(ListParamNum)
2313    ParamName=ListParamNum{ilist};
2314    CivParamName=[panel '_' ParamName];
2315    if isfield(Data,CivParamName)
2316        for icoord=1:numel(Data.(CivParamName))
2317            if numel(Data.(CivParamName))>1
2318                Tag=['num_' ParamName '_' num2str(icoord)];
2319            else
2320                Tag=['num_' ParamName];
2321            end
2322            if isfield(handles_panel,Tag)
2323                set(handles_panel.(Tag),'String',num2str(Data.(CivParamName)(icoord)))
2324                set(handles_panel.(Tag),'Visible','on')
2325            end
2326        end
2327    end
2328end
2329for ilist=1:numel(ListParamValue)
2330    ParamName=ListParamValue{ilist};
2331    CivParamName=[panel '_' ParamName];
2332    if strcmp(ParamName,'CorrSmooth')
2333        ParamName=['num_' ParamName];
2334    end
2335    if isfield(Data,CivParamName)
2336        if isfield(handles_panel,ParamName)
2337            set(handles_panel.(ParamName),'Value',Data.(CivParamName))
2338        end
2339    end
2340end
2341for ilist=1:numel(ListParamString)
2342    ParamName=ListParamString{ilist};
2343    CivParamName=[panel '_' ParamName];
2344    if isfield(Data,CivParamName)
2345        if isfield(handles_panel,ParamName)
2346            set(handles_panel.(ParamName),'String',Data.(CivParamName))
2347        end
2348    end
2349end
2350
2351%------------------------------------------------------------------------
[856]2352% --- Executes on button press in ImportParam.
[851]2353%------------------------------------------------------------------------
[856]2354function ImportParam_Callback(hObject, eventdata, handles)
[824]2355hseries=findobj(allchild(0),'Tag','series');
2356hhseries=guidata(hseries);
2357InputTable=get(hhseries.InputTable,'Data');% read the input file(s) table in the GUI series
2358oldfile=InputTable{1,1};
2359if isempty(oldfile)
2360    % use a file name stored in prefdir
2361    dir_perso=prefdir;
2362    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2363    if exist(profil_perso,'file')
2364        h=load (profil_perso);
2365        if isfield(h,'RootPath') && ischar(h.RootPath)
2366            oldfile=h.RootPath;
2367        end
2368    end
2369end
2370filexml=uigetfile_uvmat('pick a xml parameter file for civ',oldfile,'.xml');% get the xml file containing processing parameters
2371%proceed only if a file has been introduced by the browser
2372if ~isempty(filexml)
2373    Param=xml2struct(filexml);% read the input xml file as a Matlab structure
2374
2375   % Param.Action.RUN=0; %desactivate the input RUN=1
2376    if ~isfield(Param,'InputTable')||~isfield(Param,'IndexRange')
2377        msgbox_uvmat('ERROR','invalid config file: open a file in a folder ''/0_XML''')
2378        return
2379    end
2380    check_input=0;
2381    if isfield(Param,'ActionInput')
2382        if isfield(Param.ActionInput,'Program')&& strcmp(Param.ActionInput.Program,'civ_series')
2383            fill_GUI(Param.ActionInput,handles.civ_input)% fill the elements of the GUI series with the input parameters
[856]2384            set(handles.ConfigSource,'String',filexml)
[824]2385            check_input=1;
[856]2386            update_CivOptions(handles,0)             
[824]2387        end
2388    end
2389    if ~check_input
2390        msgbox_uvmat('ERROR','invalid config file (not for civ_series')
2391        return
2392    end
2393end
[849]2394
[855]2395% --- Executes on selection change in CheckCiv3.
2396function CheckCiv3_Callback(hObject, eventdata, handles)
[860]2397
2398
[851]2399%------------------------------------------------------------------------
2400% --- Executes on key press with selection of a uicontrol
2401%------------------------------------------------------------------------
2402function keyboard_callback(hObject,eventdata,handles)
2403   
2404ListExclude={'CheckCiv1','CheckFix1','CheckPatch1','CheckCiv2','CheckFix2','CheckPatch2','ref_i'};
2405if isempty(find(strcmp(get(gco,'Tag'),ListExclude),1))% if the selected uicontrol is not in the Exclude list
2406    set(handles.ConfigSource,'String','NEW')% indicate that the configuration is new
[856]2407    set(handles.OK,'BackgroundColor',[1 0 1])%
2408    drawnow
[851]2409end
[1010]2410
2411
2412
2413function num_NbSlice_Callback(hObject, eventdata, handles)
2414% hObject    handle to num_NbSlice (see GCBO)
2415% eventdata  reserved - to be defined in a future version of MATLAB
2416% handles    structure with handles and user data (see GUIDATA)
2417
2418% Hints: get(hObject,'String') returns contents of num_NbSlice as text
2419%        str2double(get(hObject,'String')) returns contents of num_NbSlice as a double
2420
2421
2422% --- Executes during object creation, after setting all properties.
2423function num_NbSlice_CreateFcn(hObject, eventdata, handles)
2424% hObject    handle to num_NbSlice (see GCBO)
2425% eventdata  reserved - to be defined in a future version of MATLAB
2426% handles    empty - handles not created until after all CreateFcns called
2427
2428% Hint: edit controls usually have a white background on Windows.
2429%       See ISPC and COMPUTER.
2430if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2431    set(hObject,'BackgroundColor','white');
2432end
Note: See TracBrowser for help on using the repository browser.