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

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

bug on waitbar corrected for background mode

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