IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39059


Ignore:
Timestamp:
Nov 6, 2015, 10:25:18 AM (11 years ago)
Author:
eugene
Message:

print floats and doubles with the sprintf_float,double commands

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/tools/src/fits_to_mysql.c

    r38998 r39059  
    302302  *ncolumn = Ncolumn;
    303303  return column;
     304}
     305
     306/* print a double an IOBuffer (sprintf_double) */
     307int PrintIOBuffer_double (IOBuffer *buffer, double value) {
     308
     309  /* add the output line to the given IOBuffer */
     310 
     311  char output[128]; // I can use a fixed-length buffer since sprintf_double prints no more than 22 bytes;
     312
     313  int Nbyte = sprintf_double (output, value);
     314
     315  if (buffer[0].Nbuffer + Nbyte + 1 >= buffer[0].Nalloc) {
     316    buffer[0].Nalloc = buffer[0].Nbuffer + Nbyte + 64;
     317    REALLOCATE (buffer[0].buffer, char, buffer[0].Nalloc);
     318  }
     319
     320  strcpy (&buffer[0].buffer[buffer[0].Nbuffer], output);
     321  buffer[0].Nbuffer += Nbyte;
     322
     323  return (TRUE);
     324}
     325
     326/* float to an IOBuffer (sprintf_float) */
     327int PrintIOBuffer_float (IOBuffer *buffer, float value) {
     328
     329  /* add the output line to the given IOBuffer */
     330 
     331  char output[128]; // I can use a fixed-length buffer since sprintf_float prints no more than 14 bytes;
     332
     333  int Nbyte = sprintf_float (output, value);
     334
     335  if (buffer[0].Nbuffer + Nbyte + 1 >= buffer[0].Nalloc) {
     336    buffer[0].Nalloc = buffer[0].Nbuffer + Nbyte + 64;
     337    REALLOCATE (buffer[0].buffer, char, buffer[0].Nalloc);
     338  }
     339
     340  strcpy (&buffer[0].buffer[buffer[0].Nbuffer], output);
     341  buffer[0].Nbuffer += Nbyte;
     342
     343  return (TRUE);
    304344}
    305345
     
    532572            float myValue = value[i*columns[Nf].Nval + j];
    533573            if (isfinite(myValue)) {
    534               PrintIOBuffer (&output, "%e", myValue);
     574              PrintIOBuffer_float (&output, myValue);
    535575            } else {
    536576              PrintIOBuffer (&output, "-999");
     
    545585          double *value = data[Nf];
    546586          for (j = 0; j < columns[Nf].Nval; j++) {
    547             PrintIOBuffer (&output, "%e", value[i*columns[Nf].Nval + j]);
     587            double myValue = value[i*columns[Nf].Nval + j];
     588            if (isfinite(myValue)) {
     589              PrintIOBuffer_double (&output, myValue);
     590            } else {
     591              PrintIOBuffer (&output, "-999");
     592            }
    548593            if (j < columns[Nf].Nval - 1) {
    549594              PrintIOBuffer (&output, ",\n");
Note: See TracChangeset for help on using the changeset viewer.