Changeset 17587 for trunk/psLib
- Timestamp:
- May 8, 2008, 11:40:25 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsHeader.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsHeader.c
r17447 r17587 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.4 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2008-0 4-17 23:43:02$9 * @version $Revision: 1.45 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2008-05-08 21:40:25 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 47 47 // List of FITS header keys not to write (handled by cfitsio); NULL-terminated 48 48 static const char *noWriteFitsKeys[] = { "SIMPLE", "XTENSION", "BITPIX", "NAXIS", "EXTNAME", "BSCALE", 49 "BZERO", "TFIELDS", "PCOUNT", "GCOUNT", "ZIMAGE", "ZBITPIX", 50 "ZCMPTYPE", "PSBITPIX", NULL }; 49 "BZERO", "TFIELDS", "PCOUNT", "GCOUNT", "PSBITPIX", NULL }; 51 50 52 51 // List of the start of FITS header keys not to write (handled by cfitsio); NULL-terminated 53 static const char *noWriteFitsKeyStarts[] = { "NAXIS", "TTYPE", "TFORM", "ZNAXIS", "ZTILE", "ZNAME", "ZVAL", 54 NULL }; 52 static const char *noWriteFitsKeyStarts[] = { "NAXIS", "TTYPE", "TFORM", NULL }; 53 54 // List of compressed FITS header keys not to write (handled by cfitsio); NULL-terminated 55 static const char *noWriteCompressedKeys[] = { "ZBITPIX", "ZIMAGE", "ZBITPIX", "ZCMPTYPE", NULL }; 56 57 // List of the start of FITS header keys not to write (handled by cfitsio); NULL-terminated 58 static const char *noWriteCompressedKeyStarts[] = { "ZNAXIS", "ZTILE", "ZNAME", "ZVAL", NULL }; 55 59 56 60 // List of FITS header keys that may be present if the header is considered "empty"; NULL-terminated … … 65 69 66 70 // Translation for compressed image headers FROM TO 71 // The "From" and "To" are appropriate for reading. 67 72 static keywordTranslation compressTranslation[] = { { "ZSIMPLE", "SIMPLE" }, 68 73 { "ZTENSION", "XTENSION" }, … … 94 99 } 95 100 101 // Compare a keyword with a list of keyword beginnings; return true if the keyword starts with one of these 102 static bool keywordStartsWith(const char *keyword, // Keyword to check 103 const char *list[] // List of keyword beginnings 104 ) 105 { 106 bool writeKey = true; // Write this keyword? 107 for (int i = 0; list[i] && writeKey; i++) { 108 if (strncmp(keyword, list[i], strlen(list[i])) == 0) { 109 return true; 110 } 111 } 112 return false; 113 } 114 115 96 116 // Translate one keyword to another. 97 117 // This is appropriate for reading … … 125 145 } 126 146 } 127 // It translates to itself , so ignore128 return NULL;147 // It translates to itself 148 return keyword; 129 149 } 130 150 … … 528 548 // image, the NAXISn haven't been changed; or after converting to F32, the BITPIX hasn't been 529 549 // changed) so we'll take care of that for them. 530 if (keywordInList(name, noWriteFitsKeys)) { 531 if (strcmp(name, "SIMPLE") == 0 || compress == PS_FITS_COMPRESS_NONE || 532 (fits->options && !fits->options->conventions.compression)) { 533 // No compression happening, so don't write keyword 550 551 // Also block out TTYPEn, NAXISn, etc --- keywords that start with a certain sequence. 552 // We want to do this when writing an image or table, since it guarantees that the NAXISn etc 553 // that go in are correct. However, when we're writing a "blank" HDU (header only), we want 554 // to preserve NAXISn etc for reference, so we don't do this. 555 556 // Options for compression 557 if (compress != PS_FITS_COMPRESS_NONE && 558 (!fits->options || fits->options->conventions.compression)) { 559 // Check to see if the keyword should be translated 560 name = (char*)keywordUntranslate(name, compressTranslation); // Casting away const for cfitsio 561 562 if (keywordInList(name, noWriteCompressedKeys) || 563 (keyStarts && keywordStartsWith(name, noWriteCompressedKeyStarts))) { 534 564 continue; 535 565 } 536 // Check to see if the keyword should be translated rather than written 537 name = (char*)keywordUntranslate(name, compressTranslation); // Casting away const for cfitsio 538 if (!name) { 539 // Not in translation list, so don't write 540 continue; 541 } 542 } 543 544 if (keyStarts) { 545 // Also block out TTYPEn, NAXISn, etc --- keywords that start with a certain sequence. 546 // We want to do this when writing an image or table, since it guarantees that the NAXISn etc 547 // that go in are correct. However, when we're writing a "blank" HDU (header only), we want 548 // to preserve NAXISn etc for reference, so we don't do this. 549 bool writeKey = true; // Write this keyword? 550 for (int i = 0; noWriteFitsKeyStarts[i] && writeKey; i++) { 551 if (strncmp(item->name, noWriteFitsKeyStarts[i], strlen(noWriteFitsKeyStarts[i])) == 0) { 552 writeKey = false; 553 } 554 } 555 if (!writeKey) { 556 // Don't write it; skip to the next key 557 continue; 558 } 566 } 567 568 if (keywordInList(name, noWriteFitsKeys) || 569 (keyStarts && keywordStartsWith(name, noWriteFitsKeyStarts))) { 570 continue; 559 571 } 560 572 }
Note:
See TracChangeset
for help on using the changeset viewer.
