source: trunk/src/civ_3D.m @ 1022

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