source: trunk/src/uvmat.m @ 546

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

bugs corrected for tps projection on a grid + pb of colorbar display solved

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