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

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

fct improved by reducing the input file check when selected.

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