IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41676


Ignore:
Timestamp:
Jul 1, 2021, 1:58:44 PM (5 years ago)
Author:
eugene
Message:

fix FITS ASCII column reading

Location:
trunk/Ohana/src/libfits/table
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/table/F_get_column.c

    r41474 r41676  
    310310   C - complex float
    311311   M - complex double
    312    P - var lenght array descrpt (64 bit)
     312   P - var length array descrpt (64 bit)
    313313   
    314314   all can be preceeded by integer N which specified number
     
    341341
    342342  if (!gfits_table_format (format, type, Nval, &Nbytes)) return (FALSE);
    343   *Nval = 1;
    344343
    345344  return (TRUE);
     
    379378  gfits_scan (header, "NAXIS2",  OFF_T_FMT, 1,  &Ny);
    380379
    381   /* scan columns to find insert point */
    382   Nstart = 0;
    383   for (i = 1; i < N; i++) {
    384     snprintf (field, 256, "TFORM%d", i);
    385     gfits_scan (header, field, "%s", 1, format);
    386     gfits_table_format (format, tmp, &Nv, &Nb);
    387     Nstart += Nv*Nb;
     380  // find the starting byte for this column
     381  // FITS ASCII table is supposed to have TBCOLn to specify the starting point
     382  // but if it is missing, we can try to find by counting
     383  snprintf (field, 256, "TBCOL%d", N);
     384  int status = gfits_scan (header, field, "%d", 1, &Nstart);
     385  if (!status) {
     386    /* scan columns to find insert point */
     387    Nstart = 0;
     388    for (i = 1; i < N; i++) {
     389      snprintf (field, 256, "TFORM%d", i);
     390      gfits_scan (header, field, "%s", 1, format);
     391      gfits_table_format (format, tmp, &Nv, &Nb);
     392      Nstart += Nv*Nb;
     393    }
     394  } else {
     395    Nstart --;
    388396  }
    389397
    390398  /* allocate temporary line, init pointers */
    391   ALLOCATE (line, char, Nval+1);
    392   bzero (line, Nval+1);
     399  ALLOCATE (line, char, Nval*Nbytes+1);
     400  bzero (line, Nval*Nbytes+1);
    393401  Pin  = table[0].buffer + Nstart;
    394402
  • trunk/Ohana/src/libfits/table/F_set_column.c

    r41422 r41676  
    478478  /* print line with appropriate formatting */
    479479  ALLOCATE (array, char, Nbytes*Nval*Nrow);
    480   ALLOCATE (line, char, Nval+1);
     480  ALLOCATE (line, char, Nbytes+1);
    481481  Pin = data;
    482482  Pout = array;
    483483  if (!strcmp (type, "char")) {
    484     for (i = 0; i < Nval*Nrow; i++, Pin++, Pout++) {
     484    for (i = 0; i < Nbytes*Nval*Nrow; i++, Pin++, Pout++) {
    485485      *Pout = *Pin;
    486486    }
    487487  }
    488488  if (!strcmp (type, "int")) {
    489     for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nval) {
    490       snprintf (line, Nval + 1, cformat, *(int *)Pin);
    491       memcpy (Pout, line, Nval);
     489    for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nbytes) {
     490      snprintf (line, Nbytes + 1, cformat, *(int *)Pin);
     491      memcpy (Pout, line, Nbytes);
    492492    }
    493493  }
    494494  if (!strcmp (type, "float")) {
    495     for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nval) {
    496       snprintf (line, Nval + 1, cformat, *(float *)Pin);
    497       memcpy (Pout, line, Nval);
     495    for (i = 0; i < Nrow; i++, Pin+=4, Pout+=Nbytes) {
     496      snprintf (line, Nbytes + 1, cformat, *(float *)Pin);
     497      memcpy (Pout, line, Nbytes);
    498498    }
    499499  }
  • trunk/Ohana/src/libfits/table/F_table_format.c

    r41474 r41676  
    55// get the format of a table column
    66// Nval : number of joined columns
    7 // Nbytes : width of column
     7// Nbytes : width of column, determined by the type (e.g., float = 4 bytes)
    88int gfits_bintable_format (char *format, char *type, int *Nval, int *Nbytes) {
    99
     
    9090
    9191/***********************/
     92// get the format of a table column
     93// Nval : number of fields (1 for all types except string)
     94// Nbytes : width of FITS table column, ie number of bytes in ASCII table
    9295int gfits_table_format (char *format, char *type, int *Nval, int *Nbytes) {
    9396
     
    109112  int isLong = FALSE;
    110113  char Type = 'x';
    111   if (Fchar == 'D') { *Nbytes = 1;  strcpy (type, "double"); Type = 'e'; *Nval = Nv; isLong = TRUE; }
    112   if (Fchar == 'E') { *Nbytes = 1;  strcpy (type, "float");  Type = 'e'; *Nval = Nv; }
    113   if (Fchar == 'F') { *Nbytes = 1;  strcpy (type, "float");  Type = 'f'; *Nval = Nv; }
    114   if (Fchar == 'I') { *Nbytes = 1;  strcpy (type, "int");    Type = 'd'; *Nval = Nv; }
    115   if (Fchar == 'A') { *Nbytes = 1;  strcpy (type, "char");   Type = 's'; *Nval = Nv; }
     114  if (Fchar == 'D') { *Nbytes = Nv;  strcpy (type, "double"); Type = 'e'; *Nval =  1; isLong = TRUE; }
     115  if (Fchar == 'E') { *Nbytes = Nv;  strcpy (type, "float");  Type = 'e'; *Nval =  1; }
     116  if (Fchar == 'F') { *Nbytes = Nv;  strcpy (type, "float");  Type = 'f'; *Nval =  1; }
     117  if (Fchar == 'I') { *Nbytes = Nv;  strcpy (type, "int");    Type = 'd'; *Nval =  1; }
     118  if (Fchar == 'A') { *Nbytes =  1;  strcpy (type, "char");   Type = 's'; *Nval = Nv; }
    116119  if (!*Nbytes) { return (FALSE); }
    117120 
     
    133136/*
    134137  valid TABLE column formats:
    135   FN.N  - floating point
    136   INN   - integer
     138  FN.N  - floating point taking NN characters in the table
     139  INN   - integer taking NN characters in the table
    137140  ANN   - NN char string
    138141 
Note: See TracChangeset for help on using the changeset viewer.