source: trunk/src/uvmat.m @ 61

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

gestion of projection objects improved. Implementation of view_field.fig
introduction of a circle to mark vectors with the mouse
various cleaning and debugging

File size: 211.7 KB
Line 
1%'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization
2%------------------------------------------------------------------------
3% function huvmat=uvmat(input)
4%
5%OUTPUT
6% huvmat=current handles of the GUI uvmat.fig
7%%
8%
9%INPUT:
10% input: input file name (if character chain), or input image matrix to
11% visualize, or Matlab structure representing  netcdf fields (with fields
12% ListVarName....)
13%
14%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
15%  Copyright Joel Sommeria,  2008, LEGI / CNRS-UJF-INPG, joel.sommeria@legi.grenoble-inp.fr.
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%     This open is part of the toolbox UVMAT.
18%
19%     UVMAT is free software; you can redistribute it and/or modify
20%     it under the terms of the GNU General Public License as published by
21%     the Free Software Foundation; either version 2 of the License, or
22%     (at your option) any later version.
23%
24%     UVMAT is distributed in the hope that it will be useful,
25%     but WITHOUT ANY WARRANTY; without even the implied warranty of
26%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27%     GNU General Public License (open UVMAT/COPYING.txt) for more details.
28%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
29%
30% Information stored on the interface:
31%    'Strings' of all edit boxes and menus: get(handles.Tag,'String')
32%    'Values' of all menus and toggle buttons: get(handles.Tag,'Value')
33%     Matlab structure stored as 'UserData' of the figure uvmat.fig,(can be obtained by right mouse click on the interface).
34%          It contains the following fields:
35%     - Fixed specifiacation of plotting figures and axes (defined bu uvmat_OpeningFcn)
36%          .PosColorbar: [0.8210 0.4710 0.0190 0.4450]; specified position of the colorbar on figures
37%     - Information read in the documentation open of a series (activated by RootPath_Callback) :
38%          .XmlData, with fields:
39%               .Time: matrix of times of the images with index i and j
40%               .GeometryCalib: [1x1 struct]
41%     - Information defined from the interface:
42%           .NewSeries: =1 when the first view of a new field series is displayed, else 0
43%           .filename:(char string)
44%           .VelType:(char string) type of velocity field selected
45%           .VelType_1:(char string)  REMPLACER LE CELL ACTUEL
46%           .FieldName: (char string) main field selected('image', 'velocity'...)
47%           .FieldName_1:(char string) second field selected('image', 'velocity'...)
48%           .CName: (char string)name of the scalar used for vector colors
49%           .CoordType: (char string) coordinate transform: e.g. 'phys' or 'px'
50%           .MouseAction: store the current effect of mouse button (create or edit objects)
51%     - Information on  projection objects
52%           .Object: {[1x1 struct]}
53%           .CurrentObjectIndex: index of the projection object .Object currently selected for editing
54%     -Information on the current field (Field{i})
55%            .Txt : text information to display (e.g. error message)
56%            .NbDim: number of dimensions (=0 by default)
57%            .NbCoord: number of vector components
58%            .CoordType: expresses the type of coordinate ('px' for image, 'sig' for instruments, or 'phys')
59%            .dt: time interval for the corresponding image pair
60%            .Mesh: estimated typical distance between vectors
61%            .ZMax:
62%            .ZMin:
63%            .X, .Y, .Z: set of vector coordinates
64%            .U,.V,.W: corresponding set of vector components
65%            .F: corresponding set of warning flags
66%            .FF: corresponding set of false flags, =0 for good vectors
67%            .C: corresponding values of the scalar used for vector color
68%             (.X, .Y, .Z,.U,.V,.W,.F,.FF,.C are matlab vectors of the same length,
69%                     equal to the number of vectors stored in the input open)
70%            .CName: name of the scalar .C
71%            .CType: type of the scalar .C, setting how the scalar is obtained (see 'Scalars' below)
72%            .A image or scalar
73%            .AX: vector of dimension 2 representing the first and last values
74%              of the X coordinates for the image or scalar known on a regular grid,
75%              or vector of dimension .A for a scaler defined on irregular grid.
76%            .AY: same as .AX along the Y direction
77%            .AName: name of the scalar, ='image' for an image
78
79% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   DATA FLOW  (for run0_Callback) %%%%%%%%%%%%%%%%%%%%:
80%
81%               Main input open   second input open(_1)        second image (pair animation)
82% read_ncfield.m         |                 |                             
83% read image.m           |                 |                                               
84%                     Field{1}         Field{2}               
85%                                                                         |
86% coord transform (phys.m) or other user defined  fct acting on Field{i}  |
87%                                                                   Field{i}
88%                                                                    |
89% calc_field.m: calculate scalar or other derived fields (vort, div..).
90%
91% sub_field.m: combine the input Field{i} in a single set of fields (vector + scalar):
92%              Field{i=1->3}.X --> UvData.X                          |
93%                                                                    |
94%                                                                 UvData
95%                                                                    |
96% plot histograms of the whole  field
97% proj_field.m: project the set of fields on the current projection objects defined by UvData.Object
98%                                                                    |                                                                          |
99%                                                                ObjectData
100%                                                                    |
101% plot_field.m: plot the projected fields and store them as user     |
102% data of the plotting axes                                          |
103%                                                                    |
104%                                                                AxeData
105%
106%%%%%%%%%%%%%%    SCALARS: %%%%%%%%%%%%??%%%
107% scalars are displayed either as an image or countour plot, either as a color of
108% velocity vectors. The scalar values in the first case is represented by
109% UvData.Field.A, and by UvData.Field.C in the second case. The corresponding set of X
110% and Y coordinates are represented by UvData.Field.AX and UvData.Field.AY, and .X and
111% .Y for C (the same as velocity vectors). If A is a nxxny matrix (scalar
112% on a regtular grid), then .AX andf.AY contains only two elements, represneting the
113% coordinates of the four image corners. The scalar name is represented by
114% the strings .AName and/or .CName.
115% If the scalar exists in an input open (image or scalar stored under its
116% name in a netcdf open), it is directly read at the level of Field{1}or Field{2}.
117% Else only its name AName is recorded in Field{i}, and its field is then calculated
118%by the fuction calc_scal after the coordinate transform or after projection on an edit
119     
120% Properties attached to plotting figures (standard Matlab properties):
121%    'CurrentAxes'= gca or get(gcf,'CurrentAxes');
122%    'CurrentPoint'=get(gcf,'CurrentPoint'): figure coordinates of the point over which the mouse is positioned
123%    'CurrentCharacter'=get(gcf,'CurrentCharacter'): last character typed  over the figure where the mouse is positioned
124%    'WindowButtonMotionFcn': function permanently called by mouse motion over the figure
125%    'KeyPressFcn': function called by pressing a key on the key board
126%    'WindowButtonDownFcn':  function called by pressing the mouse over the  figure
127%    'WindowButtonUpFcn': function called by releasing  the mouse pressure over the  figure
128
129% Properties attached to plotting axes:
130%    'CurrentPoint'=get(gca,'CurrentPoint'); (standard Matlab) same as for the figure, but position in plot coordinates.
131%     AxeData:=get(gca,'UserData');
132%     AxeData.Drawing  = create: create a new edit
133%                       = deform: modify an existing edit by moving its defining create
134%                      = off: no current drawing action
135%                     = translate: translate an existing edit
136%                    = zoom: isolate a subregion for zoom in=1 if an edit is being currently drawn, 0 else (set to 0 by releasing mouse button)
137%            .hset_edit=handle of the set_edit interface (if a projection edit is edited);
138%            .CurrentOrigin: Origin of a curently drawn edit
139%            .CurrentLine: currently drawn menuline (A REVOIR)
140%            .CurrentObject: handle of the currently drawn edit
141%            .CurrentRectZoom: current rectangle used for zoom
142%            .zoomon : zoom state (a revoir)
143%            .X, .Y, .Z: array of coordinates defining the position of the vector: ASSOCIER AU PLAN (OBJET) PLUTOT QU'A L'AXE ?
144%            .U, .V, .W: array of components of the vector
145%            .C:
146%            .F:
147%            .FF:
148%            .A
149
150% Properties attached to projection objects (create, menuline, menuplane...):
151%    'Tag'='proj_edit': for all projection objects
152%    ObjectData.Style=...: style of projection edit:
153%              .ProjMode
154%              .Coord: defines the position of the edit
155%              .XMin,YMin....
156%              .XMax,YMax....
157%              .DX,DY,DZ
158%              .Phi, .Theta, .Psi : Euler angles
159%              .X,.Y,.U,.V.... : field data projected on the edit
160%              .IndexObj: index in the list of UvData.Object
161           %during plotting
162%               .plotaxes: handles of the current axes used to plot the  result of field projection on the object
163%               .plothandle: vector of handle(s) of the object graphic represnetation in all the opened plotting axes
164% To each projection object #iobj, corresponds an axis
165% Object{iobj}.plotaxes and nbobj representation graphs  Object{iobj}.plothandles(:) (where nbobj is the
166% nbre of current objects opened in uvmat. Note that Object{iobj}.plothandles(iobj)=[] : an object is not represented in its own projection field;
167%-------------------------------------------------------------------
168%-------------------------------------------------------------------
169%  I - MAIN FUNCTION UVMAT (DO NOT MODIFY)
170%-------------------------------------------------------------------
171%-------------------------------------------------------------------
172function varargout = uvmat(varargin)
173
174% Begin initialization code - DO NOT EDIT
175gui_Singleton = 1;
176gui_State = struct('gui_Name',          mfilename, ...
177                   'gui_Singleton',     gui_Singleton, ...
178                   'gui_OpeningFcn',    @uvmat_OpeningFcn, ...
179                   'gui_OutputFcn',     @uvmat_OutputFcn, ...
180                   'gui_LayoutFcn',     [], ...
181                   'gui_Callback',      []);
182if nargin && ischar(varargin{1})
183    gui_State.gui_Callback = str2func(varargin{1});
184end
185
186if nargout
187    varargout{1:nargout} = gui_mainfcn(gui_State, varargin{:});
188else
189    gui_mainfcn(gui_State, varargin{:});
190end
191% End initialization code - DO NOT EDIT
192
193%-------------------------------------------------------------------
194% --- Executes just before uvmat is made visible.
195function uvmat_OpeningFcn(hObject, eventdata, handles, input )
196%-------------------------------------------------------------------
197%WARNING: avoid the second input parameter, leads to erros
198global dircur dir_opening nb_builtin
199% Choose default command menuline output for uvmat
200handles.output = hObject;
201
202% Update handles structure
203guidata(hObject, handles);
204
205dircur=pwd; %current working directory
206dir_opening=dircur;
207
208% set the position of colorbar and ancillary GUIs:
209set(hObject,'Units','Normalized')
210movegui(hObject,'center')
211UvData.PosColorbar=[0.805 0.022 0.019 0.445];
212UvData.SetObjectOrigin=[-0.05 -0.03]; %position for set_object
213UvData.SetObjectSize=[0.3 0.7];
214UvData.CalOrigin=[0.95 -0.03];%position for geometry_calib (TO IMPROVE)
215UvData.CalSize=[0.28 1];
216
217%functions for the mouse and keyboard
218set(handles.histo_u,'NextPlot','replacechildren');
219set(handles.histo_v,'NextPlot','replacechildren');
220set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
221set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})%set mouse action functio
222set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
223set(hObject,'WindowButtonUpFcn',{'mouse_up',handles})
224
225%TRANSFORM menu: loads the information stored in prefdir to initiate the browser and the list of functions
226menu_str={'';'phys';'px';'phys_polar'};
227nb_builtin=numel(menu_str); %number of functions
228path_uvmat=fileparts(which('uvmat'));
229addpath(fullfile(path_uvmat,'transform_field'))
230fct_handle{1,1}=[];
231testexist=zeros(size(menu_str'));%default
232testexist(1)=1;
233for ilist=2:length(menu_str)
234    if exist(menu_str{ilist},'file')
235        fct_handle{ilist,1}=str2func(menu_str{ilist});
236        testexist(ilist)=1;
237    else
238        testexist(ilist)=0;
239    end
240end
241rmpath(fullfile(path_uvmat,'transform_field'))
242
243%refresh projection plane
244UvData.Object{1}.Style='plane';%main plotting plane
245UvData.Object{1}.ProjMode='projection';%main plotting plane
246if ~isfield(UvData.Object{1},'plotaxes')
247    UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis
248    set(handles.list_object_1,'String',{'1-PLANE'});
249    set(handles.list_object_1,'Value',1);
250end
251
252%load the list of previously browsed files in menus Open and Open_1
253 dir_perso=prefdir; % path to the directory .matlab for personal data
254 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmauvmat_perso.mat' in .matlab
255 if exist(profil_perso,'file')
256      h=load (profil_perso);
257      if isfield(h,'MenuFile_1')
258          set(handles.MenuFile_1,'Label',h.MenuFile_1);
259          set(handles.MenuFile_1_1,'Label',h.MenuFile_1);
260      end
261      if isfield(h,'MenuFile_1')
262          set(handles.MenuFile_2,'Label',h.MenuFile_2);
263          set(handles.MenuFile_2_1,'Label',h.MenuFile_2);
264      end
265      if isfield(h,'MenuFile_1')
266          set(handles.MenuFile_3,'Label',h.MenuFile_3);
267          set(handles.MenuFile_3_1,'Label',h.MenuFile_3);
268      end
269      if isfield(h,'MenuFile_1')
270          set(handles.MenuFile_4,'Label',h.MenuFile_4);
271          set(handles.MenuFile_4_1,'Label',h.MenuFile_4);
272      end
273      if isfield(h,'MenuFile_1')
274          set(handles.MenuFile_5,'Label',h.MenuFile_5);
275          set(handles.MenuFile_5_1,'Label',h.MenuFile_5);
276      end
277      if isfield(h,'transform_fct') && iscell(h.transform_fct)
278         for ilist=1:length(h.transform_fct);
279             [path,file]=fileparts(h.transform_fct{ilist});
280             addpath(path)
281             if exist(file,'file')
282                h_func=str2func(file);
283                testexist=[testexist 1]; %#ok<AGROW>
284             else
285                h_func=[];
286                testexist=[testexist 0];  %#ok<AGROW>
287             end
288             fct_handle=[fct_handle; {h_func}];%#ok<AGROW> %concatene the list of paths
289             rmpath(path)
290             menu_str=[menu_str; {file}]; %#ok<AGROW>
291         end
292      end
293 end
294menu_str=menu_str(testexist==1);%=menu_str(testexist~=0)
295fct_handle=fct_handle(testexist==1);
296menu_str=[menu_str;{'more...'}];
297set(handles.transform_fct,'String',menu_str)
298set(handles.transform_fct,'UserData',fct_handle)% store the list of path in UserData of ACTION
299 
300%initiates menu of vector colors
301list_menu=calc_field;
302%list_menu=[{'ima_cor'};{'black'};{'white'};list_menu(3:end)];
303set(handles.col_vec,'String',list_menu)
304
305%check the path and date of modification of all functions in uvmat
306path_to_uvmat=which ('uvmat');% check the path detected for source file uvmat
307[errormsg,date_str]=check_functions;%check the path of the functions called by uvmat.m
308date_str=['last modification: ' date_str];
309%case of an input argument for uvmat
310testinputfield=0;
311inputfile=[];
312Field=[];
313if exist('input','var')
314    if ~isempty(errormsg)
315        msgbox_uvmat('WARNING',errormsg)
316    end
317    if ishandle(handles.UVMAT_title)
318        delete(handles.UVMAT_title)
319    end   
320    if isstruct(input)
321        if isfield(input,'InputFile')
322            inputfile=input.InputFile;
323        end
324        Field=input;
325    elseif ischar(input)% file name introduced as input
326           inputfile=input;
327    elseif isnumeric(input)%simple matrix introduced as input
328        sizinput=size(input);
329        if sizinput(1)<=1 || sizinput(2)<=1
330            msgbox_uvmat('ERROR','bad input for uvmat: file name, structure or numerical matrix accepted')
331            return
332        end
333        Field.ListVarName={'A','coord_y','coord_x'};
334        Field.VarDimName={{'coord_y','coord_x'},'cord_y','coord_x'};
335        Field.A=input;
336        Field.coord_x=[0.5 size(input,2)-0.5];
337        Field.coord_y=[size(input,1)-0.5 0.5];
338    end
339    if ~isempty(inputfile)
340        display_file_name(hObject, eventdata, handles,inputfile)
341        testinputfield=1;
342    else
343        UvData.TestInputFile=0;
344    end
345    if ~isempty(Field)
346        set(handles.Fields,'Value',1)
347        set(handles.Fields,'String',{'get_field...'})   
348       % set(handles.Fields,'UserData',Field)
349        testinputfield=1;
350       
351        % set the colorbar position on the interface:
352        UvData.PosColorbar=[0.805 0.022 0.019 0.445];
353    elseif ischar(input)
354        scan_i_Callback(handles.scan_i, eventdata, handles);       
355    end
356else
357   if ishandle(handles.UVMAT_title)
358       fid=fopen('revision.log');
359       if fid~=-1
360        a=textscan(fid,'%s%s%s',1,'HeaderLines',1,'Delimiter','|');
361        set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; ['at revision ' a{1}{1}]};a{3}{1};date_str;errormsg]);
362        fclose(fid);
363       else
364           set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat;date_str};errormsg]);
365       end
366   end
367end
368UvData.NewSeries=1;
369set(hObject,'UserData',UvData)
370if testinputfield
371    %delete drawn objects
372    hother=findobj(handles.axes3,'Tag','proj_object');%find all the proj objects
373    for iobj=1:length(hother)
374        delete_object(hother(iobj))
375    end 
376    if isempty(inputfile)
377        errormsg=refresh_field(handles,[],[],[],[],[],[],{Field});
378        set(handles.MenuTools,'Enable','on')
379        set(handles.OBJECT_txt,'Visible','on')
380        set(handles.edit,'Visible','on')
381        set(handles.list_object_1,'Visible','on')
382        set(handles.frame_object,'Visible','on')
383    else
384        update_rootinfo(hObject,eventdata,handles);
385    end
386end
387set_vec_col_bar(handles) %update the display of color code for vectors
388
389%-------------------------------------------------------------------
390% --- Outputs from this function are returned to the command menuline.
391function varargout = uvmat_OutputFcn(hObject, eventdata, handles)
392varargout{1} = handles.output;% the only output argument is the handle to the GUI figure
393
394%-------------------------------------------------------------------
395%-------------------------------------------------------------------
396% II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
397% automatically sets the global properties when the rootfile name is introduced
398% then activate the view-field action if selected
399% it is activated either by clicking on the RootPath window or by the
400% browser
401%------------------------------------------------------------------
402%------------------------------------------------------------------
403
404% --- Executes on the menu Open/Browse...
405% search the files, recognize their type according to their name and fill the rootfile input windows
406function MenuBrowse_Callback(hObject, eventdata, handles)
407oldfile=read_file_boxes(handles);
408
409if isempty(oldfile)||isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
410         dir_perso=prefdir;
411         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
412         if exist(profil_perso,'file')
413              h=load (profil_perso);
414             if isfield(h,'MenuFile_1')
415                  oldfile=h.MenuFile_1;
416             end
417         end
418end
419[FileName, PathName] = uigetfile( ...
420       {'*.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)';
421       '*.xml',  '.xml files '; ...
422        '*.xls',  '.xls files '; ...
423        '*.civ',  '.civ files '; ...
424        '*.jpg',' jpeg image files'; ...
425        '*.png','.png image files'; ...
426        '*.tif','.tif image files'; ...
427        '*.avi;*.AVI','.avi movie files'; ...
428        '*.nc','.netcdf files'; ...
429        '*.cdf','.netcdf files'; ...
430        '*.cmx','.cmx text files';...
431        '*.cmx2','.cmx2 text files';...
432        '*.fig','.fig files (matlab fig)';...
433        '*.log','.log text files ';...
434        '*.dat','.dat text files ';...
435        '*.*',  'All Files (*.*)'}, ...
436        'Pick a file',oldfile);
437%global filebase
438fileinput=[PathName FileName];%complete file name
439testblank=findstr(fileinput,' ');%look for blanks
440if ~isempty(testblank)
441    msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])
442    return
443end
444sizf=size(fileinput);
445if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
446
447% display the selected field and related information
448display_file_name(hObject, eventdata, handles,fileinput)
449
450%update list of recent files in the menubar
451MenuFile_1=fileinput;
452MenuFile_2=get(handles.MenuFile_1,'Label');
453MenuFile_3=get(handles.MenuFile_2,'Label');
454MenuFile_4=get(handles.MenuFile_3,'Label');
455MenuFile_5=get(handles.MenuFile_4,'Label');
456set(handles.MenuFile_1,'Label',MenuFile_1)
457set(handles.MenuFile_2,'Label',MenuFile_2)
458set(handles.MenuFile_3,'Label',MenuFile_3)
459set(handles.MenuFile_4,'Label',MenuFile_4)
460set(handles.MenuFile_5,'Label',MenuFile_5)
461set(handles.MenuFile_1_1,'Label',MenuFile_1)
462set(handles.MenuFile_2_1,'Label',MenuFile_2)
463set(handles.MenuFile_3_1,'Label',MenuFile_3)
464set(handles.MenuFile_4_1,'Label',MenuFile_4)
465set(handles.MenuFile_5_1,'Label',MenuFile_5)
466dir_perso=prefdir;
467profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
468if exist(profil_perso,'file')
469    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
470else
471    txt=ver;
472    Release=txt(1).Release;
473    relnumb=str2double(Release(3:4));
474    if relnumb >= 14
475        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
476    else
477        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
478    end
479end
480
481% --------------------------------------------------------------------
482function MenuFile_1_Callback(hObject, eventdata, handles)
483fileinput=get(handles.MenuFile_1,'Label');
484display_file_name(hObject, eventdata, handles,fileinput)
485
486% --------------------------------------------------------------------
487function MenuFile_2_Callback(hObject, eventdata, handles)
488fileinput=get(handles.MenuFile_2,'Label');
489display_file_name(hObject, eventdata, handles,fileinput)
490
491% --------------------------------------------------------------------
492function MenuFile_3_Callback(hObject, eventdata, handles)
493fileinput=get(handles.MenuFile_3,'Label');
494display_file_name(hObject, eventdata, handles,fileinput)
495
496% --------------------------------------------------------------------
497function MenuFile_4_Callback(hObject, eventdata, handles)
498fileinput=get(handles.MenuFile_4,'Label');
499display_file_name(hObject, eventdata, handles,fileinput)
500
501% --------------------------------------------------------------------
502function MenuFile_5_Callback(hObject, eventdata, handles)
503fileinput=get(handles.MenuFile_5,'Label');
504display_file_name(hObject, eventdata, handles,fileinput)
505
506%-----------------------------------------------------------------
507% fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
508%----------------------------------------------------------------
509function display_file_name(hObject, eventdata, handles,fileinput)
510if ~exist(fileinput,'file')
511    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
512    return
513end
514[RootPath,RootFile,i1,i2,str_a,str_b,ext,NomType,SubDir]=name2display(fileinput);
515ext_test=''; %default
516if ~isempty(ext)
517    form=imformats(ext(2:end));%test valid Matlab image formats
518    if ~isempty(form)
519        ext_test='.image';
520        imainfo=imfinfo(fileinput); 
521        if length(imainfo) >1 %case of image with multiple frames
522            i1='1'; % set the frame counter to 1 by default
523            i2='';
524            str_a='';
525            str_b='';
526            NomType='*'; %indicate a set of indexed frames within a single file
527            [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
528        end
529    elseif isequal(lower(ext),'.avi')
530        ext_test='.image';
531        i1='1'; % set the frame counter to 1 by default
532        i2='';
533        str_a='';
534        str_b='';
535        NomType='*'; %indicate a set of indexed frames within a single file
536        [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
537    else
538        ext_test=lower(ext);
539    end
540end
541switch ext_test
542    case {'.civ','.log','.cmx','.cmx2','.txt'}  %display text file
543        edit(fileinput) 
544    case '.fig'                           %display matlab figure
545        hfig=open(fileinput);
546        set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
547        set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
548        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
549    case {'.xml','.xls'}                % edit xml or Excel files
550       editxml(fileinput);
551    case {'.avi','.image','.vol','.nc','.cdf'}   
552        set(handles.RootPath,'String',RootPath);
553        if  isequal(SubDir,'')
554            rootname=fullfile(RootPath,RootFile);
555        else
556            rootname=fullfile(RootPath,SubDir,RootFile);
557            SubDir=['/' SubDir]; %display the separator
558        end
559        set(handles.SubDir,'String',SubDir);
560        set(handles.RootFile,'String',['/' RootFile]); %display the separator
561        indices=fileinput(length(rootname)+1:end);
562        indices(end-length(ext)+1:end)=[]; %remove extension
563        set(handles.FileIndex,'String',indices);       
564        set(handles.FileIndex,'UserData',NomType);
565        set(handles.FileExt,'String',ext);
566        % fill file index counters
567        set(handles.i1,'String',i1);
568     
569        set(handles.i2,'String',i2);
570        set(handles.j1,'String',str_a);
571        set(handles.j2,'String',str_b);
572       
573        % synchronise indices of the second  input file if it exists
574        if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers
575            [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
576            NomType_1=get(handles.FileIndex_1,'UserData');     
577            [FileName_1,idetect]=name_generator(FileBase_1,stra2num(i1),stra2num(i2),FileExt_1,NomType_1,1,stra2num(str_a),stra2num(str_b),SubDir_1);
578            if idetect
579                FileIndex_1=name_generator('',stra2num(i1),stra2num(i2),'',NomType_1,1,stra2num(str_a),stra2num(str_b),'');
580                set(handles.FileIndex_1,'String',FileIndex_1)
581            else
582                set(handles.SubField,'Value',0)
583                SubField_Callback(hObject, eventdata, handles)
584            end
585        end 
586
587        %enable other menus
588        set(handles.MenuOpen_1,'Enable','on')
589        set(handles.MenuFile_1_1,'Enable','on')
590        set(handles.MenuFile_2_1,'Enable','on')
591        set(handles.MenuFile_3_1,'Enable','on')
592        set(handles.MenuFile_4_1,'Enable','on')
593        set(handles.MenuFile_5_1,'Enable','on')
594        set(handles.MenuExport,'Enable','on')
595        set(handles.MenuExportFigure,'Enable','on')
596        set(handles.MenuExportMovie,'Enable','on')
597        set(handles.MenuTools,'Enable','on')
598        set(handles.OBJECT_txt,'Visible','on')
599        set(handles.edit,'Visible','on')
600        set(handles.list_object_1,'Visible','on')
601        set(handles.frame_object,'Visible','on')
602         % initiate input file:
603        update_rootinfo(hObject,eventdata,handles); 
604    otherwise
605       msgbox_uvmat('ERROR',['invalid input file extension' ext])
606end
607
608%-------------------------------------------------------------------
609function RootPath_Callback(hObject,eventdata,handles)
610update_rootinfo(hObject,eventdata,handles);
611
612%-------------------------------------------------------------------
613%-- called by action in RootFile edit box
614%-------------------------------------------------------------------
615function SubDir_Callback(hObject, eventdata, handles)
616%refresh the menu of input fields
617Fields_Callback(hObject, eventdata, handles);
618% refresh the current field
619run0_Callback(hObject, eventdata, handles);
620
621
622%-------------------------------------------------------------------
623%-- called by action in RootFile edit box
624%-------------------------------------------------------------------
625function RootFile_Callback(hObject, eventdata, handles)
626update_rootinfo(hObject,eventdata,handles)
627
628%-------------------------------------------------------------------
629%-- called by action in FileIndex edit box
630%-------------------------------------------------------------------
631function FileIndex_Callback(hObject, eventdata, handles)
632NomType_str=get(handles.FileIndex,'String') ;
633[P,F,str1,str2,str_a,str_b]=name2display(['xx' NomType_str get(handles.FileExt,'String')]);
634% display the new index values on the counters
635set(handles.i1,'String',str1);
636set(handles.i2,'String',str2);
637set(handles.j1,'String',str_a);
638set(handles.j2,'String',str_b);
639
640%-------------------------------------------------------------------
641% -- update information about a new field series (indices to scan, timing, calibration from an xml file, then refresh current plots
642%-------------------------------------------------------------------
643function update_rootinfo(hObject,eventdata,handles)
644global dircur  dir_opening
645
646set(handles.RootPath,'BackgroundColor',[1 1 0])
647drawnow
648set(handles.Fields,'UserData',[])% reinialize data from uvmat opening
649UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface
650UvData.NewSeries=1; %flag for run0: begin a new series
651UvData.TestInputFile=1;
652set(handles.fix_pair,'Value',0) % desactivate by default the comp_input '-'input window
653%FileIndex_Callback(hObject, eventdata, handles)% update field counters
654
655[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
656if ~exist(FileName,'file')
657   msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
658    return
659end
660nbfield=[];%default
661nburst=[];%default
662
663% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
664XmlData.Time=[];%default
665XmlData.GeometryCalib=[];%default
666TimeUnit=[];%default
667testima=0; %test for image input
668if isequal(lower(FileExt),'.avi') %.avi file
669    testima=1;
670    info=aviinfo([FileBase FileIndices FileExt]);
671    nbfield=info.NumFrames;
672    nburst=1;
673    set(handles.Dt_txt,'String',['Dt=' num2str(1000/info.FramesPerSecond) 'ms']);%display the elementary time interval in millisec
674    XmlData.Time=(0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond)';
675    TimeUnit='s';
676    set(handles.npx,'String',num2str(info.Width));%fills nbre of pixels x box
677    set(handles.npy,'String',num2str(info.Height));%fills nbre of pixels y box
678    hhh=which('mmreader');
679    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the function is found (recent version of matlab)
680        UvData.MovieObject=mmreader([FileBase FileIndices FileExt]);
681    end
682elseif ~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol')%&& isequal(NomType,'*')% multi-frame image
683    testima=1;
684    if ~isequal(SubDir,'')
685       RootFile=get(handles.RootFile,'String');
686        imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]);
687    else
688        imainfo=imfinfo([FileBase FileIndices FileExt]);
689    end
690    if length(imainfo) >1 %case of image with multiple frames
691        nbfield=length(imainfo);
692        nburst=1;
693    end
694    if isfield(UvData,'MovieObject')
695        UvData=rmfield(UvData,'MovieObject');
696    end
697else
698    %set(handles.last_i,'String','');%fills last_field box
699    set(handles.npx,'String','');%fills nbre of pixels x box
700    set(handles.npy,'String','');%fills nbre of pixels y box
701    if isfield(UvData,'MovieObject')
702        UvData=rmfield(UvData,'MovieObject');
703    end
704end
705
706% read parameters (time, geometric calibration..) from a documentation file (.xml advised)
707filexml=[FileBase '.xml'];
708fileciv=[FileBase '.civ'];
709warntext='';%default warning message
710NbSlice=1;%default
711
712if exist(filexml,'file')
713    set(handles.view_xml,'Visible','on')
714    set(handles.view_xml,'BackgroundColor',[1 1 0])
715    set(handles.RootPath,'BackgroundColor',[1 1 1])
716    set(handles.view_xml,'String','view .xml')
717    drawnow
718    [XmlData,warntext]=imadoc2struct(filexml);
719    if ~isempty(warntext)
720        msgbox_uvmat('WARNING',warntext)
721    end
722    if isfield(XmlData,'TimeUnit')
723        if isfield(XmlData,'TimeUnit')&& ~isempty(XmlData.TimeUnit)
724            TimeUnit=XmlData.TimeUnit;
725        end
726    end
727    set(handles.view_xml,'BackgroundColor',[1 1 1])
728    drawnow
729elseif exist(fileciv,'file')% if .civ file found
730    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
731    GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
732    GeometryCalib.Tx=0;
733    GeometryCalib.Ty=0;
734    GeometryCalib.Tz=1;
735    GeometryCalib.dpx=1;
736    GeometryCalib.dpy=1;
737    GeometryCalib.sx=1;
738    GeometryCalib.Cx=0;
739    GeometryCalib.Cy=0;
740    GeometryCalib.f=1;
741    GeometryCalib.kappa1=0;
742    GeometryCalib.CoordUnit='cm';
743    XmlData.GeometryCalib=GeometryCalib;
744    if error==2, warntext=['no file ' FileBase '.civ'];
745    elseif error==1, warntext='inconsistent number of fields in the .civ file';
746    end 
747    set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
748    set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
749    set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
750    set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
751    set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
752    set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
753    set(handles.view_xml,'Visible','on')   
754    set(handles.view_xml,'String','view .civ')
755else
756    set(handles.view_xml,'Visible','off')
757end
758
759% store last index in handles.lat_i and .last_j
760if ~isempty(XmlData.Time)
761    nbfield=size(XmlData.Time,1);
762    nburst=size(XmlData.Time,2);
763end
764last_i_cell=get(handles.last_i,'String');
765if isempty(nbfield)
766    last_i_cell{1}='';
767else
768    last_i_cell{1}=num2str(nbfield);
769end
770set(handles.last_i,'String',last_i_cell)
771last_j_cell=get(handles.last_j,'String');
772if isempty(nburst)
773     last_j_cell{1}='';
774else
775     last_j_cell{1}=num2str(nburst);
776end
777set(handles.last_j,'String',last_j_cell);
778
779% store geometric calibration in UvData
780if isfield(XmlData,'GeometryCalib')
781    GeometryCalib=XmlData.GeometryCalib;
782    if isempty(GeometryCalib)
783        set(handles.pxcm,'String','')
784        set(handles.pycm,'String','')
785        set(handles.transform_fct,'Value',1); %  no transform by default
786    else
787        if (isfield(GeometryCalib,'R')& ~isequal(GeometryCalib.R(2,1),0) & ~isequal(GeometryCalib.R(1,2),0)) |...
788            (isfield(GeometryCalib,'kappa1')& ~isequal(GeometryCalib.kappa1,0))
789            set(handles.pxcm,'String','var')
790            set(handles.pycm,'String','var')
791        else
792            pixcmx=GeometryCalib.f*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
793            pixcmy=GeometryCalib.f*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
794            set(handles.pxcm,'String',num2str(pixcmx))
795            set(handles.pycm,'String',num2str(pixcmy))
796        end
797        set(handles.transform_fct,'Value',2); % phys transform by default
798        if isfield(GeometryCalib,'SliceCoord')
799           siz=size(GeometryCalib.SliceCoord);
800           if siz(1)>1
801               NbSlice=siz(1);
802               set(handles.slices,'Visible','on')
803               set(handles.slices,'Value',1)
804           end
805           if isequal(GeometryCalib.NbSlice,'volume')
806               set(handles.nb_slice,'String','volume')
807           else
808               set(handles.nb_slice,'String',num2str(NbSlice))
809           end
810           slices_Callback(hObject, eventdata, handles)
811    %        Coord=UvData.XmlData.GeometryCalib.SliceCoord;
812    %        ZIndex=num_i1-NbSlice*(floor((num_i1-1)/NbSlice));
813        end
814
815           
816    end
817end
818
819%update the data attached to the uvmat interface
820% set(handles.nb_slice,'String',num2str(NbSlice))
821if ~isempty(TimeUnit)
822    set(handles.time_txt,'String',['time (' TimeUnit ')'])
823end
824%set(handles.DtUnit,'String',['10^(-3)' TimeUnit])
825UvData.TimeUnit=TimeUnit;
826UvData.XmlData=XmlData;
827UvData.NewSeries=1;
828set(handles.uvmat,'UserData',UvData)
829
830%display warning message
831if ~isequal(warntext,'')
832    msgbox_uvmat('WARNING',warntext);
833end
834
835% set default options in menu 'Fields'
836if testima
837   set(handles.Fields,'Value',1) % set menu to 'image'
838   set(handles.Fields,'String',{'image';'get_field...';'velocity';'vort';'div';'more...'})
839elseif isequal(FileExt,'.nc')||isequal(FileExt,'.cdf')
840   Data=nc2struct(FileName,'ListGlobalAttribute','absolut_time_T0','civ');
841   col_vec=get(handles.col_vec,'String');
842   if ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0)
843       set(handles.Fields,'String',{'image';'get_field...';'velocity';'vort';'div';'more...'})
844       set(handles.Fields,'Value',3) % set menu to 'velocity'
845       col_vec{1}='ima_cor';
846   else %general netcdf file (not civx)
847       set(handles.Fields,'Value',1) % set menu to 'get_field...
848       set(handles.Fields,'String',{'get_field...'})
849       col_vec{1}='get_field...';
850   end
851   set(handles.col_vec,'String',col_vec)
852else
853    msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
854    return
855end 
856
857% set index navigation options and refresh plots
858set(handles.RootPath,'BackgroundColor',[1 1 1])
859drawnow
860set_scan_options(hObject, eventdata, handles)
861
862
863%-------------------------------------------------------------------
864%-- set index navigation options for new series input and refresh plot
865%-------------------------------------------------------------------
866function set_scan_options(hObject, eventdata, handles)
867
868%  set the corresponding index navigation options (TO CHECK WITH THE SECOND FIELD)
869NomType=get(handles.FileIndex,'UserData');
870NomType_1=get(handles.FileIndex_1,'UserData');
871state_j='off'; %default
872scan_option='i';
873switch NomType
874    case {'_i_j','_i_j1-j2','_i1-i2_j','#_ab'},% two navigation indices
875        state_j='on';
876        if exist('nbfield','var') && isequal(nbfield,1)
877            scan_option='j';
878        else
879            scan_option='i';               
880        end
881end
882if ~isempty(NomType_1)
883    switch NomType_1
884        case {'_i_j','_i_j1-j2','_i1-i2_j','#_ab'},% two navigation indices
885            state_j='on';
886            if exist('nbfield','var') && isequal(nbfield,1)
887                scan_option='j';
888            else
889                scan_option='i';               
890            end
891    end
892end
893if isequal(scan_option,'i')
894     set(handles.scan_i,'Value',1)
895     scan_i_Callback(hObject, eventdata, handles);
896else
897     set(handles.scan_j,'Value',1)
898     scan_j_Callback(hObject, eventdata, handles);
899end
900set(handles.scan_j,'Visible',state_j)
901set(handles.j1,'Visible',state_j)
902set(handles.j2,'Visible',state_j)
903set(handles.last_j,'Visible',state_j);
904set(handles.frame_j,'Visible',state_j);
905set(handles.j_text,'Visible',state_j);
906
907% view the field 
908run0_Callback(hObject, eventdata, handles); %view field
909mask_test=get(handles.mask_test,'value');
910if mask_test
911    MaskData=get(handles.mask_test,'UserData');
912    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
913          delete(MaskData.maskhandle)    %delete old mask
914    end
915    mask_test_Callback(hObject, eventdata, handles)
916end
917
918%-------------------------------------------------------------------
919function MenuBrowse_1_Callback(hObject, eventdata, handles)
920%-------------------------------------------------------------------
921% huvmat=get(handles.run0,'parent');
922UvData=get(handles.uvmat,'UserData');
923
924RootPath=get(handles.RootPath,'String');
925[FileName, PathName, filterindex] = uigetfile( ...
926       {'*.xml;*.xls;*.civ;*.jpg;*.png;*.avi;*.AVI;*.nc;*.cmx;*.fig;*.log;*.dat', ' (*.xml,*.xls,*.civ, *.jpg,*.png, *.avi,*.nc,*.cmx ,*.fig,*.log,*.dat)';
927       '*.xml',  '.xml files '; ...
928        '*.xls',  '.xls files '; ...
929        '*.civ',  '.civ files '; ...
930        '*.jpg','.jpg image files'; ...
931        '*.png','.png image files'; ...
932        '*.avi;*.AVI','.avi movie files'; ...
933        '*.nc','.netcdf files'; ...
934        '*.cdf','.netcdf files'; ...
935        '*.cmx','.cmx text files';...
936        '*.cmx2','.cmx2 text files';...
937        '*.fig','.fig files (matlab fig)';...
938        '*.log','.log text files ';...
939        '*.dat','.dat text files ';...
940        '*.*',  'All Files (*.*)'}, ...
941        'Pick a file',RootPath);
942fileinput_1=[PathName FileName];%complete file name
943testblank=findstr(fileinput_1,' ');%look for blanks
944if ~isempty(testblank)
945    msgbox_uvmat('ERROR',['The input file name ' fileinput_1 ' contains blank character : This is not allowed. Please change name'])
946    return
947end
948sizf=size(fileinput_1);
949if (~ischar(fileinput_1)|~isequal(sizf(1),1)),return;end
950
951% refresh the current displayed field
952display_file_name_1(hObject,eventdata,handles,fileinput_1)
953
954%update list of recent files in the menubar
955MenuFile_1=fileinput_1;
956MenuFile_2=get(handles.MenuFile_1,'Label');
957MenuFile_3=get(handles.MenuFile_2,'Label');
958MenuFile_4=get(handles.MenuFile_3,'Label');
959MenuFile_5=get(handles.MenuFile_4,'Label');
960set(handles.MenuFile_1,'Label',MenuFile_1)
961set(handles.MenuFile_2,'Label',MenuFile_2)
962set(handles.MenuFile_3,'Label',MenuFile_3)
963set(handles.MenuFile_4,'Label',MenuFile_4)
964set(handles.MenuFile_5,'Label',MenuFile_5)
965set(handles.MenuFile_1_1,'Label',MenuFile_1)
966set(handles.MenuFile_2_1,'Label',MenuFile_2)
967set(handles.MenuFile_3_1,'Label',MenuFile_3)
968set(handles.MenuFile_4_1,'Label',MenuFile_4)
969set(handles.MenuFile_5_1,'Label',MenuFile_5)
970dir_perso=prefdir;
971profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
972if exist(profil_perso,'file')
973    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
974else
975    txt=ver;
976    Release=txt(1).Release;
977    relnumb=str2num(Release(3:4));
978    if relnumb >= 14
979        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
980    else
981        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
982    end
983end
984
985% --------------------------------------------------------------------
986function MenuFile_1_1_Callback(hObject, eventdata, handles)
987fileinput_1=get(handles.MenuFile_1_1,'Label');
988display_file_name_1(hObject,eventdata,handles,fileinput_1)
989
990% --------------------------------------------------------------------
991function MenuFile_2_1_Callback(hObject, eventdata, handles)
992fileinput_1=get(handles.MenuFile_2_1,'Label');
993display_file_name_1(hObject,eventdata,handles,fileinput_1)
994
995% --------------------------------------------------------------------
996function MenuFile_3_1_Callback(hObject, eventdata, handles)
997fileinput_1=get(handles.MenuFile_3_1,'Label');
998display_file_name_1(hObject,eventdata,handles,fileinput_1)
999
1000% --------------------------------------------------------------------
1001function MenuFile_4_1_Callback(hObject, eventdata, handles)
1002fileinput_1=get(handles.MenuFile_4_1,'Label');
1003display_file_name_1(hObject,eventdata,handles,fileinput_1)
1004
1005% --------------------------------------------------------------------
1006function MenuFile_5_1_Callback(hObject, eventdata, handles)
1007fileinput_1=get(handles.MenuFile_5_1,'Label');
1008display_file_name_1(hObject,eventdata,handles,fileinput_1)
1009
1010%-----------------------------------------------------------------
1011% fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
1012%----------------------------------------------------------------
1013function display_file_name_1(hObject,eventdata,handles,fileinput_1)
1014
1015%[path,name,ext]=fileparts(fileinput_1);
1016[RootPath_1,RootFile_1,field_count,str2,str_a,str_b,FileExt_1,NomType_1,SubDir_1]=name2display(fileinput_1);
1017nbfield_1=1; %default
1018ext_test=FileExt_1;%default
1019form=imformats(FileExt_1(2:end));
1020if ~isempty(form) % if the extension corresponds to an image format recognized by Matlab
1021    imainfo=imfinfo(fileinput_1); 
1022    nbfield_1=length(imainfo);
1023    ext_test='.image';
1024elseif isequal(lower(FileExt_1),'.avi')
1025    info=aviinfo(fileinput_1);
1026    nbfield_1=info.NumFrames;
1027    ext_test='.image';
1028end
1029
1030%open directly fig or text files
1031switch ext_test
1032    case {'.civ','.log','.cmx','.cmx2','.txt'}  %display text file
1033        edit(fileinput) 
1034        return
1035    case '.fig'                           %display matlab figure
1036        hfig=open(fileinput);
1037        set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
1038        set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
1039        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
1040        return
1041    case {'.xml','.xls'}                % edit xml or Excel files
1042       heditxml=editxml(fileinput);
1043       return
1044    case {'.image','.nc','.cdf'}
1045%         set(handles.FileIndex,'UserData',NomType_1);
1046    otherwise
1047        msgbox_uvmat(['invalid input file extension ' FileExt_1 ' for uvmat'],'ERROR')
1048        return
1049end
1050
1051% test for image series in a single file and synchronise file indices of the two series
1052if nbfield_1 >1 %case of image with multiple frames
1053    if nbfield_1 < num_i1
1054        msgbox_uvmat('ERROR','current frame index beyond the input movie length')
1055        return
1056    else
1057        NomType_1='*'; %indicate a set of indexed frames within a single file
1058        filename_new=fileinput_1;
1059    end
1060else  % cases of data files   
1061    RootPath=get(handles.RootPath,'String');
1062    RootFile=get(handles.RootFile,'String');
1063    FileBase=fullfile(RootPath,RootFile);
1064    FileBase_1=fullfile(RootPath_1,RootFile_1);
1065    if isequal(FileBase,FileBase_1)
1066        filename_new=fileinput_1;
1067    else       
1068        num_i1=stra2num(get(handles.i1,'String'));%get the current file indices from counters
1069        num_j1=stra2num(get(handles.j1,'String'));
1070        num_i2=stra2num(get(handles.i2,'String'));
1071        num_j2=stra2num(get(handles.j2,'String'));
1072        [filename_new,idetect]=...
1073           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
1074        indices=''; %default
1075        if ~idetect
1076            msgbox_uvmat('ERROR','second input file with indices corresponding to the first one does not exist')
1077            return
1078        end
1079    end
1080end
1081set(handles.FileIndex,'UserData',NomType_1);
1082
1083% make visible and fill the second raw of edit boxes
1084set(handles.RootPath_1,'Visible','on')
1085set(handles.RootFile_1,'Visible','on')
1086set(handles.SubDir_1,'Visible','on');
1087set(handles.FileIndex_1,'Visible','on');
1088set(handles.FileExt_1,'Visible','on');
1089[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
1090if isequal(FileBase,FileBase_1)
1091    set(handles.RootPath_1,'String','"')
1092    set(handles.RootFile_1,'String','"');
1093else
1094    set(handles.RootPath_1,'String',RootPath_1)
1095    set(handles.RootFile_1,'String',['/' RootFile_1]);
1096end
1097if  isequal(SubDir_1,'')
1098     set(handles.SubDir_1,'String','');
1099     FileBaseSub_1=FileBase_1;
1100else 
1101    set(handles.SubDir_1,'String',['/' SubDir_1]);
1102    FileBaseSub_1=fullfile(FileBase_1,SubDir_1);
1103end
1104indices=filename_new(length(FileBaseSub_1)+1:end);
1105indices(end-length(FileExt_1)+1:end)=[]; %remove extension
1106set(handles.FileIndex_1,'String',indices)
1107set(handles.FileIndex_1,'UserData',NomType_1)
1108set(handles.FileExt_1,'String',FileExt_1);
1109
1110% default choice of fields
1111if isequal(ext_test,'.image')
1112   set(handles.Fields_1,'String',{'';'image';'get_field...';'velocity';'vort';'div';'more...'})
1113   set(handles.Fields_1,'Value',2) % set menu to 'image'
1114elseif isequal(FileExt_1,'.nc')|isequal(FileExt_1,'.cdf')
1115   Data=nc2struct(fileinput_1,[]);
1116   if isfield(Data,'absolut_time_T0')
1117       set(handles.Fields_1,'String',{'';'image';'get_field...';'velocity';'vort';'div';'more...'})
1118       set(handles.Fields_1,'Value',4) % set menu to 'velocity'
1119   else   
1120       set(handles.Fields_1,'Value',2) % set menu to 'get_field...'
1121       set(handles.Fields_1,'String',{'';'get_field...'});
1122   end
1123end 
1124set(handles.SubField,'Visible','on')
1125set(handles.SubField,'Value',1)
1126RootPath_1_Callback(hObject,eventdata,handles); 
1127
1128
1129%-----------------------------------------------------
1130function RootPath_1_Callback(hObject,eventdata,handles)
1131update_rootinfo_1(hObject,eventdata,handles)
1132
1133%-------------------------------------------------------------------
1134function RootFile_1_Callback(hObject, eventdata, handles)
1135update_rootinfo_1(hObject,eventdata,handles)
1136%-------------------------------------------------------------------
1137
1138%-------------------------------------------------------------------
1139function update_rootinfo_1(hObject,eventdata,handles) %A REVOIR
1140
1141set(handles.RootPath_1,'BackgroundColor',[1 1 0])% indicate active program by yellow color
1142drawnow
1143%huvmat=get(handles.RootPath,'parent');
1144UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface
1145UvData.NewSeries=1; %flag for run0: begin a new series
1146
1147[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes_1(handles);
1148if ~exist(FileName,'file')
1149    msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
1150end
1151nbfield_1=[];%default
1152nburst_1=[];%default
1153XmlData.Time=[];
1154XmlData.GeometryCalib=[];%default
1155TimeUnit=[];
1156if isfield(UvData,'TimeUnit')
1157    TimeUnit=UvData.TimeUnit;
1158end
1159TimeUnit_1=[];
1160testima=0; %test for image input
1161if isequal(lower(FileExt),'.avi') %.avi file
1162    testima=1;
1163    info=aviinfo([FileBase FileIndices FileExt]);
1164    nbfield_1=info.NumFrames;
1165    nburst_1=1;
1166    %set(handles.last_i,'String',num2str(info.NumFrames));%fills last_field box
1167    set(handles.Dt_txt,'String',['Dt=' num2str(1000/info.FramesPerSecond) 'ms']);%display the elementary time interval in millisec
1168%     set(handles.dt,'UserData',info.FramesPerSecond);
1169    time=[0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond]';
1170    npx=get(handles.npx,'String');
1171    npy=get(handles.npy,'String');
1172    if isequal(npx,'') || isequal(npy,'')
1173        set(handles.npx,'String',num2str(info.Width));%fills nbre of pixels x box
1174        set(handles.npy,'String',num2str(info.Height));%fills nbre of pixels y box
1175    end
1176elseif ~isempty(imformats(FileExt(2:end))) %&& isequal(NomType,'*')% multi-frame image
1177    testima=1;
1178    imainfo=imfinfo([FileBase FileIndices FileExt]); 
1179    if length(imainfo) >1 %case of image with multiple frames
1180        nbfield_1=length(imainfo);
1181        nburst_1=1;
1182        %set(handles.last_i,'String',num2str(length(imainfo)));%fills last_field box
1183    end       
1184else
1185    %set(handles.last_i,'String','');%fills last_field box
1186    set(handles.npx,'String','');%fills nbre of pixels x box
1187    set(handles.npy,'String','');%fills nbre of pixels y box
1188end
1189
1190% find scaling parameters
1191filexml=[FileBase '.xml'];
1192fileciv=[FileBase '.civ'];
1193warntext='';%default warning text
1194if exist(filexml,'file')
1195    [XmlData,warntext]=imadoc2struct(filexml);
1196    if ~isempty(warntext)
1197        msgbox_uvmat('WARNING',warntext)
1198    end
1199    if isfield(XmlData,'Camera')
1200%         if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
1201%             NbSlice=XmlData.Camera.NbSlice;
1202%         end
1203        if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
1204            TimeUnit=XmlData.Camera.TimeUnit;
1205        end
1206    end
1207elseif exist(fileciv,'file')% if .civ file found
1208    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
1209    GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
1210    GeometryCalib.Tx=0;
1211    GeometryCalib.Ty=0;
1212    GeometryCalib.Tz=1;
1213    GeometryCalib.dpx=1;
1214    GeometryCalib.dpy=1;
1215    GeometryCalib.sx=1;
1216    GeometryCalib.Cx=0;
1217    GeometryCalib.Cy=0;
1218    GeometryCalib.f=1;
1219    GeometryCalib.kappa1=0;
1220    GeometryCalib.CoordUnit='cm';
1221    XmlData.GeometryCalib=GeometryCalib;
1222    if error==2, warntext=['no file ' FileBase '.civ'];
1223    elseif error==1, warntext='inconsistent number of fields in the .civ file';
1224    end
1225   
1226    set(handles.npx,'String',num2str(npx));%fills nbre of pixels x box
1227    set(handles.npy,'String',num2str(npy));%fills nbre of pixels y box
1228    set(handles.pxcm,'String',num2str(pxcmx));%fills scale x (pixel/cm) box
1229    set(handles.pycm,'String',num2str(pxcmy));%fills scale y (pixel/cm) box
1230    set(handles.pxcm,'Visible','on');%fills scale x (pixel/cm) box
1231    set(handles.pycm,'Visible','on');%fills scale y (pixel/cm) box
1232end   
1233if ~isempty(TimeUnit_1) && ~isequal(TimeUnit_1,TimeUnit)
1234        msgbox_uvmat('WARNING','the time units for the second series differs from the first one')
1235end
1236       
1237% store last index in handles.lat_i and .last_j
1238if ~isempty(XmlData.Time)
1239    nbfield_1=size(XmlData.Time,1);
1240    nburst_1=size(XmlData.Time,2);   
1241end
1242last_i_cell=get(handles.last_i,'String');
1243if isempty(nbfield_1)
1244    last_i_cell{2}='';
1245else
1246    last_i_cell{2}=num2str(nbfield_1);
1247end
1248set(handles.last_i,'String',last_i_cell)
1249last_j_cell=get(handles.last_j,'String');
1250if isempty(nburst_1)
1251     last_j_cell{2}='';
1252else
1253     last_j_cell{2}=num2str(nburst_1);
1254end
1255set(handles.last_j,'String',last_j_cell);
1256if ~isequal(last_i_cell{1},last_i_cell{2}) || ~isequal(last_j_cell{1},last_j_cell{2})
1257        msgbox_uvmat('WARNING','the numbers of input file of the second series differs from the first one')
1258end
1259
1260% store calibration data
1261GeometryCalib=XmlData.GeometryCalib;
1262if isempty(GeometryCalib)
1263    if isfield(UvData, 'GeometryCalib_1')
1264        UvData=rmfield(UvData,'GeometryCalib_1');
1265    end
1266else
1267    UvData.GeometryCalib_1=GeometryCalib;
1268    if (isfield(GeometryCalib,'R')& ~isequal(GeometryCalib.R(2,1),0) & ~isequal(GeometryCalib.R(1,2),0)) |...
1269        (isfield(GeometryCalib,'kappa1')& ~isequal(GeometryCalib.kappa1,0))
1270        set(handles.pxcm,'String','var')
1271        set(handles.pycm,'String','var')
1272    else
1273        pixcmx=GeometryCalib.f*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
1274        pixcmy=GeometryCalib.f*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
1275        set(handles.pxcm,'String',num2str(pixcmx))
1276        set(handles.pycm,'String',num2str(pixcmy))
1277    end
1278end
1279UvData.XmlData_1=XmlData;
1280set(handles.uvmat,'UserData',UvData)%update the data attached to the uvmat interface
1281
1282if ~isequal(warntext,'')
1283    msgbox_uvmat('WARNING',warntext)
1284end
1285
1286set(handles.RootPath_1,'BackgroundColor',[1 1 1])% signa the end the input operation
1287drawnow
1288
1289set_scan_options(hObject, eventdata, handles)
1290
1291%---------------------------------------------------
1292% switch file index scanning options scan_i and scan_j in an exclusive way
1293function scan_i_Callback(hObject, eventdata, handles)
1294%---------------------------------------------------
1295if get(handles.scan_i,'Value')==1
1296    set(handles.scan_i,'BackgroundColor',[1 1 0])
1297    set(handles.scan_j,'Value',0)
1298    set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
1299else
1300    set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
1301    set(handles.scan_j,'Value',1)
1302    set(handles.scan_j,'BackgroundColor',[1 1 0])
1303end
1304
1305%-------------------------------------------------------------------
1306% switch file index scanning options scan_i and scan_j in an exclusive way
1307function scan_j_Callback(hObject, eventdata, handles)
1308%-------------------------------------------------------------------
1309if get(handles.scan_j,'Value')==1
1310    set(handles.scan_j,'BackgroundColor',[1 1 0])
1311    set(handles.scan_i,'Value',0)
1312    set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
1313else
1314    set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
1315    set(handles.scan_i,'Value',1)
1316    set(handles.scan_i,'BackgroundColor',[1 1 0])
1317end
1318
1319%-------------------------------------------------------------------
1320function i1_Callback(hObject, eventdata, handles)
1321%-------------------------------------------------------------------
1322% [filebase,num1,num_a,num2,num_b,ext,NomType,subdir]=read_input_file(handles);
1323%[FileName,RootPath,filebase,xx,FileExt]=read_file_boxes(handles);
1324NomType=get(handles.FileIndex,'UserData');
1325num1=stra2num(get(handles.i1,'String'));
1326num2=stra2num(get(handles.i2,'String'));
1327num_a=stra2num(get(handles.j1,'String'));
1328num_b=stra2num(get(handles.j2,'String'));
1329indices=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
1330set(handles.FileIndex,'String',indices)
1331if get(handles.SubField,'Value')==1
1332    NomType_1=get(handles.FileIndex_1,'String');
1333     FileExt_1=get(handles.FileExt_1,'String');
1334    [P,F,str1,str2,str_a,str_b,Ext,NomType_1]=name2display(['xx' NomType_1 FileExt_1]);
1335     indices=name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,'');
1336     set(handles.FileIndex_1,'String',indices)
1337end
1338run0_Callback(hObject, eventdata, handles)
1339
1340%-------------------------------------------------------------------
1341function i2_Callback(hObject, eventdata, handles)
1342i1_Callback(hObject, eventdata, handles)
1343%-------------------------------------------------------------------
1344
1345%-------------------------------------------------------------------
1346function j1_Callback(hObject, eventdata, handles)
1347i1_Callback(hObject, eventdata, handles)
1348%-------------------------------------------------------------------
1349
1350%-------------------------------------------------------------------
1351function j2_Callback(hObject, eventdata, handles)
1352i1_Callback(hObject, eventdata, handles)
1353%-------------------------------------------------------------------
1354
1355%-------------------------------------------------------------------
1356function slices_Callback(hObject, eventdata, handles)
1357%-------------------------------------------------------------------
1358if get(handles.slices,'Value')==1
1359    set(handles.slices,'BackgroundColor',[1 1 0])
1360    set(handles.nb_slice,'Visible','on')
1361    set(handles.z_text,'Visible','on')
1362    set(handles.z_index,'Visible','on')
1363    nb_slice_Callback(hObject, eventdata, handles)
1364else
1365    set(handles.nb_slice,'Visible','off')
1366    set(handles.slices,'BackgroundColor',[0.7 0.7 0.7])
1367    set(handles.z_text,'Visible','off')
1368    set(handles.z_index,'Visible','off')
1369    set(handles.masklevel,'Value',1)
1370    set(handles.masklevel,'String',{'1'})
1371end
1372
1373%-------------------------------------------------------------------
1374function nb_slice_Callback(hObject, eventdata, handles)
1375%-------------------------------------------------------------------
1376nb_slice_str=get(handles.nb_slice,'String')
1377if isequal(nb_slice_str,'volume')
1378    num=stra2num(get(handles.j1,'String'));
1379    last_j=get(handles.last_j,'String');
1380    nbslice=str2double(last_j{1});
1381else
1382    num=str2double(get(handles.i1,'String'));
1383    nbslice=str2double(get(handles.nb_slice,'String'));
1384end
1385z=mod(num-1,nbslice)+1;
1386set(handles.z_index,'String',num2str(z))
1387for ilist=1:nbslice
1388    list_index{ilist,1}=num2str(ilist);
1389end   
1390set(handles.masklevel,'String',list_index)
1391set(handles.masklevel,'Value',z)
1392
1393
1394%-------------------------------------------------------------------
1395% --- Executes on button press in view_xml.
1396function view_xml_Callback(hObject, eventdata, handles)
1397[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
1398option=get(handles.view_xml,'String');
1399if isequal(option,'view .xml')
1400    FileXml=[FileBase '.xml'];
1401    heditxml=editxml(FileXml);
1402end
1403
1404%-------------------------------------------------------------------
1405% --- Executes on button press in mask_test.
1406function mask_test_Callback(hObject, eventdata, handles)
1407%-------------------------------------------------------------------
1408if isequal(get(handles.mask_test,'Value'),1)
1409    [FF,RootPath,FileBase]=read_file_boxes(handles);
1410    num_i1=stra2num(get(handles.i1,'String'));
1411    num_j1=stra2num(get(handles.j1,'String'));
1412    currentdir=pwd; 
1413    cd(RootPath);
1414    maskfiles=dir('*_*mask_*.png');%look for a mask file
1415    cd(currentdir);%come back to the working directory
1416    mdetect=0;
1417    if isempty(maskfiles)
1418         msgbox_uvmat('ERROR','no mask file detected (format ..._xxmask_ii.png needed), use the menu bar Tools/Make mask')
1419         return
1420    end
1421    for ilist=1:length(maskfiles)
1422        maskname=maskfiles(ilist).name;% take the first mask file in the list
1423        [rr,ff,x1,x2,xa,xb,xext,Mask_NomType{ilist}]=name2display(maskname);
1424        if ~strcmp(Mask_NomType{ilist},Mask_NomType{1})
1425            msgbox_uvmat('ERROR',['inconsistent mask types ' Mask_NomType{1} Mask_NomType{ilist } ' coexist in the current image directory'])
1426            return
1427        end
1428        [Path2,Name,ext]=fileparts(maskname);
1429        Namedouble=double(Name);
1430        val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1431        ind_mask=findstr('mask',Name);
1432        i=ind_mask-1;
1433        while val(i)==0 & i>0
1434            i=i-1;
1435        end
1436        nbmask_str=str2num(Name(i+1:ind_mask-1));
1437        if ~isempty(nbmask_str)
1438            nbslice(ilist)=nbmask_str; % number of different masks (slices)
1439        end
1440    end
1441    if isequal(min(nbslice),max(nbslice))
1442        nbslice=nbslice(1);
1443    else
1444        msgbox_uvmat('ERROR','several inconsistent mask sets coexist in the current image directory')
1445         return
1446    end
1447    if ~isempty(nbslice) && Name(i)=='_'
1448        Mask.Base=[FileBase Name(i:ind_mask+3)];
1449        Mask.NbSlice=nbslice;
1450        num_i1=mod(num_i1-1,nbslice)+1;
1451        Mask.NomType=Mask_NomType{1};
1452        [maskname,mdetect]=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);%
1453        mdetect=exist(maskname,'file');
1454        if mdetect
1455            set(handles.nb_slice,'String',Name(i+1:ind_mask-1));
1456            set(handles.nb_slice,'BackgroundColor',[1 1 0])
1457            set(handles.mask_test,'UserData',Mask); 
1458            set(handles.mask_test,'BackgroundColor',[1 1 0])
1459            if nbslice > 1
1460                set(handles.slices,'value',1)
1461                slices_Callback(hObject, eventdata, handles)
1462            end
1463        end
1464    end
1465    if mdetect==0
1466         msgbox_uvmat('ERROR','no mask file detected (format ..._xxmask_ii.png needed), use the menu bar Tools/Make mask')
1467         set(handles.mask_test,'Value',0)
1468         return
1469    end   
1470    update_mask(handles,num_i1,num_j1);
1471else
1472    MaskData=get(handles.mask_test,'UserData');
1473    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
1474          delete(MaskData.maskhandle)   
1475    end
1476    set(handles.mask_test,'UserData',[])   
1477    %huvmat=get(handles.mask_test,'parent');
1478    UvData=get(handles.uvmat,'UserData');
1479    if isfield(UvData,'MaskName')
1480        UvData=rmfield(UvData,'MaskName');
1481        set(handles.uvmat,'UserData',UvData)
1482    end
1483    set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7])
1484end
1485
1486%-------------------------------------------------------------------
1487function update_mask(handles,num_i1,num_j1)
1488%-------------------------------------------------------------------
1489
1490MaskData=get(handles.mask_test,'UserData');
1491if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1492    uistack(MaskData.maskhandle,'top');
1493end
1494num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1;
1495[MaskName,mdetect]=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType);
1496huvmat=get(handles.mask_test,'parent');
1497UvData=get(huvmat,'UserData');
1498
1499%update mask image if the mask is new
1500if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
1501    UvData.MaskName=MaskName; %update the recorded name on UvData
1502    set(huvmat,'UserData',UvData);
1503    if mdetect==0
1504        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1505            delete(MaskData.maskhandle)   
1506        end
1507    else
1508        %read mask image
1509        Mask.AName='image';
1510        Mask.A=imread(MaskName);
1511        npxy=size(Mask.A);
1512        Mask.AX=[0.5 npxy(2)-0.5];
1513        Mask.AY=[npxy(1)-0.5 0.5 ];
1514        Mask.CoordType='px';
1515        if isequal(get(handles.slices,'Value'),1)
1516           NbSlice=str2num(get(handles.nb_slice,'String'));
1517           num_i1=str2num(get(handles.i1,'String'));
1518           Mask.ZIndex=mod(num_i1-1,NbSlice)+1;
1519        end
1520        %px to phys or other transform on field
1521         menu_transform=get(handles.transform_fct,'String');
1522        choice_value=get(handles.transform_fct,'Value');
1523        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1524        transform_list=get(handles.transform_fct,'UserData');
1525        transform=transform_list{choice_value};
1526        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1527            if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1528                Calib=UvData.XmlData.GeometryCalib;
1529                Mask=transform(Mask,UvData.XmlData);
1530            end
1531        end
1532        flagmask=Mask.A < 200;
1533       
1534        %make brown color image
1535        imflag(:,:,1)=0.9*flagmask;
1536        imflag(:,:,2)=0.7*flagmask;
1537        imflag(:,:,3)=zeros(size(flagmask));
1538       
1539        %update mask image
1540        hmask=[]; %default
1541        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1542            hmask=MaskData.maskhandle;
1543        end
1544        if ~isempty(hmask)
1545            set(hmask,'CData',imflag)   
1546            set(hmask,'AlphaData',flagmask*0.6)
1547            set(hmask,'XData',Mask.AX);
1548            set(hmask,'YData',Mask.AY);
1549%             uistack(hmask,'top')
1550        else
1551            axes(handles.axes3)
1552            hold on   
1553            MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*flagmask);
1554%             set(MaskData.maskhandle,'AlphaData',0.6*flagmask)
1555            set(handles.mask_test,'UserData',MaskData)
1556        end
1557    end
1558end
1559
1560
1561%-------------------------------------------------------------------
1562function MenuExportFigure_Callback(hObject, eventdata, handles)
1563%-------------------------------------------------------------------
1564huvmat=get(handles.MenuExport,'parent');
1565UvData=get(huvmat,'UserData');
1566hfig=figure;
1567newaxes=copyobj(handles.axes3,hfig);
1568map=colormap(handles.axes3);
1569colormap(map);%transmit the current colormap to the zoom fig
1570colorbar
1571
1572%-------------------------------------------------------------------
1573%-------------------------------------------------------------------
1574% III - MAIN REFRESH FUNCTIONS : 'FRAME PLOT'
1575%-------------------------------------------------------------------
1576%-------------------------------------------------------------------
1577
1578%Executes on button press in runplus: make one step forward and call
1579%run0. The step forward is along the fields series 1 or 2 depending on
1580%the scan_i and scan_j check box (exclusive each other)
1581%-------------------------------------------------------------------
1582function runplus_Callback(hObject, eventdata, handles)
1583increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
1584runpm(hObject,eventdata,handles,increment)
1585
1586%-------------------------------------------------------------------
1587%Executes on button press in runmin: make one step backward and call
1588%run0. The step backward is along the fields series 1 or 2 depending on
1589%the scan_i and scan_j check box (exclusive each other)
1590%-------------------------------------------------------------------
1591function runmin_Callback(hObject, eventdata, handles)
1592increment=-str2num(get(handles.increment_scan,'String')); %get the field increment d
1593runpm(hObject,eventdata,handles,increment)
1594
1595%-------------------------------------------------------------------
1596%Executes on button press in runmin: make one step backward and call
1597%run0. The step backward is along the fields series 1 or 2 depending on
1598%the scan_i and scan_j check box (exclusive each other)
1599%-------------------------------------------------------------------
1600function RunMovie_Callback(hObject, eventdata, handles)
1601%------------------------------------------------------------------
1602set(handles.RunMovie,'BackgroundColor',[1 1 0])%paint the command button in yellow
1603drawnow
1604increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
1605set(handles.STOP,'Visible','on')
1606set(handles.speed,'Visible','on')
1607set(handles.speed_txt,'Visible','on')
1608set(handles.RunMovie,'BusyAction','queue')
1609testavi=0;
1610UvData=get(handles.uvmat,'UserData');
1611
1612while get(handles.speed,'Value')~=0 & isequal(get(handles.RunMovie,'BusyAction'),'queue') % enable STOP command
1613        runpm(hObject,eventdata,handles,increment)
1614        pause(1.02-get(handles.speed,'Value'))% wait for next image
1615end
1616if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1617    UvData.aviobj=close(UvData.aviobj);
1618   set(handles.uvmat,'UserData',UvData);
1619end
1620set(handles.RunMovie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1621
1622%-------------------------------------------------------------------
1623function STOP_Callback(hObject, eventdata, handles)
1624%-------------------------------------------------------------------
1625set(handles.movie_pair,'BusyAction','Cancel')
1626set(handles.movie_pair,'value',0)
1627set(handles.RunMovie,'BusyAction','Cancel')
1628set(handles.MenuExportMovie,'BusyAction','Cancel')
1629
1630
1631%------------------------------------------------------------------
1632function runpm(hObject,eventdata,handles,increment)
1633%------------------------------------------------------------------
1634%check for mùovie pair status
1635movie_status=get(handles.movie_pair,'Value');
1636if isequal(movie_status,1)
1637    STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
1638end
1639%read the data on the current input rootfile(s)
1640
1641[FileName,RootPath,filebase,FileIndices,FileExt,subdir]=read_file_boxes(handles);
1642NomType=get(handles.FileIndex,'UserData');
1643
1644num1=stra2num(get(handles.i1,'String'));
1645num2=stra2num(get(handles.i2,'String'));
1646num_a=stra2num(get(handles.j1,'String'));
1647num_b=stra2num(get(handles.j2,'String'));
1648
1649sub_value= get(handles.SubField,'Value');
1650if sub_value % a second input file has been entered
1651    [FileName_1,RootPath_1,filebase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
1652    [pp,ff,str1,str2,str_a,str_b]=name2display(FileIndices_1);
1653    num1_1=stra2num(str1);%current set of indices for the second field (may be set different than the main indices)
1654    num2_1=stra2num(str2);
1655    num_a_1=stra2num(str_a);
1656    num_b_1=stra2num(str_b);
1657    NomType_1=get(handles.FileIndex_1,'UserData');
1658else
1659    filename_1=[];
1660end   
1661
1662comp_input=get(handles.fix_pair,'Value');
1663if isequal(NomType,'_i1-i2')||isequal(NomType,'_i1-i2_j')
1664    comp_input=1; %impose a fixed pair
1665    set(handles.fix_pair,'Value',1)
1666end
1667
1668%case of scanning along the first direction (rootfile numbers)
1669if get(handles.scan_i,'Value')==1% case of scanning along index i   
1670     num1=num1+increment;
1671     num2=num2+increment;
1672     [filename,num1,num_a,num2,num_b]=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
1673     if sub_value% set the second field name and indices
1674        num1_1=num1_1+increment;
1675        num2_1=num2_1+increment;
1676        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
1677     end   
1678else % case of scanning along index j (burst numbers)
1679    num_a=num_a+increment;
1680    num_b=num_b+increment;
1681    if sub_value
1682        num_a_1=num_a_1+increment;
1683        num_b_1=num_b_1+increment;
1684        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
1685%     else % redefine the j index if it exceeds its upper bound (only in the absence of a second field)
1686%         lastfield_cell=get(handles.last_j,'String'); % get the last field number
1687%         lastfield=str2double(lastfield_cell{1});
1688%         if num_a>lastfield && ~isnan(lastfield)
1689%             num_a=mod(num_a,lastfield);
1690%             num_b=mod(num_b,lastfield)
1691%         end
1692    end
1693    filename=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
1694end
1695
1696% refresh plots
1697errormsg=refresh_field(handles,filename,filename_1,num1,num2,num_a,num_b);
1698
1699if isempty(errormsg)  %update the index counters
1700    set(handles.i1,'String',num2stra(num1,NomType,1));
1701    if isequal(num2,num1)
1702         set(handles.i2,'String','');
1703    else
1704        set(handles.i2,'String',num2stra(num2,NomType,1));
1705    end
1706    set(handles.j1,'String',num2stra(num_a,NomType,2));
1707    if isequal(num_b,num_a)
1708         set(handles.j2,'String','');
1709    else
1710        set(handles.j2,'String',num2stra(num_b,NomType,2));
1711    end
1712    [indices]=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
1713    set(handles.FileIndex,'String',indices);
1714    if sub_value
1715         indices_1=name_generator('',num1_1,num_a_1,'',NomType_1,1,num2_1,num_b_1,'');
1716         set(handles.FileIndex_1,'String',indices_1);
1717    end
1718    if isequal(movie_status,1)
1719        set(handles.movie_pair,'Value',1)
1720        movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated
1721    end
1722else
1723     msgbox_uvmat('ERROR',errormsg);
1724end
1725
1726
1727
1728%-------------------------------------------------------
1729% --- Executes on button press in movie_pair: create an alternating movie with two view
1730%-------------------------------------------------------
1731function movie_pair_Callback(hObject, eventdata, handles)
1732status=get(handles.movie_pair,'value');
1733if isequal(status,0)
1734    set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off'
1735    set(handles.i2,'String','')
1736    set(handles.j2,'String','')
1737    return
1738else
1739    set(handles.movie_pair,'BusyAction','queue')
1740end
1741%initialisation
1742set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
1743drawnow
1744list_fields=get(handles.Fields,'String');% list menu fields
1745index_fields=get(handles.Fields,'Value');% selected string index
1746FieldName=list_fields{index_fields}; % selected field
1747if isequal(FieldName,'image')
1748%     run0_Callback(hObject, eventdata, handles)%display the first image
1749    UvData=get(handles.uvmat,'UserData');
1750else
1751    msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
1752    return
1753end
1754[ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
1755NomType=get(handles.FileIndex,'UserData');
1756num_i1=stra2num(get(handles.i1,'String'));
1757num_j1=stra2num(get(handles.j1,'String'));
1758num_i2=stra2num(get(handles.i2,'String'));
1759num_j2=stra2num(get(handles.j2,'String'));
1760if isempty(num_j2)
1761    if isempty(num_i2)   
1762        msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
1763        return
1764    else
1765        num_j2=num_j1;%repeat the index i1 by default
1766    end
1767end
1768if isempty(num_i2)
1769    num_i2=num_i1;%repeat the index i1 by default
1770end
1771imaname_1=name_generator(filebase,num_i2,num_j2,Ext,NomType);
1772if ~exist(imaname_1,'file')
1773      msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
1774      return
1775end
1776% set(handles.i2,'String',''); % indicates that the second index i2 is not used
1777% set(handles.j2,'String',''); % indicates that the second index i2 is not used
1778
1779%read the second image
1780Field.AName='image';
1781Field.AX=UvData.Field.AX;
1782Field.AY=UvData.Field.AY;
1783% z index
1784nbslice=str2double(get(handles.nb_slice,'String'));
1785if ~isempty(nbslice)
1786    Field.ZIndex=mod(num_i2-1,nbslice)+1;
1787end
1788Field.CoordType='px';
1789%determine the input file type
1790if isfield(UvData,'MovieObject')
1791    FileType='movie';
1792elseif isequal(lower(Ext),'.avi')
1793    FileType='avi';
1794elseif isequal(lower(Ext),'.vol')
1795    FileType='vol';
1796else
1797   form=imformats(Ext([2:end]));
1798   if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
1799       if isequal(NomType,'*');
1800           FileType='multimage';
1801       else
1802           FileType='image';
1803       end
1804   end
1805end
1806switch FileType
1807        case 'movie'
1808            Field.A=read(UvData.MovieObject,num_i2);
1809        case 'avi'
1810            mov=aviread(imaname_1,num_i2);
1811            Field.A=frame2im(mov(1));
1812        case 'vol'
1813            Field.A=imread(imaname_1);
1814        case 'multimage'
1815            Field.A=imread(imaname_1,num_i2);
1816        case 'image'
1817            Field.A=imread(imaname_1);
1818end
1819if get(handles.slices,'Value')
1820    Field.ZIndex=str2double(get(handles.z_index,'String'));
1821end
1822
1823%px to phys or other transform on field
1824menu_transform=get(handles.transform_fct,'String');
1825choice_value=get(handles.transform_fct,'Value');
1826transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1827transform_list=get(handles.transform_fct,'UserData');
1828transform=transform_list{choice_value};
1829if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1830    if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1831        Field=transform(Field,UvData.XmlData);
1832    end
1833end
1834
1835 % make movie until movie speed is set to 0 or STOP is activated
1836hima=findobj(handles.axes3,'Tag','ima');% %handles.axes3 =main plotting window (A GENERALISER)
1837set(handles.STOP,'Visible','on')
1838set(handles.speed,'Visible','on')
1839set(handles.speed_txt,'Visible','on')
1840while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue')%isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
1841    % read and plot the series of images in non erase mode
1842    set(hima,'CData',Field.A);
1843    pause(1.02-get(handles.speed,'Value'));% wait for next image
1844    set(hima,'CData',UvData.Field.A);
1845    pause(1.02-get(handles.speed,'Value'));% wait for next image
1846end
1847set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1848
1849%------------------------------------------------------------------------
1850% --- Executes on button press in run0.
1851function run0_Callback(hObject, eventdata, handles)
1852%------------------------------------------------------------------------
1853filename=read_file_boxes(handles);
1854
1855filename_1=[];%default
1856if get(handles.SubField,'Value')
1857    filename_1=read_file_boxes_1(handles);
1858end
1859num_i1=stra2num(get(handles.i1,'String'));
1860num_i2=stra2num(get(handles.i2,'String'));
1861num_j1=stra2num(get(handles.j1,'String'));
1862num_j2=stra2num(get(handles.j2,'String'));
1863errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2);
1864if ~isempty(errormsg)
1865      msgbox_uvmat('ERROR',errormsg);
1866end   
1867
1868%------------------------------------------------------------------------
1869% --- read the input files and refresh all the plots, including projection.
1870% OUTPUT:
1871%  errormsg: error message char string  =[] by default
1872% INPUT:
1873% filename: first input file (=[] in the absence of input file)
1874% filename_1: second input file (=[] in the asbsenc of secodn input file)
1875% num_i1,num_i2,num_j1,num_j2; frame indices
1876% Field: structure describing an optional input field (then replace the input file)
1877
1878function errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,Field)
1879%------------------------------------------------------------------------
1880%initialisation
1881set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
1882drawnow
1883errormsg=[]; % default error message
1884abstime=[];
1885abstime_1=[];
1886dt=[];
1887if ~exist('Field','var')
1888    Field={};
1889end
1890UvData=get(handles.uvmat,'UserData');
1891% if isfield(UvData,'Txt')
1892%     UvData=rmfield(UvData,'Txt');%erase previous error message
1893% end
1894if ishandle(handles.UVMAT_title) %remove title panel on uvmat
1895    delete(handles.UVMAT_title)
1896end
1897
1898% determine the main input file information for action
1899FileType=[];%default
1900if ~isempty(filename)
1901%     [filename,RootPath,filebase,xx,Ext]=read_file_boxes(handles);
1902    if ~exist(filename,'file')
1903        errormsg=['input file ' filename ' does not exist'];
1904        return
1905    end
1906    Ext=get(handles.FileExt,'String');
1907    NomType=get(handles.FileIndex,'UserData');
1908    %update the z position index
1909    nbslice_str=get(handles.nb_slice,'String');
1910    z_index=1;%default
1911    if isequal(nbslice_str,'volume')
1912        z_index=num_j1;
1913        set(handles.z_index,'String',num2str(z_index))
1914    else
1915        nbslice=str2num(nbslice_str);
1916        z_index=mod(num_i1-1,nbslice)+1;
1917        set(handles.z_index,'String',num2str(z_index))
1918    end
1919    % refresh menu for save_mask if relevant
1920    masknumber=get(handles.masklevel,'String');
1921    if length(masknumber)>=z_index
1922        set(handles.masklevel,'Value',z_index)
1923    end
1924
1925    % determine the input file type
1926    if isequal(Ext,'.nc')||isequal(Ext,'.cdf')
1927        FileType='netcdf';
1928    elseif isfield(UvData,'MovieObject')
1929        FileType='movie';
1930        FieldName='image';
1931    elseif isequal(lower(Ext),'.avi')
1932        FileType='avi';
1933        FieldName='image';
1934    elseif isequal(lower(Ext),'.vol')
1935        FileType='vol';
1936        FieldName='image';
1937    else
1938       form=imformats(Ext([2:end]));
1939       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
1940           if isequal(NomType,'*');
1941               FileType='multimage';
1942           else
1943               FileType='image';
1944           end
1945           FieldName='image';
1946       end
1947    end
1948else
1949    FileType='netcdf';
1950    FieldName='get_field...';
1951end
1952VelType=[];%default
1953if isequal(FileType,'netcdf')
1954    list_fields=get(handles.Fields,'String');% list menu fields
1955    index_fields=get(handles.Fields,'Value');% selected string index
1956    FieldName= list_fields{index_fields}; % selected field
1957    if ~isequal(FieldName,'get_field...')% read the field names on the interface get_field...
1958       VelType=setfield(handles);
1959    end
1960end
1961
1962% choose a second field if Subfield option is 'on'
1963FieldName_1=[];
1964scal_color=[];
1965VelType_1=setfield_1(handles);
1966sub_value=get(handles.SubField,'Value');
1967FileType_1='none';%default
1968%if sub_value==1
1969if ~isempty(filename_1)
1970    % test for a constant second field (comparison with a fixed field)
1971    NomType_1=get(handles.FileIndex_1,'UserData');
1972    Ext_1=get(handles.FileExt_1,'String');
1973    % determine the input file type
1974    if isequal(Ext_1,'.nc')||isequal(Ext_1,'.cdf')
1975        FileType_1='netcdf';
1976    elseif isfield(UvData,'MovieObject_1')
1977        FileType_1='movie';
1978        FieldName_1='image';
1979    elseif isequal(lower(Ext_1),'.avi')
1980        FileType='avi';
1981        FieldName_1='image';
1982    elseif isequal(lower(Ext_1),'.vol')
1983        FileType_1='vol';
1984        FieldName_1='image';
1985    else
1986       form=imformats(Ext([2:end]));
1987       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
1988           if isequal(NomType_1,'*');
1989               FileType_1='multimage';
1990           else
1991               FileType_1='image';
1992           end
1993           FieldName_1='image';
1994       end
1995    end
1996    if ~isequal(FieldName_1,'image')
1997        list_fields=get(handles.Fields_1,'String');% list menu fields
1998        index_fields=get(handles.Fields_1,'Value');% selected string index
1999        FieldName_1= list_fields{index_fields}; % selected field
2000        if isequal(VelType_1,'*')% free veltype choice
2001            VelType_1=[];
2002        elseif isequal(VelType_1,'"')% veltype the same as for the first field
2003            if isempty(VelType)
2004                VelType_1=[];
2005            else
2006                VelType_1=VelType;
2007            end
2008        end
2009    end
2010    test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged
2011    if ~isequal(NomType_1,'*')%in case of a series of files (not avi movie)
2012        if isfield(UvData,'filename_1')&& isfield(UvData,'VelType_1') && isfield(UvData,'FieldName_1')
2013            test_keepdata_1= isequal(filename_1,UvData.filename_1)&&...
2014                isequal(VelType_1,UvData.filename_1) && isequal(FieldName_1,UvData.FieldName_1);
2015        end
2016    end
2017    if test_keepdata_1
2018        Field{2}=UvData.Field_1;   
2019    elseif ~exist(filename_1,'file')
2020        errormsg=['second file ' filename_1 ' does not exist'];
2021        return
2022    end
2023end
2024
2025%read the input field(s)
2026%read images
2027if ~isempty(filename) && isequal(FieldName,'image')
2028     switch FileType
2029        case 'movie'
2030            A=read(UvData.MovieObject,num_i1);
2031        case 'avi'
2032            mov=aviread(filename,num_i1);
2033            A=frame2im(mov(1));
2034        case 'vol'
2035            A=imread(filename);
2036        case 'multimage'
2037            A=imread(filename,num_i1);
2038        case 'image'
2039            A=imread(filename);
2040    end
2041    npxy=size(A);
2042    set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
2043    set(handles.npy,'String',num2str(npxy(1)));
2044    Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
2045    Rangy=[npxy(1)-0.5 0.5]; %
2046    Field{1}.AName='image';
2047    Field{1}.ListVarName={'AY','AX','A'}; %
2048    if size(A,3)==3;%color
2049        Field{1}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
2050    else
2051        Field{1}.VarDimName={'AY','AX',{'AY','AX'}}; %
2052    end
2053    Field{1}.AY=Rangy;
2054    Field{1}.AX=Rangx;
2055    Field{1}.A=A;
2056    Field{1}.CoordType='px'; %used for mouse_motion
2057    Field{1}.CoordUnit='pixel'; %used for mouse_motion
2058end
2059
2060%read a second image
2061if  ~isempty(filename_1) && ~test_keepdata_1 && isequal(FieldName_1,'image')
2062    switch FileType_1
2063        case 'movie'
2064            A=read(UvData.MovieObject_1,num_i1);
2065        case 'avi'
2066            mov=aviread(filename,num_i1);
2067            A=frame2im(mov(1));
2068        case 'vol'
2069            A=imread(filename);
2070        case 'multimage'
2071            A=imread(filename,num_i1);
2072        case 'image'
2073            A=imread(filename);
2074    end
2075    npxy=size(A);
2076    set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
2077    set(handles.npy,'String',num2str(npxy(1)));
2078    Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
2079    Rangy=[npxy(1)-0.5 0.5]; %
2080    Field{2}.AName='image';
2081    Field{2}.ListVarName={'AY','AX','A'}; %
2082    if size(A,3)==3;%color
2083        Field{2}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
2084    else
2085        Field{2}.VarDimName={'AY','AX',{'AY','AX'}}; %
2086    end
2087    Field{2}.AY=Rangy;
2088    Field{2}.AX=Rangx;
2089    Field{2}.A=A;
2090    Field{2}.CoordType='px'; %used for mouse_motion
2091    Field{2}.CoordUnit='px'; %used for move_mou
2092end
2093
2094%read ncfile(s)
2095CivStage_1=0;%default
2096VelType_out_1=[];
2097InputField={FieldName};
2098InputField_1={FieldName_1};
2099if (~isempty(filename)&& isequal(FileType,'netcdf')) || (~isempty(filename_1)&& isequal(FileType_1,'netcdf')) ;
2100    %read the velocity field(s) from netcdf rootfile(s)
2101    list_code=get(handles.col_vec,'String');% list menu fields
2102    index_code=get(handles.col_vec,'Value');% selected string index
2103    scal_color= list_code{index_code(1)}; % selected field
2104    if isequal(FieldName,'velocity')&& ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
2105        InputField=[InputField scal_color];
2106    end
2107    if isequal(FieldName_1,'velocity') && ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
2108        InputField_1=[InputField_1 scal_color];
2109    end
2110    if isequal(FileType,'netcdf')  %read the first nc field
2111        if isequal(FieldName,'get_field...')% read the field names on the interface get_field.
2112            %VelType=get(handles.Fields,'UserData');
2113            hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
2114            if isempty(hget_field)
2115                hget_field= get_field(filename);%open the get_field GUI   
2116            end
2117            hhget_field=guidata(hget_field);
2118            set(hhget_field.inputfile,'String',filename)% update the list of input fields in get_field
2119            set(hhget_field.ACTION,'Value',1)% PLOT option selected
2120            set(hhget_field.list_fig,'Value',2)% plotting axes =uvmat selected
2121            [Field{1},errormsg]=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
2122            if ~isempty(errormsg)
2123                errormsg=['error in uvmat/run0_Callback/read_get_field: ' errormsg];
2124                return
2125            end
2126            CivStage=0;
2127            VelType_out=[];         
2128        else
2129            [Field{1},VelType_out]=read_civxdata(filename,InputField,VelType);
2130            if isfield(Field{1},'Txt')
2131                errormsg=Field{1}.Txt;
2132                return
2133            end
2134            CivStage=Field{1}.CivStage;
2135            UvData.NbDim=Field{1}.nb_dim;
2136        end
2137    end
2138    if ~isempty(filename_1) && ~test_keepdata_1 && isequal(FileType_1,'netcdf') %read the second file
2139        if isequal(FieldName_1,'get_field...')% read the field names on the interface get_field.
2140            hget_field=findobj(allchild(0),'Name','get_field_1');%find the get_field... GUI
2141             if isempty(hget_field)
2142                 hget_field= get_field(filename_1);%open the get_field GUI
2143                 set(hget_field,'name','get_field_1')
2144%                 enable_transform(handles,'off')% no field transform (possible transform in the GUI get_field)
2145             end
2146            hhget_field=guidata(hget_field);%handles of GUI elements in get_field
2147            SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI
2148            [Field{2},var_detect]=nc2struct(filename_1,SubField.ListVarName); %read the corresponding input data               
2149            Field{2}.VarAttribute=SubField.VarAttribute;
2150            %update the display on get_field
2151            set(hhget_field.inputfile,'String',filename_1)
2152            set(hhget_field.variables,'Value',1)
2153            Tabchar={''};%default
2154            Tabcell=[];
2155            if isfield(Field{2},'ListGlobalAttribute')& ~isempty(Field{2}.ListGlobalAttribute)
2156                for iline=1:length(Field{2}.ListGlobalAttribute)
2157                    Tabcell{iline,1}=Field{2}.ListGlobalAttribute{iline};
2158                    if isfield(Field{2}, Field{2}.ListGlobalAttribute{iline})
2159                        eval(['val=Field{2}.' Field{2}.ListGlobalAttribute{iline} ';'])
2160                        if ischar(val);
2161                            Tabcell{iline,2}=val;
2162                        else
2163                            Tabcell{iline,2}=num2str(val);
2164                        end
2165                    end
2166                end
2167                if ~isempty(Tabcell)
2168                    Tabchar=cell2tab(Tabcell,'=');
2169                    Tabchar=[{''};Tabchar];
2170                end
2171            end
2172            set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
2173        else
2174            [Field{2},VelType_out_1]=read_civxdata(filename_1,[],VelType_1);
2175            CivStage_1=Field{2}.CivStage;
2176        end
2177        if ~isequal(FileType,'netcdf')
2178            VelType_out=VelType_out_1;
2179        end
2180    end
2181end
2182
2183%store the second field for possible latter use
2184if numel(Field)==2
2185    UvData.Field_1=Field{2};
2186end
2187
2188%update the display buttons for the first velocity type (first menuline)
2189veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2190if ~isequal(FileType,'netcdf')
2191    reset_vel_type(veltype_handles)
2192elseif isempty(VelType) && ~isequal(FieldName,'get_field...')
2193    set_veltype_display(veltype_handles,CivStage)%update the display of available velocity types for the first field
2194    if isempty(VelType_out)
2195        reset_vel_type(veltype_handles)
2196    else
2197        handle1=eval(['handles.' VelType_out]);
2198        reset_vel_type(veltype_handles,handle1)
2199    end
2200end
2201
2202%update the display buttons for the second velocity type (second menuline)
2203veltype_handles_1=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
2204if ~isequal(FileType_1,'netcdf')
2205    reset_vel_type(veltype_handles_1)
2206elseif isempty(VelType_1) && ~isequal(FieldName_1,'get_field...')
2207    set_veltype_display(veltype_handles_1,CivStage_1)%update the display of available velocity types for the first field
2208    if isempty(VelType_out_1)
2209        reset_vel_type(veltype_handles_1)
2210    else
2211        handle1=eval(['handles.' VelType_out_1 '_1']);
2212        reset_vel_type(veltype_handles_1,handle1)
2213    end
2214end
2215
2216%introduce w as background image by default for a new series (only for nbdim=2)
2217if ~isfield(UvData,'NewSeries')
2218    UvData.NewSeries=1;
2219end
2220%put W as background image by default if NbDim=2:
2221if ~isfield(UvData,'NbDim')||isempty(UvData.NbDim)||~isequal(UvData.NbDim,3)
2222    if UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W);
2223        set(handles.SubField,'Value',1);
2224        %menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
2225        set(handles.RootPath_1,'String','"')
2226        set(handles.RootFile_1,'String','"')
2227        set(handles.SubDir_1,'String','"');
2228        [indices]=name_generator('',num_i1,num_j1,'',NomType,1,num_i2,num_j2,'');
2229        set(handles.FileIndex_1,'String',indices)
2230        set(handles.FileExt_1,'String','"');
2231        set(handles.Fields_1,'Visible','on');
2232        set(handles.Fields_1,'Visible','on');
2233        set(handles.RootPath_1,'Visible','on')
2234        set(handles.RootFile_1,'Visible','on')
2235        set(handles.SubDir_1,'Visible','on');
2236        set(handles.FileIndex_1,'Visible','on');
2237        set(handles.FileExt_1,'Visible','on');
2238        set(handles.Fields_1,'Visible','on');
2239        Field{1}.AName='w';
2240        testscal=1;
2241    end
2242end           
2243
2244%multislice case
2245if ~isempty(filename) &&(~isfield(UvData,'NbDim') || isequal(UvData.NbDim,2))&&...%2D case
2246      isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')&& isfield(UvData.XmlData.GeometryCalib,'SliceCoord')
2247       siz=size(UvData.XmlData.GeometryCalib.SliceCoord);
2248       if siz(1)>1
2249           NbSlice=siz(1);
2250%            set(handles.slices,'Visible','on')
2251%            set(handles.slices,'Value',1)
2252       else
2253           NbSlice=1;
2254       end
2255       %set(handles.nb_slice,'String',num2str(NbSlice))
2256%        slices_Callback(handles.uvmat, [], handles)
2257end
2258
2259%store the current open names, fields and vel types in uvmat interface
2260UvData.filename=filename;
2261UvData.filename_1=filename_1;
2262UvData.VelType=VelType;
2263UvData.VelType_1=VelType_1;
2264UvData.FieldName=FieldName;
2265UvData.FieldName_1=FieldName_1;
2266if ~isempty(scal_color)
2267    UvData.CName=scal_color;
2268end
2269
2270%coordinate transform or user fct
2271XmlData=[];%default
2272if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
2273    XmlData=UvData.XmlData;
2274end
2275XmlData_1=[];%default
2276if isfield(UvData,'XmlData_1')
2277   XmlData_1=UvData.XmlData_1;
2278end
2279menu_transform=get(handles.transform_fct,'String');
2280choice_value=get(handles.transform_fct,'Value');
2281transform_list=get(handles.transform_fct,'UserData');
2282transform=transform_list{choice_value};%selected function handles
2283
2284% z index
2285if ~isempty(filename)
2286    Field{1}.ZIndex=z_index;
2287end
2288
2289%px to phys or other transform on field
2290if ~isempty(transform)
2291    if length(Field)>=2
2292        Field{2}.ZIndex=z_index;
2293        [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
2294        if isempty(Field{2})
2295            Field(2)=[];
2296        end
2297    else
2298        Field{1}=transform(Field{1},XmlData);
2299    end
2300end
2301
2302%calculate scalar
2303if isequal(FileType,'netcdf') && ~isequal(FieldName,'get_field...')%
2304    Field{1}=calc_field(InputField,Field{1});
2305end
2306if length(Field)==2 && ~test_keepdata_1 && isequal(FileType_1,'netcdf') && ~isequal(FieldName_1,'get_field...')
2307    Field{2}=calc_field(InputField_1,Field{2});
2308end
2309
2310% combine the two input fields (e.g. substract velocity fields)
2311if numel(Field)==2
2312   UvData.Field=sub_field(Field{1},Field{2}); %TO UPDATE FOR MORE GENERAL INPUT 
2313else
2314   UvData.Field=Field{1};
2315end
2316
2317UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
2318% test 3D , default projection menuplane and typical mesh (needed to menuopen set_object)
2319test_x=0;
2320test_z=0;% test for unstructured z coordinate
2321UvData.ZMax=0;
2322UvData.ZMin=0;%default
2323UvData.Mesh=1; %default
2324[UvData.Field,errormsg]=check_field_structure(UvData.Field);
2325if ~isempty(errormsg)
2326    errormsg=['error in uvmat/run0_Callback/check_field_structure: ' errormsg];
2327    return
2328end
2329[CellVarIndex,NbDim,VarType]=find_field_indices(UvData.Field);
2330[NbDim,imax]=max(NbDim);
2331if isempty(imax)
2332%    DimVarIndex=0;   
2333    coord_x=[];
2334else
2335%     VarIndex=CellVarIndex{imax};
2336    coord_x=VarType{imax}.coord_x;
2337end
2338if isfield(UvData,'NbDim') && ~isempty(UvData.NbDim)
2339    NbDim=UvData.NbDim;
2340else 
2341    UvData.NbDim=NbDim;
2342end
2343if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_x)  && ~isempty(VarType{imax}.coord_y)    %unstructured coordinate z
2344    XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
2345    YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
2346    test_x=1;
2347elseif isfield(UvData.Field,'X') && isfield(UvData.Field,'Y')
2348    XName='X';
2349    YName='Y';
2350    test_x=1;
2351end
2352if test_x
2353    eval(['UvData.XMax=max(UvData.Field.' XName ');'])
2354    eval(['UvData.XMin=min(UvData.Field.' XName ');'])
2355    eval(['UvData.YMax=max(UvData.Field.' YName ');'])
2356    eval(['UvData.YMin=min(UvData.Field.' YName ');'])
2357    eval(['nbvec=length(UvData.Field.' XName ');'])
2358    if NbDim==3%
2359        if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
2360            ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
2361            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
2362            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
2363            test_z=1;   
2364        elseif isfield(UvData,'Z')% usual civ data
2365            UvData.ZMax=max(UvData.Z);
2366            UvData.ZMin=min(UvData.Z);
2367            test_z=1;
2368        end
2369    end
2370    if isequal(UvData.ZMin,UvData.ZMax)%no z dependency
2371        NbDim=2;
2372        test_z=0;
2373    end   
2374    if test_z
2375         UvData.Mesh=((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)*(UvData.ZMax-UvData.ZMin))/nbvec;% volume per vector
2376         UvData.Mesh=(UvData.Mesh)^(1/3);
2377    else
2378        UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/nbvec);%2D
2379    end
2380end
2381%case of structured coordinates
2382if isfield(UvData.Field,'AX') & isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')
2383    UvData.XMax=max(UvData.Field.AX);
2384    UvData.XMin=min(UvData.Field.AX);
2385    UvData.YMax=max(UvData.Field.AY);
2386    UvData.YMin=min(UvData.Field.AY);
2387    np_A=size(UvData.Field.A);
2388    UvData.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/((np_A(1)-1) * (np_A(2)-1))) ;
2389end
2390if  isempty(coord_x)&~isempty(CellVarIndex)
2391    VarIndex=CellVarIndex{imax}; % list of variable indices
2392    DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
2393    if NbDim==3
2394        nbpoints=UvData.Field.DimValue(DimIndex(1));
2395        %Zvar=DimVarIndex(DimIndex(1));
2396         %Zvar=DimVarIndex(1);
2397         Zvar=VarType{imax}.coord_3;
2398        if Zvar~=0 % z is a dimension variable
2399            ZName=UvData.Field.ListVarName{Zvar};
2400            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
2401            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
2402        else
2403            testcoord_z=0;
2404            if length(UvData.Field.VarAttribute)>=VarIndex(1)
2405                if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_1')%regular grid
2406                    Coord_z=UvData.Field.VarAttribute{VarIndex(1)}.Coord_1;
2407                    UvData.ZMax=max(Coord_z);
2408                    UvData.ZMin=min(Coord_z);
2409                    testcoord_z=1;
2410                end
2411            end
2412            if ~testcoord_z
2413                  UvData.ZMin=1;
2414                  UvData.ZMax=UvData.Field.DimValue(DimIndex(1));
2415            end
2416        end
2417        UvData.Mesh=(UvData.ZMax-UvData.ZMin)/(nbpoints-1);
2418    elseif NbDim==2
2419        nbpoints_y=UvData.Field.DimValue(DimIndex(1));       
2420        Yvar=VarType{imax}.coord_y;
2421        if Yvar~=0  % x is a dimension variable
2422            YName=UvData.Field.ListVarName{Yvar};
2423            eval(['UvData.YMax=max(UvData.Field.' YName ');'])
2424            eval(['UvData.YMin=min(UvData.Field.' YName ');'])
2425        else
2426            testcoord_y=0;
2427            if ~testcoord_y
2428                  UvData.YMin=1;
2429                  UvData.YMax=UvData.Field.DimValue(DimIndex(1));
2430            end
2431        end
2432        DY=(UvData.YMax-UvData.YMin)/(nbpoints_y-1);
2433        nbpoints_x=UvData.Field.DimValue(DimIndex(2));
2434        Xvar=VarType{imax}.coord_x;
2435        if Xvar~=0  % x is a dimension variable
2436            XName=UvData.Field.ListVarName{Xvar};
2437            eval(['UvData.XMax=max(UvData.Field.' XName ');'])
2438            eval(['UvData.XMin=min(UvData.Field.' XName ');'])
2439        else
2440            testcoord_x=0;
2441            if ~testcoord_x
2442                  UvData.XMin=1;
2443                  UvData.XMax=UvData.Field.DimValue(DimIndex(2));
2444            end
2445        end
2446        DX=(UvData.XMax-UvData.XMin)/(nbpoints_x-1);
2447        UvData.Mesh= sqrt(DX*DY);
2448    end
2449end
2450
2451%create a default projection menuplane
2452UvData.Object{1}.Style='plane';%main plotting plane
2453UvData.Object{1}.ProjMode='projection';%main plotting plane
2454if ~isfield(UvData.Object{1},'plotaxes')
2455    UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis
2456    set(handles.list_object_1,'String',{'1-PLANE'});
2457    set(handles.list_object_1,'Value',1);
2458end
2459
2460%3D case (menuvolume)
2461if NbDim==3
2462    UvData.Object{1}.NbDim=UvData.NbDim;%test for 3D objects
2463    UvData.Object{1}.RangeZ=UvData.Mesh;%main plotting plane
2464    UvData.Object{1}.Coord(1,3)=(UvData.ZMin+UvData.ZMax)/2;%section at a middle plane chosen
2465    UvData.Object{1}.Phi=0;
2466    UvData.Object{1}.Theta=0;
2467    UvData.Object{1}.Psi=0;
2468    UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR 
2469    PlotHandles=get_plot_handles(handles);
2470    ZBounds(1)=UvData.ZMin; %minimum for the Z slider
2471    ZBounds(2)=UvData.ZMax;%maximum for the Z slider
2472    set_object(UvData.Object{1},PlotHandles,ZBounds);
2473    set(handles.list_object_1,'Value',1);
2474%multilevel case (single menuplane in a 3D space)
2475elseif isfield(UvData,'Z')
2476    if isfield(UvData,'CoordType')& isequal(UvData.CoordType,'phys') & isfield(UvData,'XmlData')
2477        XmlData=UvData.XmlData;
2478        if isfield(XmlData,'PlanePos')
2479             UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
2480        end
2481        if isfield(XmlData,'PlaneAngle')
2482            siz=size(XmlData.PlaneAngle);
2483            indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)             
2484            UvData.Object{1}.Phi=XmlData.PlaneAngle(indangle,1);
2485            UvData.Object{1}.Theta=XmlData.PlaneAngle(indangle,2);
2486            UvData.Object{1}.Psi=XmlData.PlaneAngle(indangle,3);
2487        end
2488    elseif isfield(UvData,'ZIndex')
2489        UvData.Object{1}.ZObject=UvData.ZIndex;
2490    end
2491end
2492
2493%Plot the projections on all existing  projection objects
2494keeplim=get(handles.FixedLimits,'Value');
2495%reset the min and max of scalar if only the mask is displayed
2496if isfield(UvData,'Mask')&~isfield(UvData,'A')
2497    set(handles.MinA,'String','0')
2498    set(handles.MaxA,'String','255')
2499end
2500IndexObj=get(handles.list_object_1,'Value');
2501Object=UvData.Object;
2502IndexObj=min(IndexObj,numel(Object));
2503for iobj=[1 IndexObj]
2504    if ~isempty(Object{iobj})%& isfield(Object{iobj},'plotaxes')& ishandle(Object{iobj}.plotaxes)
2505        %Projeter les champs sur l'objet:*
2506        ObjectData=proj_field(UvData.Field,Object{iobj},iobj);
2507   
2508        %use of mask
2509        if isfield(ObjectData,'NbDim')&isequal(ObjectData.NbDim,2)
2510            if isfield(ObjectData,'Mask') & isfield(ObjectData,'A')
2511                 flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2512                 AX=ObjectData.AX;
2513                 AY=ObjectData.AY;
2514                 MaskX=ObjectData.MaskX;
2515                 MaskY=ObjectData.MaskY;
2516                 if ~isequal(MaskX,AX)|~isequal(MaskY,AY)
2517                     nxy=size(flag_mask);
2518                     sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2519                     sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2520                     x_mask=[ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end)]; % pixel x coordinates for image display
2521                     y_mask=[ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end)];% pixel x coordinates for image display
2522                     %project on the positions of the scalar
2523                     npxy=size(ObjectData.A);
2524                     dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2525                     dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2526                     xi=[ObjectData.AX(1):dxy(2):ObjectData.AX(end)];
2527                     yi=[ObjectData.AY(1):dxy(1):ObjectData.AY(end)];     
2528                     [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2529                    flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2530                 end
2531                 AClass=class(ObjectData.A);
2532                 ObjectData.A=flag_mask.*double(ObjectData.A);
2533                 ObjectData.A=feval(AClass,ObjectData.A);
2534                 ind_off=[];
2535                 if isfield(ObjectData,'ListVarName')
2536                      for ilist=1:length(ObjectData.ListVarName)
2537                           if isequal(ObjectData.ListVarName{ilist},'Mask')|isequal(ObjectData.ListVarName{ilist},'MaskX')|isequal(ObjectData.ListVarName{ilist},'MaskY')
2538                               ind_off=[ind_off ilist];
2539                           end
2540                      end
2541                      ObjectData.ListVarName(ind_off)=[];
2542                      ObjectData.VarDimIndex(ind_off)=[];
2543                      ind_off=[];       
2544                      for ilist=1:length(ObjectData.ListDimName)       
2545                           if isequal(ObjectData.ListDimName{ilist},'MaskX')|isequal(ObjectData.ListDimName{ilist},'MaskY')
2546                               ind_off=[ind_off ilist];
2547                           end
2548                      end
2549                      ObjectData.ListDimName(ind_off)=[];
2550                      ObjectData.DimValue(ind_off)=[];
2551                 end
2552            end 
2553        end
2554        if ~isempty(ObjectData)
2555            haxes=[];%default
2556            if isfield(Object{iobj},'plotaxes')
2557                haxes=Object{iobj}.plotaxes;%axes used for representing the projection on the object
2558            end
2559            PosColorbar=[];%default: no colorbar
2560            if ishandle(haxes) & isequal(get(haxes,'Tag'),'axes3')& isfield(UvData,'PosColorbar')
2561                PosColorbar=UvData.PosColorbar;%prescribe the colorbar position on the uvmat interface
2562            else
2563                PosColorbar='*';%default position
2564            end
2565            PlotParam=read_plot_param(handles);%read plotting parameters on the uvmat interface
2566            [PlotType,ScalOut,UvData.Object{iobj}.plotaxes]=plot_field(ObjectData,haxes,PlotParam,keeplim,PosColorbar);
2567            if isequal(PlotType,'none')
2568                hget_field=findobj(allchild(0),'name','get_field');
2569                if isempty(hget_field)
2570                    get_field([],ObjectData)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
2571                else
2572                    errormsg='The field defined by get_field cannot be plotted';
2573                    return
2574                end
2575            end 
2576            UvData.Object{iobj}.PlotParam=ScalOut; %record the plotting parameters
2577        end       
2578    end
2579end
2580
2581%display the updated plotting parameters for the base menuplane
2582write_plot_param(handles,UvData.Object{1}.PlotParam);% update the display of the plotting parameters
2583set(handles.uvmat,'UserData',UvData)
2584
2585%update the mask
2586if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
2587   update_mask(handles,num_i1,num_i2);
2588end
2589
2590%prepare the menus of histograms (for the whole menuvolume in 3D case)
2591menu_histo=(UvData.Field.ListVarName)';
2592ind_bad=[];
2593nb_histo=1;
2594for ivar=1:numel(menu_histo)
2595    if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2596        Role=UvData.Field.VarAttribute{ivar}.Role;
2597        switch Role
2598            case {'coord_x','coord_y','coord_z','dimvar'}
2599                ind_bad=[ind_bad ivar];
2600            case {'vector_y'}
2601                nb_histo=nb_histo+1;
2602        end
2603    end
2604    DimCell=UvData.Field.VarDimName{ivar};
2605    DimName='';
2606    if ischar(DimCell)
2607        DimName=DimCell;
2608    elseif iscell(DimCell)&& numel(DimCell)==1
2609        DimName=DimCell{1};
2610    end
2611    if strcmp(DimName,menu_histo{ivar})
2612        ind_bad=[ind_bad ivar];
2613    end
2614end
2615menu_histo(ind_bad)=[];
2616test_v=0;
2617if ~isempty(menu_histo)
2618    set(handles.histo1_menu,'Value',1)
2619    set(handles.histo1_menu,'String',menu_histo)
2620    histo1_menu_Callback(handles.histo1_menu, [], handles)
2621    if nb_histo > 1
2622        test_v=1;
2623        set(handles.histo2_menu,'Visible','on')
2624        set(handles.histo_v,'Visible','on')
2625        set(handles.histo2_menu,'String',menu_histo)
2626        set(handles.histo2_menu,'Value',2)
2627        histo2_menu_Callback(handles.histo2_menu,[], handles)
2628    end
2629end
2630if ~test_v
2631    set(handles.histo2_menu,'Visible','off')
2632    set(handles.histo_v,'Visible','off')
2633    cla(handles.histo_v)
2634    set(handles.histo2_menu,'Value',1)
2635end
2636
2637%display time
2638testimedoc=0;
2639if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
2640    if isempty(num_i2)
2641        num_i2=num_i1;
2642    end
2643    if isempty(num_j1)
2644        num_j1=1;
2645    end
2646    if isempty(num_j2)
2647        num_j2=num_j1;
2648    end
2649    siz=size(UvData.XmlData.Time);
2650    if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
2651        abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
2652        dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
2653        testimedoc=1;
2654    end
2655end
2656if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
2657    [P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
2658    num_i2=str2num(str2);
2659    if isempty(num_i2)
2660        num_i2=num_i1;
2661    end
2662    num_j1=str2num(str_a);
2663    if isempty(num_j1)
2664        num_j1=1;
2665    end
2666    num_j2=str2num(str_b);
2667    if isempty(num_j2)
2668        num_j2=num_j1;
2669    end
2670    num_i1=str2num(str1);
2671    siz=size(UvData.XmlData_1.Time);
2672    if siz(1)>=max(num_i1,num_i2) & siz(2)>=max(num_j1,num_j2)
2673        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
2674    end
2675end
2676set(handles.abs_time,'String',num2str(abstime,4))
2677set(handles.abs_time_1,'String',num2str(abstime_1,4))
2678if testimedoc && isfield(UvData,'dt')
2679    dt=UvData.dt;
2680end
2681if isequal(dt,0)
2682    set(handles.Dt_txt,'String','')
2683else
2684    if ~(isfield(UvData,'TimeUnit') && ~isempty(UvData.TimeUnit))
2685        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2686    else
2687        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
2688    end
2689end
2690set(handles.run0,'BackgroundColor',[1 0 0])
2691
2692
2693
2694%-------------------------------------------------------------------
2695% --- translate coordinate to matrix index
2696%-------------------------------------------------------------------
2697function [indx,indy]=pos2ind(x0,rangx0,nxy)
2698indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
2699indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2700
2701%-------------------------------------------------------------------
2702% --- Executes on button press in 'FixedLimits'.
2703%-------------------------------------------------------------------
2704function FixedLimits_Callback(hObject, eventdata, handles)
2705test=get(handles.FixedLimits,'Value');
2706if test
2707    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2708else
2709    set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
2710end
2711
2712%-------------------------------------------------------------------
2713% --- Executes on button press in auto_xy.
2714function auto_xy_Callback(hObject, eventdata, handles)
2715test=get(handles.auto_xy,'Value');
2716if test
2717    set(handles.auto_xy,'BackgroundColor',[1 1 0])
2718    cla(handles.axes3)
2719    update_plot(handles)
2720else
2721    set(handles.auto_xy,'BackgroundColor',[0.7 0.7 0.7])
2722    update_plot(handles)
2723%     axis(handles.axes3,'image')
2724end
2725
2726
2727%-------------------------------------------------------------------
2728
2729%-------------------------------------------------------------------
2730% --- Executes on button press in 'zoom'.
2731%-------------------------------------------------------------------
2732function zoom_Callback(hObject, eventdata, handles)
2733
2734if (get(handles.zoom,'Value') == 1);
2735    set(handles.zoom,'BackgroundColor',[1 1 0])
2736    set(handles.FixedLimits,'Value',1)% propose by default fixed limits for the plotting axes
2737    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2738else
2739    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
2740end
2741
2742
2743%-------------------------------------------------------------------
2744%----Executes on button press in 'record': records the current flags of manual correction.
2745%-------------------------------------------------------------------
2746function record_Callback(hObject, eventdata, handles)
2747% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
2748filename=read_file_boxes(handles);
2749AxeData=get(gca,'UserData');
2750[erread,message]=fileattrib(filename);
2751if ~isempty(message) && ~isequal(message.UserWrite,1)
2752     msgbox_uvmat('ERROR',['no writting access to ' filename])
2753     return
2754end
2755test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
2756test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
2757if ~test_civ2 && ~test_civ1
2758    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
2759end
2760if test_civ2
2761    nbname='nb_vectors2';
2762   flagname='vec2_FixFlag';
2763   attrname='fix2';
2764end
2765if test_civ1
2766    nbname='nb_vectors';
2767   flagname='vec_FixFlag';
2768   attrname='fix';
2769end
2770%write fix flags in the netcdf file
2771hhh=which('netcdf.open');% look for built-in matlab netcdf library
2772if ~isequal(hhh,'')% case of new builtin Matlab netcdf library
2773    nc=netcdf.open(filename,'NC_WRITE');
2774    netcdf.reDef(nc)
2775    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1)
2776    dimid = netcdf.inqDimID(nc,nbname);
2777    try
2778        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
2779    catch
2780        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
2781    end
2782    netcdf.endDef(nc)
2783    netcdf.putVar(nc,varid,AxeData.FF);
2784    netcdf.close(nc) 
2785else %old netcdf library
2786    netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2787end
2788
2789function netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
2790nc=netcdf(filename,'write'); %open netcdf file
2791result=redef(nc);
2792eval(['nc.' attrname '=1;']);
2793theDim=nc(nbname) ;% get the number of velocity vectors
2794nb_vectors=size(theDim);
2795var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2796var_FixFlag(1:nb_vectors)=AxeData.FF;%
2797fin=close(nc);
2798
2799
2800%-------------------------------------------------------------------
2801%determines the fields to read from the interface
2802%------------------------------------------------------------------
2803function [VelType,civ]=setfield(handles)
2804
2805VelType=[]; %default
2806if (get(handles.civ1,'Value') == 1);
2807        VelType='civ1';
2808% interp1   
2809elseif (get(handles.interp1,'Value') == 1);
2810    VelType='interp1';
2811% filter1   
2812elseif (get(handles.filter1,'Value') == 1);
2813    VelType='filter1'; 
2814% CIV2
2815elseif (get(handles.civ2,'Value') == 1);
2816    VelType='civ2';
2817% interp2   
2818elseif (get(handles.interp2,'Value') == 1);
2819    VelType='interp2';
2820% filter2   
2821elseif (get(handles.filter2,'Value') == 1); 
2822    VelType='filter2';
2823end
2824
2825if isequal(get(handles.filter2,'Visible'),'on');
2826    civ=6;
2827% interp1   
2828elseif isequal(get(handles.interp2,'Visible'),'on');
2829    civ=5;
2830% filter1   
2831elseif isequal(get(handles.civ2,'Visible'),'on');
2832    civ=4; 
2833% CIV2
2834elseif isequal(get(handles.filter1,'Visible'),'on');
2835   civ=3;
2836% interp2   
2837elseif isequal(get(handles.interp1,'Visible'),'on');
2838    civ=2;
2839% filter2   
2840elseif isequal(get(handles.civ1,'Visible'),'on'); 
2841    civ=1;
2842else
2843    civ=0;
2844end
2845
2846%-------------------------------------------------------------------
2847%determines the veltype of the second field to read from the iinterface
2848%------------------------------------------------------------------
2849function VelType=setfield_1(handles)
2850
2851VelType=[]; %default
2852if (get(handles.civ1_1,'Value') == 1);
2853    VelType='civ1';
2854% interp1   
2855elseif (get(handles.interp1_1,'Value') == 1);
2856    VelType='interp1';
2857% filter1   
2858elseif (get(handles.filter1_1,'Value') == 1);
2859    VelType='filter1'; 
2860% CIV2
2861elseif (get(handles.civ2_1,'Value') == 1);
2862    VelType='civ2';
2863% interp2   
2864elseif (get(handles.interp2_1,'Value') == 1);
2865    VelType='interp2';
2866% filter2   
2867elseif (get(handles.filter2_1,'Value') == 1); 
2868    VelType='filter2';
2869end
2870
2871
2872%---------------------------------------------------
2873% --- Executes on button press in SubField
2874function SubField_Callback(hObject, eventdata, handles)
2875huvmat=get(handles.run0,'parent');
2876UvData=get(huvmat,'UserData');
2877if get(handles.SubField,'Value')==0% if the subfield button is desactivated   
2878    set(handles.RootPath_1,'String','')
2879    set(handles.RootFile_1,'String','')
2880    set(handles.SubDir_1,'String','');
2881    set(handles.FileIndex_1,'String','');
2882    set(handles.FileExt_1,'String','');
2883    set(handles.RootPath_1,'Visible','off')
2884    set(handles.RootFile_1,'Visible','off')
2885    set(handles.SubDir_1,'Visible','off');
2886    set(handles.FileIndex_1,'Visible','off');
2887    set(handles.FileExt_1,'Visible','off');
2888    set(handles.Fields_1,'Value',1);%set to blank state
2889    set_veltype_display([handles.civ1_1 handles.interp1_1 handles.filter1_1 ...
2890            handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
2891    if isfield(UvData,'XmlData_1')
2892        UvData=rmfield(UvData,'XmlData_1');
2893    end
2894    set(huvmat,'UserData',UvData);
2895    run0_Callback(hObject, eventdata, handles); %run
2896else
2897    MenuBrowse_1_Callback(hObject, eventdata, handles)
2898end
2899
2900% %----------------------------------------------
2901% %read the data displayed for the input rootfile windows (new)
2902% %-------------------------------------------------
2903function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
2904RootPath=get(handles.RootPath,'String');
2905FileName=RootPath; %default
2906SubDir=get(handles.SubDir,'String');
2907if ~isempty(SubDir) && ~isequal(SubDir,'')
2908    if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
2909        SubDir(1)=[]; %suppress possible / or \ separator
2910    end
2911    FileName=fullfile(RootPath,SubDir);
2912end
2913RootFile=get(handles.RootFile,'String');
2914if ~isempty(RootFile) && ~isequal(RootFile,'')
2915    if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
2916        RootFile(1)=[]; %suppress possible / or \ separator
2917    end
2918    FileName=fullfile(FileName,RootFile);
2919end
2920FileBase=fullfile(RootPath,RootFile);
2921FileIndices=get(handles.FileIndex,'String');
2922FileExt=get(handles.FileExt,'String');
2923FileName=[FileName FileIndices FileExt];
2924
2925%----------------------------------------------
2926%read the data displayed for the second input rootfile windows
2927%-------------------------------------------------
2928function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
2929RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
2930if isequal(RootPath_1,'"'),RootPath_1=get(handles.RootPath,'String'); end;
2931FileName_1=RootPath_1; %default
2932SubDir_1=get(handles.SubDir_1,'String');
2933if isequal(SubDir_1,'"')
2934    SubDir_1=get(handles.SubDir,'String');
2935end
2936if ~isempty(SubDir_1) && ~isequal(SubDir_1,'')
2937    if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
2938        SubDir_1(1)=[]; %suppress possible / or \ separator
2939    end
2940    FileName_1=fullfile(RootPath_1,SubDir_1);
2941end
2942RootFile_1=get(handles.RootFile_1,'String');
2943if isequal(RootFile_1,'"'),RootFile_1=get(handles.RootFile,'String'); end;
2944if ~isempty(RootFile_1) && ~isequal(RootFile_1,'')
2945    if ~(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
2946        RootFile_1(1)=[];%suppress possible / or \ separator
2947    end
2948    FileName_1=fullfile(FileName_1,RootFile_1);
2949end
2950FileBase_1=fullfile(RootPath_1,RootFile_1);
2951FileIndices_1=get(handles.FileIndex_1,'String');
2952FileExt_1=get(handles.FileExt_1,'String');
2953if isequal(FileExt_1,'"'),FileExt_1=get(handles.FileExt,'String'); end;
2954FileName_1=[FileName_1 FileIndices_1 FileExt_1];
2955
2956%---------------------------------------------------
2957% --- Executes on menu selection Fields
2958function Fields_Callback(hObject, eventdata, handles)
2959%-------------------------------------------------
2960
2961list_fields=get(handles.Fields,'String');% list menu fields
2962index_fields=get(handles.Fields,'Value');% selected string index
2963field= list_fields{index_fields(1)}; % selected string
2964if isequal(field,'get_field...')
2965     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2966     set_veltype_display(veltype_handles,0) % unvisible civ buttons
2967     filename=read_file_boxes(handles);
2968     hget_field=findobj(allchild(0),'name','get_field');
2969     if ~isempty(hget_field)
2970         delete(hget_field)
2971     end
2972     get_field(filename)
2973    return %no action
2974end
2975list_fields=get(handles.Fields_1,'String');% list menu fields
2976index_fields=get(handles.Fields_1,'Value');% selected string index
2977field_1= list_fields{index_fields(1)}; % selected string
2978UvData=get(handles.uvmat,'UserData');
2979
2980%read the rootfile input display
2981FileExt=get(handles.FileExt,'String');
2982[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
2983NomTypeNew=NomType;%default
2984if isequal(field,'image')
2985    % transform netc type to the corresponding image type
2986    if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')|| isequal(NomType,'#_ab')|| isequal(NomType,'_i1-i2')
2987        UvData.SubDir=get(handles.SubDir,'String'); %preserve the subdir in memory
2988        if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')||isequal(UvData.SubDir(1),'/'))
2989            UvData.SubDir(1)=[];
2990        end
2991        set(handles.SubDir,'String','')
2992        set(handles.FileExt,'String','.png');
2993        if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')
2994            NomTypeNew='_i_j';
2995        elseif isequal(NomType,'#_ab')
2996            NomTypeNew='#a';
2997        elseif isequal(NomType,'_i1-i2')
2998            NomTypeNew='_i';
2999        end 
3000    end
3001    veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3002    set_veltype_display(veltype_handles,0) % unvisible civ buttons
3003else
3004    ext=get(handles.FileExt,'String');
3005    if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
3006         MenuBrowse_Callback(hObject, eventdata, handles)
3007    end
3008    if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
3009        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3010        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
3011        set(handles.interp1,'BackgroundColor',[0.702 0.702 0.702])
3012        set(handles.interp2,'BackgroundColor',[0.702 0.702 0.702])
3013    elseif isequal(field,'more...');
3014        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3015        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
3016        str=calc_field;%get the list of available scalars by the function calc_scal
3017        [ind_answer] = listdlg('PromptString','Select a file:',...
3018                'SelectionMode','single',...
3019                'ListString',str);
3020       % edit the choice in the field and action menu
3021        scalar=cell2mat(str(ind_answer));
3022        menu=update_menu(handles.Fields,scalar);
3023        menu=[{''};menu];
3024        set(handles.Fields_1,'String',menu);% store the selected scalar type
3025    end
3026end
3027indices=name_generator('',str2double(str1),str2double(str_a),'',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3028set(handles.FileIndex,'String',indices)
3029set(handles.FileIndex,'UserData',NomTypeNew)
3030%common to Fields_1_Callback
3031if isequal(field,'image')||isequal(field_1,'image')
3032    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3033    set(handles.npy_title,'Visible','on')
3034    set(handles.npx,'Visible','on')
3035    set(handles.npy,'Visible','on')
3036    set(handles.fix_pair,'Value',0)
3037else
3038    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3039    set(handles.npy_title,'Visible','off')
3040    set(handles.npx,'Visible','off')
3041    set(handles.npy,'Visible','off')
3042    set(handles.fix_pair,'Value',1)
3043end
3044setfield(handles);% update the field structure ('civ1'....)
3045
3046if ~isfield(UvData,'NewSeries')||isequal(UvData.NewSeries,0)
3047    run0_Callback(hObject, eventdata, handles)
3048end
3049
3050%---------------------------------------------------
3051% --- Executes on menu selection Fields
3052function Fields_1_Callback(hObject, eventdata, handles)
3053%-------------------------------------------------
3054list_fields=get(handles.Fields,'String');% list menu fields
3055index_fields=get(handles.Fields,'Value');% selected string index
3056field= list_fields{index_fields(1)}; % selected string
3057list_fields=get(handles.Fields_1,'String');% list menu fields
3058index_fields=get(handles.Fields_1,'Value');% selected string index
3059field_1= list_fields{index_fields(1)}; % selected string for the second field
3060if isequal(field_1,'') %remove second field if 'blank' field is selected
3061    set(handles.SubField,'Value',0)
3062    SubField_Callback(hObject, eventdata, handles)
3063    return
3064end
3065UvData=get(handles.uvmat,'UserData');
3066
3067%read the rootfile input display
3068FileExt_prev=get(handles.FileExt_1,'String');
3069if isempty(FileExt_prev)|isequal(FileExt_prev,'')
3070    FileExt_1=get(handles.FileExt,'String');
3071else
3072    FileExt_1=FileExt_prev;
3073end
3074NomType_1=get(handles.FileIndex_1,'UserData');
3075if isempty(NomType_1)|isequal(NomType_1,'')
3076    NomType_1=get(handles.FileIndex,'UserData');
3077end
3078NomTypeNew=NomType_1;%default
3079
3080set(handles.SubField,'Value',1)%introduce second field
3081if isfield(UvData,'XmlData')
3082    UvData.XmlData_1=UvData.XmlData;
3083end
3084set(handles.FileIndex_1,'Visible','on')
3085set(handles.FileExt_1,'Visible','on')
3086RootPath_1=get(handles.RootPath_1,'String');
3087RootFile_1=get(handles.RootFile_1,'String');
3088if isempty(RootPath_1)|isequal(RootPath_1,'')
3089    set(handles.RootPath_1,'String','"')
3090end
3091if isempty(RootFile_1) | isequal(RootFile_1,'')
3092    set(handles.RootFile_1,'String','"')
3093end
3094if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
3095    RootFile_1(1)=[];
3096end
3097
3098if isequal(field_1,'get_field...')
3099     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3100     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3101     filename=read_file_boxes_1(handles);
3102     hget_field=findobj(allchild(0),'name','get_field_1');
3103     if ~isempty(hget_field)
3104         delete(hget_field)
3105     end
3106     hget_field=get_field(filename);
3107     set(hget_field,'name','get_field_1')
3108    return %no action
3109end
3110if isequal(field_1,'image')
3111    % transform netc type to the corresponding image type
3112    set(handles.FileExt_1,'String','.png');
3113    if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')| isequal(NomType_1,'#_ab')| isequal(NomType_1,'_i1-i2')
3114        UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory
3115        set(handles.SubDir_1,'String','')
3116%         set(handles.FileExt_1,'String','.png');       
3117        if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')
3118            NomTypeNew='_i_j';
3119        elseif isequal(NomType_1,'#_ab')
3120            NomTypeNew='#a';
3121        elseif isequal(NomType_1,'_i1-i2')
3122            NomTypeNew='_i';
3123        end 
3124    end
3125    veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3126    set_veltype_display(veltype_handles,0) % unvisible civ buttons
3127else
3128    set(handles.SubDir_1,'Visible','on')
3129    if ~isequal(FileExt_prev,'.nc') %find the new NomType if the previous display was not already a netcdf file
3130        veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3131        set_veltype_display(veltype_handles,6); % make all civ buttons visible
3132        RootPath_1=get(handles.RootPath_1,'String');
3133        RootFile_1=get(handles.RootFile_1,'String');
3134        if isempty(RootPath_1)|isequal(RootPath_1,'')
3135            set(handles.RootPath_1,'String','"')
3136        end
3137        if isempty(RootFile_1) | isequal(RootFile_1,'')
3138            set(handles.RootFile_1,'String','"')
3139        end
3140        if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
3141            RootFile_1(1)=[];
3142        end
3143        filebase_1=fullfile(RootPath_1,RootFile_1);
3144        SubDir_1=get(handles.SubDir,'String');
3145        if isempty(SubDir_1)|isequal(SubDir_1,'')
3146            if isfield(UvData,'SubDir_1')
3147                SubDir_1=UvData.SubDir_1;%retrieve previous subdir
3148            else
3149                SubDir_1='?';
3150            end
3151        end
3152        if isequal(NomType_1,'#_ab')|isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')|isequal(NomType_1,'_i1-i2')
3153            NomTypeNew=NomType_1;
3154        elseif isequal(NomType_1,'#a')
3155             [filename,idetect,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),str2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
3156             NomTypeNew='#_ab';
3157        elseif isequal(NomType_1,'_i_j')
3158             [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);
3159            if idetect==1
3160                NomTypeNew='_i1-i2_j';
3161            else
3162                NomTypeNew='_i_j1-j2';
3163            end
3164        else %for instance avi files or any ima_num series
3165            [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);
3166            NomTypeNew='_i1-i2';
3167        end           
3168        [Path,Name]=fileparts(filebase_1);
3169        set(handles.FileExt_1,'String','.nc');
3170        if ~isempty(SubDir_1) & ~isequal(SubDir_1,'''')& ~isequal(SubDir_1,'"')
3171            SubDir_1=['/' SubDir_1];
3172        end
3173        set(handles.SubDir_1,'String',SubDir_1);
3174    end
3175    if isequal(field,'vort') | isequal(field,'div') | isequal(field,'strain')
3176        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3177        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3178        set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
3179        set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
3180    elseif isequal(field_1,'more...'); %add new item to the menu
3181        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3182        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3183        str=calc_field;%get the list of available scalars by the function calc_scal
3184        [ind_answer,v] = listdlg('PromptString','Select a file:',...
3185                'SelectionMode','single',...
3186                'ListString',str);
3187       % edit the choice in the field and action menu
3188        scalar=cell2mat(str(ind_answer));
3189        menu=update_menu(handles.Fields_1,scalar);
3190        set(handles.Fields_1,'String',menu);% store the selected scalar type
3191    end
3192end
3193str1=get(handles.i1,'String');
3194str2=get(handles.i2,'String');
3195str_a=get(handles.j1,'String');
3196str_b=get(handles.j2,'String');
3197indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
3198set(handles.FileIndex_1,'String',indices)
3199set(handles.FileIndex_1,'UserData',NomTypeNew)
3200
3201%common to Fields_Callback
3202if isequal(field,'image')|isequal(field_1,'image')
3203    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3204    set(handles.npy_title,'Visible','on')
3205    set(handles.npx,'Visible','on')
3206    set(handles.npy,'Visible','on')
3207    set(handles.fix_pair,'Value',0)
3208else
3209    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3210    set(handles.npy_title,'Visible','off')
3211    set(handles.npx,'Visible','off')
3212    set(handles.npy,'Visible','off')
3213    set(handles.fix_pair,'Value',1)
3214end
3215if isequal(field,'velocity')|isequal(field_1,'velocity');
3216    state_vect='on';
3217else
3218    state_vect='off';
3219end
3220if ~isequal(field,'velocity')|(~isequal(field_1,'velocity')&~isequal(field_1,''));
3221    state_scal='on';
3222else
3223    state_scal='off';
3224end
3225set(handles.uvmat,'UserData',UvData)
3226setfield(handles);% update the field structure ('civ1'....)
3227if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
3228    run0_Callback(hObject, eventdata, handles)
3229end
3230
3231%------------------------------------------------------------------------
3232% --- set the visibility of relevant velocity type menus:
3233function set_veltype_display(handles,Civ)
3234%------------------------------------------------------------------------
3235%Civ=0; all states 'off'
3236%Civ=6; all states 'on'
3237if isequal(Civ,0)
3238    imax=0;
3239%    set(handles(1),'Visible','on')  % unvisible civ buttons
3240% else
3241%    set(handles(1),'String','civ1')
3242% end
3243elseif isequal(Civ,1) || isequal(Civ,2)
3244   imax=1;
3245elseif isequal(Civ,3)
3246    imax=3;
3247elseif isequal(Civ,4) || isequal(Civ,5)
3248    imax=4;
3249elseif isequal(Civ,6) %patch2
3250    imax=6;
3251end
3252for ibutton=1:imax;
3253    set(handles(ibutton),'Visible','on')  % unvisible civ buttons
3254end
3255% for ibutton=max(imax+1,2):6;
3256for ibutton=imax+1:6;
3257    set(handles(ibutton),'Visible','off')  % unvisible civ buttons
3258    set(handles(ibutton),'Value',0)%unactivate unvisible buttons
3259end
3260
3261%-------------------------------------------------------------------
3262% --- Executes on button press in civ1.
3263function civ1_Callback(hObject, eventdata, handles)
3264%-------------------------------------------------------------------
3265if get(handles.civ1,'Value')==1
3266    reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ1)
3267else
3268    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3269end
3270run0_Callback(hObject, eventdata, handles)
3271
3272%-------------------------------------------------------------------
3273% --- Executes on button press in interp1.
3274function interp1_Callback(hObject, eventdata, handles)
3275%-------------------------------------------------------------------
3276if get(handles.interp1,'Value')==1
3277    reset_vel_type([handles.civ1 handles.civ2 handles.filter1 handles.interp2 handles.filter2],handles.interp1)
3278else
3279     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3280end
3281run0_Callback(hObject, eventdata, handles)
3282
3283%-------------------------------------------------------------------
3284% --- Executes on button press in filter1.
3285function filter1_Callback(hObject, eventdata, handles)
3286%-------------------------------------------------------------------
3287if get(handles.filter1,'Value')==1
3288    reset_vel_type([handles.civ1 handles.civ2 handles.interp1 handles.interp2 handles.filter2],handles.filter1)
3289else
3290     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3291end
3292run0_Callback(hObject, eventdata, handles)
3293
3294%-------------------------------------------------------------------
3295% --- Executes on button press in civ2.
3296function civ2_Callback(hObject, eventdata, handles)
3297%-------------------------------------------------------------------
3298if get(handles.civ2,'Value')==1
3299    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ2)
3300else
3301     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3302end
3303run0_Callback(hObject, eventdata, handles)
3304
3305%-----------------------------------------
3306% --- Executes on button press in interp2.
3307%-------------------------------------------
3308function interp2_Callback(hObject, eventdata, handles)
3309if get(handles.interp2,'Value')==1
3310    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.filter2],handles.interp2)
3311else
3312     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3313end
3314run0_Callback(hObject, eventdata, handles)
3315%---------------------------------------------
3316% --- Executes on button press in filter2.
3317%-------------------------------------------
3318function filter2_Callback(hObject, eventdata, handles)
3319if get(handles.filter2,'Value')==1
3320    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2],handles.filter2)
3321else
3322     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3323end
3324run0_Callback(hObject, eventdata, handles)
3325
3326%---------------------------------------------
3327function civ1_1_Callback(hObject, eventdata, handles)
3328%---------------------------------------------
3329if get(handles.civ1_1,'Value')==1
3330    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.civ1_1)
3331else
3332     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3333end
3334run0_Callback(hObject, eventdata, handles)
3335
3336%--------------------------------------------
3337function interp1_1_Callback(hObject, eventdata, handles)
3338%--------------------------------------------
3339if get(handles.interp1_1,'Value')==1
3340    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.interp1_1)
3341else
3342    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3343end
3344run0_Callback(hObject, eventdata, handles)
3345
3346%--------------------------------------------
3347function filter1_1_Callback(hObject, eventdata, handles)
3348%--------------------------------------------
3349if get(handles.filter1_1,'Value')==1
3350    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.filter1_1)
3351else
3352    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3353end
3354run0_Callback(hObject, eventdata, handles)
3355
3356%--------------------------------------------
3357function civ2_1_Callback(hObject, eventdata, handles)
3358%--------------------------------------------
3359if get(handles.civ2_1,'Value')==1
3360    reset_vel_type([handles.civ1_1 handles.interp1_1  handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.civ2_1)
3361else
3362    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3363end
3364run0_Callback(hObject, eventdata, handles)
3365
3366%--------------------------------------------
3367function interp2_1_Callback(hObject, eventdata, handles)
3368%--------------------------------------------
3369if get(handles.interp2_1,'Value')==1
3370    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.filter2_1],handles.interp2_1)
3371else
3372    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3373end
3374run0_Callback(hObject, eventdata, handles)
3375
3376%--------------------------------------------
3377function filter2_1_Callback(hObject, eventdata, handles)
3378%--------------------------------------------
3379if get(handles.filter2_1,'Value')==1
3380    reset_vel_type([handles.civ1_1 handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1],handles.filter2_1)
3381else
3382    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3383end
3384run0_Callback(hObject, eventdata, handles)
3385
3386%-----------------------------------------------
3387% --- reset civ buttons
3388function reset_vel_type(handles_civ0,handle1)
3389for ibutton=1:length(handles_civ0)
3390    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3391    set(handles_civ0(ibutton),'Value',0)
3392end
3393if exist('handle1','var')%handles of selected button
3394        set(handle1,'BackgroundColor',[1 1 0]) 
3395end
3396
3397% %------------------------------------------------
3398% function create_Callback(hObject,eventdata,handles)
3399% %------------------------------------------------
3400% if ishandle(handles.UVMAT_title)
3401%     delete(handles.UVMAT_title)
3402% end
3403% huvmat=get(handles.create,'parent');
3404% UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface (handles huvmat)
3405% if isequal(get(handles.create,'Value'),1)
3406%     set(handles.zoom,'Value',0)
3407%     zoom_Callback(hObject, eventdata, handles)
3408%      set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
3409%     set(handles.edit_vect,'Value',0) 
3410%     edit_vect_Callback(hObject, eventdata, handles)
3411%     set(handles.edit,'Value',0)
3412%     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3413%     list_object_1=get(handles.list_object_1,'String');
3414%     if ~isempty(list_object_1)
3415%         set(handles.list_object_1,'Value',length(list_object_1))
3416%     end
3417%     MouseAction='create_object';
3418%     hset_object=findobj(allchild(0),'Name','set_object');
3419%     uistack(hset_object,'top')
3420% else
3421%     set(handles.create,'BackgroundColor',[0 1 0])
3422%     set(handles.edit,'Value',1)
3423%     set(handles.edit,'BackgroundColor',[1 1 0])
3424%     MouseAction='none';
3425% end
3426%
3427% UvData.MouseAction=MouseAction;
3428% set(huvmat,'UserData',UvData);
3429%
3430% %------------------------------------------------
3431% function POINTS_Callback(hObject,eventdata,handles)
3432% %------------------------------------------------
3433% if ishandle(handles.UVMAT_title)
3434%     delete(handles.UVMAT_title)
3435% end
3436% huvmat=get(handles.create,'parent');
3437% UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface (handles huvmat)
3438% if isequal(get(handles.create,'Value'),1)
3439%     set(handles.zoom,'Value',0)
3440%     zoom_Callback(hObject, eventdata, handles)
3441%     set(handles.edit_vect,'Value',0) 
3442%     edit_vect_Callback(hObject, eventdata, handles)
3443%     set(handles.edit,'Value',0)
3444%     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3445%     %set(handles.grid,'Value',0)
3446%     %set(handles.grid,'BackgroundColor',[0 1 0])
3447%     % initiate set_object GUI
3448%      data.TITLE='POINTS';
3449%     if isfield(UvData,'CoordType')
3450%         data.CoordType=UvData.CoordType;
3451%     end
3452%     if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3453%         data.RangeY=UvData.Mesh;
3454%     elseif isfield(UvData,'AX')&isfield(UvData,'AY')& isfield(UvData,'A')%only image
3455%         np=size(UvData.Field.A);
3456%         meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3457%         meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3458%         data.RangeY=max(meshx,meshy);
3459%         data.DX=max(meshx,meshy);
3460%     end
3461%     data.Coord=[0 0 0]; %default
3462%     data.ParentButton=handles.create;
3463%     PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
3464%     [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
3465%     if isfield(UvData,'SetObjectOrigin')
3466%     pos_uvmat=get(huvmat,'Position');
3467%     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3468%     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
3469%     set(hset_object,'Position',pos_set_object)
3470%     end
3471%     %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)]);
3472%     list_object_1=get(handles.list_object_1,'String');
3473%     if ~isempty(list_object_1)
3474%         set(handles.list_object_1,'Value',length(list_object_1))
3475%     end
3476%     MouseAction='create_object';
3477%     %UvData.ZoomOn=0;
3478% else
3479%     set(handles.create,'BackgroundColor',[0 1 0])
3480%     set(handles.edit,'Value',1)
3481%     set(handles.edit,'BackgroundColor',[1 1 0])
3482%     MouseAction='none';
3483% end
3484%
3485% UvData.MouseAction=MouseAction;
3486% set(huvmat,'UserData',UvData);
3487
3488% %-----------------------------------------------------------
3489% function LINE_Callback(hObject, eventdata, handles)
3490% %-------------------------------------------------
3491% if ishandle(handles.UVMAT_title)
3492%     delete(handles.UVMAT_title)
3493% end
3494% % handles.uvmat
3495% huvmat=get(handles.create,'parent');
3496% UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3497% set(handles.zoom,'Value',0)
3498% zoom_Callback(hObject, eventdata, handles)
3499% set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3500% set(handles.edit_vect,'Value',0)
3501% edit_vect_Callback(hObject, eventdata, handles)
3502% set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3503% set(handles.edit,'Value',0)
3504% set(handles.list_object_1,'Value',1);
3505% edit_vect_Callback(hObject, eventdata, handles)
3506% set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3507% set(handles.cal,'Value',0)
3508% set(handles.cal,'BackgroundColor',[0 1 0])
3509% %  initiate the set_object GUI
3510% data.TITLE='LINE';
3511% if isfield(UvData,'CoordType')
3512%     data.CoordType=UvData.CoordType;
3513% end
3514% if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3515%     data.RangeX=UvData.Mesh;
3516%     data.RangeY=UvData.Mesh;
3517%     data.DX=UvData.Mesh;
3518%     data.DY=UvData.Mesh;
3519% elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3520%     np=size(UvData.Field.A);
3521%     meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3522%     meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3523%     data.RangeY=max(meshx,meshy);
3524%     data.RangeX=max(meshx,meshy);
3525%     data.DX=max(meshx,meshy);
3526% end
3527% if isfield(data,'DX')
3528%     data.Coord=[[0 0 0];[data.DX 0 0]]; %default
3529% else
3530%     data.Coord=[[0 0 0];[1 0 0]]; %default
3531% end
3532% data.ParentButton=handles.create;
3533% PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3534% [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3535%                                                   % associate the set_edit interface handle to the plotting axes
3536% pos_uvmat=get(huvmat,'Position');
3537% if isfield(UvData,'SetObjectOrigin')
3538%     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3539%     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
3540%     set(hset_object,'Position',pos_set_object)
3541% end
3542% list_object_1=get(handles.list_object_1,'String');
3543% if ~isempty(list_object_1)
3544%     set(handles.list_object_1,'Value',length(list_object_1))
3545% end
3546% MouseAction='create_object';
3547% UvData.MouseAction=MouseAction;
3548% set(huvmat,'UserData',UvData)
3549
3550% %-----------------------------------------------------------
3551% function PATCH_Callback(hObject, eventdata, handles)
3552% %-----------------------------------------------------------
3553% if ishandle(handles.UVMAT_title)
3554%     delete(handles.UVMAT_title)
3555% end
3556% huvmat=get(handles.create,'parent');
3557% UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3558% % if isequal(get(handles.PATCH,'Value'),1)
3559%     set(handles.zoom,'Value',0)
3560%     set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3561% %     set(handles.create,'Value',0)%suppress the other options if LINE is chosen
3562% %     set(handles.create,'BackgroundColor',[0 1 0])
3563% %     set(handles.LINE,'Value',0)
3564% %     set(handles.LINE,'BackgroundColor',[0 1 0])
3565% %     set(handles.PATCH,'Value',1)
3566% %     set(handles.PATCH,'BackgroundColor',[1 1 0])
3567% %     set(handles.PLANE,'Value',0)
3568% %     set(handles.PLANE,'BackgroundColor',[0 1 0])%put activated buttons to yellow
3569% %     set(handles.VOLUME,'Value',0)
3570% %     set(handles.VOLUME,'BackgroundColor',[0 1 0])
3571%     %set(handles.makemask,'Value',0)
3572%     %makemask_Callback(hObject, eventdata, handles)
3573%     set(handles.edit_vect,'Value',0)
3574%     edit_vect_Callback(hObject, eventdata, handles)
3575%     set(handles.edit,'Value',0)
3576%     set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3577%     set(handles.edit_vect,'Value',0) 
3578%     edit_vect_Callback(hObject, eventdata, handles)
3579%     set(handles.cal,'Value',0)
3580%     set(handles.cal,'BackgroundColor',[0 1 0])
3581%     %set(handles.grid,'Value',0)
3582%     %set(handles.grid,'BackgroundColor',[0 1 0])
3583%     %initiate set_object GUI
3584%     data.TITLE='PATCH';
3585%     if isfield(UvData,'CoordType')
3586%         data.CoordType=UvData.CoordType;
3587%     end
3588%     if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3589%         data.YMax=UvData.Mesh;
3590%     elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3591%         np=size(UvData.Field.A);
3592%         meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
3593%         meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
3594%         data.YMax=max(meshx,meshy);
3595%         data.DX=max(meshx,meshy);
3596%     end
3597%     data.Coord=[0 0 0]; %default
3598%     data.ParentButton=handles.create;
3599%     PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
3600%     [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
3601%     pos_uvmat=get(huvmat,'Position');
3602%     if isfield(UvData,'SetObjectOrigin')
3603%         pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3604%         pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
3605%         set(hset_object,'Position',pos_set_object)
3606%     end
3607%     list_object_1=get(handles.list_object_1,'String');
3608%     if ~isempty(list_object_1)
3609%         set(handles.list_object_1,'Value',length(list_object_1))
3610%     end
3611%     UvData.MouseAction='create_object';
3612%     set(huvmat,'UserData',UvData);
3613% %-------------------------------------------------------
3614% function PLANE_Callback(hObject, eventdata, handles)
3615% %-------------------------------------------------------
3616% if ishandle(handles.UVMAT_title)
3617%     delete(handles.UVMAT_title)
3618% end
3619% huvmat=get(handles.create,'parent');
3620% UvData=get(huvmat,'UserData');%read UvData properties stored on the uvmat interface
3621% set(handles.zoom,'Value',0)
3622% set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3623% set(handles.edit_vect,'Value',0)
3624% edit_vect_Callback(hObject, eventdata, handles)
3625% set(handles.edit,'Value',0)
3626% set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3627% set(handles.cal,'Value',0)
3628% set(handles.cal,'BackgroundColor',[0 1 0])
3629% %set(handles.grid,'Value',0)
3630% %set(handles.grid,'BackgroundColor',[0 1 0])
3631% %initiate set_object GUI
3632% data.TITLE='PLANE';
3633% if isfield(UvData,'CoordType')
3634%     data.CoordType=UvData.CoordType;
3635% end
3636% %Si 3D data.nbdim=3;
3637% %Si 2D
3638% if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3639%     data.ZMax=UvData.Mesh;
3640%     data.DX=UvData.Mesh;
3641%     data.DY=UvData.Mesh;
3642% elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3643%     np=size(UvData.Field.A);
3644%     meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
3645%     meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
3646%     data.DX=max(meshx,meshy);
3647% end
3648% if isfield(UvData,'DX')
3649%     data.DX=UvData.DX;
3650% end
3651% if isfield(UvData,'DY')
3652%     data.DY=UvData.DY;
3653% elseif isfield(UvData,'Mesh')
3654%     data.DY=UvData.Mesh;
3655% end
3656% if isfield(UvData.Field,'X')& isfield(UvData.Field,'Y')
3657%     data.Coord=[0 0 0];
3658%     data.Style='plane';
3659%     data.Phi=0;
3660%     data.IndexObj=1; %act on the first reference plane by default
3661%     haxes= handles.axes3;%GENERALISER
3662%     plot_object(data,[],haxes,'m'); %plot the axes of the default plane 
3663% end
3664% data.ParentButton=handles.create;
3665% PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
3666% ZBounds=0; % default
3667% if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
3668%     ZBounds(1)=UvData.ZMin; %minimum for the Z slider
3669%     ZBounds(2)=UvData.ZMax;%maximum for the Z slider
3670% end
3671% [hset_object,UvData.sethandles]=set_object(data,PlotHandles,ZBounds);% call the set_object interface with action on haxes,
3672% if isfield(UvData,'SetObjectOrigin')
3673% pos_uvmat=get(huvmat,'Position');
3674% pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3675% pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
3676% set(hset_object,'Position',pos_set_object)
3677% end
3678% list_object_1=get(handles.list_object_1,'String');
3679% nbobject=length(list_object_1);
3680% set(handles.list_object_1,'Value',nbobject)
3681% UvData.MouseAction='create_object';
3682% set(huvmat,'UserData',UvData)
3683
3684%-------------------------------------------------------
3685% --- Executes on button press in MENUVOLUME.
3686%-------------------------------------------------------
3687function VOLUME_Callback(hObject, eventdata, handles)
3688%errordlg('command VOL not implemented yet')
3689if ishandle(handles.UVMAT_title)
3690    delete(handles.UVMAT_title)
3691end
3692UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3693if isequal(get(handles.VOLUME,'Value'),1)
3694    set(handles.zoom,'Value',0)
3695    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3696    set(handles.edit_vect,'Value',0)
3697    edit_vect_Callback(hObject, eventdata, handles)
3698    set(handles.edit,'Value',0)
3699    set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3700%     set(handles.cal,'Value',0)
3701%     set(handles.cal,'BackgroundColor',[0 1 0])
3702    set(handles.edit_vect,'Value',0)
3703    edit_vect_Callback(hObject, eventdata, handles)
3704    %initiate set_object GUI
3705    data.TITLE='VOLUME';
3706    if isfield(UvData,'CoordType')
3707        data.CoordType=UvData.CoordType;
3708    end
3709    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3710        data.RangeY=UvData.Mesh;
3711        data.RangeX=UvData.Mesh;
3712        data.DX=UvData.Mesh;
3713        data.DY=UvData.Mesh;
3714    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3715        np=size(UvData.Field.A);
3716        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3717        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3718        data.RangeY=max(meshx,meshy);
3719        data.RangeX=max(meshx,meshy);
3720        data.DX=max(meshx,meshy);
3721    end
3722    data.ParentButton=handles.VOLUME;
3723    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3724    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3725                                                      % associate the set_edit interface handle to the plotting axes
3726    if isfield(UvData,'SetObjectOrigin')                                               
3727    pos_uvmat=get(huvmat,'Position');
3728    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3729    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
3730    set(hset_object,'Position',pos_set_object)
3731    end
3732    UvData.MouseAction='create_object';
3733else
3734    set(handles.VOLUME,'BackgroundColor',[0 1 0])
3735    UvData.MouseAction='none';
3736end
3737set(huvmat,'UserData',UvData)
3738
3739%-------------------------------------------------------
3740function edit_vect_Callback(hObject, eventdata, handles)
3741%-------------------------------------------------------
3742
3743UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3744if isequal(get(handles.edit_vect,'Value'),1)
3745    test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
3746    test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
3747    if ~test_civ2 && ~test_civ1
3748        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3749    end
3750    set(handles.record,'Visible','on')
3751    set(handles.edit_vect,'BackgroundColor',[1 1 0])
3752    set(handles.edit,'Value',0)
3753    set(handles.zoom,'Value',0)
3754    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3755%     set(handles.create,'Value',0)
3756%     set(handles.create,'BackgroundColor',[0 1 0])
3757    set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
3758    set(gcf,'Pointer','arrow')
3759    UvData.MouseAction='edit_vect';
3760else
3761    set(handles.record,'Visible','off')
3762    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3763    UvData.MouseAction='none';
3764end
3765set(handles.uvmat,'UserData',UvData)
3766
3767%----------------------------------------------
3768function save_mask_Callback(hObject, eventdata, handles)
3769%-----------------------------------------------------------------------
3770huvmat=get(handles.save_mask,'parent');
3771UvData=get(huvmat,'UserData');
3772
3773hpatch=findobj(huvmat,'Type','patch');
3774flag=1;
3775npx=size(UvData.Field.A,2);
3776npy=size(UvData.Field.A,1);
3777xi=[0.5:npx-0.5];
3778yi=[0.5:npy-0.5];
3779[Xi,Yi]=meshgrid(xi,yi);
3780if isfield(UvData,'Object')
3781    for iobj=1:length(UvData.Object)
3782        ObjectData=UvData.Object{iobj};
3783        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3784            flagobj=1;
3785            testphys=0; %coordinates in pixels by default
3786            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3787                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
3788                    Calib=UvData.XmlData.GeometryCalib;
3789                    testphys=1;
3790                end
3791            end
3792            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
3793                if isequal(ObjectData.Style,'polygon')
3794                    X=ObjectData.Coord(:,1);
3795                    Y=ObjectData.Coord(:,2);
3796                    if testphys
3797                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3798                    end
3799                    flagobj=~inpolygon(Xi,Yi,X,Y);%=0 inside the polygon, 1 outside                 
3800                elseif isequal(ObjectData.Style,'ellipse')
3801                    if testphys
3802                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3803                    end
3804                    RangeX=max(ObjectData.RangeX);
3805                    RangeY=max(ObjectData.RangeY);
3806                    X2Max=RangeX*RangeX;
3807                    Y2Max=RangeY*RangeY;
3808                    distX=(Xi-ObjectData.Coord(1,1));
3809                    distY=(Yi-ObjectData.Coord(1,2));
3810                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3811                elseif isequal(ObjectData.Style,'rectangle')
3812                    if testphys
3813                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3814                    end
3815                    distX=abs(Xi-ObjectData.Coord(1,1));
3816                    distY=abs(Yi-ObjectData.Coord(1,2));
3817                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3818                end
3819                if isequal(ObjectData.ProjMode,'mask_outside')
3820                    flagobj=~flagobj;
3821                end
3822                flag=flag & flagobj;
3823            end
3824        end
3825    end
3826end
3827% flag=~flag;
3828%mask name
3829RootPath=get(handles.RootPath,'String');
3830RootFile=get(handles.RootFile,'String');
3831if ~isempty(RootFile)&(isequal(RootFile(1),'/')| isequal(RootFile(1),'\'))
3832        RootFile(1)=[];
3833end
3834filebase=fullfile(RootPath,RootFile);
3835list=get(handles.masklevel,'String');
3836masknumber=num2str(length(list));
3837maskindex=get(handles.masklevel,'Value');
3838mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3839imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3840imflag=flipdim(imflag,1);
3841% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3842msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
3843imwrite(imflag,mask_name,'BitDepth',8);
3844
3845%display the mask
3846%update_mask(handles,num_i1,num_j1)
3847figure;
3848vec=linspace(0,1,256);%define a linear greyscale colormap
3849map=[vec' vec' vec'];
3850colormap(map)
3851
3852image(imflag);
3853
3854%-------------------------------------------------------------------
3855%-------------------------------------------------------------------
3856%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3857
3858%------------------------------------------------------------------
3859
3860
3861
3862%------------------------------------------------------------------
3863% --- Executes on selection change in col_vec: choice of the color code.
3864%
3865function col_vec_Callback(hObject, eventdata, handles)
3866%------------------------------------------------------------------
3867% edit the choice for color code
3868list_code=get(handles.col_vec,'String');% list menu fields
3869index_code=get(handles.col_vec,'Value');% selected string index
3870col_code= list_code{index_code(1)}; % selected field
3871if isequal(col_code,'black') | isequal(col_code,'white')
3872   set(handles.slider1,'Visible','off')
3873   set(handles.slider2,'Visible','off')
3874   set(handles.colcode1,'Visible','off')
3875   set(handles.colcode2,'Visible','off')
3876   set(handles.AutoVecColor,'Visible','off')
3877   set_vec_col_bar(handles)
3878else
3879   set(handles.slider1,'Visible','on')
3880   set(handles.slider2,'Visible','on')
3881   set(handles.colcode1,'Visible','on')
3882   set(handles.colcode2,'Visible','on')
3883   set(handles.AutoVecColor,'Visible','on') 
3884   if isequal(col_code,'ima_cor')
3885       set(handles.AutoVecColor,'Value',0)%fixed scale by default
3886       set(handles.vec_col_bar,'Value',0)% 3 colors r,g,b by default
3887       set(handles.slider1,'Min',0);
3888       set(handles.slider1,'Max',1);
3889       set(handles.slider2,'Min',0);
3890       set(handles.slider2,'Max',1);
3891 %      set(handles.min_title_vec,'String','0')
3892       set(handles.max_vec,'String','1')
3893       set(handles.colcode1,'String','0.333')
3894       colcode1_Callback(hObject, eventdata, handles)
3895       set(handles.colcode2,'String','0.666')
3896       colcode2_Callback(hObject, eventdata, handles)
3897   else
3898       set(handles.AutoVecColor,'Value',1)%auto scale between min,max by default
3899       set(handles.vec_col_bar,'Value',1)% colormap 'jet' by default
3900       minval=get(handles.slider1,'Min');
3901       maxval=get(handles.slider1,'Max');
3902       set(handles.slider1,'Value',minval)
3903       set(handles.slider2,'Value',maxval)
3904       set_vec_col_bar(handles)
3905   end
3906%    slider_update(handles)
3907end
3908%replot the current graph
3909run0_Callback(hObject, eventdata, handles)
3910
3911
3912%----------------------------------------------------------------
3913% -- Executes on slider movement to set the color code
3914%
3915function slider1_Callback(hObject, eventdata, handles)
3916%------------------------------------------------------------------
3917slider1=get(handles.slider1,'Value');
3918min_val=str2num(get(handles.min_vec,'String'));
3919max_val=str2num(get(handles.max_vec,'String'));
3920col=min_val+(max_val-min_val)*slider1;
3921set(handles.colcode1,'String',num2str(col))
3922if(get(handles.slider2,'Value') < col)%move also the second slider at the same value if needed
3923    set(handles.slider2,'Value',col)
3924    set(handles.colcode2,'String',num2str(col))
3925end
3926colcode1_Callback(hObject, eventdata, handles)
3927
3928%----------------------------------------------------------------
3929% Executes on slider movement to set the color code
3930%----------------------------------------------------------------
3931function slider2_Callback(hObject, eventdata, handles)
3932slider2=get(handles.slider2,'Value');
3933min_val=str2num(get(handles.min_vec,'String'));
3934max_val=str2num(get(handles.max_vec,'String'));
3935col=min_val+(max_val-min_val)*slider2;
3936set(handles.colcode2,'String',num2str(col))
3937if(get(handles.slider1,'Value') > col)%move also the first slider at the same value if needed
3938    set(handles.slider1,'Value',col)
3939    set(handles.colcode1,'String',num2str(col))
3940end
3941colcode2_Callback(hObject, eventdata, handles)
3942
3943%----------------------------------------------------------------
3944%execute on return carriage on the edit box corresponding to slider 1
3945%----------------------------------------------------------------
3946function colcode1_Callback(hObject, eventdata, handles)
3947% col=str2num(get(handles.colcode1,'String'));
3948% set(handles.slider1,'Value',col)
3949set_vec_col_bar(handles)
3950update_plot(handles)
3951
3952%----------------------------------------------------------------
3953%execute on return carriage on the edit box corresponding to slider 2
3954%----------------------------------------------------------------
3955function colcode2_Callback(hObject, eventdata, handles)
3956% col=str2num(get(handles.colcode2,'String'));
3957% set(handles.slider2,'Value',col)
3958% slider2_Callback(hObject, eventdata, handles)
3959set_vec_col_bar(handles)
3960update_plot(handles)
3961%------------------------------------------------------------
3962%update the slider values after displaying vectors
3963%--------------------------------------------------------
3964% function slider_update(handles,auto,minC,colcode1,colcode2,maxC)
3965% set(handles.slider1,'Min',minC)
3966% set(handles.slider1,'Max',maxC)
3967% set(handles.slider2,'Min',minC)
3968% set(handles.slider2,'Max',maxC)
3969% set(handles.min_title_vec,'String',num2str(minC))
3970% set(handles.max_vec,'String',num2str(maxC))
3971% if auto
3972%         set(handles.colcode1,'String',num2str(colcode1,3))%update display
3973%         set(handles.colcode2,'String',num2str(colcode2,3))
3974% end
3975% set(handles.slider1,'Value',colcode1)%update slider with constant display
3976% set(handles.slider2,'Value',colcode2)
3977% set_vec_col_bar(handles)
3978
3979
3980%-------------------------------------------------------
3981% --- Executes on button press in AutoVecColor.
3982%-------------------------------------------------------
3983function vec_col_bar_Callback(hObject, eventdata, handles)
3984set_vec_col_bar(handles)
3985
3986% %--------------------------------------------
3987% %update the display of color code for vectors
3988% %--------------------------------------------
3989% function set_vec_col_bar(handles)
3990% %get the image of the color display button 'vec_col_bar' in pixels
3991% uni=get(handles.vec_col_bar,'Unit');
3992% set(handles.vec_col_bar,'Unit','pixel')
3993% pos_vert=get(handles.vec_col_bar,'Position');
3994% set(handles.vec_col_bar,'Unit','Normalized')
3995% width=ceil(pos_vert(3));
3996% height=ceil(pos_vert(4));
3997% %get slider indications
3998% colcode.min=get(handles.slider1,'Min');
3999% colcode.max=get(handles.slider1,'Max');
4000% colcode.colcode1=get(handles.slider1,'Value');
4001% colcode.colcode2=get(handles.slider2,'Value');
4002% colcode.option=get(handles.vec_col_bar,'Value');
4003% colcode.auto=1;
4004% list_code=get(handles.col_vec,'String');% list menu fields
4005% index_code=get(handles.col_vec,'Value');% selected string index
4006% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
4007% vec_C=colcode.min+(colcode.max-colcode.min)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
4008% [colorlist,col_vec]=set_col_vec(colcode,vec_C);
4009% oneheight=ones(1,height);
4010% A1=colorlist(col_vec,1)*oneheight;
4011% A2=colorlist(col_vec,2)*oneheight;
4012% A3=colorlist(col_vec,3)*oneheight;
4013% A(:,:,1)=A1';
4014% A(:,:,2)=A2';
4015% A(:,:,3)=A3';
4016% set(handles.vec_col_bar,'Cdata',A)
4017
4018%--------------------------------------------------------
4019% --- Executes on button press in cal.
4020function cal_Callback(hObject, eventdata, handles)
4021
4022
4023
4024%-------------------------------------------------------------
4025% --- Executes on selection change in transform_fct.
4026function transform_fct_Callback(hObject, eventdata, handles)
4027%-------------------------------------------------------------
4028global nb_builtin
4029
4030huvmat=get(handles.transform_fct,'parent');
4031menu=get(handles.transform_fct,'String');
4032ind_coord=get(handles.transform_fct,'Value');
4033coord_option=menu{ind_coord};
4034list_transform=get(handles.transform_fct,'UserData');
4035ff=functions(list_transform{end}); 
4036if isequal(coord_option,'more...');
4037    coord_fct='';
4038
4039%     if exist(profil_perso,'file')
4040%           h=load (profil_perso);
4041%          if isfield(h,'transform_fct')
4042%                 transform_fct=h.transform_fct;
4043%          end
4044%     end
4045    prompt = {'Enter the name of the transform function'};
4046    dlg_title = 'user defined transform';
4047    num_lines= 1;
4048    [FileName, PathName, filterindex] = uigetfile( ...
4049       {'*.m', ' (*.m)';
4050        '*.m',  '.m files '; ...
4051        '*.*', 'All Files (*.*)'}, ...
4052        'Pick a file', ff.file);
4053    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
4054        PathName(end)=[];
4055    end
4056    transform_selected =fullfile(PathName,FileName);
4057    if ~exist(transform_selected,'file')
4058%            msgbox_uvmat('ERROR',['procesing fct ' transform_selected ' not found'])
4059           return
4060    end
4061   [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
4062   if ~isequal(ext_fct,'.m')
4063        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
4064        return
4065   end
4066   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
4067   ind_coord=get(handles.transform_fct,'Value');
4068   addpath(PathName)
4069   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
4070   set(handles.transform_fct,'UserData',list_transform)
4071   rmpath(PathName)
4072   % save the new menu in the personal file 'uvmat_perso.mat'
4073   dir_perso=prefdir;%personal Matalb directory
4074   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
4075   if exist(profil_perso,'file')
4076       for ilist=nb_builtin+1:numel(list_transform)
4077           ff=functions(list_transform{ilist});
4078           transform_fct{ilist-nb_builtin}=ff.file;
4079       end
4080        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
4081   end   
4082end
4083
4084%check the current path to the selected function
4085if isa(list_transform{ind_coord},'function_handle')
4086    func=functions(list_transform{ind_coord});
4087    set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
4088else
4089    set(handles.path_transform,'String','')
4090end
4091%CurrentPath=fileparts(which(coord_option));
4092% if ~isequal(PathName,CurrentPath)
4093%     addpath(PathName)
4094%     errormsg=check_functions;
4095%     msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
4096% end
4097%set(handles.path_transform,'String',fullfile(PathName,' ')); %show the path to the senlected function
4098set(handles.FixedLimits,'Value',0)
4099set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
4100
4101UvData=get(huvmat,'UserData');
4102
4103%delete drawn objects
4104hother=findobj('Tag','proj_object');%find all the proj objects
4105for iobj=1:length(hother)
4106    delete_object(hother(iobj))
4107end
4108hother=findobj('Tag','DeformPoint');%find all the proj objects
4109for iobj=1:length(hother)
4110    delete_object(hother(iobj))
4111end
4112hh=findobj('Tag','calib_points');
4113if ~isempty(hh)
4114    delete(hh)
4115end
4116hhh=findobj('Tag','calib_marker');
4117if ~isempty(hhh)
4118    delete(hhh)
4119end
4120if isfield(UvData,'Object')
4121    nbobject=length(UvData.Object);
4122    UvData.Object([2:nbobject])=[];
4123end
4124
4125%delete mask if it is displayed
4126if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
4127   UvData=rmfield(UvData,'MaskName'); %will impose mask refresh 
4128end
4129set(huvmat,'UserData',UvData)
4130run0_Callback(hObject, eventdata, handles)
4131
4132%--------------------------------------------
4133function histo1_menu_Callback(hObject, eventdata, handles)
4134%--------------------------------------------
4135%plot first histo
4136huvmat=get(handles.histo1_menu,'parent');
4137histo_menu=get(handles.histo1_menu,'String');
4138histo_value=get(handles.histo1_menu,'Value');
4139FieldName=histo_menu{histo_value};
4140UvData=get(huvmat,'UserData');
4141update_histo(handles.histo_u,huvmat,FieldName)
4142
4143%----------------------------------------------
4144function histo2_menu_Callback(hObject, eventdata, handles)
4145%----------------------------------------------
4146%plot second histo
4147huvmat=get(handles.histo2_menu,'parent');
4148histo_menu=get(handles.histo2_menu,'String');
4149histo_value=get(handles.histo2_menu,'Value');
4150FieldName=histo_menu{histo_value};
4151UvData=get(huvmat,'UserData');
4152update_histo(handles.histo_v,huvmat,FieldName)
4153
4154
4155%--------------------------------------------
4156%read the field .Fieldname stored in UvData and plot its histogram
4157function update_histo(haxes,huvmat,FieldName)
4158UvData=get(huvmat,'UserData');
4159
4160if ~isfield(UvData.Field,FieldName)
4161    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
4162    return
4163end
4164Field=UvData.Field;
4165FieldHisto=eval(['Field.' FieldName]);
4166if isfield(Field,'FF') & ~isempty(Field.FF) & isequal(size(Field.FF),size(FieldHisto))
4167    indsel=find(Field.FF==0);%find values marked as false
4168    if ~isempty(indsel)
4169        FieldHisto=FieldHisto(indsel);
4170    end
4171end
4172if isempty(Field)
4173    msgbox_uvmat('ERROR',['empty field ' FieldName])
4174else
4175    nxy=size(FieldHisto);
4176    Amin=double(min(min(min(FieldHisto))));%min of image
4177    Amax=double(max(max(max(FieldHisto))));%max of image
4178    if isequal(Amin,Amax)
4179       Histo.Txt=['uniform field =' num2str(Amin)];
4180    else
4181    Histo.ListVarName={FieldName,'histo'};
4182    if numel(nxy)==2
4183        Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
4184    else %color images
4185        Histo.VarDimName={FieldName,{FieldName,'rgb'}}; %dimensions for the histogram
4186    end
4187    %unit
4188    units=[]; %default
4189    for ivar=1:numel(Field.ListVarName)   
4190        if strcmp(Field.ListVarName{ivar},FieldName)
4191            if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
4192                units=Field.VarAttribute{ivar}.units;
4193                break
4194            end
4195        end
4196    end
4197    if ~isempty(units)
4198        Histo.VarAttribute{1}.units=units;
4199    end
4200    eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
4201    for col=1:size(FieldHisto,3)
4202        B=FieldHisto(:,:,col);
4203        C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
4204       eval(['Histo.histo(:,col)=hist(C, Histo.' FieldName ');']);  %calculate histogram
4205    end
4206    set(haxes,'XLimMode','auto')%reset auto mode (after zoom effect)
4207    set(haxes,'YLimMode','auto')
4208    plot_field(Histo,haxes);
4209    end
4210end
4211
4212
4213
4214%------------------------------------------------
4215%CALLBACKS FOR PLOTTING PARAMETERS
4216%-------------------------------------------------
4217
4218%-----------------------------------------------------------------
4219function MinA_Callback(hObject, eventdata, handles)
4220%------------------------------------------
4221set(handles.AutoScal,'Value',1) %suppress auto mode
4222set(handles.AutoScal,'BackgroundColor',[1 1 0])
4223update_plot(handles)
4224
4225%-----------------------------------------------------------------
4226function MaxA_Callback(hObject, eventdata, handles)
4227%--------------------------------------------
4228set(handles.AutoScal,'Value',1) %suppress auto mode
4229set(handles.AutoScal,'BackgroundColor',[1 1 0])
4230update_plot(handles)
4231
4232%-----------------------------------------------
4233function AutoScal_Callback(hObject, eventdata, handles)
4234%--------------------------------------------
4235test=get(handles.AutoScal,'Value');
4236if test
4237    set(handles.AutoScal,'BackgroundColor',[1 1 0])
4238else
4239    set(handles.AutoScal,'BackgroundColor',[0.7 0.7 0.7])
4240    update_plot(handles);
4241%     set(handles.MinA,'String',num2str(ScalOut.MinA,3))
4242%     set(handles.MaxA,'String',num2str(ScalOut.MaxA,3))
4243end
4244
4245%-------------------------------------------------------------------
4246function BW_Callback(hObject, eventdata, handles)
4247%-------------------------------------------------------------------
4248update_plot(handles)
4249
4250%-------------------------------------------------------------------
4251function Contours_Callback(hObject, eventdata, handles)
4252%-------------------------------------------------------------------
4253val=get(handles.Contours,'Value');
4254if val==2
4255    set(handles.interval_txt,'Visible','on')
4256    set(handles.IncrA,'Visible','on')
4257else
4258    set(handles.interval_txt,'Visible','off')
4259    set(handles.IncrA,'Visible','off')
4260end
4261update_plot(handles)
4262
4263%-------------------------------------------------------------------
4264function IncrA_Callback(hObject, eventdata, handles)
4265%-------------------------------------------------------------------
4266update_plot(handles)
4267
4268%-------------------------------------------------------------------
4269function HideWarning_Callback(hObject, eventdata, handles)
4270%-------------------------------------------------------------------
4271update_plot(handles)
4272
4273%-------------------------------------------------------------------
4274function HideFalse_Callback(hObject, eventdata, handles)
4275%-------------------------------------------------------------------
4276update_plot(handles)
4277
4278%-------------------------------------------------------------------
4279function VecScale_Callback(hObject, eventdata, handles)
4280%-------------------------------------------------------------------
4281set(handles.AutoVec,'Value',1);
4282set(handles.AutoVec,'BackgroundColor',[1 1 0])
4283update_plot(handles)
4284
4285%-------------------------------------------------------------------
4286function AutoVec_Callback(hObject, eventdata, handles)
4287%-------------------------------------------------------------------
4288test=get(handles.AutoVec,'Value');
4289if test
4290    set(handles.AutoVec,'BackgroundColor',[1 1 0])
4291else
4292    update_plot(handles);
4293    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4294    set(handles.AutoVec,'BackgroundColor',[0.7 0.7 0.7])
4295end
4296
4297%-------------------------------------------------------
4298% --- Executes on selection change in decimate4 (nb_vec/4).
4299%-------------------------------------------------------
4300function decimate4_Callback(hObject, eventdata, handles)
4301update_plot(handles)
4302
4303
4304%-------------------------------------------------------
4305% --- Executes on selection change in color_code menu
4306%-------------------------------------------------------
4307function color_code_Callback(hObject, eventdata, handles)
4308set_vec_col_bar(handles)
4309update_plot(handles);
4310
4311%-------------------------------------------------------
4312% --- Executes on button press in AutoVecColor.
4313%-------------------------------------------------------
4314function AutoVecColor_Callback(hObject, eventdata, handles)
4315test=get(handles.AutoVecColor,'Value');
4316if test
4317    set(handles.AutoVecColor,'BackgroundColor',[1 1 0])
4318else
4319    update_plot(handles);
4320    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4321    set(handles.AutoVecColor,'BackgroundColor',[0.7 0.7 0.7])
4322end
4323%set_vec_col_bar(handles)
4324
4325%-------------------------------------------------------
4326% --- Executes on selection change in max_vec.
4327%-------------------------------------------------------
4328function min_vec_Callback(hObject, eventdata, handles)
4329max_vec_Callback(hObject, eventdata, handles)
4330
4331% --- Executes on selection change in max_vec.
4332function max_vec_Callback(hObject, eventdata, handles)
4333set(handles.AutoVecColor,'Value',1)
4334AutoVecColor_Callback(hObject, eventdata, handles)
4335min_val=str2num(get(handles.min_vec,'String'));
4336max_val=str2num(get(handles.max_vec,'String'));
4337slider1=get(handles.slider1,'Value');
4338slider2=get(handles.slider2,'Value');
4339colcode1=min_val+(max_val-min_val)*slider1;
4340colcode2=min_val+(max_val-min_val)*slider2;
4341set(handles.colcode1,'String',num2str(colcode1))
4342set(handles.colcode2,'String',num2str(colcode2))
4343update_plot(handles);
4344
4345%-------------------------------------------------------------------
4346%update the display of color code for vectors
4347function set_vec_col_bar(handles)
4348%-------------------------------------------------------------------
4349%get the image of the color display button 'vec_col_bar' in pixels
4350set(handles.vec_col_bar,'Unit','pixel');
4351pos_vert=get(handles.vec_col_bar,'Position');
4352set(handles.vec_col_bar,'Unit','Normalized');
4353width=ceil(pos_vert(3));
4354height=ceil(pos_vert(4));
4355
4356%get slider indications
4357list=get(handles.color_code,'String');
4358ichoice=get(handles.color_code,'Value');
4359colcode.ColorCode=list{ichoice};
4360colcode.MinC=str2num(get(handles.min_vec,'String'));
4361colcode.MaxC=str2num(get(handles.max_vec,'String'));
4362test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
4363if test3color
4364    colcode.colcode1=str2num(get(handles.colcode1,'String'));
4365    colcode.colcode2=str2num(get(handles.colcode2,'String'));
4366end
4367% colcode.option=get(handles.vec_col_bar,'Value');
4368colcode.FixedCbounds=0;
4369% list_code=get(handles.col_vec,'String');% list menu fields
4370% index_code=get(handles.col_vec,'Value');% selected string index
4371% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
4372colcode.FixedCbounds=1;
4373vec_C=colcode.MinC+(colcode.MaxC-colcode.MinC)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
4374[colorlist,col_vec]=set_col_vec(colcode,vec_C);
4375oneheight=ones(1,height);
4376A1=colorlist(col_vec,1)*oneheight;
4377A2=colorlist(col_vec,2)*oneheight;
4378A3=colorlist(col_vec,3)*oneheight;
4379A(:,:,1)=A1';
4380A(:,:,2)=A2';
4381A(:,:,3)=A3';
4382set(handles.vec_col_bar,'Cdata',A)
4383
4384
4385%-------------------------------------------------------------------
4386function [PlotType,ScalOut]=update_plot(handles)
4387%-------------------------------------------------------------------
4388haxes= handles.axes3;
4389AxeData=get(haxes,'UserData');
4390PlotParam=read_plot_param(handles);
4391[PlotType,PlotParamOut]= plot_field(AxeData,haxes,PlotParam,1);
4392write_plot_param(handles,PlotParamOut); %update the auto plot parameters
4393
4394%-------------------------------------------------------------------
4395% --- Executes on button press in grid.
4396function grid_Callback(hObject, eventdata, handles)
4397%-------------------------------------------------------------------
4398
4399UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4400
4401%suppress the other options if grid is chosen
4402% set(handles.create,'Value',0)
4403% set(handles.create,'BackgroundColor',[0 1 0])
4404set(handles.edit_vect,'Value',0)
4405edit_vect_Callback(hObject, eventdata, handles)
4406set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4407set(handles.edit_vect,'Value',0) 
4408edit_vect_Callback(hObject, eventdata, handles)
4409set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4410set(handles.list_object_1,'Value',1)     
4411set(handles.cal,'Value',0)
4412set(handles.cal,'BackgroundColor',[0 1 0])   
4413
4414%prepare display of the set_grid GUI
4415data.fixedtitle=1;
4416FileName=read_file_boxes(handles);
4417[hset_object,UvData.sethandles]=set_grid(FileName);% call the set_object interface
4418set(huvmat,'UserData',UvData);
4419
4420
4421%-------------------------------------------------------------------
4422% --- Executes on selection change in edit.
4423function edit_Callback(hObject, eventdata, handles)
4424%-------------------------------------------------------------------
4425UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4426test=get(handles.edit,'Value');
4427if test
4428    UvData.MouseAction='edit_object';
4429    set(handles.edit,'BackgroundColor',[1,1,0]) 
4430    %suppress the other options
4431    set(handles.zoom,'Value',0)
4432    zoom_Callback(hObject, eventdata, handles)
4433    set(handles.edit_vect,'Value',0)
4434    edit_vect_Callback(hObject, eventdata, handles) 
4435    %list_object_Callback(hObject, eventdata, handles)
4436else
4437    UvData.MouseAction='none';
4438    set(handles.edit,'BackgroundColor',[0.7,0.7,0.7])   
4439end
4440set(handles.uvmat,'UserData',UvData);
4441hset_object=findobj(allchild(0),'Tag','set_object');
4442if ~isempty(hset_object)
4443    hhset_object=guidata(hset_object);
4444    if test
4445        set(hhset_object.PLOT,'Visible','on');
4446    else
4447       set(hhset_object.PLOT,'Visible','off');
4448    end
4449end
4450
4451%------------------------------------------------------------------------
4452% --- Executes on selection change in list_object_1.
4453function list_object_1_Callback(hObject, eventdata, handles)
4454%------------------------------------------------------------------------
4455list_str=get(handles.list_object_1,'String');
4456IndexObj=get(handles.list_object_1,'Value');
4457str_1=list_str{IndexObj};
4458set(handles.list_object_1,'BackgroundColor',[1 1 0])
4459set(handles.list_object_2,'BackgroundColor',[1 1 1])
4460val_2=get(handles.list_object_2,'Value');
4461str_2=get(handles.list_object_2,'String');
4462if isequal(val_2,IndexObj)
4463    set(handles.list_object_2,'Value',numel(str_2))
4464    list_object_2_Callback(hObject, eventdata, handles)
4465end
4466hset_object=findobj(allchild(0),'Tag','set_object');
4467if ~isempty(hset_object)
4468     set(hset_object,'name',str_1);
4469end
4470update_object(handles,IndexObj,1)
4471
4472%------------------------------------------------------------------------
4473% --- Executes on selection change in list_object_1.
4474function list_object_2_Callback(hObject, eventdata, handles)
4475%------------------------------------------------------------------------
4476list_str=get(handles.list_object_2,'String');
4477IndexObj=get(handles.list_object_2,'Value');
4478if isequal(list_str{IndexObj},'...')
4479    hview_field=findobj(allchild(0),'Tag','view_field')
4480    if ~isempty(hview_field)
4481        delete(hview_field)
4482    end
4483    set(handles.list_object_2,'BackgroundColor',[1 1 1])
4484else
4485    hset_object=findobj(allchild(0),'Tag','set_object');
4486    if ~isempty(hset_object)
4487        set(hset_object,'name',list_str{IndexObj});
4488    end
4489    set(handles.list_object_2,'BackgroundColor',[1 1 0])
4490    set(handles.list_object_1,'BackgroundColor',[1 1 1])
4491    update_object(handles,IndexObj,2)
4492end
4493
4494%------------------------------------------------------------------------
4495function update_object(handles,IndexObj,option)
4496%------------------------------------------------------------------------
4497UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4498if ~(length(UvData.Object)>=IndexObj);
4499    return
4500end
4501ObjectData=UvData.Object{IndexObj};
4502if isequal(get(handles.edit,'Value'),0)
4503    ObjectData.desable_plot=1; % desable the PLOT option in the set_object GUI (editing mode
4504end
4505PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
4506ZBounds=0; % default
4507    if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
4508        ZBounds(1)=UvData.ZMin; %minimum for the Z slider
4509        ZBounds(2)=UvData.ZMax;%maximum for the Z slider
4510    end
4511hset_object=findobj(allchild(0),'Name','set_object');
4512if ~isempty(hset_object)
4513    delete(hset_object)% delete existing version of set_object
4514end
4515hset_object=set_object(ObjectData,PlotHandles,ZBounds);% call the set_object interface,
4516pos_uvmat=get(handles.uvmat,'Position');
4517%position the set_object GUI with respect to uvmat
4518if isfield(UvData,'SetObjectOrigin')
4519    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4520    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
4521    set(hset_object,'Position',pos_set_object)
4522end
4523
4524%project the current field on the object and plot it
4525ProjData= proj_field(UvData.Field,ObjectData,IndexObj);%project the current interface field on ObjectData
4526if option==1%length(UvData.Object)>= IndexObj && isfield(UvData.Object{IndexObj},'plotaxes')&& ishandle(UvData.Object{IndexObj}.plotaxes)
4527    plot_field(ProjData,handles.axes3,PlotHandles);
4528    UvData.Object{IndexObj}.plotaxes=handles.axes3;
4529else
4530    UvData.Object{IndexObj}.plotaxes=view_field(ProjData);
4531end
4532
4533hother=findobj('Tag','proj_object');%find all the proj objects
4534for iobj=1:length(hother)
4535    if isequal(get(hother(iobj),'Type'),'rectangle')|isequal(get(hother(iobj),'Type'),'patch')
4536        set(hother(iobj),'EdgeColor','b')
4537        if isequal(get(hother(iobj),'FaceColor'),'m')
4538            set(hother(iobj),'FaceColor','b')
4539        end
4540    elseif isequal(get(hother(iobj),'Type'),'image')
4541           Acolor=get(hother(iobj),'CData');
4542           Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4543           set(hother(iobj),'CData',Acolor);
4544    else
4545         set(hother(iobj),'Color','b')
4546    end
4547    set(hother(iobj),'Selected','off')
4548end
4549hother=findobj('Tag','DeformPoint');
4550set(hother,'Color','b');
4551set(hother,'Selected','off')   
4552if isfield(ObjectData,'HandlesDisplay')
4553    for iview=1:length(ObjectData.HandlesDisplay)
4554        if ishandle(ObjectData.HandlesDisplay(iview))
4555            uistack(ObjectData.HandlesDisplay(iview),'top')
4556            linetype=get(ObjectData.HandlesDisplay(iview),'Type');
4557            if isequal(linetype,'line')
4558                set(ObjectData.HandlesDisplay(iview),'Color','m'); %set the selected object to magenta color
4559            elseif isequal(linetype,'rectangle')
4560                set(ObjectData.HandlesDisplay(iview),'EdgeColor','m'); %set the selected object to magenta color
4561            elseif isequal(linetype,'patch')
4562                set(ObjectData.HandlesDisplay(iview),'FaceColor','m'); %set the selected object to magenta color
4563            end
4564            SubObjectData=get(ObjectData.HandlesDisplay(iview),'UserData');
4565            if isfield(SubObjectData,'SubObject')& ishandle(SubObjectData.SubObject)
4566                uistack(SubObjectData.SubObject,'top')
4567                for iobj=1:length(SubObjectData.SubObject)
4568                    hsub=SubObjectData.SubObject(iobj);
4569                    if isequal(get(hsub,'Type'),'rectangle')
4570                        set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4571                    elseif isequal(get(hsub,'Type'),'image')
4572                       Acolor=get(hsub,'CData');
4573                       Acolor(:,:,1)=Acolor(:,:,3);
4574                       set(hsub,'CData',Acolor);
4575                    else
4576                        set(hsub,'Color','m')
4577                    end
4578                end
4579            end
4580            if isfield(SubObjectData,'DeformPoint')& ishandle(SubObjectData.DeformPoint)
4581                set(SubObjectData.DeformPoint,'Color','m')
4582            end
4583        end
4584    end
4585end
4586pause(0.1)
4587figure(hset_object)%put set_object in front
4588
4589%------------------------------------------------------
4590% --- Executes on button press in Menu/Export/field in workspace.
4591%------------------------------------------------------
4592function MenuExportField_Callback(hObject, eventdata, handles)
4593
4594global CurData
4595huvmat=get(handles.RootPath,'parent');
4596CurData=get(huvmat,'UserData');
4597evalin('base','global CurData')%make CurData global in the workspace
4598display(['UserData of uvmat :'])
4599evalin('base','CurData') %display CurData in the workspace
4600commandwindow;
4601
4602%------------------------------------------------------
4603% --- Executes on button press in Menu/Export/extract figure.
4604%------------------------------------------------------
4605function MenuExport_plot_Callback(hObject, eventdata, handles)
4606huvmat=get(handles.MenuExport_plot,'parent');
4607UvData=get(huvmat,'UserData');
4608hfig=figure;
4609newaxes=copyobj(handles.axes3,hfig);
4610map=colormap(handles.axes3);
4611colormap(map);%transmit the current colormap to the zoom fig
4612colorbar
4613
4614
4615% --------------------------------------------------------------------
4616function Insert_Callback(hObject, eventdata, handles)
4617
4618
4619% --------------------------------------------------------------------
4620function MenuRun_Callback(hObject, eventdata, handles)
4621% --------------------------------------------------------------------
4622
4623% --------------------------------------------------------------------
4624function MenuHelp_Callback(hObject, eventdata, handles)
4625% --------------------------------------------------------------------
4626path_to_uvmat=which ('uvmat');% check the path of uvmat
4627pathelp=fileparts(path_to_uvmat);
4628helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
4629if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
4630else
4631    addpath (fullfile(pathelp,'uvmat_doc'))
4632    web(helpfile);
4633end
4634
4635% --------------------------------------------------------------------
4636function MenuOpen_Callback(hObject, eventdata, handles)
4637% --------------------------------------------------------------------
4638% --------------------------------------------------------------------
4639function MenuOpen_1_Callback(hObject, eventdata, handles)
4640% --------------------------------------------------------------------
4641% --------------------------------------------------------------------
4642function MenuExport_Callback(hObject, eventdata, handles)
4643% --------------------------------------------------------------------
4644
4645% --------------------------------------------------------------------
4646function MenuExportMovie_Callback(hObject, eventdata, handles)
4647% --------------------------------------------------------------------
4648set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
4649huvmat=get(handles.run0,'parent');
4650UvData=get(huvmat,'UserData');
4651[xx,xx,FileBase]=read_file_boxes(handles);
4652 %read the current input file name
4653prompt = {'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)'};
4654dlg_title = 'select properties of the output avi movie';
4655num_lines= 1;
4656nbfield_cell=get(handles.last_i,'String');
4657def     = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
4658answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
4659aviname=answer{1};
4660fps=str2num(answer{2});
4661% check for existing file with output name aviname
4662if exist(aviname,'file')
4663    backup=aviname;
4664    testexist=2;
4665    while testexist==2
4666        backup=[backup '~'];
4667        testexist=exist(backup,'file');     
4668    end
4669    [success,message]=copyfile(aviname,backup);%make backup of the existing file
4670    if isequal(success,1)
4671        delete(aviname)%delete existing file
4672    else
4673        msgbox_uvmat('ERROR',message)
4674        return
4675    end
4676end
4677%create avi open
4678aviobj=avifile(aviname,'Compression','None','fps',fps);
4679
4680%display first view for tests
4681newfig=figure;
4682newaxes=copyobj(handles.axes3,newfig);%new plotting axes in the new figure
4683set(newaxes,'Tag','movieaxes')
4684nbpix=[512 384]*str2num(answer{3});
4685set(gcf,'Position',[1 1 nbpix])% resolution XVGA
4686set(newaxes,'Position',eval(answer{4}));
4687map=colormap(handles.axes3);
4688colormap(map);%transmit the current colormap to the zoom fig
4689msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
4690        ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
4691UvData.Object{1}.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
4692set(huvmat,'UserData',UvData);
4693increment=str2num(get(handles.increment_scan,'String')); %get the field increment d
4694set(handles.STOP,'Visible','on')
4695set(handles.speed,'Visible','on')
4696set(handles.speed_txt,'Visible','on')
4697set(handles.RunMovie,'BusyAction','queue')
4698
4699imin=str2num(get(handles.i1,'String'));
4700imax=str2num(answer{5});
4701% if isfield(UvData,'Time')
4702htitle=get(newaxes,'Title');
4703xlim=get(newaxes,'XLim');
4704ylim=get(newaxes,'YLim');
4705set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
4706time_str=get(handles.abs_time,'String');
4707set(htitle,'String',['t=' time_str])
4708set(handles.speed,'Value',1)
4709for i=1:imax
4710    if get(handles.speed,'Value')~=0 & isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
4711            runpm(hObject,eventdata,handles,increment)
4712            drawnow
4713            time_str=get(handles.abs_time,'String');
4714            if ishandle(htitle)
4715             set(htitle,'String',['t=' time_str])
4716            end
4717            mov=getframe(newfig);
4718            aviobj=addframe(aviobj,mov);
4719    end
4720end
4721aviobj=close(aviobj);
4722UvData.Object{1}.plotaxes=handles.axes3;
4723set(huvmat,'UserData',UvData);
4724msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
4725
4726
4727% ------------------------------------------------------------------
4728function MenuCalib_Callback(hObject, eventdata, handles)
4729% set(handles.TOOLS_txt,'Visible','on')
4730% set(handles.frame_tools,'Visible','on')
4731UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4732%reinitialize the edit interface associated with uvmat
4733%suppress the other options if MENULINE is chosen
4734set(handles.zoom,'Value',0)
4735set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
4736%         set(handles.create,'Value',0)
4737%         set(handles.create,'BackgroundColor',[0 1 0])
4738%         set(handles.create,'enable','off')     
4739set(handles.edit_vect,'Value',0)
4740set(handles.edit_vect,'enable','off')
4741edit_vect_Callback(hObject, eventdata, handles)
4742set(handles.edit,'Value',0)
4743set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4744set(handles.edit,'enable','off')
4745set(handles.list_object_1,'Value',1)     
4746% initiate display of GUI geometry_calib
4747data=[]; %default
4748if isfield(UvData,'CoordType')
4749    data.CoordType=UvData.CoordType;
4750end
4751pos=get(handles.uvmat,'Position');
4752pos(1)=pos(1)+pos(3)-0.311+0.04; %0.311= width of the geometry_calib interface (units relative to the srcreen)
4753pos(2)=pos(2)-0.02;
4754[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
4755[UvData.hset_object,UvData.sethandles]=geometry_calib(handles,pos,FileName);% call the set_object interface     
4756pos_uvmat=get(handles.uvmat,'Position');
4757%pos_cal(1:2)=UvData.CalOrigin + pos_uvmat(1:2);
4758if isfield(UvData,'CalOrigin')
4759    pos_cal(1)=pos_uvmat(1)+UvData.CalOrigin(1)*pos_uvmat(3);
4760    pos_cal(2)=pos_uvmat(2)+UvData.CalOrigin(2)*pos_uvmat(4);
4761    pos_cal(3:4)=UvData.CalSize .* pos_uvmat(3:4);
4762    set(UvData.hset_object,'Position',pos_cal)
4763end
4764UvData.MouseAction='calib';
4765set(handles.uvmat,'UserData',UvData);
4766
4767
4768% ------------------------------------------------------------------
4769function MenuMask_Callback(hObject, eventdata, handles)
4770set(handles.TOOLS_txt,'Visible','on')
4771set(handles.frame_tools,'Visible','on')
4772% set(handles.create,'Visible','on')
4773% set(handles.create,'Value',1)
4774% set(handles.create,'BackgroundColor',[1 1 0]) %visualise in yellow
4775set(handles.save_mask,'Visible','on')
4776set(handles.masklevel,'Visible','on')
4777if isequal(get(handles.z_index,'Visible'),'on')
4778    nb_slice=str2num(get(handles.nb_slice,'String'));
4779    for ilist=1:nb_slice
4780        list_index{ilist,1}=num2str(ilist);
4781    end   
4782    set(handles.masklevel,'String',list_index)
4783    val=str2num(get(handles.z_index,'String'));
4784    if val<=nb_slice
4785        set(handles.masklevel,'Value',val)
4786    end
4787else
4788    set(handles.masklevel,'String',{'1'})
4789    set(handles.masklevel,'Value',1)
4790end
4791if ishandle(handles.UVMAT_title)
4792    delete(handles.UVMAT_title)
4793end
4794% huvmat=get(handles.create,'parent');
4795UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4796set(handles.zoom,'Value',0)
4797set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
4798set(handles.edit_vect,'Value',0)
4799edit_vect_Callback(hObject, eventdata, handles)
4800set(handles.edit,'Value',0)
4801set(handles.edit,'BackgroundColor',[0.7 0.7 0.7])
4802set(handles.edit_vect,'Value',0) 
4803edit_vect_Callback(hObject, eventdata, handles)
4804% set(handles.cal,'Value',0)
4805% set(handles.cal,'BackgroundColor',[0 1 0])
4806
4807%initiate the GUI set_object
4808data.TITLE='MASK';
4809if isfield(UvData,'CoordType')
4810    data.CoordType=UvData.CoordType;
4811end
4812if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
4813    data.YMax=UvData.Mesh;
4814elseif isfield(UvData.Field,'AX')&&isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
4815    np=size(UvData.Field.A);
4816    meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/(np(2)-1);
4817    meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/(np(1)-1);
4818    data.YMax=max(meshx,meshy);
4819    data.DX=max(meshx,meshy);
4820end
4821data.Coord=[0 0 0]; %default
4822PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
4823[hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
4824pos_uvmat=get(handles.huvmat,'Position');
4825if isfield(UvData,'SetObjectOrigin')
4826    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
4827    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
4828    set(hset_object,'Position',pos_set_object)
4829end
4830list_object=get(handles.list_object_1,'String');
4831if ~isempty(list_object)
4832    set(handles.list_object_1,'Value',length(list_object))
4833end
4834UvData.MouseAction='create_object';
4835set(handles.uvmat,'UserData',UvData);
4836
4837% ------------------------------------------------------------------
4838%-- open the GUI set_grid.fig to create grid
4839function MenuGrid_Callback(hObject, eventdata, handles)
4840set(handles.TOOLS_txt,'Visible','on')
4841set(handles.frame_tools,'Visible','on')
4842grid_Callback(hObject,eventdata,handles)
4843
4844%----------------------------------------------------------------
4845% open the GUI 'series'
4846%----------------------------------------------------------------
4847function MenuSeries_Callback(hObject, eventdata, handles)
4848%-------------------------------------------------------------------
4849
4850[param.FileName]=read_file_boxes(handles);
4851if isequal(get(handles.SubField,'Value'),1)
4852    FileName_1=read_file_boxes_1(handles);%
4853    if ~isequal(FileName_1,param.FileName)
4854        param.FileName_1=FileName_1;
4855    end
4856end
4857param.NomType=get(handles.FileIndex,'UserData');
4858param.NomType_1=get(handles.FileIndex_1,'UserData');
4859param.comp_input=get(handles.fix_pair,'Value');
4860huvmat=get(handles.MenuSeries,'parent');
4861UvData=get(huvmat,'UserData');
4862if isfield(UvData,'Time')
4863    param.Time=UvData.XmlData.Time;
4864end
4865if isequal(get(handles.scan_i,'Value'),1)
4866    param.incr_i=str2num(get(handles.increment_scan,'String'));
4867elseif isequal(get(handles.scan_j,'Value'),1)
4868    param.incr_j=str2num(get(handles.increment_scan,'String'));
4869end
4870param.list_fields=get(handles.Fields,'String');% list menu fields
4871param.list_fields(1)=[]; %suppress  'image' option
4872param.index_fields=get(handles.Fields,'Value');% selected string index
4873if param.index_fields>1
4874    param.index_fields=param.index_fields-1;
4875end
4876param.list_fields_1=get(handles.Fields_1,'String');% list menu fields
4877param.list_fields_1(1)=[]; %suppress  'image' option
4878param.index_fields_1=get(handles.Fields_1,'Value')-1;% selected string index
4879if param.index_fields_1>1
4880    param.index_fields_1=param.index_fields_1-1;
4881end
4882param.civ1=get(handles.civ1,'Value');
4883param.civ2=get(handles.civ2,'Value');
4884param.interp1=get(handles.interp1,'Value');
4885param.interp2=get(handles.interp2,'Value');
4886param.filter1=get(handles.filter1,'Value');
4887param.filter2=get(handles.filter2,'Value');
4888param.menu_coord_str=get(handles.transform_fct,'String');
4889param.menu_coord_val=get(handles.transform_fct,'Value');
4890
4891series(param); %run the series interface
4892
4893% ------------------------------------------------------------------
4894% -- open the GUI civ.fig for civx (PIV)
4895% ------------------------------------------------------------------
4896function MenuPIV_Callback(hObject, eventdata, handles)
4897 
4898[FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles);
4899num1=stra2num(get(handles.i1,'String'));
4900num2=stra2num(get(handles.i2,'String'));
4901num_a=stra2num(get(handles.j1,'String'));
4902num_b=stra2num(get(handles.j2,'String'));
4903NomType=get(handles.FileIndex,'UserData');
4904ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
4905if isequal(ext,'.nc') ||  isequal(ext,'.cdf')% netcdf files
4906    ind_opening=2;% propose 'fix' as the default option
4907% +read the current netcdf rootfile
4908    Data=nc2struct(FileName,[]);
4909    if isfield(Data,'fix') & isequal(Data.fix,1)
4910        ind_opening=3;
4911    end
4912    if isfield(Data,'patch') & isequal(Data.patch,1)
4913        ind_opening=4;
4914    end
4915    if isfield(Data,'civ2') & isequal(Data.civ2,1)
4916        ind_opening=5;
4917    end
4918    if isfield(Data,'fix2') & isequal(Data.fix2,1)
4919        ind_opening=6;
4920    end
4921end     
4922varargin{1}=filebase;
4923varargin{2}=NomType;
4924varargin{3}=num1;
4925varargin{4}=num2;
4926varargin{5}=num_a;
4927varargin{6}=num_b;
4928varargin{7}=SubDir;
4929varargin{8}=ind_opening;% A REVOIR +TRANSMETTRE IMADOC INFO
4930varargin{11}=ext;
4931civ(varargin);% interface de civ(not in the uvmat file)
4932
4933% ------------------------------------------------------------------
4934function MenuTools_Callback(hObject, eventdata, handles)
4935
4936% ------------------------------------------------------------------
4937function MenuEdit_Callback(hObject, eventdata, handles)
4938
4939%--------------------------------------------------------------------------
4940function enable_transform(handles,state)
4941set(handles.transform_fct,'Visible',state)
4942set(handles.TRANSFORM_txt,'Visible',state)   
4943set(handles.transform_fct,'Visible',state) 
4944set(handles.path_transform,'Visible',state)
4945set(handles.pxcmx_txt,'Visible',state)
4946set(handles.pxcmy_txt,'Visible',state)
4947set(handles.pxcm,'Visible',state)
4948set(handles.pycm,'Visible',state)
4949
4950%------------------------------------------------------------------------
4951function MenuEditVectors_Callback(hObject, eventdata, handles)
4952%------------------------------------------------------------------------
4953set(handles.edit_vect,'Visible','on')
4954set(handles.edit_vect,'Value',1)
4955edit_vect_Callback(hObject, eventdata, handles)
4956
4957% --------------------------------------------------------------------
4958function Menupoints_Callback(hObject, eventdata, handles)
4959data.Style='points';
4960data.ProjMode='projection';%default
4961create_object(data,handles)
4962
4963% --------------------------------------------------------------------
4964function Menuline_Callback(hObject, eventdata, handles)
4965% set(handles.create,'Visible','on')
4966% set(handles.create,'Value',1)
4967% LINE_Callback(hObject,eventdata,handles)
4968data.Style='line';
4969data.ProjMode='projection';%default
4970create_object(data,handles)
4971
4972%------------------------------------------------------------------------
4973function Menupolyline_Callback(hObject, eventdata, handles)
4974%------------------------------------------------------------------------
4975data.Style='polyline';
4976data.ProjMode='projection';%default
4977create_object(data,handles)
4978
4979%------------------------------------------------------------------------
4980function Menupolygon_Callback(hObject, eventdata, handles)
4981%------------------------------------------------------------------------
4982data.Style='polygon';
4983data.ProjMode='inside';%default
4984create_object(data,handles)
4985
4986%------------------------------------------------------------------------
4987function Menurectangle_Callback(hObject, eventdata, handles)
4988%------------------------------------------------------------------------
4989data.Style='rectangle';
4990data.ProjMode='inside';%default
4991create_object(data,handles)
4992
4993%------------------------------------------------------------------------
4994function Menuellipse_Callback(hObject, eventdata, handles)
4995%------------------------------------------------------------------------
4996data.Style='ellipse';
4997data.ProjMode='inside';%default
4998create_object(data,handles)
4999
5000% ------------------------------------------------------------------
5001function Menuplane_Callback(hObject, eventdata, handles)
5002% set(handles.create,'Visible','on')
5003% set(handles.create,'Value',1)
5004% PLANE_Callback(hObject,eventdata,handles)
5005data.Style='plane';
5006data.ProjMode='projection';%default
5007
5008create_object(data,handles)
5009
5010% ------------------------------------------------------------------
5011function Menuvolume_Callback(hObject, eventdata, handles)
5012% set(handles.create,'Visible','on')
5013% set(handles.create,'Value',1)
5014VOLUME_Callback(hObject,eventdata,handles)
5015
5016%------------------------------------------------------------------------
5017function MenuBrowseObject_Callback(hObject, eventdata, handles)
5018%------------------------------------------------------------------------
5019%get the object file
5020[FileName, PathName, filterindex] = uigetfile( ...
5021       {'*.xml;*.mat', ' (*.xml,*.mat)';
5022       '*.xml',  '.xml files '; ...
5023        '*.mat',  '.mat matlab files '}, ...
5024        'Pick a file',get(handles.RootPath,'String'));
5025fileinput=[PathName FileName];%complete file name
5026testblank=findstr(fileinput,' ');%look for blanks
5027if ~isempty(testblank)
5028    msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
5029    return
5030end
5031sizf=size(fileinput);
5032if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
5033
5034%read the file
5035t=xmltree(fileinput);
5036data=convert(t);
5037PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
5038hset_object=findobj(allchild(0),'Name','set_object');
5039if ~isempty(hset_object)
5040    delete(hset_object)% delete existing version of set_object
5041end
5042[hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
5043%position the set_object GUI with respect to uvmat
5044pos_uvmat=get(handles.uvmat,'Position');
5045if isfield(UvData,'SetObjectOrigin')
5046    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
5047    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
5048    set(hset_object,'Position',pos_set_object)
5049end
5050set(handles.edit,'Value',0); %suppress the object edit mode
5051set(handles.edit,'BackgroundColor',[0.7,0.7,0.7]) 
5052UvData.MouseAction='create_object';
5053set(handles.uvmat,'UserData',UvData)
5054
5055%------------------------------------------------------------------------
5056function create_object(data,handles)
5057%------------------------------------------------------------------------
5058hset_object=findobj(allchild(0),'Name','set_object');
5059if ~isempty(hset_object)
5060    delete(hset_object)% delete existing version of set_object
5061end
5062UvData=get(handles.uvmat,'UserData');
5063set(handles.edit,'Value',0); %suppress the object edit mode
5064set(handles.edit,'BackgroundColor',[0.7,0.7,0.7]) 
5065if isfield(UvData,'CoordType')
5066    data.CoordType=UvData.CoordType;
5067end
5068if isfield(UvData,'Mesh')&&~isempty(UvData.Mesh)
5069    data.RangeX=UvData.Mesh;
5070    data.RangeY=UvData.Mesh;
5071    data.DX=UvData.Mesh;
5072    data.DY=UvData.Mesh;
5073elseif isfield(UvData.Field,'AX')&& isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')%only image
5074    np=size(UvData.Field.A);
5075    meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
5076    meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
5077    data.RangeY=max(meshx,meshy);
5078    data.RangeX=max(meshx,meshy);
5079    data.DX=max(meshx,meshy);
5080end
5081data.Coord=[0 0 0]; %default
5082if isfield(data,'Style') && isequal(data.Style,'line')
5083    if isfield(data,'DX')
5084        data.Coord=[[0 0 0];[data.DX 0 0]]; %default
5085    else
5086        data.Coord=[[0 0 0];[1 0 0]]; %default
5087    end
5088end
5089%data.ParentButton=handles.create;
5090if ishandle(handles.UVMAT_title)
5091    delete(handles.UVMAT_title)%delete the initial display of uvmat if no field has been entered
5092end
5093PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
5094[hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface
5095
5096pos_uvmat=get(handles.uvmat,'Position');
5097%position the set_object GUI with respect to uvmat
5098if isfield(UvData,'SetObjectOrigin')
5099    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
5100    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
5101    set(hset_object,'Position',pos_set_object)
5102end
5103
5104UvData.MouseAction='create_object';
5105set(handles.uvmat,'UserData',UvData)
5106set(handles.zoom,'Value',0)
5107zoom_Callback(handles.uvmat, [], handles)
5108
5109
5110
5111% --------------------------------------------------------------------
5112function MenuRuler_Callback(hObject, eventdata, handles)
5113set(handles.zoom,'Value',0)
5114zoom_Callback(handles.uvmat, [], handles)
5115UvData=get(handles.uvmat,'UserData');
5116UvData.MouseAction='ruler';
5117set(handles.uvmat,'UserData',UvData);
5118
Note: See TracBrowser for help on using the repository browser.