#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 (!expTagCounterInsertFits(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 (!summitImfileInsertFits(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 (!pzDoneExpInsertFits(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 (!pzDoneImfileInsertFits(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 (!rawExpInsertFits(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 (!p2ProcessedExpInsertFits(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 (!p2MaskInsertFits(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 (!p2ProcessedImfileInsertFits(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 (!p3ProcessedExpInsertFits(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 (!p3MaskInsertFits(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 (!detProcessedExpInsertFits(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 (!detNormalizedStatImfileInsertFits(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 (!detNormalizedExpInsertFits(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 (!detResidImfileInsertFits(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 (!detResidExpInsertFits(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 (!detRunSummaryInsertFits(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 (!p4aRunInsertFits(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 (!p4aInputExpInsertFits(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 (!p4aScfileInsertFits(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 (!p4bRunInsertFits(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 (!p4bInputScfileInsertFits(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 (!p4bDiffScfileInsertFits(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 (!p4cRunInsertFits(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 (!p4cInputExpInsertFits(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 (!p4MagicMaskImfileInsertFits(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 (!skyCellInsertFits(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 (!skyCellMapInsertFits(dbh, fits)) {
            exit(EXIT_FAILURE);
        }

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

        psDBCleanup(dbh);
    }

    exit(EXIT_SUCCESS);
}
