source: trunk/src/civ.m @ 182

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

introduction of a button OK to close the status GUI in civ, bug repair for volume images .vol (uvmat and set_object)

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