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

    r8131 r20936  
    55  int  i, j, Nin;
    66  double value;
     7  opihi_flt *temp;
    78  Vector *ivec, *ovec;
    89
     
    1920    Nin = ovec[0].Nelements;
    2021    ovec[0].Nelements++;
    21     REALLOCATE (ovec[0].elements, float, ovec[0].Nelements);
    22     ovec[0].elements[Nin] = value;
     22    if (ovec[0].type == OPIHI_FLT) {
     23      REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements);
     24      ovec[0].elements.Flt[Nin] = value;
     25    } else {
     26      REALLOCATE (ovec[0].elements.Int, opihi_int, ovec[0].Nelements);
     27      ovec[0].elements.Int[Nin] = value;
     28    }
    2329    return (TRUE);
    2430  }
     
    2632  if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    2733 
    28   REALLOCATE (ovec[0].elements, float, ovec[0].Nelements + ivec[0].Nelements);
    29   for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
    30     ovec[0].elements[j] = ivec[0].elements[i];
     34  // we have 4 cases: (ivec == flt or int) and (ovec == flt or int)
     35  if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_FLT)) {
     36    REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements);
     37    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     38      ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i];
     39    }
    3140  }
     41  if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_INT)) {
     42    REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements);
     43    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     44      ovec[0].elements.Flt[j] = ivec[0].elements.Int[i];
     45    }
     46  }
     47  if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_INT)) {
     48    REALLOCATE (ovec[0].elements.Int, opihi_int, ovec[0].Nelements + ivec[0].Nelements);
     49    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     50      ovec[0].elements.Int[j] = ivec[0].elements.Int[i];
     51    }
     52  }
     53
     54  // this case forces ovec to be raised to FLT
     55  if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_FLT)) {
     56    ALLOCATE (temp, opihi_flt, ovec[0].Nelements + ivec[0].Nelements);
     57    for (i = 0; i < ovec[0].Nelements; i++) {
     58      temp[i] = ovec[0].elements.Int[i];
     59    }
     60    ovec[0].type = OPIHI_FLT;
     61    free (ovec[0].elements.Int);
     62    ovec[0].elements.Flt = temp;
     63    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     64      ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i];
     65    }
     66  }
     67
    3268  ovec[0].Nelements += ivec[0].Nelements;
    33  
    3469  return (TRUE);
    35    
    3670}
Note: See TracChangeset for help on using the changeset viewer.