source: trunk/src/civ_3D.m @ 35

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