fits.cc
// Reads a header from a FITS file.  The headers in FITS files are just
// ascii text in blocks of size FITS_BLOCK_SIZE padded with spaces.  As
// such, this function will read the text from any file beginning with the
// string 'SIMPLE' in chunks of size FITS_CARD_SIZE (FITS_BLOCK_SIZE = 36 *
// FITS_CARD_SIZE) up to EOF or the string 'END' is found at the start of
// the chunk.
Reads a header from a FITS file.  The headers in FITS files are just
ascii text in blocks of size FITS_BLOCK_SIZE padded with spaces.  As
such, this function will read the text from any file beginning with the
string 'SIMPLE' in chunks of size FITS_CARD_SIZE (FITS_BLOCK_SIZE = 36
FITS_CARD_SIZE) up to EOF or the string 'END' is found at the start of
the chunk.
Reads a header from a FITS file . The headers in FITS files are just ascii text in blocks of size FITS_BLOCK_SIZE padded with spaces . As such this function will read the text from any file beginning with the string ' SIMPLE ' in chunks of size FITS_CARD_SIZE ( FITS_BLOCK_SIZE = 36 FITS_CARD_SIZE ) up to EOF or the string ' END ' is found at the start of the chunk .
void Fits::ReadHeader(const string &fits_filename, long offset,
                      string *header) {
  header->clear();
  char *card = new char[FITS_CARD_SIZE + 1];
  card[FITS_CARD_SIZE] = '\0';
  FILE *fp = fopen(fits_filename.c_str(), "r");
  CHECK(fp != NULL) << "Can't open FITS file " << fits_filename;
  CHECK_EQ(fseek(fp, offset, SEEK_SET), 0)
      << "Can't seek to position " << offset << " in FITS file "
      << fits_filename;
  int num_read = fread(card, sizeof(char), FITS_CARD_SIZE, fp);
  CHECK_EQ(num_read, FITS_CARD_SIZE) << "Couldn't read from FITS file "
                                     << fits_filename;
  CHECK(CardEqual(card, "SIMPLE", 6)) << "Input file '" << fits_filename
                                      << "' isn't a valid FITS file";
  header->append(card, FITS_CARD_SIZE);
  while (true) {
    num_read = fread(card, sizeof(char), FITS_CARD_SIZE, fp);
    if (num_read != FITS_CARD_SIZE) {
      if (feof(fp)) {
        CHECK(false) << "Found EOF before END card in " << fits_filename;
      } else {
        CHECK(false) << "Unknown IO error in FITS file " << fits_filename;
      }
    }
    header->append(card, FITS_CARD_SIZE);
    if (CardEqual(card, "END", 3)) {
      break;
    }
  }
  delete[] card;
  fclose(fp);
}
void Fits :: ReadHeader ( const string & fits_filename , long offset , string * header ) { header -> clear ( ) ; char * card = new char [ FITS_CARD_SIZE + 1 ] ; card [ FITS_CARD_SIZE ] = ' \0 ' ; FILE * fp = fopen ( fits_filename . c_str ( ) , " " ) ; CHECK ( fp != NULL ) << " " << fits_filename ; CHECK_EQ ( fseek ( fp , offset , SEEK_SET ) , 0 ) << " " << offset << " " << fits_filename ; int num_read = fread ( card , sizeof ( char ) , FITS_CARD_SIZE , fp ) ; CHECK_EQ ( num_read , FITS_CARD_SIZE ) << " " << fits_filename ; CHECK ( CardEqual ( card , " " , 6 ) ) << " " << fits_filename << " " ; header -> append ( card , FITS_CARD_SIZE ) ; while ( true ) { num_read = fread ( card , sizeof ( char ) , FITS_CARD_SIZE , fp ) ; if ( num_read != FITS_CARD_SIZE ) { if ( feof ( fp ) ) { CHECK ( false ) << " " << fits_filename ; } else { CHECK ( false ) << " " << fits_filename ; } } header -> append ( card , FITS_CARD_SIZE ) ; if ( CardEqual ( card , " " , 3 ) ) { break ; } } delete [ ] card ; fclose ( fp ) ; }
Reads a header from a FITS file.
Reads a header from a FITS file .
// Erase previous contents. // Buffer for holding each keyword entry in a FITS header. // Read header line by line. // Check first keyword. // Read other keywords until END is found or EOF is reached.