Changeset 15180 for trunk/psModules/src/camera/pmFPAfileDefine.c
- Timestamp:
- Oct 3, 2007, 11:32:43 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAfileDefine.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAfileDefine.c
r15131 r15180 8 8 #include <pslib.h> 9 9 10 #include "pmErrorCodes.h" 10 11 #include "pmConfig.h" 11 12 #include "pmDetrendDB.h" … … 19 20 #include "pmFPAConstruct.h" 20 21 22 23 // Get the file rule of interest 24 // Look up the name of the set of file rules to use, get that set from the site configuration, and return the 25 // appropriate rule from the set. 26 static psMetadata *getFileRule(const pmConfig *config, // Configuration 27 const psMetadata *camera, // Camera configuration of interest 28 const char *name // Name of rule to read 29 ) 30 { 31 assert(config); 32 assert(config->site); 33 34 psMetadataItem *item = psMetadataLookup(camera, "FILERULES"); // Item with the file rule of interest 35 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 configuration 41 switch (item->type) { 42 case PS_DATA_METADATA: 43 // It's what we're after 44 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 use 48 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 // kids 57 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 FILERULES 70 // check for alias name (type == STR, name is aliased name) 71 bool mdok; // Status of MD lookup 72 const char *realname = psMetadataLookupStr(&mdok, filerules, name); // Name of file rule to look up 73 if (!realname || strlen(realname) == 0) { 74 realname = name; 75 } 76 77 return psMetadataLookupMetadata(NULL, filerules, realname); 78 } 79 80 // Parse an option from a metadata, returning the appropriate integer value 81 static int parseOptionInt(const psMetadata *md, // Metadata containing the option 82 const char *name, // Option name 83 const char *source, // Description of source, for warning messages 84 int defaultValue // Default value 85 ) 86 { 87 psMetadataItem *item = psMetadataLookup(md, name); // Item with the value of interest 88 if (!item) { 89 psWarning("Unable to find value for %s in %s --- set to %d.", name, source, defaultValue); 90 return defaultValue; 91 } 92 int value = psMetadataItemParseS32(item); // Value of interst 93 return value; 94 } 95 96 21 97 // define an input-type pmFPAfile, bind to the optional fpa if supplied 22 98 pmFPAfile *pmFPAfileDefineInput(const pmConfig *config, pmFPA *fpa, const char *name) … … 30 106 char *type; 31 107 32 // select the FILERULES from config->camera 33 psMetadata *filerules = psMetadataLookupPtr (&status, config->camera, "FILERULES"); 34 if (filerules == NULL) { 35 psError(PS_ERR_IO, true, "Can't find FILERULES in the CAMERA configuration!"); 36 return NULL; 37 } 38 39 // select the name from the FILERULES 40 // check for alias name (type == STR, name is aliased name) 41 const char *realname = psMetadataLookupStr (&status, filerules, name); 42 if (!realname || strlen(realname) == 0) { 43 realname = name; 44 } 45 46 psMetadata *data = psMetadataLookupPtr (&status, filerules, realname); 47 if (data == NULL) { 108 const psMetadata *camera = (fpa ? fpa->camera : config->camera); // Camera configuration for this file 109 psMetadata *data = getFileRule(config, camera, name); // File rule 110 if (!data) { 48 111 psError(PS_ERR_IO, true, "Can't find file rule %s!", name); 49 112 return NULL; … … 76 139 file->freeLevel = file->dataLevel; 77 140 78 if (fpa != NULL) {141 if (fpa) { 79 142 file->fpa = psMemIncrRefCounter(fpa); 80 143 file->camera = psMemIncrRefCounter((psMetadata *)fpa->camera); 144 file->cameraName = psMemIncrRefCounter(config->cameraName); // XXX Is this the correct thing to do? 145 } else { 146 file->camera = psMemIncrRefCounter(config->camera); 81 147 file->cameraName = psMemIncrRefCounter(config->cameraName); 82 148 } … … 103 169 { 104 170 bool status; 105 106 // select the FILERULES from the camera config107 psMetadata *filerules = psMetadataLookupPtr(&status, config->camera, "FILERULES");108 if (filerules == NULL) {109 psError(PS_ERR_IO, true, "Can't find FILERULES in the CAMERA configuration!");110 return NULL;111 }112 113 // select the name from the FILERULES114 // check for alias name (type == STR, name is aliased name)115 const char *realname = psMetadataLookupStr(&status, filerules, name);116 if (!realname || strlen(realname) == 0) {117 realname = name;118 }119 120 psMetadata *data = psMetadataLookupPtr (&status, filerules, realname);121 if (data == NULL) {122 psError(PS_ERR_IO, true, "Can't find file rule %s!", name);123 return NULL;124 }125 126 pmFPAfile *file = pmFPAfileAlloc();127 128 // save the name of this pmFPAfile129 file->name = psStringCopy(name);130 131 file->filerule = psMemIncrRefCounter(psMetadataLookupStr(&status, data, "FILENAME.RULE"));132 133 const char *type = psMetadataLookupStr(&status, data, "FILE.TYPE");134 file->type = pmFPAfileTypeFromString(type);135 if (file->type == PM_FPA_FILE_NONE) {136 psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name);137 psFree(file);138 return NULL;139 }140 141 file->mode = PM_FPA_MODE_WRITE;142 file->save = false;143 171 144 172 // Use the camera we were told to, the camera of the provided FPA, or default to the default camera … … 169 197 } 170 198 } 199 200 psMetadata *data = getFileRule(config, camera, name); // File rule 201 if (!data) { 202 psError(PS_ERR_IO, true, "Can't find file rule %s!", name); 203 return NULL; 204 } 205 206 pmFPAfile *file = pmFPAfileAlloc(); 207 208 // save the name of this pmFPAfile 209 file->name = psStringCopy(name); 210 211 file->filerule = psMemIncrRefCounter(psMetadataLookupStr(&status, data, "FILENAME.RULE")); 212 213 const char *type = psMetadataLookupStr(&status, data, "FILE.TYPE"); 214 file->type = pmFPAfileTypeFromString(type); 215 if (file->type == PM_FPA_FILE_NONE) { 216 psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name); 217 psFree(file); 218 return NULL; 219 } 220 221 file->mode = PM_FPA_MODE_WRITE; 222 file->save = false; 223 224 // Use the camera we were told to, the camera of the provided FPA, or default to the default camera 225 psMetadata *camera; // Camera configuration 226 if (!cameraName || strlen(cameraName) == 0) { 227 if (fpa && fpa->camera) { 228 camera = (psMetadata*)fpa->camera; // Casting away const, so I can put it in the file 229 } else { 230 camera = config->camera; 231 cameraName = config->cameraName; 232 } 233 } else { 234 bool mdok; // Status of MD lookup 235 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Known cameras 236 if (!mdok || !cameras) { 237 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n"); 238 return NULL; 239 } 240 camera = psMetadataLookupMetadata(&mdok, cameras, cameraName); // Camera configuration of interest 241 if (!mdok || !camera) { 242 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated " 243 "camera configuration %s in site configuration.\n", cameraName); 244 return NULL; 245 } 246 247 if (fpa && fpa->camera && fpa->camera != camera) { 248 psAbort("Camera of bound FPA is not the requested camera --- there is an inconsistency!"); 249 } 250 } 171 251 file->camera = psMemIncrRefCounter(camera); 172 252 file->cameraName = psMemIncrRefCounter(cameraName); … … 175 255 # if (0) 176 256 if (cameraName) { 177 if (!strcmp(cameraName + strlen(cameraName) - 5, "-CHIP")) {178 file->mosaicLevel = PM_FPA_LEVEL_CHIP;179 }180 if (!strcmp(cameraName + strlen(cameraName) - 5, "-FPA")) {181 file->mosaicLevel = PM_FPA_LEVEL_FPA;182 }257 if (!strcmp(cameraName + strlen(cameraName) - 5, "-CHIP")) { 258 file->mosaicLevel = PM_FPA_LEVEL_CHIP; 259 } 260 if (!strcmp(cameraName + strlen(cameraName) - 5, "-FPA")) { 261 file->mosaicLevel = PM_FPA_LEVEL_FPA; 262 } 183 263 } 184 264 # endif … … 209 289 file->fpa = pmFPAConstruct(file->camera); 210 290 } 291 292 // Get FITS output scheme 293 const char *fitsType = psMetadataLookupStr(&status, data, "FITS.TYPE"); // Name of FITS scheme to use 294 if (fitsType && strcasecmp(fitsType, "NONE") != 0) { 295 psMetadata *fitsTypes = psMetadataLookupMetadata(&status, camera, "FITS"); // The FITS schemes 296 if (!fitsTypes) { 297 psWarning("Unable to find FITS in camera configuration --- compression disabled."); 298 goto COMPRESSION_DONE; 299 } 300 psMetadata *scheme = psMetadataLookupMetadata(NULL, fitsTypes, fitsType); // FITS scheme 301 if (!scheme) { 302 psWarning("Unable to find %s in FITS in camera configuration --- compression disabled.", 303 fitsType); 304 goto COMPRESSION_DONE; 305 } 306 const char *typeString = psMetadataLookupStr(NULL, scheme, "COMPRESSION"); // Compression type 307 if (!typeString || strlen(typeString) == 0) { 308 psWarning("Can't find COMPRESSION in FITS scheme %s --- compression disabled.", fitsType); 309 goto COMPRESSION_DONE; 310 } 311 psFitsCompressionType type = psFitsCompressionTypeFromString(typeString); // Compression type enum 312 313 psString source = NULL; // Source of options 314 psStringAppend(&source, "%s in FITS in camera %s", fitsType, cameraName); 315 psVector *tile = psVectorAlloc(3, PS_TYPE_S32); // Tile sizes 316 file->bitpix = parseOptionInt(scheme, "BITPIX", source, 0); // Bits per pixel 317 tile->data.S32[0] = parseOptionInt(scheme, "TILE.X", source, 0); // Tiling in x 318 tile->data.S32[1] = parseOptionInt(scheme, "TILE.Y", source, 1); // Tiling in y 319 tile->data.S32[2] = parseOptionInt(scheme, "TILE.Z", source, 1); // Tiling in z 320 int noise = parseOptionInt(scheme, "NOISE", source, 16); // Noise bits 321 int hscale = parseOptionInt(scheme, "HSCALE", source, 0); // Scaling for HCOMPRESS 322 int hsmooth = parseOptionInt(scheme, "HSMOOTH", source, 0); // Smoothing for HCOMPRESS 323 psFree(source); 324 325 file->compression = psFitsCompressionAlloc(type, tile, noise, hscale, hsmooth); 326 psFree(tile); 327 } 328 COMPRESSION_DONE: 211 329 212 330 file->fileLevel = pmFPAPHULevel(format);
Note:
See TracChangeset
for help on using the changeset viewer.
