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

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

various bugs corrected. Introduction of campaign lists in Open menu

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