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

Last change on this file since 603 was 603, checked in by sommeria, 8 years ago

bugs corrected, improvement of civ_input GUI

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