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

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