View Raw SPL
/*****************************************************************************
*                                                                            *
*   FINDROW.SPL  Copyright (C) 2007 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Returns the rows that meet a condition                      *
*                                                                            *
*   Revisions:    5 Oct 2007  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_FINDROW

    FINDROW

    Purpose: Returns the rows that meet a condition.

    Syntax:  FINDROW(cond)

              cond - A binary series representing a condition.

    Returns: A series, the rows that meet the condition.

    Example:
             W1: ravel(1..12, 4);
             W2: findrow(W1 > 10);

             W1 == {{1, 5,  9},
                    {2, 6, 10},
                    {3, 7, 11},
                    {4, 8, 12}}

             W2 == {3, 4}

             Indicating that rows 3 and 4 meet the condtion W1 > 10.

    Remarks:
             A row value is returned only once even if multiple values in
             a row meet the condition.

    See Also:
             Find
             Findcol
#endif


/* find rows that meet a condition */
findrow(cond)
{
        local r, c, d;

        /* rows and cols that meet condition */
        (r, c) = find(cond);

        if (length(r) > 1)
        {
                /* sort rows in ascending order */
                r = sort(r, -1);

                /* find duplicates */
                d = extract(r - delay(r, 1), 2, -1);

                /* remove duplicates */
                r = delete(r, d == 0);
        }

        return(r);
}