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

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

bugrepair

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