source: trunk/src/uvmat.m @ 575

Last change on this file since 575 was 575, checked in by sommeria, 8 years ago

various bugs corrected

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