IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7589


Ignore:
Timestamp:
Jun 16, 2006, 3:50:43 PM (20 years ago)
Author:
magnier
Message:

updates from day when MHPCC CVS was down

Location:
trunk/psModules/src
Files:
8 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/Makefile.am

    r7487 r7589  
    1818        pmFPA_JPEG.c \
    1919        pmFPAview.c \
    20         pmFPAfile.c
     20        pmFPAfile.c \
     21        pmFPAfileDefine.c \
     22        pmFPAfileIO.c \
     23        pmFPAfileFitsIO.c
    2124
    2225psmoduleincludedir = $(includedir)
     
    3639        pmFPA_JPEG.h \
    3740        pmFPAview.h \
    38         pmFPAfile.h
     41        pmFPAfile.h \
     42        pmFPAfileDefine.h \
     43        pmFPAfileIO.h \
     44        pmFPAfileFitsIO.h
    3945
    4046CLEANFILES = *~
  • trunk/psModules/src/camera/pmFPA.c

    r7278 r7589  
    1212* XXX: Should we implement non-linear cell->chip transforms?
    1313*
    14 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2006-06-02 00:55:22 $
     14*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2006-06-17 01:50:43 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    619619}
    620620
    621 
     621static char *NameNONE = "NONE";
     622static char *NameFPA = "FPA";
     623static char *NameCHIP = "CHIP";
     624static char *NameCELL = "CELL";
     625static char *NameREADOUT = "READOUT";
     626
     627char *pmFPALevelToName(pmFPALevel level)
     628{
     629
     630    switch (level) {
     631    case PM_FPA_LEVEL_NONE:
     632        return NameNONE;
     633    case PM_FPA_LEVEL_FPA:
     634        return NameFPA;
     635    case PM_FPA_LEVEL_CHIP:
     636        return NameCHIP;
     637    case PM_FPA_LEVEL_CELL:
     638        return NameCELL;
     639    case PM_FPA_LEVEL_READOUT:
     640        return NameREADOUT;
     641    default:
     642        psAbort(PS_FILE_LINE, "You can't get here; level = %d", level);
     643    }
     644    return NULL;
     645}
     646
     647pmFPALevel pmFPALevelFromName(const char *name)
     648{
     649    pmFPALevel val;
     650
     651    if (name == NULL) {
     652        val = PM_FPA_LEVEL_NONE;
     653    } else if (!strcasecmp(name, "FPA"))     {
     654        val = PM_FPA_LEVEL_FPA;
     655    } else if (!strcasecmp(name, "CHIP"))    {
     656        val = PM_FPA_LEVEL_CHIP;
     657    } else if (!strcasecmp(name, "CELL"))    {
     658        val = PM_FPA_LEVEL_CELL;
     659    } else if (!strcasecmp(name, "READOUT")) {
     660        val = PM_FPA_LEVEL_READOUT;
     661    } else {
     662        val = PM_FPA_LEVEL_NONE;
     663    }
     664
     665    return val;
     666}
     667
  • trunk/psModules/src/camera/pmFPA.h

    r7284 r7589  
    77*  @author GLG, MHPCC
    88*
    9 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-06-02 02:16:12 $
     9*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-06-17 01:50:43 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    286286
    287287
     288char *pmFPALevelToName(pmFPALevel level);
     289pmFPALevel pmFPALevelFromName(const char *name);
    288290
    289291#endif // #ifndef PM_FPA_H
  • trunk/psModules/src/camera/pmFPAConstruct.c

    r7526 r7589  
    200200
    201201
    202 // Looks up the particular content based on the header
    203 static const char *getContent(psMetadata *fileInfo, // The FILE from the camera format configuration
    204                               psMetadata *contents, // The CONTENTS from the camera format configuration
    205                               psMetadata *header // The (primary) header
     202// Looks up the particular content, based on the chip and cell
     203static const char *getContent(const psMetadata *fileInfo, // The FILE from the camera format configuration
     204                              const psMetadata *contents, // The CONTENTS from the camera format configuration
     205                              const pmChip *chip, // The chip of interest
     206                              const pmCell *cell // The cell of interest
    206207                             )
    207208{
    208209    assert(fileInfo);
    209210    assert(contents);
    210     assert(header);
     211    assert(chip);
    211212
    212213    bool mdok = true;                   // Status of MD lookup
    213     const char *contentHeaders = psMetadataLookupStr(&mdok, fileInfo, "CONTENT"); // Headers for content
    214     if (!mdok || !contentHeaders || strlen(contentHeaders) == 0) {
     214    char *contentKey = psMetadataLookupStr(&mdok, fileInfo, "CONTENT"); // Key for CONTENTS
     215    if (!mdok || !contentKey || strlen(contentKey) == 0) {
    215216        psError(PS_ERR_IO, true, "Unable to find CONTENT in FILE within camera format configuration.\n");
    216217        return NULL;
    217218    }
    218219
    219     psList *keywords = psStringSplit(contentHeaders, " ,;", true); // List of keywords
    220     psListIterator *keywordsIter = psListIteratorAlloc(keywords, PS_LIST_HEAD, false); // Iterator
    221     psString keyword = NULL;        // Keyword, from iteration
    222     psString contentsKey = NULL;    // Key to the CONTENTS menu
    223     bool first = true;              // Is it the first value?
    224     while ((keyword = psListGetAndIncrement(keywordsIter))) {
    225         const char *value = psMetadataLookupStr(&mdok, header, keyword);
    226         if (first) {
    227             psStringAppend(&contentsKey, "%s", value);
    228             first = false;
    229         } else {
    230             psStringAppend(&contentsKey, "_%s", value);
    231         }
    232     }
    233     psFree(keywordsIter);
    234     psFree(keywords);
    235     psTrace(__func__, 5, "Looking up %s in the CONTENTS.\n", contentsKey);
    236     const char *content = psMetadataLookupStr(&mdok, contents, contentsKey);
     220    contentKey = psStringCopy(contentKey); // So that we're not altering something someone else might use...
     221
     222    // Replace some concept names
     223    if (strstr(contentKey, "{CHIP.NAME}")) {
     224        if (!chip) {
     225            psError(PS_ERR_IO, true, "CONTENT in FILE refers to CHIP.NAME, but no chip was provided.\n");
     226            psFree(contentKey);
     227            return NULL;
     228        }
     229        const char *name = psMetadataLookupStr(&mdok, chip->concepts, "CHIP.NAME");
     230        if (mdok && name && strlen(name) > 0) {
     231            contentKey = psStringSubstitute(contentKey, name, "{CHIP.NAME}");
     232        }
     233    }
     234
     235    if (strstr(contentKey, "{CELL.NAME}")) {
     236        if (!chip) {
     237            psError(PS_ERR_IO, true, "CONTENT in FILE refers to CELL.NAME, but no chip was provided.\n");
     238            psFree(contentKey);
     239            return NULL;
     240        }
     241        const char *name = psMetadataLookupStr(&mdok, cell->concepts, "CELL.NAME");
     242        if (mdok && name && strlen(name) > 0) {
     243            contentKey = psStringSubstitute(contentKey, name, "{CELL.NAME}");
     244        }
     245    }
     246
     247    psTrace(__func__, 5, "Looking up %s in the CONTENTS.\n", contentKey);
     248    const char *content = psMetadataLookupStr(&mdok, contents, contentKey);
    237249    if (!mdok || !content || strlen(content) == 0) {
    238         psError(PS_ERR_IO, true, "Unable to find %s in the CONTENTS.\n", contentsKey);
    239         return NULL;
    240     }
    241     psFree(contentsKey);
     250        psFree(contentKey);
     251        psError(PS_ERR_IO, true, "Unable to find %s in the CONTENTS.\n", contentKey);
     252        return NULL;
     253    }
     254
     255    psFree(contentKey);
    242256
    243257    return content;
     
    253267                           pmFPALevel level, // The level at which to add the HDU
    254268                           const char *contents, // The contents line, consisting of a list of chip:cell
    255                            psMetadata *format // Camera format configuration
     269                           const psMetadata *format // Camera format configuration
    256270                          )
    257271{
     
    364378}
    365379
    366 static pmFPALevel hduLevel(psMetadata *format // The camera format configuration
     380static pmFPALevel hduLevel(const psMetadata *format // The camera format configuration
    367381                          )
    368382{
     
    442456}
    443457
    444 bool pmFPAAddSourceFromView(pmFPA *fpa,   // The FPA
    445                             const pmFPAview *phuView, // The view, corresponding to the PHU
    446                             psMetadata *format // Format of file
     458
     459// This is the engine for the pmFPAAddSourceFrom{Header,View} functions
     460// It returns a view corresponding to the PHU
     461static pmFPAview *addSource(pmFPA *fpa,       // The FPA
     462                            const pmFPAview *phuView, // The view corresponding to the PHU, or NULL
     463                            const psMetadata *header, // The PHU header, or NULL
     464                            const psMetadata *format // Format of file
    447465                           )
    448466{
    449     PS_ASSERT_PTR_NON_NULL(fpa, false);
    450     PS_ASSERT_PTR_NON_NULL(phuView, false);
    451     PS_ASSERT_PTR_NON_NULL(format, false);
    452 
    453     // Where does the PHU go?
    454     bool mdok = true;                   // Status of MD lookup
    455     psMetadata *fileInfo = psMetadataLookupMD(&mdok, format, "FILE"); // File information from the format
    456     if (!mdok || !fileInfo) {
    457         psError(PS_ERR_IO, false, "Unable to find FILE information in the camera format configuration.\n");
    458         return false;
    459     }
    460     const char *phuType = psMetadataLookupStr(&mdok, fileInfo, "PHU"); // What is the PHU?
    461     if (!mdok || strlen(phuType) == 0) {
    462         psError(PS_ERR_IO, false, "Unable to find PHU in the FILE information of the camera format.\n");
    463         return false;
    464     }
    465 
    466     // Generate the PHU
    467     pmHDU *phdu = pmHDUAlloc("PHU");    // The primary header data unit
    468     phdu->format = psMemIncrRefCounter(format);
    469 
    470     // Put in the PHU
    471     pmChip *chip = NULL;                // The chip that corresponds to the PHU
    472     pmCell *cell = NULL;                // The cell that corresponds to the PHU
    473     if (strcasecmp(phuType, "FPA") == 0) {
    474         addHDUtoFPA(fpa, phdu);
    475         psFree(phdu);
    476     } else {
    477         psArray *chips = fpa->chips;    // Array of chips
    478         if (phuView->chip < 0 || phuView->chip > chips->n) {
    479             psError(PS_ERR_IO, true, "PHU specified by the camera format requires specification of a "
    480                     "particular chip, which cannot be determined from the view (%d).\n", phuView->chip);
    481             psFree(phdu);
    482             return false;
    483         }
    484         chip = chips->data[phuView->chip];
    485         if (strcasecmp(phuType, "CHIP") == 0) {
    486             addHDUtoChip(chip, phdu);
    487             psFree(phdu);
    488         } else if (strcasecmp(phuType, "CELL") == 0) {
    489             psArray *cells = chip->cells; // Array of cells
    490             if (phuView->cell < 0 || phuView->cell > cells->n) {
    491                 psError(PS_ERR_IO, true, "PHU specified by the camera format requires specification of a "
    492                         "particular cell, which cannot be determined from the view (%d).\n", phuView->cell);
    493                 psFree(phdu);
    494                 return false;
    495             }
    496             addHDUtoCell(cell, phdu);
    497             psFree(phdu);
    498         } else {
    499             psError(PS_ERR_IO, true, "PHU in the camera configuration format is not FPA, CHIP or CELL.\n");
    500             psFree(phdu);
    501             return false;
    502         }
    503     }
    504 
    505     // Put in the extensions
    506     pmFPALevel level = hduLevel(format);// The level for the HDUs to go
    507     if (level == PM_FPA_LEVEL_NONE) {
    508         // No extensions.  We're done unless PHU == FPA, in which case we need to process the contents
    509         if (strcasecmp(phuType, "FPA") == 0) {
    510             const char *content = psMetadataLookupStr(&mdok, format, "CONTENTS"); // Contents of the FITS file
    511             if (!mdok || !content || strlen(content) == 0) {
    512                 psError(PS_ERR_IO, true, "Unable to find CONTENTS of type STR in the camera "
    513                         "format configuration.\n");
    514                 return false;
    515             }
    516             if (processContents(fpa, chip, cell, phdu, level, content, format) < 0) {
    517                 psError(PS_ERR_IO, false, "Error setting contents.\n");
    518                 return false;
    519             }
    520         }
    521         return true;
    522     }
    523     psMetadata *contents = psMetadataLookupMD(&mdok, format, "CONTENTS"); // The contents of the FITS file
    524     if (!mdok || !contents) {
    525         psError(PS_ERR_IO, false, "Unable to find CONTENTS in the camera format configuration.\n");
    526         return false;
    527     }
    528 
    529     psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL); // Iterator
    530     psMetadataItem *contentsItem = NULL;// Item from the contents iteration
    531     while ((contentsItem = psMetadataGetAndIncrement(contentsIter))) {
    532         if (contentsItem->type != PS_DATA_STRING) {
    533             psLogMsg(__func__, PS_LOG_WARN, "Content item %s is not of type STR --- ignored.\n",
    534                      contentsItem->name);
    535             continue;
    536         }
    537         pmHDU *hdu = pmHDUAlloc(contentsItem->name); // HDU to add
    538         hdu->format = psMemIncrRefCounter(format);
    539         const char *content = contentsItem->data.V; // The content data
    540         if (processContents(fpa, chip, cell, hdu, level, content, format) < 0) {
    541             psError(PS_ERR_IO, false, "Error setting contents for %s", contentsItem->name);
    542             psFree(hdu);
    543             psFree(contentsIter);
    544 
    545             return false;
    546         }
    547         psFree(hdu);
    548     }
    549     psFree(contentsIter);
    550 
    551     return true;
    552 }
    553 
    554 
    555 
    556 // Add an input file to the FPA
    557 pmFPAview *pmFPAAddSourceFromHeader(pmFPA *fpa, // The FPA
    558                                     psMetadata *phu, // Primary header of file
    559                                     psMetadata *format // Format of file
    560                                    )
    561 {
    562     PS_ASSERT_PTR_NON_NULL(fpa, NULL);
    563     PS_ASSERT_PTR_NON_NULL(phu, NULL);
    564     PS_ASSERT_PTR_NON_NULL(format, NULL);
     467    assert(fpa);
     468    assert(phuView || header);
     469    assert(format);
    565470
    566471    bool mdok = true;                   // Status from metadata lookups
     
    571476    }
    572477
    573     // Check the name of the FPA
    574     psString newFPAname = phuNameFromHeader("FPA.NAME", fileInfo, phu); // New name for the FPA
    575     if (!newFPAname) {
    576         psError(PS_ERR_IO, true, "Unable to determine FPA.NAME");
    577         return NULL;
    578     }
    579 
    580     // is FPAname already defined, new name must match it
    581     // XXX if not, is it an error?
    582     const char *currentFPAname = psMetadataLookupStr(&mdok, fpa->concepts, "FPA.NAME"); // Current name
    583     if (mdok && currentFPAname && strlen(currentFPAname) > 0 && strcmp(currentFPAname, newFPAname) != 0) {
    584         psLogMsg(__func__, PS_LOG_WARN, "FPA.NAME for new source (%s) doesn't match FPA.NAME for current "
    585                  "fpa (%s).\n", newFPAname, currentFPAname);
    586     }
    587     psMetadataAddStr(fpa->concepts, PS_LIST_HEAD, "FPA.NAME", PS_META_REPLACE, "Name of FPA", newFPAname);
    588     psFree(newFPAname);                 // Drop reference
    589 
    590     // Where does the PHU go?
     478    // At what level does the PHU go?
    591479    const char *phuType = psMetadataLookupStr(&mdok, fileInfo, "PHU"); // What is the PHU?
    592480    if (!mdok || strlen(phuType) == 0) {
     
    594482        return NULL;
    595483    }
     484
     485    // Prepare the PHU to be placed in the camera hierarchy
    596486    pmHDU *phdu = pmHDUAlloc("PHU");    // The primary header data unit
    597     phdu->header = psMemIncrRefCounter(phu);
    598     phdu->format = psMemIncrRefCounter(format);
    599     // Generate the view
    600     pmFPAview *view = pmFPAviewAlloc(0); // The FPA view corresponding to the PHU, to be returned
    601     view->chip = -1;
    602     view->cell = -1;
    603     view->readout = -1;
    604 
    605     // And what are the individual extensions?
     487    // Casting to psPtr to avoide "warning: passing arg 1 of `p_psMemIncrRefCounter' discards qualifiers from
     488    // pointer target type"
     489    phdu->header = psMemIncrRefCounter((const psPtr)header);
     490    phdu->format = psMemIncrRefCounter((const psPtr)format);
     491    pmFPAview *view = pmFPAviewAlloc(0); // View, to be returned
     492    if (phuView) {
     493        // Copy the view, for the case where we're given a header.
     494        *view = *phuView;
     495    }
     496
     497    // And at what level do the individual extensions go?
    606498    const char *extType = psMetadataLookupStr(&mdok, fileInfo, "EXTENSIONS"); // What's in the extns?
    607499    if (!mdok || strlen(extType) == 0) {
     
    611503    }
    612504
    613 
    614     // This is a special case: PHU=FPA and EXTENSIONS=NONE.  The only reason to do this is in the case of
    615     // single CCD imagers, where the entire FPA is in the PHU image.  In this case, the CONTENTS is of type
    616     // STR (rather than METADATA), and has the usual chip:cell.
     505    // Now, there are a few cases:
     506
     507    // 1. PHU=FPA and EXTENSIONS=NONE.  This is a single CCD imager, where the entire FPA is in the PHU image.
     508    // In this case, the CONTENTS is of type STR (rather than METADATA), and has the usual chip:cell:cellType.
     509    //
     510    // 2. PHU=CHIP or PHU=CELL, and EXTENSIONS=NONE.  This is a single chip or cell from a mosaic camera in
     511    // its own file (e.g., Megacam split).  In this case, the CONTENTS is of type METADATA, and consists of a
     512    // menu of choices for the contents of the file.  This is because we need to work out which chip and/or
     513    // cell it comes from.
     514    //
     515    // 3. EXTENSIONS=CHIP or EXTENSIONS=CELL.  This is a mosaic camera, with multiple extensions.  In this
     516    // case, the CONTENTS is of type METADATA, and consists of a list of contents of the file.
     517    //
     518    // In all of the above cases, the contents are specified by chip:cell:cellType triples.  It's just how the
     519    // contents as a *whole* are collected that changes, and what that collection means.
     520    //
     521    // We deal with each of these cases in turn.
     522
     523    // Case 1: PHU=FPA and EXTENSIONS=NONE.  We need to parse the single list of chip:cell:cellType entries.
    617524    if (strcasecmp(phuType, "FPA") == 0 && strcasecmp(extType, "NONE") == 0) {
    618525        const char *contents = psMetadataLookupStr(&mdok, format, "CONTENTS"); // The contents of the file
     
    628535            psFree(phdu);
    629536            psFree(view);
    630 
    631537            return NULL;
    632538        }
    633 
    634539        psFree(phdu);
     540
    635541        return view;
    636542    }
    637543
    638     // In all other cases, the CONTENTS is of type METADATA, and is either a menu if EXTENSIONS=NONE, or
    639     // a list of extensions otherwise.
     544    // In cases 2 and 3, the CONTENTS is of type METADATA, and is either a menu (if EXTENSIONS=NONE), or a
     545    // list of extensions otherwise.
    640546    psMetadata *contents = psMetadataLookupMD(&mdok, format, "CONTENTS"); // The contents of the FITS file
    641547    if (!mdok || !contents) {
     
    649555            }
    650556        }
    651 
     557        psFree(phdu);
    652558        psFree(view);
    653559        return NULL;
    654560    }
    655561
    656     // No extensions --- only have the PHU.  In this case, the CONTENTS is a menu, with CONTENT indicating
    657     // header keywords that provides a key to the CONTENTS menu.
     562    // Case 2: EXTENSIONS=NONE.  We only have the PHU.  The value of CONTENT tells us a header keyword, which
     563    // gives us the key to the CONTENTS menu.  Or, if we've got the view specifying the PHU, we can get the
     564    // chip/cell directly from that.
    658565    if (strcasecmp(extType, "NONE") == 0) {
    659         // We have already dealt with the case PHU=FPA, in a special case, above.
    660         const char *content = getContent(fileInfo, contents, phu); // The content: string of chip:cell pairs
    661 
    662         // Need to look up what chip we have.
    663         psString chipName = phuNameFromHeader("CHIP.NAME", fileInfo, phu);
    664         psTrace(__func__, 5, "This is chip %s\n", chipName);
     566        pmChip *chip = NULL;        // The chip of interest
     567        pmCell *cell = NULL;        // The cell of interest
     568        pmFPALevel level = PM_FPA_LEVEL_NONE; // Level for HDU to be added
     569
     570        if (phuView) {
     571            // We can get the chip/cell from the view
     572            if (phuView->chip != -1 && phuView->chip < fpa->chips->n) {
     573                chip = fpa->chips->data[phuView->chip];
     574                level = PM_FPA_LEVEL_CHIP;
     575                if (phuView->cell != -1) {
     576                    if (phuView->cell < chip->cells->n) {
     577                        cell = chip->cells->data[phuView->cell];
     578                        level = PM_FPA_LEVEL_CELL;
     579                    } else {
     580                        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "PHU view for cell (%d) does not "
     581                                "correspond to camera format.\n", phuView->cell);
     582                        psFree(phdu);
     583                        return NULL;
     584                    }
     585                }
     586            } else {
     587                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "PHU view for chip (%d) does not correspond to "
     588                        "camera format.\n", phuView->chip);
     589                psFree(phdu);
     590                return NULL;
     591            }
     592        } else {
     593            // Need to look up what chip we have.
     594            psString chipName = phuNameFromHeader("CHIP.NAME", fileInfo, header);
     595            psTrace(__func__, 5, "This is chip %s\n", chipName);
     596            int chipNum = pmFPAFindChip(fpa, chipName); // Chip number
     597            if (chipNum == -1) {
     598                psError(PS_ERR_IO, true, "Unable to find chip %s in FPA.\n", chipName);
     599                psFree(phdu);
     600                psFree(view);
     601                return NULL;
     602            }
     603            pmChip *chip = fpa->chips->data[chipNum]; // Chip of interest
     604            view->chip = chipNum;
     605
     606            if (strcasecmp(phuType, "CHIP") == 0) {
     607                level = PM_FPA_LEVEL_CHIP;
     608            } else if (strcasecmp(phuType, "CELL") == 0) {
     609                level = PM_FPA_LEVEL_CELL;
     610                // Need to look up what cell we have.
     611                psString cellName = phuNameFromHeader("CELL.NAME", fileInfo, header);
     612                int cellNum = pmChipFindCell(chip, cellName); // Cell number
     613                if (cellNum == -1) {
     614                    psError(PS_ERR_IO, true, "Unable to find cell %s in chip %s.\n", cellName, chipName);
     615                    psFree(view);
     616                    psFree(phdu);
     617                    return NULL;
     618                }
     619                cell = chip->cells->data[cellNum];
     620                view->cell = cellNum;
     621                psFree(cellName);
     622            } else {
     623                // We have already dealt with the case PHU=FPA, in a special case above, so if we get here
     624                // it's an error.
     625                psError(PS_ERR_IO, true, "PHU is not FPA, CHIP or CELL.\n");
     626                psFree(phdu);
     627                psFree(view);
     628                return NULL;
     629            }
     630            psFree(chipName);
     631        }
     632
     633        const char *content = getContent(fileInfo, contents, chip, cell); // The chip:cell:cellType triples
     634        if (!content || strlen(content) == 0) {
     635            psError(PS_ERR_IO, false, "Unable to get CONTENTS.\n");
     636            psFree(phdu);
     637            psFree(view);
     638            return NULL;
     639        }
     640        if (processContents(fpa, chip, cell, phdu, level, content, format) < 0) {
     641            psError(PS_ERR_IO, false, "Error setting CONTENTS");
     642            psFree(phdu);
     643            psFree(view);
     644            return NULL;
     645        }
     646        psFree(phdu);
     647
     648        return view;
     649    }
     650
     651    // Case 3: EXTENSIONS=CHIP or EXTENSIONS=CELL.  We have extensions that we iterate through.  The CONTENTS
     652    // is a list of extensions.
     653    pmChip *chip = NULL;                // The chip of interest
     654    pmCell *cell = NULL;                // The cell of interest
     655
     656    // First, put in the PHU
     657    if (strcasecmp(phuType, "FPA") == 0) {
     658        addHDUtoFPA(fpa, phdu);
     659    } else {
     660        // Get the chip
     661        psString chipName = phuNameFromHeader("CHIP.NAME", fileInfo, header); // Name of the chip
    665662        int chipNum = pmFPAFindChip(fpa, chipName); // Chip number
    666663        if (chipNum == -1) {
     
    669666            return NULL;
    670667        }
    671         pmChip *chip = fpa->chips->data[chipNum]; // Chip of interest
    672         view->chip = chipNum;
    673 
    674         pmCell *cell = NULL;            // Cell of interest
    675 
    676         pmFPALevel level = PM_FPA_LEVEL_NONE; // Level for HDU to be added
    677         if (strcasecmp(phuType, "CHIP") == 0) {
    678             level = PM_FPA_LEVEL_CHIP;
    679         } else if (strcasecmp(phuType, "CELL") == 0) {
    680             level = PM_FPA_LEVEL_CELL;
    681             // Need to look up what cell we have.
    682             psString cellName = phuNameFromHeader("CELL.NAME", fileInfo, phu);
    683             int cellNum = pmChipFindCell(chip, cellName); // Cell number
    684             if (cellNum == -1) {
    685                 psError(PS_ERR_IO, true, "Unable to find cell %s in chip %s.\n", cellName, chipName);
    686                 psFree(view);
    687                 return NULL;
    688             }
    689             cell = chip->cells->data[cellNum];
    690             view->cell = cellNum;
    691             psFree(cellName);
    692         } else {
    693             psError(PS_ERR_IO, true, "PHU is not FPA, CHIP or CELL.\n");
    694             psFree(view);
    695             return NULL;
    696         }
    697         psFree(chipName);
    698 
    699         if (processContents(fpa, chip, cell, phdu, level, content, format) < 0) {
    700             psError(PS_ERR_IO, false, "Error setting CONTENTS");
    701             psFree(phdu);
    702             psFree(view);
    703             return NULL;
    704         }
    705         psFree(phdu);
    706         return view;
    707     }
    708 
    709 
    710     // From here on, we have extensions that we iterate through.  The CONTENTS is a list of extensions.
    711     pmChip *chip = NULL;                // The chip of interest
    712     pmCell *cell = NULL;                // The cell of interest
    713 
    714     // First, put in the PHU
    715     if (strcasecmp(phuType, "FPA") == 0) {
    716         addHDUtoFPA(fpa, phdu);
    717     } else {
    718         // Get the chip
    719         psString chipName = phuNameFromHeader("CHIP.NAME", fileInfo, phu); // Name of the chip
    720         int chipNum = pmFPAFindChip(fpa, chipName); // Chip number
    721         if (chipNum == -1) {
    722             psError(PS_ERR_IO, true, "Unable to find chip %s in FPA.\n", chipName);
    723             psFree(view);
    724             return NULL;
    725         }
    726668        chip = fpa->chips->data[chipNum]; // The specified chip
    727669        view->chip = chipNum;
     
    730672            addHDUtoChip(chip, phdu);
    731673        } else if (strcasecmp(phuType, "CELL") == 0) {
    732             psString cellName = phuNameFromHeader("CELL.NAME", fileInfo, phu); // Name of the cell
     674            psString cellName = phuNameFromHeader("CELL.NAME", fileInfo, header); // Name of the cell
    733675            int cellNum = pmChipFindCell(chip, cellName); // Cell number
    734676            if (cellNum == -1) {
     
    764706
    765707        pmHDU *hdu = pmHDUAlloc(extName); // The extension
    766         hdu->format = psMemIncrRefCounter(format);
     708        // Casting to avoid "warning: passing arg 1 of `p_psMemIncrRefCounter' discards qualifiers from
     709        // pointer target type"
     710        hdu->format = psMemIncrRefCounter((const psPtr)format);
    767711
    768712        if (processContents(fpa, chip, cell, hdu, level, contentsItem->data.V, format) < 0) {
     
    778722
    779723    if (!pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_DEFAULTS, true, NULL)) {
    780         psError(PS_ERR_UNKNOWN, false, "Unable to read concepts from defaults for FPA %s.  Attempting to "
    781                 "proceed anyway.\n", currentFPAname);
     724        psLogMsg(__func__, PS_LOG_WARN, "Unable to read concepts from defaults for FPA.  Attempting to "
     725                 "proceed anyway.\n");
    782726    }
    783727
    784728    return view;
     729
     730}
     731
     732
     733bool pmFPAAddSourceFromView(pmFPA *fpa,   // The FPA
     734                            const pmFPAview *phuView, // The view, corresponding to the PHU
     735                            const psMetadata *format // Format of file
     736                           )
     737{
     738    PS_ASSERT_PTR_NON_NULL(fpa, false);
     739    PS_ASSERT_PTR_NON_NULL(phuView, false);
     740    PS_ASSERT_PTR_NON_NULL(format, false);
     741
     742    return addSource(fpa, phuView, NULL, format) ? true : false;
     743}
     744
     745
     746
     747// Add an input file to the FPA
     748pmFPAview *pmFPAAddSourceFromHeader(pmFPA *fpa, // The FPA
     749                                    psMetadata *phu, // Primary header of file
     750                                    const psMetadata *format // Format of file
     751                                   )
     752{
     753    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
     754    PS_ASSERT_PTR_NON_NULL(phu, NULL);
     755    PS_ASSERT_PTR_NON_NULL(format, NULL);
     756
     757    bool mdok = true;                   // Status from metadata lookups
     758    psMetadata *fileInfo = psMetadataLookupMD(&mdok, format, "FILE"); // The file information
     759    if (!mdok || !fileInfo) {
     760        psError(PS_ERR_IO, false, "Unable to find FILE in the camera format configuration.\n");
     761        return NULL;
     762    }
     763
     764    // Check the name of the FPA
     765    psString newFPAname = phuNameFromHeader("FPA.NAME", fileInfo, phu); // New name for the FPA
     766    if (!newFPAname) {
     767        psError(PS_ERR_IO, true, "Unable to determine FPA.NAME");
     768        return NULL;
     769    }
     770
     771    // is FPAname already defined, new name must match it; otherwise, warn the user that something potentially
     772    // bad is happening.
     773    const char *currentFPAname = psMetadataLookupStr(&mdok, fpa->concepts, "FPA.NAME"); // Current name
     774    if (mdok && currentFPAname && strlen(currentFPAname) > 0 && strcmp(currentFPAname, newFPAname) != 0) {
     775        psLogMsg(__func__, PS_LOG_WARN, "FPA.NAME for new source (%s) doesn't match FPA.NAME for current "
     776                 "fpa (%s).\n", newFPAname, currentFPAname);
     777    }
     778    psMetadataAddStr(fpa->concepts, PS_LIST_HEAD, "FPA.NAME", PS_META_REPLACE, "Name of FPA", newFPAname);
     779    psFree(newFPAname);                 // Drop reference
     780
     781    return addSource(fpa, NULL, phu, format);
    785782}
    786783
  • trunk/psModules/src/camera/pmFPAConstruct.h

    r7492 r7589  
    1212bool pmFPAAddSourceFromView(pmFPA *fpa,   // The FPA
    1313                            const pmFPAview *phuView, // The view, corresponding to the PHU
    14                             psMetadata *format // Format of file
     14                            const psMetadata *format // Format of file
    1515                           );
    1616
    1717pmFPAview *pmFPAAddSourceFromHeader(pmFPA *fpa, // The FPA
    1818                                    psMetadata *phu, // Primary header of file
    19                                     psMetadata *format // Format of file
     19                                    const psMetadata *format // Format of file
    2020                                   );
    2121
  • trunk/psModules/src/camera/pmFPAWrite.c

    r7530 r7589  
    101101    if ((!pixels && hdu->phu && !hdu->images) || // Data-less PHU
    102102            (pixels && (hdu->images || (!hdu->images && pmHDUGenerateForCell(cell) && hdu->images)))) { // Data
     103        psMetadataPrint (stdout, cell->concepts, 0);
    103104        success &= pmConceptsWriteCell(cell, PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA |
    104105                                       PM_CONCEPT_SOURCE_DEFAULTS, false, NULL);
     
    151152        if (blankSegment || imageSegment) {
    152153            pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | PM_CONCEPT_SOURCE_DEFAULTS;
     154            for (int i = 0; i < chip->cells->n; i++) {
     155                pmCell *cell = chip->cells->data[i];
     156                psMetadataPrint (stdout, cell->concepts, 0);
     157            }
    153158            if (!pmConceptsWriteChip(chip, source, false, true, NULL)) {
    154159                psError(PS_ERR_IO, false, "Unable to write Concepts for Chip.\n");
  • trunk/psModules/src/camera/pmFPAfile.c

    r7529 r7589  
    55#include "pmHDU.h"
    66#include "pmFPA.h"
    7 #include "pmFPAMaskWeight.h"
     7// #include "pmFPAMaskWeight.h"
    88#include "pmFPAConstruct.h"
    99#include "pmFPAview.h"
    1010#include "pmFPAfile.h"
    1111#include "pmFPACopy.h"
    12 #include "pmFPARead.h"
    13 #include "pmFPAWrite.h"
    14 #include "pmPeaks.h"
    15 #include "pmMoments.h"
    16 #include "pmModel.h"
    17 #include "pmSource.h"
    18 #include "pmSourceIO.h"
    19 #include "pmGrowthCurve.h"
    20 #include "pmPSF.h"
    21 #include "pmPSF_IO.h"
    22 #include "pmFPA_JPEG.h"
     12// #include "pmFPARead.h"
     13// #include "pmFPAWrite.h"
     14// #include "pmPeaks.h"
     15// #include "pmMoments.h"
     16// #include "pmModel.h"
     17// #include "pmSource.h"
     18// #include "pmSourceIO.h"
     19// #include "pmGrowthCurve.h"
     20// #include "pmPSF.h"
     21// #include "pmPSF_IO.h"
     22// #include "pmFPA_JPEG.h"
    2323
    2424static void pmFPAfileFree(pmFPAfile *file)
     
    3333    psFree (file->names);
    3434
     35    psFree (file->camera);
    3536    psFree (file->format);
    3637    psFree (file->name);
     
    4849    psFree (file->extname);
    4950
    50     // these are just views ??
    51     // psFree (file->phu);
    52     // psFree (file->header);
    53 
    5451    return;
    5552}
     
    6865    file->names = psMetadataAlloc();
    6966
     67    file->camera = NULL;
    7068    file->format = NULL;
    7169    file->name = NULL;
     
    8684}
    8785
    88 static const char *depthEnumToName(pmFPAdepth depth)
    89 {
    90     const char *val = NULL;
    91 
    92     switch (depth) {
    93     case PM_FPA_DEPTH_NONE:
    94         val = "NONE";
    95         break;
    96     case PM_FPA_DEPTH_FPA:
    97         val = "FPA";
    98         break;
    99     case PM_FPA_DEPTH_CHIP:
    100         val = "CHIP";
    101         break;
    102     case PM_FPA_DEPTH_CELL:
    103         val = "CELL";
    104         break;
    105     case PM_FPA_DEPTH_READOUT:
    106         val = "READOUT";
    107         break;
    108     default:
    109         psAbort(PS_FILE_LINE, "You can't get here; depth = %d", depth);
    110     }
    111 
    112     return val;
    113 }
    114 
    115 static pmFPAdepth depthNameToEnum(const char *name)
    116 {
    117     pmFPAdepth val;
    118 
    119     if (name == NULL) {
    120         val = PM_FPA_DEPTH_NONE;
    121     } else if (!strcasecmp(name, "FPA"))     {
    122         val = PM_FPA_DEPTH_FPA;
    123     } else if (!strcasecmp(name, "CHIP"))    {
    124         val = PM_FPA_DEPTH_CHIP;
    125     } else if (!strcasecmp(name, "CELL"))    {
    126         val = PM_FPA_DEPTH_CELL;
    127     } else if (!strcasecmp(name, "READOUT")) {
    128         val = PM_FPA_DEPTH_READOUT;
    129     } else {
    130         val = PM_FPA_DEPTH_NONE;
    131     }
    132 
    133     return val;
    134 }
    135 
    136 // define a pmFPAfile, bind to the optional fpa if supplied
    137 pmFPAfile *pmFPAfileDefine(psMetadata *files, psMetadata *camera, pmFPA *fpa, char *name)
    138 {
    139     PS_ASSERT_PTR_NON_NULL(files, NULL);
    140     PS_ASSERT_PTR_NON_NULL(camera, NULL);
    141     PS_ASSERT_PTR_NON_NULL(name, NULL);
    142     PS_ASSERT_INT_POSITIVE(strlen(name), NULL);
    143 
    144     bool status;
    145     char *type;
    146 
    147     // select the FILERULES from the camera config
    148     psMetadata *filerules = psMetadataLookupPtr (&status, camera, "FILERULES");
    149     if (filerules == NULL) {
    150         psError(PS_ERR_IO, true, "Can't find FILERULES in the CAMERA configuration!");
    151         return NULL;
    152     }
    153 
    154     // select the name from the FILERULES
    155     // check for alias name (type == STR, name is aliased name)
    156     char *realname = psMetadataLookupStr (&status, filerules, name);
    157     if (!realname || strlen(realname) == 0) {
    158         realname = name;
    159     }
    160 
    161     psMetadata *data = psMetadataLookupPtr (&status, filerules, realname);
    162     if (data == NULL) {
    163         psError(PS_ERR_IO, true, "Can't find file concept %s!", name);
    164         return NULL;
    165     }
    166 
    167     pmFPAfile *file = pmFPAfileAlloc ();
    168 
    169     // save the name of this pmFPAfile
    170     file->name = psStringCopy (name);
    171 
    172     file->filerule = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.RULE"));
    173     file->filextra = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.XTRA"));
    174     file->extrule  = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "EXTNAME.RULE"));
    175     file->extxtra  = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "EXTNAME.XTRA"));
    176 
    177     file->fileDepth = depthNameToEnum(psMetadataLookupStr(&status, data, "FILE.DEPTH"));
    178     if (file->fileDepth == PM_FPA_DEPTH_NONE) {
    179         psError(PS_ERR_IO, true, "FILE.DEPTH is not set for %s\n", name);
    180         return NULL;
    181     }
    182 
    183     file->dataDepth = depthNameToEnum(psMetadataLookupStr (&status, data, "DATA.DEPTH"));
    184     if (file->dataDepth == PM_FPA_DEPTH_NONE) {
    185         psError(PS_ERR_IO, true, "DATA.DEPTH is not set for %s\n", name);
    186         return NULL;
    187     }
    188 
    189     file->type = PM_FPA_FILE_NONE;
    190     type = psMetadataLookupStr (&status, data, "FILE.TYPE");
    191     if (type != NULL) {
    192         if (!strcasecmp (type, "SX"))     {
    193             file->type = PM_FPA_FILE_SX;
    194         }
    195         if (!strcasecmp (type, "OBJ"))     {
    196             file->type = PM_FPA_FILE_OBJ;
    197         }
    198         if (!strcasecmp (type, "CMP"))     {
    199             file->type = PM_FPA_FILE_CMP;
    200         }
    201         if (!strcasecmp (type, "CMF"))     {
    202             file->type = PM_FPA_FILE_CMF;
    203         }
    204         if (!strcasecmp (type, "RAW"))     {
    205             file->type = PM_FPA_FILE_RAW;
    206         }
    207         if (!strcasecmp (type, "IMAGE"))     {
    208             file->type = PM_FPA_FILE_IMAGE;
    209         }
    210         if (!strcasecmp (type, "PSF"))     {
    211             file->type = PM_FPA_FILE_PSF;
    212         }
    213         if (!strcasecmp (type, "JPEG"))     {
    214             file->type = PM_FPA_FILE_JPEG;
    215         }
    216     }
    217     if (file->type == PM_FPA_FILE_NONE) {
    218         psError(PS_ERR_IO, true, "FILE.TYPE is not defined for %s\n", name);
    219         return NULL;
    220     }
    221 
    222     file->mode = PM_FPA_MODE_NONE;
    223     type = psMetadataLookupStr (&status, data, "FILE.MODE");
    224     if (type != NULL) {
    225         if (!strcasecmp (type, "READ"))     {
    226             file->mode = PM_FPA_MODE_READ;
    227         }
    228         if (!strcasecmp (type, "WRITE"))     {
    229             file->mode = PM_FPA_MODE_WRITE;
    230         }
    231     }
    232     if (file->mode == PM_FPA_MODE_NONE) {
    233         psError(PS_ERR_IO, true, "FILE.MODE is not defined for %s\n", name);
    234         return NULL;
    235     }
    236 
    237     if (fpa != NULL) {
    238         file->fpa = psMemIncrRefCounter(fpa);
    239     }
    240 
    241     // for WRITE type of data, the output format needs to be determined
    242     // this is only needed if the output file is not identical in structure to the input
    243     char *formatName = psMetadataLookupStr (&status, data, "FILE.FORMAT");
    244     if (formatName && strcasecmp (formatName, "NONE")) {
    245         psMetadata *formats = psMetadataLookupMD(&status, camera, "FORMATS"); // List of formats
    246         char *formatFile = psMetadataLookupStr (&status, formats, formatName);
    247         if (!formatFile) {
    248             psError(PS_ERR_IO, false, "format %s for %s not defined", formatName, name);
    249             psFree (file);
    250             return NULL;
    251         }
    252         readConfig (&file->format, formatFile, formatName);
    253     }
    254 
    255     psMetadataAddPtr (files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
    256 
    257     // we free this copy of file, but 'files' still has a copy
    258     psFree (file);
    259 
    260     // the returned value is a view into the version on 'files'
    261     return (file);
    262 }
    263 
    264 /*
    265 pmFPAfile *pmFPAfileConstruct (psMetadata *files, psMetadata *format, psMetadata *camera, char *name)
    266 {
    267     pmFPA *fpa = pmFPAConstruct (camera);
    268     pmFPAfile *file = pmFPAfileDefine (files, format, fpa, name);
    269     psFree (fpa);
    270     if (!file) {
    271         psErrorStackPrint(stderr, "file %s not defined\n", name);
    272         return NULL;
    273     }
    274     return file;
    275 }
    276 */
    277 
    278 // open file (if not already opened)
    279 bool pmFPAfileOpen (pmFPAfile *file, const pmFPAview *view)
    280 {
    281     PS_ASSERT_PTR_NON_NULL(file, false);
    282     PS_ASSERT_PTR_NON_NULL(view, false);
    283 
    284     bool status;
    285     char *extra;
    286     char *mode = NULL;
    287     char *readMode = "r";
    288     char *writeMode = "w";
    289 
    290     if (file->state & PM_FPA_STATE_INACTIVE) {
    291         psTrace("pmFPAfile", 6, "skip open for %s, files is inactive", file->name);
    292         return true;
    293     }
    294 
    295     if (file->state == PM_FPA_STATE_OPEN) {
    296         return true;
    297     }
    298 
    299     if (file->mode == PM_FPA_MODE_NONE) {
    300         psError(PS_ERR_IO, true, "File is mode PM_FPA_MODE_NONE");
    301         return false;
    302     }
    303     if (file->mode == PM_FPA_MODE_INTERNAL) {
    304         psError(PS_ERR_IO, true, "File is mode PM_FPA_MODE_INTERNAL");
    305         return false;
    306     }
    307     if (file->mode == PM_FPA_MODE_READ) {
    308         mode = readMode;
    309     }
    310     if (file->mode == PM_FPA_MODE_WRITE) {
    311         mode = writeMode;
    312     }
    313 
    314     // determine the file name
    315     // free a name allocated earlier
    316     psFree (file->filename);
    317     file->filename = pmFPAfileNameFromRule (file->filerule, file, view);
    318     if (file->filename == NULL) {
    319         psError(PS_ERR_IO, true, "Filename is NULL");
    320         return false;
    321     }
    322 
    323     // indirect filenames
    324     if (!strcasecmp (file->filename, "@FILES")) {
    325         psFree (file->filename);
    326         extra = pmFPAfileNameFromRule (file->filextra, file, view);
    327         file->filename = psMetadataLookupStr (&status, file->names, extra);
    328         psFree (extra);
    329         if (file->filename == NULL) {
    330             psError(PS_ERR_IO, true, "filename lookup error (@FILES) for %s : %s\n", file->filextra, extra);
    331             return false;
    332         }
    333         // psMetadataLookupStr just returns a view, file->filename must be protected
    334         psMemIncrRefCounter (file->filename);
    335     }
    336     if (!strcasecmp (file->filename, "@DETDB")) {
    337         psFree (file->filename);
    338         extra = pmFPAfileNameFromRule (file->filextra, file, view);
    339         // file->filename = pmDetrendSelect (extra);
    340         psFree (extra);
    341         if (file->filename == NULL) {
    342             psError(PS_ERR_IO, true, "filename lookup error (@DETBD) for %s : %s\n", file->filextra, extra);
    343             return false;
    344         }
    345         psMemIncrRefCounter (file->filename);
    346     }
    347 
    348     switch (file->type) {
    349         // open the FITS types:
    350     case PM_FPA_FILE_IMAGE:
    351     case PM_FPA_FILE_CMF:
    352         psTrace ("pmFPAfile", 5, "opening %s (type: %d)\n", file->filename, file->type);
    353         file->fits = psFitsOpen (file->filename, mode);
    354         if (file->fits == NULL) {
    355             psError(PS_ERR_IO, false, "error opening file %s\n", file->filename);
    356             return false;
    357         }
    358         file->state = PM_FPA_STATE_OPEN;
    359         break;
    360 
    361         // defer opening TEXT types:
    362     case PM_FPA_FILE_SX:
    363     case PM_FPA_FILE_OBJ:
    364     case PM_FPA_FILE_CMP:
    365     case PM_FPA_FILE_RAW:
    366     case PM_FPA_FILE_PSF:
    367     case PM_FPA_FILE_JPEG:
    368         psTrace ("pmFPAfile", 5, "defer opening %s\n", file->filename);
    369         break;
    370 
    371     default:
    372         psError(PS_ERR_IO, true, "type mismatch for %s : %d\n", file->filename, file->type);
    373         return false;
    374     }
    375     return true;
    376 }
    377 
    378 bool pmFPAfileRead(pmFPAfile *file, const pmFPAview *view)
    379 {
    380     PS_ASSERT_PTR_NON_NULL(file, false);
    381     PS_ASSERT_PTR_NON_NULL(view, false);
    382 
    383     if (file->state & PM_FPA_STATE_INACTIVE) {
    384         psTrace("pmFPAfile", 6, "skip read for %s, files is inactive", file->name);
    385         return true;
    386     }
    387 
    388     if (file->mode != PM_FPA_MODE_READ) {
    389         psTrace("pmFPAfile", 6, "skip read for %s, mode is not READ", file->name);
    390         return true;
    391     }
    392 
    393     // get the current depth
    394     pmFPAdepth depth = pmFPAviewDepth (view);
    395 
    396     // do we need to open this file?
    397     if (depth == file->fileDepth) {
    398         if (!pmFPAfileOpen (file, view)) {
    399             psError(PS_ERR_IO, false, "failed to open file %s", file->name);
    400             return false;
    401         }
    402     }
    403 
    404     // do we need to read this file?
    405     if (depth != file->dataDepth) {
    406         psTrace("pmFPAfile", 6, "skip reading of %s at this depth %s: dataDepth is %s",
    407                 file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
    408         return true;
    409     }
    410 
    411     switch (file->type) {
    412     case PM_FPA_FILE_IMAGE:
    413         if (pmFPAviewReadFitsImage (view, file)) {
    414             psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
    415         } else {
    416             psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
    417             return false;
    418         }
    419         break;
    420 
    421     case PM_FPA_FILE_SX:
    422     case PM_FPA_FILE_RAW:
    423     case PM_FPA_FILE_OBJ:
    424     case PM_FPA_FILE_CMP:
    425     case PM_FPA_FILE_CMF:
    426         pmFPAviewReadObjects (view, file);
    427         psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
    428         break;
    429 
    430     case PM_FPA_FILE_PSF:
    431         pmFPAviewReadPSFmodel (view, file);
    432         psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
    433         break;
    434 
    435     case PM_FPA_FILE_JPEG:
    436         break;
    437 
    438     default:
    439         psError(PS_ERR_IO, true, "warning: type mismatch; saw type %d", file->type);
    440         return false;
    441     }
    442     return true;
    443 }
    444 
    445 bool pmFPAfileFreeData(pmFPAfile *file, const pmFPAview *view)
    446 {
    447     PS_ASSERT_PTR_NON_NULL(file, false);
    448     PS_ASSERT_PTR_NON_NULL(view, false);
    449 
    450     if (file->state & PM_FPA_STATE_INACTIVE) {
    451         psTrace("pmFPAfile", 6, "skip free for %s, files is inactive", file->name);
    452         return true;
    453     }
    454 
    455     // get the current depth
    456     pmFPAdepth depth = pmFPAviewDepth (view);
    457 
    458     // do we need to read this file?
    459     if (depth != file->dataDepth) {
    460         psTrace("pmFPAfile", 6, "skip free of %s at this depth %s: dataDepth is %s",
    461                 file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
    462         return true;
    463     }
    464 
    465     switch (file->type) {
    466     case PM_FPA_FILE_IMAGE:
    467         if (pmFPAviewFreeFitsImage (view, file)) {
    468             psTrace ("pmFPAfile", 5, "freed %s (type: %d)\n", file->filename, file->type);
    469         } else {
    470             psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
    471             return false;
    472         }
    473         break;
    474 
    475     case PM_FPA_FILE_SX:
    476     case PM_FPA_FILE_RAW:
    477     case PM_FPA_FILE_OBJ:
    478     case PM_FPA_FILE_CMP:
    479     case PM_FPA_FILE_CMF:
    480         // pmFPAviewFreeObjects (view, file);
    481         psTrace ("pmFPAfile", 5, "NOT freeing %s (type: %d)\n", file->filename, file->type);
    482         break;
    483 
    484         // XXX not certain what I need to free here
    485     case PM_FPA_FILE_PSF:
    486     case PM_FPA_FILE_JPEG:
    487         break;
    488 
    489     default:
    490         psError(PS_ERR_IO, true, "warning: type mismatch; saw type %d", file->type);
    491         return false;
    492     }
    493     return true;
    494 }
    495 
    496 bool pmFPAfileWrite(pmFPAfile *file, const pmFPAview *view)
    497 {
    498     PS_ASSERT_PTR_NON_NULL(file, false);
    499     PS_ASSERT_PTR_NON_NULL(view, false);
    500 
    501     if (file->state & PM_FPA_STATE_INACTIVE) {
    502         psTrace("pmFPAfile", 6, "skip write for %s, files is inactive", file->name);
    503         return true;
    504     }
    505 
    506     if (file->mode != PM_FPA_MODE_WRITE) {
    507         psTrace("pmFPAfile", 6, "skip write for %s, mode is not WRITE", file->name);
    508         return true;
    509     }
    510 
    511     // get the current depth
    512     pmFPAdepth depth = pmFPAviewDepth (view);
    513 
    514     // do we need to write this file?
    515     if (depth != file->dataDepth) {
    516         psTrace("pmFPAfile", 6, "skip writing of %s at this depth %s: dataDepth is %s",
    517                 file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
    518         return true;
    519     }
    520 
    521     // do we need to open this file?
    522     if (depth >= file->fileDepth) {
    523         if (!pmFPAfileOpen (file, view)) {
    524             psError(PS_ERR_IO, false, "failed to open %s", file->filename);
    525             return false;
    526         }
    527     }
    528 
    529     switch (file->type) {
    530     case PM_FPA_FILE_IMAGE:
    531         pmFPAviewWriteFitsImage (view, file);
    532         psTrace ("pmFPAfile", 5, "wrote image %s (fpa: %p)\n", file->filename, file->fpa);
    533         break;
    534 
    535     case PM_FPA_FILE_SX:
    536     case PM_FPA_FILE_RAW:
    537     case PM_FPA_FILE_OBJ:
    538     case PM_FPA_FILE_CMP:
    539     case PM_FPA_FILE_CMF:
    540         psTrace ("pmFPAfile", 5, "writing object %s (fpa: %p)\n", file->filename, file->fpa);
    541         if (!pmFPAviewWriteObjects (view, file)) {
    542             psError(PS_ERR_IO, false, "Failed to write object %s", file->filename);
    543             return false;
    544         }
    545 
    546         break;
    547 
    548     case PM_FPA_FILE_PSF:
    549         pmFPAviewWritePSFmodel (view, file);
    550         psTrace ("pmFPAfile", 5, "wrote PSF %s (fpa: %p)\n", file->filename, file->fpa);
    551         break;
    552 
    553     case PM_FPA_FILE_JPEG:
    554         pmFPAviewWriteJPEG (view, file);
    555         psTrace ("pmFPAfile", 5, "wrote PSF %s (fpa: %p)\n", file->filename, file->fpa);
    556         break;
    557 
    558     default:
    559         fprintf (stderr, "warning: type mismatch\n");
    560         return false;
    561     }
    562     return true;
    563 }
    564 
    565 // create the data elements (headers, images) appropriate for this view
    566 bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view)
    567 {
    568     PS_ASSERT_PTR_NON_NULL(file, false);
    569     PS_ASSERT_PTR_NON_NULL(view, false);
    570 
    571     // these are not error conditions; these are state tests
    572     if (file->state & PM_FPA_STATE_INACTIVE) {
    573         psTrace("pmFPAfile", 6, "skip create for inactive file %s", file->name);
    574         return true;
    575     }
    576     if (file->mode != PM_FPA_MODE_WRITE) {
    577         psTrace("pmFPAfile", 6, "skip create for non-write file %s", file->name);
    578         return true;
    579     }
    580 
    581     // get the current depth
    582     pmFPAdepth depth = pmFPAviewDepth (view);
    583 
    584     // don't create the file if the src FPA is not defined
    585     if (file->src == NULL) {
    586         psTrace("pmFPAfile", 6, "skip create for FPA without src FPA for %s", file->name);
    587         return true;
    588     }
    589 
    590     // do we need to write this file?
    591     if (depth != file->dataDepth) {
    592         psTrace("pmFPAfile", 6, "skip creation of %s at this depth %s: dataDepth is %s",
    593                 file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
    594         return true;
    595     }
    596 
    597     switch (file->type) {
    598     case PM_FPA_FILE_IMAGE:
    599         /* create a PHU for thie file, if it does not exist */
    600         pmFPAfileCopyStructureView (file->fpa, file->src, file->format, file->xBin, file->yBin, view);
    601         psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->name, file->fpa);
    602         break;
    603 
    604     case PM_FPA_FILE_SX:
    605     case PM_FPA_FILE_RAW:
    606     case PM_FPA_FILE_OBJ:
    607     case PM_FPA_FILE_CMP:
    608     case PM_FPA_FILE_CMF:
    609     case PM_FPA_FILE_PSF:
    610     case PM_FPA_FILE_JPEG:
    611         break;
    612 
    613     default:
    614         psError(PS_ERR_IO, true, "Unsupported type for %s: %d", file->name, file->type);
    615         return false;
    616     }
    617     return true;
    618 }
    619 
    620 bool pmFPAfileClose (pmFPAfile *file, const pmFPAview *view)
    621 {
    622     PS_ASSERT_PTR_NON_NULL(file, false);
    623     PS_ASSERT_PTR_NON_NULL(view, false);
    624 
    625     if (file->state & PM_FPA_STATE_INACTIVE) {
    626         psTrace("pmFPAfile", 6, "skip close for %s, files is inactive", file->name);
    627         return true;
    628     }
    629     if (file->state == PM_FPA_STATE_CLOSED) {
    630         return true;
    631     }
    632 
    633     // is current depth == open depth?
    634     pmFPAdepth depth = pmFPAviewDepth (view);
    635     if (file->fileDepth != depth) {
    636         psTrace("pmFPAfile", 6, "skip closing of %s at this depth %s: dataDepth is %s",
    637                 file->name, depthEnumToName(depth), depthEnumToName(file->dataDepth));
    638         return true;
    639     }
    640 
    641     // check if we are actually open
    642     switch (file->type) {
    643         // check the FITS types
    644     case PM_FPA_FILE_IMAGE:
    645     case PM_FPA_FILE_CMF:
    646         psFitsClose (file->fits);
    647         psTrace ("pmFPAfile", 5, "closing %s (type: %d)\n", file->filename, file->type);
    648         file->fits = NULL;
    649         file->phu = NULL;
    650         file->header = NULL;
    651         file->state = PM_FPA_STATE_CLOSED;
    652         break;
    653 
    654         // ignore the TEXT types
    655     case PM_FPA_FILE_SX:
    656     case PM_FPA_FILE_RAW:
    657     case PM_FPA_FILE_OBJ:
    658     case PM_FPA_FILE_CMP:
    659     case PM_FPA_FILE_PSF:
    660     case PM_FPA_FILE_JPEG:
    661         break;
    662 
    663     default:
    664         psError(PS_ERR_IO, true, "type mismatch: %d", file->type);
    665         return false;
    666     }
    667     return true;
    668 }
    669 
    670 // set the state of the specified pmFPAfile to active (state == true) or inactive
    671 // if name is NULL, set the state for all pmFPAfiles
    672 bool pmFPAfileActivate (psMetadata *files, bool state, char *name)
    673 {
    674     PS_ASSERT_PTR_NON_NULL(files, false);
    675 
    676     if (!name) {
    677         psMetadataItem *item = NULL;
    678         psMetadataIterator *iter = psMetadataIteratorAlloc (files, PS_LIST_HEAD, NULL);
    679         while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    680             pmFPAfile *file = item->data.V;
    681             if (state) {
    682                 file->state &= NOT_U8(PM_FPA_STATE_INACTIVE);
    683             } else {
    684                 file->state |= PM_FPA_STATE_INACTIVE;
    685             }
    686         }
    687         psFree (iter);
    688         return true;
    689     }
    690 
    691     bool status = false;
    692     pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
    693     if (!status) {
    694         psTrace("pmFPAfile", 6, "%s is not a defined IO file", name);
    695         return false;
    696     }
    697     if (!file) {
    698         psError(PS_ERR_IO, true, "file %s is NULL", name);
    699         return false;
    700     }
    701     if (state) {
    702         file->state &= NOT_U8(PM_FPA_STATE_INACTIVE);
    703     } else {
    704         file->state |= PM_FPA_STATE_INACTIVE;
    705     }
    706     return true;
    707 }
    708 
    709 // attempt create, read, write, close, or free pmFPAfiles available in files
    710 // files are automatically opened before they are read
    711 bool pmFPAfileIOChecks (psMetadata *files, const pmFPAview *view, pmFPAfilePlace place)
    712 {
    713     PS_ASSERT_PTR_NON_NULL(files, false);
    714     PS_ASSERT_PTR_NON_NULL(view, false);
    715 
    716     bool status = true;
    717 
    718     // attempt to perform all create, read, write
    719     psMetadataItem *item = NULL;
    720     psMetadataIterator *iter = psMetadataIteratorAlloc (files, PS_LIST_HEAD, NULL);
    721     while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    722         pmFPAfile *file = item->data.V;
    723 
    724         switch (place) {
    725         case PM_FPA_BEFORE:
    726             if (!pmFPAfileRead (file, view)) {
    727                 psError(PS_ERR_IO, false, "failed READ in FPA_BEFORE block for %s", file->name);
    728                 status = false;
    729             }
    730             if (!pmFPAfileCreate(file, view)) {
    731                 psError(PS_ERR_IO, false, "failed CREATE in FPA_BEFORE block for %s", file->name);
    732                 status = false;
    733             }
    734             break;
    735         case PM_FPA_AFTER:
    736             if (!pmFPAfileWrite (file, view)) {
    737                 psError(PS_ERR_IO, false, "failed WRITE in FPA_AFTER block for %s", file->name);
    738                 status = false;
    739             }
    740             if (!pmFPAfileClose(file, view)) {
    741                 psError(PS_ERR_IO, false, "failed CLOSE in FPA_AFTER block for %s", file->name);
    742                 status = false;
    743             }
    744             break;
    745         default:
    746             psAbort(PS_FILE_LINE, "You can't get here");
    747         }
    748     }
    749 
    750     // attempt to free data that is no longer needed
    751     psMetadataIteratorSet (iter, PS_LIST_HEAD);
    752     while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    753         pmFPAfile *file = item->data.V;
    754 
    755         switch (place) {
    756         case PM_FPA_BEFORE:
    757             break;
    758         case PM_FPA_AFTER:
    759             if (!pmFPAfileFreeData(file, view)) {
    760                 psError(PS_ERR_IO, false, "failed FREE in FPA_AFTER block for %s", file->name);
    761                 status = false;
    762             }
    763             break;
    764         default:
    765             psAbort(PS_FILE_LINE, "You can't get here");
    766         }
    767     }
    768     psFree (iter);
    769     return status;
    770 }
    771 
    772 // create a file with the given name, assign it type "INTERNAL", and supply it with an image
    773 // of the requested dimensions. (image only, mask and weight are ignored)
    774 pmReadout *pmFPAfileCreateInternal (psMetadata *files, char *name, int Nx, int Ny, int type)
    775 {
    776     PS_ASSERT_PTR_NON_NULL(files, false);
    777     PS_ASSERT_PTR_NON_NULL(name, false);
    778     PS_ASSERT_INT_POSITIVE(strlen(name), false);
    779 
    780     pmReadout *readout = pmReadoutAlloc(NULL);
    781     readout->image = psImageAlloc(Nx, Ny, type);
    782 
    783     // I want an image from the
    784     pmFPAfile *file = pmFPAfileAlloc();
    785     file->mode = PM_FPA_MODE_INTERNAL;
    786     file->name = psStringCopy (name);
    787 
    788     file->readout = readout;
    789     psMetadataAddPtr(files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);
    790     psFree(file);
    791     // we free this copy of file, but 'files' still has a copy
    792 
    793     return readout;
    794 }
    795 
    796 bool pmFPAfileDropInternal(psMetadata *files, char *name)
    797 {
    798     PS_ASSERT_PTR_NON_NULL(files, false);
    799     PS_ASSERT_PTR_NON_NULL(name, false);
    800     PS_ASSERT_INT_POSITIVE(strlen(name), false);
    801 
    802     bool status = false;
    803 
    804     pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
    805     if (!status) {
    806         psTrace("pmFPAfile", 6, "Internal File %s not in file list", name);
    807         return true;
    808     }
    809     if (file == NULL) {
    810         psError(PS_ERR_IO, true, "file %s is NULL", name);
    811         return false;
    812     }
    813     if (file->mode != PM_FPA_MODE_INTERNAL) {
    814         psTrace("pmFPAfile", 6, "FPA File %s not Internal, not dropping", name);
    815         return true;
    816     }
    817 
    818     psMetadataRemoveKey (files, name);
    819     return true;
    820 }
    821 
    82286// select the readout from the named pmFPAfile; if the named file does not exist,
    82387pmReadout *pmFPAfileThisReadout (psMetadata *files, const pmFPAview *view, const char *name)
     
    844108}
    845109
    846 // given an already-opened fits file, read the components corresponding
    847 // to the specified view
    848 bool pmFPAviewReadFitsImage (const pmFPAview *view, pmFPAfile *file)
    849 {
    850     PS_ASSERT_PTR_NON_NULL(view, false);
    851     PS_ASSERT_PTR_NON_NULL(file, false);
    852 
    853     bool status;
    854     pmFPA *fpa = file->fpa;
    855     psFits *fits = file->fits;
    856 
    857     if (view->chip == -1) {
    858         status = pmFPARead (fpa, fits, NULL);
    859         return status;
    860     }
    861 
    862     if (view->chip >= fpa->chips->n) {
    863         psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %d", view->chip, fpa->chips->n);
    864         return false;
    865     }
    866     pmChip *chip = fpa->chips->data[view->chip];
    867 
    868     if (view->cell == -1) {
    869         status = pmChipRead (chip, fits, NULL);
    870         return status;
    871     }
    872 
    873     if (view->cell >= chip->cells->n) {
    874         psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %d", view->cell, chip->cells->n);
    875         return false;
    876     }
    877     pmCell *cell = chip->cells->data[view->cell];
    878 
    879     if (view->readout == -1) {
    880         status = pmCellRead (cell, fits, NULL);
    881         return status;
    882     }
    883     psError(PS_ERR_UNKNOWN, true, "Returning false");
    884     return false;
    885 
    886     // XXX pmReadoutRead, pmReadoutReadSegement disabled for now
    887     #if 0
    888 
    889     if (view->readout >= cell->readouts->n) {
    890         psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",
    891                 view->readout, cell->readouts->n);
    892         return false;
    893     }
    894     pmReadout *readout = cell->readouts->data[view->readout];
    895 
    896     if (view->nRows == 0) {
    897         pmReadoutRead (readout, fits, NULL);
    898     } else {
    899         pmReadoutReadSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
    900     }
    901     return true;
    902     #endif
    903 }
    904 
    905 // given an already-opened fits file, read the components corresponding
    906 // to the specified view
    907 bool pmFPAviewFreeFitsImage (const pmFPAview *view, pmFPAfile *file)
    908 {
    909     PS_ASSERT_PTR_NON_NULL(view, false);
    910     PS_ASSERT_PTR_NON_NULL(file, false);
    911 
    912     pmFPA *fpa = file->fpa;
    913 
    914     if (view->chip == -1) {
    915         psTrace ("pmFPAfile", 5, "freeing fpa for %s\n", file->filename);
    916         psFree (fpa);
    917         file->fpa = NULL;
    918         return true;
    919     }
    920 
    921     if (view->chip >= fpa->chips->n) {
    922         psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %d", view->chip, fpa->chips->n);
    923         return false;
    924     }
    925     pmChip *chip = fpa->chips->data[view->chip];
    926 
    927     if (view->cell == -1) {
    928         psTrace ("pmFPAfile", 5, "freeing chip %d for %s\n", view->chip, file->filename);
    929         psFree (chip);
    930         fpa->chips->data[view->chip] = NULL;
    931         return true;
    932     }
    933 
    934     if (view->cell >= chip->cells->n) {
    935         psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %d", view->cell, chip->cells->n);
    936         return false;
    937     }
    938     pmCell *cell = chip->cells->data[view->cell];
    939 
    940     if (view->readout == -1) {
    941         psTrace ("pmFPAfile", 5, "freeing cell %d for %s\n", view->cell, file->filename);
    942         psFree (cell);
    943         chip->cells->data[view->cell] = NULL;
    944         return true;
    945     }
    946     psError(PS_ERR_UNKNOWN, true, "Returning false");
    947     return false;
    948 
    949     // XXX pmReadoutRead, pmReadoutReadSegement disabled for now
    950     #if 0
    951 
    952     if (view->readout >= cell->readouts->n) {
    953         psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",
    954                 view->readout, cell->readouts->n);
    955         return false;
    956     }
    957     pmReadout *readout = cell->readouts->data[view->readout];
    958 
    959     if (view->nRows == 0) {
    960         pmReadoutRead (readout, fits, NULL);
    961     } else {
    962         pmReadoutReadSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
    963     }
    964     return true;
    965     #endif
    966 }
    967 
    968 // given an already-opened fits file, write the components corresponding
    969 // to the specified view
    970 bool pmFPAviewWriteFitsImage (const pmFPAview *view, pmFPAfile *file)
    971 {
    972     PS_ASSERT_PTR_NON_NULL(view, false);
    973     PS_ASSERT_PTR_NON_NULL(file, false);
    974 
    975     pmFPA *fpa = file->fpa;
    976     psFits *fits = file->fits;
    977 
    978     // pmFPAWrite takes care of all PHUs as needed
    979     if (view->chip == -1) {
    980         pmFPAWrite(fpa, fits, NULL, true, true);
    981         return true;
    982     }
    983 
    984     if (view->chip >= fpa->chips->n) {
    985         psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %d", view->chip, fpa->chips->n);
    986         return false;
    987     }
    988     pmChip *chip = fpa->chips->data[view->chip];
    989 
    990     // do we need to write out a PHU for this entry?
    991     if (file->phu == NULL) {
    992         pmHDU *hdu = pmFPAviewThisHDU (view, file->fpa);
    993         pmHDU *phu = pmFPAviewThisPHU (view, file->fpa);
    994         // if this hdu is the phu, the write function below will create the phu
    995         if (hdu != phu) {
    996             // we assume that the PHU is just a header
    997             psMetadata *outhead = psMetadataCopy (NULL, phu->header);
    998             psMetadataAdd (outhead, PS_LIST_TAIL, "EXTEND", PS_DATA_BOOL | PS_META_REPLACE, "this file has extensions", true);
    999             psFitsWriteBlank (file->fits, outhead);
    1000             file->phu = phu->header;
    1001             psTrace ("pmFPAfile", 5, "wrote phu %s (type: %d)\n", file->filename, file->type);
    1002             psFree (outhead);
    1003         }
    1004     }
    1005 
    1006     if (view->cell == -1) {
    1007         pmChipWrite (chip, fits, NULL, true, true);
    1008         return true;
    1009     }
    1010 
    1011     if (view->cell >= chip->cells->n) {
    1012         psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %d", view->cell, chip->cells->n);
    1013         return false;
    1014     }
    1015     pmCell *cell = chip->cells->data[view->cell];
    1016 
    1017     if (view->readout == -1) {
    1018         return pmCellWrite (cell, fits, NULL, true);
    1019     }
    1020     psError(PS_ERR_UNKNOWN, true, "Returning false");
    1021     return false;
    1022 
    1023     // XXX disable readout write for now
    1024     #if 0
    1025 
    1026     if (view->readout >= cell->readouts->n) {
    1027         psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",
    1028                 view->readout, cell->readouts->n);
    1029         return false;
    1030     }
    1031     pmReadout *readout = cell->readouts->data[view->readout];
    1032 
    1033     if (view->nRows == 0) {
    1034         pmReadoutWrite (readout, fits, NULL, NULL);
    1035     } else {
    1036         pmReadoutWriteSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);
    1037     }
    1038     return true;
    1039     #endif
    1040 }
    1041 
    1042 // look for the given name on the argument list.
    1043 // returns the file (a view to the one saved on config->files)
    1044 pmFPAfile *pmFPAfileFromArgs (bool *found, pmConfig *config, char *filename, char *argname)
    1045 {
    1046     PS_ASSERT_PTR_NON_NULL(config, false);
    1047     PS_ASSERT_PTR_NON_NULL(filename, false);
    1048     PS_ASSERT_INT_POSITIVE(strlen(filename), false);
    1049     PS_ASSERT_PTR_NON_NULL(argname, false);
    1050     PS_ASSERT_INT_POSITIVE(strlen(argname), false);
    1051 
    1052     bool status;
    1053     pmFPA *fpa = NULL;
    1054     psFits *fits = NULL;
    1055     pmFPAfile *file = NULL;
    1056     psMetadata *phu = NULL;
    1057     psMetadata *format = NULL;
    1058 
    1059     if (*found) {
    1060         return NULL;
    1061     }
    1062 
    1063     // we search the argument data for the named fileset (argname)
    1064     psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
    1065     if (!status) {
    1066         psTrace("pmFPAfile", 5, "Failed to find %s in argument list", argname);
    1067         return NULL;
    1068     }
    1069     if (infiles->n < 1) {
    1070         psError(PS_ERR_IO, false, "Found n == %d files in %s in arguments\n", infiles->n, argname);
    1071         return NULL;
    1072     }
    1073 
    1074     // determine the current format from the header
    1075     // if no camera has been specified, use the first image as a template for the rest.
    1076     fits = psFitsOpen (infiles->data[0], "r");
    1077     phu = psFitsReadHeader (NULL, fits);
    1078     format = pmConfigCameraFormatFromHeader (config, phu);
    1079     psFitsClose (fits);                        // don't close phu; we'll use it below
    1080     if (!format) {
    1081         psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", infiles->data[0]);
    1082         psFree(phu);
    1083         return NULL;
    1084     }
    1085 
    1086     // build the template fpa, set up the basic view
    1087     fpa = pmFPAConstruct (config->camera);
    1088     if (!fpa) {
    1089         psError(PS_ERR_IO, false, "Failed to construct FPA from %s", infiles->data[0]);
    1090         return NULL;
    1091     }
    1092 
    1093     // load the given filerule (from config->camera) and associate it with the fpa
    1094     // the output file is just a view to the file on config->files
    1095     file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
    1096     if (!file) {
    1097         psError(PS_ERR_IO, false, "file %s not defined", filename);
    1098         psFree(phu);
    1099         psFree (fpa);
    1100         psFree (format);
    1101         return NULL;
    1102     }
    1103 
    1104     // this file is (by virtue of being supplied in the argument list) coming from the fileset
    1105     psFree (file->filerule);
    1106     psFree (file->filextra);
    1107 
    1108     // adjust the rules to identify these files in the file->names data
    1109     file->filerule = psStringCopy ("@FILES");
    1110     // XXX this rule does not work in general
    1111     file->filextra = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
    1112 
    1113     // examine the list of input files and validate their cameras
    1114     for (int i = 0; i < infiles->n; i++) {
    1115         if (i > 0) {
    1116             fits = psFitsOpen (infiles->data[i], "r");
    1117             phu = psFitsReadHeader (NULL, fits);
    1118             pmConfigValidateCameraFormat (format, phu);
    1119             psFitsClose (fits);
    1120         }
    1121 
    1122         // set the view to the corresponding entry for this phu
    1123         pmFPAview *view = pmFPAAddSourceFromHeader (fpa, phu, format);
    1124         if (!view) {
    1125             psError(PS_ERR_IO, false, "Failed to set view from file %s", infiles->data[i]);
    1126             psFree(phu);
    1127             psFree (fpa);
    1128             psFree (format);
    1129             return NULL;
    1130         }
    1131 
    1132         // XXX is this the correct psMD to save the filename?
    1133         char *name = pmFPAfileNameFromRule (file->filextra, file, view);
    1134         psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
    1135 
    1136         psFree (view);
    1137         psFree (name);
    1138         psFree (phu);
    1139     }
    1140     psFree (fpa);
    1141     psFree (format);
    1142     *found = true;
    1143 
    1144     return file;
    1145 }
    1146 
    1147 // XXX this this function through, then finish
    1148 #if 0
    1149 // look for the given name on the argument list.
    1150 // returns the file (a view to the one saved on config->files)
    1151 // in this case, each file should correspond to the same view
    1152 // (except at the readout level), of multiple FPAs
    1153 // XXX think this through a bit more:
    1154 //  - do we create multiple input fpas, or assign the same files to the single fpa?
    1155 //  - do we save the multiple pmFPAfiles in the config->files psMD?
    1156 //  - do we save the multiple filenames in the file->names psMD?
    1157 //  - if we have a single FPA and multiple names, we need a method to
    1158 //    turn on a specific name for the I/O actions.  probably true if we
    1159 //    have multiple FPAs as well.
    1160 pmFPAfile *pmFPAfileSetFromArgs (bool *found, pmConfig *config, char *filename, char *argname)
    1161 {
    1162     PS_ASSERT_PTR_NON_NULL(config, false);
    1163     PS_ASSERT_PTR_NON_NULL(filename, false);
    1164     PS_ASSERT_INT_POSITIVE(strlen(filename), false);
    1165     PS_ASSERT_PTR_NON_NULL(argname, false);
    1166     PS_ASSERT_INT_POSITIVE(strlen(argname), false);
    1167 
    1168     bool status;
    1169     pmFPA *fpa = NULL;
    1170     psFits *fits = NULL;
    1171     pmFPAfile *file = NULL;
    1172     psMetadata *phu = NULL;
    1173     psMetadata *format = NULL;
    1174 
    1175     if (*found)
    1176         return NULL;
    1177 
    1178     // we search the argument data for the named fileset (argname)
    1179     psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
    1180     if (!status) {
    1181         return NULL;
    1182     }
    1183     if (infiles->n < 1) {
    1184         return NULL;
    1185     }
    1186 
    1187     // determine the current format from the header
    1188     // if no camera has been specified, use the first image as a template for the rest.
    1189     fits = psFitsOpen (infiles->data[0], "r");
    1190     phu = psFitsReadHeader (NULL, fits);
    1191     format = pmConfigCameraFormatFromHeader (config, phu);
    1192     psFitsClose (fits);
    1193 
    1194     // build the template fpa, set up the basic view
    1195     fpa = pmFPAConstruct (config->camera);
    1196 
    1197     // load the given filerule (from config->camera) and associate it with the fpa
    1198     // the output file is just a view to the file on config->files
    1199     // XXX the filenames placed on config->files should include the seq number
    1200     file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
    1201     if (!file) {
    1202         psError(PS_ERR_IO, false, "file %s not defined", filename);
    1203         psFree (fpa);
    1204         psFree (format);
    1205         return NULL;
    1206     }
    1207 
    1208     // this file is (by virtue of being supplied in the argument list) coming from the fileset
    1209     psFree (file->filerule);
    1210     psFree (file->filextra);
    1211 
    1212     // adjust the rules to identify these files in the file->names data
    1213     file->filerule = psStringCopy ("@FILES");
    1214     // XXX this rule does not work in general
    1215     file->filextra = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
    1216 
    1217     // examine the list of input files and validate their cameras
    1218     for (int i = 0; i < infiles->n; i++) {
    1219         if (i > 0) {
    1220             fits = psFitsOpen (infiles->data[i], "r");
    1221             phu = psFitsReadHeader (NULL, fits);
    1222             pmConfigValidateCameraFormat (format, phu);
    1223             psFitsClose (fits);
    1224         }
    1225 
    1226         // set the view to the corresponding entry for this phu
    1227         pmFPAview *view = pmFPAAddSourceFromHeader (fpa, phu, format);
    1228 
    1229         // XXX is this the correct psMD to save the filename?
    1230         char *name = pmFPAfileNameFromRule (file->filextra, file, view);
    1231         psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
    1232 
    1233         psFree (view);
    1234         psFree (name);
    1235         psFree (phu);
    1236     }
    1237     psFree (fpa);
    1238     psFree (format);
    1239     *found = true;
    1240 
    1241     return file;
    1242 }
    1243 #endif
    1244 
    1245 // create a new output pmFPAfile based on an existing FPA
    1246 pmFPAfile *pmFPAfileFromFPA (pmConfig *config, pmFPA *src, int xBin, int yBin, char *filename)
    1247 {
    1248     PS_ASSERT_PTR_NON_NULL(config, false);
    1249     PS_ASSERT_PTR_NON_NULL(src, false);
    1250     PS_ASSERT_PTR_NON_NULL(filename, false);
    1251     PS_ASSERT_INT_POSITIVE(strlen(filename), false);
    1252 
    1253     // XXX pmFPAConstruct has many leaks (6919)
    1254     pmFPA *fpa = pmFPAConstruct (config->camera);
    1255     pmFPAfile *file = pmFPAfileDefine (config->files, config->camera, fpa, filename);
    1256     if (!file) {
    1257         psErrorStackPrint(stderr, "file %s not defined\n", filename);
    1258         return NULL;
    1259     }
    1260     file->src = src; // inherit output elements from this source pmFPA
    1261     file->xBin = xBin;
    1262     file->yBin = yBin;
    1263 
    1264     psFree (fpa);
    1265     return file;
    1266 }
    1267 
    1268 // look for the given name on the argument list.
    1269 pmFPAfile *pmFPAfileFromConf (bool *found, pmConfig *config, char *filename, pmFPA *input)
    1270 {
    1271     PS_ASSERT_PTR_NON_NULL(config, false);
    1272     PS_ASSERT_PTR_NON_NULL(filename, false);
    1273     PS_ASSERT_INT_POSITIVE(strlen(filename), false);
    1274     PS_ASSERT_PTR_NON_NULL(input, false);
    1275 
    1276     psFits *fits = NULL;
    1277     pmFPAfile *file = NULL;
    1278     psMetadata *phu = NULL;
    1279     psMetadata *format = NULL;
    1280     psArray *infiles = NULL;
    1281 
    1282     if (*found) {
    1283         return NULL;
    1284     }
    1285 
    1286     // a camera config is needed (as source of file rule)
    1287     if (config->camera == NULL) {
    1288         psErrorStackPrint (stderr, "camera is not defined\n");
    1289         return NULL;
    1290     }
    1291 
    1292     // expect @DETDB in the config filerule
    1293     file = pmFPAfileDefine (config->files, config->camera, NULL, filename);
    1294     if (!file) {
    1295         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
    1296         return NULL;
    1297     }
    1298 
    1299     // image names come from the file->name list?
    1300     if (!strcasecmp (file->filerule, "@FILES")) {
    1301         psAbort ("pmFPAfileFromConfig", "programming error");
    1302     }
    1303 
    1304     // image needs to come from the detrend database
    1305     if (!strcasecmp (file->filerule, "@DETDB")) {
    1306         // char *extra = pmFPAfileNameFromRule (file->filextra, file, view);
    1307         // psArray *infiles = pmDetrendSelect (extra, input);
    1308         psAbort ("pmFPAfileFromConfig", "programming error: @DETDB not yet defined");
    1309     } else {
    1310         infiles = psArrayAlloc(1);
    1311         infiles->n = 1;
    1312         infiles->data[0] = psStringCopy (file->filerule);
    1313     }
    1314     if (infiles == NULL) {
    1315         return NULL;
    1316     }
    1317     if (infiles->n < 1) {
    1318         psFree (infiles);
    1319         return NULL;
    1320     }
    1321 
    1322     // determine the current format from the header
    1323     // if no camera has been specified, use the first image as a template for the rest.
    1324     fits = psFitsOpen (infiles->data[0], "r");
    1325     phu = psFitsReadHeader (NULL, fits);
    1326     format = pmConfigCameraFormatFromHeader (config, phu);
    1327     psFitsClose (fits);
    1328 
    1329     // build the template fpa, set up the basic view
    1330     file->fpa = pmFPAConstruct (config->camera);
    1331 
    1332     // this file is (by virtue of being supplied in the argument list) coming from the fileset
    1333     psFree (file->filerule);
    1334     psFree (file->filextra);
    1335 
    1336     // adjust the rules to identify these files in the file->names data
    1337     file->filerule = psStringCopy ("@FILES");
    1338     // XXX this rule does not work in general
    1339     file->filextra = psStringCopy ("{CHIP.NAME}.{CELL.NAME}");
    1340 
    1341     // examine the list of input files and validate their cameras
    1342     for (int i = 0; i < infiles->n; i++) {
    1343         if (i > 0) {
    1344             fits = psFitsOpen (infiles->data[i], "r");
    1345             phu = psFitsReadHeader (NULL, fits);
    1346             pmConfigValidateCameraFormat (format, phu);
    1347             psFitsClose (fits);
    1348         }
    1349 
    1350         // set the view to the corresponding entry for this phu
    1351         pmFPAview *view = pmFPAAddSourceFromHeader (file->fpa, phu, format);
    1352         if (!view) {
    1353             psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
    1354             return NULL;
    1355         }
    1356 
    1357         // XXX is this the correct psMD to save the filename?
    1358         char *name = pmFPAfileNameFromRule (file->filextra, file, view);
    1359         psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
    1360 
    1361         psFree (view);
    1362         psFree (name);
    1363         psFree (phu);
    1364     }
    1365     psFree (format);
    1366     psFree (infiles);
    1367     *found = true;
    1368     return file;
    1369 }
    1370 
     110// XXX reconsider this function name / concept
    1371111bool pmFPAfileAddFileNames (psMetadata *files, char *name, char *value, int mode)
    1372112{
  • trunk/psModules/src/camera/pmFPAfile.h

    r7480 r7589  
    77*  @author EAM, IfA
    88*
    9 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-06-10 03:01:29 $
     9*  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-06-17 01:50:43 $
    1111*
    1212*  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
     
    5858    pmFPAfileState state;  // have we opened the file, etc?
    5959
    60     pmFPAdepth fileDepth;  // what depth in the FPA hierarchy represents a unique file?
    61     pmFPAdepth dataDepth;  // at what depth do we read/write the data segment?
     60    pmFPALevel fileLevel;  // what level in the FPA hierarchy represents a unique file?
     61    pmFPALevel dataLevel;  // at what level do we read/write the data segment?
    6262
    6363    pmFPA *fpa;    // for I/O files, we carry a pointer to the complete fpa
     
    8080    char *extname;   // the current name of an active file extension
    8181
     82    bool save;
     83
    8284    // the following elements are used for WRITE-mode IMAGE-type pmFPAfiles to inform
    8385    // the creation of a new image based on an existing image
     
    8587    int xBin;    // desired binning in x direction
    8688    int yBin;    // desired binning in y direction
     89
     90    psMetadata *camera;
    8791    psMetadata *format;
    8892}
     
    9296pmFPAfile *pmFPAfileAlloc ();
    9397
    94 // load the pmFPAfile information from the camera configuration data
    95 pmFPAfile *pmFPAfileDefine (psMetadata *files, psMetadata *camera, pmFPA *fpa, char *name);
    96 
    97 // load the pmFPAfile information from the camera configuration data, constructing the needed fpa structure
    98 // XXX deprecate this function?
    99 // pmFPAfile *pmFPAfileConstruct (psMetadata *files, psMetadata *format, psMetadata *camera, char *name);
    100 
    101 // open the real file corresponding to the given pmFPAfile appropriate to the current view
    102 bool pmFPAfileOpen (pmFPAfile *file, const pmFPAview *view);
    103 
    104 // read from the real file corresponding to the given pmFPAfile for the current view
    105 bool pmFPAfileRead (pmFPAfile *file, const pmFPAview *view);
    106 
    107 bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view);
    108 
    109 // write to the real file corresponding to the given pmFPAfile for the current view
    110 bool pmFPAfileWrite (pmFPAfile *file, const pmFPAview *view);
    111 
    112 // close the real file corresponding to the given pmFPAfile appropriate to the current view
    113 bool pmFPAfileClose (pmFPAfile *file, const pmFPAview *view);
    114 
    115 // free the data at this level
    116 bool pmFPAfileFreeData(pmFPAfile *file, const pmFPAview *view);
    117 
    118 // set the state of the specified pmFPAfile to active (state == true) or inactive
    119 // if name is NULL, set the state for all pmFPAfiles
    120 bool pmFPAfileActivate (psMetadata *files, bool state, char *name);
    121 
    122 // examine all pmFPAfiles listed in the files and perform the needed I/O operations (open,read,write,close)
    123 bool pmFPAfileIOChecks (psMetadata *files, const pmFPAview *view, pmFPAfilePlace place);
    124 
    125 // return an image corresponding to the current readout, from the specified file.  if the pmFPAfile does not
    126 // exist, construct the image using the given size and type (save it in a pmFPAfile??)
    127 // psImage *pmFPAfileReadoutImage (psMetadata *files, const pmFPAview *view, char *name, int Nx, int Ny, int type);
    128 
    12998// select the readout from the named pmFPAfile; if the named file does not exist,
    13099pmReadout *pmFPAfileThisReadout (psMetadata *files, const pmFPAview *view, const char *name);
    131 
    132 // create a file with the given name, assign it type "INTERNAL", and supply it with an image
    133 // of the requested dimensions. (image only, mask and weight are ignored)
    134 pmReadout *pmFPAfileCreateInternal (psMetadata *files, char *name, int Nx, int Ny, int type);
    135 
    136 // delete the INTERNAL file of the given name (if it exists)
    137 bool pmFPAfileDropInternal (psMetadata *files, char *name);
    138 
    139 // read an image into the current view
    140 bool pmFPAviewReadFitsImage (const pmFPAview *view, pmFPAfile *file);
    141 
    142 // write the components for the specified view
    143 bool pmFPAviewWriteFitsImage (const pmFPAview *view, pmFPAfile *file);
    144 
    145 // free the appropriate image containers
    146 bool pmFPAviewFreeFitsImage (const pmFPAview *view, pmFPAfile *file);
    147 
    148 // look for the given argname on the argument list.  find the give filename from the file rules
    149 pmFPAfile *pmFPAfileFromArgs (bool *found, pmConfig *config, char *filename, char *argname);
    150 
    151 // look for the given argname on the argument list.  find the give filename from the file rules
    152 pmFPAfile *pmFPAfileFromConf (bool *found, pmConfig *config, char *filename, pmFPA *input);
    153 
    154 // create a new output pmFPAfile based on an existing FPA
    155 pmFPAfile *pmFPAfileFromFPA (pmConfig *config, pmFPA *src, int xBin, int yBin, char *filename);
    156100
    157101// add the specified filename info (value) to the files of the given mode using the given reference name
  • trunk/psModules/src/camera/pmFPAview.c

    r7278 r7589  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-06-02 00:55:22 $
     5 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-17 01:50:43 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3838}
    3939
    40 pmFPAdepth pmFPAviewDepth(const pmFPAview *view)
    41 {
    42     PS_ASSERT_PTR_NON_NULL(view, PM_FPA_DEPTH_NONE);
    43 
    44     if (view->chip < 0) {
    45         return PM_FPA_DEPTH_FPA;
    46     }
    47     if (view->cell < 0) {
    48         return PM_FPA_DEPTH_CHIP;
    49     }
    50     if (view->readout < 0) {
    51         return PM_FPA_DEPTH_CELL;
    52     }
    53     return PM_FPA_DEPTH_READOUT;
     40pmFPALevel pmFPAviewLevel(const pmFPAview *view)
     41{
     42    PS_ASSERT_PTR_NON_NULL(view, PM_FPA_LEVEL_NONE);
     43
     44    if (view->chip < 0) {
     45        return PM_FPA_LEVEL_FPA;
     46    }
     47    if (view->cell < 0) {
     48        return PM_FPA_LEVEL_CHIP;
     49    }
     50    if (view->readout < 0) {
     51        return PM_FPA_LEVEL_CELL;
     52    }
     53    return PM_FPA_LEVEL_READOUT;
    5454}
    5555
  • trunk/psModules/src/camera/pmFPAview.h

    r7017 r7589  
    77*  @author EAM, IfA
    88*
    9 *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-05-01 01:55:43 $
     9*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-06-17 01:50:43 $
    1111*
    1212*  Copyright 2004-2005 Institute for Astronomy, University of Hawaii
     
    2020/// @addtogroup AstroImage
    2121/// @{
    22 
    23 // depth of interest
    24 typedef enum {
    25     PM_FPA_DEPTH_NONE,
    26     PM_FPA_DEPTH_FPA,
    27     PM_FPA_DEPTH_CHIP,
    28     PM_FPA_DEPTH_CELL,
    29     PM_FPA_DEPTH_READOUT,
    30 } pmFPAdepth;
    3122
    3223typedef struct
     
    4334pmFPAview *pmFPAviewAlloc (int nRows);
    4435
    45 // determine the current view depth
    46 pmFPAdepth pmFPAviewDepth (const pmFPAview *view);
     36// determine the current view level
     37pmFPALevel pmFPAviewLevel (const pmFPAview *view);
    4738
    4839// return the currently selected chip for this view
  • trunk/psModules/src/config/pmConfig.c

    r7576 r7589  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-06-15 02:24:19 $
     5 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-17 01:50:43 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    332332            // XXX: Only stdout and stderr are provided for now; this section should be
    333333            // expanded in the future to do files, and perhaps even sockets.
    334             if (!!psLogSetDestination(psMessageDestination(argv[argNum]))) {
     334            if (!psLogSetDestination(psMessageDestination(logDest))) {
    335335                psLogMsg(__func__, PS_LOG_WARN, "Unable to set log destination to %s\n", argv[argNum]);
    336336            }
     
    546546    }
    547547    return format;
     548}
     549
     550// Work out what camera we have, based on the FITS header and a set of rules specified in the IPP
     551// configuration; return the camera configuration and format
     552psMetadata *pmConfigCameraByName(
     553    pmConfig *config,                   // The configuration
     554    const char *cameraName   // The camera name header
     555)
     556{
     557    PS_ASSERT_PTR_NON_NULL(cameraName, NULL);
     558    PS_ASSERT_PTR_NON_NULL(config, NULL);
     559
     560    psMetadata *cameras = psMetadataLookupMD(NULL, config->site, "CAMERAS");
     561    if (!cameras) {
     562        psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     563        return NULL;
     564    }
     565
     566    char *cameraPath = psMetadataLookupStr(NULL, cameras, cameraName);
     567    if (!cameraPath) {
     568        psError(PS_ERR_IO, true, "Unable to find requested CAMERA in the configuration.");
     569        return NULL;
     570    }
     571
     572    psMetadata *camera = NULL; // Camera to test against what we've got:
     573
     574    if (!readConfig(&camera, cameraPath, cameraName)) {
     575        psLogMsg(__func__, PS_LOG_WARN, "Trouble reading reading camera configuration %s", cameraName);
     576        psFree(camera);
     577        return NULL;
     578    }
     579
     580    return camera;
    548581}
    549582
  • trunk/psModules/src/config/pmConfig.h

    r7311 r7589  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-06-03 01:02:08 $
     5 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-06-17 01:50:43 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8787
    8888
     89// find the camera given the name
     90psMetadata *pmConfigCameraByName(
     91    pmConfig *config,                   // The configuration
     92    const char *cameraName   // The camera name header
     93);
     94
    8995/** pmConfigRecipeFromCamera
    9096 *
  • trunk/psModules/src/detrend/Makefile.am

    r7287 r7589  
    99        pmMaskBadPixels.c \
    1010        pmNonLinear.c \
    11         pmSubtractBias.c
     11        pmSubtractBias.c \
     12        pmDetrendDB.c
    1213
    1314#       pmSubtractSky.c
     
    2223        pmMaskBadPixels.h \
    2324        pmNonLinear.h \
    24         pmSubtractBias.h
     25        pmSubtractBias.h \
     26        pmDetrendDB.h
    2527
    2628#       pmSubtractSky.c
  • trunk/psModules/src/detrend/pmSubtractBias.c

    r7445 r7589  
    1111 *  @author GLG, MHPCC
    1212 *
    13  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-06-08 22:14:28 $
     13 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-06-17 01:50:43 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    106106    psImage *subImage = sub->image;     // The image to be subtracted
    107107    psImage *subMask  = sub->mask;      // The mask for the subtraction image
     108
     109    int xIpar = psMetadataLookupS32(NULL, in->parent->concepts, "CELL.XPARITY");
     110    int xSpar = psMetadataLookupS32(NULL, sub->parent->concepts, "CELL.XPARITY");
     111    if (xIpar != xSpar) {
     112        psError(PS_ERR_UNKNOWN, true, "images for subtraction do not have the same "
     113                "CELL.XPARITY (%d vs %d).\n    pmSubtractBias must be upgraded to handle this situation\n",
     114                xIpar, xSpar);
     115        return false;
     116    }
     117
     118    int yIpar = psMetadataLookupS32(NULL, in->parent->concepts, "CELL.YPARITY");
     119    int ySpar = psMetadataLookupS32(NULL, sub->parent->concepts, "CELL.YPARITY");
     120    if (yIpar != ySpar) {
     121        psError(PS_ERR_UNKNOWN, true, "images for subtraction do not have the same "
     122                "CELL.YPARITY (%d vs %d).\n    pmSubtractBias must be upgraded to handle this situation\n",
     123                xIpar, xSpar);
     124        return false;
     125    }
    108126
    109127    // Offsets of the cells
     
    293311XXX: The SDRS does not specify type support.  F32 is implemented here.
    294312 *****************************************************************************/
    295 pmReadout *pmSubtractBias(pmReadout *in, pmOverscanOptions *overscanOpts,
    296                           const pmReadout *bias, const pmReadout *dark)
     313bool pmSubtractBias(pmReadout *in, pmOverscanOptions *overscanOpts,
     314                    const pmReadout *bias, const pmReadout *dark)
    297315{
    298316    psTrace(".psModule.pmSubtracBias.pmSubtractBias", 4,
     
    319337                overscanOpts->fitType != PM_FIT_POLY_CHEBY && overscanOpts->fitType != PM_FIT_SPLINE) {
    320338            psError(PS_ERR_UNKNOWN, true, "Invalid fit type (%d).  Returning original image.\n", overscanOpts->fitType);
    321             return(in);
     339            return false;
    322340        }
    323341
     
    349367            if (! p_psGetStatValue(myStats, &reduced)) {
    350368                psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine result from requested statistical operation.  Returning input image.\n");
    351                 return(in);
     369                return false;
    352370            }
    353371            (void)psBinaryOp(image, image, "-", psScalarAlloc((float)reduced, PS_TYPE_F32));
     
    391409                psFree(pixels);
    392410                if (! reduced) {
    393                     return in;
     411                    return false;
    394412                }
    395413
     
    435453                psFree(pixels);
    436454                if (! reduced) {
    437                     return in;
     455                    return false;
    438456                }
    439457
     
    452470    // Bias frame subtraction
    453471    if (bias) {
    454         SubtractFrame(in, bias, 1.0);
     472        if (!SubtractFrame(in, bias, 1.0))
     473            return false;
    455474    }
    456475
     
    459478        float inTime = psMetadataLookupF32(NULL, in->parent->concepts, "CELL.DARKTIME");
    460479        float darkTime = psMetadataLookupF32(NULL, dark->parent->concepts, "CELL.DARKTIME");
    461         SubtractFrame(in, dark, inTime/darkTime);
    462     }
    463 
    464     return in;
    465 }
    466 
    467 
     480        if (!SubtractFrame(in, dark, inTime/darkTime))
     481            return false;
     482    }
     483
     484    return true;
     485}
     486
     487
  • trunk/psModules/src/detrend/pmSubtractBias.h

    r7018 r7589  
    1111 *  @author GLG, MHPCC
    1212 *
    13  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-05-01 01:56:29 $
     13 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-06-17 01:50:43 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6161pmOverscanOptions *pmOverscanOptionsAlloc(bool single, pmFit fitType, unsigned int order, psStats *stat);
    6262
    63 pmReadout *pmSubtractBias(pmReadout *in, pmOverscanOptions *overscanOpts,
    64                           const pmReadout *bias, const pmReadout *dark);
     63bool pmSubtractBias(pmReadout *in, pmOverscanOptions *overscanOpts,
     64                    const pmReadout *bias, const pmReadout *dark);
    6565
    6666#if 0
  • trunk/psModules/src/objects/pmModelGroup.c

    r7478 r7589  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-06-10 02:58:43 $
     8 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-06-17 01:50:43 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    9595void pmModelGroupCleanup (void)
    9696{
    97 
    9897    psFree (models);
     98    models = NULL;
    9999    return;
    100100}
  • trunk/psModules/src/psmodules.h

    r7487 r7589  
    2020#include <pmFPAview.h>
    2121#include <pmFPAfile.h>
     22#include <pmFPAfileDefine.h>
     23#include <pmFPAfileFitsIO.h>
     24#include <pmFPAfileIO.h>
    2225#include <pmFPARead.h>
    2326#include <pmFPAConstruct.h>
     
    3033#include <pmFPA_JPEG.h>
    3134
    32 // the following headers are from psModule:astrom
    33 #include <pmAstrometryObjects.h>
    34 #include <pmAstrometryDistortion.h>
    35 
    3635// the following headers are from psModule:detrend
    3736#include <pmFlatField.h>
     
    4342#include <pmNonLinear.h>
    4443#include <pmSubtractBias.h>
     44#include <pmDetrendDB.h>
    4545// #include <pmSubtractSky.h>
     46
     47// the following headers are from psModule:astrom
     48#include <pmAstrometryObjects.h>
     49#include <pmAstrometryDistortion.h>
    4650
    4751// the following headers are from psModule:imcombine
Note: See TracChangeset for help on using the changeset viewer.