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

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

        if (!weatherInsertFits(dbh, fits)) {
            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);
        }

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

        if (!skyp_transparencyInsertFits(dbh, fits)) {
            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);
        }

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

        if (!skyp_absorptionInsertFits(dbh, fits)) {
            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);
        }

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

        if (!skyp_emissionInsertFits(dbh, fits)) {
            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);
        }

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

        if (!dimmInsertFits(dbh, fits)) {
            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);
        }

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

        if (!skyp_irInsertFits(dbh, fits)) {
            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);
        }

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

        if (!domeInsertFits(dbh, fits)) {
            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);
        }

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

        if (!telescopeInsertFits(dbh, fits)) {
            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);
        }

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

        if (!summitExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!pzPendingExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!pzPendingImfileInsertFits(dbh, fits)) {
            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);
        }

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

        if (!newExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!newImfileInsertFits(dbh, fits)) {
            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);
        }

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

        if (!rawDetrendExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!rawScienceExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!rawImfileInsertFits(dbh, fits)) {
            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);
        }

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

        if (!p1PendingExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!p2PendingExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!p2PendingImfileInsertFits(dbh, fits)) {
            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);
        }

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

        if (!p2DoneExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!p2DoneImfileInsertFits(dbh, fits)) {
            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);
        }

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

        if (!p3PendingExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!detRunInsertFits(dbh, fits)) {
            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);
        }

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

        if (!detInputExpInsertFits(dbh, fits)) {
            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);
        }

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

        if (!detProcessedImfileInsertFits(dbh, fits)) {
            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);
        }

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

        if (!detStackedImfileInsertFits(dbh, fits)) {
            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);
        }

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

        if (!detNormalizedImfileInsertFits(dbh, fits)) {
            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);
        }

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

        if (!detMasterFrameInsertFits(dbh, fits)) {
            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);
        }

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

        if (!detMasterImfileInsertFits(dbh, fits)) {
            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);
        }

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

        if (!detResidImfileAnalysisInsertFits(dbh, fits)) {
            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);
        }

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

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

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

        psDBCleanup(dbh);
    }

    exit(EXIT_SUCCESS);
}
