/* @file  pmSourceIO.h
 * @brief functions to read and write object files
 *
 * @author EAM, IfA; GLG, MHPCC
 *
 * @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
 * @date $Date: 2009-02-16 22:30:50 $
 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 *
 */

# ifndef PM_SOURCE_IO_H
# define PM_SOURCE_IO_H

/// @addtogroup Objects Object Detection / Analysis Functions
/// @{

int pmSourceGetDophotType (pmSource *source);
bool pmSourceSetDophotType (pmSource *source, int type);

bool pmSourcesWriteRAW (psArray *sources, char *filename);
bool pmSourcesWriteOBJ (psArray *sources, char *filename);
bool pmSourcesWriteSX (psArray *sources, char *filename);
bool pmSourcesWriteCMP (psArray *sources, char *filename, psMetadata *header);

bool pmSourcesWrite_SMPDATA (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
bool pmSourcesWrite_PS1_DEV_0 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);

bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
bool pmSourcesWrite_PS1_DEV_1_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe);
bool pmSourcesWrite_PS1_DEV_1_XFIT (psFits *fits, psArray *sources, char *extname);

bool pmSourcesWrite_PS1_CAL_0 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
bool pmSourcesWrite_PS1_CAL_0_XSRC (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);
bool pmSourcesWrite_PS1_CAL_0_XFIT (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname);

bool pmSourcesWrite_CMF_PS1_V1 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
bool pmSourcesWrite_CMF_PS1_V1_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe);
bool pmSourcesWrite_CMF_PS1_V1_XFIT (psFits *fits, psArray *sources, char *extname);

bool pmSourcesWrite_CMF_PS1_V2 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
bool pmSourcesWrite_CMF_PS1_V2_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe);
bool pmSourcesWrite_CMF_PS1_V2_XFIT (psFits *fits, psArray *sources, char *extname);

bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, pmConfig *config);

psArray *pmSourcesReadCMP (char *filename, psMetadata *header);

psArray *pmSourcesRead_SMPDATA (psFits *fits, psMetadata *header);
psArray *pmSourcesRead_PS1_DEV_0 (psFits *fits, psMetadata *header);
psArray *pmSourcesRead_PS1_DEV_1 (psFits *fits, psMetadata *header);
psArray *pmSourcesRead_PS1_CAL_0 (psFits *fits, psMetadata *header);
psArray *pmSourcesRead_CMF_PS1_V1 (psFits *fits, psMetadata *header);
psArray *pmSourcesRead_CMF_PS1_V2 (psFits *fits, psMetadata *header);

bool pmSourcesWritePSFs (psArray *sources, char *filename);
bool pmSourcesWriteEXTs (psArray *sources, char *filename, bool require);
bool pmSourcesWriteNULLs (psArray *sources, char *filename);
bool pmMomentsWriteText (psArray *sources, char *filename);
bool pmPeaksWriteText (psArray *peaks, char *filename);

bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);

bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file, pmConfig *config);
bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);
bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config);

bool pmFPAviewCheckDataStatusForSources (const pmFPAview *view, const pmFPAfile *file);
bool pmFPACheckDataStatusForSources (const pmFPA *fpa);
bool pmChipCheckDataStatusForSources (const pmChip *chip);
bool pmCellCheckDataStatusForSources (const pmCell *cell);
bool pmReadoutCheckDataStatusForSources (const pmReadout *readout);

bool pmSourceLocalAstrometry (psSphere *ptSky, float *posAngle, float *pltScale, pmChip *chip, float xPos, float yPos);

bool pmSourceIO_WriteMatchedRefs (psFits *fits, pmFPA *fpa, pmConfig *config);
bool pmSourceIO_ReadMatchedRefs (psFits *fits, pmFPA *fpa, const pmConfig *config);

/// @}
# endif /* PM_SOURCE_IO_H */
