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

#ifndef PP_SUB_H
#define PP_SUB_H

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

/// @addtogroup ppSub
/// @{

#define PPSUB_RECIPE "PPSUB"            /// Name of the recipe to use

/// Setup the arguments parsing
bool ppSubArgumentsSetup(int argc, char *argv[], ///< Command-line arguments
                         pmConfig *config    ///< Configuration
    );

/// Parse the arguments
bool ppSubArgumentsParse(pmConfig *config ///< Configuration
    );

/// Parse the camera input
bool ppSubCamera(pmConfig *config       ///< Configuration
    );

/// Loop over the FPA hierarchy
bool ppSubLoop(pmConfig *config         ///< Configuration
    );

/// Perform PSF-matched image subtraction on the readout
bool ppSubReadout(pmConfig *config,     ///< Configuration
                  psMetadata *stats,    ///< Statistics, for output
                  const pmFPAview *view ///< View of readout to subtract
    );

/// Generate (if needed) and set or update the masks for input and reference images
bool ppSubSetMasks(pmConfig *config,     ///< Configuration
                   const pmFPAview *view ///< View of active readout
    );

/// Generate the PSF-matching kernel and convolve the images as needed.  Most of this function involves
/// looking up the parameters in the recipe and supplying them to the function pmSubtractionMatch()
bool ppSubMatchPSFs(pmConfig *config,    ///< Configuration
                    const pmFPAview *view ///< View of active readout
    );

/// Generate the output readout and pass the kernel info to the header
bool ppSubDefineOutput(pmConfig *config, ///< Configuration
                       const pmFPAview *view ///< View of active readout
    );

/// Photometry stage 1: measure the PSF from the minuend image
bool ppSubMakePSF(pmConfig *config,       ///< Configuration
                  const pmFPAview *view ///< View of active readout
    );

/// Perform the actual image subtraction, update output concepts
bool ppSubReadoutSubtract(pmConfig *config,       ///< Configuration
                          const pmFPAview *view ///< View of active readout
    );


/// Photometry stage 2: find and measure sources on the subtracted image
bool ppSubReadoutPhotometry(pmConfig *config,     ///< Configuration
                            psMetadata *stats,    ///< Statistics, for output
                            const pmFPAview *view ///< View of active readout
    );

/// Renormalize, update headers and generate JPEGs
bool ppSubReadoutUpdate(pmConfig *config, ///< Configuration
                        psMetadata *stats, ///< Statistics for output, or NULL
                        const pmFPAview *view ///< View of active readout
    );

/// Higher-order background subtraction
bool ppSubBackground(pmConfig *config,  ///< Configuration
                     const pmFPAview *view ///< View to readout
    );

/// Put the program version information into a metadata
void ppSubVersionMetadata(psMetadata *metadata ///< Metadata to populate
    );


// Copy every instance of a single keyword from one metadata to another
bool psMetadataCopySingle(psMetadata *target, psMetadata *source, const char *name);

///@}
#endif
