IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 27, 2007, 6:38:05 PM (18 years ago)
Author:
eugene
Message:

allowing processChip to accept a metadata or a string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAConstruct.c

    r15652 r15940  
    6666
    6767    psList *values = psStringSplit(string, " ,;", true); // List of the parts
    68 
    69     if (first) {
    70         *first = psArrayAlloc(values->n);
    71     }
    72     if (second) {
    73         *second = psArrayAlloc(values->n);
    74     }
    75     if (third) {
    76         *third = psArrayAlloc(values->n);
    77     }
    78     int num = 0;
     68    int num = values->n; // number of parsed content elements
     69
     70    // extend the arrays if they exist, create new ones if they don't
     71    if (first && !*first) {
     72        *first = psArrayAllocEmpty(values->n);
     73    }
     74    if (second && !*second) {
     75        *second = psArrayAllocEmpty(values->n);
     76    }
     77    if (third && !*third) {
     78        *third = psArrayAllocEmpty(values->n);
     79    }
     80
    7981    psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); // Iterator for values
    8082    psString value = NULL;               // "first:second:third" string
     
    8385        switch (numArrays) {
    8486          case 3:
    85             psArraySet(*third, num, fst->data[2]);
     87            psArrayAdd(*third, 8, fst->data[2]);
    8688          case 2:
    87             psArraySet(*second, num, fst->data[1]);
     89            psArrayAdd(*second, 8, fst->data[1]);
    8890          case 1:
    89             psArraySet(*first, num, fst->data[0]);
     91            psArrayAdd(*first, 8, fst->data[0]);
    9092            break;
    9193        default:
    9294          psAbort("Should never get here.");
    9395        }
    94         num++;
    9596        psFree(fst);
    9697    }
     
    395396// Process a chip, using the cellName:cellType pair
    396397static bool processChip(const psMetadata *format, // Camera format
    397                         const char *chipContents, // Contents of chip, cellName:cellType pairs
     398                        const psMetadataItem *chipContents, // Contents of chip, cellName:cellType pairs (either in a string or a metadata)
    398399                        pmFPA *fpa, // FPA of interest
    399400                        pmChip *chip, // Chip of interest
    400401                        pmFPALevel level, // Level for HDU to go
    401402                        pmHDU *hdu      // HDU to add
    402                         )
     403    )
    403404{
    404405    assert(format);
     
    414415    psArray *cellNames = NULL;      // Cell names
    415416    psArray *cellTypes = NULL;      // Cell types
    416     if (parseContent(&cellNames, &cellTypes, NULL, chipContents) == 0) {
    417         psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    418                 "Unable to parse chip contents (within %s in camera format) as cellName:cellType",
    419                 CHIP_TYPES);
    420         psFree(cellNames);
    421         psFree(cellTypes);
    422         return false;
     417   
     418    int nParsed = 0;
     419
     420    switch (chipContents->type) {
     421      case PS_DATA_STRING: {
     422          nParsed = parseContent(&cellNames, &cellTypes, NULL, chipContents->data.str);
     423          break;
     424      }
     425      case PS_DATA_METADATA: {
     426          psMetadataIterator *iter = psMetadataIteratorAlloc(chipContents->data.md, PS_LIST_HEAD, NULL); // Iterator
     427          psMetadataItem *item;           // Item from iteration
     428          while ((item = psMetadataGetAndIncrement(iter))) {
     429              if (item->type != PS_DATA_STRING) {
     430                  psWarning ("Item %s in camera format chip table is not of type STR.", item->name);
     431                  continue;
     432              }
     433              nParsed += parseContent(&cellNames, &cellTypes, NULL, item->data.str);
     434          }
     435          psFree (iter);
     436          break;
     437      }
     438      default:
     439        psWarning ("Item %s in camera format chip table is not of type STR.", chipContents->name);
     440        break;
     441    }
     442
     443    if (nParsed == 0) {
     444        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
     445                "Unable to parse chip contents (within %s in camera format) as cellName:cellType",
     446                CHIP_TYPES);
     447        psFree(cellNames);
     448        psFree(cellTypes);
     449        return false;
    423450    }
    424451
     
    552579        pmChip *chip = fpa->chips->data[chipNum]; // Chip of interest
    553580
    554         const char *chipContents = psMetadataLookupStr(NULL, chips, chipType); // Contents of chip
     581        const psMetadataItem *chipContents = psMetadataLookup(chips, chipType); // Contents of chip
    555582        psFree(chipType);
    556583        if (!chipContents) {
     
    775802    psMetadataItem *contentItem;        // Content, from iteration
    776803    while ((contentItem = psMetadataGetAndIncrement(contentsIter))) {
    777         if (contentItem->type != PS_DATA_STRING) {
    778             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    779                     "Type for %s (%x) in %s METADATA in camera format is not STR",
    780                     contentItem->name, contentItem->type, TABLE_OF_CONTENTS);
    781             psFree(contentsIter);
    782             return false;
    783         }
    784 
    785         const char *extname = contentItem->name; // Extension name
    786         pmHDU *hdu = pmHDUAlloc(extname); // HDU for this extension
     804        pmHDU *hdu = pmHDUAlloc(contentItem->name); // HDU for this extension
    787805        // Casting to avoid "warning: passing arg 1 of `p_psMemIncrRefCounter' discards qualifiers from
    788806        // pointer target type"
    789807        hdu->format = psMemIncrRefCounter((const psPtr)format);
    790808
    791         if (!processChip(format, contentItem->data.str, fpa, chip, PM_FPA_LEVEL_CELL, hdu)) {
     809        if (!processChip(format, contentItem, fpa, chip, PM_FPA_LEVEL_CELL, hdu)) {
    792810            psError(PS_ERR_UNKNOWN, false, "Unable to process chip\n");
    793811            psFree(hdu);
     
    871889
    872890    // What's in the chip?
    873     psString chipContents = psMetadataLookupStr(NULL, chips, chipType); // Contents of the chip
     891    psMetadataItem *chipContents = psMetadataLookup(chips, chipType); // Contents of the chip
    874892    if (!chipContents) {
    875893        psError(PS_ERR_UNEXPECTED_NULL, false,
Note: See TracChangeset for help on using the changeset viewer.