diff --git a/ChangeLog b/ChangeLog
index e056d40812282def36592071f4b778897159796a..c5642f5967d22d67528bbb75327adcb5853f3124 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
 
 2021-06-04  Uwe Schulzweida
 
+	* Add environment variables CDI_GRIB1_TEMPLATE and CDI_GRIB2_TEMPLATE
 	* cdf_put_att_int()/cdf_get_att_int(): change NC_ERANGE to NC_NOERR
 
 2021-05-29  Uwe Schulzweida
diff --git a/config/default b/config/default
index 6bc3c522f173b1a4655dcda1b8b193127efd84e9..d38cfeb3c9bcb99a1abef765ef8b17f922286cca 100755
--- a/config/default
+++ b/config/default
@@ -65,15 +65,12 @@ case "${HOSTNAME}" in
 	;;
     hama*)
 	${CONFPATH}configure --prefix=$HOME/local \
-                    --enable-maintainer-mode \
-                    --enable-iso-c-interface \
-                    --enable-swig \
-                    --enable-python \
+                    --disable-iso-c-interface \
                     --with-szlib=$HOME/local \
-                    --with-eccodes=$HOME/local/eccodes-2.17.0 \
+                    --with-eccodes=$HOME/local/eccodes-2.22.0 \
                     --with-netcdf=$HOME/local/netcdf-c-4.8.0 \
-                    LDFLAGS="-Wl,-rpath,$HOME/local/eccodes-2.17.0/lib" \
-	            CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -Wwrite-strings -W -Wfloat-equal -pedantic -O3"
+                    LDFLAGS="-Wl,-rpath,$HOME/local/eccodes-2.22.0/lib" \
+	            CC=clang CFLAGS="-g -pipe -D_REENTRANT -Wall -Wwrite-strings -W -Wfloat-equal -pedantic -O3"
 	;;
 # x86_64-squeeze-x64-linux
     thunder*)
diff --git a/doc/tex/environment.tex b/doc/tex/environment.tex
index 3067212c6119f72907db376e06cbad5e493523c6..ba6b8f0efc496fbf1b5915231c1e28f73560d62a 100644
--- a/doc/tex/environment.tex
+++ b/doc/tex/environment.tex
@@ -11,6 +11,8 @@ The following table describes the environment variables that affect {\CDI}.
 %\cellcolor{pcolor2}
 {\bfseries Variable name}           &  {\bfseries Default} & {\bfseries Description} \\ \hline
 CDI\_CONVERT\_CUBESPHERE &        1   & Convert cubed-sphere data to unstructured grid. \\
+CDI\_GRIB1\_TEMPLATE          &   None   &  Path to a GRIB1 template file for GRIB\_API. \\
+CDI\_GRIB2\_TEMPLATE          &   None   &  Path to a GRIB2 template file for GRIB\_API. \\
 CDI\_INVENTORY\_MODE        &   None   &  Set to time to skip double variable entries. \\
 CDI\_READ\_CELL\_CORNERS  &         1   &  Read grid cell corners. \\
 CDI\_VERSION\_INFO               &         1   &  Set to 0 to disable NetCDF global attribute CDI.
diff --git a/src/cdi_int.c b/src/cdi_int.c
index 3ae7abf6658938084f9e32d17d8df89615af798f..70d926c246c24c868ea2ac12cd61cdf934b02073 100644
--- a/src/cdi_int.c
+++ b/src/cdi_int.c
@@ -30,6 +30,8 @@ bool cdiIgnoreAttCoordinates = false;
 bool cdiCoordinatesLonLat    = false;
 bool cdiIgnoreValidRange     = false;
 int cdiSkipRecords           = 0;
+const char *CDI_GRIB1_Template = NULL;
+const char *CDI_GRIB2_Template = NULL;
 int CDI_convention           = CDI_CONVENTION_ECHAM;
 int CDI_inventory_mode       = 1;
 int CDI_version_info         = 1;
@@ -360,6 +362,12 @@ void cdiInitialize(void)
       value = cdiGetenvInt("CDI_NETCDF_HDR_PAD");
       if ( value >= 0 ) CDI_netcdf_hdr_pad = (size_t) value;
 
+      envstr = getenv("CDI_GRIB1_TEMPLATE");
+      if ( envstr ) CDI_GRIB1_Template = envstr;
+
+      envstr = getenv("CDI_GRIB2_TEMPLATE");
+      if ( envstr ) CDI_GRIB2_Template = envstr;
+
       envstr = getenv("CDI_MISSVAL");
       if ( envstr ) CDI_default_missval = atof(envstr);
       /*
diff --git a/src/cdi_int.h b/src/cdi_int.h
index 73a00d19b483adddec241c3000fa4142cdbf1754..f2867d076083a0448bf36170eab9d09b2e5147f0 100644
--- a/src/cdi_int.h
+++ b/src/cdi_int.h
@@ -373,6 +373,8 @@ extern bool cdiIgnoreAttCoordinates;
 extern bool cdiCoordinatesLonLat;
 extern bool cdiIgnoreValidRange;
 extern int cdiSkipRecords;
+extern const char *CDI_GRIB1_Template;
+extern const char *CDI_GRIB2_Template;
 extern int CDI_convention;
 extern int CDI_inventory_mode;
 extern int CDI_version_info;
diff --git a/src/gribapi.c b/src/gribapi.c
index c3b053ac3c03d29b4a68637bf71b84a3ccc4c535..4bbaa68c43c29a78348816e16731ca82307e6331 100644
--- a/src/gribapi.c
+++ b/src/gribapi.c
@@ -39,7 +39,6 @@ const char *gribapiLibraryVersionString(void)
   if (!gribapi_libvers_init)
     {
       int major_version, minor_version, revision_version;
-
       gribapiLibraryVersion(&major_version, &minor_version, &revision_version);
 
       sprintf(gribapi_libvers, "%d.%d.%d", major_version, minor_version, revision_version);
@@ -47,9 +46,52 @@ const char *gribapiLibraryVersionString(void)
     }
 #endif
 
-  return (gribapi_libvers);
+  return gribapi_libvers;
+}
+
+void *gribHandleNew(int editionNumber)
+{
+#ifdef HAVE_LIBGRIB_API
+  grib_handle *gh = NULL;
+  const char *fname = (editionNumber == 1) ? CDI_GRIB1_Template : CDI_GRIB2_Template;
+  if (fname)
+    {
+      FILE *fp = fopen(fname, "r");
+      if (fp)
+        {
+          int error;
+          gh = grib_handle_new_from_file(NULL, fp, &error);
+          fclose(fp);
+          if (gh == NULL) Error("grib_handle_new_from_file failed!");
+        }
+      else
+        {
+          Error("Open failed on >%s<!", fname);
+        }
+    }
+
+  if (gh == NULL)
+    {
+      gh = grib_handle_new_from_samples(NULL, (editionNumber == 1) ? "GRIB1" : "GRIB2");
+      if (gh == NULL) Error("grib_handle_new_from_samples failed!");
+    }
+
+  if (editionNumber == 1) GRIB_CHECK(my_grib_set_long(gh, "deleteLocalDefinition", 1L), 0);
+  if (editionNumber == 2) GRIB_CHECK(my_grib_set_long(gh, "grib2LocalSectionPresent", 0L), 0);
+  if (editionNumber == 2) GRIB_CHECK(my_grib_set_long(gh, "numberOfValues", 0L), 0);
+
+  return gh;
+#else
+  return NULL;
+#endif
 }
 
+void gribHandleDelete(void *gh)
+{
+#ifdef HAVE_LIBGRIB_API
+  grib_handle_delete((struct grib_handle *)gh);
+#endif
+}
 
 void gribContainersNew(stream_t * streamptr)
 {
diff --git a/src/gribapi.h b/src/gribapi.h
index 1c9ac5bb0c705624aedf7104f549ecaa8139966b..298e7903ebe186c068af01e6f97efc31a14b7094 100644
--- a/src/gribapi.h
+++ b/src/gribapi.h
@@ -40,7 +40,7 @@
 #define  GRIB2_LTYPE_SEDIMENT_BOTTOM_TW  165  // Bottom Of Sediment Layer Penetrated By Thermal Wave
 #define  GRIB2_LTYPE_MIX_LAYER           166  // Mixing Layer
 
-/* GRIB2 Data representation type (Grid Type) */
+// GRIB2 Data representation type (Grid Type)
 #define  GRIB2_GTYPE_LATLON                0  // Latitude/longitude (or equidistant cylindrical, or Plate Carree)
 #define  GRIB2_GTYPE_LATLON_ROT            1  // Rotated Latitude/longitude
 #define  GRIB2_GTYPE_LATLON_STR            2  // Stretched Latitude/longitude
@@ -56,13 +56,13 @@
 #define  GRIB2_GTYPE_UNSTRUCTURED        101  // General Unstructured Grid
 
 const char *gribapiLibraryVersionString(void);
-void gribContainersNew(stream_t * streamptr);
-void gribContainersDelete(stream_t * streamptr);
+void gribContainersNew(stream_t *streamptr);
+void gribContainersDelete(stream_t *streamptr);
 
 #ifdef HAVE_LIBGRIB_API
 static inline int my_grib_set_double(grib_handle* h, const char* key, double val)
 {
-  if ( CDI_gribapi_debug )
+  if (CDI_gribapi_debug)
     fprintf(stderr, "grib_set_double(\tgrib_handle* h, \"%s\", %f)\n", key, val);
 
   int ret_val = grib_set_double(h, key, val);
@@ -73,7 +73,7 @@ static inline int my_grib_set_double(grib_handle* h, const char* key, double val
 
 static inline int my_grib_set_long(grib_handle* h, const char* key, long val)
 {
-  if ( CDI_gribapi_debug )
+  if (CDI_gribapi_debug)
     fprintf(stderr, "grib_set_long(  \tgrib_handle* h, \"%s\", %ld)\n", key, val);
 
   int ret_val = grib_set_long(h, key, val);
@@ -84,7 +84,7 @@ static inline int my_grib_set_long(grib_handle* h, const char* key, long val)
 
 static inline int my_grib_set_string(grib_handle* h, const char* key, const char* val, size_t* length)
 {
-  if ( CDI_gribapi_debug )
+  if (CDI_gribapi_debug)
     fprintf(stderr, "grib_set_string(\tgrib_handle* h, \"%s\", \"%s\")\n", key, val);
 
   int ret_val = grib_set_string(h, key, val, length);
@@ -92,26 +92,6 @@ static inline int my_grib_set_string(grib_handle* h, const char* key, const char
     fprintf(stderr, "!!! grib_set_string(\tgrib_handle* h, \"%s\", \"%s\") !!!\n", key, val);
   return ret_val;
 }
-
-static inline void *gribHandleNew(int editionNumber)
-{
-  grib_handle *gh = grib_handle_new_from_samples(NULL, (editionNumber == 1) ? "GRIB1" : "GRIB2");
-  if ( gh == NULL ) Error("grib_handle_new_from_samples failed!");
-
-  if ( editionNumber == 1 ) GRIB_CHECK(my_grib_set_long(gh, "deleteLocalDefinition", 1L), 0);
-  if ( editionNumber == 2 ) GRIB_CHECK(my_grib_set_long(gh, "grib2LocalSectionPresent", 0L), 0);
-  if ( editionNumber == 2 ) GRIB_CHECK(my_grib_set_long(gh, "numberOfValues", 0L), 0);
-
-  return gh;
-}
-
-static inline void gribHandleDelete(void *gh)
-{
-  grib_handle_delete((struct grib_handle *)gh);
-}
-#else
-#define gribHandleNew(editionNumber) (NULL)
-#define gribHandleDelete(gh)
 #endif
 
 typedef struct {