From 0f668971013836ba13b8131e6247d84bf2b280f2 Mon Sep 17 00:00:00 2001 From: Tom Stephens Date: Fri, 21 Mar 2025 15:16:53 -0600 Subject: [PATCH 1/2] Update writeOutputMap_wcs() to only append new keywords and update existing ones. This also appends and new COMMENT or HISTORY keyword lines which may result in duplication. --- src/ModelMap.cxx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ModelMap.cxx b/src/ModelMap.cxx index 5e08c6891..a06763d7e 100644 --- a/src/ModelMap.cxx +++ b/src/ModelMap.cxx @@ -14,6 +14,7 @@ #include "tip/IFileSvc.h" #include "tip/Image.h" #include "tip/Table.h" +#include "tip/Header.h" #include "st_facilities/FitsUtil.h" @@ -169,13 +170,24 @@ void ModelMap::writeOutputMap_wcs(const std::string & outfile, tip::Header & output_header = output_image->getHeader(); output_image->set(m_outmap); + // tip::Header::KeyValCont_t updatedKeywords; for ( tip::Header::ConstIterator itr = orig_header.begin(); itr != orig_header.end(); itr++ ) { // Don't copy the NAXIS* keywords if ( itr->getName().find("NAXIS") != std::string::npos ) { continue; } - output_header.append(*itr); + // append any new keywords and any new HISTORY or COMMENT keywords or update the + // value for any existing kewords. - TS 03/21/25 + auto kwItr = output_header.find(itr->getName()); + if (kwItr == output_header.end() || "COMMENT" == kwItr->getName() || "HISTORY" == kwItr->getName()){ + output_header.append(*itr); + } else { + kwItr->setValue(itr->getValue()); + } } + // update the existing keywords in the generated list + // output_header.update(updatedKeywords); + if (outtype == "CMAP") { output_header.erase("CTYPE3"); output_header.erase("CRPIX3"); From 7a0d6ea0d25b4c9ae9cb6a4c261db75ed7f85842 Mon Sep 17 00:00:00 2001 From: Tom Stephens Date: Fri, 2 May 2025 13:59:09 -0600 Subject: [PATCH 2/2] fix comment --- src/ModelMap.cxx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ModelMap.cxx b/src/ModelMap.cxx index a06763d7e..df295d207 100644 --- a/src/ModelMap.cxx +++ b/src/ModelMap.cxx @@ -170,14 +170,13 @@ void ModelMap::writeOutputMap_wcs(const std::string & outfile, tip::Header & output_header = output_image->getHeader(); output_image->set(m_outmap); - // tip::Header::KeyValCont_t updatedKeywords; for ( tip::Header::ConstIterator itr = orig_header.begin(); itr != orig_header.end(); itr++ ) { // Don't copy the NAXIS* keywords if ( itr->getName().find("NAXIS") != std::string::npos ) { continue; } - // append any new keywords and any new HISTORY or COMMENT keywords or update the - // value for any existing kewords. - TS 03/21/25 + // append any new keywords and any new HISTORY or COMMENT keywords (some of these might end up duplicated) + // or update the value for any existing kewords. - TS 03/21/25 auto kwItr = output_header.find(itr->getName()); if (kwItr == output_header.end() || "COMMENT" == kwItr->getName() || "HISTORY" == kwItr->getName()){ output_header.append(*itr); @@ -185,8 +184,6 @@ void ModelMap::writeOutputMap_wcs(const std::string & outfile, kwItr->setValue(itr->getValue()); } } - // update the existing keywords in the generated list - // output_header.update(updatedKeywords); if (outtype == "CMAP") { output_header.erase("CTYPE3");