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

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

civ_input corrected to handle the new fct 'stereo_civ'

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