Changeset 14985
- Timestamp:
- Sep 21, 2007, 5:08:05 PM (19 years ago)
- Location:
- branches/pap_branch_070920/psLib/src/fits
- Files:
-
- 2 edited
-
psFitsHeader.c (modified) (6 diffs)
-
psFitsHeader.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_070920/psLib/src/fits/psFitsHeader.c
r14460 r14985 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $10 * @date $Date: 2007-0 8-10 02:23:42$9 * @version $Revision: 1.34.4.1 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-09-22 03:08:05 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 19 19 #include <unistd.h> 20 20 21 #include "psAssert.h" 21 22 #include "psFits.h" 22 23 #include "string.h" … … 32 33 33 34 #define MAX_STRING_LENGTH 256 // maximum length string for FITS routines 35 #define NUM_EMPTY_KEYS 8 // Number of keywords before header is considered practically empty 34 36 35 37 // list of FITS header keys to ignore; NULL-terminated 36 static c har* ignoreFitsKeys[] = {"", NULL};38 static const char* ignoreFitsKeys[] = {"", NULL}; 37 39 38 40 // List of FITS header keys that may be duplicated; NULL-terminated 39 static c har *duplicateFitsKeys[] = {"COMMENT", "HIERARCH", "HISTORY", NULL};41 static const char *duplicateFitsKeys[] = {"COMMENT", "HIERARCH", "HISTORY", NULL}; 40 42 41 43 // List of FITS header keys not to write (handled by cfitsio); NULL-terminated 42 static char *noWriteFitsKeys[] = {"SIMPLE", "XTENSION", "BITPIX", "NAXIS", "EXTNAME", "BSCALE", "BZERO", 43 "TFIELDS", NULL}; 44 static const char *noWriteFitsKeys[] = {"SIMPLE", "XTENSION", "BITPIX", "NAXIS", "EXTNAME", "BSCALE", "BZERO", 45 "TFIELDS", NULL}; 46 44 47 // List of the start of FITS header keys not to write (handled by cfitsio); NULL-terminated 45 static char *noWriteFitsKeyStarts[] = {"NAXIS", "TTYPE", "TFORM", NULL}; 46 47 // List of FITS header keys to be written with fits_write_comment 48 static const char *noWriteFitsKeyStarts[] = {"NAXIS", "TTYPE", "TFORM", NULL}; 49 50 // List of FITS header keys that may be present if the header is considered "empty"; NULL-terminated 51 static const char *emptyKeys[] = { "SIMPLE", "BITPIX", "NAXIS", "EXTEND", "COMMENT", "CHECKSUM", "DATASUM", 52 NULL }; 53 54 // Compare a keyword with a list of keywords; return true if it's in the list 55 static bool keywordInList(const char *keyword, // Keyword to check 56 const char **list // List of keywords 57 ) 58 { 59 for (const char **check = list; *check; *check++) { 60 if (strcmp(keyword, *check) == 0) { 61 return true; 62 } 63 } 64 return false; 65 } 66 67 68 bool psFitsEmptyPHU(const psFits *fits, const psMetadata *header) 69 { 70 PS_ASSERT_PTR_NON_NULL(fits, false); 71 PS_ASSERT_METADATA_NON_NULL(header, false); 72 73 int hduNum = 0; // Which HDU we're at 74 fits_get_hdu_num(fits->fd, &hduNum); /* Get the current output HDU position */ 75 76 if (hduNum != 1) { 77 // It's not the PHU, so it can't be an empty PHU! 78 return false; 79 } 80 81 if (header->list->n == 0) { 82 // There's nothing in the list 83 return true; 84 } 85 86 // Check if it's got any keywords of potential interest 87 psMetadataIterator *iter = psMetadataIteratorAlloc(header, PS_LIST_HEAD, NULL); // Iterator 88 psMetadataItem *item; // Item from iteration 89 while ((item = psMetadataGetAndIncrement(iter))) { 90 if (!keywordInList(item->name, emptyKeys)) { 91 psFree(iter); 92 return false; 93 } 94 } 95 96 return true; 97 } 98 48 99 49 100 psMetadata* psFitsReadHeader(psMetadata* out, … … 74 125 75 126 // Check to see if the keyword should be ignored 76 bool ignoreKey = false; // Ignore this keyword? 77 for (int i = 0; ignoreFitsKeys[i] && !ignoreKey; i++) { 78 if (strcmp(keyName, ignoreFitsKeys[i]) == 0) { 79 ignoreKey = true; 80 } 81 } 82 if (ignoreKey) { 127 if (keywordInList(keyName, ignoreFitsKeys)) { 83 128 // We're done here; skip to the next key 84 129 continue; 85 130 } 86 131 87 #if 088 // This doesn't seem to be necessary89 if (strncmp(keyName, "HIERARCH ", 9) == 0) {90 char temp[MAX_STRING_LENGTH];91 strcpy(temp, &keyName[9]);92 strcpy(keyName, temp);93 }94 #endif95 96 132 // Check to see if the keyword should be duplicated 97 133 int dupFlag = 0; // Duplicate flag 98 for (int i = 0; duplicateFitsKeys[i] && !dupFlag; i++) { 99 if (strcmp(keyName, duplicateFitsKeys[i]) == 0) { 100 dupFlag = PS_META_DUPLICATE_OK; 101 } 134 if (keywordInList(keyName, duplicateFitsKeys)) { 135 dupFlag = PS_META_DUPLICATE_OK; 102 136 } 103 137 … … 279 313 // image, the NAXISn haven't been changed; or after converting to F32, the BITPIX hasn't been 280 314 // changed) so we'll take care of that for them. 281 bool writeKey = true; // Should we write this keyword? 282 for (int i = 0; noWriteFitsKeys[i] && writeKey; i++) { 283 if (strcmp(item->name, noWriteFitsKeys[i]) == 0) { 284 writeKey = false; 285 } 286 } 287 if (!writeKey) { 315 if (keywordInList(item->name, noWriteFitsKeys)) { 288 316 // Don't write it; skip to the next key 289 317 continue; … … 294 322 // that go in are correct. However, when we're writing a "blank" HDU (header only), we want 295 323 // to preserve NAXISn etc for reference, so we don't do this. 324 bool writeKey = true; // Write this keyword? 296 325 for (int i = 0; noWriteFitsKeyStarts[i] && writeKey; i++) { 297 326 if (strncmp(item->name, noWriteFitsKeyStarts[i], strlen(noWriteFitsKeyStarts[i])) == 0) { -
branches/pap_branch_070920/psLib/src/fits/psFitsHeader.h
r11248 r14985 4 4 * @author Robert DeSonia, MHPCC 5 5 * 6 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $7 * @date $Date: 2007-0 1-23 22:47:23$6 * @version $Revision: 1.10.14.1 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-09-22 03:08:05 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 18 18 #include "psFits.h" 19 19 #include "psMetadata.h" 20 21 /// Determines whether the current HDU is an empty PHU 22 bool psFitsEmptyPHU(const psFits *fits, ///< FITS file pointer 23 const psMetadata *header ///< Header 24 ); 25 20 26 21 27 /** Reads the header of the current HDU.
Note:
See TracChangeset
for help on using the changeset viewer.
