fits.cc
// Adds NAXIS1 = image and NAXIS2 = height to the input header if they are
// not present.  This function is safe to call if both of the keywords are
// already present but NOT if only one keyword is present (this would violate
// the FITS standard anyway).
Adds NAXIS1 = image and NAXIS2 = height to the input header if they are
not present.  This function is safe to call if both of the keywords are
already present but NOT if only one keyword is present (this would violate
the FITS standard anyway).
Adds NAXIS1 = image and NAXIS2 = height to the input header if they are not present . This function is safe to call if both of the keywords are already present but NOT if only one keyword is present ( this would violate the FITS standard anyway ) .
void Fits::AddImageDimensions(int width, int height, string *header) {
  int naxis_len = strlen("NAXIS");
  int naxis_location = -1;
  for (int i = 0; i < static_cast<int>(header->size()); i += FITS_CARD_SIZE) {
    string keyword = header->substr(i, naxis_len);
    if (keyword == "NAXIS") {
      naxis_location = i;
      break;
    }
  }
  CHECK_GT(naxis_location, 0) << "Header lacks NAXIS keyword";
  int naxis_value = Fits::HeaderReadKeywordInt(*header, "NAXIS", -1);
  if (naxis_value < 2) {
    string naxis = "NAXIS   =                    2";
    *header = header->replace(naxis_location, naxis.size(), naxis);
  }
  int naxis1_location = naxis_location + FITS_CARD_SIZE;
  int naxis2_location = naxis_location + 2 * FITS_CARD_SIZE;
  string naxis1 = header->substr(naxis1_location, strlen("NAXIS1"));
  string naxis2 = header->substr(naxis2_location, strlen("NAXIS2"));
  string naxis1_card = "";
  string naxis2_card = "";
  if (naxis1 != "NAXIS1" && naxis2 != "NAXIS2") {
    SStringPrintf(&naxis1_card, "%-8s= %20d / %-47s", "NAXIS1", width,
                 "Image width");
    SStringPrintf(&naxis2_card, "%-8s= %20d / %-47s", "NAXIS2", height,
                 "Image height");
  } else if (naxis1 == "NAXIS1" && naxis2 == "NAXIS2") {
  } else {
    CHECK(false) << "Can't handle case where only NAXIS1 or NAXIS2 are missing";
  }
  string header_new =
      header->substr(0, naxis_location + FITS_CARD_SIZE) +
      naxis1_card + naxis2_card +
      header->substr(naxis_location + FITS_CARD_SIZE,
                     header->size() - naxis_location - FITS_CARD_SIZE);
  header->assign(header_new);
}
void Fits :: AddImageDimensions ( int width , int height , string * header ) { int naxis_len = strlen ( " " ) ; int naxis_location = -1 ; for ( int i = 0 ; i < static_cast < int > ( header -> size ( ) ) ; i += FITS_CARD_SIZE ) { string keyword = header -> substr ( i , naxis_len ) ; if ( keyword == " " ) { naxis_location = i ; break ; } } CHECK_GT ( naxis_location , 0 ) << " " ; int naxis_value = Fits :: HeaderReadKeywordInt ( * header , " " , -1 ) ; if ( naxis_value < 2 ) { string naxis = " " ; * header = header -> replace ( naxis_location , naxis . size ( ) , naxis ) ; } int naxis1_location = naxis_location + FITS_CARD_SIZE ; int naxis2_location = naxis_location + 2 * FITS_CARD_SIZE ; string naxis1 = header -> substr ( naxis1_location , strlen ( " " ) ) ; string naxis2 = header -> substr ( naxis2_location , strlen ( " " ) ) ; string naxis1_card = " " ; string naxis2_card = " " ; if ( naxis1 != " " && naxis2 != " " ) { SStringPrintf ( & naxis1_card , " " , " " , width , " " ) ; SStringPrintf ( & naxis2_card , " " , " " , height , " " ) ; } else if ( naxis1 == " " && naxis2 == " " ) { } else { CHECK ( false ) << " " ; } string header_new = header -> substr ( 0 , naxis_location + FITS_CARD_SIZE ) + naxis1_card + naxis2_card + header -> substr ( naxis_location + FITS_CARD_SIZE , header -> size ( ) - naxis_location - FITS_CARD_SIZE ) ; header -> assign ( header_new ) ; }
Adds NAXIS1 = image and NAXIS2 = height to the input header if they are
not present.
Adds NAXIS1 = image and NAXIS2 = height to the input header if they are not present .
// Find the location of the NAXIS keyword. To do this, // we look at each keyword in the header.  This is probably not necessary // since NAXIS should be the third keyword, but this is extra safe. // Ensure that the value of NAXIS is always at least 2 because smaller // values cannot contain images.  Some non-optical images store other // information in higher dimensions. // The FITS standard specifies that the NAXIS1 and NAXIS2 keywords must // immediately follow NAXIS. // Do nothing. // Create the new header by taking the part including NAXIS and the part // after it and adding in the NAXIS1, NAXIS2 cards if needed.  Finally // we copy the new header back to the input.