#ifndef PP_IMAGE_H
#define PP_IMAGE_H

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

#include <stdio.h>
#include <string.h>
#include <strings.h>  // for strcasecmp
#include <unistd.h>   // for unlink
#include "pslib.h"
#include "psmodules.h"
#include "psphot.h"
#include "psastro.h"
#include "ppImageOptions.h"

#define RECIPE_NAME "PPIMAGE"           // Name of the recipe to use
#define TIMERNAME "ppImage"             // Name of timer

// Get the configuration
pmConfig *ppImageArguments(int argc, char **argv);

// Determine what type of camera, and initialise
ppImageOptions *ppImageParseCamera(pmConfig *config);

// Loop over the input
bool ppImageLoop(pmConfig *config, ppImageOptions *options);

// free memory, check for leaks
void ppImageCleanup (pmConfig *config, ppImageOptions *options);

// perform the detrend analysis on the current readout
bool ppImageDetrendReadout (pmConfig *config, ppImageOptions *options, pmFPAview *view);

bool ppImageDetrendBias(pmReadout *inputReadout, pmReadout *bias, pmReadout *dark, ppImageOptions *options);
bool ppImageDetrendMask(pmReadout *input, pmReadout *mask);

bool ppImageDetrendNonLinear(pmReadout *input, ppImageOptions *options);
bool ppImageDetrendNonLinearLookup(pmReadout *input, psMetadataItem *dataItem);
bool ppImageDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem);

bool ppImageRebinChip (pmConfig *config, pmFPAview *view, char *outName);
bool ppImageRebinReadout (pmReadout *output, pmReadout *input, pmFPAfile *outFile);

bool ppImagePhotom (pmConfig *config, pmFPAview *view);
bool ppImageAstrom (pmConfig *config);
bool ppImageAddstar (pmConfig *config);

bool ppImageMosaicChip (pmConfig *config, const ppImageOptions *options, const pmFPAview *view,
                        const char *outFile, const char *inFile);
bool ppImageMosaicFPA (pmConfig *config, const ppImageOptions *options,
                       const char *outFile, const char *inFile);

void ppImageFileCheck (pmConfig *config);

// functions used by ppFocus
pmConfig *ppFocusArguments(int argc, char **argv);
ppImageOptions *ppFocusParseCamera (pmConfig *config, int entry);
bool ppFocusGetFWHM (pmConfig *config, psVector *focus, psVector *fwhm);
bool ppFocusFitFWHM (pmConfig *config, psVector *focus, psVector *fwhm);

void ppFocusDropCamera (pmConfig *config);

bool ppImageDefineFile (pmConfig *config, pmFPA *input, char *filerule, char *argname, pmFPAfileType fileType, pmDetrendType detrendType);

#endif
