source: trunk/src/civ.m @ 248

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

various modifications

File size: 198.3 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
[220]24% Last Modified by GUIDE v2.5 11-Mar-2011 08:21:21
[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);
[246]64set(hObject,'WindowButtonUpFcn',{'mouse_up_GUI',handles}) %set mouse action (zoom on uicontrols)
[2]65%default initial parameters
66filebase=''; % root file name ('filebase'.civ)
67ext=[];
[238]68set(handles.CivAll,'String',{'CivX';'CivAll';'CivUvmat'})
[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;
339        set(handles.CivAll,'Value',3)
340    end
341    if ~isempty(Data.absolut_time_T0)%test for civx files
342        set(handles.CivAll,'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]449%ext_ima=get(handles.ImaExt,'String');
450ext_ima='';%default
[2]451nom_type_ima=[];%default
452field_count=1;%default
453nom_type_nc=[];
454time=[];
[71]455TimeUnit='frame'; %default
456CoordUnit='px';%default
[2]457pxcmx_search=[];%default
458pxcmy_search=[];%default
[71]459filebase=get(handles.RootName,'String');
[128]460ext_imadoc=get(handles.ImaDoc,'String');
[135]461browse=get(handles.browse_root,'UserData');%default
[122]462if isfield(browse,'nom_type_ima')
463    nom_type_ima=browse.nom_type_ima;% get an image nomenclature type already determined by an input image name
[133]464end
465if isfield(browse,'ext_ima')
[122]466    ext_ima=browse.ext_ima;
[2]467end
[122]468if isfield(browse,'nom_type_nc')
469    nom_type_nc=browse.nom_type_nc;% get an image nomenclature type already determined by an input image name
470end
471if isfield(browse,'num_i1')
472    field_count=browse.num_i1;% get an image index type already determined by an input file
473end
[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
1163    mode_list=get(handles.mode,'String');
1164    mode_value=get(handles.mode,'Value');
1165    mode=mode_list{mode_value};
1166end
1167
1168% nomenclature type of the .nc files
1169nom_type_ima='ima_num';%default
1170if isfield(browse,'nom_type_ima')
1171    nom_type_ima=browse.nom_type_ima;
1172end
1173nom_type_nc='_i1-i2';%default
1174if isfield(browse,'nom_type_nc')
1175    nom_type_nc=browse.nom_type_nc;
1176end
[94]1177if 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]1178    nom_type_nc='netc_old';%nom_type for the netcdf files
[94]1179elseif isequal(nom_type_ima,'none')||isequal(nom_type_nc,'none')
[2]1180    nom_type_nc='none';
[94]1181elseif isequal(nom_type_ima,'avi')||isequal(nom_type_ima,'_i')||isequal(nom_type_ima,'ima_num')||isequal(nom_type_nc,'_i1-i2')
[112]1182    nom_type_nc='_i1-i2';
[2]1183else
1184    if  isequal(mode,'series(Di)')%|isequal(mode,'st_series(Di)')
1185        nom_type_nc='_i1-i2_j'; % PIV in volume
1186    else
1187        nom_type_nc='_i_j1-j2';
[112]1188    end
[2]1189end
1190browse.nom_type_nc=nom_type_nc;
1191set(handles.browse_root,'UserData',browse)
1192
1193%reads .nc subdirectory and image numbers from the interface
1194subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
1195subdir_civ2=get(handles.subdir_civ2,'String');%subdirectory subdir_civ2 for the netcdf data
[45]1196% first_i=str2num(get(handles.first_i,'String'));
1197% last_i=str2num(get(handles.last_i,'String'));
1198% incr=str2num(get(handles.incr_i,'String'));
1199% num1=first_i:incr:last_i;
1200% if isempty(num1)
1201%     set(handles.list_pair_civ2,'Value',1);
1202%     set(handles.list_pair_civ2,'String',{''});
1203%     return
1204% end
[137]1205ref_i=str2double(get(handles.ref_i_civ2,'String'));
[2]1206if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
1207    ref_j=0;
1208else
[137]1209    ref_j=str2double(get(handles.ref_j_civ2,'String'));
[2]1210end
[71]1211time=get(handles.RootName,'UserData'); %get the set of times
[2]1212if isempty(time)
1213    time=[0 1];%default
1214end
[71]1215%dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
[73]1216%dt_unit=1000;
[2]1217displ_num=get(handles.list_pair_civ1,'UserData');
1218
1219
[112]1220%eliminate the first pairs inconsistent with the position
[2]1221if isempty(displ_num)
1222    nbpair=0;
1223else
1224    nbpair=length(displ_num(1,:));%nbre of displayed pairs
[112]1225    if  isequal(mode,'series(Di)')% | isequal(mode,'st_series(Di)')
[2]1226        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
[112]1227    elseif  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]1228        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
1229    end
1230end
1231nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
1232
[112]1233%look for existing processed pairs involving the field at the middle of the series if civ1 will not
[2]1234% be performed, while the result is needed for next steps.
1235displ_pair={''}; %default
1236select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
1237if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0%&...
[112]1238    if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
1239        errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
1240        set(handles.list_pair_civ2,'Value',1);
1241        set(handles.list_pair_civ2,'String',{''});
1242        return
[2]1243    end
[112]1244    for ipair=1:nbpair
[2]1245        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
[112]1246            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
[2]1247        select(ipair)=exist(filename,'file')==2;
1248    end
1249    if  isequal(select,zeros(size(1:nbpair)))
[112]1250        if isfield(browse,'incr_pair')
[2]1251            num_i1=ref_i-floor(browse.incr_pair(1)/2);
1252            num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
1253            num_j1=ref_j-floor(browse.incr_pair(2)/2);
1254            num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
1255            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
1256            select(1)=exist(filename,'file')==2;
1257        else
[112]1258            if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
[2]1259                errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
1260            else
1261                errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
1262            end
[112]1263            set(handles.list_pair_civ2,'Value',1);
1264            set(handles.list_pair_civ2,'String',{''});
[2]1265            return
1266        end
1267    end
1268end
[112]1269if isequal(mode,'series(Di)') % | isequal(mode,'st_series(Di)')
1270    for ipair=1:nbpair
1271        if select(ipair)
1272            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
[2]1273                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
1274                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
[112]1275            end
1276        else
1277            displ_pair{ipair}='...'; %pair not displayed in the menu
1278        end
1279    end
[2]1280elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)') % series on the j index
[112]1281    for ipair=1:nbpair
1282        if select(ipair)
1283            if size(time,1)>=ref_i+displ_num(4,ipair) && size(time,2)>=ref_j+displ_num(2,ipair)
1284                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
1285                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1286            end
1287        else
1288            displ_pair{ipair}='...'; %pair not displayed in the menu
1289        end
1290    end
[2]1291elseif isequal(mode,'pair j1-j2')% | isequal(mode,'st_pair j1-j2') %case of pairs
1292    for ipair=1:nbpair
1293        if select(ipair)
[112]1294            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
1295            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
1296                ' :dt= ' num2str(dt*1000)];
1297        else
1298            displ_pair{ipair}='...'; %pair not displayed in the menu
1299        end
1300    end
[2]1301elseif isequal(mode,'displacement')
[112]1302    displ_pair={'Di=Dj=0'};
1303end
[2]1304val=get(handles.list_pair_civ2,'Value');
[229]1305ichoice=find(select,1);
[137]1306if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
1307if get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0
[2]1308    val=ichoice;% first valid pair proposed by default in the menu
1309end
1310if val>length(displ_pair')
1311    set(handles.list_pair_civ2,'Value',1);% first valid pair proposed by default in the menu
1312else
1313    set(handles.list_pair_civ2,'Value',val);
1314end
1315set(handles.list_pair_civ2,'String',displ_pair');
[12]1316set(gcf,'Pointer','arrow')
[2]1317
1318
[41]1319
[227]1320
[12]1321%------------------------------------------------------------------------
[2]1322% --- Executes on selection change in list_pair_civ1.
1323function list_pair_civ1_Callback(hObject, eventdata, handles)
[12]1324%------------------------------------------------------------------------
[2]1325%reproduce by default the chosen pair in the civ2 menu
1326list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
1327index_pair=get(handles.list_pair_civ1,'Value');
1328displ_num=get(handles.list_pair_civ1,'UserData');
[137]1329% num_a=displ_num(1,index_pair);
1330% num_b=displ_num(2,index_pair);
[2]1331list_pair2=get(handles.list_pair_civ2,'String');%get the menu of image pairs
1332if index_pair<=length(list_pair2)
1333    set(handles.list_pair_civ2,'Value',index_pair);
1334end
1335
[112]1336%update first_i and last_i according to the chosen image pairs
[2]1337mode_list=get(handles.mode,'String');
1338mode_value=get(handles.mode,'Value');
1339mode=mode_list{mode_value};
1340if isequal(mode,'series(Di)')
[137]1341    first_i=str2double(get(handles.first_i,'String'));
1342    last_i=str2double(get(handles.last_i,'String'));
1343    incr_i=str2double(get(handles.incr_i,'String'));
[2]1344    num1=first_i:incr_i:last_i;
[137]1345    lastfield=str2double(get(handles.nb_field,'String'));
1346    if ~isnan(lastfield)
[229]1347        test_find=(num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1348            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield);
1349        num1=num1(test_find);
[2]1350    end
1351    set(handles.first_i,'String',num2str(num1(1)));
1352    set(handles.last_i,'String',num2str(num1(end)));
1353elseif isequal(mode,'series(Dj)')
[137]1354    first_j=str2double(get(handles.first_j,'String'));
1355    last_j=str2double(get(handles.last_j,'String'));
1356    incr_j=str2double(get(handles.incr_j,'String'));
[2]1357    num_j=first_j:incr_j:last_j;
[137]1358    lastfield2=str2double(get(handles.nb_field2,'String'));
1359    if ~isnan(lastfield2)
[229]1360        test_find=(num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1361            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2);
1362        num1=num_j(test_find);
[2]1363    end
1364    set(handles.first_j,'String',num2str(num1(1)));
1365    set(handles.last_j,'String',num2str(num1(end)));
[112]1366end
[2]1367
[12]1368%------------------------------------------------------------------------
[2]1369% --- Executes on selection change in list_pair_civ2.
1370function list_pair_civ2_Callback(hObject, eventdata, handles)
[12]1371%------------------------------------------------------------------------
[112]1372index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu
[2]1373
[112]1374%update first_i and last_i according to the chosen image pairs
[2]1375mode_list=get(handles.mode,'String');
1376mode_value=get(handles.mode,'Value');
1377mode=mode_list{mode_value};
1378if isequal(mode,'series(Di)')
[137]1379    first_i=str2double(get(handles.first_i,'String'));
1380    last_i=str2double(get(handles.last_i,'String'));
1381    incr_i=str2double(get(handles.incr_i,'String'));
[2]1382    num1=first_i:incr_i:last_i;
[137]1383    lastfield=str2double(get(handles.nb_field,'String'));
1384    if ~isnan(lastfield)
[229]1385        test_find=(num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1386            (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield);
1387        num1=num1(test_find);
[2]1388    end
1389    set(handles.first_i,'String',num2str(num1(1)));
1390    set(handles.last_i,'String',num2str(num1(end)));
1391elseif isequal(mode,'series(Dj)')
[137]1392    first_j=str2double(get(handles.first_j,'String'));
1393    last_j=str2double(get(handles.last_j,'String'));
1394    incr_j=str2double(get(handles.incr_j,'String'));
[2]1395    num_j=first_j:incr_j:last_j;
[137]1396    lastfield2=str2double(get(handles.nb_field2,'String'));
1397    if ~isnan(lastfield2)
[229]1398        test_find=(num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1399            (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2);
1400        num1=num_j(test_find);
[2]1401    end
1402    set(handles.first_j,'String',num2str(num1(1)));
1403    set(handles.last_j,'String',num2str(num1(end)));
[112]1404end
[2]1405
[177]1406%------------------------------------------------------------------------
1407% --- Executes on button press in RUN: processing on local computer
[67]1408function RUN_Callback(hObject, eventdata, handles)
1409%------------------------------------------------------------------------
[73]1410set(handles.RUN, 'Enable','Off')
1411set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
[67]1412batch=0;
[229]1413errormsg=launch_jobs(hObject, eventdata, handles,batch);
[73]1414set(handles.RUN, 'Enable','On')
1415set(handles.RUN,'BackgroundColor',[1 0 0])
[36]1416
[177]1417% start status callback to visualise results
[229]1418if ~isempty(errormsg)
1419    display(errormsg)
1420    msgbox_uvmat('ERROR',errormsg)
[236]1421elseif  isfield(handles,'status') %&& ~isequal(get(handles.CivAll,'Value'),3)
[225]1422    set(handles.status,'Value',1);%suppress status display
1423    status_Callback(hObject, eventdata, handles)
[178]1424end
[177]1425
[12]1426%------------------------------------------------------------------------
[2]1427% --- Executes on button press in BATCH: remote processing
1428function BATCH_Callback(hObject, eventdata, handles)
[177]1429% -----------------------------------------------------------------------
[73]1430set(handles.BATCH, 'Enable','Off')
1431set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
[67]1432batch=1;
[229]1433errormsg=launch_jobs(hObject, eventdata, handles, batch);
[73]1434set(handles.BATCH, 'Enable','On')
1435set(handles.BATCH,'BackgroundColor',[1 0 0])
[67]1436
[177]1437% start status callback to visualise results
[229]1438if ~isempty(errormsg)
1439    display(errormsg)
1440    msgbox_uvmat('ERROR',errormsg)
1441elseif isfield(handles,'status')
1442    set(handles.status,'Value',1);%suppress status display
1443    status_Callback(hObject, eventdata, handles)
[178]1444end
[227]1445
[67]1446%------------------------------------------------------------------------
[133]1447% --- Lauch command called by RUN and BATCH: remote processing
[229]1448function errormsg=launch_jobs(hObject, eventdata, handles, batch)
[67]1449%-----------------------------------------------------------------------
[229]1450errormsg='';%default
[133]1451%% check the selected list of operations:
[2]1452operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
1453box_test(1)=get(handles.CIV1,'Value');
1454box_test(2)=get(handles.FIX1,'Value');
1455box_test(3)=get(handles.PATCH1,'Value');
1456box_test(4)=get(handles.CIV2,'Value');
1457box_test(5)=get(handles.FIX2,'Value');
1458box_test(6)=get(handles.PATCH2,'Value');
[180]1459index_first=find(box_test==1,1);
1460if isempty(index_first)
[229]1461    errormsg='no selected operation';
[2]1462    return
1463end
[180]1464index_last=find(box_test==1,1,'last');
[159]1465box_used=box_test(index_first : index_last);
[2]1466[box_missing,ind_missing]=min(box_used);
[180]1467if isequal(box_missing,0); %there is a missing step in the sequence of operations
[229]1468    errormsg=['missing' cell2mat(operations(ind_missing))];
[2]1469    return
1470end
1471
[177]1472%% check mask if selecetd
[2]1473if isequal(get(handles.get_mask_civ1,'Value'),1)
[12]1474    maskname=get(handles.mask_civ1,'String');
1475    if ~exist(maskname,'file')
1476        get_mask_civ1_Callback(hObject, eventdata, handles);
1477    end
[2]1478end
1479if isequal(get(handles.get_mask_fix1,'Value'),1)
[12]1480    maskname=get(handles.mask_fix1,'String');
1481    if ~exist(maskname,'file')
1482        get_mask_fix1_Callback(hObject, eventdata, handles);
1483    end
[2]1484end
1485if isequal(get(handles.get_mask_civ2,'Value'),1)
[12]1486    maskname=get(handles.mask_civ2,'String');
1487    if ~exist(maskname,'file')
[112]1488        get_mask_civ2_Callback(hObject, eventdata, handles);
[12]1489    end
[2]1490end
1491if isequal(get(handles.get_mask_fix2,'Value'),1)
[12]1492    maskname=get(handles.mask_fix2,'String');
1493    if ~exist(maskname,'file')
[112]1494        get_mask_fix2_Callback(hObject, eventdata, handles);
[12]1495    end
[2]1496end
1497
[177]1498%% reinitialise status callback
[178]1499if isfield(handles,'status')
[180]1500    set(handles.status,'Value',0);%suppress status display
1501    status_Callback(hObject, eventdata, handles)
[178]1502end
[133]1503
1504%% set the list of files and check them
1505display('checking the files...')
[227]1506[ref_i,ref_j,errormsg]=find_ref_indices(handles);
1507if ~isempty(errormsg)
1508    return
1509end
[133]1510[filecell,num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2,nom_type_nc]=...
[227]1511    set_civ_filenames(handles,ref_i,ref_j,box_test);
[177]1512set(handles.civ,'UserData',filecell);%store for futur use of status callback
[137]1513if isempty(filecell)% (error message displayed in fct set_civ_filenames)
[133]1514    return
1515end
1516nbfield=numel(num1_civ1);
1517nbslice=numel(num_a_civ1);
1518
1519%% read names of the .exe files for PIV and patch
1520path_UVMAT=fileparts(which('uvmat')); %path to the source directory of uvmat
[112]1521xmlfile='PARAM.xml';
[133]1522if exist(xmlfile,'file')% search parameter xml file in the whole matlab path
[54]1523    t=xmltree(xmlfile);
[67]1524    s=convert(t);
[2]1525end
[127]1526test_interp=0;
1527if batch
[67]1528    if isfield(s,'BatchParam')
1529        sparam=s.BatchParam;
1530        if ~ismember(sparam.BatchMode,{'sge'})
[229]1531            errormsg=['batch mode ' sparam.BatchMode ' not supported by UVMAT'];
1532            return
[67]1533        end
1534    else
[229]1535        errormsg='no batch civ binaries defined in PARAM.xml';
[67]1536        return
1537    end
[225]1538    if isfield(sparam,'BatchMode')
1539        batch_mode=sparam.BatchMode;
1540    end
1541    % choice of batch priority:
1542    ind_answer=2;
1543    [s,w]=unix('qstat -q civ.q|grep job_| wc -l'); %check the waiting list (command unix)
1544    if isequal(s,0)
1545        w(end)=[];
[232]1546        str_displ={[w ' jobs in the waiting list'];...
1547            '***********************';...
1548            'JOBS PRIORITY POLICY';...
1549            '- urgent = less than 100 images pairs';...
1550            '- normal = during the experiments';...
1551            '- low = post processing';...
1552            '***********************';...
1553            'Select a priority:'};
1554            ' ';...
1555            str={'urgent';'normal';'low'};
[225]1556        [ind_answer,v] = listdlg('PromptString',str_displ,...
1557            'SelectionMode','single',...
[232]1558            'ListString',str,'ListSize',[200 100],'Name','job priority','InitialValue',3);
[225]1559        if isequal(v,0) % to handle Cancel button and figure close,
[229]1560            errormsg='job cancelled';
[225]1561            return % a better way should be create
1562        end
1563    else
1564        msgbox_uvmat('ERROR','sge batch system not available')
1565        return
1566    end
[67]1567else
1568    if isfield(s,'RunParam')
1569        sparam=s.RunParam;
1570    else
[225]1571        msgbox_uvmat('ERROR','no run civ binaries defined in PARAM.xml')
[67]1572        return
1573    end
[225]1574end
[238]1575
1576%% choose the civ program
1577ProgList=get(handles.CivAll,'String');
1578index=get(handles.CivAll,'Value');
1579CivX=isequal(ProgList{index},'CivX');
1580CivAll=isequal(ProgList{index},'CivAll');
1581CivUvmat=isequal(ProgList{index},'CivUvmat');
1582%CivAll=isequal(get(handles.CivAll,'Value'),2); % Boolean for new civ programs
1583if CivAll && isfield(sparam,'CivBin')
[225]1584    CivBin=sparam.CivBin;
1585    if ~exist(CivBin,'file') || ~isempty(which(CivBin))% if path defined as relative to uvmat
1586        sparam.CivBin=fullfile(path_UVMAT,CivBin);
1587        if ~exist(sparam.CivBin,'file')
1588             msgbox_uvmat('ERROR',['CIVx binary ' CivBin ' defined in PARAM.xm does not exist'])
1589             return
[112]1590        end
[94]1591    end
[225]1592end
1593if isfield(sparam,'Civ1Bin')
1594    Civ1Bin=sparam.Civ1Bin;
1595    if ~exist(Civ1Bin,'file')||~isempty(which(Civ1Bin))% if path defined as relative to uvmat
1596        sparam.Civ1Bin=fullfile(path_UVMAT,Civ1Bin);
1597        if ~exist(sparam.Civ1Bin,'file')
1598             msgbox_uvmat('ERROR',['civ1 binary ' Civ1Bin ' defined in PARAM.xm does not exist'])
1599             return
[112]1600        end
[94]1601    end
[225]1602end
1603if isfield(sparam,'Civ2Bin')
1604    Civ2Bin=sparam.Civ2Bin;
1605    if ~exist(Civ2Bin,'file')||~isempty(which(Civ2Bin))% if path defined as relative to uvmat     
1606        sparam.Civ2Bin=fullfile(path_UVMAT,Civ2Bin);
1607        if ~exist(sparam.Civ2Bin,'file')
1608             msgbox_uvmat('ERROR',['civ2 binary ' Civ2Bin ' defined in PARAM.xm does not exist'])
1609             return
[112]1610        end
[94]1611    end
[225]1612end
1613if  isfield(sparam,'PatchBin')
1614    if ~exist(sparam.PatchBin,'file')||~isempty(which(sparam.PatchBin))% if path defined as relative to uvmat
1615        sparam.PatchBin=fullfile(path_UVMAT,sparam.PatchBin);
[94]1616    end
[73]1617end
[225]1618if isfield(sparam,'FixBin')
1619    if ~exist(sparam.FixBin,'file')||~isempty(which(sparam.FixBin))% if path defined as relative to uvmat
1620        sparam.FixBin=fullfile(path_UVMAT,sparam.FixBin);
[2]1621    end
1622end
1623
1624
[225]1625
[133]1626%% get civ1 parameters:
[112]1627display('files OK, processing...')
[2]1628if box_test(1)==1
1629    par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1,1});
[112]1630end
[2]1631
[133]1632%% get fix1 parameters
[112]1633if box_test(2)==1
[2]1634    flagindex1(1)=get(handles.vec_Fmin2, 'Value');
1635    flagindex1(2)=get(handles.vec_F3, 'Value');
1636    flagindex1(3)=get(handles.vec_F2, 'Value');
[127]1637    thresh_vecC1=str2double(get(handles.thresh_vecC,'String'));%threshold on image correlation vec_C
1638    thresh_vel1=str2double(get(handles.thresh_vel,'String'));%threshold on velocity modulus
[2]1639    test_mask=get(handles.get_mask_fix1,'Value');
1640    nbslice_mask=get(handles.mask_fix1,'UserData'); % get the number of slices (= number of masks)
1641    %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX
[112]1642    %     inf_sup=get(handles.inf_sup1,'Value');80
1643    %     fileref=get(handles.ref_fix1,'String');
1644    %     refpath=get(handles.ref_fix1,'UserData');
1645    %     fileref=fullfile(refpath,fileref);
[2]1646    menu=get(handles.field_ref1,'String');
1647    index=get(handles.field_ref1,'Value');
1648    if isempty(menu)
1649        fieldchoice='';
1650    else
1651        fieldchoice=menu{index};
[112]1652        msgbox_uvmat('WARNING','reference field is not used presently with batch, use RUN option')
1653    end
[2]1654end
[112]1655
[133]1656%% get patch1 parameters
[67]1657if box_test(3)==1
[127]1658    rho_patch1=str2double(get(handles.rho_patch1,'String'));
1659    if isnan(rho_patch1)
[112]1660        rho_patch1='1000';
1661        set(handles.rho_patch1,'String','1')
1662    else
1663        rho_patch1=num2str(1000*rho_patch1);
1664    end
1665    nx_patch1=get(handles.nx_patch1,'String');
1666    ny_patch1=get(handles.ny_patch1,'String');
[127]1667    if isnan(str2double(nx_patch1))
[112]1668        nx_patch1='50' ;%default
1669        set(handles.nx_patch1,'String','50');
1670    end
[127]1671    if isnan(str2double(ny_patch1))
[112]1672        ny_patch1='50' ;%default
1673        set(handles.ny_patch1,'String','50');
1674    end
1675    subdomain_patch1=get(handles.subdomain_patch1,'String');
1676    thresh_patch1=get(handles.thresh_patch1,'String');
1677end
1678
[133]1679%% get civ2 parameters:
[2]1680if box_test(4)==1
1681    par_civ2=read_param_civ2(handles,cell2mat(filecell.ima1.civ2(1,1)));
1682end
1683
[133]1684%% get fix2 parameters
[112]1685if box_test(5)==1
[2]1686    flagindex2(1)=get(handles.vec_Fmin2_2, 'Value');
1687    flagindex2(2)=get(handles.vec_F3_2, 'Value');
1688    flagindex2(3)=get(handles.vec_F4, 'Value');
[127]1689    thresh_vec2C=str2double(get(handles.thresh_vec2C,'String'));%threshold on image correlation vec_C
1690    thresh_vel2=str2double(get(handles.thresh_vel2,'String'));%threshold on velocity modulus
[2]1691    test_mask=get(handles.get_mask_fix2,'Value');
1692    nbslice_mask=get(handles.mask_fix2,'UserData'); % get the number of slices (= number of masks)
[112]1693    %%%%%%%%%%%%%COMPLETER LE PROGRAMME FIX AVEC REF FILE ET OPTION inf_sup=2
1694    %     inf_sup=get(handles.inf_sup2,'Value');
1695    %     ref=get(handles.ref_fix2,'UserData');
1696   
[2]1697    %%%%%%%%%%%%%%%%%%%
1698end
1699
[133]1700%% get patch2 parameters
[2]1701if box_test(6)==1
[127]1702    rho_patch2=str2double(get(handles.rho_patch2,'String'));
1703    if isnan(rho_patch2)
[2]1704        rho_patch2='1000';
1705        set(handles.rho_patch2,'String','1')
1706    else
1707        rho_patch2=num2str(1000*rho_patch2);
1708    end
1709    nx_patch2=get(handles.nx_patch2,'String');
1710    ny_patch2=get(handles.ny_patch2,'String');
[127]1711    if isnan(str2double(nx_patch2))
[2]1712        nx_patch2='50' ;%default
1713        set(handles.nx_patch2,'String','50');
1714    end
[127]1715    if isnan(str2double(ny_patch2))
[2]1716        ny_patch2='50' ;%default
1717        set(handles.ny_patch2,'String','50');
1718    end
1719    subdomain_patch2=get(handles.subdomain_patch2,'String');
1720    thresh_patch2=get(handles.thresh_patch2,'String');
[112]1721    %              test_interp=get(handles.test_interp,'Value');
[2]1722end
1723
[133]1724%% MAIN LOOP
[71]1725time=get(handles.RootName,'UserData'); %get the set of times
[134]1726super_cmd=[];
1727
[2]1728for ifile=1:nbfield
1729    for j=1:nbslice
[112]1730        i_cmd=0;
[2]1731        cmd='';
[73]1732        if isunix % check: necessaire aussi en RUN?
[112]1733            cmd='#!/bin/bash \n';
1734            cmd=[cmd '#$ -cwd \n'];
1735            cmd=[cmd 'hostname && date \n'];
[220]1736            cmd=[cmd 'umask 002 \n'];%allow writting access to created files for user group
[2]1737        end
[238]1738        if CivAll
1739            CivAllxml=xmltree;% xml contents,  all parameters
1740            CivAllCmd='';
1741            CivAllxml=set(CivAllxml,1,'name','CivDoc');
[2]1742        end
[174]1743        [Rootbat,Filebat]=fileparts(filecell.nc.civ1{ifile,j});%output netcdf file (without extention)
[177]1744        flname=fullfile(Rootbat,Filebat);
[159]1745        if batch
[174]1746            filename_bat=fullfile(Rootbat,['job_' Filebat]);
[159]1747         else
[177]1748            filename_bat=flname;
[159]1749        end
[174]1750        filename_bat=[filename_bat '.bat'];
[2]1751       
[112]1752        %CIV1
[2]1753        if box_test(1)==1
[41]1754            par_civ1.filename_ima_a=filecell.ima1.civ1{ifile,j};
[112]1755            par_civ1.filename_ima_b=filecell.ima2.civ1{ifile,j};
[2]1756            par_civ1.Dt=num2str(time(num2_civ1(ifile),num_b_civ1(j))-time(num1_civ1(ifile),num_a_civ1(j)));
[112]1757            par_civ1.T0=num2str((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(j)))/2);
[2]1758            par_civ1.term_a=num2stra(num_a_civ1(j),nom_type_nc);%UTILITE?
[112]1759            par_civ1.term_b=num2stra(num_b_civ1(j),nom_type_nc);%
[2]1760            test_mask=get(handles.get_mask_civ1,'Value');
[112]1761            if test_mask==0
[2]1762                par_civ1.maskname='noFile use default';
1763                par_civ1.maskflag='n';
1764            else
1765                maskdispl=get(handles.mask_civ1,'String');
[12]1766                if exist(maskdispl,'file')
1767                    par_civ1.maskname=maskdispl;
[112]1768                    par_civ1.maskflag='y';
[2]1769                else
[136]1770                    maskbase=[filecell.filebase '_' maskdispl]; %
[137]1771                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]1772                    num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
1773                    par_civ1.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
1774                    if exist(par_civ1.maskname,'file')
[82]1775                        par_civ1.maskflag='y';
[12]1776                    else
1777                        par_civ1.maskname='noFile use default';
[112]1778                        par_civ1.maskflag='n';
[12]1779                    end
[2]1780                end
1781            end
1782           
1783            test_grid=get(handles.browse_gridciv1,'Value');
1784            if test_grid
1785                par_civ1.gridflag='y';
1786                gridname=get(handles.grid_civ1,'String');
1787                if isequal(gridname(end-3:end),'grid')
[137]1788                    nbslice_grid=str2double(gridname(1:end-4)); %
1789                    if ~isnan(nbslice_grid)
[2]1790                        num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
[136]1791                        par_civ1.gridname=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[2]1792                        if ~exist(par_civ1.gridname,'file')
[112]1793                            msgbox_uvmat('ERROR','grid file absent for civ1')
[2]1794                        end
1795                    elseif exist(gridname,'file')
[112]1796                        par_civ1.gridname=gridname;
[2]1797                    else
1798                        msgbox_uvmat('ERROR','grid file absent for civ1')
1799                    end
1800                end
1801            else
[112]1802                par_civ1.gridname='noFile use default';
1803                par_civ1.gridflag='n';
[2]1804            end
[112]1805            %
[2]1806            i_cmd=i_cmd+1;
[238]1807            if isequal(CivAll,0)
[230]1808                civ1_exe=CIV1_CMD(fullfile(Rootbat,Filebat),'',par_civ1,handles,sparam);%create the parameter file .civ1.cmx and set the execution string civ1_exe
[229]1809%                 if(isunix)
1810%                      cmd=[cmd 'cp -f ' flname '.civ1.cmx ' flname '.cmx\n'];
1811%                 else
1812%                     flname=regexprep(flname,'\\','\\\\');
1813%                     cmd=[cmd 'copy /Y "' flname '.civ1.cmx" "' flname '.cmx"\n'];
1814%                 end
[230]1815                cmd=[cmd civ1_exe '\n'];
[2]1816            else
[238]1817                CivAllCmd=[CivAllCmd ' civ1 '];
[174]1818                str=CIV1_CMD_Unified(fullfile(Rootbat,Filebat),'',par_civ1);
[112]1819                fieldnames=fields(str);
[238]1820                [CivAllxml,uid_civ1]=add(CivAllxml,1,'element','civ1');
[2]1821                for ilist=1:length(fieldnames)
[112]1822                    val=eval(['str.' fieldnames{ilist}]);
1823                    if ischar(val)
[238]1824                        [CivAllxml,uid_t]=add(CivAllxml,uid_civ1,'element',fieldnames{ilist});
1825                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]1826                    end
1827                end
[2]1828            end
1829        end
1830       
[112]1831        % FIX1
1832        if box_test(2)==1
1833            test_mask=get(handles.get_mask_fix1,'Value');
1834            if test_mask==0
[2]1835                maskname='';
[112]1836            else
[2]1837                maskdispl=get(handles.mask_fix1,'String');
[137]1838                nbslice_mask=str2double(maskdispl(1:end-4)); %
[2]1839                num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
[136]1840                maskbase=[filecell.filebase '_' maskdispl];
[2]1841                maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
[112]1842            end
[238]1843            if CivX
[163]1844                if isunix %unix system
[94]1845                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ1{ifile,j} ' -fi1 ' num2str(flagindex1(1)) ...
[112]1846                    ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
1847                    ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName ' maskname];
[163]1848                else %windows system
1849                    cmd_FIX=['"' sparam.FixBin '" -f "' filecell.nc.civ1{ifile,j} '" -fi1 ' num2str(flagindex1(1)) ...
1850                    ' -fi2 ' num2str(flagindex1(2)) ' -fi3 ' num2str(flagindex1(3)) ...
1851                    ' -threshC ' num2str(thresh_vecC1) ' -threshV ' num2str(thresh_vel1) ' -maskName "' maskname '"'];
1852                    cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
1853                end
[94]1854                cmd=[cmd cmd_FIX '\n'];
[238]1855            elseif CivAll
[2]1856                fix1.inputFileName=filecell.nc.civ1{ifile,j} ;
1857                fix1.fi1=num2str(flagindex1(1));
1858                fix1.fi2=num2str(flagindex1(2));
1859                fix1.fi3=num2str(flagindex1(3));
1860                fix1.threshC=num2str(thresh_vecC1);
[112]1861                fix1.threshV=num2str(thresh_vel1);
[2]1862                fieldnames=fields(fix1);
[238]1863                [CivAllxml,uid_fix1]=add(CivAllxml,1,'element','fix1');
[2]1864                for ilist=1:length(fieldnames)
[112]1865                    val=eval(['fix1.' fieldnames{ilist}]);
1866                    if ischar(val)
[238]1867                        [CivAllxml,uid_t]=add(CivAllxml,uid_fix1,'element',fieldnames{ilist});
1868                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]1869                    end
1870                end
[238]1871                CivAllCmd=[CivAllCmd ' fix1 '];
[112]1872            end
1873        end
1874       
1875        %PATCH1
1876        if box_test(3)==1
[238]1877            if isequal(CivAll,0)
[112]1878                cmd_PATCH=PATCH_CMD(filecell.nc.civ1{ifile,j},nx_patch1,ny_patch1,rho_patch1,subdomain_patch1,thresh_patch1,test_interp,sparam.PatchBin);
1879                cmd=[cmd cmd_PATCH '\n'];
1880            else
1881                patch1.inputFileName=filecell.nc.civ1{ifile,j} ;
1882                patch1.nopt=subdomain_patch1;
1883                patch1.maxdiff=thresh_patch1;
1884                patch1.ro=rho_patch1;
1885                test_grid=get(handles.get_gridpatch1,'Value');
1886                if test_grid
1887                    patch1.gridflag='y';
1888                    gridname=get(handles.grid_patch1,'String');
1889                    if isequal(gridname(end-3:end),'grid')
[137]1890                        nbslice_grid=str2double(gridname(1:end-4)); %
1891                        if ~isnan(nbslice_grid)
[112]1892                            num1_grid=mod(num1_civ1(ifile)-1,nbslice_grid)+1;
[136]1893                            patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[112]1894                            if ~exist(patch1.gridPatch,'file')
1895                                msgbox_uvmat('ERROR','grid file absent for patch1')
1896                            end
1897                        elseif exist(gridname,'file')
1898                            patch1.gridPatch=gridname;
1899                        else
1900                            msgbox_uvmat('ERROR','grid file absent for patch1')
[2]1901                        end
1902                    end
[112]1903                else
1904                    patch1.gridPatch='none';
1905                    patch1.gridflag='n';
1906                    patch1.m=nx_patch1;
1907                    patch1.n=ny_patch1;
[2]1908                end
[112]1909                patch1.convectFlow='n';
1910                fieldnames=fields(patch1);
[238]1911                [CivAllxml,uid_patch1]=add(CivAllxml,1,'element','patch1');
[2]1912                for ilist=1:length(fieldnames)
[112]1913                    val=eval(['patch1.' fieldnames{ilist}]);
1914                    if ischar(val)
[238]1915                        [CivAllxml,uid_t]=add(CivAllxml,uid_patch1,'element',fieldnames{ilist});
1916                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]1917                    end
1918                end
[238]1919                CivAllCmd=[CivAllCmd ' patch1 '];
[112]1920            end
[2]1921        end
[112]1922       
[127]1923        if box_test(4)==1 || box_test(5)==1 || box_test(6)==1
[112]1924            filename_cmx=filecell.nc.civ2{ifile,j};%output netcdf file
[229]1925            filename_cmx(end-1:end+1)='cmx';%name of cmx file
[112]1926        end
1927       
1928        if box_test(4)==1
[2]1929            par_civ2.filename_ima_a=filecell.ima1.civ2{ifile,j};
1930            par_civ2.filename_ima_b=filecell.ima2.civ2{ifile,j};
[174]1931            [Rootbat,Filebat]=fileparts(filecell.nc.civ2{ifile,j});%output netcdf file (without extention)
[2]1932            par_civ2.Dt=num2str(time(num2_civ2(ifile),num_b_civ2(j))-time(num1_civ2(ifile),num_a_civ2(j)));
[112]1933            par_civ2.T0=num2str((time(num2_civ1(ifile),num_b_civ2(j))+time(num1_civ2(ifile),num_a_civ2(j)))/2);
[2]1934            par_civ2.term_a=num2stra(num_a_civ2(j),nom_type_nc);
[112]1935            par_civ2.term_b=num2stra(num_b_civ2(j),nom_type_nc);
[2]1936            par_civ2.filename_nc1=filecell.nc.civ1{ifile,j};
[229]1937            par_civ2.filename_nc1(end-2:end)=[]; % remove '.nc'
[2]1938            test_mask=get(handles.get_mask_civ2,'Value');
[112]1939            if test_mask==0
[2]1940                par_civ2.maskname='noFile use default';
1941                par_civ2.maskflag='n';
1942            else
1943                maskdispl=get(handles.mask_civ2,'String');
[12]1944                if exist(maskdispl,'file')
1945                    par_civ2.maskname=maskdispl;
1946                    par_civ2.maskflag='y';
[2]1947                else
[136]1948                    maskbase=[filecell.filebase '_' maskdispl]; %
[137]1949                    nbslice_mask=str2double(maskdispl(1:end-4)); %
[12]1950                    num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
1951                    par_civ2.maskname=name_generator(maskbase,num1_mask,1,'.png','_i');
1952                    if exist(par_civ2.maskname,'file')
[112]1953                        par_civ2.maskflag='y';
[12]1954                    else
1955                        par_civ2.maskname='noFile use default';
[112]1956                        par_civ2.maskflag='n';
[12]1957                    end
[2]1958                end
1959            end
1960            %TESTgrid
[137]1961            %test_grid=get(handles.browse_gridciv2,'Value');
[2]1962            gridname=get(handles.grid_civ2,'String');
[137]1963            %gridflag='y';
[2]1964            if numel(gridname)>=4 && isequal(gridname(end-3:end),'grid')
[137]1965                nbslice_grid=str2double(gridname(1:end-4)); %
1966                if ~isnan(nbslice_grid)
[2]1967                    par_civ2.gridflag='y';
1968                    num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
[136]1969                    par_civ2.gridname=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[2]1970                    if exist(par_civ2.gridname,'file')
[112]1971                        par_civ2.gridflag='y';
[2]1972                    else
1973                        par_civ2.gridname='noFile use default';
[112]1974                        par_civ2.gridflag='n';
[2]1975                    end
1976                elseif exist(gridname,'file')
[112]1977                    par_civ2.gridflag='y';
[2]1978                else
1979                    par_civ2.gridname='noFile use default';
[112]1980                    par_civ2.gridflag='n';
[2]1981                end
1982            end
1983            i_cmd=i_cmd+1;
[177]1984            flname=fullfile(Rootbat,Filebat);
[230]1985           
[238]1986            if isequal(CivAll,0)
[230]1987                cmd_CIV2=CIV2_CMD(flname,[],par_civ2,sparam);%creates the cmx file [fullfile(Rootbat,Filebat) '.civ2.cmx]
1988%                 if(isunix)
1989                 cmd=[cmd cmd_CIV2 '\n'];
1990%                 else
1991%                     flname=regexprep(flname,'\\','\\\\');
1992%                     cmd=[cmd 'copy /Y "' flname '.civ2.cmx" "' flname '.cmx"\n' cmd_CIV2 '\n'];
1993%                 end
[2]1994            else
[238]1995                CivAllCmd=[CivAllCmd ' civ2 '];
[220]1996                str=CIV2_CMD_Unified(flname,'',par_civ2);
[112]1997                fieldnames=fields(str);
[238]1998                [CivAllxml,uid_civ2]=add(CivAllxml,1,'element','civ2');
[2]1999                for ilist=1:length(fieldnames)
2000                    val=eval(['str.' fieldnames{ilist}]);
2001                    if ischar(val)
[238]2002                        [CivAllxml,uid_t]=add(CivAllxml,uid_civ2,'element',fieldnames{ilist});
2003                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[2]2004                    end
[112]2005                end
[2]2006            end
[112]2007        end
2008       
2009        % FIX2
2010        if box_test(5)==1
2011            test_mask=get(handles.get_mask_fix2,'Value');
2012            if test_mask==0
2013                maskname=''; %no mask used
[2]2014            else
2015                maskdispl=get(handles.mask_fix2,'String');
[136]2016                maskbase=[filecell.filebase '_' maskdispl]; %
[137]2017                nbslice_mask=str2double(maskdispl(1:end-4)); %
[2]2018                num1_mask=mod(num1_civ2(ifile)-1,nbslice_mask)+1;
2019                maskname =name_generator(maskbase,num1_mask,1,'.png','_i');
[112]2020            end
[238]2021            if isequal(CivAll,0)
[163]2022                if isunix
[94]2023                cmd_FIX=[sparam.FixBin ' -f ' filecell.nc.civ2{ifile,j} ' -fi1 ' num2str(flagindex2(1)) ...
[112]2024                    ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
2025                    ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName ' maskname];
[163]2026                else
2027                    cmd_FIX=['"' sparam.FixBin '" -f "' filecell.nc.civ2{ifile,j} '" -fi1 ' num2str(flagindex2(1)) ...
2028                    ' -fi2 ' num2str(flagindex2(2)) ' -fi3 ' num2str(flagindex2(3)) ...
2029                    ' -threshC ' num2str(thresh_vec2C) ' -threshV ' num2str(thresh_vel2) ' -maskName "' maskname '"'];
2030                    cmd_FIX=regexprep(cmd_FIX,'\\','\\\\');
2031                end
[112]2032                cmd=[cmd cmd_FIX '\n'];
2033            else
[2]2034                fix2.inputFileName=filecell.nc.civ2{ifile,j} ;
2035                fix2.fi1=num2str(flagindex2(1));
2036                fix2.fi2=num2str(flagindex2(2));
2037                fix2.fi3=num2str(flagindex2(3));
2038                fix2.threshC=num2str(thresh_vec2C);
[112]2039                fix2.threshV=num2str(thresh_vel2);
[2]2040                fieldnames=fields(fix2);
[238]2041                [CivAllxml,uid_fix2]=add(CivAllxml,1,'element','fix2');
[2]2042                for ilist=1:length(fieldnames)
[112]2043                    val=eval(['fix2.' fieldnames{ilist}]);
2044                    if ischar(val)
[238]2045                        [CivAllxml,uid_t]=add(CivAllxml,uid_fix2,'element',fieldnames{ilist});
2046                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]2047                    end
2048                end
[238]2049                CivAllCmd=[CivAllCmd ' fix2 '];
[112]2050            end
2051        end
2052       
2053        %PATCH2
2054        if box_test(6)==1
[238]2055            if isequal(CivAll,0)
[94]2056                cmd_PATCH=PATCH_CMD(filecell.nc.civ2{ifile,j},nx_patch2,ny_patch2,rho_patch2,subdomain_patch2,thresh_patch2,test_interp,sparam.PatchBin);
[90]2057                cmd=[cmd cmd_PATCH '\n'];
[12]2058            else
2059                patch2.inputFileName=filecell.nc.civ1{ifile,j} ;
[220]2060                patch2.nopt=subdomain_patch2;
2061                patch2.maxdiff=thresh_patch2;
2062                patch2.ro=rho_patch2;
[12]2063                test_grid=get(handles.get_gridpatch2,'Value');
2064                if test_grid
2065                    patch2.gridflag='y';
2066                    gridname=get(handles.grid_patch2,'String');
2067                    if isequal(gridname(end-3:end),'grid')
[137]2068                        nbslice_grid=str2double(gridname(1:end-4)); %
2069                        if ~isnan(nbslice_grid)
[12]2070                            num1_grid=mod(num1_civ2(ifile)-1,nbslice_grid)+1;
[136]2071                            patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,num1_grid,1,'.grid','_i')];
[12]2072                            if ~exist(patch2.gridPatch,'file')
[112]2073                                msgbox_uvmat('ERROR','grid file absent for patch2')
[12]2074                            end
2075                        elseif exist(gridname,'file')
[112]2076                            patch2.gridPatch=gridname;
[12]2077                        else
2078                            msgbox_uvmat('ERROR','grid file absent for patch2')
[2]2079                        end
2080                    end
[12]2081                else
[112]2082                    patch2.gridPatch='none';
2083                    patch2.gridflag='n';
2084                    patch2.m=nx_patch2;
2085                    patch2.n=ny_patch2;
[2]2086                end
[12]2087                patch2.convectFlow='n';
2088                fieldnames=fields(patch2);
[238]2089                [CivAllxml,uid_patch2]=add(CivAllxml,1,'element','patch2');
[12]2090                for ilist=1:length(fieldnames)
[112]2091                    val=eval(['patch2.' fieldnames{ilist}]);
2092                    if ischar(val)
[238]2093                        [CivAllxml,uid_t]=add(CivAllxml,uid_patch2,'element',fieldnames{ilist});
2094                        [CivAllxml,uid_t2]=add(CivAllxml,uid_t,'chardata',val);
[112]2095                    end
2096                end
[238]2097                CivAllCmd=[CivAllCmd ' patch2 '];
[112]2098            end
[12]2099        end
[238]2100        if CivAll
2101            save(CivAllxml,[flname '.xml']);
2102            cmd=[cmd sparam.CivBin ' -f ' flname '.xml '  CivAllCmd ' >' flname '.log' '\n'];
[12]2103        end
[112]2104        % create the .bat file:
[159]2105        [fid,message]=fopen(filename_bat,'w');
2106        if isequal(fid,-1)
2107            msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
2108            return
[12]2109        end
[39]2110        fprintf(fid,cmd);
2111        fclose(fid);
[67]2112        if batch
2113            switch batch_mode
2114                case 'sge'
2115                    pvalue=num2str((1-ind_answer)*500);
[177]2116                    display(['!qsub -p ' pvalue ' -q civ.q -e ' flname '.errors -o ' flname '.log' ' ' filename_bat]);
2117                    eval(  ['!qsub -p ' pvalue ' -q civ.q -e ' flname '.errors -o ' flname '.log' ' ' filename_bat]);
[67]2118            end
[238]2119        elseif ~CivUvmat
[112]2120            %% to lauch the jobs locally :
[12]2121            if(isunix)
[135]2122                cmd_str=['. ' filename_bat];
[133]2123            else %case of Windows
[163]2124                cmd_str=['@call "' regexprep(filename_bat,'\\','\\\\') '"'];
[2]2125            end
[135]2126            super_cmd=[super_cmd cmd_str '\n'];         
2127            disp(cmd_str);
[225]2128        else       %run PIVlab if selected
[244]2129            drawnow
[238]2130            if box_test(1)==1
2131                Param.Civ1=par_civ1;
2132            end
2133            if box_test(2)==1
2134                fix1.WarnFlags=[];
2135                if get(handles.vec_Fmin2,'Value')
2136                    fix1.WarnFlags=[fix1.WarnFlags -2];
2137                end
2138                if get(handles.vec_F3,'Value')
2139                    fix1.WarnFlags=[fix1.WarnFlags 3];
2140                end
2141                fix1.LowerBoundCorr=thresh_vecC1;
2142                if get(handles.inf_sup1,'Value')
2143                    fix1.UppperBoundVel=thresh_vel1;
2144                else
2145                     fix1.LowerBoundVel=thresh_vel1;
2146                end
2147                Param.Fix1=fix1;
2148            end
2149            if box_test(3)==1
2150                Param.Patch1.Rho=rho_patch1;
2151                Param.Patch1.Threshold=thresh_patch1;
2152                Param.Patch1.SubDomain=subdomain_patch1;
2153            end
[248]2154            if box_test(4)==1
2155                Param.Civ2=par_civ2;
2156            end
[238]2157            [Data,erromsg]=civ_uvmat(Param,filecell.nc.civ1{ifile,j});
[225]2158            if isempty(errormsg)
2159                display([filecell.nc.civ1{ifile,j} ' written'])
2160            else
2161                msgbox_uvmat('ERROR',errormsg)
2162            end
2163        end                 
[112]2164    end
[2]2165end
[134]2166
[238]2167if ~batch && ~CivUvmat
[159]2168    [Rootbat,Filebat,extbat]=fileparts(filename_bat);
[229]2169    filename_superbat=fullfile(Rootbat,'job_list.bat');
[134]2170    fid=fopen(filename_superbat,'w');
2171    fprintf(fid,super_cmd');
2172    fclose(fid);
[219]2173     if(isunix)
2174        system(['chmod +x ' filename_superbat])
2175     end
[192]2176     system([filename_superbat ' &'])% execute main commmand
[133]2177end
[2]2178
[137]2179%% save interface state
[2]2180if isfield(filecell,'nc')
2181    if isfield(filecell.nc,'civ2')
2182        fileresu=filecell.nc.civ2{1,1};
2183    else
2184        fileresu=filecell.nc.civ1{1,1};
2185    end
2186end
2187[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileresu);
2188namedoc=fullfile(RootPath,subdir,RootFile);
[112]2189detect=1;
[2]2190while detect==1
2191    namefigfull=[namedoc '.fig'];
2192    hh=dir(namefigfull);
2193    if ~isempty(hh)
2194        detect=1;
2195        namedoc=[namedoc '.0'];
2196    else
2197        detect=0;
2198    end
2199end
2200saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
2201
[227]2202%------------------------------------------------------------------------
2203% --- determine the list of reference indices of processing file
2204function [ref_i,ref_j,errormsg]=find_ref_indices(handles)
2205%------------------------------------------------------------------------
2206errormsg=''; %default error message
2207first_i=str2double(get(handles.first_i,'String'));%first index i
2208last_i=str2double(get(handles.last_i,'String'));%last index i
2209incr_i=str2double(get(handles.incr_i,'String'));% increment
2210if isequal(get(handles.first_j,'Visible'),'on')
2211    first_j=str2double(get(handles.first_j,'String'));%first index j
2212    last_j=str2double(get(handles.last_j,'String'));%last index j
2213    incr_j=str2double(get(handles.incr_j,'String'));% increment
2214else
2215    first_j=1;
2216    last_j=1;
2217    incr_j=1;
2218end
2219ref_i=first_i:incr_i:last_i;% list of i indices (reference values for each pair)
2220ref_j=first_j:incr_j:last_j;% list of j indices (reference values for each pair)
2221if isnan(first_i)||isnan(first_j)
2222    errormsg='first field number not defined';
2223elseif isnan(last_i)||isnan(last_j)
2224    errormsg='last field number not defined';
2225elseif isnan(incr_i)||isnan(incr_j)
2226    errormsg='increment in field number not defined';
2227elseif last_i < first_i || last_j < first_j
2228    errormsg='last field number must be larger than the first one';
2229end
[134]2230
[227]2231%------------------------------------------------------------------------
2232% --- determine the list of filenames and indices needed for launch_job
[2]2233function [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]=...
[227]2234    set_civ_filenames(handles,ref_i,ref_j,box_test)
[12]2235%------------------------------------------------------------------------
[85]2236filecell=[];%default
[136]2237
2238%% get the root names nomenclature and numbers
[71]2239filebase=get(handles.RootName,'String');
[136]2240
2241if isempty(filebase)||isequal(filebase,'')
2242    msgbox_uvmat('ERROR','no input files')
2243    return
2244end
2245
[137]2246%filebase=regexprep(filebase,'\.fsnet','fsnet');% temporary fix for cluster Coriolis
[136]2247filecell.filebase=filebase;
2248
[2]2249browse=get(handles.browse_root,'UserData');
2250compare_list=get(handles.compare,'String');
2251val=get(handles.compare,'Value');
2252compare=compare_list{val};
2253if strcmp(compare,'displacement')
2254    mode='displacement';
2255else
2256    mode_list=get(handles.mode,'String');
2257    mode_value=get(handles.mode,'Value');
2258    mode=mode_list{mode_value};
2259end
[137]2260%time=get(handles.RootName,'UserData'); %get the set of times
[71]2261ext_ima=get(handles.ImaExt,'String');
[2]2262nom_type_nc=browse.nom_type_nc;
[122]2263if isfield(browse,'nom_type_ima')
2264    nom_type_ima2=browse.nom_type_ima;
2265end
2266if isempty(nom_type_ima2),nom_type_ima2='1';end; %default
2267if isempty(nom_type_nc),nom_type_nc='_i1-i2';end; %default
[2]2268[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
[227]2269    find_pair_indices(handles,ref_i,ref_j,mode);
[2]2270%determine the new filebase for 'displacement' mode (comparison of two series)
2271filebase_B=filebase;% root name of the second field series for stereo
2272if strcmp(compare,'displacement') || strcmp(compare,'stereo PIV')
[127]2273%     test_disp=1;
[2]2274    nom_type_ima1=browse.nom_type_ima_1; %nomenclature type of the second file series
2275    [Path2,Name2]=fileparts(filebase_B);
2276    Path1=Path2;
[71]2277    Name1=get(handles.RootName_1,'String');% root name of the first field series for stereo
[2]2278    filebase_A=fullfile(Path1,Name1);
2279    if length(Name1)>6
2280        Name1=Name1(end-5:end);
2281    end
2282    if length(Name2)>6
2283        Name2=Name2(end-5:end);
2284    end
2285    filebase_AB=fullfile(Path2,[Name2 '-' Name1]);
2286else
[127]2287%     test_disp=0;
[2]2288    filebase_A=filebase;
2289    nom_type_ima1=nom_type_ima2;
2290    filebase_AB=filebase;
2291end
2292if strcmp(compare,'displacement')
[112]2293    filebase_ima1=filebase_A;
2294    filebase_ima2=filebase_B;
2295    filebase_nc=filebase_AB; %root name for the result of civ2
[2]2296else
[112]2297    filebase_ima1=filebase_B;
2298    filebase_ima2=filebase_B;
2299    filebase_nc=filebase_B;
2300end
[2]2301
2302%determine reference files for fix:
2303file_ref_fix1={};%default
2304file_ref_fix2={};
2305nbfield=length(num1_civ1);
2306nbslice=length(num_a_civ1);
2307if box_test(2)==1% fix1 performed
2308    ref=get(handles.ref_fix1,'UserData');%read data on the ref file stored by get_ref_fix1_Callback
2309    if ~isempty(ref)
[137]2310        first_i=str2double(get(handles.first_i,'String'));
2311        last_i=str2double(get(handles.last_i,'String'));
2312        incr_i=str2double(get(handles.incr_i,'String'));
2313        first_j=str2double(get(handles.first_j,'String'));
2314        last_j=str2double(get(handles.last_j,'String'));
2315        incr_j=str2double(get(handles.incr_j,'String'));
[127]2316        num_i_ref=first_i:incr_i:last_i;
2317        num_j_ref=first_j:incr_j:last_j;
[2]2318        if isequal(mode,'displacement')
2319            num_i1=num_i_ref;
2320            num_i2=num_i_ref;
2321            num_j1=num_j_ref;
2322            num_j2=num_j_ref;
2323        elseif isequal(mode,'pair j1-j2')% isequal(mode,'st_pair j1-j2')
2324            num_i1=num_i_ref;
2325            num_i2=num_i1;
2326            num_j1=ref.num_a*ones(size(num_i_ref));
2327            num_j2=ref.num_b*ones(size(num_i_ref));
2328        elseif isequal(mode,'series(Di)') % isequal(mode,'st_series(Di)')
2329            delta1=floor((ref.num2-ref.num1)/2);
2330            delta2=ceil((ref.num2-ref.num1)/2);
2331            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2332            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2333            if isempty(ref.num_a)
2334                ref.num_a=1;
2335            end
2336            num_j1=ref.num_a*ones(size(num_i1));
2337            num_j2=num_j1;
2338        elseif isequal(mode,'series(Dj)')%| isequal(mode,'st_series(Dj)')
2339            delta1=floor((ref.num_b-ref.num_a)/2);
2340            delta2=ceil((ref.num_b-ref.num_a)/2);
2341            num_i1=ref.num1*ones(size(num_i_ref));
2342            num_i2=num_i1;
2343            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2344            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2345        end
2346        for ifile=1:nbfield
2347            for j=1:nbslice
2348                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);%
2349                file_ref_fix1(ifile,j)={file_ref};
2350                if ~exist(file_ref,'file')
2351                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix1'])
[12]2352                    filecell=[];
[2]2353                    return
2354                end
2355            end
2356        end
2357    end
2358end
2359
2360%determine reference files for fix2:
2361if box_test(5)==1% fix2 performed
2362    ref=get(handles.ref_fix2,'UserData');
2363    if ~isempty(ref)
[127]2364        first_i=str2double(get(handles.first_i,'String'));
2365        last_i=str2double(get(handles.last_i,'String'));
2366        incr_i=str2double(get(handles.incr_i,'String'));
2367        first_j=str2double(get(handles.first_j,'String'));
2368        last_j=str2double(get(handles.last_j,'String'));
2369        incr_j=str2double(get(handles.incr_j,'String'));
[229]2370        num_i_ref=first_i:incr_i:last_i;
2371        num_j_ref=first_j:incr_j:last_j;
[2]2372        if isequal(mode,'displacement')
2373            num_i1=num_i_ref;
2374            num_i2=num_i_ref;
2375            num_j1=num_j_ref;
2376            num_j2=num_j_ref;
2377        elseif isequal(mode,'pair j1-j2')
2378            num_i1=num_i_ref;
2379            num_i2=num_i1;
2380            num_j1=ref.num_a;
2381            num_j2=ref.num_b;
2382        elseif isequal(mode,'series(Di)')
2383            delta1=floor((ref.num2-ref.num1)/2);
2384            delta2=ceil((ref.num2-ref.num1)/2);
2385            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
2386            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
2387            num_j1=ref.num_a*ones(size(num_i1));
2388            num_j2=num_j1;
2389        elseif isequal(mode,'series(Dj)')
2390            delta1=floor((ref.num_b-ref.num_a)/2);
2391            delta2=ceil((ref.num_b-ref.num_a)/2);
2392            num_i1=ref.num1*ones(size(num_i_ref));
2393            num_i2=num_i1;
2394            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
2395            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
2396        end
2397        for ifile=1:nbfield
2398            for j=1:nbslice
2399                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);%
2400                file_ref_fix2(ifile,j)={file_ref};
2401                if ~exist(file_ref,'file')
2402                    msgbox_uvmat('ERROR',['reference file ' file_ref ' not found for fix2'])
[122]2403                    filecell={};
[2]2404                    return
2405                end
2406            end
2407        end
2408    end
2409end
2410
2411%check dir
2412subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf output data
2413subdir_civ2=get(handles.subdir_civ2,'String');
[174]2414if isequal(subdir_civ1,''),subdir_civ1='CIV'; end% put default subdir
[2]2415if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
[135]2416currentdir=pwd;%store the current working directory
[2]2417[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
2418if ~exist(Path_ima,'dir')
[12]2419    msgbox_uvmat('ERROR',['path to images ' Path_ima ' not found'])
[122]2420    filecell={};
[2]2421    return
2422end
[127]2423[xx,message]=fileattrib(Path_ima);
[122]2424if ~isempty(message) && ~isequal(message.UserWrite,1)
[112]2425    msgbox_uvmat('ERROR',['No writting access to ' Path_ima])
[122]2426    filecell={};
[112]2427    cd(currentdir);
2428    return
[2]2429end
2430
2431%check the existence of the netcdf and image files involved
2432% %%%%%%%%%%%%  case CIV1 activated   %%%%%%%%%%%%%
2433if box_test(1)==1;
[112]2434    detect=1;
[127]2435    vers=0;
2436    subdir_civ1_new=subdir_civ1;
[153]2437    while detect==1 %create a new subdir if the netcdf files already exist
[122]2438        for ifile=1:nbfield
[112]2439            for j=1:nbslice
[122]2440                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]2441                detect=exist(filename,'file')==2;
2442                if detect% if a netcdf file already exists
[137]2443                    indstr=regexp(subdir_civ1_new,'\D');
2444                    if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
2445                        vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
2446                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]2447                    else
2448                        vers=vers+1;
[137]2449                        subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) '_' num2str(vers)];       
[127]2450                    end
[137]2451                    subdir_civ2=subdir_civ1_new;
[112]2452                    break
2453                end
2454                filecell.nc.civ1(ifile,j)={filename};
2455            end
2456            if detect% if a netcdf file already exists
2457                break
2458            end
2459        end
[134]2460 
[112]2461        %create the new subdir_civ1
[127]2462        if ~exist(fullfile(Path_ima,subdir_civ1_new),'dir')
[134]2463            cd(Path_ima);         
[128]2464            [xx,msg1]=mkdir(subdir_civ1_new);
[134]2465
[128]2466            if ~strcmp(msg1,'')
2467                msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])%error message for directory creation
[122]2468                filecell={};
2469                return
[163]2470            elseif isunix         
[128]2471                [xx,msg2] = fileattrib(subdir_civ1_new,'+w','g'); %yield writing access (+w) to user group (g)
2472                if ~strcmp(msg2,'')
[134]2473                    msgbox_uvmat('ERROR',['pb of permission for  ' subdir_civ1_new ': ' msg2])%error message for directory creation
[128]2474                    filecell={};
2475                    return
2476                end
[112]2477            end
[134]2478            cd(currentdir);
[112]2479        end
2480        if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
2481            for ifile=1:nbfield
2482                for j=1:nbslice
[122]2483                    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]2484                    detect=exist(filename,'file')==2;
[2]2485                    if detect% if a netcdf file already exists
[137]2486                       indstr=regexp(subdir_civ1_new,'\D');
2487                       if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
2488                           vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
2489                           subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
[127]2490                       else
2491                           vers=vers+1;
[137]2492                           subdir_civ1_new=[subdir_civ1_new '_' num2str(vers)];
[127]2493                       end
2494                       subdir_civ2=subdir_civ1;
2495                       break
[2]2496                    end
[112]2497                    filecell.ncA.civ1(ifile,j)={filename};
2498                end
2499                if detect% if a netcdf file already exists
2500                    break
2501                end
2502            end
2503            %create the new subdir_civ1
[134]2504            if exist(fullfile(Path_ima,subdir_civ1_new),'dir')
2505                   cd(Path_ima);         
[128]2506                [xx,msg1]=mkdir(subdir_civ1_new);
[134]2507                            cd(currentdir);
[128]2508                if ~strcmpl(msg1,'')
2509                    msgbox_uvmat('ERROR',['cannot create ' subdir_civ1_new ': ' msg1])
[122]2510                    cd(currentdir)
2511                    filecell={};
2512                    return
[128]2513                else
2514                    [xx,msg2] = fileattrib(subdir_civ1_new,'+w','g'); %yield writing access (+w) to user group (g)
2515                    if ~strcmp(msg2,'')
2516                        msgbox_uvmat('ERROR',['pb of permission for ' subdir_civ1_new ': ' msg2])%error message for directory creation
2517                        cd(currentdir)
2518                        filecell={};
2519                        return
2520                    end
[112]2521                end
2522            end
2523        end
2524    end
[127]2525    subdir_civ1=subdir_civ1_new;
[2]2526    % get image names
2527    for ifile=1:nbfield
[112]2528        for j=1:nbslice
[2]2529            filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2530            idetect(j)=exist(filename,'file')==2;
2531            filecell.ima1.civ1(ifile,j)={filename}; %first image
2532            filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2533            idetect_1(j)=exist(filename,'file')==2;
2534            filecell.ima2.civ1(ifile,j)={filename};%second image
[112]2535        end
2536        [idetectmin,indexj]=min(idetect);
2537        if idetectmin==0,
2538            msgbox_uvmat('ERROR',[filecell.ima1.civ1{ifile,indexj} ' not found'])
[122]2539            filecell={};
2540            cd(currentdir)
[112]2541            return
2542        end
2543        [idetectmin,indexj]=min(idetect_1);
2544        if idetectmin==0,
2545            msgbox_uvmat('ERROR',[filecell.ima2.civ1{ifile,indexj} ' not found'])
[122]2546            filecell={};
[112]2547            cd(currentdir)
2548            return
2549        end
2550    end
2551    if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
2552        for ifile=1:nbfield
2553            for j=1:nbslice
2554                filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
2555                idetect(j)=exist(filename,'file')==2;
2556                filecell.imaA1.civ1(ifile,j)={filename} ;%first image
2557                filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
2558                idetect_1(j)=exist(filename,'file')==2;
2559                filecell.imaA2.civ1(ifile,j)={filename};%second image
2560            end
[2]2561            [idetectmin,indexj]=min(idetect);
[112]2562            if idetectmin==0,
2563                msgbox_uvmat('ERROR',[filecell.imaA1.civ1{ifile,indexj} ' not found'])
[122]2564                filecell={};
[112]2565                cd(currentdir)
[2]2566                return
[112]2567            end
[2]2568            [idetectmin,indexj]=min(idetect_1);
[112]2569            if idetectmin==0,
2570                msgbox_uvmat('ERROR',[filecell.imaA2.civ1{ifile,indexj} ' not found'])
[122]2571                filecell={};
[2]2572                cd(currentdir)
2573                return
[112]2574            end
2575        end
[2]2576    end
[112]2577   
2578    %%%%%%%%%%%%%  fix1 or patch1 activated but no civ1   %%%%%%%%%%%%%
2579elseif (box_test(2)==1 || box_test(3)==1);
[2]2580    for ifile=1:nbfield
2581        for j=1:nbslice
2582            filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
[112]2583                nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2584            detect=exist(filename,'file')==2;
[122]2585            if detect==0
2586                msgbox_uvmat('ERROR',[filename ' not found'])
2587                filecell={};
2588                cd(currentdir)
2589                return
2590            end
[2]2591            filecell.nc.civ1(ifile,j)={filename};
2592        end
2593    end
2594    if strcmp(compare,'stereo PIV')
[112]2595        for ifile=1:nbfield
2596            for j=1:nbslice
2597                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);%
2598                filecell.ncA.civ1(ifile,j)={filename};
2599                if ~exist(filename,'file')
2600                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2601                    set(handles.RUN, 'Enable','On')
2602                    set(handles.RUN,'BackgroundColor',[1 0 0])
[122]2603                    filecell={};
[112]2604                    cd(currentdir)
2605                    return
[2]2606                end
2607            end
[112]2608        end
[2]2609    end
2610end
2611
2612%%%%%%%%%%%%%  if civ2 performed with pairs different than civ1  %%%%%%%%%%%%%
2613testdiff=0;
2614if (box_test(4)==1)&&...
[127]2615        ((get(handles.list_pair_civ1,'Value')~=get(handles.list_pair_civ2,'Value'))||~strcmp(subdir_civ2,subdir_civ1))
[2]2616    testdiff=1;
[112]2617    detect=1;
[127]2618    vers=0;
2619    subdir_civ2_new=subdir_civ2;
[2]2620    while detect==1 %create a new subdir if the netcdf files already exist
[112]2621        for ifile=1:nbfield
2622            for j=1:nbslice
[127]2623                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]2624                detect=exist(filename,'file')==2;
2625                if detect% if a netcdf file already exists
[127]2626                    indstr=regexp(subdir_civ2,'\D');
2627                    if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2628                        vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2629                        subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2630                    else
2631                        vers=vers+1;
2632                        subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2633                    end
[112]2634                    break
2635                end
2636                filecell.nc.civ2(ifile,j)={filename};
2637            end
2638            if detect% if a netcdf file already exists
2639                break
2640            end
2641        end
[128]2642        %create the new subdir_civ2_new
2643        if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
[174]2644            [xx,m2]=mkdir(fullfile(Path_ima,subdir_civ2_new));
[128]2645            [xx,msg2] = fileattrib(subdir_civ2_new,'+w','g'); %yield writing access (+w) to user group (g)
[112]2646            if ~isequal(m2,'')
[128]2647                msgbox_uvmat('ERROR',['cannot create ' subdir_civ2_new ': ' m2])
[122]2648                filecell={};
2649                cd(currentdir)
2650                return
[112]2651            end
2652        end
2653        if strcmp(compare,'stereo PIV')%check second nc series
2654            for ifile=1:nbfield
2655                for j=1:nbslice
2656                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[122]2657                        nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2_new);%
[112]2658                    detect=exist(filename,'file')==2;
[2]2659                    if detect% if a netcdf file already exists
[127]2660                        indstr=regexp(subdir_civ2,'\D');
2661                        if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
2662                           vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
2663                           subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
2664                        else
2665                           vers=vers+1;
2666                           subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
2667                        end
[112]2668                        break
[2]2669                    end
[112]2670                    filecell.ncA.civ2(ifile,j)={filename};
2671                end
2672                if detect% if a netcdf file already exists
2673                    break
2674                end
2675            end
[122]2676            subdir_civ2=subdir_civ2_new;
[112]2677            %create the new subdir_civ1
[127]2678            if ~exist(fullfile(Path_ima,subdir_civ2_new),'dir')
2679                [xx,m2]=mkdir(subdir_civ2_new);
[128]2680                 [xx,msg2] = fileattrib(subdir_civ2_new,'+w','g'); %yield writing access (+w) to user group (g)
[112]2681                if ~isequal(m2,'')
[128]2682                    msgbox_uvmat('ERROR', ['cannot create ' subdir_civ2_new ': ' m2])%error message for directory creation
[122]2683                    cd(currentdir)
2684                    filecell={};
2685                    return
[112]2686                end
2687            end
2688        end
2689    end
[127]2690    subdir_civ2=subdir_civ2_new;
[2]2691end
2692cd(currentdir);%come back to the current working directory
2693
2694%%%%%%%%%%%%%  if civ2 results are obtained or used  %%%%%%%%%%%%%
2695if box_test(4)==1 || box_test(5)==1 || box_test(6)==1 %civ2
2696    %check source netcdf file of civ1 estimates
2697    if box_test(1)==0; %no civ1 performed
2698        for ifile=1:nbfield
2699            for j=1:nbslice
2700                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2701                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2702                filecell.nc.civ1(ifile,j)={filename};% name of the civ1 file
2703                if ~exist(filename,'file')
2704                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[122]2705                    filecell={};
[2]2706                    return
2707                end
2708                if ~testdiff % civ2 or patch2 are written in the same file as civ1
2709                    if box_test(4)==0 ; %check the existence of civ2 if it is not calculated
[248]2710                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
2711                        if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
[2]2712                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2713                            filecell=[];
[2]2714                            return
[248]2715                        elseif isempty(Data.civ2)||isequal(Data.civ2,0)
2716                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2717                            filecell=[];
2718                            return
[112]2719                        end
[2]2720                    elseif box_test(3)==0; %check the existence of patch if it is not calculated
[248]2721                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','patch')
2722                        if ~isempty(Data.CivStage)
2723                            if Data.CivStage<3 %test for civ files
2724                                msgbox_uvmat('ERROR',['no patch data in ' filename])
2725                                filecell=[];
2726                                return
2727                            end
2728                        elseif isempty(Data.patch)||isequal(Data.patch,0)
[2]2729                            msgbox_uvmat('ERROR',['no patch data in ' filename])
[12]2730                            filecell=[];
[2]2731                            return
2732                        end
[112]2733                    end
[2]2734                end
2735            end
2736        end
2737        if strcmp(compare,'stereo PIV')
2738            for ifile=1:nbfield
2739                for j=1:nbslice
2740                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2741                        nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2742                    filecell.ncA.civ2(ifile,j)={filename};
2743                    if ~exist(filename,'file')
2744                        msgbox_uvmat('ERROR',['input file ' filename ' not found'])
2745                        set(handles.RUN, 'Enable','On')
2746                        set(handles.RUN,'BackgroundColor',[1 0 0])
2747                        return
2748                    end
2749                end
2750            end
2751        end
2752    end
[112]2753   
2754    detect=1;
2755    %     while detect==1%creates a new subdir if the netcdf files already contain civ2 data
2756    for ifile=1:nbfield
2757        for j=1:nbslice
2758            filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[2]2759                nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);
[112]2760            detect=exist(filename,'file')==2;
2761            filecell.nc.civ2(ifile,j)={filename};
[2]2762        end
[112]2763    end
[2]2764    %get first image names for civ2
2765    if box_test(1)==1 & isequal(num1_civ1,num1_civ2) & isequal(num_a_civ1,num_a_civ2)
2766        filecell.ima1.civ2=filecell.ima1.civ1;
2767    elseif box_test(4)==1
2768        for ifile=1:nbfield
2769            for j=1:nbslice
2770                filename=name_generator(filebase_ima1, num1_civ2(ifile),num_a_civ2(j),ext_ima,nom_type_ima1);
2771                idetect_2(j)=exist(filename,'file')==2;
2772                filecell.ima1.civ2(ifile,j)={filename};%first image
2773            end
[112]2774            [idetectmin,indexj]=min(idetect_2);
[2]2775            if idetectmin==0,
[112]2776                msgbox_uvmat('ERROR',['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'])
2777                filecell=[];
2778                return
[2]2779            end
2780        end
2781    end
2782   
2783    %get second image names for civ2
2784    if box_test(1)==1 & isequal(num2_civ1,num2_civ2) & isequal(num_b_civ1,num_b_civ2)
2785        filecell.ima2.civ2=filecell.ima2.civ1;
2786    elseif box_test(4)==1
2787        for ifile=1:nbfield
2788            for j=1:nbslice
2789                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),ext_ima,nom_type_ima2);
2790                idetect_3(j)=exist(filename,'file')==2;
2791                filecell.ima2.civ2(ifile,j)={filename};%first image
2792            end
[112]2793            [idetectmin,indexj]=min(idetect_3);
[2]2794            if idetectmin==0,
[112]2795                msgbox_uvmat('ERROR',['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'])
2796                filecell=[];
2797                return
[2]2798            end
2799        end
2800    end
2801end
2802if (box_test(5)==1 || box_test(6)==1 ) && box_test(4)==0  % need to read an existing netcdf civ2 file
2803    if ~testdiff
2804        filecell.nc.civ2=filecell.nc.civ1;% file already checked
[112]2805    else     % check the civ2 files
[2]2806        for ifile=1:nbfield
2807            for j=1:nbslice
2808                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',...
[112]2809                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
[2]2810                filecell.nc.civ2(ifile,j)={filename};
2811                if ~exist(filename,'file')
2812                    msgbox_uvmat('ERROR',['input file ' filename ' not found'])
[12]2813                    filecell=[];
[2]2814                    return
2815                else
[248]2816                    Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
2817                    if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
2818                            msgbox_uvmat('ERROR',['no civ2 data in ' filename])
2819                            filecell=[];
2820                            return
2821                    elseif isempty(Data.civ2)||isequal(Data.civ2,0)
[2]2822                        msgbox_uvmat('ERROR',['no civ2 data in ' filename])
[12]2823                        filecell=[];
[2]2824                        return
2825                    end
2826                end
2827            end
2828        end
2829    end
2830end
2831
2832%%%%%%%%%%%%%  if stereo fields are calculated by PATCH %%%%%%%%%%%%%
2833if strcmp(compare,'stereo PIV')
[127]2834    if  box_test(3)==1 && isequal(get(handles.test_stereo1,'Value'),1)
[2]2835        for ifile=1:nbfield
2836            for j=1:nbslice
2837                filename=name_generator(filebase_AB,num1_civ1(ifile),num_a_civ1(j),'.nc',...
2838                    nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
2839                filecell.st(ifile,j)={filename};
2840            end
2841        end
2842    end
[127]2843    if  box_test(6)==1 && isequal(get(handles.test_stereo2,'Value'),1)
[2]2844        for ifile=1:nbfield
2845            for j=1:nbslice
2846                filename=name_generator(filebase_AB,num1_civ2(ifile),num_a_civ2(j),'.nc',...
2847                    nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2);%
2848                filecell.st(ifile,j)={filename};
2849            end
2850        end
[112]2851    end
[2]2852end
2853set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
2854set(handles.subdir_civ2,'String',subdir_civ2);%update the edit box
2855browse.nom_type_nc=nom_type_nc;
2856set(handles.browse_root,'UserData',browse); %update the nomenclature type for uvmat
2857
2858
2859%COPY IMAGES TO THE FORMAT .png IF NEEDED
[45]2860if isequal(nom_type_ima1,'*')%case of movie files
2861    nom_type_imanew1='_i';
[2]2862else
2863    nom_type_imanew1=nom_type_ima1;
2864end
[45]2865if isequal(nom_type_ima2,'*')%case of movie files
2866    nom_type_imanew2='_i';
[2]2867else
2868    nom_type_imanew2=nom_type_ima2;
2869end
2870if ~isequal(ext_ima,'.png')
[45]2871    %%type of image file
2872    type_ima1='none';%default
2873    movieobject1=[];%default
[133]2874    if strcmpi(ext_ima,'.avi')
[45]2875        hhh=which('mmreader');
2876        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2877            type_ima1='movie';
2878            movieobject1=mmreader([filebase_ima2 ext_ima]);
2879        else
2880            type_ima1='avi';
2881        end
[133]2882    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2883        form=imformats(ext_ima(2:end));
2884        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2885            if isequal(nom_type_ima1,'*');
2886                type_ima1='multimage';%image series in a single image file
2887            else
2888                type_ima1='image';
2889            end
2890        end
[45]2891    end
2892    type_ima2='none';%default
2893    movieobject2=[];
[133]2894    if strcmpi(ext_ima,'.avi')
[45]2895        hhh=which('mmreader');
2896        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
2897            type_ima2='movie';
2898            movieobject2=mmreader([filebase_ima2 ext_ima]);
2899        else
2900            type_ima2='avi';
2901        end
[133]2902    elseif ischar(ext_ima) && ~isempty(ext_ima(2:end))
[112]2903        form=imformats(ext_ima(2:end));
2904        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2905            if isequal(nom_type_ima1,'*');
2906                type_ima2='multimage';%image series in a single image file
2907            else
2908                type_ima2='image';
2909            end
2910        end
[45]2911    end
[71]2912    %npxy=get(handles.ImaExt,'UserData');
[112]2913    % %     if numel(npxy)<2
2914    %
2915    %         filename=name_generator(filebase_ima1,num1_civ1(1),num_a_civ1(1),ImaExt,nom_type_ima1);
2916    %         A=imread(filename);
2917    %         npxy=size(A);
2918    % %     end
2919    %     npy=npxy(1);
2920    %     npx=npxy(2);
[2]2921    if box_test(1)==1 %if civ1 is performed
[224]2922        h = waitbar(0,'copy images to the .png format for civ1');% display a wait bar
[112]2923        for ifile=1:nbfield
[2]2924            waitbar(ifile/nbfield);
2925            for j=1:nbslice
[112]2926                filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
2927                if ~exist(filename,'file')
2928                    A=read_image(filecell.ima1.civ1{ifile,j},type_ima1,num1_civ1(ifile),movieobject1);
2929                    imwrite(A,filename,'BitDepth',16);
2930                end
2931                filecell.ima1.civ1(ifile,j)={filename};
2932                filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
2933                if ~exist(filename,'file')
2934                    A=read_image(filecell.ima2.civ1{ifile,j},type_ima2,num2_civ1(ifile),movieobject2);
2935                    imwrite(A,filename,'BitDepth',16);
2936                end
2937                filecell.ima2.civ1(ifile,j)={filename};
[2]2938            end
2939        end
2940        close(h)
2941    end
2942    if box_test(4)==1 %if civ2 is performed
[229]2943        h = waitbar(0,'copy images to the .png format for civ2');% display a wait bar
[2]2944        for ifile=1:nbfield
2945            waitbar(ifile/nbfield);
2946            for j=1:nbslice
[112]2947                filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
2948                if ~exist(filename,'file')
2949                    A=read_image(cell2mat(filecell.ima1.civ2(ifile,j)),type_ima2,num1_civ2(ifile));
2950                    imwrite(A,filename,'BitDepth',16);
2951                end
2952                filecell.ima1.civ2(ifile,j)={filename};
2953                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
2954                if ~exist(filename,'file')
2955                    A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),type_ima2,num2_civ2(ifile));
2956                    imwrite(A,filename,'BitDepth',16);
2957                end
2958                filecell.ima2.civ2(ifile,j)={filename};
[2]2959            end
2960        end
2961        close(h);
2962    end
2963end
2964
[12]2965%------------------------------------------------------------------------
[227]2966% --- determine the list of index pairs of processing file
2967function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
2968    find_pair_indices(handles,ref_i,ref_j,mode)
2969%------------------------------------------------------------------------
2970
2971list_civ1=get(handles.list_pair_civ1,'String');
2972index_civ1=get(handles.list_pair_civ1,'Value');
2973str_civ1=list_civ1{index_civ1};%string defining the image pairs for civ1
2974if isempty(str_civ1)||isequal(str_civ1,'')
2975    msgbox_uvmat('ERROR','no image pair selected for civ1')
2976    return
2977end
2978list_civ2=get(handles.list_pair_civ2,'String');
2979index_civ2=get(handles.list_pair_civ2,'Value');
2980if index_civ2>length(list_civ2)
2981    list_civ2=list_civ1;
2982    index_civ2=index_civ1;
2983end
2984str_civ2=list_civ2{index_civ2};%string defining the image pairs for civ2
2985
2986if isequal (mode,'series(Di)')
2987    lastfield=str2double(get(handles.nb_field,'String'));
2988    num1_civ1=ref_i-floor(index_civ1/2)*ones(size(ref_i));% set of first image numbers
2989    num2_civ1=ref_i+ceil(index_civ1/2)*ones(size(ref_i));
2990    num_a_civ1=ref_j;
2991    num_b_civ1=ref_j;
[229]2992    num1_civ2=ref_i-floor(index_civ2/2)*ones(size(ref_i));
[227]2993    num2_civ2=ref_i+ceil(index_civ2/2)*ones(size(ref_i));
2994    num_a_civ2=ref_j;
2995    num_b_civ2=ref_j;   
2996   
2997    % adjust the first and last field number
2998    lastfield=str2double(get(handles.nb_field,'String'));
2999    if isnan(lastfield)
3000        indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
3001    else
3002        indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
3003    end
3004    if length(indsel)>=1
3005        firstind=indsel(1);
3006        lastind=indsel(end);
3007        set(handles.first_i,'String',num2str(ref_i(firstind)))%update the display of first and last fields
3008        set(handles.last_i,'String',num2str(ref_i(lastind)))
3009        ref_i=ref_i(indsel);
3010        num1_civ1=num1_civ1(indsel);
3011        num1_civ2=num1_civ2(indsel);
3012        num2_civ1=num2_civ1(indsel);
3013        num2_civ2=num2_civ2(indsel);
3014    end
3015elseif isequal (mode,'series(Dj)')
3016    lastfield_j=str2double(get(handles.nb_field2,'String'));
3017    num1_civ1=ref_i;% set of first image numbers
3018    num2_civ1=ref_i;
3019    num_a_civ1=ref_j-floor(index_civ1/2)*ones(size(ref_j));
3020    num_b_civ1=ref_j+ceil(index_civ1/2)*ones(size(ref_j));
3021    num1_civ2=ref_i;
3022    num2_civ2=ref_i;
3023    num_a_civ2=ref_j-floor(index_civ2/2)*ones(size(ref_j));
3024    num_b_civ2=ref_j+ceil(index_civ2/2)*ones(size(ref_j));
3025    % adjust the first and last field number
3026    if isnan(lastfield_j)
3027        indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
3028    else
3029        indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
3030    end
3031    if length(indsel)>=1
3032        firstind=indsel(1);
3033        lastind=indsel(end);
3034        set(handles.first_j,'String',num2str(ref_j(firstind)))%update the display of first and last fields
3035        set(handles.last_j,'String',num2str(ref_j(lastind)))
3036        ref_j=ref_j(indsel);
3037        num_a_civ1=num_a_civ1(indsel);
3038        num_b_civ1=num_b_civ1(indsel);
3039        num_a_civ2=num_a_civ2(indsel);
3040        num_b_civ2=num_b_civ2(indsel);
3041    end
3042elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
3043    displ_num=get(handles.list_pair_civ1,'UserData');
3044    num1_civ1=ref_i;
3045    num2_civ1=ref_i;
3046    num_a_civ1=displ_num(1,index_civ1);
3047    num_b_civ1=displ_num(2,index_civ1);
3048    num1_civ2=ref_i;
3049    num2_civ2=ref_i;
3050    num_a_civ2=displ_num(1,index_civ2);
3051    num_b_civ2=displ_num(2,index_civ2);
3052elseif isequal(mode,'displacement')
3053    num1_civ1=ref_i;
3054    num2_civ1=ref_i;
3055    num_a_civ1=ref_j;
3056    num_b_civ1=ref_j;
3057    num1_civ2=ref_i;
3058    num2_civ2=ref_i;
3059    num_a_civ2=ref_j;
3060    num_b_civ2=ref_j;
3061end
3062
3063
3064%------------------------------------------------------------------------
[12]3065% --- PATCH
[94]3066function cmd_PATCH=PATCH_CMD(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp,PatchBin)
[12]3067%------------------------------------------------------------------------
[224]3068namelog=[filename_nc(1:end-3) '_patch.log'];
[112]3069if test_interp==0
[163]3070    if isunix
[112]3071    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
3072        '  > ' namelog ' 2>&1']; % redirect standard output to the log file
[163]3073    else
3074      cmd_PATCH=['"' PatchBin '" -f "' filename_nc '" -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
3075        '  > "' namelog '" 2>&1']; % redirect standard output to the log file
3076    end
[112]3077else %nouveau programme patch
3078    cmd_PATCH=[PatchBin ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
3079        ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
3080end
[163]3081cmd_PATCH=regexprep(cmd_PATCH,'\\','\\\\');
[12]3082%------------------------------------------------------------------------
3083% --- STEREO Interp
[67]3084function 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]3085%------------------------------------------------------------------------
[224]3086namelog=[filename_nc(1:end-3) '_stinterp.log'];
[67]3087cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
[2]3088    ' -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
3089
[12]3090%------------------------------------------------------------------------
[2]3091% --- Executes on button press in CIV1.
3092function CIV1_Callback(hObject, eventdata, handles)
[12]3093%------------------------------------------------------------------------
[2]3094val=get(handles.CIV1,'Value');
3095if isequal(val,1)
3096    enable_civ1(handles,'on')
3097    enable_pair1(handles,'on')
3098else
3099    enable_civ1(handles,'off')
3100end
3101find_netcpair_civ1(hObject, eventdata, handles);
3102
[12]3103%------------------------------------------------------------------------
[2]3104% --- Executes on button press in FIX1.
3105function FIX1_Callback(hObject, eventdata, handles)
[12]3106%------------------------------------------------------------------------
[2]3107enable_fix1(handles,get(handles.FIX1,'Value'))
3108
[12]3109%------------------------------------------------------------------------
[2]3110% --- Executes on button press in PATCH1.
3111function PATCH1_Callback(hObject, eventdata, handles)
[12]3112%------------------------------------------------------------------------
[2]3113if get(handles.PATCH1,'Value')==1
[12]3114    enable_patch1(handles)
[2]3115else
[12]3116    desable_patch1(handles)
[2]3117end
3118
[12]3119%------------------------------------------------------------------------
[2]3120% --- Executes on button press in CIV2.
3121function CIV2_Callback(hObject, eventdata, handles)
[12]3122%------------------------------------------------------------------------
[2]3123state=get(handles.CIV2,'Value');
3124enable_civ2(handles,state)
3125if state
3126    find_netcpair_civ2(hObject, eventdata, handles)
3127    enable_pair1(handles,'on')
3128end
3129
[12]3130%------------------------------------------------------------------------
[2]3131% --- Executes on button press in FIX2.
3132function FIX2_Callback(hObject, eventdata, handles)
[12]3133%------------------------------------------------------------------------
[2]3134if get(handles.FIX2,'Value')==1
3135    enable_fix2(handles)
3136    if get(handles.CIV2,'Value')==0
3137        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
3138    end
3139else
3140    desable_fix2(handles)
3141end
3142
[12]3143%------------------------------------------------------------------------
[2]3144% --- Executes on button press in PATCH2.
3145function PATCH2_Callback(hObject, eventdata, handles)
[12]3146%------------------------------------------------------------------------
[2]3147if get(handles.PATCH2,'Value')==1
3148    enable_patch2(handles)
3149    if get(handles.CIV2,'Value')==0
3150        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
3151    end
3152else
3153    desable_patch2(handles)
3154end
3155
[12]3156%------------------------------------------------------------------------
3157function first_i_Callback(hObject, eventdata, handles)
3158%------------------------------------------------------------------------
3159% last_i_Callback(hObject, eventdata, handles)
[137]3160first_i=str2double(get(handles.first_i,'String'));
[12]3161% last_i=str2num(get(handles.last_i,'String'));
3162% ref_i=ceil((first_i+last_i)/2);
3163set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
[71]3164set(handles.ref_i_civ2,'String', num2str(first_i))% reference index for pair dt = first index
[12]3165ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3166
[12]3167%------------------------------------------------------------------------
3168function first_j_Callback(hObject, eventdata, handles)
3169%------------------------------------------------------------------------
3170first_j=str2num(get(handles.first_j,'String'));
3171set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
3172ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
[2]3173
[12]3174%------------------------------------------------------------------------
[2]3175% --- Executes on button press in calcul_search: determine the search range isx,isy
3176function calcul_search_Callback(hObject, eventdata, handles)
[12]3177%------------------------------------------------------------------------
[2]3178%determine pair numbers
3179list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
3180index=get(handles.list_pair_civ1,'Value');
3181displ_num=get(handles.list_pair_civ1,'UserData');
[71]3182time=get(handles.RootName,'UserData'); %get the set of times
[2]3183pxcm_xy=get(handles.calcul_search,'UserData');
3184pxcmx=pxcm_xy(1);
3185pxcmy=pxcm_xy(2);
3186mode_list=get(handles.mode,'String');
3187mode_value=get(handles.mode,'Value');
3188mode=mode_list{mode_value};
3189if isequal (mode, 'series(Di)' )
[137]3190    ref_i=str2double(get(handles.ref_i,'String'));
[2]3191    num1=ref_i-floor(index/2);%  first image numbers
3192    num2=ref_i+ceil(index/2);
3193    num_a=1;
3194    num_b=1;
[112]3195elseif isequal (mode, 'series(Dj)')
[2]3196    num1=1;
3197    num2=1;
[137]3198    ref_j=str2double(get(handles.ref_j,'String'));
[2]3199    num_a=ref_j-floor(index/2);%  first image numbers
3200    num_b=ref_j+ceil(index/2);
3201elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
[137]3202    ref_i=str2double(get(handles.ref_i,'String'));
[2]3203    num1=ref_i;
3204    num2=ref_i;
3205    num_a=displ_num(1,index);
3206    num_b=displ_num(2,index);
3207end
3208dt=time(num2,num_b)-time(num1,num_a);
[137]3209ibx=str2double(get(handles.ibx,'String'));
3210iby=str2double(get(handles.iby,'String'));
3211umin=dt*pxcmx*str2double(get(handles.umin,'String'));
3212umax=dt*pxcmx*str2double(get(handles.umax,'String'));
3213vmin=dt*pxcmy*str2double(get(handles.vmin,'String'));
3214vmax=dt*pxcmy*str2double(get(handles.vmax,'String'));
[2]3215shiftx=round((umin+umax)/2);
3216shifty=round((vmin+vmax)/2);
3217isx=(umax+2-shiftx)*2+ibx;
3218isx=2*ceil(isx/2)+1;
3219isy=(vmax+2-shifty)*2+iby;
3220isy=2*ceil(isy/2)+1;
3221set(handles.shiftx,'String',num2str(shiftx));
3222set(handles.shifty,'String',num2str(shifty));
3223set(handles.isx,'String',num2str(isx));
3224set(handles.isy,'String',num2str(isy));
3225
[12]3226%------------------------------------------------------------------------
3227% --- Executes on carriage return on the subdir civ1 edit window
[2]3228function subdir_civ1_Callback(hObject, eventdata, handles)
[12]3229%------------------------------------------------------------------------
[2]3230subdir=get(handles.subdir_civ1,'String');
3231set(handles.subdir_civ2,'String',subdir);
[112]3232if get(handles.CIV1,'Value')==0
[2]3233    find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
3234end
3235
[12]3236%------------------------------------------------------------------------
3237% --- Executes on carriage return on the subdir civ1 edit window
[2]3238function subdir_civ2_Callback(hObject, eventdata, handles)
[12]3239%------------------------------------------------------------------------
[2]3240%update the list of available pairs from netcdf files in the new directory
3241if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
3242    find_netcpair_civ2(hObject, eventdata, handles);
3243end
3244
[12]3245%------------------------------------------------------------------------
[133]3246% --- Executes on button press in get_mask_civ1: select box for mask option
[2]3247function get_mask_civ1_Callback(hObject, eventdata, handles)
[12]3248%------------------------------------------------------------------------
[2]3249maskval=get(handles.get_mask_civ1,'Value');
3250if isequal(maskval,0)
3251    set(handles.mask_civ1,'String','')
3252else
3253    mask_displ='no mask'; %default
[71]3254    filebase=get(handles.RootName,'String');
[2]3255    [ nbslice_mask, flag_mask]=get_mask(filebase,handles);
3256    if isequal(flag_mask,1)
[112]3257        mask_displ=[num2str(nbslice_mask) 'mask'];
[2]3258    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[112]3259        common_path=fileparts(filebase);
3260        filebase_a=fullfile(common_path,get(handles.RootName_1,'String'));
3261        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
3262        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice_mask)
3263            mask_displ='no mask';
3264        end
[2]3265    end
3266    if isequal(mask_displ,'no mask')
[12]3267        [FileName, PathName, filterindex] = uigetfile( ...
[112]3268            {'*.png', ' (*.png)';
3269            '*.png',  '.png files '; ...
3270            '*.*', 'All Files (*.*)'}, ...
3271            'Pick a mask file *.png',filebase);
3272        mask_displ=fullfile(PathName,FileName);
[12]3273        if ~exist(mask_displ,'file')
3274            mask_displ='no mask';
3275        end
3276    end
3277    if isequal(mask_displ,'no mask')
[2]3278        set(handles.get_mask_civ1,'Value',0)
3279        set(handles.get_mask_fix1,'Value',0)
3280        set(handles.get_mask_civ2,'Value',0)
3281        set(handles.get_mask_fix2,'Value',0)
3282    else
3283        set(handles.get_mask_fix1,'Value',1)
3284        set(handles.get_mask_fix2,'Value',1)
3285    end
3286    set(handles.mask_civ1,'String',mask_displ)
3287    set(handles.mask_fix1,'String',mask_displ)
3288    set(handles.mask_civ2,'String',mask_displ)
3289    set(handles.mask_fix2,'String',mask_displ)
3290end
[133]3291set(handles.get_mask_civ2,'Value',maskval)%update the civ2 mask with the same option as civ1
[2]3292
[12]3293%------------------------------------------------------------------------
[2]3294% --- Executes on button press in get_mask_fix1.
3295function get_mask_fix1_Callback(hObject, eventdata, handles)
[12]3296%------------------------------------------------------------------------
[2]3297maskval=get(handles.get_mask_fix1,'Value');
3298if isequal(maskval,0)
3299    set(handles.mask_fix1,'String','')
3300else
[112]3301    mask_displ='no mask'; %default
3302    filebase=get(handles.RootName,'String');
3303    [nbslice, flag_mask]=get_mask(filebase,handles);
3304    if isequal(flag_mask,1)
3305        mask_displ=[num2str(nbslice) 'mask'];
3306    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3307        filebase_a=get(handles.RootName_1,'String');
[2]3308        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3309        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[2]3310            mask_displ='no mask';
3311        end
[112]3312    end
3313    if isequal(mask_displ,'no mask')
3314        [FileName, PathName, filterindex] = uigetfile( ...
3315            {'*.png', ' (*.png)';
[12]3316            '*.png',  '.png files '; ...
3317            '*.*', 'All Files (*.*)'}, ...
3318            'Pick a mask file *.png',filebase);
[112]3319        mask_displ=fullfile(PathName,FileName);
3320        if ~exist(mask_displ,'file')
3321            mask_displ='no mask';
3322        end
[12]3323    end
[112]3324    if isequal(mask_displ,'no mask')
3325        set(handles.get_mask_fix1,'Value',0)
3326        set(handles.get_mask_civ2,'Value',0)
3327        set(handles.get_mask_fix2,'Value',0)
3328    else
3329        %set(handles.get_mask_civ2,'Value',1)
3330        set(handles.get_mask_fix2,'Value',1)
3331    end
3332    set(handles.mask_fix1,'String',mask_displ)
3333    set(handles.mask_civ2,'String',mask_displ)
3334    set(handles.mask_fix2,'String',mask_displ)
[12]3335end
3336
3337%------------------------------------------------------------------------
[133]3338% --- Executes on button press in get_mask_civ2: select box for mask option
[2]3339function get_mask_civ2_Callback(hObject, eventdata, handles)
[12]3340%------------------------------------------------------------------------
[2]3341maskval=get(handles.get_mask_civ2,'Value');
3342if isequal(maskval,0)
3343    set(handles.mask_civ2,'String','')
3344else
[112]3345    mask_displ='no mask'; %default
3346    filebase=get(handles.RootName,'String');
3347    [nbslice, flag_mask]=get_mask(filebase,handles);
3348    if isequal(flag_mask,1)
3349        mask_displ=[num2str(nbslice) 'mask'];
3350    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[71]3351        filebase_a=get(handles.RootName_1,'String');
[2]3352        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3353        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[2]3354            mask_displ='no mask';
3355        end
[112]3356    end
3357    if isequal(mask_displ,'no mask')
3358        [FileName, PathName, filterindex] = uigetfile( ...
3359            {'*.png', ' (*.png)';
[12]3360            '*.png',  '.png files '; ...
3361            '*.*', 'All Files (*.*)'}, ...
3362            'Pick a mask file *.png',filebase);
[112]3363        mask_displ=fullfile(PathName,FileName);
3364        if ~exist(mask_displ,'file')
3365            mask_displ='no mask';
3366        end
[12]3367    end
[112]3368    if isequal(mask_displ,'no mask')
3369        set(handles.get_mask_civ2,'Value',0)
3370        set(handles.get_mask_fix2,'Value',0)
3371    else
3372        set(handles.get_mask_fix2,'Value',1)
3373    end
3374    set(handles.mask_civ2,'String',mask_displ)
3375    set(handles.mask_fix2,'String',mask_displ)
[12]3376end
3377
3378%------------------------------------------------------------------------
[2]3379% --- Executes on button press in get_mask_fix2.
3380function get_mask_fix2_Callback(hObject, eventdata, handles)
[12]3381%------------------------------------------------------------------------
[2]3382maskval=get(handles.get_mask_fix2,'Value');
3383if isequal(maskval,0)
3384    set(handles.mask_fix2,'String','')
3385else
[12]3386    mask_displ='no mask'; %default
[71]3387    filebase=get(handles.RootName,'String');
[12]3388    [nbslice, flag_mask]=get_mask(filebase,handles);
3389    if isequal(flag_mask,1)
[112]3390        mask_displ=[num2str(nbslice) 'mask'];
[12]3391    elseif get(handles.compare,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
[112]3392        filebase_a=get(handles.RootName_1,'String');
3393        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
[229]3394        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
[112]3395            mask_displ='no mask';
3396        end
[12]3397    end
3398    if isequal(mask_displ,'no mask')
3399        [FileName, PathName, filterindex] = uigetfile( ...
[112]3400            {'*.png', ' (*.png)';
3401            '*.png',  '.png files '; ...
3402            '*.*', 'All Files (*.*)'}, ...
3403            'Pick a mask file *.png',filebase);
3404        mask_displ=fullfile(PathName,FileName);
[12]3405        if ~exist(mask_displ,'file')
[2]3406            mask_displ='no mask';
3407        end
[12]3408    end
3409    if isequal(mask_displ,'no mask')
3410        set(handles.get_mask_fix2,'Value',0)
[112]3411    end
[12]3412    set(handles.mask_fix2,'String',mask_displ)
[2]3413end
3414
[12]3415%------------------------------------------------------------------------
3416% --- function called to look for mask files
[2]3417function [nbslice, flag_mask]=get_mask(filebase,handles)
[12]3418%------------------------------------------------------------------------
[112]3419%detect mask files, images with appropriate file base
[2]3420%[filebase '_' xx 'mask'], xx=nbslice
3421%flag_mask=1 indicates detection
3422
3423flag_mask=0;%default
3424nbslice=1;
3425
3426% subdir=get(handles.subdir_civ1,'String');
3427[Path,Name]=fileparts(filebase);
[12]3428if ~isdir(Path)
3429    msgbox_uvmat('ERROR','no path for input files')
3430    return
3431end
[2]3432currentdir=pwd;
3433cd(Path);%move in the dir of the root name filebase
3434maskfiles=dir([Name '_*mask_*.png']);%look for mask files
3435cd(currentdir);%come back to the current working directory
[12]3436if ~isempty(maskfiles)
[112]3437    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
3438    % else
[2]3439    flag_mask=1;
3440    maskname=maskfiles(1).name;% take the first mask file in the list
3441    [Path2,Name,ext]=fileparts(maskname);
3442    Namedouble=double(Name);
3443    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3444    ind_mask=findstr('mask',Name);
3445    i=ind_mask-1;
[137]3446    while val(i)==0 && i>0
[112]3447        i=i-1;
[2]3448    end
[137]3449    nbslice=str2double(Name(i+1:ind_mask-1));
3450    if ~isnan(nbslice) && Name(i)=='_'
[112]3451        flag_mask=1;
[2]3452    else
[112]3453        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
3454        return
3455        nbslice=1;
[2]3456    end
[112]3457end
[2]3458
[12]3459%------------------------------------------------------------------------
3460% --- function called to look for grid files
[2]3461function [nbslice, flag_mask]=get_grid(filebase,handles)
[12]3462%------------------------------------------------------------------------
[2]3463flag_mask=0;%default
3464nbslice=1;
3465[Path,Name]=fileparts(filebase);
3466currentdir=pwd;
3467cd(Path);%move in the dir of the root name filebase
3468maskfiles=dir([Name '_*grid_*.grid']);%look for mask files
3469cd(currentdir);%come back to the current working directory
3470if ~isempty(maskfiles)
3471    flag_mask=1;
3472    maskname=maskfiles(1).name;% take the first mask file in the list
3473    [Path2,Name,ext]=fileparts(maskname);
3474    Namedouble=double(Name);
3475    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
3476    ind_mask=findstr('grid',Name);
3477    i=ind_mask-1;
[137]3478    while val(i)==0 && i>0
[112]3479        i=i-1;
[2]3480    end
[137]3481    nbslice=str2double(Name(i+1:ind_mask-1));
3482    if ~isnan(nbslice) && Name(i)=='_'
[112]3483        flag_mask=1;
[2]3484    else
[112]3485        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
3486        return
3487        nbslice=1;
[2]3488    end
[12]3489end
[2]3490
[12]3491%------------------------------------------------------------------------
3492% --- transform numbers to letters
[122]3493function str=num2stra(num,nom_type)
[12]3494%------------------------------------------------------------------------
[122]3495if isempty(nom_type)
3496    str='';
3497elseif strcmp(nom_type(end),'a')
[2]3498    str=char(96+num);
[122]3499elseif strcmp(nom_type(end),'A')
3500    str=char(96+num);
3501elseif isempty(nom_type(2:end))%a single index
[2]3502    str='';
3503else
3504    str=num2str(num);
3505end
[12]3506
[173]3507% %------------------------------------------------------------------------
3508% function mask_civ1_Callback(hObject, eventdata, handles)
3509% %------------------------------------------------------------------------
3510% set(handles.mask_civ1,'UserData',[])
3511% set(handles.mask_civ1,'String','')
3512%
3513% %------------------------------------------------------------------------
3514% function mask_civ2_Callback(hObject, eventdata, handles)
3515% %------------------------------------------------------------------------
3516% set(handles.mask_civ2,'UserData',[])
3517% set(handles.mask_civ2,'String','')
3518%
3519% %------------------------------------------------------------------------
3520% function mask_fix1_Callback(hObject, eventdata, handles)
3521% %------------------------------------------------------------------------
3522% set(handles.mask_fix1,'UserData',[])
3523% set(handles.mask_fix1,'String','')
3524%
3525% %------------------------------------------------------------------------
3526% function mask_fix2_Callback(hObject, eventdata, handles)
3527% %------------------------------------------------------------------------
3528% set(handles.mask_fix2,'UserData',[])
3529% set(handles.mask_fix2,'String','')
[12]3530
3531%------------------------------------------------------------------------
[2]3532% --- Executes on button press in list_subdir_civ1.
3533function list_subdir_civ1_Callback(hObject, eventdata, handles)
[12]3534%------------------------------------------------------------------------
[2]3535list_subdir_civ1=get(handles.list_subdir_civ1,'String');
3536val=get(handles.list_subdir_civ1,'Value');
3537if val>1
3538    subdir=list_subdir_civ1{val};
3539    set(handles.subdir_civ1,'String',subdir);
3540    set(handles.list_subdir_civ1,'Value',1);
3541end
3542
[12]3543%------------------------------------------------------------------------
[2]3544% --- Executes on button press in list_subdir_civ2.
3545function list_subdir_civ2_Callback(hObject, eventdata, handles)
[12]3546%------------------------------------------------------------------------
[2]3547list_subdir_civ2=get(handles.list_subdir_civ2,'String');
3548val=get(handles.list_subdir_civ2,'Value');
3549if val>1
3550    subdir=list_subdir_civ2{val};
3551    set(handles.subdir_civ2,'String',subdir);
3552    set(handles.list_subdir_civ2,'Value',1);
3553end
3554
[12]3555%------------------------------------------------------------------------
[2]3556% --- Executes on button press in browse_gridciv1.
3557function browse_gridciv1_Callback(hObject, eventdata, handles)
[12]3558%------------------------------------------------------------------------
[2]3559value=get(handles.browse_gridciv1,'Value');
3560testgrid=0;
3561if value
[112]3562    filebase=get(handles.RootName,'String');
[39]3563    [nbslice, flag_grid]=get_grid(filebase,handles);
[2]3564    if isequal(flag_grid,1)
[112]3565        filegrid=[num2str(nbslice) 'grid'];
3566        testgrid=1;
3567    else
[2]3568        [FileName, PathName, filterindex] = uigetfile( ...
[112]3569            {'*.grid', ' (*.grid)';
3570            '*.grid',  '.grid files '; ...
3571            '*.*', 'All Files (*.*)'}, ...
3572            'Pick a file',filebase);
[2]3573        filegrid=fullfile(PathName,FileName);
3574        if ~(isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file'))
3575            testgrid=1;
3576        end
[112]3577    end
[2]3578end
3579if testgrid
[112]3580    set(handles.browse_gridciv2,'Value',1)
3581    set(handles.get_gridpatch1,'Value',1)
3582    set(handles.get_gridpatch2,'Value',1)
3583    set(handles.dx_civ1,'Visible','off');
3584    set(handles.dy_civ1,'Visible','off');
3585    set(handles.dx_civ2,'Visible','off');
3586    set(handles.dy_civ2,'Visible','off');
3587    set(handles.grid_civ1,'String',filegrid)
3588    set(handles.grid_patch1,'String',filegrid)
3589    set(handles.grid_civ2,'String',filegrid)
3590    set(handles.grid_patch2,'String',filegrid)
3591else
3592    set(handles.browse_gridciv1,'Value',0);
3593    set(handles.browse_gridciv2,'Value',0);
3594    set(handles.get_gridpatch1,'Value',0)
3595    set(handles.get_gridpatch2,'Value',0)
3596    set(handles.dx_civ1,'Visible','on');
3597    set(handles.dy_civ1,'Visible','on');
3598    set(handles.dx_civ2,'Visible','on');
3599    set(handles.dy_civ2,'Visible','on');
3600    set(handles.grid_civ1,'String','')
3601    set(handles.grid_patch1,'String','')
3602    set(handles.grid_civ2,'String','')
3603    set(handles.grid_patch2,'String','')
[2]3604end
3605
[12]3606%------------------------------------------------------------------------
[2]3607% --- Executes on button press in browse_gridciv1.
3608function browse_gridciv2_Callback(hObject, eventdata, handles)
[12]3609%------------------------------------------------------------------------
[2]3610value=get(handles.browse_gridciv2,'Value');
3611if value
[112]3612    filebase=get(handles.RootName,'String');
[39]3613    [nbslice, flag_grid]=get_grid(filebase,handles);
[2]3614    if isequal(flag_grid,1)
3615        mask_displ=[num2str(nbslice) 'grid'];
3616        set(handles.grid_civ2,'String',mask_displ)
3617        set(handles.dx_civ2,'Visible','off');
3618        set(handles.dy_civ2,'Visible','off');
[112]3619    else
[2]3620        [FileName, PathName, filterindex] = uigetfile( ...
[112]3621            {'*.grid', ' (*.grid)';
3622            '*.grid',  '.grid files '; ...
3623            '*.*', 'All Files (*.*)'}, ...
3624            'Pick a file',filebase);
[2]3625        filegrid=fullfile(PathName,FileName);
[229]3626        if isempty(FileName)||isempty(PathName)||isequal(FileName,0)||~exist(filegrid,'file')
[2]3627            set(handles.browse_gridciv2,'Value',0);
3628            set(handles.grid_civ2,'string','');
3629            set(handles.dx_civ2,'Visible','on');
3630            set(handles.dy_civ2,'Visible','on');
3631            set(handles.grid_civ2,'string','');
3632        else
3633            set(handles.grid_civ2,'string',filegrid);
3634            set(handles.dx_civ2,'Visible','off');
3635            set(handles.dy_civ2,'Visible','off');
3636            set(handles.grid_civ2,'string',filegrid);
3637        end
3638    end
3639else
3640    set(handles.grid_civ2,'string','');
[112]3641    set(handles.dx_civ2,'Visible','on');
3642    set(handles.dy_civ2,'Visible','on');
3643    set(handles.grid_civ2,'string','');
[2]3644end
3645
3646% % --- Executes on button press in browse_gridciv2.
3647% function browse_gridciv2_Callback(hObject, eventdata, handles)
[112]3648%
[71]3649% filebase=get(handles.RootName,'String');
[2]3650% [FileName, PathName, filterindex] = uigetfile( ...
3651%        {'*.grid', ' (*.grid)';
3652%         '*.grid',  '.grid files '; ...
3653%         '*.*', 'All Files (*.*)'}, ...
3654%         'Pick a file',filebase);
3655% filegrid=fullfile(PathName,FileName);
3656% set(handles.grid_civ2,'string',filegrid);
3657% set(handles.dx_civ2,'String',' ');
3658% set(handles.dy_civ2,'String',' ');
3659% % set(handles.grid_patch2,'string',filegrid);
3660
3661% --- Executes on button press in get_gridpatch1.
3662function get_gridpatch1_Callback(hObject, eventdata, handles)
3663% hObject    handle to get_gridpatch1 (see GCBO)
3664% eventdata  reserved - to be defined in a future version of MATLAB
3665% handles    structure with handles and user data (see GUIDATA)
3666
[71]3667filebase=get(handles.RootName,'String');
[2]3668[FileName, PathName, filterindex] = uigetfile( ...
[112]3669    {'*.grid', ' (*.grid)';
3670    '*.grid',  '.grid files '; ...
3671    '*.*', 'All Files (*.*)'}, ...
3672    'Pick a file',filebase);
[2]3673filegrid=fullfile(PathName,FileName);
3674set(handles.grid_patch1,'string',filegrid);
3675% set(handles.grid_patch2,'string',filegrid
3676
[12]3677%------------------------------------------------------------------------
[2]3678% --- Executes on button press in get_gridpatch2.
3679function get_gridpatch2_Callback(hObject, eventdata, handles)
[12]3680%------------------------------------------------------------------------
[2]3681
[12]3682%------------------------------------------------------------------------
[2]3683function enable_civ1(handles,state)
[12]3684%------------------------------------------------------------------------
[2]3685if isequal(state,'on')
3686    set(handles.frame_civ1,'BackgroundColor',[1 1 0])
3687    set(handles.frame_para_civ1,'BackgroundColor',[1 1 0])
3688    set(handles.frame_grid_civ1,'BackgroundColor',[1 1 0])
3689else
3690    set(handles.frame_civ1,'BackgroundColor',[0.831 0.816 0.784])
3691    set(handles.frame_para_civ1,'BackgroundColor',[0.831 0.816 0.784])
3692    set(handles.frame_grid_civ1,'BackgroundColor',[0.831 0.816 0.784])
3693end
3694set(handles.ibx,'Visible',state)
3695set(handles.iby,'Visible',state)
3696set(handles.isx,'Visible',state)
3697set(handles.isy,'Visible',state)
3698set(handles.shiftx,'Visible',state)
3699set(handles.shifty,'Visible',state)
3700set(handles.rho,'Visible',state)
3701set(handles.dx_civ1,'Visible',state)
3702set(handles.dy_civ1,'Visible',state)
3703set(handles.calcul_search,'Visible',state)
3704set(handles.u_text,'Visible',state)
3705set(handles.v_text,'Visible',state)
3706set(handles.min,'Visible',state)
3707set(handles.max,'Visible',state)
3708set(handles.umin,'Visible',state)
3709set(handles.umax,'Visible',state)
3710set(handles.vmin,'Visible',state)
3711set(handles.vmax,'Visible',state)
3712set(handles.grid_civ1,'Visible',state)
3713set(handles.mask_civ1,'Visible',state)
3714set(handles.browse_gridciv1,'Visible',state)
3715set(handles.get_mask_civ1,'Visible',state)
3716set(handles.parameters,'Visible',state)
3717set(handles.grid,'Visible',state)
3718set(handles.dx_civ1,'Visible',state)
3719set(handles.dy_civ1,'Visible',state)
3720set(handles.ImaThreshold,'Visible',state)
3721if isequal(state,'off')
3722    set(handles.MinIma,'Visible','off')
3723    set(handles.MaxIma,'Visible','off')
3724    set(handles.ImaThreshold,'Value',0)
3725end
3726set(handles.dx_civ1_title,'Visible',state)
3727set(handles.dy_civ1_title,'Visible',state)
3728set(handles.ImaThreshold_title,'Visible',state)
3729set(handles.ib_title,'Visible',state)
3730set(handles.is_title,'Visible',state)
3731set(handles.shift_title,'Visible',state)
3732set(handles.rho_title,'Visible',state)
[224]3733set(handles.TestCiv1,'Visible',state)
3734%set(handles.CivAll,'Visible',state)
[2]3735
[12]3736%------------------------------------------------------------------------
[2]3737function enable_fix1(handles,state)
[12]3738%------------------------------------------------------------------------
[2]3739if isequal(state,0)
3740    state='off';
3741end
3742if isequal(state,1)
3743    state='on';
3744end
3745if isequal(state,'on')
3746    set(handles.frame_fix1,'BackgroundColor',[1 1 0])
3747else
3748    set(handles.frame_fix1,'BackgroundColor',[0.7 0.7 0.7])
3749end
3750set(handles.REMOVE,'Visible',state)
3751set(handles.vec_Fmin2,'Visible',state)
3752set(handles.vec_F2,'Visible',state)
3753set(handles.vec_F3,'Visible',state)
3754set(handles.thresh_vecC,'Visible',state)
3755set(handles.thresh_vecC_title,'Visible',state)
3756set(handles.thresh_vel,'Visible',state)
3757set(handles.thresh_vel_text,'Visible',state)
3758set(handles.mask_fix1,'Visible',state)
3759set(handles.get_mask_fix1,'Visible',state)
3760set(handles.get_ref_fix1,'Visible',state)
3761set(handles.ref_fix1,'Visible',state)
3762set(handles.inf_sup1,'Visible',state)
3763set(handles.field_ref1,'Visible',state)
3764
[12]3765%------------------------------------------------------------------------
[2]3766function enable_patch1(handles)
[12]3767%------------------------------------------------------------------------
[2]3768set(handles.frame_patch1,'BackgroundColor',[1 1 0])
3769set(handles.rho_patch1,'Visible','on')
3770set(handles.rho_text1,'Visible','on')
[225]3771if get(handles.CivAll,'Value')==2
[224]3772    set(handles.thresh_patch1,'Visible','on')
3773    set(handles.thresh_text1,'Visible','on')
3774end
[2]3775set(handles.subdomain_patch1,'Visible','on')
3776set(handles.subdomain_text1,'Visible','on')
3777set(handles.nx_patch1,'Visible','on')
3778set(handles.ny_patch1,'Visible','on')
3779set(handles.nx_patch1_title,'Visible','on')
3780set(handles.ny_patch1_title,'Visible','on')
[112]3781% if ~isempty(patch_newBin)
[224]3782set(handles.test_interp,'Visible','off');
[100]3783% end
[2]3784set(handles.get_gridpatch1,'Visible','on')
3785set(handles.grid_patch1,'string','none');
3786set(handles.grid_patch1,'Visible','on')
3787
[12]3788%------------------------------------------------------------------------
[2]3789function desable_patch1(handles)
[12]3790%------------------------------------------------------------------------
[2]3791set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
3792set(handles.rho_patch1,'Visible','off')
3793set(handles.rho_text1,'Visible','off')
3794set(handles.thresh_patch1,'Visible','off')
3795set(handles.thresh_text1,'Visible','off')
3796set(handles.subdomain_patch1,'Visible','off')
3797set(handles.subdomain_text1,'Visible','off')
3798set(handles.nx_patch1,'Visible','off')
3799set(handles.ny_patch1,'Visible','off')
3800set(handles.nx_patch1_title,'Visible','off')
3801set(handles.ny_patch1_title,'Visible','off')
[100]3802%set(handles.test_interp,'Visible','off')
[2]3803set(handles.get_gridpatch1,'Visible','off')
3804set(handles.grid_patch1,'Visible','off')
3805
[12]3806%------------------------------------------------------------------------
[2]3807function enable_civ2(handles,state)
[12]3808%------------------------------------------------------------------------
[2]3809if isequal(state,0)
3810    state='off';
3811end
3812if isequal(state,1)
3813    state='on';
3814end
3815if isequal(state,'on')
3816    set(handles.frame_civ2,'BackgroundColor',[1 1 0])
3817    set(handles.frame_para_civ2,'BackgroundColor',[1 1 0])
3818    set(handles.frame_grid_civ2,'BackgroundColor',[1 1 0])
3819    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
3820else
3821    set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
3822    set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
3823    set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
3824    set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
3825end
3826set(handles.ibx_civ2,'Visible',state)
3827set(handles.iby_civ2,'Visible',state)
3828set(handles.decimal,'Visible',state)
3829set(handles.deformation,'Visible',state)
3830set(handles.rho_civ2,'Visible',state)
3831set(handles.dx_civ2,'Visible',state)
3832set(handles.dy_civ2,'Visible',state)
3833set(handles.browse_gridciv2,'Visible',state)
3834set(handles.get_mask_civ2,'Visible',state)
3835set(handles.parameters,'Visible',state)
3836set(handles.grid,'Visible',state)
3837set(handles.parameters_text,'Visible',state)
3838set(handles.grid_text,'Visible',state)
3839set(handles.grid_civ2,'Visible',state)
3840set(handles.mask_civ2,'Visible',state)
3841set(handles.dx_civ2_title,'Visible',state)
3842set(handles.dy_civ2_title,'Visible',state)
3843set(handles.ibx_civ2_text,'Visible',state)
3844set(handles.rho_civ2_title,'Visible',state)
3845set(handles.ImaThreshold2,'Visible',state)
3846set(handles.ImaThreshold_title2,'Visible',state)
3847if isequal(state,'off')
3848    set(handles.MinIma2,'Visible','off')
3849    set(handles.MaxIma2,'Visible','off')
3850    set(handles.ImaThreshold2,'Value',0)
[112]3851    if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
[2]3852        set(handles.list_pair_civ2,'Visible','off')
3853        set(handles.subdir_civ2,'Visible','off')
3854        set(handles.subdir_civ2_text,'Visible','off')
[71]3855        set(handles.dt_unit_civ2,'Visible','off')
3856        set(handles.ref_i_civ2,'Visible','off')
3857        set(handles.i_ref_civ2_title,'Visible','off')
3858        set(handles.j_ref_civ2_title,'Visible','off')
3859        set(handles.ref_j_civ2,'Visible','off')
[2]3860    end
3861else
3862    set(handles.list_pair_civ2,'Visible','on')
3863    set(handles.subdir_civ2,'Visible','on')
3864    set(handles.subdir_civ2_text,'Visible','on')
[71]3865    set(handles.dt_unit_civ2,'Visible','on')
3866    set(handles.ref_i_civ2,'Visible','on')
3867    set(handles.i_ref_civ2_title,'Visible','on')
3868    set(handles.j_ref_civ2_title,'Visible','on')
3869    set(handles.ref_j_civ2,'Visible','on')
[2]3870end
[71]3871set(handles.rho_civ2_title,'Visible',state)
[2]3872
[12]3873%------------------------------------------------------------------------
[2]3874function enable_fix2(handles)
[12]3875%------------------------------------------------------------------------
[2]3876set(handles.frame_fix2,'BackgroundColor',[1 1 0])
3877set(handles.REMOVE2,'Visible','on')
3878set(handles.vec_Fmin2_2,'Visible','on')
3879set(handles.vec_F4,'Visible','on')
3880set(handles.vec_F3_2,'Visible','on')
3881set(handles.thresh_vec2C,'Visible','on')
3882set(handles.thresh_vec2C_text,'Visible','on')
3883set(handles.thresh_vel2,'Visible','on')
3884set(handles.thresh_vel2_text,'Visible','on')
3885set(handles.mask_fix2,'Visible','on')
3886set(handles.get_mask_fix2,'Visible','on')
3887set(handles.list_pair_civ2,'Visible','on')
3888set(handles.subdir_civ2,'Visible','on')
3889set(handles.subdir_civ2_text,'Visible','on')
3890set(handles.get_ref_fix2,'Visible','on')
3891set(handles.ref_fix2,'Visible','on')
3892set(handles.inf_sup2,'Visible','on')
3893set(handles.field_ref2,'Visible','on')
3894
[12]3895%------------------------------------------------------------------------
[2]3896function desable_fix2(handles)
[12]3897%------------------------------------------------------------------------
[2]3898set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
3899set(handles.REMOVE2,'Visible','off')
3900set(handles.vec_Fmin2_2,'Visible','off')
3901set(handles.vec_F4,'Visible','off')
3902set(handles.vec_F3_2,'Visible','off')
3903set(handles.thresh_vec2C,'Visible','off')
3904set(handles.thresh_vec2C_text,'Visible','off')
3905set(handles.thresh_vel2,'Visible','off')
3906set(handles.thresh_vel2_text,'Visible','off')
3907set(handles.mask_fix2,'Visible','off')
3908set(handles.get_mask_fix2,'Visible','off')
3909set(handles.get_ref_fix2,'Visible','off')
3910set(handles.ref_fix2,'Visible','off')
3911set(handles.inf_sup2,'Visible','off')
3912set(handles.field_ref2,'Visible','off')
[112]3913if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
[2]3914    set(handles.list_pair_civ2,'Visible','off')
3915    set(handles.subdir_civ2,'Visible','off')
3916    set(handles.subdir_civ2_text,'Visible','off')
3917end
3918
[12]3919%------------------------------------------------------------------------
[2]3920function enable_patch2(handles)
[12]3921%------------------------------------------------------------------------
[2]3922set(handles.frame_patch2,'BackgroundColor',[1 1 0])
[119]3923set(handles.rho_patch2,'Visible','on')
[2]3924set(handles.rho_text2,'Visible','on')
3925set(handles.thresh_patch2,'Visible','on')
3926set(handles.thresh_text2,'Visible','on')
3927set(handles.subdomain_patch2,'Visible','on')
3928set(handles.subdomain_text2,'Visible','on')
3929set(handles.nx_patch2,'Visible','on')
3930set(handles.ny_patch2,'Visible','on')
3931set(handles.nx_patch2_title,'Visible','on')
3932set(handles.ny_patch2_title,'Visible','on')
3933set(handles.get_gridpatch2,'Visible','on')
3934set(handles.grid_patch2,'Visible','on')
3935set(handles.list_pair_civ2,'Visible','on')
3936set(handles.subdir_civ2,'Visible','on')
3937set(handles.subdir_civ2_text,'Visible','on')
3938
[12]3939%------------------------------------------------------------------------
[2]3940function desable_patch2(handles)
[12]3941%------------------------------------------------------------------------
[2]3942set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
3943set(handles.rho_patch2,'Visible','off')
3944set(handles.rho_text2,'Visible','off')
3945set(handles.thresh_patch2,'Visible','off')
3946set(handles.thresh_text2,'Visible','off')
3947set(handles.subdomain_patch2,'Visible','off')
3948set(handles.subdomain_text2,'Visible','off')
3949set(handles.nx_patch2,'Visible','off')
3950set(handles.ny_patch2,'Visible','off')
3951set(handles.nx_patch2_title,'Visible','off')
3952set(handles.ny_patch2_title,'Visible','off')
3953set(handles.get_gridpatch2,'Visible','off')
3954set(handles.grid_patch2,'Visible','off')
[112]3955if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0)
[2]3956    set(handles.list_pair_civ2,'Visible','off')
3957    set(handles.subdir_civ2,'Visible','off')
3958    set(handles.subdir_civ2_text,'Visible','off')
3959end
3960
[12]3961%------------------------------------------------------------------------
[2]3962function enable_pair1(handles,state)
[12]3963%------------------------------------------------------------------------
[2]3964set(handles.subdir_civ1,'Visible',state)
3965set(handles.list_subdir_civ1,'Visible',state)
3966set(handles.SUBDIR_CIV1_txt,'Visible',state)
3967set(handles.frame_subdirciv1,'Visible',state)
3968set(handles.list_pair_civ1,'Visible',state)
3969set(handles.PAIR_txt,'Visible',state)
[71]3970%set(handles.dt_unit,'Visible',state)
[2]3971set(handles.PAIR_frame,'Visible',state)
3972
[12]3973%------------------------------------------------------------------------
3974% --- Read the parameters for civ1 on the interface
[2]3975function par=read_param_civ1(handles,file_ima)
[12]3976%------------------------------------------------------------------------
[127]3977ibx_val=str2double(get(handles.ibx,'String'));
[2]3978par.ibx=num2str(ibx_val);
[127]3979iby_val=str2double(get(handles.iby,'String'));
[2]3980par.iby=num2str(iby_val);
3981isx=get(handles.isx,'String');
[127]3982if isnan(str2double(isx)), isx='41'; set(handles.isx,'String','41'), end; %default
3983if str2double(isx)<ibx_val+8,isx=num2str(ibx_val+8); set(handles.isx,'String',num2str(ibx_val+8)); end
[2]3984isy=get(handles.isy,'String');
[127]3985if isnan(str2double(isy)), isy='41'; set(handles.isy,'String','41'), end;%default
3986if str2double(isy)<iby_val+8,isy=num2str(iby_val+8); set(handles.isy,'String',num2str(iby_val+8)); end
[2]3987par.isx=get(handles.isx,'String');
3988par.isy=get(handles.isy,'String');
3989par.shiftx=get(handles.shiftx,'String');
3990par.shifty=get(handles.shifty,'String');
[127]3991if isnan(str2double(par.isx))
[112]3992    par.isx='41';%default
3993    set(handles.isx,'String','41');
[2]3994end
[127]3995if isnan(str2double(par.isy))
[112]3996    par.isy='41'; %default
3997    set(handles.isy,'String','41');
[12]3998end
[127]3999if isnan(str2double(par.shiftx))
[112]4000    par.shiftx='0';%default
4001    set(handles.shiftx,'String','0');
4002end
[127]4003if isnan(str2double(par.shifty))
[112]4004    par.shifty='0'; %default
4005    set(handles.shifty,'String','0');
[12]4006end
[112]4007par.rho=get(handles.rho,'String');
[238]4008if isequal(get(handles.rho,'Style'),'popupmenu')
4009    index=get(handles.rho,'Value');
4010    par.rho=par.rho{index};
4011end
[112]4012par.dx=get(handles.dx_civ1,'String');
4013par.dy=get(handles.dy_civ1,'String');
[127]4014if isnan(str2double(par.dx))
[112]4015    if isempty(get(handles.grid_civ1,'String'));
4016        par.dx='0'; %just read by civ program, not used
4017    else
[12]4018        par.dx='20';%default
4019        set(handles.dx_civ1,'String','20');
[112]4020    end
4021end
[127]4022if isnan(str2double(par.dy))
[112]4023    if isempty(get(handles.grid_civ1,'String'));
4024        par.dy='0';%just read by civ program, not used
4025    else
[12]4026        par.dy='20';%default
4027        set(handles.dy_civ1_title,'String','20');
[112]4028    end
4029end
4030par.pxcmx='1'; %velocities are expressed in pixel dispalcement
4031par.pxcmy='1';
[150]4032if exist('file_ima','var')
[112]4033A=imread(file_ima);%read the first image to get the size
4034sizim=size(A);
4035par.npx=num2str(sizim(2));
4036par.npy=num2str(sizim(1));
[150]4037end
[127]4038%time=get(handles.RootName,'UserData'); %get the set of times
[112]4039par.gridname=get(handles.grid_civ1,'String');
4040par.gridflag='y';
[127]4041if strcmp(par.gridname,'')|| isempty(par.gridname)
[112]4042    par.gridname='nogrid';
4043    par.gridflag='n';
4044end
[12]4045
4046%------------------------------------------------------------------------
[2]4047function par=read_param_civ2(handles,file_ima)
[12]4048%------------------------------------------------------------------------
4049par.ibx=get(handles.ibx_civ2,'String');
4050par.iby=get(handles.iby_civ2,'String');
4051par.rho=get(handles.rho_civ2,'String');
4052par.decimal=int2str(get(handles.decimal,'Value'));
4053par.deformation=int2str(get(handles.deformation,'Value'));
4054par.dx=get(handles.dx_civ2,'String');
4055par.dy=get(handles.dy_civ2,'String');
[127]4056if isnan(str2double(par.dx))
[112]4057    if isempty(get(handles.grid_civ2,'String'));
4058        par.dx='0'; %just read by civ program, not used
4059    else
[12]4060        par.dx='20';%default
4061        set(handles.dx_civ2,'String','20');
[112]4062    end
4063end
[127]4064if isnan(str2double(par.dy))
[112]4065    if isempty(get(handles.grid_civ2,'String'));
4066        par.dy='0';%just read by civ program, not used
4067    else
[12]4068        par.dy='20';%default
4069        set(handles.dy_civ2,'String','20');
[112]4070    end
4071end
4072par.pxcmx='1';
4073par.pxcmy='1';
[12]4074A=imread(file_ima);%read the first image to get the size
4075sizim=size(A);
4076par.npx=num2str(sizim(2));
4077par.npy=num2str(sizim(1));
[127]4078%time=get(handles.RootName,'UserData'); %get the set of times
[12]4079par.gridname=get(handles.grid_civ2,'String');
4080par.gridflag='y';
[127]4081if strcmp(par.gridname,'')|| isempty(par.gridname)
[12]4082    par.gridname='nogrid';
4083    par.gridflag='n';
4084end
[2]4085
[12]4086%------------------------------------------------------------------------
4087% --- CIV1  CIV1  CIV1 CIV1
[94]4088function cmd_CIV1=CIV1_CMD(filename,namelog,par,handles,sparam)
[12]4089%------------------------------------------------------------------------
[2]4090%pixels per cm and matrix of the image times, read from the .civ file by uvmat
4091
4092%changes : filename_cmx -> filename ( no extension )
[174]4093% input namelog not used
[112]4094if isequal(par.Dt,'0')
4095    par.Dt='1' ;%case of 'displacement' mode
4096end
[90]4097par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
[94]4098par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');
[230]4099fid=fopen([filename '.civ1.cmx'],'w');
[12]4100fprintf(fid,['##############   CMX file' '\n' ]);
[112]4101fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4102fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4103fprintf(fid,  ['XX' '\n' ]);
4104fprintf(fid,  ['Mask ' par.maskflag '\n' ]);
4105fprintf(fid,  ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);
4106fprintf(fid,   ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4107fprintf(fid,   ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
4108fprintf(fid,   ['SearchBoxeSize ' par.isx ' ' par.isy '\n' ]);
4109fprintf(fid,   ['RO ' par.rho '\n' ]);
4110fprintf(fid,   ['GridSpacing ' par.dx ' ' par.dy '\n' ]);
4111fprintf(fid,   ['XX 1.0' '\n' ]);
4112fprintf(fid,   ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
4113fprintf(fid,  ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
4114fprintf(fid,  ['XX 1' '\n' ]);
4115fprintf(fid,   ['ShiftXY ' par.shiftx ' '  par.shifty '\n' ]);
4116fprintf(fid,  ['Grid ' par.gridflag '\n' ]);
4117fprintf(fid,   ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n' ]);
4118fprintf(fid,   ['XX 85' '\n' ]);
4119fprintf(fid,   ['XX 1.0' '\n' ]);
4120fprintf(fid,   ['XX 1.0' '\n' ]);
4121fprintf(fid,   ['Hart 1' '\n' ]);
4122fprintf(fid,  [ 'DecimalShift 0' '\n' ]);
4123fprintf(fid,   ['Deformation 0' '\n' ]);
4124fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4125fprintf(fid,   ['IntensityMin 0' '\n' ]);
4126fprintf(fid,  ['SeuilImage n' '\n' ]);
4127fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
4128fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
4129fprintf(fid,   ['ImageUsedBefore null null' '\n' ]);
[12]4130fclose(fid);
[112]4131
[163]4132% cmd_CIV1=[sparam.Civ1Bin ' -f ' filename '.cmx >' filename '.log' ]; % redirect standard output to the log file
4133% cmd_CIV1=regexprep(cmd_CIV1,'\\','\\\\');
4134% namelog=regexprep(namelog,'\\','\\\\');
[12]4135if(isunix)
[230]4136    cmd_CIV1=['cp -f ' filename '.civ1.cmx ' filename '.cmx\n'];
4137    cmd_CIV1=[cmd_CIV1 sparam.Civ1Bin ' -f ' filename '.cmx >' filename '.log' ]; % redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
[219]4138    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]4139   % cmd_CIV1=[cmd_CIV1 '\n' 'mv ' filename '.cmx' ' ' filename '.civ1.cmx' '\n'];%rename .cmx as .civ1.cmx
[163]4140else %Windows system
[230]4141                    flname=regexprep(flname,'\\','\\\\');
4142%                     cmd=[cmd 'copy /Y "' flname '.civ1.cmx" "' flname '.cmx"\n'];
[174]4143    filename=regexprep(filename,'\\','\\\\');
[230]4144    cmd_CIV1=['copy /Y "' filename '.civ1.cmx" "' filename '.cmx"\n'];% copy the .civ1.cmx parameter file to .cmx
[163]4145    cmd_CIV1=['"' sparam.Civ1Bin '" -f "' filename '.cmx" >"' filename '.log"' ]; % redirect standard output to the log file
4146    cmd_CIV1=regexprep(cmd_CIV1,'\\','\\\\');
4147    namelog=regexprep(namelog,'\\','\\\\');
[230]4148    cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y "' filename '.log' '" "' filename '.civ1.log"']; %preserve the log file as .civ1.log
4149  %  cmd_CIV1=[cmd_CIV1 '\n' 'copy /Y "' filename '.cmx' '" "' filename '.civ1.cmx"'];
[12]4150end
[2]4151
[12]4152%------------------------------------------------------------------------
4153% --- CIV1  Unified
[94]4154function xml_civ1_parameters=CIV1_CMD_Unified(filename,namelog,par)
[12]4155%------------------------------------------------------------------------
[2]4156%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[73]4157%global CivBin%name of the executable for civ1 calculation
[2]4158
[112]4159civ1.image1=par.filename_ima_a;
4160civ1.image2=par.filename_ima_b;
4161civ1.imageSize_X=par.npx;
4162civ1.imageSize_Y=par.npy;
4163civ1.outputFileName=[filename '.nc'];
4164civ1.correlationBoxesSize_X=par.ibx;
4165civ1.correlationBoxesSize_Y=par.iby;
4166civ1.searchBoxesSize_X=par.isx;
4167civ1.searchBoxesSize_Y=par.isy;
4168civ1.globalShift_X=par.shiftx;
4169civ1.globalShift_Y=par.shifty;
4170civ1.ro=par.rho;
4171civ1.hart='y';
4172if isequal(par.gridflag,'y')
4173    civ1.grid=par.gridname;
4174else
4175    civ1.grid='n';
4176    civ1.gridSpacing_X=par.dx;
4177    civ1.gridSpacing_Y=par.dy;
4178end
4179if isequal(par.maskflag,'y')
4180    civ1.mask=par.maskname;
4181end
[229]4182civ1.dt=par.Dt;
[112]4183civ1.unit='pixel';
4184civ1.absolut_time_T0=par.T0;
4185civ1.pixcmx=par.pxcmx;
4186civ1.pixcmy=par.pxcmy;
4187civ1.convectFlow='n';
[12]4188
[112]4189xml_civ1_parameters=civ1;
4190
[12]4191%------------------------------------------------------------------------
4192% --- CIV2  Unified
[94]4193function civ2=CIV2_CMD_Unified(filename,namelog,par)
[12]4194%------------------------------------------------------------------------
[2]4195%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[73]4196%global CivBin%name of the executable for civ1 calculation
[2]4197
4198civ2.image1=par.filename_ima_a;
4199civ2.image2=par.filename_ima_b;
[112]4200civ2.imageSize_X=par.npx;
[2]4201civ2.imageSize_Y=par.npy;
4202civ2.inputFileName=[par.filename_nc1 '.nc'];
4203civ2.outputFileName=[filename '.nc'];
4204civ2.correlationBoxesSize_X=par.ibx;
4205civ2.correlationBoxesSize_Y=par.iby;
4206civ2.ro=par.rho;
4207%civ2.decimalShift=par.decimal;
4208%civ2.deformation=par.deformation;
4209if isequal(par.decimal,'1')
4210    civ2.decimalShift='y';
4211else
4212    civ2.decimalShift='n';
4213end
4214if isequal(par.deformation,'1')
4215    civ2.deformation='y';
4216else
4217    civ2.deformation='n';
4218end
4219if isequal(par.gridflag,'y')
4220    civ2.grid=par.gridname;
4221else
4222    civ2.grid='n';
4223    civ2.gridSpacing_X=par.dx;
4224    civ2.gridSpacing_Y=par.dy;
4225end
4226civ2.gridSpacing_X='10';
4227civ2.gridSpacing_Y='10';%NOTE: faut mettre gridSpacing pourque ca tourne, meme si c'est la grille qui est utilisee
4228if isequal(par.maskflag,'y')
4229    civ2.mask=par.maskname;
4230else
4231    civ2.mask='n';
4232end
4233civ2.dt=par.Dt;
4234civ2.unit='pixel';
4235civ2.absolut_time_T0=par.T0;
4236civ2.pixcmx=par.pxcmx;
4237civ2.pixcmy=par.pxcmy;
4238civ2.convectFlow='n';
4239civ2.pixcmx=par.pxcmx;
4240civ2.pixcmy=par.pxcmy;
4241civ2.convectFlow='n';
4242
[12]4243%------------------------------------------------------------------------
4244% --- CIV2  CIV2  CIV2 CIV2
[134]4245function cmd_CIV2=CIV2_CMD(filename,namelog,par,sparam)
[12]4246%------------------------------------------------------------------------
[2]4247%pixels per cm and matrix of the image times, read from the .civ file by uvmat
[67]4248% global civ2Bin sge%name of the executable for civ1 calculation
[112]4249if isequal(par.Dt,'0')
4250    par.Dt='1' ;%case of 'displacement' mode
4251end
[94]4252par.filename_ima_a=regexprep(par.filename_ima_a,'.png','');
4253par.filename_ima_b=regexprep(par.filename_ima_b,'.png','');% bug : .png appears two times ?
[174]4254[fid,errormsg]=fopen([filename '.civ2.cmx'],'w');
4255if isequal(fid,-1)
4256    msgbox_uvmat('ERROR',errormsg)
4257    cmd_CIV2='';
4258    return
4259end
[94]4260fprintf(fid,['##############   CMX file' '\n' ]);
4261fprintf(fid,   ['FirstImage ' regexprep(par.filename_ima_a,'\\','\\\\') '\n' ]);% for windows compatibility
4262fprintf(fid,   ['LastImage  ' regexprep(par.filename_ima_b,'\\','\\\\') '\n' ]);% for windows compatibility
4263fprintf(fid,  ['XX' '\n' ]);
4264fprintf(fid, ['Mask ' par.maskflag '\n' ]);
4265fprintf(fid, ['MaskName ' regexprep(par.maskname,'\\','\\\\') '\n' ]);% for windows compatibility
4266fprintf(fid, ['ImageSize ' par.npx ' ' par.npy '\n' ]);   %VERIFIER CAS GENERAL ?
4267fprintf(fid, ['CorrelationBoxesSize ' par.ibx ' ' par.iby '\n' ]);
4268fprintf(fid, ['SearchBoxeSize ' par.ibx ' ' par.iby '\n']);
4269fprintf(fid, ['RO ' par.rho '\n']);
4270fprintf(fid, ['GridSpacing ' par.dx ' ' par.dy '\n']);
4271fprintf(fid, ['XX 1.0' '\n' ]);
4272fprintf(fid, ['Dt_TO ' par.Dt ' ' par.T0 '\n' ]);
4273fprintf(fid, ['PixCmXY ' par.pxcmx ' ' par.pxcmy '\n' ]);
4274fprintf(fid, ['XX 1' '\n' ]);
[122]4275fprintf(fid, 'ShiftXY 0 0\n');
[94]4276fprintf(fid, ['Grid ' par.gridflag '\n' ]);
4277fprintf(fid, ['GridName ' regexprep(par.gridname,'\\','\\\\') '\n']);
4278fprintf(fid, ['XX 85' '\n' ]);
4279fprintf(fid, ['XX 1.0' '\n' ]);
4280fprintf(fid, ['XX 1.0' '\n' ]);
4281fprintf(fid, ['Hart 1' '\n' ]);
4282fprintf(fid, ['DecimalShift ' par.decimal '\n']);
4283fprintf(fid, ['Deformation ' par.deformation '\n']);
4284fprintf(fid,  ['CorrelationMin 0' '\n' ]);
4285fprintf(fid,   ['IntensityMin 0' '\n' ]);
4286fprintf(fid,  ['SeuilImage n' '\n' ]);
4287fprintf(fid,   ['SeuilImageValues 0 4096' '\n' ]);
4288fprintf(fid,   ['ImageToUse ' par.term_a ' ' par.term_b '\n' ]); % VERIFIER ?
4289fprintf(fid, ['ImageUsedBefore ' regexprep(par.filename_nc1,'\\','\\\\') '\n']);
4290fclose(fid);
4291
[134]4292if(isunix)
[230]4293    cmd_CIV2=['cp -f ' filename '.civ2.cmx ' filename '.cmx\n'];
4294    cmd_CIV2=[cmd_CIV2 sparam.Civ2Bin ' -f ' filename  '.cmx >' filename '.log' ]; % redirect standard output to the log file, the result file is named [filename '.nc'] by CIVx
4295    cmd_CIV2=[cmd_CIV2 '\n' 'mv ' filename '.log' ' ' filename '.civ2.log' '\n' 'chmod g+w ' filename '.nc'];%preserve the log file as .civ2.log
4296%    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
4297
[163]4298else
[174]4299    filename=regexprep(filename,'\\','\\\\');
[230]4300    cmd_CIV2=['copy /Y "' filename '.civ2.cmx" "' filename '.cmx"\n'];
4301    cmd_CIV2=[cmd_CIV2 '"' sparam.Civ2Bin '" -f "' filename  '.cmx" >"' filename '.log"' ]; % redirect standard output to the log file
[163]4302    cmd_CIV2=regexprep(cmd_CIV2,'\\','\\\\');
[174]4303    cmd_CIV2=[cmd_CIV2 '\n' 'copy /Y "' filename '.log' '" "' filename '.civ2.log"'];
[230]4304 %    cmd_CIV2=[cmd_CIV2 '\n' 'copy /Y "' filename '.cmx' '" "' filename '.civ2.cmx"'];
[134]4305end
4306
[238]4307% %------------------------------------------------------------------------
4308% % --- civ using pivlab
4309% function Data=civ_uvmat(par_civ1)
4310% %------------------------------------------------------------------------
4311% image1=imread(par_civ1.filename_ima_a);
4312% image2=imread(par_civ1.filename_ima_b);
4313% stepx=str2num(par_civ1.dx);
4314% stepy=str2num(par_civ1.dy);
4315% ibx2=ceil(str2num(par_civ1.ibx)/2);
4316% iby2=ceil(str2num(par_civ1.iby)/2);
4317% isx2=ceil(str2num(par_civ1.isx)/2);
4318% isy2=ceil(str2num(par_civ1.isy)/2);
4319% shiftx=str2num(par_civ1.shiftx);
4320% shifty=str2num(par_civ1.shifty);
4321% miniy=max(1+isy2-shifty,1+iby2);
4322% minix=max(1+isx2-shiftx,1+ibx2);
4323% maxiy=min(size(image1,1)-isy2-shifty,size(image1,1)-iby2);
4324% maxix=min(size(image1,2)-isx2-shiftx,size(image1,2)-ibx2);
4325% [GridX,GridY]=meshgrid(minix:stepx:maxix,miniy:stepy:maxiy);
4326% PointCoord(:,1)=reshape(GridX,[],1);
4327% PointCoord(:,2)=reshape(GridY,[],1);
4328% % caluclate velocity data (y and v in indices, reverse to y component)
4329% [xtable ytable utable vtable ctable F] = pivlab (image1,image2,ibx2,iby2,isx2,isy2,shiftx,shifty,PointCoord, 1, []);
4330% Data.ListGlobalAttribute=[{'Conventions','Program','CivStage'} {'Time','Dt'}];
4331% Data.Conventions='uvmat/civdata';
4332% Data.Program='civ_uvmat';
4333% Data.CivStage=1;
4334% % list_param=fieldnames(Param.Civ1);
4335% % for ilist=1:length(list_param)
4336% %     eval(['Data.Civ1_' list_param{ilist} '=Param.Civ1.' list_param{ilist} ';'])
4337% % end
4338% Data.Time=str2double(par_civ1.T0);
4339% Data.Dt=str2double(par_civ1.Dt);
4340% Data.ListVarName={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_F'};%  cell array containing the names of the fields to record
4341% Data.VarDimName={'nbvec','nbvec','nbvec','nbvec','nbvec','nbvec'};
4342% Data.VarAttribute{1}.Role='coord_x';
4343% Data.VarAttribute{2}.Role='coord_y';
4344% Data.VarAttribute{3}.Role='vector_x';
4345% Data.VarAttribute{4}.Role='vector_y';
4346% Data.VarAttribute{5}.Role='warnflag';
4347% Data.Civ1_X=reshape(xtable,[],1);
4348% Data.Civ1_Y=reshape(size(image1,1)-ytable+1,[],1);
4349% Data.Civ1_U=reshape(utable,[],1);
4350% Data.Civ1_V=reshape(-vtable,[],1);
4351% Data.Civ1_C=reshape(ctable,[],1);
4352% Data.Civ1_F=reshape(F,[],1);
[134]4353
[12]4354%------------------------------------------------------------------------
[2]4355% --- Executes on button press in HELP.
4356function HELP_Callback(hObject, eventdata, handles)
[12]4357%------------------------------------------------------------------------
[2]4358path_to_uvmat=which ('uvmat');% check the path of uvmat
4359pathelp=fileparts(path_to_uvmat);
[85]4360helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
[36]4361if 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]4362else
[36]4363    addpath (fullfile(pathelp,'uvmat_doc'))
[112]4364    web([helpfile '#civ'])
[2]4365end
4366
[12]4367%------------------------------------------------------------------------
[2]4368%--read images and convert them to the uint16 format used for PIV
[45]4369function A=read_image(filename,type_ima,num,movieobject)
[12]4370%------------------------------------------------------------------------
[2]4371%num is the view number needed for an avi movie
[45]4372switch type_ima
4373    case 'movie'
4374        A=read(movieobject,num);
4375    case 'avi'
[112]4376        mov=aviread(filename,num);
4377        A=frame2im(mov(1));
[45]4378    case 'multimage'
4379        A=imread(filename,num);
[112]4380    case 'image'
[45]4381        A=imread(filename);
4382end
4383siz=size(A);
4384if length(siz)==3;%color images
[2]4385    A=sum(double(A),3);
4386    A=uint16(A);
4387end
4388
[12]4389%------------------------------------------------------------------------
[2]4390function ref_i_Callback(hObject, eventdata, handles)
[12]4391%------------------------------------------------------------------------
[2]4392mode_list=get(handles.mode,'String');
4393mode_value=get(handles.mode,'Value');
4394mode=mode_list{mode_value};
[45]4395find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
[12]4396if isequal(mode,'series(Di)') || ...% we do patch2 only
[112]4397        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
[2]4398    find_netcpair_civ2(hObject, eventdata, handles);
4399end
4400
[12]4401%------------------------------------------------------------------------
[2]4402function ref_j_Callback(hObject, eventdata, handles)
[12]4403%------------------------------------------------------------------------
[2]4404mode_list=get(handles.mode,'String');
4405mode_value=get(handles.mode,'Value');
4406mode=mode_list{mode_value};
[112]4407if isequal(get(handles.CIV1,'Value'),0)|| isequal(mode,'series(Dj)')
[2]4408    find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4409end
[45]4410if isequal(mode,'series(Dj)') || ...
[112]4411        (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
[2]4412    find_netcpair_civ2(hObject, eventdata, handles);
4413end
[12]4414
4415%------------------------------------------------------------------------
[71]4416function ref_i_civ2_Callback(hObject, eventdata, handles)
4417%------------------------------------------------------------------------
4418mode_list=get(handles.mode,'String');
4419mode_value=get(handles.mode,'Value');
4420mode=mode_list{mode_value};
4421find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4422
4423%------------------------------------------------------------------------
4424function ref_j_civ2_Callback(hObject, eventdata, handles)
4425%------------------------------------------------------------------------
4426mode_list=get(handles.mode,'String');
4427mode_value=get(handles.mode,'Value');
4428mode=mode_list{mode_value};
[112]4429if  isequal(mode,'series(Dj)')
[71]4430    find_netcpair_civ2(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
4431end
4432
4433%------------------------------------------------------------------------
[2]4434% --- Executes on button press in compare.
4435function compare_Callback(hObject, eventdata, handles)
[12]4436%------------------------------------------------------------------------
[2]4437test=get(handles.compare,'Value');
[112]4438if test==2 || test==3
[71]4439    filebase=get(handles.RootName,'String');
[2]4440    browse=get(handles.browse_root,'Userdata');
4441    browse.nom_type_ima1=browse.nom_type_ima;
4442    set(handles.browse_root,'UserData',browse);
4443    set(handles.sub_txt,'Visible','on')
[112]4444    set(handles.RootName_1,'Visible','On');%mkes the second file input window visible
[2]4445    mode_store=get(handles.mode,'String');%get the present 'mode'
[112]4446    set(handles.compare,'UserData',mode_store);%store the mode display
[2]4447    set(handles.mode,'Visible','off')
4448    if test==2
[112]4449        set(handles.mode,'Visible','off')
[2]4450    else
4451        set(handles.mode,'Visible','on')
4452    end
4453   
[229]4454    %% open an image file with the browser
[2]4455    ind_opening=1;%default
4456    browse.incr_pair=[0 0]; %default
[71]4457    oldfile=get(handles.RootName,'String');
[229]4458     menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
4459       '*.xml',  '.xml files '; ...
4460        '*.civ',  '.civ files '; ...
4461        '*.png','.png image files'; ...
4462        '*.jpg',' jpeg image files'; ...
4463        '*.tif','.tif image files'; ...
4464        '*.avi;*.AVI','.avi movie files'; ...
4465        '*.nc','.netcdf files'; ...
4466        '*.*',  'All Files (*.*)'};
4467    [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file of the second series',oldfile);
[112]4468    fileinput=[PathName FileName];%complete file name
[2]4469    sizf=size(fileinput);
[229]4470    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4471    [path,name,ext]=fileparts(fileinput);
4472    [path1]=fileparts(filebase);
[229]4473%     if isunix
4474%         ['readlink ' path]
4475%         [status,path]=system(['readlink ' path])
4476%         [status,path1]=system(['readlink ' path1])% look for the true path in case of symbolic paths
4477%     end
[2]4478    if ~strcmp(path1,path)
[112]4479        msgbox_uvmat('ERROR','The two  input image series must be in the same directory')
[2]4480        return
4481    end
[71]4482    set(handles.RootName_1,'String',name);
[2]4483    [RootPath,RootFile,field_count,str2,str_a,str_b,xx,nom_type,subdir]=name2display(name);
4484    browse=get(handles.browse_root,'UserData');
4485    browse.nom_type_ima_1=nom_type;
[112]4486    set(handles.browse_root,'UserData',browse)
[2]4487   
4488    %check image extension
[71]4489    if ~strcmp(ext,get(handles.ImaExt,'String'))
[229]4490        msgbox_uvmat('ERROR','The two  input image series must have the same extension name')
[2]4491        return
4492    end
4493   
[229]4494    %% check coincidence of image sizes
4495    ref_i=get(handles.ref_i,'string');
4496    ref_j=get(handles.ref_j,'string');
4497    [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]);
4498    A=imread(filecell.ima1.civ1{1});
4499    A_1=imread(fileinput);
4500    npxy=size(A);
4501    npxy_1=size(A_1);
4502    if ~isequal(size(A),size(A_1))
4503        msgbox_uvmat('ERROR','The two input image series do not have the same size')
[2]4504        return
4505    end
4506else
4507    set(handles.mode,'Visible','on')
[71]4508    set(handles.RootName_1,'Visible','Off');
[2]4509    set(handles.sub_txt,'Visible','off')
[71]4510    set(handles.RootName_1,'String',[]);
[2]4511    mode_store=get(handles.compare,'UserData');
[177]4512    set(handles.mode,'Value',1)
[2]4513    set(handles.mode,'String',mode_store)
4514    set(handles.test_stereo1,'Value',0)
4515    set(handles.test_stereo2,'Value',0)
4516end
4517mode_Callback(hObject, eventdata, handles)
4518
[12]4519%------------------------------------------------------------------------
[2]4520% --- Executes on button press in get_ref_fix1.
4521function get_ref_fix1_Callback(hObject, eventdata, handles)
[12]4522%------------------------------------------------------------------------
[71]4523filebase=get(handles.RootName,'String');
[2]4524[FileName, PathName, filterindex] = uigetfile( ...
[112]4525    {'*.nc', ' (*.nc)';
4526    '*.nc',  'netcdf files '; ...
4527    '*.*', 'All Files (*.*)'}, ...
4528    'Pick a file',filebase);
4529
[2]4530fileinput=[PathName FileName];
4531sizf=size(fileinput);
[122]4532if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4533[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4534ref.filebase=fullfile(Path,File);
4535ref.num_a=stra2num(str_a);
4536ref.num_b=stra2num(str_b);
[89]4537ref.num1=str2double(field_count);
4538ref.num2=str2double(str2);
[2]4539browse=[];%initialisation
4540if ~isequal(ref.ext,'.nc')
4541    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4542    return
4543end
4544set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
4545set(handles.ref_fix1,'UserData',ref)
4546menu_field{1}='civ1';
4547Data=nc2struct(fileinput,[]);
[45]4548if isfield(Data,'patch') && isequal(Data.patch,1)
[2]4549    menu_field{2}='filter1';
4550end
[45]4551if isfield(Data,'civ2') && isequal(Data.civ2,1)
[2]4552    menu_field{3}='civ2';
4553end
[45]4554if isfield(Data,'patch2') && isequal(Data.patch2,1)
[2]4555    menu_field{4}='filter2';
4556end
4557set(handles.field_ref1,'String',menu_field);
4558set(handles.field_ref1,'Value',length(menu_field));
4559set(handles.inf_sup1,'Value',2);
4560set(handles.thresh_vel,'String','1');%default threshold
4561set(handles.ref_fix1,'Enable','on')
[12]4562
4563%------------------------------------------------------------------------
[2]4564% --- Executes on button press in get_ref_fix2.
4565function get_ref_fix2_Callback(hObject, eventdata, handles)
[12]4566%------------------------------------------------------------------------
[2]4567if isequal(get(handles.get_ref_fix2,'Value'),1)
[71]4568    filebase=get(handles.RootName,'String');
[2]4569    [FileName, PathName, filterindex] = uigetfile( ...
[112]4570        {'*.nc', ' (*.nc)';
4571        '*.nc',  'netcdf files '; ...
4572        '*.*', 'All Files (*.*)'}, ...
4573        'Pick a file',filebase);
[2]4574    fileinput=[PathName FileName];
4575    sizf=size(fileinput);
[45]4576    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
[2]4577    [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
4578    ref.filebase=fullfile(Path,File);
4579    ref.num_a=stra2num(str_a);
4580    ref.num_b=stra2num(str_b);
4581    ref.num1=str2num(field_count);
4582    ref.num2=str2num(str2);
4583    browse=[];%initialisation
4584    if ~isequal(ref.ext,'.nc')
4585        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
4586        return
4587    end
4588    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
[112]4589    set(handles.ref_fix2,'UserData',ref)
[2]4590    menu_field{1}='civ1';
4591    Data=nc2struct(fileinput,[]);
4592    if isfield(Data,'patch') & isequal(Data.patch,1)
4593        menu_field{2}='filter1';
4594    end
4595    if isfield(Data,'civ2') & isequal(Data.civ2,1)
4596        menu_field{3}='civ2';
4597    end
4598    if isfield(Data,'patch2') & isequal(Data.patch2,1)
4599        menu_field{4}='filter2';
4600    end
4601    set(handles.field_ref2,'String',menu_field);
4602    set(handles.field_ref2,'Value',length(menu_field));
4603    set(handles.inf_sup2,'Value',2);
4604    set(handles.thresh_vel2,'String','1');%default threshold
4605    set(handles.ref_fix2,'Enable','on')
4606    set(handles.ref_fix2,'Visible','on')
4607    set(handles.field_ref2,'Visible','on')
4608else
4609    set(handles.ref_fix2,'Visible','off')
4610    set(handles.field_ref2,'Visible','off')
4611end
4612
[12]4613%------------------------------------------------------------------------
[2]4614function ref_fix1_Callback(hObject, eventdata, handles)
[12]4615%------------------------------------------------------------------------
4616set(handles.inf_sup1,'Value',1);
4617set(handles.field_ref1,'Value',1)
4618set(handles.field_ref1,'String',{' '})
4619set(handles.ref_fix1,'UserData',[]);
4620set(handles.ref_fix1,'String','');
4621set(handles.thresh_vel1,'String','0');
[112]4622
[12]4623%------------------------------------------------------------------------
[2]4624function ref_fix2_Callback(hObject, eventdata, handles)
[12]4625%------------------------------------------------------------------------
4626set(handles.inf_sup2,'Value',1);
4627set(handles.field_ref2,'Value',1)
4628set(handles.field_ref2,'String',{' '})
4629set(handles.ref_fix2,'UserData',[]);
4630set(handles.ref_fix2,'String','');
4631set(handles.thresh_vel2,'String','0');
[2]4632
[12]4633%------------------------------------------------------------------------
[2]4634% --- Executes on button press in test_stereo1.
4635function test_stereo1_Callback(hObject, eventdata, handles)
[12]4636%------------------------------------------------------------------------
[2]4637if isequal(get(handles.test_stereo1,'Value'),0)
4638    set(handles.subdomain_patch1,'Visible','on')
4639    set(handles.rho_patch1,'Visible','on')
4640else
4641    set(handles.subdomain_patch1,'Visible','off')
4642    set(handles.rho_patch1,'Visible','off')
4643end
4644
[12]4645%------------------------------------------------------------------------
[2]4646% --- Executes on button press in test_stereo2.
4647function test_stereo2_Callback(hObject, eventdata, handles)
[12]4648%------------------------------------------------------------------------
[2]4649if isequal(get(handles.test_stereo2,'Value'),0)
4650    set(handles.subdomain_patch2,'Visible','on')
4651    set(handles.rho_patch2,'Visible','on')
4652else
4653    set(handles.subdomain_patch2,'Visible','off')
4654    set(handles.rho_patch2,'Visible','off')
4655end
4656
[12]4657%------------------------------------------------------------------------
[2]4658% --- Executes on button press in ImaThreshold.
4659function ImaThreshold_Callback(hObject, eventdata, handles)
[12]4660%------------------------------------------------------------------------
[2]4661if isequal(get(handles.ImaThreshold,'Value'),1)
4662    set(handles.MinIma,'Visible','on')
4663    set(handles.MaxIma,'Visible','on')
4664else
4665    set(handles.MinIma,'Visible','off')
4666    set(handles.MaxIma,'Visible','off')
4667end
4668
[12]4669%------------------------------------------------------------------------
[2]4670% --- Executes on button press in ImaThreshold2.
4671function ImaThreshold2_Callback(hObject, eventdata, handles)
[12]4672%------------------------------------------------------------------------
[2]4673if isequal(get(handles.ImaThreshold2,'Value'),1)
4674    set(handles.MinIma2,'Visible','on')
4675    set(handles.MaxIma2,'Visible','on')
4676else
4677    set(handles.MinIma2,'Visible','off')
4678    set(handles.MaxIma2,'Visible','off')
4679end
4680
[224]4681%------------------------------------------------------------------------
[225]4682% --- Executes on button press in TestCiv1: display image correlation function
[150]4683function TestCiv1_Callback(hObject, eventdata, handles)
[224]4684%------------------------------------------------------------------------
[233]4685set(handles.TestCiv1,'BackgroundColor',[1 1 0])
4686drawnow
[150]4687test_civ1=get(handles.TestCiv1,'Value');
4688if test_civ1
[227]4689    ref_i=str2double(get(handles.ref_i,'String'));
4690    if strcmp(get(handles.ref_j,'Visible'),'on')
4691        ref_j=str2double(get(handles.ref_j,'String'));
4692    else
4693        ref_j=1;%default
4694    end
[224]4695    [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]4696        set_civ_filenames(handles,ref_i,ref_j,[1 0 0 0 0 0])
[224]4697    Data.ListVarName={'ny','nx','A'};
4698    Data.VarDimName={'ny','nx',{'ny','nx'}};
4699    Data.A=imread(filecell.ima1.civ1{1});
4700    Data.ny=[size(Data.A,1) 1];
4701    Data.nx=[1 size(Data.A,2)];
[227]4702    par_civ1=read_param_civ1(handles,filecell.ima1.civ1{1});
[231]4703    par_civ1.filename_ima_a=filecell.ima1.civ1{1};
4704    par_civ1.filename_ima_b=filecell.ima2.civ1{1};
4705    par_civ1.T0=0;
4706    par_civ1.Dt=1;
[246]4707    Param.Civ1=par_civ1;
4708    Data=civ_uvmat(Param);
[231]4709%     stepx=str2num(par_civ1.dx);
4710%     stepy=str2num(par_civ1.dy);
4711%     ibx2=ceil(str2num(par_civ1.ibx)/2);
4712%     iby2=ceil(str2num(par_civ1.iby)/2);
4713%     isx2=ceil(str2num(par_civ1.isx)/2);
4714%     isy2=ceil(str2num(par_civ1.isy)/2);
4715%     shiftx=str2num(par_civ1.shiftx);
4716%     shifty=str2num(par_civ1.shifty);
4717% %             ibx=2*ibx2-1;%ibx and iby odd, reduced by 1 if even
4718% %             iby=2*iby2-1;
4719%     miniy=max(1+isy2-shifty,1+iby2)
4720%     minix=max(1+isx2-shiftx,1+ibx2)
4721%     maxiy=min(size(Data.A,1)-isy2-shifty,size(Data.A,1)-iby2)
4722%     maxix=min(size(Data.A,2)-isx2-shiftx,size(Data.A,2)-ibx2)
4723% %             maxix=stepx*(floor(size(image1_roi,2)/stepx))-(2*ibx2-2)+ibx2;
4724%     [GridX,GridY]=meshgrid(minix:stepx:maxix,miniy:stepy:maxiy);
4725%     PointCoord(:,1)=reshape(GridX,[],1);
4726%     PointCoord(:,2)=reshape(GridY,[],1);
4727    Data.ListVarName=[Data.ListVarName {'ny','nx','A'}];
4728    Data.VarDimName=[Data.VarDimName {'ny','nx',{'ny','nx'}}];
4729    Data.A=imread(filecell.ima1.civ1{1});
4730    Data.ny=[size(Data.A,1) 1];
4731    Data.nx=[1 size(Data.A,2)];
4732    hview_field=view_field(Data);
4733    set(0,'CurrentFigure',hview_field)
4734    hhview_field=guihandles(hview_field);
4735    set(hview_field,'CurrentAxes',hhview_field.axes3)
4736    %hpoints=line(PointCoord(:,1),PointCoord(:,2),'Color','y','LineStyle','.','Marker','*','LineWidth',4,'Tag','grid_points');
4737    ViewData=get(hview_field,'UserData');
4738    ViewData.CivHandle=handles.civ;% indicate the handle of the civ GUI in view_field
[224]4739    ViewData.axes3.B=imread(filecell.ima2.civ1{1});%store the second image in the UserData of the GUI view_field
[236]4740    ViewData.axes3.X=Data.Civ1_X; %keep the set of points in memeory
4741    ViewData.axes3.Y=Data.Civ1_Y;
[231]4742    set(hview_field,'UserData',ViewData)
[224]4743    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
4744    if isempty(corrfig)
4745        corrfig=figure;
4746        set(corrfig,'tag','corrfig')
4747        set(corrfig,'name','image correlation')
4748        set(corrfig,'DeleteFcn',{@closeview_field})%
4749    end
[233]4750    set(handles.TestCiv1,'BackgroundColor',[1 0 0])
[224]4751else
4752    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
4753    if ~isempty(corrfig)
4754        delete(corrfig)
4755    end
4756    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field   
4757    if ~isempty(hview_field)
4758        delete(hview_field)
4759    end
[150]4760end
[71]4761
[224]4762function closeview_field(gcbo,eventdata)
4763hview_field=findobj(allchild(0),'tag','view_field');% look for view_field   
4764    if ~isempty(hview_field)
4765        delete(hview_field)
4766    end
[177]4767%-------------------------------------------------------------------
4768% --- Executes on button press in status.
4769function status_Callback(hObject, eventdata, handles)
4770%-------------------------------------------------------------------
4771val=get(handles.status,'Value');
4772if val==0
4773    hfig=findobj(allchild(0),'name','civ_status');
4774    if ~isempty(hfig)
4775        delete(hfig)
4776    end
4777    return
4778end
4779listtype={'civ1','fix1','patch1','civ2','fix2','patch2'};
4780box_test(1)=get(handles.CIV1,'Value');
4781box_test(2)=get(handles.FIX1,'Value');
4782box_test(3)=get(handles.PATCH1,'Value');
4783box_test(4)=get(handles.CIV2,'Value');
4784box_test(5)=get(handles.FIX2,'Value');
[180]4785box_test(6)=get(handles.PATCH2,'Value');
4786option_civ=find(box_test,1,'last');%last selected option (non-zero index of box_test)
[177]4787filecell=get(handles.civ,'UserData');
4788if ~isfield(filecell,'nc')
[227]4789    [ref_i,ref_j,errormsg]=find_ref_indices(handles);
4790    if ~isempty(errormsg)
4791        msgbox_uvmat('ERROR',errormsg)
4792        return
4793    end
4794    filecell=set_civ_filenames(handles,ref_i,ref_j,box_test);%determine the list of output files expected from the GUI status
[177]4795end
[71]4796
[177]4797if ~isequal(box_test(4:6),[0 0 0])
4798    civ_files=filecell.nc.civ2;
4799else
4800    civ_files=filecell.nc.civ1;
4801end
4802[root,filename,ext]=fileparts(civ_files{1});
4803[rootroot,subdir,extdir]=fileparts(root);
4804hfig=findobj(allchild(0),'name','civ_status');
4805if isempty(hfig)
4806    hfig=figure;
4807    set(hfig,'name','civ_status')
[182]4808    hlist=uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @open_view_field,'tag','list');
[177]4809    uicontrol('Style','listbox','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','msgbox');
4810    uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
[182]4811    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]4812    BarPosition=[0.05 0.81 0.01 0.05];
4813    hwaitbar=uicontrol('Style','frame','Units','normalized', 'Position',BarPosition ,'BackgroundColor',[1 0 0],'tag','waitbar');
4814end
[188]4815% datnum=[];
[177]4816Tabchar={};
4817nbfiles=numel(civ_files);
4818count=0;
[188]4819testrecent=0;
[177]4820while count<nbfiles
4821    count=0;
[188]4822    datnum=zeros(1,nbfiles);
[177]4823    for ifile=1:nbfiles
4824        detect=exist(civ_files{ifile},'file'); % check the existence of the file
[179]4825        option=0;
[177]4826        if detect==0
[179]4827            option_str='not created';
[177]4828        else
[219]4829            datfile=dir(civ_files{ifile});
[188]4830            if isfield(datfile,'datenum')
4831                datnum(ifile)=datfile.datenum;%only available in recent matlab versions
4832                testrecent=1;
4833            end
[177]4834            filefound(ifile)={datfile.name};
4835            lastfield='';
4836            % check the content  netcdf file
4837            Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','patch2','fix2','civ2','patch','fix');
4838            if ~isempty(Data.patch2) && isequal(Data.patch2,1)
[179]4839                option=6;
4840                option_str='patch2';
[177]4841            elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
[179]4842                option=5;
4843                option_str='fix2';
[177]4844            elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
[179]4845                option=4;
4846                option_str='civ2';
[177]4847            elseif ~isempty(Data.patch) && isequal(Data.patch,1);
[179]4848                option=3;
4849                option_str='patch1';
[177]4850            elseif ~isempty(Data.fix) && isequal(Data.fix,1);
[179]4851                option=2;
4852                option_str='fix1';
[177]4853            else
[179]4854                option=1;
4855                option_str='civ1';
[177]4856            end
4857        end
[179]4858        if option >= option_civ
[177]4859            count=count+1;
4860        end
4861        [rr,filename,ext]=fileparts(civ_files{ifile});
[179]4862        Tabchar{ifile,1}=[fullfile([subdir extdir],filename) ext  '...' option_str];
[177]4863    end
[219]4864    datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
[188]4865    if isempty(datnum)
4866        if testrecent
4867            message='no civ result created yet';
4868        else
4869            message='';
4870        end
[177]4871    else
[219]4872        datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
[177]4873        [first,ind]=min(datnum);
4874        [last,indlast]=max(datnum);
4875        message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
4876            ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
4877    end
4878    hfig=findobj(allchild(0),'name','civ_status');
4879    if isempty(hfig)
4880        set(handles.status,'Value',0)%stop program if the figure has been suppressed
4881        return
4882    else
4883        hlist=findobj(hfig,'tag','list');
4884        hmsgbox=findobj(hfig,'tag','msgbox');
4885        hwaitbar=findobj(hfig,'tag','waitbar');
4886        set(hlist,'String',Tabchar)
4887        set(hmsgbox,'String', message)
4888        if count>0
4889            BarPosition(3)=0.9*count/nbfiles;
4890            set(hwaitbar,'Position',BarPosition)
4891        end
4892    end
4893    set(hlist,'UserData',rootroot)
4894    pause(5)% wait 5 seconds for next check
4895end
[150]4896
[177]4897   
4898%-------------------------------------------------------------------   
4899% call 'view_field.fig' to display the selected field
4900function open_view_field(hObject, eventdata)
4901%-------------------------------------------------------------------
[246]4902     list=get(hObject,'String');
4903     index=get(hObject,'Value');
4904     rootroot=get(hObject,'UserData');
[177]4905     filename=list{index};
4906     ind_dot=findstr(filename,'...');
4907     filename=filename(1:ind_dot-1);
[188]4908      filename=fullfile(rootroot,filename);
[246]4909      delete(get(hObject,'parent'))%delete the display figure to stop the check process
[177]4910      if exist(filename,'file')%visualise the vel field if it exists
[178]4911        uvmat(filename)
4912        set(gcbo,'Value',1)
[177]4913      end
[150]4914
[182]4915%-------------------------------------------------------------------   
4916% call 'view_field.fig' to display the selected field
4917function close_GUI(hObject, eventdata)
4918%-------------------------------------------------------------------
[220]4919     delete(gcbf)
4920
4921
4922% --- Executes on button press in CivAll.
4923function CivAll_Callback(hObject, eventdata, handles)
[238]4924Listprog=get(handles.CivAll,'String');
4925index=get(handles.CivAll,'Value');
4926prog=Listprog{index};
4927switch prog
4928    case 'CivX'
4929        set(handles.thresh_patch1,'Visible','off')
4930        set(handles.thresh_text1,'Visible','off')
4931        set(handles.rho,'Style','edit')
4932        set(handles.rho,'String','1')
4933    case 'CivAll'
4934        if get(handles.PATCH1,'Value')
4935            set(handles.thresh_patch1,'Visible','on')
4936            set(handles.thresh_text1,'Visible','on')
4937        end
4938        set(handles.rho,'Style','edit')
4939        set(handles.rho,'String','1')
4940    case 'CivUvmat'
4941        if get(handles.PATCH1,'Value')
4942            set(handles.thresh_patch1,'Visible','on')
4943            set(handles.thresh_text1,'Visible','on')
4944        end
4945        set(handles.rho,'Style','popupmenu')
4946        set(handles.rho,'Value',1)
4947        set(handles.rho,'String',{'1';'2'})
[224]4948end
[220]4949
Note: See TracBrowser for help on using the repository browser.