source: trunk/src/civ.m @ 173

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

small bug repair in uvmat, proj_field (.Mesh for mouse) and civ (undefined callbacks)

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