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

Last change on this file since 711 was 711, checked in by sommeria, 10 years ago

various improvements

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