source: trunk/src/civ_3D.m @ 117

Last change on this file since 117 was 72, checked in by sommeria, 15 years ago

ima2vol: write image volumes in 16 bits (test for civ_3D)
plot-text removed: put as a sub-function of plot_field
uvmat: movie stops in case of error in reding files
bug fixes for reading 3D vel fields

File size: 117.4 KB
Line 
1%'civ_3D': function associated with the interface 'civ_3D.fig' for PIV in volume   
2%------------------------------------------------------------------------
3%  provides an interface for the software CIVx
4% function varargout = civ_3D(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
10%     This file is part of the toolbox UVMAT.
11%
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.
16%
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_3D(varargin)
23
24% Last Modified by GUIDE v2.5 26-Mar-2010 22:51:31
25% Begin initialization code - DO NOT EDIT
26gui_Singleton = 1;
27gui_State = struct('gui_Name',       mfilename, ...
28                   'gui_Singleton',  gui_Singleton, ...
29                   'gui_OpeningFcn', @civ_3D_OpeningFcn, ...
30                   'gui_OutputFcn',  @civ_3D_OutputFcn, ...
31                   'gui_LayoutFcn',  [] , ...
32                   'gui_Callback',   []);
33if nargin & isstr(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
44%--------------------------------------------------------------------------
45% --- Executes just before civ_3D is made visible.
46%--------------------------------------------------------------------------
47function civ_3D_OpeningFcn(hObject, eventdata, handles, varargin)
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_3D (see VARARGIN)
53global test_batch patch_new_exe%=1 if patch processing available
54%filebase: root name
55%nom_type: nomencalture used ('png_old','_i_j'...)
56%list of field numbers to process
57%subdir: subdirectory of the opened netcdf file
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_3D
61handles.output = hObject;
62% Update handles structure
63guidata(hObject, handles);
64
65%default initial parameters
66filebase=''; % root file name ('filebase'.civ_3D)
67nom_type=[]; % nomenclature type
68ext=[];
69testall=0;
70browse=[];
71
72%load the initial parameters if the interface is started from uvmat
73if ~isempty(varargin)% the interface is opened from uvmat
74    varcell=varargin{1};
75    filebase=varcell{1};
76    nom_type_read=varcell{2};
77    num1=varcell{3};
78    num2=varcell{4};
79    num_a=varcell{5};
80    num_b=varcell{6};
81    subdir=varcell{7};
82    ind_opening=varcell{8};
83    ind_a_opening=varcell{9};
84    ind_b_opening=varcell{10};
85    ext=varcell{11};
86else
87    num1=1; % set of field i numbers
88    num2=2; % set of field i numbers
89    num_a=1; % set of field j numbers (fields a)
90    num_b=1; % second set of field j numbers (fields b)
91    subdir='A'; % subdir for the netcdf result files
92    ind_opening=1; % proposed operation number (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2)
93    ind_a_opening=1; % proposed index in the menu of fields a
94    ind_b_opening=2; % proposed index in the menu of fields b   
95end
96
97if exist('ext','var') & length(ext)>1 & (~isempty(imformats(ext([2:end])))|...
98                       isequal(ext,'.avi')|isequal(ext,'.AVI'));%if an image file has been opened by uvmat
99        browse.ext_ima=ext;
100        if exist('nom_type_read','var')
101            browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
102        end
103elseif isequal(ext,'.nc')
104    if exist('nom_type_read','var')
105        browse.nom_type_nc=nom_type_read;% the netcdf  nomenclature is stored
106    end
107end
108set(handles.displ_filebase,'String',filebase);
109set(handles.ImaDoc,'UserData',testall);
110set(handles.browse_root,'UserData',browse)
111set(handles.ImaDoc,'String',ext)
112
113
114% set(handles.ImaDoc,'String',ext)
115 
116%read names of the .exe file to adjust the interface according to
117%available prog
118%read names of the .exe file
119path_uvmat=which('uvmat');% check the path detected for source file uvmat
120path_UVMAT=fileparts(path_uvmat); %path to UVMAT
121if isunix
122    syst='LINUX'
123    %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ_3D binary names
124    xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml')
125    if exist(xmlfile,'file')
126        t=xmltree(xmlfile);
127        sparam=convert(t);
128    end
129else
130    syst='WIN'
131    %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ_3D binary names
132    xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
133    if exist(xmlfile,'file')
134        t=xmltree(xmlfile);
135        sparam=convert(t);
136    end
137end
138   
139patch_new_exe='';
140todo_patch='';
141sge=0;
142
143if isfield(sparam,'PatchNew_exe')
144    patch_new_exe=sparam.PatchNew_exe;
145end
146if isfield(sparam,'Todo_path')
147    todo_path=sparam.Todo_path
148end
149if isfield(sparam,'SGE')
150    sge=str2num(sparam.SGE);
151end   
152name_todo=fullfile(todo_path,'TODO.txt')
153test_batch=1;
154if ~sge
155if isequal(todo_path,'') |isequal(todo_path,[])
156    ['no batch distributed processing available:file path TODO.txt not defined in UVMAT/PARAM_' syst]
157    test_batch=0;
158end
159if exist(name_todo,'file')~=2
160    msgbox_uvmat('ERROR',['no batch distributed processing available, queue file ' name_todo ' absent']);
161  %  test_batch=0;  % Problems to detect file on linux/nfs filesystems
162end
163end
164
165
166if test_batch==0
167    set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
168end
169
170set(handles.subdir_civ1,'String',subdir)%default subdir on which uvmat was working
171set(handles.subdir_civ2,'String',subdir)%default subdir on which uvmat was working
172
173%initiate advised operations
174if isequal(ind_opening,[])
175    ind_opening=1; % default
176end
177% set default operation options
178    enable_civ1(handles,'off')
179    enable_civ2(handles,'off')
180    desable_fix1(handles)
181    desable_patch1(handles)
182    desable_fix2(handles)
183    desable_patch2(handles)
184    set(handles.CIV1,'Value',0)
185    set(handles.FIX1,'Value',0)
186    set(handles.PATCH1,'Value',0)
187    set(handles.CIV2,'Value',0)
188    set(handles.FIX2,'Value',0)
189    set(handles.PATCH2,'Value',0)
190    set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
191if isequal(ind_opening,1)
192    set(handles.CIV1,'Value',1)
193    enable_civ1(handles,'on')
194elseif isequal(ind_opening,2)
195    set(handles.FIX1,'Value',1)
196    enable_fix1(handles)
197elseif isequal(ind_opening,3)
198    set(handles.PATCH1,'Value',1)
199    enable_patch1(handles)
200elseif isequal(ind_opening,4)
201    set(handles.CIV2,'Value',1)
202    enable_civ2(handles,1)
203elseif isequal(ind_opening,5)
204    set(handles.FIX2,'Value',1)
205    enable_fix2(handles)
206     set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
207     set(handles.list_pair_civ2,'Enable','On')
208     set(handles.list_pair_civ2,'Enable','On')
209elseif isequal(ind_opening,6)
210    set(handles.PATCH2,'Value',1)
211    enable_patch2(handles)
212    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
213    set(handles.list_pair_civ2,'Enable','On')
214end
215
216% set the range of fields (1:1 by default) and selected pair
217if isempty(num2)|isequal(num2,num1)
218    num_ref_i=num1;
219else
220    num_ref_i=floor((num1+num2)/2);
221    browse.incr_pair(1)=num2-num1;
222    browse.incr_pair(2)=0;
223end
224if isempty(num_b)|isequal(num_a,num_b)
225    if isempty(num_a)
226        num_ref_j=1;
227    else
228        num_ref_j=num_a;
229    end
230else
231    num_ref_j=floor((num_a+num_b)/2);
232    browse.incr_pair(2)=num_b-num_a;
233end
234set(handles.first_i,'String',num2str(num_ref_i));
235set(handles.last_i,'String',num2str(num_ref_i));
236set(handles.ref_i,'String',num2str(num_ref_i));
237set(handles.browse_root,'UserData',browse);
238if ~isempty(varargin)% the interface is opened from uvmat
239    displ_filebase_Callback(hObject, eventdata, handles);
240end
241
242set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
243set(handles.waitbar_patch1,'Position',[0.946 0.626 0.03 0.001])
244set(handles.waitbar_civ2,'Position',[0.946 0.406 0.03 0.001])
245set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
246
247
248%--------------------------------------------------------------
249% --- Outputs from this function are returned to the command line.
250%-----------------------------------------------------------------
251function varargout = civ_3D_OutputFcn(hObject, eventdata, handles)
252% varargout  cell array for returning output args (see VARARGOUT);
253% hObject    handle to figure
254% eventdata  reserved - to be defined in a future version of MATLAB
255% handles    structure with handles and user data (see GUIDATA)
256% Get default command line output from handles structure
257varargout{1} = handles.output;
258
259%------------------------------------------------------------------
260% --- Executes on button press in browse_root.
261function browse_root_Callback(hObject, eventdata, handles)
262%get the input file properties
263filebase=get(handles.displ_filebase,'String');
264oldfile=''; %default
265if isempty(filebase)|isequal(filebase,'')%loads the previously stored file name and set it as default in the file_input box
266     dir_perso=prefdir;
267     profil_perso=fullfile(dir_perso,'uvmat_perso.mat')
268     if exist(profil_perso,'file')
269          h=load (profil_perso);
270         if isfield(h,'filebase')&ischar(h.filebase)
271                 oldfile=h.filebase;
272         end
273         if isfield(h,'RootPath')&ischar(h.RootPath)
274%                 oldfile=h.filebase{1}
275                 oldfile=h.RootPath;
276         end
277     end
278 else
279     oldfile=filebase;
280 end
281testall=get(handles.ImaDoc,'UserData');
282ind_opening=1;%default
283browse.incr_pair=[0 0]; %default
284
285menu={'*.*', 'All Files (*.*)'; '*.xml;*.vol; *.avi;*.AVI','(*.xml,*.civ,*.avi,*.vol)'; ...
286        '*.xml', '.xml files';'*.civ', '.civ files';...
287         '*.avi;*.AVI', '.avi files';'*.vol', '.vol files'};
288
289[FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
290fileinput=[PathName FileName];%complete file name
291sizf=size(fileinput);
292if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
293[path,name,ext]=fileparts(fileinput);
294testeditxml=0;
295if isequal(ext,'.xml')
296    testeditxml=1;
297    t_browse=xmltree(fileinput);
298    head_element=get(t_browse,1);
299    if isfield(head_element,'name')& isequal(head_element.name,'ImaDoc')
300        testeditxml=0;
301    end
302end
303if testeditxml==1 | isequal(ext,'.xls')
304   heditxml=editxml({fileinput});
305   set(heditxml,'Tag','browser')
306   waitfor(heditxml,'Tag','idle')
307   if ~ishandle(heditxml)
308       return
309   end
310   attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
311   set(handles.browse,'UserData',fileinput)% store for future opening with browser
312   fileinput=get(attr,'UserData');
313   if ~exist(fileinput,'file')
314       return
315   end
316end
317[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
318filebase=fullfile(RootPath,RootFile);
319if isequal(get(handles.compare,'Value'),1)
320    browse=get(handles.browse_root,'UserData');
321else
322    browse=[];%initialisation
323end
324if length(ext)>1 & (~isempty(imformats(ext([2:end])))||...
325                       isequal(lower(ext),'.avi')||isequal(ext,'.vol'));%if an image file has been opened by uvmat
326    browse.ext_ima=ext;
327    browse.nom_type_ima=nom_type;
328    browse.field_count=str2num(field_count);
329end
330set(handles.ImaDoc,'String',ext);
331%%%%% read the state of the selected netcdf file to advise default operation
332if isequal(ext,'.nc')
333    browse.nom_type_nc=nom_type;
334    ind_opening=2;% propose 'fix' as the default option   
335    Data=nc2struct(fileinput,[]);
336    if isfield(Data,'fix') & isequal(Data.fix,1)
337        ind_opening=3;
338    end
339    if isfield(Data,'patch') & isequal(Data.patch,1)
340        ind_opening=4;
341    end
342    if isfield(Data,'civ2') & isequal(Data.civ2,1)
343        ind_opening=5;
344    end
345    if isfield(Data,'fix2') & isequal(Data.fix2,1)
346        ind_opening=6;
347    end
348    if isfield(Data,'pixcmx') & isequal(Data,'pixcmy')
349        browse.pxcmx=Data.pixcmx;
350        browse.pxcmy=Data.pixcmy;
351    end
352    testciv=1; %TO SUPPRESS WITH NEW VERSION OF CIVX
353    subdir='';%default
354    if testciv
355        [Pathbase,Namebase]=fileparts(filebase)
356        [Pathprev,subdir,extdir]=fileparts(Pathbase)
357        subdir=[subdir extdir]
358%         if isequal (subdir,subdir_obs)
359        filebase=fullfile(Pathprev,Namebase)% move upward to get the base name (corresponding to the .civ_3D file and images)
360%         end
361    end
362    set(handles.subdir_civ1,'String',subdir);%set the default subdir directories for installing the .nc results
363    set(handles.subdir_civ2,'String',subdir);
364    browse.testciv=testciv;
365    browse.ind_opening=ind_opening;
366end
367set(handles.displ_filebase,'String',filebase);
368set(handles.ImaDoc,'String',ext);
369if ~isempty(str2num(field_count))
370    ref_i=str2num(field_count);
371    if ~isempty(str2num(str2))
372        ref_i=floor((ref_i+str2num(str2))/2);% reference image number corresponding to the file
373        browse.incr_pair(1)=str2num(str2)-str2num(field_count);
374        browse.incr_pair(2)=0;
375    end
376    set(handles.first_i,'String',num2str(ref_i));
377    set(handles.last_i,'String',num2str(ref_i));
378    set(handles.ref_i,'String',num2str(ref_i));
379end
380if isequal(ind_opening,1)
381    set(handles.CIV1,'Value',1)
382    enable_civ1(handles,'on')
383elseif isequal(ind_opening,2)
384    set(handles.FIX1,'Value',1)
385    enable_fix1(handles)
386elseif isequal(ind_opening,3)
387    set(handles.PATCH1,'Value',1)
388    enable_patch1(handles)
389elseif isequal(ind_opening,4)
390    set(handles.CIV2,'Value',1)
391    enable_civ2(handles,1)
392elseif isequal(ind_opening,5)
393    set(handles.FIX2,'Value',1)
394    enable_fix2(handles)
395     set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
396     set(handles.list_pair_civ2,'Enable','On')
397     set(handles.list_pair_civ2,'Enable','On')
398elseif isequal(ind_opening,6)
399    set(handles.PATCH2,'Value',1)
400    enable_patch2(handles)
401    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
402    set(handles.list_pair_civ2,'Enable','On')
403end
404set(handles.browse_root,'UserData',browse);% store information from browser
405testall=isequal(menu(filtindex,1),{'*.*'});
406set(handles.ImaDoc,'UserData',testall);
407
408displ_filebase_Callback(hObject, eventdata, handles);
409
410%------------------------------------------------
411
412function ImaDoc_Callback(hObject, eventdata, handles)
413displ_filebase_Callback(hObject, eventdata, handles)
414
415%--------------------------------------------------------------
416%function activated when a new filebase (image series) is introduced
417%------------------------------------------------------------
418function displ_filebase_Callback(hObject, eventdata, handles)
419
420global test_batch
421set(gcf,'Pointer','watch')
422ext_ima=[]; %default
423nom_type_ima=[];%default
424field_count=1;%default
425nom_type_nc=[];
426npx=[];%default
427npy=[];
428TimeUnit='s'; %default
429CoordUnit='cm';%default
430pxcmx_search=[];%default
431pxcmy_search=[];%default
432filebase=get(handles.displ_filebase,'String');
433
434ext=get(handles.ImaDoc,'String');
435browse=get(handles.browse_root,'UserData');%default
436if ~isempty(browse)
437    if isfield(browse,'ext_ima')
438        ext_ima=browse.ext_ima;
439    end
440    if isfield(browse,'nom_type_ima')
441        nom_type_ima=browse.nom_type_ima;
442    end
443    if isfield(browse,'field_count')
444        field_count=browse.field_count;
445    end
446end
447
448%default first_i and j and increments
449first_i=str2num(get(handles.first_i,'String'));%value possibly set by uvmat_Opening
450if isempty(first_i)| first_i < 1
451    first_i=1; %default first_i
452end
453last_i=str2num(get(handles.last_i,'String'));
454if isempty(last_i)| last_i < first_i
455    last_i=first_i;  %default last_i
456end
457
458incr_i=str2num(get(handles.incr_i,'String'));
459if isempty(incr_i) | incr_i < 1;
460    set(handles.incr_i,'String','1') %default incr_i
461end
462dt=[];%default
463testmode=0;%default
464nbfield=1; %default
465if isfield(browse,'pxcmx') & isfield(browse,'pxcmy')
466    pxcmx=num2str(browse.pxcmx);
467    pxcmy=num2str(browse.pxcmy);
468else
469    pxcmx=1;%default
470    pxcmy=1;
471end
472 %look for an image documentation file
473if ~isequal(ext,'.xml') & ~ isequal(ext,'.avi')& ~ isequal(ext,'.AVI')
474    if exist([filebase '.xml'],'file')
475         ext='.xml';
476         set(handles.ImaDoc,'String','.xml')
477    elseif exist([filebase '.civ_3D'],'file')
478         ext='.civ_3D';
479         set(handles.ImaDoc,'String','.civ_3D')
480    elseif exist([filebase '.avi'],'file')
481         ext='.avi';
482         set(handles.ImaDoc,'String','.avi')
483    elseif exist([filebase '.AVI'],'file')
484         ext='.AVI';
485         set(handles.ImaDoc,'String','.AVI')
486    end
487end
488%%%%%%%%   read image documentation file  %%%%%%%%%%%%%%%%%%%%%%%%%%%
489    mode=''; %default
490if isequal(ext,'.xml')
491    [XmlData,warntext]=imadoc2struct([filebase '.xml'])
492        if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')
493            [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
494        end
495        if isfield(XmlData,'TimeUnit')
496                TimeUnit=XmlData.TimeUnit;
497        end
498        if isfield(XmlData,'Npx')&&isfield(XmlData,'Npy')
499            set(handles.npx,'String',num2str(XmlData.Npx));
500            set(handles.npy,'String',num2str(XmlData.Npy));
501        end
502        if isfield(XmlData,'Time')&&~isempty(XmlData.Time)
503            time=XmlData.Time;
504            set(handles.npz,'String',num2str(size(time,2)));
505        end
506        pxcmx_search=1;
507        pxcmy_search=1;
508        if isfield(XmlData,'GeometryCalib')
509            tsai=XmlData.GeometryCalib;
510            if isfield(tsai,'f') & isfield(tsai,'Tz') & isfield(tsai,'dpx') & isfield(tsai,'dpy')& isfield(tsai,'R')
511                 rot2D=tsai.R([1:2],[1,2]);
512                 pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
513                 pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);           
514            end
515            if isfield(tsai,'CoordUnit')
516                 CoordUnit=tsai.CoordUnit;
517            end
518        end               
519        if isempty(ext_ima_read)
520              ext_ima='.png';%default
521        else
522              ext_ima=ext_ima_read;
523        end
524        if isempty(nom_type_read)
525                nom_type_ima='_i_j';
526                msgbox_uvmat('WARNING','no ImageName defined in ImaDoc/Heading, take _i_j indexing by default')
527        else
528                nom_type_ima=nom_type_read;
529        end
530       
531elseif isequal(ext,'.avi')|isequal(ext,'.AVI')
532        nom_type_ima='avi';
533        ext_ima=ext;
534        set(handles.mode,'String',{'series(Di)'})
535        dt=0.04;%default
536        if exist([filebase ext],'file')==2
537            info=aviinfo([filebase ext]);%read infos on the avi movie
538            dt=1/info.FramesPerSecond;%time interval between successive frames
539            nbfield=info.NumFrames;%number of frames
540        end
541        time=(dt*[0:nbfield-1])';%list of image times   
542        set(handles.dt,'String',num2str(dt*1000));%store the time interval between successive images
543       
544     % no image documentation file found: look for a series of existing images or .nc files
545elseif ~isequal(ext,'.nc')
546        subdir=get(handles.subdir_civ1,'String');
547        incr_pair=[0 0];%default
548        if isfield(browse,'incr_pair')
549                incr_pair=browse.incr_pair;
550        end
551        nbdetect=0;%test of detected images
552        field_i=field_count;
553        idetect=1;
554%         imagename='';%default
555        while idetect==1 %look for the maximum file number in the series
556                field_i=field_i+1;
557%                 imagename_last=imagename;
558                imagename=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
559                idetect=exist(imagename,'file');
560                if isequal(nom_type_ima,'none')
561                   idetect=0; %stop if the same image is repeated (if nom_type='none')
562                   nbdetect=1;
563                end
564                %SEE CASE OF NETCDF FILES
565                nbdetect=nbdetect+idetect;
566        end
567%         nb_field=field_i-1;% last detected field number
568        nb_field=field_i;% last detected field number
569        field_i=field_count;%look for the minimum file number in the series
570        idetect=1;
571        while idetect==1
572                    field_i=field_i-1;
573                    imagename=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
574                    idetect=exist(imagename,'file');
575                    if isequal(nom_type_ima,'none')
576                        idetect=0; %stop if the same image is repeted (if nom_type='none')
577                        nbdetect=1;
578                    end
579                    nbdetect=nbdetect+idetect;
580        end
581        first_i=max(field_i+1,1);
582            %determine the set of times and possible intervals for CIV_3D
583%         dt=(1/1000)*str2num(get(handles.dt,'String'));
584        time=(0:nb_field-1)';
585%             set(handles.incr_i,'UserData',dt);%store the time interval
586%             between successive images
587            %displ_num:list  of possible time intervals for civ_3D calculations
588        set(handles.mode,'String',{'series(Di)'})
589end
590if isequal(nom_type_ima,'none')% no file numbering used
591  first_i=1;
592  last_i=1;
593   first_j=1;
594  last_j=1;
595end
596
597if exist('time','var')
598    nbfield=size(time,1);
599    set(handles.displ_filebase,'UserData',time); %store the set of times
600    set(handles.TimeUnit,'String',TimeUnit);
601    set(handles.nb_field,'String',num2str(nbfield));
602end
603set(handles.CoordUnit,'String',[CoordUnit '/'])
604if isempty(pxcmx_search)
605   set(handles.calcul_search,'UserData',[pxcmx pxcmy]);
606else
607   set(handles.calcul_search,'UserData',[pxcmx_search pxcmy_search]);
608end
609set(handles.first_i,'String',num2str(first_i));
610set(handles.last_i,'String',num2str(last_i));%
611browse.ext_ima=ext_ima;
612browse.nom_type_ima=nom_type_ima;
613set(handles.browse_root,'UserData',browse)% store the nomenclature type
614
615        %%%%%%%%%%%  set the menus of image pairs and default selection for civ_3D   %%%%%%%%%%%%%%%%%%%
616if isequal(get(handles.compare,'Value'),1)
617    if isequal(nom_type_ima,'_i')| isequal(nom_type_nc,'_i1-i2')|~exist('nbfield2','var')|(nbfield2==1)
618        set(handles.mode,'String',{'st_series(Di)';'displacement'})
619        set(handles.mode,'Value',1)
620    elseif (nbfield==1)% simple series in j
621        set(handles.mode,'String',{'st_series(Dj)';'displacement'})
622        set(handles.mode,'Value',1)
623    else
624        set(handles.mode,'String',{'st_pair j1-j2';'st_series(Dj)';'st_series(Di)';'displacement'})%multiple choice
625        if isequal(mode,'volume')
626            set(handles.mode,'Value',3)
627        elseif nbfield2 <= 5
628            set(handles.mode,'Value',1)% advice 'pair j1-j2' for small bursts
629        end
630    end
631else
632    if isequal(nom_type_ima,'_i')| isequal(nom_type_nc,'_i1-i2')|~exist('nbfield2','var')|(nbfield2==1)
633        set(handles.mode,'String',{'series(Di)'})
634        set(handles.mode,'Value',1)
635    elseif isequal(nom_type_ima,'png_old')|isequal(nom_type_nc,'netc_old')
636        set(handles.mode,'String',{'pair j1-j2'})
637        set(handles.mode,'Value',1)
638    elseif (nbfield==1)% simple series in j
639        set(handles.mode,'String',{'series(Dj)'})
640        set(handles.mode,'Value',1)
641    else
642        set(handles.mode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
643        if isequal(mode,'volume')
644            set(handles.mode,'Value',3)
645        elseif nbfield2 <= 5
646            set(handles.mode,'Value',1)% advice 'pair j1-j2' for small bursts
647        else
648            set(handles.mode,'Value',2)% advice series Dj for long bursts, not volume
649        end
650    end
651end
652mode_Callback(hObject, eventdata, handles) 
653
654%%%%%% initialize waitbars and RUN button
655set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
656set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
657set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
658set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
659set(handles.RUN, 'Enable','On')
660set(handles.RUN,'BackgroundColor',[1 0 0])
661if isequal(test_batch,1)%if batch installation is available
662    set(handles.BATCH, 'Enable','On')
663    set(handles.BATCH,'BackgroundColor',[1 0 0])
664end
665   
666%%%%% store the root input filename for future opening
667dir_perso=prefdir;
668profil_perso=fullfile(prefdir,'uvmat_perso.mat');
669RootPath=fileparts(filebase);
670if exist(profil_perso,'file')
671    save (profil_perso,'RootPath','-append'); %store the root name for future opening of uvmat
672else
673    txt=ver;
674    Release=txt(1).Release;
675    relnumb=str2num(Release(3:4));
676    if relnumb >= 14
677        save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
678    else
679        save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
680    end
681end
682% save(profil_perso, 'filebase'); %store the root name for future opening of uvmat
683set(gcf,'Pointer','arrow')
684
685%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
686% --- Executes on button press in mode.
687%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
688function mode_Callback(hObject, eventdata, handles)
689browse=get(handles.browse_root,'UserData');
690mode_list=get(handles.mode,'String');
691mode_value=get(handles.mode,'Value');
692mode=mode_list{mode_value};
693displ_num=[];%default
694first_i=str2num(get(handles.first_i,'String'));
695% last_i=str2num(get(handles.last_i,'String'));
696time=get(handles.displ_filebase,'UserData'); %get the set of times
697siztime=size(time);
698nbfield=siztime(1);
699nbfield2=siztime(2);
700indchosen=1;  %%first pair selected by default
701if isequal(mode,'pair j1-j2')| isequal(mode,'st_pair j1-j2')
702    dt=1;
703    displ='';
704    index=0;
705    %get all the time intervals in bursts
706    displ_dt=1;%default
707    nbfield2=min(nbfield2,10),%limitate the number of pairs to 10x10
708%     if nbfield2<2
709%         nbfield2=2,
710%     end
711    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
712        for numod_b=(numod_a+1):nbfield2
713             index=index+1;
714             numlist_a(index)=numod_a;
715             numlist_b(index)=numod_b;
716             if ~isempty(time)
717                dt(numod_a,numod_b)=time(first_i,numod_b)-time(first_i,numod_a);%first time interval dt
718                displ_dt(index)=dt(numod_a,numod_b);
719             else
720                 displ_dt(index)=1
721             end
722         end
723     end
724     [dtsort,indsort]=sort(displ_dt);
725     displ_num(1,:)=numlist_a(indsort);
726     displ_num(2,:)=numlist_b(indsort);
727     displ_num(3,:)=0;
728     displ_num(4,:)=0;
729     set(handles.jtext,'Visible','Off')
730    set(handles.first_j,'Visible','Off')
731    set(handles.last_j,'Visible','Off')
732    set(handles.incr_j,'Visible','Off')
733    set(handles.nb_field2,'Visible','Off')
734    set(handles.ref_j,'Visible','Off')
735elseif isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
736     for index=1:min(nbfield2-1,200)
737         displ_num(1,index)=-floor(index/2);
738         displ_num(2,index)=ceil(index/2);
739         displ_num(3,index)=0;
740         displ_num(4,index)=0;
741     end       
742     set(handles.jtext,'Visible','On')
743     set(handles.first_j,'Visible','On')
744     set(handles.last_j,'Visible','On')
745     set(handles.incr_j,'Visible','On')
746     set(handles.nb_field2,'Visible','On')
747     set(handles.ref_j,'Visible','On')
748     if nbfield > 1
749        set(handles.itext,'Visible','On')
750        set(handles.first_i,'Visible','On')
751        set(handles.last_i,'Visible','On')
752        set(handles.incr_i,'Visible','On')
753        set(handles.nb_field,'Visible','On')
754        set(handles.ref_i,'Visible','On')
755    else
756        set(handles.itext,'Visible','Off')
757        set(handles.first_i,'Visible','Off')
758        set(handles.last_i,'Visible','Off')
759        set(handles.incr_i,'Visible','Off')
760        set(handles.nb_field,'Visible','Off')
761        set(handles.ref_i,'Visible','Off')
762    end
763elseif isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
764     for index=1:min(nbfield-1,200)
765         displ_num(1,index)=0;
766         displ_num(2,index)=0;
767         displ_num(3,index)=-floor(index/2);
768         displ_num(4,index)=ceil(index/2);
769     end
770     set(handles.itext,'Visible','On')
771     set(handles.first_i,'Visible','On')
772     set(handles.last_i,'Visible','On')
773     set(handles.incr_i,'Visible','On')
774     set(handles.nb_field,'Visible','On')
775     set(handles.ref_i,'Visible','On')
776elseif isequal(mode,'displacement')%the pairs have the same indices
777     displ_num(1,1)=0;
778     displ_num(2,1)=0;
779     displ_num(3,1)=0;
780     displ_num(4,1)=0;
781     if nbfield > 1
782        set(handles.itext,'Visible','On')
783        set(handles.first_i,'Visible','On')
784        set(handles.last_i,'Visible','On')
785        set(handles.incr_i,'Visible','On')
786        set(handles.nb_field,'Visible','On')
787        set(handles.ref_i,'Visible','On')
788    else
789        set(handles.itext,'Visible','Off')
790        set(handles.first_i,'Visible','Off')
791        set(handles.last_i,'Visible','Off')
792        set(handles.incr_i,'Visible','Off')
793        set(handles.nb_field,'Visible','Off')
794        set(handles.ref_i,'Visible','Off')
795    end
796    if nbfield2 > 1
797      set(handles.jtext,'Visible','On')
798     set(handles.first_j,'Visible','On')
799     set(handles.last_j,'Visible','On')
800     set(handles.incr_j,'Visible','On')
801     set(handles.nb_field2,'Visible','On')
802     set(handles.ref_j,'Visible','On')
803    else
804        set(handles.jtext,'Visible','Off')
805        set(handles.first_j,'Visible','Off')
806        set(handles.last_j,'Visible','Off')
807        set(handles.incr_j,'Visible','Off')
808        set(handles.nb_field2,'Visible','Off')
809        set(handles.ref_j,'Visible','Off')
810    end
811end 
812set(handles.list_pair_civ1,'UserData',displ_num);
813find_netcpair_civ1(hObject, eventdata, handles)
814find_netcpair_civ2(hObject, eventdata, handles)
815
816%--------------------------------------------------------------
817% determine the menu for civ1 pairs depending on existing netcdf file at the middle of
818% the field series set by first_i, incr, last_i
819%----------------------------------------------------------------
820function find_netcpair_civ1(hObject, eventdata, handles)
821set(gcf,'Pointer','watch')
822%nomenclature types
823filebase=get(handles.displ_filebase,'String');
824[filepath,Nme,ext_dir]=fileparts(filebase);
825browse=get(handles.browse_root,'UserData');
826mode_list=get(handles.mode,'String');
827mode_value=get(handles.mode,'Value');
828mode=mode_list{mode_value};
829% nomenclature type of the .nc files
830nom_type_ima=[];%default
831if isfield(browse,'nom_type_ima')
832    nom_type_ima=browse.nom_type_ima;
833end
834
835%determine nom_type_nc:
836nom_type_nc=[];%default
837if isfield(browse,'nom_type_nc')
838    nom_type_nc=browse.nom_type_nc;
839end
840if isequal(nom_type_ima,'png_old') | isequal(nom_type_nc,'netc_old')| isequal(nom_type_ima,'raw_SMD')
841    nom_type_nc='netc_old';%nom_type for the netcdf files
842elseif isequal(nom_type_ima,'none')|isequal(nom_type_nc,'none')
843    nom_type_nc='none';
844elseif isequal(nom_type_ima,'avi')|isequal(nom_type_ima,'_i')|isequal(nom_type_ima,'ima_num')|...
845        isequal(nom_type_nc,'_i1-i2')
846     nom_type_nc='_i1-i2';
847elseif isequal(nom_type_ima,'_i_j1-j2')||isequal(nom_type_nc,'_i1-i2_j1-j2')
848     nom_type_nc='_i1-i2_j1-j2';
849else
850    if  isequal(mode,'series(Di)')|isequal(mode,'st_series(Di)')
851        nom_type_nc='_i1-i2_j'; % PIV in volume
852    else
853        nom_type_nc='_i_j1-j2';
854    end   
855end
856browse.nom_type_nc=nom_type_nc;
857set(handles.browse_root,'UserData',browse)
858
859%reads .nc subdirectoy and image numbers from the interface
860subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
861first_i=str2num(get(handles.first_i,'String'));
862last_i=str2num(get(handles.last_i,'String'));
863incr=str2num(get(handles.incr_i,'String'));
864num1=first_i:incr:last_i;
865if isempty(num1)
866    set(handles.list_pair_civ1,'String',{''});
867    return
868end
869ref_i=str2num(get(handles.ref_i,'String'));
870time=get(handles.displ_filebase,'UserData');%get the set of times
871if isempty(time)
872    time=[0 1];
873end
874displ_num=get(handles.list_pair_civ1,'UserData');
875
876%eliminate the first pairs inconsistent with the position
877if isempty(displ_num)
878    nbpair=0;
879else
880    nbpair=length(displ_num(1,:));%nbre of displayed pairs
881    if  isequal(mode,'series(Di)')  | isequal(mode,'st_series(Di)')
882        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
883    elseif  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
884        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
885    end
886end
887nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
888
889%look for existing processed pairs involving the field at the middle of the series if civ1 will not
890% be performed, while the result is needed for next steps.
891displ_pair={''};
892select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
893testpair=0;
894if get(handles.CIV1,'Value')==0 %
895    dirname=fullfile(filepath,subdir_civ1,ext_dir);
896    if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
897         msgbox_uvmat('ERROR',['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist']);
898         set(handles.list_pair_civ1,'String',{});
899         return
900    end
901    for ipair=1:nbpair   
902        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
903        ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
904        select(ipair)=exist(filename,'file');
905    end
906    if ~exist('select','var') | isequal(select,zeros(size(1:nbpair)))
907        if isfield(browse,'incr_pair')
908            num_i1=ref_i-floor(browse.incr_pair(1)/2);
909            num_i2=ref_i+ceil(browse.incr_pair(1)/2);
910            num_j1=ref_j-floor(browse.incr_pair(2)/2);
911            num_j2=ref_j+ceil(browse.incr_pair(2)/2);
912            [filename]=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
913            select(1)=exist(filename,'file');
914            testpair=1;
915        else
916            if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
917                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ1]);
918            else
919                msgbox_uvmat('ERROR',['no civ1 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ1]);
920            end
921             set(handles.list_pair_civ1,'String',{''});
922             %COMPLETER CAS STEREO
923            return
924        end
925    end
926end
927if isequal(mode,'series(Di)')
928    if testpair
929              displ_pair{1}=['Di= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];       
930    else
931       for ipair=1:nbpair
932          if select(ipair)         
933              dt=time(ref_i+displ_num(4,ipair),1)-time(ref_i+displ_num(3,ipair),1);%time interval dt
934              displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
935          else
936             displ_pair{ipair}='...'; %pair not displayed in the menu
937          end
938       end
939    end
940elseif isequal(mode,'pair j1-j2')%case of pairs
941    for ipair=1:nbpair
942        if select(ipair)
943           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
944           displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
945                        ' :dt= ' num2str(dt*1000)];
946       else
947          displ_pair{ipair}='...'; %pair not displayed in the menu
948        end   
949   end
950elseif isequal(mode,'displacement')
951    displ_pair={'Di=Dj=0'}; 
952end   
953set(handles.list_pair_civ1,'String',displ_pair');
954ichoice=min(find(select));
955if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
956initial=get(handles.list_pair_civ1,'Value');
957if initial>nbpair |~isequal(select(initial),1)
958    set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
959end
960set(handles.list_pair_civ2,'String',displ_pair');
961initial=get(handles.list_pair_civ2,'Value');
962if initial>nbpair |~isequal(select(initial),1)
963    set(handles.list_pair_civ2,'Value',ichoice);% same pair proposed by default for civ2
964end
965set(gcf,'Pointer','arrow')
966%--------------------------------------------------------------
967% determine the menu for civ2 pairs depending on the existing netcdf file at the
968%middle of the series set by first_i, incr, last_i
969%--------------------------------------------------------------
970function find_netcpair_civ2(hObject, eventdata, handles)
971return %do not exist in 3D
972set(gcf,'Pointer','watch')
973%nomenclature types
974filebase=get(handles.displ_filebase,'String');
975[filepath,Nme,ext_dir]=fileparts(filebase);
976browse=get(handles.browse_root,'UserData');
977mode_list=get(handles.mode,'String');
978mode_value=get(handles.mode,'Value');
979mode=mode_list{mode_value};
980
981% nomenclature type of the .nc files
982nom_type_ima='ima_num';%default
983if isfield(browse,'nom_type_ima')
984    nom_type_ima=browse.nom_type_ima;
985end
986nom_type_nc='_i1-i2';%default
987if isfield(browse,'nom_type_nc')
988    nom_type_nc=browse.nom_type_nc;
989end
990if isequal(nom_type_ima,'png_old') | isequal(nom_type_ima,'netc_old')| isequal(nom_type_ima,'raw_SMD')| isequal(nom_type_nc,'netc_old')
991    nom_type_nc='netc_old';%nom_type for the netcdf files
992elseif isequal(nom_type_ima,'none')|isequal(nom_type_nc,'none')
993    nom_type_nc='none';
994elseif isequal(nom_type_ima,'avi')|isequal(nom_type_ima,'_i')|isequal(nom_type_ima,'ima_num')|isequal(nom_type_nc,'_i1-i2')
995     nom_type_nc='_i1-i2';
996else
997    if  isequal(mode,'series(Di)')|isequal(mode,'st_series(Di)')
998        nom_type_nc='_i1-i2_j'; % PIV in volume
999    else
1000        nom_type_nc='_i_j1-j2';
1001    end   
1002end
1003browse.nom_type_nc=nom_type_nc;
1004set(handles.browse_root,'UserData',browse)
1005
1006%reads .nc subdirectory and image numbers from the interface
1007subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
1008subdir_civ2=get(handles.subdir_civ2,'String');%subdirectory subdir_civ2 for the netcdf data
1009first_i=str2num(get(handles.first_i,'String'));
1010last_i=str2num(get(handles.last_i,'String'));
1011incr=str2num(get(handles.incr_i,'String'));
1012num1=first_i:incr:last_i;
1013if isempty(num1)
1014    set(handles.list_pair_civ2,'String',{});
1015    return
1016end
1017ref_i=str2num(get(handles.ref_i,'String'));
1018if isequal(mode,'pair j1-j2')|isequal(mode,'st_pair j1-j2')
1019    ref_j=0;
1020else
1021    ref_j=str2num(get(handles.ref_j,'String'));
1022end
1023time=get(handles.displ_filebase,'UserData'); %get the set of times
1024if isempty(time)
1025    time=[0 1];%default
1026end
1027dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
1028displ_num=get(handles.list_pair_civ1,'UserData');
1029
1030
1031%eliminate the first pairs inconsistent with the position
1032if isempty(displ_num)
1033    nbpair=0;
1034else
1035    nbpair=length(displ_num(1,:));%nbre of displayed pairs
1036    if  isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
1037        nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
1038    elseif  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
1039        nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
1040    end
1041end
1042nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
1043
1044%look for existing processed pairs involving the field at the middle of the series if civ1 will not
1045% be performed, while the result is needed for next steps.
1046displ_pair={''}; %default
1047select=ones(size(1:nbpair));%default =1 for nubers of displayed pairs
1048if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0%&...
1049    if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
1050         errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
1051         set(handles.list_pair_civ2,'String',{});
1052         return
1053    end
1054    for ipair=1:nbpair       
1055        [filename]=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
1056        ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
1057        select(ipair)=exist(filename,'file');
1058    end
1059    if  isequal(select,zeros(size(1:nbpair)))
1060        if isfield(browse,'incr_pair')
1061            num_i1=ref_i-floor(browse.incr_pair(1)/2);
1062            num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
1063            num_j1=ref_j-floor(browse.incr_pair(2)/2);
1064            num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
1065            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
1066            select(1)=exist(filename,'file');
1067        else
1068            if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
1069                msgbox_uvmat('ERROR',['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
1070            else
1071                msgbox_uvmat('ERROR',['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
1072            end
1073             set(handles.list_pair_civ2,'String',{});
1074            return
1075        end
1076    end
1077end
1078if isequal(mode,'series(Di)')  | isequal(mode,'st_series(Di)')
1079    if  ~isequal(get(handles.ext_txt,'String'),'dt(ms)=')
1080       for ipair=1:nbpair
1081          if select(ipair)
1082              dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
1083              displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
1084          else
1085             displ_pair{ipair}='...'; %pair not displayed in the menu
1086          end
1087       end
1088   else
1089       for ipair=1:nbpair
1090         if select(ipair)
1091            displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt_unit*ipair)];
1092         else
1093            displ_pair{ipair}='...'; %pair not displayed in the menu
1094         end
1095       end
1096    end
1097elseif isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)') % series on the j index
1098       for ipair=1:nbpair
1099          if select(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          else
1103             displ_pair{ipair}='...'; %pair not displayed in the menu
1104          end
1105       end
1106elseif isequal(mode,'pair j1-j2') | isequal(mode,'st_pair j1-j2') %case of pairs
1107    for ipair=1:nbpair
1108        if select(ipair)
1109           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
1110           displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
1111                        ' :dt= ' num2str(dt*1000)];
1112       else
1113          displ_pair{ipair}='...'; %pair not displayed in the menu
1114       end   
1115   end
1116elseif isequal(mode,'displacement')
1117    displ_pair={'Di=Dj=0'}; 
1118end   
1119set(handles.list_pair_civ2,'String',displ_pair');
1120ichoice=min(find(select));
1121if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
1122if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
1123    set(handles.list_pair_civ2,'Value',ichoice);% first valid pair proposed by default in the menu
1124end
1125set(gcf,'Pointer','arrow')
1126%----------------------------------------------------
1127%  determine the list of index pairs of processing file
1128%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1129function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
1130    find_pair_indices(handles,mode)
1131first_i=str2num(get(handles.first_i,'String'));
1132last_i=str2num(get(handles.last_i,'String'));
1133incr=str2num(get(handles.incr_i,'String'));
1134list_civ1=get(handles.list_pair_civ1,'String');
1135index_civ1=get(handles.list_pair_civ1,'Value');
1136str_civ1=list_civ1{index_civ1};
1137list_civ2=get(handles.list_pair_civ2,'String');
1138index_civ2=get(handles.list_pair_civ2,'Value');
1139str_civ2=list_civ2{index_civ2};
1140if isempty(first_i), msgbox_uvmat('ERROR','first field number not defined'),...
1141    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1142if isempty(last_i),msgbox_uvmat('ERROR','last field number not defined'),...
1143    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1144if isempty(incr), msgbox_uvmat('ERROR','increment in field number not defined'),...
1145    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1146if last_i < first_i , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1147    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1148num1=[first_i:incr:last_i];
1149if isequal (mode,'series(Di)')
1150     %recognize the pair civ1 from the display
1151        indsel=find((double(str_civ1)<48)|(double(str_civ1)>57));% character indices of non numerical characters
1152    str_raw=str_civ1(indsel);
1153    indsepar=find(str_raw=='|'); %character index of the separator
1154    d1=str2num(str_civ1([indsel(indsepar-1)+1:indsel(indsepar)-1]));
1155    if indsepar==length(str_raw)
1156        d2=str2num(str_civ1([indsel(indsepar)+1:end]));
1157    else
1158        d2=str2num(str_civ1([indsel(indsepar)+1:indsel(indsepar+1)-1]));
1159    end   
1160    %recognize the pair civ2 from the display
1161    num1_civ1=num1-d1;% set of first image numbers
1162    num2_civ1=num1+d2;
1163    num_a_civ1=1;
1164    num_b_civ1=1;
1165    num1_civ2=num1-floor(index_civ2/2)*ones(size(num1));% set of first image numbers
1166    num2_civ2=num1+ceil(index_civ2/2)*ones(size(num1));
1167    num1_civ2=num1-d1;% set of first image numbers
1168    num2_civ2=num1+d2;
1169    num_a_civ2=1;
1170    num_b_civ2=1;
1171    % adjust the first and last field number
1172    lastfield=str2num(get(handles.nb_field,'String'));
1173    if isequal(lastfield,[])
1174        indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
1175    else
1176        indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
1177    end
1178    if length(indsel)>=1
1179        firstind=indsel(1);
1180        lastind=indsel(end);
1181        set(handles.first_i,'String',num2str(num1(firstind)))%update the display of first and last fields
1182        set(handles.last_i,'String',num2str(num1(lastind)))
1183        num1=num1(indsel);
1184        num1_civ1=num1_civ1(indsel);
1185        num1_civ2=num1_civ2(indsel);
1186        num2_civ1=num2_civ1(indsel);
1187        num2_civ2=num2_civ2(indsel);
1188    end
1189elseif isequal (mode,'series(Dj)')|isequal (mode,'st_series(Dj)')
1190    lastfield_j=str2num(get(handles.nb_field2,'String'));
1191    num1_civ1=num1;% set of first image numbers
1192    num2_civ1=num1;
1193    num_a_civ1=num_j-floor(index_civ1/2)*ones(size(num_j));
1194    num_b_civ1=num_j+ceil(index_civ1/2)*ones(size(num_j));
1195    num1_civ2=num1;
1196    num2_civ2=num1;
1197    num_a_civ2=num_j-floor(index_civ2/2)*ones(size(num_j));
1198    num_b_civ2=num_j+ceil(index_civ2/2)*ones(size(num_j));
1199    % adjust the first and last field number
1200    if isequal(lastfield_j,[])
1201        indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
1202    else
1203        indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
1204    end
1205    if length(indsel)>=1
1206        firstind=indsel(1);
1207        lastind=indsel(end);
1208        set(handles.first_j,'String',num2str(num_j(firstind)))%update the display of first and last fields
1209        set(handles.last_j,'String',num2str(num_j(lastind)))
1210        num_j=num_j(indsel);
1211        num_a_civ1=num_a_civ1(indsel);
1212        num_a_civ2=num_a_civ2(indsel);
1213        num_b_civ1=num_b_civ1(indsel);
1214        num_b_civ2=num_b_civ2(indsel);
1215    end
1216elseif isequal(mode,'pair j1-j2') | isequal(mode,'st_pair j1-j2') %case of bursts (png_old or png_2D)
1217    num1_civ1=num1;
1218    num1_civ2=num1;
1219    displ_num=get(handles.list_pair_civ1,'UserData');
1220    num2_civ1=num1;
1221    num_a_civ1=displ_num(1,index_civ1);
1222    num_b_civ1=displ_num(2,index_civ1);
1223    num2_civ2=num1;
1224    num_a_civ2=displ_num(1,index_civ2);
1225    num_b_civ2=displ_num(2,index_civ2);
1226elseif isequal(mode,'displacement')
1227    num1_civ1=num1;
1228    num2_civ1=num1;
1229    num_a_civ1=num_j;
1230    num_b_civ1=num_j;
1231    num1_civ2=num1;
1232    num2_civ2=num1;
1233    num_a_civ2=num_j;
1234    num_b_civ2=num_j;
1235end
1236
1237
1238%-------------------------------------------------------------
1239% --- Executes on selection change in list_pair_civ1.
1240function list_pair_civ1_Callback(hObject, eventdata, handles)
1241%------------------------------------------------------------
1242%reproduce by default the chosen pair in the civ2 menu
1243list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
1244index_pair=get(handles.list_pair_civ1,'Value');
1245displ_num=get(handles.list_pair_civ1,'UserData');
1246num_a=displ_num(1,index_pair);
1247num_b=displ_num(2,index_pair);
1248set(handles.list_pair_civ2,'Value',index_pair);
1249
1250%update first_i and last_i according to the chosen image pairs
1251mode_list=get(handles.mode,'String');
1252mode_value=get(handles.mode,'Value');
1253mode=mode_list{mode_value};
1254if isequal(mode,'series(Di)')
1255    first_i=str2num(get(handles.first_i,'String'));
1256    last_i=str2num(get(handles.last_i,'String'));
1257    incr_i=str2num(get(handles.incr_i,'String'));
1258    num1=first_i:incr_i:last_i;
1259    lastfield=str2num(get(handles.nb_field,'String'));
1260    if ~isequal(lastfield,[])
1261        ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1262             (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1263        num1=num1(ind);
1264    end
1265    set(handles.first_i,'String',num2str(num1(1)));
1266    set(handles.last_i,'String',num2str(num1(end)));
1267elseif isequal(mode,'series(Dj)')
1268    first_j=str2num(get(handles.first_j,'String'));
1269    last_j=str2num(get(handles.last_j,'String'));
1270    incr_j=str2num(get(handles.incr_j,'String'));
1271    num_j=first_j:incr_j:last_j;
1272    lastfield2=str2num(get(handles.nb_field2,'String'));
1273    if ~isequal(lastfield2,[])
1274        ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1275             (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
1276        num1=num_j(ind);
1277    end
1278    set(handles.first_j,'String',num2str(num1(1)));
1279    set(handles.last_j,'String',num2str(num1(end)));
1280end
1281
1282%------------------------------------------------------------------
1283% --- Executes on selection change in list_pair_civ2.
1284function list_pair_civ2_Callback(hObject, eventdata, handles)
1285
1286index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu
1287
1288%update first_i and last_i according to the chosen image pairs
1289mode_list=get(handles.mode,'String');
1290mode_value=get(handles.mode,'Value');
1291mode=mode_list{mode_value};
1292if isequal(mode,'series(Di)')
1293    first_i=str2num(get(handles.first_i,'String'));
1294    last_i=str2num(get(handles.last_i,'String'));
1295    incr_i=str2num(get(handles.incr_i,'String'));
1296    num1=first_i:incr_i:last_i;
1297    lastfield=str2num(get(handles.nb_field,'String'));
1298    if ~isequal(lastfield,[])
1299        ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
1300             (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1301        num1=num1(ind);
1302    end
1303    set(handles.first_i,'String',num2str(num1(1)));
1304    set(handles.last_i,'String',num2str(num1(end)));
1305elseif isequal(mode,'series(Dj)')
1306    first_j=str2num(get(handles.first_j,'String'));
1307    last_j=str2num(get(handles.last_j,'String'));
1308    incr_j=str2num(get(handles.incr_j,'String'));
1309    num_j=first_j:incr_j:last_j;
1310    lastfield2=str2num(get(handles.nb_field2,'String'));
1311    if ~isequal(lastfield2,[])
1312        ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1313             (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield));
1314        num1=num_j(ind);
1315    end
1316    set(handles.first_j,'String',num2str(num1(1)));
1317    set(handles.last_j,'String',num2str(num1(end)));
1318end
1319
1320
1321
1322
1323%-----------------------------------------------------------
1324% --- Executes on button press in BATCH: remote processing
1325%-----------------------------------------------------------
1326function BATCH_Callback(hObject, eventdata, handles)
1327global civ1_exe civ2_exe patch_exe patch_new_exe fix_exe todo_path sge Civ_exe
1328
1329% pxcmx=get(handles.pxcmx,'String');
1330% pxcmy=get(handles.pxcmy,'String');
1331% npx=get(handles.pxcmx,'UserData');
1332% npy=get(handles.pxcmy,'UserData');
1333
1334%check the list of operations:
1335operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
1336run_flag=1;
1337box_test(1)=get(handles.CIV1,'Value');
1338box_test(2)=get(handles.FIX1,'Value');
1339box_test(3)=get(handles.PATCH1,'Value');
1340box_test(4)=get(handles.CIV2,'Value');
1341box_test(5)=get(handles.FIX2,'Value');
1342box_test(6)=get(handles.PATCH2,'Value');
1343index=find(box_test==1);
1344if isempty(index)
1345    errordlg('no selected operation')
1346    set(handles.BATCH, 'Enable','On')
1347    set(handles.BATCH,'BackgroundColor',[1 0 0])
1348    return
1349end
1350index_first=min(index);
1351index_last=max(index);
1352box_used=box_test([index_first : index_last]);
1353[box_missing,ind_missing]=min(box_used);
1354if isequal(box_missing,0)
1355    errordlg(['missing' cell2mat(operations(ind_missing))]);
1356    set(handles.BATCH, 'Enable','On')
1357    set(handles.BATCH,'BackgroundColor',[1 0 0])
1358    return
1359end
1360
1361%check mask if selecetd
1362if isequal(get(handles.get_mask_civ1,'Value'),1)
1363     get_mask_civ1_Callback(hObject, eventdata, handles);
1364end
1365if isequal(get(handles.get_mask_fix1,'Value'),1)
1366     get_mask_fix1_Callback(hObject, eventdata, handles);
1367end
1368if isequal(get(handles.get_mask_civ2,'Value'),1)
1369     get_mask_civ2_Callback(hObject, eventdata, handles);
1370end
1371if isequal(get(handles.get_mask_fix2,'Value'),1)
1372     get_mask_fix2_Callback(hObject, eventdata, handles);
1373end
1374
1375
1376%read names of the .exe file
1377path_uvmat=which('uvmat');% check the path detected for source file uvmat
1378path_UVMAT=fileparts(path_uvmat); %path to UVMAT
1379%fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ_3D binary names
1380xmlfile=fullfile(path_UVMAT,'PARAM.xml');
1381if exist(xmlfile,'file')
1382    t=xmltree(xmlfile);
1383    sparam=convert(t);
1384end
1385if isfield(sparam.BatchParam,'Civ3D3CBin')
1386    Civ3D3CBin=sparam.BatchParam.Civ3D3CBin;
1387else
1388    msgbox_uvmat('ERROR','binary for CIV3D3C not defined in PARAM.xml')
1389    return
1390end
1391 
1392%choice of batch priority
1393ind_answer=2;
1394% if sge
1395    [s,w]=unix('qstat -q civ_3D.q|grep job_| wc -l'); %check the waiting list (command unix)
1396    if isequal(s,0)
1397        w(end)=[];
1398        str_displ={[w ' jobs in the waiting list'];'Select a priority:'};
1399        str={'urgent';'normal';'low'};
1400        [ind_answer,v] = listdlg('PromptString',str_displ,...
1401                'SelectionMode','single',...
1402                'ListString',str,'ListSize',[200 200],'Name','job priority','InitialValue',3);
1403        if isequal(v,0) % to handle Cancel button and figure close, 
1404           return % a better way should be create
1405        end
1406    else
1407        msgbox_uvmat('ERROR','batch system not available')
1408        return
1409    end
1410% end
1411%initialize the waitbars
1412set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
1413set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
1414set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
1415set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
1416set(handles.BATCH, 'Enable','Off')
1417set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
1418
1419%get the filename root, nomenclature and numbers
1420filebase=get(handles.displ_filebase,'String');
1421% for Windows system find the UBC path name if needed
1422if ~isunix & isequal(todo_path(1:2),'\\') & isequal(filebase(2:3),':\')
1423    cur_dir=pwd;
1424    if ~isequal(cur_dir(2:3),':\')
1425        cd(matlabroot); %move to the Matlab root directory if the current Matlab dir does not allow the dos command or is M:
1426    end
1427    [ss,ww]=dos(['net use ' filebase(1:2)]);
1428    if isequal(ss,0)
1429        rankpath=findstr(ww,'\\');
1430        if ~isempty(rankpath)
1431            wwrest=ww(rankpath:end);
1432            rankend=min(find(double(wwrest)==10))-1;
1433            filebase=[wwrest(1:rankend) filebase(3:end)];
1434            set(handles.displ_filebase,'String',filebase);
1435        end
1436    else
1437         msgbox_uvmat('ERROR','for BATCH option, UBC file names, beginning by \\, are needed');
1438         set(handles.BATCH, 'Enable','On')
1439         set(handles.BATCH,'BackgroundColor',[1 0 0])
1440         return
1441    end
1442end
1443browse=get(handles.browse_root,'UserData')
1444ext_ima=browse.ext_ima;
1445nom_type_nc='_i1-i2';
1446nom_type_ima=browse.nom_type_ima;
1447% nom_type_nc=browse.nom_type_nc;
1448% if isequal(nom_type_ima2,[]),nom_type_ima2='ima_num';end; %default
1449% if isequal(nom_type_nc,[]),nom_type_nc='_i1-i2';end; %default
1450mode_list=get(handles.mode,'String');
1451mode_value=get(handles.mode,'Value');
1452mode=mode_list{mode_value};
1453time=get(handles.displ_filebase,'UserData'); %get the set of times
1454
1455[num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
1456find_pair_indices(handles,mode); %determine the pairs of processing file
1457
1458%check dir
1459subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf output data
1460subdir_civ2=get(handles.subdir_civ2,'String');
1461if isequal(subdir_civ1,''),subdir_civ1='A'; end% put default subdir
1462if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
1463currentdir=pwd;%store the current working directory
1464[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ_3D)
1465if ~exist(Path_ima,'dir')
1466    msgbox_uvmat('ERROR',['path to images ' Path_ima ' not found'])
1467    return
1468end
1469cd(Path_ima);%move to the directory of the images
1470dircur=pwd; %current working directory
1471m2='';
1472[erread,message]=fileattrib(Path_ima);
1473if ~isempty(message) & ~isequal(message.UserWrite,1)
1474      errordlg(['No writting access to ' Path_ima])
1475      cd(currentdir)
1476      return
1477end
1478
1479%test for reference file in fix
1480ref_fix1=get(handles.ref_fix1,'UserData');
1481ref_fix2=get(handles.ref_fix2,'UserData');
1482if (~isempty(ref_fix1) & box_test(2)==1)|(~isempty(ref_fix2) & box_test(5)==1)
1483    errordlg('reference file not implemented in BATCH mode, use RUN')
1484    set(handles.BATCH, 'Enable','On')
1485    set(handles.BATCH,'BackgroundColor',[1 0 0])
1486    return
1487end
1488nbfield=length(num1_civ1);
1489nbslice=length(num_a_civ1);
1490   
1491%check the existence of the netcdf and image files involved
1492% if box_test(1)==1;%CIV1 activated
1493detect=1;
1494while detect==1 %name a new subdir if one of the netcdf files already exists
1495      for ifile=1:nbfield
1496%           for j=1:nbslice
1497              filename=name_generator(filebase,num1_civ1(ifile),[],'.nc',...
1498                '_i1-i2',1,num2_civ1(ifile),[],subdir_civ1);%
1499            detect=exist(filename,'file')
1500              if detect% if a netcdf file already exists
1501                 subdir_civ1=[subdir_civ1 '.0'];
1502                 subdir_civ2=subdir_civ1;
1503                 break
1504              end
1505              filecell_nc1(ifile)={filename};
1506          if detect% if a netcdf file already exists
1507              break
1508          end
1509      end
1510       %create the new subdir_civ1 if it does not exist
1511      if ~exist(fullfile(Path_ima,subdir_civ1),'dir')
1512          [m1,m2,m3]=mkdir(subdir_civ1)
1513           if ~isequal(m2,'')
1514               msgbox(m2);%error message for directory creation
1515          end
1516     end
1517end
1518%get image names
1519for ifile=1:nbfield
1520    filecell_ima1_civ1{ifile}=name_generator(filebase, num1_civ1(ifile),[],'.vol','_i');%first image
1521    filecell_ima2_civ1{ifile}=name_generator(filebase, num2_civ1(ifile),[],'.vol','_i'); %second image
1522     if ~exist(filecell_ima1_civ1{ifile},'file')
1523            msgbox_uvmat('ERROR',[filecell_ima1_civ1{ifile} ' not found'])
1524            set(handles.BATCH, 'Enable','On')
1525            set(handles.BATCH,'BackgroundColor',[1 0 0])
1526            cd(currentdir)
1527            return
1528     end     
1529     if ~exist(filecell_ima2_civ1{ifile},'file')
1530            msgbox_uvmat('ERROR',[filecell_ima2_civ1{ifile} ' not found'])
1531            set(handles.BATCH, 'Enable','On')
1532            set(handles.BATCH,'BackgroundColor',[1 0 0])
1533            cd(currentdir)
1534            return
1535     end
1536end
1537
1538cd(currentdir);%come back to the initial working directory
1539% if ~isequal(m2,'')
1540%      msgbox(m2);%error message for directory creation
1541% end
1542set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
1543set(handles.subdir_civ2,'String',subdir_civ2);%update the edit box
1544browse.nom_type_nc=nom_type_nc;
1545set(handles.browse_root,'UserData',browse);%update the nomenclature type for uvmat
1546
1547for ifile=1:nbfield
1548    i_cmd=0;
1549       cmd='#!/bin/bash';
1550       cmd=char({cmd;'#$ -cwd'});
1551       cmd=char({cmd;'hostname && date'});
1552    filename_cmx=cell2mat(filecell_nc1(ifile));%output netcdf file
1553    filename_cmx([end-1:end])='cm';%name of cmx file
1554    filename_cmx=[filename_cmx 'x'];
1555   
1556%CIV1
1557    if box_test(1)==1
1558        %GET civ_3D PARAMETERS:
1559        par_civ1=read_param_civ1(handles,cell2mat(filecell_ima1_civ1(1,1)));
1560        p1text=[];
1561        [par_civ1.path,resu_file,resu_ext]=fileparts(filecell_nc1{ifile});
1562        par_civ1.volume1=filecell_ima1_civ1{ifile};
1563        par_civ1.volume2=filecell_ima2_civ1{ifile};
1564        par_civ1.nx=str2double(get(handles.npx,'String'));
1565        par_civ1.ny=str2double(get(handles.npy,'String'));;
1566        par_civ1.nz=par_civ1.gridLimits_Zmax - par_civ1.gridLimits_Zmin;
1567        'TEST'
1568        par_civ1
1569        % civAll=get(handles.Experimental,'Value'); % Boolean for new civ excution method
1570        % if isequal(civAll,1)
1571        civAllxml=struct2xml(par_civ1);% xml contents,  all parameters
1572        civAllxml=set(civAllxml,1,'name','civ3d3c');
1573    %    save(civAllxml)
1574        par_civ1_3d_xml=fullfile(par_civ1.path,[resu_file '.xml']);%[par_civ1.path '/test_to_change.xml'];
1575         pvalue=num2str((1-ind_answer)*500)
1576        save(civAllxml,par_civ1_3d_xml);
1577     nb_processor='8';
1578         ['echo /CIVX/bin/MPI/lam-7.1.3_g95/bin/mpirun C  ' Civ3D3CBin ' -p ' par_civ1_3d_xml '|qsub -p ' pvalue ' -q lam.q -pe lam_loose ' nb_processor ' -e ' par_civ1_3d_xml '.errors -o ' par_civ1_3d_xml '.log' ]
1579         eval ( ['!echo /CIVX/bin/MPI/lam-7.1.3_g95/bin/mpirun C  ' Civ3D3CBin ' -p ' par_civ1_3d_xml '|qsub -p ' pvalue ' -q lam.q -pe lam_loose ' nb_processor ' -e ' par_civ1_3d_xml '.errors -o ' par_civ1_3d_xml '.log' ])
1580
1581    end           
1582end
1583
1584set(handles.BATCH, 'Enable','On')
1585set(handles.BATCH,'BackgroundColor',[1 0 0])
1586
1587%save GUI state
1588[Path,Name]=fileparts(filebase);
1589namefig=fullfile(Path,subdir_civ2,Name);
1590detect=1;
1591while detect==1
1592    namefigfull=[namefig '.fig'];
1593    hh=dir(namefigfull);
1594    if ~isempty(hh)
1595        detect=1;
1596        namefig=[namefig '.0'];
1597    else
1598        detect=0;
1599    end
1600end
1601saveas(gcbf,namefigfull);%save the interface with name namefigfull
1602
1603
1604%----------------------------------------
1605%PATCH
1606%---------------------------------------
1607function cmd_PATCH=RUN_PATCH(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp)
1608global patch_exe patch_new_exe
1609        namelog=[filename_nc([1:end-3]) '_patch.log'];
1610        if test_interp==0
1611            cmd_PATCH=[patch_exe ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
1612            '  > ' namelog ' 2>&1'] % redirect standard output to the log file
1613         else %nouveau programme patch
1614             cmd_PATCH=[patch_new_exe ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
1615                ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
1616        end
1617
1618 
1619%----------------------------------------------------
1620function first_j_Callback(hObject, eventdata, handles)
1621last_j_Callback(hObject, eventdata, handles)
1622
1623%---------------------------------------------------------
1624% --- Executes on button press in CIV1.
1625function CIV1_Callback(hObject, eventdata, handles)
1626enable_civ1(handles,get(handles.CIV1,'Value'))
1627find_netcpair_civ1(hObject, eventdata, handles);
1628
1629%------------------------------------------------------
1630% --- Executes on button press in FIX1.
1631function FIX1_Callback(hObject, eventdata, handles)
1632
1633if get(handles.FIX1,'Value')==1
1634enable_fix1(handles)
1635else
1636desable_fix1(handles)
1637end
1638
1639%----------------------------------------------------------------
1640% --- Executes on button press in PATCH1.
1641function PATCH1_Callback(hObject, eventdata, handles)
1642
1643if get(handles.PATCH1,'Value')==1
1644enable_patch1(handles)
1645else
1646desable_patch1(handles)
1647end
1648
1649%----------------------------------------------------------
1650% --- Executes on button press in CIV2.
1651function CIV2_Callback(hObject, eventdata, handles)
1652state=get(handles.CIV2,'Value');
1653enable_civ2(handles,state)
1654if state
1655    find_netcpair_civ2(hObject, eventdata, handles)
1656end
1657
1658%---------------------------------------------------
1659% --- Executes on button press in FIX2.
1660function FIX2_Callback(hObject, eventdata, handles)
1661if get(handles.FIX2,'Value')==1
1662    enable_fix2(handles)
1663    if get(handles.CIV2,'Value')==0
1664        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
1665    end
1666else
1667    desable_fix2(handles)
1668end
1669
1670
1671%-------------------------------------------------------
1672% --- Executes on button press in PATCH2.
1673function PATCH2_Callback(hObject, eventdata, handles)
1674%--------------------------------------------------------
1675if get(handles.PATCH2,'Value')==1
1676    enable_patch2(handles)
1677    if get(handles.CIV2,'Value')==0
1678        find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
1679    end
1680else
1681    desable_patch2(handles)
1682end
1683
1684
1685
1686%-----------------------------------------------------------
1687function first_i_Callback(hObject, eventdata, handles)
1688%------------------------------------------------------
1689last_i_Callback(hObject, eventdata, handles)
1690
1691%-----------------------------------------------------------
1692% --- Executes on button press in calcul_search: determine the search range isx,isy
1693%--------------------------------------------------------
1694function calcul_search_Callback(hObject, eventdata, handles)
1695
1696%determine pair numbers
1697list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
1698index=get(handles.list_pair_civ1,'Value');
1699displ_num=get(handles.list_pair_civ1,'UserData');
1700time=get(handles.displ_filebase,'UserData'); %get the set of times
1701pxcm_xy=get(handles.calcul_search,'UserData')
1702pxcmx=pxcm_xy(1);
1703pxcmy=pxcm_xy(2);
1704mode_list=get(handles.mode,'String');
1705mode_value=get(handles.mode,'Value');
1706mode=mode_list{mode_value};
1707if isequal (mode, 'series(Di)' )
1708    ref_i=str2num(get(handles.ref_i,'String'));
1709    num1=ref_i-floor(index/2);%  first image numbers
1710    num2=ref_i+ceil(index/2);
1711    num_a=1;
1712    num_b=1;
1713elseif isequal (mode, 'series(Dj)')
1714    num1=1;
1715    num2=1;
1716    ref_j=str2num(get(handles.ref_j,'String'));
1717    num_a=ref_j-floor(index/2);%  first image numbers
1718    num_b=ref_j+ceil(index/2);
1719elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
1720    ref_i=str2num(get(handles.ref_i,'String'));
1721    num1=ref_i;
1722    num2=ref_i;
1723    num_a=displ_num(1,index);
1724    num_b=displ_num(2,index);
1725end
1726dt=time(num2,num_b)-time(num1,num_a);
1727ibx=str2num(get(handles.ibx,'String'));
1728iby=str2num(get(handles.iby,'String'));
1729umin=dt*pxcmx*str2num(get(handles.umin,'String'));
1730umax=dt*pxcmx*str2num(get(handles.umax,'String'));
1731vmin=dt*pxcmy*str2num(get(handles.vmin,'String'));
1732vmax=dt*pxcmy*str2num(get(handles.vmax,'String'));
1733shiftx=round((umin+umax)/2);
1734shifty=round((vmin+vmax)/2);
1735isx=(umax+2-shiftx)*2+ibx;
1736isx=2*ceil(isx/2)+1;
1737isy=(vmax+2-shifty)*2+iby;
1738isy=2*ceil(isy/2)+1;
1739set(handles.shiftx,'String',num2str(shiftx));
1740set(handles.shifty,'String',num2str(shifty));
1741set(handles.isx,'String',num2str(isx));
1742set(handles.isy,'String',num2str(isy));
1743
1744
1745%---------------------------------------------------------
1746% Executes on carriage return on the subdir civ1 edit window
1747%--------------------------------------------------------
1748function subdir_civ1_Callback(hObject, eventdata, handles)
1749subdir=get(handles.subdir_civ1,'String');
1750set(handles.subdir_civ2,'String',subdir);
1751if get(handles.CIV1,'Value')==0
1752    find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
1753end
1754
1755%---------------------------------------------------------
1756% Executes on carriage return on the subdir civ1 edit window
1757%---------------------------------------------------------
1758function subdir_civ2_Callback(hObject, eventdata, handles)
1759%update the list of available pairs from netcdf files in the new directory
1760if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
1761    find_netcpair_civ2(hObject, eventdata, handles);
1762end
1763
1764%------------------------------------------------------
1765% --- Executes on button press in get_mask_civ1.
1766%------------------------------------------------------
1767function get_mask_civ1_Callback(hObject, eventdata, handles)
1768maskval=get(handles.get_mask_civ1,'Value')
1769if isequal(maskval,0)
1770    set(handles.mask_civ1,'String','')
1771else
1772mask_displ='no mask'; %default
1773filebase=get(handles.displ_filebase,'String');
1774[ nbslice, flag_mask]=get_mask(filebase,handles)
1775if isequal(flag_mask,1)
1776      mask_displ=[num2str(nbslice) 'mask'];
1777end
1778if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1779        filebase_a=get(handles.displ_filebase2,'String');
1780        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
1781        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
1782            mask_displ='no mask';
1783        end
1784end
1785if isequal(mask_displ,'no mask')
1786    set(handles.get_mask_civ1,'Value',0)
1787    set(handles.get_mask_fix1,'Value',0)
1788    set(handles.get_mask_civ2,'Value',0)
1789    set(handles.get_mask_fix2,'Value',0)
1790else
1791    set(handles.get_mask_fix1,'Value',1)
1792    set(handles.get_mask_civ2,'Value',1)
1793    set(handles.get_mask_fix2,'Value',1)
1794end
1795set(handles.mask_civ1,'String',mask_displ)
1796set(handles.mask_fix1,'String',mask_displ)
1797set(handles.mask_civ2,'String',mask_displ)
1798set(handles.mask_fix2,'String',mask_displ)
1799end
1800%--------------------------------------------------------------
1801% --- Executes on button press in get_mask_fix1.
1802function get_mask_fix1_Callback(hObject, eventdata, handles)
1803maskval=get(handles.get_mask_fix1,'Value')
1804if isequal(maskval,0)
1805    set(handles.mask_fix1,'String','')
1806else
1807mask_displ='no mask'; %default
1808filebase=get(handles.displ_filebase,'String');
1809[nbslice, flag_mask]=get_mask(filebase,handles)
1810if isequal(flag_mask,1)
1811      mask_displ=[num2str(nbslice) 'mask'];
1812end
1813if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1814        filebase_a=get(handles.displ_filebase2,'String');
1815        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
1816        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
1817            mask_displ='no mask';
1818        end
1819end
1820if isequal(mask_displ,'no mask')
1821    set(handles.get_mask_fix1,'Value',0)
1822    set(handles.get_mask_civ2,'Value',0)
1823    set(handles.get_mask_fix2,'Value',0)
1824else
1825    set(handles.get_mask_civ2,'Value',1)
1826    set(handles.get_mask_fix2,'Value',1)
1827end
1828set(handles.mask_fix1,'String',mask_displ)
1829set(handles.mask_civ2,'String',mask_displ)
1830set(handles.mask_fix2,'String',mask_displ)
1831end
1832%-----------------------------------------
1833% --- Executes on button press in get_mask_civ2.
1834function get_mask_civ2_Callback(hObject, eventdata, handles)
1835maskval=get(handles.get_mask_civ2,'Value')
1836if isequal(maskval,0)
1837    set(handles.mask_civ2,'String','')
1838else
1839mask_displ='no mask'; %default
1840filebase=get(handles.displ_filebase,'String');
1841[nbslice, flag_mask]=get_mask(filebase,handles)
1842if isequal(flag_mask,1)
1843      mask_displ=[num2str(nbslice) 'mask'];
1844end
1845if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1846        filebase_a=get(handles.displ_filebase2,'String');
1847        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
1848        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
1849            mask_displ='no mask';
1850        end
1851end
1852if isequal(mask_displ,'no mask')
1853    set(handles.get_mask_civ2,'Value',0)
1854    set(handles.get_mask_fix2,'Value',0)
1855else
1856    set(handles.get_mask_fix2,'Value',1)
1857end
1858set(handles.mask_civ2,'String',mask_displ)
1859set(handles.mask_fix2,'String',mask_displ)
1860end
1861%-------------------------------------
1862% --- Executes on button press in get_mask_fix2.
1863function get_mask_fix2_Callback(hObject, eventdata, handles)
1864maskval=get(handles.get_mask_fix2,'Value')
1865if isequal(maskval,0)
1866    set(handles.mask_fix2,'String','')
1867else
1868mask_displ='no mask'; %default
1869filebase=get(handles.displ_filebase,'String');
1870[nbslice, flag_mask]=get_mask(filebase,handles)
1871if isequal(flag_mask,1)
1872      mask_displ=[num2str(nbslice) 'mask'];
1873end
1874if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1875        filebase_a=get(handles.displ_filebase2,'String');
1876        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
1877        if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
1878            mask_displ='no mask';
1879        end
1880end
1881if isequal(mask_displ,'no mask')
1882    set(handles.get_mask_fix2,'Value',0)
1883end
1884set(handles.mask_fix2,'String',mask_displ)
1885end
1886
1887%---------------------------------------
1888function [nbslice, flag_mask]=get_mask(filebase,handles)
1889%detect mask files, images with appropriate file base
1890%[filebase '_' xx 'mask'], xx=nbslice
1891%flag_mask=1 indicates detection
1892
1893flag_mask=0;%default
1894nbslice=1;
1895
1896% subdir=get(handles.subdir_civ1,'String');
1897[Path,Name]=fileparts(filebase)
1898currentdir=pwd;
1899cd(Path);%move in the dir of the root name filebase
1900maskfiles=dir([Name '_*mask_*.png'])%look for mask files
1901cd(currentdir);%come back to the current working directory
1902if isempty(maskfiles)
1903    browse=get(handles.browse_root,'UserData');
1904     varargin{1}='';
1905    image_name=name_generator(filebase,1,1,browse.ext_ima,browse.nom_type_ima);%name of an image
1906    if exist(image_name,'file')
1907         varargin{1}=image_name;
1908    end
1909    msgbox_uvmat('ERROR','no mask available, use TOOL menu in the uvmat interface to create it')
1910%     makemask(varargin); %open the makemask interface
1911else
1912    maskname=maskfiles(1).name;% take the first mask file in the list
1913    [Path2,Name,ext]=fileparts(maskname);
1914    Namedouble=double(Name);
1915    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1916    ind_mask=findstr('mask',Name);
1917    i=ind_mask-1;
1918    while val(i)==0 & i>0
1919       i=i-1;
1920    end
1921    nbslice=str2num(Name(i+1:ind_mask-1));
1922    if ~isequal(nbslice,[]) & Name(i)=='_'
1923          flag_mask=1;
1924    else
1925          errordlg(['bad mask file ' Name ext ' found in ' Path2])
1926          return
1927          nbslice=1;
1928    end
1929end   
1930%------------------------------
1931
1932
1933function grid_civ1_Callback(hObject, eventdata, handles)
1934% hObject    handle to grid_civ1 (see GCBO)
1935% eventdata  reserved - to be defined in a future version of MATLAB
1936% handles    structure with handles and user data (see GUIDATA)
1937
1938% Hints: get(hObject,'String') returns contents of grid_civ1 as text
1939%        str2double(get(hObject,'String')) returns contents of grid_civ1 as a double
1940
1941
1942%-----------------------------------------------------------
1943% transform numbers to letters
1944%--------------------------------------------
1945function str=num2stra(num,nom_type);
1946if isequal(nom_type,'png_old') | isequal(nom_type,'netc_old') |isequal(nom_type,'raw_SMD')
1947    str=char(96+num);
1948elseif isequal(nom_type,'_i')|isequal(nom_type,'_i1-i2')...
1949        |isequal(nom_type,'ima_num')| isequal(nom_type,'avi')| isequal(nom_type,'none')
1950    str='';
1951else
1952    str=num2str(num);
1953end
1954%---------------------------------------------------
1955function mask_civ1_Callback(hObject, eventdata, handles)
1956set(handles.mask_civ1,'UserData',[])
1957set(handles.mask_civ1,'String','')
1958%----------------------------------------------------
1959function mask_civ2_Callback(hObject, eventdata, handles)
1960set(handles.mask_civ2,'UserData',[])
1961set(handles.mask_civ2,'String','')
1962%----------------------------------------------------
1963function mask_fix1_Callback(hObject, eventdata, handles)
1964set(handles.mask_fix1,'UserData',[])
1965set(handles.mask_fix1,'String','')
1966%----------------------------------------------------
1967function mask_fix2_Callback(hObject, eventdata, handles)
1968set(handles.mask_fix2,'UserData',[])
1969set(handles.mask_fix2,'String','')
1970
1971%--------------------------------------------------------------------------
1972% --- Executes on button press in list_subdir_civ1.
1973function list_subdir_civ1_Callback(hObject, eventdata, handles)
1974
1975filebase=get(handles.displ_filebase,'String');
1976dirinput = uigetdir(filebase)
1977    set(handles.subdir_civ1,'String',dirinput)
1978    set(handles.subdir_civ2,'String',dirinput)
1979
1980displ_filebase_Callback(hObject, eventdata, handles);
1981
1982
1983function rho_civ2_Callback(hObject, eventdata, handles)
1984% hObject    handle to rho_civ2 (see GCBO)
1985% eventdata  reserved - to be defined in a future version of MATLAB
1986% handles    structure with handles and user data (see GUIDATA)
1987
1988% Hints: get(hObject,'String') returns contents of rho_civ2 as text
1989%        str2double(get(hObject,'String')) returns contents of rho_civ2 as a double
1990
1991%----------------------------------------------
1992function last_i_Callback(hObject, eventdata, handles)
1993first_i=str2num(get(handles.first_i,'String'));
1994last_i=str2num(get(handles.last_i,'String'));
1995ref_i=ceil((first_i+last_i)/2);
1996set(handles.ref_i,'String', num2str(ref_i))
1997ref_i_Callback(hObject, eventdata, handles)
1998
1999%-------------------------------------------------------
2000function last_j_Callback(hObject, eventdata, handles)
2001first_j=str2num(get(handles.first_j,'String'));
2002last_j=str2num(get(handles.last_j,'String'));
2003ref_j=ceil((first_j+last_j)/2);
2004set(handles.ref_j,'String', num2str(ref_j))
2005ref_j_Callback(hObject, eventdata, handles)
2006
2007%--------------------------------------------------------------------------
2008% --- Executes on button press in browse_gridciv1.
2009function browse_gridciv1_Callback(hObject, eventdata, handles)
2010value=get(handles.browse_gridciv1,'Value');
2011if value
2012        filebase=get(handles.displ_filebase,'String');
2013        [FileName, PathName, filterindex] = uigetfile( ...
2014           {'*.grid', ' (*.grid)';
2015            '*.grid',  '.grid files '; ...
2016            '*.*', 'All Files (*.*)'}, ...
2017            'Pick a file',filebase);
2018        filegrid=fullfile(PathName,FileName);
2019    if isempty(FileName)|isempty(PathName)|isequal(FileName,0)|~exist(filegrid,'file')
2020        set(handles.browse_gridciv1,'Value',0);
2021        set(handles.grid_civ1,'string','');
2022            set(handles.dx_civ1,'Visible','on');
2023            set(handles.dy_civ1,'Visible','on');
2024            set(handles.grid_civ2,'string','');
2025        if get(handles.CIV2,'Value')
2026                set(handles.dx_civ2,'Visible','on');
2027                set(handles.dy_civ2,'Visible','on');
2028        end
2029    else
2030                set(handles.grid_civ1,'string',filegrid);
2031                set(handles.dx_civ1,'Visible','off');
2032                set(handles.dy_civ1,'Visible','off');
2033                set(handles.grid_civ2,'string',filegrid);
2034                set(handles.dx_civ2,'Visible','off');
2035                set(handles.dy_civ2,'Visible','off');
2036% set(handles.grid_patch1,'string',filegrid);
2037% set(handles.grid_patch2,'string',filegrid);
2038    end
2039else
2040    set(handles.grid_civ1,'string','');
2041        set(handles.dx_civ1,'Visible','on');
2042        set(handles.dy_civ1,'Visible','on');
2043        set(handles.grid_civ2,'string','');
2044    if get(handles.CIV2,'Value')
2045            set(handles.dx_civ2,'Visible','on');
2046            set(handles.dy_civ2,'Visible','on');
2047    end
2048end
2049
2050
2051
2052function pxcmx_Callback(hObject, eventdata, handles)
2053% hObject    handle to pxcmx (see GCBO)
2054% eventdata  reserved - to be defined in a future version of MATLAB
2055% handles    structure with handles and user data (see GUIDATA)
2056
2057% Hints: get(hObject,'String') returns contents of pxcmx as text
2058%        str2double(get(hObject,'String')) returns contents of pxcmx as a double
2059
2060
2061
2062function pxcmy_Callback(hObject, eventdata, handles)
2063% hObject    handle to pxcmy (see GCBO)
2064% eventdata  reserved - to be defined in a future version of MATLAB
2065% handles    structure with handles and user data (see GUIDATA)
2066
2067% Hints: get(hObject,'String') returns contents of pxcmy as text
2068%        str2double(get(hObject,'String')) returns contents of pxcmy as a double
2069
2070
2071% --- Executes on button press in browse_gridciv2.
2072function browse_gridciv2_Callback(hObject, eventdata, handles)
2073
2074filebase=get(handles.displ_filebase,'String');
2075[FileName, PathName, filterindex] = uigetfile( ...
2076       {'*.grid', ' (*.grid)';
2077        '*.grid',  '.grid files '; ...
2078        '*.*', 'All Files (*.*)'}, ...
2079        'Pick a file',filebase);
2080filegrid=fullfile(PathName,FileName);
2081set(handles.grid_civ2,'string',filegrid);
2082set(handles.dx_civ2,'String',' ');
2083set(handles.dy_civ2,'String',' ');
2084% set(handles.grid_patch2,'string',filegrid);
2085
2086% --- Executes on button press in get_gridpatch1.
2087function get_gridpatch1_Callback(hObject, eventdata, handles)
2088% hObject    handle to get_gridpatch1 (see GCBO)
2089% eventdata  reserved - to be defined in a future version of MATLAB
2090% handles    structure with handles and user data (see GUIDATA)
2091
2092filebase=get(handles.displ_filebase,'String');
2093[FileName, PathName, filterindex] = uigetfile( ...
2094       {'*.grid', ' (*.grid)';
2095        '*.grid',  '.grid files '; ...
2096        '*.*', 'All Files (*.*)'}, ...
2097        'Pick a file',filebase);
2098filegrid=fullfile(PathName,FileName);
2099set(handles.grid_patch1,'string',filegrid);
2100% set(handles.grid_patch2,'string',filegrid
2101
2102%-----------------------------------------------------------------
2103% --- Executes on button press in get_gridpatch2.
2104function get_gridpatch2_Callback(hObject, eventdata, handles)
2105% hObject    handle to get_gridpatch2 (see GCBO)
2106% eventdata  reserved - to be defined in a future version of MATLAB
2107% handles    structure with handles and user data (see GUIDATA)
2108
2109
2110%----------------------------------------------------------
2111function enable_civ1(handles,state)
2112if isequal(state,0)
2113    state='off';
2114end
2115if isequal(state,1)
2116    state='on';
2117end
2118if isequal(state,'on')
2119    set(handles.frame_civ1,'BackgroundColor',[1 1 0])
2120    set(handles.frame_para_civ1,'BackgroundColor',[1 1 0])
2121    set(handles.frame_grid_civ1,'BackgroundColor',[1 1 0])
2122else
2123    set(handles.frame_civ1,'BackgroundColor',[0.831 0.816 0.784])
2124    set(handles.frame_para_civ1,'BackgroundColor',[0.831 0.816 0.784])
2125    set(handles.frame_grid_civ1,'BackgroundColor',[0.831 0.816 0.784])
2126end
2127set(handles.ibx,'Visible',state)
2128set(handles.iby,'Visible',state)
2129set(handles.isx,'Visible',state)
2130set(handles.isy,'Visible',state)
2131set(handles.shiftx,'Visible',state)
2132set(handles.shifty,'Visible',state)
2133set(handles.rho,'Visible',state)
2134set(handles.dx_civ1,'Visible',state)
2135set(handles.dy_civ1,'Visible',state)
2136set(handles.calcul_search,'Visible',state)
2137set(handles.u_text,'Visible',state)
2138set(handles.v_text,'Visible',state)
2139set(handles.min,'Visible',state)
2140set(handles.max,'Visible',state)
2141set(handles.umin,'Visible',state)
2142set(handles.umax,'Visible',state)
2143set(handles.vmin,'Visible',state)
2144set(handles.vmax,'Visible',state)
2145set(handles.grid_civ1,'Visible',state)
2146set(handles.mask_civ1,'Visible',state)
2147set(handles.browse_gridciv1,'Visible',state)
2148set(handles.get_mask_civ1,'Visible',state)
2149set(handles.parameters,'Visible',state)
2150set(handles.grid,'Visible',state)
2151set(handles.dx_civ1,'Visible',state)
2152set(handles.dy_civ1,'Visible',state)
2153set(handles.ImaThreshold,'Visible',state)
2154if isequal(state,'off')
2155    set(handles.MinIma,'Visible','off')
2156    set(handles.MaxIma,'Visible','off')
2157    set(handles.ImaThreshold,'Value',0)
2158end
2159set(handles.dx_civ1_title,'Visible',state)
2160set(handles.dy_civ1_title,'Visible',state)
2161set(handles.ImaThreshold_title,'Visible',state)
2162set(handles.ib_title,'Visible',state)
2163set(handles.is_title,'Visible',state)
2164set(handles.shift_title,'Visible',state)
2165set(handles.rho_title,'Visible',state)
2166
2167%----------------------------------------------------------
2168function enable_fix1(handles)
2169set(handles.frame_fix1,'BackgroundColor',[1 1 0])
2170set(handles.REMOVE,'Visible','on')
2171set(handles.vec_Fmin2,'Visible','on')
2172set(handles.vec_F2,'Visible','on')
2173set(handles.vec_F3,'Visible','on')
2174set(handles.thresh_vecC,'Visible','on')
2175set(handles.thresh_vecC_title,'Visible','on')
2176set(handles.thresh_vel,'Visible','on')
2177set(handles.thresh_vel_text,'Visible','on')
2178set(handles.mask_fix1,'Visible','on')
2179set(handles.get_mask_fix1,'Visible','on')
2180set(handles.get_ref_fix1,'Visible','on')
2181set(handles.ref_fix1,'Visible','on')
2182set(handles.inf_sup1,'Visible','on')
2183set(handles.field_ref1,'Visible','on')
2184
2185%----------------------------------------------------------
2186function desable_fix1(handles)
2187set(handles.frame_fix1,'BackgroundColor',[0.831 0.816 0.784])
2188set(handles.REMOVE,'Visible','off')
2189set(handles.vec_Fmin2,'Visible','off')
2190set(handles.vec_F2,'Visible','off')
2191set(handles.vec_F3,'Visible','off')
2192set(handles.thresh_vecC,'Visible','off')
2193set(handles.thresh_vecC_title,'Visible','off')
2194set(handles.thresh_vel,'Visible','off')
2195set(handles.thresh_vel_text,'Visible','off')
2196set(handles.mask_fix1,'Visible','off')
2197set(handles.get_mask_fix1,'Visible','off')
2198set(handles.get_ref_fix1,'Visible','off')
2199set(handles.ref_fix1,'Visible','off')
2200set(handles.inf_sup1,'Visible','off')
2201set(handles.field_ref1,'Visible','off')
2202
2203%--------------------------------------------------------------
2204function enable_patch1(handles)
2205global patch_new_exe
2206set(handles.frame_patch1,'BackgroundColor',[1 1 0])
2207set(handles.rho_patch1,'Visible','on')
2208set(handles.rho_text1,'Visible','on')
2209set(handles.thresh_patch1,'Visible','on')
2210set(handles.thresh_text1,'Visible','on')
2211set(handles.subdomain_patch1,'Visible','on')
2212set(handles.subdomain_text1,'Visible','on')
2213set(handles.nx_patch1,'Visible','on')
2214set(handles.ny_patch1,'Visible','on')
2215set(handles.nx_patch1_title,'Visible','on')
2216set(handles.ny_patch1_title,'Visible','on')
2217if (~isequal(patch_new_exe,[]) & ~isequal(patch_new_exe,[]))
2218    set(handles.test_interp,'Visible','on');
2219end
2220set(handles.get_gridpatch1,'Visible','on')
2221set(handles.grid_patch1,'string','none');
2222set(handles.grid_patch1,'Visible','on')
2223
2224%--------------------------------------------------------------
2225function desable_patch1(handles)
2226set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
2227set(handles.rho_patch1,'Visible','off')
2228set(handles.rho_text1,'Visible','off')
2229set(handles.thresh_patch1,'Visible','off')
2230set(handles.thresh_text1,'Visible','off')
2231set(handles.subdomain_patch1,'Visible','off')
2232set(handles.subdomain_text1,'Visible','off')
2233set(handles.nx_patch1,'Visible','off')
2234set(handles.ny_patch1,'Visible','off')
2235set(handles.nx_patch1_title,'Visible','off')
2236set(handles.ny_patch1_title,'Visible','off')
2237set(handles.test_interp,'Visible','off')
2238set(handles.get_gridpatch1,'Visible','off')
2239set(handles.grid_patch1,'Visible','off')
2240
2241%----------------------------------------------------------
2242function enable_civ2(handles,state)
2243if isequal(state,0)
2244    state='off';
2245end
2246if isequal(state,1)
2247    state='on';
2248end
2249if isequal(state,'on')
2250    set(handles.frame_civ2,'BackgroundColor',[1 1 0])
2251    set(handles.frame_para_civ2,'BackgroundColor',[1 1 0])
2252    set(handles.frame_grid_civ2,'BackgroundColor',[1 1 0])
2253    set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
2254else
2255    set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
2256    set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
2257    set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
2258    set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
2259end
2260set(handles.ibx_civ2,'Visible',state)
2261set(handles.iby_civ2,'Visible',state)
2262set(handles.decimal,'Visible',state)
2263set(handles.deformation,'Visible',state)
2264set(handles.rho_civ2,'Visible',state)
2265set(handles.dx_civ2,'Visible',state)
2266set(handles.dy_civ2,'Visible',state)
2267set(handles.browse_gridciv2,'Visible',state)
2268set(handles.get_mask_civ2,'Visible',state)
2269set(handles.parameters,'Visible',state)
2270set(handles.grid,'Visible',state)
2271set(handles.parameters_text,'Visible',state)
2272set(handles.grid_text,'Visible',state)
2273set(handles.grid_civ2,'Visible',state)
2274set(handles.mask_civ2,'Visible',state)
2275set(handles.dx_civ2_title,'Visible',state)
2276set(handles.dy_civ2_title,'Visible',state)
2277set(handles.ibx_civ2_text,'Visible',state)
2278set(handles.rho_civ2_title,'Visible',state)
2279set(handles.ImaThreshold2,'Visible',state)
2280set(handles.ImaThreshold_title2,'Visible',state)
2281if isequal(state,'off')
2282    set(handles.MinIma2,'Visible','off')
2283    set(handles.MaxIma2,'Visible','off')
2284    set(handles.ImaThreshold2,'Value',0)
2285    if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
2286        set(handles.list_pair_civ2,'Visible','off')
2287        set(handles.subdir_civ2,'Visible','off')
2288        set(handles.subdir_civ2_text,'Visible','off')
2289    end
2290else
2291    set(handles.list_pair_civ2,'Visible','on')
2292    set(handles.subdir_civ2,'Visible','on')
2293    set(handles.subdir_civ2_text,'Visible','on')
2294end
2295
2296%----------------------------------------------------------
2297% function desable_civ2(handles)
2298% set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
2299% set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
2300% set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
2301% set(handles.ibx_civ2,'Visible','off')
2302% set(handles.iby_civ2,'Visible','off')
2303% set(handles.decimal,'Visible','off')
2304% set(handles.deformation,'Visible','off')
2305% set(handles.rho_civ2,'Visible','off')
2306% set(handles.dx_civ2,'Visible','off')
2307% set(handles.dy_civ2,'Visible','off')
2308% set(handles.browse_gridciv2,'Visible','off')
2309% set(handles.get_mask_civ2,'Visible','off')
2310% set(handles.parameters,'Visible','off')
2311% set(handles.grid,'Visible','off')
2312% set(handles.grid,'Visible','on')
2313% set(handles.parameters_text,'Visible','off')
2314% set(handles.grid_text,'Visible','off')
2315% set(handles.grid_civ2,'Visible','off')
2316% set(handles.mask_civ2,'Visible','off')
2317% set(handles.dx_civ2_title,'Visible','off')
2318% set(handles.dy_civ2_title,'Visible','off')
2319% set(handles.ibx_civ2_text,'Visible','off')
2320% set(handles.rho_civ2_title,'Visible','off')
2321% set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
2322% if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
2323%     set(handles.list_pair_civ2,'Visible','off')
2324%     set(handles.subdir_civ2,'Visible','off')
2325%     set(handles.subdir_civ2_text,'Visible','off')
2326% end
2327
2328%----------------------------------------------------------
2329function enable_fix2(handles)
2330set(handles.frame_fix2,'BackgroundColor',[1 1 0])
2331set(handles.REMOVE2,'Visible','on')
2332set(handles.vec_Fmin2_2,'Visible','on')
2333set(handles.vec_F4,'Visible','on')
2334set(handles.vec_F3_2,'Visible','on')
2335set(handles.thresh_vec2C,'Visible','on')
2336set(handles.thresh_vec2C_text,'Visible','on')
2337set(handles.thresh_vel2,'Visible','on')
2338set(handles.thresh_vel2_text,'Visible','on')
2339set(handles.mask_fix2,'Visible','on')
2340set(handles.get_mask_fix2,'Visible','on')
2341set(handles.list_pair_civ2,'Visible','on')
2342set(handles.subdir_civ2,'Visible','on')
2343set(handles.subdir_civ2_text,'Visible','on')
2344set(handles.get_ref_fix2,'Visible','on')
2345set(handles.ref_fix2,'Visible','on')
2346set(handles.inf_sup2,'Visible','on')
2347set(handles.field_ref2,'Visible','on')
2348
2349%----------------------------------------------------------
2350function desable_fix2(handles)
2351set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
2352set(handles.REMOVE2,'Visible','off')
2353set(handles.vec_Fmin2_2,'Visible','off')
2354set(handles.vec_F4,'Visible','off')
2355set(handles.vec_F3_2,'Visible','off')
2356set(handles.thresh_vec2C,'Visible','off')
2357set(handles.thresh_vec2C_text,'Visible','off')
2358set(handles.thresh_vel2,'Visible','off')
2359set(handles.thresh_vel2_text,'Visible','off')
2360set(handles.mask_fix2,'Visible','off')
2361set(handles.get_mask_fix2,'Visible','off')
2362set(handles.get_ref_fix2,'Visible','off')
2363set(handles.ref_fix2,'Visible','off')
2364set(handles.inf_sup2,'Visible','off')
2365set(handles.field_ref2,'Visible','off')
2366if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
2367    set(handles.list_pair_civ2,'Visible','off')
2368    set(handles.subdir_civ2,'Visible','off')
2369    set(handles.subdir_civ2_text,'Visible','off')
2370end
2371
2372%--------------------------------------------------------------
2373function enable_patch2(handles)
2374set(handles.frame_patch2,'BackgroundColor',[1 1 0])
2375set(handles.rho_patch2,'Visible','on')
2376set(handles.rho_text2,'Visible','on')
2377set(handles.thresh_patch2,'Visible','on')
2378set(handles.thresh_text2,'Visible','on')
2379set(handles.subdomain_patch2,'Visible','on')
2380set(handles.subdomain_text2,'Visible','on')
2381set(handles.nx_patch2,'Visible','on')
2382set(handles.ny_patch2,'Visible','on')
2383set(handles.nx_patch2_title,'Visible','on')
2384set(handles.ny_patch2_title,'Visible','on')
2385set(handles.get_gridpatch2,'Visible','on')
2386set(handles.grid_patch2,'Visible','on')
2387set(handles.list_pair_civ2,'Visible','on')
2388set(handles.subdir_civ2,'Visible','on')
2389set(handles.subdir_civ2_text,'Visible','on')
2390
2391%--------------------------------------------------------------
2392function desable_patch2(handles)
2393set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
2394set(handles.rho_patch2,'Visible','off')
2395set(handles.rho_text2,'Visible','off')
2396set(handles.thresh_patch2,'Visible','off')
2397set(handles.thresh_text2,'Visible','off')
2398set(handles.subdomain_patch2,'Visible','off')
2399set(handles.subdomain_text2,'Visible','off')
2400set(handles.nx_patch2,'Visible','off')
2401set(handles.ny_patch2,'Visible','off')
2402set(handles.nx_patch2_title,'Visible','off')
2403set(handles.ny_patch2_title,'Visible','off')
2404set(handles.get_gridpatch2,'Visible','off')
2405set(handles.grid_patch2,'Visible','off')
2406if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0)
2407    set(handles.list_pair_civ2,'Visible','off')
2408    set(handles.subdir_civ2,'Visible','off')
2409    set(handles.subdir_civ2_text,'Visible','off')
2410end
2411
2412% --- Executes on button press in test_interp.
2413function test_interp_Callback(hObject, eventdata, handles)
2414
2415
2416%------------------------------------------------
2417%Read the parameters for civ1 on the interface
2418%--------------------------------------------------
2419function par=read_param_civ1(handles,file_ima)
2420
2421ibx_val=str2num(get(handles.ibx,'String'));
2422par.correlationBoxesSize_X=num2str(ibx_val);
2423iby_val=str2num(get(handles.iby,'String'));
2424par.correlationBoxesSize_Y=num2str(iby_val);
2425ibz_val=str2num(get(handles.ibz,'String'));
2426par.correlationBoxesSize_Z=num2str(ibz_val);
2427isx=get(handles.isx,'String');
2428if isempty(str2num(isx)), isx='41'; set(handles.isx,'String','41'), end; %default
2429maxDisplacement_X=floor((str2num(isx)-ibx_val)/2);
2430par.maxDisplacement_X=num2str(maxDisplacement_X);
2431isy=get(handles.isy,'String');
2432if isempty(str2num(isy)), isy='41'; set(handles.isy,'String','41'), end; %default
2433maxDisplacement_Y=floor((str2num(isy)-iby_val)/2);
2434par.maxDisplacement_Y=num2str(maxDisplacement_Y);
2435isz=get(handles.isz,'String');
2436if isempty(str2num(isz)), isz='41'; set(handles.isz,'String','41'), end; %default
2437maxDisplacement_Z=floor((str2num(isz)-ibz_val)/2);
2438par.maxDisplacement_Z=num2str(maxDisplacement_Z);
2439%      par.rho=get(handles.rho,'String');
2440par.gridSpacing_X=get(handles.dx_civ1,'String');
2441par.gridSpacing_Y=get(handles.dy_civ1,'String');
2442par.gridSpacing_Z=get(handles.dz_civ1,'String');
2443% Zmin=str2num(get(handles.first_j,'String'))-1;
2444Zmax=str2num(get(handles.npz,'String'));
2445par.gridLimits_Xmin=0;
2446par.gridLimits_Ymin=0;
2447par.gridLimits_Zmin=0;
2448% A=imread(file_ima);%read the first image to get the size
2449%sizim=size(A);
2450par.gridLimits_Xmax=str2double(get(handles.npx,'String'));%num2str(sizim(2));
2451par.gridLimits_Ymax=str2double(get(handles.npy,'String'));%num2str(sizim(1));
2452par.gridLimits_Zmax=Zmax;
2453par.grid='grille';
2454par.grid_division=4;
2455par.hart=0;
2456par.ratioHoverZ=1;
2457
2458%     
2459% %----------------------------------------------------------------
2460% function par=read_param_civ2(handles,file_ima)
2461%     par.ibx=get(handles.ibx_civ2,'String');
2462%     par.iby=get(handles.iby_civ2,'String');
2463%     par.rho=get(handles.rho_civ2,'String');
2464%     par.decimal=int2str(get(handles.decimal,'Value'));
2465%     par.deformation=int2str(get(handles.deformation,'Value'));
2466%     par.dx=get(handles.dx_civ2,'String');
2467%     par.dy=get(handles.dy_civ2,'String');
2468%     if isequal(str2num(par.dx),[])
2469%          if isempty(get(handles.grid_civ2,'String'));
2470%              par.dx='0'; %just read by civ_3D program, not used
2471%          else
2472%             par.dx='20';%default
2473%             set(handles.dx_civ2,'String','20');
2474%          end
2475%      end
2476%      if isequal(str2num(par.dy),[])
2477%          if isempty(get(handles.grid_civ2,'String'));
2478%              par.dy='0';%just read by civ_3D program, not used
2479%          else
2480%             par.dy='20';%default
2481%             set(handles.dy_civ2,'String','20');
2482%          end
2483%      end
2484%     par.pxcmx=get(handles.pxcmx,'String');
2485%     par.pxcmy=get(handles.pxcmy,'String');
2486%     if isempty(str2num(par.pxcmx)) |isempty(str2num(par.pxcmy))
2487%         par.pxcmx='1';
2488%          par.pxcmy='1';
2489%     end
2490% %     par.npx=get(handles.pxcmx,'UserData');
2491% %     par.npy=get(handles.pxcmy,'UserData');
2492%     A=imread(file_ima);%read the first image to get the size
2493%     sizim=size(A);
2494%     par.npx=num2str(sizim(2));
2495%     par.npy=num2str(sizim(1));
2496%     time=get(handles.displ_filebase,'UserData'); %get the set of times
2497%     par.gridname=get(handles.grid_civ2,'String');
2498%     par.gridflag='y';
2499%     if isequal(par.gridname,'')| isempty(par.gridname)
2500%         par.gridname='nogrid';
2501%         par.gridflag='n';
2502%     end
2503
2504
2505%---------------------------------------------------------
2506%CIV1  CIV1  CIV1 CIV1
2507%----------------------------------------------------------
2508function cmd_CIV1=BATCH_CIV1(filename,namelog,par,handles)
2509%pixels per cm and matrix of the image times, read from the .civ_3D file by uvmat
2510global civ1_exe Civ_exe sge%name of the executable for civ1 calculation
2511
2512%changes : filename_cmx -> filename ( no extension )
2513
2514            if isequal(par.Dt,'0')
2515                par.Dt='1' ;%case of 'displacement' mode
2516            end         
2517 
2518    textcmx={'##############   CMX file';...
2519    ['FirstImage ' par.filename_ima_a];...
2520    ['LastImage  ' par.filename_ima_b];...
2521    'XX' ;...
2522    ['Mask ' par.maskflag] ;...
2523    ['MaskName ' par.maskname];...
2524    ['ImageSize ' par.npx ' ' par.npy];...   %VERIFIER CAS GENERAL ?
2525    ['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
2526    ['SearchBoxeSize ' par.isx ' ' par.isy];...
2527    ['RO ' par.rho];...
2528    ['GridSpacing ' par.dx ' ' par.dy];...
2529    'XX 1.0';...
2530    ['Dt_TO ' par.Dt ' ' par.T0];...
2531    ['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
2532    'XX 1';...
2533    ['ShiftXY ' par.shiftx ' '  par.shifty];...
2534    ['Grid ' par.gridflag];...
2535    ['GridName ' par.gridname] ;...
2536    'XX 85';...
2537    'XX 1.0';...
2538    'XX 1.0';...
2539    'Hart 1';...
2540    'DecimalShift 0';...
2541    'Deformation 0';...
2542    'CorrelationMin 0';...
2543    'IntensityMin 0';...
2544    'SeuilImage n';...
2545    'SeuilImageValues 0 4096';...
2546    ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
2547    'ImageUsedBefore null null'};
2548
2549            textout=char(textcmx);
2550    %         timeL1=clock;
2551            dlmwrite([filename '.cmx'],textout,'');
2552    %             timeL2=clock;
2553    %     timciv1=etime(timeL2,timeL1)
2554          if sge 
2555          cmd_CIV1=[civ1_exe ' -f ' filename '.cmx' ]; % redirect standard output to the log file
2556          else
2557              cmd_CIV1=[civ1_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
2558          end
2559    if(isunix)
2560        [Rootbat,Filebat,extbat]=fileparts(namelog);
2561        ncName=fullfile(Rootbat,[ Filebat '.nc']);
2562            cmd_CIV1=char({cmd_CIV1 ; ['mv ' namelog  ' ' namelog '.civ1.log'];['chmod g+w ' ncName]});
2563    else
2564        cmd_CIV1=char({cmd_CIV1 ; ['copy /Y ' namelog ' ' namelog '.civ1.log']});
2565    end
2566
2567%---------------------------------------------------------
2568%CIV1  Unified
2569%----------------------------------------------------------
2570function xml_civ1_parameters=BATCH_CIV1_Unified(filename,namelog,par,handles)
2571%pixels per cm and matrix of the image times, read from the .civ_3D file by uvmat
2572global civ1_exe Civ_exe%name of the executable for civ1 calculation
2573
2574    civ1.image1=par.filename_ima_a;
2575    civ1.image2=par.filename_ima_b;
2576    civ1.imageSize_X=par.npx;
2577    civ1.imageSize_Y=par.npy;
2578    civ1.outputFileName=[filename '.nc'];
2579    civ1.correlationBoxesSize_X=par.ibx;
2580    civ1.correlationBoxesSize_Y=par.iby;
2581    civ1.searchBoxesSize_X=par.isx;
2582    civ1.searchBoxesSize_Y=par.isy;
2583    civ1.globalShift_X=par.shiftx;
2584    civ1.globalShift_Y=par.shifty;
2585    civ1.ro=par.rho;
2586    civ1.hart='y';
2587    if isequal(par.gridflag,'y')
2588        civ1.grid=par.gridname;
2589    end
2590    civ1.gridSpacing_X=par.dx;
2591    civ1.gridSpacing_Y=par.dy;
2592    if isequal(par.maskflag,'y')
2593        civ1.mask=par.maskname;
2594    end
2595    civ1.dt=par.Dt;
2596    civ1.unit='pixel';
2597    civ1.absolut_time_T0=par.T0;
2598    civ1.pixcmx=par.pxcmx;
2599    civ1.pixcmy=par.pxcmy;
2600    civ1.convectFlow='n';
2601 
2602    xml_civ1_parameters=civ1;
2603   
2604%---------------------------------------------------------
2605%CIV2  CIV2  CIV2 CIV2
2606%----------------------------------------------------------
2607function cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par)
2608%pixels per cm and matrix of the image times, read from the .civ_3D file by uvmat
2609global civ2_exe sge%name of the executable for civ1 calculation
2610   if isequal(par.Dt,'0')
2611                par.Dt='1' ;%case of 'displacement' mode
2612  end
2613textcmx={'##############   CMX file';...
2614['FirstImage ' par.filename_ima_a];...
2615['LastImage  ' par.filename_ima_b];...
2616'XX' ;...
2617['Mask ' par.maskflag];...
2618['MaskName ' par.maskname];...
2619['ImageSize ' par.npx ' ' par.npy];...   
2620['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
2621['SearchBoxeSize ' par.ibx ' ' par.iby];...
2622['RO ' par.rho];...
2623['GridSpacing ' par.dx ' ' par.dy];...
2624'XX 1.0';...
2625['Dt_TO ' par.Dt ' ' par.T0];...
2626['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
2627'XX 1';...
2628['ShiftXY 0 0'];...
2629['Grid ' par.gridflag];...
2630['GridName ' par.gridname];...
2631'XX 85';...
2632'XX 1.0';...
2633'XX 1.0';...
2634'Hart 1';...
2635['DecimalShift ' par.decimal];...
2636['Deformation ' par.deformation];...
2637'CorrelationMin 0';...
2638'IntensityMin 0';...
2639'SeuilImage n';...
2640'SeuilImageValues 0 4096';...
2641['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
2642['ImageUsedBefore ' par.filename_nc1]};
2643        textout=char(textcmx);
2644        dlmwrite([filename_cmx '2'] ,textout,'');
2645        if sge
2646        cmd_CIV2=[civ2_exe ' -f ' filename_cmx ]; % redirect standard output to the log file
2647        else
2648          cmd_CIV2=[civ2_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
2649      end
2650
2651
2652% --- Executes on button press in HELP.
2653function HELP_Callback(hObject, eventdata, handles)
2654path_to_uvmat=which ('uvmat');% check the path of uvmat
2655pathelp=fileparts(path_to_uvmat);
2656helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
2657if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
2658else
2659web([helpfile '#civ_3D'])   
2660end
2661
2662
2663%----------------------------------------------------------
2664%--read images and convert them to the uint16 format used for PIV
2665function A=read_image(filename,nom_type,npx,npy,num);
2666%npx, npy are the dimensions needed for the raw SMD images
2667%num is the view number needed for an avi movie
2668if isequal(nom_type,'avi')
2669    mov=aviread(filename,num);
2670    A=frame2im(mov(1));
2671    A=sum(double(A),3);
2672    A=uint16(A);
2673elseif isequal(nom_type,'raw_SMD')
2674    [fid,message]=fopen(filename,'r');   
2675    B=fread(fid,Inf,'int16',0,'ieee-le');%read 16 bit binary file
2676    A=(reshape(B,npx,npy))'; %remplissage ligne par ligne avec une matrice colonne ? transposer(uB) pour avoir une matrice ligne
2677    A=uint16(A);
2678    fclose(fid);
2679else
2680    A=imread(filename);
2681    siz=size(A);
2682    if length(siz)==3;%color images
2683        A=sum(double(A),3);
2684    end
2685    A=uint16(A);
2686end
2687       
2688%----------------------------------------------------------------
2689%Executes on carriage return on the time interval dt
2690%----------------------------------------------------------------
2691function dt_Callback(hObject, eventdata, handles)
2692%determine the set of times and possible intervals for CIV_3D
2693%                 answer=inputdlg('time interval between images?');
2694                dt=(1/1000)*str2num(get(handles.dt,'String'));
2695                nbfield=str2num(get(handles.nb_field,'String')); %last image number selected in the processing series
2696                time=(dt*[0:nbfield-1])';
2697%                 set(handles.incr_i,'UserData',dt);%store the time interval between successive images
2698                set(handles.displ_filebase,'UserData',time); %store the set of times
2699                for index=1:min(nbfield-1,200)
2700                    displ_num(1,index)=1;
2701                    displ_num(2,index)=1;
2702                    displ_num(3,index)=-floor(index/2);
2703                    displ_num(4,index)=ceil(index/2);
2704                end
2705set(handles.list_pair_civ1,'Value',1);
2706set(handles.list_pair_civ1,'UserData',displ_num);
2707set(handles.list_pair_civ2,'Value',1);
2708%update the list of time intervals
2709find_netcpair_civ1(hObject, eventdata, handles)
2710find_netcpair_civ2(hObject, eventdata, handles)
2711
2712%-------------------------------------------------------
2713function ref_i_Callback(hObject, eventdata, handles)
2714mode_list=get(handles.mode,'String');
2715mode_value=get(handles.mode,'Value');
2716mode=mode_list{mode_value};
2717if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Di)')
2718    find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
2719end
2720if isequal(mode,'series(Di)') | ...% we do patch2 only
2721   (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
2722    find_netcpair_civ2(hObject, eventdata, handles);
2723end
2724
2725%----------------------------------------------------
2726function ref_j_Callback(hObject, eventdata, handles)
2727mode_list=get(handles.mode,'String');
2728mode_value=get(handles.mode,'Value');
2729mode=mode_list{mode_value};
2730if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Dj)')
2731    find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
2732end
2733if isequal(mode,'series(Dj)') | ...
2734   (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
2735    find_netcpair_civ2(hObject, eventdata, handles);
2736end
2737%----------------------------------------------------
2738% --- Executes on button press in compare.
2739function compare_Callback(hObject, eventdata, handles)
2740test=get(handles.compare,'Value');
2741if test
2742    filebase=get(handles.displ_filebase,'String');
2743    browse=get(handles.browse_root,'Userdata');
2744    browse.nom_type_ima1=browse.nom_type_ima;
2745    set(handles.browse_root,'UserData',browse);
2746    set(handles.displ_filebase2,'Visible','On');%mkes the second file input window visible
2747    set(handles.displ_filebase2,'String',filebase);
2748    mode_store=get(handles.mode,'String');%get the present 'mode'
2749    set(handles.compare,'UserData',mode_store);%store the mode display
2750    set(handles.mode,'Value',1)
2751    set(handles.mode,'String',{'displacement';'st_pair j1-j2'})
2752else
2753    set(handles.displ_filebase2,'Visible','Off');
2754    set(handles.displ_filebase2,'String',[]);
2755    mode_store=get(handles.compare,'UserData');
2756    set(handles.mode,'String',mode_store)
2757    set(handles.test_stereo1,'Value',0)
2758    set(handles.test_stereo2,'Value',0)
2759end
2760mode_Callback(hObject, eventdata, handles)
2761
2762%-----------------------------------------------------------
2763% --- Executes on button press in get_ref_fix1.
2764function get_ref_fix1_Callback(hObject, eventdata, handles)
2765filebase=get(handles.displ_filebase,'String');
2766[FileName, PathName, filterindex] = uigetfile( ...
2767       {'*.nc', ' (*.nc)';
2768        '*.nc',  'netcdf files '; ...
2769        '*.*', 'All Files (*.*)'}, ...
2770        'Pick a file',filebase);
2771   
2772fileinput=[PathName FileName];
2773sizf=size(fileinput);
2774if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
2775%[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
2776[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
2777%filebase=fullfile(RootPath,RootFile);
2778% [Pth,FileN]=fileparts(filebasesub);
2779% Pth=fileparts(Pth);
2780ref.filebase=fullfile(Path,File);
2781ref.num_a=stra2num(str_a);
2782ref.num_b=stra2num(str_b);
2783ref.num1=str2num(field_count);
2784ref.num2=str2num(str2);
2785browse=[];%initialisation
2786if ~isequal(ref.ext,'.nc')
2787    errordlg('the reference file must be in netcdf format (*.nc)')
2788    return
2789end
2790% [path,name]=fileparts(ref.filebase);
2791set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
2792set(handles.ref_fix1,'UserData',ref)
2793menu_field{1}='civ1';
2794Data=nc2struct(fileinput,[]);
2795if isfield(Data,'patch') & isequal(Data.patch,1)
2796    menu_field{2}='filter1';
2797end
2798if isfield(Data,'civ2') & isequal(Data.civ2,1)
2799    menu_field{3}='civ2';
2800end
2801if isfield(Data,'patch2') & isequal(Data.patch2,1)
2802    menu_field{4}='filter2';
2803end
2804% [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
2805% if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
2806%          menu_field{2}='filter1';
2807% end
2808% if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
2809%          menu_field{3}='civ2';
2810% end
2811% if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
2812%          menu_field{4}='filter2';
2813% end
2814set(handles.field_ref1,'String',menu_field);
2815set(handles.field_ref1,'Value',length(menu_field));
2816set(handles.inf_sup1,'Value',2);
2817set(handles.thresh_vel,'String','1');%default threshold
2818set(handles.ref_fix1,'Enable','on')
2819 
2820%---------------------------------------------------------------
2821% --- Executes on button press in get_ref_fix2.
2822function get_ref_fix2_Callback(hObject, eventdata, handles)
2823if isequal(get(handles.get_ref_fix2,'Value'),1)
2824    filebase=get(handles.displ_filebase,'String');
2825    [FileName, PathName, filterindex] = uigetfile( ...
2826           {'*.nc', ' (*.nc)';
2827            '*.nc',  'netcdf files '; ...
2828            '*.*', 'All Files (*.*)'}, ...
2829            'Pick a file',filebase);
2830    fileinput=[PathName FileName];
2831    sizf=size(fileinput);
2832    if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
2833    %[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
2834    [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
2835%     [Pth,FileN]=fileparts(filebasesub);
2836%     Pth=fileparts(Pth);
2837    ref.filebase=fullfile(Path,File)
2838    ref.num_a=stra2num(str_a);
2839    ref.num_b=stra2num(str_b);
2840    ref.num1=str2num(field_count);
2841    ref.num2=str2num(str2);
2842    browse=[];%initialisation
2843    if ~isequal(ref.ext,'.nc')
2844        errordlg('the reference file must be in netcdf format (*.nc)')
2845        return
2846    end
2847%     [path,name]=fileparts(ref.filebase);
2848    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
2849    set(handles.ref_fix2,'UserData',ref)   
2850    menu_field{1}='civ1';
2851%     [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
2852    Data=nc2struct(fileinput,[]);
2853    if isfield(Data,'patch') & isequal(Data.patch,1)
2854        menu_field{2}='filter1';
2855    end
2856    if isfield(Data,'civ2') & isequal(Data.civ2,1)
2857        menu_field{3}='civ2';
2858    end
2859    if isfield(Data,'patch2') & isequal(Data.patch2,1)
2860        menu_field{4}='filter2';
2861    end
2862
2863%     if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
2864%              menu_field{2}='filter1';
2865%     end
2866%     if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
2867%              menu_field{3}='civ2';
2868%     end
2869%     if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
2870%              menu_field{4}='filter2';
2871%     end
2872    set(handles.field_ref2,'String',menu_field);
2873    set(handles.field_ref2,'Value',length(menu_field));
2874    set(handles.inf_sup2,'Value',2);
2875    set(handles.thresh_vel2,'String','1');%default threshold
2876    set(handles.ref_fix2,'Enable','on')
2877    set(handles.ref_fix2,'Visible','on')
2878    set(handles.field_ref2,'Visible','on')
2879else
2880    set(handles.ref_fix2,'Visible','off')
2881    set(handles.field_ref2,'Visible','off')
2882end
2883%-------------------------------------------------------
2884
2885function ref_fix1_Callback(hObject, eventdata, handles)
2886    set(handles.inf_sup1,'Value',1);
2887    set(handles.field_ref1,'Value',1)
2888    set(handles.field_ref1,'String',{' '})
2889    set(handles.ref_fix1,'UserData',[]);
2890    set(handles.ref_fix1,'String','');
2891    set(handles.thresh_vel1,'String','0');
2892 
2893
2894%------------------------------------------------------
2895
2896function ref_fix2_Callback(hObject, eventdata, handles)
2897    set(handles.inf_sup2,'Value',1);
2898    set(handles.field_ref2,'Value',1)
2899    set(handles.field_ref2,'String',{' '})
2900    set(handles.ref_fix2,'UserData',[]);
2901    set(handles.ref_fix2,'String','');
2902    set(handles.thresh_vel2,'String','0');
2903
2904%--------------------------------------------------------
2905% --- Executes on selection change in inf_sup1.
2906function inf_sup1_Callback(hObject, eventdata, handles)
2907
2908%--------------------------------------------------------------------------
2909
2910
2911% --- Executes on selection change in field_ref.
2912function field_ref_Callback(hObject, eventdata, handles)
2913
2914%-------------------------------------------------------------------------
2915
2916% --- Executes on selection change in field_ref2.
2917function field_ref2_Callback(hObject, eventdata, handles)
2918
2919% -----------------------------------------------------------
2920% transform letters to numbers
2921%--------------------------------------------
2922function numres=stra2num(str)
2923numres=double(str)-96;
2924if double(str) >= 48 & double(str) <= 57 % = 1 for numbers
2925    numres=str2num(str);
2926end
2927
2928
2929% --- Executes on button press in test_stereo1.
2930function test_stereo1_Callback(hObject, eventdata, handles)
2931if isequal(get(handles.test_stereo1,'Value'),0)
2932    set(handles.subdomain_patch1,'Visible','on')
2933    set(handles.rho_patch1,'Visible','on')
2934else
2935    set(handles.subdomain_patch1,'Visible','off')
2936    set(handles.rho_patch1,'Visible','off')
2937end
2938
2939% --- Executes on button press in test_stereo2.
2940function test_stereo2_Callback(hObject, eventdata, handles)
2941if isequal(get(handles.test_stereo2,'Value'),0)
2942    set(handles.subdomain_patch2,'Visible','on')
2943    set(handles.rho_patch2,'Visible','on')
2944else
2945    set(handles.subdomain_patch2,'Visible','off')
2946    set(handles.rho_patch2,'Visible','off')
2947end
2948
2949% --- Executes on button press in ImaThreshold.
2950function ImaThreshold_Callback(hObject, eventdata, handles)
2951if isequal(get(handles.ImaThreshold,'Value'),1)
2952    set(handles.MinIma,'Visible','on')
2953    set(handles.MaxIma,'Visible','on')
2954else
2955    set(handles.MinIma,'Visible','off')
2956    set(handles.MaxIma,'Visible','off')
2957end
2958
2959
2960% --- Executes on button press in ImaThreshold2.
2961function ImaThreshold2_Callback(hObject, eventdata, handles)
2962if isequal(get(handles.ImaThreshold2,'Value'),1)
2963    set(handles.MinIma2,'Visible','on')
2964    set(handles.MaxIma2,'Visible','on')
2965else
2966    set(handles.MinIma2,'Visible','off')
2967    set(handles.MaxIma2,'Visible','off')
2968end
2969
2970
2971
2972% --- Executes on button press in Experimental.
2973function Experimental_Callback(hObject, eventdata, handles)
2974
2975
2976
2977function ibz_Callback(hObject, eventdata, handles)
2978% hObject    handle to ibz (see GCBO)
2979% eventdata  reserved - to be defined in a future version of MATLAB
2980% handles    structure with handles and user data (see GUIDATA)
2981
2982% Hints: get(hObject,'String') returns contents of ibz as text
2983%        str2double(get(hObject,'String')) returns contents of ibz as a double
2984
2985
2986% --- Executes during object creation, after setting all properties.
2987function ibz_CreateFcn(hObject, eventdata, handles)
2988% hObject    handle to ibz (see GCBO)
2989% eventdata  reserved - to be defined in a future version of MATLAB
2990% handles    empty - handles not created until after all CreateFcns called
2991
2992% Hint: edit controls usually have a white background on Windows.
2993%       See ISPC and COMPUTER.
2994if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2995    set(hObject,'BackgroundColor','white');
2996end
2997
2998
2999
3000function edit74_Callback(hObject, eventdata, handles)
3001% hObject    handle to edit74 (see GCBO)
3002% eventdata  reserved - to be defined in a future version of MATLAB
3003% handles    structure with handles and user data (see GUIDATA)
3004
3005% Hints: get(hObject,'String') returns contents of edit74 as text
3006%        str2double(get(hObject,'String')) returns contents of edit74 as a double
3007
3008
3009% --- Executes during object creation, after setting all properties.
3010function edit74_CreateFcn(hObject, eventdata, handles)
3011% hObject    handle to edit74 (see GCBO)
3012% eventdata  reserved - to be defined in a future version of MATLAB
3013% handles    empty - handles not created until after all CreateFcns called
3014
3015% Hint: edit controls usually have a white background on Windows.
3016%       See ISPC and COMPUTER.
3017if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
3018    set(hObject,'BackgroundColor','white');
3019end
3020
3021
3022function dz_civ1_Callback(hObject, eventdata, handles)
3023% hObject    handle to dz_civ1 (see GCBO)
3024% eventdata  reserved - to be defined in a future version of MATLAB
3025% handles    structure with handles and user data (see GUIDATA)
3026
3027% Hints: get(hObject,'String') returns contents of dz_civ1 as text
3028%        str2double(get(hObject,'String')) returns contents of dz_civ1 as a double
3029
3030
3031function edit77_Callback(hObject, eventdata, handles)
3032% hObject    handle to edit77 (see GCBO)
3033% eventdata  reserved - to be defined in a future version of MATLAB
3034% handles    structure with handles and user data (see GUIDATA)
3035
3036% Hints: get(hObject,'String') returns contents of edit77 as text
3037%        str2double(get(hObject,'String')) returns contents of edit77 as a double
3038
3039
3040
3041function edit78_Callback(hObject, eventdata, handles)
3042% hObject    handle to ref_i (see GCBO)
3043% eventdata  reserved - to be defined in a future version of MATLAB
3044% handles    structure with handles and user data (see GUIDATA)
3045
3046% Hints: get(hObject,'String') returns contents of ref_i as text
3047%        str2double(get(hObject,'String')) returns contents of ref_i as a double
3048
3049
3050function edit79_Callback(hObject, eventdata, handles)
3051% hObject    handle to edit79 (see GCBO)
3052% eventdata  reserved - to be defined in a future version of MATLAB
3053% handles    structure with handles and user data (see GUIDATA)
3054
3055% Hints: get(hObject,'String') returns contents of edit79 as text
3056%        str2double(get(hObject,'String')) returns contents of edit79 as a double
3057
3058
3059
3060function npz_Callback(hObject, eventdata, handles)
3061% hObject    handle to npz (see GCBO)
3062% eventdata  reserved - to be defined in a future version of MATLAB
3063% handles    structure with handles and user data (see GUIDATA)
3064
3065% Hints: get(hObject,'String') returns contents of npz as text
3066%        str2double(get(hObject,'String')) returns contents of npz as a double
3067
3068
3069function npy_Callback(hObject, eventdata, handles)
3070% hObject    handle to npy (see GCBO)
3071% eventdata  reserved - to be defined in a future version of MATLAB
3072% handles    structure with handles and user data (see GUIDATA)
3073
3074% Hints: get(hObject,'String') returns contents of npy as text
3075%        str2double(get(hObject,'String')) returns contents of npy as a double
3076
3077
3078
3079
3080function npx_Callback(hObject, eventdata, handles)
3081% hObject    handle to npx (see GCBO)
3082% eventdata  reserved - to be defined in a future version of MATLAB
3083% handles    structure with handles and user data (see GUIDATA)
3084
3085% Hints: get(hObject,'String') returns contents of npx as text
3086%        str2double(get(hObject,'String')) returns contents of npx as a double
3087
3088
3089
3090
Note: See TracBrowser for help on using the repository browser.