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

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

bugs_corrected

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