Changeset 18036 for trunk/psModules/src/config/pmConfig.c
- Timestamp:
- Jun 9, 2008, 3:16:36 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfig.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r18034 r18036 78 78 } 79 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; 80 // Check the end of a string for a word; return the length of the string without the ending word 81 // Used to identify the camera base name (e.g., "MEGACAM" out of "_MEGACAM-CHIP") 82 int checkEndForWord(const char *line, // String to check for ending word 83 const char *word // Ending word to check for 84 ) 85 { 86 int wlen = strlen(word); // Length of word 87 int nlen = strlen(line); // Length of line 88 if (nlen < wlen) { 89 return 0; 90 } 91 92 char *ptr = (char *)line + nlen - wlen; // Expected position of ending word 93 if (strcasecmp(ptr, word)) { 94 return 0; 95 } 90 96 91 97 return (nlen - wlen); … … 93 99 94 100 // 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; 101 char *cameraBaseName(const char *name // Name of meta-camera 102 ) 103 { 98 104 char *answer; 99 105 100 N = checkEndForWord (name, "-CHIP");106 int N = checkEndForWord (name, "-CHIP"); 101 107 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 psString answer = psStringNCopy(name + 1, N - 1); 109 return answer; 110 } 111 112 N = checkEndForWord(name, "-FPA"); 108 113 if (N && name[0] == '_') { 109 answer = psStringNCopy (name + 1, N - 1); 110 psStringPrepend (&answer, "_"); 111 return answer; 112 } 113 114 answer = psStringCopy (name); 114 psString answer = psStringNCopy(name + 1, N - 1); 115 return answer; 116 } 117 118 N = checkEndForWord(name, "-SKYCELL"); 119 if (N && name[0] == '_') { 120 psString answer = psStringNCopy(name + 1, N - 1); 121 return answer; 122 } 123 124 answer = psStringCopy(name); 115 125 return answer; 116 126 } … … 1014 1024 // if so, return the winning format and the name of the winning format (both allocated here) 1015 1025 static bool formatFromHeader(bool *status, 1016 psMetadata **format, // Format to return1026 psMetadata **format, // Format to return 1017 1027 psString *name, // Name to return 1018 1028 psMetadata *camera, // Camera configuration … … 1027 1037 assert(*cameraName); 1028 1038 1029 *status = true; // error status1039 *status = true; // error status 1030 1040 bool result = false; // Did we find the first match? 1031 1041 … … 1035 1045 if (!mdok || !formats) { 1036 1046 psError(PS_ERR_UNKNOWN, false, "Unable to find list of FORMATS in camera %s", cameraName); 1037 *status = false;1047 *status = false; 1038 1048 return false; 1039 1049 } … … 1041 1051 if (!metadataReadFiles(formats, "camera format")) { 1042 1052 psError(PS_ERR_UNKNOWN, false, "Unable to read cameras formats within camera configuration.\n"); 1043 *status = false;1053 *status = false; 1044 1054 return false; 1045 1055 } … … 1058 1068 psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n", 1059 1069 cameraName, formatsItem->name); 1060 *status = false;1070 *status = false; 1061 1071 return false; 1062 1072 } … … 1088 1098 PS_ASSERT_PTR_NON_NULL(header, NULL); 1089 1099 1090 bool status = false; // error status1100 bool status = false; // error status 1091 1101 psMetadata *format = NULL; // The winning format 1092 1102 psString name = NULL; // Name of the winning format … … 1094 1104 // If we don't know what sort of camera we have, we try all that we know 1095 1105 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");1106 psAssert (!config->cameraName, "programming error: cameraName should be NULL if camera is undefined"); 1107 psAssert (!config->format, "programming error: format should be NULL if camera is undefined"); 1108 psAssert (!config->formatName, "programming error: formatName should be NULL if camera is undefined"); 1099 1109 1100 1110 bool mdok; // Metadata lookup status … … 1120 1130 psMetadata *testCamera = camerasItem->data.md; // Camera to test against what we've got: 1121 1131 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 config1128 } 1129 if (formatName) {1130 *formatName = psMemIncrRefCounter(name);// view on value saved on config1131 }1132 } else {1133 if (!status) {1132 config->camera = psMemIncrRefCounter(testCamera); 1133 config->cameraName = psStringCopy(camerasItem->name); 1134 config->formatName = name; 1135 config->format = format; 1136 if (camera) { 1137 *camera = psMemIncrRefCounter(testCamera); // view on value saved on config 1138 } 1139 if (formatName) { 1140 *formatName = psMemIncrRefCounter(name); // view on value saved on config 1141 } 1142 } else { 1143 if (!status) { 1134 1144 psError(PS_ERR_IO, false, "Error reading camera config data for %s", camerasItem->name); 1135 1145 return NULL; 1136 1146 } 1137 1147 } 1138 } 1148 } 1139 1149 psFree(camerasIter); 1140 1150 1141 // Done looking at all cameras1151 // Done looking at all cameras 1142 1152 if (!config->camera) { 1143 1153 psError(PS_ERR_IO, false, "Unable to find a camera that matches input FITS header!"); … … 1174 1184 // try the FPA metaCamera 1175 1185 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);1186 testName = NULL; 1187 psStringAppend (&testName, "_%s-FPA", baseName); 1188 1189 testCamera = psMetadataLookupMetadata (NULL, cameras, testName); 1190 psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName); 1191 1192 bool status; 1193 found = formatFromHeader(&status, &format, &name, testCamera, header, testName); 1194 if (!found) psFree (testName); 1185 1195 } 1186 1196 1187 1197 // try the CHIP metaCamera 1188 1198 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); 1199 testName = NULL; 1200 psStringAppend (&testName, "_%s-CHIP", baseName); 1201 1202 testCamera = psMetadataLookupMetadata (NULL, cameras, testName); 1203 psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName); 1204 1205 bool status; 1206 found = formatFromHeader(&status, &format, &name, testCamera, header, testName); 1207 if (!found) psFree (testName); 1208 } 1209 1210 // try the SKYCELL metaCamera 1211 if (!found) { 1212 testName = NULL; 1213 psStringAppend (&testName, "_%s-SKYCELL", baseName); 1214 1215 testCamera = psMetadataLookupMetadata (NULL, cameras, testName); 1216 psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName); 1217 1218 bool status; 1219 found = formatFromHeader(&status, &format, &name, testCamera, header, testName); 1220 if (!found) psFree (testName); 1198 1221 } 1199 1222 1200 1223 // try the base name 1201 1224 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);1225 testName = psMemIncrRefCounter (baseName); 1226 1227 testCamera = psMetadataLookupMetadata (NULL, cameras, testName); 1228 psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName); 1229 1230 bool status; 1231 found = formatFromHeader(&status, &format, &name, testCamera, header, testName); 1209 1232 } 1210 1233 … … 1212 1235 psError(PS_ERR_IO, true, "Unable to find a format with the specified camera (%s) that matches the " 1213 1236 "given header.\n", baseName); 1214 psFree (baseName);1237 psFree (baseName); 1215 1238 return NULL; 1216 1239 } 1217 1240 1218 1241 psFree (name); // winning format name (for metaCamera) returned by formatFromHeader 1219 1242 1220 1243 psFree (baseName); 1221 1244 if (formatName) { 1222 *formatName = testName;1245 *formatName = testName; 1223 1246 } else { 1224 psFree (testName);1247 psFree (testName); 1225 1248 } 1226 1249 if (camera) { 1227 *camera = psMemIncrRefCounter(testCamera);1228 } 1250 *camera = psMemIncrRefCounter(testCamera); 1251 } 1229 1252 return format; // we do NOT need to incr ref counter: this is the only copy 1230 1253 }
Note:
See TracChangeset
for help on using the changeset viewer.
