IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15751


Ignore:
Timestamp:
Dec 6, 2007, 3:42:40 PM (18 years ago)
Author:
eugene
Message:

handle i/o errors

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

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/header/F_read_H.c

    r15743 r15751  
    3535                    sizeof(char), FT_RECORD_SIZE, f);
    3636    if (Nbytes != FT_RECORD_SIZE) {
     37      if (feof(f)) return (FALSE);
    3738      perror ("fits read error");
     39      return (FALSE);
    3840    }
    3941   
    4042    header[0].size += Nbytes;
    41     if (Nbytes != FT_RECORD_SIZE) {
    42       return (FALSE);
    43     }
     43
    4444    if (i == 0) {
    4545      /* on first block, verify it is a FITS table: SIMPLE .. or XTENSION ... */
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r15743 r15751  
    128128int     gfits_write_header             PROTO((char *filename, Header *header));
    129129int     gfits_data_size                PROTO((Header *header));
     130int     gfits_data_min_size            PROTO((Header *header));
    130131int     gfits_extended_to_primary      PROTO((Header *header, int simple, char *comment));
    131132int     gfits_primary_to_extended      PROTO((Header *header, char *exttype, char *comment));
  • trunk/Ohana/src/libfits/matrix/F_load_M.c

    r15743 r15751  
    3131  nbytes = fread (matrix[0].buffer, sizeof(char), Nbytes, f);
    3232  if (nbytes != Nbytes) {
    33     perror ("fits matrix read error");
     33    perror ("FITS file is short in ##__func__");
     34    if (nbytes != gfits_data_min_size (header)) {
     35      fprintf (stderr, "error: fits read error in %s", __func__);
     36      return (FALSE);
     37    }
     38    fprintf (stderr, "warning: file missing pad\n");
    3439  }
    3540
  • trunk/Ohana/src/libfits/matrix/F_matrix.c

    r15487 r15751  
    2424  return (size);
    2525}
     26
     27int gfits_data_min_size (Header *header) {
     28 
     29  int i, size;
     30
     31  if (header[0].Naxes == 0) return (0);
     32
     33  size = abs(header[0].bitpix / 8);
     34
     35  for (i = 0; i < header[0].Naxes; i++)
     36    size *= header[0].Naxis[i];
     37
     38  // XXX do I multiply this times gcount?
     39  size += header[0].pcount;
     40
     41  return (size);
     42}
  • trunk/Ohana/src/libfits/table/F_read_T.c

    r15743 r15751  
    5252
    5353  int Nbytes, Nread;
     54  char string[128];
    5455
    5556  /* find buffer size */
     
    5960  Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
    6061  if (Nread != Nbytes) {
    61     perror ("fits read error");
    62     gfits_free_table  (table);
    63     return (FALSE);
     62    snprintf (string, 128, "FITS file is short (%s)", __func__);
     63    perror (string);
     64    if (Nread < gfits_data_min_size (table[0].header)) {
     65      fprintf (stderr, "error: fits read error in %s, read %d, need %d\n", __func__, Nread, gfits_data_min_size (table[0].header));
     66      gfits_free_table  (table);
     67      return (FALSE);
     68    }
     69    fprintf (stderr, "warning: file missing pad\n");
    6470  }
    6571  table[0].size = Nbytes;
Note: See TracChangeset for help on using the changeset viewer.