source: trunk/src/uvmat.m @ 751

Last change on this file since 751 was 750, checked in by sommeria, 11 years ago

bug corrections

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