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

Last change on this file since 707 was 707, checked in by sommeria, 11 years ago

bug repaired for civ_series

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