# include "psphotDetect.h"

static void usage (void) {
    fprintf (stderr, "USAGE: psphotDetect [-mask image(s)] [-masklist masklist] [-psf psfmodel] [-points pointlist] (output)\n");
    exit (PS_EXIT_CONFIG_ERROR);
}

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

    psTimerStart ("complete");
    pmErrorRegister();			// register psModule's error codes/messages
    psphotInit();

    // load command-line arguments, options, and system config data
    pmConfig *config = psphotDetectArguments (argc, argv);
    if (!config) {
	psErrorStackPrint(stderr, "Error reading arguments\n");
	usage ();
    }

    // load input data (config and images (signal, noise, mask)
    if (!psphotDetectParseCamera (config)) {
        psErrorStackPrint(stderr, "Error setting up the camera\n");
        exit (psphotGetExitStatus());
    }

    // call psphot for each readout
    if (!psphotDetectImageLoop (config)) {
        psErrorStackPrint(stderr, "Error in the psphotDetect image loop\n");
        exit (psphotGetExitStatus());
    }

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

    psErrorCode exit_status = psphotGetExitStatus();
    psphotCleanup (config);
    exit (exit_status);
}

// all functions which return to this level must raise one of the top-level error codes if they
// exit with an error.  these error codes are used to specify the program exit status
