View Raw SPL
/*****************************************************************************
*                                                                            *
*   WINFLIPY.SPL Copyright (C) 2015 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Flips Y scale orientation of an window                      *
*                                                                            *
*   Revisions:   25 Nov 2015  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_WINFLIPY

    WINFLIPY

    Purpose: Flips the Y scales of a window

    Syntax:  WINFLIPY(win, updown)

              win    - Optional. A window, defaults to current window
              updown - Optional. An integer, the scales mode:
              
                        0: bottom to top
                        1: top to bottom (default)

    Returns: Nothing, the Y scales are flipped.

    Example:
             W1: integ(gnorm(1000, 1));
             W2: w1;winflipy

             W1 and W2 contain the same series. The Y scales go upward from
             the smallest to the largest value in W1 and the Y scales go
             upward from the largest to the smallest value in W2.

    Example:
             W1: Density(spline2(rand(5), 20));
             W2: w1;winflipy

             W1 and W2 contain the same image. The Y scales go upward from
             the smallest to the largest value in W1 and the Y scales go
             upward from the largest to the smallest value in W2.

    Remarks:
             WINFLIPY changes the direction of the Y scales of a Window, 
             the actual data remains unchanged.

    See Also:
             Sety
             Setyauto
             Winflipx
#endif


/* flip y scales on series or image */
winflipy(argv)
{
        local w, mode;

        w    = {};
        mode = 1;

        loop (j = 1..argc)
        {
                arg = getargv(j);

                if (iswindow(getargv(j)))
                {
                        w = refwindow(getargv(j));
                }
                else if (isscalar(getargv(j)))
                {
                        mode = getargv(j);
                }
        }

        if (isempty(w))
        {
                w = refwindow(w0);
        }

        switch (mode)
        {
                case 0:
                default:
                        setyauto(w, -1, -1);
                        autoscale(w);
                        break;

                case 1:
                        setyauto(w, -1, -1);
                        autoscale(w);
                        setyauto(w, getyt(w), getyb(w));
                        autoscale(w);
                        break;
        }
}