View Raw SPL
/*****************************************************************************
*                                                                            *
*   ISWINDOW.SPL Copyright (C) 2010 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Returns 1 if input is a window                              *
*                                                                            *
*   Revisions:   18 Jul 2010  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/

#include 


#if @HELP_ISWINDOW

    ISWINDOW

    Purpose: Returns 1 if input parameter is a window

    Syntax:  ISWINDOW(val, as_string)

                    val - series, window or string input

              as_string - Optional. An integer, test VAL as string. Defaults
                          to 0, test VAL as specified

    Returns: The window 1 if the input is a window, else 0.

    Example:
             iswindow(W1)

             returns 1

    Example:
             iswindow(W1 + 1)

             returns 0 because the input is a series

    Example:
             win = refwindow(W1);
             iswindow(win);

             returns 1 because the input refers to a window

    Example:
             iswindow("W1")

             returns 0 because the input is a string

    Example:
             iswindow("W1", 1)

             returns 1 because the input is a string that refers to a window.

    Remarks:
             By default, if the input is not a window or window reference, 
             ISWINDOW returns 0.

             If AS_STRING is 1 and VAL is a string, the string is tested as
             refering to a window. This mode allows for fast testing
             without a possible lengthy evaluation. For example:

                 a = iswindow(1..(1024*1024*128));
                 b = iswindow("1..(1024*1024*128)", 1);

             Both A and B are 0, but A requires a lengthy evaluation to 
             determine the input is not a window whereas B simply examines
             the input string for much faster evaluation.

    See Also:
             Isarray
             Iscomplex
             Isreal
             Isscalar

#endif



/* is input window ? */
iswindow(w, as_string = 0)
{
        if (argc < 1)
        {
                /* implies current window */
                return(1);
        }

        if (as_string && isstring(w))
        {
                return(eval(sprintf("isvariable('%s', 6)", w)));
        }
        else
        {
                /* test value for window */
                return(IS_WINDOW(w));
        }
}


/* error handler - return 0 for not a window */
iswindow_error()
{
        return(0);
}