source: trunk/src/civ_3D.m @ 61

Last change on this file since 61 was 42, checked in by sommeria, 14 years ago

-proj_field, plot_field, civ_3D: bug repair for 3D3C velocity fields (not finished)
-check_function: introduce try/catch for function datenum (error with french systems)
-cleaning of warndlg_uvmat in different fcts (replaced by msgbox_uvmat)

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