/* @file  pmFPAview.h
 * @brief Tools to manipulate the FPA structure elements.
 *
 * @author EAM, IfA
 *
 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
 * @date $Date: 2007-06-08 00:31:50 $
 * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
 */

/// @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.  Multiple file rules of the same name are permitted
// if multiple is true.
pmFPAfile *pmFPAfileDefineInput (const 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 (const 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, const 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, const 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, const 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 (const 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 (const pmConfig *config, const char *filename);

/// Create a new output pmFPAfile for a skycell of the default camera
///
/// 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 *pmFPAfileDefineSkycell(const pmConfig *config, ///< Configuration data
                                  pmFPA *fpa, ///< FPA to which to bind
                                  const char *filename ///< Output (root) 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(const 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(const 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
