source: trunk/src/civ.m @ 233

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

small bug corrections, and improved display of image correlations (Testcvi1)

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