/** @file  pmReadoutCombine.h
 *
 *  This file will contain a module which will combine multiple readout images.
 *
 *  @author GLG, MHPCC
 *
 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2006-01-26 21:10:50 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 *
 */

#if !defined(PM_READOUT_COMBINE_H)
#define PM_READOUT_COMBINE_H

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

#include<stdio.h>
#include<math.h>
#include "pslib.h"
#include "psConstants.h"
#include "pmAstrometry.h"

typedef struct
{
    psStats *stats;
    unsigned int maskVal;
    float fracHigh;
    float fracLow;
    int nKeep;
}
psCombineParams;

psImage *pmReadoutCombine(psImage *output,
                          const psList *inputs,
                          psCombineParams *params,
                          const psVector *zero,
                          const psVector *scale,
                          bool applyZeroScale,
                          float gain,
                          float readnoise);

/**
 *
 * This function measures the robust median at each of the minimum and maximum
 * coordinates and determines the difference and mean of the two values. The size
 * of the box used to make the measurement at each point is specified by the
 * configuration variable FRINGE_SQUARE_RADIUS. From the collection of
 * differences, the robust median is calculated, and returned as part of the
 * fringe statistics. For each fringe point, the values of delta and midValue are
 * also assigned and available to the user on return.
 *
 */
psStats *pmFringeStats(
    psArray *fringePoints,
    psImage *image,
    psMetadata *config
);

typedef struct
{
    psF64 xMin;
    psF64 yMin;
    psF64 xMax;
    psF64 yMax;
    psF64 delta;
    psF64 midValue;
}
pmFringePoint;


/**
 * 
 * The input array fluxLevels consists of Ni vectors, one per mosaic image.
 * Each vector consists of Nj elements, each a measurement of the input
 * flat-field image flux levels. All of these vectors must be constructed with
 * the same number of elements, or the function will return an error. If a chip
 * is missing from a particular image, that element should be set to NaN. The
 * vector chipGains supplies initial guesses for the chip gains. If the vector
 * contains the values 0.0 or NaN for any of the elements, the gain is set to the
 * mean of the valid values. If the vector length does not match the number of
 * chips, an warning is raised, all chip gain guesses will be set to 1.0, and the
 * vector length modified to match the number of chips defined by the supplied
 * fluxLevels. The sourceFlux input vector must be allocated (not NULL), but the
 * routine will set the vector length to the number of source images regardless
 * of the initial state of the vector. All vectors used by this function must be
 * of type PS_DATA_F64.
 * 
 */
bool pmFlatNormalization(
    psVector *sourceFlux,
    psVector *chipGains,
    psArray *fluxLevels
);


#endif
