source: trunk/src/civ.m @ 159

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

bug in civ corrected: civ2 was not lauched for Windows system
various bugs corrections and cleaning

File size: 182.9 KB
RevLine 
[112]1%'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)
[2]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
[112]10%     This file is part of the toolbox UVMAT.
11%
[2]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.
[112]16%
[2]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
[150]24% Last Modified by GUIDE v2.5 01-Dec-2010 23:19:15
[2]25% Begin initialization code - DO NOT EDIT
26gui_Singleton = 1;
27gui_State = struct('gui_Name',       mfilename, ...
[112]28    'gui_Singleton',  gui_Singleton, ...
29    'gui_OpeningFcn', @civ_OpeningFcn, ...
30    'gui_OutputFcn',  @civ_OutputFcn, ...
31    'gui_LayoutFcn',  [] , ...
32    'gui_Callback',   []);
[2]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
[12]44%------------------------------------------------------------------------
[2]45% --- Executes just before civ is made visible.
[71]46function civ_OpeningFcn(hObject, eventdata, handles, param)
[12]47%------------------------------------------------------------------------
[2]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)
[84]53global patch_newBin %=1 if new patch processing available
[112]54%filebase: root name
[2]55%nom_type: nomencalture used ('png_old','_i_j'...)
56%list of field numbers to process
[112]57%subdir: subdirectory of the opened netcdf file
[2]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=[];
[112]68testall=0;
[71]69%default input parameters:
[153]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)
[71]74subdir='A'; % subdir for the netcdf result files
[112]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
[71]77if exist('param','var')&&isstruct(param)% the interface is opened from uvmat
78    filebase=param.RootName;
79    nom_type_read=param.NomType;
[153]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
[71]88    subdir=param.SubDir;
89    ind_opening=param.IndOpening;
90    ext=param.ImaExt;
[2]91end
[153]92browse.num_i1=num_i1;
93browse.num_i2=num_i2;
94browse.num_j1=num_j1;
95browse.num_j2=num_j2;
[122]96if ~isempty(ext) && (~isempty(imformats(ext(2:end)))||strcmpi(ext,'.avi'));%if an image file has been opened by uvmat
[112]97    set(handles.ImaExt,'String',ext)
[128]98    browse.ext_ima=ext;
[112]99    if exist('nom_type_read','var')
100        browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
101    end
[2]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
[71]107set(handles.RootName,'String',filebase);
[2]108set(handles.ImaDoc,'UserData',testall);
109set(handles.ImaDoc,'String',ext)
110
[122]111%read names of the .exe file to adjust the interface according to available binaries
[2]112path_uvmat=which('uvmat');% check the path detected for source file uvmat
113path_UVMAT=fileparts(path_uvmat); %path to UVMAT
[45]114errormsg=[];%default error message
[111]115% xmlfile=fullfile(path_UVMAT,'PARAM.xml');
116% if ~exist(xmlfile,'file')
[112]117xmlfile='PARAM.xml';
[111]118% end
[54]119if exist(xmlfile,'file')
120    try
[112]121        t=xmltree(xmlfile);
122        sparam=convert(t);
[54]123    catch
[112]124        errormsg={' Unable to read the file PARAM.xml defining the civx binaries:'; lasterr};
[2]125    end
[54]126else
127    errormsg=[xmlfile ' not found: path to civx binaries undefined'];
[2]128end
[71]129
[110]130
[45]131if ~isempty(errormsg)
[112]132    msgbox_uvmat('ERROR',errormsg);
[45]133end
[71]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
[2]138end
139if test_batch==0
[84]140    set(handles.BATCH,'Enable','off')% put the BATCH button in grey (unactivated)
[2]141    set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
142end
[94]143if isfield(sparam.RunParam,'CivBin')
144    if ~exist(sparam.RunParam.CivBin,'file')
[112]145        sparam.RunParam.CivBin=fullfile(path_UVMAT,sparam.RunParam.CivBin);
[94]146    end
[97]147else
148    sparam.RunParam.CivBin='';
[94]149end
[96]150patch_newBin=exist(sparam.RunParam.CivBin,'file');
[2]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
[112]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])
[2]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)
[112]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')
[2]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
[153]201if isequal(num_i2,num_i1)
202    num_ref_i=num_i1;
[2]203else
[153]204    num_ref_i=floor((num_i1+num_i2)/2);
205    browse.incr_pair(1)=num_i2-num_i1;
[2]206    browse.incr_pair(2)=0;
207end
[153]208if isequal(num_j1,num_j2)
209    if isnan(num_j1)
[2]210        num_ref_j=1;
211    else
[153]212        num_ref_j=num_j1;
[2]213    end
214else
[153]215    num_ref_j=floor((num_j1+num_j2)/2);
216    browse.incr_pair(2)=num_j2-num_j1;
[2]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));
[71]224set(handles.ref_i_civ2,'String',num2str(num_ref_i));
225set(handles.ref_j_civ2,'String',num2str(num_ref_j));
[2]226set(handles.browse_root,'UserData',browse);
[71]227if exist('param','var')%varargin the interface is opened from uvmat
[112]228    RootName_Callback(hObject, eventdata, handles);
[2]229end
230
[150]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])
[2]235
[12]236%------------------------------------------------------------------------
[2]237% --- Outputs from this function are returned to the command line.
238function varargout = civ_OutputFcn(hObject, eventdata, handles)
[12]239%------------------------------------------------------------------------
[2]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
[12]247%------------------------------------------------------------------------
[2]248% --- Executes on button press in browse_root.
249function browse_root_Callback(hObject, eventdata, handles)
[12]250%------------------------------------------------------------------------
[2]251%get the input file properties
[71]252filebase=get(handles.RootName,'String');
[2]253oldfile=''; %default
[39]254if isempty(filebase)|| isequal(filebase,'')%loads the previously stored file name and set it as default in the file_input box
[112]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
[2]269testall=get(handles.ImaDoc,'UserData');
270ind_opening=1;%default
271browse.incr_pair=[0 0]; %default
[112]272if testall
[2]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
[112]276    menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
[2]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);
[112]281fileinput=[PathName FileName];%complete file name
[2]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);
[45]290    if isfield(head_element,'name')&& isequal(head_element.name,'ImaDoc')
[2]291        testeditxml=0;
292    end
293end
[45]294if testeditxml==1 || isequal(ext,'.xls')
[112]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
[2]307end
[82]308[RootPath,RootFile,str1,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
[2]309filebase=fullfile(RootPath,RootFile);
[89]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
[54]314num_j1=stra2num(str_a);
[89]315if isnan(num_j1),num_j1=1;end
[54]316num_j2=stra2num(str_b);
[112]317if isnan(num_j2),num_j2=num_j1;end
[2]318if isequal(get(handles.compare,'Value'),1)
319    browse=[];%initialisation
320else
321    browse=get(handles.browse_root,'UserData');
322end
[122]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)
[2]329    browse.nom_type_ima=nom_type;
[122]330    browse.ext_ima=ext;
[2]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;
[112]337    ind_opening=2;% propose 'fix' as the default option
[2]338    Data=nc2struct(fileinput,[]);
[112]339    if isfield(Data,'absolut_time_T0')%test for civx files
[2]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
[112]354        ind_opening=3; %GUI used only for patch
[2]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
[71]362set(handles.RootName,'String',filebase);
[2]363set(handles.ImaDoc,'String',ext);
[45]364if ~isempty(num_i1)
[82]365    ref_i=num_i1;
[45]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;
[2]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));
[71]373    set(handles.ref_i,'String',num2str(ref_i));
374    set(handles.ref_i_civ2,'String',num2str(ref_i))
[2]375end
[45]376if isempty(num_j1)
[2]377    set(handles.ref_j,'String','1');
[71]378    set(handles.ref_j_civ2,'String','1');
[2]379else
[45]380    ref_j=num_j1;
381    if ~isempty(num_j2)
382        ref_j=floor((num_j1+num_j2)/2);
[112]383        browse.incr_pair(2)=num_j2-num_j1;
[2]384    end
385    set(handles.first_j,'String',num2str(ref_j));
386    set(handles.last_j,'String',num2str(ref_j));
[112]387    set(handles.ref_j,'String',num2str(ref_j));
[71]388    set(handles.ref_j_civ2,'String',num2str(ref_j));
[2]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)
[112]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')
[2]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
[71]436RootName_Callback(hObject, eventdata, handles);
[2]437
[12]438%------------------------------------------------------------------------
[2]439function ImaDoc_Callback(hObject, eventdata, handles)
[12]440%------------------------------------------------------------------------
[71]441RootName_Callback(hObject, eventdata, handles)
[2]442
[12]443%------------------------------------------------------------------------
[54]444% --- function activated when a new filebase (image series) is introduced
[71]445function RootName_Callback(hObject, eventdata, handles)
[12]446%------------------------------------------------------------------------
[2]447set(handles.compare,'Visible','on')
[122]448%ext_ima=get(handles.ImaExt,'String');
449ext_ima='';%default
[2]450nom_type_ima=[];%default
451field_count=1;%default
452nom_type_nc=[];
453time=[];
[71]454TimeUnit='frame'; %default
455CoordUnit='px';%default
[2]456pxcmx_search=[];%default
457pxcmy_search=[];%default
[71]458filebase=get(handles.RootName,'String');
[128]459ext_imadoc=get(handles.ImaDoc,'String');
[135]460browse=get(handles.browse_root,'UserData');%default
[122]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
[133]463end
464if isfield(browse,'ext_ima')
[122]465    ext_ima=browse.ext_ima;
[2]466end
[122]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
[2]473
474%default first_i and j and increments
[137]475first_i=str2double(get(handles.first_i,'String'));%value possibly set by uvmat_Opening
476if isnan(first_i)|| first_i < 1
[2]477    first_i=1; %default first_i
478end
[137]479last_i=str2double(get(handles.last_i,'String'));
480if isnan(last_i)|| last_i < first_i
[2]481    last_i=first_i;  %default last_i
482end
[137]483first_j=str2double(get(handles.first_j,'String'));
484if isnan(first_j)|| first_j < 1
[2]485    first_j=1; %default first_j
486end
[137]487last_j=str2double(get(handles.last_j,'String'));
488if isnan(last_j)|| last_j < first_j
[2]489    last_j=first_j; %default last_j
490end
[137]491incr_i=str2double(get(handles.incr_i,'String'));
492if isnan(incr_i) || incr_i < 1;
[2]493    set(handles.incr_i,'String','1') %default incr_i
494end
[137]495incr_j=str2double(get(handles.incr_j,'String'));
496if isnan(incr_j) || incr_j < 1;
[2]497    set(handles.incr_j,'String','1') %default incr_j
498end
499dt=[];%default
500testmode=0;%default
501nbfield=[]; %default
502nburst=[];%default
503pxcmx=1;
[112]504pxcmy=1;
[2]505
[112]506%look for an image documentation file
[128]507if ~strcmp(ext_imadoc,'.xml') && ~strcmp(ext_imadoc,'.civ')&& ~strcmpi(ext_imadoc,'.avi')
[2]508    if exist([filebase '.xml'],'file')
[128]509        ext_imadoc='.xml';
[2]510    elseif exist([filebase '.civxml'],'file')
[128]511        ext_imadoc='.civxml';
[2]512    elseif exist([filebase '.civ'],'file')
[128]513        ext_imadoc='.civ';
[112]514    elseif exist([filebase '.avi'],'file')
[128]515        ext_imadoc='.avi';
[2]516    elseif exist([filebase '.AVI'],'file')
[128]517        ext_imadoc='.AVI';
[2]518    end
[128]519    set(handles.ImaDoc,'String',ext_imadoc)
[2]520end
521
522%%%%%%%%   read image documentation file  %%%%%%%%%%%%%%%%%%%%%%%%%%%
[84]523mode=''; %default
524set(handles.ImaDoc,'BackgroundColor',[1 1 0])
525drawnow
[128]526if isequal(ext_imadoc,'.civxml') || isequal(ext_imadoc,'.xml')|| isequal(ext_imadoc,'.civ')
[2]527    set(handles.ref_i,'Visible','On')%use a reference index
528    set(handles.ref_j,'Visible','On')
[128]529elseif isequal(ext_imadoc,'.avi') || isequal(ext_imadoc,'.AVI')
[2]530    set(handles.ref_j,'Visible','Off')
531else
532    set(handles.ref_i,'Visible','Off')
533    set(handles.ref_j,'Visible','Off')
534end
[12]535testima_xml=0;
[128]536if isequal(ext_imadoc,'.civxml')%TO ABANDON
[122]537    [nbfield,nbfield2,time]=read_civxml([filebase '.civxml']);
[2]538    mode='pair j1-j2';
539    if isempty(nom_type_ima)% dtermine types by default if not already selected by browser or uvmat
[112]540        nom_type_ima='_i_j';
[2]541    end
[128]542elseif isequal(ext_imadoc,'.xml')
[73]543    [XmlData,warntext]=imadoc2struct([filebase '.xml']);
[2]544    ext_ima_read=[];
545    nom_type_read=[];
[12]546    if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')&&ischar(XmlData.Heading.ImageName)% get image nom type and extension from the xml file
[2]547        [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
[112]548        fullname=fullfile(fileparts(filebase),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file,
[45]549        if ~exist(fullname,'file')
[12]550            msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
551        end
[2]552    end
[84]553    if isfield(XmlData,'Time')
[85]554        time=XmlData.Time;
[84]555        nbfield=size(time,1);
[122]556        nbfield2=size(time,2);
[127]557        %transform .Time to a column vector if it is a line vector thenomenclature uses a single index: correct possible bug in xml
[122]558        if isequal(nbfield,1) && ~isequal(nbfield2,1)% .Time is a line vector
[127]559            if numel(nom_type_read)>=2 && isempty(regexp(nom_type_read(2:end),'\D'))
[84]560                time=time';
[122]561                nbfield=nbfield2;
562                nbfield2=1;
[84]563            end
564        end
565    end
[71]566    if isfield(XmlData,'TimeUnit')
567        TimeUnit=XmlData.TimeUnit;
[2]568    end
[71]569    if isfield(XmlData,'Npx')
570        npx=XmlData.Npx;
571        npy=XmlData.Npy;
572    end
[2]573    pxcmx_search=1;
574    pxcmy_search=1;
575    if isfield(XmlData,'GeometryCalib')
576        tsai=XmlData.GeometryCalib;
[112]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);
[2]581        end
[112]582        if isfield(tsai,'CoordUnit')
583            CoordUnit=tsai.CoordUnit;
[2]584        end
[112]585    end
[128]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
[112]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
[128]601    nom_type_ima='001a';
602elseif strcmpi(ext_imadoc,'.avi')
[112]603    nom_type_ima='*';
[128]604    ext_ima=ext_imadoc;
[112]605    set(handles.mode,'String',{'series(Di)'})
606    dt=0.04;%default
[128]607    if exist([filebase ext_imadoc],'file')==2
608        info=aviinfo([filebase ext_imadoc]);%read infos on the avi movie
[112]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
[2]614end
615if isempty(time)
616    set(handles.ImaDoc,'String',''); %xml file not used for timing
617end
618set(handles.ImaDoc,'BackgroundColor',[1 1 1])
619
[122]620%get the imabe nomenclature type if not defined by the input file nor by the xml file
621dirima=[];%default
[12]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)
[112]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) '.*']);
[122]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 '.*']);
[112]635            end
636        end
[12]637    end
[112]638end
[122]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)
[128]650    ext_search=ext_imadoc;
[122]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,'*')
[12]657    subdir=get(handles.subdir_civ1,'String');
658    incr_pair=[0 0];%default
659    if isfield(browse,'incr_pair')
[112]660        incr_pair=browse.incr_pair;
[12]661    end
[112]662    %     nbdetect=0;%test of detected images
[122]663    field_i=browse.num_i2;
[153]664    imagename=name_generator(filebase,field_i,1,ext_search,nom_type_search);
665    imagename_plus='';
[12]666    idetect=1;
[153]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);
[81]670        if idetect
[12]671            field_i=field_i+1;
[81]672        end
[112]673        %SEE CASE OF NETCDF FILES
674        %             nbdetect=nbdetect+(exist(imagename,'file')==2);
[12]675    end
[122]676    nbfield=field_i;% last detected field number
677    field_i=browse.num_i1;%look for the minimum file number in the series
[153]678    imagename_min='';
[12]679    idetect=1;
[112]680    while idetect==1
[153]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);
[81]683        if idetect
[112]684            field_i=field_i-1;
[81]685        end
[12]686    end
[122]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;
[153]691        imagename_plus='';
[89]692        jdetect=1;
693        while jdetect==1 %look for the maximum file number in the series
[153]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);
[89]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
[122]702        nbfield2=field_j;% last detected field number
[120]703     end
[122]704 
[89]705    %determine the set of times and possible intervals for CIV
[137]706    %   dt=(1/1000)*str2double(get(handles.dt,'String'));
[122]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'}
[112]711        % time=[0:nb_field-1]'*ones(1,nb_field_j);% time=file index -1  by default
[122]712        [x,y]=meshgrid(0:nbfield2-1,0:nbfield-1);
[120]713        time=x+y;
714%         time=[0:nb_field-1]'*[0:nb_field_j-1];% time=file index -1  by default
[89]715    end
[122]716%     set(handles.mode,'String',{'series(Di)'})
[2]717end
[120]718
[2]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);
[71]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);
[2]727        set(handles.nb_field,'String',num2str(nbfield));
728        set(handles.nb_field2,'String',num2str(nbfield2));
729    end
730end
[71]731set(handles.CoordUnit,'String',CoordUnit)
[2]732set(handles.calcul_search,'UserData',[pxcmx_search pxcmy_search]);
733% npxy=[npy npx];
[71]734set(handles.ImaExt,'String',ext_ima)
[2]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
[112]742%%%%%%%%%%%  set the menus of image pairs and default selection for civ   %%%%%%%%%%%%%%%%%%%
[122]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))
[2]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
[122]752    if nbfield2 <= 10
[112]753        set(handles.mode,'Value',1)% advice 'pair j1-j2' for small burst
[2]754    end
755end
756
[112]757%update the subdir
[2]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
[112]771set(handles.list_subdir_civ1,'Value',1)
[2]772set(handles.list_subdir_civ2,'Value',1)
[107]773set(handles.list_subdir_civ1,'String',[{'browse...'};listdir])
774set(handles.list_subdir_civ2,'String',[{'browse...'};listdir])
[2]775%check wether the current subdir exists:
776subdir_civ1=get(handles.subdir_civ1,'String');
777subdir_civ2=get(handles.subdir_civ2,'String');
778
[112]779mode_Callback(hObject, eventdata, handles)
[2]780
781%%%%%% initialize waitbars and RUN button
[150]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])
[2]786set(handles.RUN, 'Enable','On')
787set(handles.RUN,'BackgroundColor',[1 0 0])
[122]788set(handles.BATCH,'Enable','On')
789set(handles.BATCH,'BackgroundColor',[1 0 0])
[112]790
[2]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
[147]798    txt=ver('MATLAB');
799    Release=txt.Release;
[137]800    relnumb=str2double(Release(3:4));
[2]801    if relnumb >= 14
[112]802        save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
[2]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
[12]810%------------------------------------------------------------------------
[2]811% --- Executes on button press in mode.
812function mode_Callback(hObject, eventdata, handles)
[12]813%------------------------------------------------------------------------
[2]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
[137]826ref_i=str2double(get(handles.ref_i,'String'));
[2]827% last_i=str2num(get(handles.last_i,'String'));
[71]828time=get(handles.RootName,'UserData'); %get the set of times
[2]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
[112]844            index=index+1;
845            numlist_a(index)=numod_a;
846            numlist_b(index)=numod_b;
847            if ~isempty(time)
[54]848                dt(numod_a,numod_b)=time(ref_i,numod_b)-time(ref_i,numod_a);%first time interval dt
[2]849                displ_dt(index)=dt(numod_a,numod_b);
[112]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')
[2]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)')
[112]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
[2]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
[112]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
[2]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')
[112]916    else
[2]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
[112]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
[2]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
[112]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')
[2]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
[112]959end
[2]960set(handles.list_pair_civ1,'UserData',displ_num);
961find_netcpair_civ1(hObject, eventdata, handles)
962find_netcpair_civ2(hObject, eventdata, handles)
963
[12]964%------------------------------------------------------------------------
[2]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)
[12]968%------------------------------------------------------------------------
[2]969set(gcf,'Pointer','watch')
970%nomenclature types
[71]971filebase=get(handles.RootName,'String');
[2]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
[112]991%determine nom_type_nc:
[2]992nom_type_nc=[];%default
993if isfield(browse,'nom_type_nc')
994    nom_type_nc=browse.nom_type_nc;
995end
996if isempty(nom_type_nc)
[112]997    [nom_type_nc]=nomtype2pair(nom_type_ima,isequal(mode,'series(Di)'),isequal(mode,'series(Dj)'));
[2]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
[45]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'));
[2]1013if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
1014    ref_j=0;
1015else
[45]1016    ref_j=str2double(get(handles.ref_j,'String'));
[2]1017end
[71]1018time=get(handles.RootName,'UserData');%get the set of times
[2]1019if isempty(time)
1020    time=[0 1];
[112]1021end
[71]1022%dt_unit=str2double(get(handles.dt,'String'));% used when there is no image documentation file
1023dt_unit=1000;%default
[2]1024displ_num=get(handles.list_pair_civ1,'UserData');
1025
[112]1026%eliminate the first pairs inconsistent with the position
1027if isempty(displ_num)
1028    nbpair=0;
1029else
[2]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
[112]1036end
[2]1037nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
1038
[112]1039%look for existing processed pairs involving the field at the middle of the series if civ1 will not
[2]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 %
[112]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
[2]1049    end
[112]1050    for ipair=1:nbpair
[2]1051        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
[112]1052            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
[2]1053        select(ipair)=exist(filename,'file')==2;
1054    end
1055    if ~exist('select','var') || isequal(select,zeros(size(1:nbpair)))
[112]1056        if isfield(browse,'incr_pair')
[2]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
[112]1065            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]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
[112]1070            set(handles.list_pair_civ1,'String',{''});
1071            %COMPLETER CAS STEREO
[2]1072            return
1073        end
1074    end
1075end
1076if isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
1077    if testpair
[73]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
[2]1090    else
[73]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
[2]1101    end
1102elseif isequal(mode,'series(Dj)')%|isequal(mode,'st_series(Dj)')% series on the j index
1103    if testpair
[112]1104        displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
[2]1105    else
[112]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
[2]1119elseif isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')%case of pairs
1120    for ipair=1:nbpair
1121        if select(ipair)
[112]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
[2]1129elseif isequal(mode,'displacement')
[112]1130    displ_pair={'Di=Dj=0'};
1131end
[2]1132set(handles.list_pair_civ1,'String',displ_pair');
1133ichoice=min(find(select));
[45]1134if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
1135initial=get(handles.list_pair_civ1,'Value');%initial choice of pair
[112]1136if initial>nbpair
1137    set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
[45]1138end
1139if numel(select)>=initial && ~isequal(select(initial),1)
[2]1140    set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
1141end
[45]1142
[2]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')
[12]1154
1155%------------------------------------------------------------------------
[112]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
[2]1158function find_netcpair_civ2(hObject, eventdata, handles)
[12]1159%------------------------------------------------------------------------
[2]1160set(gcf,'Pointer','watch')
1161%nomenclature types
[71]1162filebase=get(handles.RootName,'String');
[2]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
[94]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')
[2]1186    nom_type_nc='netc_old';%nom_type for the netcdf files
[94]1187elseif isequal(nom_type_ima,'none')||isequal(nom_type_nc,'none')
[2]1188    nom_type_nc='none';
[94]1189elseif isequal(nom_type_ima,'avi')||isequal(nom_type_ima,'_i')||isequal(nom_type_ima,'ima_num')||isequal(nom_type_nc,'_i1-i2')
[112]1190    nom_type_nc='_i1-i2';
[2]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';
[112]1196    end
[2]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
[45]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
[137]1213ref_i=str2double(get(handles.ref_i_civ2,'String'));
[2]1214if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
1215    ref_j=0;
1216else
[137]1217    ref_j=str2double(get(handles.ref_j_civ2,'String'));
[2]1218end
[71]1219time=get(handles.RootName,'UserData'); %get the set of times
[2]1220if isempty(time)
1221    time=[0 1];%default
1222end
[71]1223%dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
[73]1224%dt_unit=1000;
[2]1225displ_num=get(handles.list_pair_civ1,'UserData');
1226
1227
[112]1228%eliminate the first pairs inconsistent with the position
[2]1229if isempty(displ_num)
1230    nbpair=0;
1231else
1232    nbpair=length(displ_num(1,:));%nbre of displayed pairs
[112]1233    if  isequal(mode,'series(Di)')% | isequal(mode,'st_series(Di)')
[2]1234        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
[112]1235    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]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
[112]1241%look for existing processed pairs involving the field at the middle of the series if civ1 will not
[2]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%&...
[112]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
[2]1251    end
[112]1252    for ipair=1:nbpair
[2]1253        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
[112]1254            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
[2]1255        select(ipair)=exist(filename,'file')==2;
1256    end
1257    if  isequal(select,zeros(size(1:nbpair)))
[112]1258        if isfield(browse,'incr_pair')
[2]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
[112]1266            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]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
[112]1271            set(handles.list_pair_civ2,'Value',1);
1272            set(handles.list_pair_civ2,'String',{''});
[2]1273            return
1274        end
1275    end
1276end
[112]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)
[2]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)];
[112]1283            end
1284        else
1285            displ_pair{ipair}='...'; %pair not displayed in the menu
1286        end
1287    end
[2]1288elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)') % series on the j index
[112]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
[2]1299elseif isequal(mode,'pair j1-j2')% | isequal(mode,'st_pair j1-j2') %case of pairs
1300    for ipair=1:nbpair
1301        if select(ipair)
[112]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
[2]1309elseif isequal(mode,'displacement')
[112]1310    displ_pair={'Di=Dj=0'};
1311end
[2]1312val=get(handles.list_pair_civ2,'Value');
1313ichoice=min(find(select));
[137]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
[2]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');
[12]1324set(gcf,'Pointer','arrow')
[2]1325
[12]1326%------------------------------------------------------------------------
[112]1327%  determine the list of index pairs of processing file
[2]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)
[12]1330%------------------------------------------------------------------------
[112]1331first_i=str2double(get(handles.first_i,'String'));%first index i
1332last_i=str2double(get(handles.last_i,'String'));%last index i
[45]1333incr=str2double(get(handles.incr_i,'String'));% increment
[137]1334num_i=first_i:incr:last_i;% list of i indices (reference values for each pair)
[2]1335if isequal(get(handles.first_j,'Visible'),'on')
[45]1336    first_j=str2double(get(handles.first_j,'String'));%first index j
[112]1337    last_j=str2double(get(handles.last_j,'String'));%last index j
[45]1338    incr_j=str2double(get(handles.incr_j,'String'));% increment
[2]1339else
1340    first_j=1;
1341    last_j=1;
1342    incr_j=1;
1343end
[36]1344num_j=[first_j:incr_j:last_j];% list of j indices (reference values for each pair)
[2]1345list_civ1=get(handles.list_pair_civ1,'String');
1346index_civ1=get(handles.list_pair_civ1,'Value');
[36]1347str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1
[2]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
[36]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'),...
[112]1360        return,end;
[39]1361if isequal(last_i,[])|| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
[112]1362        return,end;
[39]1363if isequal(incr,[])|| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
[112]1364        return,end;
[39]1365if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
[112]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
[2]1370    str_raw=str_civ1(indsel);
1371    indsepar=find(str_raw=='|'); %character index of the separator
[137]1372    d1=str2double(str_civ1(indsel(indsepar-1)+1:indsel(indsepar)-1));
[2]1373    if indsepar==length(str_raw)
[137]1374        d2=str2double(str_civ1(indsel(indsepar)+1:end));
[2]1375    else
[137]1376        d2=str2double(str_civ1(indsel(indsepar)+1:indsel(indsepar+1)-1));
[112]1377    end
[39]1378    num1_civ1=num_i-d1;% set of first image numbers
1379    num2_civ1=num_i+d2;
[2]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
[137]1387    d1=str2double(str_civ2(indsel(indsepar-1)+1:indsel(indsepar)-1));
[2]1388    if indsepar==length(str_raw)
[137]1389        d2=str2double(str_civ2(indsel(indsepar)+1:end));
[2]1390    else
[137]1391        d2=str2double(str_civ2(indsel(indsepar)+1:indsel(indsepar+1)-1));
[112]1392    end
[137]1393    if isnan(d1)
[39]1394        num1_civ2=num_i;
[2]1395    else
[39]1396        num1_civ2=num_i-d1;% set of first image numbers
[2]1397    end
[137]1398    if isnan(d2)
[39]1399        num2_civ2=num_i;
[2]1400    else
[39]1401        num2_civ2=num_i+d2;
[2]1402    end
1403    num_a_civ2=num_j;
1404    num_b_civ2=num_j;
1405   
1406    % adjust the first and last field number
[137]1407    lastfield=str2double(get(handles.nb_field,'String'));
[2]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);
[39]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);
[2]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
[36]1424elseif isequal (mode,'series(Dj)')
[137]1425    lastfield_j=str2double(get(handles.nb_field2,'String'));
[39]1426    num1_civ1=num_i;% set of first image numbers
1427    num2_civ1=num_i;
[2]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));
[39]1430    num1_civ2=num_i;
1431    num2_civ2=num_i;
[2]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
[137]1435    if isnan(lastfield_j)
[2]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
[36]1451elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
[39]1452    num1_civ1=num_i;
1453    num1_civ2=num_i;
[2]1454    displ_num=get(handles.list_pair_civ1,'UserData');
[39]1455    num2_civ1=num_i;
[2]1456    num_a_civ1=displ_num(1,index_civ1);
1457    num_b_civ1=displ_num(2,index_civ1);
[39]1458    num2_civ2=num_i;
[2]1459    num_a_civ2=displ_num(1,index_civ2);
1460    num_b_civ2=displ_num(2,index_civ2);
1461elseif isequal(mode,'displacement')
[39]1462    num1_civ1=num_i;
1463    num2_civ1=num_i;
[2]1464    num_a_civ1=num_j;
1465    num_b_civ1=num_j;
[39]1466    num1_civ2=num_i;
1467    num2_civ2=num_i;
[2]1468    num_a_civ2=num_j;
1469    num_b_civ2=num_j;
1470end
1471
[41]1472
[12]1473%------------------------------------------------------------------------
[2]1474% --- Executes on selection change in list_pair_civ1.
1475function list_pair_civ1_Callback(hObject, eventdata, handles)
[12]1476%------------------------------------------------------------------------
[2]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');
[137]1481% num_a=displ_num(1,index_pair);
1482% num_b=displ_num(2,index_pair);
[2]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
[112]1488%update first_i and last_i according to the chosen image pairs
[2]1489mode_list=get(handles.mode,'String');
1490mode_value=get(handles.mode,'Value');
1491mode=mode_list{mode_value};
1492if isequal(mode,'series(Di)')
[137]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'));
[2]1496    num1=first_i:incr_i:last_i;
[137]1497    lastfield=str2double(get(handles.nb_field,'String'));
1498    if ~isnan(lastfield)
[2]1499        ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
[112]1500            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
[2]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)')
[137]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'));
[2]1509    num_j=first_j:incr_j:last_j;
[137]1510    lastfield2=str2double(get(handles.nb_field2,'String'));
1511    if ~isnan(lastfield2)
[2]1512        ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
[112]1513            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
[2]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)));
[112]1518end
[2]1519
[12]1520%------------------------------------------------------------------------
[2]1521% --- Executes on selection change in list_pair_civ2.
1522function list_pair_civ2_Callback(hObject, eventdata, handles)
[12]1523%------------------------------------------------------------------------
[112]1524index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu
[2]1525
[112]1526%update first_i and last_i according to the chosen image pairs
[2]1527mode_list=get(handles.mode,'String');
1528mode_value=get(handles.mode,'Value');
1529mode=mode_list{mode_value};
1530if isequal(mode,'series(Di)')
[137]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'));
[2]1534    num1=first_i:incr_i:last_i;
[137]1535    lastfield=str2double(get(handles.nb_field,'String'));
1536    if ~isnan(lastfield)
[2]1537        ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
[112]1538            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
[2]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)')
[137]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'));
[2]1547    num_j=first_j:incr_j:last_j;
[137]1548    lastfield2=str2double(get(handles.nb_field2,'String'));
1549    if ~isnan(lastfield2)
[2]1550        ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
[112]1551            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
[2]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)));
[112]1556end
[2]1557
[67]1558function RUN_Callback(hObject, eventdata, handles)
1559%------------------------------------------------------------------------
1560% global civ1_exe civ2_exe patch_exe patch_new_exe sge
[73]1561set(handles.RUN, 'Enable','Off')
1562set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
[67]1563batch=0;
1564launch_jobs(hObject, eventdata, handles,batch);
[73]1565set(handles.RUN, 'Enable','On')
1566set(handles.RUN,'BackgroundColor',[1 0 0])
[36]1567
[12]1568%------------------------------------------------------------------------
[2]1569% --- Executes on button press in BATCH: remote processing
1570function BATCH_Callback(hObject, eventdata, handles)
[133]1571%% -----------------------------------------------------------------------
[67]1572%global civ1_exe civ2_exe patch_exe patch_new_exe fix_exe todo_path sge Civ_exe % probabely to remove
[73]1573set(handles.BATCH, 'Enable','Off')
1574set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
[67]1575batch=1;
1576launch_jobs(hObject, eventdata, handles, batch)
[73]1577set(handles.BATCH, 'Enable','On')
1578set(handles.BATCH,'BackgroundColor',[1 0 0])
[67]1579
1580%------------------------------------------------------------------------
[133]1581% --- Lauch command called by RUN and BATCH: remote processing
[67]1582function launch_jobs(hObject, eventdata, handles, batch)
1583%-----------------------------------------------------------------------
[133]1584%% check the selected list of operations:
[2]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);
[159]1599box_used=box_test(index_first : index_last);
[2]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)
[12]1608    maskname=get(handles.mask_civ1,'String');
1609    if ~exist(maskname,'file')
1610        get_mask_civ1_Callback(hObject, eventdata, handles);
1611    end
[2]1612end
1613if isequal(get(handles.get_mask_fix1,'Value'),1)
[12]1614    maskname=get(handles.mask_fix1,'String');
1615    if ~exist(maskname,'file')
1616        get_mask_fix1_Callback(hObject, eventdata, handles);
1617    end
[2]1618end
1619if isequal(get(handles.get_mask_civ2,'Value'),1)
[12]1620    maskname=get(handles.mask_civ2,'String');
1621    if ~exist(maskname,'file')
[112]1622        get_mask_civ2_Callback(hObject, eventdata, handles);
[12]1623    end
[2]1624end
1625if isequal(get(handles.get_mask_fix2,'Value'),1)
[12]1626    maskname=get(handles.mask_fix2,'String');
1627    if ~exist(maskname,'file')
[112]1628        get_mask_fix2_Callback(hObject, eventdata, handles);
[12]1629    end
[2]1630end
1631
[137]1632%% initialize the waitbars: TO suppress, waitbar not used
[150]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
[133]1638
1639%% set the list of files and check them
1640display('checking the files...')
[150]1641%compare=get(handles.compare,'Value');%test for usual PIV (compare=1) or displacement (=2) or stereo PIV (=3)
[133]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]=...
[150]1643    set_civ_filenames(handles,box_test);
[137]1644if isempty(filecell)% (error message displayed in fct set_civ_filenames)
[133]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
[112]1682xmlfile='PARAM.xml';
[133]1683if exist(xmlfile,'file')% search parameter xml file in the whole matlab path
[54]1684    t=xmltree(xmlfile);
[67]1685    s=convert(t);
[2]1686end
[127]1687test_interp=0;
1688if batch
[67]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
[112]1705    if isfield(sparam,'CivBin')
1706        if ~exist(sparam.CivBin,'file')
1707            sparam.CivBin=fullfile(path_UVMAT,sparam.CivBin);
1708        end
[94]1709    end
[112]1710    if isfield(sparam,'Civ1Bin')
1711        if ~exist(sparam.Civ1Bin,'file')
1712            sparam.Civ1Bin=fullfile(path_UVMAT,sparam.Civ1Bin);
1713        end
[94]1714    end
[112]1715    if isfield(sparam,'Civ2Bin')
1716        if ~exist(sparam.Civ2Bin,'file')
1717            sparam.Civ2Bin=fullfile(path_UVMAT,sparam.Civ2Bin);
1718        end
[94]1719    end
[112]1720    %test_interp=get(handles.test_interp,'Value');
[116]1721
[112]1722    if  isfield(sparam,'PatchBin')
1723        if ~exist(sparam.PatchBin,'file')
1724            sparam.PatchBin=fullfile(path_UVMAT,sparam.PatchBin);
1725        end
[94]1726    end
[112]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
[94]1736    end
[73]1737end
[67]1738if batch
1739    if isfield(sparam,'BatchMode')
1740        batch_mode=sparam.BatchMode;
[2]1741    end
[67]1742else
[133]1743%     MaxCivProcesses=50;
1744%     if isfield(sparam,'MaxCivProcesses')
1745%         MaxCivProcesses=str2double(sparam.MaxCivProcesses);
1746%     end
[2]1747end
1748
1749
[133]1750%% get civ1 parameters:
[112]1751display('files OK, processing...')
1752%get civ parameters
[2]1753if box_test(1)==1
1754    par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1,1});
[112]1755end
[2]1756
[133]1757%% get fix1 parameters
[112]1758if box_test(2)==1
[2]1759    flagindex1(1)=get(handles.vec_Fmin2, 'Value');
1760    flagindex1(2)=get(handles.vec_F3, 'Value');
1761    flagindex1(3)=get(handles.vec_F2, 'Value');
[127]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
[2]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
[112]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);
[2]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};
[112]1777        msgbox_uvmat('WARNING','reference field is not used presently with batch, use RUN option')
1778    end
[2]1779end
[112]1780
[133]1781%% get patch1 parameters
[67]1782if box_test(3)==1
[127]1783    rho_patch1=str2double(get(handles.rho_patch1,'String'));
1784    if isnan(rho_patch1)
[112]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');
[127]1792    if isnan(str2double(nx_patch1))
[112]1793        nx_patch1='50' ;%default
1794        set(handles.nx_patch1,'String','50');
1795    end
[127]1796    if isnan(str2double(ny_patch1))
[112]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
[133]1804%% get civ2 parameters:
[2]1805if box_test(4)==1
1806    par_civ2=read_param_civ2(handles,cell2mat(filecell.ima1.civ2(1,1)));
1807end
1808
[133]1809%% get fix2 parameters
[112]1810if box_test(5)==1
[2]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');
[127]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
[2]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)
[112]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   
[2]1822    %%%%%%%%%%%%%%%%%%%
1823end
1824
[133]1825%% get patch2 parameters
[2]1826if box_test(6)==1
[127]1827    rho_patch2=str2double(get(handles.rho_patch2,'String'));
1828    if isnan(rho_patch2)
[2]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');
[127]1836    if isnan(str2double(nx_patch2))
[2]1837        nx_patch2='50' ;%default
1838        set(handles.nx_patch2,'String','50');
1839    end
[127]1840    if isnan(str2double(ny_patch2))
[2]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');
[112]1846    %              test_interp=get(handles.test_interp,'Value');
[2]1847end
1848
[133]1849%% MAIN LOOP
[71]1850time=get(handles.RootName,'UserData'); %get the set of times
[112]1851civAll=get(handles.Experimental,'Value'); % Boolean for new civ excution method
[134]1852super_cmd=[];
1853
[2]1854for ifile=1:nbfield
1855    for j=1:nbslice
[112]1856        i_cmd=0;
[2]1857        cmd='';
[73]1858        if isunix % check: necessaire aussi en RUN?
[112]1859            %fid=fopen([filename '.cmx'],'w')
1860            cmd='#!/bin/bash \n';
1861            cmd=[cmd '#$ -cwd \n'];
1862            cmd=[cmd 'hostname && date \n'];
[117]1863            cmd=[cmd 'umask 002 \n'];
[2]1864        end
1865        if civAll
1866            civAllxml=xmltree;% xml contents,  all parameters
[73]1867            civAllCmd='';
[2]1868            civAllxml=set(civAllxml,1,'name','CivDoc');
1869        end
[73]1870        filename_cmx=filecell.nc.civ1{ifile,j};%output netcdf file
[127]1871        filename_cmx(end-1:end+1)='cmx';%name of cmx file
[159]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';
[2]1879       
[112]1880        %CIV1
[2]1881        if box_test(1)==1
[41]1882            par_civ1.filename_ima_a=filecell.ima1.civ1{ifile,j};
[112]1883            par_civ1.filename_ima_b=filecell.ima2.civ1{ifile,j};
[2]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)));
[112]1886            par_civ1.T0=num2str((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(j)))/2);
[2]1887            par_civ1.term_a=num2stra(num_a_civ1(j),nom_type_nc);%UTILITE?
[112]1888            par_civ1.term_b=num2stra(num_b_civ1(j),nom_type_nc);%
[2]1889            test_mask=get(handles.get_mask_civ1,'Value');
[112]1890            if test_mask==0
[2]1891                par_civ1.maskname='noFile use default';
1892                par_civ1.maskflag='n';
1893            else
1894                maskdispl=get(handles.mask_civ1,'String');
[12]1895                if exist(maskdispl,'file')
1896                    par_civ1.maskname=maskdispl;
[112]1897                    par_civ1.maskflag='y';
[2]1898                else
[136]1899                    maskbase=[filecell.filebase '_' maskdispl]; %
[137]1900                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]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')
[82]1904                        par_civ1.maskflag='y';
[12]1905                    else
1906                        par_civ1.maskname='noFile use default';
[112]1907                        par_civ1.maskflag='n';
[12]1908                    end
[2]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')
[137]1917                    nbslice_grid=str2double(gridname(1:end-4)); %
1918                    if ~isnan(nbslice_grid)
[2]1919                        num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
[136]1920                        par_civ1.gridname=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[2]1921                        if ~exist(par_civ1.gridname,'file')
[112]1922                            msgbox_uvmat('ERROR','grid file absent for civ1')
[2]1923                        end
1924                    elseif exist(gridname,'file')
[112]1925                        par_civ1.gridname=gridname;
[2]1926                    else
1927                        msgbox_uvmat('ERROR','grid file absent for civ1')
1928                    end
1929                end
1930            else
[112]1931                par_civ1.gridname='noFile use default';
1932                par_civ1.gridflag='n';
[2]1933            end
[112]1934            %
[2]1935            i_cmd=i_cmd+1;
1936            if isequal(civAll,0)
[94]1937                cmd=[cmd CIV1_CMD(filename_cmx(1:end-4),namelog,par_civ1,handles,sparam) '\n'];
[2]1938            else
[112]1939                civAllCmd=[civAllCmd ' civ1 '];
1940                str=CIV1_CMD_Unified(filename_cmx([1:end-4]),namelog,par_civ1);
1941                fieldnames=fields(str);
[2]1942                [civAllxml,uid_civ1]=add(civAllxml,1,'element','civ1');
1943                for ilist=1:length(fieldnames)
[112]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
[2]1950            end
1951        end
1952       
[112]1953        % FIX1
1954        if box_test(2)==1
1955            test_mask=get(handles.get_mask_fix1,'Value');
1956            if test_mask==0
[2]1957                maskname='';
[112]1958            else
[2]1959                maskdispl=get(handles.mask_fix1,'String');
[137]1960                nbslice_mask=str2double(maskdispl(1:end-4)); %
[2]1961                num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
[136]1962                maskbase=[filecell.filebase '_' maskdispl];
[2]1963                maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
[112]1964            end
1965            if isequal(civAll,0)
[94]1966                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ1{ifile,j} ' -fi1 ' num2str(flagindex1(1)) ...
[112]1967                    ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
1968                    ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName ' maskname];
[94]1969                cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
1970                cmd=[cmd cmd_FIX '\n'];
[112]1971            else
[2]1972                fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
1973                fix1.fi1=num2str(flagindex1(1));
1974                fix1.fi2=num2str(flagindex1(2));
1975                fix1.fi3=num2str(flagindex1(3));
1976                fix1.threshC=num2str(thresh_vecC1);
[112]1977                fix1.threshV=num2str(thresh_vel1);
[2]1978                fieldnames=fields(fix1);
1979                [civAllxml,uid_fix1]=add(civAllxml,1,'element','fix1');
1980                for ilist=1:length(fieldnames)
[112]1981                    val=eval(['fix1.' fieldnames{ilist}]);
1982                    if ischar(val)
1983                        [civAllxml,uid_t]=add(civAllxml,uid_fix1,'element',fieldnames{ilist});
1984                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
1985                    end
1986                end
1987                civAllCmd=[civAllCmd ' fix1 '];
1988            end
1989        end
1990       
1991        %PATCH1
1992        if box_test(3)==1
1993            if isequal(civAll,0)
1994                cmd_PATCH=PATCH_CMD(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp,sparam.PatchBin);
1995                cmd_PATCH=regexprep(cmd_PATCH,'\\','\\\\');
1996                cmd=[cmd cmd_PATCH '\n'];
1997            else
1998                patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
1999                patch1.nopt=subdomain_patch1;
2000                patch1.maxdiff=thresh_patch1;
2001                patch1.ro=rho_patch1;
2002                test_grid=get(handles.get_gridpatch1,'Value');
2003                if test_grid
2004                    patch1.gridflag='y';
2005                    gridname=get(handles.grid_patch1,'String');
2006                    if isequal(gridname(end-3:end),'grid')
[137]2007                        nbslice_grid=str2double(gridname(1:end-4)); %
2008                        if ~isnan(nbslice_grid)
[112]2009                            num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
[136]2010                            patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[112]2011                            if ~exist(patch1.gridPatch,'file')
2012                                msgbox_uvmat('ERROR','grid file absent for patch1')
2013                            end
2014                        elseif exist(gridname,'file')
2015                            patch1.gridPatch=gridname;
2016                        else
2017                            msgbox_uvmat('ERROR','grid file absent for patch1')
[2]2018                        end
2019                    end
[112]2020                else
2021                    patch1.gridPatch='none';
2022                    patch1.gridflag='n';
2023                    patch1.m=nx_patch1;
2024                    patch1.n=ny_patch1;
[2]2025                end
[112]2026                patch1.convectFlow='n';
2027                fieldnames=fields(patch1);
[2]2028                [civAllxml,uid_patch1]=add(civAllxml,1,'element','patch1');
2029                for ilist=1:length(fieldnames)
[112]2030                    val=eval(['patch1.' fieldnames{ilist}]);
2031                    if ischar(val)
2032                        [civAllxml,uid_t]=add(civAllxml,uid_patch1,'element',fieldnames{ilist});
2033                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
2034                    end
2035                end
2036                civAllCmd=[civAllCmd ' patch1 '];
2037            end
[2]2038        end
[112]2039       
[127]2040        if box_test(4)==1 || box_test(5)==1 || box_test(6)==1
[112]2041            filename_cmx=filecell.nc.civ2{ifile,j};%output netcdf file
[127]2042            filename_cmx([end-1:end+1])=[ 'cmx'];%name of cmx file
2043%             filename_cmx=[filename_cmx 'x'];
[112]2044        end
2045       
2046        if box_test(4)==1
[2]2047            par_civ2.filename_ima_a=filecell.ima1.civ2{ifile,j};
2048            %par_civ2.filename_ima_a([end-3:end])=[];%remove .png extension
2049            par_civ2.filename_ima_b=filecell.ima2.civ2{ifile,j};
2050            %par_civ2.filename_ima_b([end-3:end])=[];%remove .png extension
2051            namelog=[filename_cmx([1:end-3]) 'log'];
2052            par_civ2.Dt=num2str(time(num2_civ2(ifile),num_b_civ2(j))-time(num1_civ2(ifile),num_a_civ2(j)));
[112]2053            par_civ2.T0=num2str((time(num2_civ1(ifile),num_b_civ2(j))+time(num1_civ2(ifile),num_a_civ2(j)))/2);
[2]2054            par_civ2.term_a=num2stra(num_a_civ2(j),nom_type_nc);
[112]2055            par_civ2.term_b=num2stra(num_b_civ2(j),nom_type_nc);
[2]2056            par_civ2.filename_nc1=filecell.nc.civ1{ifile,j};
2057            par_civ2.filename_nc1([end-2:end])=[]; % remove '.nc'
2058            test_mask=get(handles.get_mask_civ2,'Value');
[112]2059            if test_mask==0
[2]2060                par_civ2.maskname='noFile use default';
2061                par_civ2.maskflag='n';
2062            else
2063                maskdispl=get(handles.mask_civ2,'String');
[12]2064                if exist(maskdispl,'file')
2065                    par_civ2.maskname=maskdispl;
2066                    par_civ2.maskflag='y';
[2]2067                else
[136]2068                    maskbase=[filecell.filebase '_' maskdispl]; %
[137]2069                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]2070                    num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
2071                    par_civ2.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
2072                    if exist(par_civ2.maskname,'file')
[112]2073                        par_civ2.maskflag='y';
[12]2074                    else
2075                        par_civ2.maskname='noFile use default';
[112]2076                        par_civ2.maskflag='n';
[12]2077                    end
[2]2078                end
2079            end
2080            %TESTgrid
[137]2081            %test_grid=get(handles.browse_gridciv2,'Value');
[2]2082            gridname=get(handles.grid_civ2,'String');
[137]2083            %gridflag='y';
[2]2084            if numel(gridname)>=4 && isequal(gridname(end-3:end),'grid')
[137]2085                nbslice_grid=str2double(gridname(1:end-4)); %
2086                if ~isnan(nbslice_grid)
[2]2087                    par_civ2.gridflag='y';
2088                    num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
[136]2089                    par_civ2.gridname=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[2]2090                    if exist(par_civ2.gridname,'file')
[112]2091                        par_civ2.gridflag='y';
[2]2092                    else
2093                        par_civ2.gridname='noFile use default';
[112]2094                        par_civ2.gridflag='n';
[2]2095                    end
2096                elseif exist(gridname,'file')
[112]2097                    par_civ2.gridflag='y';
[2]2098                else
2099                    par_civ2.gridname='noFile use default';
[112]2100                    par_civ2.gridflag='n';
[2]2101                end
2102            end
2103            %endTESTgrid
2104            i_cmd=i_cmd+1;
[134]2105            cmd_CIV2=CIV2_CMD(filename_cmx(1:end-4),namelog,par_civ2,sparam);
[2]2106            if isequal(civAll,0)
2107                if(isunix)
[90]2108                    cmd=[cmd 'cp -f ' filename_cmx '2 ' filename_cmx '\n' cmd_CIV2 '\n'];
[2]2109                else
[94]2110                    filename_cmx=regexprep(filename_cmx,'\\','\\\\');
[90]2111                    cmd=[cmd 'copy /Y ' filename_cmx '2 ' filename_cmx '\n' cmd_CIV2 '\n'];
[2]2112                end
2113            else
[112]2114                civAllCmd=[civAllCmd ' civ2 '];
2115                str=CIV2_CMD_Unified(filename_cmx([1:end-4]),namelog,par_civ2);
2116                fieldnames=fields(str);
[2]2117                [civAllxml,uid_civ2]=add(civAllxml,1,'element','civ2');
2118                for ilist=1:length(fieldnames)
2119                    val=eval(['str.' fieldnames{ilist}]);
2120                    if ischar(val)
[112]2121                        [civAllxml,uid_t]=add(civAllxml,uid_civ2,'element',fieldnames{ilist});
2122                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
[2]2123                    end
[112]2124                end
[2]2125            end
[112]2126        end
2127       
2128        % FIX2
2129        if box_test(5)==1
2130            test_mask=get(handles.get_mask_fix2,'Value');
2131            if test_mask==0
2132                maskname=''; %no mask used
[2]2133            else
2134                maskdispl=get(handles.mask_fix2,'String');
[136]2135                maskbase=[filecell.filebase '_' maskdispl]; %
[137]2136                nbslice_mask=str2double(maskdispl(1:end-4)); %
[2]2137                num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
2138                maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
[112]2139            end
2140            if isequal(civAll,0)
[94]2141                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
[112]2142                    ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
2143                    ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
2144                cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
2145                cmd=[cmd cmd_FIX '\n'];
2146            else
[2]2147                fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
2148                fix2.fi1=num2str(flagindex2(1));
2149                fix2.fi2=num2str(flagindex2(2));
2150                fix2.fi3=num2str(flagindex2(3));
2151                fix2.threshC=num2str(thresh_vec2C);
[112]2152                fix2.threshV=num2str(thresh_vel2);
[2]2153                fieldnames=fields(fix2);
2154                [civAllxml,uid_fix2]=add(civAllxml,1,'element','fix2');
2155                for ilist=1:length(fieldnames)
[112]2156                    val=eval(['fix2.' fieldnames{ilist}]);
2157                    if ischar(val)
2158                        [civAllxml,uid_t]=add(civAllxml,uid_fix2,'element',fieldnames{ilist});
2159                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
2160                    end
2161                end
2162                civAllCmd=[civAllCmd ' fix2 '];
2163            end
2164        end
2165       
2166        %PATCH2
2167        if box_test(6)==1
[12]2168            if isequal(civAll,0)
[94]2169                cmd_PATCH=PATCH_CMD(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,test_interp,sparam.PatchBin);
2170                cmd_PATCH=regexprep(cmd_PATCH,'\\','\\\\');
[90]2171                cmd=[cmd cmd_PATCH '\n'];
[12]2172            else
2173                patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
2174                patch2.nopt=subdomain_patch1;
2175                patch2.maxdiff=thresh_patch1;
2176                patch2.ro=rho_patch1;
2177                test_grid=get(handles.get_gridpatch2,'Value');
2178                if test_grid
2179                    patch2.gridflag='y';
2180                    gridname=get(handles.grid_patch2,'String');
2181                    if isequal(gridname(end-3:end),'grid')
[137]2182                        nbslice_grid=str2double(gridname(1:end-4)); %
2183                        if ~isnan(nbslice_grid)
[12]2184                            num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
[136]2185                            patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[12]2186                            if ~exist(patch2.gridPatch,'file')
[112]2187                                msgbox_uvmat('ERROR','grid file absent for patch2')
[12]2188                            end
2189                        elseif exist(gridname,'file')
[112]2190                            patch2.gridPatch=gridname;
[12]2191                        else
2192                            msgbox_uvmat('ERROR','grid file absent for patch2')
[2]2193                        end
2194                    end
[12]2195                else
[112]2196                    patch2.gridPatch='none';
2197                    patch2.gridflag='n';
2198                    patch2.m=nx_patch2;
2199                    patch2.n=ny_patch2;
[2]2200                end
[12]2201                patch2.convectFlow='n';
2202                fieldnames=fields(patch2);
2203                [civAllxml,uid_patch2]=add(civAllxml,1,'element','patch2');
2204                for ilist=1:length(fieldnames)
[112]2205                    val=eval(['patch2.' fieldnames{ilist}]);
2206                    if ischar(val)
2207                        [civAllxml,uid_t]=add(civAllxml,uid_patch2,'element',fieldnames{ilist});
2208                        [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
2209                    end
2210                end
[12]2211                civAllCmd=[civAllCmd ' patch2 '];
[112]2212            end
[12]2213        end
2214        if isequal(civAll,1)
2215            save(civAllxml,[filename_cmx([1:end-4]) '.xml']);
[73]2216            %cmd=char({cmd;[CivBin ' -f ' [filename_cmx([1:end-4]) '.xml'] ' ' civAllCmd]});
[90]2217            cmd=[cmd CivBin ' -f ' filename_cmx(1:end-4) '.xml '  civAllCmd  '\n'];
[12]2218        end
[112]2219        % create the .bat file:
[159]2220        [fid,message]=fopen(filename_bat,'w');
2221        if isequal(fid,-1)
2222            msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
2223            return
[12]2224        end
[39]2225        fprintf(fid,cmd);
2226        fclose(fid);
[12]2227        %dlmwrite(filename_bat,cmd,'');%write commands in filename_bat
[67]2228        if batch
2229            switch batch_mode
2230                case 'sge'
2231                    pvalue=num2str((1-ind_answer)*500);
[133]2232                    %namelog=[filename_bat '.patch.log'];
[73]2233                    display(['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
[67]2234                    eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
2235            end
[12]2236        else
[112]2237            %% to lauch the jobs locally :
[12]2238            if(isunix)
[135]2239                cmd_str=['. ' filename_bat];
2240                % cmd_str=['!at -qb now -f ' filename_bat ' &']; %ou at -qb now -f bad idea...
[133]2241            else %case of Windows
[135]2242                cmd_str=['@call ' regexprep(filename_bat,'\\','\\\\')];
[2]2243            end
[135]2244            super_cmd=[super_cmd cmd_str '\n'];         
2245            %             eval(cmd_str);
2246            disp(cmd_str);
[12]2247        end
[112]2248    end
[2]2249end
[134]2250
[137]2251if ~batch
[159]2252    [Rootbat,Filebat,extbat]=fileparts(filename_bat);
[135]2253    filename_superbat=fullfile(Rootbat,['job_list.bat']);
[134]2254    fid=fopen(filename_superbat,'w');
2255    fprintf(fid,super_cmd');
2256    fclose(fid);
[135]2257    if(isunix)
2258        eval(['!. ' filename_superbat ' &']);
2259    else
2260        eval(['!' filename_superbat ' &']);
2261    end
[133]2262end
[2]2263
[137]2264%% save interface state
[2]2265if isfield(filecell,'nc')
2266    if isfield(filecell.nc,'civ2')
2267        fileresu=filecell.nc.civ2{1,1};
2268    else
2269        fileresu=filecell.nc.civ1{1,1};
2270    end
2271end
2272[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
2273namedoc=fullfile(RootPath,subdir,RootFile);
[112]2274detect=1;
[2]2275while detect==1
2276    namefigfull=[namedoc '.fig'];
2277    hh=dir(namefigfull);
2278    if ~isempty(hh)
2279        detect=1;
2280        namedoc=[namedoc '.0'];
2281    else
2282        detect=0;
2283    end
2284end
2285saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
2286
[134]2287
2288
[2]2289function [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]=...
[150]2290    set_civ_filenames(handles,box_test)
[12]2291%------------------------------------------------------------------------
[85]2292filecell=[];%default
[136]2293
2294%% get the root names nomenclature and numbers
[71]2295filebase=get(handles.RootName,'String');
[136]2296
2297if isempty(filebase)||isequal(filebase,'')
2298    msgbox_uvmat('ERROR','no input files')
2299    return
2300end
2301
[137]2302%filebase=regexprep(filebase,'\.fsnet','fsnet');% temporary fix for cluster Coriolis
[136]2303filecell.filebase=filebase;
2304
[2]2305browse=get(handles.browse_root,'UserData');
2306compare_list=get(handles.compare,'String');
2307val=get(handles.compare,'Value');
2308compare=compare_list{val};
2309if strcmp(compare,'displacement')
2310    mode='displacement';
2311else
2312    mode_list=get(handles.mode,'String');
2313    mode_value=get(handles.mode,'Value');
2314    mode=mode_list{mode_value};
2315end
[137]2316%time=get(handles.RootName,'UserData'); %get the set of times
[71]2317ext_ima=get(handles.ImaExt,'String');
[2]2318nom_type_nc=browse.nom_type_nc;
[122]2319if isfield(browse,'nom_type_ima')
2320    nom_type_ima2=browse.nom_type_ima;
2321end
2322if isempty(nom_type_ima2),nom_type_ima2='1';end; %default
2323if isempty(nom_type_nc),nom_type_nc='_i1-i2';end; %default
[2]2324[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
2325    find_pair_indices(handles,mode);
2326%determine the new filebase for 'displacement' mode (comparison of two series)
2327filebase_B=filebase;% root name of the second field series for stereo
2328if strcmp(compare,'displacement') || strcmp(compare,'stereo PIV')
[127]2329%     test_disp=1;
[2]2330    nom_type_ima1=browse.nom_type_ima_1; %nomenclature type of the second file series
2331    [Path2,Name2]=fileparts(filebase_B);
2332    Path1=Path2;
[71]2333    Name1=get(handles.RootName_1,'String');% root name of the first field series for stereo
[2]2334    filebase_A=fullfile(Path1,Name1);
2335    if length(Name1)>6
2336        Name1=Name1(end-5:end);
2337    end
2338    if length(Name2)>6
2339        Name2=Name2(end-5:end);
2340    end
2341    filebase_AB=fullfile(Path2,[Name2 '-' Name1]);
2342else
[127]2343%     test_disp=0;
[2]2344    filebase_A=filebase;
2345    nom_type_ima1=nom_type_ima2;
2346    filebase_AB=filebase;
2347end
2348if strcmp(compare,'displacement')
[112]2349    filebase_ima1=filebase_A;
2350    filebase_ima2=filebase_B;
2351    filebase_nc=filebase_AB; %root name for the result of civ2
[2]2352else
[112]2353    filebase_ima1=filebase_B;
2354    filebase_ima2=filebase_B;
2355    filebase_nc=filebase_B;
2356end
[2]2357
2358%determine reference files for fix:
2359file_ref_fix1={};%default
2360file_ref_fix2={};
2361nbfield=length(num1_civ1);
2362nbslice=length(num_a_civ1);
2363if box_test(2)==1% fix1 performed
2364    ref=get(handles.ref_fix1,'UserData');%read data on the ref file stored by get_ref_fix1_Callback
2365    if ~isempty(ref)
[137]2366        first_i=str2double(get(handles.first_i,'String'));
2367        last_i=str2double(get(handles.last_i,'String'));
2368        incr_i=str2double(get(handles.incr_i,'String'));
2369        first_j=str2double(get(handles.first_j,'String'));
2370        last_j=str2double(get(handles.last_j,'String'));
2371        incr_j=str2double(get(handles.incr_j,'String'));
[127]2372        num_i_ref=first_i:incr_i:last_i;
2373        num_j_ref=first_j:incr_j:last_j;
[2]2374        if isequal(mode,'displacement')
2375            num_i1=num_i_ref;
2376            num_i2=num_i_ref;
2377            num_j1=num_j_ref;
2378            num_j2=num_j_ref;
2379        elseif isequal(mode,'pair j1-j2')% isequal(mode,'st_pair j1-j2')
2380            num_i1=num_i_ref;
2381            num_i2=num_i1;
2382            num_j1=ref.num_a*ones(size(num_i_ref));
2383            num_j2=ref.num_b*ones(size(num_i_ref));
2384        elseif isequal(mode,'series(Di)') % isequal(mode,'st_series(Di)')
2385            delta1=floor((ref.num2-ref.num1)/2);
2386            delta2=ceil((ref.num2-ref.num1)/2);
2387            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2388            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2389            if isempty(ref.num_a)
2390                ref.num_a=1;
2391            end
2392            num_j1=ref.num_a*ones(size(num_i1));
2393            num_j2=num_j1;
2394        elseif isequal(mode,'series(Dj)')%| isequal(mode,'st_series(Dj)')
2395            delta1=floor((ref.num_b-ref.num_a)/2);
2396            delta2=ceil((ref.num_b-ref.num_a)/2);
2397            num_i1=ref.num1*ones(size(num_i_ref));
2398            num_i2=num_i1;
2399            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2400            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2401        end
2402        for ifile=1:nbfield
2403            for j=1:nbslice
2404                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);%
2405                file_ref_fix1(ifile,j)={file_ref};
2406                if ~exist(file_ref,'file')
2407                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix1'])
[12]2408                    filecell=[];
[2]2409                    return
2410                end
2411            end
2412        end
2413    end
2414end
2415
2416%determine reference files for fix2:
2417if box_test(5)==1% fix2 performed
2418    ref=get(handles.ref_fix2,'UserData');
2419    if ~isempty(ref)
[127]2420        first_i=str2double(get(handles.first_i,'String'));
2421        last_i=str2double(get(handles.last_i,'String'));
2422        incr_i=str2double(get(handles.incr_i,'String'));
2423        first_j=str2double(get(handles.first_j,'String'));
2424        last_j=str2double(get(handles.last_j,'String'));
2425        incr_j=str2double(get(handles.incr_j,'String'));
[2]2426        num_i_ref=[first_i:incr_i:last_i];
2427        num_j_ref=[first_j:incr_j:last_j];
2428        if isequal(mode,'displacement')
2429            num_i1=num_i_ref;
2430            num_i2=num_i_ref;
2431            num_j1=num_j_ref;
2432            num_j2=num_j_ref;
2433        elseif isequal(mode,'pair j1-j2')
2434            num_i1=num_i_ref;
2435            num_i2=num_i1;
2436            num_j1=ref.num_a;
2437            num_j2=ref.num_b;
2438        elseif isequal(mode,'series(Di)')
2439            delta1=floor((ref.num2-ref.num1)/2);
2440            delta2=ceil((ref.num2-ref.num1)/2);
2441            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2442            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2443            num_j1=ref.num_a*ones(size(num_i1));
2444            num_j2=num_j1;
2445        elseif isequal(mode,'series(Dj)')
2446            delta1=floor((ref.num_b-ref.num_a)/2);
2447            delta2=ceil((ref.num_b-ref.num_a)/2);
2448            num_i1=ref.num1*ones(size(num_i_ref));
2449            num_i2=num_i1;
2450            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2451            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2452        end
2453        for ifile=1:nbfield
2454            for j=1:nbslice
2455                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);%
2456                file_ref_fix2(ifile,j)={file_ref};
2457                if ~exist(file_ref,'file')
2458                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix2'])
[122]2459                    filecell={};
[2]2460                    return
2461                end
2462            end
2463        end
2464    end
2465end
2466
2467%check dir
2468subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf output data
2469subdir_civ2=get(handles.subdir_civ2,'String');
2470if isequal(subdir_civ1,''),subdir_civ1='A'; end% put default subdir
2471if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
[135]2472currentdir=pwd;%store the current working directory
[2]2473[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
2474if ~exist(Path_ima,'dir')
[12]2475    msgbox_uvmat('ERROR',['path to images ' Path_ima ' not found'])
[122]2476    filecell={};
[2]2477    return
2478end
[127]2479[xx,message]=fileattrib(Path_ima);
[122]2480if ~isempty(message) && ~isequal(message.UserWrite,1)
[112]2481    msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
[122]2482    filecell={};
[112]2483    cd(currentdir);
2484    return
[2]2485end
2486
2487%check the existence of the netcdf and image files involved
2488% %%%%%%%%%%%%  case CIV1 activated   %%%%%%%%%%%%%
2489if box_test(1)==1;
[112]2490    detect=1;
[127]2491    vers=0;
2492    subdir_civ1_new=subdir_civ1;
[153]2493    while detect==1 %create a new subdir if the netcdf files already exist
[122]2494        for ifile=1:nbfield
[112]2495            for j=1:nbslice
[122]2496                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);
[112]2497                detect=exist(filename,'file')==2;
2498                if detect% if a netcdf file already exists
[137]2499                    indstr=regexp(subdir_civ1_new,'\D');
2500                    if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
2501                        vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
2502                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]2503                    else
2504                        vers=vers+1;
[137]2505                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) '_' num2str(vers)];       
[127]2506                    end
[137]2507                    subdir_civ2=subdir_civ1_new;
[112]2508                    break
2509                end
2510                filecell.nc.civ1(ifile,j)={filename};
2511            end
2512            if detect% if a netcdf file already exists
2513                break
2514            end
2515        end
[134]2516 
[112]2517        %create the new subdir_civ1
[127]2518        if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
[134]2519            cd(Path_ima);         
[128]2520            [xx,msg1]=mkdir(subdir_civ1_new);
[134]2521
[128]2522            if ~strcmp(msg1,'')
2523                msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])%error message for directory creation
[122]2524                filecell={};
2525                return
[134]2526            else         
[128]2527                [xx,msg2] = fileattrib(subdir_civ1_new,'+w','g'); %yield writing access (+w) to user group (g)
2528                if ~strcmp(msg2,'')
[134]2529                    msgbox_uvmat('ERROR',['pb of permission for  ' subdir_civ1_new ': ' msg2])%error message for directory creation
[128]2530                    filecell={};
2531                    return
2532                end
[112]2533            end
[134]2534            cd(currentdir);
[112]2535        end
2536        if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
2537            for ifile=1:nbfield
2538                for j=1:nbslice
[122]2539                    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);%
[112]2540                    detect=exist(filename,'file')==2;
[2]2541                    if detect% if a netcdf file already exists
[137]2542                       indstr=regexp(subdir_civ1_new,'\D');
2543                       if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
2544                           vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
2545                           subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]2546                       else
2547                           vers=vers+1;
[137]2548                           subdir_civ1_new=[subdir_civ1_new '_' num2str(vers)];
[127]2549                       end
2550                       subdir_civ2=subdir_civ1;
2551                       break
[2]2552                    end
[112]2553                    filecell.ncA.civ1(ifile,j)={filename};
2554                end
2555                if detect% if a netcdf file already exists
2556                    break
2557                end
2558            end
2559            %create the new subdir_civ1
[134]2560            if exist(fullfile(Path_ima,subdir_civ1_new),'dir')
2561                   cd(Path_ima);         
[128]2562                [xx,msg1]=mkdir(subdir_civ1_new);
[134]2563                            cd(currentdir);
[128]2564                if ~strcmpl(msg1,'')
2565                    msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])
[122]2566                    cd(currentdir)
2567                    filecell={};
2568                    return
[128]2569                else
2570                    [xx,msg2] = fileattrib(subdir_civ1_new,'+w','g'); %yield writing access (+w) to user group (g)
2571                    if ~strcmp(msg2,'')
2572                        msgbox_uvmat('ERROR',['pb of permission for ' subdir_civ1_new ': ' msg2])%error message for directory creation
2573                        cd(currentdir)
2574                        filecell={};
2575                        return
2576                    end
[112]2577                end
2578            end
2579        end
2580    end
[127]2581    subdir_civ1=subdir_civ1_new;
[2]2582    % get image names
2583    for ifile=1:nbfield
[112]2584        for j=1:nbslice
[2]2585            filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2586            idetect(j)=exist(filename,'file')==2;
2587            filecell.ima1.civ1(ifile,j)={filename}; %first image
2588            filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2589            idetect_1(j)=exist(filename,'file')==2;
2590            filecell.ima2.civ1(ifile,j)={filename};%second image
[112]2591        end
2592        [idetectmin,indexj]=min(idetect);
2593        if idetectmin==0,
2594            msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
[122]2595            filecell={};
2596            cd(currentdir)
[112]2597            return
2598        end
2599        [idetectmin,indexj]=min(idetect_1);
2600        if idetectmin==0,
2601            msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
[122]2602            filecell={};
[112]2603            cd(currentdir)
2604            return
2605        end
2606    end
2607    if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
2608        for ifile=1:nbfield
2609            for j=1:nbslice
2610                filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2611                idetect(j)=exist(filename,'file')==2;
2612                filecell.imaA1.civ1(ifile,j)={filename} ;%first image
2613                filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2614                idetect_1(j)=exist(filename,'file')==2;
2615                filecell.imaA2.civ1(ifile,j)={filename};%second image
2616            end
[2]2617            [idetectmin,indexj]=min(idetect);
[112]2618            if idetectmin==0,
2619                msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
[122]2620                filecell={};
[112]2621                cd(currentdir)
[2]2622                return
[112]2623            end
[2]2624            [idetectmin,indexj]=min(idetect_1);
[112]2625            if idetectmin==0,
2626                msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
[122]2627                filecell={};
[2]2628                cd(currentdir)
2629                return
[112]2630            end
2631        end
[2]2632    end
[112]2633   
2634    %%%%%%%%%%%%%  fix1 or patch1 activated but no civ1   %%%%%%%%%%%%%
2635elseif (box_test(2)==1 || box_test(3)==1);
[2]2636    for ifile=1:nbfield
2637        for j=1:nbslice
2638            filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
[112]2639                nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2640            detect=exist(filename,'file')==2;
[122]2641            if detect==0
2642                msgbox_uvmat('ERROR',[filename ' not found'])
2643                filecell={};
2644                cd(currentdir)
2645                return
2646            end
[2]2647            filecell.nc.civ1(ifile,j)={filename};
2648        end
2649    end
2650    if strcmp(compare,'stereo PIV')
[112]2651        for ifile=1:nbfield
2652            for j=1:nbslice
2653                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);%
2654                filecell.ncA.civ1(ifile,j)={filename};
2655                if ~exist(filename,'file')
2656                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2657                    set(handles.RUN, 'Enable','On')
2658                    set(handles.RUN,'BackgroundColor',[1 0 0])
[122]2659                    filecell={};
[112]2660                    cd(currentdir)
2661                    return
[2]2662                end
2663            end
[112]2664        end
[2]2665    end
2666end
2667
2668%%%%%%%%%%%%%  if civ2 performed with pairs different than civ1  %%%%%%%%%%%%%
2669testdiff=0;
2670if (box_test(4)==1)&&...
[127]2671        ((get(handles.list_pair_civ1,'Value')~=get(handles.list_pair_civ2,'Value'))||~strcmp(subdir_civ2,subdir_civ1))
[2]2672    testdiff=1;
[112]2673    detect=1;
[127]2674    vers=0;
2675    subdir_civ2_new=subdir_civ2;
[2]2676    while detect==1 %create a new subdir if the netcdf files already exist
[112]2677        for ifile=1:nbfield
2678            for j=1:nbslice
[127]2679                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);%
[112]2680                detect=exist(filename,'file')==2;
2681                if detect% if a netcdf file already exists
[127]2682                    indstr=regexp(subdir_civ2,'\D');
2683                    if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2684                        vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2685                        subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2686                    else
2687                        vers=vers+1;
2688                        subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2689                    end
[112]2690                    break
2691                end
2692                filecell.nc.civ2(ifile,j)={filename};
2693            end
2694            if detect% if a netcdf file already exists
2695                break
2696            end
2697        end
[128]2698        %create the new subdir_civ2_new
2699        if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
2700            [xx,m2]=mkdir(subdir_civ2_new);
2701            [xx,msg2] = fileattrib(subdir_civ2_new,'+w','g'); %yield writing access (+w) to user group (g)
[112]2702            if ~isequal(m2,'')
[128]2703                msgbox_uvmat('ERROR',['cannot create ' subdir_civ2_new ': ' m2])
[122]2704                filecell={};
2705                cd(currentdir)
2706                return
[112]2707            end
2708        end
2709        if strcmp(compare,'stereo PIV')%check second nc series
2710            for ifile=1:nbfield
2711                for j=1:nbslice
2712                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[122]2713                        nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2_new);%
[112]2714                    detect=exist(filename,'file')==2;
[2]2715                    if detect% if a netcdf file already exists
[127]2716                        indstr=regexp(subdir_civ2,'\D');
2717                        if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2718                           vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2719                           subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2720                        else
2721                           vers=vers+1;
2722                           subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2723                        end
[112]2724                        break
[2]2725                    end
[112]2726                    filecell.ncA.civ2(ifile,j)={filename};
2727                end
2728                if detect% if a netcdf file already exists
2729                    break
2730                end
2731            end
[122]2732            subdir_civ2=subdir_civ2_new;
[112]2733            %create the new subdir_civ1
[127]2734            if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
2735                [xx,m2]=mkdir(subdir_civ2_new);
[128]2736                 [xx,msg2] = fileattrib(subdir_civ2_new,'+w','g'); %yield writing access (+w) to user group (g)
[112]2737                if ~isequal(m2,'')
[128]2738                    msgbox_uvmat('ERROR', ['cannot create ' subdir_civ2_new ': ' m2])%error message for directory creation
[122]2739                    cd(currentdir)
2740                    filecell={};
2741                    return
[112]2742                end
2743            end
2744        end
2745    end
[127]2746    subdir_civ2=subdir_civ2_new;
[2]2747end
2748cd(currentdir);%come back to the current working directory
2749
2750%%%%%%%%%%%%%  if civ2 results are obtained or used  %%%%%%%%%%%%%
2751if box_test(4)==1 || box_test(5)==1 || box_test(6)==1 %civ2
2752    %check source netcdf file of civ1 estimates
2753    if box_test(1)==0; %no civ1 performed
2754        for ifile=1:nbfield
2755            for j=1:nbslice
2756                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2757                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2758                filecell.nc.civ1(ifile,j)={filename};% name of the civ1 file
2759                if ~exist(filename,'file')
2760                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[122]2761                    filecell={};
[2]2762                    return
2763                end
2764                if ~testdiff % civ2 or patch2 are written in the same file as civ1
2765                    if box_test(4)==0 ; %check the existence of civ2 if it is not calculated
2766                        Data=nc2struct(filename,'ListGlobalAttribute','civ2');
2767                        if isempty(Data.civ2)||isequal(Data.civ2,0)
2768                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2769                            filecell=[];
[2]2770                            return
[112]2771                        end
[2]2772                    elseif box_test(3)==0; %check the existence of patch if it is not calculated
2773                        Data=nc2struct(filename,'ListGlobalAttribute','patch');
2774                        if isempty(Data.patch)||isequal(Data.patch,0)
2775                            msgbox_uvmat('ERROR',['no patch data in ' filename])
[12]2776                            filecell=[];
[2]2777                            return
2778                        end
[112]2779                    end
[2]2780                end
2781            end
2782        end
2783        if strcmp(compare,'stereo PIV')
2784            for ifile=1:nbfield
2785                for j=1:nbslice
2786                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2787                        nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2788                    filecell.ncA.civ2(ifile,j)={filename};
2789                    if ~exist(filename,'file')
2790                        msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2791                        set(handles.RUN, 'Enable','On')
2792                        set(handles.RUN,'BackgroundColor',[1 0 0])
2793                        return
2794                    end
2795                end
2796            end
2797        end
2798    end
[112]2799   
2800    detect=1;
2801    %     while detect==1%creates a new subdir if the netcdf files already contain civ2 data
2802    for ifile=1:nbfield
2803        for j=1:nbslice
2804            filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[2]2805                nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);
[112]2806            detect=exist(filename,'file')==2;
2807            filecell.nc.civ2(ifile,j)={filename};
[2]2808        end
[112]2809    end
[2]2810    %get first image names for civ2
2811    if box_test(1)==1 & isequal(num1_civ1,num1_civ2) & isequal(num_a_civ1,num_a_civ2)
2812        filecell.ima1.civ2=filecell.ima1.civ1;
2813    elseif box_test(4)==1
2814        for ifile=1:nbfield
2815            for j=1:nbslice
2816                filename=name_generator(filebase_ima1, num1_civ2(ifile),num_a_civ2(j),ext_ima,nom_type_ima1);
2817                idetect_2(j)=exist(filename,'file')==2;
2818                filecell.ima1.civ2(ifile,j)={filename};%first image
2819            end
[112]2820            [idetectmin,indexj]=min(idetect_2);
[2]2821            if idetectmin==0,
[112]2822                msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
2823                filecell=[];
2824                return
[2]2825            end
2826        end
2827    end
2828   
2829    %get second image names for civ2
2830    if box_test(1)==1 & isequal(num2_civ1,num2_civ2) & isequal(num_b_civ1,num_b_civ2)
2831        filecell.ima2.civ2=filecell.ima2.civ1;
2832    elseif box_test(4)==1
2833        for ifile=1:nbfield
2834            for j=1:nbslice
2835                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),ext_ima,nom_type_ima2);
2836                idetect_3(j)=exist(filename,'file')==2;
2837                filecell.ima2.civ2(ifile,j)={filename};%first image
2838            end
[112]2839            [idetectmin,indexj]=min(idetect_3);
[2]2840            if idetectmin==0,
[112]2841                msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
2842                filecell=[];
2843                return
[2]2844            end
2845        end
2846    end
2847end
2848if (box_test(5)==1 || box_test(6)==1 ) && box_test(4)==0  % need to read an existing netcdf civ2 file
2849    if ~testdiff
2850        filecell.nc.civ2=filecell.nc.civ1;% file already checked
[112]2851    else     % check the civ2 files
[2]2852        for ifile=1:nbfield
2853            for j=1:nbslice
2854                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[112]2855                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
[2]2856                filecell.nc.civ2(ifile,j)={filename};
2857                if ~exist(filename,'file')
2858                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[12]2859                    filecell=[];
[2]2860                    return
2861                else
2862                    Data=nc2struct(filename,'ListGlobalAttribute','civ2');
[112]2863                    if isempty(Data.civ2)||isequal(Data.civ2,0)
[2]2864                        msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2865                        filecell=[];
[2]2866                        return
2867                    end
2868                end
2869            end
2870        end
2871    end
2872end
2873
2874%%%%%%%%%%%%%  if stereo fields are calculated by PATCH %%%%%%%%%%%%%
2875if strcmp(compare,'stereo PIV')
[127]2876    if  box_test(3)==1 && isequal(get(handles.test_stereo1,'Value'),1)
[2]2877        for ifile=1:nbfield
2878            for j=1:nbslice
2879                filename=name_generator(filebase_AB,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2880                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2881                filecell.st(ifile,j)={filename};
2882            end
2883        end
2884    end
[127]2885    if  box_test(6)==1 && isequal(get(handles.test_stereo2,'Value'),1)
[2]2886        for ifile=1:nbfield
2887            for j=1:nbslice
2888                filename=name_generator(filebase_AB,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2889                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2890                filecell.st(ifile,j)={filename};
2891            end
2892        end
[112]2893    end
[2]2894end
2895set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
2896set(handles.subdir_civ2,'String',subdir_civ2);%update the edit box
2897browse.nom_type_nc=nom_type_nc;
2898set(handles.browse_root,'UserData',browse); %update the nomenclature type for uvmat
2899
2900
2901%COPY IMAGES TO THE FORMAT .png IF NEEDED
[45]2902if isequal(nom_type_ima1,'*')%case of movie files
2903    nom_type_imanew1='_i';
[2]2904else
2905    nom_type_imanew1=nom_type_ima1;
2906end
[45]2907if isequal(nom_type_ima2,'*')%case of movie files
2908    nom_type_imanew2='_i';
[2]2909else
2910    nom_type_imanew2=nom_type_ima2;
2911end
2912if ~isequal(ext_ima,'.png')
[45]2913    %%type of image file
2914    type_ima1='none';%default
2915    movieobject1=[];%default
[133]2916    if strcmpi(ext_ima,'.avi')
[45]2917        hhh=which('mmreader');
2918        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2919            type_ima1='movie';
2920            movieobject1=mmreader([filebase_ima2 ext_ima]);
2921        else
2922            type_ima1='avi';
2923        end
[133]2924    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2925        form=imformats(ext_ima(2:end));
2926        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2927            if isequal(nom_type_ima1,'*');
2928                type_ima1='multimage';%image series in a single image file
2929            else
2930                type_ima1='image';
2931            end
2932        end
[45]2933    end
2934    type_ima2='none';%default
2935    movieobject2=[];
[133]2936    if strcmpi(ext_ima,'.avi')
[45]2937        hhh=which('mmreader');
2938        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2939            type_ima2='movie';
2940            movieobject2=mmreader([filebase_ima2 ext_ima]);
2941        else
2942            type_ima2='avi';
2943        end
[133]2944    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2945        form=imformats(ext_ima(2:end));
2946        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2947            if isequal(nom_type_ima1,'*');
2948                type_ima2='multimage';%image series in a single image file
2949            else
2950                type_ima2='image';
2951            end
2952        end
[45]2953    end
[71]2954    %npxy=get(handles.ImaExt,'UserData');
[112]2955    % %     if numel(npxy)<2
2956    %
2957    %         filename=name_generator(filebase_ima1,num1_civ1(1),num_a_civ1(1),ImaExt,nom_type_ima1);
2958    %         A=imread(filename);
2959    %         npxy=size(A);
2960    % %     end
2961    %     npy=npxy(1);
2962    %     npx=npxy(2);
[2]2963    if box_test(1)==1 %if civ1 is performed
[112]2964        h = waitbar(0,['copy images to the .png format for civ1']);% display a wait bar
2965        for ifile=1:nbfield
[2]2966            waitbar(ifile/nbfield);
2967            for j=1:nbslice
[112]2968                filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
2969                if ~exist(filename,'file')
2970                    A=read_image(filecell.ima1.civ1{ifile,j},type_ima1,num1_civ1(ifile),movieobject1);
2971                    imwrite(A,filename,'BitDepth',16);
2972                end
2973                filecell.ima1.civ1(ifile,j)={filename};
2974                filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
2975                if ~exist(filename,'file')
2976                    A=read_image(filecell.ima2.civ1{ifile,j},type_ima2,num2_civ1(ifile),movieobject2);
2977                    imwrite(A,filename,'BitDepth',16);
2978                end
2979                filecell.ima2.civ1(ifile,j)={filename};
[2]2980            end
2981        end
2982        close(h)
2983    end
2984    if box_test(4)==1 %if civ2 is performed
[112]2985        h = waitbar(0,['copy images to the .png format for civ2']);% display a wait bar
[2]2986        for ifile=1:nbfield
2987            waitbar(ifile/nbfield);
2988            for j=1:nbslice
[112]2989                filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
2990                if ~exist(filename,'file')
2991                    A=read_image(cell2mat(filecell.ima1.civ2(ifile,j)),type_ima2,num1_civ2(ifile));
2992                    imwrite(A,filename,'BitDepth',16);
2993                end
2994                filecell.ima1.civ2(ifile,j)={filename};
2995                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
2996                if ~exist(filename,'file')
2997                    A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),type_ima2,num2_civ2(ifile));
2998                    imwrite(A,filename,'BitDepth',16);
2999                end
3000                filecell.ima2.civ2(ifile,j)={filename};
[2]3001            end
3002        end
3003        close(h);
3004    end
3005end
3006
[12]3007%------------------------------------------------------------------------
3008% --- PATCH
[94]3009function cmd_PATCH=PATCH_CMD(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp,PatchBin)
[12]3010%------------------------------------------------------------------------
[112]3011namelog=[filename_nc([1:end-3]) '_patch.log'];
3012if test_interp==0
3013    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
3014        '  > ' namelog ' 2>&1']; % redirect standard output to the log file
3015else %nouveau programme patch
3016    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
3017        ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
3018end
[12]3019
3020%------------------------------------------------------------------------
3021% --- STEREO Interp
[67]3022function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
[12]3023%------------------------------------------------------------------------
[2]3024namelog=[filename_nc([1:end-3]) '_stinterp.log'];
[67]3025cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
[2]3026    ' -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
3027
[12]3028%------------------------------------------------------------------------
[2]3029% --- Executes on button press in CIV1.
3030function CIV1_Callback(hObject, eventdata, handles)
[12]3031%------------------------------------------------------------------------
[2]3032val=get(handles.CIV1,'Value');
3033if isequal(val,1)
3034    enable_civ1(handles,'on')
3035    enable_pair1(handles,'on')
3036else
3037    enable_civ1(handles,'off')
3038end
3039find_netcpair_civ1(hObject, eventdata, handles);
3040
[12]3041%------------------------------------------------------------------------
[2]3042% --- Executes on button press in FIX1.
3043function FIX1_Callback(hObject, eventdata, handles)
[12]3044%------------------------------------------------------------------------
[2]3045enable_fix1(handles,get(handles.FIX1,'Value'))
3046
[12]3047%------------------------------------------------------------------------
[2]3048% --- Executes on button press in PATCH1.
3049function PATCH1_Callback(hObject, eventdata, handles)
[12]3050%------------------------------------------------------------------------
[2]3051if get(handles.PATCH1,'Value')==1
[12]3052    enable_patch1(handles)
[2]3053else
[12]3054    desable_patch1(handles)
[2]3055end
3056
[12]3057%------------------------------------------------------------------------
[2]3058% --- Executes on button press in CIV2.
3059function CIV2_Callback(hObject, eventdata, handles)
[12]3060%------------------------------------------------------------------------
[2]3061state=get(handles.CIV2,'Value');
3062enable_civ2(handles,state)
3063if state
3064    find_netcpair_civ2(hObject, eventdata, handles)
3065    enable_pair1(handles,'on')
3066end
3067
[12]3068%------------------------------------------------------------------------
[2]3069% --- Executes on button press in FIX2.
3070function FIX2_Callback(hObject, eventdata, handles)
[12]3071%------------------------------------------------------------------------
[2]3072if get(handles.FIX2,'Value')==1
3073    enable_fix2(handles)
3074    if get(handles.CIV2,'Value')==0
3075        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
3076    end
3077else
3078    desable_fix2(handles)
3079end
3080
[12]3081%------------------------------------------------------------------------
[2]3082% --- Executes on button press in PATCH2.
3083function PATCH2_Callback(hObject, eventdata, handles)
[12]3084%------------------------------------------------------------------------
[2]3085if get(handles.PATCH2,'Value')==1
3086    enable_patch2(handles)
3087    if get(handles.CIV2,'Value')==0
3088        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
3089    end
3090else
3091    desable_patch2(handles)
3092end
3093
[12]3094%------------------------------------------------------------------------
3095function first_i_Callback(hObject, eventdata, handles)
3096%------------------------------------------------------------------------
3097% last_i_Callback(hObject, eventdata, handles)
[137]3098first_i=str2double(get(handles.first_i,'String'));
[12]3099% last_i=str2num(get(handles.last_i,'String'));
3100% ref_i=ceil((first_i+last_i)/2);
3101set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
[71]3102set(handles.ref_i_civ2,'String', num2str(first_i))% reference index for pair dt = first index
[12]3103ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3104
[12]3105%------------------------------------------------------------------------
3106function first_j_Callback(hObject, eventdata, handles)
3107%------------------------------------------------------------------------
3108first_j=str2num(get(handles.first_j,'String'));
3109set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
3110ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3111
[12]3112%------------------------------------------------------------------------
[2]3113% --- Executes on button press in calcul_search: determine the search range isx,isy
3114function calcul_search_Callback(hObject, eventdata, handles)
[12]3115%------------------------------------------------------------------------
[2]3116%determine pair numbers
3117list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
3118index=get(handles.list_pair_civ1,'Value');
3119displ_num=get(handles.list_pair_civ1,'UserData');
[71]3120time=get(handles.RootName,'UserData'); %get the set of times
[2]3121pxcm_xy=get(handles.calcul_search,'UserData');
3122pxcmx=pxcm_xy(1);
3123pxcmy=pxcm_xy(2);
3124mode_list=get(handles.mode,'String');
3125mode_value=get(handles.mode,'Value');
3126mode=mode_list{mode_value};
3127if isequal (mode, 'series(Di)' )
[137]3128    ref_i=str2double(get(handles.ref_i,'String'));
[2]3129    num1=ref_i-floor(index/2);%  first image numbers
3130    num2=ref_i+ceil(index/2);
3131    num_a=1;
3132    num_b=1;
[112]3133elseif isequal (mode, 'series(Dj)')
[2]3134    num1=1;
3135    num2=1;
[137]3136    ref_j=str2double(get(handles.ref_j,'String'));
[2]3137    num_a=ref_j-floor(index/2);%  first image numbers
3138    num_b=ref_j+ceil(index/2);
3139elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
[137]3140    ref_i=str2double(get(handles.ref_i,'String'));
[2]3141    num1=ref_i;
3142    num2=ref_i;
3143    num_a=displ_num(1,index);
3144    num_b=displ_num(2,index);
3145end
3146dt=time(num2,num_b)-time(num1,num_a);
[137]3147ibx=str2double(get(handles.ibx,'String'));
3148iby=str2double(get(handles.iby,'String'));
3149umin=dt*pxcmx*str2double(get(handles.umin,'String'));
3150umax=dt*pxcmx*str2double(get(handles.umax,'String'));
3151vmin=dt*pxcmy*str2double(get(handles.vmin,'String'));
3152vmax=dt*pxcmy*str2double(get(handles.vmax,'String'));
[2]3153shiftx=round((umin+umax)/2);
3154shifty=round((vmin+vmax)/2);
3155isx=(umax+2-shiftx)*2+ibx;
3156isx=2*ceil(isx/2)+1;
3157isy=(vmax+2-shifty)*2+iby;
3158isy=2*ceil(isy/2)+1;
3159set(handles.shiftx,'String',num2str(shiftx));
3160set(handles.shifty,'String',num2str(shifty));
3161set(handles.isx,'String',num2str(isx));
3162set(handles.isy,'String',num2str(isy));
3163
[12]3164%------------------------------------------------------------------------
3165% --- Executes on carriage return on the subdir civ1 edit window
[2]3166function subdir_civ1_Callback(hObject, eventdata, handles)
[12]3167%------------------------------------------------------------------------
[2]3168subdir=get(handles.subdir_civ1,'String');
3169set(handles.subdir_civ2,'String',subdir);
[112]3170if get(handles.CIV1,'Value')==0
[2]3171    find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
3172end
3173
[12]3174%------------------------------------------------------------------------
3175% --- Executes on carriage return on the subdir civ1 edit window
[2]3176function subdir_civ2_Callback(hObject, eventdata, handles)
[12]3177%------------------------------------------------------------------------
[2]3178%update the list of available pairs from netcdf files in the new directory
3179if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
3180    find_netcpair_civ2(hObject, eventdata, handles);
3181end
3182
[12]3183%------------------------------------------------------------------------
[133]3184% --- Executes on button press in get_mask_civ1: select box for mask option
[2]3185function get_mask_civ1_Callback(hObject, eventdata, handles)
[12]3186%------------------------------------------------------------------------
[2]3187maskval=get(handles.get_mask_civ1,'Value');
3188if isequal(maskval,0)
3189    set(handles.mask_civ1,'String','')
3190else
3191    mask_displ='no mask'; %default
[71]3192    filebase=get(handles.RootName,'String');
[2]3193    [ nbslice_mask, flag_mask]=get_mask(filebase,handles);
3194    if isequal(flag_mask,1)
[112]3195        mask_displ=[num2str(nbslice_mask) 'mask'];
[2]3196    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[112]3197        common_path=fileparts(filebase);
3198        filebase_a=fullfile(common_path,get(handles.RootName_1,'String'));
3199        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3200        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice_mask)
3201            mask_displ='no mask';
3202        end
[2]3203    end
3204    if isequal(mask_displ,'no mask')
[12]3205        [FileName, PathName, filterindex] = uigetfile( ...
[112]3206            {'*.png', ' (*.png)';
3207            '*.png',  '.png files '; ...
3208            '*.*', 'All Files (*.*)'}, ...
3209            'Pick a mask file *.png',filebase);
3210        mask_displ=fullfile(PathName,FileName);
[12]3211        if ~exist(mask_displ,'file')
3212            mask_displ='no mask';
3213        end
3214    end
3215    if isequal(mask_displ,'no mask')
[2]3216        set(handles.get_mask_civ1,'Value',0)
3217        set(handles.get_mask_fix1,'Value',0)
3218        set(handles.get_mask_civ2,'Value',0)
3219        set(handles.get_mask_fix2,'Value',0)
3220    else
3221        set(handles.get_mask_fix1,'Value',1)
3222        set(handles.get_mask_fix2,'Value',1)
3223    end
3224    set(handles.mask_civ1,'String',mask_displ)
3225    set(handles.mask_fix1,'String',mask_displ)
3226    set(handles.mask_civ2,'String',mask_displ)
3227    set(handles.mask_fix2,'String',mask_displ)
3228end
[133]3229set(handles.get_mask_civ2,'Value',maskval)%update the civ2 mask with the same option as civ1
[2]3230
[12]3231%------------------------------------------------------------------------
[2]3232% --- Executes on button press in get_mask_fix1.
3233function get_mask_fix1_Callback(hObject, eventdata, handles)
[12]3234%------------------------------------------------------------------------
[2]3235maskval=get(handles.get_mask_fix1,'Value');
3236if isequal(maskval,0)
3237    set(handles.mask_fix1,'String','')
3238else
[112]3239    mask_displ='no mask'; %default
3240    filebase=get(handles.RootName,'String');
3241    [nbslice, flag_mask]=get_mask(filebase,handles);
3242    if isequal(flag_mask,1)
3243        mask_displ=[num2str(nbslice) 'mask'];
3244    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3245        filebase_a=get(handles.RootName_1,'String');
[2]3246        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3247        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
3248            mask_displ='no mask';
3249        end
[112]3250    end
3251    if isequal(mask_displ,'no mask')
3252        [FileName, PathName, filterindex] = uigetfile( ...
3253            {'*.png', ' (*.png)';
[12]3254            '*.png',  '.png files '; ...
3255            '*.*', 'All Files (*.*)'}, ...
3256            'Pick a mask file *.png',filebase);
[112]3257        mask_displ=fullfile(PathName,FileName);
3258        if ~exist(mask_displ,'file')
3259            mask_displ='no mask';
3260        end
[12]3261    end
[112]3262    if isequal(mask_displ,'no mask')
3263        set(handles.get_mask_fix1,'Value',0)
3264        set(handles.get_mask_civ2,'Value',0)
3265        set(handles.get_mask_fix2,'Value',0)
3266    else
3267        %set(handles.get_mask_civ2,'Value',1)
3268        set(handles.get_mask_fix2,'Value',1)
3269    end
3270    set(handles.mask_fix1,'String',mask_displ)
3271    set(handles.mask_civ2,'String',mask_displ)
3272    set(handles.mask_fix2,'String',mask_displ)
[12]3273end
3274
3275%------------------------------------------------------------------------
[133]3276% --- Executes on button press in get_mask_civ2: select box for mask option
[2]3277function get_mask_civ2_Callback(hObject, eventdata, handles)
[12]3278%------------------------------------------------------------------------
[2]3279maskval=get(handles.get_mask_civ2,'Value');
3280if isequal(maskval,0)
3281    set(handles.mask_civ2,'String','')
3282else
[112]3283    mask_displ='no mask'; %default
3284    filebase=get(handles.RootName,'String');
3285    [nbslice, flag_mask]=get_mask(filebase,handles);
3286    if isequal(flag_mask,1)
3287        mask_displ=[num2str(nbslice) 'mask'];
3288    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3289        filebase_a=get(handles.RootName_1,'String');
[2]3290        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3291        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
3292            mask_displ='no mask';
3293        end
[112]3294    end
3295    if isequal(mask_displ,'no mask')
3296        [FileName, PathName, filterindex] = uigetfile( ...
3297            {'*.png', ' (*.png)';
[12]3298            '*.png',  '.png files '; ...
3299            '*.*', 'All Files (*.*)'}, ...
3300            'Pick a mask file *.png',filebase);
[112]3301        mask_displ=fullfile(PathName,FileName);
3302        if ~exist(mask_displ,'file')
3303            mask_displ='no mask';
3304        end
[12]3305    end
[112]3306    if isequal(mask_displ,'no mask')
3307        set(handles.get_mask_civ2,'Value',0)
3308        set(handles.get_mask_fix2,'Value',0)
3309    else
3310        set(handles.get_mask_fix2,'Value',1)
3311    end
3312    set(handles.mask_civ2,'String',mask_displ)
3313    set(handles.mask_fix2,'String',mask_displ)
[12]3314end
3315
3316%------------------------------------------------------------------------
[2]3317% --- Executes on button press in get_mask_fix2.
3318function get_mask_fix2_Callback(hObject, eventdata, handles)
[12]3319%------------------------------------------------------------------------
[2]3320maskval=get(handles.get_mask_fix2,'Value');
3321if isequal(maskval,0)
3322    set(handles.mask_fix2,'String','')
3323else
[12]3324    mask_displ='no mask'; %default
[71]3325    filebase=get(handles.RootName,'String');
[12]3326    [nbslice, flag_mask]=get_mask(filebase,handles);
3327    if isequal(flag_mask,1)
[112]3328        mask_displ=[num2str(nbslice) 'mask'];
[12]3329    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[112]3330        filebase_a=get(handles.RootName_1,'String');
3331        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3332        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
3333            mask_displ='no mask';
3334        end
[12]3335    end
3336    if isequal(mask_displ,'no mask')
3337        [FileName, PathName, filterindex] = uigetfile( ...
[112]3338            {'*.png', ' (*.png)';
3339            '*.png',  '.png files '; ...
3340            '*.*', 'All Files (*.*)'}, ...
3341            'Pick a mask file *.png',filebase);
3342        mask_displ=fullfile(PathName,FileName);
[12]3343        if ~exist(mask_displ,'file')
[2]3344            mask_displ='no mask';
3345        end
[12]3346    end
3347    if isequal(mask_displ,'no mask')
3348        set(handles.get_mask_fix2,'Value',0)
[112]3349    end
[12]3350    set(handles.mask_fix2,'String',mask_displ)
[2]3351end
3352
[12]3353%------------------------------------------------------------------------
3354% --- function called to look for mask files
[2]3355function [nbslice, flag_mask]=get_mask(filebase,handles)
[12]3356%------------------------------------------------------------------------
[112]3357%detect mask files, images with appropriate file base
[2]3358%[filebase '_' xx 'mask'], xx=nbslice
3359%flag_mask=1 indicates detection
3360
3361flag_mask=0;%default
3362nbslice=1;
3363
3364% subdir=get(handles.subdir_civ1,'String');
3365[Path,Name]=fileparts(filebase);
[12]3366if ~isdir(Path)
3367    msgbox_uvmat('ERROR','no path for input files')
3368    return
3369end
[2]3370currentdir=pwd;
3371cd(Path);%move in the dir of the root name filebase
3372maskfiles=dir([Name '_*mask_*.png']);%look for mask files
3373cd(currentdir);%come back to the current working directory
[12]3374if ~isempty(maskfiles)
[112]3375    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
3376    % else
[2]3377    flag_mask=1;
3378    maskname=maskfiles(1).name;% take the first mask file in the list
3379    [Path2,Name,ext]=fileparts(maskname);
3380    Namedouble=double(Name);
3381    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3382    ind_mask=findstr('mask',Name);
3383    i=ind_mask-1;
[137]3384    while val(i)==0 && i>0
[112]3385        i=i-1;
[2]3386    end
[137]3387    nbslice=str2double(Name(i+1:ind_mask-1));
3388    if ~isnan(nbslice) && Name(i)=='_'
[112]3389        flag_mask=1;
[2]3390    else
[112]3391        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
3392        return
3393        nbslice=1;
[2]3394    end
[112]3395end
[2]3396
[12]3397%------------------------------------------------------------------------
3398% --- function called to look for grid files
[2]3399function [nbslice, flag_mask]=get_grid(filebase,handles)
[12]3400%------------------------------------------------------------------------
[2]3401flag_mask=0;%default
3402nbslice=1;
3403[Path,Name]=fileparts(filebase);
3404currentdir=pwd;
3405cd(Path);%move in the dir of the root name filebase
3406maskfiles=dir([Name '_*grid_*.grid']);%look for mask files
3407cd(currentdir);%come back to the current working directory
3408if ~isempty(maskfiles)
3409    flag_mask=1;
3410    maskname=maskfiles(1).name;% take the first mask file in the list
3411    [Path2,Name,ext]=fileparts(maskname);
3412    Namedouble=double(Name);
3413    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3414    ind_mask=findstr('grid',Name);
3415    i=ind_mask-1;
[137]3416    while val(i)==0 && i>0
[112]3417        i=i-1;
[2]3418    end
[137]3419    nbslice=str2double(Name(i+1:ind_mask-1));
3420    if ~isnan(nbslice) && Name(i)=='_'
[112]3421        flag_mask=1;
[2]3422    else
[112]3423        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
3424        return
3425        nbslice=1;
[2]3426    end
[12]3427end
[2]3428
[12]3429%------------------------------------------------------------------------
3430% --- transform numbers to letters
[122]3431function str=num2stra(num,nom_type)
[12]3432%------------------------------------------------------------------------
[122]3433if isempty(nom_type)
3434    str='';
3435elseif strcmp(nom_type(end),'a')
[2]3436    str=char(96+num);
[122]3437elseif strcmp(nom_type(end),'A')
3438    str=char(96+num);
3439elseif isempty(nom_type(2:end))%a single index
[2]3440    str='';
3441else
3442    str=num2str(num);
3443end
[12]3444
3445%------------------------------------------------------------------------
[2]3446function mask_civ1_Callback(hObject, eventdata, handles)
[12]3447%------------------------------------------------------------------------
[2]3448set(handles.mask_civ1,'UserData',[])
3449set(handles.mask_civ1,'String','')
[12]3450
3451%------------------------------------------------------------------------
[2]3452function mask_civ2_Callback(hObject, eventdata, handles)
[12]3453%------------------------------------------------------------------------
[2]3454set(handles.mask_civ2,'UserData',[])
3455set(handles.mask_civ2,'String','')
[12]3456
3457%------------------------------------------------------------------------
[2]3458function mask_fix1_Callback(hObject, eventdata, handles)
[12]3459%------------------------------------------------------------------------
[2]3460set(handles.mask_fix1,'UserData',[])
3461set(handles.mask_fix1,'String','')
[12]3462
3463%------------------------------------------------------------------------
[2]3464function mask_fix2_Callback(hObject, eventdata, handles)
[12]3465%------------------------------------------------------------------------
[2]3466set(handles.mask_fix2,'UserData',[])
3467set(handles.mask_fix2,'String','')
3468
[12]3469%------------------------------------------------------------------------
[2]3470% --- Executes on button press in list_subdir_civ1.
3471function list_subdir_civ1_Callback(hObject, eventdata, handles)
[12]3472%------------------------------------------------------------------------
[2]3473list_subdir_civ1=get(handles.list_subdir_civ1,'String');
3474val=get(handles.list_subdir_civ1,'Value');
3475if val>1
3476    subdir=list_subdir_civ1{val};
3477    set(handles.subdir_civ1,'String',subdir);
3478    set(handles.list_subdir_civ1,'Value',1);
3479end
3480
[12]3481%------------------------------------------------------------------------
[2]3482% --- Executes on button press in list_subdir_civ2.
3483function list_subdir_civ2_Callback(hObject, eventdata, handles)
[12]3484%------------------------------------------------------------------------
[2]3485list_subdir_civ2=get(handles.list_subdir_civ2,'String');
3486val=get(handles.list_subdir_civ2,'Value');
3487if val>1
3488    subdir=list_subdir_civ2{val};
3489    set(handles.subdir_civ2,'String',subdir);
3490    set(handles.list_subdir_civ2,'Value',1);
3491end
3492
[12]3493%------------------------------------------------------------------------
[2]3494% --- Executes on button press in browse_gridciv1.
3495function browse_gridciv1_Callback(hObject, eventdata, handles)
[12]3496%------------------------------------------------------------------------
[2]3497value=get(handles.browse_gridciv1,'Value');
3498testgrid=0;
3499if value
[112]3500    filebase=get(handles.RootName,'String');
[39]3501    [nbslice, flag_grid]=get_grid(filebase,handles);
[2]3502    if isequal(flag_grid,1)
[112]3503        filegrid=[num2str(nbslice) 'grid'];
3504        testgrid=1;
3505    else
[2]3506        [FileName, PathName, filterindex] = uigetfile( ...
[112]3507            {'*.grid', ' (*.grid)';
3508            '*.grid',  '.grid files '; ...
3509            '*.*', 'All Files (*.*)'}, ...
3510            'Pick a file',filebase);
[2]3511        filegrid=fullfile(PathName,FileName);
3512        if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file'))
3513            testgrid=1;
3514        end
[112]3515    end
[2]3516end
3517if testgrid
[112]3518    set(handles.browse_gridciv2,'Value',1)
3519    set(handles.get_gridpatch1,'Value',1)
3520    set(handles.get_gridpatch2,'Value',1)
3521    set(handles.dx_civ1,'Visible','off');
3522    set(handles.dy_civ1,'Visible','off');
3523    set(handles.dx_civ2,'Visible','off');
3524    set(handles.dy_civ2,'Visible','off');
3525    set(handles.grid_civ1,'String',filegrid)
3526    set(handles.grid_patch1,'String',filegrid)
3527    set(handles.grid_civ2,'String',filegrid)
3528    set(handles.grid_patch2,'String',filegrid)
3529else
3530    set(handles.browse_gridciv1,'Value',0);
3531    set(handles.browse_gridciv2,'Value',0);
3532    set(handles.get_gridpatch1,'Value',0)
3533    set(handles.get_gridpatch2,'Value',0)
3534    set(handles.dx_civ1,'Visible','on');
3535    set(handles.dy_civ1,'Visible','on');
3536    set(handles.dx_civ2,'Visible','on');
3537    set(handles.dy_civ2,'Visible','on');
3538    set(handles.grid_civ1,'String','')
3539    set(handles.grid_patch1,'String','')
3540    set(handles.grid_civ2,'String','')
3541    set(handles.grid_patch2,'String','')
[2]3542end
3543
[12]3544%------------------------------------------------------------------------
[2]3545% --- Executes on button press in browse_gridciv1.
3546function browse_gridciv2_Callback(hObject, eventdata, handles)
[12]3547%------------------------------------------------------------------------
[2]3548value=get(handles.browse_gridciv2,'Value');
3549if value
[112]3550    filebase=get(handles.RootName,'String');
[39]3551    [nbslice, flag_grid]=get_grid(filebase,handles);
[2]3552    if isequal(flag_grid,1)
3553        mask_displ=[num2str(nbslice) 'grid'];
3554        set(handles.grid_civ2,'String',mask_displ)
3555        set(handles.dx_civ2,'Visible','off');
3556        set(handles.dy_civ2,'Visible','off');
[112]3557    else
[2]3558        [FileName, PathName, filterindex] = uigetfile( ...
[112]3559            {'*.grid', ' (*.grid)';
3560            '*.grid',  '.grid files '; ...
3561            '*.*', 'All Files (*.*)'}, ...
3562            'Pick a file',filebase);
[2]3563        filegrid=fullfile(PathName,FileName);
3564        if isempty(FileName)|isempty(PathName)|isequal(FileName,0)|~exist(filegrid,'file')
3565            set(handles.browse_gridciv2,'Value',0);
3566            set(handles.grid_civ2,'string','');
3567            set(handles.dx_civ2,'Visible','on');
3568            set(handles.dy_civ2,'Visible','on');
3569            set(handles.grid_civ2,'string','');
3570        else
3571            set(handles.grid_civ2,'string',filegrid);
3572            set(handles.dx_civ2,'Visible','off');
3573            set(handles.dy_civ2,'Visible','off');
3574            set(handles.grid_civ2,'string',filegrid);
3575        end
3576    end
3577else
3578    set(handles.grid_civ2,'string','');
[112]3579    set(handles.dx_civ2,'Visible','on');
3580    set(handles.dy_civ2,'Visible','on');
3581    set(handles.grid_civ2,'string','');
[2]3582end
3583
3584% % --- Executes on button press in browse_gridciv2.
3585% function browse_gridciv2_Callback(hObject, eventdata, handles)
[112]3586%
[71]3587% filebase=get(handles.RootName,'String');
[2]3588% [FileName, PathName, filterindex] = uigetfile( ...
3589%        {'*.grid', ' (*.grid)';
3590%         '*.grid',  '.grid files '; ...
3591%         '*.*', 'All Files (*.*)'}, ...
3592%         'Pick a file',filebase);
3593% filegrid=fullfile(PathName,FileName);
3594% set(handles.grid_civ2,'string',filegrid);
3595% set(handles.dx_civ2,'String',' ');
3596% set(handles.dy_civ2,'String',' ');
3597% % set(handles.grid_patch2,'string',filegrid);
3598
3599% --- Executes on button press in get_gridpatch1.
3600function get_gridpatch1_Callback(hObject, eventdata, handles)
3601% hObject    handle to get_gridpatch1 (see GCBO)
3602% eventdata  reserved - to be defined in a future version of MATLAB
3603% handles    structure with handles and user data (see GUIDATA)
3604
[71]3605filebase=get(handles.RootName,'String');
[2]3606[FileName, PathName, filterindex] = uigetfile( ...
[112]3607    {'*.grid', ' (*.grid)';
3608    '*.grid',  '.grid files '; ...
3609    '*.*', 'All Files (*.*)'}, ...
3610    'Pick a file',filebase);
[2]3611filegrid=fullfile(PathName,FileName);
3612set(handles.grid_patch1,'string',filegrid);
3613% set(handles.grid_patch2,'string',filegrid
3614
[12]3615%------------------------------------------------------------------------
[2]3616% --- Executes on button press in get_gridpatch2.
3617function get_gridpatch2_Callback(hObject, eventdata, handles)
[12]3618%------------------------------------------------------------------------
[2]3619
[12]3620%------------------------------------------------------------------------
[2]3621function enable_civ1(handles,state)
[12]3622%------------------------------------------------------------------------
[2]3623if isequal(state,0)
3624    state='off';
3625end
3626if isequal(state,1)
3627    state='on';
3628end
3629if isequal(state,'on')
3630    set(handles.frame_civ1,'BackgroundColor',[1 1 0])
3631    set(handles.frame_para_civ1,'BackgroundColor',[1 1 0])
3632    set(handles.frame_grid_civ1,'BackgroundColor',[1 1 0])
3633else
3634    set(handles.frame_civ1,'BackgroundColor',[0.831 0.816 0.784])
3635    set(handles.frame_para_civ1,'BackgroundColor',[0.831 0.816 0.784])
3636    set(handles.frame_grid_civ1,'BackgroundColor',[0.831 0.816 0.784])
3637end
3638set(handles.ibx,'Visible',state)
3639set(handles.iby,'Visible',state)
3640set(handles.isx,'Visible',state)
3641set(handles.isy,'Visible',state)
3642set(handles.shiftx,'Visible',state)
3643set(handles.shifty,'Visible',state)
3644set(handles.rho,'Visible',state)
3645set(handles.dx_civ1,'Visible',state)
3646set(handles.dy_civ1,'Visible',state)
3647set(handles.calcul_search,'Visible',state)
3648set(handles.u_text,'Visible',state)
3649set(handles.v_text,'Visible',state)
3650set(handles.min,'Visible',state)
3651set(handles.max,'Visible',state)
3652set(handles.umin,'Visible',state)
3653set(handles.umax,'Visible',state)
3654set(handles.vmin,'Visible',state)
3655set(handles.vmax,'Visible',state)
3656set(handles.grid_civ1,'Visible',state)
3657set(handles.mask_civ1,'Visible',state)
3658set(handles.browse_gridciv1,'Visible',state)
3659set(handles.get_mask_civ1,'Visible',state)
3660set(handles.parameters,'Visible',state)
3661set(handles.grid,'Visible',state)
3662set(handles.dx_civ1,'Visible',state)
3663set(handles.dy_civ1,'Visible',state)
3664set(handles.ImaThreshold,'Visible',state)
3665if isequal(state,'off')
3666    set(handles.MinIma,'Visible','off')
3667    set(handles.MaxIma,'Visible','off')
3668    set(handles.ImaThreshold,'Value',0)
3669end
3670set(handles.dx_civ1_title,'Visible',state)
3671set(handles.dy_civ1_title,'Visible',state)
3672set(handles.ImaThreshold_title,'Visible',state)
3673set(handles.ib_title,'Visible',state)
3674set(handles.is_title,'Visible',state)
3675set(handles.shift_title,'Visible',state)
3676set(handles.rho_title,'Visible',state)
3677
[12]3678%------------------------------------------------------------------------
[2]3679function enable_fix1(handles,state)
[12]3680%------------------------------------------------------------------------
[2]3681if isequal(state,0)
3682    state='off';
3683end
3684if isequal(state,1)
3685    state='on';
3686end
3687if isequal(state,'on')
3688    set(handles.frame_fix1,'BackgroundColor',[1 1 0])
3689else
3690    set(handles.frame_fix1,'BackgroundColor',[0.7 0.7 0.7])
3691end
3692set(handles.REMOVE,'Visible',state)
3693set(handles.vec_Fmin2,'Visible',state)
3694set(handles.vec_F2,'Visible',state)
3695set(handles.vec_F3,'Visible',state)
3696set(handles.thresh_vecC,'Visible',state)
3697set(handles.thresh_vecC_title,'Visible',state)
3698set(handles.thresh_vel,'Visible',state)
3699set(handles.thresh_vel_text,'Visible',state)
3700set(handles.mask_fix1,'Visible',state)
3701set(handles.get_mask_fix1,'Visible',state)
3702set(handles.get_ref_fix1,'Visible',state)
3703set(handles.ref_fix1,'Visible',state)
3704set(handles.inf_sup1,'Visible',state)
3705set(handles.field_ref1,'Visible',state)
3706
[12]3707%------------------------------------------------------------------------
[2]3708function enable_patch1(handles)
[12]3709%------------------------------------------------------------------------
[67]3710global patch_newBin
[2]3711set(handles.frame_patch1,'BackgroundColor',[1 1 0])
3712set(handles.rho_patch1,'Visible','on')
3713set(handles.rho_text1,'Visible','on')
3714set(handles.thresh_patch1,'Visible','on')
3715set(handles.thresh_text1,'Visible','on')
3716set(handles.subdomain_patch1,'Visible','on')
3717set(handles.subdomain_text1,'Visible','on')
3718set(handles.nx_patch1,'Visible','on')
3719set(handles.ny_patch1,'Visible','on')
3720set(handles.nx_patch1_title,'Visible','on')
3721set(handles.ny_patch1_title,'Visible','on')
[112]3722% if ~isempty(patch_newBin)
[100]3723%     set(handles.test_interp,'Visible','on');
3724% end
[2]3725set(handles.get_gridpatch1,'Visible','on')
3726set(handles.grid_patch1,'string','none');
3727set(handles.grid_patch1,'Visible','on')
3728
[12]3729%------------------------------------------------------------------------
[2]3730function desable_patch1(handles)
[12]3731%------------------------------------------------------------------------
[2]3732set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
3733set(handles.rho_patch1,'Visible','off')
3734set(handles.rho_text1,'Visible','off')
3735set(handles.thresh_patch1,'Visible','off')
3736set(handles.thresh_text1,'Visible','off')
3737set(handles.subdomain_patch1,'Visible','off')
3738set(handles.subdomain_text1,'Visible','off')
3739set(handles.nx_patch1,'Visible','off')
3740set(handles.ny_patch1,'Visible','off')
3741set(handles.nx_patch1_title,'Visible','off')
3742set(handles.ny_patch1_title,'Visible','off')
[100]3743%set(handles.test_interp,'Visible','off')
[2]3744set(handles.get_gridpatch1,'Visible','off')
3745set(handles.grid_patch1,'Visible','off')
3746
[12]3747%------------------------------------------------------------------------
[2]3748function enable_civ2(handles,state)
[12]3749%------------------------------------------------------------------------
[2]3750if isequal(state,0)
3751    state='off';
3752end
3753if isequal(state,1)
3754    state='on';
3755end
3756if isequal(state,'on')
3757    set(handles.frame_civ2,'BackgroundColor',[1 1 0])
3758    set(handles.frame_para_civ2,'BackgroundColor',[1 1 0])
3759    set(handles.frame_grid_civ2,'BackgroundColor',[1 1 0])
3760    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
3761else
3762    set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
3763    set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
3764    set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
3765    set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
3766end
3767set(handles.ibx_civ2,'Visible',state)
3768set(handles.iby_civ2,'Visible',state)
3769set(handles.decimal,'Visible',state)
3770set(handles.deformation,'Visible',state)
3771set(handles.rho_civ2,'Visible',state)
3772set(handles.dx_civ2,'Visible',state)
3773set(handles.dy_civ2,'Visible',state)
3774set(handles.browse_gridciv2,'Visible',state)
3775set(handles.get_mask_civ2,'Visible',state)
3776set(handles.parameters,'Visible',state)
3777set(handles.grid,'Visible',state)
3778set(handles.parameters_text,'Visible',state)
3779set(handles.grid_text,'Visible',state)
3780set(handles.grid_civ2,'Visible',state)
3781set(handles.mask_civ2,'Visible',state)
3782set(handles.dx_civ2_title,'Visible',state)
3783set(handles.dy_civ2_title,'Visible',state)
3784set(handles.ibx_civ2_text,'Visible',state)
3785set(handles.rho_civ2_title,'Visible',state)
3786set(handles.ImaThreshold2,'Visible',state)
3787set(handles.ImaThreshold_title2,'Visible',state)
3788if isequal(state,'off')
3789    set(handles.MinIma2,'Visible','off')
3790    set(handles.MaxIma2,'Visible','off')
3791    set(handles.ImaThreshold2,'Value',0)
[112]3792    if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
[2]3793        set(handles.list_pair_civ2,'Visible','off')
3794        set(handles.subdir_civ2,'Visible','off')
3795        set(handles.subdir_civ2_text,'Visible','off')
[71]3796        set(handles.dt_unit_civ2,'Visible','off')
3797        set(handles.ref_i_civ2,'Visible','off')
3798        set(handles.i_ref_civ2_title,'Visible','off')
3799        set(handles.j_ref_civ2_title,'Visible','off')
3800        set(handles.ref_j_civ2,'Visible','off')
[2]3801    end
3802else
3803    set(handles.list_pair_civ2,'Visible','on')
3804    set(handles.subdir_civ2,'Visible','on')
3805    set(handles.subdir_civ2_text,'Visible','on')
[71]3806    set(handles.dt_unit_civ2,'Visible','on')
3807    set(handles.ref_i_civ2,'Visible','on')
3808    set(handles.i_ref_civ2_title,'Visible','on')
3809    set(handles.j_ref_civ2_title,'Visible','on')
3810    set(handles.ref_j_civ2,'Visible','on')
[2]3811end
[71]3812set(handles.rho_civ2_title,'Visible',state)
[2]3813
[12]3814%------------------------------------------------------------------------
[2]3815function enable_fix2(handles)
[12]3816%------------------------------------------------------------------------
[2]3817set(handles.frame_fix2,'BackgroundColor',[1 1 0])
3818set(handles.REMOVE2,'Visible','on')
3819set(handles.vec_Fmin2_2,'Visible','on')
3820set(handles.vec_F4,'Visible','on')
3821set(handles.vec_F3_2,'Visible','on')
3822set(handles.thresh_vec2C,'Visible','on')
3823set(handles.thresh_vec2C_text,'Visible','on')
3824set(handles.thresh_vel2,'Visible','on')
3825set(handles.thresh_vel2_text,'Visible','on')
3826set(handles.mask_fix2,'Visible','on')
3827set(handles.get_mask_fix2,'Visible','on')
3828set(handles.list_pair_civ2,'Visible','on')
3829set(handles.subdir_civ2,'Visible','on')
3830set(handles.subdir_civ2_text,'Visible','on')
3831set(handles.get_ref_fix2,'Visible','on')
3832set(handles.ref_fix2,'Visible','on')
3833set(handles.inf_sup2,'Visible','on')
3834set(handles.field_ref2,'Visible','on')
3835
[12]3836%------------------------------------------------------------------------
[2]3837function desable_fix2(handles)
[12]3838%------------------------------------------------------------------------
[2]3839set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
3840set(handles.REMOVE2,'Visible','off')
3841set(handles.vec_Fmin2_2,'Visible','off')
3842set(handles.vec_F4,'Visible','off')
3843set(handles.vec_F3_2,'Visible','off')
3844set(handles.thresh_vec2C,'Visible','off')
3845set(handles.thresh_vec2C_text,'Visible','off')
3846set(handles.thresh_vel2,'Visible','off')
3847set(handles.thresh_vel2_text,'Visible','off')
3848set(handles.mask_fix2,'Visible','off')
3849set(handles.get_mask_fix2,'Visible','off')
3850set(handles.get_ref_fix2,'Visible','off')
3851set(handles.ref_fix2,'Visible','off')
3852set(handles.inf_sup2,'Visible','off')
3853set(handles.field_ref2,'Visible','off')
[112]3854if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
[2]3855    set(handles.list_pair_civ2,'Visible','off')
3856    set(handles.subdir_civ2,'Visible','off')
3857    set(handles.subdir_civ2_text,'Visible','off')
3858end
3859
[12]3860%------------------------------------------------------------------------
[2]3861function enable_patch2(handles)
[12]3862%------------------------------------------------------------------------
[2]3863set(handles.frame_patch2,'BackgroundColor',[1 1 0])
[119]3864set(handles.rho_patch2,'Visible','on')
[2]3865set(handles.rho_text2,'Visible','on')
3866set(handles.thresh_patch2,'Visible','on')
3867set(handles.thresh_text2,'Visible','on')
3868set(handles.subdomain_patch2,'Visible','on')
3869set(handles.subdomain_text2,'Visible','on')
3870set(handles.nx_patch2,'Visible','on')
3871set(handles.ny_patch2,'Visible','on')
3872set(handles.nx_patch2_title,'Visible','on')
3873set(handles.ny_patch2_title,'Visible','on')
3874set(handles.get_gridpatch2,'Visible','on')
3875set(handles.grid_patch2,'Visible','on')
3876set(handles.list_pair_civ2,'Visible','on')
3877set(handles.subdir_civ2,'Visible','on')
3878set(handles.subdir_civ2_text,'Visible','on')
3879
[12]3880%------------------------------------------------------------------------
[2]3881function desable_patch2(handles)
[12]3882%------------------------------------------------------------------------
[2]3883set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
3884set(handles.rho_patch2,'Visible','off')
3885set(handles.rho_text2,'Visible','off')
3886set(handles.thresh_patch2,'Visible','off')
3887set(handles.thresh_text2,'Visible','off')
3888set(handles.subdomain_patch2,'Visible','off')
3889set(handles.subdomain_text2,'Visible','off')
3890set(handles.nx_patch2,'Visible','off')
3891set(handles.ny_patch2,'Visible','off')
3892set(handles.nx_patch2_title,'Visible','off')
3893set(handles.ny_patch2_title,'Visible','off')
3894set(handles.get_gridpatch2,'Visible','off')
3895set(handles.grid_patch2,'Visible','off')
[112]3896if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0)
[2]3897    set(handles.list_pair_civ2,'Visible','off')
3898    set(handles.subdir_civ2,'Visible','off')
3899    set(handles.subdir_civ2_text,'Visible','off')
3900end
3901
[12]3902%------------------------------------------------------------------------
[2]3903function enable_pair1(handles,state)
[12]3904%------------------------------------------------------------------------
[2]3905set(handles.subdir_civ1,'Visible',state)
3906set(handles.list_subdir_civ1,'Visible',state)
3907set(handles.SUBDIR_CIV1_txt,'Visible',state)
3908set(handles.frame_subdirciv1,'Visible',state)
3909set(handles.list_pair_civ1,'Visible',state)
3910set(handles.PAIR_txt,'Visible',state)
[71]3911%set(handles.dt_unit,'Visible',state)
[2]3912set(handles.PAIR_frame,'Visible',state)
3913
[12]3914%------------------------------------------------------------------------
3915% --- Read the parameters for civ1 on the interface
[2]3916function par=read_param_civ1(handles,file_ima)
[12]3917%------------------------------------------------------------------------
[127]3918ibx_val=str2double(get(handles.ibx,'String'));
[2]3919par.ibx=num2str(ibx_val);
[127]3920iby_val=str2double(get(handles.iby,'String'));
[2]3921par.iby=num2str(iby_val);
3922isx=get(handles.isx,'String');
[127]3923if isnan(str2double(isx)), isx='41'; set(handles.isx,'String','41'), end; %default
3924if str2double(isx)<ibx_val+8,isx=num2str(ibx_val+8); set(handles.isx,'String',num2str(ibx_val+8)); end
[2]3925isy=get(handles.isy,'String');
[127]3926if isnan(str2double(isy)), isy='41'; set(handles.isy,'String','41'), end;%default
3927if str2double(isy)<iby_val+8,isy=num2str(iby_val+8); set(handles.isy,'String',num2str(iby_val+8)); end
[2]3928par.isx=get(handles.isx,'String');
3929par.isy=get(handles.isy,'String');
3930par.shiftx=get(handles.shiftx,'String');
3931par.shifty=get(handles.shifty,'String');
[127]3932if isnan(str2double(par.isx))
[112]3933    par.isx='41';%default
3934    set(handles.isx,'String','41');
[2]3935end
[127]3936if isnan(str2double(par.isy))
[112]3937    par.isy='41'; %default
3938    set(handles.isy,'String','41');
[12]3939end
[127]3940if isnan(str2double(par.shiftx))
[112]3941    par.shiftx='0';%default
3942    set(handles.shiftx,'String','0');
3943end
[127]3944if isnan(str2double(par.shifty))
[112]3945    par.shifty='0'; %default
3946    set(handles.shifty,'String','0');
[12]3947end
[112]3948par.rho=get(handles.rho,'String');
3949par.dx=get(handles.dx_civ1,'String');
3950par.dy=get(handles.dy_civ1,'String');
[127]3951if isnan(str2double(par.dx))
[112]3952    if isempty(get(handles.grid_civ1,'String'));
3953        par.dx='0'; %just read by civ program, not used
3954    else
[12]3955        par.dx='20';%default
3956        set(handles.dx_civ1,'String','20');
[112]3957    end
3958end
[127]3959if isnan(str2double(par.dy))
[112]3960    if isempty(get(handles.grid_civ1,'String'));
3961        par.dy='0';%just read by civ program, not used
3962    else
[12]3963        par.dy='20';%default
3964        set(handles.dy_civ1_title,'String','20');
[112]3965    end
3966end
3967par.pxcmx='1'; %velocities are expressed in pixel dispalcement
3968par.pxcmy='1';
[150]3969if exist('file_ima','var')
[112]3970A=imread(file_ima);%read the first image to get the size
3971sizim=size(A);
3972par.npx=num2str(sizim(2));
3973par.npy=num2str(sizim(1));
[150]3974end
[127]3975%time=get(handles.RootName,'UserData'); %get the set of times
[112]3976par.gridname=get(handles.grid_civ1,'String');
3977par.gridflag='y';
[127]3978if strcmp(par.gridname,'')|| isempty(par.gridname)
[112]3979    par.gridname='nogrid';
3980    par.gridflag='n';
3981end
[12]3982
3983%------------------------------------------------------------------------
[2]3984function par=read_param_civ2(handles,file_ima)
[12]3985%------------------------------------------------------------------------
3986par.ibx=get(handles.ibx_civ2,'String');
3987par.iby=get(handles.iby_civ2,'String');
3988par.rho=get(handles.rho_civ2,'String');
3989par.decimal=int2str(get(handles.decimal,'Value'));
3990par.deformation=int2str(get(handles.deformation,'Value'));
3991par.dx=get(handles.dx_civ2,'String');
3992par.dy=get(handles.dy_civ2,'String');
[127]3993if isnan(str2double(par.dx))
[112]3994    if isempty(get(handles.grid_civ2,'String'));
3995        par.dx='0'; %just read by civ program, not used
3996    else
[12]3997        par.dx='20';%default
3998        set(handles.dx_civ2,'String','20');
[112]3999    end
4000end
[127]4001if isnan(str2double(par.dy))
[112]4002    if isempty(get(handles.grid_civ2,'String'));
4003        par.dy='0';%just read by civ program, not used
4004    else
[12]4005        par.dy='20';%default
4006        set(handles.dy_civ2,'String','20');
[112]4007    end
4008end
4009par.pxcmx='1';
4010par.pxcmy='1';
[12]4011A=imread(file_ima);%read the first image to get the size
4012sizim=size(A);
4013par.npx=num2str(sizim(2));
4014par.npy=num2str(sizim(1));
[127]4015%time=get(handles.RootName,'UserData'); %get the set of times
[12]4016par.gridname=get(handles.grid_civ2,'String');
4017par.gridflag='y';
[127]4018if strcmp(par.gridname,'')|| isempty(par.gridname)
[12]4019    par.gridname='nogrid';
4020    par.gridflag='n';
4021end
[2]4022
[12]4023%------------------------------------------------------------------------
4024% --- CIV1  CIV1  CIV1 CIV1
[94]4025function cmd_CIV1=CIV1_CMD(filename,namelog,par,handles,sparam)
[12]4026%------------------------------------------------------------------------
[2]4027%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4028
4029%changes : filename_cmx -> filename ( no extension )
4030
[112]4031if isequal(par.Dt,'0')
4032    par.Dt='1' ;%case of 'displacement' mode
4033end
4034%
[12]4035%     textcmx={'##############   CMX file';...
4036%     ['FirstImage ' par.filename_ima_a];...
4037%     ['LastImage  ' par.filename_ima_b];...
4038%     'XX' ;...
4039%     ['Mask ' par.maskflag] ;...
4040%     ['MaskName ' par.maskname];...
4041%     ['ImageSize ' par.npx ' ' par.npy];...   %VERIFIER CAS GENERAL ?
4042%     ['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
4043%     ['SearchBoxeSize ' par.isx ' ' par.isy];...
4044%     ['RO ' par.rho];...
4045%     ['GridSpacing ' par.dx ' ' par.dy];...
4046%     'XX 1.0';...
4047%     ['Dt_TO ' par.Dt ' ' par.T0];...
4048%     ['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
4049%     'XX 1';...
4050%     ['ShiftXY ' par.shiftx ' '  par.shifty];...
4051%     ['Grid ' par.gridflag];...
4052%     ['GridName ' par.gridname] ;...
4053%     'XX 85';...
4054%     'XX 1.0';...
4055%     'XX 1.0';...
4056%     'Hart 1';...
4057%     'DecimalShift 0';...
4058%     'Deformation 0';...
4059%     'CorrelationMin 0';...
4060%     'IntensityMin 0';...
4061%     'SeuilImage n';...
4062%     'SeuilImageValues 0 4096';...
4063%     ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
4064%     'ImageUsedBefore null null'};
[112]4065%
[12]4066%             textout=char(textcmx);
[90]4067par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
[94]4068par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');
4069fid=fopen([filename '.cmx'],'w');
[12]4070fprintf(fid,['##############   CMX file' '\n' ]);
[112]4071fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4072fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4073fprintf(fid,  ['XX' '\n' ]);
4074fprintf(fid,  ['Mask ' par.maskflag '\n' ]);
4075fprintf(fid,  ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);
4076fprintf(fid,   ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4077fprintf(fid,   ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
4078fprintf(fid,   ['SearchBoxeSize ' par.isx ' ' par.isy '\n' ]);
4079fprintf(fid,   ['RO ' par.rho '\n' ]);
4080fprintf(fid,   ['GridSpacing ' par.dx ' ' par.dy '\n' ]);
4081fprintf(fid,   ['XX 1.0' '\n' ]);
4082fprintf(fid,   ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
4083fprintf(fid,  ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
4084fprintf(fid,  ['XX 1' '\n' ]);
4085fprintf(fid,   ['ShiftXY ' par.shiftx ' '  par.shifty '\n' ]);
4086fprintf(fid,  ['Grid ' par.gridflag '\n' ]);
4087fprintf(fid,   ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n' ]);
4088fprintf(fid,   ['XX 85' '\n' ]);
4089fprintf(fid,   ['XX 1.0' '\n' ]);
4090fprintf(fid,   ['XX 1.0' '\n' ]);
4091fprintf(fid,   ['Hart 1' '\n' ]);
4092fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
4093fprintf(fid,   ['Deformation 0' '\n' ]);
4094fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4095fprintf(fid,   ['IntensityMin 0' '\n' ]);
4096fprintf(fid,  ['SeuilImage n' '\n' ]);
4097fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
4098fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
4099fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
[12]4100fclose(fid);
[112]4101
[120]4102cmd_CIV1=[sparam.Civ1Bin ' -f ' filename '.cmx >' filename '.log' ]; % redirect standard output to the log file
[90]4103cmd_CIV1=regexprep(cmd_CIV1,'\\','\\\\');
4104namelog=regexprep(namelog,'\\','\\\\');
4105
[12]4106if(isunix)
4107    [Rootbat,Filebat,extbat]=fileparts(namelog);
4108    ncName=fullfile(Rootbat,[ Filebat '.nc']);
[67]4109    cmd_CIV1=[cmd_CIV1 '\n' 'mv ' namelog  ' ' regexprep(namelog,'\.log','') '.civ1.log' '\n' 'chmod g+w ' ncName];
[12]4110else
[67]4111    cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y ' namelog ' ' regexprep(namelog,'\.log','') '.civ1.log'];
[12]4112end
[2]4113
[12]4114%------------------------------------------------------------------------
4115% --- CIV1  Unified
[94]4116function xml_civ1_parameters=CIV1_CMD_Unified(filename,namelog,par)
[12]4117%------------------------------------------------------------------------
[2]4118%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[73]4119%global CivBin%name of the executable for civ1 calculation
[2]4120
[112]4121civ1.image1=par.filename_ima_a;
4122civ1.image2=par.filename_ima_b;
4123civ1.imageSize_X=par.npx;
4124civ1.imageSize_Y=par.npy;
4125civ1.outputFileName=[filename '.nc'];
4126civ1.correlationBoxesSize_X=par.ibx;
4127civ1.correlationBoxesSize_Y=par.iby;
4128civ1.searchBoxesSize_X=par.isx;
4129civ1.searchBoxesSize_Y=par.isy;
4130civ1.globalShift_X=par.shiftx;
4131civ1.globalShift_Y=par.shifty;
4132civ1.ro=par.rho;
4133civ1.hart='y';
4134if isequal(par.gridflag,'y')
4135    civ1.grid=par.gridname;
4136else
4137    civ1.grid='n';
4138    civ1.gridSpacing_X=par.dx;
4139    civ1.gridSpacing_Y=par.dy;
4140end
4141if isequal(par.maskflag,'y')
4142    civ1.mask=par.maskname;
4143end
4144civ1.dt=par.Dt;
4145civ1.unit='pixel';
4146civ1.absolut_time_T0=par.T0;
4147civ1.pixcmx=par.pxcmx;
4148civ1.pixcmy=par.pxcmy;
4149civ1.convectFlow='n';
[12]4150
[112]4151xml_civ1_parameters=civ1;
4152
[12]4153%------------------------------------------------------------------------
4154% --- CIV2  Unified
[94]4155function civ2=CIV2_CMD_Unified(filename,namelog,par)
[12]4156%------------------------------------------------------------------------
[2]4157%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[73]4158%global CivBin%name of the executable for civ1 calculation
[2]4159
4160civ2.image1=par.filename_ima_a;
4161civ2.image2=par.filename_ima_b;
[112]4162civ2.imageSize_X=par.npx;
[2]4163civ2.imageSize_Y=par.npy;
4164civ2.inputFileName=[par.filename_nc1 '.nc'];
4165civ2.outputFileName=[filename '.nc'];
4166civ2.correlationBoxesSize_X=par.ibx;
4167civ2.correlationBoxesSize_Y=par.iby;
4168civ2.ro=par.rho;
4169%civ2.decimalShift=par.decimal;
4170%civ2.deformation=par.deformation;
4171if isequal(par.decimal,'1')
4172    civ2.decimalShift='y';
4173else
4174    civ2.decimalShift='n';
4175end
4176if isequal(par.deformation,'1')
4177    civ2.deformation='y';
4178else
4179    civ2.deformation='n';
4180end
4181if isequal(par.gridflag,'y')
4182    civ2.grid=par.gridname;
4183else
4184    civ2.grid='n';
4185    civ2.gridSpacing_X=par.dx;
4186    civ2.gridSpacing_Y=par.dy;
4187end
4188civ2.gridSpacing_X='10';
4189civ2.gridSpacing_Y='10';%NOTE: faut mettre gridSpacing pourque ca tourne, meme si c'est la grille qui est utilisee
4190if isequal(par.maskflag,'y')
4191    civ2.mask=par.maskname;
4192else
4193    civ2.mask='n';
4194end
4195civ2.dt=par.Dt;
4196civ2.unit='pixel';
4197civ2.absolut_time_T0=par.T0;
4198civ2.pixcmx=par.pxcmx;
4199civ2.pixcmy=par.pxcmy;
4200civ2.convectFlow='n';
4201civ2.pixcmx=par.pxcmx;
4202civ2.pixcmy=par.pxcmy;
4203civ2.convectFlow='n';
4204
[12]4205%------------------------------------------------------------------------
4206% --- CIV2  CIV2  CIV2 CIV2
[134]4207function cmd_CIV2=CIV2_CMD(filename,namelog,par,sparam)
[12]4208%------------------------------------------------------------------------
[2]4209%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[67]4210% global civ2Bin sge%name of the executable for civ1 calculation
[112]4211if isequal(par.Dt,'0')
4212    par.Dt='1' ;%case of 'displacement' mode
4213end
[94]4214% textcmx=['##############   CMX file'  '\n'...
4215% ['FirstImage ' par.filename_ima_a]  '\n'...
4216% ['LastImage  ' par.filename_ima_b]  '\n'...
4217% 'XX'   '\n'...
4218% ['Mask ' par.maskflag]  '\n'...
4219% ['MaskName ' par.maskname]  '\n'...
[112]4220% ['ImageSize ' par.npx ' ' par.npy]  '\n'...
[94]4221% ['CorrelationBoxesSize ' par.ibx ' ' par.iby]  '\n'...
4222% ['SearchBoxeSize ' par.ibx ' ' par.iby]  '\n'...
4223% ['RO ' par.rho]  '\n'...
4224% ['GridSpacing ' par.dx ' ' par.dy]  '\n'...
4225% 'XX 1.0'  '\n'...
4226% ['Dt_TO ' par.Dt ' ' par.T0]  '\n'...
4227% ['PixCmXY ' par.pxcmx ' ' par.pxcmy]  '\n'...
4228% 'XX 1'  '\n'...
4229% ['ShiftXY 0 0']  '\n'...
4230% ['Grid ' par.gridflag]  '\n'...
4231% ['GridName ' par.gridname]  '\n'...
4232% 'XX 85'  '\n'...
4233% 'XX 1.0'  '\n'...
4234% 'XX 1.0'  '\n'...
4235% 'Hart 1'  '\n'...
4236% ['DecimalShift ' par.decimal]  '\n'...
4237% ['Deformation ' par.deformation]  '\n'...
4238% 'CorrelationMin 0'  '\n'...
4239% 'IntensityMin 0'  '\n'...
4240% 'SeuilImage n'  '\n'...
4241% 'SeuilImageValues 0 4096'  '\n'...
4242% ['ImageToUse ' par.term_a ' ' par.term_b]  '\n'... % VERIFIER ?
4243% ['ImageUsedBefore ' par.filename_nc1]];
4244% textout=char(textcmx);
4245% fid=fopen([filename_cmx '2'],'w');
[112]4246% fprintf(fid,textout);
[94]4247% fclose(fid)
[2]4248
[94]4249par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
4250par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');% bug : .png appears two times ?
[134]4251fid=fopen([filename '.cmx2'],'w');
[94]4252fprintf(fid,['##############   CMX file' '\n' ]);
4253fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4254fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4255fprintf(fid,  ['XX' '\n' ]);
4256fprintf(fid, ['Mask ' par.maskflag '\n' ]);
4257fprintf(fid, ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);% for windows compatibility
4258fprintf(fid, ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4259fprintf(fid, ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
4260fprintf(fid, ['SearchBoxeSize ' par.ibx ' ' par.iby '\n']);
4261fprintf(fid, ['RO ' par.rho '\n']);
4262fprintf(fid, ['GridSpacing ' par.dx ' ' par.dy '\n']);
4263fprintf(fid, ['XX 1.0' '\n' ]);
4264fprintf(fid, ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
4265fprintf(fid, ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
4266fprintf(fid, ['XX 1' '\n' ]);
[122]4267fprintf(fid, 'ShiftXY 0 0\n');
[94]4268fprintf(fid, ['Grid ' par.gridflag '\n' ]);
4269fprintf(fid, ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n']);
4270fprintf(fid, ['XX 85' '\n' ]);
4271fprintf(fid, ['XX 1.0' '\n' ]);
4272fprintf(fid, ['XX 1.0' '\n' ]);
4273fprintf(fid, ['Hart 1' '\n' ]);
4274fprintf(fid, ['DecimalShift ' par.decimal '\n']);
4275fprintf(fid, ['Deformation ' par.deformation '\n']);
4276fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4277fprintf(fid,   ['IntensityMin 0' '\n' ]);
4278fprintf(fid,  ['SeuilImage n' '\n' ]);
4279fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
4280fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
4281fprintf(fid, ['ImageUsedBefore ' regexprep(par.filename_nc1,'\\','\\\\') '\n']);
4282fclose(fid);
4283
[134]4284cmd_CIV2=[sparam.Civ2Bin ' -f ' filename  '.cmx >' filename '.log' ]; % redirect standard output to the log file
[94]4285cmd_CIV2=regexprep(cmd_CIV2,'\\','\\\\');
[134]4286namelog=regexprep(namelog,'\\','\\\\');
[94]4287
[134]4288if(isunix)
4289    [Rootbat,Filebat,extbat]=fileparts(namelog);
4290    ncName=fullfile(Rootbat,[ Filebat '.nc']);
4291    cmd_CIV2=[cmd_CIV2 '\n' 'mv ' namelog  ' ' regexprep(namelog,'\.log','') '.civ2.log' '\n' 'chmod g+w ' ncName];
4292else
4293    cmd_CIV2=[cmd_CIV2 '\n' 'copy /Y ' namelog ' ' regexprep(namelog,'\.log','') '.civ2.log'];
4294end
4295
4296
4297
[12]4298%------------------------------------------------------------------------
[2]4299% --- Executes on button press in HELP.
4300function HELP_Callback(hObject, eventdata, handles)
[12]4301%------------------------------------------------------------------------
[2]4302path_to_uvmat=which ('uvmat');% check the path of uvmat
4303pathelp=fileparts(path_to_uvmat);
[85]4304helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
[36]4305if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
[2]4306else
[36]4307    addpath (fullfile(pathelp,'uvmat_doc'))
[112]4308    web([helpfile '#civ'])
[2]4309end
4310
[12]4311%------------------------------------------------------------------------
[2]4312%--read images and convert them to the uint16 format used for PIV
[45]4313function A=read_image(filename,type_ima,num,movieobject)
[12]4314%------------------------------------------------------------------------
[2]4315%num is the view number needed for an avi movie
[45]4316switch type_ima
4317    case 'movie'
4318        A=read(movieobject,num);
4319    case 'avi'
[112]4320        mov=aviread(filename,num);
4321        A=frame2im(mov(1));
[45]4322    case 'multimage'
4323        A=imread(filename,num);
[112]4324    case 'image'
[45]4325        A=imread(filename);
4326end
4327siz=size(A);
4328if length(siz)==3;%color images
[2]4329    A=sum(double(A),3);
4330    A=uint16(A);
4331end
4332
[12]4333%------------------------------------------------------------------------
[2]4334function ref_i_Callback(hObject, eventdata, handles)
[12]4335%------------------------------------------------------------------------
[2]4336mode_list=get(handles.mode,'String');
4337mode_value=get(handles.mode,'Value');
4338mode=mode_list{mode_value};
[45]4339find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
[12]4340if isequal(mode,'series(Di)') || ...% we do patch2 only
[112]4341        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
[2]4342    find_netcpair_civ2(hObject, eventdata, handles);
4343end
4344
[12]4345%------------------------------------------------------------------------
[2]4346function ref_j_Callback(hObject, eventdata, handles)
[12]4347%------------------------------------------------------------------------
[2]4348mode_list=get(handles.mode,'String');
4349mode_value=get(handles.mode,'Value');
4350mode=mode_list{mode_value};
[112]4351if isequal(get(handles.CIV1,'Value'),0)|| isequal(mode,'series(Dj)')
[2]4352    find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4353end
[45]4354if isequal(mode,'series(Dj)') || ...
[112]4355        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
[2]4356    find_netcpair_civ2(hObject, eventdata, handles);
4357end
[12]4358
4359%------------------------------------------------------------------------
[71]4360function ref_i_civ2_Callback(hObject, eventdata, handles)
4361%------------------------------------------------------------------------
4362mode_list=get(handles.mode,'String');
4363mode_value=get(handles.mode,'Value');
4364mode=mode_list{mode_value};
4365find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4366
4367%------------------------------------------------------------------------
4368function ref_j_civ2_Callback(hObject, eventdata, handles)
4369%------------------------------------------------------------------------
4370mode_list=get(handles.mode,'String');
4371mode_value=get(handles.mode,'Value');
4372mode=mode_list{mode_value};
[112]4373if  isequal(mode,'series(Dj)')
[71]4374    find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4375end
4376
4377%------------------------------------------------------------------------
[2]4378% --- Executes on button press in compare.
4379function compare_Callback(hObject, eventdata, handles)
[12]4380%------------------------------------------------------------------------
[2]4381test=get(handles.compare,'Value');
[112]4382if test==2 || test==3
[71]4383    filebase=get(handles.RootName,'String');
[2]4384    browse=get(handles.browse_root,'Userdata');
4385    browse.nom_type_ima1=browse.nom_type_ima;
4386    set(handles.browse_root,'UserData',browse);
4387    set(handles.sub_txt,'Visible','on')
[112]4388    set(handles.RootName_1,'Visible','On');%mkes the second file input window visible
[2]4389    mode_store=get(handles.mode,'String');%get the present 'mode'
[112]4390    set(handles.compare,'UserData',mode_store);%store the mode display
[2]4391    set(handles.mode,'Visible','off')
4392    if test==2
[112]4393        set(handles.mode,'Visible','off')
[2]4394    else
4395        set(handles.mode,'Visible','on')
4396    end
4397   
4398    % open an image file with the browser
4399    ind_opening=1;%default
4400    browse.incr_pair=[0 0]; %default
[71]4401    oldfile=get(handles.RootName,'String');
[2]4402    menu={'*.xml;*.avi;*.AVI;*.nc','(*.xml,*.avi,*.nc)'; ...
[112]4403        '*.xml', '.xml files';'*.avi;*.AVI', '.avi files';'*.nc', '.nc files';...
4404        '*.*', 'All Files (*.*)'};
[2]4405    [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
[112]4406    fileinput=[PathName FileName];%complete file name
[2]4407    sizf=size(fileinput);
4408    if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
4409    [path,name,ext]=fileparts(fileinput);
4410    [path1]=fileparts(filebase);
4411    if ~strcmp(path1,path)
[112]4412        msgbox_uvmat('ERROR','The two  input image series must be in the same directory')
[2]4413        return
4414    end
[71]4415    set(handles.RootName_1,'String',name);
[2]4416    [RootPath,RootFile,field_count,str2,str_a,str_b,xx,nom_type,subdir]=name2display(name);
4417    browse=get(handles.browse_root,'UserData');
4418    browse.nom_type_ima_1=nom_type;
[112]4419    set(handles.browse_root,'UserData',browse)
[2]4420   
4421    %check image extension
[71]4422    if ~strcmp(ext,get(handles.ImaExt,'String'))
[2]4423        msgbox_uvmat('ERROR','The two  input image series must have the same extenion name')
4424        return
4425    end
4426   
4427    %check image size
4428    A=imread(fileinput);
[71]4429    npxy=get(handles.ImaExt,'UserData');
[2]4430    if ~isequal(npxy(1),size(A,1))|| ~isequal(npxy(2),size(A,2))
4431        msgbox_uvmat('ERROR','The two input image series must have the same size')
4432        return
4433    end
4434else
4435    set(handles.mode,'Visible','on')
[71]4436    set(handles.RootName_1,'Visible','Off');
[2]4437    set(handles.sub_txt,'Visible','off')
[71]4438    set(handles.RootName_1,'String',[]);
[2]4439    mode_store=get(handles.compare,'UserData');
4440    set(handles.mode,'String',mode_store)
4441    set(handles.test_stereo1,'Value',0)
4442    set(handles.test_stereo2,'Value',0)
4443end
4444mode_Callback(hObject, eventdata, handles)
4445
[12]4446%------------------------------------------------------------------------
[2]4447% --- Executes on button press in get_ref_fix1.
4448function get_ref_fix1_Callback(hObject, eventdata, handles)
[12]4449%------------------------------------------------------------------------
[71]4450filebase=get(handles.RootName,'String');
[2]4451[FileName, PathName, filterindex] = uigetfile( ...
[112]4452    {'*.nc', ' (*.nc)';
4453    '*.nc',  'netcdf files '; ...
4454    '*.*', 'All Files (*.*)'}, ...
4455    'Pick a file',filebase);
4456
[2]4457fileinput=[PathName FileName];
4458sizf=size(fileinput);
[122]4459if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4460[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4461ref.filebase=fullfile(Path,File);
4462ref.num_a=stra2num(str_a);
4463ref.num_b=stra2num(str_b);
[89]4464ref.num1=str2double(field_count);
4465ref.num2=str2double(str2);
[2]4466browse=[];%initialisation
4467if ~isequal(ref.ext,'.nc')
4468    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4469    return
4470end
4471set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
4472set(handles.ref_fix1,'UserData',ref)
4473menu_field{1}='civ1';
4474Data=nc2struct(fileinput,[]);
[45]4475if isfield(Data,'patch') && isequal(Data.patch,1)
[2]4476    menu_field{2}='filter1';
4477end
[45]4478if isfield(Data,'civ2') && isequal(Data.civ2,1)
[2]4479    menu_field{3}='civ2';
4480end
[45]4481if isfield(Data,'patch2') && isequal(Data.patch2,1)
[2]4482    menu_field{4}='filter2';
4483end
4484set(handles.field_ref1,'String',menu_field);
4485set(handles.field_ref1,'Value',length(menu_field));
4486set(handles.inf_sup1,'Value',2);
4487set(handles.thresh_vel,'String','1');%default threshold
4488set(handles.ref_fix1,'Enable','on')
[12]4489
4490%------------------------------------------------------------------------
[2]4491% --- Executes on button press in get_ref_fix2.
4492function get_ref_fix2_Callback(hObject, eventdata, handles)
[12]4493%------------------------------------------------------------------------
[2]4494if isequal(get(handles.get_ref_fix2,'Value'),1)
[71]4495    filebase=get(handles.RootName,'String');
[2]4496    [FileName, PathName, filterindex] = uigetfile( ...
[112]4497        {'*.nc', ' (*.nc)';
4498        '*.nc',  'netcdf files '; ...
4499        '*.*', 'All Files (*.*)'}, ...
4500        'Pick a file',filebase);
[2]4501    fileinput=[PathName FileName];
4502    sizf=size(fileinput);
[45]4503    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4504    [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4505    ref.filebase=fullfile(Path,File);
4506    ref.num_a=stra2num(str_a);
4507    ref.num_b=stra2num(str_b);
4508    ref.num1=str2num(field_count);
4509    ref.num2=str2num(str2);
4510    browse=[];%initialisation
4511    if ~isequal(ref.ext,'.nc')
4512        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4513        return
4514    end
4515    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
[112]4516    set(handles.ref_fix2,'UserData',ref)
[2]4517    menu_field{1}='civ1';
4518    Data=nc2struct(fileinput,[]);
4519    if isfield(Data,'patch') & isequal(Data.patch,1)
4520        menu_field{2}='filter1';
4521    end
4522    if isfield(Data,'civ2') & isequal(Data.civ2,1)
4523        menu_field{3}='civ2';
4524    end
4525    if isfield(Data,'patch2') & isequal(Data.patch2,1)
4526        menu_field{4}='filter2';
4527    end
4528    set(handles.field_ref2,'String',menu_field);
4529    set(handles.field_ref2,'Value',length(menu_field));
4530    set(handles.inf_sup2,'Value',2);
4531    set(handles.thresh_vel2,'String','1');%default threshold
4532    set(handles.ref_fix2,'Enable','on')
4533    set(handles.ref_fix2,'Visible','on')
4534    set(handles.field_ref2,'Visible','on')
4535else
4536    set(handles.ref_fix2,'Visible','off')
4537    set(handles.field_ref2,'Visible','off')
4538end
4539
[12]4540%------------------------------------------------------------------------
[2]4541function ref_fix1_Callback(hObject, eventdata, handles)
[12]4542%------------------------------------------------------------------------
4543set(handles.inf_sup1,'Value',1);
4544set(handles.field_ref1,'Value',1)
4545set(handles.field_ref1,'String',{' '})
4546set(handles.ref_fix1,'UserData',[]);
4547set(handles.ref_fix1,'String','');
4548set(handles.thresh_vel1,'String','0');
[112]4549
[12]4550%------------------------------------------------------------------------
[2]4551function ref_fix2_Callback(hObject, eventdata, handles)
[12]4552%------------------------------------------------------------------------
4553set(handles.inf_sup2,'Value',1);
4554set(handles.field_ref2,'Value',1)
4555set(handles.field_ref2,'String',{' '})
4556set(handles.ref_fix2,'UserData',[]);
4557set(handles.ref_fix2,'String','');
4558set(handles.thresh_vel2,'String','0');
[2]4559
[12]4560%------------------------------------------------------------------------
[2]4561% --- Executes on button press in test_stereo1.
4562function test_stereo1_Callback(hObject, eventdata, handles)
[12]4563%------------------------------------------------------------------------
[2]4564if isequal(get(handles.test_stereo1,'Value'),0)
4565    set(handles.subdomain_patch1,'Visible','on')
4566    set(handles.rho_patch1,'Visible','on')
4567else
4568    set(handles.subdomain_patch1,'Visible','off')
4569    set(handles.rho_patch1,'Visible','off')
4570end
4571
[12]4572%------------------------------------------------------------------------
[2]4573% --- Executes on button press in test_stereo2.
4574function test_stereo2_Callback(hObject, eventdata, handles)
[12]4575%------------------------------------------------------------------------
[2]4576if isequal(get(handles.test_stereo2,'Value'),0)
4577    set(handles.subdomain_patch2,'Visible','on')
4578    set(handles.rho_patch2,'Visible','on')
4579else
4580    set(handles.subdomain_patch2,'Visible','off')
4581    set(handles.rho_patch2,'Visible','off')
4582end
4583
[12]4584%------------------------------------------------------------------------
[2]4585% --- Executes on button press in ImaThreshold.
4586function ImaThreshold_Callback(hObject, eventdata, handles)
[12]4587%------------------------------------------------------------------------
[2]4588if isequal(get(handles.ImaThreshold,'Value'),1)
4589    set(handles.MinIma,'Visible','on')
4590    set(handles.MaxIma,'Visible','on')
4591else
4592    set(handles.MinIma,'Visible','off')
4593    set(handles.MaxIma,'Visible','off')
4594end
4595
[12]4596%------------------------------------------------------------------------
[2]4597% --- Executes on button press in ImaThreshold2.
4598function ImaThreshold2_Callback(hObject, eventdata, handles)
[12]4599%------------------------------------------------------------------------
[2]4600if isequal(get(handles.ImaThreshold2,'Value'),1)
4601    set(handles.MinIma2,'Visible','on')
4602    set(handles.MaxIma2,'Visible','on')
4603else
4604    set(handles.MinIma2,'Visible','off')
4605    set(handles.MaxIma2,'Visible','off')
4606end
4607
[71]4608
[150]4609% --- Executes on button press in TestCiv1.
4610function TestCiv1_Callback(hObject, eventdata, handles)
4611test_civ1=get(handles.TestCiv1,'Value');
4612if test_civ1
4613[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]=...
4614    set_civ_filenames(handles,[1 0 0 0 0 0]);
4615Data.ListVarName={'ny','nx','A'};
4616Data.VarDimName={'ny','nx',{'ny','nx'}};
4617Data.A=imread(filecell.ima1.civ1{1});
4618Data.ny=[size(Data.A,1) 1];
4619Data.nx=[1 size(Data.A,2)];
4620hh=view_field(Data);
4621ViewData=get(hh,'UserData');
4622ViewData.axes3.B=imread(filecell.ima2.civ1{1});
4623set(hh,'UserData',ViewData)
4624end
[71]4625
4626
[150]4627
4628
4629
4630
Note: See TracBrowser for help on using the repository browser.