/** @file censorParseCamera.c
 *
 *  @brief
 *
 *  @ingroup censor
 *
 *  @author IfA
 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2009-02-07 02:03:34 $
 *  Copyright 2009 Institute for Astronomy, University of Hawaii
 */

# include "censor.h"

bool censorParseCamera (pmConfig *config) {

    bool status = false;

    // the input image(s) are required arguments; they define the camera
    pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "CENSOR.INPUT", "INPUT");
    if (!status) {
	psError(CENSOR_ERR_CONFIG, false, "Failed to build FPA from CENSOR.INPUT");
	return false;
    }

    bool checkInputOnly = psMetadataLookupBool(&status, config->arguments, "CHECK.INPUT.ONLY");
    if (checkInputOnly) {
        // nothing else to do
        return true;
    }


    pmFPAfile *output = pmFPAfileDefineOutput (config, input->fpa, "CENSOR.OUTPUT");
    if (!output) {
	psError(CENSOR_ERR_CONFIG, false, "Failed to build output FPA from CENSOR.INPUT");
	return false;
    }
    output->save = true;

    // look for the file on the argument list
    pmFPAfile *inMask = pmFPAfileDefineFromArgs  (&status, config, "CENSOR.INPUT.MASK", "INPUT.MASK");
    if (!status) {
	psError (PS_ERR_UNKNOWN, false, "failed to load input mask definition");
	return false;
    }
    if (!inMask) {
	psError (PS_ERR_UNKNOWN, false, "failed to load input mask");
	return false;
    }
    if (inMask->type != PM_FPA_FILE_MASK) {
	psError(PS_ERR_IO, true, "CENSOR.INPUT.MASK is not of type MASK");
	return false;
    }

    psTrace("censor", 1, "Done with censorParseCamera...\n");
    return true;
}
