source: trunk/src/uvmat.m @ 158

Last change on this file since 158 was 158, checked in by sommeria, 10 years ago

CoordType? not used, replaced by CoordUnit?
bug repair in check_field_structure

File size: 214.8 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    end
1531    errormsg=[];%default
1532    if mdetect==0
1533        [FileName, PathName, filterindex] = uigetfile( ...
1534            {'*.png', ' (*.png)';
1535            '*.png',  '.png files '; ...
1536            '*.*', 'All Files (*.*)'}, ...
1537            'Pick a mask file *.png',FileBase);
1538        maskname=fullfile(PathName,FileName);
1539        if ~exist(maskname,'file')
1540            errormsg='no file browsed';
1541        end
1542        [RootDir,RootFile,x1,x2,xa,xb,xext,Mask.NomType]=name2display(maskname);
1543        Mask.Base=fullfile(RootDir,RootFile);
1544        Mask.NbSlice=1;
1545        set(handles.mask_test,'UserData',Mask);
1546        set(handles.mask_test,'BackgroundColor',[1 1 0])
1547    end
1548    if isempty(errormsg)
1549        errormsg=update_mask(handles,num_i1,num_j1);
1550    end
1551    if ~isempty(errormsg)
1552            set(handles.mask_test,'Value',0)
1553            set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7])
1554     end
1555else
1556    MaskData=get(handles.mask_test,'UserData');
1557    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
1558          delete(MaskData.maskhandle)   
1559    end
1560    set(handles.mask_test,'UserData',[])   
1561    %huvmat=get(handles.mask_test,'parent');
1562    UvData=get(handles.uvmat,'UserData');
1563    if isfield(UvData,'MaskName')
1564        UvData=rmfield(UvData,'MaskName');
1565        set(handles.uvmat,'UserData',UvData)
1566    end
1567    set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7])
1568end
1569
1570%-------------------------------------------------------------------
1571function errormsg=update_mask(handles,num_i1,num_j1)
1572%-------------------------------------------------------------------
1573errormsg=[];%default
1574MaskData=get(handles.mask_test,'UserData');
1575if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1576    uistack(MaskData.maskhandle,'top');
1577end
1578num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1;
1579MaskData.NomType
1580MaskName=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType);
1581huvmat=get(handles.mask_test,'parent');
1582UvData=get(huvmat,'UserData');
1583
1584%update mask image if the mask is new
1585if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
1586    UvData.MaskName=MaskName; %update the recorded name on UvData
1587    set(huvmat,'UserData',UvData);
1588    if ~exist(MaskName,'file')
1589        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1590            delete(MaskData.maskhandle)   
1591        end
1592    else
1593        %read mask image
1594        Mask.AName='image';
1595        Mask.A=imread(MaskName);
1596        npxy=size(Mask.A);
1597        test_error=0;
1598        if length(npxy)>2
1599            errormsg=[MaskName ' is not a grey scale image'];
1600            return
1601        elseif ~isa(Mask.A,'uint8')
1602            errormsg=[MaskName ' is not a 8 bit grey level image'];
1603            return
1604        end
1605        Mask.AX=[0.5 npxy(2)-0.5];
1606        Mask.AY=[npxy(1)-0.5 0.5 ];
1607        Mask.CoordUnit='pixel';
1608        if isequal(get(handles.slices,'Value'),1)
1609           NbSlice=str2num(get(handles.nb_slice,'String'));
1610           num_i1=str2num(get(handles.i1,'String'));
1611           Mask.ZIndex=mod(num_i1-1,NbSlice)+1;
1612        end
1613        %px to phys or other transform on field
1614         menu_transform=get(handles.transform_fct,'String');
1615        choice_value=get(handles.transform_fct,'Value');
1616        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1617        transform_list=get(handles.transform_fct,'UserData');
1618        transform=transform_list{choice_value};
1619        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1620            if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1621                Calib=UvData.XmlData.GeometryCalib;
1622                Mask=transform(Mask,UvData.XmlData);
1623            end
1624        end
1625        flagmask=Mask.A < 200;
1626       
1627        %make brown color image
1628        imflag(:,:,1)=0.9*flagmask;
1629        imflag(:,:,2)=0.7*flagmask;
1630        imflag(:,:,3)=zeros(size(flagmask));
1631       
1632        %update mask image
1633        hmask=[]; %default
1634        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1635            hmask=MaskData.maskhandle;
1636        end
1637        if ~isempty(hmask)
1638            set(hmask,'CData',imflag)   
1639            set(hmask,'AlphaData',flagmask*0.6)
1640            set(hmask,'XData',Mask.AX);
1641            set(hmask,'YData',Mask.AY);
1642%             uistack(hmask,'top')
1643        else
1644            axes(handles.axes3)
1645            hold on   
1646            MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*flagmask);
1647%             set(MaskData.maskhandle,'AlphaData',0.6*flagmask)
1648            set(handles.mask_test,'UserData',MaskData)
1649        end
1650    end
1651end
1652
1653
1654%-------------------------------------------------------------------
1655function MenuExportFigure_Callback(hObject, eventdata, handles)
1656%-------------------------------------------------------------------
1657huvmat=get(handles.MenuExport,'parent');
1658%UvData=get(huvmat,'UserData');
1659hfig=figure;
1660copyobj(handles.axes3,hfig);
1661map=colormap(handles.axes3);
1662colormap(map);%transmit the current colormap to the zoom fig
1663colorbar
1664
1665%-------------------------------------------------------------------
1666%-------------------------------------------------------------------
1667% III - MAIN REFRESH FUNCTIONS : 'FRAME PLOT'
1668%-------------------------------------------------------------------
1669
1670%-------------------------------------------------------------------
1671% --- Executes on button press in runplus: make one step forward and call
1672% --- run0. The step forward is along the fields series 1 or 2 depending on
1673% --- the scan_i and scan_j check box (exclusive each other)
1674function runplus_Callback(hObject, eventdata, handles)
1675%-------------------------------------------------------------------
1676set(handles.runplus,'BackgroundColor',[1 1 0])%paint the command button in yellow
1677drawnow
1678%TODO: introduce the option: increment ='*' to move to the next available view
1679increment=str2double(get(handles.increment_scan,'String')); %get the field increment d
1680if isnan(increment)
1681    set(handles.increment_scan,'String','1')%default value
1682    increment=1;
1683end
1684errormsg=runpm(hObject,eventdata,handles,increment);
1685if ~isempty(errormsg)
1686    msgbox_uvmat('ERROR',errormsg);
1687end
1688set(handles.runplus,'BackgroundColor',[1 0 0])%paint the command button back to red
1689
1690%-------------------------------------------------------------------
1691% --- Executes on button press in runmin: make one step backward and call
1692% --- run0. The step backward is along the fields series 1 or 2 depending on
1693% --- the scan_i and scan_j check box (exclusive each other)
1694function runmin_Callback(hObject, eventdata, handles)
1695%-------------------------------------------------------------------
1696set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow
1697drawnow
1698increment=-str2double(get(handles.increment_scan,'String')); %get the field increment d
1699if isnan(increment)
1700    set(handles.increment_scan,'String','1')%default value
1701    increment=1;
1702end
1703errormsg=runpm(hObject,eventdata,handles,increment);
1704if ~isempty(errormsg)
1705    msgbox_uvmat('ERROR',errormsg);
1706end
1707set(handles.runmin,'BackgroundColor',[1 0 0])%paint the command button back to red
1708
1709%-------------------------------------------------------------------
1710% -- Executes on button press in Movie: make a series of +> steps
1711function Movie_Callback(hObject, eventdata, handles)
1712%------------------------------------------------------------------
1713set(handles.Movie,'BackgroundColor',[1 1 0])%paint the command button in yellow
1714drawnow
1715increment=str2double(get(handles.increment_scan,'String')); %get the field increment d
1716if isnan(increment)
1717    set(handles.increment_scan,'String','1')%default value
1718    increment=1;
1719end
1720set(handles.STOP,'Visible','on')
1721set(handles.speed,'Visible','on')
1722set(handles.speed_txt,'Visible','on')
1723set(handles.Movie,'BusyAction','queue')
1724UvData=get(handles.uvmat,'UserData');
1725
1726while get(handles.speed,'Value')~=0 && isequal(get(handles.Movie,'BusyAction'),'queue') % enable STOP command
1727        errormsg=runpm(hObject,eventdata,handles,increment);
1728        if ~isempty(errormsg)
1729            set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1730            return
1731        end
1732        pause(1.02-get(handles.speed,'Value'))% wait for next image
1733end
1734if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1735    UvData.aviobj=close(UvData.aviobj);
1736   set(handles.uvmat,'UserData',UvData);
1737end
1738set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1739
1740%-------------------------------------------------------------------
1741% -- Executes on button press in Movie: make a series of <- steps
1742function MovieBackward_Callback(hObject, eventdata, handles)
1743%------------------------------------------------------------------
1744set(handles.MovieBackward,'BackgroundColor',[1 1 0])%paint the command button in yellow
1745drawnow
1746increment=-str2double(get(handles.increment_scan,'String')); %get the field increment d
1747if isnan(increment)
1748    set(handles.increment_scan,'String','1')%default value
1749    increment=1;
1750end
1751set(handles.STOP,'Visible','on')
1752set(handles.speed,'Visible','on')
1753set(handles.speed_txt,'Visible','on')
1754set(handles.MovieBackward,'BusyAction','queue')
1755UvData=get(handles.uvmat,'UserData');
1756
1757while get(handles.speed,'Value')~=0 && isequal(get(handles.MovieBackward,'BusyAction'),'queue') % enable STOP command
1758        errormsg=runpm(hObject,eventdata,handles,increment);
1759        if ~isempty(errormsg)
1760            set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1761            return
1762        end
1763        pause(1.02-get(handles.speed,'Value'))% wait for next image
1764end
1765if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1766    UvData.aviobj=close(UvData.aviobj);
1767   set(handles.uvmat,'UserData',UvData);
1768end
1769set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1770
1771%-------------------------------------------------------------------
1772function STOP_Callback(hObject, eventdata, handles)
1773%-------------------------------------------------------------------
1774set(handles.movie_pair,'BusyAction','Cancel')
1775set(handles.movie_pair,'value',0)
1776set(handles.Movie,'BusyAction','Cancel')
1777set(handles.MovieBackward,'BusyAction','Cancel')
1778set(handles.MenuExportMovie,'BusyAction','Cancel')
1779set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1780set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1781set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1782
1783%------------------------------------------------------------------
1784function errormsg=runpm(hObject,eventdata,handles,increment)
1785%------------------------------------------------------------------
1786%check for mï¿œovie pair status
1787movie_status=get(handles.movie_pair,'Value');
1788if isequal(movie_status,1)
1789    STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
1790end
1791%read the data on the current input rootfile(s)
1792
1793[FileName,RootPath,filebase,FileIndices,FileExt,subdir]=read_file_boxes(handles);
1794NomType=get(handles.FileIndex,'UserData');
1795
1796num1=stra2num(get(handles.i1,'String'));
1797num2=stra2num(get(handles.i2,'String'));
1798num_a=stra2num(get(handles.j1,'String'));
1799num_b=stra2num(get(handles.j2,'String'));
1800
1801sub_value= get(handles.SubField,'Value');
1802if sub_value % a second input file has been entered
1803    [FileName_1,RootPath_1,filebase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
1804    [pp,ff,str1,str2,str_a,str_b]=name2display(FileIndices_1);
1805    num1_1=stra2num(str1);%current set of indices for the second field (may be set different than the main indices)
1806    num2_1=stra2num(str2);
1807    num_a_1=stra2num(str_a);
1808    num_b_1=stra2num(str_b);
1809    NomType_1=get(handles.FileIndex_1,'UserData');
1810else
1811    filename_1=[];
1812end   
1813
1814comp_input=get(handles.fix_pair,'Value');
1815
1816%case of scanning along the first direction (rootfile numbers)
1817if get(handles.scan_i,'Value')==1% case of scanning along index i   
1818     num1=num1+increment;
1819     num2=num2+increment;
1820     [filename,num1,num_a,num2,num_b]=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
1821     if sub_value% set the second field name and indices
1822        num1_1=num1_1+increment;
1823        num2_1=num2_1+increment;
1824        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
1825     end   
1826else % case of scanning along index j (burst numbers)
1827    num_a=num_a+increment;
1828    num_b=num_b+increment;
1829    [filename,num1,num_a,num2,num_b]=name_generator(filebase,num1,num_a,FileExt,NomType,comp_input,num2,num_b,subdir);
1830    if sub_value
1831        num_a_1=num_a_1+increment;
1832        num_b_1=num_b_1+increment;
1833        filename_1=name_generator(filebase_1,num1_1,num_a_1,FileExt_1,NomType_1,1,num2_1,num_b_1,SubDir_1);
1834    end   
1835end
1836
1837% refresh plots
1838errormsg=refresh_field(handles,filename,filename_1,num1,num2,num_a,num_b);
1839if isempty(errormsg)  %update the index counters
1840    set(handles.i1,'String',num2stra(num1,NomType,1));
1841    if isequal(num2,num1)
1842         set(handles.i2,'String','');
1843    else
1844        set(handles.i2,'String',num2stra(num2,NomType,1));
1845    end
1846    set(handles.j1,'String',num2stra(num_a,NomType,2));
1847    if isequal(num_b,num_a)
1848         set(handles.j2,'String','');
1849    else
1850        set(handles.j2,'String',num2stra(num_b,NomType,2));
1851    end
1852    [indices]=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
1853    set(handles.FileIndex,'String',indices);
1854    if ~isempty(filename_1)
1855         indices_1=name_generator('',num1_1,num_a_1,'',NomType_1,1,num2_1,num_b_1,'');
1856         set(handles.FileIndex_1,'String',indices_1);
1857    end
1858    if isequal(movie_status,1)
1859        set(handles.movie_pair,'Value',1)
1860        movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated
1861    end
1862end
1863
1864
1865%-------------------------------------------------------
1866% --- Executes on button press in movie_pair: create an alternating movie with two view
1867%-------------------------------------------------------
1868function movie_pair_Callback(hObject, eventdata, handles)
1869status=get(handles.movie_pair,'value');
1870if isequal(status,0)
1871    set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off'
1872    set(handles.i2,'String','')
1873    set(handles.j2,'String','')
1874    return
1875else
1876    set(handles.movie_pair,'BusyAction','queue')
1877end
1878%initialisation
1879set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
1880drawnow
1881list_fields=get(handles.Fields,'String');% list menu fields
1882index_fields=get(handles.Fields,'Value');% selected string index
1883FieldName=list_fields{index_fields}; % selected field
1884UvData=get(handles.uvmat,'UserData');
1885if isequal(FieldName,'image')
1886    test_1=0;
1887    [ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
1888    NomType=get(handles.FileIndex,'UserData');
1889else
1890    list_fields=get(handles.Fields_1,'String');% list menu fields
1891    index_fields=get(handles.Fields_1,'Value');% selected string index
1892    FieldName=list_fields{index_fields}; % selected field
1893    if isequal(FieldName,'image')
1894        test_1=1;
1895        [ff,rr,filebase,xx,Ext,SubDir]=read_file_boxes_1(handles);
1896        NomType=get(handles.FileIndex_1,'UserData');
1897    else
1898        msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
1899        set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1900        return
1901    end
1902end
1903
1904num_i1=str2double(get(handles.i1,'String'));
1905num_j1=stra2num(get(handles.j1,'String'));
1906num_i2=str2double(get(handles.i2,'String'));
1907num_j2=stra2num(get(handles.j2,'String'));
1908if isnan(num_j2)
1909    if isempty(num_i2)   
1910        msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
1911        set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1912        return
1913    else
1914        num_j2=num_j1;%repeat the index i1 by default
1915    end
1916end
1917if isnan(num_i2)
1918    num_i2=num_i1;%repeat the index i1 by default
1919end
1920imaname_1=name_generator(filebase,num_i2,num_j2,Ext,NomType);
1921if ~exist(imaname_1,'file')
1922      msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
1923      set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1924      return
1925end
1926
1927%read the second image
1928Field.AName='image';
1929if test_1
1930    Field_a=UvData.Field_1;
1931else
1932    Field_a=UvData.Field;
1933end
1934Field_b.AX=Field_a.AX;
1935Field_b.AY=Field_a.AY;
1936% z index
1937nbslice=str2double(get(handles.nb_slice,'String'));
1938if ~isempty(nbslice)
1939    Field_b.ZIndex=mod(num_i2-1,nbslice)+1;
1940end
1941Field_b.CoordUnit='pixel';
1942%determine the input file type
1943if (test_1 && isfield(UvData,'MovieObject_1'))||(~test_1 && isfield(UvData,'MovieObject'))
1944    FileType='movie';
1945elseif isequal(lower(Ext),'.avi')
1946    FileType='avi';
1947elseif isequal(lower(Ext),'.vol')
1948    FileType='vol';
1949else
1950   form=imformats(Ext(2:end));
1951   if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
1952       if isequal(NomType,'*');
1953           FileType='multimage';
1954       else
1955           FileType='image';
1956       end
1957   end
1958end
1959switch FileType
1960        case 'movie'
1961            if test_1
1962                Field_b.A=read(UvData.MovieObject_1,num_i2);
1963            else
1964                Field_b.A=read(UvData.MovieObject,num_i2);
1965            end
1966        case 'avi'
1967            mov=aviread(imaname_1,num_i2);
1968            Field_b.A=frame2im(mov(1));
1969        case 'vol'
1970            Field_b.A=imread(imaname_1);
1971        case 'multimage'
1972            Field_b.A=imread(imaname_1,num_i2);
1973        case 'image'
1974            Field_b.A=imread(imaname_1);
1975end
1976if get(handles.slices,'Value')
1977    Field.ZIndex=str2double(get(handles.z_index,'String'));
1978end
1979
1980%px to phys or other transform on field
1981menu_transform=get(handles.transform_fct,'String');
1982choice_value=get(handles.transform_fct,'Value');
1983transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1984transform_list=get(handles.transform_fct,'UserData');
1985transform=transform_list{choice_value};
1986if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1987    if test_1 && isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1988        Field_a=transform(Field_a,UvData.XmlData_1);%the first field has been stored without transform
1989        Field_b=transform(Field_b,UvData.XmlData_1);
1990    elseif ~test_1 && isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib
1991        Field_b=transform(Field_b,UvData.XmlData);
1992    end
1993end
1994
1995 % make movie until movie speed is set to 0 or STOP is activated
1996hima=findobj(handles.axes3,'Tag','ima');% %handles.axes3 =main plotting window (A GENERALISER)
1997set(handles.STOP,'Visible','on')
1998set(handles.speed,'Visible','on')
1999set(handles.speed_txt,'Visible','on')
2000while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue')%isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
2001    % read and plot the series of images in non erase mode
2002    set(hima,'CData',Field_b.A);
2003    pause(1.02-get(handles.speed,'Value'));% wait for next image
2004    set(hima,'CData',Field_a.A);
2005    pause(1.02-get(handles.speed,'Value'));% wait for next image
2006end
2007set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
2008
2009%------------------------------------------------------------------------
2010% --- Executes on button press in run0.
2011function run0_Callback(hObject, eventdata, handles)
2012%------------------------------------------------------------------------
2013set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
2014drawnow
2015filename=read_file_boxes(handles);
2016
2017filename_1=[];%default
2018if get(handles.SubField,'Value')
2019    filename_1=read_file_boxes_1(handles);
2020end
2021num_i1=stra2num(get(handles.i1,'String'));
2022num_i2=stra2num(get(handles.i2,'String'));
2023num_j1=stra2num(get(handles.j1,'String'));
2024num_j2=stra2num(get(handles.j2,'String'));
2025errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2);
2026if ~isempty(errormsg)
2027      msgbox_uvmat('ERROR',errormsg);
2028else
2029    set(handles.i1,'BackgroundColor',[1 1 1])
2030    set(handles.i2,'BackgroundColor',[1 1 1])
2031    set(handles.j1,'BackgroundColor',[1 1 1])
2032    set(handles.j2,'BackgroundColor',[1 1 1])
2033    set(handles.FileIndex,'BackgroundColor',[1 1 1])
2034    set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
2035end   
2036set(handles.run0,'BackgroundColor',[1 0 0])
2037
2038
2039%------------------------------------------------------------------------
2040% --- read the input files and refresh all the plots, including projection.
2041% OUTPUT:
2042%  errormsg: error message char string  =[] by default
2043% INPUT:
2044% filename: first input file (=[] in the absence of input file)
2045% filename_1: second input file (=[] in the asbsenc of secodn input file)
2046% num_i1,num_i2,num_j1,num_j2; frame indices
2047% Field: structure describing an optional input field (then replace the input file)
2048function errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,Field)
2049%------------------------------------------------------------------------
2050
2051%initialisation
2052% errormsg=[]; % default error message
2053abstime=[];
2054abstime_1=[];
2055dt=[];
2056if ~exist('Field','var')
2057    Field={};
2058end
2059UvData=get(handles.uvmat,'UserData');
2060%UvData =structure containing information stored outside the uicontrol of uvmat
2061%      .NewSeries: =1 for a new series (new root fiel introduced), 0 else
2062%      .MovieObject: movie object representing an input movie
2063%      .MovieObject_1: idem for a second input series (_1)
2064%      .filename_1 : last second input file name (to deal with a constant second input without reading again the file)
2065%      .VelType_1: last velocity type (civ1, civ2...) for the second input series
2066%      .FieldName_1: last field name(velocity, vorticity...) for the second input series
2067%      .NbDim: number of space dimensions of the input field
2068%      .ZMin, .ZMax: range of the z coordinate
2069%..... to complement
2070
2071if ishandle(handles.UVMAT_title) %remove title panel on uvmat
2072    delete(handles.UVMAT_title)
2073end
2074
2075%% determine the main input file information for action
2076FileType=[];%default
2077if ~isempty(filename)
2078    if ~exist(filename,'file')
2079        errormsg=['input file ' filename ' does not exist'];
2080        return
2081    end
2082    Ext=get(handles.FileExt,'String');
2083    NomType=get(handles.FileIndex,'UserData');
2084    %update the z position index
2085    nbslice_str=get(handles.nb_slice,'String');
2086   % z_index=1;%default
2087    if isequal(nbslice_str,'volume')
2088        z_index=num_j1;
2089        set(handles.z_index,'String',num2str(z_index))
2090    else
2091        nbslice=str2num(nbslice_str);
2092        z_index=mod(num_i1-1,nbslice)+1;
2093        set(handles.z_index,'String',num2str(z_index))
2094    end
2095    % refresh menu for save_mask if relevant
2096    masknumber=get(handles.masklevel,'String');
2097    if length(masknumber)>=z_index
2098        set(handles.masklevel,'Value',z_index)
2099    end
2100
2101    % determine the input file type
2102    if isequal(Ext,'.nc')||isequal(Ext,'.cdf')
2103        FileType='netcdf';
2104    elseif isfield(UvData,'MovieObject')
2105        FileType='movie';
2106        FieldName='image';
2107    elseif isequal(lower(Ext),'.avi')
2108        FileType='avi';
2109        FieldName='image';
2110    elseif isequal(lower(Ext),'.vol')
2111        FileType='vol';
2112        FieldName='image';
2113    else
2114       form=imformats(Ext(2:end));
2115       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2116           if isequal(NomType,'*');
2117               FileType='multimage';
2118           else
2119               FileType='image';
2120           end
2121           FieldName='image';
2122       end
2123    end
2124else
2125    FileType='netcdf';
2126    FieldName='get_field...';
2127end
2128VelType=[];%default
2129if isequal(FileType,'netcdf')
2130    list_fields=get(handles.Fields,'String');% list menu fields
2131    index_fields=get(handles.Fields,'Value');% selected string index
2132    FieldName= list_fields{index_fields}; % selected field
2133    if ~isequal(FieldName,'get_field...')% read the field names on the interface get_field...
2134       VelType=setfield(handles);
2135    end
2136end
2137%% choose a second field if Subfield option is 'on'
2138FieldName_1=[];
2139scal_color=[];
2140VelType_1=setfield_1(handles);
2141% sub_value=get(handles.SubField,'Value');
2142FileType_1='none';%default
2143if ~isempty(filename_1)
2144    % test for a constant second field (comparison with a fixed field)
2145    NomType_1=get(handles.FileIndex_1,'UserData');
2146    Ext_1=get(handles.FileExt_1,'String');
2147    % determine the input file type
2148    if isequal(Ext_1,'.nc')||isequal(Ext_1,'.cdf')
2149        FileType_1='netcdf';
2150    elseif isfield(UvData,'MovieObject_1')
2151        FileType_1='movie';
2152        FieldName_1='image';
2153    elseif isequal(lower(Ext_1),'.avi')
2154        FileType='avi';
2155        FieldName_1='image';
2156    elseif isequal(lower(Ext_1),'.vol')
2157        FileType_1='vol';
2158        FieldName_1='image';
2159    elseif length(Ext_1)>1
2160       form=imformats(Ext_1(2:end));
2161       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
2162           if isequal(NomType_1,'*');
2163               FileType_1='multimage';
2164           else
2165               FileType_1='image';
2166           end
2167           FieldName_1='image';
2168       end
2169    end
2170    if ~isequal(FieldName_1,'image')
2171        list_fields=get(handles.Fields_1,'String');% list menu fields
2172        index_fields=get(handles.Fields_1,'Value');% selected string index
2173        FieldName_1= list_fields{index_fields}; % selected field
2174        if isequal(VelType_1,'*')% free veltype choice
2175            VelType_1=[];
2176        elseif isequal(VelType_1,'"')% veltype the same as for the first field
2177            if isempty(VelType)
2178                VelType_1=[];
2179            else
2180                VelType_1=VelType;
2181            end
2182        end
2183    end
2184    test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged
2185    if ~isequal(NomType_1,'*')%in case of a series of files (not avi movie)
2186        if isfield(UvData,'filename_1')&& isfield(UvData,'VelType_1') && isfield(UvData,'FieldName_1')
2187            test_keepdata_1= isequal(filename_1,UvData.filename_1)&&...
2188                isequal(VelType_1,UvData.filename_1) && isequal(FieldName_1,UvData.FieldName_1);
2189        end
2190    end
2191    if test_keepdata_1
2192        Field{2}=UvData.Field_1;   
2193    elseif ~exist(filename_1,'file')
2194        errormsg=['second file ' filename_1 ' does not exist'];
2195        return
2196    end
2197end
2198
2199%% read the input field(s)
2200%read images
2201if ~isempty(filename) && isequal(FieldName,'image')
2202     switch FileType
2203        case 'movie'
2204            try
2205                A=read(UvData.MovieObject,num_i1);
2206            catch
2207                errormsg=lasterr;
2208                return
2209            end
2210        case 'avi'
2211            try
2212                mov=aviread(filename,num_i1);
2213            catch
2214                errormsg=lasterr;
2215                return
2216            end
2217            A=frame2im(mov(1));
2218        case 'vol'
2219            A=imread(filename);
2220        case 'multimage'
2221            A=imread(filename,num_i1);
2222        case 'image'
2223            A=imread(filename);
2224    end
2225    npxy=size(A);
2226    set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
2227    set(handles.npy,'String',num2str(npxy(1)));
2228    Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
2229    Rangy=[npxy(1)-0.5 0.5]; %
2230    Field{1}.AName='image';
2231    Field{1}.ListVarName={'AY','AX','A'}; %
2232    if size(A,3)==3;%color
2233        Field{1}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
2234    else
2235        Field{1}.VarDimName={'AY','AX',{'AY','AX'}}; %
2236    end
2237    Field{1}.AY=Rangy;
2238    Field{1}.AX=Rangx;
2239    Field{1}.A=A;
2240   % Field{1}.CoordType='px'; %used for mouse_motion
2241    Field{1}.CoordUnit='pixel'; %used for mouse_motion
2242end
2243
2244%read a second image
2245if  ~isempty(filename_1) && ~test_keepdata_1 && isequal(FieldName_1,'image')
2246    switch FileType_1
2247        case 'movie'
2248            A=read(UvData.MovieObject_1,num_i1);
2249        case 'avi'
2250            mov=aviread(filename_1,num_i1);
2251            A=frame2im(mov(1));
2252        case 'vol'
2253            A=imread(filename_1);
2254        case 'multimage'
2255            A=imread(filename_1,num_i1);
2256        case 'image'
2257            A=imread(filename_1);
2258        case 'netcdf'
2259        otherwise
2260            errormsg=['unknown input file type ' filename_1];
2261    end
2262    npxy=size(A);
2263    set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
2264    set(handles.npy,'String',num2str(npxy(1)));
2265    Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
2266    Rangy=[npxy(1)-0.5 0.5]; %
2267    Field{2}.AName='image';
2268    Field{2}.ListVarName={'AY','AX','A'}; %
2269    if size(A,3)==3;%color
2270        Field{2}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
2271    else
2272        Field{2}.VarDimName={'AY','AX',{'AY','AX'}}; %
2273    end
2274    Field{2}.AY=Rangy;
2275    Field{2}.AX=Rangx;
2276    Field{2}.A=A;
2277    Field{2}.CoordType='px'; %used for mouse_motion
2278    Field{2}.CoordUnit='px'; %used for move_mou
2279end
2280
2281%read ncfile(s)
2282CivStage_1=0;%default
2283VelType_out_1=[];
2284InputField={FieldName};
2285InputField_1={FieldName_1};
2286if (~isempty(filename)&& isequal(FileType,'netcdf')) || (~isempty(filename_1)&& isequal(FileType_1,'netcdf')) ;
2287    %read the velocity field(s) from netcdf rootfile(s)
2288    list_code=get(handles.col_vec,'String');% list menu fields
2289    index_code=get(handles.col_vec,'Value');% selected string index
2290    scal_color= list_code{index_code(1)}; % selected field
2291    if isequal(FieldName,'velocity')&& ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
2292        InputField=[InputField scal_color];
2293    end
2294    if isequal(FieldName_1,'velocity') && ~isequal(scal_color,'black') && ~isequal(scal_color,'white')
2295        InputField_1=[InputField_1 scal_color];
2296    end
2297    if isequal(FileType,'netcdf')  %read the first nc field
2298        if isequal(FieldName,'get_field...')% read the field names on the interface get_field.
2299            hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
2300            if isempty(hget_field)
2301                hget_field= get_field(filename);%open the get_field GUI   
2302              %  set(hget_field,'name','get_field')
2303            elseif UvData.NewSeries% refresh the fet_field GUI for a new series
2304                delete(hget_field)
2305                hget_field= get_field(filename);%open the get_field GUI
2306                set(hget_field,'name','get_field')%rename  get_field GUI for the 'slave' mode
2307            end
2308            hhget_field=guidata(hget_field);
2309            set(hhget_field.list_fig,'Value',1)
2310            set(hhget_field.list_fig,'String',{'uvmat'})
2311            funct_list=get(hhget_field.ACTION,'UserData');
2312            funct_index=get(hhget_field.ACTION,'Value');
2313            funct=funct_list{funct_index};%select  the current action in get_field, e;g. PLOT
2314            Field{1}=funct(hget_field); %%activate the current action selected in get_field, e;g.read the names of the variables to plot
2315            CivStage=0;
2316            VelType_out=[];   
2317        else
2318            [Field{1},VelType_out]=read_civxdata(filename,InputField,VelType);
2319            if isfield(Field{1},'Txt')
2320                errormsg=Field{1}.Txt;
2321                return
2322            end
2323            CivStage=Field{1}.CivStage;
2324            UvData.NbDim=Field{1}.nb_dim;
2325        end
2326    end
2327    if ~isempty(filename_1) && ~test_keepdata_1 && isequal(FileType_1,'netcdf') %read the second file
2328        if isequal(FieldName_1,'get_field...')% read the field names on the interface get_field.
2329            hget_field_1=findobj(allchild(0),'Name','get_field_1');%find the get_field... GUI
2330            if isempty(hget_field_1)
2331                 hget_field_1= get_field(filename_1);%open the get_field GUI
2332                 set(hget_field_1,'name','get_field_1')
2333            elseif UvData.NewSeries% refresh the fet_field GUI for a new series
2334                delete(hget_field_1)
2335                hget_field_1= get_field(filename);%open the get_field GUI
2336                set(hget_field_1,'name','get_field_1')%rename  get_field GUI for the 'slave' mode
2337            end
2338            hhget_field_1=guidata(hget_field_1);%handles of GUI elements in get_field
2339            set(hhget_field_1.list_fig,'Value',1)
2340            set(hhget_field_1.list_fig,'String',{'uvmat'})
2341            funct_list=get(hhget_field_1.ACTION,'UserData');
2342            funct_index=get(hhget_field_1.ACTION,'Value');
2343            funct=funct_list{funct_index};
2344            Field{2}=funct(hget_field_1); %read the names of the variables to plot in the get_field GUI
2345        else
2346            [Field{2},VelType_out_1]=read_civxdata(filename_1,InputField_1,VelType_1);
2347            CivStage_1=Field{2}.CivStage;
2348        end
2349        if ~isequal(FileType,'netcdf')
2350            VelType_out=VelType_out_1;
2351        end
2352    end
2353end
2354
2355%store the second field for possible latter use
2356if numel(Field)==2
2357    UvData.Field_1=Field{2};
2358end
2359
2360%% update the display buttons for the first velocity type (first menuline)
2361veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
2362if ~isequal(FileType,'netcdf')
2363    reset_vel_type(veltype_handles)
2364elseif isempty(VelType) && ~isequal(FieldName,'get_field...')
2365    set_veltype_display(veltype_handles,CivStage)%update the display of available velocity types for the first field
2366    if isempty(VelType_out)
2367        reset_vel_type(veltype_handles)
2368    else
2369        handle1=eval(['handles.' VelType_out]);
2370        reset_vel_type(veltype_handles,handle1)
2371    end
2372end
2373
2374%% update the display buttons for the second velocity type (second menuline)
2375veltype_handles_1=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
2376if ~isequal(FileType_1,'netcdf')
2377    reset_vel_type(veltype_handles_1)
2378elseif isempty(VelType_1) && ~isequal(FieldName_1,'get_field...')
2379    set_veltype_display(veltype_handles_1,CivStage_1)%update the display of available velocity types for the first field
2380    if isempty(VelType_out_1)
2381        reset_vel_type(veltype_handles_1)
2382    else
2383        handle1=eval(['handles.' VelType_out_1 '_1']);
2384        reset_vel_type(veltype_handles_1,handle1)
2385    end
2386end
2387
2388%% introduce w as background image by default for a new series (only for nbdim=2)
2389if ~isfield(UvData,'NewSeries')
2390    UvData.NewSeries=1;
2391end
2392%put W as background image by default if NbDim=2:
2393if ~isfield(UvData,'NbDim')||isempty(UvData.NbDim)||~isequal(UvData.NbDim,3)
2394    if UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W);
2395        set(handles.SubField,'Value',1);
2396        %menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
2397        set(handles.RootPath_1,'String','"')
2398        set(handles.RootFile_1,'String','"')
2399        set(handles.SubDir_1,'String','"');
2400        [indices]=name_generator('',num_i1,num_j1,'',NomType,1,num_i2,num_j2,'');
2401        set(handles.FileIndex_1,'String',indices)
2402        set(handles.FileExt_1,'String','"');
2403        set(handles.Fields_1,'Visible','on');
2404        set(handles.Fields_1,'Visible','on');
2405        set(handles.RootPath_1,'Visible','on')
2406        set(handles.RootFile_1,'Visible','on')
2407        set(handles.SubDir_1,'Visible','on');
2408        set(handles.FileIndex_1,'Visible','on');
2409        set(handles.FileExt_1,'Visible','on');
2410        set(handles.Fields_1,'Visible','on');
2411        Field{1}.AName='w';
2412%         testscal=1;
2413    end
2414end           
2415
2416%multislice case
2417if ~isempty(filename) &&(~isfield(UvData,'NbDim') || isequal(UvData.NbDim,2))&&...%2D case
2418      isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')&& isfield(UvData.XmlData.GeometryCalib,'SliceCoord')
2419       siz=size(UvData.XmlData.GeometryCalib.SliceCoord);
2420%        if siz(1)>1
2421%            NbSlice=siz(1);
2422%        else
2423%            NbSlice=1;
2424%        end
2425end
2426
2427%store the current open names, fields and vel types in uvmat interface
2428UvData.filename=filename;
2429UvData.filename_1=filename_1;
2430UvData.VelType=VelType;
2431UvData.VelType_1=VelType_1;
2432UvData.FieldName=FieldName;
2433UvData.FieldName_1=FieldName_1;
2434if ~isempty(scal_color)
2435    UvData.CName=scal_color;
2436end
2437
2438%% coordinate transform or user fct
2439XmlData=[];%default
2440if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
2441    XmlData=UvData.XmlData;
2442end
2443XmlData_1=[];%default
2444if isfield(UvData,'XmlData_1')
2445   XmlData_1=UvData.XmlData_1;
2446end
2447% menu_transform=get(handles.transform_fct,'String');
2448choice_value=get(handles.transform_fct,'Value');
2449transform_list=get(handles.transform_fct,'UserData');
2450transform=transform_list{choice_value};%selected function handles
2451% z index
2452if ~isempty(filename)
2453    Field{1}.ZIndex=z_index;
2454end
2455%px to phys or other transform on field
2456if ~isempty(transform)
2457    if length(Field)>=2
2458        Field{2}.ZIndex=z_index;
2459        [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
2460        if isempty(Field{2})
2461            Field(2)=[];
2462        end
2463    else
2464        Field{1}=transform(Field{1},XmlData);
2465    end
2466end
2467
2468%% calculate scalar
2469if isequal(FileType,'netcdf') && ~isequal(FieldName,'get_field...')%
2470    Field{1}=calc_field(InputField,Field{1});
2471end
2472if length(Field)==2 && ~test_keepdata_1 && isequal(FileType_1,'netcdf') && ~isequal(FieldName_1,'get_field...')
2473    Field{2}=calc_field(InputField_1,Field{2});
2474end
2475% combine the two input fields (e.g. substract velocity fields)
2476if numel(Field)==2
2477   UvData.Field=sub_field(Field{1},Field{2}); %TO UPDATE FOR MORE GENERAL INPUT 
2478else
2479   UvData.Field=Field{1};
2480end
2481
2482%% test 3D , default projection menuplane and typical mesh (needed to menuopen set_object)
2483test_x=0;
2484test_z=0;% test for unstructured z coordinate
2485UvData.ZMax=0;
2486UvData.ZMin=0;%default
2487%UvData.Mesh=1; %default
2488[UvData.Field,errormsg]=check_field_structure(UvData.Field);
2489if ~isempty(errormsg)
2490    errormsg=['error in uvmat/run0_Callback/check_field_structure: ' errormsg];
2491    return
2492end
2493[CellVarIndex,NbDim,VarType]=find_field_indices(UvData.Field);
2494[NbDim,imax]=max(NbDim);
2495if isempty(imax)
2496%    DimVarIndex=0;   
2497    coord_x=[];
2498else
2499%     VarIndex=CellVarIndex{imax};
2500    coord_x=VarType{imax}.coord_x;
2501end
2502if isfield(UvData,'NbDim') && ~isempty(UvData.NbDim)
2503    NbDim=UvData.NbDim;
2504else 
2505    UvData.NbDim=NbDim;
2506end
2507if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_x)  && ~isempty(VarType{imax}.coord_y)    %unstructured coordinate z
2508    XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
2509    YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
2510    test_x=1;
2511elseif isfield(UvData.Field,'X') && isfield(UvData.Field,'Y')
2512    XName='X';
2513    YName='Y';
2514    test_x=1;
2515end
2516if test_x
2517    eval(['UvData.XMax=max(UvData.Field.' XName ');'])
2518    eval(['UvData.XMin=min(UvData.Field.' XName ');'])
2519    eval(['UvData.YMax=max(UvData.Field.' YName ');'])
2520    eval(['UvData.YMin=min(UvData.Field.' YName ');'])
2521    eval(['nbvec=length(UvData.Field.' XName ');'])
2522    if NbDim==3%
2523        if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
2524            ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
2525            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
2526            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
2527            test_z=1;   
2528        elseif isfield(UvData,'Z')% usual civ data
2529            UvData.ZMax=max(UvData.Z);
2530            UvData.ZMin=min(UvData.Z);
2531            test_z=1;
2532        end
2533    end
2534    if isequal(UvData.ZMin,UvData.ZMax)%no z dependency
2535        NbDim=2;
2536        test_z=0;
2537    end   
2538    if test_z
2539         Field.Mesh=((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)*(UvData.ZMax-UvData.ZMin))/nbvec;% volume per vector
2540         Field.Mesh=(Field.Mesh)^(1/3);
2541    else
2542        Field.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/nbvec);%2D
2543    end
2544end
2545
2546%case of structured coordinates
2547'TESTfield'
2548UvData.Field
2549if isfield(UvData.Field,'AX') && isfield(UvData.Field,'AY')&& isfield(UvData.Field,'A')
2550    UvData.XMax=max(UvData.Field.AX);
2551    UvData.XMin=min(UvData.Field.AX);
2552    UvData.YMax=max(UvData.Field.AY);
2553    UvData.YMin=min(UvData.Field.AY);
2554    np_A=size(UvData.Field.A);
2555    Field.Mesh=sqrt((UvData.XMax-UvData.XMin)*(UvData.YMax-UvData.YMin)/((np_A(1)-1) * (np_A(2)-1))) ;
2556end
2557if  isempty(coord_x) && ~isempty(CellVarIndex)
2558    VarIndex=CellVarIndex{imax}; % list of variable indices
2559    DimIndex=UvData.Field.VarDimIndex{VarIndex(1)}; %list of dim indices for the variable
2560    if NbDim==3
2561        nbpoints=UvData.Field.DimValue(DimIndex(1));
2562        if isfield(VarType{imax},'coord_3')&& ~isequal(VarType{imax}.coord_3,0) % z is a dimension variable
2563            ZName=UvData.Field.ListVarName{VarType{imax}.coord_3};
2564            eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
2565            eval(['UvData.ZMin=min(UvData.Field.' ZName ');'])
2566        else
2567            testcoord_z=0;
2568            if length(UvData.Field.VarAttribute)>=VarIndex(1)
2569                if isfield(UvData.Field.VarAttribute{VarIndex(1)},'Coord_1')%regular grid
2570                    Coord_z=UvData.Field.VarAttribute{VarIndex(1)}.Coord_1;
2571                    UvData.ZMax=max(Coord_z);
2572                    UvData.ZMin=min(Coord_z);
2573                    testcoord_z=1;
2574                end
2575            end
2576            if ~testcoord_z
2577                  UvData.ZMin=1;
2578                  UvData.ZMax=UvData.Field.DimValue(DimIndex(1));
2579            end
2580        end
2581        Field.Mesh=(UvData.ZMax-UvData.ZMin)/(nbpoints-1);
2582    elseif NbDim==2
2583        nbpoints_y=UvData.Field.DimValue(DimIndex(1));       
2584        Yvar=VarType{imax}.coord_y;
2585        if Yvar~=0  % x is a dimension variable
2586            YName=UvData.Field.ListVarName{Yvar};
2587            eval(['UvData.YMax=max(UvData.Field.' YName ');'])
2588            eval(['UvData.YMin=min(UvData.Field.' YName ');'])
2589        else
2590            testcoord_y=0;
2591            if ~testcoord_y
2592                  UvData.YMin=1;
2593                  UvData.YMax=UvData.Field.DimValue(DimIndex(1));
2594            end
2595        end
2596        DY=(UvData.YMax-UvData.YMin)/(nbpoints_y-1);
2597        nbpoints_x=UvData.Field.DimValue(DimIndex(2));
2598        Xvar=VarType{imax}.coord_x;
2599        if Xvar~=0  % x is a dimension variable
2600            XName=UvData.Field.ListVarName{Xvar};
2601            eval(['UvData.XMax=max(UvData.Field.' XName ');'])
2602            eval(['UvData.XMin=min(UvData.Field.' XName ');'])
2603        else
2604            testcoord_x=0;
2605            if ~testcoord_x
2606                  UvData.XMin=1;
2607                  UvData.XMax=UvData.Field.DimValue(DimIndex(2));
2608            end
2609        end
2610        DX=(UvData.XMax-UvData.XMin)/(nbpoints_x-1);
2611        Field.Mesh= sqrt(DX*DY);
2612    end
2613end
2614
2615%create a default projection menuplane
2616UvData.Object{1}.Style='plane';%main plotting plane
2617UvData.Object{1}.ProjMode='projection';%main plotting plane
2618if ~isfield(UvData.Object{1},'plotaxes')
2619    UvData.Object{1}.plotaxes=handles.axes3;%default plotting axis
2620    set(handles.list_object_1,'Value',1);
2621    set(handles.list_object_1,'String',{'1-PLANE'}); 
2622end
2623
2624%3D case (menuvolume)
2625if NbDim==3 && UvData.NewSeries
2626    UvData.Object{1}.NbDim=UvData.NbDim;%test for 3D objects
2627    UvData.Object{1}.RangeZ=Field.Mesh;%main plotting plane
2628    UvData.Object{1}.Coord(1,3)=(UvData.ZMin+UvData.ZMax)/2;%section at a middle plane chosen
2629    UvData.Object{1}.Phi=0;
2630    UvData.Object{1}.Theta=0;
2631    UvData.Object{1}.Psi=0;
2632    UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR 
2633    PlotHandles=get_plot_handles(handles);
2634    ZBounds(1)=UvData.ZMin; %minimum for the Z slider
2635    ZBounds(2)=UvData.ZMax;%maximum for the Z slider
2636    UvData.Object{1}.Name='1-PLANE';
2637    UvData.Object{1}.enable_plot=1;
2638    set_object(UvData.Object{1},PlotHandles,ZBounds);
2639    set(handles.list_object_1,'Value',1);
2640%multilevel case (single menuplane in a 3D space)
2641elseif isfield(UvData,'Z')
2642    if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData')
2643        XmlData=UvData.XmlData;
2644        if isfield(XmlData,'PlanePos')
2645             UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
2646        end
2647        if isfield(XmlData,'PlaneAngle')
2648            siz=size(XmlData.PlaneAngle);
2649            indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)             
2650            UvData.Object{1}.Phi=XmlData.PlaneAngle(indangle,1);
2651            UvData.Object{1}.Theta=XmlData.PlaneAngle(indangle,2);
2652            UvData.Object{1}.Psi=XmlData.PlaneAngle(indangle,3);
2653        end
2654    elseif isfield(UvData,'ZIndex')
2655        UvData.Object{1}.ZObject=UvData.ZIndex;
2656    end
2657end
2658
2659%% reset the min and max of scalar if only the mask is displayed(TODO: check the need)
2660if isfield(UvData,'Mask')&& ~isfield(UvData,'A')
2661    set(handles.MinA,'String','0')
2662    set(handles.MaxA,'String','255')
2663end
2664
2665%% Plot the projections on the selected  projection objects
2666
2667% main projection object (uvmat display)
2668IndexObj(1)=get(handles.list_object_1,'Value');%selected projection object for main view
2669if IndexObj(1)> numel(UvData.Object)
2670    IndexObj(1)=1;%select the first object if the selected one does not exist
2671    set(handles.list_object_1,'Value',1)
2672end
2673plot_handles{1}=handles;
2674haxes(1)=handles.axes3;
2675PlotParam{1}=read_plot_param(handles);%read plotting parameters on the uvmat interfac
2676keeplim(1)=get(handles.FixedLimits,'Value');% test for fixed graph limits
2677PosColorbar{1}=UvData.PosColorbar;%prescribe the colorbar position on the uvmat interface
2678
2679% second projection object (view_field display)
2680IndexObj_2=get(handles.list_object_2,'Value');%selected projection object for the second view
2681if isequal(get(handles.list_object_2,'Visible'),'on') && IndexObj_2 <= numel(UvData.Object)&& ~isempty(UvData.Object{IndexObj_2})
2682    UvData.Object{IndexObj_2}
2683    IndexObj(2)=IndexObj_2;
2684    view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
2685    if ~isempty(view_field_handle)
2686        plot_handles{2}=guidata(view_field_handle);
2687        haxes(2)=plot_handles{2}.axes3;
2688        PlotParam{2}=read_plot_param(plot_handles{2});%read plotting parameters on the uvmat interface
2689        keeplim(2)=get(plot_handles{2}.FixedLimits,'Value');
2690        PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
2691    end
2692end
2693
2694%loop on the projection objects: one or two
2695for imap=1:numel(IndexObj)
2696    iobj=IndexObj(imap);   
2697    [ObjectData,errormsg]=proj_field(UvData.Field,UvData.Object{iobj});% project field on the object
2698    if ~isempty(errormsg)
2699        return
2700    end
2701    %use of mask (TODO: check)
2702    if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A')
2703        flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2704        AX=ObjectData.AX;%x coordiantes for the scalar field
2705        AY=ObjectData.AY;%y coordinates for the scalar field
2706        MaskX=ObjectData.MaskX;%x coordiantes for the mask
2707        MaskY=ObjectData.MaskY;%y coordiantes for the mask
2708        if ~isequal(MaskX,AX)||~isequal(MaskY,AY)
2709            nxy=size(flag_mask);
2710            sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2711            sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2712            x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display
2713            y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display
2714            %project on the positions of the scalar
2715            npxy=size(ObjectData.A);
2716            dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2717            dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2718            xi=ObjectData.AX(1):dxy(2):ObjectData.AX(end);
2719            yi=ObjectData.AY(1):dxy(1):ObjectData.AY(end);
2720            [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2721            flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2722        end
2723        AClass=class(ObjectData.A);
2724        ObjectData.A=flag_mask.*double(ObjectData.A);
2725        ObjectData.A=feval(AClass,ObjectData.A);
2726        ind_off=[];
2727        if isfield(ObjectData,'ListVarName')
2728            for ilist=1:length(ObjectData.ListVarName)
2729                if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY')
2730                    ind_off=[ind_off ilist];
2731                end
2732            end
2733            ObjectData.ListVarName(ind_off)=[];
2734            ObjectData.VarDimIndex(ind_off)=[];
2735            ind_off=[];
2736            for ilist=1:length(ObjectData.ListDimName)
2737                if isequal(ObjectData.ListDimName{ilist},'MaskX') || isequal(ObjectData.ListDimName{ilist},'MaskY')
2738                    ind_off=[ind_off ilist];
2739                end
2740            end
2741            ObjectData.ListDimName(ind_off)=[];
2742            ObjectData.DimValue(ind_off)=[];
2743        end
2744    end
2745   
2746    if ~isempty(ObjectData)
2747        PlotType='none'; %default
2748        if imap==2 && isempty(view_field_handle)
2749            view_field(ObjectData)
2750        else
2751            [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap},keeplim(imap),PosColorbar{imap});
2752            write_plot_param(plot_handles{imap},PlotParamOut) %update the auto plot parameters
2753            if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
2754                ObjectData.Mesh=Field.Mesh; % gives an estimated mesh size (useful for mouse action on the plot)
2755            end
2756            if imap==1           
2757                UvData.axes3=ObjectData;
2758            else
2759                ViewFieldData=get(view_field_handle,'UserData');
2760                ViewFieldData.axes3=ObjectData;
2761                set(view_field_handle,'UserData',ViewFieldData)
2762            end
2763        end
2764        if isequal(PlotType,'none')
2765            hget_field=findobj(allchild(0),'name','get_field');
2766            if isempty(hget_field)
2767                get_field([],ObjectData)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
2768            else
2769                errormsg='The field defined by get_field cannot be plotted';
2770                return
2771            end
2772        end
2773    end
2774end
2775
2776%write_plot_param(handles,UvData.Object{1}.PlotParam);% update the display of the plotting parameters
2777UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
2778set(handles.uvmat,'UserData',UvData)
2779
2780%% update the mask
2781if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
2782   update_mask(handles,num_i1,num_i2);
2783end
2784
2785%% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case)
2786menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display
2787ind_bad=[];
2788nb_histo=1;
2789
2790% suppress coordinates from the histogram menu
2791for ivar=1:numel(menu_histo)%l loop on field variables:
2792    if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2793        Role=UvData.Field.VarAttribute{ivar}.Role;
2794        switch Role
2795            case {'coord_x','coord_y','coord_z','dimvar'}
2796                ind_bad=[ind_bad ivar];
2797            case {'vector_y'}
2798                nb_histo=nb_histo+1;
2799        end
2800    end
2801    DimCell=UvData.Field.VarDimName{ivar};
2802    DimName='';
2803    if ischar(DimCell)
2804        DimName=DimCell;
2805    elseif iscell(DimCell)&& numel(DimCell)==1
2806        DimName=DimCell{1};
2807    end
2808    if strcmp(DimName,menu_histo{ivar})
2809        ind_bad=[ind_bad ivar];
2810    end
2811end
2812menu_histo(ind_bad)=[];
2813
2814%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2815% display menus and plot histograms
2816test_v=0;
2817if ~isempty(menu_histo)
2818    set(handles.histo1_menu,'Value',1)
2819    set(handles.histo1_menu,'String',menu_histo)
2820    histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram
2821    % case of more than one variables (eg vector components)
2822    if nb_histo > 1
2823        test_v=1;
2824        set(handles.histo2_menu,'Visible','on')
2825        set(handles.histo_v,'Visible','on')
2826        set(handles.histo2_menu,'String',menu_histo)
2827        set(handles.histo2_menu,'Value',2)
2828        histo2_menu_Callback(handles.histo2_menu,[], handles)% plot second histogram
2829    end
2830end
2831if ~test_v
2832    set(handles.histo2_menu,'Visible','off')
2833    set(handles.histo_v,'Visible','off')
2834    cla(handles.histo_v)
2835    set(handles.histo2_menu,'Value',1)
2836end
2837%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2838
2839%% display time
2840testimedoc=0;
2841if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'Time')
2842    if isempty(num_i2)||isnan(num_i2)
2843        num_i2=num_i1;
2844    end
2845    if isempty(num_j1)||isnan(num_j1)
2846        num_j1=1;
2847    end
2848    if isempty(num_j2)||isnan(num_j2)
2849        num_j2=num_j1;
2850    end
2851    siz=size(UvData.XmlData.Time);
2852    if siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2)
2853        abstime=(UvData.XmlData.Time(num_i1,num_j1)+UvData.XmlData.Time(num_i2,num_j2))/2;%overset the time read from files
2854        dt=(UvData.XmlData.Time(num_i2,num_j2)-UvData.XmlData.Time(num_i1,num_j1));
2855        testimedoc=1;
2856    end
2857end
2858if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
2859    [P,F,str1,str2,str_a,str_b,E]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
2860    num_i2=str2double(str2);
2861    if isnan(num_i2)
2862        num_i2=num_i1;
2863    end
2864    num_j1=str2double(str_a);
2865    if isnan(num_j1)
2866        num_j1=1;
2867    end
2868    num_j2=str2double(str_b);
2869    if isnan(num_j2)
2870        num_j2=num_j1;
2871    end
2872    num_i1=str2double(str1);
2873    siz=size(UvData.XmlData_1.Time);
2874    if siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2)
2875        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
2876    end
2877end
2878set(handles.abs_time,'String',num2str(abstime,4))
2879set(handles.abs_time_1,'String',num2str(abstime_1,4))
2880if testimedoc && isfield(UvData,'dt')
2881    dt=UvData.dt;
2882end
2883if isempty(dt)||isequal(dt,0)
2884    set(handles.Dt_txt,'String','')
2885else
2886    if ~(isfield(UvData,'TimeUnit') && ~isempty(UvData.TimeUnit))
2887        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2888    else
2889        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
2890    end
2891end
2892
2893%% update the input file name in the get_field GUI
2894if isequal(FieldName,'get_field...')
2895    set(hhget_field.inputfile,'String',filename)
2896    Tabchar={''};%default
2897    Tabcell=[];
2898    if isfield(Field{1},'ListGlobalAttribute')&& ~isempty(Field{1}.ListGlobalAttribute)
2899        for iline=1:length(Field{1}.ListGlobalAttribute)
2900            Tabcell{iline,1}=Field{1}.ListGlobalAttribute{iline};
2901            if isfield(Field{1}, Field{1}.ListGlobalAttribute{iline})
2902                eval(['val=Field{1}.' Field{1}.ListGlobalAttribute{iline} ';'])
2903                if ischar(val);
2904                    Tabcell{iline,2}=val;
2905                else
2906                    Tabcell{iline,2}=num2str(val);
2907                end
2908            end
2909        end
2910        if ~isempty(Tabcell)
2911            Tabchar=cell2tab(Tabcell,'=');
2912            Tabchar=[{''};Tabchar];
2913        end
2914    end
2915    set(hhget_field.attributes,'String',Tabchar);%update list of global attributes in get_field
2916end
2917if isequal(FieldName_1,'get_field...')
2918    set(hhget_field_1.inputfile,'String',filename_1)
2919    Tabchar={''};%default
2920    Tabcell=[];
2921    if isfield(Field{2},'ListGlobalAttribute')&& ~isempty(Field{2}.ListGlobalAttribute)
2922        for iline=1:length(Field{2}.ListGlobalAttribute)
2923            Tabcell{iline,1}=Field{2}.ListGlobalAttribute{iline};
2924            if isfield(Field{2}, Field{2}.ListGlobalAttribute{iline})
2925                eval(['val=Field{2}.' Field{2}.ListGlobalAttribute{iline} ';'])
2926                if ischar(val);
2927                    Tabcell{iline,2}=val;
2928                else
2929                    Tabcell{iline,2}=num2str(val);
2930                end
2931            end
2932        end
2933        if ~isempty(Tabcell)
2934            Tabchar=cell2tab(Tabcell,'=');
2935            Tabchar=[{''};Tabchar];
2936        end
2937    end
2938    set(hhget_field_1.attributes,'String',Tabchar);%update list of global attributes in get_field
2939end
2940
2941
2942%-------------------------------------------------------------------
2943% --- translate coordinate to matrix index
2944%-------------------------------------------------------------------
2945function [indx,indy]=pos2ind(x0,rangx0,nxy)
2946indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
2947indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2948
2949%-------------------------------------------------------------------
2950% --- Executes on button press in 'FixedLimits'.
2951%-------------------------------------------------------------------
2952function FixedLimits_Callback(hObject, eventdata, handles)
2953test=get(handles.FixedLimits,'Value');
2954if test
2955    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2956else
2957    set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
2958    update_plot(handles);
2959end
2960
2961%-------------------------------------------------------------------
2962% --- Executes on button press in auto_xy.
2963function auto_xy_Callback(hObject, eventdata, handles)
2964test=get(handles.auto_xy,'Value');
2965if test
2966    set(handles.auto_xy,'BackgroundColor',[1 1 0])
2967    cla(handles.axes3)
2968    update_plot(handles);
2969else
2970    set(handles.auto_xy,'BackgroundColor',[0.7 0.7 0.7])
2971    update_plot(handles);
2972%     axis(handles.axes3,'image')
2973end
2974
2975
2976%-------------------------------------------------------------------
2977
2978%-------------------------------------------------------------------
2979% --- Executes on button press in 'zoom'.
2980%-------------------------------------------------------------------
2981function zoom_Callback(hObject, eventdata, handles)
2982
2983if (get(handles.zoom,'Value') == 1);
2984    set(handles.zoom,'BackgroundColor',[1 1 0])
2985    set(handles.FixedLimits,'Value',1)% propose by default fixed limits for the plotting axes
2986    set(handles.FixedLimits,'BackgroundColor',[1 1 0])
2987else
2988    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
2989end
2990
2991
2992%-------------------------------------------------------------------
2993%----Executes on button press in 'record': records the current flags of manual correction.
2994%-------------------------------------------------------------------
2995function record_Callback(hObject, eventdata, handles)
2996% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
2997filename=read_file_boxes(handles);
2998[erread,message]=fileattrib(filename);
2999if ~isempty(message) && ~isequal(message.UserWrite,1)
3000     msgbox_uvmat('ERROR',['no writting access to ' filename])
3001     return
3002end
3003test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
3004test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
3005if ~test_civ2 && ~test_civ1
3006    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3007end
3008if test_civ2
3009    nbname='nb_vectors2';
3010   flagname='vec2_FixFlag';
3011   attrname='fix2';
3012end
3013if test_civ1
3014    nbname='nb_vectors';
3015   flagname='vec_FixFlag';
3016   attrname='fix';
3017end
3018%write fix flags in the netcdf file
3019UvData=get(handles.uvmat,'UserData');
3020hhh=which('netcdf.open');% look for built-in matlab netcdf library
3021if ~isequal(hhh,'')% case of new builtin Matlab netcdf library
3022    nc=netcdf.open(filename,'NC_WRITE');
3023    netcdf.reDef(nc)
3024    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1)
3025    dimid = netcdf.inqDimID(nc,nbname);
3026    try
3027        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
3028    catch
3029        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
3030    end
3031    netcdf.endDef(nc)
3032    netcdf.putVar(nc,varid,UvData.axes3.FF);
3033    netcdf.close(nc) 
3034else %old netcdf library
3035    netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
3036end
3037
3038%-------------------------------------------------------------------
3039%----Correct the netcdf file, using toolbox (old versions of Matlab).
3040%-------------------------------------------------------------------
3041function netcdf_toolbox(filename,AxeData,attrname,nbname,flagname)
3042nc=netcdf(filename,'write'); %open netcdf file
3043result=redef(nc);
3044eval(['nc.' attrname '=1;']);
3045theDim=nc(nbname) ;% get the number of velocity vectors
3046nb_vectors=size(theDim);
3047var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
3048var_FixFlag(1:nb_vectors)=AxeData.FF;%
3049fin=close(nc);
3050
3051
3052%-------------------------------------------------------------------
3053%determines the fields to read from the interface
3054%------------------------------------------------------------------
3055function [VelType,civ]=setfield(handles)
3056
3057VelType=[]; %default
3058if (get(handles.civ1,'Value') == 1);
3059        VelType='civ1';
3060% interp1   
3061elseif (get(handles.interp1,'Value') == 1);
3062    VelType='interp1';
3063% filter1   
3064elseif (get(handles.filter1,'Value') == 1);
3065    VelType='filter1'; 
3066% CIV2
3067elseif (get(handles.civ2,'Value') == 1);
3068    VelType='civ2';
3069% interp2   
3070elseif (get(handles.interp2,'Value') == 1);
3071    VelType='interp2';
3072% filter2   
3073elseif (get(handles.filter2,'Value') == 1); 
3074    VelType='filter2';
3075end
3076
3077if isequal(get(handles.filter2,'Visible'),'on');
3078    civ=6;
3079% interp1   
3080elseif isequal(get(handles.interp2,'Visible'),'on');
3081    civ=5;
3082% filter1   
3083elseif isequal(get(handles.civ2,'Visible'),'on');
3084    civ=4; 
3085% CIV2
3086elseif isequal(get(handles.filter1,'Visible'),'on');
3087   civ=3;
3088% interp2   
3089elseif isequal(get(handles.interp1,'Visible'),'on');
3090    civ=2;
3091% filter2   
3092elseif isequal(get(handles.civ1,'Visible'),'on'); 
3093    civ=1;
3094else
3095    civ=0;
3096end
3097
3098%-------------------------------------------------------------------
3099%determines the veltype of the second field to read from the iinterface
3100%------------------------------------------------------------------
3101function VelType=setfield_1(handles)
3102
3103VelType=[]; %default
3104if (get(handles.civ1_1,'Value') == 1);
3105    VelType='civ1';
3106% interp1   
3107elseif (get(handles.interp1_1,'Value') == 1);
3108    VelType='interp1';
3109% filter1   
3110elseif (get(handles.filter1_1,'Value') == 1);
3111    VelType='filter1'; 
3112% CIV2
3113elseif (get(handles.civ2_1,'Value') == 1);
3114    VelType='civ2';
3115% interp2   
3116elseif (get(handles.interp2_1,'Value') == 1);
3117    VelType='interp2';
3118% filter2   
3119elseif (get(handles.filter2_1,'Value') == 1); 
3120    VelType='filter2';
3121end
3122
3123
3124%---------------------------------------------------
3125% --- Executes on button press in SubField
3126function SubField_Callback(hObject, eventdata, handles)
3127huvmat=get(handles.run0,'parent');
3128UvData=get(huvmat,'UserData');
3129if get(handles.SubField,'Value')==0% if the subfield button is desactivated   
3130    set(handles.RootPath_1,'String','')
3131    set(handles.RootFile_1,'String','')
3132    set(handles.SubDir_1,'String','');
3133    set(handles.FileIndex_1,'String','');
3134    set(handles.FileExt_1,'String','');
3135    set(handles.RootPath_1,'Visible','off')
3136    set(handles.RootFile_1,'Visible','off')
3137    set(handles.SubDir_1,'Visible','off');
3138    set(handles.FileIndex_1,'Visible','off');
3139    set(handles.FileExt_1,'Visible','off');
3140    set(handles.Fields_1,'Value',1);%set to blank state
3141    set_veltype_display([handles.civ1_1 handles.interp1_1 handles.filter1_1 ...
3142            handles.civ2_1 handles.interp2_1 handles.filter2_1],0)
3143    if isfield(UvData,'XmlData_1')
3144        UvData=rmfield(UvData,'XmlData_1');
3145    end
3146    set(huvmat,'UserData',UvData);
3147    run0_Callback(hObject, eventdata, handles); %run
3148else
3149    MenuBrowse_1_Callback(hObject, eventdata, handles)
3150end
3151
3152%------------------------------------------------------------------------
3153% --- read the data displayed for the input rootfile windows (new)
3154function [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles)
3155%------------------------------------------------------------------------
3156RootPath=get(handles.RootPath,'String');
3157FileName=RootPath; %default
3158SubDir=get(handles.SubDir,'String');
3159if ~isempty(SubDir) && ~isequal(SubDir,'')
3160    if (isequal(SubDir(1),'/')|| isequal(SubDir(1),'\'))
3161        SubDir(1)=[]; %suppress possible / or \ separator
3162    end
3163    FileName=fullfile(RootPath,SubDir);
3164end
3165RootFile=get(handles.RootFile,'String');
3166if ~isempty(RootFile) && ~isequal(RootFile,'')
3167    if (isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
3168        RootFile(1)=[]; %suppress possible / or \ separator
3169    end
3170    FileName=fullfile(FileName,RootFile);
3171end
3172FileBase=fullfile(RootPath,RootFile);
3173FileIndices=get(handles.FileIndex,'String');
3174FileExt=get(handles.FileExt,'String');
3175FileName=[FileName FileIndices FileExt];
3176
3177%------------------------------------------------------------------------
3178% ---- read the data displayed for the second input rootfile windows
3179function [FileName_1,RootPath_1,FileBase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles)
3180%------------------------------------------------------------------------
3181RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
3182if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"')
3183    RootPath_1=get(handles.RootPath,'String');
3184end;
3185FileName_1=RootPath_1; %default
3186SubDir_1=get(handles.SubDir_1,'String');
3187if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"')
3188    SubDir_1=get(handles.SubDir,'String');
3189end
3190if numel(SubDir_1)>=1
3191    if (isequal(SubDir_1(1),'/')|| isequal(SubDir_1(1),'\'))
3192        SubDir_1(1)=[]; %suppress possible / or \ separator
3193    end
3194    FileName_1=fullfile(RootPath_1,SubDir_1);
3195end
3196RootFile_1=get(handles.RootFile_1,'String');
3197if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"')
3198    RootFile_1=get(handles.RootFile,'String');
3199end
3200if numel(RootFile_1)>=1
3201    if ~(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
3202        RootFile_1(1)=[];%suppress possible / or \ separator
3203    end
3204    FileName_1=fullfile(FileName_1,RootFile_1);
3205end
3206FileBase_1=fullfile(RootPath_1,RootFile_1);
3207if isequal(get(handles.FileIndex_1,'Visible'),'off')
3208    FileIndices_1=get(handles.FileIndex,'String');
3209else
3210    FileIndices_1=get(handles.FileIndex_1,'String');
3211end
3212FileExt_1=get(handles.FileExt_1,'String');
3213if isequal(FileExt_1,'"'),FileExt_1=get(handles.FileExt,'String'); end;
3214FileName_1=[FileName_1 FileIndices_1 FileExt_1];
3215
3216%------------------------------------------------------------------------
3217% --- Executes on menu selection Fields
3218function Fields_Callback(hObject, eventdata, handles)
3219%------------------------------------------------------------------------
3220list_fields=get(handles.Fields,'String');% list menu fields
3221index_fields=get(handles.Fields,'Value');% selected string index
3222field= list_fields{index_fields(1)}; % selected string
3223if isequal(field,'get_field...')
3224     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3225     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3226     filename=read_file_boxes(handles);
3227     hget_field=findobj(allchild(0),'name','get_field');
3228     if ~isempty(hget_field)
3229         delete(hget_field)
3230     end
3231     hget_field=get_field(filename);
3232     set(hget_field,'Name','get_field')       
3233     hhget_field=guidata(hget_field);
3234     set(hhget_field.list_fig,'Value',1)
3235     set(hhget_field.list_fig,'String',{'uvmat'})
3236     set(handles.transform_fct,'Value',1)% no transform by default
3237     set(handles.path_transform,'String','')
3238    return %no action
3239end
3240list_fields=get(handles.Fields_1,'String');% list menu fields
3241index_fields=get(handles.Fields_1,'Value');% selected string index
3242field_1= list_fields{index_fields(1)}; % selected string
3243UvData=get(handles.uvmat,'UserData');
3244
3245%read the rootfile input display
3246[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
3247[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
3248NomTypeNew=NomType;%default
3249if isequal(field,'image')
3250    % transform netc type to the corresponding image type
3251%     if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')|| isequal(NomType,'#_ab')|| isequal(NomType,'_i1-i2')
3252%         UvData.SubDir=get(handles.SubDir,'String'); %preserve the subdir in memory
3253%         if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')||isequal(UvData.SubDir(1),'/'))
3254%             UvData.SubDir(1)=[];
3255%         end
3256%         set(handles.SubDir,'String','')
3257%         set(handles.FileExt,'String','.png');
3258        if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')
3259            NomTypeNew='_i_j';
3260        elseif isequal(NomType,'#_ab')
3261            NomTypeNew='#a';
3262        elseif isequal(NomType,'_i1-i2')
3263            NomTypeNew='_i';
3264        end 
3265        imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3266        if ~exist(imagename,'file')
3267                [FileName,PathName] = uigetfile( ...
3268           {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3269            '*.jpg',' jpeg image files'; ...
3270            '*.png','.png image files'; ...
3271            '*.tif','.tif image files'; ...
3272            '*.avi;*.AVI','.avi movie files'; ...
3273            '*.vol','.volume images (png)'; ...
3274            '*.*',  'All Files (*.*)'}, ...
3275            'Pick an image',imagename);           
3276            % display the selected field and related information
3277           imagename=[PathName FileName];
3278        end
3279        display_file_name(hObject, eventdata, handles,imagename)%display the image
3280        return
3281%     end
3282%     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3283%     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3284else
3285    ext=get(handles.FileExt,'String');
3286    if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
3287                [FileName,PathName] = uigetfile( ...
3288           {'*.nc', ' (*.nc)';
3289            '*.nc',' netcdf files'; ...
3290            '*.*',  'All Files (*.*)'}, ...
3291            'Pick a netcdf file',FileBase);           
3292            % display the selected field and related information
3293           filename=[PathName FileName];
3294        display_file_name(hObject, eventdata, handles,filename)
3295        return
3296       %  MenuBrowse_Callback(hObject, eventdata, handles)
3297    end
3298    if isequal(field,'vort') || isequal(field,'div') || isequal(field,'strain')
3299        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3300        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
3301        set(handles.interp1,'BackgroundColor',[0.702 0.702 0.702])
3302        set(handles.interp2,'BackgroundColor',[0.702 0.702 0.702])
3303    elseif isequal(field,'more...');
3304        set(handles.civ1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3305        set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
3306        str=calc_field;%get the list of available scalars by the function calc_scal
3307        [ind_answer] = listdlg('PromptString','Select a file:',...
3308                'SelectionMode','single',...
3309                'ListString',str);
3310       % edit the choice in the field and action menu
3311        scalar=cell2mat(str(ind_answer));
3312        menu=update_menu(handles.Fields,scalar);
3313        menu=[{''};menu];
3314        set(handles.Fields_1,'String',menu);% store the selected scalar type
3315    end
3316end
3317indices=name_generator('',str2double(str1),str2double(str_a),'',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3318set(handles.FileIndex,'String',indices)
3319set(handles.FileIndex,'UserData',NomTypeNew)
3320%common to Fields_1_Callback
3321if isequal(field,'image')||isequal(field_1,'image')
3322    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3323    set(handles.npy_title,'Visible','on')
3324    set(handles.npx,'Visible','on')
3325    set(handles.npy,'Visible','on')
3326else
3327    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3328    set(handles.npy_title,'Visible','off')
3329    set(handles.npx,'Visible','off')
3330    set(handles.npy,'Visible','off')
3331end
3332setfield(handles);% update the field structure ('civ1'....)
3333
3334if ~isfield(UvData,'NewSeries')||isequal(UvData.NewSeries,0)
3335    run0_Callback(hObject, eventdata, handles)
3336end
3337
3338%---------------------------------------------------
3339% --- Executes on menu selection Fields
3340function Fields_1_Callback(hObject, eventdata, handles)
3341%-------------------------------------------------
3342list_fields=get(handles.Fields,'String');% list menu fields
3343index_fields=get(handles.Fields,'Value');% selected string index
3344field= list_fields{index_fields(1)}; % selected string
3345list_fields=get(handles.Fields_1,'String');% list menu fields
3346index_fields=get(handles.Fields_1,'Value');% selected string index
3347field_1= list_fields{index_fields(1)}; % selected string for the second field
3348if isequal(field_1,'') %remove second field if 'blank' field is selected
3349    set(handles.SubField,'Value',0)
3350    SubField_Callback(hObject, eventdata, handles)
3351    return
3352end
3353UvData=get(handles.uvmat,'UserData');
3354
3355%read the rootfile input display
3356[FileName,RootPath,FileBase,FileIndices,FileExt_prev]=read_file_boxes_1(handles);
3357[P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt_prev]);
3358if isempty(FileExt_prev)|isequal(FileExt_prev,'')
3359    FileExt_1=get(handles.FileExt,'String');
3360else
3361    FileExt_1=FileExt_prev;
3362end
3363NomType_1=get(handles.FileIndex_1,'UserData');
3364if isempty(NomType_1)|isequal(NomType_1,'')
3365    NomType_1=get(handles.FileIndex,'UserData');
3366end
3367NomTypeNew=NomType_1;%default
3368
3369set(handles.SubField,'Value',1)%introduce second field
3370if isfield(UvData,'XmlData')
3371    UvData.XmlData_1=UvData.XmlData;
3372end
3373set(handles.FileIndex_1,'Visible','on')
3374set(handles.FileExt_1,'Visible','on')
3375RootPath_1=get(handles.RootPath_1,'String');
3376RootFile_1=get(handles.RootFile_1,'String');
3377if isempty(RootPath_1)||isequal(RootPath_1,'')
3378    set(handles.RootPath_1,'String','"')
3379end
3380if isempty(RootFile_1) || isequal(RootFile_1,'')
3381    set(handles.RootFile_1,'String','"')
3382end
3383if ~isempty(RootFile_1)&&(isequal(RootFile_1(1),'/')||isequal(RootFile_1(1),'\'))
3384    RootFile_1(1)=[];
3385end
3386
3387if isequal(field_1,'get_field...')
3388     veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
3389     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3390     filename=read_file_boxes_1(handles);
3391     hget_field=findobj(allchild(0),'name','get_field_1');
3392     if ~isempty(hget_field)
3393         delete(hget_field)
3394     end
3395     hget_field=get_field(filename);
3396     set(hget_field,'name','get_field_1')
3397     hhget_field=guidata(hget_field);
3398     set(hhget_field.list_fig,'Value',1)
3399     set(hhget_field.list_fig,'String',{'uvmat'})
3400     set(handles.transform_fct,'Value',1)% no transform by default
3401     set(handles.path_transform,'String','')
3402    return %no action
3403end
3404if isequal(field_1,'image')
3405    % transform netc type to the corresponding image type
3406%     set(handles.FileExt_1,'String','.png');
3407    if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')| isequal(NomType_1,'#_ab')| isequal(NomType_1,'_i1-i2')
3408        UvData.SubDir_1=get(handles.SubDir_1,'String'); %preserve the subdir in memory
3409%         set(handles.SubDir_1,'String','')
3410%         set(handles.FileExt_1,'String','.png');       
3411        if isequal(NomType_1,'_i1-i2_j')|isequal(NomType_1,'_i_j1-j2')
3412            NomTypeNew='_i_j';
3413        elseif isequal(NomType_1,'#_ab')
3414            NomTypeNew='#a';
3415        elseif isequal(NomType_1,'_i1-i2')
3416            NomTypeNew='_i';
3417        end 
3418    end
3419    imagename=name_generator(FileBase,str2double(str1),str2double(str_a),'.png',NomTypeNew,1,str2double(str2),str2double(str_b),'');
3420    if ~exist(imagename,'file')
3421        [FileName,PathName] = uigetfile( ...
3422            {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3423            '*.jpg',' jpeg image files'; ...
3424            '*.png','.png image files'; ...
3425            '*.tif','.tif image files'; ...
3426            '*.avi;*.AVI','.avi movie files'; ...
3427            '*.vol','.volume images (png)'; ...
3428            '*.*',  'All Files (*.*)'}, ...
3429            'Pick an image',imagename);
3430        % display the selected field and related information
3431        imagename=[PathName FileName];
3432    end
3433    display_file_name_1(hObject, eventdata, handles,imagename)%display the image
3434    return
3435%     veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3436%     set_veltype_display(veltype_handles,0) % unvisible civ buttons
3437else
3438    set(handles.SubDir_1,'Visible','on')
3439    if ~isequal(FileExt_prev,'.nc') %find the new NomType if the previous display was not already a netcdf file
3440        veltype_handles=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
3441        set_veltype_display(veltype_handles,6); % make all civ buttons visible
3442        RootPath_1=get(handles.RootPath_1,'String');
3443        RootFile_1=get(handles.RootFile_1,'String');
3444        if isempty(RootPath_1)|isequal(RootPath_1,'')
3445            set(handles.RootPath_1,'String','"')
3446        end
3447        if isempty(RootFile_1) | isequal(RootFile_1,'')
3448            set(handles.RootFile_1,'String','"')
3449        end
3450        if ~isempty(RootFile_1)&(isequal(RootFile_1(1),'/')|isequal(RootFile_1(1),'\'))
3451            RootFile_1(1)=[];
3452        end
3453        filebase_1=fullfile(RootPath_1,RootFile_1);
3454        SubDir_1=get(handles.SubDir,'String');
3455        if isempty(SubDir_1)||isequal(SubDir_1,'')
3456            if isfield(UvData,'SubDir_1')
3457                SubDir_1=UvData.SubDir_1;%retrieve previous subdir
3458            else
3459                SubDir_1='?';
3460            end
3461        end
3462        str1=get(handles.i1,'String');
3463        str_a=get(handles.j1,'String');
3464        if isequal(NomType_1,'#_ab')||isequal(NomType_1,'_i1-i2_j')||isequal(NomType_1,'_i_j1-j2')||isequal(NomType_1,'_i1-i2')
3465            NomTypeNew=NomType_1;
3466        elseif isequal(NomType_1,'#a')
3467             [filename, n1,na,n2,nb,SubDir_1]=name_generator(filebase_1, str2num(str1),stra2num(str_a),'.nc','#_ab',0,[],[],SubDir_1);
3468             NomTypeNew='#_ab';
3469        elseif isequal(NomType_1,'_i_j')
3470             [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);
3471            if idetect==1
3472                NomTypeNew='_i1-i2_j';
3473            else
3474                NomTypeNew='_i_j1-j2';
3475            end
3476        else %for instance avi files or any ima_num series
3477            [filename,n1,na,n2,nb,SubDir_1]=name_generator(filebase_1,str2num(str1),stra2num(str_a),'.nc','_i1-i2',0,str2num(str1),[],SubDir_1);
3478            NomTypeNew='_i1-i2';
3479        end           
3480        [Path,Name]=fileparts(filebase_1);
3481        set(handles.FileExt_1,'String','.nc');
3482        if ~isempty(SubDir_1) && ~strcmp(SubDir_1,'''')&& ~strcmp(SubDir_1,'"')&& ~strcmp(SubDir_1(1),'/')
3483            SubDir_1=['/' SubDir_1];
3484        end
3485        set(handles.SubDir_1,'String',SubDir_1);
3486    end
3487    if isequal(field,'vort') | isequal(field,'div') | isequal(field,'strain')
3488        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3489        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3490        set(handles.interp1_1,'BackgroundColor',[0.702 0.702 0.702])
3491        set(handles.interp2_1,'BackgroundColor',[0.702 0.702 0.702])
3492    elseif isequal(field_1,'more...'); %add new item to the menu
3493        set(handles.civ1_1,'BackgroundColor',[0.702 0.702 0.702]) % put their color to grey
3494        set(handles.civ2_1,'BackgroundColor',[0.702 0.702 0.702])
3495        str=calc_field;%get the list of available scalars by the function calc_scal
3496        [ind_answer,v] = listdlg('PromptString','Select a file:',...
3497                'SelectionMode','single',...
3498                'ListString',str);
3499       % edit the choice in the field and action menu
3500        scalar=cell2mat(str(ind_answer));
3501        menu=update_menu(handles.Fields_1,scalar);
3502        set(handles.Fields_1,'String',menu);% store the selected scalar type
3503    end
3504end
3505str1=get(handles.i1,'String');
3506str2=get(handles.i2,'String');
3507str_a=get(handles.j1,'String');
3508str_b=get(handles.j2,'String');
3509indices=name_generator('',str2num(str1),stra2num(str_a),'',NomTypeNew,1,str2num(str2),stra2num(str_b),'');
3510set(handles.FileIndex_1,'String',indices)
3511set(handles.FileIndex_1,'UserData',NomTypeNew)
3512
3513%common to Fields_Callback
3514if isequal(field,'image')|isequal(field_1,'image')
3515    set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
3516    set(handles.npy_title,'Visible','on')
3517    set(handles.npx,'Visible','on')
3518    set(handles.npy,'Visible','on')
3519%     set(handles.fix_pair,'Value',0)
3520else
3521    set(handles.npx_title,'Visible','off')% visible npx,pxcm... buttons
3522    set(handles.npy_title,'Visible','off')
3523    set(handles.npx,'Visible','off')
3524    set(handles.npy,'Visible','off')
3525%     set(handles.fix_pair,'Value',1)
3526end
3527if isequal(field,'velocity')|isequal(field_1,'velocity');
3528    state_vect='on';
3529else
3530    state_vect='off';
3531end
3532if ~isequal(field,'velocity')|(~isequal(field_1,'velocity')&~isequal(field_1,''));
3533    state_scal='on';
3534else
3535    state_scal='off';
3536end
3537set(handles.uvmat,'UserData',UvData)
3538setfield(handles);% update the field structure ('civ1'....)
3539if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
3540    run0_Callback(hObject, eventdata, handles)
3541end
3542
3543%------------------------------------------------------------------------
3544% --- set the visibility of relevant velocity type menus:
3545function set_veltype_display(handles,Civ)
3546%------------------------------------------------------------------------
3547%Civ=0; all states 'off'
3548%Civ=6; all states 'on'
3549if isequal(Civ,0)
3550    imax=0;
3551%    set(handles(1),'Visible','on')  % unvisible civ buttons
3552% else
3553%    set(handles(1),'String','civ1')
3554% end
3555elseif isequal(Civ,1) || isequal(Civ,2)
3556   imax=1;
3557elseif isequal(Civ,3)
3558    imax=3;
3559elseif isequal(Civ,4) || isequal(Civ,5)
3560    imax=4;
3561elseif isequal(Civ,6) %patch2
3562    imax=6;
3563end
3564for ibutton=1:imax;
3565    set(handles(ibutton),'Visible','on')  % unvisible civ buttons
3566end
3567% for ibutton=max(imax+1,2):6;
3568for ibutton=imax+1:6;
3569    set(handles(ibutton),'Visible','off')  % unvisible civ buttons
3570    set(handles(ibutton),'Value',0)%unactivate unvisible buttons
3571end
3572
3573%-------------------------------------------------------------------
3574% --- Executes on button press in civ1.
3575function civ1_Callback(hObject, eventdata, handles)
3576%-------------------------------------------------------------------
3577if get(handles.civ1,'Value')==1
3578    reset_vel_type([handles.interp1 handles.civ2 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ1)
3579else
3580    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3581end
3582run0_Callback(hObject, eventdata, handles)
3583
3584%-------------------------------------------------------------------
3585% --- Executes on button press in interp1.
3586function interp1_Callback(hObject, eventdata, handles)
3587%-------------------------------------------------------------------
3588if get(handles.interp1,'Value')==1
3589    reset_vel_type([handles.civ1 handles.civ2 handles.filter1 handles.interp2 handles.filter2],handles.interp1)
3590else
3591     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3592end
3593run0_Callback(hObject, eventdata, handles)
3594
3595%-------------------------------------------------------------------
3596% --- Executes on button press in filter1.
3597function filter1_Callback(hObject, eventdata, handles)
3598%-------------------------------------------------------------------
3599if get(handles.filter1,'Value')==1
3600    reset_vel_type([handles.civ1 handles.civ2 handles.interp1 handles.interp2 handles.filter2],handles.filter1)
3601else
3602     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3603end
3604run0_Callback(hObject, eventdata, handles)
3605
3606%-------------------------------------------------------------------
3607% --- Executes on button press in civ2.
3608function civ2_Callback(hObject, eventdata, handles)
3609%-------------------------------------------------------------------
3610if get(handles.civ2,'Value')==1
3611    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.interp2 handles.filter2],handles.civ2)
3612else
3613     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3614end
3615run0_Callback(hObject, eventdata, handles)
3616
3617%-----------------------------------------
3618% --- Executes on button press in interp2.
3619%-------------------------------------------
3620function interp2_Callback(hObject, eventdata, handles)
3621if get(handles.interp2,'Value')==1
3622    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.filter2],handles.interp2)
3623else
3624     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3625end
3626run0_Callback(hObject, eventdata, handles)
3627%---------------------------------------------
3628% --- Executes on button press in filter2.
3629%-------------------------------------------
3630function filter2_Callback(hObject, eventdata, handles)
3631if get(handles.filter2,'Value')==1
3632    reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2],handles.filter2)
3633else
3634     reset_vel_type([handles.civ1 handles.filter1 handles.interp1 handles.civ2 handles.interp2 handles.filter2])
3635end
3636run0_Callback(hObject, eventdata, handles)
3637
3638%---------------------------------------------
3639function civ1_1_Callback(hObject, eventdata, handles)
3640%---------------------------------------------
3641if get(handles.civ1_1,'Value')==1
3642    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.civ1_1)
3643else
3644     reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3645end
3646run0_Callback(hObject, eventdata, handles)
3647
3648%--------------------------------------------
3649function interp1_1_Callback(hObject, eventdata, handles)
3650%--------------------------------------------
3651if get(handles.interp1_1,'Value')==1
3652    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.interp1_1)
3653else
3654    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3655end
3656run0_Callback(hObject, eventdata, handles)
3657
3658%--------------------------------------------
3659function filter1_1_Callback(hObject, eventdata, handles)
3660%--------------------------------------------
3661if get(handles.filter1_1,'Value')==1
3662    reset_vel_type([handles.interp1_1 handles.civ2_1 handles.interp1_1 handles.interp2_1 handles.filter2_1],handles.filter1_1)
3663else
3664    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3665end
3666run0_Callback(hObject, eventdata, handles)
3667
3668%--------------------------------------------
3669function civ2_1_Callback(hObject, eventdata, handles)
3670%--------------------------------------------
3671if get(handles.civ2_1,'Value')==1
3672    reset_vel_type([handles.civ1_1 handles.interp1_1  handles.filter1_1 handles.interp2_1 handles.filter2_1],handles.civ2_1)
3673else
3674    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3675end
3676run0_Callback(hObject, eventdata, handles)
3677
3678%--------------------------------------------
3679function interp2_1_Callback(hObject, eventdata, handles)
3680%--------------------------------------------
3681if get(handles.interp2_1,'Value')==1
3682    reset_vel_type([handles.civ1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.filter2_1],handles.interp2_1)
3683else
3684    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3685end
3686run0_Callback(hObject, eventdata, handles)
3687
3688%--------------------------------------------
3689function filter2_1_Callback(hObject, eventdata, handles)
3690%--------------------------------------------
3691if get(handles.filter2_1,'Value')==1
3692    reset_vel_type([handles.civ1_1 handles.interp1_1 handles.civ2_1 handles.filter1_1 handles.interp1_1 handles.interp2_1],handles.filter2_1)
3693else
3694    reset_vel_type([handles.civ1_1 handles.filter1_1 handles.interp1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1])
3695end
3696run0_Callback(hObject, eventdata, handles)
3697
3698%-----------------------------------------------
3699% --- reset civ buttons
3700function reset_vel_type(handles_civ0,handle1)
3701for ibutton=1:length(handles_civ0)
3702    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3703    set(handles_civ0(ibutton),'Value',0)
3704end
3705if exist('handle1','var')%handles of selected button
3706        set(handle1,'BackgroundColor',[1 1 0]) 
3707end
3708
3709%-------------------------------------------------------
3710% --- Executes on button press in MENUVOLUME.
3711%-------------------------------------------------------
3712function VOLUME_Callback(hObject, eventdata, handles)
3713%errordlg('command VOL not implemented yet')
3714if ishandle(handles.UVMAT_title)
3715    delete(handles.UVMAT_title)
3716end
3717UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3718if isequal(get(handles.VOLUME,'Value'),1)
3719    set(handles.zoom,'Value',0)
3720    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3721    set(handles.edit_vect,'Value',0)
3722    edit_vect_Callback(hObject, eventdata, handles)
3723    set(handles.edit_object,'Value',0)
3724    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3725%     set(handles.cal,'Value',0)
3726%     set(handles.cal,'BackgroundColor',[0 1 0])
3727    set(handles.edit_vect,'Value',0)
3728    edit_vect_Callback(hObject, eventdata, handles)
3729    %initiate set_object GUI
3730    data.TITLE='VOLUME';
3731    if isfield(UvData,'CoordType')
3732        data.CoordType=UvData.CoordType;
3733    end
3734    if isfield(UvData,'Mesh')&~isempty(UvData.Mesh)
3735        data.RangeY=UvData.Mesh;
3736        data.RangeX=UvData.Mesh;
3737        data.DX=UvData.Mesh;
3738        data.DY=UvData.Mesh;
3739    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3740        np=size(UvData.Field.A);
3741        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3742        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3743        data.RangeY=max(meshx,meshy);
3744        data.RangeX=max(meshx,meshy);
3745        data.DX=max(meshx,meshy);
3746    end
3747    data.ParentButton=handles.VOLUME;
3748    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3749    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3750                                                      % associate the set_object interface handle to the plotting axes
3751    if isfield(UvData,'SetObjectOrigin')                                               
3752    pos_uvmat=get(huvmat,'Position');
3753    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
3754    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4); 
3755    set(hset_object,'Position',pos_set_object)
3756    end
3757    UvData.MouseAction='create_object';
3758else
3759    set(handles.VOLUME,'BackgroundColor',[0 1 0])
3760    UvData.MouseAction='none';
3761end
3762set(huvmat,'UserData',UvData)
3763
3764%-------------------------------------------------------
3765function edit_vect_Callback(hObject, eventdata, handles)
3766%-------------------------------------------------------
3767%
3768% UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3769if isequal(get(handles.edit_vect,'Value'),1)
3770    test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
3771    test_civ1=isequal(get(handles.civ1,'BackgroundColor'),[1 1 0]);
3772    if ~test_civ2 && ~test_civ1
3773        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3774    end
3775    set(handles.record,'Visible','on')
3776    set(handles.edit_vect,'BackgroundColor',[1 1 0])
3777    set(handles.edit_object,'Value',0)
3778    set(handles.zoom,'Value',0)
3779    set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
3780%     set(handles.create,'Value',0)
3781%     set(handles.create,'BackgroundColor',[0 1 0])
3782    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3783    set(gcf,'Pointer','arrow')
3784%     UvData.MouseAction='edit_vect';
3785else
3786    set(handles.record,'Visible','off')
3787    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3788%     UvData.MouseAction='none';
3789end
3790% set(handles.uvmat,'UserData',UvData)
3791
3792%----------------------------------------------
3793function save_mask_Callback(hObject, eventdata, handles)
3794%-----------------------------------------------------------------------
3795UvData=get(handles.uvmat,'UserData');
3796
3797flag=1;
3798npx=size(UvData.Field.A,2);
3799npy=size(UvData.Field.A,1);
3800xi=[0.5:npx-0.5];
3801yi=[0.5:npy-0.5];
3802[Xi,Yi]=meshgrid(xi,yi);
3803if isfield(UvData,'Object')
3804    for iobj=1:length(UvData.Object)
3805        ObjectData=UvData.Object{iobj};
3806        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3807            flagobj=1;
3808            testphys=0; %coordinates in pixels by default
3809            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3810                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
3811                    Calib=UvData.XmlData.GeometryCalib;
3812                    testphys=1;
3813                end
3814            end
3815            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
3816                if isequal(ObjectData.Style,'polygon')
3817                    X=ObjectData.Coord(:,1);
3818                    Y=ObjectData.Coord(:,2);
3819                    if testphys
3820                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3821                    end
3822                    flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
3823                elseif isequal(ObjectData.Style,'ellipse')
3824                    if testphys
3825                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3826                    end
3827                    RangeX=max(ObjectData.RangeX);
3828                    RangeY=max(ObjectData.RangeY);
3829                    X2Max=RangeX*RangeX;
3830                    Y2Max=RangeY*RangeY;
3831                    distX=(Xi-ObjectData.Coord(1,1));
3832                    distY=(Yi-ObjectData.Coord(1,2));
3833                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3834                elseif isequal(ObjectData.Style,'rectangle')
3835                    if testphys
3836                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3837                    end
3838                    distX=abs(Xi-ObjectData.Coord(1,1));
3839                    distY=abs(Yi-ObjectData.Coord(1,2));
3840                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3841                end
3842                if isequal(ObjectData.ProjMode,'mask_outside')
3843                    flagobj=~flagobj;
3844                end
3845                flag=flag & flagobj;
3846            end
3847        end
3848    end
3849end
3850% flag=~flag;
3851%mask name
3852RootPath=get(handles.RootPath,'String');
3853RootFile=get(handles.RootFile,'String');
3854if ~isempty(RootFile)&(isequal(RootFile(1),'/')| isequal(RootFile(1),'\'))
3855        RootFile(1)=[];
3856end
3857filebase=fullfile(RootPath,RootFile);
3858list=get(handles.masklevel,'String');
3859masknumber=num2str(length(list));
3860maskindex=get(handles.masklevel,'Value');
3861mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3862imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3863imflag=flipdim(imflag,1);
3864% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3865msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
3866imwrite(imflag,mask_name,'BitDepth',8);
3867
3868%display the mask
3869%update_mask(handles,num_i1,num_j1)
3870figure;
3871vec=linspace(0,1,256);%define a linear greyscale colormap
3872map=[vec' vec' vec'];
3873colormap(map)
3874
3875image(imflag);
3876
3877%-------------------------------------------------------------------
3878%-------------------------------------------------------------------
3879%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3880
3881%------------------------------------------------------------------
3882
3883
3884
3885%------------------------------------------------------------------
3886% --- Executes on selection change in col_vec: choice of the color code.
3887%
3888function col_vec_Callback(hObject, eventdata, handles)
3889%------------------------------------------------------------------
3890% edit the choice for color code
3891list_code=get(handles.col_vec,'String');% list menu fields
3892index_code=get(handles.col_vec,'Value');% selected string index
3893col_code= list_code{index_code(1)}; % selected field
3894if isequal(col_code,'black') || isequal(col_code,'white')
3895   set(handles.slider1,'Visible','off')
3896   set(handles.slider2,'Visible','off')
3897   set(handles.colcode1,'Visible','off')
3898   set(handles.colcode2,'Visible','off')
3899   set(handles.AutoVecColor,'Visible','off')
3900   set_vec_col_bar(handles)
3901else
3902   set(handles.slider1,'Visible','on')
3903   set(handles.slider2,'Visible','on')
3904   set(handles.colcode1,'Visible','on')
3905   set(handles.colcode2,'Visible','on')
3906   set(handles.AutoVecColor,'Visible','on') 
3907   if isequal(col_code,'ima_cor')
3908       set(handles.AutoVecColor,'Value',0)%fixed scale by default
3909       set(handles.vec_col_bar,'Value',0)% 3 colors r,g,b by default
3910       set(handles.slider1,'Min',0);
3911       set(handles.slider1,'Max',1);
3912       set(handles.slider2,'Min',0);
3913       set(handles.slider2,'Max',1);
3914 %      set(handles.min_title_vec,'String','0')
3915       set(handles.max_vec,'String','1')
3916       set(handles.colcode1,'String','0.333')
3917       colcode1_Callback(hObject, eventdata, handles)
3918       set(handles.colcode2,'String','0.666')
3919       colcode2_Callback(hObject, eventdata, handles)
3920   else
3921       set(handles.AutoVecColor,'Value',1)%auto scale between min,max by default
3922       set(handles.vec_col_bar,'Value',1)% colormap 'jet' by default
3923       minval=get(handles.slider1,'Min');
3924       maxval=get(handles.slider1,'Max');
3925       set(handles.slider1,'Value',minval)
3926       set(handles.slider2,'Value',maxval)
3927       set_vec_col_bar(handles)
3928   end
3929%    slider_update(handles)
3930end
3931%replot the current graph
3932run0_Callback(hObject, eventdata, handles)
3933
3934
3935%----------------------------------------------------------------
3936% -- Executes on slider movement to set the color code
3937%
3938function slider1_Callback(hObject, eventdata, handles)
3939%------------------------------------------------------------------
3940slider1=get(handles.slider1,'Value');
3941min_val=str2num(get(handles.min_vec,'String'));
3942max_val=str2num(get(handles.max_vec,'String'));
3943col=min_val+(max_val-min_val)*slider1;
3944set(handles.colcode1,'String',num2str(col))
3945if(get(handles.slider2,'Value') < col)%move also the second slider at the same value if needed
3946    set(handles.slider2,'Value',col)
3947    set(handles.colcode2,'String',num2str(col))
3948end
3949colcode1_Callback(hObject, eventdata, handles)
3950
3951%----------------------------------------------------------------
3952% Executes on slider movement to set the color code
3953%----------------------------------------------------------------
3954function slider2_Callback(hObject, eventdata, handles)
3955slider2=get(handles.slider2,'Value');
3956min_val=str2num(get(handles.min_vec,'String'));
3957max_val=str2num(get(handles.max_vec,'String'));
3958col=min_val+(max_val-min_val)*slider2;
3959set(handles.colcode2,'String',num2str(col))
3960if(get(handles.slider1,'Value') > col)%move also the first slider at the same value if needed
3961    set(handles.slider1,'Value',col)
3962    set(handles.colcode1,'String',num2str(col))
3963end
3964colcode2_Callback(hObject, eventdata, handles)
3965
3966%----------------------------------------------------------------
3967%execute on return carriage on the edit box corresponding to slider 1
3968%----------------------------------------------------------------
3969function colcode1_Callback(hObject, eventdata, handles)
3970% col=str2num(get(handles.colcode1,'String'));
3971% set(handles.slider1,'Value',col)
3972set_vec_col_bar(handles)
3973update_plot(handles);
3974
3975%----------------------------------------------------------------
3976%execute on return carriage on the edit box corresponding to slider 2
3977%----------------------------------------------------------------
3978function colcode2_Callback(hObject, eventdata, handles)
3979% col=str2num(get(handles.colcode2,'String'));
3980% set(handles.slider2,'Value',col)
3981% slider2_Callback(hObject, eventdata, handles)
3982set_vec_col_bar(handles)
3983update_plot(handles);
3984%------------------------------------------------------------
3985%update the slider values after displaying vectors
3986%--------------------------------------------------------
3987% function slider_update(handles,auto,minC,colcode1,colcode2,maxC)
3988% set(handles.slider1,'Min',minC)
3989% set(handles.slider1,'Max',maxC)
3990% set(handles.slider2,'Min',minC)
3991% set(handles.slider2,'Max',maxC)
3992% set(handles.min_title_vec,'String',num2str(minC))
3993% set(handles.max_vec,'String',num2str(maxC))
3994% if auto
3995%         set(handles.colcode1,'String',num2str(colcode1,3))%update display
3996%         set(handles.colcode2,'String',num2str(colcode2,3))
3997% end
3998% set(handles.slider1,'Value',colcode1)%update slider with constant display
3999% set(handles.slider2,'Value',colcode2)
4000% set_vec_col_bar(handles)
4001
4002
4003%-------------------------------------------------------
4004% --- Executes on button press in AutoVecColor.
4005%-------------------------------------------------------
4006function vec_col_bar_Callback(hObject, eventdata, handles)
4007set_vec_col_bar(handles)
4008
4009%-------------------------------------------------------------
4010% --- Executes on selection change in transform_fct.
4011function transform_fct_Callback(hObject, eventdata, handles)
4012%-------------------------------------------------------------
4013global nb_builtin
4014
4015huvmat=get(handles.transform_fct,'parent');
4016menu=get(handles.transform_fct,'String');
4017ind_coord=get(handles.transform_fct,'Value');
4018coord_option=menu{ind_coord};
4019list_transform=get(handles.transform_fct,'UserData');
4020ff=functions(list_transform{end}); 
4021if isequal(coord_option,'more...');
4022    coord_fct='';
4023    prompt = {'Enter the name of the transform function'};
4024    dlg_title = 'user defined transform';
4025    num_lines= 1;
4026    [FileName, PathName] = uigetfile( ...
4027       {'*.m', ' (*.m)';
4028        '*.m',  '.m files '; ...
4029        '*.*', 'All Files (*.*)'}, ...
4030        'Pick a file', ff.file);
4031    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
4032        PathName(end)=[];
4033    end
4034    transform_selected =fullfile(PathName,FileName);
4035    if ~exist(transform_selected,'file')
4036           return
4037    end
4038   [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
4039   if ~isequal(ext_fct,'.m')
4040        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
4041        return
4042   end
4043   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
4044   ind_coord=get(handles.transform_fct,'Value');
4045   addpath(PathName)
4046   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
4047   set(handles.transform_fct,'UserData',list_transform)
4048   rmpath(PathName)
4049   % save the new menu in the personal file 'uvmat_perso.mat'
4050   dir_perso=prefdir;%personal Matalb directory
4051   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
4052   if exist(profil_perso,'file')
4053       for ilist=nb_builtin+1:numel(list_transform)
4054           ff=functions(list_transform{ilist});
4055           transform_fct{ilist-nb_builtin}=ff.file;
4056       end
4057        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
4058   end   
4059end
4060
4061%check the current path to the selected function
4062if isa(list_transform{ind_coord},'function_handle')
4063    func=functions(list_transform{ind_coord});
4064    set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
4065else
4066    set(handles.path_transform,'String','')
4067end
4068
4069set(handles.FixedLimits,'Value',0)
4070set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
4071
4072UvData=get(huvmat,'UserData');
4073
4074%delete drawn objects
4075hother=findobj('Tag','proj_object');%find all the proj objects
4076for iobj=1:length(hother)
4077    delete_object(hother(iobj))
4078end
4079hother=findobj('Tag','DeformPoint');%find all the proj objects
4080for iobj=1:length(hother)
4081    delete_object(hother(iobj))
4082end
4083hh=findobj('Tag','calib_points');
4084if ~isempty(hh)
4085    delete(hh)
4086end
4087hhh=findobj('Tag','calib_marker');
4088if ~isempty(hhh)
4089    delete(hhh)
4090end
4091if isfield(UvData,'Object')
4092     UvData.Object=UvData.Object(1);
4093end
4094list_object=get(handles.list_object_1,'String');
4095set(handles.list_object_1,'Value',1)
4096set(handles.list_object_1,'String',list_object(1))
4097set(handles.list_object_2,'Value',2)
4098set(handles.list_object_2,'String',[list_object(1);{'...'}])
4099list_object_2_Callback(hObject, eventdata, handles)
4100
4101%delete mask if it is displayed
4102if isequal(get(handles.mask_test,'Value'),1)%if the mask option is on
4103   UvData=rmfield(UvData,'MaskName'); %will impose mask refresh 
4104end
4105set(huvmat,'UserData',UvData)
4106run0_Callback(hObject, eventdata, handles)
4107
4108%--------------------------------------------
4109function histo1_menu_Callback(hObject, eventdata, handles)
4110%--------------------------------------------
4111%plot first histo
4112huvmat=get(handles.histo1_menu,'parent');
4113histo_menu=get(handles.histo1_menu,'String');
4114histo_value=get(handles.histo1_menu,'Value');
4115FieldName=histo_menu{histo_value};
4116% UvData=get(huvmat,'UserData');
4117update_histo(handles.histo_u,huvmat,FieldName)
4118
4119%----------------------------------------------
4120function histo2_menu_Callback(hObject, eventdata, handles)
4121%----------------------------------------------
4122%plot second histo
4123huvmat=get(handles.histo2_menu,'parent');
4124histo_menu=get(handles.histo2_menu,'String');
4125histo_value=get(handles.histo2_menu,'Value');
4126FieldName=histo_menu{histo_value};
4127% UvData=get(huvmat,'UserData');
4128update_histo(handles.histo_v,huvmat,FieldName)
4129
4130
4131%--------------------------------------------
4132%read the field .Fieldname stored in UvData and plot its histogram
4133function update_histo(haxes,huvmat,FieldName)
4134UvData=get(huvmat,'UserData');
4135if ~isfield(UvData.Field,FieldName)
4136    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
4137    return
4138end
4139Field=UvData.Field;
4140FieldHisto=eval(['Field.' FieldName]);
4141if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(FieldHisto))
4142    indsel=find(Field.FF==0);%find values marked as false
4143    if ~isempty(indsel)
4144        FieldHisto=FieldHisto(indsel);
4145    end
4146end
4147if isempty(Field)
4148    msgbox_uvmat('ERROR',['empty field ' FieldName])
4149else
4150    nxy=size(FieldHisto);
4151    Amin=double(min(min(min(FieldHisto))));%min of image
4152    Amax=double(max(max(max(FieldHisto))));%max of image
4153    if isequal(Amin,Amax)
4154       Histo.Txt=['uniform field =' num2str(Amin)];
4155    else
4156    Histo.ListVarName={FieldName,'histo'};
4157    if numel(nxy)==2
4158        Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
4159    else %color images
4160        Histo.VarDimName={FieldName,{FieldName,'rgb'}}; %dimensions for the histogram
4161    end
4162    %unit
4163    units=[]; %default
4164    for ivar=1:numel(Field.ListVarName)   
4165        if strcmp(Field.ListVarName{ivar},FieldName)
4166            if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
4167                units=Field.VarAttribute{ivar}.units;
4168                break
4169            end
4170        end
4171    end
4172    if ~isempty(units)
4173        Histo.VarAttribute{1}.units=units;
4174    end
4175    eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
4176    for col=1:size(FieldHisto,3)
4177        B=FieldHisto(:,:,col);
4178        C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
4179       eval(['Histo.histo(:,col)=hist(C, Histo.' FieldName ');']);  %calculate histogram
4180    end
4181    set(haxes,'XLimMode','auto')%reset auto mode (after zoom effect)
4182    set(haxes,'YLimMode','auto')
4183    plot_field(Histo,haxes);
4184    end
4185end
4186
4187
4188
4189%------------------------------------------------
4190%CALLBACKS FOR PLOTTING PARAMETERS
4191%-------------------------------------------------
4192
4193%-----------------------------------------------------------------
4194function MinA_Callback(hObject, eventdata, handles)
4195%------------------------------------------
4196set(handles.AutoScal,'Value',1) %suppress auto mode
4197set(handles.AutoScal,'BackgroundColor',[1 1 0])
4198update_plot(handles);
4199
4200%-----------------------------------------------------------------
4201function MaxA_Callback(hObject, eventdata, handles)
4202%--------------------------------------------
4203set(handles.AutoScal,'Value',1) %suppress auto mode
4204set(handles.AutoScal,'BackgroundColor',[1 1 0])
4205update_plot(handles);
4206
4207%-----------------------------------------------
4208function AutoScal_Callback(hObject, eventdata, handles)
4209%--------------------------------------------
4210test=get(handles.AutoScal,'Value');
4211if test
4212    set(handles.AutoScal,'BackgroundColor',[1 1 0])
4213else
4214    set(handles.AutoScal,'BackgroundColor',[0.7 0.7 0.7])
4215    update_plot(handles);
4216end
4217
4218%-------------------------------------------------------------------
4219function BW_Callback(hObject, eventdata, handles)
4220%-------------------------------------------------------------------
4221update_plot(handles);
4222
4223%-------------------------------------------------------------------
4224function Contours_Callback(hObject, eventdata, handles)
4225%-------------------------------------------------------------------
4226val=get(handles.Contours,'Value');
4227if val==2
4228    set(handles.interval_txt,'Visible','on')
4229    set(handles.IncrA,'Visible','on')
4230else
4231    set(handles.interval_txt,'Visible','off')
4232    set(handles.IncrA,'Visible','off')
4233end
4234update_plot(handles);
4235
4236%-------------------------------------------------------------------
4237function IncrA_Callback(hObject, eventdata, handles)
4238%-------------------------------------------------------------------
4239update_plot(handles);
4240
4241%-------------------------------------------------------------------
4242function HideWarning_Callback(hObject, eventdata, handles)
4243%-------------------------------------------------------------------
4244update_plot(handles);
4245
4246%-------------------------------------------------------------------
4247function HideFalse_Callback(hObject, eventdata, handles)
4248%-------------------------------------------------------------------
4249update_plot(handles);
4250
4251%-------------------------------------------------------------------
4252function VecScale_Callback(hObject, eventdata, handles)
4253%-------------------------------------------------------------------
4254set(handles.AutoVec,'Value',1);
4255set(handles.AutoVec,'BackgroundColor',[1 1 0])
4256update_plot(handles);
4257
4258%-------------------------------------------------------------------
4259function AutoVec_Callback(hObject, eventdata, handles)
4260%-------------------------------------------------------------------
4261test=get(handles.AutoVec,'Value');
4262if test
4263    set(handles.AutoVec,'BackgroundColor',[1 1 0])
4264else
4265    update_plot(handles);
4266    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4267    set(handles.AutoVec,'BackgroundColor',[0.7 0.7 0.7])
4268end
4269
4270%------------------------------------------------------------------------
4271% --- Executes on selection change in decimate4 (nb_vec/4).
4272function decimate4_Callback(hObject, eventdata, handles)
4273%------------------------------------------------------------------------
4274update_plot(handles);
4275
4276%------------------------------------------------------------------------
4277% --- Executes on selection change in color_code menu
4278function color_code_Callback(hObject, eventdata, handles)
4279%------------------------------------------------------------------------
4280set_vec_col_bar(handles)
4281update_plot(handles);
4282
4283%------------------------------------------------------------------------
4284% --- Executes on button press in AutoVecColor.
4285function AutoVecColor_Callback(hObject, eventdata, handles)
4286%------------------------------------------------------------------------
4287test=get(handles.AutoVecColor,'Value');
4288if test
4289    set(handles.AutoVecColor,'BackgroundColor',[1 1 0])
4290else
4291    update_plot(handles);
4292    %set(handles.VecScale,'String',num2str(ScalOut.VecScale,3))
4293    set(handles.AutoVecColor,'BackgroundColor',[0.7 0.7 0.7])
4294end
4295
4296%------------------------------------------------------------------------
4297% --- Executes on selection change in max_vec.
4298function min_vec_Callback(hObject, eventdata, handles)
4299%------------------------------------------------------------------------
4300max_vec_Callback(hObject, eventdata, handles)
4301
4302%------------------------------------------------------------------------
4303% --- Executes on selection change in max_vec.
4304function max_vec_Callback(hObject, eventdata, handles)
4305%------------------------------------------------------------------------
4306set(handles.AutoVecColor,'Value',1)
4307AutoVecColor_Callback(hObject, eventdata, handles)
4308min_val=str2num(get(handles.min_vec,'String'));
4309max_val=str2num(get(handles.max_vec,'String'));
4310slider1=get(handles.slider1,'Value');
4311slider2=get(handles.slider2,'Value');
4312colcode1=min_val+(max_val-min_val)*slider1;
4313colcode2=min_val+(max_val-min_val)*slider2;
4314set(handles.colcode1,'String',num2str(colcode1))
4315set(handles.colcode2,'String',num2str(colcode2))
4316update_plot(handles);
4317
4318%------------------------------------------------------------------------
4319% --- update the display of color code for vectors
4320function set_vec_col_bar(handles)
4321%------------------------------------------------------------------------
4322%get the image of the color display button 'vec_col_bar' in pixels
4323set(handles.vec_col_bar,'Unit','pixel');
4324pos_vert=get(handles.vec_col_bar,'Position');
4325set(handles.vec_col_bar,'Unit','Normalized');
4326width=ceil(pos_vert(3));
4327height=ceil(pos_vert(4));
4328
4329%get slider indications
4330list=get(handles.color_code,'String');
4331ichoice=get(handles.color_code,'Value');
4332colcode.ColorCode=list{ichoice};
4333colcode.MinC=str2num(get(handles.min_vec,'String'));
4334colcode.MaxC=str2num(get(handles.max_vec,'String'));
4335test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
4336if test3color
4337    colcode.colcode1=str2num(get(handles.colcode1,'String'));
4338    colcode.colcode2=str2num(get(handles.colcode2,'String'));
4339end
4340% colcode.option=get(handles.vec_col_bar,'Value');
4341colcode.FixedCbounds=0;
4342% list_code=get(handles.col_vec,'String');% list menu fields
4343% index_code=get(handles.col_vec,'Value');% selected string index
4344% colcode.CName= list_code{index_code(1)}; % selected field used for vector color
4345colcode.FixedCbounds=1;
4346vec_C=colcode.MinC+(colcode.MaxC-colcode.MinC)*[0.5:width-0.5]/width;%sample of vec_C values from min to max
4347[colorlist,col_vec]=set_col_vec(colcode,vec_C);
4348oneheight=ones(1,height);
4349A1=colorlist(col_vec,1)*oneheight;
4350A2=colorlist(col_vec,2)*oneheight;
4351A3=colorlist(col_vec,3)*oneheight;
4352A(:,:,1)=A1';
4353A(:,:,2)=A2';
4354A(:,:,3)=A3';
4355set(handles.vec_col_bar,'Cdata',A)
4356
4357
4358%-------------------------------------------------------------------
4359function update_plot(handles)
4360%-------------------------------------------------------------------
4361haxes= handles.axes3;
4362UvData=get(handles.uvmat,'UserData');
4363AxeData=UvData.axes3;
4364PlotParam=read_plot_param(handles);
4365[PlotType,PlotParamOut]= plot_field(AxeData,haxes,PlotParam,1);
4366write_plot_param(handles,PlotParamOut); %update the auto plot parameters
4367
4368%-------------------------------------------------------------------
4369% --- Executes on button press in grid.
4370function grid_Callback(hObject, eventdata, handles)
4371
4372
4373
4374%-------------------------------------------------------------------
4375% --- Executes on selection change in edit_object.
4376function edit_object_Callback(hObject, eventdata, handles)
4377%-------------------------------------------------------------------
4378UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4379test=get(handles.edit_object,'Value');
4380if test
4381    set(handles.edit_object,'BackgroundColor',[1,1,0]) 
4382    %suppress the other options
4383    set(handles.zoom,'Value',0)
4384    zoom_Callback(hObject, eventdata, handles)
4385else
4386    UvData.MouseAction='none';
4387    set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7])   
4388end
4389set(handles.uvmat,'UserData',UvData);
4390hset_object=findobj(allchild(0),'Tag','set_object');
4391if ~isempty(hset_object)
4392    hhset_object=guidata(hset_object);
4393    if test
4394        set(hhset_object.PLOT,'enable','on');
4395    else
4396       set(hhset_object.PLOT,'enable','off');
4397    end
4398end
4399
4400%------------------------------------------------------------------------
4401% --- Executes on selection change in list_object_1.
4402function list_object_1_Callback(hObject, eventdata, handles)
4403%------------------------------------------------------------------------
4404list_str=get(handles.list_object_1,'String');
4405IndexObj=get(handles.list_object_1,'Value');
4406str_1=list_str{IndexObj};
4407val_2=get(handles.list_object_2,'Value');
4408str_2=get(handles.list_object_2,'String');
4409if isequal(val_2,IndexObj)% if the first selection is equal to the second, it will suppress the second
4410    set(handles.list_object_2,'Value',numel(str_2))%select the end of the list ('...')
4411    list_object_2_Callback(hObject, eventdata, handles)
4412end
4413update_object(handles,IndexObj,1,str_1)
4414
4415%------------------------------------------------------------------------
4416% --- Executes on selection change in list_object_1.
4417function list_object_2_Callback(hObject, eventdata, handles)
4418%------------------------------------------------------------------------
4419list_str=get(handles.list_object_2,'String');
4420IndexObj=get(handles.list_object_2,'Value');
4421if strcmp(list_str{IndexObj},'...')
4422    hview_field=findobj(allchild(0),'Tag','view_field');
4423    if ~isempty(hview_field)
4424        delete(hview_field)
4425    end
4426else
4427    update_object(handles,IndexObj,2,list_str{IndexObj})
4428end
4429
4430%------------------------------------------------------------------------
4431function update_object(handles,IndexObj,option,ObjectName)
4432%------------------------------------------------------------------------
4433UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4434if numel(UvData.Object)<IndexObj;
4435    return
4436end
4437ObjectData=UvData.Object{IndexObj};
4438ObjectData.Name=ObjectName;
4439if isequal(get(handles.edit_object,'Value'),1)
4440    ObjectData.enable_plot=1; % desable the PLOT option in the set_object GUI (editing mode
4441end
4442ZBounds=0; % default
4443    if isfield(UvData,'ZMin') && isfield(UvData,'ZMax')
4444        ZBounds(1)=UvData.ZMin; %minimum for the Z slider
4445        ZBounds(2)=UvData.ZMax;%maximum for the Z slider
4446    end
4447hset_object=findobj(allchild(0),'tag','set_object');
4448if ~isempty(hset_object)
4449    delete(hset_object)% delete existing version of set_object
4450end
4451hset_object=set_object(ObjectData,[],ZBounds);% call the set_object interface,
4452
4453% %project the current field on the object and plot it
4454ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
4455if option==1%length(UvData.Object)>= IndexObj && isfield(UvData.Object{IndexObj},'plotaxes')&& ishandle(UvData.Object{IndexObj}.plotaxes)
4456    PlotHandles=handles;
4457%     UvData.Object{IndexObj}.plotaxes=handles.axes3;
4458else
4459    hview_field=findobj(allchild(0),'tag','view_field');
4460    if isempty(hview_field)
4461        hview_field=view_field;
4462    end
4463    PlotHandles=guidata(hview_field);
4464%     hview_field=view_field(ProjData);
4465%     hhviewfield=guidata(hviewfield);
4466   % UvData.Object{IndexObj}.plotaxes=hhviewfield.axes3;
4467end
4468if ~isempty(ProjData)
4469plot_field(ProjData,PlotHandles.axes3,PlotHandles);
4470end
4471set(handles.uvmat,'UserData',UvData)
4472hother=findobj('Tag','proj_object');%find all the proj objects
4473for iobj=1:length(hother)
4474    if isequal(get(hother(iobj),'Type'),'rectangle')|isequal(get(hother(iobj),'Type'),'patch')
4475        set(hother(iobj),'EdgeColor','b')
4476        if isequal(get(hother(iobj),'FaceColor'),'m')
4477            set(hother(iobj),'FaceColor','b')
4478        end
4479    elseif isequal(get(hother(iobj),'Type'),'image')
4480           Acolor=get(hother(iobj),'CData');
4481           Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4482           set(hother(iobj),'CData',Acolor);
4483    else
4484         set(hother(iobj),'Color','b')
4485    end
4486    set(hother(iobj),'Selected','off')
4487end
4488hother=findobj('Tag','DeformPoint');
4489set(hother,'Color','b');
4490set(hother,'Selected','off')   
4491if isfield(ObjectData,'DisplayHandle_uvmat')
4492%     for iview=1:length(ObjectData.HandlesDisplay)
4493        if ishandle(ObjectData.DisplayHandle_uvmat)
4494            uistack(ObjectData.DisplayHandle_uvmat,'top')
4495            linetype=get(ObjectData.DisplayHandle_uvmat,'Type');
4496            if isequal(linetype,'line')
4497                set(ObjectData.DisplayHandle_uvmat,'Color','m'); %set the selected object to magenta color
4498            elseif isequal(linetype,'rectangle')
4499                set(ObjectData.DisplayHandle_uvmat,'EdgeColor','m'); %set the selected object to magenta color
4500            elseif isequal(linetype,'patch')
4501                set(ObjectData.DisplayHandle_uvmat,'FaceColor','m'); %set the selected object to magenta color
4502            end
4503            SubObjectData=get(ObjectData.DisplayHandle_uvmat,'UserData');
4504            if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject)
4505                uistack(SubObjectData.SubObject,'top')
4506                for iobj=1:length(SubObjectData.SubObject)
4507                    hsub=SubObjectData.SubObject(iobj);
4508                    if isequal(get(hsub,'Type'),'rectangle')
4509                        set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4510                    elseif isequal(get(hsub,'Type'),'image')
4511                       Acolor=get(hsub,'CData');
4512                       Acolor(:,:,1)=Acolor(:,:,3);
4513                       set(hsub,'CData',Acolor);
4514                    else
4515                        set(hsub,'Color','m')
4516                    end
4517                end
4518            end
4519            if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint)
4520                set(SubObjectData.DeformPoint,'Color','m')
4521            end
4522        end
4523%     end
4524end
4525pause(0.1)
4526figure(hset_object)%put set_object in front
4527
4528%------------------------------------------------------
4529% --- Executes on button press in Menu/Export/field in workspace.
4530%------------------------------------------------------
4531function MenuExportField_Callback(hObject, eventdata, handles)
4532global Data_uvmat
4533Data_uvmat=get(handles.uvmat,'UserData');
4534evalin('base','global Data_uvmat')%make CurData global in the workspace
4535display('current field :')
4536evalin('base','Data_uvmat') %display CurData in the workspace
4537commandwindow; %brings the Matlab command window to the front
4538
4539%------------------------------------------------------
4540% --- Executes on button press in Menu/Export/extract figure.
4541%------------------------------------------------------
4542function MenuExport_plot_Callback(hObject, eventdata, handles)
4543huvmat=get(handles.MenuExport_plot,'parent');
4544UvData=get(huvmat,'UserData');
4545hfig=figure;
4546newaxes=copyobj(handles.axes3,hfig);
4547map=colormap(handles.axes3);
4548colormap(map);%transmit the current colormap to the zoom fig
4549colorbar
4550
4551
4552% --------------------------------------------------------------------
4553function Insert_Callback(hObject, eventdata, handles)
4554
4555
4556% --------------------------------------------------------------------
4557function MenuHelp_Callback(hObject, eventdata, handles)
4558% --------------------------------------------------------------------
4559path_to_uvmat=which ('uvmat');% check the path of uvmat
4560pathelp=fileparts(path_to_uvmat);
4561helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
4562if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
4563else
4564    addpath (fullfile(pathelp,'uvmat_doc'))
4565    web(helpfile);
4566end
4567
4568
4569% --------------------------------------------------------------------
4570function MenuExportMovie_Callback(hObject, eventdata, handles)
4571% --------------------------------------------------------------------
4572set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
4573huvmat=get(handles.run0,'parent');
4574UvData=get(huvmat,'UserData');
4575[xx,xx,FileBase]=read_file_boxes(handles);
4576 %read the current input file name
4577prompt = {'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)'};
4578dlg_title = 'select properties of the output avi movie';
4579num_lines= 1;
4580% nbfield_cell=get(handles.last_i,'String');
4581def     = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
4582answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
4583aviname=answer{1};
4584fps=str2double(answer{2});
4585% check for existing file with output name aviname
4586if exist(aviname,'file')
4587    backup=aviname;
4588    testexist=2;
4589    while testexist==2
4590        backup=[backup '~'];
4591        testexist=exist(backup,'file');     
4592    end
4593    [success,message]=copyfile(aviname,backup);%make backup of the existing file
4594    if isequal(success,1)
4595        delete(aviname)%delete existing file
4596    else
4597        msgbox_uvmat('ERROR',message)
4598        return
4599    end
4600end
4601%create avi open
4602aviobj=avifile(aviname,'Compression','None','fps',fps);
4603
4604%display first view for tests
4605newfig=figure;
4606newaxes=copyobj(handles.axes3,newfig);%new plotting axes in the new figure
4607set(newaxes,'Tag','movieaxes')
4608nbpix=[512 384]*str2double(answer{3});
4609set(gcf,'Position',[1 1 nbpix])% resolution XVGA
4610set(newaxes,'Position',eval(answer{4}));
4611map=colormap(handles.axes3);
4612colormap(map);%transmit the current colormap to the zoom fig
4613msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
4614        ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
4615UvData.Object{1}.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
4616set(huvmat,'UserData',UvData);
4617increment=str2double(get(handles.increment_scan,'String')); %get the field increment d
4618if isnan(increment)
4619    set(handles.increment_scan,'String','1')%default value
4620    increment=1;
4621end
4622set(handles.STOP,'Visible','on')
4623set(handles.speed,'Visible','on')
4624set(handles.speed_txt,'Visible','on')
4625set(handles.Movie,'BusyAction','queue')
4626
4627%imin=str2double(get(handles.i1,'String'));
4628imax=str2double(answer{5});
4629% if isfield(UvData,'Time')
4630htitle=get(newaxes,'Title');
4631xlim=get(newaxes,'XLim');
4632ylim=get(newaxes,'YLim');
4633set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
4634time_str=get(handles.abs_time,'String');
4635set(htitle,'String',['t=' time_str])
4636set(handles.speed,'Value',1)
4637for i=1:imax
4638    if get(handles.speed,'Value')~=0 && isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
4639            runpm(hObject,eventdata,handles,increment)% run plus
4640            drawnow
4641            time_str=get(handles.abs_time,'String');
4642            if ishandle(htitle)
4643             set(htitle,'String',['t=' time_str])
4644            end
4645            mov=getframe(newfig);
4646            aviobj=addframe(aviobj,mov);
4647    end
4648end
4649close(aviobj);
4650UvData.Object{1}.plotaxes=handles.axes3;
4651set(huvmat,'UserData',UvData);
4652msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
4653
4654
4655% ------------------------------------------------------------------
4656function MenuCalib_Callback(hObject, eventdata, handles)
4657%geometry_calib; %display the GUI as a  waiting display
4658
4659UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4660
4661%suppress competing options
4662set(handles.zoom,'Value',0)
4663set(handles.zoom,'BackgroundColor',[0.7 0.7 0.7])
4664% set(handles.MenuMask,'enable','off')
4665% set(handles.MenuGrid,'enable','off')
4666% set(handles.MenuObject,'enable','off')
4667% set(handles.MenuEdit,'enable','off')
4668set(handles.list_object_1,'Value',1)     
4669% initiate display of GUI geometry_calib
4670data=[]; %default
4671if isfield(UvData,'CoordType')
4672    data.CoordType=UvData.CoordType;
4673end
4674pos=get(handles.uvmat,'Position');
4675pos(1)=pos(1)+pos(3)-0.311+0.04; %0.311= width of the geometry_calib interface (units relative to the srcreen)
4676pos(2)=pos(2)-0.02;
4677[FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
4678set(handles.view_xml,'Backgroundcolor',[1 1 0])%indicate the reading of the current xml file by geometry_calib
4679if isfield(UvData,'CalOrigin')
4680    pos_uvmat=get(handles.uvmat,'Position');
4681    pos_cal(1)=pos_uvmat(1)+UvData.CalOrigin(1)*pos_uvmat(3);
4682    pos_cal(2)=pos_uvmat(2)+UvData.CalOrigin(2)*pos_uvmat(4);
4683    pos_cal(3:4)=UvData.CalSize .* pos_uvmat(3:4);
4684    %set(UvData.hset_object,'Position',pos_cal)
4685end
4686geometry_calib(FileName,pos_cal);% call the geometry_calib interface   
4687set(handles.view_xml,'Backgroundcolor',[1 1 1])%indicate the end of reading of the current xml file by geometry_calib
4688set(handles.MenuCalib,'checked','on')% indicate that MenuCalib is activated, test used by mouse action
4689
4690%UvData.MouseAction='calib';
4691% set(handles.uvmat,'UserData',UvData);
4692
4693
4694% ------------------------------------------------------------------
4695function MenuMask_Callback(hObject, eventdata, handles)
4696UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4697ListObj=UvData.Object;
4698select=zeros(1,numel(ListObj));
4699for iobj=1:numel(ListObj);
4700    if strcmp(ListObj{iobj}.ProjMode,'mask_inside')||strcmp(ListObj{iobj}.ProjMode,'mask_outside')
4701        select(iobj)=1;
4702    end
4703end
4704val=find(select);
4705if isempty(val)
4706    msgbox_uvmat('ERROR','polygons must be first created by Projection object/mask polygon in the menu bar');
4707    return
4708else
4709    set(handles.list_object_1,'Max',2);%allow multiple selection
4710    set(handles.list_object_1,'Value',val);
4711    flag=1;
4712    npx=size(UvData.Field.A,2);
4713    npy=size(UvData.Field.A,1);
4714    xi=0.5:npx-0.5;
4715    yi=0.5:npy-0.5;
4716    [Xi,Yi]=meshgrid(xi,yi);
4717    if isfield(UvData,'Object')
4718        for iobj=1:length(UvData.Object)
4719            ObjectData=UvData.Object{iobj};
4720            if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
4721                flagobj=1;
4722                testphys=0; %coordinates in pixels by default
4723                if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
4724                    if isfield(UvData,'XmlData')&& isfield(UvData.XmlData,'GeometryCalib')
4725                        Calib=UvData.XmlData.GeometryCalib;
4726                        testphys=1;
4727                    end
4728                end
4729                if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
4730                    if isequal(ObjectData.Style,'polygon')
4731                        X=ObjectData.Coord(:,1);
4732                        Y=ObjectData.Coord(:,2);
4733                        if testphys
4734                            [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
4735                        end
4736                        flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside
4737                    elseif isequal(ObjectData.Style,'ellipse')
4738                        if testphys
4739                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4740                        end
4741                        RangeX=max(ObjectData.RangeX);
4742                        RangeY=max(ObjectData.RangeY);
4743                        X2Max=RangeX*RangeX;
4744                        Y2Max=RangeY*RangeY;
4745                        distX=(Xi-ObjectData.Coord(1,1));
4746                        distY=(Yi-ObjectData.Coord(1,2));
4747                        flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
4748                    elseif isequal(ObjectData.Style,'rectangle')
4749                        if testphys
4750                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4751                        end
4752                        distX=abs(Xi-ObjectData.Coord(1,1));
4753                        distY=abs(Yi-ObjectData.Coord(1,2));
4754                        flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
4755                    end
4756                    if isequal(ObjectData.ProjMode,'mask_outside')
4757                        flagobj=~flagobj;
4758                    end
4759                    flag=flag & flagobj;
4760                end
4761            end
4762        end
4763    end
4764    % flag=~flag;
4765    %mask name
4766    RootPath=get(handles.RootPath,'String');
4767    RootFile=get(handles.RootFile,'String');
4768    if ~isempty(RootFile)&(isequal(RootFile(1),'/')| isequal(RootFile(1),'\'))
4769        RootFile(1)=[];
4770    end
4771    filebase=fullfile(RootPath,RootFile);
4772    list=get(handles.masklevel,'String');
4773    masknumber=num2str(length(list));
4774    maskindex=get(handles.masklevel,'Value');
4775    mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
4776    imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
4777    imflag=flipdim(imflag,1);
4778
4779    %display the mask
4780    figure;
4781    vec=linspace(0,1,256);%define a linear greyscale colormap
4782    map=[vec' vec' vec'];
4783    colormap(map)
4784    image(imflag);
4785    answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name);
4786    if ~strcmp(answer,'Cancel')
4787        mask_dir=fileparts(answer);
4788        if ~exist(mask_dir,'dir')
4789            msgbox_uvmat('ERROR',['directory ' mask_dir ' does not exist'])
4790            return
4791        end
4792        imwrite(imflag,answer,'BitDepth',8);
4793    end
4794    set(handles.list_object_1,'Value',1)
4795    set(handles.list_object_1,'Max',1)
4796end
4797
4798%set(handles.uvmat,'UserData',UvData);
4799
4800% ------------------------------------------------------------------
4801%-- open the GUI set_grid.fig to create grid
4802function MenuGrid_Callback(hObject, eventdata, handles)
4803%UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4804
4805%suppress the other options if grid is chosen
4806set(handles.edit_vect,'Value',0)
4807edit_vect_Callback(hObject, eventdata, handles)
4808set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
4809set(handles.list_object_1,'Value',1)     
4810
4811%prepare display of the set_grid GUI
4812FileName=read_file_boxes(handles);
4813CoordList=get(handles.transform_fct,'String');
4814val=get(handles.transform_fct,'Value');
4815set_grid(FileName,CoordList{val});% call the set_object interface
4816%set(handles.uvmat,'UserData',UvData);
4817
4818%----------------------------------------------------------------
4819% open the GUI 'series'
4820%----------------------------------------------------------------
4821function MenuSeries_Callback(hObject, eventdata, handles)
4822%-------------------------------------------------------------------
4823series; %first display of the GUI to fill waiting time
4824[param.FileName]=read_file_boxes(handles);
4825if isequal(get(handles.SubField,'Value'),1)
4826    FileName_1=read_file_boxes_1(handles);%
4827    if ~isequal(FileName_1,param.FileName)
4828        param.FileName_1=FileName_1;
4829    end
4830end
4831param.NomType=get(handles.FileIndex,'UserData');
4832param.NomType_1=get(handles.FileIndex_1,'UserData');
4833param.comp_input=get(handles.fix_pair,'Value');
4834huvmat=get(handles.MenuSeries,'parent');
4835UvData=get(huvmat,'UserData');
4836if isfield(UvData,'Time')
4837    param.Time=UvData.XmlData.Time;
4838end
4839if isequal(get(handles.scan_i,'Value'),1)
4840    param.incr_i=str2double(get(handles.increment_scan,'String'));
4841elseif isequal(get(handles.scan_j,'Value'),1)
4842    param.incr_j=str2double(get(handles.increment_scan,'String'));
4843end
4844param.list_fields=get(handles.Fields,'String');% list menu fields
4845param.list_fields(1)=[]; %suppress  'image' option
4846param.index_fields=get(handles.Fields,'Value');% selected string index
4847if param.index_fields>1
4848    param.index_fields=param.index_fields-1;
4849end
4850param.list_fields_1=get(handles.Fields_1,'String');% list menu fields
4851param.list_fields_1(1)=[]; %suppress  'image' option
4852param.index_fields_1=get(handles.Fields_1,'Value')-1;% selected string index
4853if param.index_fields_1>1
4854    param.index_fields_1=param.index_fields_1-1;
4855end
4856param.civ1=get(handles.civ1,'Value');
4857param.civ2=get(handles.civ2,'Value');
4858param.interp1=get(handles.interp1,'Value');
4859param.interp2=get(handles.interp2,'Value');
4860param.filter1=get(handles.filter1,'Value');
4861param.filter2=get(handles.filter2,'Value');
4862param.menu_coord_str=get(handles.transform_fct,'String');
4863param.menu_coord_val=get(handles.transform_fct,'Value');
4864
4865series(param); %run the series interface
4866
4867% ------------------------------------------------------------------
4868% -- open the GUI civ.fig for civx (PIV)
4869% ------------------------------------------------------------------
4870function MenuPIV_Callback(hObject, eventdata, handles)
4871 
4872[FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles);
4873num1=stra2num(get(handles.i1,'String'));
4874num2=stra2num(get(handles.i2,'String'));
4875num_a=stra2num(get(handles.j1,'String'));
4876num_b=stra2num(get(handles.j2,'String'));
4877NomType=get(handles.FileIndex,'UserData');
4878ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
4879if isequal(ext,'.nc') ||  isequal(ext,'.cdf')% netcdf files
4880    ind_opening=2;% propose 'fix' as the default option
4881% +read the current netcdf rootfile
4882    Data=nc2struct(FileName,'ListGlobalAttribute','fix','patch','civ2','fix2');
4883    if isfield(Data,'fix') && isequal(Data.fix,1)
4884        ind_opening=3;
4885    end
4886    if isfield(Data,'patch') && isequal(Data.patch,1)
4887        ind_opening=4;
4888    end
4889    if isfield(Data,'civ2') && isequal(Data.civ2,1)
4890        ind_opening=5;
4891    end
4892    if isfield(Data,'fix2') && isequal(Data.fix2,1)
4893        ind_opening=6;
4894    end
4895end     
4896param.RootName=filebase;
4897param.NomType=NomType;
4898param.num1=num1;
4899param.num2=num2;
4900param.num_a=num_a;
4901param.num_b=num_b;
4902param.SubDir=SubDir;
4903param.IndOpening=ind_opening;% A REVOIR +TRANSMETTRE IMADOC INFO
4904param.ImaExt=ext;
4905civ(param);% interface de civ(not in the uvmat file)
4906   
4907% ------------------------------------------------------------------
4908function MenuTools_Callback(hObject, eventdata, handles)
4909
4910% ------------------------------------------------------------------
4911function MenuEditObject_Callback(hObject, eventdata, handles)
4912set(handles.edit_object,'Value',1)
4913edit_Callback(hObject, eventdata, handles)
4914
4915%--------------------------------------------------------------------------
4916function enable_transform(handles,state)
4917set(handles.transform_fct,'Visible',state)
4918set(handles.TRANSFORM_txt,'Visible',state)   
4919set(handles.transform_fct,'Visible',state) 
4920set(handles.path_transform,'Visible',state)
4921set(handles.pxcmx_txt,'Visible',state)
4922set(handles.pxcmy_txt,'Visible',state)
4923set(handles.pxcm,'Visible',state)
4924set(handles.pycm,'Visible',state)
4925
4926%------------------------------------------------------------------------
4927function MenuEditVectors_Callback(hObject, eventdata, handles)
4928%------------------------------------------------------------------------
4929% set(handles.MenuEditVectors,'checked','on')
4930set(handles.edit_vect,'Visible','on')
4931set(handles.edit_vect,'Value',1)
4932edit_vect_Callback(hObject, eventdata, handles)
4933
4934% --------------------------------------------------------------------
4935function Menupoints_Callback(hObject, eventdata, handles)
4936data.Style='points';
4937data.ProjMode='projection';%default
4938create_object(data,handles)
4939
4940% --------------------------------------------------------------------
4941function Menuline_Callback(hObject, eventdata, handles)
4942% set(handles.create,'Visible','on')
4943% set(handles.create,'Value',1)
4944% LINE_Callback(hObject,eventdata,handles)
4945data.Style='line';
4946data.ProjMode='projection';%default
4947create_object(data,handles)
4948
4949%------------------------------------------------------------------------
4950function Menupolyline_Callback(hObject, eventdata, handles)
4951%------------------------------------------------------------------------
4952data.Style='polyline';
4953data.ProjMode='projection';%default
4954create_object(data,handles)
4955
4956%------------------------------------------------------------------------
4957function Menupolygon_Callback(hObject, eventdata, handles)
4958%------------------------------------------------------------------------
4959data.Style='polygon';
4960data.ProjMode='inside';%default
4961create_object(data,handles)
4962
4963%------------------------------------------------------------------------
4964function Menurectangle_Callback(hObject, eventdata, handles)
4965%------------------------------------------------------------------------
4966data.Style='rectangle';
4967data.ProjMode='inside';%default
4968create_object(data,handles)
4969
4970%------------------------------------------------------------------------
4971function Menuellipse_Callback(hObject, eventdata, handles)
4972%------------------------------------------------------------------------
4973data.Style='ellipse';
4974data.ProjMode='inside';%default
4975create_object(data,handles)
4976
4977%------------------------------------------------------------------------
4978function MenuMaskObject_Callback(hObject, eventdata, handles)
4979%------------------------------------------------------------------------
4980data.Style='polygon';
4981data.StyleMenu={'polygon'};
4982data.ProjMode='mask_inside';%default
4983data.ProjMenu={'mask_inside';'mask_outside'};
4984create_object(data,handles)
4985
4986% ------------------------------------------------------------------
4987function Menuplane_Callback(hObject, eventdata, handles)
4988data.Style='plane';
4989data.ProjMode='projection';%default
4990
4991create_object(data,handles)
4992
4993% ------------------------------------------------------------------
4994function Menuvolume_Callback(hObject, eventdata, handles)
4995data.Style='volume';
4996data.ProjMode='interp';%default
4997% set(handles.create,'Visible','on')
4998% set(handles.create,'Value',1)
4999% VOLUME_Callback(hObject,eventdata,handles)
5000create_object(data,handles)
5001
5002%------------------------------------------------------------------------
5003function MenuBrowseObject_Callback(hObject, eventdata, handles)
5004%------------------------------------------------------------------------
5005%get the object file
5006[FileName, PathName, filterindex] = uigetfile( ...
5007       {'*.xml;*.mat', ' (*.xml,*.mat)';
5008       '*.xml',  '.xml files '; ...
5009        '*.mat',  '.mat matlab files '}, ...
5010        'Pick an xml Object file',get(handles.RootPath,'String'));
5011fileinput=[PathName FileName];%complete file name
5012testblank=findstr(fileinput,' ');%look for blanks
5013if ~isempty(testblank)
5014    msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
5015    return
5016end
5017sizf=size(fileinput);
5018if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
5019
5020%read the file
5021t=xmltree(fileinput);
5022data=convert(t);
5023data.enable_plot=1;
5024[pp,data.Name]=fileparts(FileName);
5025%PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
5026hset_object=findobj(allchild(0),'tag','set_object');
5027if ~isempty(hset_object)
5028    delete(hset_object)% delete existing version of set_object
5029end
5030% UvData=get(handles.uvmat,'UserData');
5031set_object(data);% call the set_object interface
5032% %position the set_object GUI with respect to uvmat
5033% pos_uvmat=get(handles.uvmat,'Position');
5034% if isfield(UvData,'SetObjectOrigin')
5035%     pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
5036%     pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
5037%     set(hset_object,'Position',pos_set_object)
5038% end
5039set(handles.edit_object,'Value',0); %suppress the object edit mode
5040set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) 
5041set(handles.MenuObject,'checked','on')
5042%UvData.MouseAction='create_object';
5043% set(handles.uvmat,'UserData',UvData)
5044set(handles.delete_object,'Visible','on')
5045set(handles.uvmat_title,'Visible','on')
5046set(handles.view_field_title,'Visible','on')
5047
5048%------------------------------------------------------------------------
5049% --- generic function used for the creation of a projection object
5050function create_object(data,handles)
5051%------------------------------------------------------------------------
5052hset_object=findobj(allchild(0),'tag','set_object');
5053if ~isempty(hset_object)
5054    delete(hset_object)% delete existing version of set_object
5055end
5056UvData=get(handles.uvmat,'UserData');
5057set(handles.edit_object,'Value',0); %suppress the object edit mode
5058set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) 
5059data.enable_plot=1;
5060transform_list=get(handles.transform_fct,'String');
5061val=get(handles.transform_fct,'Value');
5062%data.CoordType=transform_list{val};
5063if isfield(UvData,'Field')
5064    Field=UvData.Field;
5065    if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
5066        data.RangeX=Field.Mesh;
5067        data.RangeY=Field.Mesh;
5068        data.DX=Field.Mesh;
5069        data.DY=Field.Mesh;
5070    elseif isfield(Field,'AX')&& isfield(Field,'AY')&& isfield(Field,'A')%only image
5071        np=size(Field.A);
5072        meshx=(Field.AX(end)-Field.AX(1))/np(2);
5073        meshy=abs(Field.AY(end)-Field.AY(1))/np(1);
5074        data.RangeY=max(meshx,meshy);
5075        data.RangeX=max(meshx,meshy);
5076        data.DX=max(meshx,meshy);
5077    end
5078    if isfield(Field,'NbDim')
5079        data.NbDim=Field.NbDim;
5080    end
5081    if isfield(Field,'CoordUnit')
5082        data.CoordUnit=Field.CoordUnit;
5083    end
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
5093if ishandle(handles.UVMAT_title)
5094    delete(handles.UVMAT_title)%delete the initial display of uvmat if no field has been entered
5095end
5096PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
5097set_object(data,PlotHandles);% call the set_object interface
5098set(handles.MenuObject,'checked','on')
5099set(handles.uvmat,'UserData',UvData)
5100set(handles.zoom,'Value',0)
5101zoom_Callback(handles.uvmat, [], handles)
5102set(handles.delete_object,'Visible','on')
5103set(handles.uvmat_title,'Visible','on')
5104set(handles.view_field_title,'Visible','on')
5105
5106%------------------------------------------------------------------------
5107function MenuRuler_Callback(hObject, eventdata, handles)
5108%------------------------------------------------------------------------
5109set(handles.zoom,'Value',0)
5110zoom_Callback(handles.uvmat, [], handles)
5111set(handles.MenuRuler,'checked','on')
5112UvData=get(handles.uvmat,'UserData');
5113UvData.MouseAction='ruler';
5114set(handles.uvmat,'UserData',UvData);
5115
5116%------------------------------------------------------------------------
5117% --- executed when closing: set the parent interface button to value 0
5118function closefcn(gcbo,eventdata)
5119%------------------------------------------------------------------------
5120%delete all the associated figures if exist
5121hh=findobj(allchild(0),'tag','view_field');
5122if ~isempty(hh)
5123    delete(hh)
5124end
5125hh=findobj(allchild(0),'tag','geometry_calib');
5126if ~isempty(hh)
5127    delete(hh)
5128end
5129hh=findobj(allchild(0),'tag','set_object');
5130if ~isempty(hh)
5131    hhh=findobj(hh,'tag','PLOT');
5132    set(hhh,'enable','off')
5133end
5134
5135
5136% --- Executes on button press in delete_object.
5137function delete_object_Callback(hObject, eventdata, handles)
5138IndexObj=get(handles.list_object_2,'Value');
5139    if IndexObj>1
5140        delete_object(IndexObj)
5141    end
5142   
5143
5144
5145
5146
Note: See TracBrowser for help on using the repository browser.