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

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

a few bugs corrected

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