IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 24, 2006, 3:06:51 PM (20 years ago)
Author:
magnier
Message:

added psVectorBracketDescend for reverse-sorted vectors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/psVectorBracket.c

    r8885 r8927  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-09-22 21:35:10 $
     7 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-09-25 01:06:51 $
    99 *
    1010 *  Copyright 2006 Institute for Astronomy, University of Hawaii
     
    5959}
    6060
     61// return the last entry below or first entry above key value (reverse sorted input)
     62int psVectorBracketDescend (psVector *index, psF32 key, bool above)
     63{
     64
     65    int N;
     66    int Nhi = 0;
     67    int Nlo = index->n;
     68
     69    if (above) {
     70        while (Nlo - Nhi > 10) {
     71            N = 0.5*(Nhi + Nlo);
     72            if (index->data.F32[N] < key) {
     73                Nlo = N;
     74            } else {
     75                Nhi = N - 1;
     76            }
     77        }
     78        // at this point, index[Nhi] >= key > index[Nlo]
     79        N = Nhi;
     80        while ((index->data.F32[N] >= key) && (N < Nlo)) {
     81            N++;
     82        }
     83        return (N);
     84    }
     85    while (Nlo - Nhi > 10) {
     86        N = 0.5*(Nhi + Nlo);
     87        if (index->data.F32[N] > key) {
     88            Nhi = N;
     89        } else {
     90            Nlo = N + 1;
     91        }
     92    }
     93    // at this point, index[Nhi] > key >= index[Nlo]
     94    N = Nlo;
     95    while ((index->data.F32[N] <= key) && (N > Nhi)) {
     96        N--;
     97    }
     98    return (N);
     99}
     100
    61101// search for the bins bounding key in index, interpolate the corresponding values
    62102psF32 psVectorInterpolate (psVector *index, psVector *value, psF32 key)
Note: See TracChangeset for help on using the changeset viewer.