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

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

testcivadded

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