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

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

turb_stat corrected
civ corrected to allow civ2 from an existing civ1 series

File size: 83.5 KB
Line 
1%'civ_input': function associated with the GUI 'civ_input.fig' to set the input parameters for civ_series
2%------------------------------------------------------------------------
3% function ParamOut = civ_input(Param)
4%
5% OUPUT:
6% ParamOut: Matlab structure containing the parameters set by the GUI civ_input
7%
8% INPUT:
9% Param: Matlab structure containing the input parameters set by the GUI
10%
11%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
12%  Copyright Joel Sommeria, 2011, LEGI / CNRS-UJF-INPG, sommeria@legi.grenoble-inp.fr
13%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
14%     This file is part of the toolbox UVMAT.
15%
16%     UVMAT is free software; you can redistribute it and/or modify
17%     it under the terms of the GNU General Public License as published by
18%     the Free Software Foundation; either version 2 of the License, or
19%     (at your option) any later version.
20%
21%     UVMAT is distributed in the hope that it will be useful,
22%     but WITHOUT ANY WARRANTY; without even the implied warranty of
23%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
25%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
26function varargout = civ_input(varargin)
27
28gui_Singleton = 1;
29gui_State = struct('gui_Name',       mfilename, ...
30    'gui_Singleton',  gui_Singleton, ...
31    'gui_OpeningFcn', @civ_input_OpeningFcn, ...
32    'gui_OutputFcn',  @civ_input_OutputFcn, ...
33    'gui_LayoutFcn',  [] , ...
34    'gui_Callback',   []);
35
36if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback$','once'))
37        gui_State.gui_Callback = str2func(varargin{1});
38end
39
40if nargout
41    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
42else
43    gui_mainfcn(gui_State, varargin{:});
44end
45
46% End initialization code - DO NOT EDIT
47
48%------------------------------------------------------------------------
49% --- Executes just before civ_input is made visible.
50function civ_input_OpeningFcn(hObject, eventdata, handles, Param)
51%------------------------------------------------------------------------
52% This function has no output args, see OutputFcn.
53
54%% General settings
55handles.output = Param;
56guidata(hObject, handles); % Update handles structure
57set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
58hseries=findobj(allchild(0),'Tag','series');
59hhseries=guidata(hseries);
60%SeriesData.ParentHandle=hseries;
61SeriesData=get(hseries,'UserData');
62% relevant data in gcbf:.FileType,.FileInfo,.Time,.TimeUnit,.GeometryCalib{1};
63
64%% set visibility options:
65if strcmp(Param.Action.ActionName,'civ_series')
66        set(handles.Program,'String','civ_series')
67        set(handles.num_MaxDiff,'Visible','on')
68        set(handles.num_MaxVel,'Visible','on')
69        set(handles.title_MaxVel,'Visible','on')
70        set(handles.title_MaxDiff,'Visible','on')
71        set(handles.num_Nx,'Visible','off')
72        set(handles.num_Ny,'Visible','off')
73        set(handles.title_Nx,'Visible','off')
74        set(handles.title_Ny,'Visible','off')
75        set(handles.num_CorrSmooth,'Style','popupmenu')
76        set(handles.num_CorrSmooth,'Value',1)
77        set(handles.num_CorrSmooth,'String',{'1';'2'})
78        set(handles.CheckThreshold,'Visible','on')
79        set(handles.CheckDeformation,'Value',0)% desactivate (work in progress)
80        set(handles.CheckDecimal,'Value',0)% desactivate (work in progress)
81end
82
83%% input file info
84% RootPath=Param.InputTable{1,1};
85% %set(handles.RootPath,'String',RootPath)
86% RootFile=Param.InputTable{1,3};
87% SubDir=Param.InputTable{1,2};
88NomTypeInput=Param.InputTable{1,4};
89% FileExt=Param.InputTable{1,5};
90FileType='image';%fdefault
91FileInfo=[];
92if isfield(SeriesData,'FileType')&&isfield(SeriesData,'FileInfo')
93    FileType=SeriesData.FileType{1};%type of the first input file series
94    FileInfo=SeriesData.FileInfo{1};
95else
96    set(hhseries.REFRESH,'BackgroundColor',[1 0 1])
97%     msgbox_uvmat('ERROR','please refresh the input file series')
98%     return
99end
100
101
102%% case of netcdf file as input, get the processing stage and look for corresponding images
103% imageinput=fileinput;%default
104% TODO: insert image input in the GUI series
105ind_opening=0;%default
106NomTypeNc='';
107switch FileType
108    case {'image','multimage','video','mmreader'}
109        NomTypeImaA=NomTypeInput;
110        iview_image=1;%line # for the input images
111    case 'civdata'
112        if ~strcmp(Param.Action.ActionName,'civ_series')
113            msgbox_uvmat('ERROR','bad input data file: open an image or a nc file from civ_series')
114            %return
115        end
116        NomTypeNc=NomTypeInput;
117        ind_opening=FileInfo.CivStage;
118        if isempty(regexp(NomTypeInput,'[ab|AB|-]', 'once'))
119            set(handles.ListCompareMode,'Value',2) %mode displacement advised if the nomencalture does not involve index pairs
120%             set(handles.RootFile_1,'Visible','On');
121        else
122            set(handles.ListCompareMode,'Value',1)
123        end
124        imageinput='';
125        FileInput=SeriesData.RefFile{1};
126        Data=nc2struct(FileInput,'ListGlobalAttribute','Civ2_ImageA','Civ1_ImageA','Civ2_ImageB','Civ1_ImageB');
127        [PathCiv1_ImageA,Civ1_ImageA,FileExtA]=fileparts(Data.Civ1_ImageA);
128        [PathCiv1_ImageB,Civ1_ImageB,FileExtA]=fileparts(Data.Civ1_ImageB);
129        if ~isempty(Data.Civ2_ImageA)
130            [PathCiv2_ImageA,Civ2_ImageA,FileExtA]=fileparts(Data.Civ2_ImageA);
131            [PathCiv2_ImageB,Civ2_ImageB,FileExtA]=fileparts(Data.Civ2_ImageB);
132        end
133        if size(Param.InputTable,1)==1
134            series('display_file_name',hhseries,Data.Civ1_ImageA,'append');%append the image series to the input list
135        end
136        if isfield(Data,'Txt')
137            errormsg=Data.Txt;
138            return
139            %TODO: introduce the image in the input table of series
140        end
141        [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaA]=fileparts_uvmat(Data.Civ1_ImageA);
142        [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaB]=fileparts_uvmat(Data.Civ1_ImageB);
143        iview_image=2;%line # for the input images
144    case 'civxdata'% case of  civx data,
145        msgbox_uvmat('ERROR','old civX convention, use the GUI civ')
146        return
147    otherwise
148        msgbox_uvmat('ERROR','civ_series needs images or civ data as input')
149        return
150end
151if isfield(SeriesData,'FileType') && numel(SeriesData.FileType)>=2 && strcmp(SeriesData.FileType{end-1},'image') &&   strcmp(SeriesData.FileType{end},'image')
152    set(handles.ListCompareMode,'Value',3)% we compare two image series term to term ('shift')
153    set(handles.PairIndices,'Visible','off')
154end
155
156%% TODO: get corresponding image in nc case
157
158%% reinitialise menus
159set(handles.ListPairMode,'Value',1)
160set(handles.ListPairMode,'String',{''})
161set(handles.ListPairCiv1,'Value',1)
162set(handles.ListPairCiv1,'String',{''})
163set(handles.ListPairCiv2,'Value',1)
164set(handles.ListPairCiv2,'String',{''})
165       
166%% prepare the GUI with input parameters
167set(handles.ListCompareMode,'Visible','on')
168
169%display the parameters stored on the GUI series
170set(handles.ref_i,'String',num2str(Param.IndexRange.first_i))
171if isfield(Param.IndexRange,'first_j')
172    set(handles.ref_j,'String',num2str(Param.IndexRange.first_j))
173end
174
175%% set the civ_input options depending on the input file content when a nc file has been opened
176ListOptions={'CheckCiv1', 'CheckFix1' 'CheckPatch1', 'CheckCiv2', 'CheckFix2', 'CheckPatch2'};
177checkbox=zeros(size(ListOptions));%default
178if ind_opening==0%case of image opening, start with Civ1
179    for index=1:numel(ListOptions)
180        checkbox(index)=get(handles.(ListOptions{index}),'Value');
181    end
182    index_max=find(checkbox, 1, 'last' );
183    if isempty(index_max),index_max=1;end
184    for index=1:index_max
185        set(handles.(ListOptions{index}),'Value',1)% select all operations starting from CIV1
186    end
187else
188    for index = 1:min(ind_opening,5)
189        set(handles.(ListOptions{index}),'value',0)
190    end
191    set(handles.(ListOptions{min(ind_opening+1,6)}),'value',1)
192    for index = ind_opening+2:6
193        set(handles.(ListOptions{index}),'value',0)
194    end
195end
196
197
198%%  set the menus of image pairs and default selection for civ_input   %%%%%%%%%%%%%%%%%%%
199MaxIndex_i=Param.IndexRange.MaxIndex_i(iview_image);
200MinIndex_i=Param.IndexRange.MinIndex_i(iview_image);
201MaxIndex_j=1;%default
202MinIndex_j=1;
203if isfield(Param.IndexRange,'MaxIndex_j')&&isfield(Param.IndexRange,'MinIndex_j')...
204     && numel(Param.IndexRange.MaxIndex_j')>=iview_image &&numel(Param.IndexRange.MinIndex_j')>=iview_image 
205MaxIndex_j=Param.IndexRange.MaxIndex_j(iview_image);
206MinIndex_j=Param.IndexRange.MinIndex_j(iview_image);
207end
208CivInputData.MaxIndex_i=MaxIndex_i;
209CivInputData.MaxIndex_j=MaxIndex_j;
210CivInputData.MinIndex_i=MinIndex_i;
211CivInputData.MinIndex_j=MinIndex_j;
212if ~isfield(Param.IndexRange,'first_j')||isequal(MaxIndex_j,MinIndex_j)% no possibility of j pairs
213    set(handles.ListPairMode,'Value',1)
214    set(handles.ListPairMode,'String',{'series(Di)'})
215elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
216    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)'})
217    if  MaxIndex_j <= 10
218        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
219    end
220else
221    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
222    if strcmp(NomTypeNc,'_1-2_1')
223        set(handles.ListPairMode,'Value',3)% advise 'series(Di)'
224    elseif  MaxIndex_j <= 10
225        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
226    end
227end
228
229%%  transfer the time from the GUI series, or use file index by default
230time=[];
231TimeUnit='frame'; %default
232CoordUnit='';%default
233pxcm_search=1;
234if isfield(SeriesData,'Time') && ~isempty(SeriesData.Time{1})
235    time=SeriesData.Time{1};
236end
237if isfield(Param.IndexRange,'TimeUnit')&&~isempty(Param.IndexRange.TimeUnit)
238    TimeUnit=Param.IndexRange.TimeUnit;
239end
240if isfield(SeriesData,'TimeSource')
241    set(handles.ImaDoc,'String',SeriesData.TimeSource)
242end 
243if isfield(SeriesData,'GeometryCalib')
244    tsai=SeriesData.GeometryCalib;
245    if isfield(tsai,'fx_fy')
246        pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
247    end
248    if isfield(tsai,'CoordUnit')
249        CoordUnit=tsai.CoordUnit;
250    end
251end
252
253%% timing display
254%show the reference image edit box if relevant (not needed for movies or in the absence of time information
255if numel(time)>=2 % if there are at least two time values to define dt
256    if size(time,1)<MaxIndex_i;
257        msgbox_uvmat('WARNING','maximum i index restricted by the timing of the xml file');
258    elseif size(time,2)<MaxIndex_j
259        msgbox_uvmat('WARNING','maximum j index restricted by the timing of the xml file');
260    end
261    MaxIndex_i=min(size(time,1),MaxIndex_i);%possibly adjust the max index according to time data
262    MaxIndex_j=min(size(time,2),MaxIndex_j);
263else
264    set(handles.ImaDoc,'String',''); %xml file not used for timing
265    TimeUnit='frame';
266    time=ones(MaxIndex_j-MinIndex_j+1,1)*(MinIndex_i:MaxIndex_i);
267    time=time+0.001*(MinIndex_j:MaxIndex_j)'*ones(1,MaxIndex_i-MinIndex_i+1);
268end
269CivInputData.Time=time;
270CivInputData.NomTypeIma=NomTypeImaA;
271set(handles.civ_input,'UserData',CivInputData)
272set(handles.dt_unit,'String',['dt in m' TimeUnit]);%display dt in unit 10-3 of the time (e.g ms)
273set(handles.TimeUnit,'String',TimeUnit);
274set(handles.CoordUnit,'String',CoordUnit)
275set(handles.SearchRange,'UserData', pxcm_search);
276
277%% set the reference indices from the input file indices
278num_ref_i=str2num(get(handles.ref_i,'String'));
279num_ref_j=str2num(get(handles.ref_j,'String'));
280
281update_CivOptions(handles,ind_opening)
282
283%% list the possible index pairs, depending on the option set in ListPairMode
284ListPairMode_Callback([], [], handles)
285ListPairCiv1_Callback(hObject, eventdata, handles)
286
287%% introduce the stored parameters if relevant
288if isfield(Param,'ActionInput')
289    fill_GUI(Param.ActionInput,hObject);%fill the GUI with the parameters retrieved from the input Param
290    hcheckgrid=findobj(handles.civ_input,'Tag','CheckGrid');
291    for ilist=1:numel(hcheckgrid)
292        if get(hcheckgrid(ilist),'Value')
293            hparent=get(hcheckgrid(ilist),'parent');%handles of the parent panel
294            hchildren=get(hparent,'children');
295            %handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel
296            handle_dx=findobj(hchildren,'tag','num_Dx');
297            handle_dy=findobj(hchildren,'tag','num_Dy');
298            handle_title_dx=findobj(hchildren,'tag','title_Dx');
299            handle_title_dy=findobj(hchildren,'tag','title_Dy');
300            set(handle_dx,'Visible','off');
301            set(handle_dy,'Visible','off');
302            set(handle_title_dy,'Visible','off');
303            set(handle_title_dx,'Visible','off');
304        end
305    end
306end
307
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%------------------------------------------------------------------------
903% index_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
906% mode_list=get(handles.ListPairMode,'String');
907% mode_value=get(handles.ListPairMode,'Value');
908% mode=mode_list{mode_value};
909% if isequal(mode,'series(Di)')
910%     first_i=str2double(get(handles.MinIndex_i,'String'));
911%     last_i=str2double(get(handles.MaxIndex_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(last_i)
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))<=last_i);
918%         num_i=num_i(test_find);
919%     end
920%     set(handles.MinIndex_i,'String',num2str(num_i(1)));
921%     set(handles.MaxIndex_i,'String',num2str(num_i(end)));
922% elseif 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)));
935% end
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 for Civ1
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
1104
1105%% determine the default selection in the pair menu for Civ2
1106if strcmp(get(handles.ListPairCiv2,'Visible'),'on')
1107    initial=get(handles.ListPairCiv2,'Value');
1108    if initial>length(displ_pair')%|~isequal(select(initial),1)
1109        if ichoice <= length(displ_pair')
1110            set(handles.ListPairCiv2,'Value',ichoice);% same pair proposed by default for civ2
1111        else
1112            set(handles.ListPairCiv2,'Value',1);% same pair proposed by default for civ2
1113        end
1114    end
1115else
1116    set(handles.ListPairCiv2,'Value',get(handles.ListPairCiv1,'Value'))% initiate the choice of Civ2 as a reproduction of if civ1
1117end
1118set(handles.ListPairCiv2,'String',displ_pair');
1119set(gcf,'Pointer','arrow')% Indicate that the process is finished
1120
1121
1122   
1123% %------------------------------------------------------------------------   
1124% % call 'view_field.fig' to display the  field selected in the list of 'status'
1125% function open_view_field(hObject, eventdata)
1126% %------------------------------------------------------------------------
1127% list=get(hObject,'String');
1128% index=get(hObject,'Value');
1129% rootroot=get(hObject,'UserData');
1130% filename=list{index};
1131% ind_dot=strfind(filename,'...');
1132% filename=filename(1:ind_dot-1);
1133% filename=fullfile(rootroot,filename);
1134% delete(get(hObject,'parent'))%delete the display figure to stop the check process
1135% if exist(filename,'file')%visualise the vel field if it exists
1136%     uvmat(filename)
1137%     set(gcbo,'Value',1)
1138% end
1139
1140
1141%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1142% Callbacks in the uipanel Reference Indices
1143%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1144%------------------------------------------------------------------------
1145function MinIndex_i_Callback(hObject, eventdata, handles)
1146%------------------------------------------------------------------------
1147first_i=str2double(get(handles.MinIndex_i,'String'));
1148set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
1149ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
1150
1151%------------------------------------------------------------------------
1152function MinIndex_j_Callback(hObject, eventdata, handles)
1153%------------------------------------------------------------------------
1154first_j=str2num(get(handles.MinIndex_j,'String'));
1155set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
1156ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
1157
1158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1159% Callbacks in the uipanel Civ1
1160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1161%------------------------------------------------------------------------
1162% --- Executes on button press in SearchRange: determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2
1163function SearchRange_Callback(hObject, eventdata, handles)
1164%------------------------------------------------------------------------
1165%determine pair numbers
1166if strcmp(get(handles.num_UMin,'Visible'),'off')
1167    set(handles.u_title,'Visible','on')
1168    set(handles.v_title,'Visible','on')
1169    set(handles.num_UMin,'Visible','on')
1170    set(handles.num_UMax,'Visible','on')
1171    set(handles.num_VMin,'Visible','on')
1172    set(handles.num_VMax,'Visible','on')
1173    set(handles.CoordUnit,'Visible','on')
1174    set(handles.TimeUnit,'Visible','on')
1175    set(handles.slash_title,'Visible','on')
1176    set(handles.min_title,'Visible','on')
1177    set(handles.max_title,'Visible','on')
1178    set(handles.unit_title,'Visible','on')
1179else
1180    get_search_range(hObject, eventdata, handles)
1181end
1182
1183%------------------------------------------------------------------------
1184% ---  determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2 and shift
1185function get_search_range(hObject, eventdata, handles)
1186%------------------------------------------------------------------------
1187param_civ1=read_GUI(handles.Civ1);
1188umin=param_civ1.UMin;
1189umax=param_civ1.UMax;
1190vmin=param_civ1.VMin;
1191vmax=param_civ1.VMax;
1192%switch min_title and max_title in case of error
1193if umax<=umin
1194    umin_old=umin;
1195    umin=umax;
1196    umax=umin_old;
1197    set(handles.num_UMin,'String', num2str(umin))
1198    set(handles.num_UMax,'String', num2str(umax))
1199end
1200if vmax<=vmin
1201    vmin_old=vmin;
1202    vmin=vmax;
1203    vmax=vmin_old;
1204    set(handles.num_VMin,'String', num2str(vmin))
1205    set(handles.num_VMax,'String', num2str(vmax))
1206end   
1207if ~(isempty(umin)||isempty(umax)||isempty(vmin)||isempty(vmax))
1208    list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
1209    index=get(handles.ListPairCiv1,'Value');
1210    pair_string=list_pair{index};
1211    time=get(handles.ImaDoc,'UserData'); %get the set of times
1212    pxcm=get(handles.SearchRange,'UserData');
1213    mode_list=get(handles.ListPairMode,'String');
1214    mode_value=get(handles.ListPairMode,'Value');
1215    mode=mode_list{mode_value};     
1216    if isequal (mode, 'series(Di)' )
1217        ref_i=str2double(get(handles.ref_i,'String'));
1218        num1=ref_i-floor(index/2);%  first image numbers
1219        num2=ref_i+ceil(index/2);
1220        num_a=1;
1221        num_b=1;
1222    elseif isequal (mode, 'series(Dj)')
1223        num1=1;
1224        num2=1;
1225        ref_j=str2double(get(handles.ref_j,'String'));
1226        num_a=ref_j-floor(index/2);%  first image numbers
1227        num_b=ref_j+ceil(index/2);
1228    elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)     
1229        ref_i=str2double(get(handles.ref_i,'String'));
1230        num1=ref_i;
1231        num2=ref_i;
1232                r=regexp(pair_string,'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
1233        if isempty(r)
1234            r=regexp(pair_string,'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
1235        end 
1236        num_a=str2num(r.num1);
1237        num_b=str2num(r.num2);
1238    end
1239    dt=time(num2+1,num_b+1)-time(num1+1,num_a+1);
1240    ibx=str2double(get(handles.num_CorrBoxSize_1,'String'));
1241    iby=str2double(get(handles.num_CorrBoxSize_2,'String'));
1242    umin=dt*pxcm*umin;
1243    umax=dt*pxcm*umax;
1244    vmin=dt*pxcm*vmin;
1245    vmax=dt*pxcm*vmax;
1246    shiftx=round((umin+umax)/2);
1247    shifty=round((vmin+vmax)/2);
1248    isx=(umax+2-shiftx)*2+param_civ1.Bx;
1249    isx=2*ceil(isx/2)+1;
1250    isy=(vmax+2-shifty)*2+param_civ1.Bx;
1251    isy=2*ceil(isy/2)+1;
1252    set(handles.num_SearchBoxShift_1,'String',num2str(shiftx));
1253    set(handles.num_SearchBoxShift_2,'String',num2str(shifty));
1254    set(handles.num_SearchBoxSize_1,'String',num2str(isx));
1255    set(handles.num_SearchBoxSize_2,'String',num2str(isy));
1256end
1257
1258%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1259% Callbacks in the uipanel Fix1
1260%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1261%------------------------------------------------------------------------
1262% --- Executes on button press in CheckMask.
1263function get_mask_fix1_Callback(hObject, eventdata, handles)
1264%------------------------------------------------------------------------
1265maskval=get(handles.CheckMask,'Value');
1266if isequal(maskval,0)
1267    set(handles.Mask,'String','')
1268else
1269    mask_displ='no mask'; %default
1270    filebase=get(handles.RootPath,'String');
1271    [nbslice, flag_mask]=get_mask(filebase,handles);
1272    if isequal(flag_mask,1)
1273        mask_displ=[num2str(nbslice) 'mask'];
1274    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1275        filebase_a=get(handles.RootFile_1,'String');
1276        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1277        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1278            mask_displ='no mask';
1279        end
1280    end
1281    if isequal(mask_displ,'no mask')
1282        [FileName, PathName, filterindex] = uigetfile( ...
1283            {'*.png', ' (*.png)';
1284            '*.png',  '.png files '; ...
1285            '*.*', 'All Files (*.*)'}, ...
1286            'Pick a mask file *.png',filebase);
1287        mask_displ=fullfile(PathName,FileName);
1288        if ~exist(mask_displ,'file')
1289            mask_displ='no mask';
1290        end
1291    end
1292    if isequal(mask_displ,'no mask')
1293        set(handles.CheckMask,'Value',0)
1294        set(handles.CheckMask,'Value',0)
1295        set(handles.CheckMask,'Value',0)
1296    else
1297        %set(handles.CheckMask,'Value',1)
1298        set(handles.CheckMask,'Value',1)
1299    end
1300    set(handles.Mask,'String',mask_displ)
1301    set(handles.Mask,'String',mask_displ)
1302    set(handles.Mask,'String',mask_displ)
1303end
1304
1305%------------------------------------------------------------------------
1306% --- Executes on button press in CheckMask: select box for mask option
1307function get_mask_civ2_Callback(hObject, eventdata, handles)
1308%------------------------------------------------------------------------
1309maskval=get(handles.CheckMask,'Value');
1310if isequal(maskval,0)
1311    set(handles.Mask,'String','')
1312else
1313    mask_displ='no mask'; %default
1314    filebase=get(handles.RootPath,'String');
1315    [nbslice, flag_mask]=get_mask(filebase,handles);
1316    if isequal(flag_mask,1)
1317        mask_displ=[num2str(nbslice) 'mask'];
1318    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1319        filebase_a=get(handles.RootFile_1,'String');
1320        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1321        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1322            mask_displ='no mask';
1323        end
1324    end
1325    if isequal(mask_displ,'no mask')
1326        [FileName, PathName, filterindex] = uigetfile( ...
1327            {'*.png', ' (*.png)';
1328            '*.png',  '.png files '; ...
1329            '*.*', 'All Files (*.*)'}, ...
1330            'Pick a mask file *.png',filebase);
1331        mask_displ=fullfile(PathName,FileName);
1332        if ~exist(mask_displ,'file')
1333            mask_displ='no mask';
1334        end
1335    end
1336    if isequal(mask_displ,'no mask')
1337        set(handles.CheckMask,'Value',0)
1338        set(handles.CheckMask,'Value',0)
1339    else
1340        set(handles.CheckMask,'Value',1)
1341    end
1342    set(handles.Mask,'String',mask_displ)
1343    set(handles.Mask,'String',mask_displ)
1344end
1345
1346%------------------------------------------------------------------------
1347% --- Executes on button press in CheckMask.
1348function get_mask_fix2_Callback(hObject, eventdata, handles)
1349%------------------------------------------------------------------------
1350maskval=get(handles.CheckMask,'Value');
1351if isequal(maskval,0)
1352    set(handles.Mask,'String','')
1353else
1354    mask_displ='no mask'; %default
1355    filebase=get(handles.RootPath,'String');
1356    [nbslice, flag_mask]=get_mask(filebase,handles);
1357    if isequal(flag_mask,1)
1358        mask_displ=[num2str(nbslice) 'mask'];
1359    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1360        filebase_a=get(handles.RootFile_1,'String');
1361        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1362        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1363            mask_displ='no mask';
1364        end
1365    end
1366    if isequal(mask_displ,'no mask')
1367        [FileName, PathName, filterindex] = uigetfile( ...
1368            {'*.png', ' (*.png)';
1369            '*.png',  '.png files '; ...
1370            '*.*', 'All Files (*.*)'}, ...
1371            'Pick a mask file *.png',filebase);
1372        mask_displ=fullfile(PathName,FileName);
1373        if ~exist(mask_displ,'file')
1374            mask_displ='no mask';
1375        end
1376    end
1377    if isequal(mask_displ,'no mask')
1378        set(handles.CheckMask,'Value',0)
1379    end
1380    set(handles.Mask,'String',mask_displ)
1381end
1382
1383%------------------------------------------------------------------------
1384% --- function called to look for mask files
1385function [nbslice, flag_mask]=get_mask(filebase,handles)
1386%------------------------------------------------------------------------
1387%detect mask files, images with appropriate file base
1388%[filebase '_' xx 'mask'], xx=nbslice
1389%flag_mask=1 indicates detection
1390
1391flag_mask=0;%default
1392nbslice=1;
1393
1394% subdir=get(handles.Civ1_ImageB,'String');
1395[Path,Name]=fileparts(filebase);
1396if ~isdir(Path)
1397    msgbox_uvmat('ERROR','no path for input files')
1398    return
1399end
1400% currentdir=pwd;
1401% cd(Path);%move in the dir of the root name filebase
1402maskfiles=dir(fullfile(Path,[Name '_*mask_*.png']));%look for mask files
1403% cd(currentdir);%come back to the current working directory
1404if ~isempty(maskfiles)
1405    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
1406    % else
1407    flag_mask=1;
1408    maskname=maskfiles(1).name;% take the first mask file in the list
1409    [Path2,Name,ext]=fileparts(maskname);
1410    Namedouble=double(Name);
1411    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1412    ind_mask=findstr('mask',Name);
1413    i=ind_mask-1;
1414    while val(i)==0 && i>0
1415        i=i-1;
1416    end
1417    nbslice=str2double(Name(i+1:ind_mask-1));
1418    if ~isnan(nbslice) && Name(i)=='_'
1419        flag_mask=1;
1420    else
1421        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
1422        return
1423        nbslice=1;
1424    end
1425end
1426
1427%------------------------------------------------------------------------
1428% --- function called to look for grid files
1429function [nbslice, flag_grid]=get_grid(filebase,handles)
1430%------------------------------------------------------------------------
1431flag_grid=0;%default
1432nbslice=1;
1433[Path,Name]=fileparts(filebase);
1434currentdir=pwd;
1435cd(Path);%move in the dir of the root name filebase
1436gridfiles=dir([Name '_*grid_*.grid']);%look for grid files
1437cd(currentdir);%come back to the current working directory
1438if ~isempty(gridfiles)
1439    flag_grid=1;
1440    gridname=gridfiles(1).name;% take the first grid file in the list
1441    [Path2,Name,ext]=fileparts(gridname);
1442    Namedouble=double(Name);
1443    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1444    ind_grid=findstr('grid',Name);
1445    i=ind_grid-1;
1446    while val(i)==0 && i>0
1447        i=i-1;
1448    end
1449    nbslice=str2double(Name(i+1:ind_grid-1));
1450    if ~isnan(nbslice) && Name(i)=='_'
1451        flag_grid=1;
1452    else
1453        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
1454        return
1455        nbslice=1;
1456    end
1457end
1458
1459%------------------------------------------------------------------------
1460% --- transform numbers to letters
1461function str=num2stra(num,nom_type)
1462%------------------------------------------------------------------------
1463if isempty(nom_type)
1464    str='';
1465elseif strcmp(nom_type(end),'a')
1466    str=char(96+num);
1467elseif strcmp(nom_type(end),'A')
1468    str=char(96+num);
1469elseif isempty(nom_type(2:end))%a single index
1470    str='';
1471else
1472    str=num2str(num);
1473end
1474
1475% %------------------------------------------------------------------------
1476% % --- Executes on button press in ListSubdirCiv1.
1477% function ListSubdirCiv1_Callback(hObject, eventdata, handles)
1478% %------------------------------------------------------------------------
1479% list_subdir_civ1=get(handles.ListSubdirCiv1,'String');
1480% val=get(handles.ListSubdirCiv1,'Value');
1481% SubDir=list_subdir_civ1{val};
1482% if strcmp(SubDir,'new...')
1483%     if get(handles.CheckCiv1,'Value')
1484%         SubDir='CIV_INPUT'; %default subdirectory
1485%     else
1486%         msgbox_uvmat('ERROR','select CheckCiv1 to perform a new civ_input operation')
1487%         return
1488%     end   
1489% end
1490% set(handles.Civ1_ImageB,'String',SubDir);
1491% errormsg=find_netcpair_civ(handles,1);
1492% if ~isempty(errormsg)
1493%     msgbox_uvmat('ERROR',errormsg)
1494% end
1495%     
1496%------------------------------------------------------------------------
1497% % --- Executes on button press in ListSubdirCiv2.
1498% function ListSubdirCiv2_Callback(hObject, eventdata, handles)
1499% %------------------------------------------------------------------------
1500% list_subdir_civ2=get(handles.ListSubdirCiv2,'String');
1501% val=get(handles.ListSubdirCiv2,'Value');
1502% SubDir=list_subdir_civ2{val};
1503% if strcmp(SubDir,'new...')
1504%     if get(handles.CheckCiv2,'Value')
1505%         SubDir='CIV_INPUT'; %default subdirectory
1506%     else
1507%         msgbox_uvmat('ERROR','select CheckCiv2 to perform a new civ_input operation')
1508%         return
1509%     end
1510% end
1511% set(handles.Civ2_ImageA,'String',SubDir);
1512
1513%------------------------------------------------------------------------
1514% --- Executes on button press in CheckGrid.
1515function CheckGrid_Callback(hObject, eventdata, handles)
1516%------------------------------------------------------------------------
1517value=get(hObject,'Value');
1518hparent=get(hObject,'parent');%handles of the parent panel
1519hchildren=get(hparent,'children');
1520handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel
1521handle_dx=findobj(hchildren,'tag','num_Dx');
1522handle_dy=findobj(hchildren,'tag','num_Dy');
1523handle_title_dx=findobj(hchildren,'tag','title_Dx');
1524handle_title_dy=findobj(hchildren,'tag','title_Dy');
1525testgrid=0;
1526filegrid='';
1527if value
1528        hseries=findobj(allchild(0),'Tag','series');
1529    hhseries=guidata(hseries);
1530    InputTable=get(hhseries.InputTable,'Data');
1531     ind_A=1;% line index of the (first) image series
1532    if strcmp(InputTable{1,5},'.nc');
1533        ind_A=2;
1534    end
1535    filebase=InputTable{ind_A,1};
1536    [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name
1537    if isequal(flag_grid,1)
1538        filegrid=[num2str(nbslice) 'grid'];
1539        testgrid=1;
1540    else % browse for a grid
1541        filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData
1542        if exist(filegrid,'file')
1543            filebase=filegrid;
1544        end
1545       filegrid = uigetfile_uvmat('pick a grid file .grid:',filebase,'.grid');
1546        set(hObject,'UserData',filegrid);%store for future use
1547        if ~isempty(filegrid)
1548            testgrid=1;
1549        end
1550        set(hObject,'UserData',filegrid);%store for future use
1551    end
1552end
1553if testgrid
1554    set(handle_dx,'Visible','off');
1555    set(handle_dy,'Visible','off');
1556    set(handle_title_dy,'Visible','off');
1557    set(handle_title_dx,'Visible','off');
1558    set(handle_txtbox,'Visible','on')
1559    set(handle_txtbox,'String',filegrid)
1560else
1561    set(hObject,'Value',0);
1562    set(handle_dx,'Visible','on');
1563    set(handle_dy,'Visible','on');
1564    set(handle_title_dy,'Visible','on');
1565    set(handle_title_dx,'Visible','on');
1566    set(handle_txtbox,'Visible','off')
1567end
1568
1569%% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
1570PanelName=get(hparent,'tag');
1571if strcmp(PanelName,'Civ1')
1572    hchildren=get(handles.Civ2,'children');
1573    handle_checkbox=findobj(hchildren,'tag','CheckGrid');
1574    handle_txtbox=findobj(hchildren,'tag','Grid');
1575    handle_dx=findobj(hchildren,'tag','num_Dx');
1576    handle_dy=findobj(hchildren,'tag','num_Dy');
1577    handle_title_dx=findobj(hchildren,'tag','title_Dx');
1578    handle_title_dy=findobj(hchildren,'tag','title_Dy');
1579    set(handle_checkbox,'UserData',filegrid);%store for future use
1580    if testgrid
1581        set(handle_checkbox,'Value',1);
1582        set(handle_dx,'Visible','off');
1583        set(handle_dy,'Visible','off');
1584        set(handle_title_dx,'Visible','off');
1585        set(handle_title_dy,'Visible','off');
1586        set(handle_txtbox,'Visible','on')
1587        set(handle_txtbox,'String',filegrid)
1588    end
1589end
1590
1591%------------------------------------------------------------------------
1592% --- Executes on button press in CheckMask: common to all panels (civ1, Civ2..)
1593function CheckMask_Callback(hObject, eventdata, handles)
1594%------------------------------------------------------------------------
1595value=get(hObject,'Value');
1596hparent=get(hObject,'parent');
1597parent_tag=get(hparent,'Tag');
1598hchildren=get(hparent,'children');
1599handle_txtbox=findobj(hchildren,'tag','Mask');% look for the mask name box in the same panel
1600
1601testmask=0;
1602if value
1603    hseries=findobj(allchild(0),'Tag','series');
1604    hhseries=guidata(hseries);
1605    InputTable=get(hhseries.InputTable,'Data');
1606     ind_A=1;% line index of the (first) image series
1607    if strcmp(InputTable{1,5},'.nc');
1608        ind_A=2;
1609    end
1610    [nbslice, flag_mask]=get_mask(InputTable{ind_A,1},handles);% look for a mask with appropriate name
1611    if isequal(flag_mask,1)
1612        filemask=[num2str(nbslice) 'mask'];
1613        testmask=1;
1614    else % browse for a mask
1615        filemask=get(hObject,'UserData');%look for previous mask name stored as UserData
1616        if exist(filemask,'file')
1617            filebase=filemask;
1618        end
1619        filemask= uigetfile_uvmat('pick a mask image file:',InputTable{ind_A,1},'image');
1620        set(hObject,'UserData',filemask);%store for future use
1621        if ~isempty(filemask)
1622            testmask=1;
1623        end
1624    end
1625end
1626if testmask
1627    if strcmp(parent_tag,'Civ1')
1628        set(handles.Mask,'Visible','on')
1629        set(handles.Mask,'String',filemask)
1630    set(handles.CheckMask,'Value',1)
1631    end
1632else
1633    set(hObject,'Value',0);
1634    set(handle_txtbox,'Visible','off')
1635end
1636
1637%------------------------------------------------------------------------
1638% --- Executes on button press in get_gridpatch1.
1639function get_gridpatch1_Callback(hObject, eventdata, handles)
1640%------------------------------------------------------------------------
1641filebase=get(handles.RootPath,'String');
1642[FileName, PathName, filterindex] = uigetfile( ...
1643    {'*.grid', ' (*.grid)';
1644    '*.grid',  '.grid files '; ...
1645    '*.*', 'All Files (*.*)'}, ...
1646    'Pick a file',filebase);
1647filegrid=fullfile(PathName,FileName);
1648set(handles.grid_patch1,'string',filegrid);
1649
1650
1651%------------------------------------------------------------------------
1652% --- Executes on button press in get_gridpatch2.
1653function get_gridpatch2_Callback(hObject, eventdata, handles)
1654%------------------------------------------------------------------------
1655
1656
1657%------------------------------------------------------------------------
1658% --- STEREO Interp
1659function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
1660%------------------------------------------------------------------------
1661namelog=[filename_nc(1:end-3) '_stinterp.log'];
1662cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
1663    ' -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
1664
1665% %------------------------------------------------------------------------
1666% %--read images and convert them to the uint16 format used for PIV
1667% function A=read_image(filename,type_ima,num,movieobject)
1668% %------------------------------------------------------------------------
1669% %num is the view number needed for an avi movie
1670% switch type_ima
1671%     case 'movie'
1672%         A=read(movieobject,num);
1673%     case 'avi'
1674%         mov=aviread(filename,num);
1675%         A=frame2im(mov(1));
1676%     case 'multimage'
1677%         A=imread(filename,num);
1678%     case 'image'
1679%         A=imread(filename);
1680% end
1681% siz=size(A);
1682% if length(siz)==3;%color images
1683%     A=sum(double(A),3);
1684%     A=uint16(A);
1685% end
1686
1687
1688%------------------------------------------------------------------------
1689% --- Executes on button press in get_ref_fix1.
1690function get_ref_fix1_Callback(hObject, eventdata, handles)
1691%------------------------------------------------------------------------
1692filebase=get(handles.RootPath,'String');
1693[FileName, PathName, filterindex] = uigetfile( ...
1694    {'*.nc', ' (*.nc)';
1695    '*.nc',  'netcdf files '; ...
1696    '*.*', 'All Files (*.*)'}, ...
1697    'Pick a file',filebase);
1698
1699fileinput=[PathName FileName];
1700sizf=size(fileinput);
1701if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1702%[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1703[Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1704ref.filebase=fullfile(Path,File);
1705% ref.num_a=stra2num(str_a);
1706% ref.num_b=stra2num(str_b);
1707% ref.num1=str2double(field_count);
1708% ref.num2=str2double(str2);
1709browse=[];%initialisation
1710if ~isequal(ref.ext,'.nc')
1711    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1712    return
1713end
1714set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
1715set(handles.ref_fix1,'UserData',ref)
1716menu_field{1}='civ1';
1717Data=nc2struct(fileinput,[]);
1718if isfield(Data,'patch') && isequal(Data.patch,1)
1719    menu_field{2}='filter1';
1720end
1721if isfield(Data,'civ2') && isequal(Data.civ2,1)
1722    menu_field{3}='civ2';
1723end
1724if isfield(Data,'patch2') && isequal(Data.patch2,1)
1725    menu_field{4}='filter2';
1726end
1727set(handles.field_ref1,'String',menu_field);
1728set(handles.field_ref1,'Value',length(menu_field));
1729set(handles.num_MinVel,'Value',2);
1730set(handles.num_MinVel,'String','1');%default threshold
1731set(handles.ref_fix1,'Enable','on')
1732
1733%------------------------------------------------------------------------
1734% --- Executes on button press in get_ref_fix2.
1735function get_ref_fix2_Callback(hObject, eventdata, handles)
1736%------------------------------------------------------------------------
1737if isequal(get(handles.get_ref_fix2,'Value'),1)
1738    filebase=get(handles.RootPath,'String');
1739    [FileName, PathName, filterindex] = uigetfile( ...
1740        {'*.nc', ' (*.nc)';
1741        '*.nc',  'netcdf files '; ...
1742        '*.*', 'All Files (*.*)'}, ...
1743        'Pick a file',filebase);
1744    fileinput=[PathName FileName];
1745    sizf=size(fileinput);
1746    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1747    %[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1748    [Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1749    ref.filebase=fullfile(Path,File);
1750    %     ref.num_a=stra2num(str_a);
1751    %     ref.num_b=stra2num(str_b);
1752    %     ref.num1=str2num(field_count);
1753    %     ref.num2=str2num(str2);
1754    browse=[];%initialisation
1755    if ~isequal(ref.ext,'.nc')
1756        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1757        return
1758    end
1759    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
1760    set(handles.ref_fix2,'UserData',ref)
1761    menu_field{1}='civ1';
1762    Data=nc2struct(fileinput,[]);
1763    if isfield(Data,'patch') && isequal(Data.patch,1)
1764        menu_field{2}='filter1';
1765    end
1766    if isfield(Data,'civ2') && isequal(Data.civ2,1)
1767        menu_field{3}='civ2';
1768    end
1769    if isfield(Data,'patch2') && isequal(Data.patch2,1)
1770        menu_field{4}='filter2';
1771    end
1772    set(handles.field_ref2,'String',menu_field);
1773    set(handles.field_ref2,'Value',length(menu_field));
1774    set(handles.num_MinVel,'Value',2);
1775    set(handles.num_MinVel,'String','1');%default threshold
1776    set(handles.ref_fix2,'Enable','on')
1777    set(handles.ref_fix2,'Visible','on')
1778    set(handles.field_ref2,'Visible','on')
1779else
1780    set(handles.ref_fix2,'Visible','off')
1781    set(handles.field_ref2,'Visible','off')
1782end
1783
1784%------------------------------------------------------------------------
1785function ref_fix1_Callback(hObject, eventdata, handles)
1786%------------------------------------------------------------------------
1787set(handles.num_MinVel,'Value',1);
1788set(handles.field_ref1,'Value',1)
1789set(handles.field_ref1,'String',{' '})
1790set(handles.ref_fix1,'UserData',[]);
1791set(handles.ref_fix1,'String','');
1792set(handles.thresh_vel1,'String','0');
1793
1794%------------------------------------------------------------------------
1795function ref_fix2_Callback(hObject, eventdata, handles)
1796%------------------------------------------------------------------------
1797set(handles.num_MinVel,'Value',1);
1798set(handles.field_ref2,'Value',1)
1799set(handles.field_ref2,'String',{' '})
1800set(handles.ref_fix2,'UserData',[]);
1801set(handles.ref_fix2,'String','');
1802set(handles.num_MinVel,'String','0');
1803
1804%------------------------------------------------------------------------
1805% --- TO ABANDON Executes on button press in test_stereo1.
1806function CheckStereo_Callback(hObject, eventdata, handles)
1807%------------------------------------------------------------------------
1808hparent=get(hObject,'parent');
1809parent_tag=get(hparent,'Tag');
1810hchildren=get(hparent,'children');
1811handle_txtbox=findobj(hchildren,'tag','txt_Mask');
1812if isequal(get(hObject,'Value'),0)
1813    set(handles.num_SubDomainSize,'Visible','on')
1814    set(handles.num_FieldSmooth,'Visible','on')
1815else
1816    set(handles.num_SubDomainSize,'Visible','off')
1817    set(handles.num_FieldSmooth,'Visible','off')
1818end
1819
1820% %------------------------------------------------------------------------
1821% % --- Executes on button press in CheckStereo.
1822% function StereoCheck_Callback(hObject, eventdata, handles)
1823% %------------------------------------------------------------------------
1824% if isequal(get(handles.CheckStereo,'Value'),0)
1825%     set(handles.num_subdomainsize,'Visible','on')
1826%     set(handles.num_FieldSmooth,'Visible','on')
1827% else
1828
1829%     set(handles.num_subdomainsize,'Visible','off')
1830%     set(handles.num_FieldSmooth,'Visible','off')
1831% end
1832
1833%------------------------------------------------------------------------
1834% --- Executes on button press in TestCiv1: prepare the image correlation function
1835% activated by mouse motion
1836function TestCiv1_Callback(hObject, eventdata, handles)
1837%------------------------------------------------------------------------
1838drawnow
1839if get(handles.TestCiv1,'Value')
1840    set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch
1841    ref_i=str2double(get(handles.ref_i,'String'));% read reference i index
1842    if strcmp(get(handles.ref_j,'Visible'),'on')
1843        ref_j=str2double(get(handles.ref_j,'String'));% read reference j index if relevant
1844    else
1845        ref_j=1;%default j index
1846    end
1847    % [filecell,i1,i2]=set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0]);% get the corresponding file name and indices
1848    Data.ListVarName={'ny','nx','A'};
1849    Data.VarDimName= {'ny','nx',{'ny','nx'}};
1850    hseries=findobj(allchild(0),'Tag','series');
1851    hhseries=guidata(hseries);
1852    InputTable=get(hhseries.InputTable,'Data');
1853    ind_A=1;
1854    if strcmp(InputTable{1,5},'.nc');
1855        ind_A=2;
1856    end
1857    list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
1858    PairString=list_pair{get(handles.ListPairCiv1,'Value')};
1859    %    [i1_series_Civ1,i2_series_Civ1,j1_series_Civ1,j2_series_Civ1,check_bounds,NomTypeNc]=...
1860    %       find_pair_indices(PairCiv1,i_series{1},j_series{1},MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j);
1861    [ind1,ind2,mode]=find_pair_indices(PairString,ref_i,ref_j)%,MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j)
1862    switch mode
1863        case 'Di'
1864            i1=ref_i+ind1;
1865            i2=ref_i+ind2;
1866                        j1=ref_j;
1867            j2=ref_j;
1868        case 'Dj'
1869                           i1=ref_i;
1870            i2=ref_i;
1871                        j1=ref_j+ind1;
1872            j2=ref_j+ind2;
1873        case 'burst'
1874
1875                           i1=ref_i;
1876            i2=ref_i;
1877                        j1=ind1;
1878            j2=ind2;
1879    end
1880    ImageName_A=fullfile_uvmat(InputTable{ind_A,1},InputTable{ind_A,2},InputTable{ind_A,3},InputTable{ind_A,5},InputTable{ind_A,4},...
1881        i1,[],j1);
1882        ImageName_B=fullfile_uvmat(InputTable{ind_A,1},InputTable{ind_A,2},InputTable{ind_A,3},InputTable{ind_A,5},InputTable{ind_A,4},...
1883        i2,[],j2);
1884    Data.A=imread(ImageName_A); % read the first image
1885    if ndims(Data.A)==3 %case of color image
1886        Data.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
1887    end
1888    Data.ny=[size(Data.A,1) 1];
1889    Data.nx=[1 size(Data.A,2)];
1890    Data.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
1891    par_civ1=read_GUI(handles.Civ1);
1892    par_civ1.FileTypeA=get_file_type(ImageName_A);
1893    par_civ1.ImageWidth=size(Data.A,2);
1894    par_civ1.ImageHeight=size(Data.A,1);
1895    par_civ1.Mask='all';% will provide only the grid set for PIV, no image correlation
1896    par_civ1.FrameIndexA=num2str(i1);
1897    par_civ1.FrameIndexB=num2str(i2);
1898    Param.Civ1=par_civ1;
1899    Grid=civ_matlab(Param);% get the grid of x, y positions set for PIV
1900    hview_field=view_field(Data); %view the image in the GUI view_field
1901    set(0,'CurrentFigure',hview_field)
1902    hhview_field=guihandles(hview_field);
1903    set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
1904    ViewData=get(hview_field,'UserData');
1905    ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
1906    ViewData.PlotAxes.B=imread(ImageName_B);%store the second image in the UserData of the GUI view_field
1907    ViewData.PlotAxes.X=Grid.Civ1_X; %keep the set of points in memeory
1908    ViewData.PlotAxes.Y=Grid.Civ1_Y;
1909    set(hview_field,'UserData',ViewData)
1910    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1911    if isempty(corrfig)
1912        corrfig=figure;
1913        set(corrfig,'tag','corrfig')
1914        set(corrfig,'name','image correlation')
1915        set(corrfig,'DeleteFcn',{@closeview_field})%
1916        % end
1917        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
1918    else
1919        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
1920        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1921        if ~isempty(corrfig)
1922            delete(corrfig)
1923        end
1924        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1925        if ~isempty(hview_field)
1926            delete(hview_field)
1927        end
1928    end
1929end
1930
1931%------------------------------------------------------------------------
1932%----function introduced for the correlation window figure, activated by deleting this window
1933function closeview_field(gcbo,eventdata)
1934%------------------------------------------------------------------------
1935hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1936if ~isempty(hview_field)
1937    delete(hview_field)
1938end
1939
1940%------------------------------------------------------------------------
1941% --- Executes on button press in CheckThreshold.
1942function CheckThreshold_Callback(hObject, eventdata, handles)
1943%------------------------------------------------------------------------
1944huipanel=get(hObject,'parent');
1945obj(1)=findobj(huipanel,'Tag','num_MinIma');
1946obj(2)=findobj(huipanel,'Tag','num_MaxIma');
1947obj(3)=findobj(huipanel,'Tag','title_Threshold');
1948if get(hObject,'Value')
1949    set(obj,'Visible','on')
1950else
1951    set(obj,'Visible','off')
1952end
1953
1954
1955
1956
1957%'nomtype2pair': creates nomencalture for index pairs knowing the image nomenclature
1958%---------------------------------------------------------------------
1959function NomTypeNc=nomtype2pair(NomTypeIma,mode)
1960%---------------------------------------------------------------------           
1961% OUTPUT:
1962% NomTypeNc
1963%---------------------------------------------------------------------
1964% INPUT:
1965% 'NomTypeIma': string defining the kind of nomenclature used for images
1966
1967NomTypeNc=NomTypeIma;%default
1968switch mode
1969    case 'pair j1-j2'     
1970    if ~isempty(regexp(NomTypeIma,'a$'))
1971        NomTypeNc=[NomTypeIma 'b'];
1972    elseif ~isempty(regexp(NomTypeIma,'A$'))
1973        NomTypeNc=[NomTypeIma 'B'];
1974    else
1975        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
1976        if ~isempty(r)
1977            NomTypeNc='_1_1-2';
1978        end
1979    end
1980    case 'series(Dj)' 
1981%         r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
1982%         if ~isempty(r)
1983            NomTypeNc='_1_1-2';
1984%         end
1985   case 'series(Di)'
1986        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
1987        if ~isempty(r)
1988            NomTypeNc='_1-2_1';
1989        else
1990            NomTypeNc='_1-2';
1991        end
1992end
1993
1994% --- Executes on button press in TestPatch1.
1995function TestPatch1_Callback(hObject, eventdata, handles)
1996set(handles.TestPatch1,'BackgroundColor',[1 1 0])
1997drawnow
1998if get(handles.TestPatch1,'Value')
1999    ref_i=str2double(get(handles.ref_i,'String'));
2000    if strcmp(get(handles.ref_j,'Visible'),'on')
2001        ref_j=str2double(get(handles.ref_j,'String'));
2002    else
2003        ref_j=1;%default
2004    end
2005    filecell=set_civ_filenames(handles,ref_i,ref_j,[0 0 1 0 0 0]);   
2006    Data.ListVarName={'ny','nx','A'};
2007    Data.VarDimName= {'ny','nx',{'ny','nx'}};   
2008    param_patch1=read_GUI(handles.Patch1);
2009    param_patch1.CivFile=filecell.nc.civ1{1};
2010    Param.Patch1=param_patch1;
2011    for irho=1:7
2012        [Data,errormsg]=civ_matlab(Param);% get the grid of x, y positions set for PIV
2013        if ~isempty(errormsg)
2014            msgbox_uvmat('ERROR',errormsg)
2015            return
2016        end
2017        SmoothingParam(irho)=Param.Patch1.FieldSmooth;
2018        Data.Civ1_U_Diff=Data.Civ1_U_Diff(Data.Civ1_FF==0);
2019        Data.Civ1_V_Diff=Data.Civ1_V_Diff(Data.Civ1_FF==0);
2020        DiffVel(irho)=sqrt(mean(Data.Civ1_U_Diff.*Data.Civ1_U_Diff+Data.Civ1_V_Diff.*Data.Civ1_V_Diff));
2021        NbSites(irho,:)=Data.Civ1_NbSites*numel(Data.Civ1_NbSites)/numel(Data.Civ1_U_Diff);
2022        Param.Patch1.SmoothingParam=2*Param.Patch1.FieldSmooth;
2023    end
2024    figure
2025    plot(SmoothingParam,DiffVel,'b',SmoothingParam,NbSites,'r')
2026    set(handles.TestPatch1,'BackgroundColor',[1 0 0])
2027else
2028    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
2029    if ~isempty(corrfig)
2030        delete(corrfig)
2031    end
2032    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
2033    if ~isempty(hview_field)
2034        delete(hview_field)
2035    end
2036end
2037
2038
2039% --- Executes on button press in TestCiv2.
2040function TestCiv2_Callback(hObject, eventdata, handles)
2041
2042
2043
2044function num_OriginIndex_Callback(hObject, eventdata, handles)
2045% hObject    handle to num_OriginIndex (see GCBO)
2046% eventdata  reserved - to be defined in a future version of MATLAB
2047% handles    structure with handles and user data (see GUIDATA)
2048
2049% Hints: get(hObject,'String') returns contents of num_OriginIndex as text
2050%        str2double(get(hObject,'String')) returns contents of num_OriginIndex as a double
2051
2052
2053% --- Executes during object creation, after setting all properties.
2054function num_OriginIndex_CreateFcn(hObject, eventdata, handles)
2055% hObject    handle to num_OriginIndex (see GCBO)
2056% eventdata  reserved - to be defined in a future version of MATLAB
2057% handles    empty - handles not created until after all CreateFcns called
2058
2059% Hint: edit controls usually have a white background on Windows.
2060%       See ISPC and COMPUTER.
2061if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2062    set(hObject,'BackgroundColor','white');
2063end
2064
2065%------------------------------------------------------------------------
2066% --- determine the list of index pairs of processing file
2067function [ind1,ind2,mode]=...
2068    find_pair_indices(str_civ,i_series,j_series,MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j)
2069%------------------------------------------------------------------------
2070% i1_series=i_series;% set of first image indexes
2071% i2_series=i_series;
2072% j1_series=ones(size(i_series));% set of first image numbers
2073% j2_series=ones(size(i_series));
2074% check_bounds=false(size(i_series));
2075ind1='';
2076ind2='';
2077r=regexp(str_civ,'^\D(?<ind>[i|j])=( -| )(?<num1>\d+)\|(?<num2>\d+)','names');
2078if ~isempty(r)
2079    mode=['D' r.ind];
2080    ind1=stra2num(r.num1);
2081    ind2=stra2num(r.num2);
2082else
2083    mode='burst';
2084    r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names');
2085    if ~isempty(r)
2086        NomTypeNc='_1ab';
2087    else
2088        r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names');
2089        if ~isempty(r)
2090            NomTypeNc='_1AB';
2091        else
2092            r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names');
2093            if ~isempty(r)
2094                NomTypeNc='_1_1-2';
2095            end           
2096        end
2097    end
2098    if isempty(r)
2099        display('wrong pair mode input option')
2100    else
2101    ind1=stra2num(r.num1);
2102    ind2=stra2num(r.num2);
2103    end
2104end
2105% if strcmp (mode,'Di')
2106%     i1_series=i_series-ind1;% set of first image numbers
2107%     i2_series=i_series+ind2;
2108%      check_bounds=i1_series<MinIndex_i | i2_series>MaxIndex_i;
2109%     if isempty(j_series)
2110%         NomTypeNc='_1-2';
2111%     else
2112%         j1_series=j_series;
2113%         j2_series=j_series;
2114%         NomTypeNc='_1-2_1';
2115%     end
2116% elseif strcmp (mode,'Dj')
2117%     j1_series=j_series-ind1;
2118%     j2_series=j_series+ind2;
2119%     check_bounds=j1_series<MinIndex_j | j2_series>MaxIndex_j;
2120%     NomTypeNc='_1_1-2';
2121% else  %bursts
2122%     j1_series=ind1*ones(size(i_series));
2123%     j2_series=ind2*ones(size(i_series));
2124% end
Note: See TracBrowser for help on using the repository browser.