source: trunk/src/uvmat.m @ 368

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

various bugs fixed

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