source: trunk/src/civ.m @ 134

Last change on this file since 134 was 134, checked in by gostiaux, 13 years ago

fonction super_cmd ajoutés pour un run en background; a tester sous windows.
.log pour civ2 ajouté

File size: 181.6 KB
Line 
1%'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)
2%------------------------------------------------------------------------
3%  provides an interface for the software CIVx
4% function varargout = civ(varargin)
5% provides an interface for the software CIVx
6%
7%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
8%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
9%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
10%     This file is part of the toolbox UVMAT.
11%
12%     UVMAT is free software; you can redistribute it and/or modify
13%     it under the terms of the GNU General Public License as published by
14%     the Free Software Foundation; either version 2 of the License, or
15%     (at your option) any later version.
16%
17%     UVMAT is distributed in the hope that it will be useful,
18%     but WITHOUT ANY WARRANTY; without even the implied warranty of
19%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
21%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
22function varargout = civ(varargin)
23
24% Last Modified by GUIDE v2.5 27-Mar-2010 13:41:11
25% Begin initialization code - DO NOT EDIT
26gui_Singleton = 1;
27gui_State = struct('gui_Name',       mfilename, ...
28    'gui_Singleton',  gui_Singleton, ...
29    'gui_OpeningFcn', @civ_OpeningFcn, ...
30    'gui_OutputFcn',  @civ_OutputFcn, ...
31    'gui_LayoutFcn',  [] , ...
32    'gui_Callback',   []);
33if nargin && ischar(varargin{1})
34    gui_State.gui_Callback = str2func(varargin{1});
35end
36
37if nargout
38    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
39else
40    gui_mainfcn(gui_State, varargin{:});
41end
42% End initialization code - DO NOT EDIT
43
44%------------------------------------------------------------------------
45% --- Executes just before civ is made visible.
46function civ_OpeningFcn(hObject, eventdata, handles, param)
47%------------------------------------------------------------------------
48% This function has no output args, see OutputFcn.
49% hObject    handle to figure
50% eventdata  reserved - to be defined in a future version of MATLAB
51% handles    structure with handles and user data (see GUIDATA)
52% varargin   command line arguments to civ (see VARARGIN)
53global patch_newBin %=1 if new patch processing available
54%filebase: root name
55%nom_type: nomencalture used ('png_old','_i_j'...)
56%list of field numbers to process
57%subdir: subdirectory of the opened netcdf file
58%ind_opening: operation number advised for beginning (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2),
59%ind_a_opening ind_b_opening chosen pair from the opened netcdf file
60% Choose default command line output for civ
61handles.output = hObject;
62% Update handles structure
63guidata(hObject, handles);
64
65%default initial parameters
66filebase=''; % root file name ('filebase'.civ)
67ext=[];
68testall=0;
69%default input parameters:
70num1=1; % set of field i numbers
71num2=1; % set of field i numbers
72num_a=1; % set of field j numbers (fields a)
73num_b=1; % second set of field j numbers (fields b)
74subdir='A'; % subdir for the netcdf result files
75ind_opening=1; % proposed operation number (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2)
76%load the initial parameters if the interface is started from uvmat
77if exist('param','var')&&isstruct(param)% the interface is opened from uvmat
78    filebase=param.RootName;
79    nom_type_read=param.NomType;
80    num1=param.num1;
81    num2=param.num2;
82    num_a=param.num_a;
83    num_b=param.num_b;
84    subdir=param.SubDir;
85    ind_opening=param.IndOpening;
86    ext=param.ImaExt;
87end
88browse.num_i1=num1;
89browse.num_i2=num2;
90browse.num_j1=num_a;
91browse.num_j2=num_b;
92if ~isempty(ext) && (~isempty(imformats(ext(2:end)))||strcmpi(ext,'.avi'));%if an image file has been opened by uvmat
93    set(handles.ImaExt,'String',ext)
94    browse.ext_ima=ext;
95    if exist('nom_type_read','var')
96        browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
97    end
98elseif isequal(ext,'.nc')
99    if exist('nom_type_read','var')
100        browse.nom_type_nc=nom_type_read;% the netcdf  nomenclature is stored
101    end
102end
103set(handles.RootName,'String',filebase);
104set(handles.ImaDoc,'UserData',testall);
105set(handles.ImaDoc,'String',ext)
106
107%read names of the .exe file to adjust the interface according to available binaries
108path_uvmat=which('uvmat');% check the path detected for source file uvmat
109path_UVMAT=fileparts(path_uvmat); %path to UVMAT
110errormsg=[];%default error message
111% xmlfile=fullfile(path_UVMAT,'PARAM.xml');
112% if ~exist(xmlfile,'file')
113xmlfile='PARAM.xml';
114% end
115if exist(xmlfile,'file')
116    try
117        t=xmltree(xmlfile);
118        sparam=convert(t);
119    catch
120        errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr};
121    end
122else
123    errormsg=[xmlfile ' not found: path to civx binaries undefined'];
124end
125
126
127if ~isempty(errormsg)
128    msgbox_uvmat('ERROR',errormsg);
129end
130% patch_newBin='';
131test_batch=0;%default: ,no batch mode available
132if isfield(sparam,'BatchParam') && isfield(sparam.BatchParam,'BatchMode')
133    test_batch=strcmp(sparam.BatchParam.BatchMode,'sge'); %sge is currently the only implemented batch mod
134end
135if test_batch==0
136    set(handles.BATCH,'Enable','off')% put the BATCH button in grey (unactivated)
137    set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
138end
139if isfield(sparam.RunParam,'CivBin')
140    if ~exist(sparam.RunParam.CivBin,'file')
141        sparam.RunParam.CivBin=fullfile(path_UVMAT,sparam.RunParam.CivBin);
142    end
143else
144    sparam.RunParam.CivBin='';
145end
146patch_newBin=exist(sparam.RunParam.CivBin,'file');
147set(handles.subdir_civ1,'String',subdir)%default subdir on which uvmat was working
148set(handles.subdir_civ2,'String',subdir)%default subdir on which uvmat was working
149
150%initiate advised operations
151if isequal(ind_opening,[])
152    ind_opening=1; % default
153end
154% set default operation options
155enable_civ1(handles,'off')
156enable_civ2(handles,'off')
157enable_pair1(handles,'on')
158enable_fix1(handles,'off')
159desable_patch1(handles)
160desable_fix2(handles)
161desable_patch2(handles)
162set(handles.CIV1,'Value',0)
163set(handles.FIX1,'Value',0)
164set(handles.PATCH1,'Value',0)
165set(handles.CIV2,'Value',0)
166set(handles.FIX2,'Value',0)
167set(handles.PATCH2,'Value',0)
168set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
169if isequal(ind_opening,1)
170    set(handles.CIV1,'Value',1)
171    enable_civ1(handles,'on')
172elseif isequal(ind_opening,2)
173    set(handles.FIX1,'Value',1)
174    enable_fix1(handles,'on')
175elseif isequal(ind_opening,3)
176    set(handles.PATCH1,'Value',1)
177    enable_patch1(handles)
178elseif isequal(ind_opening,4)
179    set(handles.CIV2,'Value',1)
180    enable_civ2(handles,1)
181elseif isequal(ind_opening,5)
182    set(handles.FIX2,'Value',1)
183    enable_fix2(handles)
184    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
185    set(handles.list_pair_civ2,'Enable','On')
186    set(handles.list_pair_civ2,'Enable','On')
187    enable_pair1(handles,'off')
188elseif isequal(ind_opening,6)
189    set(handles.PATCH2,'Value',1)
190    enable_patch2(handles)
191    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
192    set(handles.list_pair_civ2,'Enable','On')
193    enable_pair1(handles,'off')
194end
195
196% set the range of fields (1:1 by default) and selected pair
197if isnan(num2)||isequal(num2,num1)
198    num_ref_i=num1;
199else
200    num_ref_i=floor((num1+num2)/2);
201    browse.incr_pair(1)=num2-num1;
202    browse.incr_pair(2)=0;
203end
204if isnan(num_b)||isequal(num_a,num_b)
205    if isnan(num_a)
206        num_ref_j=1;
207    else
208        num_ref_j=num_a;
209    end
210else
211    num_ref_j=floor((num_a+num_b)/2);
212    browse.incr_pair(2)=num_b-num_a;
213end
214set(handles.first_i,'String',num2str(num_ref_i));
215set(handles.last_i,'String',num2str(num_ref_i));
216set(handles.first_j,'String',num2str(num_ref_j));
217set(handles.last_j,'String',num2str(num_ref_j));
218set(handles.ref_i,'String',num2str(num_ref_i));
219set(handles.ref_j,'String',num2str(num_ref_j));
220set(handles.ref_i_civ2,'String',num2str(num_ref_i));
221set(handles.ref_j_civ2,'String',num2str(num_ref_j));
222set(handles.browse_root,'UserData',browse);
223if exist('param','var')%varargin the interface is opened from uvmat
224    RootName_Callback(hObject, eventdata, handles);
225end
226
227set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
228set(handles.waitbar_patch1,'Position',[0.946 0.626 0.03 0.001])
229set(handles.waitbar_civ2,'Position',[0.946 0.406 0.03 0.001])
230set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
231
232%------------------------------------------------------------------------
233% --- Outputs from this function are returned to the command line.
234function varargout = civ_OutputFcn(hObject, eventdata, handles)
235%------------------------------------------------------------------------
236% varargout  cell array for returning output args (see VARARGOUT);
237% hObject    handle to figure
238% eventdata  reserved - to be defined in a future version of MATLAB
239% handles    structure with handles and user data (see GUIDATA)
240% Get default command line output from handles structure
241varargout{1} = handles.output;
242
243%------------------------------------------------------------------------
244% --- Executes on button press in browse_root.
245function browse_root_Callback(hObject, eventdata, handles)
246%------------------------------------------------------------------------
247%get the input file properties
248filebase=get(handles.RootName,'String');
249oldfile=''; %default
250if isempty(filebase)|| isequal(filebase,'')%loads the previously stored file name and set it as default in the file_input box
251    dir_perso=prefdir;
252    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
253    if exist(profil_perso,'file')
254        h=load (profil_perso);
255        if isfield(h,'filebase')&& ischar(h.filebase)
256            oldfile=h.filebase;
257        end
258        if isfield(h,'RootPath') && ischar(h.RootPath)
259            oldfile=h.RootPath;
260        end
261    end
262else
263    oldfile=filebase;
264end
265testall=get(handles.ImaDoc,'UserData');
266ind_opening=1;%default
267browse.incr_pair=[0 0]; %default
268if testall
269    menu={'*.*', 'All Files (*.*)'; '*.xml; *.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
270        '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc','.nc files'};
271else % menu selecting only .civ or .avi files
272    menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
273        '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc', '.nc files';...
274        '*.*', 'All Files (*.*)'};
275end
276[FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
277fileinput=[PathName FileName];%complete file name
278sizf=size(fileinput);
279if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
280[path,name,ext]=fileparts(fileinput);
281testeditxml=0;
282if isequal(ext,'.xml')
283    testeditxml=1;
284    t_browse=xmltree(fileinput);
285    head_element=get(t_browse,1);
286    if isfield(head_element,'name')&& isequal(head_element.name,'ImaDoc')
287        testeditxml=0;
288    end
289end
290if testeditxml==1 || isequal(ext,'.xls')
291    heditxml=editxml({fileinput});
292    set(heditxml,'Tag','browser')
293    waitfor(heditxml,'Tag','idle')
294    if ~ishandle(heditxml)
295        return
296    end
297    attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
298    set(handles.browse,'UserData',fileinput)% store for future opening with browser
299    fileinput=get(attr,'UserData');
300    if ~exist(fileinput,'file')
301        return
302    end
303end
304[RootPath,RootFile,str1,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
305filebase=fullfile(RootPath,RootFile);
306num_i1=str2double(str1);
307if isnan(num_i1),num_i1=1;end
308num_i2=str2double(str2);
309if isnan(num_i2),num_i2=num_i1;end
310num_j1=stra2num(str_a);
311if isnan(num_j1),num_j1=1;end
312num_j2=stra2num(str_b);
313if isnan(num_j2),num_j2=num_j1;end
314if isequal(get(handles.compare,'Value'),1)
315    browse=[];%initialisation
316else
317    browse=get(handles.browse_root,'UserData');
318end
319browse.num_i1=num_i1;
320browse.num_i2=num_i2;
321browse.num_j1=num_j1;
322browse.num_j2=num_j2;
323if length(ext)>1 && (~isempty(imformats(ext(2:end)))||strcmpi(ext,'.avi'));%if an image file has been opened by uvmat
324%     set(handles.ImaExt,'String',ext)
325    browse.nom_type_ima=nom_type;
326    browse.ext_ima=ext;
327end
328set(handles.ImaDoc,'String',ext);
329
330%%%%% read the state of the selected netcdf file to advise default operation
331if isequal(ext,'.nc')
332    browse.nom_type_nc=nom_type;
333    ind_opening=2;% propose 'fix' as the default option
334    Data=nc2struct(fileinput,[]);
335    if isfield(Data,'absolut_time_T0')%test for civx files
336        if isfield(Data,'fix') && isequal(Data.fix,1)
337            ind_opening=3;
338        end
339        if isfield(Data,'patch') && isequal(Data.patch,1)
340            ind_opening=4;
341        end
342        if isfield(Data,'civ2') && isequal(Data.civ2,1)
343            ind_opening=5;
344        end
345        if isfield(Data,'fix2') && isequal(Data.fix2,1)
346            ind_opening=6;
347        end
348        testciv=1; %TO SUPPRESS WITH NEW VERSION OF CIVX
349    else
350        ind_opening=3; %GUI used only for patch
351        testciv=0;
352    end
353    set(handles.subdir_civ1,'String',subdir);%set the default subdir directories for installing the .nc results
354    set(handles.subdir_civ2,'String',subdir);
355    browse.testciv=testciv;
356    browse.ind_opening=ind_opening;
357end
358set(handles.RootName,'String',filebase);
359set(handles.ImaDoc,'String',ext);
360if ~isempty(num_i1)
361    ref_i=num_i1;
362    if ~isempty(num_i2)
363        ref_i=floor((ref_i+num_i2)/2);% reference image number corresponding to the file
364        browse.incr_pair(1)=num_i2-num_i1;
365        browse.incr_pair(2)=0;
366    end
367    set(handles.first_i,'String',num2str(ref_i));
368    set(handles.last_i,'String',num2str(ref_i));
369    set(handles.ref_i,'String',num2str(ref_i));
370    set(handles.ref_i_civ2,'String',num2str(ref_i))
371end
372if isempty(num_j1)
373    set(handles.ref_j,'String','1');
374    set(handles.ref_j_civ2,'String','1');
375else
376    ref_j=num_j1;
377    if ~isempty(num_j2)
378        ref_j=floor((num_j1+num_j2)/2);
379        browse.incr_pair(2)=num_j2-num_j1;
380    end
381    set(handles.first_j,'String',num2str(ref_j));
382    set(handles.last_j,'String',num2str(ref_j));
383    set(handles.ref_j,'String',num2str(ref_j));
384    set(handles.ref_j_civ2,'String',num2str(ref_j));
385end
386
387% set default operation options
388enable_civ1(handles,'off')
389enable_civ2(handles,'off')
390enable_pair1(handles,'on')
391enable_fix1(handles,'off')
392desable_patch1(handles)
393desable_fix2(handles)
394desable_patch2(handles)
395set(handles.CIV1,'Value',0)
396set(handles.FIX1,'Value',0)
397set(handles.PATCH1,'Value',0)
398set(handles.CIV2,'Value',0)
399set(handles.FIX2,'Value',0)
400set(handles.PATCH2,'Value',0)
401set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
402if isequal(ind_opening,1)
403    set(handles.CIV1,'Value',1)
404    enable_civ1(handles,'on')
405elseif isequal(ind_opening,2)
406    set(handles.FIX1,'Value',1)
407    enable_fix1(handles,'on')
408elseif isequal(ind_opening,3)
409    set(handles.PATCH1,'Value',1)
410    enable_patch1(handles)
411elseif isequal(ind_opening,4)
412    set(handles.CIV2,'Value',1)
413    enable_civ2(handles,1)
414elseif isequal(ind_opening,5)
415    enable_pair1(handles,'off')
416    set(handles.FIX2,'Value',1)
417    enable_fix2(handles)
418    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
419    set(handles.list_pair_civ2,'Enable','On')
420    set(handles.list_pair_civ2,'Enable','On')
421elseif isequal(ind_opening,6)
422    enable_pair1(handles,'off')
423    set(handles.PATCH2,'Value',1)
424    enable_patch2(handles)
425    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
426    set(handles.list_pair_civ2,'Enable','On')
427end
428set(handles.browse_root,'UserData',browse);% store information from browser
429testall=isequal(menu(filtindex,1),{'*.*'});
430set(handles.ImaDoc,'UserData',testall);
431
432RootName_Callback(hObject, eventdata, handles);
433
434%------------------------------------------------------------------------
435function ImaDoc_Callback(hObject, eventdata, handles)
436%------------------------------------------------------------------------
437RootName_Callback(hObject, eventdata, handles)
438
439%------------------------------------------------------------------------
440% --- function activated when a new filebase (image series) is introduced
441function RootName_Callback(hObject, eventdata, handles)
442%------------------------------------------------------------------------
443set(handles.compare,'Visible','on')
444%ext_ima=get(handles.ImaExt,'String');
445ext_ima='';%default
446nom_type_ima=[];%default
447field_count=1;%default
448nom_type_nc=[];
449time=[];
450TimeUnit='frame'; %default
451CoordUnit='px';%default
452pxcmx_search=[];%default
453pxcmy_search=[];%default
454filebase=get(handles.RootName,'String');
455ext_imadoc=get(handles.ImaDoc,'String');
456browse=get(handles.browse_root,'UserData')%default
457if isfield(browse,'nom_type_ima')
458    nom_type_ima=browse.nom_type_ima;% get an image nomenclature type already determined by an input image name
459end
460if isfield(browse,'ext_ima')
461    ext_ima=browse.ext_ima;
462end
463if isfield(browse,'nom_type_nc')
464    nom_type_nc=browse.nom_type_nc;% get an image nomenclature type already determined by an input image name
465end
466if isfield(browse,'num_i1')
467    field_count=browse.num_i1;% get an image index type already determined by an input file
468end
469
470%default first_i and j and increments
471first_i=str2num(get(handles.first_i,'String'));%value possibly set by uvmat_Opening
472if isempty(first_i)|| first_i < 1
473    first_i=1; %default first_i
474end
475last_i=str2num(get(handles.last_i,'String'));
476if isempty(last_i)|| last_i < first_i
477    last_i=first_i;  %default last_i
478end
479first_j=str2num(get(handles.first_j,'String'));
480if isempty(first_j)|| first_j < 1
481    first_j=1; %default first_j
482end
483last_j=str2num(get(handles.last_j,'String'));
484if isempty(last_j)|| last_j < first_j
485    last_j=first_j; %default last_j
486end
487incr_i=str2num(get(handles.incr_i,'String'));
488if isempty(incr_i) || incr_i < 1;
489    set(handles.incr_i,'String','1') %default incr_i
490end
491incr_j=str2num(get(handles.incr_j,'String'));
492if isempty(incr_j) || incr_j < 1;
493    set(handles.incr_j,'String','1') %default incr_j
494end
495dt=[];%default
496testmode=0;%default
497nbfield=[]; %default
498nburst=[];%default
499pxcmx=1;
500pxcmy=1;
501
502%look for an image documentation file
503if ~strcmp(ext_imadoc,'.xml') && ~strcmp(ext_imadoc,'.civ')&& ~strcmpi(ext_imadoc,'.avi')
504    if exist([filebase '.xml'],'file')
505        ext_imadoc='.xml';
506    elseif exist([filebase '.civxml'],'file')
507        ext_imadoc='.civxml';
508    elseif exist([filebase '.civ'],'file')
509        ext_imadoc='.civ';
510    elseif exist([filebase '.avi'],'file')
511        ext_imadoc='.avi';
512    elseif exist([filebase '.AVI'],'file')
513        ext_imadoc='.AVI';
514    end
515    set(handles.ImaDoc,'String',ext_imadoc)
516end
517
518%%%%%%%%   read image documentation file  %%%%%%%%%%%%%%%%%%%%%%%%%%%
519mode=''; %default
520set(handles.ImaDoc,'BackgroundColor',[1 1 0])
521drawnow
522if isequal(ext_imadoc,'.civxml') || isequal(ext_imadoc,'.xml')|| isequal(ext_imadoc,'.civ')
523    set(handles.ref_i,'Visible','On')%use a reference index
524    set(handles.ref_j,'Visible','On')
525elseif isequal(ext_imadoc,'.avi') || isequal(ext_imadoc,'.AVI')
526    set(handles.ref_j,'Visible','Off')
527else
528    set(handles.ref_i,'Visible','Off')
529    set(handles.ref_j,'Visible','Off')
530end
531testima_xml=0;
532if isequal(ext_imadoc,'.civxml')%TO ABANDON
533    [nbfield,nbfield2,time]=read_civxml([filebase '.civxml']);
534    mode='pair j1-j2';
535    if isempty(nom_type_ima)% dtermine types by default if not already selected by browser or uvmat
536        nom_type_ima='_i_j';
537    end
538elseif isequal(ext_imadoc,'.xml')
539    [XmlData,warntext]=imadoc2struct([filebase '.xml']);
540    ext_ima_read=[];
541    nom_type_read=[];
542    if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
543        [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
544        fullname=fullfile(fileparts(filebase),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file,
545        if ~exist(fullname,'file')
546            msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
547        end
548    end
549    if isfield(XmlData,'Time')
550        time=XmlData.Time;
551        nbfield=size(time,1);
552        nbfield2=size(time,2);
553        %transform .Time to a column vector if it is a line vector thenomenclature uses a single index: correct possible bug in xml
554        if isequal(nbfield,1) && ~isequal(nbfield2,1)% .Time is a line vector
555            if numel(nom_type_read)>=2 && isempty(regexp(nom_type_read(2:end),'\D'))
556                time=time';
557                nbfield=nbfield2;
558                nbfield2=1;
559            end
560        end
561    end
562    if isfield(XmlData,'TimeUnit')
563        TimeUnit=XmlData.TimeUnit;
564    end
565    if isfield(XmlData,'Npx')
566        npx=XmlData.Npx;
567        npy=XmlData.Npy;
568    end
569    pxcmx_search=1;
570    pxcmy_search=1;
571    if isfield(XmlData,'GeometryCalib')
572        tsai=XmlData.GeometryCalib;
573        if isfield(tsai,'f') && isfield(tsai,'Tz') && isfield(tsai,'dpx') && isfield(tsai,'dpy')&& isfield(tsai,'R')
574            rot2D=tsai.R(1:2,[1,2]);
575            pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
576            pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);
577        end
578        if isfield(tsai,'CoordUnit')
579            CoordUnit=tsai.CoordUnit;
580        end
581    end
582%     if ~isempty(ext_ima_read) && ~isempty(nom_type_read)
583% %         if isempty(ext_ima)
584% %             ext_ima=ext_ima_read;% define image extension from the xml file if an image has not been opened previously
585% %         else   %keep the image extension
586% %             if  ~strcmp(ext_ima_read,ext_ima)
587% %                 msgbox_uvmat('WARNING',['FirtsImage extension ' ext_ima_read ' announced in the xml file inconsistent with the selected image'])
588% %             end
589% %         end
590%         nom_type_ima=nom_type_read;
591%     end
592elseif strcmp(ext_imadoc,'.civ')% case of .civ image documentation file
593    [error,time,TimeUnit,mode,npx,npy]=read_imatext([filebase '.civ']);
594    if error==2, msgbox_uvmat('WARNING',['no file ' filebase '.civ']);
595    elseif error==1, msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
596    end
597    nom_type_ima='001a';
598elseif strcmpi(ext_imadoc,'.avi')
599    nom_type_ima='*';
600    ext_ima=ext_imadoc;
601    set(handles.mode,'String',{'series(Di)'})
602    dt=0.04;%default
603    if exist([filebase ext_imadoc],'file')==2
604        info=aviinfo([filebase ext_imadoc]);%read infos on the avi movie
605        dt=1/info.FramesPerSecond;%time interval between successive frames
606        nbfield=info.NumFrames;%number of frames
607    end
608    time=(dt*(0:nbfield-1))';%list of image times
609    %set(handles.dt,'String',num2str(dt*1000));%store the time interval between successive images
610end
611if isempty(time)
612    set(handles.ImaDoc,'String',''); %xml file not used for timing
613end
614set(handles.ImaDoc,'BackgroundColor',[1 1 1])
615
616%get the imabe nomenclature type if not defined by the input file nor by the xml file
617dirima=[];%default
618if isempty(nom_type_ima)
619    %look for double image series '_i_j'
620    dirima=dir([filebase '_' num2str(first_i) '_' num2str(first_j) '.*']);
621    if isempty(dirima)
622        % look for images series  with sub marker '_'
623        dirima=dir([filebase '_*' num2str(first_i) '.*']);
624        if isempty(dirima)
625            % look for other images series
626            dirima=dir([filebase '*' num2str(first_i) '.*']);
627            if isempty(dirima)
628                % look for other images series witth letter appendix
629                appendix=char(96+first_j);
630                dirima=dir([filebase '*' num2str(first_i) appendix '.*']);
631            end
632        end
633    end
634end
635for ilist=1:numel(dirima)
636    [pp,ff,fc,str2,str_a,str_b,ext_list,nom_type_list]=name2display(dirima(ilist).name);
637    form=imformats(ext_list(2:end));
638    if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
639        ext_ima=ext_list;
640        nom_type_ima=nom_type_list;
641            break
642    end
643end
644% no image documentation file found: look for a series of existing files,images by priority or .nc files
645if isempty(nom_type_ima)
646    ext_search=ext_imadoc;
647    nom_type_search=nom_type_nc;
648else
649    ext_search=ext_ima;
650    nom_type_search=nom_type_ima;
651end
652if isempty(time) && ~strcmp(nom_type_search,'none') && ~strcmp(nom_type_search,'') && ~strcmp(nom_type_search,'*')
653    subdir=get(handles.subdir_civ1,'String');
654    incr_pair=[0 0];%default
655    if isfield(browse,'incr_pair')
656        incr_pair=browse.incr_pair;
657    end
658    %     nbdetect=0;%test of detected images
659    field_i=browse.num_i2;
660    idetect=1;
661    while idetect==1 %look for the maximum file number in the series
662        imagename=name_generator(filebase,field_i+1,1,ext_search,nom_type_search);
663        idetect=(exist(imagename,'file')==2);
664        if idetect
665            field_i=field_i+1;
666        end
667        %SEE CASE OF NETCDF FILES
668        %             nbdetect=nbdetect+(exist(imagename,'file')==2);
669    end
670    nbfield=field_i;% last detected field number
671    field_i=browse.num_i1;%look for the minimum file number in the series
672    idetect=1;
673    while idetect==1
674        imagename=name_generator(filebase,field_i-1,1,ext_search,nom_type_search);
675        idetect=(exist(imagename,'file')==2);
676        if idetect
677            field_i=field_i-1;
678        end
679    end
680    first_i=max(field_i,1);
681    if numel(regexp(nom_type_search,'\D'))>=1%two indices i and j
682        field_i=browse.num_i1;
683        field_j=browse.num_j2;
684        jdetect=1;
685        while jdetect==1 %look for the maximum file number in the series
686            imagename=name_generator(filebase,field_i,field_j,ext_search,nom_type_search);
687            jdetect=(exist(imagename,'file')==2);
688            if jdetect
689                field_j=field_j+1;
690            end
691            %SEE CASE OF NETCDF FILES
692            %             nbdetect=nbdetect+(exist(imagename,'file')==2);
693        end
694        nbfield2=field_j;% last detected field number
695     end
696 
697    %determine the set of times and possible intervals for CIV
698    %   dt=(1/1000)*str2num(get(handles.dt,'String'));
699    time=(0:nbfield-1)';% time=file index -1  by default
700    if numel(regexp(nom_type_search,'\D'))>=1%two indices i and j
701%     switch nom_type_search 
702%         case {'_i_j','%01dA','%02dA','%03dA','%04dA'}
703        % time=[0:nb_field-1]'*ones(1,nb_field_j);% time=file index -1  by default
704        [x,y]=meshgrid(0:nbfield2-1,0:nbfield-1);
705        time=x+y;
706%         time=[0:nb_field-1]'*[0:nb_field_j-1];% time=file index -1  by default
707    end
708%     set(handles.mode,'String',{'series(Di)'})
709end
710
711if exist('time','var')
712    if size(time,1)+size(time,2)>=3 % if there are at least two time values to define dt
713        nbfield=size(time,1);
714        nbfield2=size(time,2);
715        set(handles.RootName,'UserData',time); %store the set of times
716        set(handles.dt_unit,'String',['dt in m' TimeUnit]);
717        set(handles.dt_unit_civ2,'String',['dt in m' TimeUnit]);
718        set(handles.TimeUnit,'String',TimeUnit);
719        set(handles.nb_field,'String',num2str(nbfield));
720        set(handles.nb_field2,'String',num2str(nbfield2));
721    end
722end
723set(handles.CoordUnit,'String',CoordUnit)
724set(handles.calcul_search,'UserData',[pxcmx_search pxcmy_search]);
725% npxy=[npy npx];
726set(handles.ImaExt,'String',ext_ima)
727set(handles.first_i,'String',num2str(first_i));
728set(handles.last_i,'String',num2str(last_i));%
729set(handles.first_j,'String',num2str(first_j));
730set(handles.last_j,'String',num2str(last_j));%
731browse.nom_type_ima=nom_type_ima;
732set(handles.browse_root,'UserData',browse)% store the nomenclature type
733
734%%%%%%%%%%%  set the menus of image pairs and default selection for civ   %%%%%%%%%%%%%%%%%%%
735test_ima_i=numel(nom_type_ima)>1 && isempty(regexp(nom_type_ima(2:end),'\D'));%images with single indexing
736if test_ima_i || isequal(nom_type_nc,'_i1-i2')||~(exist('nbfield2','var')&&(nbfield2~=1))
737    set(handles.mode,'String',{'series(Di)'})
738    set(handles.mode,'Value',1)
739elseif (nbfield==1)% simple series in j
740    set(handles.mode,'String',{'series(Dj)'})
741    set(handles.mode,'Value',1)
742else
743    set(handles.mode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
744    if nbfield2 <= 10
745        set(handles.mode,'Value',1)% advice 'pair j1-j2' for small burst
746    end
747end
748
749%update the subdir
750pathdir=fileparts(filebase);%path to the current xml file
751listot=dir(pathdir);
752idir=0;
753listdir={''};%default
754for ilist=1:length(listot)
755    if listot(ilist).isdir
756        name=listot(ilist).name;
757        if ~isequal(name,'.') && ~isequal(name,'..')
758            idir=idir+1;
759            listdir{idir,1}=listot(ilist).name;
760        end
761    end
762end
763set(handles.list_subdir_civ1,'Value',1)
764set(handles.list_subdir_civ2,'Value',1)
765set(handles.list_subdir_civ1,'String',[{'browse...'};listdir])
766set(handles.list_subdir_civ2,'String',[{'browse...'};listdir])
767%check wether the current subdir exists:
768subdir_civ1=get(handles.subdir_civ1,'String');
769subdir_civ2=get(handles.subdir_civ2,'String');
770
771mode_Callback(hObject, eventdata, handles)
772
773%%%%%% initialize waitbars and RUN button
774set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
775set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
776set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
777set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
778set(handles.RUN, 'Enable','On')
779set(handles.RUN,'BackgroundColor',[1 0 0])
780set(handles.BATCH,'Enable','On')
781set(handles.BATCH,'BackgroundColor',[1 0 0])
782
783%%%%% store the root input filename for future opening
784dir_perso=prefdir;
785profil_perso=fullfile(prefdir,'uvmat_perso.mat');
786RootPath=fileparts(filebase);
787if exist(profil_perso,'file')
788    save (profil_perso,'RootPath','-append'); %store the root name for future opening of uvmat
789else
790    txt=ver;
791    Release=txt(1).Release;
792    relnumb=str2num(Release(3:4));
793    if relnumb >= 14
794        save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
795    else
796        save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
797    end
798end
799% save(profil_perso, 'filebase'); %store the root name for future opening of uvmat
800set(gcf,'Pointer','arrow')
801
802%------------------------------------------------------------------------
803% --- Executes on button press in mode.
804function mode_Callback(hObject, eventdata, handles)
805%------------------------------------------------------------------------
806browse=get(handles.browse_root,'UserData');
807compare_list=get(handles.compare,'String');
808val=get(handles.compare,'Value');
809compare=compare_list{val};
810if strcmp(compare,'displacement')
811    mode='displacement';
812else
813    mode_list=get(handles.mode,'String');
814    mode_value=get(handles.mode,'Value');
815    mode=mode_list{mode_value};
816end
817displ_num=[];%default
818ref_i=str2num(get(handles.ref_i,'String'));
819% last_i=str2num(get(handles.last_i,'String'));
820time=get(handles.RootName,'UserData'); %get the set of times
821siztime=size(time);
822nbfield=siztime(1);
823nbfield2=siztime(2);
824indchosen=1;  %%first pair selected by default
825if isequal(mode,'pair j1-j2')%| isequal(mode,'st_pair j1-j2')
826    dt=1;
827    displ='';
828    index=0;
829    numlist_a=[];
830    numlist_B=[];
831    %get all the time intervals in bursts
832    displ_dt=1;%default
833    nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
834    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
835        for numod_b=(numod_a+1):nbfield2
836            index=index+1;
837            numlist_a(index)=numod_a;
838            numlist_b(index)=numod_b;
839            if ~isempty(time)
840                dt(numod_a,numod_b)=time(ref_i,numod_b)-time(ref_i,numod_a);%first time interval dt
841                displ_dt(index)=dt(numod_a,numod_b);
842            else
843                displ_dt(index)=1;
844            end
845        end
846    end
847    [dtsort,indsort]=sort(displ_dt);
848    if ~isempty(numlist_a)
849        displ_num(1,:)=numlist_a(indsort);
850        displ_num(2,:)=numlist_b(indsort);
851    end
852    displ_num(3,:)=0;
853    displ_num(4,:)=0;
854    set(handles.jtext,'Visible','Off')
855    set(handles.first_j,'Visible','Off')
856    set(handles.last_j,'Visible','Off')
857    set(handles.incr_j,'Visible','Off')
858    set(handles.nb_field2,'Visible','Off')
859    set(handles.ref_j,'Visible','Off')
860elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)')
861    for index=1:min(nbfield2-1,200)
862        displ_num(1,index)=-floor(index/2);
863        displ_num(2,index)=ceil(index/2);
864        displ_num(3,index)=0;
865        displ_num(4,index)=0;
866    end
867    set(handles.jtext,'Visible','On')
868    set(handles.first_j,'Visible','On')
869    set(handles.last_j,'Visible','On')
870    set(handles.incr_j,'Visible','On')
871    set(handles.nb_field2,'Visible','On')
872    set(handles.ref_j,'Visible','On')
873    if nbfield > 1
874        set(handles.itext,'Visible','On')
875        set(handles.first_i,'Visible','On')
876        set(handles.last_i,'Visible','On')
877        set(handles.incr_i,'Visible','On')
878        set(handles.nb_field,'Visible','On')
879        set(handles.ref_i,'Visible','On')
880    else
881        set(handles.itext,'Visible','Off')
882        set(handles.first_i,'Visible','Off')
883        set(handles.last_i,'Visible','Off')
884        set(handles.incr_i,'Visible','Off')
885        set(handles.nb_field,'Visible','Off')
886        set(handles.ref_i,'Visible','Off')
887    end
888elseif isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
889    for index=1:200%min(nbfield-1,200)
890        displ_num(1,index)=0;
891        displ_num(2,index)=0;
892        displ_num(3,index)=-floor(index/2);
893        displ_num(4,index)=ceil(index/2);
894    end
895    set(handles.itext,'Visible','On')
896    set(handles.first_i,'Visible','On')
897    set(handles.last_i,'Visible','On')
898    set(handles.incr_i,'Visible','On')
899    set(handles.nb_field,'Visible','On')
900    set(handles.ref_i,'Visible','On')
901    if nbfield2 > 1
902        set(handles.jtext,'Visible','On')
903        set(handles.first_j,'Visible','On')
904        set(handles.last_j,'Visible','On')
905        set(handles.incr_j,'Visible','On')
906        set(handles.nb_field2,'Visible','On')
907        set(handles.ref_j,'Visible','On')
908    else
909        set(handles.jtext,'Visible','Off')
910        set(handles.first_j,'Visible','Off')
911        set(handles.last_j,'Visible','Off')
912        set(handles.incr_j,'Visible','Off')
913        set(handles.nb_field2,'Visible','Off')
914        set(handles.ref_j,'Visible','Off')
915    end
916elseif isequal(mode,'displacement')%the pairs have the same indices
917    displ_num(1,1)=0;
918    displ_num(2,1)=0;
919    displ_num(3,1)=0;
920    displ_num(4,1)=0;
921    if nbfield > 1
922        set(handles.itext,'Visible','On')
923        set(handles.first_i,'Visible','On')
924        set(handles.last_i,'Visible','On')
925        set(handles.incr_i,'Visible','On')
926        set(handles.nb_field,'Visible','On')
927        set(handles.ref_i,'Visible','On')
928    else
929        set(handles.itext,'Visible','Off')
930        set(handles.first_i,'Visible','Off')
931        set(handles.last_i,'Visible','Off')
932        set(handles.incr_i,'Visible','Off')
933        set(handles.nb_field,'Visible','Off')
934        set(handles.ref_i,'Visible','Off')
935    end
936    if nbfield2 > 1
937        set(handles.jtext,'Visible','On')
938        set(handles.first_j,'Visible','On')
939        set(handles.last_j,'Visible','On')
940        set(handles.incr_j,'Visible','On')
941        set(handles.nb_field2,'Visible','On')
942        set(handles.ref_j,'Visible','On')
943    else
944        set(handles.jtext,'Visible','Off')
945        set(handles.first_j,'Visible','Off')
946        set(handles.last_j,'Visible','Off')
947        set(handles.incr_j,'Visible','Off')
948        set(handles.nb_field2,'Visible','Off')
949        set(handles.ref_j,'Visible','Off')
950    end
951end
952set(handles.list_pair_civ1,'UserData',displ_num);
953find_netcpair_civ1(hObject, eventdata, handles)
954find_netcpair_civ2(hObject, eventdata, handles)
955
956%------------------------------------------------------------------------
957% determine the menu for civ1 pairs depending on existing netcdf file at the middle of
958% the field series set by first_i, incr, last_i
959function find_netcpair_civ1(hObject, eventdata, handles)
960%------------------------------------------------------------------------
961set(gcf,'Pointer','watch')
962%nomenclature types
963filebase=get(handles.RootName,'String');
964[filepath,Nme,ext_dir]=fileparts(filebase);
965browse=get(handles.browse_root,'UserData');
966compare_list=get(handles.compare,'String');
967val=get(handles.compare,'Value');
968compare=compare_list{val};
969if strcmp(compare,'displacement')
970    mode='displacement';
971else
972    mode_list=get(handles.mode,'String');
973    mode_value=get(handles.mode,'Value');
974    mode=mode_list{mode_value};
975end
976
977% nomenclature type of the .nc files
978nom_type_ima=[];%default
979if isfield(browse,'nom_type_ima')
980    nom_type_ima=browse.nom_type_ima;
981end
982
983%determine nom_type_nc:
984nom_type_nc=[];%default
985if isfield(browse,'nom_type_nc')
986    nom_type_nc=browse.nom_type_nc;
987end
988if isempty(nom_type_nc)
989    [nom_type_nc]=nomtype2pair(nom_type_ima,isequal(mode,'series(Di)'),isequal(mode,'series(Dj)'));
990end
991browse.nom_type_nc=nom_type_nc;
992set(handles.browse_root,'UserData',browse)
993
994%reads .nc subdirectoy and image numbers from the interface
995subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
996% first_i=str2num(get(handles.first_i,'String'));
997% last_i=str2num(get(handles.last_i,'String'));
998% incr=str2num(get(handles.incr_i,'String'));
999% num1=first_i:incr:last_i;
1000% if isempty(num1)
1001%     set(handles.list_pair_civ1,'String',{''});
1002%     return
1003% end
1004ref_i=str2double(get(handles.ref_i,'String'));
1005if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
1006    ref_j=0;
1007else
1008    ref_j=str2double(get(handles.ref_j,'String'));
1009end
1010time=get(handles.RootName,'UserData');%get the set of times
1011if isempty(time)
1012    time=[0 1];
1013end
1014%dt_unit=str2double(get(handles.dt,'String'));% used when there is no image documentation file
1015dt_unit=1000;%default
1016displ_num=get(handles.list_pair_civ1,'UserData');
1017
1018%eliminate the first pairs inconsistent with the position
1019if isempty(displ_num)
1020    nbpair=0;
1021else
1022    nbpair=length(displ_num(1,:));%nbre of displayed pairs
1023    if  isequal(mode,'series(Di)')  %| isequal(mode,'st_series(Di)')
1024        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
1025    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
1026        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
1027    end
1028end
1029nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
1030
1031%look for existing processed pairs involving the field at the middle of the series if civ1 will not
1032% be performed, while the result is needed for next steps.
1033displ_pair={''};
1034select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
1035testpair=0;
1036if get(handles.CIV1,'Value')==0 %
1037    if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
1038        msgbox_uvmat('ERROR',['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist']);
1039        set(handles.list_pair_civ1,'String',{});
1040        return
1041    end
1042    for ipair=1:nbpair
1043        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
1044            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
1045        select(ipair)=exist(filename,'file')==2;
1046    end
1047    if ~exist('select','var') || isequal(select,zeros(size(1:nbpair)))
1048        if isfield(browse,'incr_pair')
1049            num_i1=ref_i-floor(browse.incr_pair(1)/2);
1050            num_i2=ref_i+ceil(browse.incr_pair(1)/2);
1051            num_j1=ref_j-floor(browse.incr_pair(2)/2);
1052            num_j2=ref_j+ceil(browse.incr_pair(2)/2);
1053            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
1054            select(1)=exist(filename,'file')==2;
1055            testpair=1;
1056        else
1057            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
1058                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ1]);
1059            else
1060                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ1]);
1061            end
1062            set(handles.list_pair_civ1,'String',{''});
1063            %COMPLETER CAS STEREO
1064            return
1065        end
1066    end
1067end
1068if isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
1069    if testpair
1070        displ_pair{1}=['Di= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
1071        %     elseif ~isequal(get(handles.root_txt,'String'),'dt(ms)=')
1072        %        for ipair=1:nbpair
1073        %           if select(ipair)
1074        %               if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1075        %               dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1076        %               displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1077        %               end
1078        %           else
1079        %              displ_pair{ipair}='...'; %pair not displayed in the menu
1080        %           end
1081        %        end
1082    else
1083        for ipair=1:nbpair
1084            if select(ipair)
1085                if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1086                    dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1087                    displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1088                else
1089                    displ_pair{ipair}='...'; %pair not displayed in the menu
1090                end
1091            end
1092        end
1093    end
1094elseif isequal(mode,'series(Dj)')%|isequal(mode,'st_series(Dj)')% series on the j index
1095    if testpair
1096        displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
1097    else
1098        for ipair=1:nbpair
1099            if select(ipair)
1100                if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1101                    dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1102                    displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1103                end
1104            elseif testpair
1105                displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(2)/2)) '|' num2str(ceil(browse.incr_pair(2)/2))];
1106            else
1107                displ_pair{ipair}='...'; %pair not displayed in the menu
1108            end
1109        end
1110    end
1111elseif isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')%case of pairs
1112    for ipair=1:nbpair
1113        if select(ipair)
1114            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
1115            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
1116                ' :dt= ' num2str(dt*1000)];
1117        else
1118            displ_pair{ipair}='...'; %pair not displayed in the menu
1119        end
1120    end
1121elseif isequal(mode,'displacement')
1122    displ_pair={'Di=Dj=0'};
1123end
1124set(handles.list_pair_civ1,'String',displ_pair');
1125ichoice=min(find(select));
1126if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
1127initial=get(handles.list_pair_civ1,'Value');%initial choice of pair
1128if initial>nbpair
1129    set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
1130end
1131if numel(select)>=initial && ~isequal(select(initial),1)
1132    set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
1133end
1134
1135%set(handles.list_pair_civ2,'String',displ_pair');
1136initial=get(handles.list_pair_civ2,'Value');
1137if initial>length(displ_pair')%|~isequal(select(initial),1)
1138    if ichoice <= length(displ_pair')
1139        set(handles.list_pair_civ2,'Value',ichoice);% same pair proposed by default for civ2
1140    else
1141        set(handles.list_pair_civ2,'Value',1);% same pair proposed by default for civ2
1142    end
1143end
1144set(handles.list_pair_civ2,'String',displ_pair');
1145set(gcf,'Pointer','arrow')
1146
1147%------------------------------------------------------------------------
1148% determine the menu for civ2 pairs depending on the existing netcdf file at the
1149%middle of the series set by first_i, incr, last_i
1150function find_netcpair_civ2(hObject, eventdata, handles)
1151%------------------------------------------------------------------------
1152set(gcf,'Pointer','watch')
1153%nomenclature types
1154filebase=get(handles.RootName,'String');
1155[filepath,Nme,ext_dir]=fileparts(filebase);
1156browse=get(handles.browse_root,'UserData');
1157compare_list=get(handles.compare,'String');
1158val=get(handles.compare,'Value');
1159compare=compare_list{val};
1160if strcmp(compare,'displacement')
1161    mode='displacement';
1162else
1163    mode_list=get(handles.mode,'String');
1164    mode_value=get(handles.mode,'Value');
1165    mode=mode_list{mode_value};
1166end
1167
1168% nomenclature type of the .nc files
1169nom_type_ima='ima_num';%default
1170if isfield(browse,'nom_type_ima')
1171    nom_type_ima=browse.nom_type_ima;
1172end
1173nom_type_nc='_i1-i2';%default
1174if isfield(browse,'nom_type_nc')
1175    nom_type_nc=browse.nom_type_nc;
1176end
1177if isequal(nom_type_ima,'png_old') || isequal(nom_type_ima,'netc_old')|| isequal(nom_type_ima,'raw_SMD')|| isequal(nom_type_nc,'netc_old')
1178    nom_type_nc='netc_old';%nom_type for the netcdf files
1179elseif isequal(nom_type_ima,'none')||isequal(nom_type_nc,'none')
1180    nom_type_nc='none';
1181elseif isequal(nom_type_ima,'avi')||isequal(nom_type_ima,'_i')||isequal(nom_type_ima,'ima_num')||isequal(nom_type_nc,'_i1-i2')
1182    nom_type_nc='_i1-i2';
1183else
1184    if  isequal(mode,'series(Di)')%|isequal(mode,'st_series(Di)')
1185        nom_type_nc='_i1-i2_j'; % PIV in volume
1186    else
1187        nom_type_nc='_i_j1-j2';
1188    end
1189end
1190browse.nom_type_nc=nom_type_nc;
1191set(handles.browse_root,'UserData',browse)
1192
1193%reads .nc subdirectory and image numbers from the interface
1194subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
1195subdir_civ2=get(handles.subdir_civ2,'String');%subdirectory subdir_civ2 for the netcdf data
1196% first_i=str2num(get(handles.first_i,'String'));
1197% last_i=str2num(get(handles.last_i,'String'));
1198% incr=str2num(get(handles.incr_i,'String'));
1199% num1=first_i:incr:last_i;
1200% if isempty(num1)
1201%     set(handles.list_pair_civ2,'Value',1);
1202%     set(handles.list_pair_civ2,'String',{''});
1203%     return
1204% end
1205ref_i=str2num(get(handles.ref_i_civ2,'String'));
1206if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
1207    ref_j=0;
1208else
1209    ref_j=str2num(get(handles.ref_j_civ2,'String'));
1210end
1211time=get(handles.RootName,'UserData'); %get the set of times
1212if isempty(time)
1213    time=[0 1];%default
1214end
1215%dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
1216%dt_unit=1000;
1217displ_num=get(handles.list_pair_civ1,'UserData');
1218
1219
1220%eliminate the first pairs inconsistent with the position
1221if isempty(displ_num)
1222    nbpair=0;
1223else
1224    nbpair=length(displ_num(1,:));%nbre of displayed pairs
1225    if  isequal(mode,'series(Di)')% | isequal(mode,'st_series(Di)')
1226        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
1227    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
1228        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
1229    end
1230end
1231nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
1232
1233%look for existing processed pairs involving the field at the middle of the series if civ1 will not
1234% be performed, while the result is needed for next steps.
1235displ_pair={''}; %default
1236select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
1237if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0%&...
1238    if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
1239        errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
1240        set(handles.list_pair_civ2,'Value',1);
1241        set(handles.list_pair_civ2,'String',{''});
1242        return
1243    end
1244    for ipair=1:nbpair
1245        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
1246            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
1247        select(ipair)=exist(filename,'file')==2;
1248    end
1249    if  isequal(select,zeros(size(1:nbpair)))
1250        if isfield(browse,'incr_pair')
1251            num_i1=ref_i-floor(browse.incr_pair(1)/2);
1252            num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
1253            num_j1=ref_j-floor(browse.incr_pair(2)/2);
1254            num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
1255            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
1256            select(1)=exist(filename,'file')==2;
1257        else
1258            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
1259                errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
1260            else
1261                errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
1262            end
1263            set(handles.list_pair_civ2,'Value',1);
1264            set(handles.list_pair_civ2,'String',{''});
1265            return
1266        end
1267    end
1268end
1269if isequal(mode,'series(Di)') % | isequal(mode,'st_series(Di)')
1270    for ipair=1:nbpair
1271        if select(ipair)
1272            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1273                dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1274                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1275            end
1276        else
1277            displ_pair{ipair}='...'; %pair not displayed in the menu
1278        end
1279    end
1280elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)') % series on the j index
1281    for ipair=1:nbpair
1282        if select(ipair)
1283            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1284                dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1285                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1286            end
1287        else
1288            displ_pair{ipair}='...'; %pair not displayed in the menu
1289        end
1290    end
1291elseif isequal(mode,'pair j1-j2')% | isequal(mode,'st_pair j1-j2') %case of pairs
1292    for ipair=1:nbpair
1293        if select(ipair)
1294            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
1295            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
1296                ' :dt= ' num2str(dt*1000)];
1297        else
1298            displ_pair{ipair}='...'; %pair not displayed in the menu
1299        end
1300    end
1301elseif isequal(mode,'displacement')
1302    displ_pair={'Di=Dj=0'};
1303end
1304val=get(handles.list_pair_civ2,'Value');
1305ichoice=min(find(select));
1306if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
1307if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
1308    val=ichoice;% first valid pair proposed by default in the menu
1309end
1310if val>length(displ_pair')
1311    set(handles.list_pair_civ2,'Value',1);% first valid pair proposed by default in the menu
1312else
1313    set(handles.list_pair_civ2,'Value',val);
1314end
1315set(handles.list_pair_civ2,'String',displ_pair');
1316set(gcf,'Pointer','arrow')
1317
1318%------------------------------------------------------------------------
1319%  determine the list of index pairs of processing file
1320function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
1321    find_pair_indices(handles,mode)
1322%------------------------------------------------------------------------
1323first_i=str2double(get(handles.first_i,'String'));%first index i
1324last_i=str2double(get(handles.last_i,'String'));%last index i
1325incr=str2double(get(handles.incr_i,'String'));% increment
1326num_i=[first_i:incr:last_i];% list of i indices (reference values for each pair)
1327if isequal(get(handles.first_j,'Visible'),'on')
1328    first_j=str2double(get(handles.first_j,'String'));%first index j
1329    last_j=str2double(get(handles.last_j,'String'));%last index j
1330    incr_j=str2double(get(handles.incr_j,'String'));% increment
1331else
1332    first_j=1;
1333    last_j=1;
1334    incr_j=1;
1335end
1336num_j=[first_j:incr_j:last_j];% list of j indices (reference values for each pair)
1337list_civ1=get(handles.list_pair_civ1,'String');
1338index_civ1=get(handles.list_pair_civ1,'Value');
1339str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1
1340if isempty(str_civ1)||isequal(str_civ1,'')
1341    msgbox_uvmat('ERROR','no image pair selected for civ1')
1342    return
1343end
1344list_civ2=get(handles.list_pair_civ2,'String');
1345index_civ2=get(handles.list_pair_civ2,'Value');
1346if index_civ2>length(list_civ2)
1347    list_civ2=list_civ1;
1348    index_civ2=index_civ1;
1349end
1350str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2
1351if isempty(first_i)||isempty(first_j), msgbox_uvmat('ERROR','first field number not defined'),...
1352        return,end;
1353if isequal(last_i,[])|| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
1354        return,end;
1355if isequal(incr,[])|| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
1356        return,end;
1357if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1358        return,end;
1359if isequal (mode,'series(Di)')
1360    %recognize the pair civ1 from the display
1361    indsel=find((double(str_civ1)<48)|(double(str_civ1)>57));% character indices of non numerical characters
1362    str_raw=str_civ1(indsel);
1363    indsepar=find(str_raw=='|'); %character index of the separator
1364    d1=str2double(str_civ1([indsel(indsepar-1)+1:indsel(indsepar)-1]));
1365    if indsepar==length(str_raw)
1366        d2=str2double(str_civ1([indsel(indsepar)+1:end]));
1367    else
1368        d2=str2double(str_civ1([indsel(indsepar)+1:indsel(indsepar+1)-1]));
1369    end
1370    num1_civ1=num_i-d1;% set of first image numbers
1371    num2_civ1=num_i+d2;
1372    num_a_civ1=num_j;
1373    num_b_civ1=num_j;
1374   
1375    %recognize the pair civ2 from the display
1376    indsel=find((double(str_civ2)<48)|(double(str_civ2)>57));% character indices of non numerical characters
1377    str_raw=str_civ2(indsel);
1378    indsepar=find(str_raw=='|'); %character index of the separator
1379    d1=str2num(str_civ2([indsel(indsepar-1)+1:indsel(indsepar)-1]));
1380    if indsepar==length(str_raw)
1381        d2=str2num(str_civ2([indsel(indsepar)+1:end]));
1382    else
1383        d2=str2num(str_civ2([indsel(indsepar)+1:indsel(indsepar+1)-1]));
1384    end
1385    if isempty(d1)
1386        num1_civ2=num_i;
1387    else
1388        num1_civ2=num_i-d1;% set of first image numbers
1389    end
1390    if isempty(d2)
1391        num2_civ2=num_i;
1392    else
1393        num2_civ2=num_i+d2;
1394    end
1395    num_a_civ2=num_j;
1396    num_b_civ2=num_j;
1397   
1398    % adjust the first and last field number
1399    lastfield=str2num(get(handles.nb_field,'String'));
1400    if isequal(lastfield,[])
1401        indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
1402    else
1403        indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
1404    end
1405    if length(indsel)>=1
1406        firstind=indsel(1);
1407        lastind=indsel(end);
1408        set(handles.first_i,'String',num2str(num_i(firstind)))%update the display of first and last fields
1409        set(handles.last_i,'String',num2str(num_i(lastind)))
1410        num_i=num_i(indsel);
1411        num1_civ1=num1_civ1(indsel);
1412        num1_civ2=num1_civ2(indsel);
1413        num2_civ1=num2_civ1(indsel);
1414        num2_civ2=num2_civ2(indsel);
1415    end
1416elseif isequal (mode,'series(Dj)')
1417    lastfield_j=str2num(get(handles.nb_field2,'String'));
1418    num1_civ1=num_i;% set of first image numbers
1419    num2_civ1=num_i;
1420    num_a_civ1=num_j-floor(index_civ1/2)*ones(size(num_j));
1421    num_b_civ1=num_j+ceil(index_civ1/2)*ones(size(num_j));
1422    num1_civ2=num_i;
1423    num2_civ2=num_i;
1424    num_a_civ2=num_j-floor(index_civ2/2)*ones(size(num_j));
1425    num_b_civ2=num_j+ceil(index_civ2/2)*ones(size(num_j));
1426    % adjust the first and last field number
1427    if isequal(lastfield_j,[])
1428        indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
1429    else
1430        indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
1431    end
1432    if length(indsel)>=1
1433        firstind=indsel(1);
1434        lastind=indsel(end);
1435        set(handles.first_j,'String',num2str(num_j(firstind)))%update the display of first and last fields
1436        set(handles.last_j,'String',num2str(num_j(lastind)))
1437        num_j=num_j(indsel);
1438        num_a_civ1=num_a_civ1(indsel);
1439        num_a_civ2=num_a_civ2(indsel);
1440        num_b_civ1=num_b_civ1(indsel);
1441        num_b_civ2=num_b_civ2(indsel);
1442    end
1443elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
1444    num1_civ1=num_i;
1445    num1_civ2=num_i;
1446    displ_num=get(handles.list_pair_civ1,'UserData');
1447    num2_civ1=num_i;
1448    num_a_civ1=displ_num(1,index_civ1);
1449    num_b_civ1=displ_num(2,index_civ1);
1450    num2_civ2=num_i;
1451    num_a_civ2=displ_num(1,index_civ2);
1452    num_b_civ2=displ_num(2,index_civ2);
1453elseif isequal(mode,'displacement')
1454    num1_civ1=num_i;
1455    num2_civ1=num_i;
1456    num_a_civ1=num_j;
1457    num_b_civ1=num_j;
1458    num1_civ2=num_i;
1459    num2_civ2=num_i;
1460    num_a_civ2=num_j;
1461    num_b_civ2=num_j;
1462end
1463
1464
1465%------------------------------------------------------------------------
1466% --- Executes on selection change in list_pair_civ1.
1467function list_pair_civ1_Callback(hObject, eventdata, handles)
1468%------------------------------------------------------------------------
1469%reproduce by default the chosen pair in the civ2 menu
1470list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
1471index_pair=get(handles.list_pair_civ1,'Value');
1472displ_num=get(handles.list_pair_civ1,'UserData');
1473num_a=displ_num(1,index_pair);
1474num_b=displ_num(2,index_pair);
1475list_pair2=get(handles.list_pair_civ2,'String');%get the menu of image pairs
1476if index_pair<=length(list_pair2)
1477    set(handles.list_pair_civ2,'Value',index_pair);
1478end
1479
1480%update first_i and last_i according to the chosen image pairs
1481mode_list=get(handles.mode,'String');
1482mode_value=get(handles.mode,'Value');
1483mode=mode_list{mode_value};
1484if isequal(mode,'series(Di)')
1485    first_i=str2num(get(handles.first_i,'String'));
1486    last_i=str2num(get(handles.last_i,'String'));
1487    incr_i=str2num(get(handles.incr_i,'String'));
1488    num1=first_i:incr_i:last_i;
1489    lastfield=str2num(get(handles.nb_field,'String'));
1490    if ~isequal(lastfield,[])
1491        ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1492            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1493        num1=num1(ind);
1494    end
1495    set(handles.first_i,'String',num2str(num1(1)));
1496    set(handles.last_i,'String',num2str(num1(end)));
1497elseif isequal(mode,'series(Dj)')
1498    first_j=str2num(get(handles.first_j,'String'));
1499    last_j=str2num(get(handles.last_j,'String'));
1500    incr_j=str2num(get(handles.incr_j,'String'));
1501    num_j=first_j:incr_j:last_j;
1502    lastfield2=str2num(get(handles.nb_field2,'String'));
1503    if ~isequal(lastfield2,[])
1504        ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1505            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
1506        num1=num_j(ind);
1507    end
1508    set(handles.first_j,'String',num2str(num1(1)));
1509    set(handles.last_j,'String',num2str(num1(end)));
1510end
1511
1512%------------------------------------------------------------------------
1513% --- Executes on selection change in list_pair_civ2.
1514function list_pair_civ2_Callback(hObject, eventdata, handles)
1515%------------------------------------------------------------------------
1516index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu
1517
1518%update first_i and last_i according to the chosen image pairs
1519mode_list=get(handles.mode,'String');
1520mode_value=get(handles.mode,'Value');
1521mode=mode_list{mode_value};
1522if isequal(mode,'series(Di)')
1523    first_i=str2num(get(handles.first_i,'String'));
1524    last_i=str2num(get(handles.last_i,'String'));
1525    incr_i=str2num(get(handles.incr_i,'String'));
1526    num1=first_i:incr_i:last_i;
1527    lastfield=str2num(get(handles.nb_field,'String'));
1528    if ~isequal(lastfield,[])
1529        ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1530            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1531        num1=num1(ind);
1532    end
1533    set(handles.first_i,'String',num2str(num1(1)));
1534    set(handles.last_i,'String',num2str(num1(end)));
1535elseif isequal(mode,'series(Dj)')
1536    first_j=str2num(get(handles.first_j,'String'));
1537    last_j=str2num(get(handles.last_j,'String'));
1538    incr_j=str2num(get(handles.incr_j,'String'));
1539    num_j=first_j:incr_j:last_j;
1540    lastfield2=str2num(get(handles.nb_field2,'String'));
1541    if ~isequal(lastfield2,[])
1542        ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1543            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
1544        num1=num_j(ind);
1545    end
1546    set(handles.first_j,'String',num2str(num1(1)));
1547    set(handles.last_j,'String',num2str(num1(end)));
1548end
1549
1550function RUN_Callback(hObject, eventdata, handles)
1551%------------------------------------------------------------------------
1552% global civ1_exe civ2_exe patch_exe patch_new_exe sge
1553set(handles.RUN, 'Enable','Off')
1554set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1555batch=0;
1556launch_jobs(hObject, eventdata, handles,batch);
1557set(handles.RUN, 'Enable','On')
1558set(handles.RUN,'BackgroundColor',[1 0 0])
1559
1560%------------------------------------------------------------------------
1561% --- Executes on button press in BATCH: remote processing
1562function BATCH_Callback(hObject, eventdata, handles)
1563%% -----------------------------------------------------------------------
1564%global civ1_exe civ2_exe patch_exe patch_new_exe fix_exe todo_path sge Civ_exe % probabely to remove
1565set(handles.BATCH, 'Enable','Off')
1566set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
1567batch=1;
1568launch_jobs(hObject, eventdata, handles, batch)
1569set(handles.BATCH, 'Enable','On')
1570set(handles.BATCH,'BackgroundColor',[1 0 0])
1571
1572%------------------------------------------------------------------------
1573% --- Lauch command called by RUN and BATCH: remote processing
1574function launch_jobs(hObject, eventdata, handles, batch)
1575%-----------------------------------------------------------------------
1576%% check the selected list of operations:
1577operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
1578box_test(1)=get(handles.CIV1,'Value');
1579box_test(2)=get(handles.FIX1,'Value');
1580box_test(3)=get(handles.PATCH1,'Value');
1581box_test(4)=get(handles.CIV2,'Value');
1582box_test(5)=get(handles.FIX2,'Value');
1583box_test(6)=get(handles.PATCH2,'Value');
1584index=find(box_test==1);
1585if isempty(index)
1586    msgbox_uvmat('ERROR','no selected operation')
1587    return
1588end
1589index_first=min(index);
1590index_last=max(index);
1591box_used=box_test([index_first : index_last]);
1592[box_missing,ind_missing]=min(box_used);
1593if isequal(box_missing,0)
1594    msgbox_uvmat('ERROR',['missing' cell2mat(operations(ind_missing))]);
1595    return
1596end
1597
1598%% get the root names
1599filebase=get(handles.RootName,'String');
1600if isempty(filebase)||isequal(filebase,'')
1601    msgbox_uvmat('ERROR','no input files')
1602    return
1603end
1604
1605%check mask if selecetd
1606if isequal(get(handles.get_mask_civ1,'Value'),1)
1607    maskname=get(handles.mask_civ1,'String');
1608    if ~exist(maskname,'file')
1609        get_mask_civ1_Callback(hObject, eventdata, handles);
1610    end
1611end
1612if isequal(get(handles.get_mask_fix1,'Value'),1)
1613    maskname=get(handles.mask_fix1,'String');
1614    if ~exist(maskname,'file')
1615        get_mask_fix1_Callback(hObject, eventdata, handles);
1616    end
1617end
1618if isequal(get(handles.get_mask_civ2,'Value'),1)
1619    maskname=get(handles.mask_civ2,'String');
1620    if ~exist(maskname,'file')
1621        get_mask_civ2_Callback(hObject, eventdata, handles);
1622    end
1623end
1624if isequal(get(handles.get_mask_fix2,'Value'),1)
1625    maskname=get(handles.mask_fix2,'String');
1626    if ~exist(maskname,'file')
1627        get_mask_fix2_Callback(hObject, eventdata, handles);
1628    end
1629end
1630
1631%% initialize the waitbars
1632set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
1633set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
1634set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
1635set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
1636drawnow
1637
1638%% set the list of files and check them
1639display('checking the files...')
1640compare=get(handles.compare,'Value');%test for usual PIV (compare=1) or displacement (=2) or stereo PIV (=3)
1641[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=...
1642    set_civ_filenames(handles,compare,box_test);
1643if isempty(filecell)
1644    return
1645end
1646nbfield=numel(num1_civ1);
1647nbslice=numel(num_a_civ1);
1648
1649%% choice of batch priority
1650ind_answer=2;
1651if batch
1652    [s,w]=unix('qstat -q civ.q|grep job_| wc -l'); %check the waiting list (command unix)
1653    if isequal(s,0)
1654        w(end)=[];
1655        str_displ={[w ' jobs in the waiting list'];'Select a priority:'};
1656        str={'urgent';'normal';'low'};
1657        [ind_answer,v] = listdlg('PromptString',str_displ,...
1658            'SelectionMode','single',...
1659            'ListString',str,'ListSize',[200 200],'Name','job priority','InitialValue',3);
1660        if isequal(v,0) % to handle Cancel button and figure close,
1661            return % a better way should be create
1662        end
1663    else
1664        msgbox_uvmat('ERROR','batch system not available')
1665        return
1666    end
1667else
1668    if isunix
1669        [xx,w]=unix('ps faux |grep civ|wc -l');
1670        w(end)=[];
1671        if str2double(w)+numel(num1_civ1)> 50
1672            msgbox_uvmat('ERROR',{['There are already ' w ' civ processes running locally'];'Use BATCH or submit RUN later'})
1673            return
1674        end
1675    end
1676end
1677
1678
1679%% read names of the .exe files for PIV and patch
1680path_UVMAT=fileparts(which('uvmat')); %path to the source directory of uvmat
1681xmlfile='PARAM.xml';
1682if exist(xmlfile,'file')% search parameter xml file in the whole matlab path
1683    t=xmltree(xmlfile);
1684    s=convert(t);
1685end
1686test_interp=0;
1687if batch
1688    if isfield(s,'BatchParam')
1689        sparam=s.BatchParam;
1690        if ~ismember(sparam.BatchMode,{'sge'})
1691            msgbox_uvmat('ERROR',['batch mode ' sparam.BatchMode ' not supported by UVMAT'])
1692        end
1693    else
1694        msgbox_uvmat('ERROR','no batch mode defined in PARAM.xml')
1695        return
1696    end
1697else
1698    if isfield(s,'RunParam')
1699        sparam=s.RunParam;
1700    else
1701        msgbox_uvmat('ERROR','no civ binaries defined in PARAM.xml')
1702        return
1703    end
1704    if isfield(sparam,'CivBin')
1705        if ~exist(sparam.CivBin,'file')
1706            sparam.CivBin=fullfile(path_UVMAT,sparam.CivBin);
1707        end
1708    end
1709    if isfield(sparam,'Civ1Bin')
1710        if ~exist(sparam.Civ1Bin,'file')
1711            sparam.Civ1Bin=fullfile(path_UVMAT,sparam.Civ1Bin);
1712        end
1713    end
1714    if isfield(sparam,'Civ2Bin')
1715        if ~exist(sparam.Civ2Bin,'file')
1716            sparam.Civ2Bin=fullfile(path_UVMAT,sparam.Civ2Bin);
1717        end
1718    end
1719    %test_interp=get(handles.test_interp,'Value');
1720
1721    if  isfield(sparam,'PatchBin')
1722        if ~exist(sparam.PatchBin,'file')
1723            sparam.PatchBin=fullfile(path_UVMAT,sparam.PatchBin);
1724        end
1725    end
1726    % if test_interp && isfield(sparam,'PatchNewBin')
1727    %     if ~exist(sparam.PatchNewBin,'file')
1728    %          sparam.PatchNewBin=fullfile(path_UVMAT,sparam.PatchNewBin);
1729    %     end
1730    % end
1731    if isfield(sparam,'FixBin')
1732        if ~exist(sparam.FixBin,'file')
1733            sparam.FixBin=fullfile(path_UVMAT,sparam.FixBin);
1734        end
1735    end
1736end
1737if batch
1738    if isfield(sparam,'BatchMode')
1739        batch_mode=sparam.BatchMode;
1740    end
1741else
1742%     MaxCivProcesses=50;
1743%     if isfield(sparam,'MaxCivProcesses')
1744%         MaxCivProcesses=str2double(sparam.MaxCivProcesses);
1745%     end
1746end
1747
1748
1749%% get civ1 parameters:
1750display('files OK, processing...')
1751%get civ parameters
1752if box_test(1)==1
1753    par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1,1});
1754end
1755
1756%% get fix1 parameters
1757if box_test(2)==1
1758    flagindex1(1)=get(handles.vec_Fmin2, 'Value');
1759    flagindex1(2)=get(handles.vec_F3, 'Value');
1760    flagindex1(3)=get(handles.vec_F2, 'Value');
1761    thresh_vecC1=str2double(get(handles.thresh_vecC,'String'));%threshold on image correlation vec_C
1762    thresh_vel1=str2double(get(handles.thresh_vel,'String'));%threshold on velocity modulus
1763    test_mask=get(handles.get_mask_fix1,'Value');
1764    nbslice_mask=get(handles.mask_fix1,'UserData'); % get the number of slices (= number of masks)
1765    %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX
1766    %     inf_sup=get(handles.inf_sup1,'Value');80
1767    %     fileref=get(handles.ref_fix1,'String');
1768    %     refpath=get(handles.ref_fix1,'UserData');
1769    %     fileref=fullfile(refpath,fileref);
1770    menu=get(handles.field_ref1,'String');
1771    index=get(handles.field_ref1,'Value');
1772    if isempty(menu)
1773        fieldchoice='';
1774    else
1775        fieldchoice=menu{index};
1776        msgbox_uvmat('WARNING','reference field is not used presently with batch, use RUN option')
1777    end
1778end
1779
1780%% get patch1 parameters
1781if box_test(3)==1
1782    rho_patch1=str2double(get(handles.rho_patch1,'String'));
1783    if isnan(rho_patch1)
1784        rho_patch1='1000';
1785        set(handles.rho_patch1,'String','1')
1786    else
1787        rho_patch1=num2str(1000*rho_patch1);
1788    end
1789    nx_patch1=get(handles.nx_patch1,'String');
1790    ny_patch1=get(handles.ny_patch1,'String');
1791    if isnan(str2double(nx_patch1))
1792        nx_patch1='50' ;%default
1793        set(handles.nx_patch1,'String','50');
1794    end
1795    if isnan(str2double(ny_patch1))
1796        ny_patch1='50' ;%default
1797        set(handles.ny_patch1,'String','50');
1798    end
1799    subdomain_patch1=get(handles.subdomain_patch1,'String');
1800    thresh_patch1=get(handles.thresh_patch1,'String');
1801end
1802
1803%% get civ2 parameters:
1804if box_test(4)==1
1805    par_civ2=read_param_civ2(handles,cell2mat(filecell.ima1.civ2(1,1)));
1806end
1807
1808%% get fix2 parameters
1809if box_test(5)==1
1810    flagindex2(1)=get(handles.vec_Fmin2_2, 'Value');
1811    flagindex2(2)=get(handles.vec_F3_2, 'Value');
1812    flagindex2(3)=get(handles.vec_F4, 'Value');
1813    thresh_vec2C=str2double(get(handles.thresh_vec2C,'String'));%threshold on image correlation vec_C
1814    thresh_vel2=str2double(get(handles.thresh_vel2,'String'));%threshold on velocity modulus
1815    test_mask=get(handles.get_mask_fix2,'Value');
1816    nbslice_mask=get(handles.mask_fix2,'UserData'); % get the number of slices (= number of masks)
1817    %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX AVEC REF FILE ET OPTION inf_sup=2
1818    %     inf_sup=get(handles.inf_sup2,'Value');
1819    %     ref=get(handles.ref_fix2,'UserData');
1820   
1821    %%%%%%%%%%%%%%%%%%%
1822end
1823
1824%% get patch2 parameters
1825if box_test(6)==1
1826    rho_patch2=str2double(get(handles.rho_patch2,'String'));
1827    if isnan(rho_patch2)
1828        rho_patch2='1000';
1829        set(handles.rho_patch2,'String','1')
1830    else
1831        rho_patch2=num2str(1000*rho_patch2);
1832    end
1833    nx_patch2=get(handles.nx_patch2,'String');
1834    ny_patch2=get(handles.ny_patch2,'String');
1835    if isnan(str2double(nx_patch2))
1836        nx_patch2='50' ;%default
1837        set(handles.nx_patch2,'String','50');
1838    end
1839    if isnan(str2double(ny_patch2))
1840        ny_patch2='50' ;%default
1841        set(handles.ny_patch2,'String','50');
1842    end
1843    subdomain_patch2=get(handles.subdomain_patch2,'String');
1844    thresh_patch2=get(handles.thresh_patch2,'String');
1845    %              test_interp=get(handles.test_interp,'Value');
1846end
1847
1848%% MAIN LOOP
1849time=get(handles.RootName,'UserData'); %get the set of times
1850civAll=get(handles.Experimental,'Value'); % Boolean for new civ excution method
1851super_cmd=[];
1852
1853for ifile=1:nbfield
1854    for j=1:nbslice
1855        i_cmd=0;
1856        cmd='';
1857        if isunix % check: necessaire aussi en RUN?
1858            %fid=fopen([filename '.cmx'],'w')
1859            cmd='#!/bin/bash \n';
1860            cmd=[cmd '#$ -cwd \n'];
1861            cmd=[cmd 'hostname && date \n'];
1862            cmd=[cmd 'umask 002 \n'];
1863        end
1864        if civAll
1865            civAllxml=xmltree;% xml contents,  all parameters
1866            civAllCmd='';
1867            civAllxml=set(civAllxml,1,'name','CivDoc');
1868        end
1869        filename_cmx=filecell.nc.civ1{ifile,j};%output netcdf file
1870        filename_cmx(end-1:end+1)='cmx';%name of cmx file
1871       
1872        %CIV1
1873        if box_test(1)==1
1874            par_civ1.filename_ima_a=filecell.ima1.civ1{ifile,j};
1875            par_civ1.filename_ima_b=filecell.ima2.civ1{ifile,j};
1876            namelog=[filename_cmx([1:end-3]) 'log'];
1877            par_civ1.Dt=num2str(time(num2_civ1(ifile),num_b_civ1(j))-time(num1_civ1(ifile),num_a_civ1(j)));
1878            par_civ1.T0=num2str((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(j)))/2);
1879            par_civ1.term_a=num2stra(num_a_civ1(j),nom_type_nc);%UTILITE?
1880            par_civ1.term_b=num2stra(num_b_civ1(j),nom_type_nc);%
1881            test_mask=get(handles.get_mask_civ1,'Value');
1882            if test_mask==0
1883                par_civ1.maskname='noFile use default';
1884                par_civ1.maskflag='n';
1885            else
1886                maskdispl=get(handles.mask_civ1,'String');
1887                if exist(maskdispl,'file')
1888                    par_civ1.maskname=maskdispl;
1889                    par_civ1.maskflag='y';
1890                else
1891                    maskbase=[filebase '_' maskdispl]; %
1892                    nbslice_mask=str2num(maskdispl(1:end-4)); %
1893                    num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
1894                    par_civ1.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
1895                    if exist(par_civ1.maskname,'file')
1896                        par_civ1.maskflag='y';
1897                    else
1898                        par_civ1.maskname='noFile use default';
1899                        par_civ1.maskflag='n';
1900                    end
1901                end
1902            end
1903           
1904            test_grid=get(handles.browse_gridciv1,'Value');
1905            if test_grid
1906                par_civ1.gridflag='y';
1907                gridname=get(handles.grid_civ1,'String');
1908                if isequal(gridname(end-3:end),'grid')
1909                    nbslice_grid=str2num(gridname(1:end-4)); %
1910                    if ~isempty(nbslice_grid)
1911                        num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
1912                        par_civ1.gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
1913                        if ~exist(par_civ1.gridname,'file')
1914                            msgbox_uvmat('ERROR','grid file absent for civ1')
1915                        end
1916                    elseif exist(gridname,'file')
1917                        par_civ1.gridname=gridname;
1918                    else
1919                        msgbox_uvmat('ERROR','grid file absent for civ1')
1920                    end
1921                end
1922            else
1923                par_civ1.gridname='noFile use default';
1924                par_civ1.gridflag='n';
1925            end
1926            %
1927            i_cmd=i_cmd+1;
1928            if isequal(civAll,0)
1929                cmd=[cmd CIV1_CMD(filename_cmx(1:end-4),namelog,par_civ1,handles,sparam) '\n'];
1930            else
1931                civAllCmd=[civAllCmd ' civ1 '];
1932                str=CIV1_CMD_Unified(filename_cmx([1:end-4]),namelog,par_civ1);
1933                fieldnames=fields(str);
1934                [civAllxml,uid_civ1]=add(civAllxml,1,'element','civ1');
1935                for ilist=1:length(fieldnames)
1936                    val=eval(['str.' fieldnames{ilist}]);
1937                    if ischar(val)
1938                        [civAllxml,uid_t]=add(civAllxml,uid_civ1,'element',fieldnames{ilist});
1939                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
1940                    end
1941                end
1942            end
1943        end
1944       
1945        % FIX1
1946        if box_test(2)==1
1947            test_mask=get(handles.get_mask_fix1,'Value');
1948            if test_mask==0
1949                maskname='';
1950            else
1951                maskdispl=get(handles.mask_fix1,'String');
1952                nbslice_mask=str2num(maskdispl(1:end-4)); %
1953                num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
1954                maskbase=[filebase '_' maskdispl];
1955                maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
1956            end
1957            if isequal(civAll,0)
1958                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ1{ifile,j} ' -fi1 ' num2str(flagindex1(1)) ...
1959                    ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
1960                    ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName ' maskname];
1961                cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
1962                cmd=[cmd cmd_FIX '\n'];
1963            else
1964                fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
1965                fix1.fi1=num2str(flagindex1(1));
1966                fix1.fi2=num2str(flagindex1(2));
1967                fix1.fi3=num2str(flagindex1(3));
1968                fix1.threshC=num2str(thresh_vecC1);
1969                fix1.threshV=num2str(thresh_vel1);
1970                fieldnames=fields(fix1);
1971                [civAllxml,uid_fix1]=add(civAllxml,1,'element','fix1');
1972                for ilist=1:length(fieldnames)
1973                    val=eval(['fix1.' fieldnames{ilist}]);
1974                    if ischar(val)
1975                        [civAllxml,uid_t]=add(civAllxml,uid_fix1,'element',fieldnames{ilist});
1976                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
1977                    end
1978                end
1979                civAllCmd=[civAllCmd ' fix1 '];
1980            end
1981        end
1982       
1983        %PATCH1
1984        if box_test(3)==1
1985            if isequal(civAll,0)
1986                cmd_PATCH=PATCH_CMD(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp,sparam.PatchBin);
1987                cmd_PATCH=regexprep(cmd_PATCH,'\\','\\\\');
1988                cmd=[cmd cmd_PATCH '\n'];
1989            else
1990                patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
1991                patch1.nopt=subdomain_patch1;
1992                patch1.maxdiff=thresh_patch1;
1993                patch1.ro=rho_patch1;
1994                test_grid=get(handles.get_gridpatch1,'Value');
1995                if test_grid
1996                    patch1.gridflag='y';
1997                    gridname=get(handles.grid_patch1,'String');
1998                    if isequal(gridname(end-3:end),'grid')
1999                        nbslice_grid=str2num(gridname(1:end-4)); %
2000                        if ~isempty(nbslice_grid)
2001                            num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
2002                            patch1.gridPatch=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
2003                            if ~exist(patch1.gridPatch,'file')
2004                                msgbox_uvmat('ERROR','grid file absent for patch1')
2005                            end
2006                        elseif exist(gridname,'file')
2007                            patch1.gridPatch=gridname;
2008                        else
2009                            msgbox_uvmat('ERROR','grid file absent for patch1')
2010                        end
2011                    end
2012                else
2013                    patch1.gridPatch='none';
2014                    patch1.gridflag='n';
2015                    patch1.m=nx_patch1;
2016                    patch1.n=ny_patch1;
2017                end
2018                patch1.convectFlow='n';
2019                fieldnames=fields(patch1);
2020                [civAllxml,uid_patch1]=add(civAllxml,1,'element','patch1');
2021                for ilist=1:length(fieldnames)
2022                    val=eval(['patch1.' fieldnames{ilist}]);
2023                    if ischar(val)
2024                        [civAllxml,uid_t]=add(civAllxml,uid_patch1,'element',fieldnames{ilist});
2025                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
2026                    end
2027                end
2028                civAllCmd=[civAllCmd ' patch1 '];
2029            end
2030        end
2031       
2032        if box_test(4)==1 || box_test(5)==1 || box_test(6)==1
2033            filename_cmx=filecell.nc.civ2{ifile,j};%output netcdf file
2034            filename_cmx([end-1:end+1])=[ 'cmx'];%name of cmx file
2035%             filename_cmx=[filename_cmx 'x'];
2036        end
2037       
2038        if box_test(4)==1
2039            par_civ2.filename_ima_a=filecell.ima1.civ2{ifile,j};
2040            %par_civ2.filename_ima_a([end-3:end])=[];%remove .png extension
2041            par_civ2.filename_ima_b=filecell.ima2.civ2{ifile,j};
2042            %par_civ2.filename_ima_b([end-3:end])=[];%remove .png extension
2043            namelog=[filename_cmx([1:end-3]) 'log'];
2044            par_civ2.Dt=num2str(time(num2_civ2(ifile),num_b_civ2(j))-time(num1_civ2(ifile),num_a_civ2(j)));
2045            par_civ2.T0=num2str((time(num2_civ1(ifile),num_b_civ2(j))+time(num1_civ2(ifile),num_a_civ2(j)))/2);
2046            par_civ2.term_a=num2stra(num_a_civ2(j),nom_type_nc);
2047            par_civ2.term_b=num2stra(num_b_civ2(j),nom_type_nc);
2048            par_civ2.filename_nc1=filecell.nc.civ1{ifile,j};
2049            par_civ2.filename_nc1([end-2:end])=[]; % remove '.nc'
2050            test_mask=get(handles.get_mask_civ2,'Value');
2051            if test_mask==0
2052                par_civ2.maskname='noFile use default';
2053                par_civ2.maskflag='n';
2054            else
2055                maskdispl=get(handles.mask_civ2,'String');
2056                if exist(maskdispl,'file')
2057                    par_civ2.maskname=maskdispl;
2058                    par_civ2.maskflag='y';
2059                else
2060                    maskbase=[filebase '_' maskdispl]; %
2061                    nbslice_mask=str2num(maskdispl(1:end-4)); %
2062                    num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
2063                    par_civ2.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
2064                    if exist(par_civ2.maskname,'file')
2065                        par_civ2.maskflag='y';
2066                    else
2067                        par_civ2.maskname='noFile use default';
2068                        par_civ2.maskflag='n';
2069                    end
2070                end
2071            end
2072            %TESTgrid
2073            test_grid=get(handles.browse_gridciv2,'Value');
2074            gridname=get(handles.grid_civ2,'String');
2075            gridflag='y';
2076            if numel(gridname)>=4 && isequal(gridname(end-3:end),'grid')
2077                nbslice_grid=str2num(gridname(1:end-4)); %
2078                if ~isempty(nbslice_grid)
2079                    par_civ2.gridflag='y';
2080                    num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
2081                    par_civ2.gridname=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
2082                    if exist(par_civ2.gridname,'file')
2083                        par_civ2.gridflag='y';
2084                    else
2085                        par_civ2.gridname='noFile use default';
2086                        par_civ2.gridflag='n';
2087                    end
2088                elseif exist(gridname,'file')
2089                    par_civ2.gridflag='y';
2090                else
2091                    par_civ2.gridname='noFile use default';
2092                    par_civ2.gridflag='n';
2093                end
2094            end
2095            %endTESTgrid
2096            i_cmd=i_cmd+1;
2097            filename_cmx(1:end-4)
2098            cmd_CIV2=CIV2_CMD(filename_cmx(1:end-4),namelog,par_civ2,sparam);
2099            if isequal(civAll,0)
2100                if(isunix)
2101                    cmd=[cmd 'cp -f ' filename_cmx '2 ' filename_cmx '\n' cmd_CIV2 '\n'];
2102                else
2103                    filename_cmx=regexprep(filename_cmx,'\\','\\\\');
2104                    cmd=[cmd 'copy /Y ' filename_cmx '2 ' filename_cmx '\n' cmd_CIV2 '\n'];
2105                end
2106            else
2107                civAllCmd=[civAllCmd ' civ2 '];
2108                str=CIV2_CMD_Unified(filename_cmx([1:end-4]),namelog,par_civ2);
2109                fieldnames=fields(str);
2110                [civAllxml,uid_civ2]=add(civAllxml,1,'element','civ2');
2111                for ilist=1:length(fieldnames)
2112                    val=eval(['str.' fieldnames{ilist}]);
2113                    if ischar(val)
2114                        [civAllxml,uid_t]=add(civAllxml,uid_civ2,'element',fieldnames{ilist});
2115                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
2116                    end
2117                end
2118            end
2119        end
2120       
2121        % FIX2
2122        if box_test(5)==1
2123            test_mask=get(handles.get_mask_fix2,'Value');
2124            if test_mask==0
2125                maskname=''; %no mask used
2126            else
2127                maskdispl=get(handles.mask_fix2,'String');
2128                maskbase=[filebase '_' maskdispl]; %
2129                nbslice_mask=str2num(maskdispl(1:end-4)); %
2130                num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
2131                maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
2132            end
2133            if isequal(civAll,0)
2134                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
2135                    ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
2136                    ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
2137                cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
2138                cmd=[cmd cmd_FIX '\n'];
2139            else
2140                fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
2141                fix2.fi1=num2str(flagindex2(1));
2142                fix2.fi2=num2str(flagindex2(2));
2143                fix2.fi3=num2str(flagindex2(3));
2144                fix2.threshC=num2str(thresh_vec2C);
2145                fix2.threshV=num2str(thresh_vel2);
2146                fieldnames=fields(fix2);
2147                [civAllxml,uid_fix2]=add(civAllxml,1,'element','fix2');
2148                for ilist=1:length(fieldnames)
2149                    val=eval(['fix2.' fieldnames{ilist}]);
2150                    if ischar(val)
2151                        [civAllxml,uid_t]=add(civAllxml,uid_fix2,'element',fieldnames{ilist});
2152                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
2153                    end
2154                end
2155                civAllCmd=[civAllCmd ' fix2 '];
2156            end
2157        end
2158       
2159        %PATCH2
2160        if box_test(6)==1
2161            if isequal(civAll,0)
2162                cmd_PATCH=PATCH_CMD(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,test_interp,sparam.PatchBin);
2163                cmd_PATCH=regexprep(cmd_PATCH,'\\','\\\\');
2164                cmd=[cmd cmd_PATCH '\n'];
2165            else
2166                patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
2167                patch2.nopt=subdomain_patch1;
2168                patch2.maxdiff=thresh_patch1;
2169                patch2.ro=rho_patch1;
2170                test_grid=get(handles.get_gridpatch2,'Value');
2171                if test_grid
2172                    patch2.gridflag='y';
2173                    gridname=get(handles.grid_patch2,'String');
2174                    if isequal(gridname(end-3:end),'grid')
2175                        nbslice_grid=str2num(gridname(1:end-4)); %
2176                        if ~isempty(nbslice_grid)
2177                            num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
2178                            patch2.gridPatch=[filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
2179                            if ~exist(patch2.gridPatch,'file')
2180                                msgbox_uvmat('ERROR','grid file absent for patch2')
2181                            end
2182                        elseif exist(gridname,'file')
2183                            patch2.gridPatch=gridname;
2184                        else
2185                            msgbox_uvmat('ERROR','grid file absent for patch2')
2186                        end
2187                    end
2188                else
2189                    patch2.gridPatch='none';
2190                    patch2.gridflag='n';
2191                    patch2.m=nx_patch2;
2192                    patch2.n=ny_patch2;
2193                end
2194                patch2.convectFlow='n';
2195                fieldnames=fields(patch2);
2196                [civAllxml,uid_patch2]=add(civAllxml,1,'element','patch2');
2197                for ilist=1:length(fieldnames)
2198                    val=eval(['patch2.' fieldnames{ilist}]);
2199                    if ischar(val)
2200                        [civAllxml,uid_t]=add(civAllxml,uid_patch2,'element',fieldnames{ilist});
2201                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
2202                    end
2203                end
2204                civAllCmd=[civAllCmd ' patch2 '];
2205            end
2206        end
2207        if isequal(civAll,1)
2208            save(civAllxml,[filename_cmx([1:end-4]) '.xml']);
2209            %cmd=char({cmd;[CivBin ' -f ' [filename_cmx([1:end-4]) '.xml'] ' ' civAllCmd]});
2210            cmd=[cmd CivBin ' -f ' filename_cmx(1:end-4) '.xml '  civAllCmd  '\n'];
2211        end
2212        % create the .bat file:
2213        if batch
2214            [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
2215            filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
2216        else
2217            filename_bat=filename_cmx;
2218        end
2219        filename_bat(end-2:end)='bat';
2220        fid=fopen(filename_bat,'w');
2221        fprintf(fid,cmd);
2222        fclose(fid);
2223        %dlmwrite(filename_bat,cmd,'');%write commands in filename_bat
2224        if batch
2225            switch batch_mode
2226                case 'sge'
2227                    pvalue=num2str((1-ind_answer)*500);
2228                    %namelog=[filename_bat '.patch.log'];
2229                    display(['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
2230                    eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
2231            end
2232        else
2233            %% to lauch the jobs locally :
2234            if(isunix)
2235              cmd_str=['!. ' filename_bat ' &'];
2236%                 cmd_str=['!. ' filename_bat];
2237                display(cmd_str)
2238     %            cmd_str=['!at -qb now -f ' filename_bat ' &']; %ou at -qb now -f bad idea...
2239            else %case of Windows
2240               cmd_str=['!' filename_bat ' &'];
2241            end
2242               super_cmd=[super_cmd '. ' filename_bat '\n']
2243%             eval(cmd_str);
2244%             display(cmd_str);
2245        end
2246    end
2247end
2248
2249           
2250% filename_superbat(end-2:end)='bat';
2251%         fid=fopen(filename_bat,'w');
2252%         fprintf(fid,cmd);
2253%         fclose(fid);
2254
2255if ~batch%TODO: a revoir, cas 'run as background task'
2256    eval(['!. ' filename_superbat ' &'])
2257    [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
2258    filename_superbat=fullfile(Rootbat,['toto.bat']);
2259    fid=fopen(filename_superbat,'w');
2260    fprintf(fid,super_cmd');
2261    fclose(fid);
2262end
2263
2264
2265%save interface state
2266if isfield(filecell,'nc')
2267    if isfield(filecell.nc,'civ2')
2268        fileresu=filecell.nc.civ2{1,1};
2269    else
2270        fileresu=filecell.nc.civ1{1,1};
2271    end
2272end
2273[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
2274namedoc=fullfile(RootPath,subdir,RootFile);
2275detect=1;
2276while detect==1
2277    namefigfull=[namedoc '.fig'];
2278    hh=dir(namefigfull);
2279    if ~isempty(hh)
2280        detect=1;
2281        namedoc=[namedoc '.0'];
2282    else
2283        detect=0;
2284    end
2285end
2286saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
2287
2288
2289
2290function [filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc,file_ref_fix1,file_ref_fix2]=...
2291    set_civ_filenames(handles,compare,box_test)
2292%------------------------------------------------------------------------
2293filecell=[];%default
2294%get the filename root, nomenclature and numbers
2295filebase=get(handles.RootName,'String');
2296browse=get(handles.browse_root,'UserData');
2297compare_list=get(handles.compare,'String');
2298val=get(handles.compare,'Value');
2299compare=compare_list{val};
2300if strcmp(compare,'displacement')
2301    mode='displacement';
2302else
2303    mode_list=get(handles.mode,'String');
2304    mode_value=get(handles.mode,'Value');
2305    mode=mode_list{mode_value};
2306end
2307time=get(handles.RootName,'UserData'); %get the set of times
2308ext_ima=get(handles.ImaExt,'String');
2309nom_type_nc=browse.nom_type_nc;
2310if isfield(browse,'nom_type_ima')
2311    nom_type_ima2=browse.nom_type_ima;
2312end
2313if isempty(nom_type_ima2),nom_type_ima2='1';end; %default
2314if isempty(nom_type_nc),nom_type_nc='_i1-i2';end; %default
2315[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
2316    find_pair_indices(handles,mode);
2317%determine the new filebase for 'displacement' mode (comparison of two series)
2318filebase_B=filebase;% root name of the second field series for stereo
2319if strcmp(compare,'displacement') || strcmp(compare,'stereo PIV')
2320%     test_disp=1;
2321    nom_type_ima1=browse.nom_type_ima_1; %nomenclature type of the second file series
2322    [Path2,Name2]=fileparts(filebase_B);
2323    Path1=Path2;
2324    Name1=get(handles.RootName_1,'String');% root name of the first field series for stereo
2325    filebase_A=fullfile(Path1,Name1);
2326    if length(Name1)>6
2327        Name1=Name1(end-5:end);
2328    end
2329    if length(Name2)>6
2330        Name2=Name2(end-5:end);
2331    end
2332    filebase_AB=fullfile(Path2,[Name2 '-' Name1]);
2333else
2334%     test_disp=0;
2335    filebase_A=filebase;
2336    nom_type_ima1=nom_type_ima2;
2337    filebase_AB=filebase;
2338end
2339if strcmp(compare,'displacement')
2340    filebase_ima1=filebase_A;
2341    filebase_ima2=filebase_B;
2342    filebase_nc=filebase_AB; %root name for the result of civ2
2343else
2344    filebase_ima1=filebase_B;
2345    filebase_ima2=filebase_B;
2346    filebase_nc=filebase_B;
2347end
2348
2349%determine reference files for fix:
2350file_ref_fix1={};%default
2351file_ref_fix2={};
2352nbfield=length(num1_civ1);
2353nbslice=length(num_a_civ1);
2354if box_test(2)==1% fix1 performed
2355    ref=get(handles.ref_fix1,'UserData');%read data on the ref file stored by get_ref_fix1_Callback
2356    if ~isempty(ref)
2357        first_i=str2num(get(handles.first_i,'String'));
2358        last_i=str2num(get(handles.last_i,'String'));
2359        incr_i=str2num(get(handles.incr_i,'String'));
2360        first_j=str2num(get(handles.first_j,'String'));
2361        last_j=str2num(get(handles.last_j,'String'));
2362        incr_j=str2num(get(handles.incr_j,'String'));
2363        num_i_ref=first_i:incr_i:last_i;
2364        num_j_ref=first_j:incr_j:last_j;
2365        if isequal(mode,'displacement')
2366            num_i1=num_i_ref;
2367            num_i2=num_i_ref;
2368            num_j1=num_j_ref;
2369            num_j2=num_j_ref;
2370        elseif isequal(mode,'pair j1-j2')% isequal(mode,'st_pair j1-j2')
2371            num_i1=num_i_ref;
2372            num_i2=num_i1;
2373            num_j1=ref.num_a*ones(size(num_i_ref));
2374            num_j2=ref.num_b*ones(size(num_i_ref));
2375        elseif isequal(mode,'series(Di)') % isequal(mode,'st_series(Di)')
2376            delta1=floor((ref.num2-ref.num1)/2);
2377            delta2=ceil((ref.num2-ref.num1)/2);
2378            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2379            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2380            if isempty(ref.num_a)
2381                ref.num_a=1;
2382            end
2383            num_j1=ref.num_a*ones(size(num_i1));
2384            num_j2=num_j1;
2385        elseif isequal(mode,'series(Dj)')%| isequal(mode,'st_series(Dj)')
2386            delta1=floor((ref.num_b-ref.num_a)/2);
2387            delta2=ceil((ref.num_b-ref.num_a)/2);
2388            num_i1=ref.num1*ones(size(num_i_ref));
2389            num_i2=num_i1;
2390            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2391            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2392        end
2393        for ifile=1:nbfield
2394            for j=1:nbslice
2395                file_ref=name_generator(ref.filebase,num_i1(ifile),num_j1(j),'.nc',ref.nom_type,1,num_i2(ifile),num_j2(j),ref.subdir);%
2396                file_ref_fix1(ifile,j)={file_ref};
2397                if ~exist(file_ref,'file')
2398                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix1'])
2399                    filecell=[];
2400                    return
2401                end
2402            end
2403        end
2404    end
2405end
2406
2407%determine reference files for fix2:
2408if box_test(5)==1% fix2 performed
2409    ref=get(handles.ref_fix2,'UserData');
2410    if ~isempty(ref)
2411        first_i=str2double(get(handles.first_i,'String'));
2412        last_i=str2double(get(handles.last_i,'String'));
2413        incr_i=str2double(get(handles.incr_i,'String'));
2414        first_j=str2double(get(handles.first_j,'String'));
2415        last_j=str2double(get(handles.last_j,'String'));
2416        incr_j=str2double(get(handles.incr_j,'String'));
2417        num_i_ref=[first_i:incr_i:last_i];
2418        num_j_ref=[first_j:incr_j:last_j];
2419        if isequal(mode,'displacement')
2420            num_i1=num_i_ref;
2421            num_i2=num_i_ref;
2422            num_j1=num_j_ref;
2423            num_j2=num_j_ref;
2424        elseif isequal(mode,'pair j1-j2')
2425            num_i1=num_i_ref;
2426            num_i2=num_i1;
2427            num_j1=ref.num_a;
2428            num_j2=ref.num_b;
2429        elseif isequal(mode,'series(Di)')
2430            delta1=floor((ref.num2-ref.num1)/2);
2431            delta2=ceil((ref.num2-ref.num1)/2);
2432            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2433            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2434            num_j1=ref.num_a*ones(size(num_i1));
2435            num_j2=num_j1;
2436        elseif isequal(mode,'series(Dj)')
2437            delta1=floor((ref.num_b-ref.num_a)/2);
2438            delta2=ceil((ref.num_b-ref.num_a)/2);
2439            num_i1=ref.num1*ones(size(num_i_ref));
2440            num_i2=num_i1;
2441            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2442            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2443        end
2444        for ifile=1:nbfield
2445            for j=1:nbslice
2446                file_ref=name_generator(ref.filebase,num_i1(ifile),num_j1(j),'.nc',ref.nom_type,1,num_i2(ifile),num_j2(j),ref.subdir);%
2447                file_ref_fix2(ifile,j)={file_ref};
2448                if ~exist(file_ref,'file')
2449                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix2'])
2450                    filecell={};
2451                    return
2452                end
2453            end
2454        end
2455    end
2456end
2457
2458%check dir
2459subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf output data
2460subdir_civ2=get(handles.subdir_civ2,'String');
2461if isequal(subdir_civ1,''),subdir_civ1='A'; end% put default subdir
2462if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
2463currentdir=pwd%store the current working directory
2464[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
2465if ~exist(Path_ima,'dir')
2466    msgbox_uvmat('ERROR',['path to images ' Path_ima ' not found'])
2467    filecell={};
2468    return
2469end
2470[xx,message]=fileattrib(Path_ima);
2471if ~isempty(message) && ~isequal(message.UserWrite,1)
2472    msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
2473    filecell={};
2474    cd(currentdir);
2475    return
2476end
2477
2478%check the existence of the netcdf and image files involved
2479% %%%%%%%%%%%%  case CIV1 activated   %%%%%%%%%%%%%
2480if box_test(1)==1;
2481    detect=1;
2482    vers=0;
2483    subdir_civ1_new=subdir_civ1;
2484    while detect==1 %create a new subdir if the netcdf files already exist
2485        for ifile=1:nbfield
2486            for j=1:nbslice
2487                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);
2488                detect=exist(filename,'file')==2;
2489                if detect% if a netcdf file already exists
2490                    indstr=regexp(subdir_civ1,'\D');
2491                    if indstr(end)<length(subdir_civ1) %subdir_civ1 ends by a number
2492                        vers=str2double(subdir_civ1(indstr(end)+1:end))+1;
2493                        subdir_civ1_new=[subdir_civ1(1:indstr(end)) num2str(vers)];
2494                    else
2495                        vers=vers+1;
2496                        subdir_civ1_new=[subdir_civ1(1:indstr(end)) '_' num2str(vers)];       
2497                    end
2498                    subdir_civ2=subdir_civ1;
2499                    break
2500                end
2501                filecell.nc.civ1(ifile,j)={filename};
2502            end
2503            if detect% if a netcdf file already exists
2504                break
2505            end
2506        end
2507 
2508        %create the new subdir_civ1
2509        if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
2510            cd(Path_ima);         
2511            [xx,msg1]=mkdir(subdir_civ1_new);
2512
2513            if ~strcmp(msg1,'')
2514                msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])%error message for directory creation
2515                filecell={};
2516                return
2517            else         
2518                [xx,msg2] = fileattrib(subdir_civ1_new,'+w','g'); %yield writing access (+w) to user group (g)
2519                if ~strcmp(msg2,'')
2520                    msgbox_uvmat('ERROR',['pb of permission for  ' subdir_civ1_new ': ' msg2])%error message for directory creation
2521                    filecell={};
2522                    return
2523                end
2524            end
2525            cd(currentdir);
2526        end
2527        if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
2528%             vers=0;
2529%             subdir_civ1_new=subdir_civ1;
2530            for ifile=1:nbfield
2531                for j=1:nbslice
2532                    filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);%
2533                    detect=exist(filename,'file')==2;
2534                    if detect% if a netcdf file already exists
2535                       indstr=regexp(subdir_civ1,'\D');
2536                       if indstr(end)<length(subdir_civ1) %subdir_civ1 ends by a number
2537                           vers=str2double(subdir_civ1(indstr(end)+1:end))+1;
2538                           subdir_civ1_new=[subdir_civ1(1:indstr(end)) num2str(vers)];
2539                       else
2540                           vers=vers+1;
2541                           subdir_civ1_new=[subdir_civ1 '_' num2str(vers)];
2542                       end
2543                       subdir_civ2=subdir_civ1;
2544                       break
2545                    end
2546                    filecell.ncA.civ1(ifile,j)={filename};
2547                end
2548                if detect% if a netcdf file already exists
2549                    break
2550                end
2551            end
2552%             subdir_civ1=subdir_civ1_new;
2553            %create the new subdir_civ1
2554            if exist(fullfile(Path_ima,subdir_civ1_new),'dir')
2555                   cd(Path_ima);         
2556                [xx,msg1]=mkdir(subdir_civ1_new);
2557                            cd(currentdir);
2558                if ~strcmpl(msg1,'')
2559                    msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])
2560                    cd(currentdir)
2561                    filecell={};
2562                    return
2563                else
2564                    [xx,msg2] = fileattrib(subdir_civ1_new,'+w','g'); %yield writing access (+w) to user group (g)
2565                    if ~strcmp(msg2,'')
2566                        msgbox_uvmat('ERROR',['pb of permission for ' subdir_civ1_new ': ' msg2])%error message for directory creation
2567                        cd(currentdir)
2568                        filecell={};
2569                        return
2570                    end
2571                end
2572            end
2573        end
2574    end
2575    subdir_civ1=subdir_civ1_new;
2576    % get image names
2577    for ifile=1:nbfield
2578        for j=1:nbslice
2579            filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2580            idetect(j)=exist(filename,'file')==2;
2581            filecell.ima1.civ1(ifile,j)={filename}; %first image
2582            filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2583            idetect_1(j)=exist(filename,'file')==2;
2584            filecell.ima2.civ1(ifile,j)={filename};%second image
2585        end
2586        [idetectmin,indexj]=min(idetect);
2587        if idetectmin==0,
2588            msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
2589            filecell={};
2590            cd(currentdir)
2591            return
2592        end
2593        [idetectmin,indexj]=min(idetect_1);
2594        if idetectmin==0,
2595            msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
2596            filecell={};
2597            cd(currentdir)
2598            return
2599        end
2600    end
2601    if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
2602        for ifile=1:nbfield
2603            for j=1:nbslice
2604                filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2605                idetect(j)=exist(filename,'file')==2;
2606                filecell.imaA1.civ1(ifile,j)={filename} ;%first image
2607                filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2608                idetect_1(j)=exist(filename,'file')==2;
2609                filecell.imaA2.civ1(ifile,j)={filename};%second image
2610            end
2611            [idetectmin,indexj]=min(idetect);
2612            if idetectmin==0,
2613                msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
2614                filecell={};
2615                cd(currentdir)
2616                return
2617            end
2618            [idetectmin,indexj]=min(idetect_1);
2619            if idetectmin==0,
2620                msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
2621                filecell={};
2622                cd(currentdir)
2623                return
2624            end
2625        end
2626    end
2627   
2628    %%%%%%%%%%%%%  fix1 or patch1 activated but no civ1   %%%%%%%%%%%%%
2629elseif (box_test(2)==1 || box_test(3)==1);
2630    for ifile=1:nbfield
2631        for j=1:nbslice
2632            filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2633                nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2634            detect=exist(filename,'file')==2;
2635            if detect==0
2636                msgbox_uvmat('ERROR',[filename ' not found'])
2637                filecell={};
2638                cd(currentdir)
2639                return
2640            end
2641            filecell.nc.civ1(ifile,j)={filename};
2642        end
2643    end
2644    if strcmp(compare,'stereo PIV')
2645        for ifile=1:nbfield
2646            for j=1:nbslice
2647                filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2648                filecell.ncA.civ1(ifile,j)={filename};
2649                if ~exist(filename,'file')
2650                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2651                    set(handles.RUN, 'Enable','On')
2652                    set(handles.RUN,'BackgroundColor',[1 0 0])
2653                    filecell={};
2654                    cd(currentdir)
2655                    return
2656                end
2657            end
2658        end
2659    end
2660end
2661
2662%%%%%%%%%%%%%  if civ2 performed with pairs different than civ1  %%%%%%%%%%%%%
2663testdiff=0;
2664if (box_test(4)==1)&&...
2665        ((get(handles.list_pair_civ1,'Value')~=get(handles.list_pair_civ2,'Value'))||~strcmp(subdir_civ2,subdir_civ1))
2666    testdiff=1;
2667    detect=1;
2668    vers=0;
2669    subdir_civ2_new=subdir_civ2;
2670    while detect==1 %create a new subdir if the netcdf files already exist
2671        for ifile=1:nbfield
2672            for j=1:nbslice
2673                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2_new);%
2674                detect=exist(filename,'file')==2;
2675                if detect% if a netcdf file already exists
2676                    indstr=regexp(subdir_civ2,'\D');
2677                    if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2678                        vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2679                        subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2680                    else
2681                        vers=vers+1;
2682                        subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2683                    end
2684                    break
2685                end
2686                filecell.nc.civ2(ifile,j)={filename};
2687            end
2688            if detect% if a netcdf file already exists
2689                break
2690            end
2691        end
2692        %create the new subdir_civ2_new
2693        if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
2694            [xx,m2]=mkdir(subdir_civ2_new);
2695            [xx,msg2] = fileattrib(subdir_civ2_new,'+w','g'); %yield writing access (+w) to user group (g)
2696            if ~isequal(m2,'')
2697                msgbox_uvmat('ERROR',['cannot create ' subdir_civ2_new ': ' m2])
2698                filecell={};
2699                cd(currentdir)
2700                return
2701            end
2702        end
2703        if strcmp(compare,'stereo PIV')%check second nc series
2704            for ifile=1:nbfield
2705                for j=1:nbslice
2706                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2707                        nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2_new);%
2708                    detect=exist(filename,'file')==2;
2709                    if detect% if a netcdf file already exists
2710                        indstr=regexp(subdir_civ2,'\D');
2711                        if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2712                           vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2713                           subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2714                        else
2715                           vers=vers+1;
2716                           subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2717                        end
2718                        break
2719                    end
2720                    filecell.ncA.civ2(ifile,j)={filename};
2721                end
2722                if detect% if a netcdf file already exists
2723                    break
2724                end
2725            end
2726            subdir_civ2=subdir_civ2_new;
2727            %create the new subdir_civ1
2728            if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
2729                [xx,m2]=mkdir(subdir_civ2_new);
2730                 [xx,msg2] = fileattrib(subdir_civ2_new,'+w','g'); %yield writing access (+w) to user group (g)
2731                if ~isequal(m2,'')
2732                    msgbox_uvmat('ERROR', ['cannot create ' subdir_civ2_new ': ' m2])%error message for directory creation
2733                    cd(currentdir)
2734                    filecell={};
2735                    return
2736                end
2737            end
2738        end
2739    end
2740    subdir_civ2=subdir_civ2_new;
2741end
2742cd(currentdir);%come back to the current working directory
2743
2744%%%%%%%%%%%%%  if civ2 results are obtained or used  %%%%%%%%%%%%%
2745if box_test(4)==1 || box_test(5)==1 || box_test(6)==1 %civ2
2746    %check source netcdf file of civ1 estimates
2747    if box_test(1)==0; %no civ1 performed
2748        for ifile=1:nbfield
2749            for j=1:nbslice
2750                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2751                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2752                filecell.nc.civ1(ifile,j)={filename};% name of the civ1 file
2753                if ~exist(filename,'file')
2754                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2755                    filecell={};
2756                    return
2757                end
2758                if ~testdiff % civ2 or patch2 are written in the same file as civ1
2759                    if box_test(4)==0 ; %check the existence of civ2 if it is not calculated
2760                        Data=nc2struct(filename,'ListGlobalAttribute','civ2');
2761                        if isempty(Data.civ2)||isequal(Data.civ2,0)
2762                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2763                            filecell=[];
2764                            return
2765                        end
2766                    elseif box_test(3)==0; %check the existence of patch if it is not calculated
2767                        Data=nc2struct(filename,'ListGlobalAttribute','patch');
2768                        if isempty(Data.patch)||isequal(Data.patch,0)
2769                            msgbox_uvmat('ERROR',['no patch data in ' filename])
2770                            filecell=[];
2771                            return
2772                        end
2773                    end
2774                end
2775            end
2776        end
2777        if strcmp(compare,'stereo PIV')
2778            for ifile=1:nbfield
2779                for j=1:nbslice
2780                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2781                        nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2782                    filecell.ncA.civ2(ifile,j)={filename};
2783                    if ~exist(filename,'file')
2784                        msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2785                        set(handles.RUN, 'Enable','On')
2786                        set(handles.RUN,'BackgroundColor',[1 0 0])
2787                        return
2788                    end
2789                end
2790            end
2791        end
2792    end
2793   
2794    detect=1;
2795    %     while detect==1%creates a new subdir if the netcdf files already contain civ2 data
2796    for ifile=1:nbfield
2797        for j=1:nbslice
2798            filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2799                nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);
2800            detect=exist(filename,'file')==2;
2801            filecell.nc.civ2(ifile,j)={filename};
2802        end
2803    end
2804    %get first image names for civ2
2805    if box_test(1)==1 & isequal(num1_civ1,num1_civ2) & isequal(num_a_civ1,num_a_civ2)
2806        filecell.ima1.civ2=filecell.ima1.civ1;
2807    elseif box_test(4)==1
2808        for ifile=1:nbfield
2809            for j=1:nbslice
2810                filename=name_generator(filebase_ima1, num1_civ2(ifile),num_a_civ2(j),ext_ima,nom_type_ima1);
2811                idetect_2(j)=exist(filename,'file')==2;
2812                filecell.ima1.civ2(ifile,j)={filename};%first image
2813            end
2814            [idetectmin,indexj]=min(idetect_2);
2815            if idetectmin==0,
2816                msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
2817                filecell=[];
2818                return
2819            end
2820        end
2821    end
2822   
2823    %get second image names for civ2
2824    if box_test(1)==1 & isequal(num2_civ1,num2_civ2) & isequal(num_b_civ1,num_b_civ2)
2825        filecell.ima2.civ2=filecell.ima2.civ1;
2826    elseif box_test(4)==1
2827        for ifile=1:nbfield
2828            for j=1:nbslice
2829                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),ext_ima,nom_type_ima2);
2830                idetect_3(j)=exist(filename,'file')==2;
2831                filecell.ima2.civ2(ifile,j)={filename};%first image
2832            end
2833            [idetectmin,indexj]=min(idetect_3);
2834            if idetectmin==0,
2835                msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
2836                filecell=[];
2837                return
2838            end
2839        end
2840    end
2841end
2842if (box_test(5)==1 || box_test(6)==1 ) && box_test(4)==0  % need to read an existing netcdf civ2 file
2843    if ~testdiff
2844        filecell.nc.civ2=filecell.nc.civ1;% file already checked
2845    else     % check the civ2 files
2846        for ifile=1:nbfield
2847            for j=1:nbslice
2848                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2849                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2850                filecell.nc.civ2(ifile,j)={filename};
2851                if ~exist(filename,'file')
2852                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2853                    filecell=[];
2854                    return
2855                else
2856                    Data=nc2struct(filename,'ListGlobalAttribute','civ2');
2857                    if isempty(Data.civ2)||isequal(Data.civ2,0)
2858                        msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2859                        filecell=[];
2860                        return
2861                    end
2862                end
2863            end
2864        end
2865    end
2866end
2867
2868%%%%%%%%%%%%%  if stereo fields are calculated by PATCH %%%%%%%%%%%%%
2869if strcmp(compare,'stereo PIV')
2870    if  box_test(3)==1 && isequal(get(handles.test_stereo1,'Value'),1)
2871        for ifile=1:nbfield
2872            for j=1:nbslice
2873                filename=name_generator(filebase_AB,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2874                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2875                filecell.st(ifile,j)={filename};
2876            end
2877        end
2878    end
2879    if  box_test(6)==1 && isequal(get(handles.test_stereo2,'Value'),1)
2880        for ifile=1:nbfield
2881            for j=1:nbslice
2882                filename=name_generator(filebase_AB,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2883                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2884                filecell.st(ifile,j)={filename};
2885            end
2886        end
2887    end
2888end
2889set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
2890set(handles.subdir_civ2,'String',subdir_civ2);%update the edit box
2891browse.nom_type_nc=nom_type_nc;
2892set(handles.browse_root,'UserData',browse); %update the nomenclature type for uvmat
2893
2894
2895%COPY IMAGES TO THE FORMAT .png IF NEEDED
2896if isequal(nom_type_ima1,'*')%case of movie files
2897    nom_type_imanew1='_i';
2898else
2899    nom_type_imanew1=nom_type_ima1;
2900end
2901if isequal(nom_type_ima2,'*')%case of movie files
2902    nom_type_imanew2='_i';
2903else
2904    nom_type_imanew2=nom_type_ima2;
2905end
2906if ~isequal(ext_ima,'.png')
2907    %%type of image file
2908    type_ima1='none';%default
2909    movieobject1=[];%default
2910    if strcmpi(ext_ima,'.avi')
2911        hhh=which('mmreader');
2912        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2913            type_ima1='movie';
2914            movieobject1=mmreader([filebase_ima2 ext_ima]);
2915        else
2916            type_ima1='avi';
2917        end
2918    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
2919        form=imformats(ext_ima(2:end));
2920        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2921            if isequal(nom_type_ima1,'*');
2922                type_ima1='multimage';%image series in a single image file
2923            else
2924                type_ima1='image';
2925            end
2926        end
2927    end
2928    type_ima2='none';%default
2929    movieobject2=[];
2930    if strcmpi(ext_ima,'.avi')
2931        hhh=which('mmreader');
2932        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2933            type_ima2='movie';
2934            movieobject2=mmreader([filebase_ima2 ext_ima]);
2935        else
2936            type_ima2='avi';
2937        end
2938    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
2939        form=imformats(ext_ima(2:end));
2940        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2941            if isequal(nom_type_ima1,'*');
2942                type_ima2='multimage';%image series in a single image file
2943            else
2944                type_ima2='image';
2945            end
2946        end
2947    end
2948    %npxy=get(handles.ImaExt,'UserData');
2949    % %     if numel(npxy)<2
2950    %
2951    %         filename=name_generator(filebase_ima1,num1_civ1(1),num_a_civ1(1),ImaExt,nom_type_ima1);
2952    %         A=imread(filename);
2953    %         npxy=size(A);
2954    % %     end
2955    %     npy=npxy(1);
2956    %     npx=npxy(2);
2957    if box_test(1)==1 %if civ1 is performed
2958        h = waitbar(0,['copy images to the .png format for civ1']);% display a wait bar
2959        for ifile=1:nbfield
2960            waitbar(ifile/nbfield);
2961            for j=1:nbslice
2962                filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
2963                if ~exist(filename,'file')
2964                    A=read_image(filecell.ima1.civ1{ifile,j},type_ima1,num1_civ1(ifile),movieobject1);
2965                    imwrite(A,filename,'BitDepth',16);
2966                end
2967                filecell.ima1.civ1(ifile,j)={filename};
2968                filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
2969                if ~exist(filename,'file')
2970                    A=read_image(filecell.ima2.civ1{ifile,j},type_ima2,num2_civ1(ifile),movieobject2);
2971                    imwrite(A,filename,'BitDepth',16);
2972                end
2973                filecell.ima2.civ1(ifile,j)={filename};
2974            end
2975        end
2976        close(h)
2977    end
2978    if box_test(4)==1 %if civ2 is performed
2979        h = waitbar(0,['copy images to the .png format for civ2']);% display a wait bar
2980        for ifile=1:nbfield
2981            waitbar(ifile/nbfield);
2982            for j=1:nbslice
2983                filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
2984                if ~exist(filename,'file')
2985                    A=read_image(cell2mat(filecell.ima1.civ2(ifile,j)),type_ima2,num1_civ2(ifile));
2986                    imwrite(A,filename,'BitDepth',16);
2987                end
2988                filecell.ima1.civ2(ifile,j)={filename};
2989                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
2990                if ~exist(filename,'file')
2991                    A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),type_ima2,num2_civ2(ifile));
2992                    imwrite(A,filename,'BitDepth',16);
2993                end
2994                filecell.ima2.civ2(ifile,j)={filename};
2995            end
2996        end
2997        close(h);
2998    end
2999end
3000
3001%------------------------------------------------------------------------
3002% --- PATCH
3003function cmd_PATCH=PATCH_CMD(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp,PatchBin)
3004%------------------------------------------------------------------------
3005namelog=[filename_nc([1:end-3]) '_patch.log'];
3006if test_interp==0
3007    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
3008        '  > ' namelog ' 2>&1']; % redirect standard output to the log file
3009else %nouveau programme patch
3010    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
3011        ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
3012end
3013
3014%------------------------------------------------------------------------
3015% --- STEREO Interp
3016function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
3017%------------------------------------------------------------------------
3018namelog=[filename_nc([1:end-3]) '_stinterp.log'];
3019cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
3020    ' -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
3021
3022%------------------------------------------------------------------------
3023% --- Executes on button press in CIV1.
3024function CIV1_Callback(hObject, eventdata, handles)
3025%------------------------------------------------------------------------
3026val=get(handles.CIV1,'Value');
3027if isequal(val,1)
3028    enable_civ1(handles,'on')
3029    enable_pair1(handles,'on')
3030else
3031    enable_civ1(handles,'off')
3032end
3033find_netcpair_civ1(hObject, eventdata, handles);
3034
3035%------------------------------------------------------------------------
3036% --- Executes on button press in FIX1.
3037function FIX1_Callback(hObject, eventdata, handles)
3038%------------------------------------------------------------------------
3039enable_fix1(handles,get(handles.FIX1,'Value'))
3040
3041%------------------------------------------------------------------------
3042% --- Executes on button press in PATCH1.
3043function PATCH1_Callback(hObject, eventdata, handles)
3044%------------------------------------------------------------------------
3045if get(handles.PATCH1,'Value')==1
3046    enable_patch1(handles)
3047else
3048    desable_patch1(handles)
3049end
3050
3051%------------------------------------------------------------------------
3052% --- Executes on button press in CIV2.
3053function CIV2_Callback(hObject, eventdata, handles)
3054%------------------------------------------------------------------------
3055state=get(handles.CIV2,'Value');
3056enable_civ2(handles,state)
3057if state
3058    find_netcpair_civ2(hObject, eventdata, handles)
3059    enable_pair1(handles,'on')
3060end
3061
3062%------------------------------------------------------------------------
3063% --- Executes on button press in FIX2.
3064function FIX2_Callback(hObject, eventdata, handles)
3065%------------------------------------------------------------------------
3066if get(handles.FIX2,'Value')==1
3067    enable_fix2(handles)
3068    if get(handles.CIV2,'Value')==0
3069        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
3070    end
3071else
3072    desable_fix2(handles)
3073end
3074
3075%------------------------------------------------------------------------
3076% --- Executes on button press in PATCH2.
3077function PATCH2_Callback(hObject, eventdata, handles)
3078%------------------------------------------------------------------------
3079if get(handles.PATCH2,'Value')==1
3080    enable_patch2(handles)
3081    if get(handles.CIV2,'Value')==0
3082        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
3083    end
3084else
3085    desable_patch2(handles)
3086end
3087
3088%------------------------------------------------------------------------
3089function first_i_Callback(hObject, eventdata, handles)
3090%------------------------------------------------------------------------
3091% last_i_Callback(hObject, eventdata, handles)
3092first_i=str2num(get(handles.first_i,'String'));
3093% last_i=str2num(get(handles.last_i,'String'));
3094% ref_i=ceil((first_i+last_i)/2);
3095set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
3096set(handles.ref_i_civ2,'String', num2str(first_i))% reference index for pair dt = first index
3097ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
3098
3099%------------------------------------------------------------------------
3100function first_j_Callback(hObject, eventdata, handles)
3101%------------------------------------------------------------------------
3102first_j=str2num(get(handles.first_j,'String'));
3103set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
3104ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
3105
3106%------------------------------------------------------------------------
3107% --- Executes on button press in calcul_search: determine the search range isx,isy
3108function calcul_search_Callback(hObject, eventdata, handles)
3109%------------------------------------------------------------------------
3110%determine pair numbers
3111list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
3112index=get(handles.list_pair_civ1,'Value');
3113displ_num=get(handles.list_pair_civ1,'UserData');
3114time=get(handles.RootName,'UserData'); %get the set of times
3115pxcm_xy=get(handles.calcul_search,'UserData');
3116pxcmx=pxcm_xy(1);
3117pxcmy=pxcm_xy(2);
3118mode_list=get(handles.mode,'String');
3119mode_value=get(handles.mode,'Value');
3120mode=mode_list{mode_value};
3121if isequal (mode, 'series(Di)' )
3122    ref_i=str2num(get(handles.ref_i,'String'));
3123    num1=ref_i-floor(index/2);%  first image numbers
3124    num2=ref_i+ceil(index/2);
3125    num_a=1;
3126    num_b=1;
3127elseif isequal (mode, 'series(Dj)')
3128    num1=1;
3129    num2=1;
3130    ref_j=str2num(get(handles.ref_j,'String'));
3131    num_a=ref_j-floor(index/2);%  first image numbers
3132    num_b=ref_j+ceil(index/2);
3133elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
3134    ref_i=str2num(get(handles.ref_i,'String'));
3135    num1=ref_i;
3136    num2=ref_i;
3137    num_a=displ_num(1,index);
3138    num_b=displ_num(2,index);
3139end
3140dt=time(num2,num_b)-time(num1,num_a);
3141ibx=str2num(get(handles.ibx,'String'));
3142iby=str2num(get(handles.iby,'String'));
3143umin=dt*pxcmx*str2num(get(handles.umin,'String'));
3144umax=dt*pxcmx*str2num(get(handles.umax,'String'));
3145vmin=dt*pxcmy*str2num(get(handles.vmin,'String'));
3146vmax=dt*pxcmy*str2num(get(handles.vmax,'String'));
3147shiftx=round((umin+umax)/2);
3148shifty=round((vmin+vmax)/2);
3149isx=(umax+2-shiftx)*2+ibx;
3150isx=2*ceil(isx/2)+1;
3151isy=(vmax+2-shifty)*2+iby;
3152isy=2*ceil(isy/2)+1;
3153set(handles.shiftx,'String',num2str(shiftx));
3154set(handles.shifty,'String',num2str(shifty));
3155set(handles.isx,'String',num2str(isx));
3156set(handles.isy,'String',num2str(isy));
3157
3158%------------------------------------------------------------------------
3159% --- Executes on carriage return on the subdir civ1 edit window
3160function subdir_civ1_Callback(hObject, eventdata, handles)
3161%------------------------------------------------------------------------
3162subdir=get(handles.subdir_civ1,'String');
3163set(handles.subdir_civ2,'String',subdir);
3164if get(handles.CIV1,'Value')==0
3165    find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
3166end
3167
3168%------------------------------------------------------------------------
3169% --- Executes on carriage return on the subdir civ1 edit window
3170function subdir_civ2_Callback(hObject, eventdata, handles)
3171%------------------------------------------------------------------------
3172%update the list of available pairs from netcdf files in the new directory
3173if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
3174    find_netcpair_civ2(hObject, eventdata, handles);
3175end
3176
3177%------------------------------------------------------------------------
3178% --- Executes on button press in get_mask_civ1: select box for mask option
3179function get_mask_civ1_Callback(hObject, eventdata, handles)
3180%------------------------------------------------------------------------
3181maskval=get(handles.get_mask_civ1,'Value');
3182if isequal(maskval,0)
3183    set(handles.mask_civ1,'String','')
3184else
3185    mask_displ='no mask'; %default
3186    filebase=get(handles.RootName,'String');
3187    [ nbslice_mask, flag_mask]=get_mask(filebase,handles);
3188    if isequal(flag_mask,1)
3189        mask_displ=[num2str(nbslice_mask) 'mask'];
3190    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
3191        common_path=fileparts(filebase);
3192        filebase_a=fullfile(common_path,get(handles.RootName_1,'String'));
3193        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3194        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice_mask)
3195            mask_displ='no mask';
3196        end
3197    end
3198    if isequal(mask_displ,'no mask')
3199        [FileName, PathName, filterindex] = uigetfile( ...
3200            {'*.png', ' (*.png)';
3201            '*.png',  '.png files '; ...
3202            '*.*', 'All Files (*.*)'}, ...
3203            'Pick a mask file *.png',filebase);
3204        mask_displ=fullfile(PathName,FileName);
3205        if ~exist(mask_displ,'file')
3206            mask_displ='no mask';
3207        end
3208    end
3209    if isequal(mask_displ,'no mask')
3210        set(handles.get_mask_civ1,'Value',0)
3211        set(handles.get_mask_fix1,'Value',0)
3212        set(handles.get_mask_civ2,'Value',0)
3213        set(handles.get_mask_fix2,'Value',0)
3214    else
3215        set(handles.get_mask_fix1,'Value',1)
3216        set(handles.get_mask_fix2,'Value',1)
3217    end
3218    set(handles.mask_civ1,'String',mask_displ)
3219    set(handles.mask_fix1,'String',mask_displ)
3220    set(handles.mask_civ2,'String',mask_displ)
3221    set(handles.mask_fix2,'String',mask_displ)
3222end
3223set(handles.get_mask_civ2,'Value',maskval)%update the civ2 mask with the same option as civ1
3224
3225%------------------------------------------------------------------------
3226% --- Executes on button press in get_mask_fix1.
3227function get_mask_fix1_Callback(hObject, eventdata, handles)
3228%------------------------------------------------------------------------
3229maskval=get(handles.get_mask_fix1,'Value');
3230if isequal(maskval,0)
3231    set(handles.mask_fix1,'String','')
3232else
3233    mask_displ='no mask'; %default
3234    filebase=get(handles.RootName,'String');
3235    [nbslice, flag_mask]=get_mask(filebase,handles);
3236    if isequal(flag_mask,1)
3237        mask_displ=[num2str(nbslice) 'mask'];
3238    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
3239        filebase_a=get(handles.RootName_1,'String');
3240        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3241        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
3242            mask_displ='no mask';
3243        end
3244    end
3245    if isequal(mask_displ,'no mask')
3246        [FileName, PathName, filterindex] = uigetfile( ...
3247            {'*.png', ' (*.png)';
3248            '*.png',  '.png files '; ...
3249            '*.*', 'All Files (*.*)'}, ...
3250            'Pick a mask file *.png',filebase);
3251        mask_displ=fullfile(PathName,FileName);
3252        if ~exist(mask_displ,'file')
3253            mask_displ='no mask';
3254        end
3255    end
3256    if isequal(mask_displ,'no mask')
3257        set(handles.get_mask_fix1,'Value',0)
3258        set(handles.get_mask_civ2,'Value',0)
3259        set(handles.get_mask_fix2,'Value',0)
3260    else
3261        %set(handles.get_mask_civ2,'Value',1)
3262        set(handles.get_mask_fix2,'Value',1)
3263    end
3264    set(handles.mask_fix1,'String',mask_displ)
3265    set(handles.mask_civ2,'String',mask_displ)
3266    set(handles.mask_fix2,'String',mask_displ)
3267end
3268
3269%------------------------------------------------------------------------
3270% --- Executes on button press in get_mask_civ2: select box for mask option
3271function get_mask_civ2_Callback(hObject, eventdata, handles)
3272%------------------------------------------------------------------------
3273maskval=get(handles.get_mask_civ2,'Value');
3274if isequal(maskval,0)
3275    set(handles.mask_civ2,'String','')
3276else
3277    mask_displ='no mask'; %default
3278    filebase=get(handles.RootName,'String');
3279    [nbslice, flag_mask]=get_mask(filebase,handles);
3280    if isequal(flag_mask,1)
3281        mask_displ=[num2str(nbslice) 'mask'];
3282    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
3283        filebase_a=get(handles.RootName_1,'String');
3284        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3285        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
3286            mask_displ='no mask';
3287        end
3288    end
3289    if isequal(mask_displ,'no mask')
3290        [FileName, PathName, filterindex] = uigetfile( ...
3291            {'*.png', ' (*.png)';
3292            '*.png',  '.png files '; ...
3293            '*.*', 'All Files (*.*)'}, ...
3294            'Pick a mask file *.png',filebase);
3295        mask_displ=fullfile(PathName,FileName);
3296        if ~exist(mask_displ,'file')
3297            mask_displ='no mask';
3298        end
3299    end
3300    if isequal(mask_displ,'no mask')
3301        set(handles.get_mask_civ2,'Value',0)
3302        set(handles.get_mask_fix2,'Value',0)
3303    else
3304        set(handles.get_mask_fix2,'Value',1)
3305    end
3306    set(handles.mask_civ2,'String',mask_displ)
3307    set(handles.mask_fix2,'String',mask_displ)
3308end
3309
3310%------------------------------------------------------------------------
3311% --- Executes on button press in get_mask_fix2.
3312function get_mask_fix2_Callback(hObject, eventdata, handles)
3313%------------------------------------------------------------------------
3314maskval=get(handles.get_mask_fix2,'Value');
3315if isequal(maskval,0)
3316    set(handles.mask_fix2,'String','')
3317else
3318    mask_displ='no mask'; %default
3319    filebase=get(handles.RootName,'String');
3320    [nbslice, flag_mask]=get_mask(filebase,handles);
3321    if isequal(flag_mask,1)
3322        mask_displ=[num2str(nbslice) 'mask'];
3323    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
3324        filebase_a=get(handles.RootName_1,'String');
3325        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3326        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
3327            mask_displ='no mask';
3328        end
3329    end
3330    if isequal(mask_displ,'no mask')
3331        [FileName, PathName, filterindex] = uigetfile( ...
3332            {'*.png', ' (*.png)';
3333            '*.png',  '.png files '; ...
3334            '*.*', 'All Files (*.*)'}, ...
3335            'Pick a mask file *.png',filebase);
3336        mask_displ=fullfile(PathName,FileName);
3337        if ~exist(mask_displ,'file')
3338            mask_displ='no mask';
3339        end
3340    end
3341    if isequal(mask_displ,'no mask')
3342        set(handles.get_mask_fix2,'Value',0)
3343    end
3344    set(handles.mask_fix2,'String',mask_displ)
3345end
3346
3347%------------------------------------------------------------------------
3348% --- function called to look for mask files
3349function [nbslice, flag_mask]=get_mask(filebase,handles)
3350%------------------------------------------------------------------------
3351%detect mask files, images with appropriate file base
3352%[filebase '_' xx 'mask'], xx=nbslice
3353%flag_mask=1 indicates detection
3354
3355flag_mask=0;%default
3356nbslice=1;
3357
3358% subdir=get(handles.subdir_civ1,'String');
3359[Path,Name]=fileparts(filebase);
3360if ~isdir(Path)
3361    msgbox_uvmat('ERROR','no path for input files')
3362    return
3363end
3364currentdir=pwd;
3365cd(Path);%move in the dir of the root name filebase
3366maskfiles=dir([Name '_*mask_*.png']);%look for mask files
3367cd(currentdir);%come back to the current working directory
3368if ~isempty(maskfiles)
3369    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
3370    % else
3371    flag_mask=1;
3372    maskname=maskfiles(1).name;% take the first mask file in the list
3373    [Path2,Name,ext]=fileparts(maskname);
3374    Namedouble=double(Name);
3375    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3376    ind_mask=findstr('mask',Name);
3377    i=ind_mask-1;
3378    while val(i)==0 & i>0
3379        i=i-1;
3380    end
3381    nbslice=str2num(Name(i+1:ind_mask-1));
3382    if ~isequal(nbslice,[]) & Name(i)=='_'
3383        flag_mask=1;
3384    else
3385        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
3386        return
3387        nbslice=1;
3388    end
3389end
3390
3391%------------------------------------------------------------------------
3392% --- function called to look for grid files
3393function [nbslice, flag_mask]=get_grid(filebase,handles)
3394%------------------------------------------------------------------------
3395flag_mask=0;%default
3396nbslice=1;
3397[Path,Name]=fileparts(filebase);
3398currentdir=pwd;
3399cd(Path);%move in the dir of the root name filebase
3400maskfiles=dir([Name '_*grid_*.grid']);%look for mask files
3401cd(currentdir);%come back to the current working directory
3402if ~isempty(maskfiles)
3403    flag_mask=1;
3404    maskname=maskfiles(1).name;% take the first mask file in the list
3405    [Path2,Name,ext]=fileparts(maskname);
3406    Namedouble=double(Name);
3407    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3408    ind_mask=findstr('grid',Name);
3409    i=ind_mask-1;
3410    while val(i)==0 & i>0
3411        i=i-1;
3412    end
3413    nbslice=str2num(Name(i+1:ind_mask-1));
3414    if ~isequal(nbslice,[]) & Name(i)=='_'
3415        flag_mask=1;
3416    else
3417        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
3418        return
3419        nbslice=1;
3420    end
3421end
3422
3423%------------------------------------------------------------------------
3424% --- transform numbers to letters
3425function str=num2stra(num,nom_type)
3426%------------------------------------------------------------------------
3427if isempty(nom_type)
3428    str='';
3429elseif strcmp(nom_type(end),'a')
3430    str=char(96+num);
3431elseif strcmp(nom_type(end),'A')
3432    str=char(96+num);
3433elseif isempty(nom_type(2:end))%a single index
3434    str='';
3435else
3436    str=num2str(num);
3437end
3438
3439%------------------------------------------------------------------------
3440function mask_civ1_Callback(hObject, eventdata, handles)
3441%------------------------------------------------------------------------
3442set(handles.mask_civ1,'UserData',[])
3443set(handles.mask_civ1,'String','')
3444
3445%------------------------------------------------------------------------
3446function mask_civ2_Callback(hObject, eventdata, handles)
3447%------------------------------------------------------------------------
3448set(handles.mask_civ2,'UserData',[])
3449set(handles.mask_civ2,'String','')
3450
3451%------------------------------------------------------------------------
3452function mask_fix1_Callback(hObject, eventdata, handles)
3453%------------------------------------------------------------------------
3454set(handles.mask_fix1,'UserData',[])
3455set(handles.mask_fix1,'String','')
3456
3457%------------------------------------------------------------------------
3458function mask_fix2_Callback(hObject, eventdata, handles)
3459%------------------------------------------------------------------------
3460set(handles.mask_fix2,'UserData',[])
3461set(handles.mask_fix2,'String','')
3462
3463%------------------------------------------------------------------------
3464% --- Executes on button press in list_subdir_civ1.
3465function list_subdir_civ1_Callback(hObject, eventdata, handles)
3466%------------------------------------------------------------------------
3467list_subdir_civ1=get(handles.list_subdir_civ1,'String');
3468val=get(handles.list_subdir_civ1,'Value');
3469if val>1
3470    subdir=list_subdir_civ1{val};
3471    set(handles.subdir_civ1,'String',subdir);
3472    set(handles.list_subdir_civ1,'Value',1);
3473end
3474
3475%------------------------------------------------------------------------
3476% --- Executes on button press in list_subdir_civ2.
3477function list_subdir_civ2_Callback(hObject, eventdata, handles)
3478%------------------------------------------------------------------------
3479list_subdir_civ2=get(handles.list_subdir_civ2,'String');
3480val=get(handles.list_subdir_civ2,'Value');
3481if val>1
3482    subdir=list_subdir_civ2{val};
3483    set(handles.subdir_civ2,'String',subdir);
3484    set(handles.list_subdir_civ2,'Value',1);
3485end
3486
3487%------------------------------------------------------------------------
3488% --- Executes on button press in browse_gridciv1.
3489function browse_gridciv1_Callback(hObject, eventdata, handles)
3490%------------------------------------------------------------------------
3491value=get(handles.browse_gridciv1,'Value');
3492testgrid=0;
3493if value
3494    filebase=get(handles.RootName,'String');
3495    [nbslice, flag_grid]=get_grid(filebase,handles);
3496    if isequal(flag_grid,1)
3497        filegrid=[num2str(nbslice) 'grid'];
3498        testgrid=1;
3499    else
3500        [FileName, PathName, filterindex] = uigetfile( ...
3501            {'*.grid', ' (*.grid)';
3502            '*.grid',  '.grid files '; ...
3503            '*.*', 'All Files (*.*)'}, ...
3504            'Pick a file',filebase);
3505        filegrid=fullfile(PathName,FileName);
3506        if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file'))
3507            testgrid=1;
3508        end
3509    end
3510end
3511if testgrid
3512    set(handles.browse_gridciv2,'Value',1)
3513    set(handles.get_gridpatch1,'Value',1)
3514    set(handles.get_gridpatch2,'Value',1)
3515    set(handles.dx_civ1,'Visible','off');
3516    set(handles.dy_civ1,'Visible','off');
3517    set(handles.dx_civ2,'Visible','off');
3518    set(handles.dy_civ2,'Visible','off');
3519    set(handles.grid_civ1,'String',filegrid)
3520    set(handles.grid_patch1,'String',filegrid)
3521    set(handles.grid_civ2,'String',filegrid)
3522    set(handles.grid_patch2,'String',filegrid)
3523else
3524    set(handles.browse_gridciv1,'Value',0);
3525    set(handles.browse_gridciv2,'Value',0);
3526    set(handles.get_gridpatch1,'Value',0)
3527    set(handles.get_gridpatch2,'Value',0)
3528    set(handles.dx_civ1,'Visible','on');
3529    set(handles.dy_civ1,'Visible','on');
3530    set(handles.dx_civ2,'Visible','on');
3531    set(handles.dy_civ2,'Visible','on');
3532    set(handles.grid_civ1,'String','')
3533    set(handles.grid_patch1,'String','')
3534    set(handles.grid_civ2,'String','')
3535    set(handles.grid_patch2,'String','')
3536end
3537
3538%------------------------------------------------------------------------
3539% --- Executes on button press in browse_gridciv1.
3540function browse_gridciv2_Callback(hObject, eventdata, handles)
3541%------------------------------------------------------------------------
3542value=get(handles.browse_gridciv2,'Value');
3543if value
3544    filebase=get(handles.RootName,'String');
3545    [nbslice, flag_grid]=get_grid(filebase,handles);
3546    if isequal(flag_grid,1)
3547        mask_displ=[num2str(nbslice) 'grid'];
3548        set(handles.grid_civ2,'String',mask_displ)
3549        set(handles.dx_civ2,'Visible','off');
3550        set(handles.dy_civ2,'Visible','off');
3551    else
3552        [FileName, PathName, filterindex] = uigetfile( ...
3553            {'*.grid', ' (*.grid)';
3554            '*.grid',  '.grid files '; ...
3555            '*.*', 'All Files (*.*)'}, ...
3556            'Pick a file',filebase);
3557        filegrid=fullfile(PathName,FileName);
3558        if isempty(FileName)|isempty(PathName)|isequal(FileName,0)|~exist(filegrid,'file')
3559            set(handles.browse_gridciv2,'Value',0);
3560            set(handles.grid_civ2,'string','');
3561            set(handles.dx_civ2,'Visible','on');
3562            set(handles.dy_civ2,'Visible','on');
3563            set(handles.grid_civ2,'string','');
3564        else
3565            set(handles.grid_civ2,'string',filegrid);
3566            set(handles.dx_civ2,'Visible','off');
3567            set(handles.dy_civ2,'Visible','off');
3568            set(handles.grid_civ2,'string',filegrid);
3569        end
3570    end
3571else
3572    set(handles.grid_civ2,'string','');
3573    set(handles.dx_civ2,'Visible','on');
3574    set(handles.dy_civ2,'Visible','on');
3575    set(handles.grid_civ2,'string','');
3576end
3577
3578% % --- Executes on button press in browse_gridciv2.
3579% function browse_gridciv2_Callback(hObject, eventdata, handles)
3580%
3581% filebase=get(handles.RootName,'String');
3582% [FileName, PathName, filterindex] = uigetfile( ...
3583%        {'*.grid', ' (*.grid)';
3584%         '*.grid',  '.grid files '; ...
3585%         '*.*', 'All Files (*.*)'}, ...
3586%         'Pick a file',filebase);
3587% filegrid=fullfile(PathName,FileName);
3588% set(handles.grid_civ2,'string',filegrid);
3589% set(handles.dx_civ2,'String',' ');
3590% set(handles.dy_civ2,'String',' ');
3591% % set(handles.grid_patch2,'string',filegrid);
3592
3593% --- Executes on button press in get_gridpatch1.
3594function get_gridpatch1_Callback(hObject, eventdata, handles)
3595% hObject    handle to get_gridpatch1 (see GCBO)
3596% eventdata  reserved - to be defined in a future version of MATLAB
3597% handles    structure with handles and user data (see GUIDATA)
3598
3599filebase=get(handles.RootName,'String');
3600[FileName, PathName, filterindex] = uigetfile( ...
3601    {'*.grid', ' (*.grid)';
3602    '*.grid',  '.grid files '; ...
3603    '*.*', 'All Files (*.*)'}, ...
3604    'Pick a file',filebase);
3605filegrid=fullfile(PathName,FileName);
3606set(handles.grid_patch1,'string',filegrid);
3607% set(handles.grid_patch2,'string',filegrid
3608
3609%------------------------------------------------------------------------
3610% --- Executes on button press in get_gridpatch2.
3611function get_gridpatch2_Callback(hObject, eventdata, handles)
3612%------------------------------------------------------------------------
3613
3614%------------------------------------------------------------------------
3615function enable_civ1(handles,state)
3616%------------------------------------------------------------------------
3617if isequal(state,0)
3618    state='off';
3619end
3620if isequal(state,1)
3621    state='on';
3622end
3623if isequal(state,'on')
3624    set(handles.frame_civ1,'BackgroundColor',[1 1 0])
3625    set(handles.frame_para_civ1,'BackgroundColor',[1 1 0])
3626    set(handles.frame_grid_civ1,'BackgroundColor',[1 1 0])
3627else
3628    set(handles.frame_civ1,'BackgroundColor',[0.831 0.816 0.784])
3629    set(handles.frame_para_civ1,'BackgroundColor',[0.831 0.816 0.784])
3630    set(handles.frame_grid_civ1,'BackgroundColor',[0.831 0.816 0.784])
3631end
3632set(handles.ibx,'Visible',state)
3633set(handles.iby,'Visible',state)
3634set(handles.isx,'Visible',state)
3635set(handles.isy,'Visible',state)
3636set(handles.shiftx,'Visible',state)
3637set(handles.shifty,'Visible',state)
3638set(handles.rho,'Visible',state)
3639set(handles.dx_civ1,'Visible',state)
3640set(handles.dy_civ1,'Visible',state)
3641set(handles.calcul_search,'Visible',state)
3642set(handles.u_text,'Visible',state)
3643set(handles.v_text,'Visible',state)
3644set(handles.min,'Visible',state)
3645set(handles.max,'Visible',state)
3646set(handles.umin,'Visible',state)
3647set(handles.umax,'Visible',state)
3648set(handles.vmin,'Visible',state)
3649set(handles.vmax,'Visible',state)
3650set(handles.grid_civ1,'Visible',state)
3651set(handles.mask_civ1,'Visible',state)
3652set(handles.browse_gridciv1,'Visible',state)
3653set(handles.get_mask_civ1,'Visible',state)
3654set(handles.parameters,'Visible',state)
3655set(handles.grid,'Visible',state)
3656set(handles.dx_civ1,'Visible',state)
3657set(handles.dy_civ1,'Visible',state)
3658set(handles.ImaThreshold,'Visible',state)
3659if isequal(state,'off')
3660    set(handles.MinIma,'Visible','off')
3661    set(handles.MaxIma,'Visible','off')
3662    set(handles.ImaThreshold,'Value',0)
3663end
3664set(handles.dx_civ1_title,'Visible',state)
3665set(handles.dy_civ1_title,'Visible',state)
3666set(handles.ImaThreshold_title,'Visible',state)
3667set(handles.ib_title,'Visible',state)
3668set(handles.is_title,'Visible',state)
3669set(handles.shift_title,'Visible',state)
3670set(handles.rho_title,'Visible',state)
3671
3672%------------------------------------------------------------------------
3673function enable_fix1(handles,state)
3674%------------------------------------------------------------------------
3675if isequal(state,0)
3676    state='off';
3677end
3678if isequal(state,1)
3679    state='on';
3680end
3681if isequal(state,'on')
3682    set(handles.frame_fix1,'BackgroundColor',[1 1 0])
3683else
3684    set(handles.frame_fix1,'BackgroundColor',[0.7 0.7 0.7])
3685end
3686set(handles.REMOVE,'Visible',state)
3687set(handles.vec_Fmin2,'Visible',state)
3688set(handles.vec_F2,'Visible',state)
3689set(handles.vec_F3,'Visible',state)
3690set(handles.thresh_vecC,'Visible',state)
3691set(handles.thresh_vecC_title,'Visible',state)
3692set(handles.thresh_vel,'Visible',state)
3693set(handles.thresh_vel_text,'Visible',state)
3694set(handles.mask_fix1,'Visible',state)
3695set(handles.get_mask_fix1,'Visible',state)
3696set(handles.get_ref_fix1,'Visible',state)
3697set(handles.ref_fix1,'Visible',state)
3698set(handles.inf_sup1,'Visible',state)
3699set(handles.field_ref1,'Visible',state)
3700
3701%------------------------------------------------------------------------
3702function enable_patch1(handles)
3703%------------------------------------------------------------------------
3704global patch_newBin
3705set(handles.frame_patch1,'BackgroundColor',[1 1 0])
3706set(handles.rho_patch1,'Visible','on')
3707set(handles.rho_text1,'Visible','on')
3708set(handles.thresh_patch1,'Visible','on')
3709set(handles.thresh_text1,'Visible','on')
3710set(handles.subdomain_patch1,'Visible','on')
3711set(handles.subdomain_text1,'Visible','on')
3712set(handles.nx_patch1,'Visible','on')
3713set(handles.ny_patch1,'Visible','on')
3714set(handles.nx_patch1_title,'Visible','on')
3715set(handles.ny_patch1_title,'Visible','on')
3716% if ~isempty(patch_newBin)
3717%     set(handles.test_interp,'Visible','on');
3718% end
3719set(handles.get_gridpatch1,'Visible','on')
3720set(handles.grid_patch1,'string','none');
3721set(handles.grid_patch1,'Visible','on')
3722
3723%------------------------------------------------------------------------
3724function desable_patch1(handles)
3725%------------------------------------------------------------------------
3726set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
3727set(handles.rho_patch1,'Visible','off')
3728set(handles.rho_text1,'Visible','off')
3729set(handles.thresh_patch1,'Visible','off')
3730set(handles.thresh_text1,'Visible','off')
3731set(handles.subdomain_patch1,'Visible','off')
3732set(handles.subdomain_text1,'Visible','off')
3733set(handles.nx_patch1,'Visible','off')
3734set(handles.ny_patch1,'Visible','off')
3735set(handles.nx_patch1_title,'Visible','off')
3736set(handles.ny_patch1_title,'Visible','off')
3737%set(handles.test_interp,'Visible','off')
3738set(handles.get_gridpatch1,'Visible','off')
3739set(handles.grid_patch1,'Visible','off')
3740
3741%------------------------------------------------------------------------
3742function enable_civ2(handles,state)
3743%------------------------------------------------------------------------
3744if isequal(state,0)
3745    state='off';
3746end
3747if isequal(state,1)
3748    state='on';
3749end
3750if isequal(state,'on')
3751    set(handles.frame_civ2,'BackgroundColor',[1 1 0])
3752    set(handles.frame_para_civ2,'BackgroundColor',[1 1 0])
3753    set(handles.frame_grid_civ2,'BackgroundColor',[1 1 0])
3754    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
3755else
3756    set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
3757    set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
3758    set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
3759    set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
3760end
3761set(handles.ibx_civ2,'Visible',state)
3762set(handles.iby_civ2,'Visible',state)
3763set(handles.decimal,'Visible',state)
3764set(handles.deformation,'Visible',state)
3765set(handles.rho_civ2,'Visible',state)
3766set(handles.dx_civ2,'Visible',state)
3767set(handles.dy_civ2,'Visible',state)
3768set(handles.browse_gridciv2,'Visible',state)
3769set(handles.get_mask_civ2,'Visible',state)
3770set(handles.parameters,'Visible',state)
3771set(handles.grid,'Visible',state)
3772set(handles.parameters_text,'Visible',state)
3773set(handles.grid_text,'Visible',state)
3774set(handles.grid_civ2,'Visible',state)
3775set(handles.mask_civ2,'Visible',state)
3776set(handles.dx_civ2_title,'Visible',state)
3777set(handles.dy_civ2_title,'Visible',state)
3778set(handles.ibx_civ2_text,'Visible',state)
3779set(handles.rho_civ2_title,'Visible',state)
3780set(handles.ImaThreshold2,'Visible',state)
3781set(handles.ImaThreshold_title2,'Visible',state)
3782if isequal(state,'off')
3783    set(handles.MinIma2,'Visible','off')
3784    set(handles.MaxIma2,'Visible','off')
3785    set(handles.ImaThreshold2,'Value',0)
3786    if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
3787        set(handles.list_pair_civ2,'Visible','off')
3788        set(handles.subdir_civ2,'Visible','off')
3789        set(handles.subdir_civ2_text,'Visible','off')
3790        set(handles.dt_unit_civ2,'Visible','off')
3791        set(handles.ref_i_civ2,'Visible','off')
3792        set(handles.i_ref_civ2_title,'Visible','off')
3793        set(handles.j_ref_civ2_title,'Visible','off')
3794        set(handles.ref_j_civ2,'Visible','off')
3795    end
3796else
3797    set(handles.list_pair_civ2,'Visible','on')
3798    set(handles.subdir_civ2,'Visible','on')
3799    set(handles.subdir_civ2_text,'Visible','on')
3800    set(handles.dt_unit_civ2,'Visible','on')
3801    set(handles.ref_i_civ2,'Visible','on')
3802    set(handles.i_ref_civ2_title,'Visible','on')
3803    set(handles.j_ref_civ2_title,'Visible','on')
3804    set(handles.ref_j_civ2,'Visible','on')
3805end
3806set(handles.rho_civ2_title,'Visible',state)
3807
3808%------------------------------------------------------------------------
3809function enable_fix2(handles)
3810%------------------------------------------------------------------------
3811set(handles.frame_fix2,'BackgroundColor',[1 1 0])
3812set(handles.REMOVE2,'Visible','on')
3813set(handles.vec_Fmin2_2,'Visible','on')
3814set(handles.vec_F4,'Visible','on')
3815set(handles.vec_F3_2,'Visible','on')
3816set(handles.thresh_vec2C,'Visible','on')
3817set(handles.thresh_vec2C_text,'Visible','on')
3818set(handles.thresh_vel2,'Visible','on')
3819set(handles.thresh_vel2_text,'Visible','on')
3820set(handles.mask_fix2,'Visible','on')
3821set(handles.get_mask_fix2,'Visible','on')
3822set(handles.list_pair_civ2,'Visible','on')
3823set(handles.subdir_civ2,'Visible','on')
3824set(handles.subdir_civ2_text,'Visible','on')
3825set(handles.get_ref_fix2,'Visible','on')
3826set(handles.ref_fix2,'Visible','on')
3827set(handles.inf_sup2,'Visible','on')
3828set(handles.field_ref2,'Visible','on')
3829
3830%------------------------------------------------------------------------
3831function desable_fix2(handles)
3832%------------------------------------------------------------------------
3833set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
3834set(handles.REMOVE2,'Visible','off')
3835set(handles.vec_Fmin2_2,'Visible','off')
3836set(handles.vec_F4,'Visible','off')
3837set(handles.vec_F3_2,'Visible','off')
3838set(handles.thresh_vec2C,'Visible','off')
3839set(handles.thresh_vec2C_text,'Visible','off')
3840set(handles.thresh_vel2,'Visible','off')
3841set(handles.thresh_vel2_text,'Visible','off')
3842set(handles.mask_fix2,'Visible','off')
3843set(handles.get_mask_fix2,'Visible','off')
3844set(handles.get_ref_fix2,'Visible','off')
3845set(handles.ref_fix2,'Visible','off')
3846set(handles.inf_sup2,'Visible','off')
3847set(handles.field_ref2,'Visible','off')
3848if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
3849    set(handles.list_pair_civ2,'Visible','off')
3850    set(handles.subdir_civ2,'Visible','off')
3851    set(handles.subdir_civ2_text,'Visible','off')
3852end
3853
3854%------------------------------------------------------------------------
3855function enable_patch2(handles)
3856%------------------------------------------------------------------------
3857set(handles.frame_patch2,'BackgroundColor',[1 1 0])
3858set(handles.rho_patch2,'Visible','on')
3859set(handles.rho_text2,'Visible','on')
3860set(handles.thresh_patch2,'Visible','on')
3861set(handles.thresh_text2,'Visible','on')
3862set(handles.subdomain_patch2,'Visible','on')
3863set(handles.subdomain_text2,'Visible','on')
3864set(handles.nx_patch2,'Visible','on')
3865set(handles.ny_patch2,'Visible','on')
3866set(handles.nx_patch2_title,'Visible','on')
3867set(handles.ny_patch2_title,'Visible','on')
3868set(handles.get_gridpatch2,'Visible','on')
3869set(handles.grid_patch2,'Visible','on')
3870set(handles.list_pair_civ2,'Visible','on')
3871set(handles.subdir_civ2,'Visible','on')
3872set(handles.subdir_civ2_text,'Visible','on')
3873
3874%------------------------------------------------------------------------
3875function desable_patch2(handles)
3876%------------------------------------------------------------------------
3877set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
3878set(handles.rho_patch2,'Visible','off')
3879set(handles.rho_text2,'Visible','off')
3880set(handles.thresh_patch2,'Visible','off')
3881set(handles.thresh_text2,'Visible','off')
3882set(handles.subdomain_patch2,'Visible','off')
3883set(handles.subdomain_text2,'Visible','off')
3884set(handles.nx_patch2,'Visible','off')
3885set(handles.ny_patch2,'Visible','off')
3886set(handles.nx_patch2_title,'Visible','off')
3887set(handles.ny_patch2_title,'Visible','off')
3888set(handles.get_gridpatch2,'Visible','off')
3889set(handles.grid_patch2,'Visible','off')
3890if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0)
3891    set(handles.list_pair_civ2,'Visible','off')
3892    set(handles.subdir_civ2,'Visible','off')
3893    set(handles.subdir_civ2_text,'Visible','off')
3894end
3895
3896%------------------------------------------------------------------------
3897function enable_pair1(handles,state)
3898%------------------------------------------------------------------------
3899set(handles.subdir_civ1,'Visible',state)
3900set(handles.list_subdir_civ1,'Visible',state)
3901set(handles.SUBDIR_CIV1_txt,'Visible',state)
3902set(handles.frame_subdirciv1,'Visible',state)
3903set(handles.list_pair_civ1,'Visible',state)
3904set(handles.PAIR_txt,'Visible',state)
3905%set(handles.dt_unit,'Visible',state)
3906set(handles.PAIR_frame,'Visible',state)
3907
3908%------------------------------------------------------------------------
3909% --- Read the parameters for civ1 on the interface
3910function par=read_param_civ1(handles,file_ima)
3911%------------------------------------------------------------------------
3912ibx_val=str2double(get(handles.ibx,'String'));
3913par.ibx=num2str(ibx_val);
3914iby_val=str2double(get(handles.iby,'String'));
3915par.iby=num2str(iby_val);
3916isx=get(handles.isx,'String');
3917if isnan(str2double(isx)), isx='41'; set(handles.isx,'String','41'), end; %default
3918if str2double(isx)<ibx_val+8,isx=num2str(ibx_val+8); set(handles.isx,'String',num2str(ibx_val+8)); end
3919isy=get(handles.isy,'String');
3920if isnan(str2double(isy)), isy='41'; set(handles.isy,'String','41'), end;%default
3921if str2double(isy)<iby_val+8,isy=num2str(iby_val+8); set(handles.isy,'String',num2str(iby_val+8)); end
3922par.isx=get(handles.isx,'String');
3923par.isy=get(handles.isy,'String');
3924par.shiftx=get(handles.shiftx,'String');
3925par.shifty=get(handles.shifty,'String');
3926if isnan(str2double(par.isx))
3927    par.isx='41';%default
3928    set(handles.isx,'String','41');
3929end
3930if isnan(str2double(par.isy))
3931    par.isy='41'; %default
3932    set(handles.isy,'String','41');
3933end
3934if isnan(str2double(par.shiftx))
3935    par.shiftx='0';%default
3936    set(handles.shiftx,'String','0');
3937end
3938if isnan(str2double(par.shifty))
3939    par.shifty='0'; %default
3940    set(handles.shifty,'String','0');
3941end
3942par.rho=get(handles.rho,'String');
3943par.dx=get(handles.dx_civ1,'String');
3944par.dy=get(handles.dy_civ1,'String');
3945if isnan(str2double(par.dx))
3946    if isempty(get(handles.grid_civ1,'String'));
3947        par.dx='0'; %just read by civ program, not used
3948    else
3949        par.dx='20';%default
3950        set(handles.dx_civ1,'String','20');
3951    end
3952end
3953if isnan(str2double(par.dy))
3954    if isempty(get(handles.grid_civ1,'String'));
3955        par.dy='0';%just read by civ program, not used
3956    else
3957        par.dy='20';%default
3958        set(handles.dy_civ1_title,'String','20');
3959    end
3960end
3961par.pxcmx='1'; %velocities are expressed in pixel dispalcement
3962par.pxcmy='1';
3963%      end
3964A=imread(file_ima);%read the first image to get the size
3965sizim=size(A);
3966par.npx=num2str(sizim(2));
3967par.npy=num2str(sizim(1));
3968%time=get(handles.RootName,'UserData'); %get the set of times
3969par.gridname=get(handles.grid_civ1,'String');
3970par.gridflag='y';
3971if strcmp(par.gridname,'')|| isempty(par.gridname)
3972    par.gridname='nogrid';
3973    par.gridflag='n';
3974end
3975
3976%------------------------------------------------------------------------
3977function par=read_param_civ2(handles,file_ima)
3978%------------------------------------------------------------------------
3979par.ibx=get(handles.ibx_civ2,'String');
3980par.iby=get(handles.iby_civ2,'String');
3981par.rho=get(handles.rho_civ2,'String');
3982par.decimal=int2str(get(handles.decimal,'Value'));
3983par.deformation=int2str(get(handles.deformation,'Value'));
3984par.dx=get(handles.dx_civ2,'String');
3985par.dy=get(handles.dy_civ2,'String');
3986if isnan(str2double(par.dx))
3987    if isempty(get(handles.grid_civ2,'String'));
3988        par.dx='0'; %just read by civ program, not used
3989    else
3990        par.dx='20';%default
3991        set(handles.dx_civ2,'String','20');
3992    end
3993end
3994if isnan(str2double(par.dy))
3995    if isempty(get(handles.grid_civ2,'String'));
3996        par.dy='0';%just read by civ program, not used
3997    else
3998        par.dy='20';%default
3999        set(handles.dy_civ2,'String','20');
4000    end
4001end
4002par.pxcmx='1';
4003par.pxcmy='1';
4004A=imread(file_ima);%read the first image to get the size
4005sizim=size(A);
4006par.npx=num2str(sizim(2));
4007par.npy=num2str(sizim(1));
4008%time=get(handles.RootName,'UserData'); %get the set of times
4009par.gridname=get(handles.grid_civ2,'String');
4010par.gridflag='y';
4011if strcmp(par.gridname,'')|| isempty(par.gridname)
4012    par.gridname='nogrid';
4013    par.gridflag='n';
4014end
4015
4016%------------------------------------------------------------------------
4017% --- CIV1  CIV1  CIV1 CIV1
4018function cmd_CIV1=CIV1_CMD(filename,namelog,par,handles,sparam)
4019%------------------------------------------------------------------------
4020%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4021
4022%changes : filename_cmx -> filename ( no extension )
4023
4024if isequal(par.Dt,'0')
4025    par.Dt='1' ;%case of 'displacement' mode
4026end
4027%
4028%     textcmx={'##############   CMX file';...
4029%     ['FirstImage ' par.filename_ima_a];...
4030%     ['LastImage  ' par.filename_ima_b];...
4031%     'XX' ;...
4032%     ['Mask ' par.maskflag] ;...
4033%     ['MaskName ' par.maskname];...
4034%     ['ImageSize ' par.npx ' ' par.npy];...   %VERIFIER CAS GENERAL ?
4035%     ['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
4036%     ['SearchBoxeSize ' par.isx ' ' par.isy];...
4037%     ['RO ' par.rho];...
4038%     ['GridSpacing ' par.dx ' ' par.dy];...
4039%     'XX 1.0';...
4040%     ['Dt_TO ' par.Dt ' ' par.T0];...
4041%     ['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
4042%     'XX 1';...
4043%     ['ShiftXY ' par.shiftx ' '  par.shifty];...
4044%     ['Grid ' par.gridflag];...
4045%     ['GridName ' par.gridname] ;...
4046%     'XX 85';...
4047%     'XX 1.0';...
4048%     'XX 1.0';...
4049%     'Hart 1';...
4050%     'DecimalShift 0';...
4051%     'Deformation 0';...
4052%     'CorrelationMin 0';...
4053%     'IntensityMin 0';...
4054%     'SeuilImage n';...
4055%     'SeuilImageValues 0 4096';...
4056%     ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
4057%     'ImageUsedBefore null null'};
4058%
4059%             textout=char(textcmx);
4060par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
4061par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');
4062fid=fopen([filename '.cmx'],'w');
4063fprintf(fid,['##############   CMX file' '\n' ]);
4064fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4065fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4066fprintf(fid,  ['XX' '\n' ]);
4067fprintf(fid,  ['Mask ' par.maskflag '\n' ]);
4068fprintf(fid,  ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);
4069fprintf(fid,   ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4070fprintf(fid,   ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
4071fprintf(fid,   ['SearchBoxeSize ' par.isx ' ' par.isy '\n' ]);
4072fprintf(fid,   ['RO ' par.rho '\n' ]);
4073fprintf(fid,   ['GridSpacing ' par.dx ' ' par.dy '\n' ]);
4074fprintf(fid,   ['XX 1.0' '\n' ]);
4075fprintf(fid,   ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
4076fprintf(fid,  ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
4077fprintf(fid,  ['XX 1' '\n' ]);
4078fprintf(fid,   ['ShiftXY ' par.shiftx ' '  par.shifty '\n' ]);
4079fprintf(fid,  ['Grid ' par.gridflag '\n' ]);
4080fprintf(fid,   ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n' ]);
4081fprintf(fid,   ['XX 85' '\n' ]);
4082fprintf(fid,   ['XX 1.0' '\n' ]);
4083fprintf(fid,   ['XX 1.0' '\n' ]);
4084fprintf(fid,   ['Hart 1' '\n' ]);
4085fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
4086fprintf(fid,   ['Deformation 0' '\n' ]);
4087fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4088fprintf(fid,   ['IntensityMin 0' '\n' ]);
4089fprintf(fid,  ['SeuilImage n' '\n' ]);
4090fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
4091fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
4092fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
4093fclose(fid);
4094
4095cmd_CIV1=[sparam.Civ1Bin ' -f ' filename '.cmx >' filename '.log' ]; % redirect standard output to the log file
4096cmd_CIV1=regexprep(cmd_CIV1,'\\','\\\\');
4097namelog=regexprep(namelog,'\\','\\\\');
4098
4099if(isunix)
4100    [Rootbat,Filebat,extbat]=fileparts(namelog);
4101    ncName=fullfile(Rootbat,[ Filebat '.nc']);
4102    cmd_CIV1=[cmd_CIV1 '\n' 'mv ' namelog  ' ' regexprep(namelog,'\.log','') '.civ1.log' '\n' 'chmod g+w ' ncName];
4103else
4104    cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y ' namelog ' ' regexprep(namelog,'\.log','') '.civ1.log'];
4105end
4106
4107%------------------------------------------------------------------------
4108% --- CIV1  Unified
4109function xml_civ1_parameters=CIV1_CMD_Unified(filename,namelog,par)
4110%------------------------------------------------------------------------
4111%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4112%global CivBin%name of the executable for civ1 calculation
4113
4114civ1.image1=par.filename_ima_a;
4115civ1.image2=par.filename_ima_b;
4116civ1.imageSize_X=par.npx;
4117civ1.imageSize_Y=par.npy;
4118civ1.outputFileName=[filename '.nc'];
4119civ1.correlationBoxesSize_X=par.ibx;
4120civ1.correlationBoxesSize_Y=par.iby;
4121civ1.searchBoxesSize_X=par.isx;
4122civ1.searchBoxesSize_Y=par.isy;
4123civ1.globalShift_X=par.shiftx;
4124civ1.globalShift_Y=par.shifty;
4125civ1.ro=par.rho;
4126civ1.hart='y';
4127if isequal(par.gridflag,'y')
4128    civ1.grid=par.gridname;
4129else
4130    civ1.grid='n';
4131    civ1.gridSpacing_X=par.dx;
4132    civ1.gridSpacing_Y=par.dy;
4133end
4134if isequal(par.maskflag,'y')
4135    civ1.mask=par.maskname;
4136end
4137civ1.dt=par.Dt;
4138civ1.unit='pixel';
4139civ1.absolut_time_T0=par.T0;
4140civ1.pixcmx=par.pxcmx;
4141civ1.pixcmy=par.pxcmy;
4142civ1.convectFlow='n';
4143
4144xml_civ1_parameters=civ1;
4145
4146%------------------------------------------------------------------------
4147% --- CIV2  Unified
4148function civ2=CIV2_CMD_Unified(filename,namelog,par)
4149%------------------------------------------------------------------------
4150%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4151%global CivBin%name of the executable for civ1 calculation
4152
4153civ2.image1=par.filename_ima_a;
4154civ2.image2=par.filename_ima_b;
4155civ2.imageSize_X=par.npx;
4156civ2.imageSize_Y=par.npy;
4157civ2.inputFileName=[par.filename_nc1 '.nc'];
4158civ2.outputFileName=[filename '.nc'];
4159civ2.correlationBoxesSize_X=par.ibx;
4160civ2.correlationBoxesSize_Y=par.iby;
4161civ2.ro=par.rho;
4162%civ2.decimalShift=par.decimal;
4163%civ2.deformation=par.deformation;
4164if isequal(par.decimal,'1')
4165    civ2.decimalShift='y';
4166else
4167    civ2.decimalShift='n';
4168end
4169if isequal(par.deformation,'1')
4170    civ2.deformation='y';
4171else
4172    civ2.deformation='n';
4173end
4174if isequal(par.gridflag,'y')
4175    civ2.grid=par.gridname;
4176else
4177    civ2.grid='n';
4178    civ2.gridSpacing_X=par.dx;
4179    civ2.gridSpacing_Y=par.dy;
4180end
4181civ2.gridSpacing_X='10';
4182civ2.gridSpacing_Y='10';%NOTE: faut mettre gridSpacing pourque ca tourne, meme si c'est la grille qui est utilisee
4183if isequal(par.maskflag,'y')
4184    civ2.mask=par.maskname;
4185else
4186    civ2.mask='n';
4187end
4188civ2.dt=par.Dt;
4189civ2.unit='pixel';
4190civ2.absolut_time_T0=par.T0;
4191civ2.pixcmx=par.pxcmx;
4192civ2.pixcmy=par.pxcmy;
4193civ2.convectFlow='n';
4194civ2.pixcmx=par.pxcmx;
4195civ2.pixcmy=par.pxcmy;
4196civ2.convectFlow='n';
4197
4198%------------------------------------------------------------------------
4199% --- CIV2  CIV2  CIV2 CIV2
4200function cmd_CIV2=CIV2_CMD(filename,namelog,par,sparam)
4201%------------------------------------------------------------------------
4202%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4203% global civ2Bin sge%name of the executable for civ1 calculation
4204if isequal(par.Dt,'0')
4205    par.Dt='1' ;%case of 'displacement' mode
4206end
4207% textcmx=['##############   CMX file'  '\n'...
4208% ['FirstImage ' par.filename_ima_a]  '\n'...
4209% ['LastImage  ' par.filename_ima_b]  '\n'...
4210% 'XX'   '\n'...
4211% ['Mask ' par.maskflag]  '\n'...
4212% ['MaskName ' par.maskname]  '\n'...
4213% ['ImageSize ' par.npx ' ' par.npy]  '\n'...
4214% ['CorrelationBoxesSize ' par.ibx ' ' par.iby]  '\n'...
4215% ['SearchBoxeSize ' par.ibx ' ' par.iby]  '\n'...
4216% ['RO ' par.rho]  '\n'...
4217% ['GridSpacing ' par.dx ' ' par.dy]  '\n'...
4218% 'XX 1.0'  '\n'...
4219% ['Dt_TO ' par.Dt ' ' par.T0]  '\n'...
4220% ['PixCmXY ' par.pxcmx ' ' par.pxcmy]  '\n'...
4221% 'XX 1'  '\n'...
4222% ['ShiftXY 0 0']  '\n'...
4223% ['Grid ' par.gridflag]  '\n'...
4224% ['GridName ' par.gridname]  '\n'...
4225% 'XX 85'  '\n'...
4226% 'XX 1.0'  '\n'...
4227% 'XX 1.0'  '\n'...
4228% 'Hart 1'  '\n'...
4229% ['DecimalShift ' par.decimal]  '\n'...
4230% ['Deformation ' par.deformation]  '\n'...
4231% 'CorrelationMin 0'  '\n'...
4232% 'IntensityMin 0'  '\n'...
4233% 'SeuilImage n'  '\n'...
4234% 'SeuilImageValues 0 4096'  '\n'...
4235% ['ImageToUse ' par.term_a ' ' par.term_b]  '\n'... % VERIFIER ?
4236% ['ImageUsedBefore ' par.filename_nc1]];
4237% textout=char(textcmx);
4238% fid=fopen([filename_cmx '2'],'w');
4239% fprintf(fid,textout);
4240% fclose(fid)
4241
4242par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
4243par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');% bug : .png appears two times ?
4244fid=fopen([filename '.cmx2'],'w');
4245fprintf(fid,['##############   CMX file' '\n' ]);
4246fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4247fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4248fprintf(fid,  ['XX' '\n' ]);
4249fprintf(fid, ['Mask ' par.maskflag '\n' ]);
4250fprintf(fid, ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);% for windows compatibility
4251fprintf(fid, ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4252fprintf(fid, ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
4253fprintf(fid, ['SearchBoxeSize ' par.ibx ' ' par.iby '\n']);
4254fprintf(fid, ['RO ' par.rho '\n']);
4255fprintf(fid, ['GridSpacing ' par.dx ' ' par.dy '\n']);
4256fprintf(fid, ['XX 1.0' '\n' ]);
4257fprintf(fid, ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
4258fprintf(fid, ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
4259fprintf(fid, ['XX 1' '\n' ]);
4260fprintf(fid, 'ShiftXY 0 0\n');
4261fprintf(fid, ['Grid ' par.gridflag '\n' ]);
4262fprintf(fid, ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n']);
4263fprintf(fid, ['XX 85' '\n' ]);
4264fprintf(fid, ['XX 1.0' '\n' ]);
4265fprintf(fid, ['XX 1.0' '\n' ]);
4266fprintf(fid, ['Hart 1' '\n' ]);
4267fprintf(fid, ['DecimalShift ' par.decimal '\n']);
4268fprintf(fid, ['Deformation ' par.deformation '\n']);
4269fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4270fprintf(fid,   ['IntensityMin 0' '\n' ]);
4271fprintf(fid,  ['SeuilImage n' '\n' ]);
4272fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
4273fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
4274fprintf(fid, ['ImageUsedBefore ' regexprep(par.filename_nc1,'\\','\\\\') '\n']);
4275fclose(fid);
4276
4277cmd_CIV2=[sparam.Civ2Bin ' -f ' filename  '.cmx >' filename '.log' ]; % redirect standard output to the log file
4278cmd_CIV2=regexprep(cmd_CIV2,'\\','\\\\');
4279namelog=regexprep(namelog,'\\','\\\\');
4280
4281if(isunix)
4282    [Rootbat,Filebat,extbat]=fileparts(namelog);
4283    ncName=fullfile(Rootbat,[ Filebat '.nc']);
4284    cmd_CIV2=[cmd_CIV2 '\n' 'mv ' namelog  ' ' regexprep(namelog,'\.log','') '.civ2.log' '\n' 'chmod g+w ' ncName];
4285else
4286    cmd_CIV2=[cmd_CIV2 '\n' 'copy /Y ' namelog ' ' regexprep(namelog,'\.log','') '.civ2.log'];
4287end
4288
4289
4290
4291%------------------------------------------------------------------------
4292% --- Executes on button press in HELP.
4293function HELP_Callback(hObject, eventdata, handles)
4294%------------------------------------------------------------------------
4295path_to_uvmat=which ('uvmat');% check the path of uvmat
4296pathelp=fileparts(path_to_uvmat);
4297helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
4298if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
4299else
4300    addpath (fullfile(pathelp,'uvmat_doc'))
4301    web([helpfile '#civ'])
4302end
4303
4304%------------------------------------------------------------------------
4305%--read images and convert them to the uint16 format used for PIV
4306function A=read_image(filename,type_ima,num,movieobject)
4307%------------------------------------------------------------------------
4308%num is the view number needed for an avi movie
4309switch type_ima
4310    case 'movie'
4311        A=read(movieobject,num);
4312    case 'avi'
4313        mov=aviread(filename,num);
4314        A=frame2im(mov(1));
4315    case 'multimage'
4316        A=imread(filename,num);
4317    case 'image'
4318        A=imread(filename);
4319end
4320siz=size(A);
4321if length(siz)==3;%color images
4322    A=sum(double(A),3);
4323    A=uint16(A);
4324end
4325
4326%------------------------------------------------------------------------
4327function ref_i_Callback(hObject, eventdata, handles)
4328%------------------------------------------------------------------------
4329mode_list=get(handles.mode,'String');
4330mode_value=get(handles.mode,'Value');
4331mode=mode_list{mode_value};
4332find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4333if isequal(mode,'series(Di)') || ...% we do patch2 only
4334        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
4335    find_netcpair_civ2(hObject, eventdata, handles);
4336end
4337
4338%------------------------------------------------------------------------
4339function ref_j_Callback(hObject, eventdata, handles)
4340%------------------------------------------------------------------------
4341mode_list=get(handles.mode,'String');
4342mode_value=get(handles.mode,'Value');
4343mode=mode_list{mode_value};
4344if isequal(get(handles.CIV1,'Value'),0)|| isequal(mode,'series(Dj)')
4345    find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4346end
4347if isequal(mode,'series(Dj)') || ...
4348        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
4349    find_netcpair_civ2(hObject, eventdata, handles);
4350end
4351
4352%------------------------------------------------------------------------
4353function ref_i_civ2_Callback(hObject, eventdata, handles)
4354%------------------------------------------------------------------------
4355mode_list=get(handles.mode,'String');
4356mode_value=get(handles.mode,'Value');
4357mode=mode_list{mode_value};
4358find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4359
4360%------------------------------------------------------------------------
4361function ref_j_civ2_Callback(hObject, eventdata, handles)
4362%------------------------------------------------------------------------
4363mode_list=get(handles.mode,'String');
4364mode_value=get(handles.mode,'Value');
4365mode=mode_list{mode_value};
4366if  isequal(mode,'series(Dj)')
4367    find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4368end
4369
4370%------------------------------------------------------------------------
4371% --- Executes on button press in compare.
4372function compare_Callback(hObject, eventdata, handles)
4373%------------------------------------------------------------------------
4374test=get(handles.compare,'Value');
4375if test==2 || test==3
4376    filebase=get(handles.RootName,'String');
4377    browse=get(handles.browse_root,'Userdata');
4378    browse.nom_type_ima1=browse.nom_type_ima;
4379    set(handles.browse_root,'UserData',browse);
4380    set(handles.sub_txt,'Visible','on')
4381    set(handles.RootName_1,'Visible','On');%mkes the second file input window visible
4382    mode_store=get(handles.mode,'String');%get the present 'mode'
4383    set(handles.compare,'UserData',mode_store);%store the mode display
4384    set(handles.mode,'Visible','off')
4385    if test==2
4386        set(handles.mode,'Visible','off')
4387    else
4388        set(handles.mode,'Visible','on')
4389    end
4390   
4391    % open an image file with the browser
4392    ind_opening=1;%default
4393    browse.incr_pair=[0 0]; %default
4394    oldfile=get(handles.RootName,'String');
4395    menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
4396        '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc', '.nc files';...
4397        '*.*', 'All Files (*.*)'};
4398    [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
4399    fileinput=[PathName FileName];%complete file name
4400    sizf=size(fileinput);
4401    if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
4402    [path,name,ext]=fileparts(fileinput);
4403    [path1]=fileparts(filebase);
4404    if ~strcmp(path1,path)
4405        msgbox_uvmat('ERROR','The two  input image series must be in the same directory')
4406        return
4407    end
4408    set(handles.RootName_1,'String',name);
4409    [RootPath,RootFile,field_count,str2,str_a,str_b,xx,nom_type,subdir]=name2display(name);
4410    browse=get(handles.browse_root,'UserData');
4411    browse.nom_type_ima_1=nom_type;
4412    set(handles.browse_root,'UserData',browse)
4413   
4414    %check image extension
4415    if ~strcmp(ext,get(handles.ImaExt,'String'))
4416        msgbox_uvmat('ERROR','The two  input image series must have the same extenion name')
4417        return
4418    end
4419   
4420    %check image size
4421    A=imread(fileinput);
4422    npxy=get(handles.ImaExt,'UserData');
4423    if ~isequal(npxy(1),size(A,1))|| ~isequal(npxy(2),size(A,2))
4424        msgbox_uvmat('ERROR','The two input image series must have the same size')
4425        return
4426    end
4427else
4428    set(handles.mode,'Visible','on')
4429    set(handles.RootName_1,'Visible','Off');
4430    set(handles.sub_txt,'Visible','off')
4431    set(handles.RootName_1,'String',[]);
4432    mode_store=get(handles.compare,'UserData');
4433    set(handles.mode,'String',mode_store)
4434    set(handles.test_stereo1,'Value',0)
4435    set(handles.test_stereo2,'Value',0)
4436end
4437mode_Callback(hObject, eventdata, handles)
4438
4439%------------------------------------------------------------------------
4440% --- Executes on button press in get_ref_fix1.
4441function get_ref_fix1_Callback(hObject, eventdata, handles)
4442%------------------------------------------------------------------------
4443filebase=get(handles.RootName,'String');
4444[FileName, PathName, filterindex] = uigetfile( ...
4445    {'*.nc', ' (*.nc)';
4446    '*.nc',  'netcdf files '; ...
4447    '*.*', 'All Files (*.*)'}, ...
4448    'Pick a file',filebase);
4449
4450fileinput=[PathName FileName];
4451sizf=size(fileinput);
4452if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
4453[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4454ref.filebase=fullfile(Path,File);
4455ref.num_a=stra2num(str_a);
4456ref.num_b=stra2num(str_b);
4457ref.num1=str2double(field_count);
4458ref.num2=str2double(str2);
4459browse=[];%initialisation
4460if ~isequal(ref.ext,'.nc')
4461    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4462    return
4463end
4464set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
4465set(handles.ref_fix1,'UserData',ref)
4466menu_field{1}='civ1';
4467Data=nc2struct(fileinput,[]);
4468if isfield(Data,'patch') && isequal(Data.patch,1)
4469    menu_field{2}='filter1';
4470end
4471if isfield(Data,'civ2') && isequal(Data.civ2,1)
4472    menu_field{3}='civ2';
4473end
4474if isfield(Data,'patch2') && isequal(Data.patch2,1)
4475    menu_field{4}='filter2';
4476end
4477set(handles.field_ref1,'String',menu_field);
4478set(handles.field_ref1,'Value',length(menu_field));
4479set(handles.inf_sup1,'Value',2);
4480set(handles.thresh_vel,'String','1');%default threshold
4481set(handles.ref_fix1,'Enable','on')
4482
4483%------------------------------------------------------------------------
4484% --- Executes on button press in get_ref_fix2.
4485function get_ref_fix2_Callback(hObject, eventdata, handles)
4486%------------------------------------------------------------------------
4487if isequal(get(handles.get_ref_fix2,'Value'),1)
4488    filebase=get(handles.RootName,'String');
4489    [FileName, PathName, filterindex] = uigetfile( ...
4490        {'*.nc', ' (*.nc)';
4491        '*.nc',  'netcdf files '; ...
4492        '*.*', 'All Files (*.*)'}, ...
4493        'Pick a file',filebase);
4494    fileinput=[PathName FileName];
4495    sizf=size(fileinput);
4496    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
4497    [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4498    ref.filebase=fullfile(Path,File);
4499    ref.num_a=stra2num(str_a);
4500    ref.num_b=stra2num(str_b);
4501    ref.num1=str2num(field_count);
4502    ref.num2=str2num(str2);
4503    browse=[];%initialisation
4504    if ~isequal(ref.ext,'.nc')
4505        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4506        return
4507    end
4508    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
4509    set(handles.ref_fix2,'UserData',ref)
4510    menu_field{1}='civ1';
4511    Data=nc2struct(fileinput,[]);
4512    if isfield(Data,'patch') & isequal(Data.patch,1)
4513        menu_field{2}='filter1';
4514    end
4515    if isfield(Data,'civ2') & isequal(Data.civ2,1)
4516        menu_field{3}='civ2';
4517    end
4518    if isfield(Data,'patch2') & isequal(Data.patch2,1)
4519        menu_field{4}='filter2';
4520    end
4521    set(handles.field_ref2,'String',menu_field);
4522    set(handles.field_ref2,'Value',length(menu_field));
4523    set(handles.inf_sup2,'Value',2);
4524    set(handles.thresh_vel2,'String','1');%default threshold
4525    set(handles.ref_fix2,'Enable','on')
4526    set(handles.ref_fix2,'Visible','on')
4527    set(handles.field_ref2,'Visible','on')
4528else
4529    set(handles.ref_fix2,'Visible','off')
4530    set(handles.field_ref2,'Visible','off')
4531end
4532
4533%------------------------------------------------------------------------
4534function ref_fix1_Callback(hObject, eventdata, handles)
4535%------------------------------------------------------------------------
4536set(handles.inf_sup1,'Value',1);
4537set(handles.field_ref1,'Value',1)
4538set(handles.field_ref1,'String',{' '})
4539set(handles.ref_fix1,'UserData',[]);
4540set(handles.ref_fix1,'String','');
4541set(handles.thresh_vel1,'String','0');
4542
4543%------------------------------------------------------------------------
4544function ref_fix2_Callback(hObject, eventdata, handles)
4545%------------------------------------------------------------------------
4546set(handles.inf_sup2,'Value',1);
4547set(handles.field_ref2,'Value',1)
4548set(handles.field_ref2,'String',{' '})
4549set(handles.ref_fix2,'UserData',[]);
4550set(handles.ref_fix2,'String','');
4551set(handles.thresh_vel2,'String','0');
4552
4553%------------------------------------------------------------------------
4554% --- Executes on button press in test_stereo1.
4555function test_stereo1_Callback(hObject, eventdata, handles)
4556%------------------------------------------------------------------------
4557if isequal(get(handles.test_stereo1,'Value'),0)
4558    set(handles.subdomain_patch1,'Visible','on')
4559    set(handles.rho_patch1,'Visible','on')
4560else
4561    set(handles.subdomain_patch1,'Visible','off')
4562    set(handles.rho_patch1,'Visible','off')
4563end
4564
4565%------------------------------------------------------------------------
4566% --- Executes on button press in test_stereo2.
4567function test_stereo2_Callback(hObject, eventdata, handles)
4568%------------------------------------------------------------------------
4569if isequal(get(handles.test_stereo2,'Value'),0)
4570    set(handles.subdomain_patch2,'Visible','on')
4571    set(handles.rho_patch2,'Visible','on')
4572else
4573    set(handles.subdomain_patch2,'Visible','off')
4574    set(handles.rho_patch2,'Visible','off')
4575end
4576
4577%------------------------------------------------------------------------
4578% --- Executes on button press in ImaThreshold.
4579function ImaThreshold_Callback(hObject, eventdata, handles)
4580%------------------------------------------------------------------------
4581if isequal(get(handles.ImaThreshold,'Value'),1)
4582    set(handles.MinIma,'Visible','on')
4583    set(handles.MaxIma,'Visible','on')
4584else
4585    set(handles.MinIma,'Visible','off')
4586    set(handles.MaxIma,'Visible','off')
4587end
4588
4589%------------------------------------------------------------------------
4590% --- Executes on button press in ImaThreshold2.
4591function ImaThreshold2_Callback(hObject, eventdata, handles)
4592%------------------------------------------------------------------------
4593if isequal(get(handles.ImaThreshold2,'Value'),1)
4594    set(handles.MinIma2,'Visible','on')
4595    set(handles.MaxIma2,'Visible','on')
4596else
4597    set(handles.MinIma2,'Visible','off')
4598    set(handles.MaxIma2,'Visible','off')
4599end
4600
4601
4602
4603
Note: See TracBrowser for help on using the repository browser.