IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36999


Ignore:
Timestamp:
Jul 11, 2014, 2:55:24 PM (12 years ago)
Author:
eugene
Message:

use "byte" for FITS table columns with 1-byte int fields (not char)

Location:
branches/eam_branches/ipp-20140610/Ohana/src
Files:
6 edited

Legend:

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

    r36630 r36999  
    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;
  • branches/eam_branches/ipp-20140610/Ohana/src/libfits/table/F_set_column.c

    r35101 r36999  
    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) {
  • branches/eam_branches/ipp-20140610/Ohana/src/libfits/table/F_table_format.c

    r28241 r36999  
    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++) {
  • branches/eam_branches/ipp-20140610/Ohana/src/opihi/cmd.data/read_vectors.c

    r36941 r36999  
    321321}
    322322
    323 # define ESCAPE(MSG) { \
    324   gprint (GP_ERR, "%s\n", MSG); \
     323# define ESCAPE(...) {          \
     324  gprint (GP_ERR, __VA_ARGS__); \
    325325  if (CCDKeyword != NULL) free (CCDKeyword); \
    326326  gfits_free_table  (&table); \
     
    331331
    332332  off_t Nbytes;
    333   int i, j, k, N, Nextend, Ny, Binary, vecType, padIfShort;
     333  int i, j, N, Nextend, Ny, Binary, vecType, padIfShort;
    334334  char type[16], ID[80], *CCDKeyword;
    335335  FTable table;
     
    374374  // }
    375375
    376   if (argc < 2) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...");
    377 
    378   if (f == NULL) ESCAPE ("file not found");
     376  if (argc < 2) ESCAPE ("USAGE: read -fits extension [-extnum] [-keyword key] name name ...\n");
     377
     378  if (f == NULL) ESCAPE ("file not found\n");
    379379  fseeko (f, 0LL, SEEK_SET);
    380380  table.header = &header;
     
    384384    // first extension is PHU, cannot be a table.
    385385    // Nextend counts from 0 for first extension
    386     if (!gfits_load_header (f, &header)) ESCAPE ("error reading primary header for file");
     386    if (!gfits_load_header (f, &header)) ESCAPE ("error reading primary header for file\n");
    387387    Nbytes = gfits_data_size (&header);
    388388    fseeko (f, Nbytes, SEEK_CUR);
     
    390390
    391391    for (i = 0; i < Nextend; i++) {
    392       if (!gfits_load_header (f, &header)) ESCAPE ("extension not found");
     392      if (!gfits_load_header (f, &header)) ESCAPE ("extension %d not found\n", i);
    393393      Nbytes = gfits_data_size (&header);
    394394      /* skip the prior data buffers */
     
    396396      gfits_free_header (&header);
    397397    }
    398     if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension");
    399     if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension");
     398    if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension %d\n", Nextend);
     399    if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension %d\n", Nextend);
    400400
    401401  } else {
     
    428428        continue;
    429429      }
    430       if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension");
     430      if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension\n");
    431431      break;
    432432    }
     
    437437  gfits_scan (&header, "XTENSION", "%s", 1, type);
    438438  if (strcmp (type, "BINTABLE") && strcmp (type, "TABLE")) {
    439     ESCAPE ("specified extension is not a table\n");
     439    ESCAPE ("specified extension %s is not a table\n", type);
    440440  }
    441441  Binary = !strcmp (type, "BINTABLE");
     
    497497      }
    498498
    499       if (!strcmp (type, "short")) {
    500         short *Ptr = data;
    501         for (j = 0; j < Ny; j++) {
    502           for (k = 0; k < Nval; k++, Ptr++) {
    503             vec[k][0].elements.Int[j] = *Ptr;
    504           }
    505         }
    506       }
    507       if (!strcmp (type, "int")) {
    508         int *Ptr = data;
    509         for (j = 0; j < Ny; j++) {
    510           for (k = 0; k < Nval; k++, Ptr++) {
    511             vec[k][0].elements.Int[j] = *Ptr;
    512           }
    513         }
    514       }
    515       if (!strcmp (type, "int64_t")) {
    516         int64_t *Ptr = data;
    517         for (j = 0; j < Ny; j++) {
    518           for (k = 0; k < Nval; k++, Ptr++) {
    519             vec[k][0].elements.Int[j] = *Ptr;
    520           }
    521         }
    522       }
    523       if (!strcmp (type, "float")) {
    524         float *Ptr = data;
    525         for (j = 0; j < Ny; j++) {
    526           for (k = 0; k < Nval; k++, Ptr++) {
    527             vec[k][0].elements.Flt[j] = *Ptr;
    528           }
    529         }
    530       }
    531       if (!strcmp (type, "double")) {
    532         double *Ptr = data;
    533         for (j = 0; j < Ny; j++) {
    534           for (k = 0; k < Nval; k++, Ptr++) {
    535             vec[k][0].elements.Flt[j] = *Ptr;
    536           }
    537         }
    538       }
     499      if (!VectorAssignData (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
     500
    539501    } else {
    540502      // define the multifield vector names (Ny vectors x Nval elements)
     
    549511      }
    550512
    551       if (!strcmp (type, "char")) {
    552         char *Ptr = data;
    553         for (j = 0; j < Ny; j++) {
    554           for (k = 0; k < Nval; k++, Ptr++) {
    555             vec[j][0].elements.Int[k] = *Ptr;
    556           }
    557         }
    558       }
    559       if (!strcmp (type, "short")) {
    560         short *Ptr = data;
    561         for (j = 0; j < Ny; j++) {
    562           for (k = 0; k < Nval; k++, Ptr++) {
    563             vec[j][0].elements.Int[k] = *Ptr;
    564           }
    565         }
    566       }
    567       if (!strcmp (type, "int")) {
    568         int *Ptr = data;
    569         for (j = 0; j < Ny; j++) {
    570           for (k = 0; k < Nval; k++, Ptr++) {
    571             vec[j][0].elements.Int[k] = *Ptr;
    572           }
    573         }
    574       }
    575       if (!strcmp (type, "int64_t")) {
    576         int64_t *Ptr = data;
    577         for (j = 0; j < Ny; j++) {
    578           for (k = 0; k < Nval; k++, Ptr++) {
    579             vec[j][0].elements.Int[k] = *Ptr;
    580           }
    581         }
    582       }
    583       if (!strcmp (type, "float")) {
    584         float *Ptr = data;
    585         for (j = 0; j < Ny; j++) {
    586           for (k = 0; k < Nval; k++, Ptr++) {
    587             vec[j][0].elements.Flt[k] = *Ptr;
    588           }
    589         }
    590       }
    591       if (!strcmp (type, "double")) {
    592         double *Ptr = data;
    593         for (j = 0; j < Ny; j++) {
    594           for (k = 0; k < Nval; k++, Ptr++) {
    595             vec[j][0].elements.Flt[k] = *Ptr;
    596           }
    597         }
    598       }
     513      if (!VectorAssignDataTranspose (vec, type, data, Ny, Nval)) ESCAPE ("bad column type %s", type);
    599514    }
    600515    free (data);
  • branches/eam_branches/ipp-20140610/Ohana/src/opihi/include/dvomath.h

    r36375 r36999  
    170170Vector      **ReadVectorTableFITS   PROTO((char *filename, char *extname, int *Nvec));
    171171
     172int           VectorAssignData          PROTO((Vector **vec, char *type, void *data, int Nrows, int Nval));
     173int           VectorAssignDataTranspose PROTO((Vector **vec, char *type, void *data, int Nrows, int Nval));
     174
    172175/* buffer handling */
    173176Buffer       *InitBuffer            PROTO((void));
  • branches/eam_branches/ipp-20140610/Ohana/src/opihi/lib.shell/VectorIO.c

    r35109 r36999  
    134134  FTable ftable;
    135135
    136   int i, j, k;
     136  int i, j;
    137137  FILE *f = NULL;
    138138
     
    202202    assert (status);
    203203
    204 # define ASSIGN_DATA(TYPE,OPTYPE) \
    205     /* assign the data to the actual vector */ \
    206     if (!strcmp (type, #TYPE)) { \
    207       TYPE *Ptr = data;     \
    208       for (k = 0; k < Nrows; k++) { \
    209         for (j = 0; j < Nval; j++, Ptr++) { \
    210           vec[Nvec + j][0].elements.OPTYPE[k] = *Ptr; \
    211         } } }
    212 
    213     // assign the data to the actual vector
    214     ASSIGN_DATA(char,    Int);
    215     ASSIGN_DATA(short,   Int);
    216     ASSIGN_DATA(int,     Int);
    217     ASSIGN_DATA(int64_t, Int);
    218     ASSIGN_DATA(float,   Flt);
    219     ASSIGN_DATA(double,  Flt);
     204    if (!VectorAssignData(&vec[Nvec], type, data, Nrows, Nval)) {
     205      // free unneeded things
     206      gprint (GP_ERR, "trouble parsing data block type %s\n", type);
     207      return (NULL);
     208    }
    220209
    221210    free (data);
     
    241230//  return (FALSE);
    242231}
     232
     233# define ASSIGN_DATA(TYPE,DTYPE,OPTYPE)        \
     234    /* assign the data to the actual vector */ \
     235    if (!strcmp (type, #TYPE)) { \
     236      DTYPE *Ptr = data;                    \
     237      for (k = 0; k < Nrows; k++) { \
     238        for (j = 0; j < Nval; j++, Ptr++) { \
     239          vec[j][0].elements.OPTYPE[k] = *Ptr; \
     240          } } return TRUE; }
     241
     242int VectorAssignData (Vector **vec, char *type, void *data, int Nrows, int Nval) {
     243
     244  int j, k;
     245
     246  // assign the data to the actual vector
     247  ASSIGN_DATA(byte,    char,    Int);
     248  ASSIGN_DATA(char,    char,    Int);
     249  ASSIGN_DATA(short,   short,   Int);
     250  ASSIGN_DATA(int,     int,     Int);
     251  ASSIGN_DATA(int64_t, int64_t, Int);
     252  ASSIGN_DATA(float,   float,   Flt);
     253  ASSIGN_DATA(double,  double,  Flt);
     254
     255  return FALSE;
     256}
     257
     258# define ASSIGN_DATA_TRANSPOSE(TYPE,DTYPE,OPTYPE)       \
     259    /* assign the data to the actual vector */ \
     260    if (!strcmp (type, #TYPE)) { \
     261      DTYPE *Ptr = data;                    \
     262      for (k = 0; k < Nrows; k++) { \
     263        for (j = 0; j < Nval; j++, Ptr++) { \
     264          vec[k][0].elements.OPTYPE[j] = *Ptr; \
     265          } } return TRUE; }
     266
     267int VectorAssignDataTranspose (Vector **vec, char *type, void *data, int Nrows, int Nval) {
     268
     269  int j, k;
     270
     271  // assign the data to the actual vector
     272  ASSIGN_DATA_TRANSPOSE(byte,    char,    Int);
     273  ASSIGN_DATA_TRANSPOSE(char,    char,    Int);
     274  ASSIGN_DATA_TRANSPOSE(short,   short,   Int);
     275  ASSIGN_DATA_TRANSPOSE(int,     int,     Int);
     276  ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Int);
     277  ASSIGN_DATA_TRANSPOSE(float,   float,   Flt);
     278  ASSIGN_DATA_TRANSPOSE(double,  double,  Flt);
     279
     280  return FALSE;
     281}
Note: See TracChangeset for help on using the changeset viewer.