IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17991 for trunk/psModules


Ignore:
Timestamp:
Jun 8, 2008, 2:38:19 PM (18 years ago)
Author:
eugene
Message:

added output format and camera name (to pmConfigCameraFormatFromHeader) so format may be derived from a different metaCamera from the config value

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfig.c

    r17944 r17991  
    7777    return;
    7878}
     79
     80int 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:
     95char *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
    79118
    80119pmConfig *pmConfigAlloc()
     
    9731012
    9741013// 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)
     1015static bool formatFromHeader(bool *status,
     1016                             psMetadata **format, // Format to return
    9761017                             psString *name, // Name to return
    9771018                             psMetadata *camera, // Camera configuration
     
    9861027    assert(*cameraName);
    9871028
     1029    *status = true;                     // error status
    9881030    bool result = false;                // Did we find the first match?
    9891031
     
    9931035    if (!mdok || !formats) {
    9941036        psError(PS_ERR_UNKNOWN, false, "Unable to find list of FORMATS in camera %s", cameraName);
     1037        *status = false;
    9951038        return false;
    9961039    }
     
    9981041    if (!metadataReadFiles(formats, "camera format")) {
    9991042        psError(PS_ERR_UNKNOWN, false, "Unable to read cameras formats within camera configuration.\n");
     1043        *status = false;
    10001044        return false;
    10011045    }
     
    10141058            psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n",
    10151059                     cameraName, formatsItem->name);
     1060            *status = false;
    10161061            return false;
    10171062        }
     
    10301075    }
    10311076    psFree(formatsIter);
     1077    *status = true;
    10321078    return result;
    10331079}
    10341080
    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.
     1085psMetadata *pmConfigCameraFormatFromHeader(psMetadata **camera, psString *formatName, pmConfig *config, const psMetadata *header, bool readRecipes)
    10381086{
    10391087    PS_ASSERT_PTR_NON_NULL(config, NULL);
    10401088    PS_ASSERT_PTR_NON_NULL(header, NULL);
    10411089
     1090    bool status = false;                // error status
    10421091    psMetadata *format = NULL;          // The winning format
    10431092    psString name = NULL;               // Name of the winning format
     
    10451094    // If we don't know what sort of camera we have, we try all that we know
    10461095    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
    10471100        bool mdok;                      // Metadata lookup status
    10481101        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS");
     
    10661119            assert(camerasItem->type == PS_DATA_METADATA); // It should be because we've read it in or deleted
    10671120            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) {
    10851134                    psError(PS_ERR_IO, false, "Error reading camera config data for %s", camerasItem->name);
    10861135                    return NULL;
    10871136                }
    1088                 psFree(error);
    1089             }
    1090         } // Done looking at all cameras
     1137            }
     1138        }
    10911139        psFree(camerasIter);
    10921140
    1093         if (! config->camera) {
     1141        // Done looking at all cameras
     1142        if (!config->camera) {
    10941143            psError(PS_ERR_IO, false, "Unable to find a camera that matches input FITS header!");
    10951144            return NULL;
     
    11041153    }
    11051154
    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) {
    11081212        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);
    11101215        return NULL;
    11111216    }
    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;
    11221221    } else {
    1123         psFree(format);
    1124         psFree(name);
    1125     }
     1222        psFree (testName);
     1223    }
     1224    if (camera) {
     1225        *camera = psMemIncrRefCounter(testCamera);
     1226    }
    11261227    return psMemIncrRefCounter(format);
    11271228}
Note: See TracChangeset for help on using the changeset viewer.