source: trunk/src/civ.m @ 228

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

add function sub_field_series to apply the sub_field operation to a series of fileds (for instance subtracting a background to an image series)

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