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/applyfit2d.c

    r16428 r20936  
    11# include "data.h"
    2 
    3 char *get_variable (char *);
    42
    53int applyfit2d (int argc, char **argv) {
     
    86  char *c, name[64];
    97  double **C, X, Y;
    10   float *x, *y, *z;
     8  opihi_flt *z;
    119  Vector *xvec, *yvec, *zvec;
    1210
     
    4543  }
    4644
    47   zvec[0].Nelements = xvec[0].Nelements;
    48   REALLOCATE (zvec[0].elements, float, zvec[0].Nelements);
    49   bzero (zvec[0].elements, sizeof(float)*zvec[0].Nelements);
    50   x = xvec[0].elements;
    51   y = yvec[0].elements;
    52   z = zvec[0].elements;
     45  ResetVector (zvec, OPIHI_FLT, xvec[0].Nelements);
     46  bzero (zvec[0].elements.Flt, sizeof(opihi_flt)*zvec[0].Nelements);
     47  z = zvec[0].elements.Flt;
    5348
    54   for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) {
    55     Y = X = 1;
    56     for (j = 0; j < order + 1; j++) {
    57       X = Y;
    58       for (i = 0; i < order + 1 - j; i++) {
    59         *z += C[i][j]*X;
    60         X = X * (*x);
     49  // we have four cases (x == flt or int) and (y == flt or int)
     50  if ((xvec[0].type == OPIHI_FLT) && (yvec[0].type == OPIHI_FLT)) {
     51    opihi_flt *x = xvec[0].elements.Flt;
     52    opihi_flt *y = yvec[0].elements.Flt;
     53    for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) {
     54      Y = X = 1;
     55      for (j = 0; j < order + 1; j++) {
     56        X = Y;
     57        for (i = 0; i < order + 1 - j; i++) {
     58          *z += C[i][j]*X;
     59          X = X * (*x);
     60        }
     61        Y = Y * (*y);
    6162      }
    62       Y = Y * (*y);
    6363    }
    6464  }
     65  if ((xvec[0].type == OPIHI_FLT) && (yvec[0].type == OPIHI_INT)) {
     66    opihi_flt *x = xvec[0].elements.Flt;
     67    opihi_int *y = yvec[0].elements.Int;
     68    for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) {
     69      Y = X = 1;
     70      for (j = 0; j < order + 1; j++) {
     71        X = Y;
     72        for (i = 0; i < order + 1 - j; i++) {
     73          *z += C[i][j]*X;
     74          X = X * (*x);
     75        }
     76        Y = Y * (*y);
     77      }
     78    }
     79  }
     80  if ((xvec[0].type == OPIHI_INT) && (yvec[0].type == OPIHI_FLT)) {
     81    opihi_int *x = xvec[0].elements.Int;
     82    opihi_flt *y = yvec[0].elements.Flt;
     83    for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) {
     84      Y = X = 1;
     85      for (j = 0; j < order + 1; j++) {
     86        X = Y;
     87        for (i = 0; i < order + 1 - j; i++) {
     88          *z += C[i][j]*X;
     89          X = X * (*x);
     90        }
     91        Y = Y * (*y);
     92      }
     93    }
     94  }
     95  if ((xvec[0].type == OPIHI_INT) && (yvec[0].type == OPIHI_INT)) {
     96    opihi_int *x = xvec[0].elements.Int;
     97    opihi_int *y = yvec[0].elements.Int;
     98    for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) {
     99      Y = X = 1;
     100      for (j = 0; j < order + 1; j++) {
     101        X = Y;
     102        for (i = 0; i < order + 1 - j; i++) {
     103          *z += C[i][j]*X;
     104          X = X * (*x);
     105        }
     106        Y = Y * (*y);
     107      }
     108    }
     109  }
     110
    65111  for (i = 0; i < order + 1; i++) free (C[i]);
    66112  free (C);
Note: See TracChangeset for help on using the changeset viewer.