Changeset 7221
- Timestamp:
- May 25, 2006, 1:41:18 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsHeader.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsHeader.c
r7162 r7221 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-05-2 2 22:39:07$9 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-05-25 23:41:18 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 28 28 #define MAX_STRING_LENGTH 256 // maximum length string for FITS routines 29 29 30 // list of FITS header keys to ignore. 31 static char* standardFitsKeys[] = { 32 NULL 33 }; 30 // list of FITS header keys to ignore; NULL-terminated 31 static char* ignoreFitsKeys[] = {NULL}; 32 33 // List of FITS header keys that may be duplicated; NULL-terminated 34 static char *duplicateFitsKeys[] = {"COMMENT", "HIERARCH", "HISTORY", "", NULL}; 34 35 35 36 psMetadata* psFitsReadHeader(psMetadata* out, … … 52 53 53 54 // Get number of key names 54 int numKeys = 0; 55 int keyNum = 0; 56 int status = 0; 55 int numKeys = 0; // Number of keywords 56 int keyNum = 0; // Current key number 57 int status = 0; // Status of cfitsio calls 57 58 fits_get_hdrpos(fits->fd, &numKeys, &keyNum, &status); 58 59 59 60 // Get each key name. Keywords start at one. 60 char keyType;61 char keyName[MAX_STRING_LENGTH];62 char keyValue[MAX_STRING_LENGTH];63 char keyComment[MAX_STRING_LENGTH];64 psBool tempBool;65 psBool success;66 psBool stdKey;67 61 for (int i = 1; i <= numKeys; i++) { 68 62 char keyName[MAX_STRING_LENGTH];// Keyword name 63 char keyValue[MAX_STRING_LENGTH]; // Corresponding value 64 char keyComment[MAX_STRING_LENGTH]; // Corresponding comment 69 65 fits_read_keyn(fits->fd, i, keyName, keyValue, keyComment, &status); 70 66 71 stdKey = false; 72 73 int stdKeyIdx = 0; 74 while (standardFitsKeys[stdKeyIdx] != NULL && ! stdKey) { 75 if (strcmp(keyName,standardFitsKeys[stdKeyIdx++]) == 0) { 76 stdKey = true; 77 } 78 } 79 67 // Check to see if the keyword should be ignored 68 bool ignoreKey = false; // Ignore this keyword? 69 for (int i = 0; ignoreFitsKeys[i] && !ignoreKey; i++) { 70 if (strcmp(keyName, ignoreFitsKeys[i]) == 0) { 71 ignoreKey = true; 72 } 73 } 74 if (ignoreKey) { 75 // We're done here; skip to the next key 76 continue; 77 } 78 79 // Check to see if the keyword should be duplicated 80 int dupFlag = 0; // Duplicate flag 81 for (int i = 0; duplicateFitsKeys[i] && !dupFlag; i++) { 82 if (strcmp(keyName, duplicateFitsKeys[i]) == 0) { 83 dupFlag = PS_META_DUPLICATE_OK; 84 } 85 } 86 87 char keyType; // Type of key; from cfitsio 80 88 if (keyValue[0] != 0) { // blank values are not handled by fits_get_keytype 81 89 fits_get_keytype(keyValue, &keyType, &status); … … 87 95 } 88 96 89 if (! stdKey) { 90 switch (keyType) { 91 case 'X': // bit 92 case 'B': // byte 93 success = psMetadataAdd(out, 94 PS_LIST_TAIL, 95 keyName, 96 PS_DATA_S8 | PS_META_DUPLICATE_OK, 97 keyComment, 98 atoi(keyValue)); 97 psBool success; // Was the add to the metadata successful? 98 switch (keyType) { 99 case 'X': // bit 100 case 'B': // byte 101 success = psMetadataAdd(out, PS_LIST_TAIL, keyName, PS_DATA_S8 | dupFlag, keyComment, 102 atoi(keyValue)); 103 break; 104 case 'I': // short int. 105 success = psMetadataAdd(out, PS_LIST_TAIL, keyName, PS_DATA_S16 | dupFlag, keyComment, 106 (psS16)atoi(keyValue)); 107 break; 108 case 'J': // int. 109 success = psMetadataAdd(out, PS_LIST_TAIL, keyName, PS_DATA_S32 | dupFlag, keyComment, 110 atoi(keyValue)); 111 break; 112 case 'U': // unsigned int. 113 success = psMetadataAdd(out, PS_LIST_TAIL, keyName, PS_DATA_U32 | dupFlag, keyComment, 114 atol(keyValue)); 115 break; 116 117 case 'K': // long int. can't all fit in a psS32, put in psF64 118 case 'F': 119 success = psMetadataAdd(out, PS_LIST_TAIL, keyName, PS_DATA_F64 | dupFlag, keyComment, 120 atof(keyValue)); 121 break; 122 case 'C': { 123 char *keyValueFixed = keyValue; // Fixed version of the string 124 // remove the single-quotes at front/end 125 if (keyValueFixed[0] == '\'' && keyValueFixed[strlen(keyValue)-1] == '\'') { 126 keyValue[strlen(keyValue)-1] = '\0'; // Remove the trailing quote 127 keyValueFixed += 1; // Advance past the leading quote 128 } 129 // Remove trailing spaces, which are not significant, according to the FITS standard 130 // http://archive.stsci.edu/fits/fits_standard/node31.html 131 char *lastSpace = NULL; // The last space in the string 132 while (strlen(keyValueFixed) > 1 && (lastSpace = strrchr(keyValueFixed, ' ')) && 133 lastSpace[1] == '\0') { 134 // This is a trailing space, not a leading space. 135 lastSpace[0] = '\0'; // Truncate the string here 136 } 137 138 success = psMetadataAdd(out, PS_LIST_TAIL, keyName, PS_DATA_STRING | dupFlag, keyComment, 139 keyValueFixed); 99 140 break; 100 case 'I': // short int. 101 success = psMetadataAdd(out, 102 PS_LIST_TAIL, 103 keyName, 104 PS_DATA_S16 | PS_META_DUPLICATE_OK, 105 keyComment, 106 (psS16)atoi(keyValue)); 141 } 142 case 'L': { 143 bool temp = (keyValue[0] == 'T') ? 1 : 0; 144 success = psMetadataAdd(out, PS_LIST_TAIL, keyName, PS_DATA_BOOL | dupFlag, keyComment, temp); 107 145 break; 108 case 'J': // int. 109 success = psMetadataAdd(out, 110 PS_LIST_TAIL, 111 keyName, 112 PS_DATA_S32 | PS_META_DUPLICATE_OK, 113 keyComment, 114 atoi(keyValue)); 115 break; 116 case 'U': // unsigned int. 117 success = psMetadataAdd(out, 118 PS_LIST_TAIL, 119 keyName, 120 PS_DATA_U32 | PS_META_DUPLICATE_OK, 121 keyComment, 122 atol(keyValue)); 123 break; 124 125 case 'K': // long int. can't all fit in a psS32, put in psF64 126 case 'F': 127 success = psMetadataAdd(out, 128 PS_LIST_TAIL, 129 keyName, 130 PS_DATA_F64 | PS_META_DUPLICATE_OK, 131 keyComment, 132 atof(keyValue)); 133 break; 134 case 'C': { 135 char *keyValueFixed = keyValue; // Fixed version of the string 136 // remove the single-quotes at front/end 137 if (keyValueFixed[0] == '\'' && keyValueFixed[strlen(keyValue)-1] == '\'') { 138 keyValue[strlen(keyValue)-1] = '\0'; // Remove the trailing quote 139 keyValueFixed += 1; // Advance past the leading quote 140 } 141 // Remove trailing spaces, which are not significant, according to the FITS standard 142 // http://archive.stsci.edu/fits/fits_standard/node31.html 143 char *lastSpace = NULL; // The last space in the string 144 while (strlen(keyValueFixed) > 1 && (lastSpace = strrchr(keyValueFixed, ' ')) && 145 lastSpace[1] == '\0') { 146 // This is a trailing space, not a leading space. 147 lastSpace[0] = '\0'; // Truncate the string here 148 } 149 150 success = psMetadataAdd(out, 151 PS_LIST_TAIL, 152 keyName, 153 PS_DATA_STRING | PS_META_DUPLICATE_OK, 154 keyComment, 155 keyValueFixed); 156 break; 157 } 158 case 'L': 159 tempBool = (keyValue[0] == 'T') ? 1 : 0; 160 success = psMetadataAdd(out, 161 PS_LIST_TAIL, 162 keyName, 163 PS_DATA_BOOL | PS_META_DUPLICATE_OK, 164 keyComment, 165 tempBool); 166 break; 167 default: 168 psError(PS_ERR_IO, true, 169 PS_ERRORTEXT_psFits_METATYPE_INVALID, 170 keyType); 171 return out; 172 } 173 174 if (!success) { 175 psError(PS_ERR_UNKNOWN, false, 176 PS_ERRORTEXT_psFits_METADATA_ADD_FAILED, 177 keyName); 178 return out; 179 } 180 } 181 182 } 183 184 if ( status != 0) { 146 } 147 default: 148 psError(PS_ERR_IO, true, PS_ERRORTEXT_psFits_METATYPE_INVALID, keyType); 149 return out; 150 } 151 152 if (!success) { 153 psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psFits_METADATA_ADD_FAILED, keyName); 154 return out; 155 } 156 157 } 158 159 if (status != 0) { 185 160 char fitsErr[MAX_STRING_LENGTH]; 186 161 (void)fits_get_errstatus(status, fitsErr); 187 psError(PS_ERR_IO, true, 188 PS_ERRORTEXT_psFits_METADATA_ADD_FAILED, 189 fitsErr); 162 psError(PS_ERR_IO, true, PS_ERRORTEXT_psFits_METADATA_ADD_FAILED, fitsErr); 190 163 return false; 191 164 } … … 197 170 { 198 171 if (fits == NULL) { 199 psError(PS_ERR_BAD_PARAMETER_NULL, true, 200 PS_ERRORTEXT_psFits_NULL); 172 psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_NULL); 201 173 psFree(out); 202 174 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.
