Home > . > uvmat.m

uvmat

PURPOSE ^

'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization

SYNOPSIS ^

function varargout = uvmat(varargin)

DESCRIPTION ^

'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization 
------------------------------------------------------------------------
 function huvmat=uvmat(input)

OUTPUT
 huvmat=current handles of the GUI uvmat.fig

INPUT:
 input: input file name (if character chain), or input image matrix to
 visualize, or Matlab structure representing  netcdf fields (with fields
 ListVarName....)

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
     This open 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 (open UVMAT/COPYING.txt) for more details.
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

 Information stored on the interface:
    'Strings' of all edit boxes and menus: get(handles.Tag,'String')
    'Values' of all menus and toggle buttons: get(handles.Tag,'Value')
     Matlab structure stored as 'UserData' of the figure uvmat.fig,(can be obtained by right mouse click on the interface).
          It contains the following fields:
     - Fixed specifiacation of plotting figures and axes (defined bu uvmat_OpeningFcn) 
          .PosColorbar: [0.8210 0.4710 0.0190 0.4450]; specified position of the colorbar on figures
     - Information read in the documentation open of a series (activated by RootPath_Callback) :
          .XmlData, with fields:
               .Time: matrix of times of the images with index i and j
               .GeometryCalib: [1x1 struct]
     - Information defined from the interface:
           .NewSeries: =1 when the first view of a new field series is displayed, else 0
           .filename:(char string)
           .VelType:(char string) type of velocity field selected
           .VelType_1:(char string)  REMPLACER LE CELL ACTUEL
           .FieldName: (char string) main field selected('image', 'velocity'...)
           .FieldName_1:(char string) second field selected('image', 'velocity'...)
           .CName: (char string)name of the scalar used for vector colors
           .CoordType: (char string) coordinate transform: e.g. 'phys' or 'px'
           .MouseAction: store the current effect of mouse button (create or edit objects)
     - Information on  projection objects
           .Object: {[1x1 struct]}
           .CurrentObjectIndex: index of the projection object .Object currently selected for editing
     -Information on the current field (Field{i})
            .Txt : text information to display (e.g. error message)
            .NbDim: number of dimensions (=0 by default)
            .NbCoord: number of vector components
            .CoordType: expresses the type of coordinate ('px' for image, 'sig' for instruments, or 'phys')
            .dt: time interval for the corresponding image pair
            .Mesh: estimated typical distance between vectors
            .ZMax:
            .ZMin: 
            .X, .Y, .Z: set of vector coordinates 
            .U,.V,.W: corresponding set of vector components
            .F: corresponding set of warning flags
            .FF: corresponding set of false flags, =0 for good vectors
            .C: corresponding values of the scalar used for vector color
             (.X, .Y, .Z,.U,.V,.W,.F,.FF,.C are matlab vectors of the same length,
                     equal to the number of vectors stored in the input open)
            .CName: name of the scalar .C
            .CType: type of the scalar .C, setting how the scalar is obtained (see 'Scalars' below)
            .A image or scalar 
            .AX: vector of dimension 2 representing the first and last values
              of the X coordinates for the image or scalar known on a regular grid,
              or vector of dimension .A for a scaler defined on irregular grid.
            .AY: same as .AX along the Y direction
            .AName: name of the scalar, ='image' for an image

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization
0002 %------------------------------------------------------------------------
0003 % function huvmat=uvmat(input)
0004 %
0005 %OUTPUT
0006 % huvmat=current handles of the GUI uvmat.fig
0007 %
0008 %INPUT:
0009 % input: input file name (if character chain), or input image matrix to
0010 % visualize, or Matlab structure representing  netcdf fields (with fields
0011 % ListVarName....)
0012 %
0013 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0014 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
0015 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0016 %     This open is part of the toolbox UVMAT.
0017 %
0018 %     UVMAT is free software; you can redistribute it and/or modify
0019 %     it under the terms of the GNU General Public License as published by
0020 %     the Free Software Foundation; either version 2 of the License, or
0021 %     (at your option) any later version.
0022 %
0023 %     UVMAT is distributed in the hope that it will be useful,
0024 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
0025 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0026 %     GNU General Public License (open UVMAT/COPYING.txt) for more details.
0027 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0028 %
0029 % Information stored on the interface:
0030 %    'Strings' of all edit boxes and menus: get(handles.Tag,'String')
0031 %    'Values' of all menus and toggle buttons: get(handles.Tag,'Value')
0032 %     Matlab structure stored as 'UserData' of the figure uvmat.fig,(can be obtained by right mouse click on the interface).
0033 %          It contains the following fields:
0034 %     - Fixed specifiacation of plotting figures and axes (defined bu uvmat_OpeningFcn)
0035 %          .PosColorbar: [0.8210 0.4710 0.0190 0.4450]; specified position of the colorbar on figures
0036 %     - Information read in the documentation open of a series (activated by RootPath_Callback) :
0037 %          .XmlData, with fields:
0038 %               .Time: matrix of times of the images with index i and j
0039 %               .GeometryCalib: [1x1 struct]
0040 %     - Information defined from the interface:
0041 %           .NewSeries: =1 when the first view of a new field series is displayed, else 0
0042 %           .filename:(char string)
0043 %           .VelType:(char string) type of velocity field selected
0044 %           .VelType_1:(char string)  REMPLACER LE CELL ACTUEL
0045 %           .FieldName: (char string) main field selected('image', 'velocity'...)
0046 %           .FieldName_1:(char string) second field selected('image', 'velocity'...)
0047 %           .CName: (char string)name of the scalar used for vector colors
0048 %           .CoordType: (char string) coordinate transform: e.g. 'phys' or 'px'
0049 %           .MouseAction: store the current effect of mouse button (create or edit objects)
0050 %     - Information on  projection objects
0051 %           .Object: {[1x1 struct]}
0052 %           .CurrentObjectIndex: index of the projection object .Object currently selected for editing
0053 %     -Information on the current field (Field{i})
0054 %            .Txt : text information to display (e.g. error message)
0055 %            .NbDim: number of dimensions (=0 by default)
0056 %            .NbCoord: number of vector components
0057 %            .CoordType: expresses the type of coordinate ('px' for image, 'sig' for instruments, or 'phys')
0058 %            .dt: time interval for the corresponding image pair
0059 %            .Mesh: estimated typical distance between vectors
0060 %            .ZMax:
0061 %            .ZMin:
0062 %            .X, .Y, .Z: set of vector coordinates
0063 %            .U,.V,.W: corresponding set of vector components
0064 %            .F: corresponding set of warning flags
0065 %            .FF: corresponding set of false flags, =0 for good vectors
0066 %            .C: corresponding values of the scalar used for vector color
0067 %             (.X, .Y, .Z,.U,.V,.W,.F,.FF,.C are matlab vectors of the same length,
0068 %                     equal to the number of vectors stored in the input open)
0069 %            .CName: name of the scalar .C
0070 %            .CType: type of the scalar .C, setting how the scalar is obtained (see 'Scalars' below)
0071 %            .A image or scalar
0072 %            .AX: vector of dimension 2 representing the first and last values
0073 %              of the X coordinates for the image or scalar known on a regular grid,
0074 %              or vector of dimension .A for a scaler defined on irregular grid.
0075 %            .AY: same as .AX along the Y direction
0076 %            .AName: name of the scalar, ='image' for an image
0077 
0078 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   DATA FLOW  (for run0_Callback) %%%%%%%%%%%%%%%%%%%%:
0079 %
0080 %               Main input open   second input open(_1)        second image (pair animation)
0081 % read_ncfield.m         |                 |
0082 % read_image.m           |                 |
0083 %                     Field{1}         Field{2}
0084 %                                                                         |
0085 % coord transform (phys.m) or other user defined  fct acting on Field{i}  |
0086 %                                                                   Field{i}
0087 %                                                                    |
0088 % calc_field.m: calculate scalar or other derived fields (vort, div..).
0089 %
0090 % sub_field.m: combine the input Field{i} in a single set of fields (vector + scalar):
0091 %              Field{i=1->3}.X --> UvData.X                          |
0092 %                                                                    |
0093 %                                                                 UvData
0094 %                                                                    |
0095 % plot histograms of the whole  field
0096 % proj_field.m: project the set of fields on the current projection objects defined by UvData.Object
0097 %                                                                    |                                                                          |
0098 %                                                                ObjectData
0099 %                                                                    |
0100 % plot_field.m: plot the projected fields and store them as user     |
0101 % data of the plotting axes                                          |
0102 %                                                                    |
0103 %                                                                AxeData
0104 %
0105 %%%%%%%%%%%%%%    SCALARS: %%%%%%%%%%%%שש%%%
0106 % scalars are displayed either as an image or countour plot, either as a color of
0107 % velocity vectors. The scalar values in the first case is represented by
0108 % UvData.Field.A, and by UvData.Field.C in the second case. The corresponding set of X
0109 % and Y coordinates are represented by UvData.Field.AX and UvData.Field.AY, and .X and
0110 % .Y for C (the same as velocity vectors). If A is a nxxny matrix (scalar
0111 % on a regtular grid), then .AX andf.AY contains only two elements, represneting the
0112 % coordinates of the four image corners. The scalar name is represented by
0113 % the strings .AName and/or .CName.
0114 % If the scalar exists in an input open (image or scalar stored under its
0115 % name in a netcdf open), it is directly read at the level of Field{1}or Field{2}.
0116 % Else only its name AName is recorded in Field{i}, and its field is then calculated
0117 %by the fuction calc_scal after the coordinate transform or after projection on an edit
0118      
0119 % Properties attached to plotting figures (standard Matlab properties):
0120 %    'CurrentAxes'= gca or get(gcf,'CurrentAxes');
0121 %    'CurrentPoint'=get(gcf,'CurrentPoint'): figure coordinates of the point over which the mouse is positioned
0122 %    'CurrentCharacter'=get(gcf,'CurrentCharacter'): last character typed  over the figure where the mouse is positioned
0123 %    'WindowButtonMotionFcn': function permanently called by mouse motion over the figure
0124 %    'KeyPressFcn': function called by pressing a key on the key board
0125 %    'WindowButtonDownFcn':  function called by pressing the mouse over the  figure
0126 %    'WindowButtonUpFcn': function called by releasing  the mouse pressure over the  figure
0127 
0128 % Properties attached to plotting axes:
0129 %    'CurrentPoint'=get(gca,'CurrentPoint'); (standard Matlab) same as for the figure, but position in plot coordinates.
0130 %     AxeData:=get(gca,'UserData');
0131 %     AxeData.Drawing  = create: create a new edit
0132 %                       = deform: modify an existing edit by moving its defining create
0133 %                      = off: no current drawing action
0134 %                     = translate: translate an existing edit
0135 %                    = zoom: isolate a subregion for zoom in=1 if an edit is being currently drawn, 0 else (set to 0 by releasing mouse button)
0136 %            .hset_edit=handle of the set_edit interface (if a projection edit is edited);
0137 %            .CurrentOrigin: Origin of a curently drawn edit
0138 %            .CurrentLine: currently drawn menuline (A REVOIR)
0139 %            .CurrentObject: handle of the currently drawn edit
0140 %            .CurrentRectZoom: current rectangle used for zoom
0141 %            .zoomon : zoom state (a revoir)
0142 %            .X, .Y, .Z: array of coordinates defining the position of the vector: ASSOCIER AU PLAN (OBJET) PLUTOT QU'A L'AXE ?
0143 %            .U, .V, .W: array of components of the vector
0144 %            .C:
0145 %            .F:
0146 %            .FF:
0147 %            .A
0148 
0149 % Properties attached to projection objects (create, menuline, menuplane...):
0150 %    'Tag'='proj_edit': for all projection objects
0151 %    ObjectData.Style=...: style of projection edit:
0152 %              .ProjMode
0153 %              .Coord: defines the position of the edit
0154 %              .XMin,YMin....
0155 %              .XMax,YMax....
0156 %              .DX,DY,DZ
0157 %              .Phi, .Theta, .Psi : Euler angles
0158 %              .X,.Y,.U,.V.... : field data projected on the edit
0159 %              .IndexObj: index in the list of UvData.Object
0160            %during plotting
0161 %               .plotaxes: handles of the current axes used to plot the  result of field projection on the object
0162 %               .plothandle: vector of handle(s) of the object graphic represnetation in all the opened plotting axes
0163 % To each projection object #iobj, corresponds an axis
0164 % Object{iobj}.plotaxes and nbobj representation graphs  Object{iobj}.plothandles(:) (where nbobj is the
0165 % nbre of current objects opened in uvmat. Note that Object{iobj}.plothandles(iobj)=[] : an object is not represented in its own projection field;
0166 %-------------------------------------------------------------------
0167 %-------------------------------------------------------------------
0168 %  I - MAIN FUNCTION UVMAT (DO NOT MODIFY)
0169 %-------------------------------------------------------------------
0170 %-------------------------------------------------------------------
0171 function varargout = uvmat(varargin)
0172 
0173 % Begin initialization code - DO NOT EDIT
0174 gui_Singleton = 1;
0175 gui_State = struct('gui_Name',          mfilename, ...
0176                    'gui_Singleton',     gui_Singleton, ...
0177                    'gui_OpeningFcn',    @uvmat_OpeningFcn, ...
0178                    'gui_OutputFcn',     @uvmat_OutputFcn, ...
0179                    'gui_LayoutFcn',     [], ...
0180                    'gui_Callback',      []);
0181 if nargin && ischar(varargin{1})
0182     gui_State.gui_Callback = str2func(varargin{1});
0183 end
0184 
0185 if nargout
0186     varargout{1:nargout} = gui_mainfcn(gui_State, varargin{:});
0187 else
0188     gui_mainfcn(gui_State, varargin{:});
0189 end
0190 % End initialization code - DO NOT EDIT
0191 
0192 %-------------------------------------------------------------------
0193 % --- Executes just before uvmat is made visible.
0194 function uvmat_OpeningFcn(hObject, eventdata, handles, input )
0195 %-------------------------------------------------------------------
0196 %WARNING: avoid the second input parameter, leads to erros
0197 global dircur dir_opening
0198 % Choose default command menuline output for uvmat
0199 handles.output = hObject;
0200 
0201 % %group handles for input file in a structure handles.InputFile
0202 % handlesInputFile={handles.RootPath,handles.SubDir,handles.RootFile,handles.FileIndex,handles.FileExt};
0203 % TagsInputFile={'RootPath','SubDir','RootFile','FileIndex','FileExt'};
0204 % handles.InputFile=cell2struct(handlesInputFile,TagsInputFile,2);
0205 %
0206 % %group handles for the second input file in a structure handles.InputFile_1
0207 % handlesInputFile={handles.RootPath_1,handles.SubDir_1,handles.RootFile_1,handles.FileIndex_1,handles.FileExt_1};
0208 % TagsInputFile={'RootPath','SubDir','RootFile','FileIndex','FileExt'};
0209 % handles.InputFile_1=cell2struct(handlesInputFile,TagsInputFile,2);
0210 
0211 % Update handles structure
0212 guidata(hObject, handles);
0213 
0214 dircur=pwd; %current working directory
0215 dir_opening=dircur;
0216 
0217 % set the position of colorbar and ancillary GUIs:
0218 set(hObject,'Units','Normalized')
0219 movegui(hObject,'center')
0220 UvData.PosColorbar=[0.805 0.022 0.019 0.445];
0221 UvData.SetObjectOrigin=[-0.05 -0.03]; %position for set_object
0222 UvData.SetObjectSize=[0.3 0.7];
0223 UvData.CalOrigin=[0.95 -0.03];%position for geometry_calib (TO IMPROVE)
0224 UvData.CalSize=[0.28 1];
0225 
0226 %functions for the mouse and keyboard
0227 set(handles.histo_u,'NextPlot','replacechildren');
0228 set(handles.histo_v,'NextPlot','replacechildren');
0229 set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
0230 set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})%set mouse action functio
0231 set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
0232 set(hObject,'WindowButtonUpFcn',{'mouse_up',handles}) 
0233 %set(hObject,'ResizeFcn',{@resize_uvmat})
0234 
0235 %load the list of previously browsed files in menus Open and Open_1
0236  dir_perso=prefdir;
0237  profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0238  if exist(profil_perso,'file')
0239       h=load (profil_perso);
0240       if isfield(h,'MenuFile_1')
0241           set(handles.MenuFile_1,'Label',h.MenuFile_1);
0242           set(handles.MenuFile_1_1,'Label',h.MenuFile_1);
0243       end
0244       if isfield(h,'MenuFile_1')
0245           set(handles.MenuFile_2,'Label',h.MenuFile_2);
0246           set(handles.MenuFile_2_1,'Label',h.MenuFile_2);
0247       end
0248       if isfield(h,'MenuFile_1')
0249           set(handles.MenuFile_3,'Label',h.MenuFile_3);
0250           set(handles.MenuFile_3_1,'Label',h.MenuFile_3);
0251       end
0252       if isfield(h,'MenuFile_1')
0253           set(handles.MenuFile_4,'Label',h.MenuFile_4);
0254           set(handles.MenuFile_4_1,'Label',h.MenuFile_4);
0255       end
0256       if isfield(h,'MenuFile_1')
0257           set(handles.MenuFile_5,'Label',h.MenuFile_5);
0258           set(handles.MenuFile_5_1,'Label',h.MenuFile_5);
0259      end
0260  end
0261  
0262 %initiates menu of vector colors
0263 list_menu=calc_field;
0264 %list_menu=[{'ima_cor'};{'black'};{'white'};list_menu(3:end)];
0265 set(handles.col_vec,'String',list_menu)
0266 
0267 %check the path and date of modification of all functions in uvmat
0268 path_to_uvmat=which ('uvmat');% check the path detected for source file uvmat
0269 [errormsg,date_str]=check_functions;%check the path of the functions called by uvmat.m
0270 
0271 %check the path of menu_coord transform
0272 %set(handles.menu_coord,'String',{'';'phys';'px';'more...'})
0273 path_fct{1}='';
0274 path_fct{2}=fileparts(path_to_uvmat);
0275 path_fct{3}=fileparts(path_to_uvmat);
0276 path_fct{4}=fileparts(path_to_uvmat);
0277 set(handles.menu_coord,'UserData',path_fct)
0278 
0279 %case of an input argument for uvmat
0280 testinputfield=0;
0281 inputfile=[];
0282 Field=[];
0283 if exist('input','var')
0284     if ~isempty(errormsg)
0285         warndlg_uvmat(errormsg,'WARNING')
0286     end
0287     if ishandle(handles.UVMAT_title)
0288         delete(handles.UVMAT_title)
0289     end   
0290     if isstruct(input)
0291         if isfield(input,'InputFile')
0292             inputfile=input.InputFile;
0293         end
0294         Field=input;
0295     elseif ischar(input)% file name introduced as input
0296            inputfile=input;
0297     elseif isnumeric(input)
0298         sizinput=size(input);
0299         if sizinput(1)<=1 || sizinput(2)<=1
0300             warndlg_uvmat('bad input for uvmat: file name, structure or numerical matrix accepted','ERROR')
0301             return
0302         end
0303         Field.A=input;
0304         Field.AX=[0.5 size(input,2)-0.5];
0305         Field.AY=[size(input,1)-0.5 0.5];
0306     end
0307     if ~isempty(inputfile)
0308         display_file_name(hObject, eventdata, handles,inputfile)
0309         testinputfield=1;
0310     else
0311         UvData.TestInputFile=0;
0312     end
0313     if ~isempty(Field)
0314         set(handles.Fields,'Value',1)
0315         set(handles.Fields,'String',{'get_field...'})
0316 %         set(handles.Fields,'Value',2)% option 'get_field...'
0317         set(handles.Fields,'UserData',Field)
0318         testinputfield=1;
0319         
0320         % set the colorbar position on the interface:
0321         UvData.PosColorbar=[0.805 0.022 0.019 0.445];
0322     elseif ischar(input)
0323         scan_i_Callback(handles.scan_i, eventdata, handles);        
0324     end
0325 else
0326    if ishandle(handles.UVMAT_title)
0327         set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; 'version 2.2.beta';date_str};errormsg]);
0328    end
0329 end
0330 UvData.NewSeries=1;
0331 set(hObject,'UserData',UvData)
0332 if testinputfield
0333     %delete drawn objects
0334     hother=findobj(handles.axes3,'Tag','proj_object');%find all the proj objects
0335     for iobj=1:length(hother)
0336         delete_object(hother(iobj))
0337     end  
0338     if isempty(inputfile)
0339         run0_Callback(hObject, eventdata, handles)
0340         set(handles.MenuTools,'Enable','on')
0341         set(handles.OBJECT_txt,'Visible','on')
0342         set(handles.edit,'Visible','on')
0343         set(handles.list_object,'Visible','on')
0344         set(handles.frame_object,'Visible','on')
0345     else
0346         update_rootinfo(hObject,eventdata,handles);
0347     end
0348 end
0349 set_vec_col_bar(handles)
0350 
0351 %-------------------------------------------------------------------
0352 % --- Outputs from this function are returned to the command menuline.
0353 function varargout = uvmat_OutputFcn(hObject, eventdata, handles)
0354 varargout{1} = handles.output;% the only output argument is the handle to the GUI figure
0355 
0356 %-------------------------------------------------------------------
0357 %-------------------------------------------------------------------
0358 % II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
0359 % automatically sets the global properties when the rootfile name is introduced
0360 % then activate the view-field action if selected
0361 % it is activated either by clicking on the RootPath window or by the
0362 % browser
0363 %------------------------------------------------------------------
0364 %------------------------------------------------------------------
0365 
0366 % --- Executes on the menu Open/Browse...
0367 % search the files, recognize their type according to their name and fill the rootfile input windows
0368 function MenuBrowse_Callback(hObject, eventdata, handles)
0369 oldfile=read_file_boxes(handles);
0370 
0371 if isempty(oldfile)||isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
0372          dir_perso=prefdir;
0373          profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0374          if exist(profil_perso,'file')
0375               h=load (profil_perso);
0376              if isfield(h,'MenuFile_1')
0377                   oldfile=h.MenuFile_1;
0378              end
0379          end
0380 end
0381 [FileName, PathName] = uigetfile( ...
0382        {'*.xml;*.xls;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;*.cmx;*.fig;*.log;*.dat', ' (*.xml,*.xls,*.civ,*.jpg ,*.png, .tif, *.avi,*.nc,*.cmx ,*.fig,*.log,*.dat)';
0383        '*.xml',  '.xml files '; ...
0384         '*.xls',  '.xls files '; ...
0385         '*.civ',  '.civ files '; ...
0386         '*.jpg',' jpeg image files'; ...
0387         '*.png','.png image files'; ...
0388         '*.tif','.tif image files'; ...
0389         '*.avi;*.AVI','.avi movie files'; ...
0390         '*.nc','.netcdf files'; ...
0391         '*.cdf','.netcdf files'; ...
0392         '*.cmx','.cmx text files';...
0393         '*.cmx2','.cmx2 text files';...
0394         '*.fig','.fig files (matlab fig)';...
0395         '*.log','.log text files ';...
0396         '*.dat','.dat text files ';...
0397         '*.*',  'All Files (*.*)'}, ...
0398         'Pick a file',oldfile);
0399 %global filebase
0400 fileinput=[PathName FileName];%complete file name
0401 testblank=findstr(fileinput,' ');%look for blanks
0402 if ~isempty(testblank)
0403     warndlg_uvmat(['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'],'ERROR')
0404     return
0405 end
0406 sizf=size(fileinput);
0407 if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
0408 
0409 % display the selected field and related information
0410 display_file_name(hObject, eventdata, handles,fileinput)
0411 
0412 %update list of recent files in the menubar
0413 MenuFile_1=fileinput;
0414 MenuFile_2=get(handles.MenuFile_1,'Label');
0415 MenuFile_3=get(handles.MenuFile_2,'Label');
0416 MenuFile_4=get(handles.MenuFile_3,'Label');
0417 MenuFile_5=get(handles.MenuFile_4,'Label');
0418 set(handles.MenuFile_1,'Label',MenuFile_1)
0419 set(handles.MenuFile_2,'Label',MenuFile_2)
0420 set(handles.MenuFile_3,'Label',MenuFile_3)
0421 set(handles.MenuFile_4,'Label',MenuFile_4)
0422 set(handles.MenuFile_5,'Label',MenuFile_5)
0423 set(handles.MenuFile_1_1,'Label',MenuFile_1)
0424 set(handles.MenuFile_2_1,'Label',MenuFile_2)
0425 set(handles.MenuFile_3_1,'Label',MenuFile_3)
0426 set(handles.MenuFile_4_1,'Label',MenuFile_4)
0427 set(handles.MenuFile_5_1,'Label',MenuFile_5)
0428 dir_perso=prefdir;
0429 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0430 if exist(profil_perso,'file')
0431     save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
0432 else
0433     txt=ver;
0434     Release=txt(1).Release;
0435     relnumb=str2double(Release(3:4));
0436     if relnumb >= 14
0437         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
0438     else
0439         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
0440     end
0441 end
0442 
0443 % --------------------------------------------------------------------
0444 function MenuFile_1_Callback(hObject, eventdata, handles)
0445 fileinput=get(handles.MenuFile_1,'Label');
0446 display_file_name(hObject, eventdata, handles,fileinput)
0447 
0448 % --------------------------------------------------------------------
0449 function MenuFile_2_Callback(hObject, eventdata, handles)
0450 fileinput=get(handles.MenuFile_2,'Label');
0451 display_file_name(hObject, eventdata, handles,fileinput)
0452 
0453 % --------------------------------------------------------------------
0454 function MenuFile_3_Callback(hObject, eventdata, handles)
0455 fileinput=get(handles.MenuFile_3,'Label');
0456 display_file_name(hObject, eventdata, handles,fileinput)
0457 
0458 % --------------------------------------------------------------------
0459 function MenuFile_4_Callback(hObject, eventdata, handles)
0460 fileinput=get(handles.MenuFile_4,'Label');
0461 display_file_name(hObject, eventdata, handles,fileinput)
0462 
0463 % --------------------------------------------------------------------
0464 function MenuFile_5_Callback(hObject, eventdata, handles)
0465 fileinput=get(handles.MenuFile_5,'Label');
0466 display_file_name(hObject, eventdata, handles,fileinput)
0467 
0468 %-----------------------------------------------------------------
0469 % fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
0470 %----------------------------------------------------------------
0471 function display_file_name(hObject, eventdata, handles,fileinput)
0472 [RootPath,RootFile,i1,i2,str_a,str_b,ext,NomType,SubDir]=name2display(fileinput);
0473 form=imformats(ext(2:end));%test valid Matlab image formats
0474 if ~isempty(form)
0475     ext_test='.image';
0476     imainfo=imfinfo(fileinput);  
0477     if length(imainfo) >1 %case of image with multiple frames
0478         i1='1'; % set the frame counter to 1 by default
0479         i2='';
0480         str_a='';
0481         str_b='';
0482         NomType='*'; %indicate a set of indexed frames within a single file
0483         [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
0484     end
0485 elseif isequal(lower(ext),'.avi')
0486     ext_test='.image';
0487     i1='1'; % set the frame counter to 1 by default
0488     i2='';
0489     str_a='';
0490     str_b='';
0491     NomType='*'; %indicate a set of indexed frames within a single file
0492     [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
0493 else
0494     ext_test=lower(ext);
0495 end
0496 switch ext_test
0497     case {'.civ','.log','.cmx','.cmx2','.txt'}  %display text file
0498         edit(fileinput)  
0499     case '.fig'                           %display matlab figure
0500         hfig=open(fileinput);
0501         set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
0502         set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
0503         set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
0504     case {'.xml','.xls'}                % edit xml or Excel files
0505        editxml(fileinput);
0506     case {'.avi','.image','.vol','.nc','.cdf'}    
0507         set(handles.RootPath,'String',RootPath);
0508         if  isequal(SubDir,'')
0509             rootname=fullfile(RootPath,RootFile);
0510         else
0511             rootname=fullfile(RootPath,SubDir,RootFile);
0512             SubDir=['/' SubDir]; %display the separator
0513         end
0514         set(handles.SubDir,'String',SubDir);
0515         set(handles.RootFile,'String',['/' RootFile]); %display the separator
0516         indices=fileinput(length(rootname)+1:end);
0517         indices(end-length(ext)+1:end)=[]; %remove extension
0518         set(handles.FileIndex,'String',indices);        
0519         set(handles.FileIndex,'UserData',NomType);
0520         set(handles.FileExt,'String',ext);
0521         % fill file index counters
0522         set(handles.i1,'String',i1);
0523       
0524         set(handles.i2,'String',i2);
0525         set(handles.j1,'String',str_a);
0526         set(handles.j2,'String',str_b);
0527         
0528         % synchronise indices of the second  input file if it exists
0529         if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers
0530             [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
0531             NomType_1=get(handles.FileIndex_1,'UserData');     
0532             [FileName_1,idetect]=name_generator(FileBase_1,stra2num(i1),stra2num(i2),FileExt_1,NomType_1,1,stra2num(str_a),stra2num(str_b),SubDir_1);
0533             if idetect
0534                 FileIndex_1=name_generator('',stra2num(i1),stra2num(i2),'',NomType_1,1,stra2num(str_a),stra2num(str_b),'');
0535                 set(handles.FileIndex_1,'String',FileIndex_1)
0536             else
0537                 set(handles.SubField,'Value',0)
0538                 SubField_Callback(hObject, eventdata, handles)
0539             end
0540         end  
0541 
0542         %enable other menus
0543         set(handles.MenuOpen_1,'Enable','on')
0544         set(handles.MenuFile_1_1,'Enable','on')
0545         set(handles.MenuFile_2_1,'Enable','on')
0546         set(handles.MenuFile_3_1,'Enable','on')
0547         set(handles.MenuFile_4_1,'Enable','on')
0548         set(handles.MenuFile_5_1,'Enable','on')
0549         set(handles.MenuExport,'Enable','on')
0550         set(handles.MenuExportFigure,'Enable','on')
0551         set(handles.MenuExportMovie,'Enable','on')
0552         set(handles.MenuTools,'Enable','on')
0553         set(handles.OBJECT_txt,'Visible','on')
0554         set(handles.edit,'Visible','on')
0555         set(handles.list_object,'Visible','on')
0556         set(handles.frame_object,'Visible','on')
0557          % initiate input file:
0558         update_rootinfo(hObject,eventdata,handles);  
0559     otherwise
0560         warndlg_uvmat(['invalid input file extension' ext],'ERROR')
0561 end
0562 
0563 %-------------------------------------------------------------------
0564 function RootPath_Callback(hObject,eventdata,handles)
0565 update_rootinfo(hObject,eventdata,handles);
0566 
0567 %-------------------------------------------------------------------
0568 %-- called by action in RootFile edit box
0569 %-------------------------------------------------------------------
0570 function SubDir_Callback(hObject, eventdata, handles)
0571 %refresh the menu of input fields
0572 Fields_Callback(hObject, eventdata, handles);
0573 % refresh the current field
0574 run0_Callback(hObject, eventdata, handles); 
0575 
0576 
0577 %-------------------------------------------------------------------
0578 %-- called by action in RootFile edit box
0579 %-------------------------------------------------------------------
0580 function RootFile_Callback(hObject, eventdata, handles)
0581 update_rootinfo(hObject,eventdata,handles)
0582 
0583 %-------------------------------------------------------------------
0584 %-- called by action in FileIndex edit box
0585 %-------------------------------------------------------------------
0586 function FileIndex_Callback(hObject, eventdata, handles)
0587 NomType_str=get(handles.FileIndex,'String') ;
0588 [P,F,str1,str2,str_a,str_b]=name2display(['xx' NomType_str get(handles.FileExt,'String')]);
0589 % display the new index values on the counters
0590 set(handles.i1,'String',str1); 
0591 set(handles.i2,'String',str2);
0592 set(handles.j1,'String',str_a);
0593 set(handles.j2,'String',str_b);
0594 
0595 %-------------------------------------------------------------------
0596 % -- update information about a new field series (indices to scan, timing, calibration from an xml file, then refresh current plots
0597 %-------------------------------------------------------------------
0598 function update_rootinfo(hObject,eventdata,handles)
0599 global dircur  dir_opening
0600 
0601 set(handles.RootPath,'BackgroundColor',[1 1 0])
0602 drawnow
0603 set(handles.Fields,'UserData',[])% reinialize data from uvmat opening
0604 huvmat=get(handles.RootPath,'parent');
0605 UvData=get(huvmat,'UserData');%huvmat=handles of the uvmat interface
0606 UvData.NewSeries=1; %flag for run0: begin a new series
0607 UvData.TestInputFile=1;
0608 set(handles.fix_pair,'Value',0) % desactivate by default the comp_input '-'input window
0609 %FileIndex_Callback(hObject, eventdata, handles)% update field counters
0610 
0611 [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
0612 if ~exist(FileName,'file')
0613    msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
0614     return
0615 end
0616 nbfield=[];%default
0617 nburst=[];%default
0618 
0619 % read timing and total frame number from the current file (movie files) !! may be overrid by xml file
0620 XmlData.Time=[];%default
0621 XmlData.GeometryCalib=[];%default
0622 TimeUnit=[];%default
0623 testima=0; %test for image input
0624 if isequal(lower(FileExt),'.avi') %.avi file
0625     testima=1;
0626     info=aviinfo([FileBase FileIndices FileExt]);
0627     nbfield=info.NumFrames;
0628     nburst=1;
0629     set(handles.Dt_txt,'String',['Dt=' num2str(1000/info.FramesPerSecond) 'ms']);%display the elementary time interval in millisec
0630     XmlData.Time=[0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond]';
0631     TimeUnit='s';
0632     set(handles.npx,'String',num2str(info.Width));%fills nbre of pixels x box
0633     set(handles.npy,'String',num2str(info.Height));%fills nbre of pixels y box
0634     hhh=which('mmreader');
0635     if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the function is found (recent version of matlab)
0636         UvData.MovieObject=mmreader([FileBase FileIndices FileExt]);
0637     end
0638 elseif ~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol')%&& isequal(NomType,'*')% multi-frame image
0639     testima=1;
0640     if ~isequal(SubDir,'')
0641        RootFile=get(handles.RootFile,'String');
0642         imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]);
0643     else
0644         imainfo=imfinfo([FileBase FileIndices FileExt]);
0645     end
0646     if length(imainfo) >1 %case of image with multiple frames
0647         nbfield=length(imainfo);
0648         nburst=1;
0649     end 
0650     if isfield(UvData,'MovieObject')
0651         UvData=rmfield(UvData,'MovieObject');
0652     end
0653 else 
0654     %set(handles.last_i,'String','');%fills last_field box
0655     set(handles.npx,'String','');%fills nbre of pixels x box
0656     set(handles.npy,'String','');%fills nbre of pixels y box
0657     if isfield(UvData,'MovieObject')
0658         UvData=rmfield(UvData,'MovieObject');
0659     end
0660 end
0661 
0662 % read parameters (time, geometric calibration..) from a documentation file (.xml advised)
0663 filexml=[FileBase '.xml'];
0664 fileciv=[FileBase '.civ'];
0665 warntext='';%default warning message
0666 NbSlice=1;%default
0667 
0668 if exist(filexml,'file')
0669     [XmlData,warntext]=imadoc2struct(filexml);
0670     if ~isempty(warntext)
0671         msgbox_uvmat('WARNING',warntext)
0672     end
0673     if isfield(XmlData,'Camera')
0674         if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
0675             TimeUnit=XmlData.Camera.TimeUnit;
0676         end
0677     end
0678     set(handles.view_xml,'Visible','on')
0679     set(handles.view_xml,'String','view .xml')
0680 elseif exist(fileciv,'file')% if .civ file found
0681     [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
0682     GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
0683     GeometryCalib.Tx=0;
0684     GeometryCalib.Ty=0;
0685     GeometryCalib.Tz=1;
0686     GeometryCalib.dpx=1;
0687     GeometryCalib.dpy=1;
0688     GeometryCalib.sx=1;
0689     GeometryCalib.Cx=0;
0690     GeometryCalib.Cy=0;
0691     GeometryCalib.f=1;
0692     GeometryCalib.kappa1=0;
0693     GeometryCalib.CoordUnit='cm';
0694     XmlData.GeometryCalib=GeometryCalib;
0695     if error==2, warntext=['no file ' FileBase '.civ'];
0696     elseif error==1, warntext='inconsistent number of fields in the .civ file';
0697     end  
0698     set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
0699     set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
0700     set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
0701     set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
0702     set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
0703     set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
0704     set(handles.view_xml,'Visible','on')
0705     set(handles.view_xml,'String','view .civ')
0706 else
0707     set(handles.view_xml,'Visible','off')
0708 end
0709 
0710 % store last index in handles.lat_i and .last_j
0711 
0712 if ~isempty(XmlData.Time)
0713     nbfield=size(XmlData.Time,1);
0714     nburst=size(XmlData.Time,2);   
0715 end
0716 last_i_cell=get(handles.last_i,'String');
0717 if isempty(nbfield)
0718     last_i_cell{1}='';
0719 else
0720     last_i_cell{1}=num2str(nbfield);
0721 end
0722 set(handles.last_i,'String',last_i_cell)
0723 last_j_cell=get(handles.last_j,'String');
0724 if isempty(nburst)
0725      last_j_cell{1}='';
0726 else
0727      last_j_cell{1}=num2str(nburst);
0728 end
0729 set(handles.last_j,'String',last_j_cell);
0730 
0731 % store geometric calibration in UvData
0732 if isfield(XmlData,'GeometryCalib')
0733 GeometryCalib=XmlData.GeometryCalib;
0734 if isempty(GeometryCalib)
0735     set(handles.pxcm,'String','')
0736     set(handles.pycm,'String','')
0737     set(handles.menu_coord,'Value',1); %  no transform by default
0738 else
0739     if (isfield(GeometryCalib,'R')& ~isequal(GeometryCalib.R(2,1),0) & ~isequal(GeometryCalib.R(1,2),0)) |...
0740         (isfield(GeometryCalib,'kappa1')& ~isequal(GeometryCalib.kappa1,0))
0741         set(handles.pxcm,'String','var')
0742         set(handles.pycm,'String','var')
0743     else
0744         pixcmx=GeometryCalib.f*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
0745         pixcmy=GeometryCalib.f*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
0746         set(handles.pxcm,'String',num2str(pixcmx))
0747         set(handles.pycm,'String',num2str(pixcmy))
0748     end
0749     set(handles.menu_coord,'Value',2); % phys transform by default
0750     if isfield(GeometryCalib,'SliceCoord')
0751        siz=size(GeometryCalib.SliceCoord);
0752        if siz(1)>1
0753            NbSlice=siz(1);
0754            set(handles.slices,'Visible','on')
0755            set(handles.slices,'Value',1)
0756        end
0757        set(handles.nb_slice,'String',num2str(NbSlice))
0758        slices_Callback(hObject, eventdata, handles)
0759 %        Coord=UvData.XmlData.GeometryCalib.SliceCoord;
0760 %        ZIndex=num_i1-NbSlice*(floor((num_i1-1)/NbSlice));
0761     end
0762 end
0763 end
0764 
0765 %update the data attached to the uvmat interface
0766 set(handles.nb_slice,'String',num2str(NbSlice)) 
0767 if ~isempty(TimeUnit)
0768     set(handles.time_txt,'String',['time (' TimeUnit ')'])
0769 end
0770 %set(handles.DtUnit,'String',['10^(-3)' TimeUnit])
0771 UvData.TimeUnit=TimeUnit;
0772 UvData.XmlData=XmlData;
0773 UvData.NewSeries=1;
0774 set(huvmat,'UserData',UvData)
0775 
0776 %display warning message
0777 if ~isequal(warntext,'')
0778     warndlg_uvmat(warntext,'WARNING');
0779 end
0780 
0781 % set default options in menu 'Fields'
0782 if testima
0783    set(handles.Fields,'Value',1) % set menu to 'image'
0784    set(handles.Fields,'String',{'image';'get_field...';'velocity';'vort';'div';'more...'})
0785 elseif isequal(FileExt,'.nc')|isequal(FileExt,'.cdf')
0786    Data=nc2struct(FileName,[]);
0787    col_vec=get(handles.col_vec,'String');
0788    if isfield(Data,'absolut_time_T0')
0789        set(handles.Fields,'String',{'image';'get_field...';'velocity';'vort';'div';'more...'})
0790        set(handles.Fields,'Value',3) % set menu to 'velocity'
0791        col_vec{1}='ima_cor';
0792    else
0793        set(handles.Fields,'Value',1) % set menu to 'get_field...
0794        set(handles.Fields,'String',{'get_field...'})
0795        col_vec{1}='get_field...';
0796    end
0797    set(handles.col_vec,'String',col_vec)
0798 else
0799     warndlg_uvmat(['invalid input file extension ' FileExt],'ERROR')
0800     return
0801 end  
0802 
0803 %
0804 
0805 % set index navigation options and refresh plots
0806 set(handles.RootPath,'BackgroundColor',[1 1 1])
0807 drawnow
0808 set_scan_options(hObject, eventdata, handles)
0809 
0810 %-------------------------------------------------------------------
0811 %-- set index navigation options for new series input and refresh plot
0812 %-------------------------------------------------------------------
0813 function set_scan_options(hObject, eventdata, handles)
0814 
0815 %  set the corresponding index navigation options (TO CHECK WITH THE SECOND FIELD)
0816 NomType=get(handles.FileIndex,'UserData');
0817 NomType_1=get(handles.FileIndex_1,'UserData');
0818 state_j='off'; %default
0819 scan_option='i';
0820 switch NomType
0821     case {'_i_j','_i_j1-j2','_i1-i2_j','#_ab'},% two navigation indices
0822         state_j='on';
0823         if exist('nbfield','var') && isequal(nbfield,1)
0824             scan_option='j'; 
0825         else
0826             scan_option='i';                
0827         end 
0828 end
0829 if ~isempty(NomType_1)
0830     switch NomType_1
0831         case {'_i_j','_i_j1-j2','_i1-i2_j','#_ab'},% two navigation indices
0832             state_j='on';
0833             if exist('nbfield','var') && isequal(nbfield,1)
0834                 scan_option='j'; 
0835             else
0836                 scan_option='i';                
0837             end 
0838     end
0839 end
0840 if isequal(scan_option,'i')
0841      set(handles.scan_i,'Value',1)
0842      scan_i_Callback(hObject, eventdata, handles); 
0843 else
0844      set(handles.scan_j,'Value',1)
0845      scan_j_Callback(hObject, eventdata, handles); 
0846 end
0847 set(handles.scan_j,'Visible',state_j)
0848 set(handles.j1,'Visible',state_j)
0849 set(handles.j2,'Visible',state_j)
0850 set(handles.last_j,'Visible',state_j);
0851 set(handles.frame_j,'Visible',state_j);
0852 set(handles.j_text,'Visible',state_j);
0853 
0854 % refresh the mask view if the option is selected
0855 % if isequal(get(handles.mask_test,'Value'),1)
0856 %     set_mask(handles,RootPath,FileBase,NomType,str2num(i1),stra2num(j1))
0857 % end
0858     
0859 % view the field  if the viewfield action is selected and no subfield option
0860 run0_Callback(hObject, eventdata, handles); %view field
0861 
0862 %-------------------------------------------------------------------
0863 function MenuBrowse_1_Callback(hObject, eventdata, handles)
0864 %-------------------------------------------------------------------
0865 huvmat=get(handles.run0,'parent');
0866 UvData=get(huvmat,'UserData');
0867 
0868 RootPath=get(handles.RootPath,'String');
0869 [FileName, PathName, filterindex] = uigetfile( ...
0870        {'*.xml;*.xls;*.civ;*.jpg;*.png;*.avi;*.AVI;*.nc;*.cmx;*.fig;*.log;*.dat', ' (*.xml,*.xls,*.civ, *.jpg,*.png, *.avi,*.nc,*.cmx ,*.fig,*.log,*.dat)';
0871        '*.xml',  '.xml files '; ...
0872         '*.xls',  '.xls files '; ...
0873         '*.civ',  '.civ files '; ...
0874         '*.jpg','.jpg image files'; ...
0875         '*.png','.png image files'; ...
0876         '*.avi;*.AVI','.avi movie files'; ...
0877         '*.nc','.netcdf files'; ...
0878         '*.cdf','.netcdf files'; ...
0879         '*.cmx','.cmx text files';...
0880         '*.cmx2','.cmx2 text files';...
0881         '*.fig','.fig files (matlab fig)';...
0882         '*.log','.log text files ';...
0883         '*.dat','.dat text files ';...
0884         '*.*',  'All Files (*.*)'}, ...
0885         'Pick a file',RootPath);
0886 fileinput_1=[PathName FileName];%complete file name
0887 testblank=findstr(fileinput_1,' ');%look for blanks
0888 if ~isempty(testblank)
0889     warndlg_uvmat(['The input file name ' fileinput_1 ' contains blank character : This is not allowed. Please change name'],'ERROR')
0890     return
0891 end
0892 sizf=size(fileinput_1);
0893 if (~ischar(fileinput_1)|~isequal(sizf(1),1)),return;end
0894 
0895 % refresh the current displayed field
0896 display_file_name_1(hObject,eventdata,handles,fileinput_1)
0897 
0898 %update list of recent files in the menubar
0899 MenuFile_1=fileinput_1;
0900 MenuFile_2=get(handles.MenuFile_1,'Label');
0901 MenuFile_3=get(handles.MenuFile_2,'Label');
0902 MenuFile_4=get(handles.MenuFile_3,'Label');
0903 MenuFile_5=get(handles.MenuFile_4,'Label');
0904 set(handles.MenuFile_1,'Label',MenuFile_1)
0905 set(handles.MenuFile_2,'Label',MenuFile_2)
0906 set(handles.MenuFile_3,'Label',MenuFile_3)
0907 set(handles.MenuFile_4,'Label',MenuFile_4)
0908 set(handles.MenuFile_5,'Label',MenuFile_5)
0909 set(handles.MenuFile_1_1,'Label',MenuFile_1)
0910 set(handles.MenuFile_2_1,'Label',MenuFile_2)
0911 set(handles.MenuFile_3_1,'Label',MenuFile_3)
0912 set(handles.MenuFile_4_1,'Label',MenuFile_4)
0913 set(handles.MenuFile_5_1,'Label',MenuFile_5)
0914 dir_perso=prefdir;
0915 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
0916 if exist(profil_perso,'file')
0917     save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
0918 else
0919     txt=ver;
0920     Release=txt(1).Release;
0921     relnumb=str2num(Release(3:4));
0922     if relnumb >= 14
0923         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
0924     else
0925         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
0926     end
0927 end
0928 
0929 % --------------------------------------------------------------------
0930 function MenuFile_1_1_Callback(hObject, eventdata, handles)
0931 fileinput_1=get(handles.MenuFile_1_1,'Label');
0932 display_file_name_1(hObject,eventdata,handles,fileinput_1)
0933 
0934 % --------------------------------------------------------------------
0935 function MenuFile_2_1_Callback(hObject, eventdata, handles)
0936 fileinput_1=get(handles.MenuFile_2_1,'Label');
0937 display_file_name_1(hObject,eventdata,handles,fileinput_1)
0938 
0939 % --------------------------------------------------------------------
0940 function MenuFile_3_1_Callback(hObject, eventdata, handles)
0941 fileinput_1=get(handles.MenuFile_3_1,'Label');
0942 display_file_name_1(hObject,eventdata,handles,fileinput_1)
0943 
0944 % --------------------------------------------------------------------
0945 function MenuFile_4_1_Callback(hObject, eventdata, handles)
0946 fileinput_1=get(handles.MenuFile_4_1,'Label');
0947 display_file_name_1(hObject,eventdata,handles,fileinput_1)
0948 
0949 % --------------------------------------------------------------------
0950 function MenuFile_5_1_Callback(hObject, eventdata, handles)
0951 fileinput_1=get(handles.MenuFile_5_1,'Label');
0952 display_file_name_1(hObject,eventdata,handles,fileinput_1)
0953 
0954 %-----------------------------------------------------------------
0955 % fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
0956 %----------------------------------------------------------------
0957 function display_file_name_1(hObject,eventdata,handles,fileinput_1)
0958 
0959 %[path,name,ext]=fileparts(fileinput_1);
0960 [RootPath_1,RootFile_1,field_count,str2,str_a,str_b,FileExt_1,NomType_1,SubDir_1]=name2display(fileinput_1);
0961 nbfield_1=1; %default
0962 ext_test=FileExt_1;%default
0963 form=imformats(FileExt_1(2:end));
0964 if ~isempty(form) % if the extension corresponds to an image format recognized by Matlab
0965     imainfo=imfinfo(fileinput_1);  
0966     nbfield_1=length(imainfo);
0967     ext_test='.image';
0968 elseif isequal(lower(FileExt_1),'.avi')
0969     info=aviinfo(fileinput_1);
0970     nbfield_1=info.NumFrames;
0971     ext_test='.image';
0972 end
0973 
0974 %open directly fig or text files
0975 switch ext_test
0976     case {'.civ','.log','.cmx','.cmx2','.txt'}  %display text file
0977         edit(fileinput)  
0978         return
0979     case '.fig'                           %display matlab figure
0980         hfig=open(fileinput);
0981         set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
0982         set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
0983         set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
0984         return
0985     case {'.xml','.xls'}                % edit xml or Excel files
0986        heditxml=editxml(fileinput);
0987        return
0988     case {'.image','.nc','.cdf'}
0989 %         set(handles.FileIndex,'UserData',NomType_1);
0990     otherwise
0991         warndlg_uvmat(['invalid input file extension ' FileExt_1 ' for uvmat'],'ERROR')
0992         return
0993 end
0994 
0995 % test for image series in a single file and synchronise file indices of the two series
0996 if nbfield_1 >1 %case of image with multiple frames
0997     if nbfield_1 < num_i1
0998         warndlg_uvmat('current frame index beyond the input movie length','ERROR')
0999         return
1000     else
1001         NomType_1='*'; %indicate a set of indexed frames within a single file
1002         filename_new=fileinput_1;
1003     end
1004 else  % cases of data files
1005     RootPath=get(handles.RootPath,'String');
1006     RootFile=get(handles.RootFile,'String');
1007     FileBase=fullfile(RootPath,RootFile);
1008     FileBase_1=fullfile(RootPath_1,RootFile_1);
1009     if isequal(FileBase,FileBase_1)
1010         filename_new=fileinput_1;
1011     else        
1012         num_i1=stra2num(get(handles.i1,'String'));%get the current file indices from counters
1013         num_j1=stra2num(get(handles.j1,'String'));
1014         num_i2=stra2num(get(handles.i2,'String'));
1015         num_j2=stra2num(get(handles.j2,'String'));
1016         [filename_new,idetect]=...
1017            name_generator(FileBase_1,num_i1,num_j1,FileExt_1,NomType_1,1,num_i2,num_j2,SubDir_1);%create name with indices synchronised with the first file
1018         indices=''; %default
1019         if ~idetect
1020             warndlg_uvmat('second input file with indices corresponding to the first one does not exist','ERROR')
1021             return
1022         end 
1023     end
1024 end
1025 set(handles.FileIndex,'UserData',NomType_1);
1026 
1027 % make visible and fill the second raw of edit boxes
1028 set(handles.RootPath_1,'Visible','on')
1029 set(handles.RootFile_1,'Visible','on')
1030 set(handles.SubDir_1,'Visible','on');
1031 set(handles.FileIndex_1,'Visible','on');
1032 set(handles.FileExt_1,'Visible','on');
1033 [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
1034 if isequal(FileBase,FileBase_1)
1035     set(handles.RootPath_1,'String','"')
1036     set(handles.RootFile_1,'String','"');
1037 else
1038     set(handles.RootPath_1,'String',RootPath_1)
1039     set(handles.RootFile_1,'String',['/' RootFile_1]);
1040 end 
1041 if  isequal(SubDir_1,'')
1042      set(handles.SubDir_1,'String','');
1043      FileBaseSub_1=FileBase_1;
1044 else  
1045     set(handles.SubDir_1,'String',['/' SubDir_1]);
1046     FileBaseSub_1=fullfile(FileBase_1,SubDir_1);
1047 end
1048 indices=filename_new(length(FileBaseSub_1)+1:end);
1049 indices(end-length(FileExt_1)+1:end)=[]; %remove extension
1050 set(handles.FileIndex_1,'String',indices)
1051 set(handles.FileIndex_1,'UserData',NomType_1)
1052 set(handles.FileExt_1,'String',FileExt_1);
1053 
1054 % default choice of fields
1055 if isequal(ext_test,'.image')
1056    set(handles.Fields_1,'String',{'';'image';'get_field...';'velocity';'vort';'div';'more...'})
1057    set(handles.Fields_1,'Value',2) % set menu to 'image'
1058 elseif isequal(FileExt_1,'.nc')|isequal(FileExt_1,'.cdf')
1059    Data=nc2struct(fileinput_1,[]);
1060    if isfield(Data,'absolut_time_T0')
1061        set(handles.Fields_1,'String',{'';'image';'get_field...';'velocity';'vort';'div';'more...'})
1062        set(handles.Fields_1,'Value',4) % set menu to 'velocity'
1063    else   
1064        set(handles.Fields_1,'Value',2) % set menu to 'get_field...'
1065        set(handles.Fields_1,'String',{'';'get_field...'});
1066    end
1067 end  
1068 set(handles.SubField,'Visible','on')
1069 set(handles.SubField,'Value',1)
1070 RootPath_1_Callback(hObject,eventdata,handles);  
1071 
1072 
1073 %-----------------------------------------------------
1074 function RootPath_1_Callback(hObject,eventdata,handles)
1075 update_rootinfo_1(hObject,eventdata,handles)
1076 
1077 %-------------------------------------------------------------------
1078 function RootFile_1_Callback(hObject, eventdata, handles)
1079 update_rootinfo_1(hObject,eventdata,handles)
1080 %-------------------------------------------------------------------
1081 
1082 %-------------------------------------------------------------------
1083 function update_rootinfo_1(hObject,eventdata,handles) %A REVOIR
1084 
1085 set(handles.RootPath_1,'BackgroundColor',[1 1 0])% indicate active program by yellow color
1086 drawnow
1087 huvmat=get(handles.RootPath,'parent');
1088 UvData=get(huvmat,'UserData');%huvmat=handles of the uvmat interface
1089 UvData.NewSeries=1; %flag for run0: begin a new series
1090 
1091 [FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes_1(handles);
1092 if ~exist(FileName,'file')
1093     msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
1094 end
1095 nbfield_1=[];%default
1096 nburst_1=[];%default
1097 XmlData.Time=[];
1098 XmlData.GeometryCalib=[];%default
1099 TimeUnit=[];
1100 if isfield(UvData,'TimeUnit')
1101     TimeUnit=UvData.TimeUnit;
1102 end
1103 TimeUnit_1=[];
1104 testima=0; %test for image input
1105 if isequal(lower(FileExt),'.avi') %.avi file
1106     testima=1;
1107     info=aviinfo([FileBase FileIndices FileExt]);
1108     nbfield_1=info.NumFrames;
1109     nburst_1=1;
1110     %set(handles.last_i,'String',num2str(info.NumFrames));%fills last_field box
1111     set(handles.Dt_txt,'String',['Dt=' num2str(1000/info.FramesPerSecond) 'ms']);%display the elementary time interval in millisec
1112 %     set(handles.dt,'UserData',info.FramesPerSecond);
1113     time=[0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond]';
1114     npx=get(handles.npx,'String');
1115     npy=get(handles.npy,'String');
1116     if isequal(npx,'') || isequal(npy,'')
1117         set(handles.npx,'String',num2str(info.Width));%fills nbre of pixels x box
1118         set(handles.npy,'String',num2str(info.Height));%fills nbre of pixels y box
1119     end
1120 elseif ~isempty(imformats(FileExt(2:end))) %&& isequal(NomType,'*')% multi-frame image
1121     testima=1;
1122     imainfo=imfinfo([FileBase FileIndices FileExt]);  
1123     if length(imainfo) >1 %case of image with multiple frames
1124         nbfield_1=length(imainfo);
1125         nburst_1=1;
1126         %set(handles.last_i,'String',num2str(length(imainfo)));%fills last_field box
1127     end       
1128 else 
1129     %set(handles.last_i,'String','');%fills last_field box
1130     set(handles.npx,'String','');%fills nbre of pixels x box
1131     set(handles.npy,'String','');%fills nbre of pixels y box
1132 end
1133 
1134 % find scaling parameters
1135 filexml=[FileBase '.xml'];
1136 fileciv=[FileBase '.civ'];
1137 warntext='';%default warning text
1138 if exist(filexml,'file')
1139     [XmlData,warntext]=imadoc2struct(filexml);
1140     if ~isempty(warntext)
1141         msgbox_uvmat('WARNING',warntext)
1142     end
1143     if isfield(XmlData,'Camera')
1144 %         if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
1145 %             NbSlice=XmlData.Camera.NbSlice;
1146 %         end
1147         if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
1148             TimeUnit=XmlData.Camera.TimeUnit;
1149         end
1150     end 
1151 elseif exist(fileciv,'file')% if .civ file found
1152     [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
1153     GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
1154     GeometryCalib.Tx=0;
1155     GeometryCalib.Ty=0;
1156     GeometryCalib.Tz=1;
1157     GeometryCalib.dpx=1;
1158     GeometryCalib.dpy=1;
1159     GeometryCalib.sx=1;
1160     GeometryCalib.Cx=0;
1161     GeometryCalib.Cy=0;
1162     GeometryCalib.f=1;
1163     GeometryCalib.kappa1=0;
1164     GeometryCalib.CoordUnit='cm';
1165     XmlData.GeometryCalib=GeometryCalib;
1166     if error==2, warntext=['no file ' FileBase '.civ'];
1167     elseif error==1, warntext='inconsistent number of fields in the .civ file';
1168     end
1169     
1170     set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
1171     set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
1172     set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
1173     set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
1174     set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
1175     set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
1176 end   
1177 if ~isempty(TimeUnit_1) && ~isequal(TimeUnit_1,TimeUnit)
1178         warndlg_uvmat('the time units for the second series differs from the first one','WARNING')
1179 end
1180         
1181 % store last index in handles.lat_i and .last_j
1182 if ~isempty(XmlData.Time)
1183     nbfield_1=size(XmlData.Time,1);
1184     nburst_1=size(XmlData.Time,2);   
1185 end
1186 last_i_cell=get(handles.last_i,'String');
1187 if isempty(nbfield_1)
1188     last_i_cell{2}='';
1189 else
1190     last_i_cell{2}=num2str(nbfield_1);
1191 end
1192 set(handles.last_i,'String',last_i_cell)
1193 last_j_cell=get(handles.last_j,'String');
1194 if isempty(nburst_1)
1195      last_j_cell{2}='';
1196 else
1197      last_j_cell{2}=num2str(nburst_1);
1198 end
1199 set(handles.last_j,'String',last_j_cell);
1200 if ~isequal(last_i_cell{1},last_i_cell{2}) || ~isequal(last_j_cell{1},last_j_cell{2})
1201         warndlg_uvmat('the numbers of input file of the second series differs from the first one','WARNING')
1202 end
1203 
1204 % store calibration data
1205 GeometryCalib=XmlData.GeometryCalib;
1206 if isempty(GeometryCalib)
1207     if isfield(UvData, 'GeometryCalib_1')
1208         UvData=rmfield(UvData,'GeometryCalib_1');
1209     end
1210 else
1211     UvData.GeometryCalib_1=GeometryCalib;
1212     if (isfield(GeometryCalib,'R')& ~isequal(GeometryCalib.R(2,1),0) & ~isequal(GeometryCalib.R(1,2),0)) |...
1213         (isfield(GeometryCalib,'kappa1')& ~isequal(GeometryCalib.kappa1,0))
1214         set(handles.pxcm,'String','var')
1215         set(handles.pycm,'String','var')
1216     else
1217         pixcmx=GeometryCalib.f*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
1218         pixcmy=GeometryCalib.f*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
1219         set(handles.pxcm,'String',num2str(pixcmx))
1220         set(handles.pycm,'String',num2str(pixcmy))
1221     end
1222 end
1223 UvData.XmlData_1=XmlData;
1224 set(huvmat,'UserData',UvData)%update the data attached to the uvmat interface
1225 
1226 if ~isequal(warntext,'')
1227     warndlg_uvmat(warntext,'WARNING')
1228 end
1229 
1230 set(handles.RootPath_1,'BackgroundColor',[1 1 1])% signa the end the input operation
1231 drawnow
1232 
1233 set_scan_options(hObject, eventdata, handles)
1234 
1235 
1236 %---------------------------------------------------
1237 % switch file index scanning options scan_i and scan_j in an exclusive way
1238 function scan_i_Callback(hObject, eventdata, handles)
1239 %---------------------------------------------------
1240 if get(handles.scan_i,'Value')==1
1241     set(handles.scan_i,'BackgroundColor',[1 1 0])
1242     set(handles.scan_j,'Value',0)
1243     set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
1244 else
1245     set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
1246     set(handles.scan_j,'Value',1)
1247     set(handles.scan_j,'BackgroundColor',[1 1 0])
1248 end
1249 %-------------------------------------------------------------------
1250 %---------------------------------------------------
1251 % switch file index scanning options scan_i and scan_j in an exclusive way
1252 function scan_j_Callback(hObject, eventdata, handles)
1253 %---------------------------------------------------
1254 %-------------------------------------------------------------------
1255 if get(handles.scan_j,'Value')==1
1256     set(handles.scan_j,'BackgroundColor',[1 1 0])
1257     set(handles.scan_i,'Value',0)
1258     set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
1259 else
1260     set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
1261     set(handles.scan_i,'Value',1)
1262     set(handles.scan_i,'BackgroundColor',[1 1 0])
1263 end
1264 
1265 %-------------------------------------------------------------------
1266 function i1_Callback(hObject, eventdata, handles)
1267 %-------------------------------------------------------------------
1268 % [filebase,num1,num_a,num2,num_b,ext,NomType,subdir]=read_input_file(handles);
1269 [FileName,RootPath,filebase,xx,FileExt]=read_file_boxes(handles);
1270 NomType=get(handles.FileIndex,'UserData');
1271 num1=stra2num(get(handles.i1,'String'));
1272 num2=stra2num(get(handles.i2,'String'));
1273 num_a=stra2num(get(handles.j1,'String'));
1274 num_b=stra2num(get(handles.j2,'String'));
1275 indices=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
1276 set(handles.FileIndex,'String',indices)
1277 if get(handles.SubField,'Value')==1
1278     NomType_1=get(handles.FileIndex_1,'String');
1279      FileExt_1=get(handles.FileExt_1,'String');
1280     [P,F,str1,str2,str_a,str_b,Ext,NomType_1]=name2display(['xx' NomType_1 FileExt_1]);
1281      indices=name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,'');
1282      set(handles.FileIndex_1,'String',indices)
1283 end
1284 run0_Callback(hObject, eventdata, handles)
1285 
1286 %-------------------------------------------------------------------
1287 function i2_Callback(hObject, eventdata, handles)
1288 i1_Callback(hObject, eventdata, handles)
1289 %-------------------------------------------------------------------
1290 
1291 %-------------------------------------------------------------------
1292 function j1_Callback(hObject, eventdata, handles)
1293 i1_Callback(hObject, eventdata, handles)
1294 %-------------------------------------------------------------------
1295 
1296 %-------------------------------------------------------------------
1297 function j2_Callback(hObject, eventdata, handles)
1298 i1_Callback(hObject, eventdata, handles)
1299 %-------------------------------------------------------------------
1300 
1301 %-------------------------------------------------------------------
1302 function slices_Callback(hObject, eventdata, handles)
1303 %-------------------------------------------------------------------
1304 if get(handles.slices,'Value')==1
1305     set(handles.slices,'BackgroundColor',[1 1 0])
1306     set(handles.nb_slice,'Visible','on')
1307     set(handles.z_text,'Visible','on')
1308     set(handles.z_index,'Visible','on')
1309     nb_slice_Callback(hObject, eventdata, handles)
1310 %      z=mod(num_i1-1,nbslice)+1;
1311 %         set(handles.z_index,'String',num2str(z))
1312 else
1313     set(handles.nb_slice,'Visible','off')
1314     set(handles.slices,'BackgroundColor',[0.7 0.7 0.7])
1315     set(handles.z_text,'Visible','off')
1316     set(handles.z_index,'Visible','off') 
1317     set(handles.masklevel,'Value',1)
1318     set(handles.masklevel,'String',{'1'})
1319 end
1320 
1321 %-------------------------------------------------------------------
1322 function nb_slice_Callback(hObject, eventdata, handles)
1323 %-------------------------------------------------------------------
1324 num_i1=str2num(get(handles.i1,'String'));
1325 nbslice=str2num(get(handles.nb_slice,'String'));
1326 z=mod(num_i1-1,nbslice)+1;
1327 set(handles.z_index,'String',num2str(z))
1328 for ilist=1:nbslice
1329     list_index{ilist,1}=num2str(ilist);
1330 end   
1331 set(handles.masklevel,'String',list_index)
1332 set(handles.masklevel,'Value',z)
1333 
1334 
1335 %-------------------------------------------------------------------
1336 % --- Executes on button press in view_xml.
1337 function view_xml_Callback(hObject, eventdata, handles)
1338 [FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
1339 option=get(handles.view_xml,'String');
1340 if isequal(option,'view .xml')
1341     FileXml=[FileBase '.xml'];
1342     heditxml=editxml(FileXml);
1343 end
1344 
1345 %-------------------------------------------------------------------
1346 % --- Executes on button press in mask_test.
1347 function mask_test_Callback(hObject, eventdata, handles)
1348 %-------------------------------------------------------------------
1349 if isequal(get(handles.mask_test,'Value'),1)
1350     [FF,RootPath,FileBase]=read_file_boxes(handles);
1351     num_i1=stra2num(get(handles.i1,'String'));
1352     num_j1=stra2num(get(handles.j1,'String'));
1353     %NomType=get(handles.FileIndex,'UserData');
1354     %[xx,xx,i1,i2,j1,j2,ext,NomType,subdir]=name2display(FileName);
1355     currentdir=pwd;  
1356     cd(RootPath);
1357     maskfiles=dir('*_*mask_*.png');%look for a mask file
1358     cd(currentdir);%come back to the working directory
1359     mdetect=0;
1360     if isempty(maskfiles)
1361          warndlg_uvmat('no mask file detected (format ..._xxmask_ii.png needed), use the menu bar Tools/Make mask','ERROR')
1362          return
1363     end
1364     for ilist=1:length(maskfiles)
1365         maskname=maskfiles(ilist).name;% take the first mask file in the list
1366         [rr,ff,x1,x2,xa,xb,xext,Mask.NomType]=name2display(maskname);
1367         [Path2,Name,ext]=fileparts(maskname);
1368         Namedouble=double(Name);
1369         val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1370         ind_mask=findstr('mask',Name);
1371         i=ind_mask-1;
1372         while val(i)==0 & i>0
1373             i=i-1;
1374         end
1375         nbslice(ilist)=str2num(Name(i+1:ind_mask-1)); % number of different masks (slices)
1376     end
1377     if isequal(min(nbslice),max(nbslice))
1378         nbslice=nbslice(1);
1379     else
1380         warndlg_uvmat('several mask sets coexist in the current image directory','ERROR')
1381          return
1382     end
1383     if ~isequal(nbslice,[]) && Name(i)=='_'
1384         Mask.Base=[FileBase Name(i:ind_mask+3)];
1385         [maskname,mdetect]=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);%
1386         if mdetect==1
1387             set(handles.nb_slice,'String',Name(i+1:ind_mask-1));
1388             set(handles.nb_slice,'BackgroundColor',[1 1 0])
1389             set(handles.mask_test,'UserData',Mask);  
1390             set(handles.mask_test,'BackgroundColor',[1 1 0])
1391             if nbslice > 1
1392                 set(handles.slices,'value',1)
1393                 slices_Callback(hObject, eventdata, handles)
1394             end
1395         end
1396     end
1397     if mdetect==0
1398          warndlg_uvmat('no mask file detected (format ..._xxmask_ii.png needed), use the menu bar Tools/Make mask','ERROR')
1399          set(handles.mask_test,'Value',0)
1400          return
1401     end    
1402     update_mask(handles,num_i1,num_j1);
1403 else
1404     MaskData=get(handles.mask_test,'UserData');
1405     if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
1406           delete(MaskData.maskhandle)    
1407     end
1408     set(handles.mask_test,'UserData',[])    
1409     huvmat=get(handles.mask_test,'parent');
1410     UvData=get(huvmat,'UserData');
1411     if isfield(UvData,'MaskName')
1412         UvData=rmfield(UvData,'MaskName');
1413         set(huvmat,'UserData',UvData)
1414     end
1415     set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7])
1416 end
1417 
1418 %-------------------------------------------------------------------
1419 function update_mask(handles,num_i1,num_j1)
1420 %-------------------------------------------------------------------
1421 
1422 MaskData=get(handles.mask_test,'UserData');
1423 if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1424     uistack(MaskData.maskhandle,'top');
1425 end
1426 [MaskName,mdetect]=name_generator(MaskData.Base,num_i1,num_j1,'.png',MaskData.NomType);
1427 huvmat=get(handles.mask_test,'parent');
1428 UvData=get(huvmat,'UserData');
1429 
1430 %update mask image if the mask is new
1431 if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName)) 
1432     UvData.MaskName=MaskName; %update the recorded name on UvData
1433     set(huvmat,'UserData',UvData);
1434     if mdetect==0
1435         if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1436             delete(MaskData.maskhandle)    
1437         end
1438     else
1439         %read mask image
1440         Mask.AName='image';
1441         Mask.A=imread(MaskName);
1442         npxy=size(Mask.A);
1443         Mask.AX=[0.5 npxy(2)-0.5];
1444         Mask.AY=[npxy(1)-0.5 0.5 ];
1445         Mask.CoordType='px';
1446         
1447         %px to phys or other transform on field
1448         menu_transform=get(handles.menu_coord,'String');
1449         choice_value=get(handles.menu_coord,'Value');
1450         transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
1451         if  ~isequal(transform,'') && ~isequal(transform,'px')
1452             if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1453                 Calib=UvData.XmlData.GeometryCalib;
1454                 Mask=feval(transform,Mask,UvData.XmlData);
1455             end
1456         end
1457         flagmask=Mask.A < 200;
1458         
1459         %make brown color image
1460         imflag(:,:,1)=0.9*flagmask;
1461         imflag(:,:,2)=0.7*flagmask;
1462         imflag(:,:,3)=zeros(size(flagmask));
1463         
1464         %update mask image
1465         hmask=[]; %default
1466         if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1467             hmask=MaskData.maskhandle;
1468         end
1469         if ~isempty(hmask)
1470             set(hmask,'CData',imflag)    
1471             set(hmask,'AlphaData',flagmask*0.6)
1472             set(hmask,'XData',Mask.AX);
1473             set(hmask,'YData',Mask.AY);
1474 %             uistack(hmask,'top')
1475         else
1476             axes(handles.axes3)
1477             hold on    
1478             MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*flagmask);
1479 %             set(MaskData.maskhandle,'AlphaData',0.6*flagmask)
1480             set(handles.mask_test,'UserData',MaskData)
1481         end
1482     end
1483 end
1484 
1485 
1486 %-------------------------------------------------------------------
1487 function MenuExportFigure_Callback(hObject, eventdata, handles)
1488 %-------------------------------------------------------------------
1489 huvmat=get(handles.MenuExport,'parent');
1490 UvData=get(huvmat,'UserData');
1491 hfig=figure;
1492 newaxes=copyobj(handles.axes3,hfig);
1493 map=colormap(handles.axes3);
1494 colormap(map);%transmit the current colormap to the zoom fig
1495 colorbar
1496 
1497 %-------------------------------------------------------------------
1498 %-------------------------------------------------------------------
1499 % III - MAIN REFRESH FUNCTIONS : 'FRAME PLOT'
1500 %-------------------------------------------------------------------
1501 %-------------------------------------------------------------------
1502 
1503 %Executes on button press in runplus: make one step forward and call
1504 %run0. The step forward is along the fields series 1 or 2 depending on
1505 %the scan_i and scan_j check box (exclusive each other)
1506 %-------------------------------------------------------------------
1507 function runplus_Callback(hObject, eventdata, handles)
1508 increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
1509 runpm(hObject,eventdata,handles,increment)
1510 
1511 %-------------------------------------------------------------------
1512 %Executes on button press in runmin: make one step backward and call
1513 %run0. The step backward is along the fields series 1 or 2 depending on
1514 %the scan_i and scan_j check box (exclusive each other)
1515 %-------------------------------------------------------------------
1516 function runmin_Callback(hObject, eventdata, handles)
1517 increment=-str2num(get(handles.increment_scan,'String')); %get the field increment d
1518 runpm(hObject,eventdata,handles,increment)
1519 
1520 %-------------------------------------------------------------------
1521 %Executes on button press in runmin: make one step backward and call
1522 %run0. The step backward is along the fields series 1 or 2 depending on
1523 %the scan_i and scan_j check box (exclusive each other)
1524 %-------------------------------------------------------------------
1525 function RunMovie_Callback(hObject, eventdata, handles)
1526 %------------------------------------------------------------------
1527 set(handles.RunMovie,'BackgroundColor',[1 1 0])%paint the command button in yellow
1528 drawnow
1529 increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
1530 set(handles.STOP,'Visible','on')
1531 set(handles.speed,'Visible','on')
1532 set(handles.speed_txt,'Visible','on')
1533 set(handles.RunMovie,'BusyAction','queue')
1534 testavi=0;
1535 huvmat=get(handles.RunMovie,'parent');
1536 UvData=get(huvmat,'UserData');
1537 
1538 while get(handles.speed,'Value')~=0 & isequal(get(handles.RunMovie,'BusyAction'),'queue') % enable STOP command
1539         runpm(hObject,eventdata,handles,increment)
1540         pause(1.02-get(handles.speed,'Value'))% wait for next image
1541 end
1542 if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1543     UvData.aviobj=close(UvData.aviobj);
1544    set(huvmat,'UserData',UvData);
1545 end
1546 set(handles.RunMovie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1547 
1548 %-------------------------------------------------------------------
1549 function STOP_Callback(hObject, eventdata, handles)
1550 %-------------------------------------------------------------------
1551 set(handles.run0,'BusyAction','Cancel')
1552 set(handles.RunMovie,'BusyAction','Cancel')
1553 set(handles.MenuExportMovie,'BusyAction','Cancel')
1554 
1555 
1556 %------------------------------------------------------------------
1557 function runpm(hObject,eventdata,handles,increment)
1558 %------------------------------------------------------------------
1559 %read the data on the current input rootfile(s)
1560 
1561 [FileName,RootPath,filebase,FileIndices,FileExt,subdir]=read_file_boxes(handles);
1562 NomType=get(handles.FileIndex,'UserData');
1563 
1564 num1=stra2num(get(handles.i1,'String'));
1565 num2=stra2num(get(handles.i2,'String'));
1566 num_a=stra2num(get(handles.j1,'String'));
1567 num_b=stra2num(get(handles.j2,'String'));
1568 
1569 sub_value= get(handles.SubField,'Value');
1570 if sub_value ==1
1571     [FileName_1,RootPath_1,filebase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
1572 end   
1573 
1574 comp_input=get(handles.fix_pair,'Value');
1575 if isequal(NomType,'_i1-i2')|isequal(NomType,'_i1-i2_j')
1576     comp_input=1; %impose a fixed pair interval
1577     set(handles.fix_pair,'Value',1)
1578 end
1579 
1580 %case of scanning along the first direction (rootfile numbers)
1581 if get(handles.scan_i,'Value')==1% case of scanning along field numbers
1582      num1=num1+increment;
1583      num2=num2+increment;
1584     if comp_input==0% find a free pair
1585         [filename,idetect,num_i1_out,num_j1_out,num_i2_out,num_j2_out]=...
1586            name_generator(filebase,num1,num_a,FileExt,NomType,0,num2,num_b,subdir);
1587         if idetect==1
1588             num_a=num_j1_out;
1589             num_b=num_j2_out;
1590         end 
1591     end
1592     if sub_value>=2
1593         num_i1=num_i1+increment;
1594         num_i2=num_i2+increment;
1595     end   
1596 else % case of scanning along the second direction (burst numbers)
1597     lastfield_cell=get(handles.last_j,'String'); % get the last field number
1598     lastfield=str2num(lastfield_cell{1});
1599     num_a=num_a+increment;
1600     num_b=num_b+increment;
1601     if sub_value >=2
1602       num_j1=num_j1+increment;
1603       num_j2=num_j2+increment;
1604     elseif ~isempty(lastfield) && num_a>lastfield
1605         num_a=1;
1606         num1=num1+1;
1607         num2=num2+1;
1608     end
1609 end
1610 
1611 % display the new open numbers
1612 set(handles.i1,'String',num2stra(num1,NomType,1)); 
1613 set(handles.i2,'String',num2stra(num2,NomType,1));
1614 set(handles.j1,'String',num2stra(num_a,NomType,2));
1615 set(handles.j2,'String',num2stra(num_b,NomType,2));
1616 [indices]=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
1617 set(handles.FileIndex,'String',indices);
1618 if sub_value ==1
1619     NomType_1=get(handles.FileIndex_1,'UserData');
1620      [indices]=...
1621            name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,'');
1622      set(handles.FileIndex_1,'String',indices);
1623 end
1624 
1625 % refresh plots
1626 run0_Callback(hObject, eventdata, handles); %run
1627 
1628 
1629 %-------------------------------------------------------
1630 % --- Executes on button press in movie_pair.
1631 %-------------------------------------------------------
1632 function movie_pair_Callback(hObject, eventdata, handles)
1633 %initialisation
1634 set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
1635 drawnow
1636 list_fields=get(handles.Fields,'String');% list menu fields
1637 index_fields=get(handles.Fields,'Value');% selected string index
1638 FieldName=list_fields{index_fields}; % selected field
1639 huvmat=get(handles.movie_pair,'parent');
1640 if isequal(FieldName,'image')
1641     run0_Callback(hObject, eventdata, handles)%display the first image
1642     UvData=get(huvmat,'UserData');
1643 else
1644     warndlg_uvmat('an image or movie must be first introduced as input','ERROR')
1645     return
1646 end
1647 [ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
1648 NomType=get(handles.FileIndex,'UserData');
1649 num_i2=str2num(get(handles.i2,'String'));
1650 num_j2=str2num(get(handles.j2,'String'));
1651 if ~isempty(num_j2) 
1652     num_i1=str2num(get(handles.i1,'String'));
1653     [imaname_1,idetect]=name_generator(filebase,num_i1,num_j2,Ext,NomType);
1654     if idetect==0
1655         warndlg_uvmat(['second input open (-)  ' imaname_1 ' not found'],'ERROR');
1656         return
1657     end
1658     set(handles.i2,'String',''); % indicates that the second index i2 is not used
1659 elseif ~isempty(num_i2)
1660     num_j1=str2num(get(handles.j1,'String'));
1661     [imaname_1,idetect]=name_generator(filebase,num_i2,num_j1,Ext,NomType);
1662     if idetect==0
1663         warndlg_uvmat(['second input open (-)  ' imaname_1 ' not found'],'ERROR');
1664         return
1665     end
1666 else   
1667     warndlg_uvmat('a second image index i2 or j2 is needed to show the pair as a movie','ERROR')
1668     return
1669 end 
1670 
1671 %read the second image
1672 Field.AName='image';
1673 % Field.ListDimName={'AY','AX'}; %A FAIRE
1674 % Field.DimValue=[];
1675 % Field.ListVarName={'A'};
1676 Field.AX=UvData.Field.AX;
1677 Field.AY=UvData.Field.AY;
1678 Field.CoordType='px';
1679 [Field.A,error]=read_image(imaname_1,NomType,num_i2);
1680 
1681 
1682 %px to phys or other transform on field
1683 menu_transform=get(handles.menu_coord,'String');
1684 choice_value=get(handles.menu_coord,'Value');
1685 transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
1686 if  ~isequal(transform,'') && ~isequal(transform,'px')
1687     if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1688         Field=feval(transform,Field,UvData.XmlData);
1689     end
1690 end
1691 
1692  % make movie until movie speed is set to 0 or STOP is activated
1693 hima=findobj(handles.axes3,'Tag','ima');% %handles.axes3 =main plotting window (A GENERALISER)
1694 set(handles.STOP,'Visible','on')
1695 set(handles.speed,'Visible','on')
1696 set(handles.speed_txt,'Visible','on')
1697 while get(handles.speed,'Value')~=0 & isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
1698     % read and plot the series of images in non erase mode
1699     set(hima,'CData',Field.A); 
1700     pause(1.02-get(handles.speed,'Value'));% wait for next image
1701     set(hima,'CData',UvData.Field.A);
1702     pause(1.02-get(handles.speed,'Value'));% wait for next image
1703 end
1704 set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1705 
1706 %run0_Callback(hObject, eventdata, handles)
1707 
1708 %-------------------------------------------------------
1709 % --- Executes on button press in run0.
1710 %-------------------------------------------------
1711 function run0_Callback(hObject, eventdata, handles)
1712 
1713 %initialisation
1714 set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
1715 drawnow
1716 abstime=[];
1717 abstime_1=[];
1718 dt=[];
1719 CalibCell={};%default
1720 Field={};
1721 huvmat=get(handles.run0,'parent');
1722 UvData=get(huvmat,'UserData');
1723 if isfield(UvData,'Txt')
1724     UvData=rmfield(UvData,'Txt');%erase previous error message
1725 end
1726 set(handles.run0,'BusyAction','queue');
1727 if ishandle(handles.UVMAT_title) %remove title panel on uvmat
1728     delete(handles.UVMAT_title)
1729 end
1730 
1731 % determine the main input file information for action
1732 TestInputFile=1;%default
1733 if isfield(UvData,'TestInputFile')&& isequal(UvData.TestInputFile,0),
1734     TestInputFile=0;
1735 end
1736 num_i1=[];%default
1737 if TestInputFile
1738     [filename,RootPath,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
1739     if ~exist(filename,'file')
1740         msgbox_uvmat('ERROR',['input file ' filename ' does not exist'])
1741         return
1742     end
1743     num_i1=stra2num(get(handles.i1,'String'));
1744     num_i2=stra2num(get(handles.i2,'String'));
1745     num_j1=stra2num(get(handles.j1,'String'));
1746     num_j2=stra2num(get(handles.j2,'String'));
1747     NomType=get(handles.FileIndex,'UserData');
1748     %update the z position index
1749 %     if isequal(get(handles.nb_slice,'String'),'vol.')%case of volume
1750 %         set(handles.z_index,'String',get(handles.j1,'String'));
1751 %     else
1752     nbslice=str2num(get(handles.nb_slice,'String'));
1753     z_index=mod(num_i1-1,nbslice)+1;
1754     if ~isempty(nbslice)
1755         z_index=mod(num_i1-1,nbslice)+1;
1756         set(handles.z_index,'String',num2str(z_index))
1757         % refresh menu for save_mask if relevant
1758         masknumber=get(handles.masklevel,'String');
1759         if length(masknumber)>=z_index
1760             set(handles.masklevel,'Value',z_index)
1761         end
1762     end
1763 %     end
1764     % choose the main field
1765     testima=0;
1766     if isequal(lower(Ext),'.avi')||isequal(lower(Ext),'.vol')
1767        testima=1; 
1768        FieldName='image';
1769     else 
1770        form=imformats(Ext([2:end]));
1771        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
1772            testima=1;
1773            FieldName='image';
1774        end
1775     end
1776 else
1777     filename=[];
1778     FieldName='get_field...';
1779     testima=0;
1780 end
1781 VelType=[];%default
1782 
1783 if ~testima
1784     list_fields=get(handles.Fields,'String');% list menu fields
1785     index_fields=get(handles.Fields,'Value');% selected string index
1786     FieldName= list_fields{index_fields}; % selected field
1787     if isequal(FieldName,'get_field...')% read the field names on the interface get_field...
1788         VelType=get(handles.Fields,'UserData'); 
1789         Field{1}=get(handles.Fields,'UserData');
1790     else
1791        VelType=setfield(handles);
1792        %enable_transform(handles,'on')% no field transform (possible transform in the GUI get_field)
1793     end
1794 end
1795 
1796 % choose a second field if Subfield option is 'on'
1797 filename_1=[];
1798 VelType_1=[];%default
1799 FieldName_1=[];
1800 scal_color=[];
1801 testvel=0;
1802 testX=0;%default
1803 VelType_1=setfield_1(handles);
1804 sub_value=get(handles.SubField,'Value');
1805 if sub_value==1
1806     filename_1=read_file_boxes_1(handles);
1807     if ~exist(filename_1,'file')
1808         msgbox_uvmat('ERROR',['second file ' filename_1 ' does not exist'])
1809         return
1810     end
1811     NomType_1=get(handles.FileIndex_1,'UserData');
1812     list_fields=get(handles.Fields_1,'String');% list menu fields
1813     index_fields=get(handles.Fields_1,'Value');% selected string index
1814     FieldName_1= list_fields{index_fields}; % selected field
1815     if isequal(VelType_1,'*')% free veltype choice
1816         VelType_1=[];
1817     elseif isequal(VelType_1,'"')% veltype the same as for the first field
1818         if isempty(VelType)
1819             VelType_1=[];
1820         else
1821             VelType_1=VelType;
1822         end
1823     end
1824 end
1825 
1826 % test for keeping the previous stored data if the input files are unchanged
1827 test_keepdata_1=0;%defautl
1828 test_keepdata=0;
1829 if sub_value>=2
1830     if ~isequal(NomType_1,'*')%in cas of a series of files (not avi movie)
1831         if isfield(UvData,'filename_1')& isfield(UvData,'VelType_1') & isfield(UvData,'FieldName_1')
1832             test_keepdata_1= isequal(filename_1,UvData.filename_1)&...
1833                 isequal(VelType_1,UvData.filename_1) & isequal(FieldName_1,UvData.FieldName_1);
1834 
1835         end
1836     end
1837 end
1838 
1839 %read the input field(s)
1840 testima_1=isequal(FieldName_1,'image');
1841 %read images
1842 if  ~isempty(filename) && testima
1843     if isfield(UvData,'MovieObject')
1844         A=read(UvData.MovieObject,num_i1);
1845     else
1846         [A,error]=read_image(filename,NomType,num_i1);
1847         if ~isequal(error,0)
1848             msgbox_uvmat('ERROR',error)
1849             return
1850         end
1851     end 
1852     npxy=size(A);
1853     set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
1854     set(handles.npy,'String',num2str(npxy(1)));
1855     Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
1856     Rangy=[npxy(1)-0.5 0.5]; %
1857     npx=str2num(get(handles.npx,'String'));
1858     npy=str2num(get(handles.npy,'String'));
1859     if isfield(UvData.XmlData,'Time')
1860         abs_time=UvData.XmlData.Time;
1861     end
1862     Field{1}.AName='image';
1863     Field{1}.ListVarName={'AY','AX','A'}; %
1864     if size(A,3)==3;%color
1865         Field{1}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
1866     else
1867         Field{1}.VarDimName={'AY','AX',{'AY','AX'}}; %
1868     end
1869     Field{1}.AY=Rangy;
1870     Field{1}.AX=Rangx;
1871     Field{1}.A=A;
1872     Field{1}.CoordType='px'; %used for mouse_motion
1873     Field{1}.CoordUnit='pixel'; %used for mouse_motion
1874 end
1875 if ~isfield(UvData,'Txt')& ~isempty(filename_1) & testima_1
1876     [A,error]=read_image(filename_1,NomType_1,num_i1);
1877     if ~isequal(error,0)
1878         msgbox_uvmat('ERROR',error)
1879         return
1880     end
1881     npxy=size(A);
1882     set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
1883     set(handles.npy,'String',num2str(npxy(1)));
1884     Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
1885     Rangy=[npxy(1)-0.5 0.5]; %
1886     npx=str2num(get(handles.npx,'String'));
1887     npy=str2num(get(handles.npy,'String'));
1888     if isfield(UvData,'Time')
1889         abs_time=UvData.XmlData.Time;
1890     end
1891     Field{2}.AName='image';
1892     Field{1}.ListVarName={'AY','AX','A'}; %
1893     if size(A,3)==3;%color
1894         Field{1}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
1895     else
1896         Field{1}.VarDimName={'AY','AX',{'AY','AX'}}; %
1897     end
1898     Field{2}.AY=Rangy;
1899     Field{2}.AX=Rangx;
1900     Field{2}.A=A;
1901     Field{2}.CoordType='px'; %used for mouse_motion
1902     Field{2}.CoordUnit='px'; %used for move_mou
1903 end
1904 
1905 %read ncfile(s)
1906 CivStage_1=0;%default
1907 VelType_out_1=[];
1908 InputField={FieldName};
1909 InputField_1={FieldName_1};
1910 if ~isfield(UvData,'Txt') && ((~isempty(filename)&~testima) || (~isempty(filename_1)&~testima_1)) ;
1911     %read the velocity field(s) from netcdf rootfile(s)
1912     list_code=get(handles.col_vec,'String');% list menu fields
1913     index_code=get(handles.col_vec,'Value');% selected string index
1914     scal_color= list_code{index_code(1)}; % selected field
1915     if isequal(FieldName,'velocity')&& ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
1916         InputField=[InputField scal_color];
1917         %ScalName=scal_color;
1918 %     else
1919 %         ScalDisplay='image';
1920 %        % ScalName=FieldName;
1921     end
1922     if isequal(FieldName_1,'velocity') && ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
1923 %         ScalDisplay_1='vec_color';
1924         InputField_1=[InputField_1 scal_color];
1925 %         ScalName_1=scal_color;
1926 %     else
1927 %         ScalDisplay_1='image';
1928 %         ScalName_1=FieldName_1;
1929     end
1930     if ~testima  %read the first nc field
1931         if isequal(FieldName,'get_field...')% read the field names on the interface get_field.
1932             test_detect=0;%default
1933             VelType=get(handles.Fields,'UserData');
1934             hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
1935             if isempty(hget_field)
1936                 hget_field= get_field(filename);%open the get_field GUI
1937             end
1938             test_detect=1;
1939             hhget_field=guidata(hget_field);
1940             set(hhget_field.inputfile,'String',filename)% update the list of input fields in get_field
1941             set(hhget_field.ACTION,'Value',1)% PLOT option selected
1942             set(hhget_field.list_fig,'Value',2)% plotting axes =uvmat selected
1943             [Field{1},errormsg]=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
1944             if ~isempty(errormsg)
1945                 msgbox_uvmat('ERROR',['error in uvmat/run0_Callback/read_get_field: ' errormsg])
1946                 return
1947             end
1948 %             [Field{1},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data          (included in read_get_field
1949 %             Field{1}.VarAttribute=SubField.VarAttribute;
1950             CivStage=0;
1951             VelType_out=[];
1952             %update the display on get_field
1953            
1954 %             set(hhget_field.variables,'Value',1)
1955 %             Tabchar={''};%default
1956 %             Tabcell=[];
1957 %             if isfield(Field{1},'ListGlobalAttribute')& ~isempty(Field{1}.ListGlobalAttribute)
1958 %                 for iline=1:length(Field{1}.ListGlobalAttribute)
1959 %                     Tabcell{iline,1}=Field{1}.ListGlobalAttribute{iline};
1960 %                     if isfield(Field{1}, Field{1}.ListGlobalAttribute{iline})
1961 %                         eval(['val=Field{1}.' Field{1}.ListGlobalAttribute{iline} ';'])
1962 %                         if ischar(val);
1963 %                             Tabcell{iline,2}=val;
1964 %                         else
1965 %                             Tabcell{iline,2}=num2str(val);
1966 %                         end
1967 %                     end
1968 %                     if isequal(Field{1}.ListGlobalAttribute{iline},'Time')
1969 %                         abstime=Field{1}.Time;
1970 %                     end
1971 %                 end
1972 %                 if ~isempty(Tabcell)
1973 %                     Tabchar=cell2tab(Tabcell,'=');
1974 %                     Tabchar=[{''};Tabchar];
1975 %                 end
1976 %             end
1977             %set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
1978         else
1979             %[nxx,UvData.NbDim,cxx,CivStage,abstime,Field{1},VelType_out]...
1980             %    =read_ncfield(filename,VelType,ScalDisplay,ScalName);%
1981             [Field{1},VelType_out]=read_civxdata(filename,InputField,VelType);
1982             if isfield(Field{1},'Txt')
1983                 msgbox_uvmat('ERROR',Field{1}.Txt)
1984                 return
1985             end
1986             CivStage=Field{1}.CivStage;
1987             UvData.NbDim=Field{1}.nb_dim;
1988         end
1989     end
1990     if ~isempty(filename_1) && ~testima_1 %read the second file
1991         if isequal(FieldName_1,'get_field...')% read the field names on the interface get_field.
1992             test_detect=0;%default
1993             hget_field=findobj(allchild(0),'Name','get_field_1');%find the get_field... GUI
1994              if isempty(hget_field)
1995                  hget_field= get_field(filename_1);%open the get_field GUI
1996                  set(hget_field,'name','get_field_1')
1997 %                 enable_transform(handles,'off')% no field transform (possible transform in the GUI get_field)
1998              end
1999             test_detect=1;
2000             hhget_field=guidata(hget_field);%handles of GUI elements in get_field
2001             SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI
2002             [Field{2},var_detect]=nc2struct(filename_1,SubField.ListVarName); %read the corresponding input data
2003             Field{2}.VarAttribute=SubField.VarAttribute;
2004             if isequal(get(hhget_field.menu_coord,'Visible'),'on')
2005                 list_transform=get(hhget_field.menu_coord,'String');
2006                 val_list=get(hhget_field.menu_coord,'Value');
2007                 transf=list_transform{val_list};
2008                 if ~isempty(transf)
2009                     Field{2}=feval(transf,Field{2});
2010                 end
2011             end
2012 %             CivStage_1=0;
2013 %              VelType_out_1=[];
2014             %update the display on get_field
2015             set(hhget_field.inputfile,'String',filename_1)
2016             set(hhget_field.variables,'Value',1)
2017             Tabchar={''};%default
2018             Tabcell=[];
2019             if isfield(Field{2},'ListGlobalAttribute')& ~isempty(Field{2}.ListGlobalAttribute)
2020                 for iline=1:length(Field{2}.ListGlobalAttribute)
2021                     Tabcell{iline,1}=Field{2}.ListGlobalAttribute{iline};
2022                     if isfield(Field{2}, Field{2}.ListGlobalAttribute{iline})
2023                         eval(['val=Field{2}.' Field{2}.ListGlobalAttribute{iline} ';'])
2024                         if ischar(val);
2025                             Tabcell{iline,2}=val;
2026                         else
2027                             Tabcell{iline,2}=num2str(val);
2028                         end
2029                     end
2030                 end
2031                 if ~isempty(Tabcell)
2032                     Tabchar=cell2tab(Tabcell,'=');
2033                     Tabchar=[{''};Tabchar];
2034                 end
2035             end
2036             set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
2037         else
2038             %[nxx,UvData.NbDim,cxx,CivStage_1,abstime_1,Field{2},VelType_out_1]...
2039            %     =read_ncfield(filename_1,VelType_1,ScalDisplay_1,ScalName_1);%TODO:  REPLACE BY read_civxdata
2040             [Field{2},VelType_out_1]=read_civxdata(filename_1,[],VelType_1);
2041             CivStage_1=Field{2}.CivStage;
2042         end
2043         if testima
2044             VelType_out=VelType_out_1;
2045         end
2046     end
2047 end
2048 
2049 %update the display buttons for the first velocity type (first menuline)
2050 veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2051 if testima
2052     %reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
2053     reset_vel_type(veltype_handles)
2054 elseif isempty(VelType)
2055     set_veltype_display(veltype_handles,CivStage)%update the display of available velocity types for the first field
2056     if isempty(VelType_out)
2057         %reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
2058         reset_vel_type(veltype_handles)
2059     else
2060         handle1=eval(['handles.' VelType_out]);
2061         %reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2],handle1)
2062         reset_vel_type(veltype_handles,handle1)
2063     end
2064 end
2065 
2066 %update the display buttons for the second velocity type (second menuline)
2067 veltype_handles_1=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
2068 if testima_1
2069     reset_vel_type(veltype_handles_1)
2070 elseif isempty(VelType_1)
2071     set_veltype_display(veltype_handles_1,CivStage_1)%update the display of available velocity types for the first field
2072     if isempty(VelType_out_1)
2073         reset_vel_type(veltype_handles_1)
2074     else
2075         handle1=eval(['handles.' VelType_out_1 '_1']);
2076         reset_vel_type(veltype_handles_1,handle1)
2077     end
2078 end
2079 
2080 %introduce w as background image by default for a new series (only for nbdim=2)
2081 if ~isfield(UvData,'NewSeries')
2082     UvData.NewSeries=1;
2083 end
2084 %put W as background image by default if NbDim=2:
2085 if ~isfield(UvData,'NbDim')|isempty(UvData.NbDim)|~isequal(UvData.NbDim,3)
2086     if UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W);
2087         set(handles.SubField,'Value',1);
2088         menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
2089         set(handles.RootPath_1,'String','"')
2090         set(handles.RootFile_1,'String','"')
2091         set(handles.SubDir_1,'String','"');
2092         [indices]=name_generator('',num_i1,num_j1,'',NomType,1,num_i2,num_j2,'');
2093         set(handles.FileIndex_1,'String',indices)
2094         set(handles.FileExt_1,'String','"');
2095         set(handles.Fields_1,'Visible','on');
2096         set(handles.Fields_1,'Visible','on');
2097         set(handles.RootPath_1,'Visible','on')
2098         set(handles.RootFile_1,'Visible','on')
2099         set(handles.SubDir_1,'Visible','on');
2100         set(handles.FileIndex_1,'Visible','on');
2101         set(handles.FileExt_1,'Visible','on');
2102         set(handles.Fields_1,'Visible','on');
2103         Field{1}.AName='w';
2104         testscal=1;
2105     end
2106 end           
2107 
2108 %multislice case
2109 if TestInputFile &&(~isfield(UvData,'NbDim') || isequal(UvData.NbDim,2))&&...%2D case
2110       isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')&& isfield(UvData.XmlData.GeometryCalib,'SliceCoord')
2111 %     nbfield2=str2num(get(handles.last_j,'String'));
2112        siz=size(UvData.XmlData.GeometryCalib.SliceCoord);
2113        if siz(1)>1
2114            NbSlice=siz(1);
2115            set(handles.slices,'Visible','on')
2116            set(handles.slices,'Value',1)
2117        else
2118            NbSlice=1;
2119        end
2120        set(handles.nb_slice,'String',num2str(NbSlice))
2121        slices_Callback(hObject, eventdata, handles)
2122        Coord=UvData.XmlData.GeometryCalib.SliceCoord;
2123        ZIndex=num_i1-NbSlice*(floor((num_i1-1)/NbSlice));
2124        Field{1}.Z=ZIndex;
2125 end
2126 
2127 %store the current open names, fields and vel types in uvmat interface
2128 UvData.filename=filename;
2129 UvData.filename_1=filename_1;
2130 UvData.VelType=VelType;
2131 UvData.VelType_1=VelType_1;
2132 UvData.FieldName=FieldName;
2133 UvData.FieldName_1=FieldName_1;
2134 if ~isempty(scal_color)
2135     UvData.CName=scal_color;
2136 end
2137 
2138 %coordinate transform or user fct
2139 XmlData=[];%default
2140 if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
2141     XmlData=UvData.XmlData;
2142 end
2143 XmlData_1=[];%default
2144 if isfield(UvData,'XmlData_1')
2145    XmlData_1=UvData.XmlData_1;
2146 end
2147 menu_transform=get(handles.menu_coord,'String');
2148 choice_value=get(handles.menu_coord,'Value');
2149 transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
2150 
2151 % z index
2152 if TestInputFile
2153     Field{1}.ZIndex=mod(num_i1-1,nbslice)+1;
2154 end
2155 %px to phys or other transform on field
2156 if  ~isequal(transform,'') 
2157     if length(Field)>=2
2158         Field{2}.ZIndex=mod(num_i1-1,nbslice)+1;
2159         [Field{1},Field{2}]=feval(transform,Field{1},XmlData,Field{2},XmlData_1);
2160         if isempty(Field{2})
2161             Field(2)=[];
2162         end
2163     else
2164         Field{1}=feval(transform,Field{1},XmlData);
2165     end
2166 end 
2167 
2168 %calculate scalar
2169 if ~testima && ~isequal(FieldName,'get_field...')%
2170     Field{1}=calc_field(InputField,Field{1});
2171 end
2172 if length(Field)==2 && ~testima_1 && ~isequal(FieldName,'get_field...')
2173     Field{2}=calc_field(InpuField_1,Field{2});
2174 end
2175 
2176 % combine the two input fields (e.g. substract velocity fields)
2177 if length(Field)==2
2178     if ~(isequal(get(handles.movie_pair,'Value'),1) & isequal(FieldName,'image') & isequal(FieldName_1,'image')) %combine fields if not viewing image pairs
2179         UvData.Field=sub_field(UvData,Field); %TO UPDATE FOR MORE GENERAL INPUT
2180     end
2181 else
2182    UvData.Field=Field{1};
2183 end
2184 UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
2185 % test 3D , default projection menuplane and typical mesh (needed to menuopen set_object)
2186 test_x=0;
2187 test_z=0;% test for unstructured z coordinate
2188 UvData.ZMax=0;
2189 UvData.ZMin=0;%default
2190 UvData.Mesh=1; %default
2191 [UvData.Field,errormsg]=check_field_structure(UvData.Field);
2192 if ~isempty(errormsg)
2193     msgbox_uvmat('ERROR',['error in uvmat/run0_Callback/check_field_structure: ' errormsg])
2194     return
2195 end
2196 [CellVarIndex,NbDim,VarType]=find_field_indices(UvData.Field);
2197 [NbDim,imax]=max(NbDim);
2198 if isempty(imax)
2199    DimVarIndex=0;    
2200     coord_x=[];
2201 else
2202     VarIndex=CellVarIndex{imax};
2203     coord_x=VarType{imax}.coord_x;
2204     
2205    % DimVarIndex=DimVarIndex(UvData.Field.VarDimIndex{VarIndex(1)});
2206 end
2207 if isfield(UvData,'NbDim') & ~isempty(UvData.NbDim)
2208     NbDim=UvData.NbDim;
2209 else  
2210     UvData.NbDim=NbDim;
2211 end
2212 if ~isempty(CellVarIndex) & ~isempty(VarType{imax}.coord_x)  & ~isempty(VarType{imax}.coord_y)    %unstructured coordinate z
2213     XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
2214     YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
2215     test_x=1;
2216 elseif isfield(UvData.Field,'X')&isfield(UvData.Field,'Y')
2217     XName='X';
2218     YName='Y';
2219     test_x=1;
2220 end
2221 if test_x
2222     eval(['UvData.XMax=max(UvData.Field.' XName ');'])
2223     eval(['UvData.XMin=min(UvData.Field.' XName ');'])
2224     eval(['UvData.YMax=max(UvData.Field.' YName ');'])
2225     eval(['UvData.YMin=min(UvData.Field.' YName ');'])
2226     eval(['nbvec=length(UvData.Field.' XName ');'])
2227     if NbDim==3%
2228         if ~isempty(CellVarIndex) & ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
2229             ZName=UvData.ListVarName{VarType{imax}.coord_z};
2230             eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
2231             eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
2232             test_z=1;   
2233         elseif isfield(UvData,'Z')% usual civ data
2234             UvData.ZMax=max(UvData.Z);
2235             UvData.ZMin=min(UvData.Z);
2236             test_z=1;
2237         end
2238     end
2239     if isequal(UvData.ZMin,UvData.ZMax)%no z dependency
2240         NbDim=2;
2241         test_z=0;
2242     end    
2243     if test_z
2244          UvData.Mesh=((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)*(UvData.ZMax-UvData.ZMin))/nbvec;% volume per vector
2245          UvData.Mesh=(UvData.Mesh)^(1/3);
2246     else
2247         UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/nbvec);%2D
2248     end
2249 end
2250 %case of structured coordinates
2251 if isfield(UvData.Field,'AX') & isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')
2252     UvData.XMax=max(UvData.Field.AX);
2253     UvData.XMin=min(UvData.Field.AX);
2254     UvData.YMax=max(UvData.Field.AY);
2255     UvData.YMin=min(UvData.Field.AY);
2256     np_A=size(UvData.Field.A);
2257     UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/((np_A(1)-1) * (np_A(2)-1))) ; 
2258 end
2259 if  isempty(coord_x)&~isempty(CellVarIndex)
2260     VarIndex=CellVarIndex{imax}; % list of variable indices
2261     DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
2262     if NbDim==3
2263         nbpoints=UvData.Field.DimValue(DimIndex(1));
2264         %Zvar=DimVarIndex(DimIndex(1));
2265          %Zvar=DimVarIndex(1);
2266          Zvar=VarType{imax}.coord_3;
2267         if Zvar~=0 % z is a dimension variable
2268             ZName=UvData.Field.ListVarName{Zvar};
2269             eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
2270             eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
2271         else
2272             testcoord_z=0;
2273             if length(UvData.Field.VarAttribute)>=VarIndex(1)
2274                 if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_1')%regular grid
2275                     Coord_z=UvData.Field.VarAttribute{VarIndex(1)}.Coord_1;
2276                     UvData.ZMax=max(Coord_z);
2277                     UvData.ZMin=min(Coord_z);
2278                     testcoord_z=1;
2279                 end
2280             end
2281             if ~testcoord_z
2282                   UvData.ZMin=1;
2283                   UvData.ZMax=UvData.Field.DimValue(DimIndex(1));
2284             end
2285         end
2286         UvData.Mesh=(UvData.ZMax-UvData.ZMin)/(nbpoints-1); 
2287     elseif NbDim==2
2288         nbpoints_y=UvData.Field.DimValue(DimIndex(1));       
2289         %Yvar=DimVarIndex(1);
2290         Yvar=VarType{imax}.coord_y;
2291         if Yvar~=0  % x is a dimension variable
2292             YName=UvData.Field.ListVarName{Yvar};
2293             eval(['UvData.YMax=max(UvData.Field.' YName ');'])
2294             eval(['UvData.YMin=min(UvData.Field.' YName ');'])
2295         else
2296             testcoord_y=0;
2297 %             if length(UvData.Field.VarAttribute)>=VarIndex(1)
2298 %                 if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_1') %regular grid
2299 %                     Coord_y=UvData.Field.VarAttribute{VarIndex(1)}.Coord_1;
2300 %                     UvData.YMax=max(Coord_y);
2301 %                     UvData.YMin=min(Coord_y);
2302 %                     testcoord_y=1;
2303 %                 end
2304 %             end
2305             if ~testcoord_y
2306                   UvData.YMin=1;
2307                   UvData.YMax=UvData.Field.DimValue(DimIndex(1));
2308             end
2309         end
2310         DY=(UvData.YMax-UvData.YMin)/(nbpoints_y-1);
2311         nbpoints_x=UvData.Field.DimValue(DimIndex(2));
2312         %Xvar=DimVarIndex(2);
2313         Xvar=VarType{imax}.coord_x;
2314         if Xvar~=0  % x is a dimension variable
2315             XName=UvData.Field.ListVarName{Xvar};
2316             eval(['UvData.XMax=max(UvData.Field.' XName ');'])
2317             eval(['UvData.XMin=min(UvData.Field.' XName ');'])
2318         else
2319             testcoord_x=0;
2320 %             if length(UvData.Field.VarAttribute)>=VarIndex(1)
2321 %                 if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_2') %regular grid
2322 %                     Coord_x=UvData.Field.VarAttribute{VarIndex(1)}.Coord_2;
2323 %                     UvData.XMax=max(Coord_x);
2324 %                     UvData.XMin=min(Coord_x);
2325 %                     testcoord_x=1;
2326 %                 end
2327 %             end
2328             if ~testcoord_x
2329                   UvData.XMin=1;
2330                   UvData.XMax=UvData.Field.DimValue(DimIndex(2));
2331             end
2332         end
2333         DX=(UvData.XMax-UvData.XMin)/(nbpoints_x-1);
2334         UvData.Mesh= sqrt(DX*DY); 
2335     end
2336 end
2337 
2338 %create a default projection menuplane
2339 UvData.Object{1}.Style='plane';%main plotting plane
2340 UvData.Object{1}.ProjMode='projection';%main plotting plane
2341 if ~isfield(UvData.Object{1},'plotaxes')
2342     UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis
2343     set(handles.list_object,'String',{'1-PLANE';'...'});
2344     set(handles.list_object,'Value',1);
2345 end
2346 
2347 %3D case (menuvolume)
2348 if NbDim==3
2349     UvData.Object{1}.NbDim=UvData.NbDim;%test for 3D objects
2350     UvData.Object{1}.RangeZ=UvData.Mesh;%main plotting plane
2351     UvData.Object{1}.Coord(1,3)=(UvData.ZMin+UvData.ZMax)/2;%section at a middle plane chosen
2352     UvData.Object{1}.Phi=0;
2353     UvData.Object{1}.Theta=0;
2354     UvData.Object{1}.Psi=0;
2355     UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR
2356     PlotHandles=get_plot_handles(handles);
2357     ZBounds(1)=UvData.ZMin; %minimum for the Z slider
2358     ZBounds(2)=UvData.ZMax;%maximum for the Z slider
2359     set_object(UvData.Object{1},PlotHandles,ZBounds);
2360     set(handles.list_object,'Value',1);
2361 %multilevel case (single menuplane in a 3D space)
2362 elseif isfield(UvData,'Z')
2363     if isfield(UvData,'CoordType')& isequal(UvData.CoordType,'phys') & isfield(UvData,'XmlData')
2364         XmlData=UvData.XmlData;
2365         if isfield(XmlData,'PlanePos')
2366              UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
2367         end
2368         if isfield(XmlData,'PlaneAngle')
2369             siz=size(XmlData.PlaneAngle);
2370             indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
2371             UvData.Object{1}.Phi=XmlData.PlaneAngle(indangle,1);
2372             UvData.Object{1}.Theta=XmlData.PlaneAngle(indangle,2);
2373             UvData.Object{1}.Psi=XmlData.PlaneAngle(indangle,3);
2374         end
2375     elseif isfield(UvData,'ZIndex')
2376         UvData.Object{1}.ZObject=UvData.ZIndex;
2377     end
2378 end
2379 
2380 %Plot the projections on all existing  projection objects
2381 keeplim=get(handles.FixedLimits,'Value');
2382 %reset the min and max of scalar if only the mask is displayed
2383 if isfield(UvData,'Mask')&~isfield(UvData,'A')
2384     set(handles.MinA,'String','0')
2385     set(handles.MaxA,'String','255')
2386 end
2387 
2388 Object=UvData.Object;
2389 for iobj=1:length(Object)
2390     if ~isempty(Object{iobj})%& isfield(Object{iobj},'plotaxes')& ishandle(Object{iobj}.plotaxes)
2391         %Projeter les champs sur l'objet:*
2392         ObjectData=proj_field(UvData.Field,Object{iobj},iobj);
2393    
2394         %use of mask
2395         if isfield(ObjectData,'NbDim')&isequal(ObjectData.NbDim,2)
2396             if isfield(ObjectData,'Mask') & isfield(ObjectData,'A')
2397                 %if isfield(ProjData,'A') %case of an existing scalar field or image: put the image to 'NaN' behind the mask
2398                  flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2399                  AX=ObjectData.AX;
2400                  AY=ObjectData.AY;
2401                  MaskX=ObjectData.MaskX;
2402                  MaskY=ObjectData.MaskY;
2403                  if ~isequal(MaskX,AX)|~isequal(MaskY,AY)
2404                      nxy=size(flag_mask);
2405                      sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2406                      sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2407                      x_mask=[ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end)]; % pixel x coordinates for image display
2408                      y_mask=[ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end)];% pixel x coordinates for image display
2409                      %project on the positions of the scalar
2410                      npxy=size(ObjectData.A);
2411                      dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2412                      dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2413                      xi=[ObjectData.AX(1):dxy(2):ObjectData.AX(end)];
2414                      yi=[ObjectData.AY(1):dxy(1):ObjectData.AY(end)];      
2415                      [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2416                     flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2417                  end
2418                  AClass=class(ObjectData.A);
2419                  ObjectData.A=flag_mask.*double(ObjectData.A);
2420                  ObjectData.A=feval(AClass,ObjectData.A);
2421                  ind_off=[];
2422                  if isfield(ObjectData,'ListVarName')
2423                       for ilist=1:length(ObjectData.ListVarName)
2424                            if isequal(ObjectData.ListVarName{ilist},'Mask')|isequal(ObjectData.ListVarName{ilist},'MaskX')|isequal(ObjectData.ListVarName{ilist},'MaskY')
2425                                ind_off=[ind_off ilist];
2426                            end
2427                       end
2428                       ObjectData.ListVarName(ind_off)=[];
2429                       ObjectData.VarDimIndex(ind_off)=[];
2430                       ind_off=[];        
2431                       for ilist=1:length(ObjectData.ListDimName)       
2432                            if isequal(ObjectData.ListDimName{ilist},'MaskX')|isequal(ObjectData.ListDimName{ilist},'MaskY')
2433                                ind_off=[ind_off ilist];
2434                            end
2435                       end
2436                       ObjectData.ListDimName(ind_off)=[];
2437                       ObjectData.DimValue(ind_off)=[];
2438                  end
2439             end  
2440         end
2441         if ~isempty(ObjectData)
2442             haxes=[];%default
2443             if isfield(Object{iobj},'plotaxes')
2444                 haxes=Object{iobj}.plotaxes;%axes used for representing the projection on the object
2445             end
2446             PosColorbar=[];%default: no colorbar
2447             if ishandle(haxes) & isequal(get(haxes,'Tag'),'axes3')& isfield(UvData,'PosColorbar')
2448                 PosColorbar=UvData.PosColorbar;%prescribe the colorbar position on the uvmat interface
2449             else
2450                 PosColorbar='*';%default position
2451             end
2452             PlotParam=read_plot_param(handles);%read plotting parameters on the uvmat interface
2453             [PlotType,ScalOut,UvData.Object{iobj}.plotaxes]=plot_field(ObjectData,haxes,PlotParam,keeplim,PosColorbar);
2454             if isequal(PlotType,'none')
2455                 hget_field=findobj(allchild(0),'name','get_field');
2456                 if isempty(hget_field)
2457                     get_field([],ObjectData)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
2458                 else
2459                     msgbox_uvmat('ERROR','The field defined by get_field cannot be plotted')
2460                 end 
2461             end  
2462             UvData.Object{iobj}.PlotParam=ScalOut; %record the plotting parameters
2463         end
2464         
2465     end
2466 end
2467 
2468 %display the updated plotting parameters for the base menuplane
2469 write_plot_param(handles,UvData.Object{1}.PlotParam);% update the display of the plotting parameters
2470 set(huvmat,'UserData',UvData)
2471 
2472 %update the mask
2473 if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
2474    update_mask(handles,num_i1,num_i2);
2475 end
2476 
2477 %prepare the menus of histograms (for the whole menuvolume in 3D case)
2478 menu_histo=(UvData.Field.ListVarName)';
2479 ind_bad=[];
2480 nb_histo=1;
2481 for ivar=1:numel(menu_histo)
2482     if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2483         Role=UvData.Field.VarAttribute{ivar}.Role;
2484         switch Role
2485             case {'coord_x','coord_y','coord_z','dimvar'}
2486                 ind_bad=[ind_bad ivar];
2487             case {'vector_y'}
2488                 nb_histo=nb_histo+1;
2489         end
2490     end
2491     DimCell=UvData.Field.VarDimName{ivar};
2492     DimName='';
2493     if ischar(DimCell)
2494         DimName=DimCell;
2495     elseif iscell(DimCell)&& numel(DimCell)==1
2496         DimName=DimCell{1};
2497     end
2498     if strcmp(DimName,menu_histo{ivar})
2499         ind_bad=[ind_bad ivar];
2500     end
2501 end
2502 menu_histo(ind_bad)=[];
2503 test_v=0;
2504 if ~isempty(menu_histo)
2505     set(handles.histo1_menu,'Value',1)
2506     set(handles.histo1_menu,'String',menu_histo)
2507     histo1_menu_Callback(hObject, eventdata, handles)
2508     if nb_histo > 1
2509         test_v=1;
2510         set(handles.histo2_menu,'Visible','on')
2511         set(handles.histo_v,'Visible','on')
2512         set(handles.histo2_menu,'String',menu_histo)
2513         set(handles.histo2_menu,'Value',2)
2514         histo2_menu_Callback(hObject, eventdata, handles)
2515     end
2516 end
2517 if ~test_v
2518     set(handles.histo2_menu,'Visible','off')
2519     set(handles.histo_v,'Visible','off')
2520     cla(handles.histo_v)
2521     set(handles.histo2_menu,'Value',1)
2522 end
2523 
2524 %display time
2525 testimedoc=0;
2526 if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
2527     if isempty(num_i2)
2528         num_i2=num_i1;
2529     end
2530     if isempty(num_j1)
2531         num_j1=1;
2532     end
2533     if isempty(num_j2)
2534         num_j2=num_j1;
2535     end
2536     siz=size(UvData.XmlData.Time);
2537     if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
2538         abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
2539         dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
2540         testimedoc=1;
2541     end
2542 end
2543 if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
2544     [P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
2545     num_i2=str2num(str2);
2546     if isempty(num_i2)
2547         num_i2=num_i1;
2548     end
2549     num_j1=str2num(str_a);
2550     if isempty(num_j1)
2551         num_j1=1;
2552     end
2553     num_j2=str2num(str_b);
2554     if isempty(num_j2)
2555         num_j2=num_j1;
2556     end
2557     num_i1=str2num(str1);
2558     siz=size(UvData.XmlData_1.Time);
2559     if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
2560         abstime_1=(UvData.XmlData_1.Time(num_i1,num_j1)+UvData.XmlData_1.Time(num_i2,num_j2))/2;%overset the time read from files
2561     end
2562 end
2563 set(handles.abs_time,'String',num2str(abstime,4))
2564 set(handles.abs_time_1,'String',num2str(abstime_1,4))
2565 if testimedoc && isfield(UvData,'dt')
2566     dt=UvData.dt;
2567 end 
2568 if isequal(dt,0)
2569     set(handles.Dt_txt,'String','')
2570 else
2571     if ~(isfield(UvData,'TimeUnit') && ~isempty(UvData.TimeUnit))
2572         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2573     else
2574         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
2575     end
2576 end
2577 set(handles.run0,'BackgroundColor',[1 0 0])
2578 
2579 
2580 
2581 %-------------------------------------------------------------------
2582 % --- translate coordinate to matrix index
2583 %-------------------------------------------------------------------
2584 function [indx,indy]=pos2ind(x0,rangx0,nxy)
2585 indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel
2586 indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2587 
2588 %-------------------------------------------------------------------
2589 % --- Executes on button press in 'FixedLimits'.
2590 %-------------------------------------------------------------------
2591 function FixedLimits_Callback(hObject, eventdata, handles)
2592 test=get(handles.FixedLimits,'Value');
2593 if test
2594     set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2595 else
2596     set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
2597 end
2598 
2599 %-------------------------------------------------------------------
2600 % --- Executes on button press in auto_xy.
2601 function auto_xy_Callback(hObject, eventdata, handles)
2602 test=get(handles.auto_xy,'Value');
2603 if test
2604     set(handles.auto_xy,'BackgroundColor',[1 1 0])
2605     cla(handles.axes3)
2606     update_plot(handles)
2607 else
2608     set(handles.auto_xy,'BackgroundColor',[0.7 0.7 0.7])
2609     update_plot(handles)
2610 %     axis(handles.axes3,'image')
2611 end
2612 
2613 
2614 %-------------------------------------------------------------------
2615 
2616 %-------------------------------------------------------------------
2617 % --- Executes on button press in 'zoom'.
2618 %-------------------------------------------------------------------
2619 function zoom_Callback(hObject, eventdata, handles)
2620 huvmat=get(handles.zoom,'parent');%general input
2621 UvData=get(huvmat,'UserData');
2622 if (get(handles.zoom,'Value') == 1); 
2623     set(handles.zoom,'BackgroundColor',[1 1 0])
2624     set(handles.FixedLimits,'Value',1)% propose by default fixed limits for the plotting axes
2625     set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2626     %UvData.ZoomOn=1;   %test for mouse action
2627 else
2628     set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
2629     %UvData.ZoomOn=0;  %test for mouse action
2630 end
2631 set(huvmat,'UserData',UvData);
2632 
2633 %-------------------------------------------------------------------
2634 %----Executes on button press in 'record': records the current flags of manual correction.
2635 %-------------------------------------------------------------------
2636 function record_Callback(hObject, eventdata, handles)
2637 % [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
2638 filename=read_file_boxes(handles);
2639 AxeData=get(gca,'UserData');
2640 [erread,message]=fileattrib(filename);
2641 if ~isempty(message) & ~isequal(message.UserWrite,1)
2642      msgbox_uvmat('ERROR',['no writting access to ' filename])
2643      return
2644 end
2645 nc=netcdf(filename,'write'); %open netcdf file
2646 result=redef(nc);
2647 if isempty(result), warndlg_uvmat('##Bad redef operation.','ERROR'),end
2648 test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
2649 if ~test_civ2
2650     test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
2651 end 
2652 if test_civ2 % for civ2
2653    
2654     theDim=nc('nb_vectors2') ;% get the number of velocity vectors
2655     nb_vectors2=size(theDim);
2656     var_FixFlag=ncvar('vec2_FixFlag',nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2657     var_FixFlag(1:nb_vectors2)=AxeData.FF;%
2658 elseif test_civ1 % for civ1
2659     
2660     theDim=nc('nb_vectors') ;% get the number of velocity vectors
2661     nb_vectors=size(theDim);
2662      var_FixFlag=ncvar('vec_FixFlag',nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2663     var_FixFlag(1:nb_vectors)=AxeData.FF;%
2664 else
2665     msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
2666 end 
2667 fin=close(nc);
2668 
2669 
2670 
2671 %-------------------------------------------------------------------
2672 %determines the fields to read from the interface
2673 %------------------------------------------------------------------
2674 function [VelType,civ]=setfield(handles)
2675 
2676 VelType=[]; %default
2677 if (get(handles.civ1,'Value') == 1);
2678 %     if isequal(get(handles.civ1,'String'),'civ1')
2679         VelType='civ1';
2680 %     else
2681 %         huvmat=get(handles.civ1,'parent');%general input
2682 %         UvData=get(huvmat,'UserData');
2683 %         if isfield (UvData,'VelType')
2684 %             VelType=UvData.VelType;
2685 %         end
2686 %     end
2687 % interp1
2688 elseif (get(handles.interp1,'Value') == 1);
2689     VelType='interp1';
2690 % filter1
2691 elseif (get(handles.filter1,'Value') == 1); 
2692     VelType='filter1';  
2693 % CIV2
2694 elseif (get(handles.civ2,'Value') == 1);
2695     VelType='civ2';
2696 % interp2
2697 elseif (get(handles.interp2,'Value') == 1); 
2698     VelType='interp2';
2699 % filter2
2700 elseif (get(handles.filter2,'Value') == 1);  
2701     VelType='filter2'; 
2702 end 
2703 
2704 if isequal(get(handles.filter2,'Visible'),'on');
2705     civ=6;
2706 % interp1
2707 elseif isequal(get(handles.interp2,'Visible'),'on');
2708     civ=5;
2709 % filter1
2710 elseif isequal(get(handles.civ2,'Visible'),'on'); 
2711     civ=4;  
2712 % CIV2
2713 elseif isequal(get(handles.filter1,'Visible'),'on');
2714    civ=3;
2715 % interp2
2716 elseif isequal(get(handles.interp1,'Visible'),'on'); 
2717     civ=2;
2718 % filter2
2719 elseif isequal(get(handles.civ1,'Visible'),'on');  
2720     civ=1; 
2721 else
2722     civ=0;
2723 end 
2724 
2725 %-------------------------------------------------------------------
2726 %determines the veltype of the second field to read from the iinterface
2727 %------------------------------------------------------------------
2728 function VelType=setfield_1(handles)
2729 
2730 VelType=[]; %default
2731 if (get(handles.civ1_1,'Value') == 1);
2732     VelType='civ1';
2733 % interp1
2734 elseif (get(handles.interp1_1,'Value') == 1);
2735     VelType='interp1';
2736 % filter1
2737 elseif (get(handles.filter1_1,'Value') == 1); 
2738     VelType='filter1';  
2739 % CIV2
2740 elseif (get(handles.civ2_1,'Value') == 1);
2741     VelType='civ2';
2742 % interp2
2743 elseif (get(handles.interp2_1,'Value') == 1); 
2744     VelType='interp2';
2745 % filter2
2746 elseif (get(handles.filter2_1,'Value') == 1);  
2747     VelType='filter2'; 
2748 end 
2749 
2750 
2751 %---------------------------------------------------
2752 % --- Executes on button press in SubField
2753 function SubField_Callback(hObject, eventdata, handles)
2754 huvmat=get(handles.run0,'parent');
2755 UvData=get(huvmat,'UserData');
2756 if get(handles.SubField,'Value')==0% if the subfield button is desactivated
2757     set(handles.RootPath_1,'String','')
2758     set(handles.RootFile_1,'String','')
2759     set(handles.SubDir_1,'String','');
2760     set(handles.FileIndex_1,'String','');
2761     set(handles.FileExt_1,'String','');
2762     set(handles.RootPath_1,'Visible','off')
2763     set(handles.RootFile_1,'Visible','off')
2764     set(handles.SubDir_1,'Visible','off');
2765     set(handles.FileIndex_1,'Visible','off');
2766     set(handles.FileExt_1,'Visible','off');
2767     set(handles.Fields_1,'Value',1);%set to blank state
2768     set_veltype_display([handles.civ1_1 handles.interp1_1 handles.filter1_1 ...
2769             handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
2770 
2771 %     if isfield(UvData,'Time_1')
2772 %         UvData=rmfield(UvData,'Time_1');
2773 %     end
2774     if isfield(UvData,'XmlData_1')
2775         UvData=rmfield(UvData,'XmlData_1');
2776     end 
2777     set(huvmat,'UserData',UvData);
2778     run0_Callback(hObject, eventdata, handles); %run
2779 end
2780 
2781 % %----------------------------------------------
2782 % %read the data displayed for the input rootfile windows (new)
2783 % %-------------------------------------------------
2784 function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
2785 RootPath=get(handles.RootPath,'String');
2786 FileName=RootPath; %default
2787 SubDir=get(handles.SubDir,'String');
2788 if ~isempty(SubDir) && ~isequal(SubDir,'')
2789     if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
2790         SubDir(1)=[]; %suppress possible / or \ separator
2791     end
2792     FileName=fullfile(RootPath,SubDir);
2793 end
2794 RootFile=get(handles.RootFile,'String');
2795 if ~isempty(RootFile) && ~isequal(RootFile,'')
2796     if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
2797         RootFile(1)=[]; %suppress possible / or \ separator
2798     end
2799     FileName=fullfile(FileName,RootFile);
2800 end
2801 FileBase=fullfile(RootPath,RootFile);
2802 FileIndices=get(handles.FileIndex,'String');
2803 FileExt=get(handles.FileExt,'String');
2804 FileName=[FileName FileIndices FileExt];
2805 
2806 %----------------------------------------------
2807 %read the data displayed for the second input rootfile windows
2808 %-------------------------------------------------
2809 function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
2810 RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
2811 if isequal(RootPath_1,'"'),RootPath_1=get(handles.RootPath,'String'); end;
2812 FileName_1=RootPath_1; %default
2813 SubDir_1=get(handles.SubDir_1,'String');
2814 if isequal(SubDir_1,'"')
2815     SubDir_1=get(handles.SubDir,'String');
2816 end
2817 if ~isempty(SubDir_1) && ~isequal(SubDir_1,'')
2818     if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
2819         SubDir_1(1)=[]; %suppress possible / or \ separator
2820     end
2821     FileName_1=fullfile(RootPath_1,SubDir_1);
2822 end
2823 RootFile_1=get(handles.RootFile_1,'String');
2824 if isequal(RootFile_1,'"'),RootFile_1=get(handles.RootFile,'String'); end;
2825 if ~isempty(RootFile_1) && ~isequal(RootFile_1,'')
2826     if ~(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
2827         RootFile_1(1)=[];%suppress possible / or \ separator
2828     end
2829     FileName_1=fullfile(FileName_1,RootFile_1);
2830 end
2831 FileBase_1=fullfile(RootPath_1,RootFile_1);
2832 FileIndices_1=get(handles.FileIndex_1,'String');
2833 FileExt_1=get(handles.FileExt_1,'String');
2834 if isequal(FileExt_1,'"'),FileExt_1=get(handles.FileExt,'String'); end;
2835 FileName_1=[FileName_1 FileIndices_1 FileExt_1];
2836 
2837 %---------------------------------------------------
2838 % --- Executes on menu selection Fields
2839 function Fields_Callback(hObject, eventdata, handles)
2840 %-------------------------------------------------
2841 huvmat=get(handles.Fields,'parent');
2842 list_fields=get(handles.Fields,'String');% list menu fields
2843 index_fields=get(handles.Fields,'Value');% selected string index
2844 field= list_fields{index_fields(1)}; % selected string
2845 if isequal(field,'get_field...')
2846      veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2847      set_veltype_display(veltype_handles,0) % unvisible civ buttons
2848      filename=read_file_boxes(handles);
2849      hget_field=findobj(allchild(0),'name','get_field');
2850      if ~isempty(hget_field)
2851          delete(hget_field)
2852      end
2853      get_field(filename)
2854     return %no action
2855 end
2856 list_fields=get(handles.Fields_1,'String');% list menu fields
2857 index_fields=get(handles.Fields_1,'Value');% selected string index
2858 field_1= list_fields{index_fields(1)}; % selected string
2859 UvData=get(huvmat,'UserData');
2860 
2861 %read the rootfile input display
2862 FileExt=get(handles.FileExt,'String');
2863 [P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
2864 NomTypeNew=NomType;%default
2865 if isequal(field,'image') 
2866     % transform netc type to the corresponding image type
2867     if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')|| isequal(NomType,'#_ab')|| isequal(NomType,'_i1-i2')
2868         UvData.SubDir=get(handles.SubDir,'String'); %preserve the subdir in memory
2869         if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')|isequal(UvData.SubDir(1),'/'))
2870             UvData.SubDir(1)=[];
2871         end
2872         set(handles.SubDir,'String','')
2873         set(handles.FileExt,'String','.png');
2874         if isequal(NomType,'_i1-i2_j')|isequal(NomType,'_i_j1-j2')
2875             NomTypeNew='_i_j';
2876         elseif isequal(NomType,'#_ab')
2877             NomTypeNew='#a';
2878         elseif isequal(NomType,'_i1-i2')
2879             NomTypeNew='_i';
2880         end  
2881     end
2882     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2883     set_veltype_display(veltype_handles,0) % unvisible civ buttons
2884 else
2885     ext=get(handles.FileExt,'String');
2886     if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
2887          MenuBrowse_Callback(hObject, eventdata, handles)
2888     end
2889     if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
2890         set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
2891         set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
2892         set(handles.interp1,'BackgroundColor',[0.702 0.702 0.702])
2893         set(handles.interp2,'BackgroundColor',[0.702 0.702 0.702])
2894     elseif isequal(field,'more...'); 
2895         set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
2896         set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
2897         str=calc_field;%get the list of available scalars by the function calc_scal
2898         [ind_answer,v] = listdlg('PromptString','Select a file:',...
2899                 'SelectionMode','single',...
2900                 'ListString',str);
2901        % edit the choice in the field and action menu
2902         scalar=cell2mat(str(ind_answer));
2903         menu=update_menu(handles.Fields,scalar);
2904         menu=[{''};menu];
2905         set(handles.Fields_1,'String',menu);% store the selected scalar type
2906     end
2907 end
2908 indices=name_generator('',str2num(str1),str2num(str_a),'',NomTypeNew,1,str2num(str2),str2num(str_b),'');
2909 set(handles.FileIndex,'String',indices)
2910 set(handles.FileIndex,'UserData',NomTypeNew)
2911 %common to Fields_1_Callback
2912 if isequal(field,'image')|isequal(field_1,'image')
2913     set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
2914     set(handles.npy_title,'Visible','on')
2915     set(handles.npx,'Visible','on')
2916     set(handles.npy,'Visible','on')
2917     set(handles.fix_pair,'Value',0)
2918 else
2919     set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
2920     set(handles.npy_title,'Visible','off')
2921     set(handles.npx,'Visible','off')
2922     set(handles.npy,'Visible','off')
2923     set(handles.fix_pair,'Value',1)
2924 end
2925 if isequal(field,'velocity')|isequal(field_1,'velocity');
2926     state_vect='on';
2927 else
2928     state_vect='off';
2929 end 
2930 if ~isequal(field,'velocity')|(~isequal(field_1,'velocity'));
2931     state_scal='on';
2932 else
2933     state_scal='off';
2934 end 
2935 setfield(handles);% update the field structure ('civ1'....)
2936 
2937 if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
2938     run0_Callback(hObject, eventdata, handles)
2939 end
2940 
2941 %---------------------------------------------------
2942 % --- Executes on menu selection Fields
2943 function Fields_1_Callback(hObject, eventdata, handles)
2944 %-------------------------------------------------
2945 huvmat=get(handles.Fields_1,'parent');
2946 list_fields=get(handles.Fields,'String');% list menu fields
2947 index_fields=get(handles.Fields,'Value');% selected string index
2948 field= list_fields{index_fields(1)}; % selected string
2949 list_fields=get(handles.Fields_1,'String');% list menu fields
2950 index_fields=get(handles.Fields_1,'Value');% selected string index
2951 field_1= list_fields{index_fields(1)}; % selected string for the second field
2952 if isequal(field_1,'') %remove second field if 'blank' field is selected
2953     set(handles.SubField,'Value',0)
2954     SubField_Callback(hObject, eventdata, handles)
2955     return
2956 end
2957 UvData=get(huvmat,'UserData');
2958 
2959 %read the rootfile input display
2960 FileExt_prev=get(handles.FileExt_1,'String');
2961 if isempty(FileExt_prev)|isequal(FileExt_prev,'')
2962     FileExt_1=get(handles.FileExt,'String');
2963 else
2964     FileExt_1=FileExt_prev;
2965 end
2966 NomType_1=get(handles.FileIndex_1,'UserData');
2967 if isempty(NomType_1)|isequal(NomType_1,'')
2968     NomType_1=get(handles.FileIndex,'UserData');
2969 end
2970 NomTypeNew=NomType_1;%default
2971 
2972 set(handles.SubField,'Value',1)%introduce second field
2973 if isfield(UvData,'XmlData')
2974     UvData.XmlData_1=UvData.XmlData;
2975 end
2976 set(handles.FileIndex_1,'Visible','on')
2977 set(handles.FileExt_1,'Visible','on')
2978 RootPath_1=get(handles.RootPath_1,'String');
2979 RootFile_1=get(handles.RootFile_1,'String');
2980 if isempty(RootPath_1)|isequal(RootPath_1,'')
2981     set(handles.RootPath_1,'String','"')
2982 end
2983 if isempty(RootFile_1) | isequal(RootFile_1,'')
2984     set(handles.RootFile_1,'String','"')
2985 end
2986 if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
2987     RootFile_1(1)=[];
2988 end
2989 
2990 if isequal(field_1,'get_field...')
2991      veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2992      set_veltype_display(veltype_handles,0) % unvisible civ buttons
2993      filename=read_file_boxes_1(handles);
2994      hget_field=findobj(allchild(0),'name','get_field_1');
2995      if ~isempty(hget_field)
2996          delete(hget_field)
2997      end
2998      hget_field=get_field(filename);
2999      set(hget_field,'name','get_field_1')
3000     return %no action
3001 end
3002 if isequal(field_1,'image') 
3003     % transform netc type to the corresponding image type
3004     set(handles.FileExt_1,'String','.png');
3005     if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')| isequal(NomType_1,'#_ab')| isequal(NomType_1,'_i1-i2')
3006         UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory
3007         set(handles.SubDir_1,'String','')
3008 %         set(handles.FileExt_1,'String','.png');
3009         if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')
3010             NomTypeNew='_i_j';
3011         elseif isequal(NomType_1,'#_ab')
3012             NomTypeNew='#a';
3013         elseif isequal(NomType_1,'_i1-i2')
3014             NomTypeNew='_i';
3015         end  
3016     end
3017     veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3018     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3019 else
3020     set(handles.SubDir_1,'Visible','on')
3021     if ~isequal(FileExt_prev,'.nc') %find the new NomType if the previous display was not already a netcdf file
3022         veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3023         set_veltype_display(veltype_handles,6); % make all civ buttons visible
3024         RootPath_1=get(handles.RootPath_1,'String');
3025         RootFile_1=get(handles.RootFile_1,'String');
3026         if isempty(RootPath_1)|isequal(RootPath_1,'')
3027             set(handles.RootPath_1,'String','"')
3028         end
3029         if isempty(RootFile_1) | isequal(RootFile_1,'')
3030             set(handles.RootFile_1,'String','"')
3031         end
3032         if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
3033             RootFile_1(1)=[];
3034         end
3035         filebase_1=fullfile(RootPath_1,RootFile_1);
3036         SubDir_1=get(handles.SubDir,'String');
3037         if isempty(SubDir_1)|isequal(SubDir_1,'')
3038             if isfield(UvData,'SubDir_1')
3039                 SubDir_1=UvData.SubDir_1;%retrieve previous subdir
3040             else
3041                 SubDir_1='?';
3042             end
3043         end
3044         if isequal(NomType_1,'#_ab')|isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')|isequal(NomType_1,'_i1-i2')
3045             NomTypeNew=NomType_1;
3046         elseif isequal(NomType_1,'#a')
3047              [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),str2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
3048              NomTypeNew='#_ab';
3049         elseif isequal(NomType_1,'_i_j')
3050              [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),str2num(str_a),'.nc','_i1-i2_j',0,str2num(str1),[],SubDir_1);
3051             if idetect==1
3052                 NomTypeNew='_i1-i2_j';
3053             else
3054                 NomTypeNew='_i_j1-j2';
3055             end
3056         else %for instance avi files or any ima_num series
3057             [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),str2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
3058             NomTypeNew='_i1-i2';
3059         end            
3060         [Path,Name]=fileparts(filebase_1);
3061         set(handles.FileExt_1,'String','.nc');
3062         if ~isempty(SubDir_1) & ~isequal(SubDir_1,'''')& ~isequal(SubDir_1,'"')
3063             SubDir_1=['/' SubDir_1];
3064         end
3065         set(handles.SubDir_1,'String',SubDir_1);
3066     end
3067     if isequal(field,'vort') | isequal(field,'div') | isequal(field,'strain')
3068         set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3069         set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3070         set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
3071         set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
3072     elseif isequal(field_1,'more...'); %add new item to the menu
3073         set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3074         set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3075         str=calc_field;%get the list of available scalars by the function calc_scal
3076         [ind_answer,v] = listdlg('PromptString','Select a file:',...
3077                 'SelectionMode','single',...
3078                 'ListString',str);
3079        % edit the choice in the field and action menu
3080         scalar=cell2mat(str(ind_answer));
3081         menu=update_menu(handles.Fields_1,scalar);
3082         set(handles.Fields_1,'String',menu);% store the selected scalar type
3083     end
3084 end
3085 str1=get(handles.i1,'String');
3086 str2=get(handles.i2,'String');
3087 str_a=get(handles.j1,'String');
3088 str_b=get(handles.j2,'String');
3089 indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
3090 set(handles.FileIndex_1,'String',indices)
3091 set(handles.FileIndex_1,'UserData',NomTypeNew)
3092 
3093 %common to Fields_Callback
3094 if isequal(field,'image')|isequal(field_1,'image')
3095     set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3096     set(handles.npy_title,'Visible','on')
3097     set(handles.npx,'Visible','on')
3098     set(handles.npy,'Visible','on')
3099     set(handles.fix_pair,'Value',0)
3100 else
3101     set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3102     set(handles.npy_title,'Visible','off')
3103     set(handles.npx,'Visible','off')
3104     set(handles.npy,'Visible','off')
3105     set(handles.fix_pair,'Value',1)
3106 end
3107 if isequal(field,'velocity')|isequal(field_1,'velocity');
3108     state_vect='on';
3109 else
3110     state_vect='off';
3111 end 
3112 if ~isequal(field,'velocity')|(~isequal(field_1,'velocity')&~isequal(field_1,''));
3113     state_scal='on';
3114 else
3115     state_scal='off';
3116 end 
3117 set(huvmat,'UserData',UvData)
3118 setfield(handles);% update the field structure ('civ1'....)
3119 if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
3120     run0_Callback(hObject, eventdata, handles)
3121 end
3122 
3123 
3124 %-----------------------------------
3125 %set the visibility of relevant velocity type menus:
3126 %-----------------------------------
3127 %Civ=0; all states 'off'
3128 %Civ=6; all states 'on'
3129 function set_veltype_display(handles,Civ)
3130 if isequal(Civ,0)
3131     imax=0;
3132 %    set(handles(1),'Visible','on')  % unvisible civ buttons
3133 % else
3134 %    set(handles(1),'String','civ1')
3135 % end
3136 elseif isequal(Civ,1)
3137    imax=1;
3138 elseif isequal(Civ,2) | isequal(Civ,3) 
3139     imax=3;
3140 elseif isequal(Civ,4) | isequal(Civ,5)
3141     imax=4;
3142 elseif isequal(Civ,6) 
3143     imax=6;
3144 end
3145 for ibutton=1:imax;
3146     set(handles(ibutton),'Visible','on')  % unvisible civ buttons
3147 end
3148 % for ibutton=max(imax+1,2):6;
3149 for ibutton=imax+1:6;
3150     set(handles(ibutton),'Visible','off')  % unvisible civ buttons
3151     set(handles(ibutton),'Value',0)%unactivate unvisible buttons
3152 end
3153 
3154 %-------------------------------------------------------------------
3155 % --- Executes on button press in civ1.
3156 function civ1_Callback(hObject, eventdata, handles)
3157 %-------------------------------------------------------------------
3158 if get(handles.civ1,'Value')==1
3159     reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ1)
3160 else
3161     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3162 end
3163 run0_Callback(hObject, eventdata, handles)
3164 
3165 %-------------------------------------------------------------------
3166 % --- Executes on button press in interp1.
3167 function interp1_Callback(hObject, eventdata, handles)
3168 %-------------------------------------------------------------------
3169 if get(handles.interp1,'Value')==1
3170     reset_vel_type([handles.civ1 handles.civ2 handles.filter1 handles.interp2 handles.filter2],handles.interp1)
3171 else
3172      reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3173 end
3174 run0_Callback(hObject, eventdata, handles)
3175 
3176 %-------------------------------------------------------------------
3177 % --- Executes on button press in filter1.
3178 function filter1_Callback(hObject, eventdata, handles)
3179 %-------------------------------------------------------------------
3180 if get(handles.filter1,'Value')==1
3181     reset_vel_type([handles.civ1 handles.civ2 handles.interp1 handles.interp2 handles.filter2],handles.filter1)
3182 else
3183      reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3184 end
3185 run0_Callback(hObject, eventdata, handles)
3186 
3187 %-------------------------------------------------------------------
3188 % --- Executes on button press in civ2.
3189 function civ2_Callback(hObject, eventdata, handles)
3190 %-------------------------------------------------------------------
3191 if get(handles.civ2,'Value')==1
3192     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ2)
3193 else
3194      reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3195 end
3196 run0_Callback(hObject, eventdata, handles)
3197 
3198 %-----------------------------------------
3199 % --- Executes on button press in interp2.
3200 %-------------------------------------------
3201 function interp2_Callback(hObject, eventdata, handles)
3202 if get(handles.interp2,'Value')==1
3203     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.filter2],handles.interp2)
3204 else
3205      reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3206 end
3207 run0_Callback(hObject, eventdata, handles)
3208 %---------------------------------------------
3209 % --- Executes on button press in filter2.
3210 %-------------------------------------------
3211 function filter2_Callback(hObject, eventdata, handles)
3212 if get(handles.filter2,'Value')==1
3213     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2],handles.filter2)
3214 else
3215      reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3216 end
3217 run0_Callback(hObject, eventdata, handles)
3218 
3219 %---------------------------------------------
3220 function civ1_1_Callback(hObject, eventdata, handles)
3221 %---------------------------------------------
3222 if get(handles.civ1_1,'Value')==1
3223     reset_vel_type([handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.civ1_1)
3224 else
3225      reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3226 end
3227 run0_Callback(hObject, eventdata, handles)
3228 
3229 %--------------------------------------------
3230 function interp1_1_Callback(hObject, eventdata, handles)
3231 %--------------------------------------------
3232 if get(handles.interp1_1,'Value')==1
3233     reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.interp1_1)
3234 else
3235     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3236 end
3237 run0_Callback(hObject, eventdata, handles)
3238 
3239 %--------------------------------------------
3240 function filter1_1_Callback(hObject, eventdata, handles)
3241 %--------------------------------------------
3242 if get(handles.filter1_1,'Value')==1
3243     reset_vel_type([handles.interp1_1 handles.civ2_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.filter1_1)
3244 else
3245     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3246 end
3247 run0_Callback(hObject, eventdata, handles)
3248 
3249 %--------------------------------------------
3250 function civ2_1_Callback(hObject, eventdata, handles)
3251 %--------------------------------------------
3252 if get(handles.civ2_1,'Value')==1
3253     reset_vel_type([handles.civ1_1 handles.interp1_1  handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.civ2_1)
3254 else
3255     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3256 end
3257 run0_Callback(hObject, eventdata, handles)
3258 
3259 %--------------------------------------------
3260 function interp2_1_Callback(hObject, eventdata, handles)
3261 %--------------------------------------------
3262 if get(handles.interp2_1,'Value')==1
3263     reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.filter2_1],handles.interp2_1)
3264 else
3265     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3266 end
3267 run0_Callback(hObject, eventdata, handles)
3268 
3269 %--------------------------------------------
3270 function filter2_1_Callback(hObject, eventdata, handles)
3271 %--------------------------------------------
3272 if get(handles.filter2_1,'Value')==1
3273     reset_vel_type([handles.civ1_1 handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1],handles.filter2_1)
3274 else
3275     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3276 end
3277 run0_Callback(hObject, eventdata, handles)
3278 
3279 %-----------------------------------------------
3280 % --- reset civ buttons
3281 function reset_vel_type(handles_civ0,handle1)
3282 for ibutton=1:length(handles_civ0)
3283     set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3284     set(handles_civ0(ibutton),'Value',0)
3285 end
3286 if exist('handle1','var')%handles of selected button
3287     set(handle1,'BackgroundColor',[1 1 0])  
3288 end
3289 
3290 %------------------------------------------------
3291 function create_Callback(hObject,eventdata,handles)
3292 %------------------------------------------------
3293 if ishandle(handles.UVMAT_title)
3294     delete(handles.UVMAT_title)
3295 end
3296 huvmat=get(handles.create,'parent');
3297 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface (handles huvmat)
3298 if isequal(get(handles.create,'Value'),1)
3299     set(handles.zoom,'Value',0)
3300     zoom_Callback(hObject, eventdata, handles)
3301      set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
3302     set(handles.edit_vect,'Value',0)  
3303     edit_vect_Callback(hObject, eventdata, handles)
3304     set(handles.edit,'Value',0)
3305     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3306     list_object=get(handles.list_object,'String');
3307     if ~isempty(list_object)
3308         set(handles.list_object,'Value',length(list_object))
3309     end
3310     MouseAction='create_object';
3311     hset_object=findobj(allchild(0),'Name','set_object');
3312     uistack(hset_object,'top')
3313 else
3314     set(handles.create,'BackgroundColor',[0 1 0])
3315     set(handles.edit,'Value',1)
3316     set(handles.edit,'BackgroundColor',[1 1 0])
3317     MouseAction='none';
3318 end
3319 
3320 UvData.MouseAction=MouseAction;
3321 set(huvmat,'UserData',UvData);
3322 
3323 %------------------------------------------------
3324 function POINTS_Callback(hObject,eventdata,handles)
3325 %------------------------------------------------
3326 if ishandle(handles.UVMAT_title)
3327     delete(handles.UVMAT_title)
3328 end
3329 huvmat=get(handles.create,'parent');
3330 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface (handles huvmat)
3331 if isequal(get(handles.create,'Value'),1)
3332     set(handles.zoom,'Value',0)
3333     zoom_Callback(hObject, eventdata, handles)
3334     set(handles.edit_vect,'Value',0)  
3335     edit_vect_Callback(hObject, eventdata, handles)
3336     set(handles.edit,'Value',0)
3337     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3338     %set(handles.grid,'Value',0)
3339     %set(handles.grid,'BackgroundColor',[0 1 0])
3340     % initiate set_object GUI
3341      data.TITLE='POINTS';
3342     if isfield(UvData,'CoordType')
3343         data.CoordType=UvData.CoordType;
3344     end
3345     if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3346         data.RangeY=UvData.Mesh;
3347     elseif isfield(UvData,'AX')&isfield(UvData,'AY')& isfield(UvData,'A')%only image
3348         np=size(UvData.Field.A);
3349         meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3350         meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3351         data.RangeY=max(meshx,meshy);
3352         data.DX=max(meshx,meshy);
3353     end
3354     data.Coord=[0 0 0]; %default
3355     data.ParentButton=handles.create;
3356     PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
3357     [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
3358     if isfield(UvData,'SetObjectOrigin')
3359     pos_uvmat=get(huvmat,'Position');
3360     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3361     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
3362     set(hset_object,'Position',pos_set_object)
3363     end
3364     %set(hset_object,'Position',[pos_uvmat(1) pos_uvmat(2)-0.05*pos_uvmat(4) 0.2*pos_uvmat(3)  0.5*pos_uvmat(4)]);
3365     list_object=get(handles.list_object,'String');
3366     if ~isempty(list_object)
3367         set(handles.list_object,'Value',length(list_object))
3368     end
3369     MouseAction='create_object';
3370     %UvData.ZoomOn=0;
3371 else
3372     set(handles.create,'BackgroundColor',[0 1 0])
3373     set(handles.edit,'Value',1)
3374     set(handles.edit,'BackgroundColor',[1 1 0])
3375     MouseAction='none';
3376 end
3377 
3378 UvData.MouseAction=MouseAction;
3379 set(huvmat,'UserData',UvData);
3380 
3381 %-----------------------------------------------------------
3382 function LINE_Callback(hObject, eventdata, handles)
3383 %-------------------------------------------------
3384 if ishandle(handles.UVMAT_title)
3385     delete(handles.UVMAT_title)
3386 end
3387 huvmat=get(handles.create,'parent');
3388 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3389 % if (get(handles.LINE,'Value')==1)
3390     %suppress the other options if MENULINE is chosen
3391     set(handles.zoom,'Value',0)
3392     zoom_Callback(hObject, eventdata, handles)
3393 %     set(handles.create,'Value',0)
3394 %     set(handles.create,'BackgroundColor',[0 1 0])
3395 %     set(handles.LINE,'Value',1)
3396 %     set(handles.LINE,'BackgroundColor',[1 1 0])
3397 %     set(handles.PATCH,'Value',0)
3398 %     set(handles.PATCH,'BackgroundColor',[0 1 0])
3399 %     set(handles.PLANE,'Value',0)
3400 %     set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
3401 %     set(handles.VOLUME,'Value',0)
3402 %     set(handles.VOLUME,'BackgroundColor',[0 1 0])
3403     %et(handles.makemask,'Value',0)
3404     %makemask_Callback(hObject, eventdata, handles)
3405     set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3406     set(handles.edit_vect,'Value',0)
3407     edit_vect_Callback(hObject, eventdata, handles)
3408     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3409     set(handles.edit,'Value',0)
3410     set(handles.list_object,'Value',1);
3411     edit_vect_Callback(hObject, eventdata, handles)
3412     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3413     set(handles.cal,'Value',0)
3414     set(handles.cal,'BackgroundColor',[0 1 0])
3415    % set(handles.grid,'Value',0)
3416    % set(handles.grid,'BackgroundColor',[0 1 0])
3417 %  initiate the set_object GUI
3418     data.TITLE='LINE';
3419     if isfield(UvData,'CoordType')
3420         data.CoordType=UvData.CoordType;
3421     end
3422     if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3423         data.RangeX=UvData.Mesh;
3424         data.RangeY=UvData.Mesh;
3425 %         data.YMax=UvData.Mesh;
3426 %         data.XMax=UvData.Mesh;
3427         data.DX=UvData.Mesh;
3428         data.DY=UvData.Mesh;
3429     elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3430         np=size(UvData.Field.A);
3431         meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3432         meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3433         data.RangeY=max(meshx,meshy);
3434         data.RangeX=max(meshx,meshy);
3435 %         data.YMax=max(meshx,meshy);
3436 %         data.XMax=max(meshx,meshy);
3437         data.DX=max(meshx,meshy);
3438     end 
3439     if isfield(data,'DX')
3440         data.Coord=[[0 0 0];[data.DX 0 0]]; %default
3441     else
3442         data.Coord=[[0 0 0];[1 0 0]]; %default
3443     end
3444     data.ParentButton=handles.create;
3445     PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3446     [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3447                                                       % associate the set_edit interface handle to the plotting axes
3448     pos_uvmat=get(huvmat,'Position');
3449     if isfield(UvData,'SetObjectOrigin')
3450         pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3451         pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);  
3452         set(hset_object,'Position',pos_set_object)
3453     end
3454     list_object=get(handles.list_object,'String');
3455     if ~isempty(list_object)
3456         set(handles.list_object,'Value',length(list_object))
3457     end
3458      MouseAction='create_object';
3459 % else
3460 %     set(handles.LINE,'BackgroundColor',[0 1 0])
3461 %      MouseAction='none';
3462 % end
3463 
3464 UvData.MouseAction=MouseAction;
3465 set(huvmat,'UserData',UvData)
3466 
3467 %-----------------------------------------------------------
3468 function PATCH_Callback(hObject, eventdata, handles)
3469 %-----------------------------------------------------------
3470 if ishandle(handles.UVMAT_title)
3471     delete(handles.UVMAT_title)
3472 end
3473 huvmat=get(handles.create,'parent');
3474 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3475 % if isequal(get(handles.PATCH,'Value'),1)
3476     set(handles.zoom,'Value',0)
3477     set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3478 %     set(handles.create,'Value',0)%suppress the other options if LINE is chosen
3479 %     set(handles.create,'BackgroundColor',[0 1 0])
3480 %     set(handles.LINE,'Value',0)
3481 %     set(handles.LINE,'BackgroundColor',[0 1 0])
3482 %     set(handles.PATCH,'Value',1)
3483 %     set(handles.PATCH,'BackgroundColor',[1 1 0])
3484 %     set(handles.PLANE,'Value',0)
3485 %     set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
3486 %     set(handles.VOLUME,'Value',0)
3487 %     set(handles.VOLUME,'BackgroundColor',[0 1 0])
3488     %set(handles.makemask,'Value',0)
3489     %makemask_Callback(hObject, eventdata, handles)
3490     set(handles.edit_vect,'Value',0)
3491     edit_vect_Callback(hObject, eventdata, handles)
3492     set(handles.edit,'Value',0)
3493     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3494     set(handles.edit_vect,'Value',0)  
3495     edit_vect_Callback(hObject, eventdata, handles)
3496     set(handles.cal,'Value',0)
3497     set(handles.cal,'BackgroundColor',[0 1 0])
3498     %set(handles.grid,'Value',0)
3499     %set(handles.grid,'BackgroundColor',[0 1 0])
3500     %initiate set_object GUI
3501     data.TITLE='PATCH';
3502     if isfield(UvData,'CoordType')
3503         data.CoordType=UvData.CoordType;
3504     end
3505     if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3506         data.YMax=UvData.Mesh;
3507     elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3508         np=size(UvData.Field.A);
3509         meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
3510         meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
3511         data.YMax=max(meshx,meshy);
3512         data.DX=max(meshx,meshy);
3513     end
3514     data.Coord=[0 0 0]; %default
3515     data.ParentButton=handles.create;
3516     PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
3517     [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
3518     pos_uvmat=get(huvmat,'Position');
3519     if isfield(UvData,'SetObjectOrigin')
3520         pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3521         pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
3522         set(hset_object,'Position',pos_set_object)
3523     end
3524     list_object=get(handles.list_object,'String');
3525     if ~isempty(list_object)
3526         set(handles.list_object,'Value',length(list_object))
3527     end
3528     UvData.MouseAction='create_object';
3529     set(huvmat,'UserData',UvData);
3530 %-------------------------------------------------------
3531 function PLANE_Callback(hObject, eventdata, handles)
3532 %-------------------------------------------------------
3533 if ishandle(handles.UVMAT_title)
3534     delete(handles.UVMAT_title)
3535 end
3536 huvmat=get(handles.create,'parent');
3537 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3538 set(handles.zoom,'Value',0)
3539 set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3540 set(handles.edit_vect,'Value',0)
3541 edit_vect_Callback(hObject, eventdata, handles)
3542 set(handles.edit,'Value',0)
3543 set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3544 set(handles.cal,'Value',0)
3545 set(handles.cal,'BackgroundColor',[0 1 0])
3546 %set(handles.grid,'Value',0)
3547 %set(handles.grid,'BackgroundColor',[0 1 0])
3548 %initiate set_object GUI
3549 data.TITLE='PLANE';
3550 if isfield(UvData,'CoordType')
3551     data.CoordType=UvData.CoordType;
3552 end
3553 %Si 3D data.nbdim=3;
3554 %Si 2D
3555 if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3556     data.ZMax=UvData.Mesh;
3557     data.DX=UvData.Mesh;
3558     data.DY=UvData.Mesh;
3559 elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3560     np=size(UvData.Field.A);
3561     meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
3562     meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
3563     data.DX=max(meshx,meshy);
3564 end
3565 if isfield(UvData,'DX')
3566     data.DX=UvData.DX;
3567 end
3568 if isfield(UvData,'DY')
3569     data.DY=UvData.DY;
3570 elseif isfield(UvData,'Mesh')
3571     data.DY=UvData.Mesh;
3572 end
3573 if isfield(UvData.Field,'X')& isfield(UvData.Field,'Y')
3574     data.Coord=[0 0 0];
3575     data.Style='plane';
3576     data.Phi=0;
3577     data.IndexObj=1; %act on the first reference plane by default
3578     haxes= handles.axes3;%GENERALISER
3579     plot_object(data,[],haxes,'m'); %plot the axes of the default plane
3580 end
3581 data.ParentButton=handles.create;
3582 PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
3583 ZBounds=0; % default
3584 if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
3585     ZBounds(1)=UvData.ZMin; %minimum for the Z slider
3586     ZBounds(2)=UvData.ZMax;%maximum for the Z slider
3587 end
3588 [hset_object,UvData.sethandles]=set_object(data,PlotHandles,ZBounds);% call the set_object interface with action on haxes,
3589 if isfield(UvData,'SetObjectOrigin')
3590 pos_uvmat=get(huvmat,'Position');
3591 pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3592 pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);  
3593 set(hset_object,'Position',pos_set_object)
3594 end
3595 list_object=get(handles.list_object,'String');
3596 nbobject=length(list_object);
3597 set(handles.list_object,'Value',nbobject)
3598 UvData.MouseAction='create_object';
3599 set(huvmat,'UserData',UvData)
3600 
3601 %-------------------------------------------------------
3602 % --- Executes on button press in MENUVOLUME.
3603 %-------------------------------------------------------
3604 function VOLUME_Callback(hObject, eventdata, handles)
3605 %errordlg('command VOL not implemented yet')
3606 if ishandle(handles.UVMAT_title)
3607     delete(handles.UVMAT_title)
3608 end
3609 huvmat=get(handles.create,'parent');
3610 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3611 if isequal(get(handles.VOLUME,'Value'),1)
3612     set(handles.zoom,'Value',0)
3613     set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3614     set(handles.edit_vect,'Value',0)
3615     edit_vect_Callback(hObject, eventdata, handles)
3616     set(handles.edit,'Value',0)
3617     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3618     set(handles.cal,'Value',0)
3619     set(handles.cal,'BackgroundColor',[0 1 0])
3620     set(handles.edit_vect,'Value',0)
3621     edit_vect_Callback(hObject, eventdata, handles)
3622     %initiate set_object GUI
3623     data.TITLE='VOLUME';
3624     if isfield(UvData,'CoordType')
3625         data.CoordType=UvData.CoordType;
3626     end
3627     if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3628         data.RangeY=UvData.Mesh;
3629         data.RangeX=UvData.Mesh;
3630         data.DX=UvData.Mesh;
3631         data.DY=UvData.Mesh;
3632     elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3633         np=size(UvData.Field.A);
3634         meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3635         meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3636         data.RangeY=max(meshx,meshy);
3637         data.RangeX=max(meshx,meshy);
3638         data.DX=max(meshx,meshy);
3639     end 
3640     data.ParentButton=handles.VOLUME;
3641     PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3642     [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3643                                                       % associate the set_edit interface handle to the plotting axes
3644     if isfield(UvData,'SetObjectOrigin')                                                
3645     pos_uvmat=get(huvmat,'Position');
3646     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3647     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);  
3648     set(hset_object,'Position',pos_set_object)
3649     end
3650     UvData.MouseAction='create_object';
3651 else
3652     set(handles.VOLUME,'BackgroundColor',[0 1 0])
3653     UvData.MouseAction='none';
3654 end
3655 set(huvmat,'UserData',UvData)
3656 
3657 %-------------------------------------------------------
3658 function edit_vect_Callback(hObject, eventdata, handles)
3659 %-------------------------------------------------------
3660 huvmat=get(handles.edit_vect,'parent');
3661 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3662 if isequal(get(handles.edit_vect,'Value'),1)
3663     set(handles.record,'Visible','on')
3664     set(handles.edit_vect,'BackgroundColor',[1 1 0])
3665     set(handles.edit,'Value',0)
3666     set(handles.create,'Value',0)
3667     set(handles.create,'BackgroundColor',[0 1 0])
3668     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3669     set(gcf,'Pointer','arrow')
3670     UvData.MouseAction='edit_vect';
3671 else
3672     set(handles.record,'Visible','off')
3673     set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3674     UvData.MouseAction='none';
3675 end
3676 set(huvmat,'UserData',UvData)
3677 
3678 %----------------------------------------------
3679 function save_mask_Callback(hObject, eventdata, handles)
3680 %-----------------------------------------------------------------------
3681 huvmat=get(handles.save_mask,'parent');
3682 UvData=get(huvmat,'UserData');
3683 
3684 hpatch=findobj(huvmat,'Type','patch');
3685 flag=1;
3686 npx=size(UvData.Field.A,2);
3687 npy=size(UvData.Field.A,1);
3688 xi=[0.5:npx-0.5];
3689 yi=[0.5:npy-0.5];
3690 [Xi,Yi]=meshgrid(xi,yi);
3691 if isfield(UvData,'Object')
3692     for iobj=1:length(UvData.Object)
3693         ObjectData=UvData.Object{iobj};
3694         if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3695             flagobj=1;
3696             testphys=0; %coordinates in pixels by default
3697             if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3698                 if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
3699                     Calib=UvData.XmlData.GeometryCalib;
3700                     testphys=1;
3701                 end
3702             end
3703             if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style') 
3704                 if isequal(ObjectData.Style,'polygon') 
3705                     X=ObjectData.Coord(:,1);
3706                     Y=ObjectData.Coord(:,2);
3707                     if testphys
3708                         [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3709                     end
3710                     flagobj=~inpolygon(Xi,Yi,X,Y);%=0 inside the polygon, 1 outside
3711                 elseif isequal(ObjectData.Style,'ellipse')
3712                     if testphys
3713                         %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3714                     end
3715                     RangeX=max(ObjectData.RangeX);
3716                     RangeY=max(ObjectData.RangeY);
3717                     X2Max=RangeX*RangeX;
3718                     Y2Max=RangeY*RangeY;
3719                     distX=(Xi-ObjectData.Coord(1,1));
3720                     distY=(Yi-ObjectData.Coord(1,2));
3721                     flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3722                 elseif isequal(ObjectData.Style,'rectangle')
3723                     if testphys
3724                         %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3725                     end
3726                     distX=abs(Xi-ObjectData.Coord(1,1));
3727                     distY=abs(Yi-ObjectData.Coord(1,2));
3728                     flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3729                 end
3730                 if isequal(ObjectData.ProjMode,'mask_outside')
3731                     flagobj=~flagobj;
3732                 end
3733                 flag=flag & flagobj;
3734             end
3735         end
3736     end
3737 end
3738 % flag=~flag;
3739 %mask name
3740 RootPath=get(handles.RootPath,'String');
3741 RootFile=get(handles.RootFile,'String');
3742 if ~isempty(RootFile)&(isequal(RootFile(1),'/')| isequal(RootFile(1),'\'))
3743         RootFile(1)=[];
3744 end
3745 filebase=fullfile(RootPath,RootFile);
3746 list=get(handles.masklevel,'String');
3747 masknumber=num2str(length(list));
3748 maskindex=get(handles.masklevel,'Value');
3749 mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3750 imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3751 imflag=flipdim(imflag,1);
3752 % imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3753 warndlg_uvmat([mask_name ' saved'],'CONFIRMATION')
3754 imwrite(imflag,mask_name,'BitDepth',8); 
3755 
3756 %display the mask
3757 %update_mask(handles,num_i1,num_j1)
3758 figure;
3759 vec=linspace(0,1,256);%define a linear greyscale colormap
3760 map=[vec' vec' vec'];
3761 colormap(map)
3762 
3763 image(imflag);
3764 
3765 %-------------------------------------------------------------------
3766 %-------------------------------------------------------------------
3767 %  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3768 
3769 %------------------------------------------------------------------
3770 
3771 
3772 
3773 %------------------------------------------------------------------
3774 % --- Executes on selection change in col_vec: choice of the color code.
3775 %
3776 function col_vec_Callback(hObject, eventdata, handles)
3777 %------------------------------------------------------------------
3778 % edit the choice for color code
3779 list_code=get(handles.col_vec,'String');% list menu fields
3780 index_code=get(handles.col_vec,'Value');% selected string index
3781 col_code= list_code{index_code(1)}; % selected field
3782 if isequal(col_code,'black') | isequal(col_code,'white')
3783    set(handles.slider1,'Visible','off')
3784    set(handles.slider2,'Visible','off')
3785    set(handles.colcode1,'Visible','off')
3786    set(handles.colcode2,'Visible','off')
3787    set(handles.AutoVecColor,'Visible','off')
3788    set_vec_col_bar(handles)
3789 else
3790    set(handles.slider1,'Visible','on')
3791    set(handles.slider2,'Visible','on') 
3792    set(handles.colcode1,'Visible','on')
3793    set(handles.colcode2,'Visible','on')
3794    set(handles.AutoVecColor,'Visible','on')  
3795    if isequal(col_code,'ima_cor')
3796        set(handles.AutoVecColor,'Value',0)%fixed scale by default
3797        set(handles.vec_col_bar,'Value',0)% 3 colors r,g,b by default
3798        set(handles.slider1,'Min',0);
3799        set(handles.slider1,'Max',1);
3800        set(handles.slider2,'Min',0);
3801        set(handles.slider2,'Max',1);
3802  %      set(handles.min_title_vec,'String','0')
3803        set(handles.max_vec,'String','1')
3804        set(handles.colcode1,'String','0.333')
3805        colcode1_Callback(hObject, eventdata, handles)
3806        set(handles.colcode2,'String','0.666')
3807        colcode2_Callback(hObject, eventdata, handles)
3808    else
3809        set(handles.AutoVecColor,'Value',1)%auto scale between min,max by default
3810        set(handles.vec_col_bar,'Value',1)% colormap 'jet' by default
3811        minval=get(handles.slider1,'Min');
3812        maxval=get(handles.slider1,'Max');
3813        set(handles.slider1,'Value',minval)
3814        set(handles.slider2,'Value',maxval)
3815        set_vec_col_bar(handles)
3816    end
3817 %    slider_update(handles)
3818 end
3819 %replot the current graph
3820 run0_Callback(hObject, eventdata, handles)
3821 
3822 
3823 %----------------------------------------------------------------
3824 % -- Executes on slider movement to set the color code
3825 %
3826 function slider1_Callback(hObject, eventdata, handles)
3827 %------------------------------------------------------------------
3828 slider1=get(handles.slider1,'Value');
3829 min_val=str2num(get(handles.min_vec,'String'));
3830 max_val=str2num(get(handles.max_vec,'String'));
3831 col=min_val+(max_val-min_val)*slider1;
3832 set(handles.colcode1,'String',num2str(col))
3833 if(get(handles.slider2,'Value') < col)%move also the second slider at the same value if needed
3834     set(handles.slider2,'Value',col)
3835     set(handles.colcode2,'String',num2str(col))
3836 end
3837 colcode1_Callback(hObject, eventdata, handles)
3838 
3839 %----------------------------------------------------------------
3840 % Executes on slider movement to set the color code
3841 %----------------------------------------------------------------
3842 function slider2_Callback(hObject, eventdata, handles)
3843 slider2=get(handles.slider2,'Value');
3844 min_val=str2num(get(handles.min_vec,'String'));
3845 max_val=str2num(get(handles.max_vec,'String'));
3846 col=min_val+(max_val-min_val)*slider2;
3847 set(handles.colcode2,'String',num2str(col))
3848 if(get(handles.slider1,'Value') > col)%move also the first slider at the same value if needed
3849     set(handles.slider1,'Value',col)
3850     set(handles.colcode1,'String',num2str(col))
3851 end
3852 colcode2_Callback(hObject, eventdata, handles)
3853 
3854 %----------------------------------------------------------------
3855 %execute on return carriage on the edit box corresponding to slider 1
3856 %----------------------------------------------------------------
3857 function colcode1_Callback(hObject, eventdata, handles)
3858 % col=str2num(get(handles.colcode1,'String'));
3859 % set(handles.slider1,'Value',col)
3860 set_vec_col_bar(handles)
3861 update_plot(handles)
3862 
3863 %----------------------------------------------------------------
3864 %execute on return carriage on the edit box corresponding to slider 2
3865 %----------------------------------------------------------------
3866 function colcode2_Callback(hObject, eventdata, handles)
3867 % col=str2num(get(handles.colcode2,'String'));
3868 % set(handles.slider2,'Value',col)
3869 % slider2_Callback(hObject, eventdata, handles)
3870 set_vec_col_bar(handles)
3871 update_plot(handles)
3872 %------------------------------------------------------------
3873 %update the slider values after displaying vectors
3874 %--------------------------------------------------------
3875 % function slider_update(handles,auto,minC,colcode1,colcode2,maxC)
3876 % set(handles.slider1,'Min',minC)
3877 % set(handles.slider1,'Max',maxC)
3878 % set(handles.slider2,'Min',minC)
3879 % set(handles.slider2,'Max',maxC)
3880 % set(handles.min_title_vec,'String',num2str(minC))
3881 % set(handles.max_vec,'String',num2str(maxC))
3882 % if auto
3883 %         set(handles.colcode1,'String',num2str(colcode1,3))%update display
3884 %         set(handles.colcode2,'String',num2str(colcode2,3))
3885 % end
3886 % set(handles.slider1,'Value',colcode1)%update slider with constant display
3887 % set(handles.slider2,'Value',colcode2)
3888 % set_vec_col_bar(handles)
3889 
3890 
3891 %-------------------------------------------------------
3892 % --- Executes on button press in AutoVecColor.
3893 %-------------------------------------------------------
3894 function vec_col_bar_Callback(hObject, eventdata, handles)
3895 set_vec_col_bar(handles)
3896 
3897 % %--------------------------------------------
3898 % %update the display of color code for vectors
3899 % %--------------------------------------------
3900 % function set_vec_col_bar(handles)
3901 % %get the image of the color display button 'vec_col_bar' in pixels
3902 % uni=get(handles.vec_col_bar,'Unit');
3903 % set(handles.vec_col_bar,'Unit','pixel')
3904 % pos_vert=get(handles.vec_col_bar,'Position');
3905 % set(handles.vec_col_bar,'Unit','Normalized')
3906 % width=ceil(pos_vert(3));
3907 % height=ceil(pos_vert(4));
3908 % %get slider indications
3909 % colcode.min=get(handles.slider1,'Min');
3910 % colcode.max=get(handles.slider1,'Max');
3911 % colcode.colcode1=get(handles.slider1,'Value');
3912 % colcode.colcode2=get(handles.slider2,'Value');
3913 % colcode.option=get(handles.vec_col_bar,'Value');
3914 % colcode.auto=1;
3915 % list_code=get(handles.col_vec,'String');% list menu fields
3916 % index_code=get(handles.col_vec,'Value');% selected string index
3917 % colcode.CName= list_code{index_code(1)}; % selected field used for vector color
3918 % vec_C=colcode.min+(colcode.max-colcode.min)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
3919 % [colorlist,col_vec]=set_col_vec(colcode,vec_C);
3920 % oneheight=ones(1,height);
3921 % A1=colorlist(col_vec,1)*oneheight;
3922 % A2=colorlist(col_vec,2)*oneheight;
3923 % A3=colorlist(col_vec,3)*oneheight;
3924 % A(:,:,1)=A1';
3925 % A(:,:,2)=A2';
3926 % A(:,:,3)=A3';
3927 % set(handles.vec_col_bar,'Cdata',A)
3928 
3929 %--------------------------------------------------------
3930 % --- Executes on button press in cal.
3931 function cal_Callback(hObject, eventdata, handles)
3932 
3933 huvmat=get(handles.cal,'parent');%handles of the uvmat interface
3934 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3935 %reinitialize the edit interface associated with uvmat
3936 value=get(handles.cal,'Value'); 
3937 if value
3938         set(handles.cal,'BackgroundColor',[1 1 0])
3939         %suppress the other options if MENULINE is chosen
3940         set(handles.zoom,'Value',0)
3941         set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3942         set(handles.create,'Value',0)
3943         set(handles.create,'BackgroundColor',[0 1 0])
3944         set(handles.create,'enable','off')      
3945         set(handles.edit_vect,'Value',0)
3946         set(handles.edit_vect,'enable','off')
3947         edit_vect_Callback(hObject, eventdata, handles)
3948         set(handles.edit,'Value',0)
3949         set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3950         set(handles.edit,'enable','off')
3951         set(handles.list_object,'Value',1)      
3952         % initiate display of GUI geometry_calib
3953         data=[]; %default
3954         if isfield(UvData,'CoordType')
3955             data.CoordType=UvData.CoordType;
3956         end
3957         %data.ParentButton=handles.cal; % transmit the handles of the calling button to the GUI geometry_calib
3958         pos=get(huvmat,'Position');
3959         pos(1)=pos(1)+pos(3)-0.311+0.04; %0.311= width of the geometry_calib interface (units relative to the srcreen)
3960         pos(2)=pos(2)-0.02;
3961         [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
3962 %         [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
3963 %         [inputfile,idetect]=name_generator(filebase,num_i1,num_j1,Ext,NomType,1,num_i2,num_j2,SubDir);
3964         [UvData.hset_object,UvData.sethandles]=geometry_calib(handles,pos,FileName);% call the set_object interface
3965         pos_uvmat=get(huvmat,'Position');
3966         %pos_cal(1:2)=UvData.CalOrigin + pos_uvmat(1:2);
3967         if isfield(UvData,'CalOrigin')
3968             pos_cal(1)=pos_uvmat(1)+UvData.CalOrigin(1)*pos_uvmat(3);
3969             pos_cal(2)=pos_uvmat(2)+UvData.CalOrigin(2)*pos_uvmat(4);
3970             pos_cal(3:4)=UvData.CalSize .* pos_uvmat(3:4);
3971             set(UvData.hset_object,'Position',pos_cal)
3972         end
3973         UvData.MouseAction='calib';
3974 else
3975      UvData.MouseAction='none';     
3976      hgeometry_calib=findobj(allchild(0),'Name','geometry_calib');
3977      if ~isempty(hgeometry_calib)
3978          answer=questdlg('close the GUI geometry-calib?');
3979          if isequal(answer,'Yes')
3980              delete(hgeometry_calib)
3981              set(handles.cal,'BackgroundColor',[0 1 0])
3982          else
3983              set(handles.cal,'Value',1)% keep the calibration function active
3984          end
3985      end
3986      set(handles.edit_vect,'enable','on')
3987      set(handles.edit,'enable','on')
3988      set(handles.create,'enable','on')
3989 %      set(handles.LINE,'enable','on')
3990 %      set(handles.PATCH,'enable','on')
3991 %      set(handles.PLANE,'enable','on')
3992 %      set(handles.VOLUME,'enable','on')
3993      %set(handles.makemask,'enable','on')
3994      hh=findobj(handles.axes3,'Tag','calib_points');
3995      if ~isempty(hh)
3996          delete(hh)
3997      end
3998      hhh=findobj(handles.axes3,'Tag','calib_marker');
3999      if ~isempty(hhh)
4000          delete(hhh)
4001      end    
4002 end
4003 set(huvmat,'UserData',UvData);
4004 
4005 %-------------------------------------------------------------
4006 % --- Executes on selection change in menu_coord.
4007 function menu_coord_Callback(hObject, eventdata, handles)
4008 %-------------------------------------------------------------
4009 huvmat=get(handles.menu_coord,'parent');
4010 menu=get(handles.menu_coord,'String');
4011 ind_coord=get(handles.menu_coord,'Value');
4012 coord_option=menu{ind_coord};
4013 list_path=get(handles.menu_coord,'UserData');
4014     
4015 if isequal(coord_option,'more...'); 
4016     coord_fct='';
4017     dir_perso=prefdir;
4018     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
4019     if exist(profil_perso,'file')
4020           h=load (profil_perso);
4021          if isfield(h,'coord_fct')
4022                 coord_fct=h.coord_fct;
4023          end
4024     end
4025     prompt = {'Enter the name of the transform function'};
4026     dlg_title = 'user defined transform';
4027     num_lines= 1;
4028     [FileName, PathName, filterindex] = uigetfile( ...
4029        {'*.m', ' (*.m)';
4030         '*.m',  '.m files '; ...
4031         '*.*', 'All Files (*.*)'}, ...
4032         'Pick a file', coord_fct);
4033     if isequal(PathName(end),'/')||isequal(PathName(end),'\')
4034         PathName(end)=[];
4035     end
4036     coord_fct=fullfile(PathName,FileName);
4037     if ~exist(coord_fct,'file')
4038            msgbox_uvmat('ERROR',['image procesing fct ' coord_fct ' not found'])
4039     else
4040        transform=FileName(1:end-2);%
4041        menu=update_menu(handles.menu_coord,transform);%add the selected fct to the menu
4042        ind_coord=get(handles.menu_coord,'Value');
4043        list_path{ind_coord}=PathName;
4044        set(handles.menu_coord,'UserData',list_path)
4045        if exist(profil_perso,'file')
4046             save (profil_perso,'coord_fct','-append'); %store the root name for future opening of uvmat
4047         end
4048     end   
4049 end
4050 
4051 %check the current path to the selected function
4052 PathName=list_path{ind_coord};
4053 CurrentPath=fileparts(which(coord_option));
4054 if ~isequal(PathName,CurrentPath)
4055     addpath(PathName) 
4056     errormsg=check_functions;
4057     msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
4058 end
4059 set(handles.path_transform,'String',fullfile(PathName,' ')); %show the path to the senlected function
4060 set(handles.FixedLimits,'Value',0)
4061 set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
4062 
4063 UvData=get(huvmat,'UserData');
4064 
4065 %delete drawn objects
4066 hother=findobj('Tag','proj_object');%find all the proj objects
4067 for iobj=1:length(hother)
4068     delete_object(hother(iobj))
4069 end
4070 hother=findobj('Tag','DeformPoint');%find all the proj objects
4071 for iobj=1:length(hother)
4072     delete_object(hother(iobj))
4073 end
4074 hh=findobj('Tag','calib_points');
4075 if ~isempty(hh)
4076     delete(hh)
4077 end
4078 hhh=findobj('Tag','calib_marker');
4079 if ~isempty(hhh)
4080     delete(hhh)
4081 end
4082 if isfield(UvData,'Object')
4083     nbobject=length(UvData.Object);
4084     UvData.Object([2:nbobject])=[];
4085 end 
4086 
4087 %delete mask if it is displayed
4088 if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
4089    UvData=rmfield(UvData,'MaskName'); %will impose mask refresh
4090 end
4091 set(huvmat,'UserData',UvData)
4092 run0_Callback(hObject, eventdata, handles)
4093 
4094 %--------------------------------------------
4095 function histo1_menu_Callback(hObject, eventdata, handles)
4096 %--------------------------------------------
4097 %plot first histo
4098 huvmat=get(handles.histo1_menu,'parent');
4099 histo_menu=get(handles.histo1_menu,'String');
4100 histo_value=get(handles.histo1_menu,'Value');
4101 FieldName=histo_menu{histo_value};
4102 UvData=get(huvmat,'UserData');
4103 update_histo(handles.histo_u,huvmat,FieldName)
4104 
4105 %----------------------------------------------
4106 function histo2_menu_Callback(hObject, eventdata, handles)
4107 %----------------------------------------------
4108 %plot second histo
4109 huvmat=get(handles.histo2_menu,'parent');
4110 histo_menu=get(handles.histo2_menu,'String');
4111 histo_value=get(handles.histo2_menu,'Value');
4112 FieldName=histo_menu{histo_value};
4113 UvData=get(huvmat,'UserData');
4114 update_histo(handles.histo_v,huvmat,FieldName)
4115 
4116 
4117 %--------------------------------------------
4118 %read the field .Fieldname stored in UvData and plot its histogram
4119 function update_histo(haxes,huvmat,FieldName)
4120 UvData=get(huvmat,'UserData');
4121 
4122 if ~isfield(UvData.Field,FieldName)
4123     msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
4124     return
4125 end
4126 Field=UvData.Field;
4127 FieldHisto=eval(['Field.' FieldName]);
4128 if isfield(Field,'FF') & ~isempty(Field.FF) & isequal(size(Field.FF),size(FieldHisto))
4129     indsel=find(Field.FF==0);%find values marked as false
4130     if ~isempty(indsel)
4131         FieldHisto=FieldHisto(indsel);
4132     end
4133 end
4134 if isempty(Field)
4135     msgbox_uvmat('ERROR',['empty field ' FieldName])
4136 else
4137     nxy=size(FieldHisto);
4138     Amin=double(min(min(min(FieldHisto))));%min of image
4139     Amax=double(max(max(max(FieldHisto))));%max of image
4140     if isequal(Amin,Amax)
4141        Histo.Txt=['uniform field =' num2str(Amin)];
4142     else
4143     Histo.ListVarName={FieldName,'histo'};
4144     if numel(nxy)==2
4145         Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
4146     else %color images
4147         Histo.VarDimName={FieldName,{FieldName,'rgb'}}; %dimensions for the histogram
4148     end
4149     %unit
4150     units=[]; %default
4151     for ivar=1:numel(Field.ListVarName)    
4152         if strcmp(Field.ListVarName{ivar},FieldName)
4153             if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
4154                 units=Field.VarAttribute{ivar}.units;
4155                 break
4156             end
4157         end
4158     end
4159     if ~isempty(units)
4160         Histo.VarAttribute{1}.units=units;
4161     end
4162     eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
4163     for col=1:size(FieldHisto,3)
4164         B=FieldHisto(:,:,col);
4165         C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
4166        eval(['Histo.histo(:,col)=hist(C, Histo.' FieldName ');']);  %calculate histogram
4167     end
4168     set(haxes,'XLimMode','auto')%reset auto mode (after zoom effect)
4169     set(haxes,'YLimMode','auto')
4170     plot_field(Histo,haxes);
4171     end
4172 end
4173 
4174 
4175 
4176 %------------------------------------------------
4177 %CALLBACKS FOR PLOTTING PARAMETERS
4178 %-------------------------------------------------
4179 
4180 %-----------------------------------------------------------------
4181 function MinA_Callback(hObject, eventdata, handles)
4182 %------------------------------------------
4183 set(handles.AutoScal,'Value',1) %suppress auto mode
4184 set(handles.AutoScal,'BackgroundColor',[1 1 0])
4185 update_plot(handles)
4186 
4187 %-----------------------------------------------------------------
4188 function MaxA_Callback(hObject, eventdata, handles)
4189 %--------------------------------------------
4190 set(handles.AutoScal,'Value',1) %suppress auto mode
4191 set(handles.AutoScal,'BackgroundColor',[1 1 0])
4192 update_plot(handles)
4193 
4194 %-----------------------------------------------
4195 function AutoScal_Callback(hObject, eventdata, handles)
4196 %--------------------------------------------
4197 test=get(handles.AutoScal,'Value');
4198 if test
4199     set(handles.AutoScal,'BackgroundColor',[1 1 0])
4200 else
4201     set(handles.AutoScal,'BackgroundColor',[0.7 0.7 0.7])
4202     update_plot(handles);
4203 %     set(handles.MinA,'String',num2str(ScalOut.MinA,3))
4204 %     set(handles.MaxA,'String',num2str(ScalOut.MaxA,3))
4205 end
4206 
4207 %-------------------------------------------------------------------
4208 function BW_Callback(hObject, eventdata, handles)
4209 %-------------------------------------------------------------------
4210 update_plot(handles)
4211 
4212 %-------------------------------------------------------------------
4213 function Contours_Callback(hObject, eventdata, handles)
4214 %-------------------------------------------------------------------
4215 val=get(handles.Contours,'Value');
4216 if val==2
4217     set(handles.interval_txt,'Visible','on')
4218     set(handles.IncrA,'Visible','on')
4219 else
4220     set(handles.interval_txt,'Visible','off')
4221     set(handles.IncrA,'Visible','off')
4222 end
4223 update_plot(handles)
4224 
4225 %-------------------------------------------------------------------
4226 function IncrA_Callback(hObject, eventdata, handles)
4227 %-------------------------------------------------------------------
4228 update_plot(handles)
4229 
4230 %-------------------------------------------------------------------
4231 function HideWarning_Callback(hObject, eventdata, handles)
4232 %-------------------------------------------------------------------
4233 update_plot(handles)
4234 
4235 %-------------------------------------------------------------------
4236 function HideFalse_Callback(hObject, eventdata, handles)
4237 %-------------------------------------------------------------------
4238 update_plot(handles)
4239 
4240 %-------------------------------------------------------------------
4241 function VecScale_Callback(hObject, eventdata, handles)
4242 %-------------------------------------------------------------------
4243 set(handles.AutoVec,'Value',1);
4244 set(handles.AutoVec,'BackgroundColor',[1 1 0])
4245 update_plot(handles)
4246 
4247 %-------------------------------------------------------------------
4248 function AutoVec_Callback(hObject, eventdata, handles)
4249 %-------------------------------------------------------------------
4250 test=get(handles.AutoVec,'Value');
4251 if test
4252     set(handles.AutoVec,'BackgroundColor',[1 1 0])
4253 else
4254     update_plot(handles);
4255     %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4256     set(handles.AutoVec,'BackgroundColor',[0.7 0.7 0.7])
4257 end
4258 
4259 %-------------------------------------------------------
4260 % --- Executes on selection change in decimate4 (nb_vec/4).
4261 %-------------------------------------------------------
4262 function decimate4_Callback(hObject, eventdata, handles)
4263 update_plot(handles)
4264 
4265 
4266 %-------------------------------------------------------
4267 % --- Executes on selection change in color_code menu
4268 %-------------------------------------------------------
4269 function color_code_Callback(hObject, eventdata, handles)
4270 set_vec_col_bar(handles)
4271 update_plot(handles);
4272 
4273 %-------------------------------------------------------
4274 % --- Executes on button press in AutoVecColor.
4275 %-------------------------------------------------------
4276 function AutoVecColor_Callback(hObject, eventdata, handles)
4277 test=get(handles.AutoVecColor,'Value');
4278 if test
4279     set(handles.AutoVecColor,'BackgroundColor',[1 1 0])
4280 else
4281     update_plot(handles);
4282     %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4283     set(handles.AutoVecColor,'BackgroundColor',[0.7 0.7 0.7])
4284 end
4285 %set_vec_col_bar(handles)
4286 
4287 %-------------------------------------------------------
4288 % --- Executes on selection change in max_vec.
4289 %-------------------------------------------------------
4290 function min_vec_Callback(hObject, eventdata, handles)
4291 max_vec_Callback(hObject, eventdata, handles)
4292 
4293 % --- Executes on selection change in max_vec.
4294 function max_vec_Callback(hObject, eventdata, handles)
4295 set(handles.AutoVecColor,'Value',1)
4296 AutoVecColor_Callback(hObject, eventdata, handles)
4297 min_val=str2num(get(handles.min_vec,'String'));
4298 max_val=str2num(get(handles.max_vec,'String'));
4299 slider1=get(handles.slider1,'Value');
4300 slider2=get(handles.slider2,'Value');
4301 colcode1=min_val+(max_val-min_val)*slider1;
4302 colcode2=min_val+(max_val-min_val)*slider2;
4303 set(handles.colcode1,'String',num2str(colcode1))
4304 set(handles.colcode2,'String',num2str(colcode2))
4305 update_plot(handles);
4306 
4307 %-------------------------------------------------------------------
4308 %update the display of color code for vectors
4309 function set_vec_col_bar(handles)
4310 %-------------------------------------------------------------------
4311 %get the image of the color display button 'vec_col_bar' in pixels
4312 set(handles.vec_col_bar,'Unit','pixel');
4313 pos_vert=get(handles.vec_col_bar,'Position');
4314 set(handles.vec_col_bar,'Unit','Normalized');
4315 width=ceil(pos_vert(3));
4316 height=ceil(pos_vert(4));
4317 
4318 %get slider indications
4319 list=get(handles.color_code,'String');
4320 ichoice=get(handles.color_code,'Value');
4321 colcode.ColorCode=list{ichoice};
4322 colcode.MinC=str2num(get(handles.min_vec,'String'));
4323 colcode.MaxC=str2num(get(handles.max_vec,'String'));
4324 test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
4325 if test3color
4326 %     set(handles.colcode1,'Visible','on')
4327 %     set(handles.colcode2,'Visible','on')
4328 %     set(handles.slider1,'Visible','on')
4329 %     set(handles.slider2,'Visible','on')
4330     colcode.colcode1=str2num(get(handles.colcode1,'String'));
4331     colcode.colcode2=str2num(get(handles.colcode2,'String'));
4332 else
4333 %     set(handles.colcode1,'Visible','off')
4334 %     set(handles.colcode2,'Visible','off')
4335 %     set(handles.slider1,'Visible','off')
4336 %     set(handles.slider2,'Visible','off')
4337 %     colcode.colcode1=colcode.min;
4338 %     colcode.colcode2=colcode.max;
4339 end
4340 % colcode.option=get(handles.vec_col_bar,'Value');
4341 colcode.FixedCbounds=0;
4342 % list_code=get(handles.col_vec,'String');% list menu fields
4343 % index_code=get(handles.col_vec,'Value');% selected string index
4344 % colcode.CName= list_code{index_code(1)}; % selected field used for vector color
4345 colcode.FixedCbounds=1;
4346 vec_C=colcode.MinC+(colcode.MaxC-colcode.MinC)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
4347 [colorlist,col_vec]=set_col_vec(colcode,vec_C);
4348 oneheight=ones(1,height);
4349 A1=colorlist(col_vec,1)*oneheight;
4350 A2=colorlist(col_vec,2)*oneheight;
4351 A3=colorlist(col_vec,3)*oneheight;
4352 A(:,:,1)=A1';
4353 A(:,:,2)=A2';
4354 A(:,:,3)=A3';
4355 set(handles.vec_col_bar,'Cdata',A)
4356 
4357 
4358 %-------------------------------------------------------------------
4359 function [PlotType,ScalOut]=update_plot(handles)
4360 %-------------------------------------------------------------------
4361 haxes= handles.axes3;
4362 AxeData=get(haxes,'UserData');
4363 PlotParam=read_plot_param(handles);
4364 [PlotType,PlotParamOut]= plot_field(AxeData,haxes,PlotParam,1);
4365 write_plot_param(handles,PlotParamOut); %update the auto plot parameters
4366 
4367 %-------------------------------------------------------------------
4368 % --- Executes on button press in grid.
4369 function grid_Callback(hObject, eventdata, handles)
4370 %-------------------------------------------------------------------
4371 huvmat=get(handles.create,'parent');
4372 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
4373 % if isequal(get(handles.grid,'Value'),1)
4374    % set(handles.grid,'BackgroundColor',[1 1 0])
4375     %suppress the other options if grid is chosen
4376     set(handles.create,'Value',0)
4377     set(handles.create,'BackgroundColor',[0 1 0])
4378 %     set(handles.LINE,'Value',0)
4379 %     set(handles.LINE,'BackgroundColor',[0 1 0])
4380 %     set(handles.PATCH,'Value',0)
4381 %     set(handles.PATCH,'BackgroundColor',[0 1 0])
4382 %     set(handles.PLANE,'Value',0)
4383 %     set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
4384 %     set(handles.VOLUME,'Value',0)
4385 %     set(handles.VOLUME,'BackgroundColor',[0 1 0])
4386     %set(handles.makemask,'Value',0)
4387     %makemask_Callback(hObject, eventdata, handles)
4388     set(handles.edit_vect,'Value',0)
4389     edit_vect_Callback(hObject, eventdata, handles)
4390     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4391     set(handles.edit_vect,'Value',0)  
4392     edit_vect_Callback(hObject, eventdata, handles)
4393     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4394     set(handles.list_object,'Value',1)      
4395     set(handles.cal,'Value',0)
4396     set(handles.cal,'BackgroundColor',[0 1 0])   
4397    % set(handles.grid,'BackgroundColor',[1 1 0])
4398     %prepare display of the set_grid GUI
4399     data.fixedtitle=1;
4400     [FileName]=read_file_boxes(handles);
4401     %[filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
4402     %[inputfile,idetect]=name_generator(filebase,num_i1,num_j1,Ext,NomType,1,num_i2,num_j2,SubDir);
4403     [hset_object,UvData.sethandles]=set_grid(FileName);% call the set_object interface
4404     set(huvmat,'UserData',UvData);
4405 % else
4406 %     set(handles.grid,'BackgroundColor',[1 0 1])
4407 % end
4408 
4409 %-------------------------------------------------------------------
4410 % --- Executes on selection change in edit.
4411 function edit_Callback(hObject, eventdata, handles)
4412 %-------------------------------------------------------------------
4413 huvmat=get(handles.list_object,'parent');
4414 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
4415 test=get(handles.edit,'Value');
4416 if test
4417     UvData.MouseAction='edit_object';
4418     set(handles.edit,'BackgroundColor',[1,1,0])  
4419     %suppress the other options
4420     set(handles.zoom,'Value',0)
4421     zoom_Callback(hObject, eventdata, handles)
4422     set(handles.create,'Value',0)
4423     set(handles.create,'BackgroundColor',[0 1 0])
4424 %     set(handles.LINE,'Value',0)
4425 %     set(handles.LINE,'BackgroundColor',[0 1 0])
4426 %     set(handles.PATCH,'Value',0)
4427 %     set(handles.PATCH,'BackgroundColor',[0 1 0])
4428 %     set(handles.PLANE,'Value',0)
4429 %     set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
4430 %     set(handles.VOLUME,'Value',0)
4431 %     set(handles.VOLUME,'BackgroundColor',[0 1 0])
4432     set(handles.edit_vect,'Value',0)
4433     edit_vect_Callback(hObject, eventdata, handles)  
4434     set(handles.cal,'Value',0)
4435     set(handles.cal,'BackgroundColor',[0 1 0])   
4436     %set(handles.grid,'Value',0)
4437     %set(handles.grid,'BackgroundColor',[0 1 0])
4438     list_object_Callback(hObject, eventdata, handles)
4439 else 
4440     UvData.MouseAction='none';
4441     set(handles.edit,'BackgroundColor',[0.7,0.7,0.7])   
4442 end
4443 set(huvmat,'UserData',UvData);
4444 
4445 %--------------------------------------------------------
4446 % --- Executes on selection change in list_object.
4447 %--------------------------------------------------------
4448 function list_object_Callback(hObject, eventdata, handles)
4449 huvmat=get(handles.list_object,'parent');
4450 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
4451 list_str=get(handles.list_object,'String');
4452 IndexObj=get(handles.list_object,'Value');
4453 
4454 if ~(length(UvData.Object)>=IndexObj);
4455     return
4456 end
4457 ObjectData=UvData.Object{IndexObj};
4458 ObjectData.desable_open=1; % desable the OPEN option in the set_object GUI (editing mode)
4459 if isequal(get(handles.edit,'Value'),0)
4460     ObjectData.desable_plot=1; % desable the PLOT option in the set_object GUI (editing mode
4461 end
4462 PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4463 ZBounds=0; % default
4464     if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
4465         ZBounds(1)=UvData.ZMin; %minimum for the Z slider
4466         ZBounds(2)=UvData.ZMax;%maximum for the Z slider
4467     end
4468 AxeData.hset_object=set_object(ObjectData,PlotHandles,ZBounds);% call the set_object interface,
4469 pos_uvmat=get(huvmat,'Position');
4470 if isfield(UvData,'SetObjectOrigin')
4471 pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4472 pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
4473 set(AxeData.hset_object,'Position',pos_set_object)
4474 end
4475 hother=findobj('Tag','proj_object');%find all the proj objects
4476 for iobj=1:length(hother)
4477     if isequal(get(hother(iobj),'Type'),'rectangle')|isequal(get(hother(iobj),'Type'),'patch')
4478         set(hother(iobj),'EdgeColor','b')
4479         if isequal(get(hother(iobj),'FaceColor'),'m')
4480             set(hother(iobj),'FaceColor','b')
4481         end
4482     elseif isequal(get(hother(iobj),'Type'),'image')
4483            Acolor=get(hother(iobj),'CData');
4484            Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4485            set(hother(iobj),'CData',Acolor);
4486     else
4487          set(hother(iobj),'Color','b')
4488     end
4489     set(hother(iobj),'Selected','off')
4490 end
4491 hother=findobj('Tag','DeformPoint');
4492 set(hother,'Color','b');
4493 set(hother,'Selected','off')    
4494 if isfield(ObjectData,'HandlesDisplay')
4495     for iview=1:length(ObjectData.HandlesDisplay)
4496         if ishandle(ObjectData.HandlesDisplay(iview))
4497             uistack(ObjectData.HandlesDisplay(iview),'top')
4498             linetype=get(ObjectData.HandlesDisplay(iview),'Type');
4499             if isequal(linetype,'line')
4500                 set(ObjectData.HandlesDisplay(iview),'Color','m'); %set the selected object to magenta color
4501             elseif isequal(linetype,'rectangle')
4502                 set(ObjectData.HandlesDisplay(iview),'EdgeColor','m'); %set the selected object to magenta color
4503             elseif isequal(linetype,'patch')
4504                 set(ObjectData.HandlesDisplay(iview),'FaceColor','m'); %set the selected object to magenta color
4505             end 
4506             SubObjectData=get(ObjectData.HandlesDisplay(iview),'UserData');
4507             if isfield(SubObjectData,'SubObject')& ishandle(SubObjectData.SubObject)
4508                 uistack(SubObjectData.SubObject,'top')
4509                 for iobj=1:length(SubObjectData.SubObject)
4510                     hsub=SubObjectData.SubObject(iobj);
4511                     if isequal(get(hsub,'Type'),'rectangle')
4512                         set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4513                     elseif isequal(get(hsub,'Type'),'image')
4514                        Acolor=get(hsub,'CData');
4515                        Acolor(:,:,1)=Acolor(:,:,3);
4516                        set(hsub,'CData',Acolor);
4517                     else
4518                         set(hsub,'Color','m')
4519                     end
4520                 end
4521             end
4522             if isfield(SubObjectData,'DeformPoint')& ishandle(SubObjectData.DeformPoint)
4523                 set(SubObjectData.DeformPoint,'Color','m')
4524             end
4525         end
4526     end
4527 end
4528 
4529 %------------------------------------------------------
4530 % --- Executes on button press in Menu/Export/field in workspace.
4531 %------------------------------------------------------
4532 function MenuExportField_Callback(hObject, eventdata, handles)
4533 
4534 global CurData
4535 huvmat=get(handles.RootPath,'parent');
4536 CurData=get(huvmat,'UserData');
4537 evalin('base','global CurData')%make CurData global in the workspace
4538 display(['UserData of uvmat :'])
4539 evalin('base','CurData') %display CurData in the workspace
4540 commandwindow;
4541 
4542 %------------------------------------------------------
4543 % --- Executes on button press in Menu/Export/extract figure.
4544 %------------------------------------------------------
4545 function MenuExport_plot_Callback(hObject, eventdata, handles)
4546 huvmat=get(handles.MenuExport_plot,'parent');
4547 UvData=get(huvmat,'UserData');
4548 hfig=figure;
4549 newaxes=copyobj(handles.axes3,hfig);
4550 map=colormap(handles.axes3);
4551 colormap(map);%transmit the current colormap to the zoom fig
4552 colorbar
4553 
4554 
4555 % --------------------------------------------------------------------
4556 function Insert_Callback(hObject, eventdata, handles)
4557 
4558 
4559 % --------------------------------------------------------------------
4560 function MenuRun_Callback(hObject, eventdata, handles)
4561 
4562 
4563 % --------------------------------------------------------------------
4564 function MenuHelp_Callback(hObject, eventdata, handles)
4565 % --------------------------------------------------------------------
4566 path_to_uvmat=which ('uvmat');% check the path of uvmat
4567 pathelp=fileparts(path_to_uvmat);
4568 helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
4569 if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
4570 else
4571     web(helpfile);
4572 end
4573 
4574 % --------------------------------------------------------------------
4575 function MenuOpen_Callback(hObject, eventdata, handles)
4576 
4577 % --------------------------------------------------------------------
4578 % --- Executes on selection change in sub_menu.
4579 %---------------------------------------------------------------------
4580 function MenuOpen_1_Callback(hObject, eventdata, handles)
4581 
4582 % --------------------------------------------------------------------
4583 function MenuExport_Callback(hObject, eventdata, handles)
4584 
4585 
4586 % --------------------------------------------------------------------
4587 function MenuExportMovie_Callback(hObject, eventdata, handles)
4588 
4589 set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
4590 huvmat=get(handles.run0,'parent');
4591 UvData=get(huvmat,'UserData');
4592 [xx,xx,FileBase]=read_file_boxes(handles);
4593  %read the current input file name
4594 prompt = {'movie file name';'frames per second';'frame resolution (*[512x384] pixels)';'axis position relative to the frame';'total frame number (starting from the current uvmat display)'};
4595 dlg_title = 'select properties of the output avi movie';
4596 num_lines= 1;
4597 nbfield_cell=get(handles.last_i,'String');
4598 def     = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
4599 answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
4600 aviname=answer{1};
4601 fps=str2num(answer{2});
4602 % check for existing file with output name aviname
4603 if exist(aviname,'file')
4604     backup=aviname;
4605     testexist=2;
4606     while testexist==2
4607         backup=[backup '~'];
4608         testexist=exist(backup,'file');      
4609     end
4610     [success,message]=copyfile(aviname,backup);%make backup of the existing file
4611     if isequal(success,1)
4612         delete(aviname)%delete existing file
4613     else
4614         msgbox_uvmat('ERROR',message)
4615         return
4616     end 
4617 end
4618 %create avi open
4619 aviobj=avifile(aviname,'Compression','None','fps',fps);
4620 
4621 %display first view for tests
4622 newfig=figure;
4623 newaxes=copyobj(handles.axes3,newfig);%new plotting axes in the new figure
4624 set(newaxes,'Tag','movieaxes')
4625 nbpix=[512 384]*str2num(answer{3});
4626 set(gcf,'Position',[1 1 nbpix])% resolution XVGA
4627 set(newaxes,'Position',eval(answer{4}));
4628 map=colormap(handles.axes3);
4629 colormap(map);%transmit the current colormap to the zoom fig
4630 msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
4631         ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
4632 UvData.Object{1}.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
4633 set(huvmat,'UserData',UvData);
4634 increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
4635 set(handles.STOP,'Visible','on')
4636 set(handles.speed,'Visible','on')
4637 set(handles.speed_txt,'Visible','on')
4638 set(handles.RunMovie,'BusyAction','queue')
4639 
4640 imin=str2num(get(handles.i1,'String'));
4641 imax=str2num(answer{5});
4642 % if isfield(UvData,'Time')
4643 htitle=get(newaxes,'Title');
4644 xlim=get(newaxes,'XLim');
4645 ylim=get(newaxes,'YLim');
4646 set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
4647 time_str=get(handles.abs_time,'String');
4648 set(htitle,'String',['t=' time_str])
4649 set(handles.speed,'Value',1)
4650 for i=1:imax
4651     if get(handles.speed,'Value')~=0 & isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
4652             runpm(hObject,eventdata,handles,increment)
4653             drawnow
4654             time_str=get(handles.abs_time,'String');
4655             if ishandle(htitle)
4656              set(htitle,'String',['t=' time_str])
4657             end
4658             mov=getframe(newfig);
4659             aviobj=addframe(aviobj,mov);
4660     end
4661 end
4662 aviobj=close(aviobj);
4663 UvData.Object{1}.plotaxes=handles.axes3;
4664 set(huvmat,'UserData',UvData);
4665 msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
4666 
4667 % --------------------------------------------------------------------
4668 function MenuPoints_Callback(hObject, eventdata, handles)
4669 set(handles.create,'Visible','on')
4670 set(handles.create,'Value',1)
4671 POINTS_Callback(hObject,eventdata,handles)
4672 
4673 % --------------------------------------------------------------------
4674 function MenuLine_Callback(hObject, eventdata, handles)
4675 set(handles.create,'Visible','on')
4676 set(handles.create,'Value',1)
4677 LINE_Callback(hObject,eventdata,handles)
4678 
4679 % ------------------------------------------------------------------
4680 function MenuPatch_Callback(hObject, eventdata, handles)
4681 set(handles.create,'Visible','on')
4682 set(handles.create,'Value',1)
4683 PATCH_Callback(hObject,eventdata,handles)
4684 
4685 % ------------------------------------------------------------------
4686 function MenuPlane_Callback(hObject, eventdata, handles)
4687 set(handles.create,'Visible','on')
4688 set(handles.create,'Value',1)
4689 PLANE_Callback(hObject,eventdata,handles)
4690 
4691 % ------------------------------------------------------------------
4692 function MenuVolume_Callback(hObject, eventdata, handles)
4693 set(handles.create,'Visible','on')
4694 set(handles.create,'Value',1)
4695 VOLUME_Callback(hObject,eventdata,handles)
4696 
4697 % ------------------------------------------------------------------
4698 function MenuCalib_Callback(hObject, eventdata, handles)
4699 set(handles.TOOLS_txt,'Visible','on')
4700 set(handles.frame_tools,'Visible','on')
4701 set(handles.cal,'Visible','on')
4702 set(handles.cal,'Value',1)
4703 cal_Callback(hObject,eventdata,handles)
4704 
4705 % ------------------------------------------------------------------
4706 function MenuMask_Callback(hObject, eventdata, handles)
4707 set(handles.TOOLS_txt,'Visible','on')
4708 set(handles.frame_tools,'Visible','on')
4709 set(handles.create,'Visible','on')
4710 set(handles.create,'Value',1)
4711 set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
4712 set(handles.save_mask,'Visible','on')
4713 set(handles.masklevel,'Visible','on')
4714 if isequal(get(handles.z_index,'Visible'),'on')
4715     nb_slice=str2num(get(handles.nb_slice,'String'));
4716     for ilist=1:nb_slice
4717         list_index{ilist,1}=num2str(ilist);
4718     end   
4719     set(handles.masklevel,'String',list_index)
4720     val=str2num(get(handles.z_index,'String'));
4721     if val<=nb_slice
4722         set(handles.masklevel,'Value',val)
4723     end
4724 else
4725     set(handles.masklevel,'String',{'1'})
4726     set(handles.masklevel,'Value',1)
4727 end
4728 if ishandle(handles.UVMAT_title)
4729     delete(handles.UVMAT_title)
4730 end
4731 huvmat=get(handles.create,'parent');
4732 UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
4733 set(handles.zoom,'Value',0)
4734 set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
4735 set(handles.edit_vect,'Value',0)
4736 edit_vect_Callback(hObject, eventdata, handles)
4737 set(handles.edit,'Value',0)
4738 set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4739 set(handles.edit_vect,'Value',0)  
4740 edit_vect_Callback(hObject, eventdata, handles)
4741 set(handles.cal,'Value',0)
4742 set(handles.cal,'BackgroundColor',[0 1 0])
4743 
4744 %initiate the GUI set_object
4745 data.TITLE='MASK';
4746 if isfield(UvData,'CoordType')
4747     data.CoordType=UvData.CoordType;
4748 end
4749 if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
4750     data.YMax=UvData.Mesh;
4751 elseif isfield(UvData.Field,'AX')&&isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
4752     np=size(UvData.Field.A);
4753     meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
4754     meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
4755     data.YMax=max(meshx,meshy);
4756     data.DX=max(meshx,meshy);
4757 end
4758 data.Coord=[0 0 0]; %default
4759 PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
4760 [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
4761 pos_uvmat=get(huvmat,'Position');
4762 if isfield(UvData,'SetObjectOrigin')
4763     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4764     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
4765     set(hset_object,'Position',pos_set_object)
4766 end
4767 list_object=get(handles.list_object,'String');
4768 if ~isempty(list_object)
4769     set(handles.list_object,'Value',length(list_object))
4770 end
4771 UvData.MouseAction='create_object';
4772 set(huvmat,'UserData',UvData);
4773 
4774 % ------------------------------------------------------------------
4775 %-- open the GUI set_grid.fig to create grid
4776 function MenuGrid_Callback(hObject, eventdata, handles)
4777 set(handles.TOOLS_txt,'Visible','on')
4778 set(handles.frame_tools,'Visible','on')
4779 grid_Callback(hObject,eventdata,handles)
4780 
4781 %----------------------------------------------------------------
4782 % open the GUI 'series'
4783 %----------------------------------------------------------------
4784 function MenuSeries_Callback(hObject, eventdata, handles)
4785 
4786 [param.FileName]=read_file_boxes(handles);
4787 if isequal(get(handles.SubField,'Value'),1)
4788     FileName_1=read_file_boxes_1(handles);%
4789     if ~isequal(FileName_1,param.FileName)
4790         param.FileName_1=FileName_1;
4791     end
4792 end
4793 param.NomType=get(handles.FileIndex,'UserData');
4794 param.NomType_1=get(handles.FileIndex_1,'UserData');
4795 param.comp_input=get(handles.fix_pair,'Value');
4796 huvmat=get(handles.MenuSeries,'parent');
4797 UvData=get(huvmat,'UserData');
4798 if isfield(UvData,'Time')
4799     param.Time=UvData.XmlData.Time;
4800 end
4801 if isequal(get(handles.scan_i,'Value'),1)
4802     param.incr_i=str2num(get(handles.increment_scan,'String'));
4803 elseif isequal(get(handles.scan_j,'Value'),1)
4804     param.incr_j=str2num(get(handles.increment_scan,'String'));
4805 end
4806 param.list_fields=get(handles.Fields,'String');% list menu fields
4807 param.list_fields(1)=[]; %suppress  'image' option
4808 param.index_fields=get(handles.Fields,'Value');% selected string index
4809 if param.index_fields>1
4810     param.index_fields=param.index_fields-1;
4811 end
4812 param.list_fields_1=get(handles.Fields_1,'String');% list menu fields
4813 param.list_fields_1(1)=[]; %suppress  'image' option
4814 param.index_fields_1=get(handles.Fields_1,'Value')-1;% selected string index
4815 if param.index_fields_1>1
4816     param.index_fields_1=param.index_fields_1-1;
4817 end
4818 param.civ1=get(handles.civ1,'Value');
4819 param.civ2=get(handles.civ2,'Value');
4820 param.interp1=get(handles.interp1,'Value');
4821 param.interp2=get(handles.interp2,'Value');
4822 param.filter1=get(handles.filter1,'Value');
4823 param.filter2=get(handles.filter2,'Value');
4824 param.menu_coord_str=get(handles.menu_coord,'String');
4825 param.menu_coord_val=get(handles.menu_coord,'Value');
4826 
4827 series(param); %run the series interface
4828 
4829 % ------------------------------------------------------------------
4830 % -- open the GUI civ.fig for civx (PIV)
4831 % ------------------------------------------------------------------
4832 function MenuPIV_Callback(hObject, eventdata, handles)
4833  
4834 [FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles);
4835 [P,F,str1,str2,str_a,str_b]=name2display(FileName);
4836 num1=stra2num(str1);
4837 num2=stra2num(str2);
4838 num_a=stra2num(str_a);
4839 num_b=stra2num(str_b);
4840 NomType=get(handles.FileIndex,'UserData');
4841 ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
4842 if isequal(ext,'.nc') ||  isequal(ext,'.cdf')% netcdf files
4843     ind_opening=2;% propose 'fix' as the default option
4844 % +read the current netcdf rootfile
4845     Data=nc2struct(FileName,[]);
4846     if isfield(Data,'fix') & isequal(Data.fix,1)
4847         ind_opening=3;
4848     end
4849     if isfield(Data,'patch') & isequal(Data.patch,1)
4850         ind_opening=4;
4851     end
4852     if isfield(Data,'civ2') & isequal(Data.civ2,1)
4853         ind_opening=5;
4854     end
4855     if isfield(Data,'fix2') & isequal(Data.fix2,1)
4856         ind_opening=6;
4857     end
4858 end      
4859 varargin{1}=filebase;
4860 varargin{2}=NomType;
4861 varargin{3}=num1;
4862 varargin{4}=num2;
4863 varargin{5}=num_a;
4864 varargin{6}=num_b;
4865 varargin{7}=SubDir;
4866 varargin{8}=ind_opening;% A REVOIR +TRANSMETTRE IMADOC INFO
4867 varargin{11}=ext;
4868 civ(varargin);% interface de civ(not in the uvmat file)
4869 
4870 % ------------------------------------------------------------------
4871 function MenuTools_Callback(hObject, eventdata, handles)
4872 
4873 % ------------------------------------------------------------------
4874 function MenuEdit_Callback(hObject, eventdata, handles)
4875 
4876 %--------------------------------------------------------------------------
4877 function enable_transform(handles,state)
4878 set(handles.menu_coord,'Visible',state)
4879 set(handles.TRANSFORM_txt,'Visible',state)    
4880 set(handles.menu_coord,'Visible',state)  
4881 set(handles.path_transform,'Visible',state)
4882 set(handles.pxcmx_txt,'Visible',state)
4883 set(handles.pxcmy_txt,'Visible',state)
4884 set(handles.pxcm,'Visible',state)
4885 set(handles.pycm,'Visible',state)
4886 
4887 % --------------------------------------------------------------------
4888 function MenuEditVectors_Callback(hObject, eventdata, handles)
4889 set(handles.edit_vect,'Visible','on')
4890 set(handles.edit_vect,'Value',1)
4891 edit_vect_Callback(hObject, eventdata, handles)
4892 
4893 
4894 
4895

Generated on Fri 13-Nov-2009 11:17:03 by m2html © 2003