Home > atplot > atbaseplot.m

atbaseplot

PURPOSE ^

ATBASEPLOT Plots data generated by a user-supplied function

SYNOPSIS ^

function curve = atbaseplot(varargin)

DESCRIPTION ^

ATBASEPLOT Plots data generated by a user-supplied function

ATBASEPLOT             Plots THERING in the current axes

ATBASEPLOT(RING)       Plots the lattice specified by RING

ATBASEPLOT(RING,DPP)   Plots at momentum deviation DPP (default: 0)

ATBASEPLOT(...,[SMIN SMAX])  Zoom on the specified range

ATBASEPLOT(...,@PLOTFUNCTION,PLOTARGS)
   PLOTFUNCTION: User supplied function providing the values to be plotted
   PLOTARGS:     Optional cell array of arguments to PLOTFUNCTION
   PLOTFUNCTION is called as: 
   [S,PLOTDATA]=PLOTFUNCTION(RING,DPP,PLOTARGS{:})

       S:        longitudinal position, length(ring)+1 x 1
       PLOTDATA: structure array,
         PLOTDATA(1) describes data for the left (main) axis
           PLOTDATA(1).VALUES: data to be plotted, length(ring)+1 x nbcurve
           PLOTDATA(1).LABELS: curve labels, cell array, 1 x nbcurve
           PLOTDATA(1).AXISLABEL: string
         PLOTDATA(2) optional, describes data for the right (secondary) axis

ATBASEPLOT(...,'OptionName',OptionValue,...) Available options:
   'synopt',true|false         Plots the lattice elements
   'labels',REFPTS             Display the names of selected element names
   'index',REFPTS             Display the index of selected element names
   'leftargs',{properties}     properties set on the left axis
   'rightargs',{properties}    properties set on the right axis

ATBASEPLOT(AX,...)     Plots in the axes specified by AX. AX can precede
                       any previous argument combination

CURVE=ATBASEPLOT(...)  Returns handles to some objects:
   CURVE.PERIODICIY ring periodicity
   CURVE.LENGTH    structure length
   CURVE.DPP       deltap/p
   CURVE.LEFT      Handles to the left axis plots
   CURVE.RIGHT     Handles to the right axis plots
   CURVE.LATTICE   Handles to the Element patches: structure with fields
          Dipole,Quadrupole,Sextupole,Multipole,BPM,Label

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function curve = atbaseplot(varargin)
0002 %ATBASEPLOT Plots data generated by a user-supplied function
0003 %
0004 %ATBASEPLOT             Plots THERING in the current axes
0005 %
0006 %ATBASEPLOT(RING)       Plots the lattice specified by RING
0007 %
0008 %ATBASEPLOT(RING,DPP)   Plots at momentum deviation DPP (default: 0)
0009 %
0010 %ATBASEPLOT(...,[SMIN SMAX])  Zoom on the specified range
0011 %
0012 %ATBASEPLOT(...,@PLOTFUNCTION,PLOTARGS)
0013 %   PLOTFUNCTION: User supplied function providing the values to be plotted
0014 %   PLOTARGS:     Optional cell array of arguments to PLOTFUNCTION
0015 %   PLOTFUNCTION is called as:
0016 %   [S,PLOTDATA]=PLOTFUNCTION(RING,DPP,PLOTARGS{:})
0017 %
0018 %       S:        longitudinal position, length(ring)+1 x 1
0019 %       PLOTDATA: structure array,
0020 %         PLOTDATA(1) describes data for the left (main) axis
0021 %           PLOTDATA(1).VALUES: data to be plotted, length(ring)+1 x nbcurve
0022 %           PLOTDATA(1).LABELS: curve labels, cell array, 1 x nbcurve
0023 %           PLOTDATA(1).AXISLABEL: string
0024 %         PLOTDATA(2) optional, describes data for the right (secondary) axis
0025 %
0026 %ATBASEPLOT(...,'OptionName',OptionValue,...) Available options:
0027 %   'synopt',true|false         Plots the lattice elements
0028 %   'labels',REFPTS             Display the names of selected element names
0029 %   'index',REFPTS             Display the index of selected element names
0030 %   'leftargs',{properties}     properties set on the left axis
0031 %   'rightargs',{properties}    properties set on the right axis
0032 %
0033 %ATBASEPLOT(AX,...)     Plots in the axes specified by AX. AX can precede
0034 %                       any previous argument combination
0035 %
0036 %CURVE=ATBASEPLOT(...)  Returns handles to some objects:
0037 %   CURVE.PERIODICIY ring periodicity
0038 %   CURVE.LENGTH    structure length
0039 %   CURVE.DPP       deltap/p
0040 %   CURVE.LEFT      Handles to the left axis plots
0041 %   CURVE.RIGHT     Handles to the right axis plots
0042 %   CURVE.LATTICE   Handles to the Element patches: structure with fields
0043 %          Dipole,Quadrupole,Sextupole,Multipole,BPM,Label
0044 %
0045 
0046 global THERING
0047 
0048 npts=400;
0049 narg=1;
0050 % Select axes for the plot
0051 if narg<=length(varargin) && isscalar(varargin{narg}) && ishandle(varargin{narg});
0052     ax=varargin{narg};
0053     narg=narg+1;
0054 else
0055     ax=gca;
0056 end
0057 % Select the lattice
0058 if narg<=length(varargin) && iscell(varargin{narg});
0059     [elt0,curve.periodicity,ring0]=get1cell(varargin{narg});
0060     narg=narg+1;
0061 else
0062     [elt0,curve.periodicity,ring0]=get1cell(THERING);
0063 end
0064 s0=findspos(ring0,1:elt0+1);
0065 curve.length=s0(end);
0066 % Select the momentum deviation
0067 if narg<=length(varargin) && isscalar(varargin{narg}) && isnumeric(varargin{narg});
0068     curve.dpp=varargin{narg};
0069     narg=narg+1;
0070 else
0071     curve.dpp=0;
0072 end
0073 % Select the plotting range
0074 el1=1;
0075 el2=elt0+1;
0076 if narg<=length(varargin) && isnumeric(varargin{narg}) && (numel(varargin{narg})==2)
0077     srange=varargin{narg};
0078     els=find(srange(1)>s0,1,'last');
0079     if ~isempty(els), el1=els; end
0080     els=find(s0>srange(2),1,'first');
0081     if ~isempty(els), el2=els; end
0082     narg=narg+1;
0083 else
0084     srange=[0 curve.length];
0085 end
0086 % select the plotting function
0087 plotargs={};
0088 if narg<=length(varargin) && isa(varargin{narg},'function_handle')
0089     plotfun=varargin{narg};
0090     narg=narg+1;
0091     if narg<=length(varargin) && iscell(varargin{narg})
0092         plotargs=varargin{narg};
0093         narg=narg+1;
0094     end
0095 else
0096     plotfun=@defaultplot;
0097 end
0098 % Get options
0099 rsrc=varargin(narg:end);
0100 [synopt,rsrc]=getoption(rsrc,'synopt',true);
0101 [leftargs,rsrc]=getoption(rsrc,'leftargs',{});
0102 [rightargs,rsrc]=getoption(rsrc,'rightargs',{});
0103 % Split the ring
0104 elmlength=findspos(ring0(el1:el2-1),el2-el1+1)/npts;
0105 r2=cellfun(@splitelem,ring0(el1:el2-1),'UniformOutput',false);
0106 ring=cat(1,ring0(1:el1-1),r2{:},ring0(el2:elt0));
0107 plrange=el1:el2+length(ring)-elt0;
0108 
0109 [s,outp]=plotfun(ring,curve.dpp,plotargs{:});
0110 if numel(outp) >= 2
0111     [ax2,curve.left,curve.right]=plotyy(ax,...
0112         s(plrange),outp(1).values(plrange,:),...
0113         s(plrange),outp(2).values(plrange,:));
0114     set(ax2(2),'XTick',[],'YColor',get(ax2(1),'YColor'),rightargs{:});
0115     ylabel(ax2(1),outp(1).axislabel);
0116     ylabel(ax2(2),outp(2).axislabel);
0117     linkaxes([ax2(1) ax2(2)],'x');% allows zoom on both right and left plots
0118 elseif numel(outp) == 1
0119     curve.left=plot(ax,s(plrange),outp(1).values(plrange,:));
0120     curve.right=[];
0121     ylabel(ax,outp(1).axislabel);
0122 else
0123     curve.left=[];
0124     curve.right=[];
0125     set(ax,'YLim',[0 1]);
0126 end
0127 set(ax,'XLim',srange,'XGrid','on','YGrid','on',leftargs{:});
0128 xlabel(ax,'s [m]');
0129 if synopt
0130     curve.lattice=atplotsyn(ax,ring0,rsrc{:});  % Plot lattice elements
0131 end
0132 lines=[curve.left;curve.right];
0133 if ~isempty(lines)
0134     legend(lines,[outp.labels],'FontSize',11);
0135 end
0136 
0137     function newelems=splitelem(elem)
0138         if isfield(elem,'Length') && elem.Length > 0
0139             nslices=ceil(elem.Length/elmlength);
0140             newelems=atdivelem(elem,ones(1,nslices)./nslices);
0141         else
0142             newelems={elem};
0143         end
0144     end
0145 
0146     function [cellsize,np,cell]=get1cell(ring)
0147         [cellsize,np]=size(ring);
0148         cell=ring(:,1);
0149         params=atgetcells(cell,'Class','RingParam');
0150         if any(params)
0151             np=ring{find(params,1)}.Periodicity;
0152         end
0153     end
0154 end
0155 
0156 function [s,plotdata]=defaultplot(ring,dpp,varargin) %#ok<INUSD>
0157 %DEFAULTPLOT    Default plotting function for ATBASEPLOT
0158 %Plots nothing
0159 
0160 s=[];
0161 plotdata=[];
0162 end

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005