source: trunk/src/uvmat.m @ 729

Last change on this file since 729 was 729, checked in by sommeria, 10 years ago

bugs repaired for line plots

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