View Raw SPL
/*****************************************************************************
*                                                                            *
*   SETVPORT.SPL Copyright (C) 1998-2012 DSP Development Corporation         *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Sets the viewport to the viewport of the input window       *
*                                                                            *
*   Revisions:    8 Jun 1998  RRR  Creation                                  *
*                 4 Jan 1999  RRR  Added optional destination window         *
*                20 Jan 2012  RRR  multiple destination windows              *
*                                                                            *
*****************************************************************************/

#include 

#if @HELP_SETVPORT

    SETVPORT

    Purpose: Sets the viewport of one or more windows to the input window.

    Syntax:  SETVPORT(srcwin, win1, win2, .., winN)

              srcwin - A window, the template window.

              winN   - Optional. One or more destination windows, the 
                       windows to modify, defaults to the current window.

    Returns: Nothing

    Example:
             W1: Gnorm(1000,.01);setx(.2, .5)
             W2: W1*W1;setvport(w1);

             The squared data in W2 is displayed with the same X and Y
             range as W1.

    Example:
             setvport(w1, w2)

             Same as above, but the destination window, W2, is explicit.

    Example:
             W3:Gnorm(100,1);onplot(eval("setvport(w3, w2, w4)"))
             W4:Gsin(100,1,.02)

             The viewports of W2 and W4 are linked to the viewport of
             W3.  W2 and W4 will scroll, expand or compress whenever W3
             scrolls, expands or compresses (ONPLOT). The ONPLOT
             function uses EVAL to prevent W3 from referring to itself.

    Remarks:
             SETVPORT also properly on arrays and images and is useful
             when visually comparing data.

    See Also:
             Cut
             Eval
             Onplot
             Setwlike
#endif


/* set one or more window viewports */
setvport(src, argv)
{
        local xl, xr, yb, yt, des, i;

        if (argc > 0)
        {
                if (not(iswindow(src)))
                {
                        error("setvport - Window Required");
                }

                xl = getxl(src);
                xr = getxr(src);
                yb = getyb(src);
                yt = getyt(src);

                if (argc > 1)
                {
                        loop (i = 1..(argc - 1))
                        {
                                des = getargv(i);

                                if (iswindow(des))
                                {
                                        setx(des, xl, xr);
                                        sety(des, yb, yt);
                                }
                        }
                }
                else
                {
                        setx(xl, xr);
                        sety(yb, yt);
                }
        }
        else
        {
                error("setvport - Window Required");
        }
}