source: trunk/src/civ.m @ 121

Last change on this file since 121 was 120, checked in by gostiaux, 14 years ago

gedit

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