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

# include "psastroStandAlone.h"

static void usage (void) {
    fprintf (stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)\n");
    exit (2);
}

int main (int argc, char **argv) {

    pmConfig *config = NULL;

    psTimerStart ("complete");

    psastroErrorRegister();              // register our error codes/messages

    // model inits are needed in pmSourceIO
    // models defined in psphot/src/models are not available in psastro
    pmModelClassInit ();

    // load configuration information
    config = psastroArguments (argc, argv);
    if (!config) usage ();

    // load identify the data sources
    if (!psastroParseCamera (config)) {
	psErrorStackPrint(stderr, "error setting up the camera\n");
	exit (1);
    }

    // load the raw detection data (using PSPHOT.SOURCES filerule)
    // select subset of stars for astrometry
    if (!psastroDataLoad (config)) {
	psErrorStackPrint(stderr, "error loading input data\n");
	exit (1);
    }

    // run the full astrometry analysis (chip and/or mosaic)
    if (!psastroAnalysis (config)) {
	psErrorStackPrint(stderr, "failure in psastro analysis\n");
	exit (1);
    }
    
    // write out the results
    if (!psastroDataSave (config)) {
	psErrorStackPrint(stderr, "failed to write out data\n");
	exit (1);
    }

    psLogMsg ("psastro", 3, "complete psastro run: %f sec\n", psTimerMark ("complete"));

    psastroCleanup (config);
    exit (EXIT_SUCCESS);
}
