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

#include 

#if @HELP_SETXDATE

    SETXDATE

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

    Syntax:  SETXDATE(window, "xldate", "xrdate")

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

              xldate - A string. Left hand Window date.

              xrdate - A string. Right hand Window date.


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


    Example:
             W1:gnorm(1000, 1);setdate("1-1-2010");sethunits("daily");
             setxdate(W1,"7-20-10", "8-24-2011");

             creates a 1000 point series with horizontal time units of
             Daily. The starting date is 1-1-2010. The X axis is set
             to display data between 7-20-2010 and 8-24-2011. 

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

             The horizontal units of the series must be a date unit
             such as Daily, Monthly or Yearly.

             See SETXTIME to set the x-axis coordinates in time 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
             SETXTIME
#endif


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

        (win, xl, xr) = setxdate_parse_args(win, xl, xr);
        offset = setxdate_offset(win);

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


setxdate_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   = strjul(castint(getxl(castwindow(wnum))+setxdate_offset(wnum)));
                                xr   = strjul(castint(getxr(castwindow(wnum))+setxdate_offset(wnum)));
                        }
                        else if (isstring(win))
                        {
                                wnum = getwnum();
                                xl   = win;
                                xr   = strjul(castint(getxr(castwindow(wnum))+setxdate_offset(wnum)));
                        }
                }
                else if (iswindow(win))
                {
                        wnum = getwnum(win);
                        
                        if (isstring(xl))
                        {
                                xr = strjul(castint(getxr(castwindow(wnum))+setxdate_offset(wnum)));
                        }
                        else
                        {
                                error("setxdate - date string required");
                        }
                }
                else if (isstring(win) && isstring(xl))
                {
                        wnum = getwnum();
                        xr   = xl;
                        xl   = win;
                }
                else
                {
                        error("setxdate - date string required");
                }
        }
        else if (iswindow(win) && isstring(xl) && isstring(xr))
        {
                wnum = getwnum(win);
        }
        else
        {
                error("setxdate - date string required");
        }
        
        return(wnum, xl, xr);
}


/* date offset based on start date */
setxdate_offset(wnum)
{
        local offset;

        offset = julstr(getdate(castwindow(wnum)));
        
        return(offset);
}