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

Last change on this file since 1169 was 1169, checked in by sommeria, 8 weeks ago

civ3 introduced

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