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

Last change on this file since 647 was 647, checked in by sommeria, 11 years ago

bug corrected in time_series, LIF functions introduced (but not in operation)

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