source: trunk/src/uvmat.m @ 74

Last change on this file since 74 was 74, checked in by sommeria, 14 years ago

rotate_points: used for geometry_calib was forgotten. It is now added
plot_field now does not consider black the vectors with either vec_F=0 or vec_F=1 (vec_F=0 in the 3D3C software instead of vec_F=1)
set_object and uvmat: improvements for projection plane in volume vel data

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