/*
 *
 * Copyright (c) Vaisala Group 2009. All rights reserved.
 *
 * The terms "Vaisala" and "Vaisala Group" are defined as
 * "Vaisala Oyj and all its subsidiaries".
 *
 */

/** @file archive2_io.h
 *  NEXRAD Archive 2  file I/O API 
 */

#ifndef SIGMET_ARCHIVE2_IO_H
#define SIGMET_ARCHIVE2_IO_H

#ifdef __cplusplus
extern "C" {
#endif

/** @defgroup gr_archive2_io NEXRAD Archive 2 file I/O
 * 
 *
 *  @ingroup gr_radar_scan
 *  @{
 */

/** NEXRAD ID to/from IRIS site name map entry */
struct archive2_convert_site
{
  char sNrRadarId[12];       /* Radar ID, null terminated */
  char sIrisSitename[20];    /* IRIS sitename, null terminated */
};

/** Information to customize the convertor */
struct archive2_convert_config
{
    struct sig_logging_spec Logging;
    uint8_t bIgnoreRayTimes;     /**< Ignore ray times, use sweep time instead */
    uint8_t bAllowSingleSweep;
    uint8_t bOutputHybridsSeparate; 
    uint8_t bSkipVolumeHeader;   /**< Skip the volume header */
    double  fMinReflectivity;    /**< Minimum refl. Lower values are thresholded */
    double  fDesiredDopRes;      /**< Desired Doppler resolution in meters */
    double  fDesiredRefRes;      /**< Desired Reflectivity resolution in meters */
    int     iExtension;          /**< Filename extension to use */
    char    sVolumeHeaderFileName[10];  
    int     iSiteCount;          /**< Number of sites in the list */
    int     ByteOrder;           /**< Byte order in Archive2 file */
    int     ByteOrderRDBinStep;       /**< Byte order of radar data bin step */
    int     ByteOrderRDDataDate;      /**< Byte order of radar data data date */
    int     ByteOrderRDVolumePattern; /**< Byte order of radar data volume pattern */
    struct archive2_convert_site *SiteList; /**< NEXRAD ID to/from
                                             * IRIS site name map */
};

/** Converts an IRIS RAW product to NEXRAD Archive2 format.
 *
 *  Returns 0 on sucess.
 */
int rscan_to_archive2(const struct radar_scan* rscan_a,
                      const char * sfname_a,  /* Path to write the file to */
                      void (*error_report)(const char *message),  /* Optional error function */
                      const struct archive2_convert_config *pConfig_a );

/** Search for the site in the list.  Return NULL if not found */
const struct archive2_convert_site* archive2_find_site
( const char* sIrisSite,    /* Null terminated IRIS sitename */
  const struct archive2_convert_config *pConvert_a );

/** Initialize config to the default values */
void archive2_config_init(struct archive2_convert_config *pConvert_a);

/** @}  gr_archive2_io */

#ifdef __cplusplus
}
#endif
#endif // SIGMET_ARCHIVE2_IO_H
