# 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
    pmModelGroupInit ();

    // 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 pixel data (from PSPHOT.SOURCES)
    // select subset of stars for astrometry
    if (!psastroDataLoad (config)) {
	psErrorStackPrint(stderr, "error loading input data\n");
	exit (1);
    }

    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);
}
