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

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

civ_input improved and small bug corrections

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