Changeset 16822 for trunk/psLib/src/fits/psFitsHeader.c
- Timestamp:
- Mar 4, 2008, 4:19:28 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsHeader.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsHeader.c
r16665 r16822 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.4 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2008-0 2-26 23:42:21$9 * @version $Revision: 1.41 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2008-03-05 02:19:28 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 93 93 } 94 94 95 // Translate one keyword to another. 96 // This is appropriate for reading 95 97 static const char *keywordTranslate(const char *keyword, // Keyword to check 96 98 keywordTranslation translation[] // Translation list … … 108 110 // It translates to itself 109 111 return keyword; 112 } 113 114 // Translate back the other way. 115 // This is appropriate for writing. 116 static const char *keywordUntranslate(const char *keyword, // Keyword to check 117 keywordTranslation translation[] // Translation list 118 ) 119 { 120 for (keywordTranslation *trans = translation; (*trans).to; ++trans) { 121 if (strcmp(keyword, (*trans).to) == 0) { 122 // Translate it 123 return (*trans).from; 124 } 125 } 126 // It translates to itself, so ignore 127 return NULL; 110 128 } 111 129 … … 461 479 int status = 0; // Status of cfitsio calls 462 480 bool simple = true; // If SIMPLE is T, then the file should conform to the FITS standard 463 psMetadataItem *simpleItem = psMetadataLookup(output, "SIMPLE"); // SIMPLE in the header 464 if (simpleItem) { 481 if (psFitsGetExtNum(fits) == 0) { 465 482 // We allow the user to write SIMPLE, but it must be boolean 466 if (simpleItem->type != PS_DATA_BOOL) { 467 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "SIMPLE in a FITS header must be of boolean type: " 468 "not %x --- assuming TRUE.\n", simpleItem->type); 469 int value = false; // Temporary holder for boolean 470 fits_update_key(fits->fd, TLOGICAL, "SIMPLE", &value, 471 "File does not conform to FITS standard", &status); 472 simple = false; 473 } else if (!simpleItem->data.B) { 474 simple = false; 475 int value = false; // Temporary holder for boolean 476 fits_update_key(fits->fd, TLOGICAL, "SIMPLE", &value, 477 "File does not conform to FITS standard", &status); 478 } 479 // SIMPLE = T is taken care of by cfitsio. 483 psMetadataItem *simpleItem = psMetadataLookup(output, "SIMPLE"); // SIMPLE in the header 484 if (simpleItem) { 485 if (simpleItem->type != PS_DATA_BOOL) { 486 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "SIMPLE in a FITS header must be of boolean type: " 487 "not %x --- assuming TRUE.\n", simpleItem->type); 488 int value = false; // Temporary holder for boolean 489 fits_update_key(fits->fd, TLOGICAL, "SIMPLE", &value, 490 "File does not conform to FITS standard", &status); 491 simple = false; 492 } else if (!simpleItem->data.B) { 493 simple = false; 494 int value = false; // Temporary holder for boolean 495 fits_update_key(fits->fd, TLOGICAL, "SIMPLE", &value, 496 "File does not conform to FITS standard", &status); 497 } 498 // SIMPLE = T is taken care of by cfitsio. 499 } 480 500 } 481 501 482 502 // Traverse the metadata list and add each key. 503 psFitsCompressionType compress = psFitsCompressionGetType(fits); // Compression type 483 504 psListIterator* iter = psListIteratorAlloc(output->list, PS_LIST_HEAD, true); // Iterator 484 505 psMetadataItem* item; // Item from iteration 485 506 while ((item = psListGetAndIncrement(iter))) { 507 char *name = item->name; // Keyword name to use when writing out 486 508 // Check to see if the item should be ignored 487 509 if (simple) { … … 490 512 // image, the NAXISn haven't been changed; or after converting to F32, the BITPIX hasn't been 491 513 // changed) so we'll take care of that for them. 492 if (keywordInList(item->name, noWriteFitsKeys)) { 493 // Don't write it; skip to the next key 494 continue; 495 } 514 if (keywordInList(name, noWriteFitsKeys)) { 515 if ((fits->options && !fits->options->conventions.compression) || 516 compress == PS_FITS_COMPRESS_NONE) { 517 // No compression happening, so don't write keyword 518 continue; 519 } 520 // Check to see if the keyword should be translated rather than written 521 name = (char*)keywordUntranslate(name, compressTranslation); // Casting away const for cfitsio 522 if (!name) { 523 // Not in translation list, so don't write 524 continue; 525 } 526 } 527 496 528 if (keyStarts) { 497 529 // Also block out TTYPEn, NAXISn, etc --- keywords that start with a certain sequence. … … 512 544 } 513 545 514 if (strcmp( item->name, "COMMENT") == 0) {546 if (strcmp(name, "COMMENT") == 0) { 515 547 if (item->type != PS_DATA_STRING) { 516 548 psWarning("COMMENT header is not of type STRING (%x) --- ignored.", item->type); … … 518 550 fits_write_comment(fits->fd, item->data.str, &status); 519 551 } 520 } else if (strcmp( item->name, "HISTORY") == 0) {552 } else if (strcmp(name, "HISTORY") == 0) { 521 553 if (item->type != PS_DATA_STRING) { 522 554 psWarning("COMMENT header is not of type STRING (%x) --- ignored.", item->type); … … 529 561 case PS_DATA_BOOL: { 530 562 int value = item->data.B; 531 fits_update_key(fits->fd, TLOGICAL, item->name, &value, item->comment, &status);563 fits_update_key(fits->fd, TLOGICAL, name, &value, item->comment, &status); 532 564 break; 533 565 } 534 566 case PS_DATA_S8: 535 fits_update_key(fits->fd, TBYTE, item->name, &item->data.S8, item->comment, &status);567 fits_update_key(fits->fd, TBYTE, name, &item->data.S8, item->comment, &status); 536 568 break; 537 569 case PS_DATA_S16: 538 fits_update_key(fits->fd, TSHORT, item->name, &item->data.S16, item->comment, &status);570 fits_update_key(fits->fd, TSHORT, name, &item->data.S16, item->comment, &status); 539 571 break; 540 572 case PS_DATA_S32: 541 fits_update_key(fits->fd, TINT, item->name, &item->data.S32, item->comment, &status);573 fits_update_key(fits->fd, TINT, name, &item->data.S32, item->comment, &status); 542 574 break; 543 575 case PS_DATA_U8: { 544 576 unsigned short int temp = item->data.U8; 545 fits_update_key(fits->fd, TUSHORT, item->name, &temp, item->comment, &status);577 fits_update_key(fits->fd, TUSHORT, name, &temp, item->comment, &status); 546 578 } 547 579 break; 548 580 case PS_DATA_U16: 549 fits_update_key(fits->fd, TUSHORT, item->name, &item->data.U16, item->comment, &status);581 fits_update_key(fits->fd, TUSHORT, name, &item->data.U16, item->comment, &status); 550 582 break; 551 583 case PS_DATA_U32: 552 fits_update_key(fits->fd, TUINT, item->name, &item->data.U32, item->comment, &status);584 fits_update_key(fits->fd, TUINT, name, &item->data.U32, item->comment, &status); 553 585 break; 554 586 case PS_DATA_F32: { 555 587 int infCheck = 0; // Result of isinf() 556 588 if (isnan(item->data.F32)) { 557 fits_update_key(fits->fd, TSTRING, item->name, "NaN", item->comment, &status);589 fits_update_key(fits->fd, TSTRING, name, "NaN", item->comment, &status); 558 590 } else if ((infCheck = isinf(item->data.F32)) != 0) { 559 591 if (infCheck == 1) { 560 fits_update_key(fits->fd, TSTRING, item->name, "Inf", item->comment, &status);592 fits_update_key(fits->fd, TSTRING, name, "Inf", item->comment, &status); 561 593 } else { 562 fits_update_key(fits->fd, TSTRING, item->name, "-Inf", item->comment, &status);594 fits_update_key(fits->fd, TSTRING, name, "-Inf", item->comment, &status); 563 595 } 564 596 } else { 565 fits_update_key(fits->fd, TFLOAT, item->name, &item->data.F32, item->comment,597 fits_update_key(fits->fd, TFLOAT, name, &item->data.F32, item->comment, 566 598 &status); 567 599 } … … 571 603 int infCheck = 0; // Result of isinf() 572 604 if (isnan(item->data.F64)) { 573 fits_update_key(fits->fd, TSTRING, item->name, "NaN", item->comment, &status);605 fits_update_key(fits->fd, TSTRING, name, "NaN", item->comment, &status); 574 606 } else if ((infCheck = isinf(item->data.F64)) != 0) { 575 607 if (infCheck == 1) { 576 fits_update_key(fits->fd, TSTRING, item->name, "Inf", item->comment, &status);608 fits_update_key(fits->fd, TSTRING, name, "Inf", item->comment, &status); 577 609 } else { 578 fits_update_key(fits->fd, TSTRING, item->name, "-Inf", item->comment, &status);610 fits_update_key(fits->fd, TSTRING, name, "-Inf", item->comment, &status); 579 611 } 580 612 } else { 581 fits_update_key(fits->fd, TDOUBLE, item->name, &item->data.F64, item->comment,613 fits_update_key(fits->fd, TDOUBLE, name, &item->data.F64, item->comment, 582 614 &status); 583 615 } … … 585 617 } 586 618 case PS_DATA_STRING: 587 fits_update_key(fits->fd, TSTRING, item->name, item->data.V, item->comment, &status);619 fits_update_key(fits->fd, TSTRING, name, item->data.V, item->comment, &status); 588 620 break; 589 621 default: // all other META types are ignored
Note:
See TracChangeset
for help on using the changeset viewer.
