#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

# include "ppImage.h"

// this function is mostly equivalent to the top-level of psastro, with some
// modifications since the data has already been loaded.
bool ppImageAstrom (pmConfig *config) {

    bool status;

    // select recipe options supplied on command line
    // XXX move these options to the "PSASTRO" recipe?
    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);

    // find or define a pmFPAfile PSPHOT.INPUT
    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSASTRO.INPUT");
    PS_ASSERT (input, false);

    // convert the output sources created by psphot into astrometry objects
    if (!psastroConvertFPA (input->fpa, recipe)) {
	psError (PSASTRO_ERR_UNKNOWN, false, "error reading input data\n");
	return false;
    }

    if (!psastroAnalysis (config)) {
	psError (PSASTRO_ERR_UNKNOWN, false, "failure in psastro analysis\n");
	return false;
    }

    return true;
}
