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

Last change on this file since 1137 was 1137, checked in by sommeria, 6 months ago

tps improved by a cosine window in each subdomain. Default size of subdomains reduced for faster computation in the civ interface

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