#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 (!weatherSelectRowsFits(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 (!skyp_transparencySelectRowsFits(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 (!skyp_absorptionSelectRowsFits(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 (!skyp_emissionSelectRowsFits(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 (!dimmSelectRowsFits(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 (!skyp_irSelectRowsFits(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 (!domeSelectRowsFits(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 (!telescopeSelectRowsFits(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 (!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 (!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 (!rawDetrendExpSelectRowsFits(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 (!rawScienceExpSelectRowsFits(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 (!p2DoneExpSelectRowsFits(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 (!p2DoneImfileSelectRowsFits(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 (!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 (!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 (!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 (!detMasterFrameSelectRowsFits(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 (!detMasterImfileSelectRowsFits(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 (!detResidImfileAnalysisSelectRowsFits(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 (!detResidExpAnalysisSelectRowsFits(dbh, fits, NULL, 1)) {
            exit(EXIT_FAILURE);
        }

        psFree(fits);
        psDBCleanup(dbh);
    }

    exit(EXIT_SUCCESS);
}
