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

Last change on this file since 859 was 859, checked in by sommeria, 6 years ago

bug_repair

File size: 91.1 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% --- Executes on button press in CheckDeformation.
1152function CheckDeformation_Callback(hObject, eventdata, handles)
1153set(handles.configSource,'String','NEW')
1154set(handles.OK,'BackgroundColor',[1 0 1])
1155
1156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157% Callbacks in the uipanel Fix1
1158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1159%------------------------------------------------------------------------
1160% % --- Executes on button press in CheckMask.
1161% function get_mask_fix1_Callback(hObject, eventdata, handles)
1162% %------------------------------------------------------------------------
1163% maskval=get(handles.CheckMask,'Value');
1164% if isequal(maskval,0)
1165%     set(handles.Mask,'String','')
1166% else
1167%     mask_displ='no mask'; %default
1168%     filebase=get(handles.RootPath,'String');
1169%     [nbslice, flag_mask]=get_mask(filebase,handles);
1170%     if isequal(flag_mask,1)
1171%         mask_displ=[num2str(nbslice) 'mask'];
1172%     elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1173%         filebase_a=get(handles.RootFile_1,'String');
1174%         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1175%         if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1176%             mask_displ='no mask';
1177%         end
1178%     end
1179%     if isequal(mask_displ,'no mask')
1180%         [FileName, PathName, filterindex] = uigetfile( ...
1181%             {'*.png', ' (*.png)';
1182%             '*.png',  '.png files '; ...
1183%             '*.*', 'All Files (*.*)'}, ...
1184%             'Pick a mask file *.png',filebase);
1185%         mask_displ=fullfile(PathName,FileName);
1186%         if ~exist(mask_displ,'file')
1187%             mask_displ='no mask';
1188%         end
1189%     end
1190%     if isequal(mask_displ,'no mask')
1191%         set(handles.CheckMask,'Value',0)
1192%         set(handles.CheckMask,'Value',0)
1193%         set(handles.CheckMask,'Value',0)
1194%     else
1195%         %set(handles.CheckMask,'Value',1)
1196%         set(handles.CheckMask,'Value',1)
1197%     end
1198%     set(handles.Mask,'String',mask_displ)
1199%     set(handles.Mask,'String',mask_displ)
1200%     set(handles.Mask,'String',mask_displ)
1201% end
1202
1203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1204% Callbacks in the uipanel Civ2
1205%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1206%------------------------------------------------------------------------
1207% --- Executes on button press in CheckMask: select box for mask option
1208function get_mask_civ2_Callback(hObject, eventdata, handles)
1209%------------------------------------------------------------------------
1210maskval=get(handles.CheckMask,'Value');
1211if isequal(maskval,0)
1212    set(handles.Mask,'String','')
1213else
1214    mask_displ='no mask'; %default
1215    filebase=get(handles.RootPath,'String');
1216    [nbslice, flag_mask]=get_mask(filebase,handles);
1217    if isequal(flag_mask,1)
1218        mask_displ=[num2str(nbslice) 'mask'];
1219    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1220        filebase_a=get(handles.RootFile_1,'String');
1221        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1222        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1223            mask_displ='no mask';
1224        end
1225    end
1226    if isequal(mask_displ,'no mask')
1227        [FileName, PathName, filterindex] = uigetfile( ...
1228            {'*.png', ' (*.png)';
1229            '*.png',  '.png files '; ...
1230            '*.*', 'All Files (*.*)'}, ...
1231            'Pick a mask file *.png',filebase);
1232        mask_displ=fullfile(PathName,FileName);
1233        if ~exist(mask_displ,'file')
1234            mask_displ='no mask';
1235        end
1236    end
1237    if isequal(mask_displ,'no mask')
1238        set(handles.CheckMask,'Value',0)
1239        set(handles.CheckMask,'Value',0)
1240    else
1241        set(handles.CheckMask,'Value',1)
1242    end
1243    set(handles.Mask,'String',mask_displ)
1244end
1245
1246% %------------------------------------------------------------------------
1247% % --- Executes on button press in CheckMask.
1248% function get_mask_fix2_Callback(hObject, eventdata, handles)
1249% %------------------------------------------------------------------------
1250% maskval=get(handles.CheckMask,'Value');
1251% if isequal(maskval,0)
1252%     set(handles.Mask,'String','')
1253% else
1254%     mask_displ='no mask'; %default
1255%     filebase=get(handles.RootPath,'String');
1256%     [nbslice, flag_mask]=get_mask(filebase,handles);
1257%     if isequal(flag_mask,1)
1258%         mask_displ=[num2str(nbslice) 'mask'];
1259%     elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1260%         filebase_a=get(handles.RootFile_1,'String');
1261%         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1262%         if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1263%             mask_displ='no mask';
1264%         end
1265%     end
1266%     if isequal(mask_displ,'no mask')
1267%         [FileName, PathName, filterindex] = uigetfile( ...
1268%             {'*.png', ' (*.png)';
1269%             '*.png',  '.png files '; ...
1270%             '*.*', 'All Files (*.*)'}, ...
1271%             'Pick a mask file *.png',filebase);
1272%         mask_displ=fullfile(PathName,FileName);
1273%         if ~exist(mask_displ,'file')
1274%             mask_displ='no mask';
1275%         end
1276%     end
1277%     if isequal(mask_displ,'no mask')
1278%         set(handles.CheckMask,'Value',0)
1279%     end
1280%     set(handles.Mask,'String',mask_displ)
1281% end
1282
1283%------------------------------------------------------------------------
1284% --- function called to look for mask files
1285function [nbslice, flag_mask]=get_mask(filebase,handles)
1286%------------------------------------------------------------------------
1287%detect mask files, images with appropriate file base
1288%[filebase '_' xx 'mask'], xx=nbslice
1289%flag_mask=1 indicates detection
1290
1291flag_mask=0;%default
1292nbslice=1;
1293
1294% subdir=get(handles.Civ1_ImageB,'String');
1295[Path,Name]=fileparts(filebase);
1296if ~isdir(Path)
1297    msgbox_uvmat('ERROR','no path for input files')
1298    return
1299end
1300% currentdir=pwd;
1301% cd(Path);%move in the dir of the root name filebase
1302maskfiles=dir(fullfile(Path,[Name '_*mask_*.png']));%look for mask files
1303% cd(currentdir);%come back to the current working directory
1304if ~isempty(maskfiles)
1305    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
1306    % else
1307    flag_mask=1;
1308    maskname=maskfiles(1).name;% take the first mask file in the list
1309    [Path2,Name,ext]=fileparts(maskname);
1310    Namedouble=double(Name);
1311    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1312    ind_mask=findstr('mask',Name);
1313    i=ind_mask-1;
1314    while val(i)==0 && i>0
1315        i=i-1;
1316    end
1317    nbslice=str2double(Name(i+1:ind_mask-1));
1318    if ~isnan(nbslice) && Name(i)=='_'
1319        flag_mask=1;
1320    else
1321        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
1322        return
1323        nbslice=1;
1324    end
1325end
1326
1327%------------------------------------------------------------------------
1328% --- function called to look for grid files
1329function [nbslice, flag_grid]=get_grid(filebase,handles)
1330%------------------------------------------------------------------------
1331flag_grid=0;%default
1332nbslice=1;
1333[Path,Name]=fileparts(filebase);
1334currentdir=pwd;
1335cd(Path);%move in the dir of the root name filebase
1336gridfiles=dir([Name '_*grid_*.grid']);%look for grid files
1337cd(currentdir);%come back to the current working directory
1338if ~isempty(gridfiles)
1339    flag_grid=1;
1340    gridname=gridfiles(1).name;% take the first grid file in the list
1341    [Path2,Name,ext]=fileparts(gridname);
1342    Namedouble=double(Name);
1343    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1344    ind_grid=findstr('grid',Name);
1345    i=ind_grid-1;
1346    while val(i)==0 && i>0
1347        i=i-1;
1348    end
1349    nbslice=str2double(Name(i+1:ind_grid-1));
1350    if ~isnan(nbslice) && Name(i)=='_'
1351        flag_grid=1;
1352    else
1353        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
1354        return
1355        nbslice=1;
1356    end
1357end
1358
1359%------------------------------------------------------------------------
1360% --- transform numbers to letters
1361function str=num2stra(num,nom_type)
1362%------------------------------------------------------------------------
1363if isempty(nom_type)
1364    str='';
1365elseif strcmp(nom_type(end),'a')
1366    str=char(96+num);
1367elseif strcmp(nom_type(end),'A')
1368    str=char(96+num);
1369elseif isempty(nom_type(2:end))%a single index
1370    str='';
1371else
1372    str=num2str(num);
1373end
1374
1375% %------------------------------------------------------------------------
1376% % --- Executes on button press in ListSubdirCiv1.
1377% function ListSubdirCiv1_Callback(hObject, eventdata, handles)
1378% %------------------------------------------------------------------------
1379% list_subdir_civ1=get(handles.ListSubdirCiv1,'String');
1380% val=get(handles.ListSubdirCiv1,'Value');
1381% SubDir=list_subdir_civ1{val};
1382% if strcmp(SubDir,'new...')
1383%     if get(handles.CheckCiv1,'Value')
1384%         SubDir='CIV_INPUT'; %default subdirectory
1385%     else
1386%         msgbox_uvmat('ERROR','select CheckCiv1 to perform a new civ_input operation')
1387%         return
1388%     end   
1389% end
1390% set(handles.Civ1_ImageB,'String',SubDir);
1391% errormsg=find_netcpair_civ(handles,1);
1392% if ~isempty(errormsg)
1393%     msgbox_uvmat('ERROR',errormsg)
1394% end
1395%     
1396%------------------------------------------------------------------------
1397% % --- Executes on button press in ListSubdirCiv2.
1398% function ListSubdirCiv2_Callback(hObject, eventdata, handles)
1399% %------------------------------------------------------------------------
1400% list_subdir_civ2=get(handles.ListSubdirCiv2,'String');
1401% val=get(handles.ListSubdirCiv2,'Value');
1402% SubDir=list_subdir_civ2{val};
1403% if strcmp(SubDir,'new...')
1404%     if get(handles.CheckCiv2,'Value')
1405%         SubDir='CIV_INPUT'; %default subdirectory
1406%     else
1407%         msgbox_uvmat('ERROR','select CheckCiv2 to perform a new civ_input operation')
1408%         return
1409%     end
1410% end
1411% set(handles.Civ2_ImageA,'String',SubDir);
1412
1413%------------------------------------------------------------------------
1414% --- Executes on button press in CheckGrid.
1415function CheckGrid_Callback(hObject, eventdata, handles)
1416%------------------------------------------------------------------------
1417value=get(hObject,'Value');
1418hparent=get(hObject,'parent');%handles of the parent panel
1419hchildren=get(hparent,'children');
1420handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel
1421handle_dx=findobj(hchildren,'tag','num_Dx');
1422handle_dy=findobj(hchildren,'tag','num_Dy');
1423handle_title_dx=findobj(hchildren,'tag','title_Dx');
1424handle_title_dy=findobj(hchildren,'tag','title_Dy');
1425testgrid=0;
1426filegrid='';
1427if value
1428        hseries=findobj(allchild(0),'Tag','series');
1429    hhseries=guidata(hseries);
1430    InputTable=get(hhseries.InputTable,'Data');
1431     ind_A=1;% line index of the (first) image series
1432    if strcmp(InputTable{1,5},'.nc');
1433        ind_A=2;
1434    end
1435    filebase=InputTable{ind_A,1};
1436    [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name
1437    if isequal(flag_grid,1)
1438        filegrid=[num2str(nbslice) 'grid'];
1439        testgrid=1;
1440    else % browse for a grid
1441        filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData
1442        if exist(filegrid,'file')
1443            filebase=filegrid;
1444        end
1445       filegrid = uigetfile_uvmat('pick a grid file .grid:',filebase,'.grid');
1446        set(hObject,'UserData',filegrid);%store for future use
1447        if ~isempty(filegrid)
1448            testgrid=1;
1449        end
1450        set(hObject,'UserData',filegrid);%store for future use
1451    end
1452end
1453if testgrid
1454    set(handle_dx,'Visible','off');
1455    set(handle_dy,'Visible','off');
1456    set(handle_title_dy,'Visible','off');
1457    set(handle_title_dx,'Visible','off');
1458    set(handle_txtbox,'Visible','on')
1459    set(handle_txtbox,'String',filegrid)
1460else
1461    set(hObject,'Value',0);
1462    set(handle_dx,'Visible','on');
1463    set(handle_dy,'Visible','on');
1464    set(handle_title_dy,'Visible','on');
1465    set(handle_title_dx,'Visible','on');
1466    set(handle_txtbox,'Visible','off')
1467end
1468
1469%% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
1470PanelName=get(hparent,'tag');
1471if strcmp(PanelName,'Civ1')
1472    hchildren=get(handles.Civ2,'children');
1473    handle_checkbox=findobj(hchildren,'tag','CheckGrid');
1474    handle_txtbox=findobj(hchildren,'tag','Grid');
1475    handle_dx=findobj(hchildren,'tag','num_Dx');
1476    handle_dy=findobj(hchildren,'tag','num_Dy');
1477    handle_title_dx=findobj(hchildren,'tag','title_Dx');
1478    handle_title_dy=findobj(hchildren,'tag','title_Dy');
1479    set(handle_checkbox,'UserData',filegrid);%store for future use
1480    if testgrid
1481        set(handle_checkbox,'Value',1);
1482        set(handle_dx,'Visible','off');
1483        set(handle_dy,'Visible','off');
1484        set(handle_title_dx,'Visible','off');
1485        set(handle_title_dy,'Visible','off');
1486        set(handle_txtbox,'Visible','on')
1487        set(handle_txtbox,'String',filegrid)
1488    end
1489end
1490set(hObject,'BackgroundColor',[1 0 1])
1491set(handles.configSource,'String','NEW')
1492set(handles.OK,'BackgroundColor',[1 0 1])
1493%------------------------------------------------------------------------
1494% --- Executes on button press in CheckMask: common to all panels (civ1, Civ2..)
1495function CheckMask_Callback(hObject, eventdata, handles)
1496%------------------------------------------------------------------------
1497value=get(hObject,'Value');
1498hparent=get(hObject,'parent');
1499parent_tag=get(hparent,'Tag');
1500hchildren=get(hparent,'children');
1501handle_txtbox=findobj(hchildren,'tag','Mask');% look for the mask name box in the same panel
1502
1503testmask=0;
1504if value
1505    hseries=findobj(allchild(0),'Tag','series');
1506    hhseries=guidata(hseries);
1507    InputTable=get(hhseries.InputTable,'Data');
1508    ind_A=1;% line index of the (first) image series
1509    if strcmp(InputTable{1,5},'.nc');
1510        ind_A=2;
1511    end
1512    [nbslice, flag_mask]=get_mask(InputTable{ind_A,1},handles);% look for a mask with appropriate name
1513    if isequal(flag_mask,1)
1514        filemask=[num2str(nbslice) 'mask'];
1515        testmask=1;
1516    else % browse for a mask
1517%         filemask=get(hObject,'UserData');%look for previous mask name stored as UserData
1518%         if exist(filemask,'file')
1519%             filebase=filemask;
1520%         end
1521        filemask= uigetfile_uvmat('pick a mask image file:',InputTable{ind_A,1},'image');
1522        set(hObject,'UserData',filemask);%store for future use
1523        if ~isempty(filemask)
1524            testmask=1;
1525        end
1526    end
1527end
1528if testmask
1529    set(handles.Mask,'Visible','on')
1530    set(handles.Mask,'String',filemask)
1531    set(handles.CheckMask,'Value',1)
1532else
1533    set(hObject,'Value',0);
1534    set(handle_txtbox,'Visible','off')
1535end
1536set(handles.configSource,'String','NEW')
1537set(handles.configSource,'BackgroundColor',[1 0 1])
1538
1539% %------------------------------------------------------------------------
1540% % --- Executes on button press in get_gridpatch1.
1541% function get_gridpatch1_Callback(hObject, eventdata, handles)
1542% %------------------------------------------------------------------------
1543% filebase=get(handles.RootPath,'String');
1544% [FileName, PathName, filterindex] = uigetfile( ...
1545%     {'*.grid', ' (*.grid)';
1546%     '*.grid',  '.grid files '; ...
1547%     '*.*', 'All Files (*.*)'}, ...
1548%     'Pick a file',filebase);
1549% filegrid=fullfile(PathName,FileName);
1550% set(handles.grid_patch1,'string',filegrid);
1551% set(hObject,'BackgroundColor',[1 0 1])
1552
1553%------------------------------------------------------------------------
1554% --- STEREO Interp
1555function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
1556%------------------------------------------------------------------------
1557namelog=[filename_nc(1:end-3) '_stinterp.log'];
1558cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
1559    ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ' -c1 ' xmlA ' -c2 ' xmlB '  -xy  x -Nfy 1024 > ' namelog ' 2>&1']; % redirect standard output to the log file
1560
1561% %------------------------------------------------------------------------
1562% %--read images and convert them to the uint16 format used for PIV
1563% function A=read_image(filename,type_ima,num,movieobject)
1564% %------------------------------------------------------------------------
1565% %num is the view number needed for an avi movie
1566% switch type_ima
1567%     case 'movie'
1568%         A=read(movieobject,num);
1569%     case 'avi'
1570%         mov=aviread(filename,num);
1571%         A=frame2im(mov(1));
1572%     case 'multimage'
1573%         A=imread(filename,num);
1574%     case 'image'
1575%         A=imread(filename);
1576% end
1577% siz=size(A);
1578% if length(siz)==3;%color images
1579%     A=sum(double(A),3);
1580%     A=uint16(A);
1581% end
1582
1583
1584%------------------------------------------------------------------------
1585% --- Executes on button press in get_ref_fix1.
1586function get_ref_fix1_Callback(hObject, eventdata, handles)
1587%------------------------------------------------------------------------
1588filebase=get(handles.RootPath,'String');
1589[FileName, PathName, filterindex] = uigetfile( ...
1590    {'*.nc', ' (*.nc)';
1591    '*.nc',  'netcdf files '; ...
1592    '*.*', 'All Files (*.*)'}, ...
1593    'Pick a file',filebase);
1594
1595fileinput=[PathName FileName];
1596sizf=size(fileinput);
1597if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1598%[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1599[Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1600ref.filebase=fullfile(Path,File);
1601% ref.num_a=stra2num(str_a);
1602% ref.num_b=stra2num(str_b);
1603% ref.num1=str2double(field_count);
1604% ref.num2=str2double(str2);
1605browse=[];%initialisation
1606if ~isequal(ref.ext,'.nc')
1607    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1608    return
1609end
1610set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
1611set(handles.ref_fix1,'UserData',ref)
1612menu_field{1}='civ1';
1613Data=nc2struct(fileinput,[]);
1614if isfield(Data,'patch') && isequal(Data.patch,1)
1615    menu_field{2}='filter1';
1616end
1617if isfield(Data,'civ2') && isequal(Data.civ2,1)
1618    menu_field{3}='civ2';
1619end
1620if isfield(Data,'patch2') && isequal(Data.patch2,1)
1621    menu_field{4}='filter2';
1622end
1623set(handles.field_ref1,'String',menu_field);
1624set(handles.field_ref1,'Value',length(menu_field));
1625set(handles.num_MinVel,'Value',2);
1626set(handles.num_MinVel,'String','1');%default threshold
1627set(handles.ref_fix1,'Enable','on')
1628
1629%------------------------------------------------------------------------
1630% --- Executes on button press in get_ref_fix2.
1631function get_ref_fix2_Callback(hObject, eventdata, handles)
1632%------------------------------------------------------------------------
1633if isequal(get(handles.get_ref_fix2,'Value'),1)
1634    filebase=get(handles.RootPath,'String');
1635    [FileName, PathName, filterindex] = uigetfile( ...
1636        {'*.nc', ' (*.nc)';
1637        '*.nc',  'netcdf files '; ...
1638        '*.*', 'All Files (*.*)'}, ...
1639        'Pick a file',filebase);
1640    fileinput=[PathName FileName];
1641    sizf=size(fileinput);
1642    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1643    %[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1644    [Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1645    ref.filebase=fullfile(Path,File);
1646    %     ref.num_a=stra2num(str_a);
1647    %     ref.num_b=stra2num(str_b);
1648    %     ref.num1=str2num(field_count);
1649    %     ref.num2=str2num(str2);
1650    browse=[];%initialisation
1651    if ~isequal(ref.ext,'.nc')
1652        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1653        return
1654    end
1655    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
1656    set(handles.ref_fix2,'UserData',ref)
1657    menu_field{1}='civ1';
1658    Data=nc2struct(fileinput,[]);
1659    if isfield(Data,'patch') && isequal(Data.patch,1)
1660        menu_field{2}='filter1';
1661    end
1662    if isfield(Data,'civ2') && isequal(Data.civ2,1)
1663        menu_field{3}='civ2';
1664    end
1665    if isfield(Data,'patch2') && isequal(Data.patch2,1)
1666        menu_field{4}='filter2';
1667    end
1668    set(handles.field_ref2,'String',menu_field);
1669    set(handles.field_ref2,'Value',length(menu_field));
1670    set(handles.num_MinVel,'Value',2);
1671    set(handles.num_MinVel,'String','1');%default threshold
1672    set(handles.ref_fix2,'Enable','on')
1673    set(handles.ref_fix2,'Visible','on')
1674    set(handles.field_ref2,'Visible','on')
1675else
1676    set(handles.ref_fix2,'Visible','off')
1677    set(handles.field_ref2,'Visible','off')
1678end
1679
1680%------------------------------------------------------------------------
1681function ref_fix1_Callback(hObject, eventdata, handles)
1682%------------------------------------------------------------------------
1683set(handles.num_MinVel,'Value',1);
1684set(handles.field_ref1,'Value',1)
1685set(handles.field_ref1,'String',{' '})
1686set(handles.ref_fix1,'UserData',[]);
1687set(handles.ref_fix1,'String','');
1688set(handles.thresh_vel1,'String','0');
1689
1690%------------------------------------------------------------------------
1691function ref_fix2_Callback(hObject, eventdata, handles)
1692%------------------------------------------------------------------------
1693set(handles.num_MinVel,'Value',1);
1694set(handles.field_ref2,'Value',1)
1695set(handles.field_ref2,'String',{' '})
1696set(handles.ref_fix2,'UserData',[]);
1697set(handles.ref_fix2,'String','');
1698set(handles.num_MinVel,'String','0');
1699
1700%------------------------------------------------------------------------
1701% --- TO ABANDON Executes on button press in test_stereo1.
1702function CheckStereo_Callback(hObject, eventdata, handles)
1703%------------------------------------------------------------------------
1704hparent=get(hObject,'parent');
1705parent_tag=get(hparent,'Tag');
1706hchildren=get(hparent,'children');
1707handle_txtbox=findobj(hchildren,'tag','txt_Mask');
1708if isequal(get(hObject,'Value'),0)
1709    set(handles.num_SubDomainSize,'Visible','on')
1710    set(handles.num_FieldSmooth,'Visible','on')
1711else
1712    set(handles.num_SubDomainSize,'Visible','off')
1713    set(handles.num_FieldSmooth,'Visible','off')
1714end
1715
1716% %------------------------------------------------------------------------
1717% % --- Executes on button press in CheckStereo.
1718% function StereoCheck_Callback(hObject, eventdata, handles)
1719% %------------------------------------------------------------------------
1720% if isequal(get(handles.CheckStereo,'Value'),0)
1721%     set(handles.num_subdomainsize,'Visible','on')
1722%     set(handles.num_FieldSmooth,'Visible','on')
1723% else
1724
1725%     set(handles.num_subdomainsize,'Visible','off')
1726%     set(handles.num_FieldSmooth,'Visible','off')
1727% end
1728
1729
1730
1731%------------------------------------------------------------------------
1732%----function introduced for the correlation window figure, activated by deleting this window
1733function closeview_field(gcbo,eventdata)
1734%------------------------------------------------------------------------
1735hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1736if ~isempty(hview_field)
1737    delete(hview_field)
1738end
1739
1740%------------------------------------------------------------------------
1741% --- Executes on button press in CheckThreshold.
1742function CheckThreshold_Callback(hObject, eventdata, handles)
1743%------------------------------------------------------------------------
1744huipanel=get(hObject,'parent');
1745obj(1)=findobj(huipanel,'Tag','num_MinIma');
1746obj(2)=findobj(huipanel,'Tag','num_MaxIma');
1747obj(3)=findobj(huipanel,'Tag','title_Threshold');
1748if get(hObject,'Value')
1749    set(obj,'Visible','on')
1750else
1751    set(obj,'Visible','off')
1752end
1753set(handles.configSource,'String','NEW')
1754set(handles.OK,'BackgroundColor',[1 0 1])
1755%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1756%%%%%%%%%%%%%%   TEST functions
1757%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1758%------------------------------------------------------------------------
1759% --- Executes on button press in TestCiv1: prepare the image correlation function
1760%     activated by mouse motion
1761function TestCiv1_Callback(hObject, eventdata, handles)
1762%------------------------------------------------------------------------
1763drawnow
1764if get(handles.TestCiv1,'Value')
1765    set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch 
1766    %Param.Action.RUN=1;
1767    Param.ActionInput=read_GUI(handles.civ_input);
1768    par_civ=Param.ActionInput.Civ1;
1769    [Data,ImageName_B]=get_param_civ1(handles);
1770
1771    %% create the figure view_field for image visualization
1772    hview_field=view_field(Data); %view the image in the GUI view_field
1773    set(0,'CurrentFigure',hview_field)
1774    hhview_field=guihandles(hview_field);
1775    set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
1776    ViewData=get(hview_field,'UserData');
1777    ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
1778    ViewData.PlotAxes.B=imread(ImageName_B);%store the second image in the UserData of the GUI view_field
1779   
1780    %% prepare measurement grid
1781    if isfield(par_civ,'Grid')% grid points set as input
1782            par_civ.Grid=dlmread(par_civ.Grid);
1783            par_civ.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
1784    else% automatic grid
1785        minix=floor(par_civ.Dx/2)-0.5;
1786        maxix=minix+par_civ.Dx*floor((size(Data.A,2)-1)/par_civ.Dx);
1787        miniy=floor(par_civ.Dy/2)-0.5;
1788        maxiy=minix+par_civ.Dy*floor((size(Data.A,1)-1)/par_civ.Dy);
1789        [GridX,GridY]=meshgrid(minix:par_civ.Dx:maxix,miniy:par_civ.Dy:maxiy);
1790        ViewData.PlotAxes.X=reshape(GridX,[],1);
1791        ViewData.PlotAxes.Y=reshape(GridY,[],1);
1792    end
1793
1794    set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
1795   
1796    %% look for a current figure for image correlation display
1797    corrfig=findobj(allchild(0),'tag','corrfig');
1798    if isempty(corrfig)
1799        corrfig=figure;
1800        set(corrfig,'tag','corrfig')
1801        set(corrfig,'name','image correlation')
1802        set(corrfig,'DeleteFcn',{@closeview_field})%
1803        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
1804    else
1805        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
1806        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1807        if ~isempty(corrfig)
1808            delete(corrfig)
1809        end
1810        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1811        if ~isempty(hview_field)
1812            delete(hview_field)
1813        end
1814    end
1815else
1816    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
1817    if ~isempty(hview_field)
1818        delete(hview_field)
1819    end     
1820end
1821
1822% --------------------------------------------------------------------
1823% --- Executes on button press in TestPatch1.
1824% --------------------------------------------------------------------
1825function TestPatch1_Callback(hObject, eventdata, handles)
1826
1827if get(handles.TestPatch1,'Value')% if TestPatch1 is activated
1828     set(handles.TestPatch1,'BackgroundColor',[1 1 0])%paint TestPatch1 button in yellow to induicate activation
1829     hseries=findobj(allchild(0),'Tag','series');
1830     Param=read_GUI(hseries);
1831     Param.Action.RUN=1;
1832     Param.ActionInput=read_GUI(handles.civ_input);
1833     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1834     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
1835     
1836     %% prepare Param for iterative Patch processing without input file reading
1837     Param.Civ1_X=Data.Civ1_X;
1838     Param.Civ1_Y=Data.Civ1_Y;
1839     Param.Civ1_U=Data.Civ1_U;
1840     Param.Civ1_V=Data.Civ1_V;
1841     Param.Civ1_FF=Data.Civ1_FF;
1842     Param=rmfield(Param,'InputTable');%desactivate input file reading
1843    if isfield(Param.ActionInput,'Civ1')
1844        Param.ActionInput=rmfield(Param.ActionInput,'Civ1');%desactivate civ1: remove civ1 input param if relevant
1845    end
1846    if isfield(Param.ActionInput,'Fix1')
1847        Param.ActionInput=rmfield(Param.ActionInput,'Fix1');%desactivate fix1:remove fix1 input param if relevant
1848    end
1849    SmoothingParam=(Param.ActionInput.Patch1.FieldSmooth/10)*2.^(1:7);%scan the smoothing param from 1/10 to 12.8 current value
1850    NbGood=numel(find(Data.Civ1_FF==0));
1851    for irho=1:7
1852        Param.ActionInput.Patch1.FieldSmooth=SmoothingParam(irho);
1853        [Data,errormsg]= civ_series(Param);%apply the processing fct
1854        if ~isempty(errormsg)
1855            msgbox_uvmat('ERROR',errormsg)
1856            return
1857        end
1858        ind_good=find(Data.Civ1_FF==0);
1859        Civ1_U_Diff=Data.Civ1_U(ind_good)-Data.Civ1_U_smooth(ind_good);
1860        Civ1_V_Diff=Data.Civ1_V(ind_good)-Data.Civ1_V_smooth(ind_good);
1861        DiffVel(irho)=sqrt(mean(Civ1_U_Diff.*Civ1_U_Diff+Civ1_V_Diff.*Civ1_V_Diff));
1862        NbExclude(irho)=(NbGood-numel(ind_good))/NbGood;
1863    end
1864    figure
1865    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r')
1866    grid on
1867    legend('rms velocity diff. Patch1-Civ1 (pixels)','proportion of excluded vectors (between 0 to 1)')
1868    xlabel('smoothing parameter')
1869    ylabel('smoothing effect')
1870    set(handles.TestPatch1,'BackgroundColor',[1 0 0])
1871else
1872    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1873    if ~isempty(corrfig)
1874        delete(corrfig)
1875    end
1876    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1877    if ~isempty(hview_field)
1878        delete(hview_field)
1879    end
1880end
1881
1882%------------------------------------------------------------------------
1883% --- Executes on button press in TestCiv2.
1884%------------------------------------------------------------------------
1885function TestCiv2_Callback(hObject, eventdata, handles)
1886drawnow
1887if get(handles.TestCiv2,'Value')
1888    set(handles.TestCiv2,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch
1889      hseries=findobj(allchild(0),'Tag','series');
1890     Param=read_GUI(hseries);
1891     Param.Action.RUN=1;
1892     Param.ActionInput=read_GUI(handles.civ_input);
1893     if isfield(Param,'OutputSubDir')
1894     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1895     end
1896     Param.ActionInput.Civ2.CorrSmooth=0;% launch Civ2 with no data point (to get the image names for A and B)
1897     set(handles.Civ1,'BackgroundColor',[1 1 0])
1898     set(handles.Fix1,'BackgroundColor',[1 1 0])
1899     set(handles.Patch1,'BackgroundColor',[1 1 0])
1900     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
1901     
1902     %% create image data ImageData for display
1903     ImageData.ListVarName={'ny','nx','A'};
1904     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
1905     ImageData.A=imread(Data.Civ2_ImageA); % read the first image
1906     if ndims(ImageData.A)==3 %case of color image
1907         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
1908     end
1909     ImageData.ny=[size(ImageData.A,1) 1];
1910     ImageData.nx=[1 size(ImageData.A,2)];
1911     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
1912
1913     %% create the figure view_field for image visualization
1914    hview_field=view_field(ImageData); %view the image in the GUI view_field
1915    set(0,'CurrentFigure',hview_field)
1916    % plot the boundaries of the subdomains used for patch
1917    RectCentre=squeeze(mean(Data.Civ1_SubRange,2));
1918    for isub=1:size(Data.Civ1_SubRange,3);
1919        pos_x=Data.Civ1_SubRange(1,1,isub);
1920        pos_y=Data.Civ1_SubRange(2,1,isub);
1921        width=Data.Civ1_SubRange(1,2,isub)-Data.Civ1_SubRange(1,1,isub);
1922        height=Data.Civ1_SubRange(2,2,isub)-Data.Civ1_SubRange(2,1,isub);
1923        rectangle('Position',[pos_x pos_y width height],'EdgeColor',[0 0 1])
1924    end
1925    hhview_field=guihandles(hview_field);%
1926    set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
1927    ViewData=get(hview_field,'UserData'); % get the currently plotted field (the image A)
1928    % store info in the UserData of view-field
1929    ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
1930    ViewData.PlotAxes.B=imread(Data.Civ2_ImageB);%store the second image in the UserData of the GUI view_field
1931    ViewData.PlotAxes.X=Data.Civ2_X';
1932    ViewData.PlotAxes.Y=Data.Civ2_Y';
1933    ViewData.PlotAxes.ShiftX=Data.Civ2_U';% shift at each point (from patch1) estimated by running civ2
1934    ViewData.PlotAxes.ShiftY=Data.Civ2_V';
1935    ViewData.PlotAxes.Civ1_SubRange=Data.Civ1_SubRange;
1936    ViewData.PlotAxes.Civ1_NbCentres=Data.Civ1_NbCentres;
1937    ViewData.PlotAxes.Civ1_Coord_tps=Data.Civ1_Coord_tps;
1938    ViewData.PlotAxes.Civ1_U_tps=Data.Civ1_U_tps;
1939    ViewData.PlotAxes.Civ1_V_tps=Data.Civ1_V_tps;
1940    ViewData.PlotAxes.Civ1_Dt=Data.Civ1_Dt;
1941    ViewData.PlotAxes.Civ2_Dt=Data.Civ2_Dt;
1942    set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
1943    bckcolor=get(handles.civ_input,'Color');
1944    set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calmculation is finished
1945    set(handles.Fix1,'BackgroundColor',bckcolor)
1946    set(handles.Patch1,'BackgroundColor',bckcolor)
1947    drawnow
1948   
1949    %% look for a current figure for image correlation display
1950    corrfig=findobj(allchild(0),'tag','corrfig');
1951    if isempty(corrfig)
1952        corrfig=figure;
1953        set(corrfig,'tag','corrfig')
1954        set(corrfig,'name','image correlation')
1955        set(corrfig,'DeleteFcn',{@closeview_field})%
1956        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
1957    else
1958        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
1959        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1960        if ~isempty(corrfig)
1961            delete(corrfig)
1962        end
1963        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1964        if ~isempty(hview_field)
1965            delete(hview_field)
1966        end
1967    end   
1968else
1969    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
1970    if ~isempty(hview_field)
1971        delete(hview_field)
1972    end     
1973end
1974
1975
1976%'nomtype2pair': creates nomencalture for index pairs knowing the image nomenclature
1977%---------------------------------------------------------------------
1978function NomTypeNc=nomtype2pair(NomTypeIma,mode)
1979%---------------------------------------------------------------------           
1980% OUTPUT:
1981% NomTypeNc
1982%---------------------------------------------------------------------
1983% INPUT:
1984% 'NomTypeIma': string defining the kind of nomenclature used for images
1985
1986NomTypeNc=NomTypeIma;%default
1987switch mode
1988    case 'pair j1-j2'     
1989    if ~isempty(regexp(NomTypeIma,'a$'))
1990        NomTypeNc=[NomTypeIma 'b'];
1991    elseif ~isempty(regexp(NomTypeIma,'A$'))
1992        NomTypeNc=[NomTypeIma 'B'];
1993    else
1994        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
1995        if ~isempty(r)
1996            NomTypeNc='_1_1-2';
1997        end
1998    end
1999    case 'series(Dj)' 
2000%         r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2001%         if ~isempty(r)
2002            NomTypeNc='_1_1-2';
2003%         end
2004   case 'series(Di)'
2005        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2006        if ~isempty(r)
2007            NomTypeNc='_1-2_1';
2008        else
2009            NomTypeNc='_1-2';
2010        end
2011end
2012
2013
2014%------------------------------------------------------------------------
2015% --- determine the list of index pairs of processing file
2016function [ind1,ind2,mode]=...
2017    find_pair_indices(str_civ,i_series,j_series,MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j)
2018%------------------------------------------------------------------------
2019ind1='';
2020ind2='';
2021r=regexp(str_civ,'^\D(?<ind>[i|j])=( -| )(?<num1>\d+)\|(?<num2>\d+)','names');
2022if ~isempty(r)
2023    mode=['D' r.ind];
2024    ind1=stra2num(r.num1);
2025    ind2=stra2num(r.num2);
2026else
2027    mode='burst';
2028    r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names');
2029    if ~isempty(r)
2030        NomTypeNc='_1ab';
2031    else
2032        r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names');
2033        if ~isempty(r)
2034            NomTypeNc='_1AB';
2035        else
2036            r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names');
2037            if ~isempty(r)
2038                NomTypeNc='_1_1-2';
2039            end           
2040        end
2041    end
2042    if isempty(r)
2043        display('wrong pair mode input option')
2044    else
2045    ind1=stra2num(r.num1);
2046    ind2=stra2num(r.num2);
2047    end
2048end
2049
2050%------------------------------------------------------------------------
2051% --- fill civ_input with the parameters retrieved from an input Civ file
2052%------------------------------------------------------------------------
2053function fill_civ_input(Data,handles)
2054
2055%% Civ param
2056% lists of parameters to enter
2057ListParamNum={'CorrBoxSize','SearchBoxSize','SearchBoxShift','Dx','Dy','Dz','MinIma','MaxIma'};% list of numerical values (to transform in strings)
2058ListParamValue={'CorrSmooth','CheckGrid','CheckMask','CheckThreshold'};
2059ListParamString={'Grid','Mask'};
2060% CorrSmooth ??
2061option={'Civ1','Civ2'};
2062for ichoice=1:2
2063    if isfield(Data,[option{ichoice} '_CorrBoxSize'])
2064        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2065    end
2066end
2067
2068%% Fix param
2069option={'Fix1','Fix2'};
2070for ichoice=1:2
2071    if isfield(Data,[option{ichoice} '_CheckFmin2'])
2072        ListParamNum={'MinVel','MaxVel','MinCorr'};% list of numerical values (to transform in strings)
2073        ListParamValue={'CheckFmin2','CheckF3','CheckF4'};
2074        ListParamString={'ref_fix_1'};
2075        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2076    end
2077end
2078
2079%% Patch param
2080option={'Patch1','Patch2'};
2081for ichoice=1:2
2082    if isfield(Data,[option{ichoice} '_FieldSmooth'])
2083        ListParamNum={'FieldSmooth','MaxDiff','SubDomainSize'};% list of numerical values (to transform in strings)
2084        ListParamValue={};
2085        ListParamString={};
2086        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2087    end
2088end
2089%------------------------------------------------------------------------
2090% --- fill a panel of civ_input with the parameters retrieved from an input Civ file
2091%------------------------------------------------------------------------
2092function fill_panel(Data,handles,panel,ListParamNum,ListParamValue,ListParamString)
2093children=get(handles.(panel),'children');%handles of the children of the input GUI with handle 'GUI_handle'
2094handles_panel=[];
2095for ichild=1:numel(children)
2096    if ~isempty(get(children(ichild),'tag'))
2097        handles_panel.(get(children(ichild),'tag'))=children(ichild);
2098    end
2099end
2100for ilist=1:numel(ListParamNum)
2101    ParamName=ListParamNum{ilist};
2102    CivParamName=[panel '_' ParamName];
2103    if isfield(Data,CivParamName)
2104        for icoord=1:numel(Data.(CivParamName))
2105            if numel(Data.(CivParamName))>1
2106                Tag=['num_' ParamName '_' num2str(icoord)];
2107            else
2108                Tag=['num_' ParamName];
2109            end
2110            if isfield(handles_panel,Tag)
2111                set(handles_panel.(Tag),'String',num2str(Data.(CivParamName)(icoord)))
2112                set(handles_panel.(Tag),'Visible','on')
2113            end
2114        end
2115    end
2116end
2117for ilist=1:numel(ListParamValue)
2118    ParamName=ListParamValue{ilist};
2119    CivParamName=[panel '_' ParamName];
2120    if strcmp(ParamName,'CorrSmooth')
2121        ParamName=['num_' ParamName];
2122    end
2123    if isfield(Data,CivParamName)
2124        if isfield(handles_panel,ParamName)
2125            set(handles_panel.(ParamName),'Value',Data.(CivParamName))
2126        end
2127    end
2128end
2129for ilist=1:numel(ListParamString)
2130    ParamName=ListParamString{ilist};
2131    CivParamName=[panel '_' ParamName];
2132    if isfield(Data,CivParamName)
2133        if isfield(handles_panel,ParamName)
2134            set(handles_panel.(ParamName),'String',Data.(CivParamName))
2135        end
2136    end
2137end
2138
2139
2140%------------------------------------------------------------------------
2141function [Data,ImageName_B]=get_param_civ1(handles)
2142
2143 ref_i=str2double(get(handles.ref_i,'String'));% read reference i index
2144 if strcmp(get(handles.ref_j,'Visible'),'on')
2145     ref_j=str2double(get(handles.ref_j,'String'));% read reference j index if relevant
2146 else
2147     ref_j=1;%default j index
2148 end
2149 Data.ListVarName={'ny','nx','A'};
2150 Data.VarDimName= {'ny','nx',{'ny','nx'}};
2151 hseries=findobj(allchild(0),'Tag','series');
2152 hhseries=guidata(hseries);
2153 InputTable=get(hhseries.InputTable,'Data');
2154 ind_A=1;
2155 if strcmp(InputTable{1,5},'.nc');
2156     ind_A=2;
2157 end
2158 list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
2159 PairString=list_pair{get(handles.ListPairCiv1,'Value')};
2160 [ind1,ind2,mode]=find_pair_indices(PairString,ref_i,ref_j);%,MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j)
2161 switch mode
2162     case 'Di'
2163         i1=ref_i-ind1;
2164         i2=ref_i+ind2;
2165         j1=ref_j;
2166         j2=ref_j;
2167     case 'Dj'
2168         i1=ref_i;
2169         i2=ref_i;
2170         j1=ref_j-ind1;
2171         j2=ref_j+ind2;
2172     case 'burst'
2173         i1=ref_i;
2174         i2=ref_i;
2175         j1=ind1;
2176         j2=ind2;
2177 end
2178 ImageName_A=fullfile_uvmat(InputTable{ind_A,1},InputTable{ind_A,2},InputTable{ind_A,3},InputTable{ind_A,5},InputTable{ind_A,4},...
2179     i1,[],j1);
2180 ImageName_B=fullfile_uvmat(InputTable{ind_A,1},InputTable{ind_A,2},InputTable{ind_A,3},InputTable{ind_A,5},InputTable{ind_A,4},...
2181     i2,[],j2);
2182 Data.A=imread(ImageName_A); % read the first image
2183 if ndims(Data.A)==3 %case of color image
2184     Data.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
2185 end
2186 Data.ny=[size(Data.A,1) 1];
2187 Data.nx=[1 size(Data.A,2)];
2188 Data.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
2189%  par_civ1=read_GUI(handles.Civ1);
2190% FileInfo=get_file_info(ImageName_A);
2191%  par_civ1.FileTypeA=FileInfo.FileType;
2192%  par_civ1.ImageWidth=size(Data.A,2);
2193%  par_civ1.ImageHeight=size(Data.A,1);
2194%  par_civ1.Mask='all';% will provide only the grid set for PIV, no image correlation
2195%  par_civ1.FrameIndexA=num2str(i1);
2196%  par_civ1.FrameIndexB=num2str(i2);
2197%  par_civ1.ImageName_B=ImageName_B;
2198
2199%------------------------------------------------------------------------
2200% --- Executes on button press in ImportParam.
2201%------------------------------------------------------------------------
2202function ImportParam_Callback(hObject, eventdata, handles)
2203hseries=findobj(allchild(0),'Tag','series');
2204hhseries=guidata(hseries);
2205InputTable=get(hhseries.InputTable,'Data');% read the input file(s) table in the GUI series
2206oldfile=InputTable{1,1};
2207if isempty(oldfile)
2208    % use a file name stored in prefdir
2209    dir_perso=prefdir;
2210    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2211    if exist(profil_perso,'file')
2212        h=load (profil_perso);
2213        if isfield(h,'RootPath') && ischar(h.RootPath)
2214            oldfile=h.RootPath;
2215        end
2216    end
2217end
2218filexml=uigetfile_uvmat('pick a xml parameter file for civ',oldfile,'.xml');% get the xml file containing processing parameters
2219%proceed only if a file has been introduced by the browser
2220if ~isempty(filexml)
2221    Param=xml2struct(filexml);% read the input xml file as a Matlab structure
2222
2223   % Param.Action.RUN=0; %desactivate the input RUN=1
2224    if ~isfield(Param,'InputTable')||~isfield(Param,'IndexRange')
2225        msgbox_uvmat('ERROR','invalid config file: open a file in a folder ''/0_XML''')
2226        return
2227    end
2228    check_input=0;
2229    if isfield(Param,'ActionInput')
2230        if isfield(Param.ActionInput,'Program')&& strcmp(Param.ActionInput.Program,'civ_series')
2231            fill_GUI(Param.ActionInput,handles.civ_input)% fill the elements of the GUI series with the input parameters
2232            set(handles.ConfigSource,'String',filexml)
2233            check_input=1;
2234            update_CivOptions(handles,0)             
2235        end
2236    end
2237    if ~check_input
2238        msgbox_uvmat('ERROR','invalid config file (not for civ_series')
2239        return
2240    end
2241end
2242
2243% --- Executes on selection change in CheckCiv3.
2244function CheckCiv3_Callback(hObject, eventdata, handles)
2245   
2246%------------------------------------------------------------------------
2247% --- Executes on key press with selection of a uicontrol
2248%------------------------------------------------------------------------
2249function keyboard_callback(hObject,eventdata,handles)
2250   
2251ListExclude={'CheckCiv1','CheckFix1','CheckPatch1','CheckCiv2','CheckFix2','CheckPatch2','ref_i'};
2252if isempty(find(strcmp(get(gco,'Tag'),ListExclude),1))% if the selected uicontrol is not in the Exclude list
2253    set(handles.ConfigSource,'String','NEW')% indicate that the configuration is new
2254    set(handles.OK,'BackgroundColor',[1 0 1])%
2255    drawnow
2256end
2257
2258
2259% --- Executes on button press in TestPatch2.
2260function TestPatch2_Callback(hObject, eventdata, handles)
2261
2262
2263
Note: See TracBrowser for help on using the repository browser.