IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 7, 2008, 3:31:01 PM (18 years ago)
Author:
eugene
Message:

big update from eam_branch_20081124 with updates to Opihi math

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/integrate.c

    r7917 r20936  
    33int integrate (int argc, char **argv) {
    44 
    5   int i, N, VERBOSE;
    6   float *X, *Y;
    7   double start, end, value, range;
     5  int i, N, VERBOSE, isFloat;
     6  opihi_flt *Yf;
     7  opihi_int *Yi;
     8  double start, end, value, range, dvalue;
    89  Vector *vecx, *vecy;
    910
     
    2526  end   = atof (argv[4]);
    2627
    27   X = vecx[0].elements;
    28   Y = vecy[0].elements;
     28  isFloat = vecy[0].type == OPIHI_FLT;
     29  Yf = vecy[0].elements.Flt;
     30  Yi = vecy[0].elements.Int;
    2931
    3032  value = 0;
    3133  range = 0;
    32   for (i = 0; i < vecx[0].Nelements-1; i++, X++, Y++) {
    33     if ((*X >= start) && (*X <= end)) {
    34       value += *Y * (X[1] - X[0]);
    35       range += (X[1] - X[0]);
    36     }
    37   }     
     34
     35  if (vecx[0].type == OPIHI_FLT) {
     36    opihi_flt *X = vecx[0].elements.Flt;
     37    for (i = 0; i < vecx[0].Nelements-1; i++, X++, Yi++, Yf++) {
     38      if ((*X >= start) && (*X <= end)) {
     39        dvalue = (isFloat) ? *Yf : *Yi;
     40        value += dvalue * (X[1] - X[0]);
     41        range += (X[1] - X[0]);
     42      }
     43    }     
     44  } else {
     45    opihi_int *X = vecx[0].elements.Int;
     46    for (i = 0; i < vecx[0].Nelements-1; i++, X++, Yi++, Yf++) {
     47      if ((*X >= start) && (*X <= end)) {
     48        dvalue = (isFloat) ? *Yf : *Yi;
     49        value += dvalue * (X[1] - X[0]);
     50        range += (X[1] - X[0]);
     51      }
     52    }     
     53  }
    3854
    3955  set_variable ("sum", value);
Note: See TracChangeset for help on using the changeset viewer.