source: trunk/src/uvmat.m @ 404

Last change on this file since 404 was 404, checked in by sommeria, 9 years ago

various bugs corrected. nc2struct_toolbox suppressed (correspond to obsolete versions of Matlab)

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