Home > . > civ_3D.m

# civ_3D

## PURPOSE

'civ_3D': function associated with the interface 'civ_3D.fig' for PIV in volume

## SYNOPSIS

function varargout = civ_3D(varargin)

## DESCRIPTION

    'civ_3D': function associated with the interface 'civ_3D.fig' for PIV in volume
    ------------------------------------------------------------------------
      provides an interface for the software CIVx
     function varargout = civ_3D(varargin)
     provides an interface for the software CIVx

    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
      Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
         This file is part of the toolbox UVMAT.

         UVMAT is free software; you can redistribute it and/or modify
         it under the terms of the GNU General Public License as published by
         the Free Software Foundation; either version 2 of the License, or
         (at your option) any later version.

         UVMAT is distributed in the hope that it will be useful,
         but WITHOUT ANY WARRANTY; without even the implied warranty of
         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
         GNU General Public License (file UVMAT/COPYING.txt) for more details.
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

## CROSS-REFERENCE INFORMATION

This function calls:

- editxml 'editxml': function for editing xml files using a xml schema (associated with the GUI editxml.fig)
- imadoc2struct 'imadoc2struct': reads the xml file for image documentation
- name2display 'name2display': extracts the root name and field numbers from an input filename
- name_generator 'name_generator': creates a file name from a root name and indices.
- nc2struct 'nc2struct': transform a netcdf file in a corresponding matlab structure
- num2stra 'num2stra': transform number to the corresponding character string depending on the nomenclature
- read_image 'read_image': reads an image from a single file or a movie file
- stra2num 'stra2num': transform letters (a, b, c) or numerical strings ('1','2'..) to the corresponding numbers
- struct2xml 'struct2xml': transform a matlab structure to a xml tree.
- warndlg_uvmat 'warndlg_uvmat': display warning message (error, warning, confirmation) in a given figure

This function is called by:

## SUBFUNCTIONS

- function civ_3D_OpeningFcn(hObject, eventdata, handles, varargin)
- function varargout = civ_3D_OutputFcn(hObject, eventdata, handles)
- function browse_root_Callback(hObject, eventdata, handles)
- function ImaDoc_Callback(hObject, eventdata, handles)
- function displ_filebase_Callback(hObject, eventdata, handles)
- function mode_Callback(hObject, eventdata, handles)
- function find_netcpair_civ1(hObject, eventdata, handles)
- function find_netcpair_civ2(hObject, eventdata, handles)
- function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=
- function list_pair_civ1_Callback(hObject, eventdata, handles)
- function list_pair_civ2_Callback(hObject, eventdata, handles)
- function BATCH_Callback(hObject, eventdata, handles)
- function cmd_PATCH=RUN_PATCH(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp)
- function first_j_Callback(hObject, eventdata, handles)
- function CIV1_Callback(hObject, eventdata, handles)
- function FIX1_Callback(hObject, eventdata, handles)
- function PATCH1_Callback(hObject, eventdata, handles)
- function CIV2_Callback(hObject, eventdata, handles)
- function FIX2_Callback(hObject, eventdata, handles)
- function PATCH2_Callback(hObject, eventdata, handles)
- function first_i_Callback(hObject, eventdata, handles)
- function calcul_search_Callback(hObject, eventdata, handles)
- function subdir_civ1_Callback(hObject, eventdata, handles)
- function subdir_civ2_Callback(hObject, eventdata, handles)
- function get_mask_civ1_Callback(hObject, eventdata, handles)
- function get_mask_fix1_Callback(hObject, eventdata, handles)
- function get_mask_civ2_Callback(hObject, eventdata, handles)
- function get_mask_fix2_Callback(hObject, eventdata, handles)
- function [nbslice, flag_mask]=get_mask(filebase,handles)
- function grid_civ1_Callback(hObject, eventdata, handles)
- function str=num2stra(num,nom_type);
- function mask_civ1_Callback(hObject, eventdata, handles)
- function mask_civ2_Callback(hObject, eventdata, handles)
- function mask_fix1_Callback(hObject, eventdata, handles)
- function mask_fix2_Callback(hObject, eventdata, handles)
- function list_subdir_civ1_Callback(hObject, eventdata, handles)
- function rho_civ2_Callback(hObject, eventdata, handles)
- function last_i_Callback(hObject, eventdata, handles)
- function last_j_Callback(hObject, eventdata, handles)
- function browse_gridciv1_Callback(hObject, eventdata, handles)
- function pxcmx_Callback(hObject, eventdata, handles)
- function pxcmy_Callback(hObject, eventdata, handles)
- function browse_gridciv2_Callback(hObject, eventdata, handles)
- function get_gridpatch1_Callback(hObject, eventdata, handles)
- function get_gridpatch2_Callback(hObject, eventdata, handles)
- function enable_civ1(handles,state)
- function enable_fix1(handles)
- function desable_fix1(handles)
- function enable_patch1(handles)
- function desable_patch1(handles)
- function enable_civ2(handles,state)
- function enable_fix2(handles)
- function desable_fix2(handles)
- function enable_patch2(handles)
- function desable_patch2(handles)
- function test_interp_Callback(hObject, eventdata, handles)
- function par=read_param_civ1(handles,file_ima)
- function cmd_CIV1=BATCH_CIV1(filename,namelog,par,handles)
- function xml_civ1_parameters=BATCH_CIV1_Unified(filename,namelog,par,handles)
- function cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par)
- function HELP_Callback(hObject, eventdata, handles)
- function A=read_image(filename,nom_type,npx,npy,num);
- function dt_Callback(hObject, eventdata, handles)
- function ref_i_Callback(hObject, eventdata, handles)
- function ref_j_Callback(hObject, eventdata, handles)
- function compare_Callback(hObject, eventdata, handles)
- function get_ref_fix1_Callback(hObject, eventdata, handles)
- function get_ref_fix2_Callback(hObject, eventdata, handles)
- function ref_fix1_Callback(hObject, eventdata, handles)
- function ref_fix2_Callback(hObject, eventdata, handles)
- function inf_sup1_Callback(hObject, eventdata, handles)
- function field_ref_Callback(hObject, eventdata, handles)
- function field_ref2_Callback(hObject, eventdata, handles)
- function numres=stra2num(str)
- function test_stereo1_Callback(hObject, eventdata, handles)
- function test_stereo2_Callback(hObject, eventdata, handles)
- function ImaThreshold_Callback(hObject, eventdata, handles)
- function ImaThreshold2_Callback(hObject, eventdata, handles)
- function Experimental_Callback(hObject, eventdata, handles)
- function ibz_Callback(hObject, eventdata, handles)
- function ibz_CreateFcn(hObject, eventdata, handles)
- function edit74_Callback(hObject, eventdata, handles)
- function edit74_CreateFcn(hObject, eventdata, handles)
- function edit75_Callback(hObject, eventdata, handles)
- function edit75_CreateFcn(hObject, eventdata, handles)
- function dz_civ1_Callback(hObject, eventdata, handles)
- function dz_civ1_CreateFcn(hObject, eventdata, handles)

## SOURCE CODE

    0001 %'civ_3D': function associated with the interface 'civ_3D.fig' for PIV in volume
    0002 %------------------------------------------------------------------------
    0003 %  provides an interface for the software CIVx
    0004 % function varargout = civ_3D(varargin)
    0005 % provides an interface for the software CIVx
    0006 %
    0007 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0008 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    0009 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0010 %     This file is part of the toolbox UVMAT.
    0011 %
    0012 %     UVMAT is free software; you can redistribute it and/or modify
    0013 %     it under the terms of the GNU General Public License as published by
    0014 %     the Free Software Foundation; either version 2 of the License, or
    0015 %     (at your option) any later version.
    0016 %
    0017 %     UVMAT is distributed in the hope that it will be useful,
    0018 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
    0019 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0020 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
    0021 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0022 function varargout = civ_3D(varargin)
    0023
    0024 % Last Modified by GUIDE v2.5 25-Feb-2009 23:14:16
    0025 % Begin initialization code - DO NOT EDIT
    0026 gui_Singleton = 1;
    0027 gui_State = struct('gui_Name',       mfilename, ...
    0028                    'gui_Singleton',  gui_Singleton, ...
    0029                    'gui_OpeningFcn', @civ_3D_OpeningFcn, ...
    0030                    'gui_OutputFcn',  @civ_3D_OutputFcn, ...
    0031                    'gui_LayoutFcn',  [] , ...
    0032                    'gui_Callback',   []);
    0033 if nargin & isstr(varargin{1})
    0034     gui_State.gui_Callback = str2func(varargin{1});
    0035 end
    0036
    0037 if nargout
    0038     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    0039 else
    0040     gui_mainfcn(gui_State, varargin{:});
    0041 end
    0042 % End initialization code - DO NOT EDIT
    0043
    0044 %--------------------------------------------------------------------------
    0045 % --- Executes just before civ_3D is made visible.
    0046 %--------------------------------------------------------------------------
    0047 function civ_3D_OpeningFcn(hObject, eventdata, handles, varargin)
    0048 % This function has no output args, see OutputFcn.
    0049 % hObject    handle to figure
    0050 % eventdata  reserved - to be defined in a future version of MATLAB
    0051 % handles    structure with handles and user data (see GUIDATA)
    0052 % varargin   command line arguments to civ_3D (see VARARGIN)
    0053 global test_batch patch_new_exe%=1 if patch processing available
    0054 %filebase: root name
    0055 %nom_type: nomencalture used ('png_old','_i_j'...)
    0056 %list of field numbers to process
    0057 %subdir: subdirectory of the opened netcdf file
    0058 %ind_opening: operation number advised for beginning (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2),
    0059 %ind_a_opening ind_b_opening chosen pair from the opened netcdf file
    0060 % Choose default command line output for civ_3D
    0061 handles.output = hObject;
    0062 % Update handles structure
    0063 guidata(hObject, handles);
    0064
    0065 %default initial parameters
    0066 filebase=''; % root file name ('filebase'.civ_3D)
    0067 nom_type=[]; % nomenclature type
    0068 ext=[];
    0069 testall=0;
    0070 browse=[];
    0071
    0072 %load the initial parameters if the interface is started from uvmat
    0073 if ~isempty(varargin)% the interface is opened from uvmat
    0074     varcell=varargin{1};
    0075     filebase=varcell{1};
    0076     nom_type_read=varcell{2};
    0077     num1=varcell{3};
    0078     num2=varcell{4};
    0079     num_a=varcell{5};
    0080     num_b=varcell{6};
    0081     subdir=varcell{7};
    0082     ind_opening=varcell{8};
    0083     ind_a_opening=varcell{9};
    0084     ind_b_opening=varcell{10};
    0085     ext=varcell{11};
    0086 else
    0087     num1=1; % set of field i numbers
    0088     num2=2; % set of field i numbers
    0089     num_a=1; % set of field j numbers (fields a)
    0090     num_b=1; % second set of field j numbers (fields b)
    0091     subdir='A'; % subdir for the netcdf result files
    0092     ind_opening=1; % proposed operation number (1=civ1,2=fix1,3=patch1,4=civ2,5=fix2,6=patch2)
    0093     ind_a_opening=1; % proposed index in the menu of fields a
    0094     ind_b_opening=2; % proposed index in the menu of fields b
    0095 end
    0096
    0097 if exist('ext','var') & length(ext)>1 & (~isempty(imformats(ext([2:end])))|...
    0098                        isequal(ext,'.avi')|isequal(ext,'.AVI'));%if an image file has been opened by uvmat
    0099         browse.ext_ima=ext;
    0100         if exist('nom_type_read','var')
    0101             browse.nom_type_ima=nom_type_read; % the image nomenclature is stored
    0102         end
    0103 elseif isequal(ext,'.nc')
    0104     if exist('nom_type_read','var')
    0105         browse.nom_type_nc=nom_type_read;% the netcdf  nomenclature is stored
    0106     end
    0107 end
    0108 set(handles.displ_filebase,'String',filebase);
    0109 set(handles.ImaDoc,'UserData',testall);
    0110 set(handles.browse_root,'UserData',browse)
    0111 set(handles.ImaDoc,'String',ext)
    0112
    0113
    0114 % set(handles.ImaDoc,'String',ext)
    0115
    0116 %read names of the .exe file to adjust the interface according to
    0117 %available prog
    0118 %read names of the .exe file
    0119 path_uvmat=which('uvmat');% check the path detected for source file uvmat
    0120 path_UVMAT=fileparts(path_uvmat); %path to UVMAT
    0121 if isunix
    0122     syst='LINUX'
    0123     %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ_3D binary names
    0124     xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml')
    0125     if exist(xmlfile,'file')
    0126         t=xmltree(xmlfile);
    0127         sparam=convert(t);
    0128     end
    0129 else
    0130     syst='WIN'
    0131     %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ_3D binary names
    0132     xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
    0133     if exist(xmlfile,'file')
    0134         t=xmltree(xmlfile);
    0135         sparam=convert(t);
    0136     end
    0137 end
    0138
    0139 patch_new_exe='';
    0140 todo_patch='';
    0141 sge=0;
    0142
    0143 if isfield(sparam,'PatchNew_exe')
    0144     patch_new_exe=sparam.PatchNew_exe;
    0145 end
    0146 if isfield(sparam,'Todo_path')
    0147     todo_path=sparam.Todo_path
    0148 end
    0149 if isfield(sparam,'SGE')
    0150     sge=str2num(sparam.SGE);
    0151 end
    0152 name_todo=fullfile(todo_path,'TODO.txt')
    0153 test_batch=1;
    0154 if ~sge
    0155 if isequal(todo_path,'') |isequal(todo_path,[])
    0156     ['no batch distributed processing available:file path TODO.txt not defined in UVMAT/PARAM_' syst]
    0157     test_batch=0;
    0158 end
    0159 if exist(name_todo,'file')~=2
    0160     hwarn=warndlg(['no batch distributed processing available, queue file ' name_todo ' absent']);
    0161   %  test_batch=0;  % Problems to detect file on linux/nfs filesystems
    0162 end
    0163 end
    0164
    0165
    0166 if test_batch==0
    0167     set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])% put the BATCH button in grey (unactivated)
    0168 end
    0169
    0170 set(handles.subdir_civ1,'String',subdir)%default subdir on which uvmat was working
    0171 set(handles.subdir_civ2,'String',subdir)%default subdir on which uvmat was working
    0172
    0173 %initiate advised operations
    0174 if isequal(ind_opening,[])
    0175     ind_opening=1; % default
    0176 end
    0177 % set default operation options
    0178     enable_civ1(handles,'off')
    0179     enable_civ2(handles,'off')
    0180     desable_fix1(handles)
    0181     desable_patch1(handles)
    0182     desable_fix2(handles)
    0183     desable_patch2(handles)
    0184     set(handles.CIV1,'Value',0)
    0185     set(handles.FIX1,'Value',0)
    0186     set(handles.PATCH1,'Value',0)
    0187     set(handles.CIV2,'Value',0)
    0188     set(handles.FIX2,'Value',0)
    0189     set(handles.PATCH2,'Value',0)
    0190     set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
    0191 if isequal(ind_opening,1)
    0192     set(handles.CIV1,'Value',1)
    0193     enable_civ1(handles,'on')
    0194 elseif isequal(ind_opening,2)
    0195     set(handles.FIX1,'Value',1)
    0196     enable_fix1(handles)
    0197 elseif isequal(ind_opening,3)
    0198     set(handles.PATCH1,'Value',1)
    0199     enable_patch1(handles)
    0200 elseif isequal(ind_opening,4)
    0201     set(handles.CIV2,'Value',1)
    0202     enable_civ2(handles,1)
    0203 elseif isequal(ind_opening,5)
    0204     set(handles.FIX2,'Value',1)
    0205     enable_fix2(handles)
    0206      set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
    0207      set(handles.list_pair_civ2,'Enable','On')
    0208      set(handles.list_pair_civ2,'Enable','On')
    0209 elseif isequal(ind_opening,6)
    0210     set(handles.PATCH2,'Value',1)
    0211     enable_patch2(handles)
    0212     set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
    0213     set(handles.list_pair_civ2,'Enable','On')
    0214 end
    0215
    0216 % set the range of fields (1:1 by default) and selected pair
    0217 if isempty(num2)|isequal(num2,num1)
    0218     num_ref_i=num1;
    0219 else
    0220     num_ref_i=floor((num1+num2)/2);
    0221     browse.incr_pair(1)=num2-num1;
    0222     browse.incr_pair(2)=0;
    0223 end
    0224 if isempty(num_b)|isequal(num_a,num_b)
    0225     if isempty(num_a)
    0226         num_ref_j=1;
    0227     else
    0228         num_ref_j=num_a;
    0229     end
    0230 else
    0231     num_ref_j=floor((num_a+num_b)/2);
    0232     browse.incr_pair(2)=num_b-num_a;
    0233 end
    0234 set(handles.first_i,'String',num2str(num_ref_i));
    0235 set(handles.last_i,'String',num2str(num_ref_i));
    0236 set(handles.first_j,'String',num2str(num_ref_j));
    0237 set(handles.last_j,'String',num2str(num_ref_j));
    0238 set(handles.ref_i,'String',num2str(num_ref_i));
    0239 set(handles.ref_j,'String',num2str(num_ref_j));
    0240 set(handles.browse_root,'UserData',browse);
    0241 if ~isempty(varargin)% the interface is opened from uvmat
    0242     displ_filebase_Callback(hObject, eventdata, handles);
    0243 end
    0244
    0245 set(handles.waitbar_1,'Position',[0.946 0.877 0.03 0.001])
    0246 set(handles.waitbar_patch1,'Position',[0.946 0.626 0.03 0.001])
    0247 set(handles.waitbar_civ2,'Position',[0.946 0.406 0.03 0.001])
    0248 set(handles.waitbar_patch2,'Position',[0.946 0.187 0.03 0.001])
    0249
    0250
    0251 %--------------------------------------------------------------
    0252 % --- Outputs from this function are returned to the command line.
    0253 %-----------------------------------------------------------------
    0254 function varargout = civ_3D_OutputFcn(hObject, eventdata, handles)
    0255 % varargout  cell array for returning output args (see VARARGOUT);
    0256 % hObject    handle to figure
    0257 % eventdata  reserved - to be defined in a future version of MATLAB
    0258 % handles    structure with handles and user data (see GUIDATA)
    0259 % Get default command line output from handles structure
    0260 varargout{1} = handles.output;
    0261
    0262 %------------------------------------------------------------------
    0263 % --- Executes on button press in browse_root.
    0264 function browse_root_Callback(hObject, eventdata, handles)
    0265 %get the input file properties
    0266 filebase=get(handles.displ_filebase,'String');
    0267 oldfile=''; %default
    0268 if isempty(filebase)|isequal(filebase,'')%loads the previously stored file name and set it as default in the file_input box
    0269      dir_perso=prefdir;
    0270      profil_perso=fullfile(dir_perso,'uvmat_perso.mat')
    0271      if exist(profil_perso,'file')
    0272           h=load (profil_perso);
    0273          if isfield(h,'filebase')&ischar(h.filebase)
    0274                  oldfile=h.filebase;
    0275          end
    0276          if isfield(h,'RootPath')&ischar(h.RootPath)
    0277 %                 oldfile=h.filebase{1}
    0278                  oldfile=h.RootPath;
    0279          end
    0280      end
    0281  else
    0282      oldfile=filebase;
    0283  end
    0284 testall=get(handles.ImaDoc,'UserData');
    0285 ind_opening=1;%default
    0286 browse.incr_pair=[0 0]; %default
    0287
    0288 menu={'*.*', 'All Files (*.*)'; '*.xml;*.vol; *.avi;*.AVI','(*.xml,*.civ,*.avi,*.vol)'; ...
    0289         '*.xml', '.xml files';'*.civ', '.civ files';...
    0290          '*.avi;*.AVI', '.avi files';'*.vol', '.vol files'};
    0291
    0292 [FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
    0293 fileinput=[PathName FileName];%complete file name
    0294 sizf=size(fileinput);
    0295 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
    0296 [path,name,ext]=fileparts(fileinput);
    0297 testeditxml=0;
    0298 if isequal(ext,'.xml')
    0299     testeditxml=1;
    0300     t_browse=xmltree(fileinput);
    0301     head_element=get(t_browse,1);
    0302     if isfield(head_element,'name')& isequal(head_element.name,'ImaDoc')
    0303         testeditxml=0;
    0304     end
    0305 end
    0306 if testeditxml==1 | isequal(ext,'.xls')
    0307    heditxml=editxml({fileinput});
    0308    set(heditxml,'Tag','browser')
    0309    waitfor(heditxml,'Tag','idle')
    0310    if ~ishandle(heditxml)
    0311        return
    0312    end
    0313    attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
    0314    set(handles.browse,'UserData',fileinput)% store for future opening with browser
    0315    fileinput=get(attr,'UserData');
    0316    if ~exist(fileinput,'file')
    0317        return
    0318    end
    0319 end
    0320 [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
    0321 filebase=fullfile(RootPath,RootFile);
    0322 if isequal(get(handles.compare,'Value'),1)
    0323     browse=get(handles.browse_root,'UserData');
    0324 else
    0325     browse=[];%initialisation
    0326 end
    0327 if length(ext)>1 & (~isempty(imformats(ext([2:end])))||...
    0328                        isequal(lower(ext),'.avi')||isequal(ext,'.vol'));%if an image file has been opened by uvmat
    0329     browse.ext_ima=ext;
    0330     browse.nom_type_ima=nom_type;
    0331     browse.field_count=str2num(field_count);
    0332 end
    0333 set(handles.ImaDoc,'String',ext);
    0334 %%%%% read the state of the selected netcdf file to advise default operation
    0335 if isequal(ext,'.nc')
    0336     browse.nom_type_nc=nom_type;
    0337     ind_opening=2;% propose 'fix' as the default option
    0338     Data=nc2struct(fileinput,[]);
    0339     if isfield(Data,'fix') & isequal(Data.fix,1)
    0340         ind_opening=3;
    0341     end
    0342     if isfield(Data,'patch') & isequal(Data.patch,1)
    0343         ind_opening=4;
    0344     end
    0345     if isfield(Data,'civ2') & isequal(Data.civ2,1)
    0346         ind_opening=5;
    0347     end
    0348     if isfield(Data,'fix2') & isequal(Data.fix2,1)
    0349         ind_opening=6;
    0350     end
    0351     if isfield(Data,'pixcmx') & isequal(Data,'pixcmy')
    0352         browse.pxcmx=Data.pixcmx;
    0353         browse.pxcmy=Data.pixcmy;
    0354     end
    0355     testciv=1; %TO SUPPRESS WITH NEW VERSION OF CIVX
    0356     subdir='';%default
    0357     if testciv
    0358         [Pathbase,Namebase]=fileparts(filebase)
    0359         [Pathprev,subdir,extdir]=fileparts(Pathbase)
    0360         subdir=[subdir extdir]
    0361 %         if isequal (subdir,subdir_obs)
    0362         filebase=fullfile(Pathprev,Namebase)% move upward to get the base name (corresponding to the .civ_3D file and images)
    0363 %         end
    0364     end
    0365     set(handles.subdir_civ1,'String',subdir);%set the default subdir directories for installing the .nc results
    0366     set(handles.subdir_civ2,'String',subdir);
    0367     browse.testciv=testciv;
    0368     browse.ind_opening=ind_opening;
    0369 end
    0370 set(handles.displ_filebase,'String',filebase);
    0371 set(handles.ImaDoc,'String',ext);
    0372 if ~isempty(str2num(field_count))
    0373     ref_i=str2num(field_count);
    0374     if ~isempty(str2num(str2))
    0375         ref_i=floor((ref_i+str2num(str2))/2);% reference image number corresponding to the file
    0376         browse.incr_pair(1)=str2num(str2)-str2num(field_count);
    0377         browse.incr_pair(2)=0;
    0378     end
    0379     set(handles.first_i,'String',num2str(ref_i));
    0380     set(handles.last_i,'String',num2str(ref_i));
    0381     set(handles.ref_i,'String',num2str(ref_i));
    0382 end
    0383 if isempty(str2num(str_a))
    0384     set(handles.ref_j,'String','1');
    0385 else
    0386     ref_j=str2num(str_a);
    0387     if ~isempty(str2num(str_b))
    0388         ref_j=floor((str2num(str_a)+str2num(str_b))/2);
    0389         browse.incr_pair(2)=str2num(str_b)-str2num(str_a);
    0390     end
    0391     set(handles.first_j,'String',num2str(ref_j));
    0392     set(handles.last_j,'String',num2str(ref_j));
    0393     set(handles.ref_j,'String',num2str(ref_j));
    0394 end;
    0395 if isequal(ind_opening,1)
    0396     set(handles.CIV1,'Value',1)
    0397     enable_civ1(handles,'on')
    0398 elseif isequal(ind_opening,2)
    0399     set(handles.FIX1,'Value',1)
    0400     enable_fix1(handles)
    0401 elseif isequal(ind_opening,3)
    0402     set(handles.PATCH1,'Value',1)
    0403     enable_patch1(handles)
    0404 elseif isequal(ind_opening,4)
    0405     set(handles.CIV2,'Value',1)
    0406     enable_civ2(handles,1)
    0407 elseif isequal(ind_opening,5)
    0408     set(handles.FIX2,'Value',1)
    0409     enable_fix2(handles)
    0410      set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
    0411      set(handles.list_pair_civ2,'Enable','On')
    0412      set(handles.list_pair_civ2,'Enable','On')
    0413 elseif isequal(ind_opening,6)
    0414     set(handles.PATCH2,'Value',1)
    0415     enable_patch2(handles)
    0416     set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
    0417     set(handles.list_pair_civ2,'Enable','On')
    0418 end
    0419 set(handles.browse_root,'UserData',browse);% store information from browser
    0420 testall=isequal(menu(filtindex,1),{'*.*'});
    0421 set(handles.ImaDoc,'UserData',testall);
    0422
    0423 displ_filebase_Callback(hObject, eventdata, handles);
    0424
    0425 %------------------------------------------------
    0426
    0427 function ImaDoc_Callback(hObject, eventdata, handles)
    0428 displ_filebase_Callback(hObject, eventdata, handles)
    0429
    0430 %--------------------------------------------------------------
    0431 %function activated when a new filebase (image series) is introduced
    0432 %------------------------------------------------------------
    0433 function displ_filebase_Callback(hObject, eventdata, handles)
    0434
    0435 global test_batch
    0436 set(gcf,'Pointer','watch')
    0437 ext_ima=[]; %default
    0438 nom_type_ima=[];%default
    0439 field_count=1;%default
    0440 nom_type_nc=[];
    0441 npx=[];%default
    0442 npy=[];
    0443 TimeUnit='s'; %default
    0444 CoordUnit='cm';%default
    0445 pxcmx_search=[];%default
    0446 pxcmy_search=[];%default
    0447 filebase=get(handles.displ_filebase,'String');
    0448
    0449 ext=get(handles.ImaDoc,'String');
    0450 browse=get(handles.browse_root,'UserData');%default
    0451 if ~isempty(browse)
    0452     if isfield(browse,'ext_ima')
    0453         ext_ima=browse.ext_ima;
    0454     end
    0455     if isfield(browse,'nom_type_ima')
    0456         nom_type_ima=browse.nom_type_ima;
    0457     end
    0458     if isfield(browse,'field_count')
    0459         field_count=browse.field_count;
    0460     end
    0461 end
    0462
    0463 %default first_i and j and increments
    0464 first_i=str2num(get(handles.first_i,'String'));%value possibly set by uvmat_Opening
    0465 if isempty(first_i)| first_i < 1
    0466     first_i=1; %default first_i
    0467 end
    0468 last_i=str2num(get(handles.last_i,'String'));
    0469 if isempty(last_i)| last_i < first_i
    0470     last_i=first_i;  %default last_i
    0471 end
    0472 first_j=str2num(get(handles.first_j,'String'));
    0473 if isempty(first_j)| first_j < 1
    0474     first_j=1; %default first_j
    0475 end
    0476 last_j=str2num(get(handles.last_j,'String'));
    0477 if isempty(last_j)| last_j < first_j
    0478     last_j=first_j; %default last_j
    0479 end
    0480 incr_i=str2num(get(handles.incr_i,'String'));
    0481 if isempty(incr_i) | incr_i < 1;
    0482     set(handles.incr_i,'String','1') %default incr_i
    0483 end
    0484 incr_j=str2num(get(handles.incr_j,'String'));
    0485 if isempty(incr_j) | incr_j < 1;
    0486     set(handles.incr_j,'String','1') %default incr_j
    0487 end
    0488 dt=[];%default
    0489 testmode=0;%default
    0490 nbfield=1; %default
    0491 if isfield(browse,'pxcmx') & isfield(browse,'pxcmy')
    0492     pxcmx=num2str(browse.pxcmx);
    0493     pxcmy=num2str(browse.pxcmy);
    0494 else
    0495     pxcmx=1;%default
    0496     pxcmy=1;
    0497 end
    0498  %look for an image documentation file
    0499 if ~isequal(ext,'.xml') & ~ isequal(ext,'.avi')& ~ isequal(ext,'.AVI')
    0500     if exist([filebase '.xml'],'file')
    0501          ext='.xml';
    0502          set(handles.ImaDoc,'String','.xml')
    0503     elseif exist([filebase '.civ_3D'],'file')
    0504          ext='.civ_3D';
    0505          set(handles.ImaDoc,'String','.civ_3D')
    0506     elseif exist([filebase '.avi'],'file')
    0507          ext='.avi';
    0508          set(handles.ImaDoc,'String','.avi')
    0509     elseif exist([filebase '.AVI'],'file')
    0510          ext='.AVI';
    0511          set(handles.ImaDoc,'String','.AVI')
    0512     end
    0513 end
    0514 %%%%%%%%   read image documentation file  %%%%%%%%%%%%%%%%%%%%%%%%%%%
    0515     mode=''; %default
    0516     %read the image documentation file if found
    0517 if  isequal(ext,'.xml')
    0518     set(handles.ref_i,'Visible','On')%use a reference index
    0519     set(handles.ref_j,'Visible','On')
    0520     set(handles.dt,'Visible','Off')
    0521     set(handles.dt_text,'String','ref. ind.')
    0522 elseif isequal(ext,'.avi') | isequal(ext,'.AVI')
    0523     set(handles.ref_j,'Visible','Off')
    0524     set(handles.dt,'Visible','Off')
    0525     set(handles.dt_text,'String','ref. ind.')
    0526 else
    0527     set(handles.ref_i,'Visible','Off')
    0528     set(handles.ref_j,'Visible','Off')
    0529     set(handles.dt,'Visible','On')
    0530     set(handles.dt_text,'String','dt(ms)=')
    0531 end
    0532
    0533 if isequal(ext,'.xml')
    0534     [XmlData,warntext]=imadoc2struct([filebase '.xml']);
    0535         if isfield(XmlData,'Heading')&&isfield(XmlData.Heading','ImageName')
    0536             [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
    0537         end
    0538         if isfield(XmlData,'Camera')
    0539             if isfield(XmlData.Camera,'TimeUnit')
    0540                 TimeUnit=XmlData.Camera.TimeUnit;
    0541             end
    0542             if isfield(XmlData.Camera,'ImageSize')
    0543                ImageSize=XmlData.Camera.ImageSize;
    0544                if ~isempty(ImageSize)&& ~isempty(ImageSize)
    0545                    xindex=findstr(ImageSize,'x');
    0546                    if length(xindex)>=2
    0547                         npx=str2num(ImageSize(1:xindex(1)-1));
    0548                         npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
    0549                    end
    0550                end
    0551            end
    0552         end
    0553         pxcmx_search=1;
    0554         pxcmy_search=1;
    0555         if isfield(XmlData,'GeometryCalib')
    0556             tsai=XmlData.GeometryCalib;
    0557             if isfield(tsai,'f') & isfield(tsai,'Tz') & isfield(tsai,'dpx') & isfield(tsai,'dpy')& isfield(tsai,'R')
    0558                  rot2D=tsai.R([1:2],[1,2]);
    0559                  pxcmx_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpx);
    0560                  pxcmy_search=tsai.f * sqrt(det(rot2D))/(tsai.Tz*tsai.dpy);
    0561             end
    0562             if isfield(tsai,'CoordUnit')
    0563                  CoordUnit=tsai.CoordUnit;
    0564             end
    0565         end
    0566         if isempty(ext_ima_read)
    0567               ext_ima='.png';%default
    0568         else
    0569               ext_ima=ext_ima_read;
    0570         end
    0571         if isempty(nom_type_read)
    0572                 nom_type_ima='_i_j';
    0573                 warndlg_uvmat('no ImageName defined in ImaDoc/Heading, take _i_j indexing by default','WARNING')
    0574         else
    0575                 nom_type_ima=nom_type_read;
    0576         end
    0577
    0578 elseif isequal(ext,'.avi')|isequal(ext,'.AVI')
    0579         nom_type_ima='avi';
    0580         ext_ima=ext;
    0581         set(handles.mode,'String',{'series(Di)'})
    0582         dt=0.04;%default
    0583         if exist([filebase ext],'file')==2
    0584             info=aviinfo([filebase ext]);%read infos on the avi movie
    0585             dt=1/info.FramesPerSecond;%time interval between successive frames
    0586             nbfield=info.NumFrames;%number of frames
    0587         end
    0588         time=(dt*[0:nbfield-1])';%list of image times
    0589         set(handles.dt,'String',num2str(dt*1000));%store the time interval between successive images
    0590
    0591      % no image documentation file found: look for a series of existing images or .nc files
    0592 elseif ~isequal(ext,'.nc')
    0593         subdir=get(handles.subdir_civ1,'String');
    0594         incr_pair=[0 0];%default
    0595         if isfield(browse,'incr_pair')
    0596                 incr_pair=browse.incr_pair;
    0597         end
    0598         nbdetect=0;%test of detected images
    0599         field_i=field_count;
    0600         idetect=1;
    0601 %         imagename='';%default
    0602         while idetect==1 %look for the maximum file number in the series
    0603                 field_i=field_i+1;
    0604 %                 imagename_last=imagename;
    0605                 [imagename,idetect]=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
    0606                 if isequal(nom_type_ima,'none')
    0607                    idetect=0; %stop if the same image is repeated (if nom_type='none')
    0608                    nbdetect=1;
    0609                 end
    0610                 %SEE CASE OF NETCDF FILES
    0611                 nbdetect=nbdetect+idetect;
    0612         end
    0613 %         nb_field=field_i-1;% last detected field number
    0614         nb_field=field_i;% last detected field number
    0615         field_i=field_count;%look for the minimum file number in the series
    0616         idetect=1;
    0617         while idetect==1
    0618                     field_i=field_i-1;
    0619                     [imagename,idetect]=name_generator(filebase,field_i,1,ext_ima,nom_type_ima);
    0620                     if isequal(nom_type_ima,'none')
    0621                         idetect=0; %stop if the same image is repeted (if nom_type='none')
    0622                         nbdetect=1;
    0623                     end
    0624                     nbdetect=nbdetect+idetect;
    0625         end
    0626         first_i=max(field_i+1,1);
    0627             %determine the set of times and possible intervals for CIV_3D
    0628         dt=(1/1000)*str2num(get(handles.dt,'String'));
    0629         time=(dt*[0:nb_field-1])';
    0630 %             set(handles.incr_i,'UserData',dt);%store the time interval
    0631 %             between successive images
    0632             %displ_num:list  of possible time intervals for civ_3D calculations
    0633         set(handles.mode,'String',{'series(Di)'})
    0634 end
    0635 if isequal(nom_type_ima,'none')% no file numbering used
    0636   first_i=1;
    0637   last_i=1;
    0638    first_j=1;
    0639   last_j=1;
    0640 end
    0641 if exist('time','var')
    0642     siztime=size(time);
    0643     nbfield=siztime(1);
    0644     nbfield2=siztime(2);
    0645     set(handles.displ_filebase,'UserData',time); %store the set of times
    0646     set(handles.dt_unit,'String',['m' TimeUnit]);
    0647     set(handles.TimeUnit,'String',TimeUnit);
    0648     set(handles.nb_field,'String',num2str(nbfield));
    0649     set(handles.nb_field2,'String',num2str(nbfield2));
    0650 end
    0651 set(handles.CoordUnit,'String',[CoordUnit '/'])
    0652 set(handles.pxcmx,'String',num2str(pxcmx));
    0653 set(handles.pxcmy,'String',num2str(pxcmy));
    0654 if isempty(pxcmx_search)
    0655    set(handles.calcul_search,'UserData',[pxcmx pxcmy]);
    0656 else
    0657    set(handles.calcul_search,'UserData',[pxcmx_search pxcmy_search]);
    0658 end
    0659 set(handles.pxcmx,'UserData',npx);
    0660 set(handles.pxcmy,'UserData',npy);
    0661 set(handles.first_i,'String',num2str(first_i));
    0662 set(handles.last_i,'String',num2str(last_i));%
    0663 set(handles.first_j,'String',num2str(first_j));
    0664 set(handles.last_j,'String',num2str(last_j));%
    0665 browse.ext_ima=ext_ima;
    0666 browse.nom_type_ima=nom_type_ima;
    0667 set(handles.browse_root,'UserData',browse)% store the nomenclature type
    0668
    0669         %%%%%%%%%%%  set the menus of image pairs and default selection for civ_3D   %%%%%%%%%%%%%%%%%%%
    0670 if isequal(get(handles.compare,'Value'),1)
    0671     if isequal(nom_type_ima,'_i')| isequal(nom_type_nc,'_i1-i2')|~exist('nbfield2','var')|(nbfield2==1)
    0672         set(handles.mode,'String',{'st_series(Di)';'displacement'})
    0673         set(handles.mode,'Value',1)
    0674     elseif (nbfield==1)% simple series in j
    0675         set(handles.mode,'String',{'st_series(Dj)';'displacement'})
    0676         set(handles.mode,'Value',1)
    0677     else
    0678         set(handles.mode,'String',{'st_pair j1-j2';'st_series(Dj)';'st_series(Di)';'displacement'})%multiple choice
    0679         if isequal(mode,'volume')
    0680             set(handles.mode,'Value',3)
    0681         elseif nbfield2 <= 5
    0682             set(handles.mode,'Value',1)% advice 'pair j1-j2' for small bursts
    0683         end
    0684     end
    0685 else
    0686     if isequal(nom_type_ima,'_i')| isequal(nom_type_nc,'_i1-i2')|~exist('nbfield2','var')|(nbfield2==1)
    0687         set(handles.mode,'String',{'series(Di)'})
    0688         set(handles.mode,'Value',1)
    0689     elseif isequal(nom_type_ima,'png_old')|isequal(nom_type_nc,'netc_old')
    0690         set(handles.mode,'String',{'pair j1-j2'})
    0691         set(handles.mode,'Value',1)
    0692     elseif (nbfield==1)% simple series in j
    0693         set(handles.mode,'String',{'series(Dj)'})
    0694         set(handles.mode,'Value',1)
    0695     else
    0696         set(handles.mode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
    0697         if isequal(mode,'volume')
    0698             set(handles.mode,'Value',3)
    0699         elseif nbfield2 <= 5
    0700             set(handles.mode,'Value',1)% advice 'pair j1-j2' for small bursts
    0701         else
    0702             set(handles.mode,'Value',2)% advice series Dj for long bursts, not volume
    0703         end
    0704     end
    0705 end
    0706 mode_Callback(hObject, eventdata, handles)
    0707
    0708 %%%%%% initialize waitbars and RUN button
    0709 set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
    0710 set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
    0711 set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
    0712 set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
    0713 set(handles.RUN, 'Enable','On')
    0714 set(handles.RUN,'BackgroundColor',[1 0 0])
    0715 if isequal(test_batch,1)%if batch installation is available
    0716     set(handles.BATCH, 'Enable','On')
    0717     set(handles.BATCH,'BackgroundColor',[1 0 0])
    0718 end
    0719
    0720 %%%%% store the root input filename for future opening
    0721 dir_perso=prefdir;
    0722 profil_perso=fullfile(prefdir,'uvmat_perso.mat');
    0723 RootPath=fileparts(filebase);
    0724 if exist(profil_perso,'file')
    0725     save (profil_perso,'RootPath','-append'); %store the root name for future opening of uvmat
    0726 else
    0727     txt=ver;
    0728     Release=txt(1).Release;
    0729     relnumb=str2num(Release(3:4));
    0730     if relnumb >= 14
    0731         save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
    0732     else
    0733         save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
    0734     end
    0735 end
    0736 % save(profil_perso, 'filebase'); %store the root name for future opening of uvmat
    0737 set(gcf,'Pointer','arrow')
    0738
    0739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
    0740 % --- Executes on button press in mode.
    0741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0742 function mode_Callback(hObject, eventdata, handles)
    0743 browse=get(handles.browse_root,'UserData');
    0744 mode_list=get(handles.mode,'String');
    0745 mode_value=get(handles.mode,'Value');
    0746 mode=mode_list{mode_value};
    0747 displ_num=[];%default
    0748 first_i=str2num(get(handles.first_i,'String'));
    0749 % last_i=str2num(get(handles.last_i,'String'));
    0750 time=get(handles.displ_filebase,'UserData'); %get the set of times
    0751 siztime=size(time);
    0752 nbfield=siztime(1);
    0753 nbfield2=siztime(2);
    0754 indchosen=1;  %%first pair selected by default
    0755 if isequal(mode,'pair j1-j2')| isequal(mode,'st_pair j1-j2')
    0756     dt=1;
    0757     displ='';
    0758     index=0;
    0759     %get all the time intervals in bursts
    0760     displ_dt=1;%default
    0761     nbfield2=min(nbfield2,10),%limitate the number of pairs to 10x10
    0762 %     if nbfield2<2
    0763 %         nbfield2=2,
    0764 %     end
    0765     for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
    0766         for numod_b=(numod_a+1):nbfield2
    0767              index=index+1;
    0768              numlist_a(index)=numod_a;
    0769              numlist_b(index)=numod_b;
    0770              if ~isempty(time)
    0771                 dt(numod_a,numod_b)=time(first_i,numod_b)-time(first_i,numod_a);%first time interval dt
    0772                 displ_dt(index)=dt(numod_a,numod_b);
    0773              else
    0774                  displ_dt(index)=1
    0775              end
    0776          end
    0777      end
    0778      [dtsort,indsort]=sort(displ_dt);
    0779      displ_num(1,:)=numlist_a(indsort);
    0780      displ_num(2,:)=numlist_b(indsort);
    0781      displ_num(3,:)=0;
    0782      displ_num(4,:)=0;
    0783      set(handles.jtext,'Visible','Off')
    0784     set(handles.first_j,'Visible','Off')
    0785     set(handles.last_j,'Visible','Off')
    0786     set(handles.incr_j,'Visible','Off')
    0787     set(handles.nb_field2,'Visible','Off')
    0788     set(handles.ref_j,'Visible','Off')
    0789 elseif isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
    0790      for index=1:min(nbfield2-1,200)
    0791          displ_num(1,index)=-floor(index/2);
    0792          displ_num(2,index)=ceil(index/2);
    0793          displ_num(3,index)=0;
    0794          displ_num(4,index)=0;
    0795      end
    0796      set(handles.jtext,'Visible','On')
    0797      set(handles.first_j,'Visible','On')
    0798      set(handles.last_j,'Visible','On')
    0799      set(handles.incr_j,'Visible','On')
    0800      set(handles.nb_field2,'Visible','On')
    0801      set(handles.ref_j,'Visible','On')
    0802      if nbfield > 1
    0803         set(handles.itext,'Visible','On')
    0804         set(handles.first_i,'Visible','On')
    0805         set(handles.last_i,'Visible','On')
    0806         set(handles.incr_i,'Visible','On')
    0807         set(handles.nb_field,'Visible','On')
    0808         set(handles.ref_i,'Visible','On')
    0809     else
    0810         set(handles.itext,'Visible','Off')
    0811         set(handles.first_i,'Visible','Off')
    0812         set(handles.last_i,'Visible','Off')
    0813         set(handles.incr_i,'Visible','Off')
    0814         set(handles.nb_field,'Visible','Off')
    0815         set(handles.ref_i,'Visible','Off')
    0816     end
    0817 elseif isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
    0818      for index=1:min(nbfield-1,200)
    0819          displ_num(1,index)=0;
    0820          displ_num(2,index)=0;
    0821          displ_num(3,index)=-floor(index/2);
    0822          displ_num(4,index)=ceil(index/2);
    0823      end
    0824      set(handles.itext,'Visible','On')
    0825      set(handles.first_i,'Visible','On')
    0826      set(handles.last_i,'Visible','On')
    0827      set(handles.incr_i,'Visible','On')
    0828      set(handles.nb_field,'Visible','On')
    0829      set(handles.ref_i,'Visible','On')
    0830      if nbfield2 > 1
    0831         set(handles.jtext,'Visible','On')
    0832         set(handles.first_j,'Visible','On')
    0833         set(handles.last_j,'Visible','On')
    0834         set(handles.incr_j,'Visible','On')
    0835         set(handles.nb_field2,'Visible','On')
    0836         set(handles.ref_j,'Visible','On')
    0837      else
    0838         set(handles.jtext,'Visible','Off')
    0839         set(handles.first_j,'Visible','Off')
    0840         set(handles.last_j,'Visible','Off')
    0841         set(handles.incr_j,'Visible','Off')
    0842         set(handles.nb_field2,'Visible','Off')
    0843         set(handles.ref_j,'Visible','Off')
    0844     end
    0845 elseif isequal(mode,'displacement')%the pairs have the same indices
    0846      displ_num(1,1)=0;
    0847      displ_num(2,1)=0;
    0848      displ_num(3,1)=0;
    0849      displ_num(4,1)=0;
    0850      if nbfield > 1
    0851         set(handles.itext,'Visible','On')
    0852         set(handles.first_i,'Visible','On')
    0853         set(handles.last_i,'Visible','On')
    0854         set(handles.incr_i,'Visible','On')
    0855         set(handles.nb_field,'Visible','On')
    0856         set(handles.ref_i,'Visible','On')
    0857     else
    0858         set(handles.itext,'Visible','Off')
    0859         set(handles.first_i,'Visible','Off')
    0860         set(handles.last_i,'Visible','Off')
    0861         set(handles.incr_i,'Visible','Off')
    0862         set(handles.nb_field,'Visible','Off')
    0863         set(handles.ref_i,'Visible','Off')
    0864     end
    0865     if nbfield2 > 1
    0866       set(handles.jtext,'Visible','On')
    0867      set(handles.first_j,'Visible','On')
    0868      set(handles.last_j,'Visible','On')
    0869      set(handles.incr_j,'Visible','On')
    0870      set(handles.nb_field2,'Visible','On')
    0871      set(handles.ref_j,'Visible','On')
    0872     else
    0873         set(handles.jtext,'Visible','Off')
    0874         set(handles.first_j,'Visible','Off')
    0875         set(handles.last_j,'Visible','Off')
    0876         set(handles.incr_j,'Visible','Off')
    0877         set(handles.nb_field2,'Visible','Off')
    0878         set(handles.ref_j,'Visible','Off')
    0879     end
    0880 end
    0881 set(handles.list_pair_civ1,'UserData',displ_num);
    0882 find_netcpair_civ1(hObject, eventdata, handles)
    0883 find_netcpair_civ2(hObject, eventdata, handles)
    0884
    0885 %--------------------------------------------------------------
    0886 % determine the menu for civ1 pairs depending on existing netcdf file at the middle of
    0887 % the field series set by first_i, incr, last_i
    0888 %----------------------------------------------------------------
    0889 function find_netcpair_civ1(hObject, eventdata, handles)
    0890 set(gcf,'Pointer','watch')
    0891 %nomenclature types
    0892 filebase=get(handles.displ_filebase,'String');
    0893 [filepath,Nme,ext_dir]=fileparts(filebase);
    0894 browse=get(handles.browse_root,'UserData');
    0895 mode_list=get(handles.mode,'String');
    0896 mode_value=get(handles.mode,'Value');
    0897 mode=mode_list{mode_value};
    0898 % nomenclature type of the .nc files
    0899 nom_type_ima=[];%default
    0900 if isfield(browse,'nom_type_ima')
    0901     nom_type_ima=browse.nom_type_ima;
    0902 end
    0903
    0904 %determine nom_type_nc:
    0905 nom_type_nc=[];%default
    0906 if isfield(browse,'nom_type_nc')
    0907     nom_type_nc=browse.nom_type_nc;
    0908 end
    0909 if isequal(nom_type_ima,'png_old') | isequal(nom_type_nc,'netc_old')| isequal(nom_type_ima,'raw_SMD')
    0910     nom_type_nc='netc_old';%nom_type for the netcdf files
    0911 elseif isequal(nom_type_ima,'none')|isequal(nom_type_nc,'none')
    0912     nom_type_nc='none';
    0913 elseif isequal(nom_type_ima,'avi')|isequal(nom_type_ima,'_i')|isequal(nom_type_ima,'ima_num')|...
    0914         isequal(nom_type_nc,'_i1-i2')
    0915      nom_type_nc='_i1-i2';
    0916 elseif isequal(nom_type_ima,'_i_j1-j2')||isequal(nom_type_nc,'_i1-i2_j1-j2')
    0917      nom_type_nc='_i1-i2_j1-j2';
    0918 else
    0919     if  isequal(mode,'series(Di)')|isequal(mode,'st_series(Di)')
    0920         nom_type_nc='_i1-i2_j'; % PIV in volume
    0921     else
    0922         nom_type_nc='_i_j1-j2';
    0923     end
    0924 end
    0925 browse.nom_type_nc=nom_type_nc;
    0926 set(handles.browse_root,'UserData',browse)
    0927
    0928 %reads .nc subdirectoy and image numbers from the interface
    0929 subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
    0930 first_i=str2num(get(handles.first_i,'String'));
    0931 last_i=str2num(get(handles.last_i,'String'));
    0932 incr=str2num(get(handles.incr_i,'String'));
    0933 num1=first_i:incr:last_i;
    0934 if isempty(num1)
    0935     set(handles.list_pair_civ1,'String',{''});
    0936     return
    0937 end
    0938 ref_i=str2num(get(handles.ref_i,'String'));
    0939 if isequal(mode,'pair j1-j2')|isequal(mode,'st_pair j1-j2')
    0940     ref_j=0;
    0941 else
    0942     ref_j=str2num(get(handles.ref_j,'String'));
    0943 end
    0944 if isequal(get(handles.dt_text,'String'),'dt(ms)=')%simple series(Di) with equal interval
    0945     ref_i=floor((first_i+last_i)/2);
    0946     ref_j=1;
    0947 end
    0948 time=get(handles.displ_filebase,'UserData');%get the set of times
    0949 if isempty(time)
    0950     time=[0 1];
    0951 end
    0952 dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
    0953 displ_num=get(handles.list_pair_civ1,'UserData');
    0954
    0955 %eliminate the first pairs inconsistent with the position
    0956 if isempty(displ_num)
    0957     nbpair=0;
    0958 else
    0959     nbpair=length(displ_num(1,:));%nbre of displayed pairs
    0960     if  isequal(mode,'series(Di)')  | isequal(mode,'st_series(Di)')
    0961         nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
    0962     elseif  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
    0963         nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
    0964     end
    0965 end
    0966 nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
    0967
    0968 %look for existing processed pairs involving the field at the middle of the series if civ1 will not
    0969 % be performed, while the result is needed for next steps.
    0970 displ_pair={''};
    0971 select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
    0972 testpair=0;
    0973 if get(handles.CIV1,'Value')==0 %
    0974     dirname=fullfile(filepath,subdir_civ1,ext_dir);
    0975     if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
    0976          hwarn=warndlg_uvmat(['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist'],'ERROR');
    0977          set(handles.list_pair_civ1,'String',{});
    0978          return
    0979     end
    0980     for ipair=1:nbpair
    0981         [filename,select(ipair)]=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
    0982         ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
    0983     end
    0984     if ~exist('select','var') | isequal(select,zeros(size(1:nbpair)))
    0985         if isfield(browse,'incr_pair')
    0986             num_i1=ref_i-floor(browse.incr_pair(1)/2);
    0987             num_i2=ref_i+ceil(browse.incr_pair(1)/2);
    0988             num_j1=ref_j-floor(browse.incr_pair(2)/2);
    0989             num_j2=ref_j+ceil(browse.incr_pair(2)/2);
    0990             [filename,select(1)]=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
    0991             testpair=1;
    0992         else
    0993             if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
    0994                 hwarn=warndlg_uvmat(['no civ1 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ1],'ERROR');
    0995                 set(hwarn,'WindowStyle','modal');
    0996             else
    0997                 hwarn=warndlg_uvmat(['no civ1 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ1],'ERROR');
    0998                 set(hwarn,'WindowStyle','modal');
    0999             end
    1000              set(handles.list_pair_civ1,'String',{''});
    1001              %COMPLETER CAS STEREO
    1002             return
    1003         end
    1004     end
    1005 end
    1006 if isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
    1007     if testpair
    1008               displ_pair{1}=['Di= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
    1009     elseif ~isequal(get(handles.dt_text,'String'),'dt(ms)=')
    1010        for ipair=1:nbpair
    1011           if select(ipair)
    1012               dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
    1013               displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
    1014           else
    1015              displ_pair{ipair}='...'; %pair not displayed in the menu
    1016           end
    1017        end
    1018     else
    1019        for ipair=1:nbpair
    1020          if select(ipair)
    1021             displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt_unit*ipair)];
    1022          else
    1023             displ_pair{ipair}='...'; %pair not displayed in the menu
    1024          end
    1025        end
    1026     end
    1027 elseif isequal(mode,'series(Dj)')|isequal(mode,'st_series(Dj)')% series on the j index
    1028     if testpair
    1029          displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(1)/2)) '|' num2str(ceil(browse.incr_pair(1)/2))];
    1030     else
    1031        for ipair=1:nbpair
    1032           if select(ipair)
    1033               dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
    1034               displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
    1035            elseif testpair
    1036               displ_pair{1}=['Dj= ' num2str(-floor(browse.incr_pair(2)/2)) '|' num2str(ceil(browse.incr_pair(2)/2))];
    1037           else
    1038              displ_pair{ipair}='...'; %pair not displayed in the menu
    1039           end
    1040        end
    1041    end
    1042 elseif isequal(mode,'pair j1-j2')|isequal(mode,'st_pair j1-j2')%case of pairs
    1043     for ipair=1:nbpair
    1044         if select(ipair)
    1045            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
    1046            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
    1047                         ' :dt= ' num2str(dt*1000)];
    1048        else
    1049           displ_pair{ipair}='...'; %pair not displayed in the menu
    1050         end
    1051    end
    1052 elseif isequal(mode,'displacement')
    1053     displ_pair={'Di=Dj=0'};
    1054 end
    1055 set(handles.list_pair_civ1,'String',displ_pair');
    1056 ichoice=min(find(select));
    1057 if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
    1058 initial=get(handles.list_pair_civ1,'Value');
    1059 if initial>nbpair |~isequal(select(initial),1)
    1060     set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
    1061 end
    1062 set(handles.list_pair_civ2,'String',displ_pair');
    1063 initial=get(handles.list_pair_civ2,'Value');
    1064 if initial>nbpair |~isequal(select(initial),1)
    1065     set(handles.list_pair_civ2,'Value',ichoice);% same pair proposed by default for civ2
    1066 end
    1067 set(gcf,'Pointer','arrow')
    1068 %--------------------------------------------------------------
    1069 % determine the menu for civ2 pairs depending on the existing netcdf file at the
    1070 %middle of the series set by first_i, incr, last_i
    1071 %--------------------------------------------------------------
    1072 function find_netcpair_civ2(hObject, eventdata, handles)
    1073 set(gcf,'Pointer','watch')
    1074 %nomenclature types
    1075 filebase=get(handles.displ_filebase,'String');
    1076 [filepath,Nme,ext_dir]=fileparts(filebase);
    1077 browse=get(handles.browse_root,'UserData');
    1078 mode_list=get(handles.mode,'String');
    1079 mode_value=get(handles.mode,'Value');
    1080 mode=mode_list{mode_value};
    1081
    1082 % nomenclature type of the .nc files
    1083 nom_type_ima='ima_num';%default
    1084 if isfield(browse,'nom_type_ima')
    1085     nom_type_ima=browse.nom_type_ima;
    1086 end
    1087 nom_type_nc='_i1-i2';%default
    1088 if isfield(browse,'nom_type_nc')
    1089     nom_type_nc=browse.nom_type_nc;
    1090 end
    1091 if isequal(nom_type_ima,'png_old') | isequal(nom_type_ima,'netc_old')| isequal(nom_type_ima,'raw_SMD')| isequal(nom_type_nc,'netc_old')
    1092     nom_type_nc='netc_old';%nom_type for the netcdf files
    1093 elseif isequal(nom_type_ima,'none')|isequal(nom_type_nc,'none')
    1094     nom_type_nc='none';
    1095 elseif isequal(nom_type_ima,'avi')|isequal(nom_type_ima,'_i')|isequal(nom_type_ima,'ima_num')|isequal(nom_type_nc,'_i1-i2')
    1096      nom_type_nc='_i1-i2';
    1097 else
    1098     if  isequal(mode,'series(Di)')|isequal(mode,'st_series(Di)')
    1099         nom_type_nc='_i1-i2_j'; % PIV in volume
    1100     else
    1101         nom_type_nc='_i_j1-j2';
    1102     end
    1103 end
    1104 browse.nom_type_nc=nom_type_nc;
    1105 set(handles.browse_root,'UserData',browse)
    1106
    1107 %reads .nc subdirectory and image numbers from the interface
    1108 subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
    1109 subdir_civ2=get(handles.subdir_civ2,'String');%subdirectory subdir_civ2 for the netcdf data
    1110 first_i=str2num(get(handles.first_i,'String'));
    1111 last_i=str2num(get(handles.last_i,'String'));
    1112 incr=str2num(get(handles.incr_i,'String'));
    1113 num1=first_i:incr:last_i;
    1114 if isempty(num1)
    1115     set(handles.list_pair_civ2,'String',{});
    1116     return
    1117 end
    1118 ref_i=str2num(get(handles.ref_i,'String'));
    1119 if isequal(mode,'pair j1-j2')|isequal(mode,'st_pair j1-j2')
    1120     ref_j=0;
    1121 else
    1122     ref_j=str2num(get(handles.ref_j,'String'));
    1123 end
    1124 if isequal(get(handles.dt_text,'String'),'dt(ms)=')%simple series(Di) with equal interval
    1125     ref_i=ceil((first_i+last_i)/2);
    1126     ref_j=1;
    1127 end
    1128 %     ref_i=browse.num_ref;%field number initially selected by the browser
    1129 time=get(handles.displ_filebase,'UserData'); %get the set of times
    1130 if isempty(time)
    1131     time=[0 1];%default
    1132 end
    1133 dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
    1134 displ_num=get(handles.list_pair_civ1,'UserData');
    1135
    1136
    1137 %eliminate the first pairs inconsistent with the position
    1138 if isempty(displ_num)
    1139     nbpair=0;
    1140 else
    1141     nbpair=length(displ_num(1,:));%nbre of displayed pairs
    1142     if  isequal(mode,'series(Di)') | isequal(mode,'st_series(Di)')
    1143         nbpair=min(2*ref_i-1,nbpair);%limit the number of pairs with positive first index
    1144     elseif  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
    1145         nbpair=min(2*ref_j-1,nbpair);%limit the number of pairs with positive first index
    1146     end
    1147 end
    1148 nbpair=min(200,nbpair);%limit the number of displayed pairs to 200
    1149
    1150 %look for existing processed pairs involving the field at the middle of the series if civ1 will not
    1151 % be performed, while the result is needed for next steps.
    1152 displ_pair={''}; %default
    1153 select=ones(size(1:nbpair));%default =1 for nubers of displayed pairs
    1154 if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0%&...
    1155     if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
    1156          errordlg(['no civ2 file available: subdirectory ' subdir_civ2 ' does not exist'])
    1157          set(handles.list_pair_civ2,'String',{});
    1158          return
    1159     end
    1160     for ipair=1:nbpair
    1161         [filename,select(ipair)]=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
    1162         ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
    1163     end
    1164     if  isequal(select,zeros(size(1:nbpair)))
    1165         if isfield(browse,'incr_pair')
    1166             num_i1=ref_i-floor(browse.incr_pair(1)/2);
    1167             num_i2=ref_i+floor((browse.incr_pair(1)+1)/2);
    1168             num_j1=ref_j-floor(browse.incr_pair(2)/2);
    1169             num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
    1170             [filename,select(1)]=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
    1171         else
    1172             if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
    1173                 errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
    1174             else
    1175                 errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
    1176             end
    1177              set(handles.list_pair_civ2,'String',{});
    1178             return
    1179         end
    1180     end
    1181 end
    1182 if isequal(mode,'series(Di)')  | isequal(mode,'st_series(Di)')
    1183     if  ~isequal(get(handles.dt_text,'String'),'dt(ms)=')
    1184        for ipair=1:nbpair
    1185           if select(ipair)
    1186               dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
    1187               displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
    1188           else
    1189              displ_pair{ipair}='...'; %pair not displayed in the menu
    1190           end
    1191        end
    1192    else
    1193        for ipair=1:nbpair
    1194          if select(ipair)
    1195             displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt_unit*ipair)];
    1196          else
    1197             displ_pair{ipair}='...'; %pair not displayed in the menu
    1198          end
    1199        end
    1200     end
    1201 elseif isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)') % series on the j index
    1202        for ipair=1:nbpair
    1203           if select(ipair)
    1204               dt=time(ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair));%time interval dt
    1205               displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ' :dt= ' num2str(dt*1000)];
    1206           else
    1207              displ_pair{ipair}='...'; %pair not displayed in the menu
    1208           end
    1209        end
    1210 elseif isequal(mode,'pair j1-j2') | isequal(mode,'st_pair j1-j2') %case of pairs
    1211     for ipair=1:nbpair
    1212         if select(ipair)
    1213            dt=time(ref_i+displ_num(4,ipair),displ_num(2,ipair))-time(ref_i+displ_num(3,ipair),displ_num(1,ipair));%time interval dt
    1214            displ_pair{ipair}=['j= ' num2stra(displ_num(1,ipair),nom_type_ima) '-' num2stra(displ_num(2,ipair),nom_type_ima) ...
    1215                         ' :dt= ' num2str(dt*1000)];
    1216        else
    1217           displ_pair{ipair}='...'; %pair not displayed in the menu
    1218        end
    1219    end
    1220 elseif isequal(mode,'displacement')
    1221     displ_pair={'Di=Dj=0'};
    1222 end
    1223 set(handles.list_pair_civ2,'String',displ_pair');
    1224 ichoice=min(find(select));
    1225 if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
    1226 if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
    1227     set(handles.list_pair_civ2,'Value',ichoice);% first valid pair proposed by default in the menu
    1228 end
    1229 set(gcf,'Pointer','arrow')
    1230 %----------------------------------------------------
    1231 %  determine the list of index pairs of processing file
    1232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1233 function [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
    1234     find_pair_indices(handles,mode)
    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 first_j=str2num(get(handles.first_j,'String'));
    1239 last_j=str2num(get(handles.last_j,'String'));
    1240 incr_j=str2num(get(handles.incr_j,'String'));
    1241 list_civ1=get(handles.list_pair_civ1,'String');
    1242 index_civ1=get(handles.list_pair_civ1,'Value');
    1243 str_civ1=list_civ1{index_civ1};
    1244 list_civ2=get(handles.list_pair_civ2,'String');
    1245 index_civ2=get(handles.list_pair_civ2,'Value');
    1246 str_civ2=list_civ2{index_civ2};
    1247 if isequal(first_i,[])|isequal(first_j,[]), errordlg('first field number not defined'),...
    1248     set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
    1249 if isequal(last_i,[])| isequal(last_j,[]),errordlg('last field number not defined'),...
    1250     set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
    1251 if isequal(incr,[])| isequal(incr_j,[]),errordlg('increment in field number not defined'),...
    1252     set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
    1253 if last_i < first_i | last_j < first_j , errordlg('last field number must be larger than the first one'),...
    1254     set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
    1255 num1=[first_i:incr:last_i];
    1256 num_j=[first_j:incr_j:last_j];
    1257 if isequal (mode,'series(Di)') |isequal(mode,'st_series(Di)')
    1258      %recognize the pair civ1 from the display
    1259     indsel=find((double(str_civ1)<48)|(double(str_civ1)>57));% character indices of non numerical characters
    1260     str_raw=str_civ1(indsel);
    1261     indsepar=find(str_raw=='|'); %character index of the separator
    1262     d1=str2num(str_civ1([indsel(indsepar-1)+1:indsel(indsepar)-1]));
    1263     if indsepar==length(str_raw)
    1264         d2=str2num(str_civ1([indsel(indsepar)+1:end]));
    1265     else
    1266         d2=str2num(str_civ1([indsel(indsepar)+1:indsel(indsepar+1)-1]));
    1267     end
    1268     %recognize the pair civ2 from the display
    1269     num1_civ1=num1-d1;% set of first image numbers
    1270     num2_civ1=num1+d2;
    1271     num_a_civ1=num_j;
    1272     num_b_civ1=num_j;
    1273     num1_civ2=num1-floor(index_civ2/2)*ones(size(num1));% set of first image numbers
    1274     num2_civ2=num1+ceil(index_civ2/2)*ones(size(num1));
    1275     num1_civ2=num1-d1;% set of first image numbers
    1276     num2_civ2=num1+d2;
    1277     num_a_civ2=num_j;
    1278     num_b_civ2=num_j;
    1279     % adjust the first and last field number
    1280     lastfield=str2num(get(handles.nb_field,'String'));
    1281     if isequal(lastfield,[])
    1282         indsel=find((num1_civ1 >= 1)&(num1_civ2 >= 1));
    1283     else
    1284         indsel=find((num2_civ1 <= lastfield)&(num2_civ2 <= lastfield)&(num1_civ1 >= 1)&(num1_civ2 >= 1));
    1285     end
    1286     if length(indsel)>=1
    1287         firstind=indsel(1);
    1288         lastind=indsel(end);
    1289         set(handles.first_i,'String',num2str(num1(firstind)))%update the display of first and last fields
    1290         set(handles.last_i,'String',num2str(num1(lastind)))
    1291         num1=num1(indsel);
    1292         num1_civ1=num1_civ1(indsel);
    1293         num1_civ2=num1_civ2(indsel);
    1294         num2_civ1=num2_civ1(indsel);
    1295         num2_civ2=num2_civ2(indsel);
    1296     end
    1297 elseif isequal (mode,'series(Dj)')|isequal (mode,'st_series(Dj)')
    1298     lastfield_j=str2num(get(handles.nb_field2,'String'));
    1299     num1_civ1=num1;% set of first image numbers
    1300     num2_civ1=num1;
    1301     num_a_civ1=num_j-floor(index_civ1/2)*ones(size(num_j));
    1302     num_b_civ1=num_j+ceil(index_civ1/2)*ones(size(num_j));
    1303     num1_civ2=num1;
    1304     num2_civ2=num1;
    1305     num_a_civ2=num_j-floor(index_civ2/2)*ones(size(num_j));
    1306     num_b_civ2=num_j+ceil(index_civ2/2)*ones(size(num_j));
    1307     % adjust the first and last field number
    1308     if isequal(lastfield_j,[])
    1309         indsel=find((num_a_civ1 >= 1)&(num_a_civ2 >= 1));
    1310     else
    1311         indsel=find((num_b_civ1 <= lastfield_j)&(num_b_civ2 <= lastfield_j)&(num_a_civ1 >= 1)&(num_a_civ2 >= 1));
    1312     end
    1313     if length(indsel)>=1
    1314         firstind=indsel(1);
    1315         lastind=indsel(end);
    1316         set(handles.first_j,'String',num2str(num_j(firstind)))%update the display of first and last fields
    1317         set(handles.last_j,'String',num2str(num_j(lastind)))
    1318         num_j=num_j(indsel);
    1319         num_a_civ1=num_a_civ1(indsel);
    1320         num_a_civ2=num_a_civ2(indsel);
    1321         num_b_civ1=num_b_civ1(indsel);
    1322         num_b_civ2=num_b_civ2(indsel);
    1323     end
    1324 elseif isequal(mode,'pair j1-j2') | isequal(mode,'st_pair j1-j2') %case of bursts (png_old or png_2D)
    1325     num1_civ1=num1;
    1326     num1_civ2=num1;
    1327     displ_num=get(handles.list_pair_civ1,'UserData');
    1328     num2_civ1=num1;
    1329     num_a_civ1=displ_num(1,index_civ1);
    1330     num_b_civ1=displ_num(2,index_civ1);
    1331     num2_civ2=num1;
    1332     num_a_civ2=displ_num(1,index_civ2);
    1333     num_b_civ2=displ_num(2,index_civ2);
    1334 elseif isequal(mode,'displacement')
    1335     num1_civ1=num1;
    1336     num2_civ1=num1;
    1337     num_a_civ1=num_j;
    1338     num_b_civ1=num_j;
    1339     num1_civ2=num1;
    1340     num2_civ2=num1;
    1341     num_a_civ2=num_j;
    1342     num_b_civ2=num_j;
    1343 end
    1344
    1345
    1346 %-------------------------------------------------------------
    1347 % --- Executes on selection change in list_pair_civ1.
    1348 function list_pair_civ1_Callback(hObject, eventdata, handles)
    1349 %------------------------------------------------------------
    1350 %reproduce by default the chosen pair in the civ2 menu
    1351 list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
    1352 index_pair=get(handles.list_pair_civ1,'Value');
    1353 displ_num=get(handles.list_pair_civ1,'UserData');
    1354 num_a=displ_num(1,index_pair);
    1355 num_b=displ_num(2,index_pair);
    1356 set(handles.list_pair_civ2,'Value',index_pair);
    1357
    1358 %update first_i and last_i according to the chosen image pairs
    1359 mode_list=get(handles.mode,'String');
    1360 mode_value=get(handles.mode,'Value');
    1361 mode=mode_list{mode_value};
    1362 if isequal(mode,'series(Di)')
    1363     first_i=str2num(get(handles.first_i,'String'));
    1364     last_i=str2num(get(handles.last_i,'String'));
    1365     incr_i=str2num(get(handles.incr_i,'String'));
    1366     num1=first_i:incr_i:last_i;
    1367     lastfield=str2num(get(handles.nb_field,'String'));
    1368     if ~isequal(lastfield,[])
    1369         ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
    1370              (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
    1371         num1=num1(ind);
    1372     end
    1373     set(handles.first_i,'String',num2str(num1(1)));
    1374     set(handles.last_i,'String',num2str(num1(end)));
    1375 elseif isequal(mode,'series(Dj)')
    1376     first_j=str2num(get(handles.first_j,'String'));
    1377     last_j=str2num(get(handles.last_j,'String'));
    1378     incr_j=str2num(get(handles.incr_j,'String'));
    1379     num_j=first_j:incr_j:last_j;
    1380     lastfield2=str2num(get(handles.nb_field2,'String'));
    1381     if ~isequal(lastfield2,[])
    1382         ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
    1383              (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
    1384         num1=num_j(ind);
    1385     end
    1386     set(handles.first_j,'String',num2str(num1(1)));
    1387     set(handles.last_j,'String',num2str(num1(end)));
    1388 end
    1389
    1390 %------------------------------------------------------------------
    1391 % --- Executes on selection change in list_pair_civ2.
    1392 function list_pair_civ2_Callback(hObject, eventdata, handles)
    1393
    1394 index_pair=get(handles.list_pair_civ2,'Value');%get the selected position index in the menu
    1395
    1396 %update first_i and last_i according to the chosen image pairs
    1397 mode_list=get(handles.mode,'String');
    1398 mode_value=get(handles.mode,'Value');
    1399 mode=mode_list{mode_value};
    1400 if isequal(mode,'series(Di)')
    1401     first_i=str2num(get(handles.first_i,'String'));
    1402     last_i=str2num(get(handles.last_i,'String'));
    1403     incr_i=str2num(get(handles.incr_i,'String'));
    1404     num1=first_i:incr_i:last_i;
    1405     lastfield=str2num(get(handles.nb_field,'String'));
    1406     if ~isequal(lastfield,[])
    1407         ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& ...
    1408              (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
    1409         num1=num1(ind);
    1410     end
    1411     set(handles.first_i,'String',num2str(num1(1)));
    1412     set(handles.last_i,'String',num2str(num1(end)));
    1413 elseif isequal(mode,'series(Dj)')
    1414     first_j=str2num(get(handles.first_j,'String'));
    1415     last_j=str2num(get(handles.last_j,'String'));
    1416     incr_j=str2num(get(handles.incr_j,'String'));
    1417     num_j=first_j:incr_j:last_j;
    1418     lastfield2=str2num(get(handles.nb_field2,'String'));
    1419     if ~isequal(lastfield2,[])
    1420         ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
    1421              (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield));
    1422         num1=num_j(ind);
    1423     end
    1424     set(handles.first_j,'String',num2str(num1(1)));
    1425     set(handles.last_j,'String',num2str(num1(end)));
    1426 end
    1427
    1428
    1429
    1430
    1431 %-----------------------------------------------------------
    1432 % --- Executes on button press in BATCH: remote processing
    1433 %-----------------------------------------------------------
    1434 function BATCH_Callback(hObject, eventdata, handles)
    1435 global civ1_exe civ2_exe patch_exe patch_new_exe fix_exe todo_path sge Civ_exe
    1436
    1437 pxcmx=get(handles.pxcmx,'String');
    1438 pxcmy=get(handles.pxcmy,'String');
    1439 npx=get(handles.pxcmx,'UserData');
    1440 npy=get(handles.pxcmy,'UserData');
    1441
    1442 %check the list of operations:
    1443 operations={'CIV1','FIX1','PATCH1','CIV2','FIX2','PATCH2'};
    1444 run_flag=1;
    1445 box_test(1)=get(handles.CIV1,'Value');
    1446 box_test(2)=get(handles.FIX1,'Value');
    1447 box_test(3)=get(handles.PATCH1,'Value');
    1448 box_test(4)=get(handles.CIV2,'Value');
    1449 box_test(5)=get(handles.FIX2,'Value');
    1450 box_test(6)=get(handles.PATCH2,'Value');
    1451 index=find(box_test==1);
    1452 if isempty(index)
    1453     errordlg('no selected operation')
    1454     set(handles.BATCH, 'Enable','On')
    1455     set(handles.BATCH,'BackgroundColor',[1 0 0])
    1456     return
    1457 end
    1458 index_first=min(index);
    1459 index_last=max(index);
    1460 box_used=box_test([index_first : index_last]);
    1461 [box_missing,ind_missing]=min(box_used);
    1462 if isequal(box_missing,0)
    1463     errordlg(['missing' cell2mat(operations(ind_missing))]);
    1464     set(handles.BATCH, 'Enable','On')
    1465     set(handles.BATCH,'BackgroundColor',[1 0 0])
    1466     return
    1467 end
    1468
    1469 %check mask if selecetd
    1470 if isequal(get(handles.get_mask_civ1,'Value'),1)
    1471      get_mask_civ1_Callback(hObject, eventdata, handles);
    1472 end
    1473 if isequal(get(handles.get_mask_fix1,'Value'),1)
    1474      get_mask_fix1_Callback(hObject, eventdata, handles);
    1475 end
    1476 if isequal(get(handles.get_mask_civ2,'Value'),1)
    1477      get_mask_civ2_Callback(hObject, eventdata, handles);
    1478 end
    1479 if isequal(get(handles.get_mask_fix2,'Value'),1)
    1480      get_mask_fix2_Callback(hObject, eventdata, handles);
    1481 end
    1482
    1483
    1484 %read names of the .exe file
    1485 path_uvmat=which('uvmat');% check the path detected for source file uvmat
    1486 path_UVMAT=fileparts(path_uvmat); %path to UVMAT
    1487 if isunix
    1488     %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ_3D binary names
    1489     xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml');
    1490     if exist(xmlfile,'file')
    1491         t=xmltree(xmlfile);
    1492         sparam=convert(t);
    1493     end
    1494 else
    1495     %fid = fopen(fullfile(path_UVMAT,'PARAM_WIN.txt'),'r');%open the file with civ_3D binary names
    1496     xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
    1497     if exist(xmlfile,'file')
    1498         t=xmltree(xmlfile);
    1499         sparam=convert(t);
    1500     end
    1501 end
    1502  sge=0;
    1503 if isfield(sparam,'Civ_exe')
    1504     Civ_exe=sparam.Civ_exe
    1505 end
    1506 if isfield(sparam,'Civ1_exe')
    1507     civ1_exe=sparam.Civ1_exe
    1508 end
    1509 if isfield(sparam,'Civ2_exe')
    1510     civ2_exe=sparam.Civ2_exe
    1511 end
    1512 if isfield(sparam,'Patch_exe')
    1513     patch_exe=sparam.Patch_exe
    1514 end
    1515 if isfield(sparam,'PatchNew_exe')
    1516     patch_new_exe=sparam.PatchNew_exe
    1517 end
    1518 if isfield(sparam,'Fix_exe')
    1519     fix_exe=sparam.Fix_exe
    1520 end
    1521 if isfield(sparam,'Todo_path')
    1522     todo_path=sparam.Todo_path
    1523 end
    1524 if isfield(sparam,'SGE')
    1525     sge=str2num(sparam.SGE)
    1526 end
    1527 %choice of batch priority
    1528 ind_answer=2;
    1529 if sge
    1530     [s,w]=unix('qstat -q civ_3D.q|grep job_| wc -l'); %check the waiting list (command unix)
    1531     if isequal(s,0)
    1532         w(end)=[];
    1533         str_displ={[w ' jobs in the waiting list'];'Select a priority:'};
    1534         str={'urgent';'normal';'low'};
    1535         [ind_answer,v] = listdlg('PromptString',str_displ,...
    1536                 'SelectionMode','single',...
    1537                 'ListString',str,'ListSize',[200 200],'Name','job priority','InitialValue',3);
    1538         if isequal(v,0) % to handle Cancel button and figure close,
    1539            return % a better way should be create
    1540         end
    1541     else
    1542         warndlg_uvmat('batch system not available','ERROR')
    1543         return
    1544     end
    1545 end
    1546 %initialize the waitbars
    1547 set(handles.waitbar_1,'Position',[0.946 0.876 0.03 0.001])
    1548 set(handles.waitbar_patch1,'Position',[0.946 0.439 0.03 0.001])
    1549 set(handles.waitbar_civ2,'Position',[0.946 0.219 0.03 0.001])
    1550 set(handles.waitbar_patch2,'Position',[0.946 0.0 0.03 0.001])
    1551 set(handles.BATCH, 'Enable','Off')
    1552 set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
    1553
    1554 %get the filename root, nomenclature and numbers
    1555 filebase=get(handles.displ_filebase,'String');
    1556 % for Windows system find the UBC path name if needed
    1557 if ~isunix & isequal(todo_path(1:2),'\\') & isequal(filebase(2:3),':\')
    1558     cur_dir=pwd;
    1559     if ~isequal(cur_dir(2:3),':\')
    1560         cd(matlabroot); %move to the Matlab root directory if the current Matlab dir does not allow the dos command or is M:
    1561     end
    1562     [ss,ww]=dos(['net use ' filebase(1:2)]);
    1563     if isequal(ss,0)
    1564         rankpath=findstr(ww,'\\');
    1565         if ~isempty(rankpath)
    1566             wwrest=ww(rankpath:end);
    1567             rankend=min(find(double(wwrest)==10))-1;
    1568             filebase=[wwrest(1:rankend) filebase(3:end)];
    1569             set(handles.displ_filebase,'String',filebase);
    1570         end
    1571     else
    1572          warndlg_uvmat('for BATCH option, UBC file names, beginning by \\, are needed','ERROR');
    1573          set(handles.BATCH, 'Enable','On')
    1574          set(handles.BATCH,'BackgroundColor',[1 0 0])
    1575          return
    1576     end
    1577 end
    1578 browse=get(handles.browse_root,'UserData')
    1579 ext_ima=browse.ext_ima;
    1580 nom_type_nc='_i1-i2';
    1581 nom_type_ima=browse.nom_type_ima;
    1582 % nom_type_nc=browse.nom_type_nc;
    1583 % if isequal(nom_type_ima2,[]),nom_type_ima2='ima_num';end; %default
    1584 % if isequal(nom_type_nc,[]),nom_type_nc='_i1-i2';end; %default
    1585 mode_list=get(handles.mode,'String');
    1586 mode_value=get(handles.mode,'Value');
    1587 mode=mode_list{mode_value};
    1588 time=get(handles.displ_filebase,'UserData'); %get the set of times
    1589
    1590 [num1_civ1,num2_civ1,num_a_civ1,num_b_civ1,num1_civ2,num2_civ2,num_a_civ2,num_b_civ2]=...
    1591 find_pair_indices(handles,mode); %determine the pairs of processing file
    1592
    1593 %check dir
    1594 subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf output data
    1595 subdir_civ2=get(handles.subdir_civ2,'String');
    1596 if isequal(subdir_civ1,''),subdir_civ1='A'; end% put default subdir
    1597 if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
    1598 currentdir=pwd;%store the current working directory
    1599 [Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ_3D)
    1600 if ~exist(Path_ima,'dir')
    1601     warndlg_uvmat(['path to images ' Path_ima ' not found'],'ERROR')
    1602     return
    1603 end
    1604 cd(Path_ima);%move to the directory of the images
    1605 dircur=pwd; %current working directory
    1606 m2='';
    1607 [erread,message]=fileattrib(Path_ima);
    1608 if ~isempty(message) & ~isequal(message.UserWrite,1)
    1609       errordlg(['No writting access to ' Path_ima])
    1610       cd(currentdir)
    1611       return
    1612 end
    1613
    1614 %test for reference file in fix
    1615 ref_fix1=get(handles.ref_fix1,'UserData');
    1616 ref_fix2=get(handles.ref_fix2,'UserData');
    1617 if (~isempty(ref_fix1) & box_test(2)==1)|(~isempty(ref_fix2) & box_test(5)==1)
    1618     errordlg('reference file not implemented in BATCH mode, use RUN')
    1619     set(handles.BATCH, 'Enable','On')
    1620     set(handles.BATCH,'BackgroundColor',[1 0 0])
    1621     return
    1622 end
    1623 nbfield=length(num1_civ1);
    1624 nbslice=length(num_a_civ1);
    1625
    1626 %check the existence of the netcdf and image files involved
    1627 % if box_test(1)==1;%CIV1 activated
    1628 detect=1;
    1629 while detect==1 %name a new subdir if one of the netcdf files already exists
    1630       for ifile=1:nbfield
    1631 %           for j=1:nbslice
    1632               [filename,detect]=name_generator(filebase,num1_civ1(ifile),[],'.nc',...
    1633                 nom_type_nc,1,num2_civ1(ifile),[],subdir_civ1);%
    1634               if detect==1% if a netcdf file already exists
    1635                  subdir_civ1=[subdir_civ1 '.0'];
    1636                  subdir_civ2=subdir_civ1;
    1637                  break
    1638               end
    1639               filecell_nc1(ifile)={filename};
    1640           if detect==1% if a netcdf file already exists
    1641               break
    1642           end
    1643       end
    1644        %create the new subdir_civ1 if it does not exist
    1645       if ~exist(fullfile(Path_ima,subdir_civ1),'dir')
    1646           [m1,m2,m3]=mkdir(subdir_civ1)
    1647            if ~isequal(m2,'')
    1648                msgbox(m2);%error message for directory creation
    1649           end
    1650      end
    1651 end
    1652 %get image names
    1653 for ifile=1:nbfield
    1654     [filecell_ima1_civ1{ifile},idetect]=name_generator(filebase, num1_civ1(ifile),[],ext_ima,nom_type_ima);%first image
    1655     [filecell_ima2_civ1{ifile},idetect_1]=name_generator(filebase, num2_civ1(ifile),[],ext_ima,nom_type_ima); %second image
    1656      if idetect==0
    1657             warndlg_uvmat([filecell_ima1_civ1{ifile} ' not found'],'ERROR')
    1658             set(handles.BATCH, 'Enable','On')
    1659             set(handles.BATCH,'BackgroundColor',[1 0 0])
    1660             cd(currentdir)
    1661             return
    1662      end
    1663      if idetect_1==0,
    1664             errordlg([filecell_ima2_civ1{ifile} ' not found'])
    1665             set(handles.BATCH, 'Enable','On')
    1666             set(handles.BATCH,'BackgroundColor',[1 0 0])
    1667             cd(currentdir)
    1668             return
    1669      end
    1670 end
    1671
    1672 cd(currentdir);%come back to the initial working directory
    1673 % if ~isequal(m2,'')
    1674 %      msgbox(m2);%error message for directory creation
    1675 % end
    1676 set(handles.subdir_civ1,'String',subdir_civ1);%update the edit box
    1677 set(handles.subdir_civ2,'String',subdir_civ2);%update the edit box
    1678 browse.nom_type_nc=nom_type_nc;
    1679 set(handles.browse_root,'UserData',browse);%update the nomenclature type for uvmat
    1680
    1681 %COPY IMAGES TO THE FORMAT .vol IF NEEDED
    1682 if isequal(nom_type_ima,'avi')
    1683     nom_type_imanew='_i';
    1684 else
    1685     nom_type_imanew=nom_type_ima;
    1686 end
    1687
    1688 if ~isequal(ext_ima,'.vol')
    1689     if box_test(1)==1 %if civ1 is performed
    1690        h = waitbar(0,['copy images to the .png format for civ1']);% display a wait bar
    1691        for ifile=1:nbfield
    1692             waitbar(ifile/nbfield);
    1693             Atot=[];
    1694             [filename_A,idetect_cur]=name_generator(filebase,num1_civ1(ifile),1,'.png','_i');%A VOIR
    1695             for j=1:nbslice
    1696                     if idetect_cur==0
    1697                         A=read_image(cell2mat(filecell_ima1_civ1(ifile,j)),nom_type_ima2,npx,npy,num1_civ1(ifile));
    1698                         Atot=[Atot;A];
    1699                         %imwrite(A,filename,'BitDepth',16);
    1700                     end
    1701             end
    1702             imwrite(Atot,filename_A,'BitDepth',16);
    1703                     %filecell_ima1_civ1(ifile,j)={filename};
    1704             Atot=[];
    1705             [filename_B,idetect_cur]=name_generator(filebase, num2_civ1(ifile),1,'.png','_i');
    1706             for j=1:nbslice
    1707                     if idetect_cur==0
    1708                         A=read_image(cell2mat(filecell_ima2_civ1(ifile,j)),nom_type_ima2,npx,npy,num2_civ1(ifile));
    1709                         Atot=[Atot;A];
    1710 %                         imwrite(A,filename,'BitDepth',16);
    1711                     end
    1712                     %filecell_ima2_civ1(ifile,j)={filename};
    1713             end
    1714             imwrite(Atot,filename_B,'BitDepth',16);
    1715         end
    1716         close(h)
    1717     end
    1718 end
    1719
    1720 if ~sge
    1721     %OPEN THE WAIT LIST FOR BATCH PROCESSES
    1722     name_lock=fullfile(todo_path,'lock'); %lock file
    1723     iwait=0;
    1724     while(exist(name_lock) & iwait<15)
    1725         pause(1); %wait 1 second
    1726         iwait=iwait+1;
    1727     end
    1728     if iwait==15
    1729         errordlg(['I''m tired to wait for the lock file, please delete it then click again on BATCH' name_lock ])
    1730         set(handles.BATCH, 'Enable','On')
    1731         set(handles.BATCH,'BackgroundColor',[1 0 0])
    1732         return
    1733     end
    1734     p0=fopen(name_lock,'w'); %create the file name_lock: prevents other users to interfere
    1735     name_todo=fullfile(todo_path,'TODO.txt');
    1736     p1=fopen(name_todo,'a');
    1737     if (p1<0)
    1738         errordlg(['error in opening ' name_todo])
    1739         set(handles.BATCH, 'Enable','On')
    1740         set(handles.BATCH,'BackgroundColor',[1 0 0])
    1741         return;
    1742     end
    1743 end
    1744
    1745 for ifile=1:nbfield
    1746     i_cmd=0;
    1747     cmd='';
    1748     if sge
    1749        cmd='#!/bin/bash';
    1750        cmd=char({cmd;'#$ -cwd'});
    1751        cmd=char({cmd;'hostname && date'});
    1752     end
    1753     filename_cmx=cell2mat(filecell_nc1(ifile));%output netcdf file
    1754     filename_cmx([end-1:end])='cm';%name of cmx file
    1755     filename_cmx=[filename_cmx 'x'];
    1756
    1757 %CIV1
    1758     if box_test(1)==1
    1759         %GET civ_3D PARAMETERS:
    1760         par_civ1=read_param_civ1(handles,cell2mat(filecell_ima1_civ1(1,1)));
    1761         p1text=[];
    1762         [par_civ1.path,resu_file,resu_ext]=fileparts(filecell_nc1{ifile});
    1763         par_civ1.volume1=filecell_ima1_civ1{ifile};
    1764         par_civ1.volume2=filecell_ima2_civ1{ifile}
    1765         par_civ1.nx=1024;
    1766         par_civ1.ny=1024;
    1767         par_civ1.nz=par_civ1.gridLimits_Zmax - par_civ1.gridLimits_Zmin;
    1768         'TEST'
    1769         par_civ1
    1770         % civAll=get(handles.Experimental,'Value'); % Boolean for new civ excution method
    1771         % if isequal(civAll,1)
    1772         civAllxml=struct2xml(par_civ1);% xml contents,  all parameters
    1773         civAllxml=set(civAllxml,1,'name','civ3d3c');
    1774     %    save(civAllxml)
    1775         par_civ1_3d_xml=fullfile(par_civ1.path,[resu_file '.xml']);%[par_civ1.path '/test_to_change.xml'];
    1776      pvalue=num2str((1-ind_answer)*500);
    1777         save(civAllxml,par_civ1_3d_xml);
    1778       if(isunix && sge)
    1779      ['echo /CIVX/bin/MPI/lam-7.1.3_g95/bin/mpirun C  /CIVX/bin/civ3d3c -p ' par_civ1_3d_xml '|qsub -p ' pvalue ' -q lam.q -pe lam_loose 16 -e ' par_civ1_3d_xml '.errors -o ' par_civ1_3d_xml '.log' ]
    1780      eval ( ['!echo /CIVX/bin/MPI/lam-7.1.3_g95/bin/mpirun C  /CIVX/bin/civ3d3c -p ' par_civ1_3d_xml '|qsub -p ' pvalue ' -q lam.q -pe lam_loose 16 -e ' par_civ1_3d_xml '.errors -o ' par_civ1_3d_xml '.log' ])
    1781       else
    1782          '3D mode is NOT supported without sge'
    1783       end
    1784      return
    1785         % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1786         %  fichier xml produit
    1787         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1788         % A CONTINUER
    1789         %civAllxml
    1790         civAllCmd=[];
    1791         civAllxml=set(civAllxml,1,'name','civ3d3c');
    1792         namelog=[filename_cmx([1:end-3]) 'log'];
    1793         %par_civ1.Dt=num2str(time(num2_civ1(ifile),num_b_civ1(j))-time(num1_civ1(ifile),num_a_civ1(1)));
    1794         %par_civ1.T0=num2str((time(num2_civ1(ifile),num_b_civ1(j))+time(num1_civ1(ifile),num_a_civ1(1)))/2);
    1795        % test_mask=get(handles.get_mask_civ1,'Value');
    1796         i_cmd=i_cmd+1;
    1797 %         if isequal(civAll,0)
    1798 %             cmd=char({cmd;BATCH_CIV1(filename_cmx([1:end-4]),namelog,par_civ1,handles)});
    1799 %         else
    1800              civAllCmd=[civAllCmd ' civ1 '];
    1801              str=BATCH_CIV1_Unified(filename_cmx([1:end-4]),namelog,par_civ1,handles);
    1802             fieldnames=fields(str);
    1803             [civAllxml,uid_civ1]=add(civAllxml,1,'element','civ1');
    1804             for ilist=1:length(fieldnames)
    1805               val=eval(['str.' fieldnames{ilist}]);
    1806               if ischar(val)
    1807                 [civAllxml,uid_t]=add(civAllxml,uid_civ1,'element',fieldnames{ilist});
    1808                 [civAllxml,uid_t2]=add(civAllxml,uid_t,'chardata',val);
    1809                end
    1810             end
    1811 %         end
    1812     end
    1813     if(isunix)
    1814         cmd=char({cmd ; ['cp -f ' filename_cmx '2 ' filename_cmx]; cmd_CIV2});
    1815     else
    1816         cmd=char({cmd ; ['copy /Y ' filename_cmx '2 ' filename_cmx]; cmd_CIV2});
    1817     end
    1818 end
    1819
    1820 %  if isequal(civAll,1)
    1821     save(civAllxml,[filename_cmx([1:end-4]) '.xml']);
    1822     cmd=char({cmd;[Civ_exe ' -f ' [filename_cmx([1:end-4]) '.xml'] ' ' civAllCmd]});
    1823
    1824      %save(civAllxml,'/tmp/test.xml');
    1825 %  end
    1826
    1827
    1828 % create the .bat file:
    1829 if sge
    1830         [Rootbat,Filebat,extbat]=fileparts(filename_cmx);
    1831         filename_bat=fullfile(Rootbat,['job_' Filebat extbat]);
    1832 else
    1833     filename_bat=filename_cmx;
    1834 end
    1835 filename_bat(end-2:end)='bat';
    1836
    1837 %     pbat=fopen(filename_bat,'w'); %create the file filename_bat
    1838 dlmwrite(filename_bat,cmd,'');%write commands in filename_bat
    1839 if sge
    1840     pvalue=num2str((1-ind_answer)*500);
    1841     namelog=[filename_bat '.patch.log'];
    1842     ['!qsub -p ' pvalue ' -q civ_3D.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat];
    1843     eval(  ['!qsub -p ' pvalue ' -q civ_3D.q -e ' filename_cmx(1:end-4) '.errors -o ' filename_cmx(1:end-4) '.log' ' ' filename_bat]);
    1844 else
    1845     if(isunix)
    1846       cmdtodo=['. ' filename_bat ];%removed for Mathieu tests %' && rm -f ' filename_bat] ;
    1847     else
    1848 %      cmdtodo=[filename_bat ' && del /F /Q ' filename_bat];
    1849        cmdtodo=[filename_bat];%removed for Mathieu tests %' && del /F /Q ' filename_bat' ;
    1850     end
    1851     count= fprintf(p1,'%s\n', cmdtodo);
    1852 end
    1853 if ~sge
    1854     fclose(p1);
    1855     fclose(p0);
    1856     delete(name_lock);
    1857 end
    1858 set(handles.BATCH, 'Enable','On')
    1859 set(handles.BATCH,'BackgroundColor',[1 0 0])
    1860 %save interface state
    1861 [Path,Name]=fileparts(filebase);
    1862 namefig=fullfile(Path,subdir_civ2,Name);
    1863 detect=1;
    1864 while detect==1
    1865     namefigfull=[namefig '.fig'];
    1866     hh=dir(namefigfull);
    1867     if ~isempty(hh)
    1868         detect=1;
    1869         namefig=[namefig '.0'];
    1870     else
    1871         detect=0;
    1872     end
    1873 end
    1874 saveas(gcbf,namefigfull);%save the interface with name namefigfull
    1875
    1876
    1877 %----------------------------------------
    1878 %PATCH
    1879 %---------------------------------------
    1880 function cmd_PATCH=RUN_PATCH(filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,test_interp)
    1881 global patch_exe patch_new_exe
    1882         namelog=[filename_nc([1:end-3]) '_patch.log'];
    1883         if test_interp==0
    1884             cmd_PATCH=[patch_exe ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ...
    1885             '  > ' namelog ' 2>&1'] % redirect standard output to the log file
    1886          else %nouveau programme patch
    1887              cmd_PATCH=[patch_new_exe ' -f ' filename_nc ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ...
    1888                 ' -max ' thresh_value ' -nopt ' subdomain_patch  '  > ' namelog ' 2>&1']; % redirect standard output to the log file
    1889         end
    1890
    1891
    1892 %----------------------------------------------------
    1893 function first_j_Callback(hObject, eventdata, handles)
    1894 last_j_Callback(hObject, eventdata, handles)
    1895
    1896 %---------------------------------------------------------
    1897 % --- Executes on button press in CIV1.
    1898 function CIV1_Callback(hObject, eventdata, handles)
    1899 enable_civ1(handles,get(handles.CIV1,'Value'))
    1900 find_netcpair_civ1(hObject, eventdata, handles);
    1901
    1902 %------------------------------------------------------
    1903 % --- Executes on button press in FIX1.
    1904 function FIX1_Callback(hObject, eventdata, handles)
    1905
    1906 if get(handles.FIX1,'Value')==1
    1907 enable_fix1(handles)
    1908 else
    1909 desable_fix1(handles)
    1910 end
    1911
    1912 %----------------------------------------------------------------
    1913 % --- Executes on button press in PATCH1.
    1914 function PATCH1_Callback(hObject, eventdata, handles)
    1915
    1916 if get(handles.PATCH1,'Value')==1
    1917 enable_patch1(handles)
    1918 else
    1919 desable_patch1(handles)
    1920 end
    1921
    1922 %----------------------------------------------------------
    1923 % --- Executes on button press in CIV2.
    1924 function CIV2_Callback(hObject, eventdata, handles)
    1925 state=get(handles.CIV2,'Value');
    1926 enable_civ2(handles,state)
    1927 if state
    1928     find_netcpair_civ2(hObject, eventdata, handles)
    1929 end
    1930
    1931 %---------------------------------------------------
    1932 % --- Executes on button press in FIX2.
    1933 function FIX2_Callback(hObject, eventdata, handles)
    1934 if get(handles.FIX2,'Value')==1
    1935     enable_fix2(handles)
    1936     if get(handles.CIV2,'Value')==0
    1937         find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
    1938     end
    1939 else
    1940     desable_fix2(handles)
    1941 end
    1942
    1943
    1944 %-------------------------------------------------------
    1945 % --- Executes on button press in PATCH2.
    1946 function PATCH2_Callback(hObject, eventdata, handles)
    1947 %--------------------------------------------------------
    1948 if get(handles.PATCH2,'Value')==1
    1949     enable_patch2(handles)
    1950     if get(handles.CIV2,'Value')==0
    1951         find_netcpair_civ2(hObject, eventdata, handles) % select the available netcdf files
    1952     end
    1953 else
    1954     desable_patch2(handles)
    1955 end
    1956
    1957
    1958
    1959 %-----------------------------------------------------------
    1960 function first_i_Callback(hObject, eventdata, handles)
    1961 %------------------------------------------------------
    1962 last_i_Callback(hObject, eventdata, handles)
    1963
    1964 %-----------------------------------------------------------
    1965 % --- Executes on button press in calcul_search: determine the search range isx,isy
    1966 %--------------------------------------------------------
    1967 function calcul_search_Callback(hObject, eventdata, handles)
    1968
    1969 %determine pair numbers
    1970 list_pair=get(handles.list_pair_civ1,'String');%get the menu of image pairs
    1971 index=get(handles.list_pair_civ1,'Value');
    1972 displ_num=get(handles.list_pair_civ1,'UserData');
    1973 time=get(handles.displ_filebase,'UserData'); %get the set of times
    1974 pxcm_xy=get(handles.calcul_search,'UserData')
    1975 pxcmx=pxcm_xy(1);
    1976 pxcmy=pxcm_xy(2);
    1977 mode_list=get(handles.mode,'String');
    1978 mode_value=get(handles.mode,'Value');
    1979 mode=mode_list{mode_value};
    1980 if isequal (mode, 'series(Di)' )
    1981     ref_i=str2num(get(handles.ref_i,'String'));
    1982     num1=ref_i-floor(index/2);%  first image numbers
    1983     num2=ref_i+ceil(index/2);
    1984     num_a=1;
    1985     num_b=1;
    1986 elseif isequal (mode, 'series(Dj)')
    1987     num1=1;
    1988     num2=1;
    1989     ref_j=str2num(get(handles.ref_j,'String'));
    1990     num_a=ref_j-floor(index/2);%  first image numbers
    1991     num_b=ref_j+ceil(index/2);
    1992 elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)
    1993     ref_i=str2num(get(handles.ref_i,'String'));
    1994     num1=ref_i;
    1995     num2=ref_i;
    1996     num_a=displ_num(1,index);
    1997     num_b=displ_num(2,index);
    1998 end
    1999 dt=time(num2,num_b)-time(num1,num_a);
    2000 ibx=str2num(get(handles.ibx,'String'));
    2001 iby=str2num(get(handles.iby,'String'));
    2002 umin=dt*pxcmx*str2num(get(handles.umin,'String'));
    2003 umax=dt*pxcmx*str2num(get(handles.umax,'String'));
    2004 vmin=dt*pxcmy*str2num(get(handles.vmin,'String'));
    2005 vmax=dt*pxcmy*str2num(get(handles.vmax,'String'));
    2006 shiftx=round((umin+umax)/2);
    2007 shifty=round((vmin+vmax)/2);
    2008 isx=(umax+2-shiftx)*2+ibx;
    2009 isx=2*ceil(isx/2)+1;
    2010 isy=(vmax+2-shifty)*2+iby;
    2011 isy=2*ceil(isy/2)+1;
    2012 set(handles.shiftx,'String',num2str(shiftx));
    2013 set(handles.shifty,'String',num2str(shifty));
    2014 set(handles.isx,'String',num2str(isx));
    2015 set(handles.isy,'String',num2str(isy));
    2016
    2017
    2018 %---------------------------------------------------------
    2019 % Executes on carriage return on the subdir civ1 edit window
    2020 %--------------------------------------------------------
    2021 function subdir_civ1_Callback(hObject, eventdata, handles)
    2022 subdir=get(handles.subdir_civ1,'String');
    2023 set(handles.subdir_civ2,'String',subdir);
    2024 if get(handles.CIV1,'Value')==0
    2025     find_netcpair_civ1(hObject, eventdata, handles); %update the list of available pairs from netcdf files in the new directory
    2026 end
    2027
    2028 %---------------------------------------------------------
    2029 % Executes on carriage return on the subdir civ1 edit window
    2030 %---------------------------------------------------------
    2031 function subdir_civ2_Callback(hObject, eventdata, handles)
    2032 %update the list of available pairs from netcdf files in the new directory
    2033 if get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0
    2034     find_netcpair_civ2(hObject, eventdata, handles);
    2035 end
    2036
    2037 %------------------------------------------------------
    2038 % --- Executes on button press in get_mask_civ1.
    2039 %------------------------------------------------------
    2040 function get_mask_civ1_Callback(hObject, eventdata, handles)
    2041 maskval=get(handles.get_mask_civ1,'Value')
    2042 if isequal(maskval,0)
    2043     set(handles.mask_civ1,'String','')
    2044 else
    2045 mask_displ='no mask'; %default
    2046 filebase=get(handles.displ_filebase,'String');
    2047 [ nbslice, flag_mask]=get_mask(filebase,handles)
    2048 if isequal(flag_mask,1)
    2049       mask_displ=[num2str(nbslice) 'mask'];
    2050 end
    2051 if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
    2052         filebase_a=get(handles.displ_filebase2,'String');
    2053         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
    2054         if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
    2055             mask_displ='no mask';
    2056         end
    2057 end
    2058 if isequal(mask_displ,'no mask')
    2059     set(handles.get_mask_civ1,'Value',0)
    2060     set(handles.get_mask_fix1,'Value',0)
    2061     set(handles.get_mask_civ2,'Value',0)
    2062     set(handles.get_mask_fix2,'Value',0)
    2063 else
    2064     set(handles.get_mask_fix1,'Value',1)
    2065     set(handles.get_mask_civ2,'Value',1)
    2066     set(handles.get_mask_fix2,'Value',1)
    2067 end
    2068 set(handles.mask_civ1,'String',mask_displ)
    2069 set(handles.mask_fix1,'String',mask_displ)
    2070 set(handles.mask_civ2,'String',mask_displ)
    2071 set(handles.mask_fix2,'String',mask_displ)
    2072 end
    2073 %--------------------------------------------------------------
    2074 % --- Executes on button press in get_mask_fix1.
    2075 function get_mask_fix1_Callback(hObject, eventdata, handles)
    2076 maskval=get(handles.get_mask_fix1,'Value')
    2077 if isequal(maskval,0)
    2078     set(handles.mask_fix1,'String','')
    2079 else
    2080 mask_displ='no mask'; %default
    2081 filebase=get(handles.displ_filebase,'String');
    2082 [nbslice, flag_mask]=get_mask(filebase,handles)
    2083 if isequal(flag_mask,1)
    2084       mask_displ=[num2str(nbslice) 'mask'];
    2085 end
    2086 if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
    2087         filebase_a=get(handles.displ_filebase2,'String');
    2088         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
    2089         if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
    2090             mask_displ='no mask';
    2091         end
    2092 end
    2093 if isequal(mask_displ,'no mask')
    2094     set(handles.get_mask_fix1,'Value',0)
    2095     set(handles.get_mask_civ2,'Value',0)
    2096     set(handles.get_mask_fix2,'Value',0)
    2097 else
    2098     set(handles.get_mask_civ2,'Value',1)
    2099     set(handles.get_mask_fix2,'Value',1)
    2100 end
    2101 set(handles.mask_fix1,'String',mask_displ)
    2102 set(handles.mask_civ2,'String',mask_displ)
    2103 set(handles.mask_fix2,'String',mask_displ)
    2104 end
    2105 %-----------------------------------------
    2106 % --- Executes on button press in get_mask_civ2.
    2107 function get_mask_civ2_Callback(hObject, eventdata, handles)
    2108 maskval=get(handles.get_mask_civ2,'Value')
    2109 if isequal(maskval,0)
    2110     set(handles.mask_civ2,'String','')
    2111 else
    2112 mask_displ='no mask'; %default
    2113 filebase=get(handles.displ_filebase,'String');
    2114 [nbslice, flag_mask]=get_mask(filebase,handles)
    2115 if isequal(flag_mask,1)
    2116       mask_displ=[num2str(nbslice) 'mask'];
    2117 end
    2118 if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
    2119         filebase_a=get(handles.displ_filebase2,'String');
    2120         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
    2121         if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
    2122             mask_displ='no mask';
    2123         end
    2124 end
    2125 if isequal(mask_displ,'no mask')
    2126     set(handles.get_mask_civ2,'Value',0)
    2127     set(handles.get_mask_fix2,'Value',0)
    2128 else
    2129     set(handles.get_mask_fix2,'Value',1)
    2130 end
    2131 set(handles.mask_civ2,'String',mask_displ)
    2132 set(handles.mask_fix2,'String',mask_displ)
    2133 end
    2134 %-------------------------------------
    2135 % --- Executes on button press in get_mask_fix2.
    2136 function get_mask_fix2_Callback(hObject, eventdata, handles)
    2137 maskval=get(handles.get_mask_fix2,'Value')
    2138 if isequal(maskval,0)
    2139     set(handles.mask_fix2,'String','')
    2140 else
    2141 mask_displ='no mask'; %default
    2142 filebase=get(handles.displ_filebase,'String');
    2143 [nbslice, flag_mask]=get_mask(filebase,handles)
    2144 if isequal(flag_mask,1)
    2145       mask_displ=[num2str(nbslice) 'mask'];
    2146 end
    2147 if get(handles.compare,'Value')==1 & ~isequal(mask_displ,'no mask')% look for the second mask series
    2148         filebase_a=get(handles.displ_filebase2,'String');
    2149         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles)
    2150         if isequal(flag_mask_a,0) | ~isequal(nbslice_a,nbslice)
    2151             mask_displ='no mask';
    2152         end
    2153 end
    2154 if isequal(mask_displ,'no mask')
    2155     set(handles.get_mask_fix2,'Value',0)
    2156 end
    2157 set(handles.mask_fix2,'String',mask_displ)
    2158 end
    2159
    2160 %---------------------------------------
    2161 function [nbslice, flag_mask]=get_mask(filebase,handles)
    2162 %detect mask files, images with appropriate file base
    2163 %[filebase '_' xx 'mask'], xx=nbslice
    2164 %flag_mask=1 indicates detection
    2165
    2166 flag_mask=0;%default
    2167 nbslice=1;
    2168
    2169 % subdir=get(handles.subdir_civ1,'String');
    2170 [Path,Name]=fileparts(filebase)
    2171 currentdir=pwd;
    2172 cd(Path);%move in the dir of the root name filebase
    2173 maskfiles=dir([Name '_*mask_*.png'])%look for mask files
    2174 cd(currentdir);%come back to the current working directory
    2175 if isempty(maskfiles)
    2176     browse=get(handles.browse_root,'UserData');
    2177      varargin{1}='';
    2178     [image_name,idetect]=name_generator(filebase,1,1,browse.ext_ima,browse.nom_type_ima);%name of an image
    2179     if idetect==1
    2180          varargin{1}=image_name;
    2181     end
    2182     warndlg_uvmat('no mask available, use TOOL menu in the uvmat interface to create it','ERROR')
    2183 %     makemask(varargin); %open the makemask interface
    2184 else
    2185     maskname=maskfiles(1).name;% take the first mask file in the list
    2186     [Path2,Name,ext]=fileparts(maskname);
    2187     Namedouble=double(Name);
    2188     val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
    2189     ind_mask=findstr('mask',Name);
    2190     i=ind_mask-1;
    2191     while val(i)==0 & i>0
    2192        i=i-1;
    2193     end
    2194     nbslice=str2num(Name(i+1:ind_mask-1));
    2195     if ~isequal(nbslice,[]) & Name(i)=='_'
    2196           flag_mask=1;
    2197     else
    2198           errordlg(['bad mask file ' Name ext ' found in ' Path2])
    2199           return
    2200           nbslice=1;
    2201     end
    2202 end
    2203 %------------------------------
    2204
    2205
    2206 function grid_civ1_Callback(hObject, eventdata, handles)
    2207 % hObject    handle to grid_civ1 (see GCBO)
    2208 % eventdata  reserved - to be defined in a future version of MATLAB
    2209 % handles    structure with handles and user data (see GUIDATA)
    2210
    2211 % Hints: get(hObject,'String') returns contents of grid_civ1 as text
    2212 %        str2double(get(hObject,'String')) returns contents of grid_civ1 as a double
    2213
    2214
    2215 %-----------------------------------------------------------
    2216 % transform numbers to letters
    2217 %--------------------------------------------
    2218 function str=num2stra(num,nom_type);
    2219 if isequal(nom_type,'png_old') | isequal(nom_type,'netc_old') |isequal(nom_type,'raw_SMD')
    2220     str=char(96+num);
    2221 elseif isequal(nom_type,'_i')|isequal(nom_type,'_i1-i2')...
    2222         |isequal(nom_type,'ima_num')| isequal(nom_type,'avi')| isequal(nom_type,'none')
    2223     str='';
    2224 else
    2225     str=num2str(num);
    2226 end
    2227 %---------------------------------------------------
    2228 function mask_civ1_Callback(hObject, eventdata, handles)
    2229 set(handles.mask_civ1,'UserData',[])
    2230 set(handles.mask_civ1,'String','')
    2231 %----------------------------------------------------
    2232 function mask_civ2_Callback(hObject, eventdata, handles)
    2233 set(handles.mask_civ2,'UserData',[])
    2234 set(handles.mask_civ2,'String','')
    2235 %----------------------------------------------------
    2236 function mask_fix1_Callback(hObject, eventdata, handles)
    2237 set(handles.mask_fix1,'UserData',[])
    2238 set(handles.mask_fix1,'String','')
    2239 %----------------------------------------------------
    2240 function mask_fix2_Callback(hObject, eventdata, handles)
    2241 set(handles.mask_fix2,'UserData',[])
    2242 set(handles.mask_fix2,'String','')
    2243
    2244 %--------------------------------------------------------------------------
    2245 % --- Executes on button press in list_subdir_civ1.
    2246 function list_subdir_civ1_Callback(hObject, eventdata, handles)
    2247
    2248 filebase=get(handles.displ_filebase,'String');
    2249 dirinput = uigetdir(filebase)
    2250     set(handles.subdir_civ1,'String',dirinput)
    2251     set(handles.subdir_civ2,'String',dirinput)
    2252
    2253 displ_filebase_Callback(hObject, eventdata, handles);
    2254
    2255
    2256 function rho_civ2_Callback(hObject, eventdata, handles)
    2257 % hObject    handle to rho_civ2 (see GCBO)
    2258 % eventdata  reserved - to be defined in a future version of MATLAB
    2259 % handles    structure with handles and user data (see GUIDATA)
    2260
    2261 % Hints: get(hObject,'String') returns contents of rho_civ2 as text
    2262 %        str2double(get(hObject,'String')) returns contents of rho_civ2 as a double
    2263
    2264 %----------------------------------------------
    2265 function last_i_Callback(hObject, eventdata, handles)
    2266 first_i=str2num(get(handles.first_i,'String'));
    2267 last_i=str2num(get(handles.last_i,'String'));
    2268 ref_i=ceil((first_i+last_i)/2);
    2269 set(handles.ref_i,'String', num2str(ref_i))
    2270 ref_i_Callback(hObject, eventdata, handles)
    2271
    2272 %-------------------------------------------------------
    2273 function last_j_Callback(hObject, eventdata, handles)
    2274 first_j=str2num(get(handles.first_j,'String'));
    2275 last_j=str2num(get(handles.last_j,'String'));
    2276 ref_j=ceil((first_j+last_j)/2);
    2277 set(handles.ref_j,'String', num2str(ref_j))
    2278 ref_j_Callback(hObject, eventdata, handles)
    2279
    2280 %--------------------------------------------------------------------------
    2281 % --- Executes on button press in browse_gridciv1.
    2282 function browse_gridciv1_Callback(hObject, eventdata, handles)
    2283 value=get(handles.browse_gridciv1,'Value');
    2284 if value
    2285     filebase=get(handles.displ_filebase,'String');
    2286     [FileName, PathName, filterindex] = uigetfile( ...
    2287            {'*.grid', ' (*.grid)';
    2288             '*.grid',  '.grid files '; ...
    2289             '*.*', 'All Files (*.*)'}, ...
    2290             'Pick a file',filebase);
    2291     filegrid=fullfile(PathName,FileName);
    2292     if isempty(FileName)|isempty(PathName)|isequal(FileName,0)|~exist(filegrid,'file')
    2293         set(handles.browse_gridciv1,'Value',0);
    2294         set(handles.grid_civ1,'string','');
    2295         set(handles.dx_civ1,'Visible','on');
    2296         set(handles.dy_civ1,'Visible','on');
    2297         set(handles.grid_civ2,'string','');
    2298         if get(handles.CIV2,'Value')
    2299             set(handles.dx_civ2,'Visible','on');
    2300             set(handles.dy_civ2,'Visible','on');
    2301         end
    2302     else
    2303         set(handles.grid_civ1,'string',filegrid);
    2304         set(handles.dx_civ1,'Visible','off');
    2305         set(handles.dy_civ1,'Visible','off');
    2306         set(handles.grid_civ2,'string',filegrid);
    2307         set(handles.dx_civ2,'Visible','off');
    2308         set(handles.dy_civ2,'Visible','off');
    2309 % set(handles.grid_patch1,'string',filegrid);
    2310 % set(handles.grid_patch2,'string',filegrid);
    2311     end
    2312 else
    2313     set(handles.grid_civ1,'string','');
    2314     set(handles.dx_civ1,'Visible','on');
    2315     set(handles.dy_civ1,'Visible','on');
    2316     set(handles.grid_civ2,'string','');
    2317     if get(handles.CIV2,'Value')
    2318         set(handles.dx_civ2,'Visible','on');
    2319         set(handles.dy_civ2,'Visible','on');
    2320     end
    2321 end
    2322
    2323
    2324
    2325 function pxcmx_Callback(hObject, eventdata, handles)
    2326 % hObject    handle to pxcmx (see GCBO)
    2327 % eventdata  reserved - to be defined in a future version of MATLAB
    2328 % handles    structure with handles and user data (see GUIDATA)
    2329
    2330 % Hints: get(hObject,'String') returns contents of pxcmx as text
    2331 %        str2double(get(hObject,'String')) returns contents of pxcmx as a double
    2332
    2333
    2334
    2335 function pxcmy_Callback(hObject, eventdata, handles)
    2336 % hObject    handle to pxcmy (see GCBO)
    2337 % eventdata  reserved - to be defined in a future version of MATLAB
    2338 % handles    structure with handles and user data (see GUIDATA)
    2339
    2340 % Hints: get(hObject,'String') returns contents of pxcmy as text
    2341 %        str2double(get(hObject,'String')) returns contents of pxcmy as a double
    2342
    2343
    2344 % --- Executes on button press in browse_gridciv2.
    2345 function browse_gridciv2_Callback(hObject, eventdata, handles)
    2346
    2347 filebase=get(handles.displ_filebase,'String');
    2348 [FileName, PathName, filterindex] = uigetfile( ...
    2349        {'*.grid', ' (*.grid)';
    2350         '*.grid',  '.grid files '; ...
    2351         '*.*', 'All Files (*.*)'}, ...
    2352         'Pick a file',filebase);
    2353 filegrid=fullfile(PathName,FileName);
    2354 set(handles.grid_civ2,'string',filegrid);
    2355 set(handles.dx_civ2,'String',' ');
    2356 set(handles.dy_civ2,'String',' ');
    2357 % set(handles.grid_patch2,'string',filegrid);
    2358
    2359 % --- Executes on button press in get_gridpatch1.
    2360 function get_gridpatch1_Callback(hObject, eventdata, handles)
    2361 % hObject    handle to get_gridpatch1 (see GCBO)
    2362 % eventdata  reserved - to be defined in a future version of MATLAB
    2363 % handles    structure with handles and user data (see GUIDATA)
    2364
    2365 filebase=get(handles.displ_filebase,'String');
    2366 [FileName, PathName, filterindex] = uigetfile( ...
    2367        {'*.grid', ' (*.grid)';
    2368         '*.grid',  '.grid files '; ...
    2369         '*.*', 'All Files (*.*)'}, ...
    2370         'Pick a file',filebase);
    2371 filegrid=fullfile(PathName,FileName);
    2372 set(handles.grid_patch1,'string',filegrid);
    2373 % set(handles.grid_patch2,'string',filegrid
    2374
    2375 %-----------------------------------------------------------------
    2376 % --- Executes on button press in get_gridpatch2.
    2377 function get_gridpatch2_Callback(hObject, eventdata, handles)
    2378 % hObject    handle to get_gridpatch2 (see GCBO)
    2379 % eventdata  reserved - to be defined in a future version of MATLAB
    2380 % handles    structure with handles and user data (see GUIDATA)
    2381
    2382
    2383 %----------------------------------------------------------
    2384 function enable_civ1(handles,state)
    2385 if isequal(state,0)
    2386     state='off';
    2387 end
    2388 if isequal(state,1)
    2389     state='on';
    2390 end
    2391 if isequal(state,'on')
    2392     set(handles.frame_civ1,'BackgroundColor',[1 1 0])
    2393     set(handles.frame_para_civ1,'BackgroundColor',[1 1 0])
    2394     set(handles.frame_grid_civ1,'BackgroundColor',[1 1 0])
    2395 else
    2396     set(handles.frame_civ1,'BackgroundColor',[0.831 0.816 0.784])
    2397     set(handles.frame_para_civ1,'BackgroundColor',[0.831 0.816 0.784])
    2398     set(handles.frame_grid_civ1,'BackgroundColor',[0.831 0.816 0.784])
    2399 end
    2400 set(handles.ibx,'Visible',state)
    2401 set(handles.iby,'Visible',state)
    2402 set(handles.isx,'Visible',state)
    2403 set(handles.isy,'Visible',state)
    2404 set(handles.shiftx,'Visible',state)
    2405 set(handles.shifty,'Visible',state)
    2406 set(handles.rho,'Visible',state)
    2407 set(handles.dx_civ1,'Visible',state)
    2408 set(handles.dy_civ1,'Visible',state)
    2409 set(handles.calcul_search,'Visible',state)
    2410 set(handles.u_text,'Visible',state)
    2411 set(handles.v_text,'Visible',state)
    2412 set(handles.min,'Visible',state)
    2413 set(handles.max,'Visible',state)
    2414 set(handles.umin,'Visible',state)
    2415 set(handles.umax,'Visible',state)
    2416 set(handles.vmin,'Visible',state)
    2417 set(handles.vmax,'Visible',state)
    2418 set(handles.grid_civ1,'Visible',state)
    2419 set(handles.mask_civ1,'Visible',state)
    2420 set(handles.browse_gridciv1,'Visible',state)
    2421 set(handles.get_mask_civ1,'Visible',state)
    2422 set(handles.parameters,'Visible',state)
    2423 set(handles.grid,'Visible',state)
    2424 set(handles.dx_civ1,'Visible',state)
    2425 set(handles.dy_civ1,'Visible',state)
    2426 set(handles.ImaThreshold,'Visible',state)
    2427 if isequal(state,'off')
    2428     set(handles.MinIma,'Visible','off')
    2429     set(handles.MaxIma,'Visible','off')
    2430     set(handles.ImaThreshold,'Value',0)
    2431 end
    2432 set(handles.dx_civ1_title,'Visible',state)
    2433 set(handles.dy_civ1_title,'Visible',state)
    2434 set(handles.ImaThreshold_title,'Visible',state)
    2435 set(handles.ib_title,'Visible',state)
    2436 set(handles.is_title,'Visible',state)
    2437 set(handles.shift_title,'Visible',state)
    2438 set(handles.rho_title,'Visible',state)
    2439
    2440 %----------------------------------------------------------
    2441 function enable_fix1(handles)
    2442 set(handles.frame_fix1,'BackgroundColor',[1 1 0])
    2443 set(handles.REMOVE,'Visible','on')
    2444 set(handles.vec_Fmin2,'Visible','on')
    2445 set(handles.vec_F2,'Visible','on')
    2446 set(handles.vec_F3,'Visible','on')
    2447 set(handles.thresh_vecC,'Visible','on')
    2448 set(handles.thresh_vecC_title,'Visible','on')
    2449 set(handles.thresh_vel,'Visible','on')
    2450 set(handles.thresh_vel_text,'Visible','on')
    2451 set(handles.mask_fix1,'Visible','on')
    2452 set(handles.get_mask_fix1,'Visible','on')
    2453 set(handles.get_ref_fix1,'Visible','on')
    2454 set(handles.ref_fix1,'Visible','on')
    2455 set(handles.inf_sup1,'Visible','on')
    2456 set(handles.field_ref1,'Visible','on')
    2457
    2458 %----------------------------------------------------------
    2459 function desable_fix1(handles)
    2460 set(handles.frame_fix1,'BackgroundColor',[0.831 0.816 0.784])
    2461 set(handles.REMOVE,'Visible','off')
    2462 set(handles.vec_Fmin2,'Visible','off')
    2463 set(handles.vec_F2,'Visible','off')
    2464 set(handles.vec_F3,'Visible','off')
    2465 set(handles.thresh_vecC,'Visible','off')
    2466 set(handles.thresh_vecC_title,'Visible','off')
    2467 set(handles.thresh_vel,'Visible','off')
    2468 set(handles.thresh_vel_text,'Visible','off')
    2469 set(handles.mask_fix1,'Visible','off')
    2470 set(handles.get_mask_fix1,'Visible','off')
    2471 set(handles.get_ref_fix1,'Visible','off')
    2472 set(handles.ref_fix1,'Visible','off')
    2473 set(handles.inf_sup1,'Visible','off')
    2474 set(handles.field_ref1,'Visible','off')
    2475
    2476 %--------------------------------------------------------------
    2477 function enable_patch1(handles)
    2478 global patch_new_exe
    2479 set(handles.frame_patch1,'BackgroundColor',[1 1 0])
    2480 set(handles.rho_patch1,'Visible','on')
    2481 set(handles.rho_text1,'Visible','on')
    2482 set(handles.thresh_patch1,'Visible','on')
    2483 set(handles.thresh_text1,'Visible','on')
    2484 set(handles.subdomain_patch1,'Visible','on')
    2485 set(handles.subdomain_text1,'Visible','on')
    2486 set(handles.nx_patch1,'Visible','on')
    2487 set(handles.ny_patch1,'Visible','on')
    2488 set(handles.nx_patch1_title,'Visible','on')
    2489 set(handles.ny_patch1_title,'Visible','on')
    2490 if (~isequal(patch_new_exe,[]) & ~isequal(patch_new_exe,[]))
    2491     set(handles.test_interp,'Visible','on');
    2492 end
    2493 set(handles.get_gridpatch1,'Visible','on')
    2494 set(handles.grid_patch1,'string','none');
    2495 set(handles.grid_patch1,'Visible','on')
    2496
    2497 %--------------------------------------------------------------
    2498 function desable_patch1(handles)
    2499 set(handles.frame_patch1,'BackgroundColor',[0.831 0.816 0.784])
    2500 set(handles.rho_patch1,'Visible','off')
    2501 set(handles.rho_text1,'Visible','off')
    2502 set(handles.thresh_patch1,'Visible','off')
    2503 set(handles.thresh_text1,'Visible','off')
    2504 set(handles.subdomain_patch1,'Visible','off')
    2505 set(handles.subdomain_text1,'Visible','off')
    2506 set(handles.nx_patch1,'Visible','off')
    2507 set(handles.ny_patch1,'Visible','off')
    2508 set(handles.nx_patch1_title,'Visible','off')
    2509 set(handles.ny_patch1_title,'Visible','off')
    2510 set(handles.test_interp,'Visible','off')
    2511 set(handles.get_gridpatch1,'Visible','off')
    2512 set(handles.grid_patch1,'Visible','off')
    2513
    2514 %----------------------------------------------------------
    2515 function enable_civ2(handles,state)
    2516 if isequal(state,0)
    2517     state='off';
    2518 end
    2519 if isequal(state,1)
    2520     state='on';
    2521 end
    2522 if isequal(state,'on')
    2523     set(handles.frame_civ2,'BackgroundColor',[1 1 0])
    2524     set(handles.frame_para_civ2,'BackgroundColor',[1 1 0])
    2525     set(handles.frame_grid_civ2,'BackgroundColor',[1 1 0])
    2526     set(handles.frame_subdirciv2,'BackgroundColor',[1 1 0])
    2527 else
    2528     set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
    2529     set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
    2530     set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
    2531     set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
    2532 end
    2533 set(handles.ibx_civ2,'Visible',state)
    2534 set(handles.iby_civ2,'Visible',state)
    2535 set(handles.decimal,'Visible',state)
    2536 set(handles.deformation,'Visible',state)
    2537 set(handles.rho_civ2,'Visible',state)
    2538 set(handles.dx_civ2,'Visible',state)
    2539 set(handles.dy_civ2,'Visible',state)
    2540 set(handles.browse_gridciv2,'Visible',state)
    2541 set(handles.get_mask_civ2,'Visible',state)
    2542 set(handles.parameters,'Visible',state)
    2543 set(handles.grid,'Visible',state)
    2544 set(handles.parameters_text,'Visible',state)
    2545 set(handles.grid_text,'Visible',state)
    2546 set(handles.grid_civ2,'Visible',state)
    2547 set(handles.mask_civ2,'Visible',state)
    2548 set(handles.dx_civ2_title,'Visible',state)
    2549 set(handles.dy_civ2_title,'Visible',state)
    2550 set(handles.ibx_civ2_text,'Visible',state)
    2551 set(handles.rho_civ2_title,'Visible',state)
    2552 set(handles.ImaThreshold2,'Visible',state)
    2553 set(handles.ImaThreshold_title2,'Visible',state)
    2554 if isequal(state,'off')
    2555     set(handles.MinIma2,'Visible','off')
    2556     set(handles.MaxIma2,'Visible','off')
    2557     set(handles.ImaThreshold2,'Value',0)
    2558     if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
    2559         set(handles.list_pair_civ2,'Visible','off')
    2560         set(handles.subdir_civ2,'Visible','off')
    2561         set(handles.subdir_civ2_text,'Visible','off')
    2562     end
    2563 else
    2564     set(handles.list_pair_civ2,'Visible','on')
    2565     set(handles.subdir_civ2,'Visible','on')
    2566     set(handles.subdir_civ2_text,'Visible','on')
    2567 end
    2568
    2569 %----------------------------------------------------------
    2570 % function desable_civ2(handles)
    2571 % set(handles.frame_civ2,'BackgroundColor',[0.831 0.816 0.784])
    2572 % set(handles.frame_para_civ2,'BackgroundColor',[0.831 0.816 0.784])
    2573 % set(handles.frame_grid_civ2,'BackgroundColor',[0.831 0.816 0.784])
    2574 % set(handles.ibx_civ2,'Visible','off')
    2575 % set(handles.iby_civ2,'Visible','off')
    2576 % set(handles.decimal,'Visible','off')
    2577 % set(handles.deformation,'Visible','off')
    2578 % set(handles.rho_civ2,'Visible','off')
    2579 % set(handles.dx_civ2,'Visible','off')
    2580 % set(handles.dy_civ2,'Visible','off')
    2581 % set(handles.browse_gridciv2,'Visible','off')
    2582 % set(handles.get_mask_civ2,'Visible','off')
    2583 % set(handles.parameters,'Visible','off')
    2584 % set(handles.grid,'Visible','off')
    2585 % set(handles.grid,'Visible','on')
    2586 % set(handles.parameters_text,'Visible','off')
    2587 % set(handles.grid_text,'Visible','off')
    2588 % set(handles.grid_civ2,'Visible','off')
    2589 % set(handles.mask_civ2,'Visible','off')
    2590 % set(handles.dx_civ2_title,'Visible','off')
    2591 % set(handles.dy_civ2_title,'Visible','off')
    2592 % set(handles.ibx_civ2_text,'Visible','off')
    2593 % set(handles.rho_civ2_title,'Visible','off')
    2594 % set(handles.frame_subdirciv2,'BackgroundColor',[0.831 0.816 0.784])
    2595 % if isequal(get(handles.FIX2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
    2596 %     set(handles.list_pair_civ2,'Visible','off')
    2597 %     set(handles.subdir_civ2,'Visible','off')
    2598 %     set(handles.subdir_civ2_text,'Visible','off')
    2599 % end
    2600
    2601 %----------------------------------------------------------
    2602 function enable_fix2(handles)
    2603 set(handles.frame_fix2,'BackgroundColor',[1 1 0])
    2604 set(handles.REMOVE2,'Visible','on')
    2605 set(handles.vec_Fmin2_2,'Visible','on')
    2606 set(handles.vec_F4,'Visible','on')
    2607 set(handles.vec_F3_2,'Visible','on')
    2608 set(handles.thresh_vec2C,'Visible','on')
    2609 set(handles.thresh_vec2C_text,'Visible','on')
    2610 set(handles.thresh_vel2,'Visible','on')
    2611 set(handles.thresh_vel2_text,'Visible','on')
    2612 set(handles.mask_fix2,'Visible','on')
    2613 set(handles.get_mask_fix2,'Visible','on')
    2614 set(handles.list_pair_civ2,'Visible','on')
    2615 set(handles.subdir_civ2,'Visible','on')
    2616 set(handles.subdir_civ2_text,'Visible','on')
    2617 set(handles.get_ref_fix2,'Visible','on')
    2618 set(handles.ref_fix2,'Visible','on')
    2619 set(handles.inf_sup2,'Visible','on')
    2620 set(handles.field_ref2,'Visible','on')
    2621
    2622 %----------------------------------------------------------
    2623 function desable_fix2(handles)
    2624 set(handles.frame_fix2,'BackgroundColor',[0.831 0.816 0.784])
    2625 set(handles.REMOVE2,'Visible','off')
    2626 set(handles.vec_Fmin2_2,'Visible','off')
    2627 set(handles.vec_F4,'Visible','off')
    2628 set(handles.vec_F3_2,'Visible','off')
    2629 set(handles.thresh_vec2C,'Visible','off')
    2630 set(handles.thresh_vec2C_text,'Visible','off')
    2631 set(handles.thresh_vel2,'Visible','off')
    2632 set(handles.thresh_vel2_text,'Visible','off')
    2633 set(handles.mask_fix2,'Visible','off')
    2634 set(handles.get_mask_fix2,'Visible','off')
    2635 set(handles.get_ref_fix2,'Visible','off')
    2636 set(handles.ref_fix2,'Visible','off')
    2637 set(handles.inf_sup2,'Visible','off')
    2638 set(handles.field_ref2,'Visible','off')
    2639 if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.PATCH2,'Value'),0)
    2640     set(handles.list_pair_civ2,'Visible','off')
    2641     set(handles.subdir_civ2,'Visible','off')
    2642     set(handles.subdir_civ2_text,'Visible','off')
    2643 end
    2644
    2645 %--------------------------------------------------------------
    2646 function enable_patch2(handles)
    2647 set(handles.frame_patch2,'BackgroundColor',[1 1 0])
    2648 set(handles.rho_patch2,'Visible','on')
    2649 set(handles.rho_text2,'Visible','on')
    2650 set(handles.thresh_patch2,'Visible','on')
    2651 set(handles.thresh_text2,'Visible','on')
    2652 set(handles.subdomain_patch2,'Visible','on')
    2653 set(handles.subdomain_text2,'Visible','on')
    2654 set(handles.nx_patch2,'Visible','on')
    2655 set(handles.ny_patch2,'Visible','on')
    2656 set(handles.nx_patch2_title,'Visible','on')
    2657 set(handles.ny_patch2_title,'Visible','on')
    2658 set(handles.get_gridpatch2,'Visible','on')
    2659 set(handles.grid_patch2,'Visible','on')
    2660 set(handles.list_pair_civ2,'Visible','on')
    2661 set(handles.subdir_civ2,'Visible','on')
    2662 set(handles.subdir_civ2_text,'Visible','on')
    2663
    2664 %--------------------------------------------------------------
    2665 function desable_patch2(handles)
    2666 set(handles.frame_patch2,'BackgroundColor',[0.831 0.816 0.784])
    2667 set(handles.rho_patch2,'Visible','off')
    2668 set(handles.rho_text2,'Visible','off')
    2669 set(handles.thresh_patch2,'Visible','off')
    2670 set(handles.thresh_text2,'Visible','off')
    2671 set(handles.subdomain_patch2,'Visible','off')
    2672 set(handles.subdomain_text2,'Visible','off')
    2673 set(handles.nx_patch2,'Visible','off')
    2674 set(handles.ny_patch2,'Visible','off')
    2675 set(handles.nx_patch2_title,'Visible','off')
    2676 set(handles.ny_patch2_title,'Visible','off')
    2677 set(handles.get_gridpatch2,'Visible','off')
    2678 set(handles.grid_patch2,'Visible','off')
    2679 if isequal(get(handles.CIV2,'Value'),0) & isequal(get(handles.FIX2,'Value'),0)
    2680     set(handles.list_pair_civ2,'Visible','off')
    2681     set(handles.subdir_civ2,'Visible','off')
    2682     set(handles.subdir_civ2_text,'Visible','off')
    2683 end
    2684
    2685 % --- Executes on button press in test_interp.
    2686 function test_interp_Callback(hObject, eventdata, handles)
    2687
    2688
    2689 %------------------------------------------------
    2690 %Read the parameters for civ1 on the interface
    2691 %--------------------------------------------------
    2692 function par=read_param_civ1(handles,file_ima)
    2693
    2694 ibx_val=str2num(get(handles.ibx,'String'));
    2695 par.correlationBoxesSize_X=num2str(ibx_val);
    2696 iby_val=str2num(get(handles.iby,'String'));
    2697 par.correlationBoxesSize_Y=num2str(iby_val);
    2698 ibz_val=str2num(get(handles.ibz,'String'));
    2699 par.correlationBoxesSize_Z=num2str(ibz_val);
    2700 isx=get(handles.isx,'String');
    2701 if isempty(str2num(isx)), isx='41'; set(handles.isx,'String','41'), end; %default
    2702 maxDisplacement_X=floor((str2num(isx)-ibx_val)/2);
    2703 par.maxDisplacement_X=num2str(maxDisplacement_X);
    2704 isy=get(handles.isy,'String');
    2705 if isempty(str2num(isy)), isy='41'; set(handles.isy,'String','41'), end; %default
    2706 maxDisplacement_Y=floor((str2num(isy)-iby_val)/2);
    2707 par.maxDisplacement_Y=num2str(maxDisplacement_Y);
    2708 isz=get(handles.isz,'String');
    2709 if isempty(str2num(isz)), isz='41'; set(handles.isz,'String','41'), end; %default
    2710 maxDisplacement_Z=floor((str2num(isz)-ibz_val)/2);
    2711 par.maxDisplacement_Z=num2str(maxDisplacement_Z);
    2712 %      par.rho=get(handles.rho,'String');
    2713 par.gridSpacing_X=get(handles.dx_civ1,'String');
    2714 par.gridSpacing_Y=get(handles.dy_civ1,'String');
    2715 par.gridSpacing_Z=get(handles.dz_civ1,'String');
    2716 % Zmin=str2num(get(handles.first_j,'String'))-1;
    2717 Zmax=str2num(get(handles.nb_field2,'String'));
    2718 par.gridLimits_Xmin=0;
    2719 par.gridLimits_Ymin=0;
    2720 par.gridLimits_Zmin=0;
    2721 % A=imread(file_ima);%read the first image to get the size
    2722 %sizim=size(A);
    2723 par.gridLimits_Xmax=1024;%num2str(sizim(2));
    2724 par.gridLimits_Ymax=1024;%num2str(sizim(1));
    2725 par.gridLimits_Zmax=Zmax;
    2726 par.grid='grille';
    2727 par.grid_division=4;
    2728 par.hart=0;
    2729 par.ratioHoverZ=1;
    2730
    2731 %
    2732 % %----------------------------------------------------------------
    2733 % function par=read_param_civ2(handles,file_ima)
    2734 %     par.ibx=get(handles.ibx_civ2,'String');
    2735 %     par.iby=get(handles.iby_civ2,'String');
    2736 %     par.rho=get(handles.rho_civ2,'String');
    2737 %     par.decimal=int2str(get(handles.decimal,'Value'));
    2738 %     par.deformation=int2str(get(handles.deformation,'Value'));
    2739 %     par.dx=get(handles.dx_civ2,'String');
    2740 %     par.dy=get(handles.dy_civ2,'String');
    2741 %     if isequal(str2num(par.dx),[])
    2742 %          if isempty(get(handles.grid_civ2,'String'));
    2743 %              par.dx='0'; %just read by civ_3D program, not used
    2744 %          else
    2745 %             par.dx='20';%default
    2746 %             set(handles.dx_civ2,'String','20');
    2747 %          end
    2748 %      end
    2749 %      if isequal(str2num(par.dy),[])
    2750 %          if isempty(get(handles.grid_civ2,'String'));
    2751 %              par.dy='0';%just read by civ_3D program, not used
    2752 %          else
    2753 %             par.dy='20';%default
    2754 %             set(handles.dy_civ2,'String','20');
    2755 %          end
    2756 %      end
    2757 %     par.pxcmx=get(handles.pxcmx,'String');
    2758 %     par.pxcmy=get(handles.pxcmy,'String');
    2759 %     if isempty(str2num(par.pxcmx)) |isempty(str2num(par.pxcmy))
    2760 %         par.pxcmx='1';
    2761 %          par.pxcmy='1';
    2762 %     end
    2763 % %     par.npx=get(handles.pxcmx,'UserData');
    2764 % %     par.npy=get(handles.pxcmy,'UserData');
    2765 %     A=imread(file_ima);%read the first image to get the size
    2766 %     sizim=size(A);
    2767 %     par.npx=num2str(sizim(2));
    2768 %     par.npy=num2str(sizim(1));
    2769 %     time=get(handles.displ_filebase,'UserData'); %get the set of times
    2770 %     par.gridname=get(handles.grid_civ2,'String');
    2771 %     par.gridflag='y';
    2772 %     if isequal(par.gridname,'')| isempty(par.gridname)
    2773 %         par.gridname='nogrid';
    2774 %         par.gridflag='n';
    2775 %     end
    2776
    2777
    2778 %---------------------------------------------------------
    2779 %CIV1  CIV1  CIV1 CIV1
    2780 %----------------------------------------------------------
    2781 function cmd_CIV1=BATCH_CIV1(filename,namelog,par,handles)
    2782 %pixels per cm and matrix of the image times, read from the .civ_3D file by uvmat
    2783 global civ1_exe Civ_exe sge%name of the executable for civ1 calculation
    2784
    2785 %changes : filename_cmx -> filename ( no extension )
    2786
    2787             if isequal(par.Dt,'0')
    2788                 par.Dt='1' ;%case of 'displacement' mode
    2789             end
    2790
    2791     textcmx={'##############   CMX file';...
    2792     ['FirstImage ' par.filename_ima_a];...
    2793     ['LastImage  ' par.filename_ima_b];...
    2794     'XX' ;...
    2795     ['Mask ' par.maskflag] ;...
    2796     ['MaskName ' par.maskname];...
    2797     ['ImageSize ' par.npx ' ' par.npy];...   %VERIFIER CAS GENERAL ?
    2798     ['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
    2799     ['SearchBoxeSize ' par.isx ' ' par.isy];...
    2800     ['RO ' par.rho];...
    2801     ['GridSpacing ' par.dx ' ' par.dy];...
    2802     'XX 1.0';...
    2803     ['Dt_TO ' par.Dt ' ' par.T0];...
    2804     ['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
    2805     'XX 1';...
    2806     ['ShiftXY ' par.shiftx ' '  par.shifty];...
    2807     ['Grid ' par.gridflag];...
    2808     ['GridName ' par.gridname] ;...
    2809     'XX 85';...
    2810     'XX 1.0';...
    2811     'XX 1.0';...
    2812     'Hart 1';...
    2813     'DecimalShift 0';...
    2814     'Deformation 0';...
    2815     'CorrelationMin 0';...
    2816     'IntensityMin 0';...
    2817     'SeuilImage n';...
    2818     'SeuilImageValues 0 4096';...
    2819     ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
    2820     'ImageUsedBefore null null'};
    2821
    2822             textout=char(textcmx);
    2823     %         timeL1=clock;
    2824             dlmwrite([filename '.cmx'],textout,'');
    2825     %             timeL2=clock;
    2826     %     timciv1=etime(timeL2,timeL1)
    2827           if sge
    2828           cmd_CIV1=[civ1_exe ' -f ' filename '.cmx' ]; % redirect standard output to the log file
    2829           else
    2830               cmd_CIV1=[civ1_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
    2831           end
    2832     if(isunix)
    2833         [Rootbat,Filebat,extbat]=fileparts(namelog);
    2834         ncName=fullfile(Rootbat,[ Filebat '.nc']);
    2835         cmd_CIV1=char({cmd_CIV1 ; ['mv ' namelog  ' ' namelog '.civ1.log'];['chmod g+w ' ncName]});
    2836     else
    2837         cmd_CIV1=char({cmd_CIV1 ; ['copy /Y ' namelog ' ' namelog '.civ1.log']});
    2838     end
    2839
    2840 %---------------------------------------------------------
    2841 %CIV1  Unified
    2842 %----------------------------------------------------------
    2843 function xml_civ1_parameters=BATCH_CIV1_Unified(filename,namelog,par,handles)
    2844 %pixels per cm and matrix of the image times, read from the .civ_3D file by uvmat
    2845 global civ1_exe Civ_exe%name of the executable for civ1 calculation
    2846
    2847     civ1.image1=par.filename_ima_a;
    2848     civ1.image2=par.filename_ima_b;
    2849     civ1.imageSize_X=par.npx;
    2850     civ1.imageSize_Y=par.npy;
    2851     civ1.outputFileName=[filename '.nc'];
    2852     civ1.correlationBoxesSize_X=par.ibx;
    2853     civ1.correlationBoxesSize_Y=par.iby;
    2854     civ1.searchBoxesSize_X=par.isx;
    2855     civ1.searchBoxesSize_Y=par.isy;
    2856     civ1.globalShift_X=par.shiftx;
    2857     civ1.globalShift_Y=par.shifty;
    2858     civ1.ro=par.rho;
    2859     civ1.hart='y';
    2860     if isequal(par.gridflag,'y')
    2861         civ1.grid=par.gridname;
    2862     end
    2863     civ1.gridSpacing_X=par.dx;
    2864     civ1.gridSpacing_Y=par.dy;
    2865     if isequal(par.maskflag,'y')
    2866         civ1.mask=par.maskname;
    2867     end
    2868     civ1.dt=par.Dt;
    2869     civ1.unit='pixel';
    2870     civ1.absolut_time_T0=par.T0;
    2871     civ1.pixcmx=par.pxcmx;
    2872     civ1.pixcmy=par.pxcmy;
    2873     civ1.convectFlow='n';
    2874
    2875     xml_civ1_parameters=civ1;
    2876
    2877 %---------------------------------------------------------
    2878 %CIV2  CIV2  CIV2 CIV2
    2879 %----------------------------------------------------------
    2880 function cmd_CIV2=BATCH_CIV2(filename_cmx,namelog,par)
    2881 %pixels per cm and matrix of the image times, read from the .civ_3D file by uvmat
    2882 global civ2_exe sge%name of the executable for civ1 calculation
    2883    if isequal(par.Dt,'0')
    2884                 par.Dt='1' ;%case of 'displacement' mode
    2885   end
    2886 textcmx={'##############   CMX file';...
    2887 ['FirstImage ' par.filename_ima_a];...
    2888 ['LastImage  ' par.filename_ima_b];...
    2889 'XX' ;...
    2890 ['Mask ' par.maskflag];...
    2891 ['MaskName ' par.maskname];...
    2892 ['ImageSize ' par.npx ' ' par.npy];...
    2893 ['CorrelationBoxesSize ' par.ibx ' ' par.iby];...
    2894 ['SearchBoxeSize ' par.ibx ' ' par.iby];...
    2895 ['RO ' par.rho];...
    2896 ['GridSpacing ' par.dx ' ' par.dy];...
    2897 'XX 1.0';...
    2898 ['Dt_TO ' par.Dt ' ' par.T0];...
    2899 ['PixCmXY ' par.pxcmx ' ' par.pxcmy];...
    2900 'XX 1';...
    2901 ['ShiftXY 0 0'];...
    2902 ['Grid ' par.gridflag];...
    2903 ['GridName ' par.gridname];...
    2904 'XX 85';...
    2905 'XX 1.0';...
    2906 'XX 1.0';...
    2907 'Hart 1';...
    2908 ['DecimalShift ' par.decimal];...
    2909 ['Deformation ' par.deformation];...
    2910 'CorrelationMin 0';...
    2911 'IntensityMin 0';...
    2912 'SeuilImage n';...
    2913 'SeuilImageValues 0 4096';...
    2914 ['ImageToUse ' par.term_a ' ' par.term_b];... % VERIFIER ?
    2915 ['ImageUsedBefore ' par.filename_nc1]};
    2916         textout=char(textcmx);
    2917         dlmwrite([filename_cmx '2'] ,textout,'');
    2918         if sge
    2919         cmd_CIV2=[civ2_exe ' -f ' filename_cmx ]; % redirect standard output to the log file
    2920         else
    2921           cmd_CIV2=[civ2_exe ' -f ' filename_cmx ' > ' namelog ' 2>&1']; % redirect standard output to the log file
    2922       end
    2923
    2924
    2925 % --- Executes on button press in HELP.
    2926 function HELP_Callback(hObject, eventdata, handles)
    2927 path_to_uvmat=which ('uvmat');% check the path of uvmat
    2928 pathelp=fileparts(path_to_uvmat);
    2929 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
    2930 if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
    2931 else
    2932 web([helpfile '#civ_3D'])
    2933 end
    2934
    2935
    2936 %----------------------------------------------------------
    2937 %--read images and convert them to the uint16 format used for PIV
    2938 function A=read_image(filename,nom_type,npx,npy,num);
    2939 %npx, npy are the dimensions needed for the raw SMD images
    2940 %num is the view number needed for an avi movie
    2941 if isequal(nom_type,'avi')
    2942     mov=aviread(filename,num);
    2943     A=frame2im(mov(1));
    2944     A=sum(double(A),3);
    2945     A=uint16(A);
    2946 elseif isequal(nom_type,'raw_SMD')
    2947     [fid,message]=fopen(filename,'r');
    2948     B=fread(fid,Inf,'int16',0,'ieee-le');%read 16 bit binary file
    2949     A=(reshape(B,npx,npy))'; %remplissage ligne par ligne avec une matrice colonne ? transposer(uB) pour avoir une matrice ligne
    2950     A=uint16(A);
    2951     fclose(fid);
    2952 else
    2953     A=imread(filename);
    2954     siz=size(A);
    2955     if length(siz)==3;%color images
    2956         A=sum(double(A),3);
    2957     end
    2958     A=uint16(A);
    2959 end
    2960
    2961 %----------------------------------------------------------------
    2962 %Executes on carriage return on the time interval dt
    2963 %----------------------------------------------------------------
    2964 function dt_Callback(hObject, eventdata, handles)
    2965 %determine the set of times and possible intervals for CIV_3D
    2966 %                 answer=inputdlg('time interval between images?');
    2967                 dt=(1/1000)*str2num(get(handles.dt,'String'));
    2968                 nbfield=str2num(get(handles.nb_field,'String')); %last image number selected in the processing series
    2969                 time=(dt*[0:nbfield-1])';
    2970 %                 set(handles.incr_i,'UserData',dt);%store the time interval between successive images
    2971                 set(handles.displ_filebase,'UserData',time); %store the set of times
    2972                 for index=1:min(nbfield-1,200)
    2973                     displ_num(1,index)=1;
    2974                     displ_num(2,index)=1;
    2975                     displ_num(3,index)=-floor(index/2);
    2976                     displ_num(4,index)=ceil(index/2);
    2977                 end
    2978 set(handles.list_pair_civ1,'Value',1);
    2979 set(handles.list_pair_civ1,'UserData',displ_num);
    2980 set(handles.list_pair_civ2,'Value',1);
    2981 %update the list of time intervals
    2982 find_netcpair_civ1(hObject, eventdata, handles)
    2983 find_netcpair_civ2(hObject, eventdata, handles)
    2984
    2985 %-------------------------------------------------------
    2986 function ref_i_Callback(hObject, eventdata, handles)
    2987 mode_list=get(handles.mode,'String');
    2988 mode_value=get(handles.mode,'Value');
    2989 mode=mode_list{mode_value};
    2990 if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Di)')
    2991     find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
    2992 end
    2993 if isequal(mode,'series(Di)') | ...% we do patch2 only
    2994    (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
    2995     find_netcpair_civ2(hObject, eventdata, handles);
    2996 end
    2997
    2998 %----------------------------------------------------
    2999 function ref_j_Callback(hObject, eventdata, handles)
    3000 mode_list=get(handles.mode,'String');
    3001 mode_value=get(handles.mode,'Value');
    3002 mode=mode_list{mode_value};
    3003 if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Dj)')
    3004     find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
    3005 end
    3006 if isequal(mode,'series(Dj)') | ...
    3007    (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
    3008     find_netcpair_civ2(hObject, eventdata, handles);
    3009 end
    3010 %----------------------------------------------------
    3011 % --- Executes on button press in compare.
    3012 function compare_Callback(hObject, eventdata, handles)
    3013 test=get(handles.compare,'Value');
    3014 if test
    3015     filebase=get(handles.displ_filebase,'String');
    3016     browse=get(handles.browse_root,'Userdata');
    3017     browse.nom_type_ima1=browse.nom_type_ima;
    3018     set(handles.browse_root,'UserData',browse);
    3019     set(handles.displ_filebase2,'Visible','On');%mkes the second file input window visible
    3020     set(handles.displ_filebase2,'String',filebase);
    3021     mode_store=get(handles.mode,'String');%get the present 'mode'
    3022     set(handles.compare,'UserData',mode_store);%store the mode display
    3023     set(handles.mode,'Value',1)
    3024     set(handles.mode,'String',{'displacement';'st_pair j1-j2'})
    3025 else
    3026     set(handles.displ_filebase2,'Visible','Off');
    3027     set(handles.displ_filebase2,'String',[]);
    3028     mode_store=get(handles.compare,'UserData');
    3029     set(handles.mode,'String',mode_store)
    3030     set(handles.test_stereo1,'Value',0)
    3031     set(handles.test_stereo2,'Value',0)
    3032 end
    3033 mode_Callback(hObject, eventdata, handles)
    3034
    3035 %-----------------------------------------------------------
    3036 % --- Executes on button press in get_ref_fix1.
    3037 function get_ref_fix1_Callback(hObject, eventdata, handles)
    3038 filebase=get(handles.displ_filebase,'String');
    3039 [FileName, PathName, filterindex] = uigetfile( ...
    3040        {'*.nc', ' (*.nc)';
    3041         '*.nc',  'netcdf files '; ...
    3042         '*.*', 'All Files (*.*)'}, ...
    3043         'Pick a file',filebase);
    3044
    3045 fileinput=[PathName FileName];
    3046 sizf=size(fileinput);
    3047 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
    3048 %[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
    3049 [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
    3050 %filebase=fullfile(RootPath,RootFile);
    3051 % [Pth,FileN]=fileparts(filebasesub);
    3052 % Pth=fileparts(Pth);
    3053 ref.filebase=fullfile(Path,File);
    3054 ref.num_a=stra2num(str_a);
    3055 ref.num_b=stra2num(str_b);
    3056 ref.num1=str2num(field_count);
    3057 ref.num2=str2num(str2);
    3058 browse=[];%initialisation
    3059 if ~isequal(ref.ext,'.nc')
    3060     errordlg('the reference file must be in netcdf format (*.nc)')
    3061     return
    3062 end
    3063 % [path,name]=fileparts(ref.filebase);
    3064 set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
    3065 set(handles.ref_fix1,'UserData',ref)
    3066 menu_field{1}='civ1';
    3067 Data=nc2struct(fileinput,[]);
    3068 if isfield(Data,'patch') & isequal(Data.patch,1)
    3069     menu_field{2}='filter1';
    3070 end
    3071 if isfield(Data,'civ2') & isequal(Data.civ2,1)
    3072     menu_field{3}='civ2';
    3073 end
    3074 if isfield(Data,'patch2') & isequal(Data.patch2,1)
    3075     menu_field{4}='filter2';
    3076 end
    3077 % [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
    3078 % if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
    3079 %          menu_field{2}='filter1';
    3080 % end
    3081 % if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
    3082 %          menu_field{3}='civ2';
    3083 % end
    3084 % if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
    3085 %          menu_field{4}='filter2';
    3086 % end
    3087 set(handles.field_ref1,'String',menu_field);
    3088 set(handles.field_ref1,'Value',length(menu_field));
    3089 set(handles.inf_sup1,'Value',2);
    3090 set(handles.thresh_vel,'String','1');%default threshold
    3091 set(handles.ref_fix1,'Enable','on')
    3092
    3093 %---------------------------------------------------------------
    3094 % --- Executes on button press in get_ref_fix2.
    3095 function get_ref_fix2_Callback(hObject, eventdata, handles)
    3096 if isequal(get(handles.get_ref_fix2,'Value'),1)
    3097     filebase=get(handles.displ_filebase,'String');
    3098     [FileName, PathName, filterindex] = uigetfile( ...
    3099            {'*.nc', ' (*.nc)';
    3100             '*.nc',  'netcdf files '; ...
    3101             '*.*', 'All Files (*.*)'}, ...
    3102             'Pick a file',filebase);
    3103     fileinput=[PathName FileName];
    3104     sizf=size(fileinput);
    3105     if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
    3106     %[filebasesub,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
    3107     [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
    3108 %     [Pth,FileN]=fileparts(filebasesub);
    3109 %     Pth=fileparts(Pth);
    3110     ref.filebase=fullfile(Path,File)
    3111     ref.num_a=stra2num(str_a);
    3112     ref.num_b=stra2num(str_b);
    3113     ref.num1=str2num(field_count);
    3114     ref.num2=str2num(str2);
    3115     browse=[];%initialisation
    3116     if ~isequal(ref.ext,'.nc')
    3117         errordlg('the reference file must be in netcdf format (*.nc)')
    3118         return
    3119     end
    3120 %     [path,name]=fileparts(ref.filebase);
    3121     set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
    3122     set(handles.ref_fix2,'UserData',ref)
    3123     menu_field{1}='civ1';
    3124 %     [cte_detect,vdt,cte_read]=read_netcdf(fileinput,{'patch','civ2','patch2'});
    3125     Data=nc2struct(fileinput,[]);
    3126     if isfield(Data,'patch') & isequal(Data.patch,1)
    3127         menu_field{2}='filter1';
    3128     end
    3129     if isfield(Data,'civ2') & isequal(Data.civ2,1)
    3130         menu_field{3}='civ2';
    3131     end
    3132     if isfield(Data,'patch2') & isequal(Data.patch2,1)
    3133         menu_field{4}='filter2';
    3134     end
    3135
    3136 %     if isequal(cte_detect(1),1) & isequal(cte_read(1),1)
    3137 %              menu_field{2}='filter1';
    3138 %     end
    3139 %     if isequal(cte_detect(2),1) & isequal(cte_read(2),1)
    3140 %              menu_field{3}='civ2';
    3141 %     end
    3142 %     if isequal(cte_detect(3),1) & isequal(cte_read(3),1)
    3143 %              menu_field{4}='filter2';
    3144 %     end
    3145     set(handles.field_ref2,'String',menu_field);
    3146     set(handles.field_ref2,'Value',length(menu_field));
    3147     set(handles.inf_sup2,'Value',2);
    3148     set(handles.thresh_vel2,'String','1');%default threshold
    3149     set(handles.ref_fix2,'Enable','on')
    3150     set(handles.ref_fix2,'Visible','on')
    3151     set(handles.field_ref2,'Visible','on')
    3152 else
    3153     set(handles.ref_fix2,'Visible','off')
    3154     set(handles.field_ref2,'Visible','off')
    3155 end
    3156 %-------------------------------------------------------
    3157
    3158 function ref_fix1_Callback(hObject, eventdata, handles)
    3159     set(handles.inf_sup1,'Value',1);
    3160     set(handles.field_ref1,'Value',1)
    3161     set(handles.field_ref1,'String',{' '})
    3162     set(handles.ref_fix1,'UserData',[]);
    3163     set(handles.ref_fix1,'String','');
    3164     set(handles.thresh_vel1,'String','0');
    3165
    3166
    3167 %------------------------------------------------------
    3168
    3169 function ref_fix2_Callback(hObject, eventdata, handles)
    3170     set(handles.inf_sup2,'Value',1);
    3171     set(handles.field_ref2,'Value',1)
    3172     set(handles.field_ref2,'String',{' '})
    3173     set(handles.ref_fix2,'UserData',[]);
    3174     set(handles.ref_fix2,'String','');
    3175     set(handles.thresh_vel2,'String','0');
    3176
    3177 %--------------------------------------------------------
    3178 % --- Executes on selection change in inf_sup1.
    3179 function inf_sup1_Callback(hObject, eventdata, handles)
    3180
    3181 %--------------------------------------------------------------------------
    3182
    3183
    3184 % --- Executes on selection change in field_ref.
    3185 function field_ref_Callback(hObject, eventdata, handles)
    3186
    3187 %-------------------------------------------------------------------------
    3188
    3189 % --- Executes on selection change in field_ref2.
    3190 function field_ref2_Callback(hObject, eventdata, handles)
    3191
    3192 % -----------------------------------------------------------
    3193 % transform letters to numbers
    3194 %--------------------------------------------
    3195 function numres=stra2num(str)
    3196 numres=double(str)-96;
    3197 if double(str) >= 48 & double(str) <= 57 % = 1 for numbers
    3198     numres=str2num(str);
    3199 end
    3200
    3201
    3202 % --- Executes on button press in test_stereo1.
    3203 function test_stereo1_Callback(hObject, eventdata, handles)
    3204 if isequal(get(handles.test_stereo1,'Value'),0)
    3205     set(handles.subdomain_patch1,'Visible','on')
    3206     set(handles.rho_patch1,'Visible','on')
    3207 else
    3208     set(handles.subdomain_patch1,'Visible','off')
    3209     set(handles.rho_patch1,'Visible','off')
    3210 end
    3211
    3212 % --- Executes on button press in test_stereo2.
    3213 function test_stereo2_Callback(hObject, eventdata, handles)
    3214 if isequal(get(handles.test_stereo2,'Value'),0)
    3215     set(handles.subdomain_patch2,'Visible','on')
    3216     set(handles.rho_patch2,'Visible','on')
    3217 else
    3218     set(handles.subdomain_patch2,'Visible','off')
    3219     set(handles.rho_patch2,'Visible','off')
    3220 end
    3221
    3222 % --- Executes on button press in ImaThreshold.
    3223 function ImaThreshold_Callback(hObject, eventdata, handles)
    3224 if isequal(get(handles.ImaThreshold,'Value'),1)
    3225     set(handles.MinIma,'Visible','on')
    3226     set(handles.MaxIma,'Visible','on')
    3227 else
    3228     set(handles.MinIma,'Visible','off')
    3229     set(handles.MaxIma,'Visible','off')
    3230 end
    3231
    3232
    3233 % --- Executes on button press in ImaThreshold2.
    3234 function ImaThreshold2_Callback(hObject, eventdata, handles)
    3235 if isequal(get(handles.ImaThreshold2,'Value'),1)
    3236     set(handles.MinIma2,'Visible','on')
    3237     set(handles.MaxIma2,'Visible','on')
    3238 else
    3239     set(handles.MinIma2,'Visible','off')
    3240     set(handles.MaxIma2,'Visible','off')
    3241 end
    3242
    3243
    3244
    3245 % --- Executes on button press in Experimental.
    3246 function Experimental_Callback(hObject, eventdata, handles)
    3247
    3248
    3249
    3250 function ibz_Callback(hObject, eventdata, handles)
    3251 % hObject    handle to ibz (see GCBO)
    3252 % eventdata  reserved - to be defined in a future version of MATLAB
    3253 % handles    structure with handles and user data (see GUIDATA)
    3254
    3255 % Hints: get(hObject,'String') returns contents of ibz as text
    3256 %        str2double(get(hObject,'String')) returns contents of ibz as a double
    3257
    3258
    3259 % --- Executes during object creation, after setting all properties.
    3260 function ibz_CreateFcn(hObject, eventdata, handles)
    3261 % hObject    handle to ibz (see GCBO)
    3262 % eventdata  reserved - to be defined in a future version of MATLAB
    3263 % handles    empty - handles not created until after all CreateFcns called
    3264
    3265 % Hint: edit controls usually have a white background on Windows.
    3266 %       See ISPC and COMPUTER.
    3267 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    3268     set(hObject,'BackgroundColor','white');
    3269 end
    3270
    3271
    3272
    3273 function edit74_Callback(hObject, eventdata, handles)
    3274 % hObject    handle to edit74 (see GCBO)
    3275 % eventdata  reserved - to be defined in a future version of MATLAB
    3276 % handles    structure with handles and user data (see GUIDATA)
    3277
    3278 % Hints: get(hObject,'String') returns contents of edit74 as text
    3279 %        str2double(get(hObject,'String')) returns contents of edit74 as a double
    3280
    3281
    3282 % --- Executes during object creation, after setting all properties.
    3283 function edit74_CreateFcn(hObject, eventdata, handles)
    3284 % hObject    handle to edit74 (see GCBO)
    3285 % eventdata  reserved - to be defined in a future version of MATLAB
    3286 % handles    empty - handles not created until after all CreateFcns called
    3287
    3288 % Hint: edit controls usually have a white background on Windows.
    3289 %       See ISPC and COMPUTER.
    3290 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    3291     set(hObject,'BackgroundColor','white');
    3292 end
    3293
    3294
    3295
    3296 function edit75_Callback(hObject, eventdata, handles)
    3297 % hObject    handle to edit75 (see GCBO)
    3298 % eventdata  reserved - to be defined in a future version of MATLAB
    3299 % handles    structure with handles and user data (see GUIDATA)
    3300
    3301 % Hints: get(hObject,'String') returns contents of edit75 as text
    3302 %        str2double(get(hObject,'String')) returns contents of edit75 as a double
    3303
    3304
    3305 % --- Executes during object creation, after setting all properties.
    3306 function edit75_CreateFcn(hObject, eventdata, handles)
    3307 % hObject    handle to edit75 (see GCBO)
    3308 % eventdata  reserved - to be defined in a future version of MATLAB
    3309 % handles    empty - handles not created until after all CreateFcns called
    3310
    3311 % Hint: edit controls usually have a white background on Windows.
    3312 %       See ISPC and COMPUTER.
    3313 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    3314     set(hObject,'BackgroundColor','white');
    3315 end
    3316
    3317
    3318
    3319 function dz_civ1_Callback(hObject, eventdata, handles)
    3320 % hObject    handle to dz_civ1 (see GCBO)
    3321 % eventdata  reserved - to be defined in a future version of MATLAB
    3322 % handles    structure with handles and user data (see GUIDATA)
    3323
    3324 % Hints: get(hObject,'String') returns contents of dz_civ1 as text
    3325 %        str2double(get(hObject,'String')) returns contents of dz_civ1 as a double
    3326
    3327
    3328 % --- Executes during object creation, after setting all properties.
    3329 function dz_civ1_CreateFcn(hObject, eventdata, handles)
    3330 % hObject    handle to dz_civ1 (see GCBO)
    3331 % eventdata  reserved - to be defined in a future version of MATLAB
    3332 % handles    empty - handles not created until after all CreateFcns called
    3333
    3334 % Hint: edit controls usually have a white background on Windows.
    3335 %       See ISPC and COMPUTER.
    3336 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    3337     set(hObject,'BackgroundColor','white');
    3338 end
    3339
    3340