IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35092


Ignore:
Timestamp:
Feb 6, 2013, 11:14:02 AM (13 years ago)
Author:
eugene
Message:

table I/O functions were not handling int64 columns

Location:
branches/eam_branches/ipp-20121219/Ohana/src/libfits/table
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20121219/Ohana/src/libfits/table/F_get_column.c

    r33648 r35092  
    9696  }
    9797  if (!strcmp (type, "int64_t")) {
    98     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    99 # ifdef BYTE_SWAP
    100       SWAP_DBLE;
    101 # endif
    102       *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
     98    if ((Bzero == 0.0) && (Bscale == 1.0)) {
     99      for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     100# ifdef BYTE_SWAP
     101        SWAP_DBLE;
     102# endif
     103        *(int64_t *)Pout = *(int64_t *)Pin;
     104      }
     105    } else {
     106      for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     107# ifdef BYTE_SWAP
     108        SWAP_DBLE;
     109# endif
     110        *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
     111      }
    103112    }
    104113  }
     
    243252  }
    244253  if (!strcmp (type, "int64_t")) {
    245     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    246 # ifdef BYTE_SWAP
    247       SWAP_DBLE;
    248 # endif
    249       *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
     254    // XXX 64 bit int operations with Bzero & Bscale are inaccurate even with doubles
     255    if ((Bzero == 0.0) && (Bscale == 1.0)) {
     256      for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     257# ifdef BYTE_SWAP
     258        SWAP_DBLE;
     259# endif
     260        *(int64_t *)Pout = *(int64_t *)Pin;
     261      }
     262    } else {
     263      for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     264# ifdef BYTE_SWAP
     265        SWAP_DBLE;
     266# endif
     267        *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
     268      }
    250269    }
    251270  }
  • branches/eam_branches/ipp-20121219/Ohana/src/libfits/table/F_set_column.c

    r33648 r35092  
    102102    }
    103103  }
     104  if (!strcmp (type, "int64_t")) {
     105    // XXX 64 bit int operations with Bzero & Bscale are inaccurate even with doubles
     106    if ((Bzero == 0.0) && (Bscale == 1.0)) {
     107      for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     108        *(int64_t *)Pout = *(int64_t *)Pin;
     109# ifdef BYTE_SWAP
     110        SWAP_DBLE;
     111# endif
     112      }
     113    } else {
     114      for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     115        *(int64_t *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
     116# ifdef BYTE_SWAP
     117        SWAP_DBLE;
     118# endif
     119      }
     120    }
     121  }
    104122  if (!strcmp (type, "float")) {
    105123    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     
    228246    }
    229247  }
     248  if (!strcmp (outtype, "int64_t") && !strcmp (intype, "char")) {
     249    int NbytesIn = 1;
     250    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     251      *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
     252# ifdef BYTE_SWAP
     253      SWAP_DBLE;
     254# endif
     255    }
     256  }
    230257  if (!strcmp (outtype, "float") && !strcmp (intype, "char")) {
    231258    int NbytesIn = 1;
     
    272299    }
    273300  }
     301  if (!strcmp (outtype, "int64_t") && !strcmp (intype, "short")) {
     302    int NbytesIn = 2;
     303    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     304      *(int64_t *)Pout = (*(short *)Pin - Bzero) / Bscale;
     305# ifdef BYTE_SWAP
     306      SWAP_DBLE;
     307# endif
     308    }
     309  }
    274310  if (!strcmp (outtype, "float") && !strcmp (intype, "short")) {
    275311    int NbytesIn = 2;
     
    316352    }
    317353  }
     354  if (!strcmp (outtype, "int64_t") && !strcmp (intype, "int")) {
     355    int NbytesIn = 4;
     356    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     357      *(int64_t *)Pout = (*(int *)Pin - Bzero) / Bscale;
     358# ifdef BYTE_SWAP
     359      SWAP_DBLE;
     360# endif
     361    }
     362  }
    318363  if (!strcmp (outtype, "float") && !strcmp (intype, "int")) {
    319364    int NbytesIn = 4;
     
    329374    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
    330375      *(double *)Pout = (*(int *)Pin - Bzero) / Bscale;
     376# ifdef BYTE_SWAP
     377      SWAP_DBLE;
     378# endif
     379    }
     380  }
     381
     382  /** input == int64_t **/
     383  if (!strcmp (outtype, "char") && !strcmp (intype, "int64_t")) {
     384    int NbytesIn = 8;
     385    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     386      *(char *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
     387    }
     388  }
     389  if (!strcmp (outtype, "short") && !strcmp (intype, "int64_t")) {
     390    int NbytesIn = 8;
     391    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     392      *(short *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
     393# ifdef BYTE_SWAP
     394      SWAP_BYTE;
     395# endif
     396    } 
     397  }
     398  if (!strcmp (outtype, "int") && !strcmp (intype, "int64_t")) {
     399    int NbytesIn = 8;
     400    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     401      *(int *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
     402# ifdef BYTE_SWAP
     403      SWAP_WORD;
     404# endif
     405    }
     406  }
     407  if (!strcmp (outtype, "int64_t") && !strcmp (intype, "int64_t")) {
     408    int NbytesIn = 8;
     409    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     410      *(int64_t *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
     411# ifdef BYTE_SWAP
     412      SWAP_DBLE;
     413# endif
     414    }
     415  }
     416  if (!strcmp (outtype, "float") && !strcmp (intype, "int64_t")) {
     417    int NbytesIn = 8;
     418    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     419      *(float *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
     420# ifdef BYTE_SWAP
     421      SWAP_WORD;
     422# endif
     423    }
     424  }
     425  if (!strcmp (outtype, "double") && !strcmp (intype, "int64_t")) {
     426    int NbytesIn = 8;
     427    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     428      *(double *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
    331429# ifdef BYTE_SWAP
    332430      SWAP_DBLE;
     
    360458    }
    361459  }
     460  if (!strcmp (outtype, "int64_t") && !strcmp (intype, "float")) {
     461    int NbytesIn = 4;
     462    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     463      *(int64_t *)Pout = (*(float *)Pin - Bzero) / Bscale;
     464# ifdef BYTE_SWAP
     465      SWAP_DBLE;
     466# endif
     467    }
     468  }
    362469  if (!strcmp (outtype, "float") && !strcmp (intype, "float")) {
    363470    int NbytesIn = 4;
     
    401508# ifdef BYTE_SWAP
    402509      SWAP_WORD;
     510# endif
     511    }
     512  }
     513  if (!strcmp (outtype, "int64_t") && !strcmp (intype, "double")) {
     514    int NbytesIn = 8;
     515    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     516      *(int64_t *)Pout = (*(double *)Pin - Bzero) / Bscale;
     517# ifdef BYTE_SWAP
     518      SWAP_DBLE;
    403519# endif
    404520    }
Note: See TracChangeset for help on using the changeset viewer.