source: trunk/src/uvmat.m @ 399

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

implementation of thin plate interpolation (proj on planes with mode 'filter'), rationalisation of variable formats in civ_matlab

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