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

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

bugs corrected in series, ima_levels cleaned as exemple

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