function fig=qp_interface(showUI)
%QP_INTERFACE Initialize QuickPlot user interface.

%----- LGPL --------------------------------------------------------------------
%                                                                               
%   Copyright (C) 2011-2021 Stichting Deltares.                                     
%                                                                               
%   This library is free software; you can redistribute it and/or                
%   modify it under the terms of the GNU Lesser General Public                   
%   License as published by the Free Software Foundation version 2.1.                         
%                                                                               
%   This library is distributed in the hope that it will be useful,              
%   but WITHOUT ANY WARRANTY; without even the implied warranty of               
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU            
%   Lesser General Public License for more details.                              
%                                                                               
%   You should have received a copy of the GNU Lesser General Public             
%   License along with this library; if not, see <http://www.gnu.org/licenses/>. 
%                                                                               
%   contact: delft3d.support@deltares.nl                                         
%   Stichting Deltares                                                           
%   P.O. Box 177                                                                 
%   2600 MH Delft, The Netherlands                                               
%                                                                               
%   All indications and logos of, and references to, "Delft3D" and "Deltares"    
%   are registered trademarks of Stichting Deltares, and remain the property of  
%   Stichting Deltares. All rights reserved.                                     
%                                                                               
%-------------------------------------------------------------------------------
%   http://www.deltaressystems.com
%   $HeadURL$
%   $Id$

if ischar(showUI)
    m = showUI;
    %
    mfig = findobj(allchild(0),'flat','tag','Delft3D-QUICKPLOT');
    UD = getappdata(mfig,'QPHandles');
    MW = UD.MainWin;
    %
    fpos = get(mfig,'position');
    fpos(4) = fpos(4)+30;
    fpos(2) = fpos(2)-30;
    set(mfig,'position',fpos)
    %
    ui = findall(mfig,'type','uicontrol');
    pos = get(ui,'position');
    for i = 1:length(ui)
        if ismember(ui(i),[MW.LoadData MW.DefVar MW.Add2Plot MW.QuickV])
            continue
        elseif ismember(ui(i),UD.Options.Slider)
            pos{i}(4) = pos{i}(4)+30;
            set(ui(i),'position',pos{i})
        else
            pos{i}(2) = pos{i}(2)+30;
            set(ui(i),'position',pos{i})
        end
    end
    %
    ax = findall(mfig,'type','axes');
    pos = get(ax,'pos');
    pos(4) = pos(4)+30;
    set(ax,'position',pos)
    %
    voffset = 40;
    [NameDim,AllDim,EditDim,MaxDim]=DimControls(mfig,voffset,m);
    %
    UD.MainWin.(m)          = NameDim;
    UD.MainWin.(['All'  m]) = AllDim;
    UD.MainWin.(['Edit' m]) = EditDim;
    UD.MainWin.(['Max'  m]) = MaxDim;
    setappdata(mfig,'QPHandles',UD)
    %
    update_option_positions(UD,'main',fpos(4)-30+1)
    %
    fig = {NameDim AllDim EditDim MaxDim};
    return
end
panewidth=180;

screensize=qp_getscreen;
PosUR=qp_settings('MainPositionUR',screensize(1:2)+screensize(3:4)/2+[270 200]);
dims=[339+panewidth 400];
pos(1:2)=PosUR-dims;
pos(3:4)=dims;

mfig = qp_uifigure('Delft3D-QUICKPLOT','','Delft3D-QUICKPLOT',pos);
MW.Fig = mfig;
UD.Active=qp_settings('UIActiveColor');
UD.Inactive=qp_settings('UIInActiveColor');
%=============
m1=qp_uimenu(mfig,'&File', ...
    {'openfile','&Open File...',1,1,0
    'openurl','&Open URL...',1,1,0
    'difffiles','&Diff Files...',1,1,0
    'fileinfo','File &Info',1,0,0
    'closefile','&Close File',1,0,0
    'closeallfiles','Close &All Files',1,0,0
    'openfigure','Open &Figure...',1,1,1
    'preferences','Pre&ferences...',1,1,1
    'close','E&xit',1,1,1});
%=============
m1=qp_uimenu(mfig,'&Macro', ...
    {'logfile','Record &Log File',1,1,0
    'scriptfile','Record MATLAB &Script',1,1,0
    '','Record to Message &Window',1,1,0
    'scriptfiletomcw','Record to &MATLAB Command Window',1,1,0
    'stoprecord','&Stop Recording',1,0,0
    'run','&Run Log File',1,1,1});
qp_uimenu(findobj(mfig,'tag','Record to Message &Window'), ...
    {'logfiletomw','&Log File Commands',1,1,0; ...
    'scriptfiletomw','MATLAB &Script Commands',1,1,0});
MW.StartRec=m1(2:5);
%=============
m1=qp_uimenu(mfig,'&Window', ...
    {'closeallfig','Close &All Figures',1,1,0
    'plotmngr','Show &Plot Manager',1,1,1
    'plotmngr','Hide &Plot Manager',0,1,1
    'gridview','Show &Grid View',1,1,0
    'gridview','Hide &Grid View',0,1,0
    'showmessagewin','Show &Message Window',1,1,0
    'comline','Show C&ommand Line',1,1,0
    'comline','Hide C&ommand Line',0,1,0
    'dock','Dock Plot &Options',0,1,0});
%=============
showqpm = ispc && d3d_qp('qpmanual');
showmim = ispc && ~isstandalone && d3d_qp('matlabmanual');
m1=qp_uimenu(mfig,'&Help', ...
    {'qpmanual','&QUICKPLOT manual',showqpm,1,0
    'matlabmanual','MATLAB Interface &Toolbox manual',showmim,1,0
    'deltaresweb','&Deltares Systems',1,1,showqpm || showmim
    'deltaresweboss','Deltares &Open Source',1,1,0
    'aboutmatlab','About &MATLAB',1,1,1
    'about','&About Delft3D-QUICKPLOT',1,1,1});
%=============



a0 = axes('Parent',mfig, ...
    'Visible','off', ...
    'Units','pixels', ...
    'Position',[1 1 dims], ...
    'Xlim',[1 dims(1)], ...
    'Ylim',[1 dims(2)]);

offset=350;
width=panewidth-36;
l1=line(offset-10+[1 1],[0 dims(2)],[0 0],'color',[1 1 1],'parent',a0);
l2=line(offset-10+[0 0],[0 dims(2)],[0 0],'color',[128 128 128]/255,'parent',a0);

UD.State=qp_state_startup;
MW.TB = uitoolbar('Parent',mfig);
%=============
MW.RFl = qp_toolbarpush(MW.TB,'reloadfile',0,'Reload the selected data file');
MW.OFl = qp_toolbarpush(MW.TB,'openfile',0,'Open a data file');
MW.CFl = qp_toolbarpush(MW.TB,'closefile',0,'Close the selected data file');
MW.FlOps = qp_toolbartoggle(MW.TB,'fileoptions',0,'Set file dependent options');
set([MW.RFl MW.CFl MW.FlOps],'enable','off')
set(MW.OFl,'userdata','')
%=============
MW.OpnFig = qp_toolbarpush(MW.TB,'openfigure',1,'Load a figure from file');
%=============
MW.TB_CL = qp_toolbartoggle(MW.TB,'comline',1,'Show/hide command line');
MW.RecTB(1) = qp_toolbarpush(MW.TB,'logfile',0,'Record a macro/log file');
MW.RecTB(2) = qp_toolbarpush(MW.TB,'scriptfile',0,'Record a MATLAB script file');
MW.StopRec = qp_toolbarpush(MW.TB,'stoprecord',0,'Stop recording');
MW.Run = qp_toolbarpush(MW.TB,'run',0,'Run a macro/log file');
MW.Rerun = qp_toolbarpush(MW.TB,'rerun',0,'Run previous macro/log file again');
set(MW.StopRec,'enable','off')
set(MW.Rerun,'enable','off')
%=============
MW.TB_PM = qp_toolbartoggle(MW.TB,'plotmngr',1,'Show/hide plot manager');
MW.TB_GV = qp_toolbartoggle(MW.TB,'gridview',0,'Show/hide grid view');

voffset=dims(2)-29;
MW.File = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp selectfile', ...
    'Enable','off', ...
    'Position',[11 voffset 320 20], ...
    'String',' ', ...
    'Style','popupmenu', ...
    'Tag','selectfile', ...
    'Value',1);

voffset=voffset-30;
MW.D = uicontrol('Parent',mfig, ...
    'Enable','off', ...
    'Position',[11 voffset 50 18], ...
    'String','Domain', ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'Tag','domain');
MW.DList = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp selectdomain', ...
    'Enable','off', ...
    'Position',[81 voffset 250 20], ...
    'Style','popupmenu', ...
    'Tag','selectdomain', ...
    'String',' ', ...
    'Value',1);

voffset=voffset-30;
MW.Field = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp selectfield', ...
    'Enable','off', ...
    'Position',[11 voffset 320 20], ...
    'String',' ', ...
    'Style','popupmenu', ...
    'Tag','selectfield', ...
    'Value',1);

voffset=voffset-30;
MW.SubFldTxt = uicontrol('Parent',mfig, ...
    'Enable','off', ...
    'Position',[11 voffset 50 18], ...
    'String','Subfield', ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'Tag','subfield');
MW.SubFld = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp selectsubfield', ...
    'Enable','off', ...
    'Position',[81 voffset 250 20], ...
    'Style','popupmenu', ...
    'Tag','selectsubfield', ...
    'String',' ', ...
    'Value',1);

voffset=voffset-30;
[MW.T,MW.AllT,MW.EditT,MW.MaxT]=DimControls(mfig,voffset,'t');
set(MW.T,'string','Time Step')

voffset=voffset-30;
MW.TZtxt = uicontrol('Parent',mfig, ...
    'Enable','off', ...
    'Position',[11 voffset 100 20], ...
    'String','Time Zone', ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'Tag','timezone');
voffset=voffset-20;
MW.TZdata = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp selecttimezone', ...
    'Enable','off', ...
    'Position',[11 voffset 100 20], ...
    'String','unknown', ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'Tag','datatimezone');
voffset=voffset-40;
MW.ShowT = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp showtimeswitch', ...
    'Enable','off', ...
    'Position',[11 voffset 100 20], ...
    'String','Show Times', ...
    'Style','checkbox', ...
    'Tag','showtimes');
MW.TList = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp timelist', ...
    'Enable','off', ...
    'Max',2, ...
    'Position',[121 voffset 210 80], ...
    'Style','listbox', ...
    'Tag','timelist', ...
    'UserData',0, ...
    'Value',[]);

voffset=voffset-30;
[MW.S,MW.AllS,MW.EditS,MW.MaxS]=DimControls(mfig,voffset,'s');
set(MW.S,'string','Station','tag','station')
MW.StList = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp station', ...
    'Enable','off', ...
    'ListboxTop',0, ...
    'Position',[121 voffset 210 20], ...
    'String',' ', ...
    'Style','popupmenu', ...
    'Tag','stationlist', ...
    'Value',1);
MW.Stat=[MW.S,MW.AllS,MW.EditS,MW.MaxS,MW.StList];

%===== M,N,K,X,Y,Z select
%voffset=voffset-30;
set(MW.Stat,'visible','off')
MW.HSelType=uicontrol('Parent',mfig, ...
    'Callback','d3d_qp hselectiontype', ...
    'Enable','off', ...
    'Position',[11 voffset 155 20], ...
    'String',{'M range and N range','(M,N) point/path','(X,Y) point/path'}, ...
    'Style','popupmenu', ...
    'Tag','hselectiontype', ...
    'Value',1);
MW.VSelType=uicontrol('Parent',mfig, ...
    'Callback','d3d_qp vselectiontype', ...
    'Enable','off', ...
    'Position',[176 voffset 155 20], ...
    'String',{'K range','Z slice','dZ below surface','dZ above bed','depth percentage'}, ...
    'Style','popupmenu', ...
    'Tag','vselectiontype', ...
    'Value',1);

voffset=voffset-30;
MW.MN = uicontrol('Parent',mfig, ...
    'Enable','off', ...
    'Visible','off', ...
    'Position',[11 voffset 30 20], ...
    'String','M,N', ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'Tag','MN');
MW.MNrev = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp reverseMN', ...
    'Enable','on', ...
    'Visible','off', ...
    'Position',[46 voffset-5 25 25], ...
    'Style','pushbutton', ...
    'CData',qp_icon('reversemn','nan'), ...
    'Tag','ReverseMNpath');
qp_tooltip(MW.MNrev,'Reverse M,N path')
MW.EditMN = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp editMN', ...
    'Enable','off', ...
    'Visible','off', ...
    'Max',2, ...
    'HorizontalAlignment','left', ...
    'Position',[81 voffset-30 210 50], ...
    'Style','edit', ...
    'Tag','MN=?');
MW.MN2XY = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp convertMN2XY', ...
    'Enable','on', ...
    'Visible','off', ...
    'Position',[11 voffset-30 25 25], ...
    'Style','pushbutton', ...
    'CData',qp_icon('convertmn','nan'), ...
    'Tag','ConvertMN2XY');
qp_tooltip(MW.MN2XY,'Convert M,N (or M) index path to X,Y path')
MW.MN2M = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp convertMN2M', ...
    'Enable','on', ...
    'Visible','off', ...
    'Position',[46 voffset-30 25 25], ...
    'Style','pushbutton', ...
    'CData',qp_icon('convertmn2m','nan'), ...
    'Tag','ConvertMN2Mrange');
qp_tooltip(MW.MN2XY,'Copy M index path to plain M index (losing selection order)')
%
MW.XY = uicontrol('Parent',mfig, ...
    'Enable','off', ...
    'Visible','off', ...
    'Position',[11 voffset 60 20], ...
    'String','X,Y', ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'Tag','XY');
MW.LoadXY = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp loadXY', ...
    'Enable','on', ...
    'Visible','off', ...
    'Position',[11 voffset-30 25 25], ...
    'Style','pushbutton', ...
    'CData',qp_icon('openfigure','nan'), ...
    'Tag','LoadXY');
MW.SaveXY = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp saveXY', ...
    'Enable','off', ...
    'Visible','off', ...
    'Position',[46 voffset-30 25 25], ...
    'Style','pushbutton', ...
    'CData',qp_icon('savefigure','nan'), ...
    'Tag','SaveXY');
MW.EditXY = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp editXY', ...
    'Enable','off', ...
    'Visible','off', ...
    'Max',2, ...
    'HorizontalAlignment','left', ...
    'Position',[81 voffset-30 250 50], ...
    'Style','edit', ...
    'Tag','XY=?');
[MW.M,MW.AllM,MW.EditM,MW.MaxM]=DimControls(mfig,voffset,'m');

voffset=voffset-30;
[MW.N,MW.AllN,MW.EditN,MW.MaxN]=DimControls(mfig,voffset,'n');

voffset=voffset-30;
MW.Z = uicontrol('Parent',mfig, ...
    'Enable','off', ...
    'Visible','off', ...
    'Position',[11 voffset 60 20], ...
    'String','Z', ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'Tag','Z');
MW.EditZ = uicontrol('Parent',mfig, ...
    'Callback','d3d_qp editZ', ...
    'Enable','off', ...
    'Visible','off', ...
    'HorizontalAlignment','left', ...
    'Position',[81 voffset 250 20], ...
    'Style','edit', ...
    'Tag','Z=?');
[MW.K,MW.AllK,MW.EditK,MW.MaxK]=DimControls(mfig,voffset,'k');

if 0,
    voffset=voffset-30;
    MW.PName = uicontrol('Parent',mfig, ...
        'Enable','off', ...
        'Position',[11 voffset 90 20], ...
        'String','name', ...
        'Style','text', ...
        'Horizontalalignment','left', ...
        'Tag','plotname');
    MW.PNameEdit = uicontrol('Parent',mfig, ...
        'Callback','d3d_qp setname', ...
        'Enable','off', ...
        'Position',[71 voffset 240 20], ...
        'String','', ...
        'Style','edit', ...
        'Tag','setname');
    MW.PNameEdit = uicontrol('Parent',mfig, ...
        'Callback','d3d_qp autosetname', ...
        'Enable','off', ...
        'Position',[311 voffset 20 20], ...
        'String','...', ...
        'Style','pushbutton', ...
        'Tag','autosetname');
end

voffset=voffset-30;
MW.LoadData = LocButton(mfig,[11 voffset 70 20],'loaddata','Load Data',0, ...
    {'Load selected data into the variable ''data''','in Matlab''s base workspace'});
MW.DefVar   = LocButton(mfig,[91 voffset 70 20],'defvariable','Define Var.',0, ...
    'Define a variable based on current settings');
MW.Add2Plot = LocButton(mfig,[171 voffset 70 20],'addtoplot','Add to Plot',0, ...
    'Add plot to the active axes (see Plot Manager)');
MW.Add2PlotMenu = uicontextmenu('parent',MW.Fig);
qp_uimenu(MW.Add2PlotMenu, ...
    {'addtoplot_left','Add to Left Y Axis',1,1,0
    'addtoplot_right','Add to Right Y Axis',1,1,0});
MW.QuickV   = LocButton(mfig,[251 voffset 80 20],'quickview','Quick View',0,'Plot selected data');
UD.MainWin=MW;

%
% options ...
%
UD.Options = AddOptions(mfig,dims,offset,width,UD,true);
%
% ------ plot manager ...
%
%panewidth = 0;
PMsize = [445 400]+[panewidth 0];
PMsizeMin = [445 190]+[panewidth 0];
pos=[qp_settings('PlotMngrPositionUL',screensize(1:2)+screensize(3:4)/2+PMsize/2) PMsize];
pos(2)=pos(2)-pos(4);
%
ArrowActive=repmat(reshape(UD.Inactive,[1 1 3]),[16,16,1]);
ArrowInactive=repmat(reshape(UD.Inactive,[1 1 3]),[16,16,1]);
ArrowActive(8:14,7:10,:)=0;
ArrowInactive(8:14,7:10,:)=0.5;
for i=1:6
    ArrowActive(2+i,(9-i):(8+i),:)=0;
    ArrowInactive(2+i,(9-i):(8+i),:)=0.5;
end
%
PM.CurrentAxes = [];
PM.Fig = qp_uifigure('Plot Manager','hideplotmngr','Plot Manager',pos);
set(PM.Fig,'resize','on','resizefcn','d3d_qp plotmanagerresize')
setappdata(PM.Fig,'FigureSize',PMsize);
setappdata(PM.Fig,'MinimumFigureSize',PMsizeMin);
%=============
m1=qp_uimenu(PM.Fig,'&File', ...
    {'openfigure','&Open Figure...',1,1,0
    'closeallfig','Close &All Figures',1,1,0
    'hideplotmngr','&Close',1,1,1});
%=============
PM.TB = uitoolbar('Parent',PM.Fig);
%
PM.NewFig = qp_toolbarpush(PM.TB,'newfigure',0,'Create a new figure');
PM.OpnFig = qp_toolbarpush(PM.TB,'openfigure',0,'Load a figure from file');
PM.SavFig = qp_toolbarpush(PM.TB,'savefigure',0,'Save a figure to a MATLAB fig file');
PM.FigOpt = qp_toolbarpush(PM.TB,'figureoptions',0,'Set figure options');
PM.ClsFig = qp_toolbarpush(PM.TB,'closefigure',0,'Close active figure (without confirmation)');
set([PM.SavFig PM.FigOpt PM.ClsFig],'enable','off');
%
PM.Separator = axes('Parent',PM.Fig, ...
    'Visible','off', ...
    'Units','pixels', ...
    'Position',[1 1 PMsize], ...
    'Xlim',[1 PMsize(1)], ...
    'Ylim',[1 PMsize(2)]);

offset=PMsize(1)-panewidth+10;
line(offset-10+[1 1],[0 PMsize(2)],[0 0],'color',[1 1 1],'parent',PM.Separator);
line(offset-10+[0 0],[0 PMsize(2)],[0 0],'color',[128 128 128]/255,'parent',PM.Separator);
%
Top = PMsize(2)-10;
Width = PMsize(1)-60-45-panewidth;
PM.FigTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Top-20 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Figure');
PM.FigList = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Top-20 Width 20], ...
    'String',{' '}, ...
    'Style','popupmenu', ...
    'Tag','selectfigure', ...
    'Callback','d3d_qp selectfigure', ...
    'Enable','off', ...
    'Value',1);
PM.FigAll = uicontrol('Parent',PM.Fig, ...
    'Position',[65+Width Top-20 35 20], ...
    'String','All', ...
    'Style','checkbox', ...
    'Tag','allfigures', ...
    'Callback','d3d_qp allfigures', ...
    'Enable','off', ...
    'Value',0);
%
PM.NewAx = qp_toolbarpush(PM.TB,'newaxes',1,'Add new axes to active figure');
PM.NewAxMenu = uicontextmenu('parent',PM.Fig);
qp_uimenu(PM.NewAxMenu, ...
    {'newaxes_oneplot','One Big Plot',1,1,0
    'newaxes_matrix','Matrix of Plots',1,1,0
    'newaxes_specloc','Plot at Specific Location',1,1,0});
PM.AxOpt = qp_toolbarpush(PM.TB,'axesoptions',0,'Set axes options');
PM.DelAx = qp_toolbarpush(PM.TB,'deleteaxes',0,'Delete active axes (without confirmation)');
set([PM.NewAx PM.AxOpt PM.DelAx],'enable','off');
%
PM.AxTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Top-50 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Axes');
PM.AxList = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Top-50 Width 20], ...
    'String',' ', ...
    'Style','popupmenu', ...
    'Tag','selectaxes', ...
    'Callback','d3d_qp selectaxes', ...
    'Enable','off', ...
    'Value',1);
PM.AxAll = uicontrol('Parent',PM.Fig, ...
    'Position',[Width+65 Top-50 35 20], ...
    'String','All', ...
    'Style','checkbox', ...
    'Tag','allaxes', ...
    'Callback','d3d_qp allaxes', ...
    'Enable','off', ...
    'Value',0);
%
PM.DelIt = qp_toolbarpush(PM.TB,'deleteitems',1,'Delete items (without confirmation)');
PM.ItInfo = qp_toolbarpush(PM.TB,'iteminfo',0,'Get some extra information on the selected item');
PM.ItLink = qp_toolbarpush(PM.TB,'linkitems',0,'Select and link items for animation');
PM.GeoData = qp_toolbarpush(PM.TB,'geodata',0,'Add geodata item to axes');
PM.GeoDataMenu = uicontextmenu('parent',PM.Fig);
qp_uimenu(PM.GeoDataMenu, ...
    {'geodata_gshhs','Plot GSHHG shore lines',1,1,0
    'geodata_border','Plot GSHHG borders',1,1,0
    'geodata_river','Plot GSHHG rivers',1,1,0
    'geodata_wms_bluemarble','Plot WMS Blue Marble',1,1,1
    'geodata_wms_bingmaps','Plot WMS Bing Maps Virtual Earth',1,1,0
    'geodata_wms_esri_worldimagery','Plot WMS ESRI World Imagery',1,1,0
    'geodata_wms_openstreetmap','Plot WMS Open Street Map',1,1,0});
set([PM.DelIt PM.ItInfo PM.ItLink PM.GeoData],'enable','off');
%
PM.Show = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Top-80 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Show');
PM.ShowList = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Top-80 Width 20], ...
    'Style','popupmenu', ...
    'Horizontalalignment','left', ...
    'Backgroundcolor',UD.Active, ...
    'String',{'Item(s)','Figure Properties','Axes Properties'}, ...
    'Callback','d3d_qp pmshowselect');
%
%------- Item(s)
%
PM.ItList = uicontrol('Parent',PM.Fig, ...
    'Position',[60 10 Width Top-100], ...
    'String',{''}, ...
    'Style','listbox', ...
    'Tag','itemlist', ...
    'Callback','d3d_qp itemlist', ...
    'Enable','off', ...
    'Max',2, ...
    'Value',[]);
PM.ItTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Top-110 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Item(s)');
PM.ItUp = uicontrol('Parent',PM.Fig, ...
    'Position',[Width+70 Top-110 20 20], ...
    'Enable','inactive', ...
    'Callback','d3d_qp moveitemup', ...
    'CData',ArrowInactive, ...
    'Tag','moveitemup');
setappdata(PM.ItUp,'ArrowInactive',ArrowInactive)
setappdata(PM.ItUp,'ArrowActive',ArrowActive)
PM.ItDown = uicontrol('Parent',PM.Fig, ...
    'Position',[Width+70 10 20 20], ...
    'Enable','inactive', ...
    'Callback','d3d_qp moveitemdown', ...
    'CData',ArrowInactive(16:-1:1,:,:), ...
    'Tag','moveitemdown');
setappdata(PM.ItDown,'ArrowInactive',ArrowInactive(16:-1:1,:,:))
setappdata(PM.ItDown,'ArrowActive',ArrowActive(16:-1:1,:,:))
PM.LstHandles = [PM.ItTxt PM.ItList PM.ItUp PM.ItDown];
PM.Handles = PM.LstHandles;
PM.Pane = {};
PM.Pane(end+1:length(PM.Handles)) = {'Item(s)'};
%
%------- Figure Properties
%
PM.FigNameTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Top-110 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Name');
PM.FigName = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Top-110 280 20], ...
    'Style','edit', ...
    'Horizontalalignment','left', ...
    'Callback','d3d_qp figurename', ...
    'Enable','off');
PM.FigColorTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[350 Top-110 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Colour');
PM.FigColor = uicontrol('Parent',PM.Fig, ...
    'Position',[405 Top-110 25 20], ...
    'Style','pushbutton', ...
    'Callback','d3d_qp figurecolour', ...
    'Enable','off');

PM.FigPaperTypeTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Top-140 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Paper');
PM.FigPaperType = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Top-140 80 20], ...
    'Style','popupmenu', ...
    'Callback','d3d_qp figurepapertype', ...
    'String',set(PM.Fig,'papertype'), ...
    'Enable','off');
PM.FigPaperOrientation = uicontrol('Parent',PM.Fig, ...
    'Position',[150 Top-140 80 20], ...
    'Style','popupmenu', ...
    'Callback','d3d_qp figurepapertype', ...
    'String',set(PM.Fig,'paperorientation'), ...
    'Enable','off');
PM.FigPaperWidth = uicontrol('Parent',PM.Fig, ...
    'Position',[240 Top-140 40 20], ...
    'Style','edit', ...
    'Callback','d3d_qp figurepapertype', ...
    'String','', ...
    'Enable','off');
PM.FigPaperX = uicontrol('Parent',PM.Fig, ...
    'Position',[280 Top-140 20 17], ...
    'Style','text', ...
    'String','x', ...
    'Horizontalalignment','center', ...
    'Enable','off');
PM.FigPaperHeight = uicontrol('Parent',PM.Fig, ...
    'Position',[300 Top-140 40 20], ...
    'Style','edit', ...
    'Callback','d3d_qp figurepapertype', ...
    'String','', ...
    'Enable','off');
PM.FigPaperUnit = uicontrol('Parent',PM.Fig, ...
    'Position',[350 Top-140 80 20], ...
    'Style','popupmenu', ...
    'Callback','d3d_qp figurepaperunit', ...
    'String',{'inches','centimeters','points'}, ...
    'Enable','off');

PM.FigBorderStyleTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Top-170 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Border');
PM.FigBorderStyle = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Top-170 80 20], ...
    'Style','popupmenu', ...
    'Callback','d3d_qp figureborderstyle', ...
    'String',md_paper('borderstyles'), ...
    'Enable','off');
PM.FigBorder = uicontrol('Parent',PM.Fig, ...
    'Position',[150 Top-170 80 20], ...
    'Style','pushbutton', ...
    'String','Edit Texts', ...
    'Callback','d3d_qp figureborder', ...
    'Enable','off');
PM.FigHandles = [PM.FigNameTxt PM.FigName PM.FigColorTxt PM.FigColor ...
    PM.FigPaperTypeTxt PM.FigPaperType PM.FigPaperOrientation ...
    PM.FigPaperWidth PM.FigPaperX PM.FigPaperHeight PM.FigPaperUnit ...
    PM.FigBorderStyleTxt PM.FigBorderStyle PM.FigBorder];
PM.Handles = [PM.Handles PM.FigHandles];
PM.Pane(end+1:length(PM.Handles)) = {'Figure Properties'};
setappdata(PM.Fig,'FigPropsHeight',Top-80-(Top-170)+10)
setappdata(PM.Fig,'FigPropsShift',60)
%
%------- Axes Properties
%
Line = Top-110;
PM.AxNameTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Name');
PM.AxName = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 200 20], ...
    'Style','edit', ...
    'Horizontalalignment','left', ...
    'Callback','d3d_qp axesname', ...
    'Enable','off');
PM.AxTypeTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[270 Line 30 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Type');
PM.AxType = uicontrol('Parent',PM.Fig, ...
    'Position',[310 Line 90 20], ...
    'Style','popupmenu', ...
    'Horizontalalignment','left', ...
    'string',{' '}, ....
    'Callback','d3d_qp setaxestype', ...
    'Enable','off');
PM.SecondY = uicontrol('Parent',PM.Fig, ...
    'Position',[410 Line 20 20], ...
    'Style','pushbutton', ...
    'Enable','off', ...
    'CData',qp_icon('secondy','nan'), ...
    'Callback','d3d_qp secondy', ...
    'String','');
PM.SecondYMenu = uicontextmenu('parent',PM.Fig);
qp_uimenu(PM.SecondYMenu, ...
    {'secondy_left','Remove Left Y Axis',1,1,0
    'secondy_right','Remove Right Y Axis',1,1,0});
%
Line = Line-30;
PM.AxTitleTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Title', ...
    'Enable','off');
PM.AxTitleAuto = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 60 17], ...
    'Style','checkbox', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp title', ...
    'String','Auto');
PM.AxTitle = uicontrol('Parent',PM.Fig, ...
    'Position',[130 Line 270 20], ...
    'Style','edit', ...
    'Horizontalalignment','left', ...
    'Callback','d3d_qp title', ...
    'Enable','off');
%
Line = Line-30;
PM.AxColorTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Colour');
PM.HasAxColor = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 20 20], ...
    'Style','checkbox', ...
    'Callback','d3d_qp axescolour', ...
    'Value',1, ...
    'Enable','off');
PM.AxColor = uicontrol('Parent',PM.Fig, ...
    'Position',[85 Line 35 20], ...
    'Style','pushbutton', ...
    'Callback','d3d_qp axescolour', ...
    'Enable','off');
PM.AxLineWTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[130 Line 60 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Line Width', ...
    'Enable','off');
PM.AxLineWidth = uicontrol('Parent',PM.Fig, ...
    'Position',[200 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'String','', ...
    'Callback','d3d_qp axeslinewidth', ...
    'Enable','off');
PM.AxBox = uicontrol('Parent',PM.Fig, ...
    'Position',[270 Line 60 20], ...
    'Style','checkbox', ...
    'String','Box', ...
    'Callback','d3d_qp axesboxed', ...
    'Enable','off');
%
Line = Line-30;
PM.AxPosition = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 40 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Position', ...
    'Enable','off');
PM.AxXLowerLeft = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axesposition', ...
    'Enable','off');
PM.AxYLowerLeft = uicontrol('Parent',PM.Fig, ...
    'Position',[130 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axesposition', ...
    'Enable','off');
PM.AxWidth = uicontrol('Parent',PM.Fig, ...
    'Position',[200 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axesposition', ...
    'Enable','off');
PM.AxHeight = uicontrol('Parent',PM.Fig, ...
    'Position',[270 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axesposition', ...
    'Enable','off');
PM.AxPosUnit = uicontrol('Parent',PM.Fig, ...
    'Position',[340 Line 60 20], ...
    'Style','popupmenu', ...
    'Horizontalalignment','left', ...
    'Callback','d3d_qp axesposunit', ...
    'String',{'cm' 'inch' '%page'});
%
Line = Line-30;
PM.XLimitTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 50 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','X Limit', ...
    'Enable','off');
PM.XLimitMin = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axeslimits', ...
    'Enable','off');
PM.XLimitMax = uicontrol('Parent',PM.Fig, ...
    'Position',[130 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axeslimits', ...
    'Enable','off');
PM.XScale = uicontrol('Parent',PM.Fig, ...
    'Position',[200 Line 60 20], ...
    'Style','popupmenu', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp axesscale', ...
    'String',{'Linear','Log'});
PM.XGrid = uicontrol('Parent',PM.Fig, ...
    'Position',[270 Line 60 17], ...
    'Style','checkbox', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp axesgrid', ...
    'String','X Grid');
PM.XLoc = uicontrol('Parent',PM.Fig, ...
    'Position',[340 Line 60 20], ...
    'Style','popupmenu', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp axesloc', ...
    'String',{'Top','Bottom'});
PM.XColor = uicontrol('Parent',PM.Fig, ...
    'Position',[410 Line 20 20], ...
    'Style','pushbutton', ...
    'Enable','off', ...
    'Callback','d3d_qp xcolour', ...
    'String','');
Line = Line-30;
PM.XLabelTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 50 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','X Label', ...
    'Enable','off');
PM.XLabelAuto = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 60 17], ...
    'Style','checkbox', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp xlabel', ...
    'String','Auto');
PM.XLabel = uicontrol('Parent',PM.Fig, ...
    'Position',[130 Line 270 20], ...
    'Style','edit', ...
    'Horizontalalignment','left', ...
    'Callback','d3d_qp xlabel', ...
    'Enable','off');
%
Line = Line-30;
PM.YLimitTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 50 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Y Limit', ...
    'Enable','off');
PM.YLimitMin = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axeslimits', ...
    'Enable','off');
PM.YLimitMax = uicontrol('Parent',PM.Fig, ...
    'Position',[130 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axeslimits', ...
    'Enable','off');
PM.YScale = uicontrol('Parent',PM.Fig, ...
    'Position',[200 Line 60 20], ...
    'Style','popupmenu', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp axesscale', ...
    'String',{'Linear','Log'});
PM.YGrid = uicontrol('Parent',PM.Fig, ...
    'Position',[270 Line 60 17], ...
    'Style','checkbox', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp axesgrid', ...
    'String','Y Grid');
PM.YLoc = uicontrol('Parent',PM.Fig, ...
    'Position',[340 Line 60 20], ...
    'Style','popupmenu', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp axesloc', ...
    'String',{'Left','Right'});
PM.YColor = uicontrol('Parent',PM.Fig, ...
    'Position',[410 Line 20 20], ...
    'Style','pushbutton', ...
    'Enable','off', ...
    'Callback','d3d_qp ycolour', ...
    'String','');
Line = Line-30;
PM.YLabelTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 50 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Y Label', ...
    'Enable','off');
PM.YLabelAuto = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 60 17], ...
    'Style','checkbox', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp ylabel', ...
    'String','Auto');
PM.YLabel = uicontrol('Parent',PM.Fig, ...
    'Position',[130 Line 270 20], ...
    'Style','edit', ...
    'Horizontalalignment','left', ...
    'Callback','d3d_qp ylabel', ...
    'Enable','off');
%
Line = Line-30;
PM.ZLimitTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 50 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Z Limit', ...
    'Enable','off');
PM.ZLimitMin = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axeslimits', ...
    'Enable','off');
PM.ZLimitMax = uicontrol('Parent',PM.Fig, ...
    'Position',[130 Line 60 20], ...
    'Style','edit', ...
    'Horizontalalignment','right', ...
    'Callback','d3d_qp axeslimits', ...
    'Enable','off');
PM.ZScale = uicontrol('Parent',PM.Fig, ...
    'Position',[200 Line 60 20], ...
    'Style','popupmenu', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp axesscale', ...
    'String',{'Linear','Log'});
PM.ZGrid = uicontrol('Parent',PM.Fig, ...
    'Position',[270 Line 60 17], ...
    'Style','checkbox', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp axesgrid', ...
    'String','Z Grid');
PM.ZLoc = uicontrol('Parent',PM.Fig, ...
    'Position',[340 Line 60 20], ...
    'Style','popupmenu', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp axesloc', ...
    'String',{'Left','Right'});
PM.ZColor = uicontrol('Parent',PM.Fig, ...
    'Position',[410 Line 20 20], ...
    'Style','pushbutton', ...
    'Enable','off', ...
    'Callback','d3d_qp zcolour', ...
    'String','');
Line = Line-30;
PM.ZLabelTxt = uicontrol('Parent',PM.Fig, ...
    'Position',[10 Line 50 17], ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'String','Z Label', ...
    'Enable','off');
PM.ZLabelAuto = uicontrol('Parent',PM.Fig, ...
    'Position',[60 Line 60 17], ...
    'Style','checkbox', ...
    'Horizontalalignment','left', ...
    'Enable','off', ...
    'Callback','d3d_qp zlabel', ...
    'String','Auto');
PM.ZLabel = uicontrol('Parent',PM.Fig, ...
    'Position',[130 Line 270 20], ...
    'Style','edit', ...
    'Horizontalalignment','left', ...
    'Callback','d3d_qp zlabel', ...
    'Enable','off');
PM.AxHandles = [PM.AxNameTxt PM.AxName PM.AxTypeTxt PM.AxType PM.SecondY ...
    PM.AxTitleTxt PM.AxTitleAuto PM.AxTitle ...
    PM.AxColorTxt PM.HasAxColor PM.AxColor PM.AxBox PM.AxLineWTxt PM.AxLineWidth ...
    PM.AxPosition PM.AxXLowerLeft PM.AxYLowerLeft PM.AxWidth PM.AxHeight PM.AxPosUnit ...
    PM.XLimitTxt PM.XLimitMin PM.XLimitMax PM.XScale PM.XGrid PM.XLoc PM.XColor ...
    PM.XLabelTxt PM.XLabelAuto PM.XLabel ...
    PM.YLimitTxt PM.YLimitMin PM.YLimitMax PM.YScale PM.YGrid PM.YLoc PM.YColor ...
    PM.YLabelTxt PM.YLabelAuto PM.YLabel ...
    PM.ZLimitTxt PM.ZLimitMin PM.ZLimitMax PM.ZScale PM.ZGrid PM.ZLoc PM.ZColor ...
    PM.ZLabelTxt PM.ZLabelAuto PM.ZLabel];
PM.Handles = [PM.Handles PM.AxHandles];
PM.Pane(end+1:length(PM.Handles)) = {'Axes Properties'};
setappdata(PM.Fig,'AxPropsHeight',Top-80-Line+10)
setappdata(PM.Fig,'AxPropsShift',30)
%
iList = strcmp(PM.Pane,PM.Pane{1});
set(PM.Handles(iList),'visible','on')
set(PM.Handles(~iList),'visible','off')

% Options
PM.Options = AddOptions(PM.Fig,PMsize,offset,width,UD,false);
if panewidth==0
    set(PM.Options.Slider,'visible','off')
    set(PM.Options.Handles,'visible','off')
end

UD.PlotMngr = PM;
%============
pos=get(mfig,'position');
pos(3)=340;
%pos(2)=pos(2)-19;
FO.Fig = qp_uifigure('File Options','fileoptions','FileOptions',pos);
%set(FO.Fig,'Handlevisibility','callback');
set(FO.Fig,'resizefcn','d3d_qp fileoptionsresize')
setappdata(FO.Fig,'DefaultFileOptionsSize',pos(3:4))
FO.Close = LocButton(FO.Fig,[171 11 160 20],'fileoptions','Close',1,'Close dialog window');
UD.FilOpt=FO;


%============
GV.Fig=qp_gridview([],[]);
setappdata(GV.Fig,'WL_UserInterface',1)
UICONTROL = findall(GV.Fig,'type','uicontrol');
uicontrolfont = qp_fontsettings('Font');
set(UICONTROL,uicontrolfont)
%-------------
m1=qp_uimenu(GV.Fig,'&File', ...
    {'showgridviewldb','Show &Land Boundary ...',1,1,0
    'hidegridview','&Close',1,1,1});
f=allchild(GV.Fig);
set(GV.Fig,'children',f([2 1 3:end]))
%-------------
set(GV.Fig,'CloseRequestFcn','d3d_qp hidegridview','visible','off','name','Grid View')
set(findobj(GV.Fig,'tag','gridviewarbline'),'enable','off')
set(findobj(GV.Fig,'tag','gridviewpiecewise'),'enable','off')
qp_gridview('callback',GV.Fig,'d3d_qp','gridview_selected')
UD.GridView=GV;

%============
pos=get(mfig,'position');
hght=40;
pos(2)=pos(2)-hght-25;
pos(4)=hght;

UD.ComLine.Fig = qp_uifigure('Command Line','hidecomline','ComLineFig',pos);
UD.ComLine.Eval = uicontrol('Parent',UD.ComLine.Fig, ...
    'FontUnits','pixels', ...
    'Callback','d3d_qp evalcmd', ...
    'Style','edit', ...
    'Backgroundcolor',UD.Active, ...
    'Enable','on', ...
    'FontSize',12, ...
    'Horizontalalignment','left', ...
    'Position',[11 11 pos(3)-40 20], ...
    'tag','evalcmd', ...
    'String','');
UD.ComLine.EvalHist = uicontrol('Parent',UD.ComLine.Fig, ...
    'Style','pushbutton', ...
    'Callback','d3d_qp evalhist', ...
    'Enable','on', ...
    'FontUnits','pixels', ...
    'FontSize',12, ...
    'Horizontalalignment','left', ...
    'Position',[11+pos(3)-35 13 15 15], ...
    'tag','evalhistory', ...
    'String','v');
UD.ComLine.EvalHistMenu = uicontextmenu( ...
    'tag','evalhistoryuicontextmenu', ...
    'userdata',{}, ...
    'Parent',UD.ComLine.Fig);
set(UD.ComLine.EvalHist,'uicontextmenu',UD.ComLine.EvalHistMenu)
qp_update_evalhistmenu(UD.ComLine.EvalHistMenu,'initialize')

%
% ---------------------
%
setappdata(mfig,'QPHandles',UD)
%
% ---------------------
%
if matlabversionnumber > 5.02
    set(mfig,'ToolBar','none');
end
h1vec=[findall(mfig)' findall(UD.PlotMngr.Fig)' findall(UD.ComLine.Fig)'];
c10=char(10);
for h1=h1vec
    t=get(h1,'tag');
    switch t
        case ''
            Str='';
        case 'selectfile'
            Str='Select a data file for plotting';
        case 'selectfield'
            Str='Select a data field to plot';
        case 'allt'
            Str='Select all timesteps (equal to : range)';
        case 't=?'
            Str=cat(2,'Specify time step(s):',c10,'single value, e.g. 4,',c10,'range, e.g. 20:100',c10,'range with step, e.g. 101:-4:1,',c10,'or any combination, e.g. 1:5 7 10 14');
        case 'timelist'
            Str='Select time(s)';
        case 'showtimes'
            Str='Check to load and show times stored in the file';
        case 'stationlist'
            Str='Select location, station, cross section, particle, etc.';
        case 'alls'
            Str='Select all locations, stations, cross sections, particles, etc.';
        case 'hselectiontype'
            Str='Select the desired type of data selection in the horizontal plane';
        case 'vselectiontype'
            Str='Select the desired type of data selection in the vertical direction';

        case 'optionslider'
            Str='Drag slide to scroll through options';
        case 'markercolor=?'
            Str='Select marker colour';
        case 'markerfillcolor='
            Str='Check to fill marker';
        case 'markerfillcolor=?'
            Str='Select marker fill colour';
        case 'colclassify'
            Str='Check to classify the colours';
        case 'threshdistr=?'
            Str=cat(2,'Specify automatic distribution method',c10,'for thresholds/contour values');
        case 'climsymm'
            Str='Select to force colour limits to be symmetric around zero';
        case 'colourbar'
            Str='Check to draw colourbar';
        case 'colbarhorz'
            Str='Check to draw horizontal colourbar';

        case 'selectfigure'
            Str='Select active figure';
        case 'selectaxes'
            Str='Select active axes';
        case 'itemlist'
            Str=cat(2,'List of Delft3D-QUICKPLOT items in active axes',c10,'select item(s)');
        case 'evalcmd'
            Str='Enter macro command';
        case 'evalhistory'
            Str='Click to recall previous commands';
        case 'dock'
            Str='Undock plot options';
        case 'extend2edge'
            Str='Extend the data by half a grid cell to the edge of the model domain';
        otherwise
            Str='';
    end
    if ~isempty(Str)
        qp_tooltip(h1,Str)
    end
end

%
% Show figure ...
set(mfig,'handlevisibility','off');
if showUI
    set(mfig,'visible','on');
    drawnow
end
if nargout > 0
    fig = mfig;
end


%============
function H=LocButton(hP,pos,cmd,str,enab,tooltip)
offon={'off','on'};
enab=offon{1+enab};
H = uicontrol('Parent',hP, ...
    'Callback',cat(2,'d3d_qp ',cmd), ...
    'Position',pos, ...
    'String',str, ...
    'Enable',enab, ...
    'UserData','', ...
    'Tag',cmd);
qp_tooltip(H,tooltip)


%============
function [M,AllM,EditM,MaxM]=DimControls(hP,voffset,m)
M = uicontrol('Parent',hP, ...
    'Enable','off', ...
    'Position',[11 voffset-2 60 18], ...
    'String',upper(m), ...
    'Style','text', ...
    'Horizontalalignment','left', ...
    'Tag',m);
AllM = uicontrol('Parent',hP, ...
    'Callback',cat(2,'d3d_qp all',m), ...
    'Enable','off', ...
    'Position',[81 voffset 40 20], ...
    'String','All', ...
    'Style','checkbox', ...
    'Tag',cat(2,'all',m));
EditM = uicontrol('Parent',hP, ...
    'Callback',cat(2,'d3d_qp edit',m), ...
    'Enable','off', ...
    'HorizontalAlignment','left', ...
    'Position',[121 voffset 170 20], ...
    'Style','edit', ...
    'Tag',cat(2,m,'=?'));
MaxM = uicontrol('Parent',hP, ...
    'Enable','off', ...
    'Position',[291 voffset-2 40 18], ...
    'String','-', ...
    'Style','text', ...
    'Tag',cat(2,'max_',m), ...
    'UserData',1);
qp_tooltip(AllM,cat(2,'Select all ',m,' (equal to : range)'))
qp_tooltip(EditM,{cat(2,'Specify ',m,' value(s):'),'single value, e.g. 4, or','range, e.g. 20:100'})


%============
function H=LocTextEdit_pair(hP,str,cmd,val,pos,tooltip)
H=LocTextPopup_pair(hP,str,cmd,pos,tooltip);
if ischar(val)
    X={'String',val};
else
    X={'String',sprintf('%g',val), ...
        'Userdata',val};
end
set(H(2),'Style','edit',X{:});


%============
function H=LocTextPopup_pair(hP,str,cmd,pos,tooltip)
txtpos=pos;
txtpos(2)=txtpos(2)+25;
txtpos(4)=18;
H(1) = uicontrol('Parent',hP, ...
    'Enable','off', ...
    'Position',txtpos, ...
    'Style','text', ...
    'String',str, ...
    'Horizontalalignment','left', ...
    'Tag',cmd);
H(2) = uicontrol('Parent',hP, ...
    'Enable','off', ...
    'Position',pos, ...
    'Callback',cat(2,'d3d_qp ',cmd), ...
    'Style','popupmenu', ...
    'String',{' '}, ...
    'Value',1, ...
    'Horizontalalignment','left', ...
    'Tag',cat(2,cmd,'=?'));
qp_tooltip(H(2),tooltip)


%============
function H=LocTextEdit_line(hP,str,cmd,val,pos,tooltip)
H=LocTextPopup_line(hP,str,cmd,pos,tooltip);
if ischar(val)
    X={'String',val};
else
    X={'String',sprintf('%g',val), ...
        'Userdata',val};
end
set(H(2),'HorizontalAlignment','right', ...
    'Style','edit',X{:});


%============
function H=LocTextColor_line(hP,str,cmd,clr,pos,tooltip)
H=LocTextPopup_line(hP,str,cmd,pos,tooltip);
txtpos=get(H(1),'position');
txtpos(3)=pos(3)-30;
set(H(1),'position',txtpos)
pos=get(H(2),'position');
pos(1)=pos(1)+pos(3)-25;
pos(3)=25;
set(H(2),'position',pos, ...
    'Style','pushbutton', ...
    'String','', ...
    'BackgroundColor',clr, ...
    'Userdata',clr);


%============
function H=LocTextPopup_line(hP,str,cmd,pos,tooltip)
txtwidth=0.38*pos(3);
txtpos=pos;
txtpos(3:4)=[txtwidth 18];
H(1) = uicontrol('Parent',hP, ...
    'Enable','off', ...
    'Position',txtpos, ...
    'Style','text', ...
    'String',str, ...
    'Horizontalalignment','left', ...
    'Tag',cmd);
pos(1)=pos(1)+txtwidth+5;
pos(3)=pos(3)-txtwidth-5;
H(2) = uicontrol('Parent',hP, ...
    'Callback',cat(2,'d3d_qp ',cmd), ...
    'Enable','off', ...
    'Position',pos, ...
    'Style','popupmenu', ...
    'String',{' '}, ...
    'Value',1, ...
    'Horizontalalignment','left', ...
    'Tag',cat(2,cmd,'=?'));
qp_tooltip(H(2),tooltip)


%============
function Options = AddOptions(mfig,dims,offset,width,UD,mainwindow)
voffset=dims(2)-4;
Options.Fig = [];
if mainwindow
    Options.Dock = uicontrol('Parent',mfig, ...
        'Enable','on', ...
        'Position',[dims(1)-15 dims(2)-15 15 15], ...
        'CData',qp_icon('undock','nan'), ...
        'Callback','d3d_qp dock', ...
        'Style','pushbutton', ...
        'UserData',0, ...
        'Tag','dock');
    ddock = 15;
else
    ddock = 0;
end
Options.Slider = uicontrol('Parent',mfig, ...
    'Enable','on', ...
    'Position',[dims(1)-15 0 15 dims(2)-ddock], ...
    'Callback','d3d_qp optslider', ...
    'Style','slider', ...
    'Min',0, ...
    'Max',1, ...
    'Sliderstep',[0.01 1], ...
    'Value',0, ...
    'Tag','optionslider');
items0 = allchild(mfig);
%
% ------ axes type ...
%
voffset=voffset-50;
LocTextPopup_pair(mfig,'Axes Type','axestype',[offset voffset width 20],'');
%
% ------ time axis - time zone ...
%
voffset=voffset-25;
h1 = LocTextPopup_line(mfig,'Time Zone','axestimezone',[offset voffset width 20],'Select time zone');
[TZshift,TZstr]=gettimezone('supported');
set(h1(2),'string',TZstr,'userdata',TZshift);
%
% ------ component ...
%
voffset=voffset-50;
LocTextPopup_pair(mfig,'Component','component',[offset voffset width 20],'Select component');
%
% ------ presenttype ...
%
voffset=voffset-50;
LocTextPopup_pair(mfig,'Presentation Type','presenttype',[offset voffset width 20], ...
    'Select presentation type');
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Callback','d3d_qp extend2edge', ...
    'Enable','off', ...
    'Value',0, ...
    'HorizontalAlignment','left', ...
    'Position',[offset voffset width 20], ...
    'Style','checkbox', ...
    'String','Extend to Domain Edge', ...
    'Tag','extend2edge');
%
% ------ colour vectors ...
%
voffset=voffset-50;
h1 = LocTextPopup_pair(mfig,'Colour Vectors','vectorcolour',[offset voffset width 20], ...
    'Select quantity for colouring');
set(h1(1),'Callback','d3d_qp colourvectors', ...
    'Style','checkbox', ...
    'Value',0,...
    'Tag','colourvectors');
qp_tooltip(h1(1),'Check to colour the vectors');
%
% ------ data units ...
%
voffset=voffset-25;
h1 = LocTextPopup_line(mfig,'Data Units','dataunits',[offset voffset width 20],'Select data units');
UnitSystems = cat(2,{'As in file'},qp_unitconversion('systems'),{'Other','Hide'});
SelectedUnitSystem = qp_settings('UnitSystem','As in file');
sus = strmatch(SelectedUnitSystem,UnitSystems,'exact');
if isempty(sus)
    sus = 1;
end
set(h1(2),'String',UnitSystems,'Value',sus);
voffset=voffset-25;
hl = uicontrol('Parent',mfig, ...
    'Enable','off', ...
    'Position',[offset voffset width 20], ...
    'Callback','d3d_qp dataunits', ...
    'Style','edit', ...
    'String',' ', ...
    'Horizontalalignment','left', ...
    'Tag','dataunits=!');
qp_tooltip(hl,'Specify the units to be used for plotting/exporting')
%
% ------ angle convention ...
%
voffset=voffset-50;
h1 = LocTextPopup_pair(mfig,'Angle Convention','angleconvention',[offset voffset width 20],'Select nautical or Cartesian');
AngConv={'Nautical To [-180 to 180]', 'Nautical To [0 to 360]', 'Nautical From [-180 to 180]', 'Nautical From [0 to 360]','Cartesian To [-180 to 180]', 'Cartesian To [0 to 360]','Cartesian From [-180 to 180]', 'Cartesian From [0 to 360]'};
set(h1(2),'string',AngConv)
%
% ------ plot coordinate ...
%
voffset=voffset-50;
LocTextPopup_pair(mfig,'Plot Coordinate','plotcoordinate',[offset voffset width 20],'');
%
% ------ vector style ...
%
voffset=voffset-50;
h1 = LocTextPopup_pair(mfig,'Vector Style','vectorstyle',[offset voffset width 20], ...
    'Select plotting style of vectors');
set(h1(2),'string',{'rooted arrow','centered arrow','rooted line'})
%
% ------ vector scaling ...
%
voffset=voffset-50;
h1 = LocTextPopup_pair(mfig,'Vector Scaling','vecscalem',[offset voffset width 20], ...
    'Select method of vector scaling');
set(h1(2),'string',{'automatic','manual','automatic normalised','manual normalised'})
voffset=voffset-25;
LocTextEdit_line(mfig,'1 Unit =','1vecunit',1,[offset voffset width 20], ...
    {'Set vector scale:','the length of the unit vector expressed in distance units'});
%
% ------ vertical scaling ...
%
voffset=voffset-50;
h1 = LocTextPopup_pair(mfig,'Vertical Scaling','vertscalem',[offset voffset width 20], ...
    'Select method for scaling in z direction');
set(h1(2),'string',{'unrestricted','automatic','manual'})
voffset=voffset-25;
LocTextEdit_line(mfig,'Enlarge','vscale',1,[offset voffset width 20], ...
    'set z scale relative to (x,y) scale');
%
% ------ format string
%
voffset=voffset-25;
LocTextEdit_line(mfig,'Format','numformat','%.2f',[offset voffset width 20], ...
    {'Specify format for value display: %f for decimal notation,','%e for exponential notation, %g for automatic selection','use %.nf for n decimal places'});
%
% ------ font characteristics
%
voffset=voffset-25;
LocTextEdit_line(mfig,'Fontsize','fontsize',6,[offset voffset width 20], ...
    'Specify font size in points');
%
% ------ label alignment
%
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Enable','off', ...
    'Position',[offset voffset width 20], ...
    'Style','text', ...
    'String','Alignment', ...
    'Horizontalalignment','left', ...
    'Tag','alignment');
voffset=voffset-25;
h1 = LocTextPopup_line(mfig,'Horizontal','horizontalalignment',[offset voffset width 20], ...
    'Select horizontal alignment style: left, centre or right');
set(h1(2),'String',{'left','centre','right'},'Value',2);
voffset=voffset-25;
h1 = LocTextPopup_line(mfig,'Vertical','verticalalignment',[offset voffset width 20], ...
    'Select vertical alignment style: top, cap, middle, baseline, bottom');
set(h1(2),'String',{'top','cap','middle','baseline','bottom'},'Value',3);
%
% ------ colour dams ...
%
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Callback','d3d_qp colourdams', ...
    'Enable','off', ...
    'HorizontalAlignment','left', ...
    'Position',[offset voffset width 20], ...
    'Style','checkbox', ...
    'Value',0,...
    'String','Colour Dams', ...
    'Tag','colourdams');
%
% ------ value operator ...
%
voffset=voffset-25;
h1 = LocTextPopup_line(mfig,'Operator','operator',[offset voffset width 20],'Select value operator');
set(h1(2),'String',{'none','abs'},'Value',1);
%
% ------ uniform colours ...
%
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Callback','d3d_qp unicolour', ...
    'Enable','off', ...
    'HorizontalAlignment','left', ...
    'Position',[offset voffset width 20], ...
    'Style','checkbox', ...
    'Value',0,...
    'String','Colour Uniformly', ...
    'Tag','unicolour');
%
% ------ colour ...
%
voffset=voffset-25;
LocTextColor_line(mfig,'Colour','colour',UD.State.colour,[offset voffset width 20],'Press to select colour');
%
% ------ face colour ...
%
voffset=voffset-25;
h1 = LocTextColor_line(mfig,'Fill Polygons','facecolour',UD.State.facecolour,[offset voffset width 20],'Press to select fill colour for polygons');
set(h1(1),'tag','fillpolygons','style','checkbox','value',0,'callback','d3d_qp fillpolygons')
%
% ------ text box colour ...
%
voffset=voffset-25;
h1 = LocTextColor_line(mfig,'Text Box','textboxfacecolour',UD.State.textboxfacecolour,[offset voffset width 20],'Select colour of the text box');
set(h1(1),'tag','textbox=?','style','checkbox','value',0,'callback','d3d_qp textbox')
qp_tooltip(h1(1),'Add box around text')
%
% ------ linestyle ...
%
L=set(0,'defaultlinelinestyle');
Li=strmatch(UD.State.linestyle,L,'exact');
voffset=voffset-25;
h1 = LocTextPopup_line(mfig,'Line Style','linestyle',[offset voffset width 20],'Select line style');
set(h1(2),'String',L,'Value',Li);
voffset=voffset-25;
LocTextEdit_line(mfig,'Width','linewidth',UD.State.linewidth,[offset voffset width 20], ...
    'Specify line width');
%
% ------ marker ...
%
L=set(0,'defaultlinemarker');
Li=strmatch('none',L,'exact');
voffset=voffset-25;
h1 = LocTextPopup_line(mfig,'Marker','marker',[offset voffset width 20],'Select marker style');
set(h1(2),'String',L,'Value',Li);
%
% ------ markersize ...
%
voffset=voffset-25;
LocTextEdit_line(mfig,'Size','markersize',6,[offset voffset width 20],'Select marker size');
%
% ------ marker colour ...
%
voffset=voffset-25;
h1 = LocTextColor_line(mfig,'Marker Colour','markercolour',UD.State.markercolour,[offset voffset width 20],'Press to select marker (edge) colour');
set(h1(1),'tag','usemarkercolour','style','checkbox','value',0,'callback','d3d_qp usemarkercolour')
qp_tooltip(h1(1),'Use different colour for marker (edge)')
%
% ------ marker fill colour ...
%
voffset=voffset-25;
h1 = LocTextColor_line(mfig,'Marker Fill','markerfillcolour',UD.State.markerfillcolour,[offset voffset width 20],'Press to select marker fill colour');
set(h1(1),'tag','usemarkerfillcolour','style','checkbox','value',0,'callback','d3d_qp usemarkerfillcolour')
qp_tooltip(h1(1),'Use different colour for marker fill')
%
% ------ classify colours ...
%
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Callback','d3d_qp colclassify', ...
    'Enable','off', ...
    'HorizontalAlignment','left', ...
    'Position',[offset voffset width 20], ...
    'Style','checkbox', ...
    'Value',0,...
    'String','Use Value Classes', ...
    'Tag','colclassify');
%
% ------ thresholds ...
%
voffset=voffset-50;
LocTextEdit_pair(mfig,'Thresholds','thresholds','',[offset voffset width 20], ...
    {'Specify thresholds/contour values:','specify the number, e.g. 15 (default 10),','or the values, e.g. 0:0.5:3 4:6','or just the step, e.g. :0.02:'});
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Enable','off', ...
    'Position',[offset voffset width 20], ...
    'Callback','d3d_qp threshdistr', ...
    'Style','popupmenu', ...
    'String',{'linear','logarithmic'}, ...
    'Value',1, ...
    'Horizontalalignment','left', ...
    'Tag','threshdistr=?');
%
% ------ colour limits ...
%
voffset=voffset-50;
h1=LocTextPopup_pair(mfig,'Colour Limits','climmode',[offset voffset width 20], ...
    'Select method for determining the colour limits');
set(h1(2),'string',{'automatic','manual'})
voffset=voffset-25;
LocTextEdit_line(mfig,'Max','climmax',1,[offset voffset width 20], ...
    'Select upper limit for colour scale');
voffset=voffset-25;
LocTextEdit_line(mfig,'Min','climmin',0,[offset voffset width 20], ...
    'Select lower limit for colour scale');
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Callback','d3d_qp climsymm', ...
    'Enable','off', ...
    'Value',0, ...
    'HorizontalAlignment','left', ...
    'Position',[offset voffset width 20], ...
    'Style','checkbox', ...
    'String','Symmetric Limits', ...
    'Tag','climsymm');
%
% ------ colour map ...
%
voffset=voffset-50;
h2 = LocTextPopup_pair(mfig,'Colour Map','colourmap',[offset voffset width 20],'Select colour map');
h1 = uicontrol('Parent',mfig, ...
    'Enable','on', ...
    'Callback','d3d_qp colourmapeditor', ...
    'Position',[offset+75 voffset+25 width-75 18], ...
    'Style','pushbutton', ...
    'Horizontalalignment','left', ...
    'Tag','colourmapbutton');
qp_tooltip(h1,'Click to add colour maps')
cmaps=qp_colormap;
imap=ustrcmpi(UD.State.colourmap,cmaps);
cmap=qp_colormap(UD.State.colourmap,width-75);
set(h1,'cdata',repmat(reshape(cmap,[1 size(cmap)]),18,1))
set(h2(2),'String',cmaps, ...
    'Value',imap);
%
% ------ colourbar ...
%
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Callback','d3d_qp colourbar', ...
    'Enable','off', ...
    'Value',1, ...
    'HorizontalAlignment','left', ...
    'Position',[offset voffset width 20], ...
    'Style','checkbox', ...
    'String','Draw Colourbar', ...
    'Tag','colourbar');
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Callback','d3d_qp colbarhorz', ...
    'Enable','off', ...
    'Value',0, ...
    'HorizontalAlignment','left', ...
    'Position',[offset+20 voffset width-20 18], ...
    'Style','checkbox', ...
    'String','Horizontal', ...
    'Tag','colbarhorz');
%
% ------ thin vector/value field ...
%
voffset=voffset-50;
h1 = LocTextPopup_pair(mfig,'Field Thinning','thinfld',[offset voffset width 20], ...
    'Select method used for thinning of the vector or value field');
ThinMths={'<dummy>'};
set(h1(2),'string',ThinMths)
voffset=voffset-25;
LocTextEdit_line(mfig,'Factor','thinfact',1,[offset voffset width 20], ...
    'Keep every <?> select method used for thinning of the vectors / values');
voffset=voffset-25;
LocTextEdit_line(mfig,'Distance','thindist',50,[offset voffset width 20], ...
    'Specify minimum distance between vector plot locations.');
%
% ------ data clipping values ...
%
voffset=voffset-50;
LocTextEdit_pair(mfig,'Clipping Values','clippingvals',-999,[offset voffset width 20], ...
    {'Specify blanking or clipping values not to be plotted:','specify the value, e.g. -999,','a lower or upper limit, e.g. <-10 >=10,','a clipping range, e.g. [-0.01 0.01]','or any combination.'});
%
% ------ clip NaNs ...
%
voffset=voffset-25;
uicontrol('Parent',mfig, ...
    'Callback','d3d_qp clipnans', ...
    'Enable','off', ...
    'Value',1, ...
    'HorizontalAlignment','left', ...
    'Position',[offset voffset width 20], ...
    'Style','checkbox', ...
    'String','Clip NaNs', ...
    'Tag','clipnans');
qp_tooltip(h1(1),'When switched on NaN values will not be plotted.')
%
% ------ x/y clipping values ...
%
voffset=voffset-150;
h1 = LocTextEdit_line(mfig,'X','xclipping',[],[offset voffset width 20], ...
    {'Specify x coordinates not to be plotted:','specify the value, e.g. -999,','a lower or upper limit, e.g. <-10 >=10,','a clipping range, e.g. [-0.01 0.01]','or any combination.'});
set(h1(2),'horizontalalignment','left')
voffset=voffset-25;
h1 = LocTextEdit_line(mfig,'Y','yclipping',[],[offset voffset width 20], ...
    {'Specify y coordinates not to be plotted:','specify the value, e.g. -999,','a lower or upper limit, e.g. <-10 >=10,','a clipping range, e.g. [-0.01 0.01]','or any combination.'});
set(h1(2),'horizontalalignment','left')
%
% ------ export data ...
%
voffset=voffset-50;
LocTextPopup_pair(mfig,'Export File Type','exporttype',[offset voffset width 20], ...
    'Select the kind of file that should be created');
voffset=voffset-25;
LocTextEdit_line(mfig,'Format','expformat','%16.7e',[offset voffset width 20], ...
    {'Specify value format:','%16.7e gives e.g. -9.9900000E+002','%15.7f gives e.g. -999.000000'});
voffset=voffset-25;
LocButton(mfig,[offset+60 voffset width-60 20],'exportdata','Export Data...',0, ...
    'press this button to export the data');
%
set(Options.Slider,'min',voffset-10,'max',0,'value',0,'enable','off','userdata',0)
%
items1 = allchild(mfig);
H = setdiff(items1,items0);

p = get(H,'position');
p = cat(1,p{:});
[ps,reorder] = sort(p(:,2),1,'descend');
H = H(reorder);
p = p(reorder,:);
[f,i,Line] = unique(p(:,2));
set(H,'visible','off')
Options.Handles = H;
Options.Line = Line;
Options.Top = p(1,2);
%
Options.Act=logical(zeros(size(p(:,1))));
Options.ActPos=zeros(1,4);
p(:,2)=(p(:,2)-p(1,2))/25;
Options.Pos=p;