source: trunk/src/uvmat.m @ 174

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

civ.m : clarification of .cmx : creation of .civ1.cmx and .civ2.cmx
uvmat: reading and projecting volume images (not yet successfull)

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