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

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

civ_series cleaned. Introduction of a nc file as input (to further debug)

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