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

Last change on this file since 774 was 774, checked in by sommeria, 10 years ago

bug corrected in sub_background. test_patch1 introduced in civ_series

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