IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38406


Ignore:
Timestamp:
Jun 6, 2015, 10:03:56 AM (11 years ago)
Author:
eugene
Message:

add options to cast to force single-precision floats or long long int (stuffed into double); fits table I/O puts int64 into opihi double vector

Location:
branches/eam_branches/ohana.20150429/src/opihi
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/opihi/cmd.data/cast.c

    r36489 r38406  
    1717  // out type
    1818  char outType = OPIHI_NOTYPE;
    19   if (!strcasecmp(argv[5], "int")) outType = OPIHI_INT;
    20   if (!strcasecmp(argv[5], "float")) outType = OPIHI_FLT;
     19  if (!strcasecmp(argv[5], "int"))    outType = OPIHI_INT;
     20  if (!strcasecmp(argv[5], "float"))  outType = OPIHI_FLT;
     21  if (!strcasecmp(argv[5], "single")) outType = OPIHI_FLT;
     22  if (!strcasecmp(argv[5], "int64"))  outType = OPIHI_FLT;
    2123  if (outType == OPIHI_NOTYPE) goto usage;
     24
     25  int ForceSingle = FALSE;
     26  if (!strcasecmp(argv[5], "single")) ForceSingle = TRUE;
     27
     28  int ForceI64 = FALSE;
     29  if (!strcasecmp(argv[5], "int64")) ForceI64 = TRUE;
    2230
    2331  if ((ovec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto error;
     
    3240    opihi_flt *vo = ovec[0].elements.Flt;
    3341    for (i = 0; i < ovec[0].Nelements; i++, vi++, vo++) {
    34       *vo = *vi;
     42      if (ForceSingle) {
     43        float tmp = *vi;
     44        *vo = tmp;
     45      } else if (ForceI64) {
     46        int64_t tmp = *vi;
     47        *vo = tmp;
     48      } else {
     49        *vo = *vi;
     50      }
    3551    }
    3652    return (TRUE);
     
    4864    opihi_flt *vo = ovec[0].elements.Flt;
    4965    for (i = 0; i < ovec[0].Nelements; i++, vi++, vo++) {
    50       *vo = *vi;
     66      if (ForceSingle) {
     67        float tmp = *vi;
     68        *vo = tmp;
     69      } else {
     70        *vo = *vi;
     71      }
    5172    }
    5273    return (TRUE);
     
    6687
    6788usage:
    68   gprint (GP_ERR, "SYNTAX: cast vec = vec as (int/float)\n");
     89  gprint (GP_ERR, "SYNTAX: cast vec = vec as (int/float/single)\n");
     90  gprint (GP_ERR, "  note: (single) forces vector to have single precision\n");
    6991  return (FALSE);
    7092}
  • branches/eam_branches/ohana.20150429/src/opihi/cmd.data/read_vectors.c

    r38367 r38406  
    487487  }
    488488  if (start < 0) ESCAPE ("invalid range: start < 0\n");
    489   if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny (%d)\n", header.Naxis[1]);
     489  if (start >= header.Naxis[1]) ESCAPE ("invalid range: start >= Ny ("OFF_T_FMT")\n", header.Naxis[1]);
    490490  if (Nrows < 0) ESCAPE ("invalid range: Nrows < 0\n");
    491491
    492492  // just a warning:
    493493  if (start + Nrows > header.Naxis[1]) {
    494     if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only %d rows\n", header.Naxis[1] - start);
     494    if (VERBOSE) gprint (GP_ERR, "NOTE: reading last block will return only "OFF_T_FMT" rows\n", header.Naxis[1] - start);
    495495  }
    496496
     
    555555   
    556556    vecType = OPIHI_INT;
    557     if (!strcmp (type, "double") || !strcmp (type, "float")) {
     557    if (!strcmp (type, "double") || !strcmp (type, "float") || !strcmp (type, "int64_t")) {
    558558      vecType = OPIHI_FLT;
    559559    }
  • branches/eam_branches/ohana.20150429/src/opihi/cmd.data/vstats.c

    r35109 r38406  
    121121      goto skip;
    122122    }
     123    // we can hit inf if pmax and pmin are close to the max range
     124    if (isinf(dx)) dx = DBL_MAX / Nbin;
    123125
    124126    ALLOCATE (Nval, int, Nbin + 2);
  • branches/eam_branches/ohana.20150429/src/opihi/lib.shell/VectorIO.c

    r38367 r38406  
    320320  ASSIGN_DATA(short,   short,   Int);
    321321  ASSIGN_DATA(int,     int,     Int);
    322   ASSIGN_DATA(int64_t, int64_t, Int);
     322  ASSIGN_DATA(int64_t, int64_t, Flt); // int64_t has a problem: Int is too small, Flt is wrong precision
    323323  ASSIGN_DATA(float,   float,   Flt);
    324324  ASSIGN_DATA(double,  double,  Flt);
     
    345345  ASSIGN_DATA_TRANSPOSE(short,   short,   Int);
    346346  ASSIGN_DATA_TRANSPOSE(int,     int,     Int);
    347   ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Int);
     347  ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Flt);
    348348  ASSIGN_DATA_TRANSPOSE(float,   float,   Flt);
    349349  ASSIGN_DATA_TRANSPOSE(double,  double,  Flt);
  • branches/eam_branches/ohana.20150429/src/opihi/lib.shell/evaluate_stack.c

    r38062 r38406  
    115115
    116116        /* there are no valid unary string operators */
    117         push_error ("invalid operands for trinary operator (mismatch types?)");
     117        snprintf (line, 512, "invalid operands for trinary operator %s (mismatch types?)", stack[i].name);
     118        push_error (line);
    118119        clear_stack (&tmp_stack);
    119120        return (FALSE);
     
    210211
    211212        /* there are no valid unary string operators */
    212         push_error ("syntax error: no valid string unary ops");
     213        snprintf (line, 512, "invalid operand for unary operator %s (undefined value?)", stack[i].name);
     214        push_error (line);
    213215        clear_stack (&tmp_stack);
    214216        return (FALSE);
Note: See TracChangeset for help on using the changeset viewer.