source: trunk/src/uvmat.m @ 389

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

several bugs corrected: object managing, tps filter...

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