source: trunk/src/civ.m @ 272

Last change on this file since 272 was 272, checked in by gostiaux, 12 years ago

functions read_param_... and cmd_... for civ1, civ2, fix1, fix2 generalized.

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