View Raw SPL
/*****************************************************************************
*                                                                            *
*   XYALT.SPL       Copyright (C) 2011 DSP Development Corporation           *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:         Randy Race                                               *
*                                                                            *
*   Synopsis:       Creates an XY plot with alternate X labels               *
*                                                                            *
*   Revisions:      15 Aug 2011  RRR  Creation                               *
*                                                                            *
*****************************************************************************/


#if @HELP_XYALT

    XYALT

    Purpose: Creates an XY plot with alternate X scales.

    Syntax:  XYALT(x, xalt, y, scales1, scales2)

                    x - A series. The primary X values.
 
                 xalt - A series. The alternate X values.

                    y - A series. The Y values.

              scales1 - Optional. An integer, the primary axis label
                        type. Defaults to 2, X bottom, Y left with labels.

              scales2 - Optional. An integer, the alternate axis label
                        type. Defaults to 16, X top with labels.

    Returns: An XY series. The series is plotted with two sets of X axes.

    Example:
             W1: integ(gnorm(1000, 1));setvunits("V")
             W2: xvals(w1)
             W3: rev((xvals(w1)/100)^2);setvunits("N")
             W4: xyalt(w2, w3, w1)

             W4 contains an XY plot where the primary X values are in Seconds
             and derived from W2. The alternate X values are in Newtons and
             derived from W3. The resulting plot displays the primary X values
             at the bottom of the plot and the alternate X values at the top
             of the plot. The plot shows the corresponding Newton value for
             a given time value. 

    Example:
             W1: integ(gnorm(1000, 1));setvunits("V")
             W2: xvals(w1)
             W3: rev((xvals(w1)/100)^2);setvunits("N")
             W4: xyalt(w3, w2, w1)

             Same as the previous example except Newtons are the primary X
             values and Seconds are the alternate values.   

    Remarks:
             XYALT displays an XY plot with two sets of X axes. Because
             the alternate X axis is synched to the primary X axis, the
             alternate X axis tic values may not occur at a regular
             interval.

             See SCALES for a description of axes display options.

    See Also:
             Overlay
             Scales
             XY
#endif


/* XY plot with alternate X axis */
xyalt(x, xalt, y, scales1, scales2)
{
        local altxy;

        if (argc < 5)
        {
                if (argc < 4)
                {
                        if (argc < 3) error("xyalt - 2 X series and 1 Y series required");

                        scales1 = -1;
                }

                scales2 = -1;
        }

        if (scales2 < 0)
        {
                /* secondary scales - X top with labels */
                scales2 = 16;
        }

        if (scales1 < 0)
        {
                /* primary scales, X bottom, Y left with labels */
                scales1 = 2;
        }

        /* defer plotting */
        plotmode(w0, 0);

        /* create xy alternate series */
        altxy = xy(xalt, y, x);

        /* place xy plot in current window as host */
        xy(x, y);

        /* overlay alternate xy with transparent color */
        overlay(altxy, w0, -10);

        /* set secondary scales */
        focus(2);
        scales(scales2);

        /* set primary scales */
        focus(1);
        scales(scales1);
        
        /* set sync and scaling */
        autosync();

        /* show it */
        plotmode(w0, 1);
}