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

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

various bug corrections. Steps further for civ_series (still development needed)

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