Changeset 15217
- Timestamp:
- Oct 4, 2007, 10:15:48 AM (19 years ago)
- Location:
- trunk/psModules/src
- Files:
-
- 3 edited
-
camera/pmFPAfileDefine.c (modified) (3 diffs)
-
config/pmConfig.c (modified) (5 diffs)
-
config/pmConfig.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAfileDefine.c
r15183 r15217 20 20 #include "pmFPAConstruct.h" 21 21 22 23 // Get the file rule of interest24 // Look up the name of the set of file rules to use, get that set from the site configuration, and return the25 // appropriate rule from the set.26 static psMetadata *getFileRule(const pmConfig *config, // Configuration27 const psMetadata *camera, // Camera configuration of interest28 const char *name // Name of rule to read29 )30 {31 assert(config);32 assert(config->site);33 34 psMetadataItem *item = psMetadataLookup(camera, "FILERULES"); // Item with the file rule of interest35 if (!item) {36 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the camera configuration.");37 return NULL;38 }39 40 psMetadata *filerules = NULL; // File rules from the site configuration41 switch (item->type) {42 case PS_DATA_METADATA:43 // It's what we're after44 filerules = item->data.md;45 break;46 case PS_DATA_STRING: {47 // It's the name of a file --- read the file, and store it for future use48 if (!pmConfigFileRead(&filerules, item->data.str, "filerules")) {49 psError(PM_ERR_CONFIG, false, "Trouble reading reading file rules from %s --- "50 "ignored.\n", item->data.str);51 psFree(filerules);52 return NULL;53 }54 55 // Muck around under the hood to replace the filename with the metadata; don't try this at home,56 // kids57 item->type = PS_DATA_METADATA;58 psFree(item->data.str);59 item->data.md = filerules;60 break;61 }62 default:63 psError(PS_ERR_BAD_PARAMETER_TYPE, true,64 "Unexpected type for %s (%x) in FILERULES in SITE configuration.",65 name, item->type);66 return NULL;67 }68 69 // select the name from the FILERULES70 // check for alias name (type == STR, name is aliased name)71 bool mdok; // Status of MD lookup72 const char *realname = psMetadataLookupStr(&mdok, filerules, name); // Name of file rule to look up73 if (!realname || strlen(realname) == 0) {74 realname = name;75 }76 77 return psMetadataLookupMetadata(NULL, filerules, realname);78 }79 80 22 // Parse an option from a metadata, returning the appropriate integer value 81 23 static int parseOptionInt(const psMetadata *md, // Metadata containing the option … … 107 49 108 50 const psMetadata *camera = (fpa ? fpa->camera : config->camera); // Camera configuration for this file 109 psMetadata *data = getFileRule(config, camera, name); // File rule51 psMetadata *data = pmConfigFileRule(config, camera, name); // File rule 110 52 if (!data) { 111 53 psError(PS_ERR_IO, true, "Can't find file rule %s!", name); … … 198 140 } 199 141 200 psMetadata *data = getFileRule(config, camera, name); // File rule142 psMetadata *data = pmConfigFileRule(config, camera, name); // File rule 201 143 if (!data) { 202 144 psError(PS_ERR_IO, true, "Can't find file rule %s!", name); -
trunk/psModules/src/config/pmConfig.c
r15180 r15217 229 229 } 230 230 231 // Read a file into a metadataItem, if required 232 static bool metadataItemReadFile(psMetadataItem *item, // Item into which to read file 233 const char *description // Description, for error messages 234 ) 235 { 236 assert(item); 237 assert(description); 238 239 if (item->type == PS_DATA_METADATA) { 240 return true; // We've already read it 241 } 242 if (item->type != PS_DATA_STRING) { 243 psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n", 244 item->name, description); 245 return false; 246 } 247 248 psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str); 249 psMetadata *new = NULL; // New metadata 250 if (!pmConfigFileRead(&new, item->data.str, item->name)) { 251 psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s.\n", 252 description, item->name); 253 psFree(new); 254 return false; 255 } 256 257 // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids 258 item->type = PS_DATA_METADATA; 259 psFree(item->data.str); 260 item->data.md = new; 261 262 return true; 263 } 264 231 265 // Read metadata config files in a metadata 232 266 // The metadata contains file names, which will be replaced with the metadata that are in the files. … … 239 273 psMetadataItem *item; // Item from iteration 240 274 while ((item = psMetadataGetAndIncrement(iter))) { 241 if (item->type == PS_DATA_METADATA) { 242 continue; // We've already read it 243 } 244 if (item->type != PS_DATA_STRING) { 245 psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n", 246 item->name, description); 247 continue; 248 } 249 250 psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str); 251 psMetadata *new = NULL; // New metadata 252 if (!pmConfigFileRead(&new, item->data.str, item->name)) { 253 psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s --- " 254 "ignored.\n", description, item->name); 255 psFree(new); 275 if (!metadataItemReadFile(item, description)) { 276 psError(PM_ERR_CONFIG, false, "Unable to read %s %s.", description, item->name); 256 277 psFree(iter); 257 278 return false; 258 279 } 259 260 // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids261 item->type = PS_DATA_METADATA;262 psFree(item->data.str);263 item->data.md = new;264 280 } 265 281 psFree(iter); … … 694 710 } 695 711 psMetadata *camera = cameraItem->data.md; // Camera configuration 712 713 psMetadata *newRule = pmConfigFileRule(config, camera, new); // The rule of interest 714 if (!newRule) { 715 psWarning("Unable to find filerule %s in camera %s --- ignored.", new, cameraItem->name); 716 continue; 717 } 718 719 // By calling pmConfigFileRule, we've assured that the FILERULES is now a metadata 696 720 psMetadata *filerules = psMetadataLookupMetadata(NULL, camera, "FILERULES"); // File rules 697 721 if (!filerules) { … … 700 724 continue; 701 725 } 702 psMetadataItem *newItem = psMetadataLookup(filerules, new); // The rule of interest, or a redir. 703 if (!newItem) { 704 psWarning("Can't find file rule %s in camera %s --- ignored.", new, cameraItem->name); 705 continue; 706 } 707 psMetadata *newRule; // New rule (replacement) 708 switch (newItem->type) { 709 case PS_DATA_STRING: 710 // A redirection 711 newRule = psMetadataLookupMetadata(NULL, filerules, newItem->data.str); 712 break; 713 case PS_DATA_METADATA: 714 // The rule itself 715 newRule = newItem->data.md; 716 break; 717 default: 718 psWarning("Unable to find filerule %s of the correct type in camera %s --- ignored.", 719 new, cameraItem->name); 720 continue; 721 } 726 722 727 psMetadataAddMetadata(filerules, PS_LIST_TAIL, old, PS_META_REPLACE, 723 728 "Original replaced by -F option", newRule); … … 1414 1419 return psStringCopy(filename); 1415 1420 } 1421 1422 psMetadata *pmConfigFileRule(const pmConfig *config, const psMetadata *camera, const char *name) 1423 { 1424 PS_ASSERT_PTR_NON_NULL(config, NULL); 1425 PS_ASSERT_METADATA_NON_NULL(camera, NULL); 1426 PS_ASSERT_STRING_NON_EMPTY(name, NULL); 1427 1428 psMetadataItem *item = psMetadataLookup(camera, "FILERULES"); // Item with the file rule of interest 1429 if (!item) { 1430 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the camera configuration."); 1431 return NULL; 1432 } 1433 1434 if (!metadataItemReadFile(item, "file rules ")) { 1435 psError(PM_ERR_CONFIG, false, "Unable to read file rules for camera."); 1436 return NULL; 1437 } 1438 1439 assert(item->type == PS_DATA_METADATA); 1440 psMetadata *filerules = item->data.md; // File rules from the camera configuration 1441 1442 // select the name from the FILERULES 1443 // check for alias name (type == STR, name is aliased name) 1444 bool mdok; // Status of MD lookup 1445 const char *realname = psMetadataLookupStr(&mdok, filerules, name); // Name of file rule to look up 1446 if (!realname || strlen(realname) == 0) { 1447 realname = name; 1448 } 1449 1450 return psMetadataLookupMetadata(NULL, filerules, realname); 1451 } 1452 -
trunk/psModules/src/config/pmConfig.h
r12916 r15217 1 1 /* @file pmConfig.h 2 2 * @brief Configuration functions 3 * 3 * 4 4 * @author Paul Price, IfA 5 5 * @author Eugene Magnier, IfA 6 * 7 * @version $Revision: 1.3 0$ $Name: not supported by cvs2svn $8 * @date $Date: 2007- 04-19 02:10:12$6 * 7 * @version $Revision: 1.31 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2007-10-04 20:15:48 $ 9 9 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii 10 10 */ … … 56 56 int *argc; ///< Number of command-line arguments 57 57 char **argv; ///< Command-line arguments (raw version) 58 # endif 58 # endif 59 59 } 60 60 pmConfig; … … 110 110 /// configuration. The accepted format is returned. 111 111 psMetadata *pmConfigCameraFormatFromHeader(pmConfig *config, ///< The configuration 112 const psMetadata *header, ///< The FITS header113 bool readRecipes ///< optionally read the recipes as well as the format112 const psMetadata *header, ///< The FITS header 113 bool readRecipes ///< optionally read the recipes as well as the format 114 114 ); 115 115 … … 170 170 ); 171 171 172 /// Get the file rule of interest 173 /// 174 /// Look up the name of the set of file rules to use, get that set from the site configuration, and return the 175 /// appropriate rule from the set. 176 psMetadata *pmConfigFileRule(const pmConfig *config, ///< Configuration 177 const psMetadata *camera, ///< Camera configuration of interest 178 const char *name ///< Name of rule to read 179 ); 180 172 181 /// @} 173 182 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
