source: trunk/src/civ.m @ 279

Last change on this file since 279 was 279, checked in by gostiaux, 13 years ago

civ opens again from uvmat

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