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

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

bug corrected in civ_input

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