#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 (!p4RunInsertFits(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 (!p4InputImfileInsertFits(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 (!p4WarpedImfileInsertFits(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 (!p4StackedImfileInsertFits(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 (!p4DiffImfileInsertFits(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);
    }

    exit(EXIT_SUCCESS);
}
