#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif

#if defined(HAVE_LIBGRIB_API)
#include <grib_api.h>
#endif

#include <stdio.h>

#include "gribapi.h"

const char *
gribapiLibraryVersion(void)
{
  static char gribapi_libvers[64] = "";
#if defined(HAVE_LIBGRIB_API)
  if (gribapi_libvers[0] == 0)
    {
      long version = grib_get_api_version();

      int major_version = (int) (version / 10000), minor_version = (int) ((version - major_version * 10000) / 100),
          revision_version = (int) (version - major_version * 10000 - minor_version * 100);
      snprintf(gribapi_libvers, sizeof(gribapi_libvers), "%d.%d.%d", major_version, minor_version, revision_version);
    }
#endif
  return (gribapi_libvers);
}
