/**
 @file fes.h
 @brief Main routines for the FES prediction software.
 @author CLS
 */
#ifndef _FES_H
#define _FES_H

/**
 @enum fes_enum_access
 Possible type of access.
 */
typedef enum
{
    /** Direct access (Grids are not loaded into memory). */
    FES_IO = 0,
    /** Memory access (Grids are loaded into memory). */
    FES_MEM
} fes_enum_access;

/**
 @enum fes_enum_tide_type
 Possible type of tide.
 */
typedef enum
{
    /** Ocean tide. */
    FES_TIDE = 0,
    /** Radial tide. */
    FES_RADIAL
} fes_enum_tide_type;

/**
 @enum fes_enum_error
 Possible error codes we can returned.
 */
typedef enum
{
    /** No error reporting */
    FES_SUCCESS,
    /** Not enough memory */
    FES_NO_MEMORY,
    /** netCDF error */
    FES_NETCDF_ERROR,
    /** IO error */
    FES_IO_ERROR,
    /** Invalid configuration file */
    FES_INI_ERROR,
    /** No data available in grids for the location asked */
    FES_NO_DATA
} fes_enum_error;

/**
 @typedef FES
 Fes handler
 */
typedef void* FES;

/**
 @fn fes_new(FES* handle, const fes_enum_tide_type tide,
 const fes_enum_access mode, const char* const path)

 @brief Initializes the computation of the tide.

 @param handle    FES data handler.
 @param tide      Computation mode. If mode is equals to FES_TIDE, the core
 function computes the tide otherwise she computes the
 radial tide.
 @param mode      One of FES_MEM, FES_IO which request loading grids into
 memory or direct access from NetCDF grids.
 @param path      Path to the configuration file.

 @return If an error occurs, the return value is 1, otherwise 0.
 */
int fes_new(FES* handle, const fes_enum_tide_type tide,
        const fes_enum_access mode, const char* const path);

/**
 @fn fes_delete(FES handle)

 @brief Frees the memory used.

 @param handle    FES data indentifier
 */
void fes_delete(FES handle);

/**
 @fn fes_core(FES handle, const double lat, const double lon,
 const double time, double* h, double* h_long_period)

 @brief Driver for tidal computation.

 @param handle        FES handler.
 @param lat           Latitude in degrees (positive north) for the position
 at which tide is computed.
 @param lon           Longitude in degrees for the position at which tide is
 computed.
 @param time          Julian day (days since 1950-01-01 00:00:00.000 UTC).
 @param h             Computed height of the diurnal and semi-diunral
 constituents of the tidal spectrum (in centimeters).
 @param h_long_period Computed height of the long period wave constituents of
 the tidal spectrum (in centimeters).

 h and h_long_period are set to nan if no data is available at the given
 position.

 @return If an error occurs, the return value is 1, otherwise 0.
 */
int fes_core(FES handle, const double lat, const double lon, const double time,
        double* h, double* h_long_period);

/**
 @fn fes_errno(FES fes)

 @brief Returns the last error code.

 @param fes        FES handler

 @return the error code.
 */
fes_enum_error fes_errno(FES fes);

/**
 @fn fes_error(FES fes)

 @brief Returns the message error.

 @param fes        FES handler

 @return the message error.
 */
const char * fes_error(FES fes);

#endif
