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

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

various bug fix

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