source: trunk/src/civ.m @ 177

Last change on this file since 177 was 177, checked in by sommeria, 13 years ago

bug with mouse object editing resolved. Display feature 'satus' for PIV task advancement introduced. Various bug repair and cleaning

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