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

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