View Raw SPL
/*****************************************************************************
*                                                                            *
*   MARKMIN.SPL   Copyright (C) 2000, 2010 DSP Development Corporation       *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:       Randy Race                                                 *
*                                                                            *
*   Synopsis:     Marks the minimum of a series with a symbol                *
*                                                                            *
*   Revisions:     7 Mar 2000  RRR  Creation                                 *
*                 23 Jul 2010  RRR  set to "point" style                     *
*                                                                            *
*****************************************************************************/

#include 

#if @HELP_MARKMIN

    MARKMIN

    Purpose: Marks the minimum of a series with a symbol

    Syntax:  MARKMIN(s, color, symbol)

                s - an optional series, defaults to the current Window

            color - an option integer, the color for the mimimum
                    marker, defaults to SERIESGREEN

           symbol - an optional integer, the symbol for the minimum
                    marker, defaults to UP_ARROW



    Returns: Nothing, overplots the series with a symbol

    Example:

             W1: gnorm(1000,.01);markmin;

             creates 1000 samples of uniformly distributed
             random noise an marks the minimum with a light
             green up arrow.

    Example:
             W1: gnorm(1000,.01);markmin(BLUE, CIRCLE)

             Same as above except the minimum is marked with
             a blue circle.

    Example:
             W1: randn(100,100);setplotstyle(2);markmin

             Creates a 100x100 image and marks the minimum.


    Remarks:
             If the series is XYZ or a LIST (i.e. Z surface, density
             or contour), MARKMIN overplots an XYZ series.


    See Also:
             Find
             Findmax
             Findmin
             Findval
             Markmin
             Maxloc
             Minloc

#endif


/* marks the minimum of a series with a symbol */
markmin(s, color, symbol)
{
        local x, y, z, minser;

        if (argc < 3)
        {
                if (argc < 2)
                {
                        if (argc < 1)
                        {
                                s = refseries();
                        }
                        
                        /* markmin(color) */
                        if (not(isarray(s)))
                        {
                                color = castint(s);
                                s     = refseries();
                        }
                        else
                        {
                                color = SERIESGREEN;
                        }
                }
                
                if (not(isarray(s)))
                {
                        /* markmin(color, symbol) */
                        symbol = color;
                        color  = s;
                        s      = refseries();
                }
                else
                {
                        symbol = UP_ARROW;
                }
        }

        /* get min values */
        (x, y, z) = minloc(s);

        if (ISLIST(s) || isxyz(s))
        {
                /* has z values */
                minser = xyz({x}, {y}, {z});
                setzunits(minser, getzunits(s));
        }
        else
        {
                /* regular series type - create XY series */
                minser = xy({x}, {y});
        }

        /* point plot style */
        setplotstyle(minser, 1);

        setcomment(minser, "Minimum Marker");
        setvunits(minser, getvunits(s));
        sethunits(minser, gethunits(s));

        /* set symbol type */
        if (symbol != 0)
        {
                /* if using a value, force it to print below the symbol */
                if (symbol > 1000) symbol += 2000;
                
                setsym(minser, symbol);
        }

        /* overplot with no rescaling */
        overp(minser, color, 0);
}