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

    r7917 r20936  
    66 
    77  char *out;
    8   int  i, j, size;
     8  int  i, Npts, size;
    99  Vector *ivec, *ovec, *tvec;
    1010
     
    2828  /* check size of ivec, tvec: must match */
    2929
    30   REALLOCATE (ovec[0].elements, float, MAX (tvec[0].Nelements, 1));
    31   for (j = i = 0; i < tvec[0].Nelements; i++) {
    32     if (tvec[0].elements[i]) {
    33       ovec[0].elements[j] = ivec[0].elements[i];
    34       j++;
     30  // ovec matches ivec in type
     31  ResetVector (ovec, ivec->type, MAX (tvec[0].Nelements, 1));
     32
     33  // we have four cases: (ivec == flt or int) and (tvec == flt or int)
     34  if ((ivec->type == OPIHI_FLT) && (tvec->type == OPIHI_FLT)) {
     35    opihi_flt *vi = ivec[0].elements.Flt;
     36    opihi_flt *vt = tvec[0].elements.Flt;
     37    for (Npts = i = 0; i < tvec[0].Nelements; i++, vi++, vt++) {
     38      if (!*vt) continue;
     39      ovec[0].elements.Flt[Npts] = *vi;
     40      Npts++;
    3541    }
    3642  }
    37   ovec[0].Nelements = j;
    38   REALLOCATE (ovec[0].elements, float, MAX (ovec[0].Nelements, 1));
     43  if ((ivec->type == OPIHI_FLT) && (tvec->type == OPIHI_INT)) {
     44    opihi_flt *vi = ivec[0].elements.Flt;
     45    opihi_int *vt = tvec[0].elements.Int;
     46    for (Npts = i = 0; i < tvec[0].Nelements; i++, vi++, vt++) {
     47      if (!*vt) continue;
     48      ovec[0].elements.Flt[Npts] = *vi;
     49      Npts++;
     50    }
     51  }
     52  if ((ivec->type == OPIHI_INT) && (tvec->type == OPIHI_FLT)) {
     53    opihi_int *vi = ivec[0].elements.Int;
     54    opihi_flt *vt = tvec[0].elements.Flt;
     55    for (Npts = i = 0; i < tvec[0].Nelements; i++, vi++, vt++) {
     56      if (!*vt) continue;
     57      ovec[0].elements.Int[Npts] = *vi;
     58      Npts++;
     59    }
     60  }
     61  if ((ivec->type == OPIHI_INT) && (tvec->type == OPIHI_INT)) {
     62    opihi_int *vi = ivec[0].elements.Int;
     63    opihi_int *vt = tvec[0].elements.Int;
     64    for (Npts = i = 0; i < tvec[0].Nelements; i++, vi++, vt++) {
     65      if (!*vt) continue;
     66      ovec[0].elements.Int[Npts] = *vi;
     67      Npts++;
     68    }
     69  }
     70
     71  // free up unused memory
     72  ResetVector (ovec, ivec->type, MAX (Npts, 1));
    3973
    4074  DeleteVector (tvec);
Note: See TracChangeset for help on using the changeset viewer.