source: trunk/src/uvmat.m @ 156

Last change on this file since 156 was 155, checked in by sommeria, 13 years ago

many bug repairs and corrections for mouse action

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