View Raw SPL
/****************************************************************************
*                                                                           *
*   SETXTIME.SPL Copyright 2010 (C) DSP Development Corporation             *
*                                                                           *
*   Author:      Randy Race                                                 *
*                                                                           *
*   Synopsis:    Sets X coordinates in time values                          *
*                                                                           *
*   Revisions:   12 Apr 2010     RRR     Creation                           *
*                                                                           *
****************************************************************************/

#include 

#if @HELP_SETXTIME

    SETXTIME

    Purpose: Specifies the x-axis coordinate range of a Window by time values.

    Syntax:  SETXTIME(window, "xltime", "xrtime")

              window - Optional. Window reference. Defaults to the current
                       Window.

              xltime - A string. Left hand Window time.

              xrtime - A string. Right hand Window time.


    Returns: Nothing, the x-axis range is set in terms of time.


    Example:
             W1:gnorm(1000, 1);settime("8:00");sethunits("time");
             setxtime(W1, "8:05", "8:10");

             creates a 1000 point series with horizontal time units of
             Time. The starting time is 8:00. The X axis is set to
             display data between 8:05 and 8:10.

    Remarks:
             SETXTIME will expand or compress the current units scale. 

             The horizontal units of the series must be a time unit
             such as Time or Real Time.

             See SETXDATE to set the x-axis coordinates in date values.

             See SETX to set the x-axis coordinates in terms of the
             delta-x between values.

             See SETHUNITS to set the x-axis units to a time unit.

    See Also:
             GETXL
             GETXR
             GETXDATE
             GETXTIME
             SETX 
             SETHUNITS
             SETXDATE
#endif


/* set x axis based on time strings */
setxtime(win, xl, xr)
{
        local offset;

        (win, xl, xr) = setxtime_parse_args(win, xl, xr);

        offset = setxtime_offset(win);

        setx(castwindow(win), todmsecstr(xl) - offset, todmsecstr(xr) - offset);
}


setxtime_parse_args(win, xl, xr)
{
        local wnum;

        if (argc < 3)
        {
                if (argc < 2)
                {
                        if (argc < 1)
                        {
                                wnum = getwnum();
                        }

                        if (iswindow(win))
                        {
                                wnum = getwnum(win);
                                xl   = strtodmsec(getxl(castwindow(wnum))+setxtime_offset(wnum));
                                xr   = strtodmsec(getxr(castwindow(wnum))+setxtime_offset(wnum));
                        }
                        else if (isstring(win))
                        {
                                wnum = getwnum();
                                xl   = win;
                                xr   = strtodmsec(getxr(castwindow(wnum))+setxtime_offset(wnum));
                        }
                }
                else if (iswindow(win))
                {
                        wnum = getwnum(win);

                        if (isstring(xl))
                        {
                                xr = strtodmsec(getxr(castwindow(wnum))+setxtime_offset(wnum));
                        }
                        else
                        {
                                error("setxtime - time string required");
                        }
                }
                else if (isstring(win) && isstring(xl))
                {
                        wnum = getwnum();
                        xr   = xl;
                        xl   = win;
                }
                else
                {
                        error("setxtime - time string required");
                }
        }
        else if (iswindow(win) && isstring(xl) && isstring(xr))
        {
                wnum = getwnum(win);
        }
        else
        {
                error("setxtime - time string required");
        }

        return(wnum, xl, xr);
}


/* time offset based on start time */
setxtime_offset(wnum)
{
        local offset;

        /* get start time to axis precision */
        offset = todmsecstr(gettime(castwindow(wnum), 1));

        return(offset);
}