source: trunk/src/civ.m @ 112

Last change on this file since 112 was 112, checked in by gostiaux, 14 years ago

launch_jobs now reads correctly PARAM.xml
lots of autoindent corrections

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