IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18036


Ignore:
Timestamp:
Jun 9, 2008, 3:16:36 PM (18 years ago)
Author:
Paul Price
Message:

Was neglecting SKYCELL meta-cameras.

File:
1 edited

Legend:

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

    r18034 r18036  
    7878}
    7979
    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")
     82int 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    }
    9096
    9197    return (nlen - wlen);
     
    9399
    94100// 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;
     101char *cameraBaseName(const char *name   // Name of meta-camera
     102                     )
     103{
    98104    char *answer;
    99105
    100     N = checkEndForWord (name, "-CHIP");
     106    int N = checkEndForWord (name, "-CHIP");
    101107    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");
    108113    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);
    115125    return answer;
    116126}
     
    10141024// if so, return the winning format and the name of the winning format (both allocated here)
    10151025static bool formatFromHeader(bool *status,
    1016                              psMetadata **format, // Format to return
     1026                             psMetadata **format, // Format to return
    10171027                             psString *name, // Name to return
    10181028                             psMetadata *camera, // Camera configuration
     
    10271037    assert(*cameraName);
    10281038
    1029     *status = true;                     // error status
     1039    *status = true;                     // error status
    10301040    bool result = false;                // Did we find the first match?
    10311041
     
    10351045    if (!mdok || !formats) {
    10361046        psError(PS_ERR_UNKNOWN, false, "Unable to find list of FORMATS in camera %s", cameraName);
    1037         *status = false;
     1047        *status = false;
    10381048        return false;
    10391049    }
     
    10411051    if (!metadataReadFiles(formats, "camera format")) {
    10421052        psError(PS_ERR_UNKNOWN, false, "Unable to read cameras formats within camera configuration.\n");
    1043         *status = false;
     1053        *status = false;
    10441054        return false;
    10451055    }
     
    10581068            psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n",
    10591069                     cameraName, formatsItem->name);
    1060             *status = false;
     1070            *status = false;
    10611071            return false;
    10621072        }
     
    10881098    PS_ASSERT_PTR_NON_NULL(header, NULL);
    10891099
    1090     bool status = false;                // error status
     1100    bool status = false;                // error status
    10911101    psMetadata *format = NULL;          // The winning format
    10921102    psString name = NULL;               // Name of the winning format
     
    10941104    // If we don't know what sort of camera we have, we try all that we know
    10951105    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");
    10991109
    11001110        bool mdok;                      // Metadata lookup status
     
    11201130            psMetadata *testCamera = camerasItem->data.md; // Camera to test against what we've got:
    11211131            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) {
     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) {
    11341144                    psError(PS_ERR_IO, false, "Error reading camera config data for %s", camerasItem->name);
    11351145                    return NULL;
    11361146                }
    11371147            }
    1138         } 
     1148        }
    11391149        psFree(camerasIter);
    11401150
    1141         // Done looking at all cameras
     1151        // Done looking at all cameras
    11421152        if (!config->camera) {
    11431153            psError(PS_ERR_IO, false, "Unable to find a camera that matches input FITS header!");
     
    11741184    // try the FPA metaCamera
    11751185    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);
    11851195    }
    11861196
    11871197    // try the CHIP metaCamera
    11881198    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);
    11981221    }
    11991222
    12001223    // try the base name
    12011224    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);
    12091232    }
    12101233
     
    12121235        psError(PS_ERR_IO, true, "Unable to find a format with the specified camera (%s) that matches the "
    12131236                "given header.\n", baseName);
    1214         psFree (baseName);
     1237        psFree (baseName);
    12151238        return NULL;
    12161239    }
    1217    
     1240
    12181241    psFree (name); // winning format name (for metaCamera) returned by formatFromHeader
    12191242
    12201243    psFree (baseName);
    12211244    if (formatName) {
    1222         *formatName = testName;
     1245        *formatName = testName;
    12231246    } else {
    1224         psFree (testName);
     1247        psFree (testName);
    12251248    }
    12261249    if (camera) {
    1227         *camera = psMemIncrRefCounter(testCamera);
    1228     } 
     1250        *camera = psMemIncrRefCounter(testCamera);
     1251    }
    12291252    return format; // we do NOT need to incr ref counter: this is the only copy
    12301253}
Note: See TracChangeset for help on using the changeset viewer.