IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39996 for trunk


Ignore:
Timestamp:
Mar 5, 2017, 11:23:19 AM (9 years ago)
Author:
eugene
Message:

try a second time if we get an error but it is not EOF

File:
1 edited

Legend:

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

    r38986 r39996  
    2929}
    3030
     31/*********************** gfits_fread_incomplete_case ***********************************/
     32int gfits_fread_incomplete_case (FILE *f, FTable *table, int padIfShort, off_t Nread, off_t Nbytes) {
     33  char string[128];
     34
     35  snprintf (string, 128, "FITS file is short (%s)", __func__);
     36  perror (string);
     37  if (Nread < gfits_data_min_size (table[0].header)) {
     38    fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__,  Nread,  gfits_data_min_size (table[0].header));
     39    if (!padIfShort) {
     40      gfits_free_table (table);
     41      return FALSE;
     42    }
     43    memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
     44    fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
     45  } else {
     46    fprintf (stderr, "warning: file missing pad\n");
     47  }
     48  return TRUE;
     49}
     50
    3151/*********************** fits read ftable data ***********************************/
    3252int gfits_fread_ftable_data (FILE *f, FTable *table, int padIfShort) {
    3353
    3454  off_t Nbytes, Nread;
    35   char string[128];
    3655
    3756  /* find buffer size */
     
    4160  Nread = fread (table[0].buffer, sizeof (char), Nbytes, f);
    4261  if (Nread != Nbytes) {
    43     snprintf (string, 128, "FITS file is short (%s)", __func__);
    44     perror (string);
    45     if (Nread < gfits_data_min_size (table[0].header)) {
    46       fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__,  Nread,  gfits_data_min_size (table[0].header));
    47       if (!padIfShort) {
    48         gfits_free_table (table);
    49         return (FALSE);
     62    if (feof(f)) {
     63      if (!gfits_fread_incomplete_case(f, table, padIfShort, Nread, Nbytes)) return FALSE;
     64    } else {
     65      off_t Nextra = Nbytes - Nread;
     66      off_t Nxread = fread (&table[0].buffer[Nread], sizeof (char), Nextra, f);
     67      Nread += Nxread;
     68      if (Nread != Nbytes) {
     69        if (!gfits_fread_incomplete_case(f, table, padIfShort, Nread, Nbytes)) return FALSE;
    5070      }
    51       memset (&table[0].buffer[Nread], 0, Nbytes - Nread);
    52       fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n");
    53     } else {
    54       fprintf (stderr, "warning: file missing pad\n");
    5571    }
    5672  }
Note: See TracChangeset for help on using the changeset viewer.