/** @file ppSubReadout.c
 *
 *  @brief
 *
 *  @ingroup ppSub
 *
 *  @author IfA
 *  @version $Revision: 1.113 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2009-02-18 00:31:20 $
 *  Copyright 2009 Institute for Astronomy, University of Hawaii
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <pslib.h>
#include <psmodules.h>

#include "ppSub.h"

bool ppSubReadout(const char *name, bool reverse, ppSubData *data, const pmFPAview *view)
{
    psAssert(data, "Require processing data");
    pmConfig *config = data->config;    // Configuration
    psAssert(config, "Require configuration");

    psAssert(name, "Require name");
    psAssert(view, "Require view");

    if (!ppSubDefineOutput(name, config, data, view)) {
        psError(PS_ERR_UNKNOWN, false, "Unable to define output.");
        return false;
    }

    if (!data->quality && !ppSubMakePSF(name, config, data, view)) {
        psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF.");
        return false;
    }

    if (!ppSubReadoutSubtract(name, reverse, config, view)) {
        psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.");
        return false;
    }

    // Higher order background subtraction using psphot
    if (!ppSubBackground(name, config, view)) {
        psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
        return false;
    }

    if (!data->quality && data->!ppSubReadoutPhotometry(name, config, data, view)) {
        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
        return false;
    }

    if (!ppSubReadoutUpdate(name, config, data, view)) {
        psError(PS_ERR_UNKNOWN, false, "Unable to update.");
        return false;
    }




    return true;
}
