#ifndef PPSTACK_OPTIONS_H
#define PPSTACK_OPTIONS_H

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

/// Options for stacking process
typedef struct {
    // Setup
    bool convolve;                      // Convolve images?
    bool matchZPs;                      // Adjust relative fluxes based on transparency analysis?
    bool photometry;                    // Perform photometry?
    psMetadata *stats;                  // Statistics for output
    FILE *statsFile;                    // File to which to write statistics
    psArray *origImages, *origMasks, *origVariances; // Filenames of the original images
    psArray *convImages, *convMasks, *convVariances; // Filenames for the temporary convolved images
    psArray *origCovars;                // Original covariances matrices
    int num;                            // Number of inputs
    int quality;                        // Bad data quality flag
    // Prepare
    pmPSF *psf;                         // Target PSF
    psVector *inputSeeing;              // Input seeing FWHMs
    float targetSeeing;                 // Target seeing FWHM
    psVector *exposures;                // Exposure times
    float sumExposure;                  // Sum of exposure times
    float zp;                           // Zero point for output
    psVector *inputMask;                // Mask for inputs
    psArray *sourceLists;               // Individual lists of sources for matching
    psVector *norm;                     // Normalisation for each image
    psArray *sources;                   // Matched sources
    // Convolve
    psArray *cells;                     // Cells for convolved images --- a handle for reading again
    psArray *kernels;                   // PSF-matching kernels --- required in the stacking
    psArray *regions;                   // PSF-matching regions --- required in the stacking
    int numCols, numRows;               // Size of image
    psVector *matchChi2;                // chi^2 for stamps from matching
    psVector *weightings;               // Combination weightings for images (1/noise^2)
    psArray *convCovars;                // Convolved covariance matrices
    // Combine initial
    pmReadout *outRO;                   // Output readout
    pmReadout *expRO;                   // Exposure readout
    psArray *inspect;                   // Array of arrays of pixels to inspect
    // Rejection
    psArray *rejected;                  // Rejected pixels
} ppStackOptions;

/// Allocator
ppStackOptions *ppStackOptionsAlloc(void);


#endif
