Changeset 1970
- Timestamp:
- Oct 5, 2004, 3:06:27 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 6 edited
-
astronomy/psMetadata.c (modified) (9 diffs)
-
astronomy/psMetadata.h (modified) (5 diffs)
-
collections/psMetadata.c (modified) (9 diffs)
-
collections/psMetadata.h (modified) (5 diffs)
-
types/psMetadata.c (modified) (9 diffs)
-
types/psMetadata.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astronomy/psMetadata.c
r1844 r1970 3 3 * 4 4 * 5 * @brief Contains metadata stru uctures, enumerations and functions prototypes5 * @brief Contains metadata structures, enumerations and functions prototypes. 6 6 * 7 7 * This file defines metadata item, metadata type, metadata flags, metadata containers, and function … … 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.2 8$ $Name: not supported by cvs2svn $15 * @date $Date: 2004- 09-21 23:27:55$14 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-10-06 01:06:20 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 #include "psList.h" 33 33 #include "psHash.h" 34 #include "psVector.h" 34 35 #include "psMetadata.h" 35 36 #include "psString.h" … … 39 40 /******************************************************************************/ 40 41 41 #define FITS_ERROR(STRING,PS_ERROR) \42 fits_get_errstatus(status, fitsErr); \43 psError(__func__, STRING, PS_ERROR, fitsErr); \44 status = 0; \45 fits_close_file(fd, &status); \46 if(status){ \47 fits_get_errstatus(status, fitsErr); \48 psError(__func__, "Couldn't close FITS file. FITS error: %s", fitsErr); \49 } \50 status = 0; \51 return output;52 53 /** Maximum size of a FITS line */54 #define FITS_LINE_SIZE 8055 56 42 /** Maximum size of a string */ 57 43 #define MAX_STRING_LENGTH 1024 … … 93 79 psFree(metadataItem->items); 94 80 95 if (type == PS_META_STR || 96 type == PS_META_IMG || 97 type == PS_META_JPEG || type == PS_META_PNG || type == PS_META_ASTROM || type == PS_META_UNKNOWN) { 81 if (type == PS_META_STR || type == PS_META_VEC || type == PS_META_IMG || type == PS_META_JPEG || 82 type == PS_META_PNG || type == PS_META_ASTROM || type == PS_META_UNKNOWN) { 98 83 psFree(metadataItem->data.V); 99 84 } … … 133 118 va_list argPtr) 134 119 { 120 psVector *vecIn = NULL; 121 psVector *vecOut = NULL; 135 122 psMetadataItem* metadataItem = NULL; 123 136 124 137 125 if (name == NULL) { … … 182 170 metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH); 183 171 break; 172 case PS_META_VEC: 173 vecIn = (psVector*)va_arg(argPtr, psVector*); 174 vecOut = psVectorAlloc(vecIn->nalloc, vecIn->type.type); 175 memcpy(vecOut->data.V, vecIn->data.V, vecIn->nalloc*PSELEMTYPE_SIZEOF(vecIn->type.type)); 176 metadataItem->data.V = vecOut; 177 break; 184 178 case PS_META_IMG: 185 179 case PS_META_JPEG: … … 373 367 return true; 374 368 } 375 376 377 369 378 370 bool psMetadataRemove(psMetadata* restrict md, int where, const char *restrict key) … … 603 595 return entry; 604 596 } 605 606 void psMetadataItemPrint(FILE * fd, const char *format, const psMetadataItem* restrict metadataItem)607 {608 psMetadataType type;609 610 if (fd == NULL) {611 psError(__func__, "Null file descriptor not allowed");612 return;613 }614 615 if (format == NULL) {616 psError(__func__, "Null format not allowed");617 return;618 }619 620 if (metadataItem == NULL) {621 psError(__func__, "Null metadata not allowed");622 return;623 }624 625 type = metadataItem->type;626 627 switch (type) {628 case PS_META_BOOL:629 fprintf(fd, format, metadataItem->data.B);630 break;631 case PS_META_S32:632 fprintf(fd,format, metadataItem->data.S32);633 break;634 case PS_META_F32:635 fprintf(fd, format, metadataItem->data.F32);636 break;637 case PS_META_F64:638 fprintf(fd, format, metadataItem->data.F64);639 break;640 case PS_META_STR:641 fprintf(fd, format, metadataItem->data.V);642 break;643 case PS_META_ITEM_SET:644 case PS_META_IMG:645 case PS_META_JPEG:646 case PS_META_PNG:647 case PS_META_ASTROM:648 case PS_META_UNKNOWN:649 default:650 psError(__func__, " Invalid psMetadataType to print: %d", type);651 }652 }653 654 psMetadata* psMetadataReadHeader(psMetadata* output, char *extName, int extNum, char *fileName)655 {656 bool tempBool;657 bool success;658 char keyType;659 char keyName[FITS_LINE_SIZE];660 char keyValue[FITS_LINE_SIZE];661 char keyComment[FITS_LINE_SIZE];662 char fitsErr[MAX_STRING_LENGTH];663 int i;664 int hduType = 0;665 int status = 0;666 int numKeys = 0;667 int keyNum = 0;668 psMetadataType metadataItemType;669 fitsfile *fd = NULL;670 671 if(fileName == NULL) {672 psError(__func__, "Null fileName not allowed");673 return NULL;674 }675 676 fits_open_file(&fd, fileName, READONLY, &status);677 if(fd == NULL || status != 0) {678 FITS_ERROR("FITS error while opening file: %s %s", fileName);679 return NULL;680 }681 682 if (extName == NULL && extNum == 0) {683 psError(__func__, "Null extName and extNum = 0 not allowed");684 return NULL;685 } else if (extName && extNum) {686 psError(__func__, "Both extName and extNum arguments should not have non zero values.");687 return NULL;688 }689 690 // Allocate metadata if user didn't691 if (output == NULL) {692 output = psMetadataAlloc();693 }694 695 // Move to user designated HDU number or HDU name in FITS file. HDU numbers starts at one.696 if (extName != NULL) {697 if (fits_movnam_hdu(fd, ANY_HDU, extName, 0, &status) != 0) {698 FITS_ERROR("FITS error while locating header %s: %s", extName);699 }700 } else {701 if (fits_movabs_hdu(fd, extNum, &hduType, &status) != 0) {702 FITS_ERROR("FITS error while locating header %d: %s", extNum);703 }704 }705 706 // Get number of key names707 if (fits_get_hdrpos(fd, &numKeys, &keyNum, &status) != 0) {708 FITS_ERROR("FITS error while reading key %d: %s", keyNum);709 }710 711 // Get each key name. Keywords start at one.712 for (i = 1; i <= numKeys; i++) {713 if (fits_read_keyn(fd, i, keyName, keyValue, keyComment, &status) != 0) {714 FITS_ERROR("FITS error while reading key %d: %s", keyNum);715 }716 if (fits_get_keytype(keyValue, &keyType, &status) != 0) {717 fits_get_errstatus(status, fitsErr);718 if (status != VALUE_UNDEFINED) {719 FITS_ERROR("FITS error while determining key %d type: %s", keyNum);720 } else {721 // Some keywords are still valid if they don't have a type (like COMMENTS and HISTORY)722 keyType = 'C';723 status = 0;724 }725 }726 727 switch (keyType) {728 case 'I':729 metadataItemType = PS_META_S32;730 success =731 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment,732 atoi(keyValue));733 break;734 case 'F':735 metadataItemType = PS_META_F64;736 success =737 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment,738 atof(keyValue));739 break;740 case 'C':741 metadataItemType = PS_META_STR;742 success =743 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, keyValue);744 break;745 case 'L':746 metadataItemType = PS_META_BOOL;747 tempBool = (keyValue[0] == 'T') ? 1 : 0;748 success =749 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, tempBool);750 break;751 case 'U':752 case 'X':753 default:754 psError(__func__, "Invalid psMetadataType: %c", keyType);755 return output;756 }757 758 if (!success) {759 psError(__func__, "Failed to add metadata item. Name: %s", keyName);760 return output;761 }762 }763 764 return output;765 } -
trunk/psLib/src/astronomy/psMetadata.h
r1844 r1970 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2004- 09-21 23:27:55$13 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-06 01:06:27 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 21 21 #include <stdarg.h> 22 22 #include <stdio.h> 23 #include <fitsio.h>24 23 25 24 #include "psHash.h" … … 40 39 PS_META_F64, ///< Double-precision float data. 41 40 PS_META_STR, ///< String data (Stored in as void *). 41 PS_META_VEC, ///< Vector data (Stored in as void *). 42 42 PS_META_IMG, ///< Image data (Stored in as void *). 43 43 PS_META_JPEG, ///< JPEG data (Stored in as void *). … … 84 84 psMetadata; 85 85 86 /*****************************************************************************/87 88 /* FUNCTION PROTOTYPES */89 90 /*****************************************************************************/91 92 86 /** Create a metadata item. 93 87 * … … 248 242 ); 249 243 250 /** Print metadata item to file.251 *252 * Metadata items may be printed to an open file descriptor based on a253 * provided format. The format is a sprintf format statement with exactly254 * one % formatting command. If the metadata item type is a numeric type,255 * this formatting command must also be numeric, and the type conversion256 * performed to the value to match the format type. If the metadata type is257 * a string, the fromatting command must also be for a string. If the258 * metadata type is any other data type, printing is not allowed.259 *260 * @return psMetadataItem* : Pointer metadata item.261 */262 void psMetadataItemPrint(263 FILE * fd, ///< Pointer to file to write metadata item.264 const char *format, ///< Format to print metadata item.265 const psMetadataItem* restrict metadataItem ///< Metadata item to print.266 );267 268 /** Read metadata header.269 *270 * Read a metadata header from file. If the file is not found, an error is271 * reported. This file is currently unimplemented.272 *273 * @return psMetadata* : Pointer metadata.274 */275 psMetadata* psMetadataReadHeader(276 psMetadata* output, ///< Resulting metadata from read.277 char *extName, ///< File name extension string.278 int extNum, ///< File name extension number. Starts at 1.279 char *fileName ///< Name of file to read.280 );281 244 282 245 /// @} -
trunk/psLib/src/collections/psMetadata.c
r1844 r1970 3 3 * 4 4 * 5 * @brief Contains metadata stru uctures, enumerations and functions prototypes5 * @brief Contains metadata structures, enumerations and functions prototypes. 6 6 * 7 7 * This file defines metadata item, metadata type, metadata flags, metadata containers, and function … … 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.2 8$ $Name: not supported by cvs2svn $15 * @date $Date: 2004- 09-21 23:27:55$14 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-10-06 01:06:20 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 #include "psList.h" 33 33 #include "psHash.h" 34 #include "psVector.h" 34 35 #include "psMetadata.h" 35 36 #include "psString.h" … … 39 40 /******************************************************************************/ 40 41 41 #define FITS_ERROR(STRING,PS_ERROR) \42 fits_get_errstatus(status, fitsErr); \43 psError(__func__, STRING, PS_ERROR, fitsErr); \44 status = 0; \45 fits_close_file(fd, &status); \46 if(status){ \47 fits_get_errstatus(status, fitsErr); \48 psError(__func__, "Couldn't close FITS file. FITS error: %s", fitsErr); \49 } \50 status = 0; \51 return output;52 53 /** Maximum size of a FITS line */54 #define FITS_LINE_SIZE 8055 56 42 /** Maximum size of a string */ 57 43 #define MAX_STRING_LENGTH 1024 … … 93 79 psFree(metadataItem->items); 94 80 95 if (type == PS_META_STR || 96 type == PS_META_IMG || 97 type == PS_META_JPEG || type == PS_META_PNG || type == PS_META_ASTROM || type == PS_META_UNKNOWN) { 81 if (type == PS_META_STR || type == PS_META_VEC || type == PS_META_IMG || type == PS_META_JPEG || 82 type == PS_META_PNG || type == PS_META_ASTROM || type == PS_META_UNKNOWN) { 98 83 psFree(metadataItem->data.V); 99 84 } … … 133 118 va_list argPtr) 134 119 { 120 psVector *vecIn = NULL; 121 psVector *vecOut = NULL; 135 122 psMetadataItem* metadataItem = NULL; 123 136 124 137 125 if (name == NULL) { … … 182 170 metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH); 183 171 break; 172 case PS_META_VEC: 173 vecIn = (psVector*)va_arg(argPtr, psVector*); 174 vecOut = psVectorAlloc(vecIn->nalloc, vecIn->type.type); 175 memcpy(vecOut->data.V, vecIn->data.V, vecIn->nalloc*PSELEMTYPE_SIZEOF(vecIn->type.type)); 176 metadataItem->data.V = vecOut; 177 break; 184 178 case PS_META_IMG: 185 179 case PS_META_JPEG: … … 373 367 return true; 374 368 } 375 376 377 369 378 370 bool psMetadataRemove(psMetadata* restrict md, int where, const char *restrict key) … … 603 595 return entry; 604 596 } 605 606 void psMetadataItemPrint(FILE * fd, const char *format, const psMetadataItem* restrict metadataItem)607 {608 psMetadataType type;609 610 if (fd == NULL) {611 psError(__func__, "Null file descriptor not allowed");612 return;613 }614 615 if (format == NULL) {616 psError(__func__, "Null format not allowed");617 return;618 }619 620 if (metadataItem == NULL) {621 psError(__func__, "Null metadata not allowed");622 return;623 }624 625 type = metadataItem->type;626 627 switch (type) {628 case PS_META_BOOL:629 fprintf(fd, format, metadataItem->data.B);630 break;631 case PS_META_S32:632 fprintf(fd,format, metadataItem->data.S32);633 break;634 case PS_META_F32:635 fprintf(fd, format, metadataItem->data.F32);636 break;637 case PS_META_F64:638 fprintf(fd, format, metadataItem->data.F64);639 break;640 case PS_META_STR:641 fprintf(fd, format, metadataItem->data.V);642 break;643 case PS_META_ITEM_SET:644 case PS_META_IMG:645 case PS_META_JPEG:646 case PS_META_PNG:647 case PS_META_ASTROM:648 case PS_META_UNKNOWN:649 default:650 psError(__func__, " Invalid psMetadataType to print: %d", type);651 }652 }653 654 psMetadata* psMetadataReadHeader(psMetadata* output, char *extName, int extNum, char *fileName)655 {656 bool tempBool;657 bool success;658 char keyType;659 char keyName[FITS_LINE_SIZE];660 char keyValue[FITS_LINE_SIZE];661 char keyComment[FITS_LINE_SIZE];662 char fitsErr[MAX_STRING_LENGTH];663 int i;664 int hduType = 0;665 int status = 0;666 int numKeys = 0;667 int keyNum = 0;668 psMetadataType metadataItemType;669 fitsfile *fd = NULL;670 671 if(fileName == NULL) {672 psError(__func__, "Null fileName not allowed");673 return NULL;674 }675 676 fits_open_file(&fd, fileName, READONLY, &status);677 if(fd == NULL || status != 0) {678 FITS_ERROR("FITS error while opening file: %s %s", fileName);679 return NULL;680 }681 682 if (extName == NULL && extNum == 0) {683 psError(__func__, "Null extName and extNum = 0 not allowed");684 return NULL;685 } else if (extName && extNum) {686 psError(__func__, "Both extName and extNum arguments should not have non zero values.");687 return NULL;688 }689 690 // Allocate metadata if user didn't691 if (output == NULL) {692 output = psMetadataAlloc();693 }694 695 // Move to user designated HDU number or HDU name in FITS file. HDU numbers starts at one.696 if (extName != NULL) {697 if (fits_movnam_hdu(fd, ANY_HDU, extName, 0, &status) != 0) {698 FITS_ERROR("FITS error while locating header %s: %s", extName);699 }700 } else {701 if (fits_movabs_hdu(fd, extNum, &hduType, &status) != 0) {702 FITS_ERROR("FITS error while locating header %d: %s", extNum);703 }704 }705 706 // Get number of key names707 if (fits_get_hdrpos(fd, &numKeys, &keyNum, &status) != 0) {708 FITS_ERROR("FITS error while reading key %d: %s", keyNum);709 }710 711 // Get each key name. Keywords start at one.712 for (i = 1; i <= numKeys; i++) {713 if (fits_read_keyn(fd, i, keyName, keyValue, keyComment, &status) != 0) {714 FITS_ERROR("FITS error while reading key %d: %s", keyNum);715 }716 if (fits_get_keytype(keyValue, &keyType, &status) != 0) {717 fits_get_errstatus(status, fitsErr);718 if (status != VALUE_UNDEFINED) {719 FITS_ERROR("FITS error while determining key %d type: %s", keyNum);720 } else {721 // Some keywords are still valid if they don't have a type (like COMMENTS and HISTORY)722 keyType = 'C';723 status = 0;724 }725 }726 727 switch (keyType) {728 case 'I':729 metadataItemType = PS_META_S32;730 success =731 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment,732 atoi(keyValue));733 break;734 case 'F':735 metadataItemType = PS_META_F64;736 success =737 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment,738 atof(keyValue));739 break;740 case 'C':741 metadataItemType = PS_META_STR;742 success =743 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, keyValue);744 break;745 case 'L':746 metadataItemType = PS_META_BOOL;747 tempBool = (keyValue[0] == 'T') ? 1 : 0;748 success =749 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, tempBool);750 break;751 case 'U':752 case 'X':753 default:754 psError(__func__, "Invalid psMetadataType: %c", keyType);755 return output;756 }757 758 if (!success) {759 psError(__func__, "Failed to add metadata item. Name: %s", keyName);760 return output;761 }762 }763 764 return output;765 } -
trunk/psLib/src/collections/psMetadata.h
r1844 r1970 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2004- 09-21 23:27:55$13 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-06 01:06:27 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 21 21 #include <stdarg.h> 22 22 #include <stdio.h> 23 #include <fitsio.h>24 23 25 24 #include "psHash.h" … … 40 39 PS_META_F64, ///< Double-precision float data. 41 40 PS_META_STR, ///< String data (Stored in as void *). 41 PS_META_VEC, ///< Vector data (Stored in as void *). 42 42 PS_META_IMG, ///< Image data (Stored in as void *). 43 43 PS_META_JPEG, ///< JPEG data (Stored in as void *). … … 84 84 psMetadata; 85 85 86 /*****************************************************************************/87 88 /* FUNCTION PROTOTYPES */89 90 /*****************************************************************************/91 92 86 /** Create a metadata item. 93 87 * … … 248 242 ); 249 243 250 /** Print metadata item to file.251 *252 * Metadata items may be printed to an open file descriptor based on a253 * provided format. The format is a sprintf format statement with exactly254 * one % formatting command. If the metadata item type is a numeric type,255 * this formatting command must also be numeric, and the type conversion256 * performed to the value to match the format type. If the metadata type is257 * a string, the fromatting command must also be for a string. If the258 * metadata type is any other data type, printing is not allowed.259 *260 * @return psMetadataItem* : Pointer metadata item.261 */262 void psMetadataItemPrint(263 FILE * fd, ///< Pointer to file to write metadata item.264 const char *format, ///< Format to print metadata item.265 const psMetadataItem* restrict metadataItem ///< Metadata item to print.266 );267 268 /** Read metadata header.269 *270 * Read a metadata header from file. If the file is not found, an error is271 * reported. This file is currently unimplemented.272 *273 * @return psMetadata* : Pointer metadata.274 */275 psMetadata* psMetadataReadHeader(276 psMetadata* output, ///< Resulting metadata from read.277 char *extName, ///< File name extension string.278 int extNum, ///< File name extension number. Starts at 1.279 char *fileName ///< Name of file to read.280 );281 244 282 245 /// @} -
trunk/psLib/src/types/psMetadata.c
r1844 r1970 3 3 * 4 4 * 5 * @brief Contains metadata stru uctures, enumerations and functions prototypes5 * @brief Contains metadata structures, enumerations and functions prototypes. 6 6 * 7 7 * This file defines metadata item, metadata type, metadata flags, metadata containers, and function … … 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.2 8$ $Name: not supported by cvs2svn $15 * @date $Date: 2004- 09-21 23:27:55$14 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-10-06 01:06:20 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 32 32 #include "psList.h" 33 33 #include "psHash.h" 34 #include "psVector.h" 34 35 #include "psMetadata.h" 35 36 #include "psString.h" … … 39 40 /******************************************************************************/ 40 41 41 #define FITS_ERROR(STRING,PS_ERROR) \42 fits_get_errstatus(status, fitsErr); \43 psError(__func__, STRING, PS_ERROR, fitsErr); \44 status = 0; \45 fits_close_file(fd, &status); \46 if(status){ \47 fits_get_errstatus(status, fitsErr); \48 psError(__func__, "Couldn't close FITS file. FITS error: %s", fitsErr); \49 } \50 status = 0; \51 return output;52 53 /** Maximum size of a FITS line */54 #define FITS_LINE_SIZE 8055 56 42 /** Maximum size of a string */ 57 43 #define MAX_STRING_LENGTH 1024 … … 93 79 psFree(metadataItem->items); 94 80 95 if (type == PS_META_STR || 96 type == PS_META_IMG || 97 type == PS_META_JPEG || type == PS_META_PNG || type == PS_META_ASTROM || type == PS_META_UNKNOWN) { 81 if (type == PS_META_STR || type == PS_META_VEC || type == PS_META_IMG || type == PS_META_JPEG || 82 type == PS_META_PNG || type == PS_META_ASTROM || type == PS_META_UNKNOWN) { 98 83 psFree(metadataItem->data.V); 99 84 } … … 133 118 va_list argPtr) 134 119 { 120 psVector *vecIn = NULL; 121 psVector *vecOut = NULL; 135 122 psMetadataItem* metadataItem = NULL; 123 136 124 137 125 if (name == NULL) { … … 182 170 metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH); 183 171 break; 172 case PS_META_VEC: 173 vecIn = (psVector*)va_arg(argPtr, psVector*); 174 vecOut = psVectorAlloc(vecIn->nalloc, vecIn->type.type); 175 memcpy(vecOut->data.V, vecIn->data.V, vecIn->nalloc*PSELEMTYPE_SIZEOF(vecIn->type.type)); 176 metadataItem->data.V = vecOut; 177 break; 184 178 case PS_META_IMG: 185 179 case PS_META_JPEG: … … 373 367 return true; 374 368 } 375 376 377 369 378 370 bool psMetadataRemove(psMetadata* restrict md, int where, const char *restrict key) … … 603 595 return entry; 604 596 } 605 606 void psMetadataItemPrint(FILE * fd, const char *format, const psMetadataItem* restrict metadataItem)607 {608 psMetadataType type;609 610 if (fd == NULL) {611 psError(__func__, "Null file descriptor not allowed");612 return;613 }614 615 if (format == NULL) {616 psError(__func__, "Null format not allowed");617 return;618 }619 620 if (metadataItem == NULL) {621 psError(__func__, "Null metadata not allowed");622 return;623 }624 625 type = metadataItem->type;626 627 switch (type) {628 case PS_META_BOOL:629 fprintf(fd, format, metadataItem->data.B);630 break;631 case PS_META_S32:632 fprintf(fd,format, metadataItem->data.S32);633 break;634 case PS_META_F32:635 fprintf(fd, format, metadataItem->data.F32);636 break;637 case PS_META_F64:638 fprintf(fd, format, metadataItem->data.F64);639 break;640 case PS_META_STR:641 fprintf(fd, format, metadataItem->data.V);642 break;643 case PS_META_ITEM_SET:644 case PS_META_IMG:645 case PS_META_JPEG:646 case PS_META_PNG:647 case PS_META_ASTROM:648 case PS_META_UNKNOWN:649 default:650 psError(__func__, " Invalid psMetadataType to print: %d", type);651 }652 }653 654 psMetadata* psMetadataReadHeader(psMetadata* output, char *extName, int extNum, char *fileName)655 {656 bool tempBool;657 bool success;658 char keyType;659 char keyName[FITS_LINE_SIZE];660 char keyValue[FITS_LINE_SIZE];661 char keyComment[FITS_LINE_SIZE];662 char fitsErr[MAX_STRING_LENGTH];663 int i;664 int hduType = 0;665 int status = 0;666 int numKeys = 0;667 int keyNum = 0;668 psMetadataType metadataItemType;669 fitsfile *fd = NULL;670 671 if(fileName == NULL) {672 psError(__func__, "Null fileName not allowed");673 return NULL;674 }675 676 fits_open_file(&fd, fileName, READONLY, &status);677 if(fd == NULL || status != 0) {678 FITS_ERROR("FITS error while opening file: %s %s", fileName);679 return NULL;680 }681 682 if (extName == NULL && extNum == 0) {683 psError(__func__, "Null extName and extNum = 0 not allowed");684 return NULL;685 } else if (extName && extNum) {686 psError(__func__, "Both extName and extNum arguments should not have non zero values.");687 return NULL;688 }689 690 // Allocate metadata if user didn't691 if (output == NULL) {692 output = psMetadataAlloc();693 }694 695 // Move to user designated HDU number or HDU name in FITS file. HDU numbers starts at one.696 if (extName != NULL) {697 if (fits_movnam_hdu(fd, ANY_HDU, extName, 0, &status) != 0) {698 FITS_ERROR("FITS error while locating header %s: %s", extName);699 }700 } else {701 if (fits_movabs_hdu(fd, extNum, &hduType, &status) != 0) {702 FITS_ERROR("FITS error while locating header %d: %s", extNum);703 }704 }705 706 // Get number of key names707 if (fits_get_hdrpos(fd, &numKeys, &keyNum, &status) != 0) {708 FITS_ERROR("FITS error while reading key %d: %s", keyNum);709 }710 711 // Get each key name. Keywords start at one.712 for (i = 1; i <= numKeys; i++) {713 if (fits_read_keyn(fd, i, keyName, keyValue, keyComment, &status) != 0) {714 FITS_ERROR("FITS error while reading key %d: %s", keyNum);715 }716 if (fits_get_keytype(keyValue, &keyType, &status) != 0) {717 fits_get_errstatus(status, fitsErr);718 if (status != VALUE_UNDEFINED) {719 FITS_ERROR("FITS error while determining key %d type: %s", keyNum);720 } else {721 // Some keywords are still valid if they don't have a type (like COMMENTS and HISTORY)722 keyType = 'C';723 status = 0;724 }725 }726 727 switch (keyType) {728 case 'I':729 metadataItemType = PS_META_S32;730 success =731 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment,732 atoi(keyValue));733 break;734 case 'F':735 metadataItemType = PS_META_F64;736 success =737 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment,738 atof(keyValue));739 break;740 case 'C':741 metadataItemType = PS_META_STR;742 success =743 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, keyValue);744 break;745 case 'L':746 metadataItemType = PS_META_BOOL;747 tempBool = (keyValue[0] == 'T') ? 1 : 0;748 success =749 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, tempBool);750 break;751 case 'U':752 case 'X':753 default:754 psError(__func__, "Invalid psMetadataType: %c", keyType);755 return output;756 }757 758 if (!success) {759 psError(__func__, "Failed to add metadata item. Name: %s", keyName);760 return output;761 }762 }763 764 return output;765 } -
trunk/psLib/src/types/psMetadata.h
r1844 r1970 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2004- 09-21 23:27:55$13 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-06 01:06:27 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 21 21 #include <stdarg.h> 22 22 #include <stdio.h> 23 #include <fitsio.h>24 23 25 24 #include "psHash.h" … … 40 39 PS_META_F64, ///< Double-precision float data. 41 40 PS_META_STR, ///< String data (Stored in as void *). 41 PS_META_VEC, ///< Vector data (Stored in as void *). 42 42 PS_META_IMG, ///< Image data (Stored in as void *). 43 43 PS_META_JPEG, ///< JPEG data (Stored in as void *). … … 84 84 psMetadata; 85 85 86 /*****************************************************************************/87 88 /* FUNCTION PROTOTYPES */89 90 /*****************************************************************************/91 92 86 /** Create a metadata item. 93 87 * … … 248 242 ); 249 243 250 /** Print metadata item to file.251 *252 * Metadata items may be printed to an open file descriptor based on a253 * provided format. The format is a sprintf format statement with exactly254 * one % formatting command. If the metadata item type is a numeric type,255 * this formatting command must also be numeric, and the type conversion256 * performed to the value to match the format type. If the metadata type is257 * a string, the fromatting command must also be for a string. If the258 * metadata type is any other data type, printing is not allowed.259 *260 * @return psMetadataItem* : Pointer metadata item.261 */262 void psMetadataItemPrint(263 FILE * fd, ///< Pointer to file to write metadata item.264 const char *format, ///< Format to print metadata item.265 const psMetadataItem* restrict metadataItem ///< Metadata item to print.266 );267 268 /** Read metadata header.269 *270 * Read a metadata header from file. If the file is not found, an error is271 * reported. This file is currently unimplemented.272 *273 * @return psMetadata* : Pointer metadata.274 */275 psMetadata* psMetadataReadHeader(276 psMetadata* output, ///< Resulting metadata from read.277 char *extName, ///< File name extension string.278 int extNum, ///< File name extension number. Starts at 1.279 char *fileName ///< Name of file to read.280 );281 244 282 245 /// @}
Note:
See TracChangeset
for help on using the changeset viewer.
