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

    r20839 r20859  
    1919    Nin = ovec[0].Nelements;
    2020    ovec[0].Nelements++;
    21     REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements);
    22     ovec[0].elements.Flt[Nin] = value;
     21    if (ovec[0].type == OPIHI_FLT) {
     22      REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements);
     23      ovec[0].elements.Flt[Nin] = value;
     24    } else {
     25      REALLOCATE (ovec[0].elements.Int, opihi_int, ovec[0].Nelements);
     26      ovec[0].elements.Int[Nin] = value;
     27    }
    2328    return (TRUE);
    2429  }
     
    2631  if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    2732 
    28   REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements);
    29   for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
    30     ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i];
     33  // we have 4 cases: (ivec == flt or int) and (ovec == flt or int)
     34  if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_FLT)) {
     35    REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements);
     36    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     37      ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i];
     38    }
    3139  }
     40  if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_INT)) {
     41    REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements);
     42    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     43      ovec[0].elements.Flt[j] = ivec[0].elements.Int[i];
     44    }
     45  }
     46  if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_INT)) {
     47    REALLOCATE (ovec[0].elements.Int, opihi_int, ovec[0].Nelements + ivec[0].Nelements);
     48    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     49      ovec[0].elements.Int[j] = ivec[0].elements.Int[i];
     50    }
     51  }
     52
     53  // this case forces ovec to be raised to FLT
     54  if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_FLT)) {
     55    ALLOCATE (temp, opihi_flt, ovec[0].Nelements + ivec[0].Nelements);
     56    for (i = 0; i < ovec[0].Nelements; i++) {
     57      temp[i] = ovec[0].elements.Int[i];
     58    }
     59    ovec[0].type = OPIHI_FLT;
     60    free (ovec[0].elements.Int);
     61    ovec[0].elements.Flt = temp;
     62    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     63      ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i];
     64    }
     65  }
     66
    3267  ovec[0].Nelements += ivec[0].Nelements;
    33  
    3468  return (TRUE);
    35    
    3669}
Note: See TracChangeset for help on using the changeset viewer.