IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37039


Ignore:
Timestamp:
Jul 17, 2014, 10:14:43 AM (12 years ago)
Author:
eugene
Message:

distinguish "byte" and "char" column fields (char is interpretted as a string)

Location:
trunk/Ohana/src/libfits
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r35756 r37039  
    2727# define FT_RECORD_SIZE        2880  /* FITS block size */
    2828
     29# define FT_BZERO_INT8 -1.0*0x80
    2930# define FT_BZERO_INT16 1.0*0x8000       
    3031# define FT_BZERO_INT32 1.0*0x80000000
     32# define FT_BZERO_INT64 1.0*0x8000000000000000
    3133
    3234/* this structure defines the buffer which contains a header
  • trunk/Ohana/src/libfits/table/F_get_column.c

    r36630 r37039  
    7575  Pout = array;
    7676  if (!strcmp (type, "char")) {
     77    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
     78      *(char *)Pout = *(char *)Pin*Bscale + Bzero;
     79    }
     80  }
     81  if (!strcmp (type, "byte")) {
    7782    for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    7883      *(char *)Pout = *(char *)Pin*Bscale + Bzero;
  • trunk/Ohana/src/libfits/table/F_set_column.c

    r35101 r37039  
    8181  Pin = data;
    8282  Pout = array;
     83  // does it makes sense to scale 'char' data?
    8384  if (!strcmp (type, "char")) {
     85    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
     86      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     87    }
     88  }
     89  if (!strcmp (type, "byte")) {
    8490    for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) {
    8591      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     
    221227  Pout = array;
    222228
     229  // # define ASSIGN_DATA(ITYPE,INAME,ISIZE,OTYPE,ONAME)
     230  // if (!strcmp (intype, #ITYPE)) {
     231
    223232  /** input == char **/
    224233  if (!strcmp (outtype, "char") && !strcmp (intype, "char")) {
     
    228237    }
    229238  }
     239  if (!strcmp (outtype, "byte") && !strcmp (intype, "char")) {
     240    int NbytesIn = 1;
     241    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     242      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     243    }
     244  }
    230245  if (!strcmp (outtype, "short") && !strcmp (intype, "char")) {
    231246    int NbytesIn = 1;
     
    265280  }
    266281  if (!strcmp (outtype, "double") && !strcmp (intype, "char")) {
     282    int NbytesIn = 1;
     283    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     284      *(double *)Pout = (*(char *)Pin - Bzero) / Bscale;
     285# ifdef BYTE_SWAP
     286      SWAP_DBLE;
     287# endif
     288    }
     289  }
     290
     291  /** input == byte **/
     292  if (!strcmp (outtype, "char") && !strcmp (intype, "byte")) {
     293    int NbytesIn = 1;
     294    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     295      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     296    }
     297  }
     298  if (!strcmp (outtype, "byte") && !strcmp (intype, "byte")) {
     299    int NbytesIn = 1;
     300    for (i = 0; i < Nval*Nrow; i++, Pin+=NbytesIn, Pout+=NbytesOut) {
     301      *(char *)Pout = (*(char *)Pin - Bzero) / Bscale;
     302    }
     303  }
     304  if (!strcmp (outtype, "short") && !strcmp (intype, "byte")) {
     305    int NbytesIn = 1;
     306    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     307      *(short *)Pout = (*(char *)Pin - Bzero) / Bscale;
     308# ifdef BYTE_SWAP
     309      SWAP_BYTE;
     310# endif
     311    } 
     312  }
     313  if (!strcmp (outtype, "int") && !strcmp (intype, "byte")) {
     314    int NbytesIn = 1;
     315    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     316      *(int *)Pout = (*(char *)Pin - Bzero) / Bscale;
     317# ifdef BYTE_SWAP
     318      SWAP_WORD;
     319# endif
     320    }
     321  }
     322  if (!strcmp (outtype, "int64_t") && !strcmp (intype, "byte")) {
     323    int NbytesIn = 1;
     324    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     325      *(int64_t *)Pout = (*(char *)Pin - Bzero) / Bscale;
     326# ifdef BYTE_SWAP
     327      SWAP_DBLE;
     328# endif
     329    }
     330  }
     331  if (!strcmp (outtype, "float") && !strcmp (intype, "byte")) {
     332    int NbytesIn = 1;
     333    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     334      *(float *)Pout = (*(char *)Pin - Bzero) / Bscale;
     335# ifdef BYTE_SWAP
     336      SWAP_WORD;
     337# endif
     338    }
     339  }
     340  if (!strcmp (outtype, "double") && !strcmp (intype, "byte")) {
    267341    int NbytesIn = 1;
    268342    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     
    281355    }
    282356  }
     357  if (!strcmp (outtype, "byte") && !strcmp (intype, "short")) {
     358    int NbytesIn = 2;
     359    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     360      *(char *)Pout = (*(short *)Pin - Bzero) / Bscale;
     361    }
     362  }
    283363  if (!strcmp (outtype, "short") && !strcmp (intype, "short")) {
    284364    int NbytesIn = 2;
     
    334414    }
    335415  }
     416  if (!strcmp (outtype, "byte") && !strcmp (intype, "int")) {
     417    int NbytesIn = 4;
     418    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     419      *(char *)Pout = (*(int *)Pin - Bzero) / Bscale;
     420    }
     421  }
    336422  if (!strcmp (outtype, "short") && !strcmp (intype, "int")) {
    337423    int NbytesIn = 4;
     
    387473    }
    388474  }
     475  if (!strcmp (outtype, "byte") && !strcmp (intype, "int64_t")) {
     476    int NbytesIn = 8;
     477    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     478      *(char *)Pout = (*(int64_t *)Pin - Bzero) / Bscale;
     479    }
     480  }
    389481  if (!strcmp (outtype, "short") && !strcmp (intype, "int64_t")) {
    390482    int NbytesIn = 8;
     
    440532    }
    441533  }
     534  if (!strcmp (outtype, "byte") && !strcmp (intype, "float")) {
     535    int NbytesIn = 4;
     536    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     537      *(char *)Pout = (*(float *)Pin - Bzero) / Bscale;
     538    }
     539  }
    442540  if (!strcmp (outtype, "short") && !strcmp (intype, "float")) {
    443541    int NbytesIn = 4;
     
    488586  /** input == double **/
    489587  if (!strcmp (outtype, "char") && !strcmp (intype, "double")) {
     588    int NbytesIn = 8;
     589    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
     590      *(char *)Pout = (*(double *)Pin - Bzero) / Bscale;
     591    }
     592  }
     593  if (!strcmp (outtype, "byte") && !strcmp (intype, "double")) {
    490594    int NbytesIn = 8;
    491595    for (i = 0; i < Nval*Nrow; i++, Pin += NbytesIn, Pout += NbytesOut) {
  • trunk/Ohana/src/libfits/table/F_table_format.c

    r28241 r37039  
    1919  if ((Nv == 0) && (Fchar == format)) Nv = 1;
    2020
     21  // NOTE: X, L, B all are stored in 1-byte columns (X by default has at least room for 8 bits)
     22  // I report these as type 'byte' as opposed to 'char', which is interpreted as a string
     23
    2124  *Nbytes = 0;
    2225  switch (*Fchar) {
    2326  case  'X':
    24     { *Nbytes = 1;  strcpy (type, "char");   *Nval = 1 + (int) Nv / 8; }
     27    { *Nbytes = 1;  strcpy (type, "byte");   *Nval = 1 + (int) Nv / 8; }
    2528    break;
    2629  case  'L':
    27     { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
     30    { *Nbytes = 1;  strcpy (type, "byte");   *Nval = Nv;               }
    2831    break;
    2932  case  'A':
     
    3134    break;
    3235  case  'B':
    33     { *Nbytes = 1;  strcpy (type, "char");   *Nval = Nv;               }
     36    { *Nbytes = 1;  strcpy (type, "byte");   *Nval = Nv;               }
    3437    break;
    3538  case  'I':
     
    268271    }
    269272
     273    // Does it make sense to scale 'char' data (as opposed to 'byte')?
    270274    if (!strcmp (type, "char"))   {
     275      for (j = 0; j < Ny; j++) {
     276        for (n = 0; n < Nval; n++) {
     277          tmpChar = (char *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
     278          *tmpChar = *tmpChar * tscale + tzero;
     279        }
     280      }
     281    }
     282    if (!strcmp (type, "byte"))   {
    271283      for (j = 0; j < Ny; j++) {
    272284        for (n = 0; n < Nval; n++) {
     
    352364    }
    353365
     366    // does this make sense? (see note above)
    354367    if (!strcmp (type, "char"))   {
    355368      for (j = 0; j < Ny; j++) {
     
    360373      }
    361374    }
     375    if (!strcmp (type, "byte"))   {
     376      for (j = 0; j < Ny; j++) {
     377        for (n = 0; n < Nval; n++) {
     378          tmpChar = (char *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
     379          *tmpChar = (*tmpChar - tzero) / tscale;
     380        }
     381      }
     382    }
    362383    if (!strcmp (type, "short"))   {
    363384      for (j = 0; j < Ny; j++) {
Note: See TracChangeset for help on using the changeset viewer.