00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00017
00018
00019
00021
00022 #include <Stiostream.h>
00023 #include <math.h>
00024 #include "StMessMgr.h"
00025
00026
00027 int Locate(const int npt, const float* x, const float xx)
00028 {
00029
00030
00031
00032
00033 int jlow = 0;
00034 int jup = npt-1;
00035 int jmid;
00036 int rising = (x[npt-1] > x[0]) ? (1) : (0) ;
00037
00038 if ( (rising && (xx > x[jup] || xx < x[jlow])) ||
00039 (!rising && (xx < x[jup] || xx > x[jlow])) ) {
00040 LOG_WARN << "Locate(): xx is out of range!" << endm;
00041 return 0;
00042 }
00043
00044 while (jup-jlow-1 ) {
00045 jmid = (jlow + jup)/2;
00046
00047 if ( (rising && (xx > x[jmid])) ||
00048 (!rising && (xx < x[jmid])) ) {
00049 jlow = jmid;
00050 }
00051 else {
00052 jup = jmid;
00053 }
00054 }
00055
00056 return jlow;
00057 }
00058