# include "psphotDetect.h"

// define the needed / desired I/O files
bool psphotDetectParseCamera (pmConfig *config) {

    bool status = false;

    // if MASK or WEIGHT was supplied on command line, bind files to 'load'
    // the mask and weight will be mosaicked with the image
    pmFPAfile *mask = pmFPAfileDefineFromArgs (&status, config, "PSPHOT.MASK", "MASK");
    if (!status) {
        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
        return NULL;
    }
    if (!psphotSetMaskBits (config)) {
      // XXX shouldn't this come after the file has been read?
        psError (PS_ERR_UNKNOWN, false, "failed to set mask bit values");
        return NULL;
    }
    mask->dataLevel = PM_FPA_LEVEL_CHIP; // force load at the CHIP level

    // the psphot analysis is performed on chips
    pmFPAfile *input = pmFPAfileDefineChipMosaic(config, mask->fpa, "PSPHOT.INPUT");
    if (!input) {
        psError(PSPHOT_ERR_CONFIG, false, _("Unable to generate new file from PSPHOT.INPUT"));
        return NULL;
    }

    // the PSF model is required
    pmFPAfileBindFromArgs(&status, mask, config, "PSPHOT.PSF.LOAD", "PSPHOT.PSF");
    if (!status) {
      psError(PSPHOT_ERR_CONFIG, false, "Failed to find/build PSPHOT.PSF.LOAD");
      return status;
    }

    if (!pmFPAfileDefineFromArgs (&status, config, "PSPHOT.INPUT.PTS", "POINTS")) {
      psError(PSPHOT_ERR_CONFIG, false, "Failed to find/build PSPHOT.INPUT.PTS");
      return status;
    }

    psErrorClear();                     // some metadata lookup may have failed
    return true;
}
