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

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

bugs corrected for mask

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