source: trunk/src/uvmat.m @ 398

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

find_file_series corrected and rationalised, with induced transforms in uvmat, civ, series

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