source: trunk/src/uvmat.m @ 397

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

civ_matlab and patch improved, changes in the management of interpolation (still in progress).
adapatation to movies (use of VideoReader?)

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