/* @file  pmFPAview.h
 * @brief Tools to manipulate the FPA structure elements.
 *
 * @author EAM, IfA
 *
 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
 * @date $Date: 2007-01-24 02:54:14 $
 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
 */

#include <pmDetrendDB.h>

/// @addtogroup Camera Camera Layout
/// @{

#ifndef PM_FPA_FILE_DEFINE_H
#define PM_FPA_FILE_DEFINE_H

// load the pmFPAfile information from the camera configuration data
//
// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
// reference count is held by the config->files metadata.
pmFPAfile *pmFPAfileDefineInput (pmConfig *config, pmFPA *fpa, const char *name);

// load the pmFPAfile information from the camera configuration data
//
// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
// reference count is held by the config->files metadata.
pmFPAfile *pmFPAfileDefineOutput (pmConfig *config, pmFPA *fpa, const char *name);

// look for the given argname on the argument list.  find the give filename from the file rules
//
// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
// reference count is held by the config->files metadata.
pmFPAfile *pmFPAfileDefineFromArgs (bool *found, pmConfig *config, const char *filename, const char *argname);

// look for the given argname on the argument list; bind the associated files to the specified
// fpa.  these are, eg, mask or weight images.
// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
// reference count is held by the config->files metadata.
pmFPAfile *pmFPAfileBindFromArgs (bool *found, pmFPAfile *input, pmConfig *config, const char *filename, const char *argname);

// look for the given argname on the argument list.  find the give filename from the file rules
//
// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
// reference count is held by the config->files metadata.
pmFPAfile *pmFPAfileDefineFromConf (bool *found, pmConfig *config, const char *filename);

// look for the given argname on the argument list.  find the give filename from the file rules
//
// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
// reference count is held by the config->files metadata.
pmFPAfile *pmFPAfileDefineFromDetDB (bool *found, pmConfig *config, const char *filename,
                                     pmFPA *input, pmDetrendType type);

// create a new output pmFPAfile based on an existing FPA
//
// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
// reference count is held by the config->files metadata.
pmFPAfile *pmFPAfileDefineFromFPA (pmConfig *config, pmFPA *src, int xBin, int yBin, const char *filename);

// create a new output pmFPAfile based on an existing FPA
// only valid for pmFPAfile->mode == WRITE (or internal?)
//
// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
// reference count is held by the config->files metadata.
pmFPAfile *pmFPAfileDefineNewCamera (pmConfig *config, const char *filename);

/// Create a new output pmFPAfile based upon a chip mosaic of an existing FPA
///
/// The new pmFPAfile is inserted into the config->files metadata, freed and returned; so that the user does
/// not have to (and should not!) free the result.
pmFPAfile *pmFPAfileDefineChipMosaic(pmConfig *config, ///< Configuration data
                                     pmFPA *src, ///< Source FPA
                                     const char *filename ///< Output (root) filename
                                    );

/// Create a new output pmFPAfile based upon an FPA mosaic of an existing FPA
///
/// The new pmFPAfile is inserted into the config->files metadata, freed and returned; so that the user does
/// not have to (and should not!) free the result.
pmFPAfile *pmFPAfileDefineFPAMosaic(pmConfig *config, ///< Configuration data
                                    pmFPA *src, ///< Source FPA
                                    const char *filename ///< Output (root) filename
                                   );

// create a file with the given name, assign it type "INTERNAL", and supply it with an image
// of the requested dimensions. (image only, mask and weight are ignored)
pmReadout *pmFPAfileDefineInternal (psMetadata *files, const char *name, int Nx, int Ny, int type);

// delete the INTERNAL file of the given name (if it exists)
bool pmFPAfileDropInternal (psMetadata *files, const char *name);

// look for the given argname on the argument list.  find the give filename from the file rules
//
// Note that the returned pmFPAfile is a view only, so it should not be freed by the caller --- the only
// reference count is held by the config->files metadata.
pmFPAfile *pmFPAfileDefineSingleFromArgs (bool *found, pmConfig *config, const char *filename,
        const char *argname, int entry);
/// @}
# endif
