#include <pslib.h>
#include <ippdb.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#define TMP_FILENAME "./blargh"

int main ()
{
    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!weatherPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!skyp_transparencyPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!skyp_absorptionPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!skyp_emissionPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!dimmPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!skyp_irPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!domePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!telescopePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!summitExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!pzPendingExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!pzPendingImfilePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!newExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!newImfilePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!rawDetrendExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!rawScienceExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!rawImfilePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!p1PendingExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!p2PendingExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!p2PendingImfilePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!p2DoneExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!p2DoneImfilePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!p3PendingExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!detRunPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!detInputExpPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!detProcessedImfilePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!detStackedImfilePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!detNormalizedImfilePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!detMasterFramePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!detMasterImfilePopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!detResidImfileAnalysisPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

        dbh = psDBInit("localhost", "test", NULL, "test");
        if (!dbh) {
            exit(EXIT_FAILURE);
        }

        // allocate a temp
        fits = psFitsOpen(TMP_FILENAME, "w");
        if (!fits) {
            exit(EXIT_FAILURE);
        }

        if (!detResidExpAnalysisPopFits(dbh, fits, 1)) {
            exit(EXIT_FAILURE);
        }

        if (!psFitsClose(fits)) {
            exit(EXIT_FAILURE);
        }

        psDBCleanup(dbh);
    }

    exit(EXIT_SUCCESS);
}
