source: trunk/src/uvmat.m @ 527

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

various bugs corrected

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