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

Last change on this file since 824 was 824, checked in by sommeria, 9 years ago

message

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