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

Last change on this file since 874 was 874, checked in by sommeria, 9 years ago

merge_proj corrected + various bugs

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