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

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

various bugs corrected after tests with Windows OS.

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