source: trunk/src/uvmat.m @ 71

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

civ3D updated: introduction of image size
imadoc2struct: reding of image size from the xml file
set_object, view_field and related functions: improvement of projection object editing
mouse: possibility of adjusting the calibrations points with the mouse

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