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

#include <stdio.h>
#include <pslib.h>
#include <psmodules.h>

#define TIMERNAME "PPSTAC"

#include "ppStac.h"

int main(int argc, char *argv[])
{
    psExit status = PS_EXIT_SUCCESS;

    psLibInit(NULL);
    psTimerStart(TIMERNAME);

    // Parse the command-line arguments, open the files
    ppStacOptions *options = ppStacOptionsRead(&argc, argv);
    if (!options) {
        psError(PS_ERR_UNKNOWN, false, "Unable to set program options.\n");
        status = PS_EXIT_CONFIG_ERROR;
        goto die;
    }

    if (!ppStacCombine(options)) {
        psError(PS_ERR_UNKNOWN, false, "Unable to combine images.\n");
        status = PS_EXIT_DATA_ERROR;
        goto die;
    }


    // Common code for the death.
die:
    psFree(options);
    pmConceptsDone();
    pmConfigDone();
    psLibFinalize();

    return status;
}
