source: trunk/src/uvmat.m @ 384

Last change on this file since 384 was 384, checked in by sommeria, 12 years ago

pb with masks corrected
bug in fileparts_uvmat corrected
find_file_series corrected so that it finds the root name corresponding tothe existing xml file : for instance Dalsa1_0001 gives root=Dalsa1 instead of Dalsa
bug corrected in uvmat, runpm (j1 and j2 set to 1 when not visible)

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