IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 30, 2008, 11:13:15 AM (18 years ago)
Author:
eugene
Message:

allow functions to use FLT or INT vectors as appropriate; document valid types

File:
1 edited

Legend:

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

    r20839 r20859  
    33int integrate (int argc, char **argv) {
    44 
    5   int i, N, VERBOSE;
     5  int i, N, VERBOSE, isFloat;
    66  opihi_flt *X, *Y;
    7   double start, end, value, range;
     7  double start, end, value, range, dvalue;
    88  Vector *vecx, *vecy;
    99
     
    2525  end   = atof (argv[4]);
    2626
    27   X = vecx[0].elements.Flt;
    28   Y = vecy[0].elements.Flt;
     27  isFloat = vecy[0].type == OPIHI_FLT;
     28  Yf = vecy[0].elements.Flt;
     29  Yi = vecy[0].elements.Int;
    2930
    3031  value = 0;
    3132  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   }     
     33
     34  if (vecx[0].type == OPIHI_FLT) {
     35    opihi_flt *X = vecx[0].elements.Flt;
     36    for (i = 0; i < vecx[0].Nelements-1; i++, X++, Yi++, Yf++) {
     37      if ((*X >= start) && (*X <= end)) {
     38        dvalue = (isFloat) ? *Yf : *Yi;
     39        value += *Y * (X[1] - X[0]);
     40        range += (X[1] - X[0]);
     41      }
     42    }     
     43  } else {
     44    opihi_int *X = vecx[0].elements.Int;
     45    for (i = 0; i < vecx[0].Nelements-1; i++, X++, Yi++, Yf++) {
     46      if ((*X >= start) && (*X <= end)) {
     47        dvalue = (isFloat) ? *Yf : *Yi;
     48        value += *Y * (X[1] - X[0]);
     49        range += (X[1] - X[0]);
     50      }
     51    }     
     52  }
    3853
    3954  set_variable ("sum", value);
Note: See TracChangeset for help on using the changeset viewer.