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

#define TMP_FILENAME "./blargh"

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

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    {
        psDB            *dbh;
        psFits          *fits;

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

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

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

        psFree(fits);
        psDBCleanup(dbh);
    }

    exit(EXIT_SUCCESS);
}
