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

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

read_rdvision corrected

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