/** @file  pmConfig.h
 *
 *  @author PAP, IfA
 *
 *  @version $Revision: 1.3.4.8 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2006-04-13 06:18:22 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 *
 */
#ifndef PM_CONFIG_H
#define PM_CONFIG_H

#include "pslib.h"


// Configuration information
typedef struct
{
    psMetadata *site;                   // Site configuration
    psMetadata *camera;                 // Camera specification
    psMetadata *recipes;                // Recipes for processing
    psMetadata *arguments;              // Command-line arguments
    psMetadata *files;                  // pmFPAfiles used for analysis
    //    psMetadata *format;   // camera format for primary image
    psDB *database;                     // Database handle
}
pmConfig;

pmConfig *pmConfigAlloc(void);

// Free static variables
void pmConfigDone(void);

/** pmConfigRead
 *
 * pmConfigRead shall load the site configuration (according to the above rule
 * for determining the source). The camera configuration shall also be loaded if
 * it is specified on the command line (argc, argv); otherwise it shall be set to
 * NULL. The recipe shall also be loaded from the command line (if specified) or,
 * if the camera configuration has been loaded, from the camera configuration and
 * recipe specification therein (see below). In dealing with the command line
 * parameters, the functions shall use the appropriate functions in psLib to
 * retrieve and remove the relevant options from the argument list; this
 * simplifies assignment of the mandatory arguments, since all the optional
 * command line arguments are removed leaving only the mandatory arguments. The
 * following psLib setups shall also be performed if they are specified in the
 * site configuration:
 *
 */
pmConfig *pmConfigRead(
    int *argc,
    char **argv);

/** we need this elsewhere; make it public **/
bool readConfig(
    psMetadata **config,                // Config to output
    const char *name,                   // Name of file
    const char *description             // Description of file
);

/** pmConfigValidateCamera
 *
 * This function, used by pmConfigCameraFromHeader, shall return true if the
 * FITS header matches the rule contained in the camera configuration (see
 * x2.2.2.3); otherwise it shall return false.
 *
 */
bool pmConfigValidateCameraFormat(
    const psMetadata *cameraFormat,
    const psMetadata *header);


/** pmConfigCameraFromHeader
 *
 * pmConfigCameraFromHeader shall load the camera configuration based on the
 * contents of the FITS header, using the list of known cameras contained in the
 * site configuration. If more than one camera matches the FITS header, a warning
 * shall be generated and the first matching camera returned.
 *
 */
psMetadata *pmConfigCameraFormatFromHeader(
    pmConfig *config,                   // The configuration
    const psMetadata *header           // The FITS header
);


/** pmConfigRecipeFromCamera
 *
 * pmConfigRecipeFromCamera shall load the recipes from the list of known recipes contained in the camera
 * configuration.
 *
 */
bool pmConfigReadRecipes(
    pmConfig *config
);

/** pmConfigDB
 *
 * pmConfigDB shall use the site configuration data to open a database handle.
 * This is fairly straightforward at the moment, but will change when we beef up
 * security. (TBD)
 *
 */
#ifdef DOMIT_PSDB
typedef psDB void;
#endif

psDB *pmConfigDB(
    psMetadata *site
);

/** pmConfigConformHeader
 *
 * Make the supplied header conform to the nominated camera format.
 */
bool pmConfigConformHeader(psMetadata *header, // Header to conform
                           const psMetadata *format // Camera format
                          );


psArray *pmConfigFileSets (int *argc, char **argv, char *file, char *list);
bool pmConfigFileSetsMD (psMetadata *metadata, int *argc, char **argv, char *name, char *file, char *list);


#endif
