Changeset 17991 for trunk/psModules/src/config/pmConfig.c
- Timestamp:
- Jun 8, 2008, 2:38:19 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfig.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r17944 r17991 77 77 return; 78 78 } 79 80 int checkEndForWord (const char *line, const char *word) { 81 82 int wlen = strlen (word); 83 int nlen = strlen (line); 84 85 if (nlen < wlen) return 0; 86 87 char *ptr = (char *) line + nlen - wlen; 88 89 if (strcasecmp (ptr, word)) return 0; 90 91 return (nlen - wlen); 92 } 93 94 // the camera name is of the form: BASE, BASE_CHIP, or BASE_FPA. pull out BASE: 95 char *cameraBaseName (const char *name) { 96 97 int N; 98 char *answer; 99 100 N = checkEndForWord (name, "-CHIP"); 101 if (N && name[0] == '_') { 102 answer = psStringNCopy (name + 1, N - 1); 103 psStringPrepend (&answer, "_"); 104 return answer; 105 } 106 107 N = checkEndForWord (name, "-FPA"); 108 if (N && name[0] == '_') { 109 answer = psStringNCopy (name + 1, N - 1); 110 psStringPrepend (&answer, "_"); 111 return answer; 112 } 113 114 answer = psStringCopy (name); 115 return answer; 116 } 117 79 118 80 119 pmConfig *pmConfigAlloc() … … 973 1012 974 1013 // Given a camera and a header, see if any of the camera formats match the header 975 static bool formatFromHeader(psMetadata **format, // Format to return 1014 // if so, return the winning format and the name of the winning format (both allocated here) 1015 static bool formatFromHeader(bool *status, 1016 psMetadata **format, // Format to return 976 1017 psString *name, // Name to return 977 1018 psMetadata *camera, // Camera configuration … … 986 1027 assert(*cameraName); 987 1028 1029 *status = true; // error status 988 1030 bool result = false; // Did we find the first match? 989 1031 … … 993 1035 if (!mdok || !formats) { 994 1036 psError(PS_ERR_UNKNOWN, false, "Unable to find list of FORMATS in camera %s", cameraName); 1037 *status = false; 995 1038 return false; 996 1039 } … … 998 1041 if (!metadataReadFiles(formats, "camera format")) { 999 1042 psError(PS_ERR_UNKNOWN, false, "Unable to read cameras formats within camera configuration.\n"); 1043 *status = false; 1000 1044 return false; 1001 1045 } … … 1014 1058 psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n", 1015 1059 cameraName, formatsItem->name); 1060 *status = false; 1016 1061 return false; 1017 1062 } … … 1030 1075 } 1031 1076 psFree(formatsIter); 1077 *status = true; 1032 1078 return result; 1033 1079 } 1034 1080 1035 // we only need to read the recipe for the main camera images. for additional images (eg, sky 1036 // cells) do not need to re-read the recipe files! 1037 psMetadata *pmConfigCameraFormatFromHeader(pmConfig *config, const psMetadata *header, bool readRecipes) 1081 // determine the camera format based on the keywords in the header. If we have already chosen 1082 // a camera, then we select the formats only from that camera, and the meta-cameras for that 1083 // camera. If we are discovering the camera (config->camera == NULL), then we also load the 1084 // recipe files for the camera. 1085 psMetadata *pmConfigCameraFormatFromHeader(psMetadata **camera, psString *formatName, pmConfig *config, const psMetadata *header, bool readRecipes) 1038 1086 { 1039 1087 PS_ASSERT_PTR_NON_NULL(config, NULL); 1040 1088 PS_ASSERT_PTR_NON_NULL(header, NULL); 1041 1089 1090 bool status = false; // error status 1042 1091 psMetadata *format = NULL; // The winning format 1043 1092 psString name = NULL; // Name of the winning format … … 1045 1094 // If we don't know what sort of camera we have, we try all that we know 1046 1095 if (! config->camera) { 1096 psAssert (!config->cameraName, "programming error: cameraName should be NULL if camera is undefined"); 1097 psAssert (!config->format, "programming error: format should be NULL if camera is undefined"); 1098 psAssert (!config->formatName, "programming error: formatName should be NULL if camera is undefined"); 1099 1047 1100 bool mdok; // Metadata lookup status 1048 1101 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS"); … … 1066 1119 assert(camerasItem->type == PS_DATA_METADATA); // It should be because we've read it in or deleted 1067 1120 psMetadata *testCamera = camerasItem->data.md; // Camera to test against what we've got: 1068 if (formatFromHeader(&format, &name, testCamera, header, camerasItem->name)) { 1069 // Set the defaults, if they are not already set 1070 if (!config->camera && !config->cameraName) { 1071 config->camera = psMemIncrRefCounter(testCamera); 1072 config->cameraName = psStringCopy(camerasItem->name); 1073 } 1074 if (!config->format && !config->formatName) { 1075 config->formatName = name; 1076 config->format = format; 1077 } else { 1078 psFree(name); 1079 psFree(format); 1080 } 1081 } else { 1082 // XXX have to be careful with this construction: it catches other errors cluttering up the stack... 1083 psErr *error = psErrorLast(); 1084 if (error->code != PS_ERR_NONE) { 1121 if (formatFromHeader(&status, &format, &name, testCamera, header, camerasItem->name)) { 1122 config->camera = psMemIncrRefCounter(testCamera); 1123 config->cameraName = psStringCopy(camerasItem->name); 1124 config->formatName = name; 1125 config->format = format; 1126 if (camera) { 1127 *camera = psMemIncrRefCounter(testCamera); // view on value saved on config 1128 } 1129 if (formatName) { 1130 *formatName = psMemIncrRefCounter(name); // view on value saved on config 1131 } 1132 } else { 1133 if (!status) { 1085 1134 psError(PS_ERR_IO, false, "Error reading camera config data for %s", camerasItem->name); 1086 1135 return NULL; 1087 1136 } 1088 psFree(error); 1089 } 1090 } // Done looking at all cameras 1137 } 1138 } 1091 1139 psFree(camerasIter); 1092 1140 1093 if (! config->camera) { 1141 // Done looking at all cameras 1142 if (!config->camera) { 1094 1143 psError(PS_ERR_IO, false, "Unable to find a camera that matches input FITS header!"); 1095 1144 return NULL; … … 1104 1153 } 1105 1154 1106 // Otherwise, try the specific camera 1107 if (!formatFromHeader(&format, &name, config->camera, header, config->cameraName)) { 1155 // we have a config with a specified camera. However, the supplied header may not 1156 // correspond to this mosaic level for the camera. We need to try the CHIP and FPA mosaic 1157 // versions as well as the base version 1158 1159 psAssert (config->cameraName, "programming error: cameraName should not be NULL if camera is defined"); 1160 psAssert (config->format, "programming error: format should not be NULL if camera is defined"); 1161 psAssert (config->formatName, "programming error: formatName should not be NULL if camera is defined"); 1162 1163 // the camera name is of the form: BASE, BASE_CHIP, or BASE_FPA. pull out BASE: 1164 char *baseName = cameraBaseName (config->cameraName); 1165 1166 bool found = false; 1167 1168 psMetadata *testCamera = NULL; 1169 char *testName = NULL; 1170 1171 psMetadata *cameras = psMetadataLookupMetadata (NULL, config->complete, "CAMERAS"); 1172 psAssert (cameras, "missing CAMERAS in complete metadata"); 1173 1174 // try the FPA metaCamera 1175 if (!found) { 1176 testName = NULL; 1177 psStringAppend (&testName, "_%s-FPA", baseName); 1178 1179 testCamera = psMetadataLookupMetadata (NULL, cameras, testName); 1180 psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName); 1181 1182 bool status; 1183 found = formatFromHeader(&status, &format, &name, testCamera, header, testName); 1184 if (!found) psFree (testName); 1185 } 1186 1187 // try the CHIP metaCamera 1188 if (!found) { 1189 testName = NULL; 1190 psStringAppend (&testName, "_%s-CHIP", baseName); 1191 1192 testCamera = psMetadataLookupMetadata (NULL, cameras, testName); 1193 psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName); 1194 1195 bool status; 1196 found = formatFromHeader(&status, &format, &name, testCamera, header, testName); 1197 if (!found) psFree (testName); 1198 } 1199 1200 // try the base name 1201 if (!found) { 1202 testName = psMemIncrRefCounter (baseName); 1203 1204 testCamera = psMetadataLookupMetadata (NULL, cameras, testName); 1205 psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName); 1206 1207 bool status; 1208 found = formatFromHeader(&status, &format, &name, testCamera, header, testName); 1209 } 1210 1211 if (!found) { 1108 1212 psError(PS_ERR_IO, true, "Unable to find a format with the specified camera (%s) that matches the " 1109 "given header.\n", config->cameraName); 1213 "given header.\n", baseName); 1214 psFree (baseName); 1110 1215 return NULL; 1111 1216 } 1112 1113 // Now that we have the camera, we can apply recipes based on command-line arguments 1114 if (readRecipes && !pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CL)) { 1115 psError(PS_ERR_IO, false, "Error reading recipes from camera config for %s", config->cameraName); 1116 return NULL; 1117 } 1118 1119 if (!config->format && !config->formatName) { 1120 config->formatName = name; 1121 config->format = format; 1217 1218 psFree (baseName); 1219 if (formatName) { 1220 *formatName = testName; 1122 1221 } else { 1123 psFree(format); 1124 psFree(name); 1125 } 1222 psFree (testName); 1223 } 1224 if (camera) { 1225 *camera = psMemIncrRefCounter(testCamera); 1226 } 1126 1227 return psMemIncrRefCounter(format); 1127 1228 }
Note:
See TracChangeset
for help on using the changeset viewer.
