# include "pswarp.h"

static void usage (void) {
    fprintf (stderr, "USAGE: pswarp [-file image(s)] [-list imagelist] [options] (output) (skycell)\n");
    fprintf (stderr, "  options:\n");
    fprintf (stderr, "    [-astrom astrom.cmp] : provide an alternative astrometry calibration\n");
    fprintf (stderr, "    [-mask mask.fits] : provide a corresponding mask image\n");
    fprintf (stderr, "    [-weight weight.fits] : provide a corresponding weight image (pixel varience)\n");
    psErrorStackPrint(stderr, "\n");
    exit (2);
}

int main (int argc, char **argv)
{
    psTimerStart("pswarp");

    psLibInit(NULL);

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

    pmConfig *config = pswarpArguments(argc, argv);
    if (!config) usage();

    if (!pswarpOptions(config)) {
        psErrorStackPrint(stderr, "error parsing options\n");
        exit(1);
    }

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

    // load the skycell layout information
    if (!pswarpDefine(config)) {
        psErrorStackPrint(stderr, "error loading output definition\n");
        exit (1);
    }

    // load and warp
    if (!pswarpLoop(config)) {
        psErrorStackPrint(stderr, "error warping data\n");
        exit (1);
    }

    psLogMsg("pswarp", 3, "complete pswarp run: %f sec\n", psTimerMark("pswarp"));
    pswarpCleanup(config);
    psLibFinalize();
    exit(EXIT_SUCCESS);
}
