[cdo] 70/84: 1.6.6 release

Alastair McKinstry mckinstry at moszumanska.debian.org
Sat Jun 13 16:48:42 UTC 2015


This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch master
in repository cdo.

commit 94300600c91fe0e4d3a994b86cfe87215025c200
Author: Alastair McKinstry <mckinstry at debian.org>
Date:   Wed Dec 10 17:07:17 2014 +0000

    1.6.6 release
---
 ChangeLog                                         |   43 +-
 NEWS                                              |   11 +
 OPERATORS                                         |    1 +
 cdo.spec                                          |    2 +-
 config/default                                    |   33 +-
 configure                                         |   32 +-
 configure.ac                                      |    7 +-
 contrib/cdoCompletion.bash                        |    1 +
 contrib/cdoCompletion.tcsh                        |    1 +
 contrib/cdoCompletion.zsh                         |    1 +
 doc/cdo.pdf                                       |  Bin 1308412 -> 1314332 bytes
 doc/cdo_refcard.pdf                               |  Bin 96478 -> 96705 bytes
 libcdi/ChangeLog                                  |   30 +-
 libcdi/Makefile.in                                |    1 +
 libcdi/NEWS                                       |   11 +
 libcdi/app/Makefile.in                            |    1 +
 libcdi/app/cdi.c                                  |   49 +-
 libcdi/app/printinfo.h                            |   26 +-
 libcdi/configure                                  |  155 +-
 libcdi/configure.ac                               |   16 +-
 libcdi/examples/Makefile.in                       |    1 +
 libcdi/examples/pio/Makefile.in                   |    1 +
 libcdi/examples/pio/collectData.c                 |   66 +-
 libcdi/examples/pio/collectData2003.F90           |   24 +-
 libcdi/examples/pio/collectDataNStreams.c         |    8 +-
 libcdi/examples/pio/compareResourcesArray.c       |    2 +-
 libcdi/interfaces/Makefile.in                     |    1 +
 libcdi/interfaces/f2003/bindGen.rb                |    6 +-
 libcdi/m4/starlink_fpp.m4                         |   14 +-
 libcdi/src/Makefile.am                            |    7 +-
 libcdi/src/Makefile.in                            |   48 +-
 libcdi/src/cdi.h                                  |   19 +-
 libcdi/src/cdi.inc                                |   26 +-
 libcdi/src/cdiFortran.c                           |   15 +-
 libcdi/src/cdi_int.c                              |    2 +-
 libcdi/src/cdi_int.h                              |   15 +-
 libcdi/src/cdilib.c                               | 2416 ++++++++++-----------
 libcdi/src/cdipio.inc                             |    4 +-
 libcdi/src/config.h.in                            |   17 +
 libcdi/src/dmemory.c                              |    2 +-
 libcdi/src/extralib.c                             |   11 +-
 libcdi/src/gribapi.c                              |    2 +-
 libcdi/src/gribapi.h                              |   25 +-
 libcdi/src/grid.c                                 |  826 +++----
 libcdi/src/grid.h                                 |    8 +-
 libcdi/src/ieg.h                                  |    1 +
 libcdi/src/ieglib.c                               |    2 +-
 libcdi/src/institution.c                          |    3 +-
 libcdi/src/mo_cdi.f90                             |   39 +-
 libcdi/src/model.c                                |    2 +-
 libcdi/src/pio.c                                  |    2 +-
 libcdi/src/pio_client.c                           |   11 +-
 libcdi/src/pio_comm.c                             |   49 +-
 libcdi/src/pio_interface.c                        |  103 +-
 libcdi/src/pio_mpinonb.c                          |    2 +-
 libcdi/src/pio_posixasynch.c                      |  134 +-
 libcdi/src/pio_posixfpguardsendrecv.c             |    6 +-
 libcdi/src/pio_posixnonb.c                        |   35 +-
 libcdi/src/pio_record_send.c                      |   10 +-
 libcdi/src/pio_serialize.c                        |    4 +-
 libcdi/src/pio_server.c                           |  112 +-
 libcdi/src/resource_handle.c                      |    9 +-
 libcdi/src/serialize.c                            |    5 +-
 libcdi/src/stream.c                               |   56 +-
 libcdi/src/stream_cdf.c                           |  777 +++----
 libcdi/src/stream_cdf.h                           |    2 +-
 libcdi/src/stream_cgribex.c                       |   29 +-
 libcdi/src/stream_ext.c                           |    2 +-
 libcdi/src/stream_grb.c                           |   35 +-
 libcdi/src/stream_gribapi.c                       |  148 +-
 libcdi/src/stream_history.c                       |   27 +-
 libcdi/src/stream_ieg.c                           |  102 +-
 libcdi/src/stream_record.c                        |   31 +-
 libcdi/src/stream_srv.c                           |    2 +-
 libcdi/src/table.c                                |   38 +-
 libcdi/src/util.c                                 |   60 +-
 libcdi/src/varscan.c                              |   71 +-
 libcdi/src/varscan.h                              |    7 +-
 libcdi/src/vlist.c                                |    6 +-
 libcdi/src/vlist.h                                |    2 +
 libcdi/src/vlist_att.c                            |   21 +-
 libcdi/src/zaxis.c                                |   55 +-
 libcdi/tests/Makefile.am                          |   39 +-
 libcdi/tests/Makefile.in                          |  141 +-
 libcdi/tests/cksum_read.c                         |    2 +-
 libcdi/tests/cksum_write.c                        |   93 +-
 libcdi/tests/create_uuid.c                        |   91 +
 libcdi/tests/create_uuid.h                        |   13 +
 libcdi/tests/deco2d_model.c                       |   40 +-
 libcdi/tests/pio_cksum_asynch.in                  |    7 +-
 libcdi/tests/pio_cksum_cdf.in                     |    5 +
 libcdi/tests/pio_cksum_fpguard.in                 |    7 +-
 libcdi/tests/pio_cksum_mpinonb.in                 |    7 +-
 libcdi/tests/pio_cksum_writer.in                  |    7 +-
 libcdi/tests/pio_write.c                          |   48 +-
 libcdi/tests/pio_write_deco2d_run.in              |   32 +-
 libcdi/tests/pio_write_run.in                     |   34 +-
 libcdi/tests/simple_model.c                       |   69 +-
 libcdi/tests/stream_cksum.c                       |   16 +-
 libcdi/tests/test_cdf_read.c                      |   69 +
 libcdi/tests/test_cdf_transformation.in           |   25 +
 libcdi/tests/test_cdf_write.c                     |  173 ++
 libcdi/tests/test_grib.c                          |    2 +-
 libcdi/tests/test_resource_copy.c                 |   34 +-
 m4/._ax_pthread.m4                                |  Bin 197 -> 197 bytes
 src/Deltime.c                                     |    3 +-
 src/Filedes.c                                     |   70 +-
 src/Gradsdes.c                                    |    3 +-
 src/Histogram.c                                   |   33 +-
 src/Merge.c                                       |  129 +-
 src/Output.c                                      |   72 +-
 src/Seasstat.c                                    |   26 +
 src/Selrec.c                                      |    7 +-
 src/Settime.c                                     |   16 +-
 src/Sinfo.c                                       |    3 +-
 src/Timstat.c                                     |   31 +-
 src/cdo.c                                         |   30 +-
 src/cdo.h                                         |    2 +-
 src/clipping/clipping.c                           |   42 +-
 src/clipping/grid.h                               |    2 +-
 src/clipping/intersection.c                       |    6 +-
 src/exception.c                                   |   59 +-
 src/expr.c                                        |   12 +-
 src/features.c                                    |   13 +
 src/grid_area.c                                   |   50 +-
 src/griddes.c                                     |    4 +-
 src/griddes.h                                     |    2 +-
 src/gridreference.c                               |   51 +-
 src/modules.c                                     |    6 +-
 src/operator_help.h                               |   46 +-
 src/printinfo.h                                   |   12 +-
 src/pstream.c                                     |   17 +-
 src/remap_conserv.c                               |   18 +-
 src/remap_conserv_scrip.c                         |    4 +-
 src/remap_search_latbins.c                        |   80 +-
 src/remaplib.c                                    |    8 +
 test/Arith.test.in                                |   80 +
 test/{Read_netcdf.test.in => Copy_netcdf.test.in} |   20 +-
 test/Makefile.am                                  |    4 +-
 test/Makefile.in                                  |   30 +-
 test/{Read_netcdf.test.in => Read_grib.test.in}   |   14 +-
 test/Read_netcdf.test.in                          |    6 +-
 test/data/._netcdf_testfile01.nc                  |  Bin 197 -> 197 bytes
 test/data/Makefile.am                             |    9 +-
 test/data/Makefile.in                             |    9 +-
 test/data/grib_testfile01.grb                     |  Bin 0 -> 63264 bytes
 test/data/grib_testfile01_info_ref                |   13 +
 test/data/grib_testfile01_sinfo_ref               |   14 +
 test/data/grib_testfile02.grb                     |  Bin 0 -> 10560 bytes
 test/data/grib_testfile02_info_ref                |  121 ++
 test/data/grib_testfile02_sinfo_ref               |   42 +
 test/data/netcdf_testfile02.nc                    |  Bin 0 -> 2376 bytes
 test/data/netcdf_testfile02_infon_ref             |  121 ++
 test/data/netcdf_testfile02_sinfon_ref            |   42 +
 test/data/pl_data                                 |  Bin 0 -> 10080 bytes
 test/data/testfile01c.nc                          |  Bin 0 -> 33140 bytes
 156 files changed, 4739 insertions(+), 3584 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8416843..a47cdf7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,44 @@
-2015-02-19  Uwe Schulzweida
+2014-11-27  Uwe Schulzweida
 
-	* using CDI library version 1.7.0
-	* Version 1.7.0 released
+	* using CDI library version 1.6.6
+	* Version 1.6.6 released
+
+2014-11-25  Uwe Schulzweida
+
+	* merge: check number of timesteps [Bug #5338]
+
+2014-11-24  Uwe Schulzweida
+
+	* Seasstat: added support for time bounds
+	* Timstat: added time bounds
+
+2014-11-21  Uwe Schulzweida
+
+	* outputtab: added key nohead and docu
+
+2014-11-20  Uwe Schulzweida
+
+	* outputtab: added key timestep
+	* selrec: abort if used in combination with other operators
+
+2014-11-19  Uwe Schulzweida
+
+	* remapycon: fix omp Race Condition
+
+2014-11-12  Uwe Schulzweida
+
+	* using CDI library version 1.6.5.2
+	* Version 1.6.5.2 released
+
+2014-11-11  Uwe Schulzweida
+
+	* histcount: doesn't recognize missing values (bug fix)
+	* filesdes: doesn't work for GRIB2 files [Bug #5307]
+
+2014-10-31  Uwe Schulzweida
+
+	* using CDI library version 1.6.5.1
+	* Version 1.6.5.1 released
 
 2014-10-30  Uwe Schulzweida
 
diff --git a/NEWS b/NEWS
index dea4643..102e7d5 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,17 @@
 CDO NEWS
 --------
 
+Version 1.6.6 (27 November 2014):
+
+   New operators:
+     * outputtab: table output
+   Fixed bugs:
+     * option -t table: segmentation fault if parameter table entry longname is missing
+     * merge: check number of timesteps [Bug #5338]
+     * seasmean: sets all time_bnds to the same values [Bug #5329]
+     * histcount: doesn't recognize missing values
+     * filesdes: doesn't work for GRIB2 files [Bug #5307]
+
 Version 1.6.5 (23 October 2014):
 
    New operators:
diff --git a/OPERATORS b/OPERATORS
index 5bb990c..66e4230 100644
--- a/OPERATORS
+++ b/OPERATORS
@@ -473,6 +473,7 @@ Operator catalog:
    Output        outputint       Integer output
    Output        outputsrv       SERVICE ASCII output
    Output        outputext       EXTRA ASCII output
+   Outputtab     outputtab       Table output
 -------------------------------------------------------------
    Miscellaneous
 -------------------------------------------------------------
diff --git a/cdo.spec b/cdo.spec
index cbfdb98..0ab3285 100644
--- a/cdo.spec
+++ b/cdo.spec
@@ -4,7 +4,7 @@
 
 Name:           cdo
 #BuildRequires:  
-Version:        1.6.5.1
+Version:        1.6.6
 Release:        1
 Summary:        Climate Data Operators
 License:        GNU GENERAL PUBLIC LICENSE Version 2, June 1991
diff --git a/config/default b/config/default
index 8dc1427..057fe8c 100755
--- a/config/default
+++ b/config/default
@@ -31,7 +31,7 @@ case "${HOSTNAME}" in
     bailung*|d133*|d134*)
         CDOLIBS="--with-fftw3 \
                  --with-jasper=$HOME/local \
-                 --with-grib_api=$HOME/local/gribapi-1.12.3 \
+                 --with-grib_api=$HOME/local/gribapi-1.13.0 \
                  --with-netcdf=$HOME/local \
                  --with-hdf5=$HOME/local \
                  --with-szlib=$HOME/local \
@@ -62,7 +62,7 @@ case "${HOSTNAME}" in
     hama*)
         CDOLIBS="--with-fftw3 \
                  --with-jasper=/opt/local \
-                 --with-grib_api=$HOME/local/gribapi-1.9.16 \
+                 --with-grib_api=$HOME/local/gribapi-1.13.0 \
                  --with-netcdf=/opt/local \
                  --with-hdf5=/opt/local \
                  --with-szlib=$HOME/local \
@@ -112,21 +112,24 @@ case "${HOSTNAME}" in
                     --enable-all-static \
                     --with-fftw3 \
                     $CDOLIBS \
-                    CC=gcc CFLAGS='-g -Wall -O3 -mavx'
+                    CC=gcc CFLAGS='-g -Wall -O3'
 	fi
 	;;
-# x86_64-lenny-linux-gnu
-    squall*)
-        ${CONFPATH}configure --prefix=$HOME/local --exec_prefix=$HOME/local/squeeze-x64 \
-                    --enable-all-static \
-                    --with-jasper=/sw/squeeze-x64/jasper-1.900.1-static \
-                    --with-grib_api=/sw/squeeze-x64/grib_api-1.9.9-static \
-                    --with-netcdf=/sw/squeeze-x64/netcdf-4.2-static \
-                    --with-hdf5=/sw/squeeze-x64/hdf5-1.8.8-static \
-                    --with-szlib=/sw/squeeze-x64/szip-2.1 \
-                    --with-udunits2=/sw/squeeze-x64/udunits-2.1.19 \
-                    --with-proj=/sw/squeeze-x64/proj-4.7.0 \
-                    CC=gcc CFLAGS='-g -Wall -O3'
+# x86_64-unknown-linux-gnu
+    btlogin*)
+        CDOLIBS=""
+
+        if  test "$COMP" = icc ; then
+          ${CONFPATH}configure --prefix=$HOME/local \
+                    --with-fftw3 \
+                    $CDOLIBS \
+	            CC=icc CFLAGS="-g -Wall -O3 -vec-report2 -march=native -fp-model source -fast-transcendentals"
+	else
+          ${CONFPATH}configure --prefix=$HOME/local \
+                    --with-fftw3 \
+                    $CDOLIBS \
+                    CC=gcc CFLAGS='-g -Wall -O3 -march=native'
+	fi
 	;;
 # ia64-xxx-linux
     ds*)
diff --git a/configure b/configure
index 919a2ff..08acc19 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for cdo 1.6.5.1.
+# Generated by GNU Autoconf 2.68 for cdo 1.6.6.
 #
 # Report bugs to <http://code.zmaw.de/projects/cdo>.
 #
@@ -570,8 +570,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='cdo'
 PACKAGE_TARNAME='cdo'
-PACKAGE_VERSION='1.6.5.1'
-PACKAGE_STRING='cdo 1.6.5.1'
+PACKAGE_VERSION='1.6.6'
+PACKAGE_STRING='cdo 1.6.6'
 PACKAGE_BUGREPORT='http://code.zmaw.de/projects/cdo'
 PACKAGE_URL=''
 
@@ -1391,7 +1391,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures cdo 1.6.5.1 to adapt to many kinds of systems.
+\`configure' configures cdo 1.6.6 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1461,7 +1461,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of cdo 1.6.5.1:";;
+     short | recursive ) echo "Configuration of cdo 1.6.6:";;
    esac
   cat <<\_ACEOF
 
@@ -1615,7 +1615,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-cdo configure 1.6.5.1
+cdo configure 1.6.6
 generated by GNU Autoconf 2.68
 
 Copyright (C) 2010 Free Software Foundation, Inc.
@@ -2208,7 +2208,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by cdo $as_me 1.6.5.1, which was
+It was created by cdo $as_me 1.6.6, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   $ $0 $@
@@ -3151,7 +3151,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='cdo'
- VERSION='1.6.5.1'
+ VERSION='1.6.6'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -20765,11 +20765,13 @@ fi
 done
 
 
-ac_config_files="$ac_config_files test/Read_netcdf.test test/Cat.test test/Gridarea.test test/Genweights.test test/Remap.test"
+ac_config_files="$ac_config_files test/Read_grib.test test/Read_netcdf.test test/Copy_netcdf.test"
+
+ac_config_files="$ac_config_files test/Cat.test test/Gridarea.test test/Genweights.test test/Remap.test"
 
 ac_config_files="$ac_config_files test/Select.test test/Spectral.test test/Timstat.test test/Vertint.test"
 
-ac_config_files="$ac_config_files test/Detrend.test"
+ac_config_files="$ac_config_files test/Detrend.test test/Arith.test"
 
 ac_config_files="$ac_config_files Makefile src/Makefile contrib/Makefile test/Makefile test/data/Makefile cdo.spec cdo.settings"
 
@@ -21347,7 +21349,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by cdo $as_me 1.6.5.1, which was
+This file was extended by cdo $as_me 1.6.6, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -21413,7 +21415,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-cdo config.status 1.6.5.1
+cdo config.status 1.6.6
 configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
 
@@ -21920,7 +21922,9 @@ do
     "src/config.h") CONFIG_HEADERS="$CONFIG_HEADERS src/config.h" ;;
     "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
     "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
+    "test/Read_grib.test") CONFIG_FILES="$CONFIG_FILES test/Read_grib.test" ;;
     "test/Read_netcdf.test") CONFIG_FILES="$CONFIG_FILES test/Read_netcdf.test" ;;
+    "test/Copy_netcdf.test") CONFIG_FILES="$CONFIG_FILES test/Copy_netcdf.test" ;;
     "test/Cat.test") CONFIG_FILES="$CONFIG_FILES test/Cat.test" ;;
     "test/Gridarea.test") CONFIG_FILES="$CONFIG_FILES test/Gridarea.test" ;;
     "test/Genweights.test") CONFIG_FILES="$CONFIG_FILES test/Genweights.test" ;;
@@ -21930,6 +21934,7 @@ do
     "test/Timstat.test") CONFIG_FILES="$CONFIG_FILES test/Timstat.test" ;;
     "test/Vertint.test") CONFIG_FILES="$CONFIG_FILES test/Vertint.test" ;;
     "test/Detrend.test") CONFIG_FILES="$CONFIG_FILES test/Detrend.test" ;;
+    "test/Arith.test") CONFIG_FILES="$CONFIG_FILES test/Arith.test" ;;
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
     "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
     "contrib/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/Makefile" ;;
@@ -23422,7 +23427,9 @@ compiler_lib_search_path=$lt_compiler_lib_search_path_CXX
 _LT_EOF
 
  ;;
+    "test/Read_grib.test":F) chmod a+x "$ac_file" ;;
     "test/Read_netcdf.test":F) chmod a+x "$ac_file" ;;
+    "test/Copy_netcdf.test":F) chmod a+x "$ac_file" ;;
     "test/Cat.test":F) chmod a+x "$ac_file" ;;
     "test/Gridarea.test":F) chmod a+x "$ac_file" ;;
     "test/Genweights.test":F) chmod a+x "$ac_file" ;;
@@ -23432,6 +23439,7 @@ _LT_EOF
     "test/Timstat.test":F) chmod a+x "$ac_file" ;;
     "test/Vertint.test":F) chmod a+x "$ac_file" ;;
     "test/Detrend.test":F) chmod a+x "$ac_file" ;;
+    "test/Arith.test":F) chmod a+x "$ac_file" ;;
 
   esac
 done # for ac_tag
diff --git a/configure.ac b/configure.ac
index c2ddf3e..135647b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,7 +4,7 @@
 #  autoconf 2.68
 #  libtool  2.4.2
 
-AC_INIT([cdo], [1.6.5.1], [http://code.zmaw.de/projects/cdo])
+AC_INIT([cdo], [1.6.6], [http://code.zmaw.de/projects/cdo])
 
 CONFIG_ABORT=yes
 AC_CONFIG_AUX_DIR(config)
@@ -214,9 +214,10 @@ AC_DEFINE_UNQUOTED(COMPILER, ["$COMPILER"], [Compiler])
 AC_REQUIRE_AUX_FILE([tap-driver.sh])
 AC_PROG_AWK
 
-AC_CONFIG_FILES([test/Read_netcdf.test test/Cat.test test/Gridarea.test test/Genweights.test test/Remap.test],[chmod a+x "$ac_file"])
+AC_CONFIG_FILES([test/Read_grib.test test/Read_netcdf.test test/Copy_netcdf.test],[chmod a+x "$ac_file"])
+AC_CONFIG_FILES([test/Cat.test test/Gridarea.test test/Genweights.test test/Remap.test],[chmod a+x "$ac_file"])
 AC_CONFIG_FILES([test/Select.test test/Spectral.test test/Timstat.test test/Vertint.test],[chmod a+x "$ac_file"])
-AC_CONFIG_FILES([test/Detrend.test],[chmod a+x "$ac_file"])
+AC_CONFIG_FILES([test/Detrend.test test/Arith.test],[chmod a+x "$ac_file"])
 AC_CONFIG_FILES([Makefile src/Makefile contrib/Makefile test/Makefile test/data/Makefile cdo.spec cdo.settings])
 AC_OUTPUT
 
diff --git a/contrib/cdoCompletion.bash b/contrib/cdoCompletion.bash
index 55b8f2b..83b100c 100644
--- a/contrib/cdoCompletion.bash
+++ b/contrib/cdoCompletion.bash
@@ -572,6 +572,7 @@ sp2fc -sp2fc \
 sp2gp -sp2gp \
 sp2gpl -sp2gpl \
 sp2sp -sp2sp \
+spartab -spartab \
 spcut -spcut \
 specinfo -specinfo \
 spectrum -spectrum \
diff --git a/contrib/cdoCompletion.tcsh b/contrib/cdoCompletion.tcsh
index 296225b..6ec31a3 100644
--- a/contrib/cdoCompletion.tcsh
+++ b/contrib/cdoCompletion.tcsh
@@ -572,6 +572,7 @@ sp2fc \
 sp2gp \
 sp2gpl \
 sp2sp \
+spartab \
 spcut \
 specinfo \
 spectrum \
diff --git a/contrib/cdoCompletion.zsh b/contrib/cdoCompletion.zsh
index f7c551c..7f46403 100644
--- a/contrib/cdoCompletion.zsh
+++ b/contrib/cdoCompletion.zsh
@@ -572,6 +572,7 @@ sp2fc -sp2fc \
 sp2gp -sp2gp \
 sp2gpl -sp2gpl \
 sp2sp -sp2sp \
+spartab -spartab \
 spcut -spcut \
 specinfo -specinfo \
 spectrum -spectrum \
diff --git a/doc/cdo.pdf b/doc/cdo.pdf
index abe6e3b..fd7e3c7 100644
Binary files a/doc/cdo.pdf and b/doc/cdo.pdf differ
diff --git a/doc/cdo_refcard.pdf b/doc/cdo_refcard.pdf
index d161726..3ddd244 100644
Binary files a/doc/cdo_refcard.pdf and b/doc/cdo_refcard.pdf differ
diff --git a/libcdi/ChangeLog b/libcdi/ChangeLog
index f063a7b..7474812 100644
--- a/libcdi/ChangeLog
+++ b/libcdi/ChangeLog
@@ -1,3 +1,31 @@
+2014-11-27  Uwe Schulzweida
+
+	* Version 1.6.6 released
+
+2014-11-20  Uwe Schulzweida
+
+	* table::decodeForm1: missing longname results in Abort trap (bug fix)
+
+2014-11-14  Uwe Schulzweida
+
+	* cdfCopyRecord: removed limit for datasize
+
+2014-11-12  Uwe Schulzweida
+
+	* Version 1.6.5.2 released
+
+2014-11-12  Uwe Schulzweida
+
+	* transpose2dArrayXX: wrong result (bug fix)
+
+2014-11-08  Uwe Schulzweida
+
+	* cgribexScanTimestep1: set flag to 0 in call to cgribexVarCompare() (bug fix)
+
+2014-11-05  Uwe Schulzweida
+
+	* IEG: added support for coordinate scale factor [patch from Kevin Sieck]
+
 2014-10-31  Uwe Schulzweida
 
 	* Version 1.6.5.1 released
@@ -39,7 +67,7 @@
 
 2014-08-21  Uwe Schulzweida
 
-	* reshGetElem: call show_stackframe() to print a backtrace 
+	* reshGetElem: call show_stackframe() to print a backtrace
 
 2014-08-20  Uwe Schulzweida
 
diff --git a/libcdi/Makefile.in b/libcdi/Makefile.in
index 8d3d571..705f5ce 100644
--- a/libcdi/Makefile.in
+++ b/libcdi/Makefile.in
@@ -338,6 +338,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
 THREADS_LIBS = @THREADS_LIBS@
 USER_NAME = @USER_NAME@
 USE_MPI = @USE_MPI@
+UUID_C_LIB = @UUID_C_LIB@
 VERSION = @VERSION@
 YAXT_CFLAGS = @YAXT_CFLAGS@
 YAXT_LIBS = @YAXT_LIBS@
diff --git a/libcdi/NEWS b/libcdi/NEWS
index 2d77819..9a15890 100644
--- a/libcdi/NEWS
+++ b/libcdi/NEWS
@@ -1,6 +1,17 @@
 CDI NEWS
 --------
 
+Version 1.6.6 (27 November 2014):
+
+   New features:
+     * IEG: added support for coordinate scale factor
+   Fixed bugs:
+     * table::decodeForm1: missing longname results in Abort trap
+     * transpose2dArrayXX: wrong result
+     * cgribexScanTimestep1: set flag to 0 in call to cgribexVarCompare()
+     * netCDF: call set_validrangeDP() in cdfReadVar()
+     * netCDF: call cdfDoInputDataTransformation() if have missvals
+
 Version 1.6.5 (23 October 2014):
 
    New features:
diff --git a/libcdi/app/Makefile.in b/libcdi/app/Makefile.in
index 34c4624..1bfdd48 100644
--- a/libcdi/app/Makefile.in
+++ b/libcdi/app/Makefile.in
@@ -311,6 +311,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
 THREADS_LIBS = @THREADS_LIBS@
 USER_NAME = @USER_NAME@
 USE_MPI = @USE_MPI@
+UUID_C_LIB = @UUID_C_LIB@
 VERSION = @VERSION@
 YAXT_CFLAGS = @YAXT_CFLAGS@
 YAXT_LIBS = @YAXT_LIBS@
diff --git a/libcdi/app/cdi.c b/libcdi/app/cdi.c
index c14cf03..1df9da2 100644
--- a/libcdi/app/cdi.c
+++ b/libcdi/app/cdi.c
@@ -33,6 +33,13 @@ int      vlistInqVarMissvalUsed(int vlistID, int varID);
 #endif
 
 
+static inline int
+cdiUUIDIsNull(const unsigned char uuid[CDI_UUID_SIZE])
+{
+  static unsigned char uuid_nil[CDI_UUID_SIZE];
+  return !memcmp(uuid, uuid_nil, CDI_UUID_SIZE);
+}
+
 #include "printinfo.h"
 
 void cdiDefTableID(int tableID);
@@ -161,7 +168,7 @@ void usage(void)
 
 
 static
-void printInfo(int gridtype, int vdate, int vtime, char *varname, double level,
+void printInfo(int vdate, int vtime, char *varname, double level,
 	       int datasize, int number, int nmiss, double missval, const double *data, int vardis)
 {
   static int rec = 0;
@@ -190,13 +197,6 @@ void printInfo(int gridtype, int vdate, int vtime, char *varname, double level,
 
   fprintf(stdout, "%7d :", nmiss);
 
-  /*
-  if ( gridtype == GRID_SPECTRAL )
-    {
-      fprintf(stdout, "            %#12.5g\n", data[0]);
-    }
-  else
-  */
   if ( number == CDI_REAL )
     {
       if ( nmiss > 0 )
@@ -325,7 +325,7 @@ void printShortinfo(int streamID, int vlistID, int vardis)
   int tsteptype, taxisID;
   char tmpname[CDI_MAX_NAME];
   char varname[CDI_MAX_NAME];
-  char *modelptr, *instptr;
+  const char *modelptr, *instptr;
   int datatype;
   int year, month, day, hour, minute, second;
   char pstr[4];
@@ -374,6 +374,7 @@ void printShortinfo(int streamID, int vlistID, int vardis)
 	  else if ( tsteptype == TSTEP_INSTANT3 ) fprintf(stdout, "%-8s ", "instant");
 	  else if ( tsteptype == TSTEP_MIN      ) fprintf(stdout, "%-8s ", "min");
 	  else if ( tsteptype == TSTEP_MAX      ) fprintf(stdout, "%-8s ", "max");
+	  else if ( tsteptype == TSTEP_AVG      ) fprintf(stdout, "%-8s ", "avg");
 	  else if ( tsteptype == TSTEP_ACCUM    ) fprintf(stdout, "%-8s ", "accum");
 	  else if ( tsteptype == TSTEP_RANGE    ) fprintf(stdout, "%-8s ", "range");
 	  else if ( tsteptype == TSTEP_DIFF     ) fprintf(stdout, "%-8s ", "diff");
@@ -417,10 +418,11 @@ void printShortinfo(int streamID, int vlistID, int vardis)
 
 	  cdiParamToString(param, paramstr, sizeof(paramstr));
 
-	  if ( vardis ) vlistInqVarName(vlistID, varID, varname);
-
-          if ( vardis )
-	    fprintf(stdout, "%-11s", varname);
+	  if (vardis)
+            {
+              vlistInqVarName(vlistID, varID, varname);
+              fprintf(stdout, "%-11s", varname);
+            }
 	  else
 	    fprintf(stdout, "%-11s", paramstr);
 
@@ -827,7 +829,6 @@ int main(int argc, char *argv[])
       int tsID;
       int ntsteps = 0;
       int taxisID1, taxisID2 = CDI_UNDEFID;
-      int gridtype;
       int vlistID1, vlistID2 = CDI_UNDEFID;
 
       streamID1 = streamOpenRead(fname1);
@@ -850,8 +851,9 @@ int main(int argc, char *argv[])
       taxisID1 = vlistInqTaxis(vlistID1);
       ntsteps = vlistNtsteps(vlistID1);
 
-      if ( Debug ) fprintf(stderr, "nvars   = %d\n", nvars);
-      if ( Debug ) fprintf(stderr, "ntsteps = %d\n", ntsteps);
+      if (Debug)
+        fprintf(stderr, "nvars   = %d\n"
+                "ntsteps = %d\n", nvars, ntsteps);
 
       if ( fname2 )
         {
@@ -904,11 +906,10 @@ int main(int argc, char *argv[])
       /*
 	nts = cdiInqTimeSize(streamID1);
       */
-      if ( Debug )
-	printf("nts = %d\n", nts);
-
-      if ( Debug )
-	printf("streamID1 = %d, streamID2 = %d\n", streamID1, streamID2);
+      if (Debug)
+	printf("nts = %d\n"
+               "streamID1 = %d, streamID2 = %d\n",
+               nts, streamID1, streamID2);
 
       if ( Shortinfo )
 	{
@@ -951,13 +952,12 @@ int main(int argc, char *argv[])
 		  printf("varID=%d, param=%d, gridID=%d, zaxisID=%d levelID=%d\n",
 			 varID, param, gridID, zaxisID, levelID);
 		  */
-		  gridtype = gridInqType(gridID);
 		  gridsize = gridInqSize(gridID);
 		  level    = zaxisInqLevel(zaxisID, levelID);
 		  missval  = vlistInqVarMissval(vlistID1, varID);
 
 		  if ( Info )
-		    printInfo(gridtype, vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
+		    printInfo(vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
 
 		  if ( fname2 )
 		    {
@@ -989,7 +989,6 @@ int main(int argc, char *argv[])
 		    fprintf(stdout, "varID = %d param = %d gridID = %d zaxisID = %d\n",
 			    varID, param, gridID, zaxisID);
 
-		  gridtype = gridInqType(gridID);
 		  gridsize = gridInqSize(gridID);
 		  missval  = vlistInqVarMissval(vlistID1, varID);
 
@@ -1000,7 +999,7 @@ int main(int argc, char *argv[])
 		      streamReadVarSlice(streamID1, varID, levelID, data, &nmiss);
 
 		      if ( Info )
-			printInfo(gridtype, vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
+			printInfo(vdate, vtime, varname, level, gridsize, number, nmiss, missval, data, Vardis);
 
 		      if ( fname2 )
 			streamWriteVarSlice(streamID2, varID, levelID, data, nmiss);
diff --git a/libcdi/app/printinfo.h b/libcdi/app/printinfo.h
index 46a03d0..20611fa 100644
--- a/libcdi/app/printinfo.h
+++ b/libcdi/app/printinfo.h
@@ -1,7 +1,7 @@
 #define DATE_FORMAT "%5.4d-%2.2d-%2.2d"
 #define TIME_FORMAT "%2.2d:%2.2d:%2.2d"
 
-void uuid2str(const char *uuid, char *uuidstr);
+void uuid2str(const unsigned char uuid[CDI_UUID_SIZE], char *uuidstr);
 
 void date2str(int date, char *datestr, int maxlen)
 {
@@ -135,7 +135,7 @@ void printGridInfo(int vlistID)
   int ngrids, index;
   int gridID, gridtype, trunc, gridsize, xsize, ysize, xysize;
   char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME];
-  char uuidOfHGrid[17];
+  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
 
   ngrids = vlistNgrids(vlistID);
   for ( index = 0; index < ngrids; index++ )
@@ -229,8 +229,7 @@ void printGridInfo(int vlistID)
 	  if ( gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
 	    {
 	      fprintf(stdout, "%33s :", "available");
-	      if ( gridInqXbounds(gridID, NULL) ) fprintf(stdout, " xbounds");
-	      if ( gridInqYbounds(gridID, NULL) ) fprintf(stdout, " ybounds");
+	      if ( gridInqXbounds(gridID, NULL) && gridInqYbounds(gridID, NULL) ) fprintf(stdout, " cellbounds");
 	      if ( gridHasArea(gridID) )          fprintf(stdout, " area");
 	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
 	      fprintf(stdout, "\n");
@@ -303,8 +302,8 @@ void printGridInfo(int vlistID)
 	      int i;
 	      double *xvals, *yvals;
 	      double xfirst, xlast, yfirst, ylast;
-	      xvals = (double *)malloc((size_t)gridsize * sizeof (double));
-	      yvals = (double *)malloc((size_t)gridsize * sizeof (double));
+	      xvals = (double*) malloc((size_t)gridsize*sizeof(double));
+	      yvals = (double*) malloc((size_t)gridsize*sizeof(double));
 
 	      gridInqXvals(gridID, xvals);
 	      gridInqYvals(gridID, yvals);
@@ -357,14 +356,11 @@ void printGridInfo(int vlistID)
 
       if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED || gridtype == GRID_LCC )
 	{
-	  if ( gridInqXvals(gridID, NULL) || gridInqYvals(gridID, NULL) || gridHasArea(gridID) ||
+	  if ( gridHasArea(gridID) ||
 	       gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
 	    {
 	      fprintf(stdout, "%33s :", "available");
-	      if ( gridInqXvals(gridID, NULL) )   fprintf(stdout, " xvals");
-	      if ( gridInqYvals(gridID, NULL) )   fprintf(stdout, " yvals");
-	      if ( gridInqXbounds(gridID, NULL) ) fprintf(stdout, " xbounds");
-	      if ( gridInqYbounds(gridID, NULL) ) fprintf(stdout, " ybounds");
+	      if ( gridInqXbounds(gridID, NULL) && gridInqYbounds(gridID, NULL) ) fprintf(stdout, " cellbounds");
 	      if ( gridHasArea(gridID) )          fprintf(stdout, " area");
 	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
 	      fprintf(stdout, "\n");
@@ -372,7 +368,7 @@ void printGridInfo(int vlistID)
 	}
 
       gridInqUUID(gridID, uuidOfHGrid);
-      if ( uuidOfHGrid[0] != 0 )
+      if ( !cdiUUIDIsNull(uuidOfHGrid) )
         {
           char uuidOfHGridStr[37];
           uuid2str(uuidOfHGrid, uuidOfHGridStr);
@@ -414,7 +410,7 @@ void printZaxisInfo(int vlistID)
       fprintf(stdout, " levels=%d", levelsize);
       fprintf(stdout, "\n");
 
-      levels = (double*) malloc(levelsize*sizeof(double));
+      levels = (double*) malloc((size_t)levelsize*sizeof(double));
       zaxisInqLevels(zaxisID, levels);
 
       if ( !(zaxistype == ZAXIS_SURFACE && levelsize == 1 && !(fabs(levels[0]) > 0)) )
@@ -473,9 +469,9 @@ void printZaxisInfo(int vlistID)
               fprintf(stdout, "number = %d\n", number);
             }
 
-          char uuidOfVGrid[17];
+          unsigned char uuidOfVGrid[CDI_UUID_SIZE];
           zaxisInqUUID(zaxisID, uuidOfVGrid);
-          if ( uuidOfVGrid[0] != 0 )
+          if ( !cdiUUIDIsNull(uuidOfVGrid) )
             {
               char uuidOfVGridStr[37];
               uuid2str(uuidOfVGrid, uuidOfVGridStr);
diff --git a/libcdi/configure b/libcdi/configure
index 65181f2..726aef4 100755
--- a/libcdi/configure
+++ b/libcdi/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for cdi 1.6.5.1.
+# Generated by GNU Autoconf 2.68 for cdi 1.6.6.
 #
 # Report bugs to <http://code.zmaw.de/projects/cdi>.
 #
@@ -570,8 +570,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='cdi'
 PACKAGE_TARNAME='cdi'
-PACKAGE_VERSION='1.6.5.1'
-PACKAGE_STRING='cdi 1.6.5.1'
+PACKAGE_VERSION='1.6.6'
+PACKAGE_STRING='cdi 1.6.6'
 PACKAGE_BUGREPORT='http://code.zmaw.de/projects/cdi'
 PACKAGE_URL=''
 
@@ -660,6 +660,8 @@ PKG_CONFIG_LIBDIR
 PKG_CONFIG_PATH
 PKG_CONFIG
 MPI_LAUNCH
+ENABLE_NETCDF_FALSE
+ENABLE_NETCDF_TRUE
 ENABLE_ALL_STATIC_FALSE
 ENABLE_ALL_STATIC_TRUE
 ENABLE_CDI_LIB
@@ -699,6 +701,7 @@ ax_pthread_config
 SYSTEM_TYPE
 HOST_NAME
 USER_NAME
+UUID_C_LIB
 AS
 CXXCPP
 am__fastdepCXX_FALSE
@@ -1445,7 +1448,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures cdi 1.6.5.1 to adapt to many kinds of systems.
+\`configure' configures cdi 1.6.6 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1515,7 +1518,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of cdi 1.6.5.1:";;
+     short | recursive ) echo "Configuration of cdi 1.6.6:";;
    esac
   cat <<\_ACEOF
 
@@ -1702,7 +1705,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-cdi configure 1.6.5.1
+cdi configure 1.6.6
 generated by GNU Autoconf 2.68
 
 Copyright (C) 2010 Free Software Foundation, Inc.
@@ -2463,7 +2466,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by cdi $as_me 1.6.5.1, which was
+It was created by cdi $as_me 1.6.6, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   $ $0 $@
@@ -3408,7 +3411,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='cdi'
- VERSION='1.6.5.1'
+ VERSION='1.6.6'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -15593,14 +15596,10 @@ fi
   for ac_fpp in `cd $srcdir ; pwd`/util/sxpreproc-wrapper \
            `cd $srcdir ; pwd`/util/xlfpreproc-wrapper \
            `cd $srcdir ; pwd`/util/sunf95preproc-wrapper \
-           "$FC -F" "$FC -F -fpp" "$FC -E" "$FC -E" "$FC -E -cpp" \
+           `cd $srcdir ; pwd`/util/crayftnpreproc-wrapper \
+           "$FC -F" "$FC -F -fpp" "$FC -E" "$FC -E -cpp" \
            "$FC $FCFLAGS -F" "$FC $FCFLAGS -E" "$FC $FCFLAGS -E" \
-           "$FC $FCFLAGS -E -cpp" "$FC $FCFLAGS -x f95-cpp-input -E -P" \
-           "${F77-f77} -F" "${F77-f77} -E" 'fpp' \
-           "$CPP -std=c89" "$CPP -x c -std=c89" 'cpp -std=c89' '/lib/cpp - std=c89' \
-           '/usr/ccs/lib/cpp -std=c89' 'g77 -E -std=c89' '${CC-cc} -E -std=c89' \
-           "$CPP" "$CPP -x c" 'cpp' '/lib/cpp' \
-           '/usr/ccs/lib/cpp' 'g77 -E' '${CC-cc} -E'
+           "$FC $FCFLAGS -E -cpp" "$FC $FCFLAGS -x f95-cpp-input -E -P"
          do
            rm -f conftest*
 
@@ -15691,7 +15690,7 @@ $as_echo "$ac_try_echo"; } >&5
   $as_echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-                         FPP="$ac_fpp -P"
+            FPP="$ac_fpp -P"
               break
 else
              $as_echo "$as_me: failed program was:" >&5
@@ -24327,24 +24326,13 @@ fi
 
 #  ----------------------------------------------------------------------
 # Checks for header files
-for ac_header in malloc.h
+for ac_header in malloc.h execinfo.h uuid.h uuid/uuid.h
 do :
-  ac_fn_c_check_header_mongrel "$LINENO" "malloc.h" "ac_cv_header_malloc_h" "$ac_includes_default"
-if test "x$ac_cv_header_malloc_h" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_MALLOC_H 1
-_ACEOF
-
-fi
-
-done
-
-for ac_header in execinfo.h
-do :
-  ac_fn_c_check_header_mongrel "$LINENO" "execinfo.h" "ac_cv_header_execinfo_h" "$ac_includes_default"
-if test "x$ac_cv_header_execinfo_h" = xyes; then :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
   cat >>confdefs.h <<_ACEOF
-#define HAVE_EXECINFO_H 1
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
 
 fi
@@ -24375,6 +24363,89 @@ _ACEOF
 fi
 done
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uuid_generate in -luuid" >&5
+$as_echo_n "checking for uuid_generate in -luuid... " >&6; }
+if ${ac_cv_lib_uuid_uuid_generate+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-luuid  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char uuid_generate ();
+int
+main ()
+{
+return uuid_generate ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_uuid_uuid_generate=yes
+else
+  ac_cv_lib_uuid_uuid_generate=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_uuid_uuid_generate" >&5
+$as_echo "$ac_cv_lib_uuid_uuid_generate" >&6; }
+if test "x$ac_cv_lib_uuid_uuid_generate" = xyes; then :
+  ac_fn_c_check_decl "$LINENO" "uuid_generate" "ac_cv_have_decl_uuid_generate" "$ac_includes_default
+#include <uuid/uuid.h>
+"
+if test "x$ac_cv_have_decl_uuid_generate" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_UUID_GENERATE $ac_have_decl
+_ACEOF
+if test $ac_have_decl = 1; then :
+  UUID_C_LIB=-luuid
+fi
+
+else
+  for ac_func in uuid_create
+do :
+  ac_fn_c_check_func "$LINENO" "uuid_create" "ac_cv_func_uuid_create"
+if test "x$ac_cv_func_uuid_create" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_UUID_CREATE 1
+_ACEOF
+ ac_fn_c_check_decl "$LINENO" "uuid_create" "ac_cv_have_decl_uuid_create" "$ac_includes_default
+#include <uuid.h>
+"
+if test "x$ac_cv_have_decl_uuid_create" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_UUID_CREATE $ac_have_decl
+_ACEOF
+if test $ac_have_decl = 1; then :
+  UUID_C_LIB=""
+fi
+
+fi
+done
+
+fi
+
+
 #  ----------------------------------------------------------------------
 # Checks for the availability of ANSI-C99 functions
 ac_fn_c_check_decl "$LINENO" "isnan" "ac_cv_have_decl_isnan" "$ac_includes_default
@@ -26974,6 +27045,14 @@ else
 fi
 
 
+ if test x$ENABLE_NETCDF = xyes; then
+  ENABLE_NETCDF_TRUE=
+  ENABLE_NETCDF_FALSE='#'
+else
+  ENABLE_NETCDF_TRUE='#'
+  ENABLE_NETCDF_FALSE=
+fi
+
 #  ----------------------------------------------------------------------
 # Compile with MPI support
 # Check whether --enable-mpi was given.
@@ -27994,7 +28073,7 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
-ac_config_files="$ac_config_files tests/test_cksum_grib tests/test_cksum_nc tests/test_cksum_nc2 tests/test_cksum_nc4 tests/test_cksum_extra tests/test_cksum_service tests/test_cksum_ieg tests/test_chunk_cksum tests/test_f2003 tests/pio_write_run tests/pio_write_deco2d_run tests/pio_cksum_mpinonb tests/pio_cksum_fpguard tests/pio_cksum_asynch tests/pio_cksum_writer tests/pio_cksum_cdf tests/test_resource_copy_mpi_run tables/gen_tableheaderfile util/serialrun"
+ac_config_files="$ac_config_files tests/test_cksum_grib tests/test_cksum_nc tests/test_cksum_nc2 tests/test_cksum_nc4 tests/test_cksum_extra tests/test_cksum_service tests/test_cksum_ieg tests/test_chunk_cksum tests/test_f2003 tests/pio_write_run tests/pio_write_deco2d_run tests/pio_cksum_mpinonb tests/pio_cksum_fpguard tests/pio_cksum_asynch tests/pio_cksum_writer tests/pio_cksum_cdf tests/test_resource_copy_mpi_run tests/test_cdf_transformation tables/gen_tableheaderfile util/serialrun"
 
 
 ac_config_files="$ac_config_files Makefile src/Makefile interfaces/Makefile app/Makefile tests/Makefile examples/Makefile cdi.settings examples/pio/Makefile src/pkgconfig/cdi.pc src/pkgconfig/cdipio.pc"
@@ -28149,6 +28228,10 @@ if test -z "${ENABLE_ALL_STATIC_TRUE}" && test -z "${ENABLE_ALL_STATIC_FALSE}";
   as_fn_error $? "conditional \"ENABLE_ALL_STATIC\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${ENABLE_NETCDF_TRUE}" && test -z "${ENABLE_NETCDF_FALSE}"; then
+  as_fn_error $? "conditional \"ENABLE_NETCDF\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${USE_MPI_TRUE}" && test -z "${USE_MPI_FALSE}"; then
   as_fn_error $? "conditional \"USE_MPI\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
@@ -28598,7 +28681,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by cdi $as_me 1.6.5.1, which was
+This file was extended by cdi $as_me 1.6.6, which was
 generated by GNU Autoconf 2.68.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -28664,7 +28747,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-cdi config.status 1.6.5.1
+cdi config.status 1.6.6
 configured by $0, generated by GNU Autoconf 2.68,
   with options \\"\$ac_cs_config\\"
 
@@ -29360,6 +29443,7 @@ do
     "tests/pio_cksum_writer") CONFIG_FILES="$CONFIG_FILES tests/pio_cksum_writer" ;;
     "tests/pio_cksum_cdf") CONFIG_FILES="$CONFIG_FILES tests/pio_cksum_cdf" ;;
     "tests/test_resource_copy_mpi_run") CONFIG_FILES="$CONFIG_FILES tests/test_resource_copy_mpi_run" ;;
+    "tests/test_cdf_transformation") CONFIG_FILES="$CONFIG_FILES tests/test_cdf_transformation" ;;
     "tables/gen_tableheaderfile") CONFIG_FILES="$CONFIG_FILES tables/gen_tableheaderfile" ;;
     "util/serialrun") CONFIG_FILES="$CONFIG_FILES util/serialrun" ;;
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
@@ -31180,6 +31264,7 @@ _LT_EOF
     "tests/pio_cksum_writer":F) chmod a+x "$ac_file" ;;
     "tests/pio_cksum_cdf":F) chmod a+x "$ac_file" ;;
     "tests/test_resource_copy_mpi_run":F) chmod a+x "$ac_file" ;;
+    "tests/test_cdf_transformation":F) chmod a+x "$ac_file" ;;
     "tables/gen_tableheaderfile":F) chmod a+x "$ac_file" ;;
     "util/serialrun":F) chmod a+x "$ac_file" ;;
 
diff --git a/libcdi/configure.ac b/libcdi/configure.ac
index 8d8bfc5..27f0311 100644
--- a/libcdi/configure.ac
+++ b/libcdi/configure.ac
@@ -4,7 +4,7 @@
 #  autoconf 2.68
 #  libtool  2.4.2
 
-AC_INIT([cdi], [1.6.5.1], [http://code.zmaw.de/projects/cdi])
+AC_INIT([cdi], [1.6.6], [http://code.zmaw.de/projects/cdi])
 
 echo "configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}"
 
@@ -64,12 +64,20 @@ AC_CHECK_LIB(malloc, malloc)
 AC_CHECK_MEMBERS([struct stat.st_blksize])
 #  ----------------------------------------------------------------------
 # Checks for header files
-AC_CHECK_HEADERS(malloc.h)
-AC_CHECK_HEADERS(execinfo.h)
+AC_CHECK_HEADERS([malloc.h execinfo.h uuid.h uuid/uuid.h])
 #  ----------------------------------------------------------------------
 # Checks for the availability of functions
 AC_CHECK_FUNCS([mallinfo])
 AC_CHECK_FUNCS([getline])
+AC_CHECK_LIB([uuid],[uuid_generate],
+  [AC_CHECK_DECLS([uuid_generate],
+  [UUID_C_LIB=-luuid],,[AC_INCLUDES_DEFAULT
+@%:@include <uuid/uuid.h>])],
+  [AC_CHECK_FUNCS([uuid_create],
+     [AC_CHECK_DECLS([uuid_create],
+        [UUID_C_LIB=""],,[AC_INCLUDES_DEFAULT
+@%:@include <uuid.h>])])])
+AC_SUBST([UUID_C_LIB])
 #  ----------------------------------------------------------------------
 # Checks for the availability of ANSI-C99 functions
 AC_CHECK_DECLS([isnan],,,[AC_INCLUDES_DEFAULT
@@ -116,6 +124,7 @@ AC_CHECK_LIB(m, floor)
 #  ----------------------------------------------------------------------
 # Add basic configure options
 ACX_OPTIONS
+AM_CONDITIONAL([ENABLE_NETCDF],[test x$ENABLE_NETCDF = xyes])
 #  ----------------------------------------------------------------------
 # Compile with MPI support
 AC_ARG_ENABLE(mpi,AS_HELP_STRING([--enable-mpi],[Compile with MPI compiler [default=no]]),enable_mpi=yes,enable_mpi=no)
@@ -351,6 +360,7 @@ AC_CONFIG_FILES([tests/test_cksum_grib \
                  tests/pio_cksum_writer \
                  tests/pio_cksum_cdf \
                  tests/test_resource_copy_mpi_run \
+                 tests/test_cdf_transformation \
                  tables/gen_tableheaderfile \
                  util/serialrun],[chmod a+x "$ac_file"])
 
diff --git a/libcdi/examples/Makefile.in b/libcdi/examples/Makefile.in
index e66719a..40f33e0 100644
--- a/libcdi/examples/Makefile.in
+++ b/libcdi/examples/Makefile.in
@@ -359,6 +359,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
 THREADS_LIBS = @THREADS_LIBS@
 USER_NAME = @USER_NAME@
 USE_MPI = @USE_MPI@
+UUID_C_LIB = @UUID_C_LIB@
 VERSION = @VERSION@
 YAXT_CFLAGS = @YAXT_CFLAGS@
 YAXT_LIBS = @YAXT_LIBS@
diff --git a/libcdi/examples/pio/Makefile.in b/libcdi/examples/pio/Makefile.in
index 7c5c04a..4d51a50 100644
--- a/libcdi/examples/pio/Makefile.in
+++ b/libcdi/examples/pio/Makefile.in
@@ -353,6 +353,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
 THREADS_LIBS = @THREADS_LIBS@
 USER_NAME = @USER_NAME@
 USE_MPI = @USE_MPI@
+UUID_C_LIB = @UUID_C_LIB@
 VERSION = @VERSION@
 YAXT_CFLAGS = @YAXT_CFLAGS@
 YAXT_LIBS = @YAXT_LIBS@
diff --git a/libcdi/examples/pio/collectData.c b/libcdi/examples/pio/collectData.c
index 677934f..f532a9d 100644
--- a/libcdi/examples/pio/collectData.c
+++ b/libcdi/examples/pio/collectData.c
@@ -82,20 +82,20 @@ static void modelRun(MPI_Comm commModel)
       varID[i] = vlistDefVar ( vlistID, gridID, zaxisID[i], TIME_VARIABLE );
 #ifdef USE_MPI
       {
-         int start = uniform_partition_start((int [2]){ 0, varSize[i] - 1 },
+        int start = uniform_partition_start((int [2]){ 0, (int)varSize[i] - 1 },
                                              comm_size, rank),
-           chunkSize = uniform_partition_start((int [2]){ 0, varSize[i] - 1 },
-                                               comm_size, rank + 1) - start;
-         fprintf(stderr, "%d: start=%d, chunkSize = %d\n", rank,
-                 start, chunkSize);
-         Xt_idxlist idxlist
-           = xt_idxstripes_new(&(struct Xt_stripe){ .start = start,
-                 .nstrides = chunkSize, .stride = 1 }, 1);
-         varDeco[i] = (struct var1DDeco){
-           .start = start,
-           .chunkSize = chunkSize,
-           .partDesc = idxlist
-         };
+          chunkSize = uniform_partition_start((int [2]){ 0, (int)varSize[i] - 1 },
+                                              comm_size, rank + 1) - start;
+        fprintf(stderr, "%d: start=%d, chunkSize = %d\n", rank,
+                start, chunkSize);
+        Xt_idxlist idxlist
+          = xt_idxstripes_new(&(struct Xt_stripe){ .start = start,
+                .nstrides = chunkSize, .stride = 1 }, 1);
+        varDeco[i] = (struct var1DDeco){
+          .start = start,
+          .chunkSize = chunkSize,
+          .partDesc = idxlist
+        };
       }
 #endif
     }
@@ -172,6 +172,21 @@ static struct {
   { "PIO_WRITER", PIO_WRITER },
   { "PIO_FPGUARD", PIO_FPGUARD},
 };
+
+static inline int
+search_iomode_str(const char *modestr)
+{
+  int retval = -1;
+  for (size_t i = 0;
+       i < sizeof (mode_map) / sizeof (mode_map[0]);
+       ++i)
+    if (!strcmp(modestr, mode_map[i].text))
+      {
+        retval = (int)i;
+        break;
+      }
+  return retval;
+}
 #endif
 
 
@@ -197,25 +212,24 @@ int main (int argc, char *argv[])
       switch (opt) {
       case 'p':
         {
-          int i, found=0;
-          for (i = 0;
-               i < sizeof (mode_map) / sizeof (mode_map[0]);
-               ++i)
-            if (!strcmp(optarg, mode_map[i].text))
-              {
-                found = 1;
-                IOMode = mode_map[i].mode;
-              }
-          if (!found)
+          int entry = search_iomode_str(optarg);
+          if (entry < 0)
             {
               fprintf(stderr, "Unsupported PIO mode requested: %s\n", optarg);
               exit(EXIT_FAILURE);
             }
+          IOMode = mode_map[entry].mode;
         }
         break;
       case 'w':
         {
-          nProcsIO = strtol(optarg, NULL, 0);
+          long temp = strtol(optarg, NULL, 0);
+          if (temp < 0 || temp > INT_MAX/2)
+            {
+              fprintf(stderr, "Unsupported number of I/O servers: %ld\n", temp);
+              exit(EXIT_FAILURE);
+            }
+          nProcsIO = (int)temp;
           break;
         }
       }
@@ -244,8 +258,8 @@ static int
 uniform_partition_start(int set_interval[2], int nparts, int part_idx)
 {
   int part_offset
-    = (((long long)set_interval[1] - (long long)set_interval[0] + 1LL)
-       * (long long)part_idx) / (long long)nparts;
+    = (int)((((long long)set_interval[1] - (long long)set_interval[0] + 1LL)
+             * (long long)part_idx) / (long long)nparts);
   int start = set_interval[0] + part_offset;
   return start;
 }
diff --git a/libcdi/examples/pio/collectData2003.F90 b/libcdi/examples/pio/collectData2003.F90
index 25d2019..70e5fee 100644
--- a/libcdi/examples/pio/collectData2003.F90
+++ b/libcdi/examples/pio/collectData2003.F90
@@ -1,7 +1,8 @@
 PROGRAM collectdata2003
 #ifdef USE_MPI
   USE yaxt, ONLY: xt_initialize, xt_finalize, xt_idxlist, xt_idxstripes_new, &
-       xt_idxlist_delete, xt_int_kind, xt_stripe
+       xt_idxlist_delete, xi => xt_int_kind, xt_stripe
+  USE iso_c_binding, ONLY: c_int
 #endif
 
   IMPLICIT NONE
@@ -25,16 +26,17 @@ PROGRAM collectdata2003
   ! INTEGER, PARAMETER :: IOMode       = PIO_ASYNCH
   INTEGER, PARAMETER :: IOMode       = PIO_FPGUARD
 
-  INTEGER ::commGlob, commModel, error, pio_namespace
+  INTEGER :: commModel
 #ifdef USE_MPI
   LOGICAL :: run_model
+  INTEGER :: commGlob, ierror, pio_namespace
 #else
   LOGICAL, PARAMETER :: run_model = .TRUE.
 #endif
 
   ! Start parallel environment
 #ifdef USE_MPI
-  CALL MPI_INIT ( error )
+  CALL MPI_INIT ( ierror )
   commGlob = MPI_COMM_WORLD
   CALL xt_initialize(commGlob)
 
@@ -44,6 +46,8 @@ PROGRAM collectdata2003
        cdiPioNoPostCommSetup)
   run_model = commModel /= MPI_COMM_NULL
   IF (run_model) CALL namespaceSetActive(pio_namespace)
+#else
+  commModel = 0
 #endif
 
   IF (run_model) CALL modelrun ( commModel )
@@ -53,7 +57,7 @@ PROGRAM collectdata2003
   ! Cleanup environment.
   IF (run_model) CALL pioFinalize ()
   CALL xt_finalize
-  CALL MPI_FINALIZE ( error )
+  CALL MPI_FINALIZE ( ierror )
 #endif
 
 CONTAINS
@@ -76,9 +80,9 @@ CONTAINS
     DOUBLE PRECISION :: lons ( nlon ), lats ( nlat ), levs ( nlev )
     DOUBLE PRECISION :: var1 ( nlon * nlat ), var2 ( nlon * nlat * nlev )
     CHARACTER(len=256) :: varname
-    INTEGER :: last, start, chunk
+    INTEGER :: last, start
 #ifdef USE_MPI
-    INTEGER :: rank, comm_size, ierror
+    INTEGER :: rank, comm_size, ierror, chunk
     TYPE var1ddeco
       INTEGER :: start, chunksize
       TYPE(xt_idxlist) :: partdesc
@@ -122,12 +126,14 @@ CONTAINS
     chunk = uniform_partition_start((/ 1, SIZE(var1) /), comm_size, rank + 2) &
          - start
     vardeco1 = var1ddeco(start, chunk, &
-         xt_idxstripes_new(xt_stripe(start - 1, chunk, 1)))
+         xt_idxstripes_new(xt_stripe(INT(start, xi) - 1_xi, 1_xi, &
+         INT(chunk, c_int))))
     start = uniform_partition_start((/ 1, SIZE(var2) /), comm_size, rank + 1)
     chunk = uniform_partition_start((/ 1, SIZE(var2) /), comm_size, rank + 2) &
          - start
     vardeco2 = var1ddeco(start, chunk, &
-         xt_idxstripes_new(xt_stripe(start - 1, chunk, 1)))
+         xt_idxstripes_new(xt_stripe(INT(start, xi) - 1_xi, 1_xi, &
+         INT(chunk, c_int))))
 #endif
     !     Define the variable names
     varname = 'varname1'
@@ -228,6 +234,8 @@ CONTAINS
     CALL zaxisDestroy(zaxisID2)
     CALL gridDestroy(gridID)
 #ifdef USE_MPI
+    CALL xt_idxlist_delete(vardeco1%partdesc)
+    CALL xt_idxlist_delete(vardeco2%partdesc)
     CALL mpi_barrier(commModel, ierror)
     IF (ierror /= mpi_success) STOP 1
 #endif
diff --git a/libcdi/examples/pio/collectDataNStreams.c b/libcdi/examples/pio/collectDataNStreams.c
index 2257f0c..8f8b048 100644
--- a/libcdi/examples/pio/collectDataNStreams.c
+++ b/libcdi/examples/pio/collectDataNStreams.c
@@ -108,9 +108,9 @@ static void modelRun(MPI_Comm commModel)
         varSize[i][j] = nlon * nlat * (size_t)nlev[i][j];
 #ifdef USE_MPI
         {
-          int start = uniform_partition_start((int [2]){ 0, varSize[i][j] - 1 },
+          int start = uniform_partition_start((int [2]){ 0, (int)varSize[i][j] - 1 },
                                               comm_size, rank),
-            chunkSize = uniform_partition_start((int [2]){ 0, varSize[i][j] - 1 },
+            chunkSize = uniform_partition_start((int [2]){ 0, (int)varSize[i][j] - 1 },
                                                 comm_size, rank + 1) - start;
           if (maxChunkSize < chunkSize)
             maxChunkSize = chunkSize;
@@ -289,8 +289,8 @@ static int
 uniform_partition_start(int set_interval[2], int nparts, int part_idx)
 {
   int part_offset
-    = (((long long)set_interval[1] - (long long)set_interval[0] + 1LL)
-       * (long long)part_idx) / (long long)nparts;
+    = (int)((((long long)set_interval[1] - (long long)set_interval[0] + 1LL)
+             * (long long)part_idx) / (long long)nparts);
   int start = set_interval[0] + part_offset;
   return start;
 }
diff --git a/libcdi/examples/pio/compareResourcesArray.c b/libcdi/examples/pio/compareResourcesArray.c
index f7e0b9f..e97daa9 100644
--- a/libcdi/examples/pio/compareResourcesArray.c
+++ b/libcdi/examples/pio/compareResourcesArray.c
@@ -206,7 +206,7 @@ static void modelRun ( MPI_Comm comm )
 
   reshPackBufferCreate(&sendBuffer, &bufferSize, &comm);
   xmpi ( MPI_Send ( sendBuffer, bufferSize, MPI_PACKED, 0, 0, comm ));
-  recvBuffer = xmalloc ( bufferSize * sizeof ( char ));
+  recvBuffer = xmalloc((size_t)bufferSize);
   xmpi ( MPI_Recv ( recvBuffer, bufferSize, MPI_PACKED, 0,
 		    0, comm, &status ));
 
diff --git a/libcdi/interfaces/Makefile.in b/libcdi/interfaces/Makefile.in
index 7d159d6..49846b5 100644
--- a/libcdi/interfaces/Makefile.in
+++ b/libcdi/interfaces/Makefile.in
@@ -337,6 +337,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
 THREADS_LIBS = @THREADS_LIBS@
 USER_NAME = @USER_NAME@
 USE_MPI = @USE_MPI@
+UUID_C_LIB = @UUID_C_LIB@
 VERSION = @VERSION@
 YAXT_CFLAGS = @YAXT_CFLAGS@
 YAXT_LIBS = @YAXT_LIBS@
diff --git a/libcdi/interfaces/f2003/bindGen.rb b/libcdi/interfaces/f2003/bindGen.rb
index 9e99357..68dc32b 100755
--- a/libcdi/interfaces/f2003/bindGen.rb
+++ b/libcdi/interfaces/f2003/bindGen.rb
@@ -145,7 +145,7 @@ def isBadFunction(returnType, returnPointer, paramList)
       CFTypeInfo[ctype].nil? or                        # derived data type
       param == '*' or                                  # unnamed pointer
       param[0,2] == '**' or                            # pointer2pointer
-      (param[0,1] == '*' and /\w\[\d*\]/.match(param)) # array of pointers
+      (param[0,1] == '*' and /\w\[\w*\]/.match(param)) # array of pointers
     )
   }
   return false
@@ -173,10 +173,10 @@ def setFortranParams(paramswithtypes,fFuncname)
       # remove '*' from funcnames and paramnames
       param.sub!('*','')
     end
-    if ( md = /\w\[(\d*)\]/.match(param); not md.nil? )
+    if ( md = /\w\[(\w*)\]/.match(param); not md.nil? )
       isArray   = true
       arraySize = md[1] == '' ? '*' : md[1]
-      param.tr!("[#{md[1]}]",'')
+      param[md.begin(1)-1,md.end(1)-1] = ''
     end
 
     # change param name if it equals the funcname
diff --git a/libcdi/m4/starlink_fpp.m4 b/libcdi/m4/starlink_fpp.m4
index 49c9e41..423ede9 100644
--- a/libcdi/m4/starlink_fpp.m4
+++ b/libcdi/m4/starlink_fpp.m4
@@ -293,7 +293,7 @@ dnl preprocessing failed. So this command doesn't work.
 # _ACX_SL_PROG_FPP([SUFFIX], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
 # ------------
 # Try to figure out how to preprocess files with the given suffix
-# for use with the selected Fortran compiler
+# just like the selected Fortran compiler does
 #
 # Must be run after _ACX_SL_PROG_FC_CPP
 AC_DEFUN([_ACX_SL_PROG_FPP],dnl
@@ -313,18 +313,14 @@ AC_DEFUN([_ACX_SL_PROG_FPP],dnl
         [for ac_fpp in `cd $srcdir ; pwd`/util/sxpreproc-wrapper \
            `cd $srcdir ; pwd`/util/xlfpreproc-wrapper \
            `cd $srcdir ; pwd`/util/sunf95preproc-wrapper \
-           "$FC -F" "$FC -F -fpp" "$FC -E" "$FC -E" "$FC -E -cpp" \
+           `cd $srcdir ; pwd`/util/crayftnpreproc-wrapper \
+           "$FC -F" "$FC -F -fpp" "$FC -E" "$FC -E -cpp" \
            "$FC $FCFLAGS -F" "$FC $FCFLAGS -E" "$FC $FCFLAGS -E" \
-           "$FC $FCFLAGS -E -cpp" "$FC $FCFLAGS -x f95-cpp-input -E -P" \
-           "${F77-f77} -F" "${F77-f77} -E" 'fpp' \
-           "$CPP -std=c89" "$CPP -x c -std=c89" 'cpp -std=c89' '/lib/cpp - std=c89' \
-           '/usr/ccs/lib/cpp -std=c89' 'g77 -E -std=c89' '${CC-cc} -E -std=c89' \
-           "$CPP" "$CPP -x c" 'cpp' '/lib/cpp' \
-           '/usr/ccs/lib/cpp' 'g77 -E' '${CC-cc} -E'
+           "$FC $FCFLAGS -E -cpp" "$FC $FCFLAGS -x f95-cpp-input -E -P"
          do
            _ACX_SL_TEST_FPP([$ac_fpp],[$acx_sl_fpp_srcext],[FPP="$ac_fpp"
               break])
-           _ACX_SL_TEST_FPP([$ac_fpp -P],[$acx_sl_fpp_srcext],dnl
+           _ACX_SL_TEST_FPP([$ac_fpp -P],[$acx_sl_fpp_srcext],
              [FPP="$ac_fpp -P"
               break])
          done
diff --git a/libcdi/src/Makefile.am b/libcdi/src/Makefile.am
index 4e83286..387609c 100644
--- a/libcdi/src/Makefile.am
+++ b/libcdi/src/Makefile.am
@@ -2,11 +2,13 @@
 #
 EXTRA_DIST = cdilib.c mo_cdi.f90
 
+noinst_LTLIBRARIES = libcdiresunpack.la
+
 if ENABLE_CDI_LIB
   lib_LTLIBRARIES = libcdi.la
   include_HEADERS = cdi.h cdi.inc
 else
-  noinst_LTLIBRARIES = libcdi.la
+  noinst_LTLIBRARIES += libcdi.la
 endif
 
 AM_CFLAGS = $(PPM_CORE_CFLAGS) $(YAXT_CFLAGS)
@@ -109,6 +111,9 @@ libcdi_la_SOURCES = 	 \
         stream.c         \
         swap.c
 
+libcdiresunpack_la_SOURCES = \
+	resource_unpack.c
+
 if USE_MPI
 if ENABLE_CDI_LIB
 lib_LTLIBRARIES += libcdipio.la
diff --git a/libcdi/src/Makefile.in b/libcdi/src/Makefile.in
index 43d1c37..cc58a8e 100644
--- a/libcdi/src/Makefile.in
+++ b/libcdi/src/Makefile.in
@@ -79,17 +79,18 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
- at ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am__append_1 = libcdipio.la
- at ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am__append_2 = cdipio.h cdipio.inc
- at ENABLE_CDI_LIB_FALSE@@USE_MPI_TRUE at am__append_3 = libcdipio.la
- at ENABLE_CDI_LIB_TRUE@am__append_4 = pkgconfig/cdi.pc
- at ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am__append_5 = pkgconfig/cdipio.pc
- at CREATE_ISOC_TRUE@am__append_6 = mo_cdi.$(OBJEXT)
+ at ENABLE_CDI_LIB_FALSE@am__append_1 = libcdi.la
+ at ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am__append_2 = libcdipio.la
+ at ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am__append_3 = cdipio.h cdipio.inc
+ at ENABLE_CDI_LIB_FALSE@@USE_MPI_TRUE at am__append_4 = libcdipio.la
+ at ENABLE_CDI_LIB_TRUE@am__append_5 = pkgconfig/cdi.pc
+ at ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am__append_6 = pkgconfig/cdipio.pc
+ at CREATE_ISOC_TRUE@am__append_7 = mo_cdi.$(OBJEXT)
 #CLEANFILES += cdilib.c
- at CREATE_ISOC_TRUE@am__append_7 = mo_cdi.$(FCMODEXT) mo_cdi.$(OBJEXT) mo_cdi.f90
- at ENABLE_CDI_LIB_TRUE@am__append_8 = pkgconfig/cdi.pc
- at ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am__append_9 = pkgconfig/cdipio.pc
+ at CREATE_ISOC_TRUE@am__append_8 = mo_cdi.$(FCMODEXT) mo_cdi.$(OBJEXT) mo_cdi.f90
+ at ENABLE_CDI_LIB_TRUE@am__append_9 = pkgconfig/cdi.pc
 @ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am__append_10 = pkgconfig/cdipio.pc
+ at ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am__append_11 = pkgconfig/cdipio.pc
 subdir = src
 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
 	$(srcdir)/config.h.in $(top_srcdir)/config/mkinstalldirs \
@@ -176,6 +177,9 @@ libcdipio_la_OBJECTS = $(am_libcdipio_la_OBJECTS)
 @ENABLE_CDI_LIB_FALSE@@USE_MPI_TRUE at am_libcdipio_la_rpath =
 @ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE at am_libcdipio_la_rpath = -rpath \
 @ENABLE_CDI_LIB_TRUE@@USE_MPI_TRUE@	$(libdir)
+libcdiresunpack_la_LIBADD =
+am_libcdiresunpack_la_OBJECTS = resource_unpack.lo
+libcdiresunpack_la_OBJECTS = $(am_libcdiresunpack_la_OBJECTS)
 AM_V_P = $(am__v_P_ at AM_V@)
 am__v_P_ = $(am__v_P_ at AM_DEFAULT_V@)
 am__v_P_0 = false
@@ -210,8 +214,10 @@ AM_V_CCLD = $(am__v_CCLD_ at AM_V@)
 am__v_CCLD_ = $(am__v_CCLD_ at AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
-SOURCES = $(libcdi_la_SOURCES) $(libcdipio_la_SOURCES)
-DIST_SOURCES = $(libcdi_la_SOURCES) $(libcdipio_la_SOURCES)
+SOURCES = $(libcdi_la_SOURCES) $(libcdipio_la_SOURCES) \
+	$(libcdiresunpack_la_SOURCES)
+DIST_SOURCES = $(libcdi_la_SOURCES) $(libcdipio_la_SOURCES) \
+	$(libcdiresunpack_la_SOURCES)
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
     n|no|NO) false;; \
@@ -364,6 +370,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
 THREADS_LIBS = @THREADS_LIBS@
 USER_NAME = @USER_NAME@
 USE_MPI = @USE_MPI@
+UUID_C_LIB = @UUID_C_LIB@
 VERSION = @VERSION@
 YAXT_CFLAGS = @YAXT_CFLAGS@
 YAXT_LIBS = @YAXT_LIBS@
@@ -429,9 +436,10 @@ top_srcdir = @top_srcdir@
 
 #
 EXTRA_DIST = cdilib.c mo_cdi.f90
- at ENABLE_CDI_LIB_TRUE@lib_LTLIBRARIES = libcdi.la $(am__append_1)
- at ENABLE_CDI_LIB_TRUE@include_HEADERS = cdi.h cdi.inc $(am__append_2)
- at ENABLE_CDI_LIB_FALSE@noinst_LTLIBRARIES = libcdi.la $(am__append_3)
+noinst_LTLIBRARIES = libcdiresunpack.la $(am__append_1) \
+	$(am__append_4)
+ at ENABLE_CDI_LIB_TRUE@lib_LTLIBRARIES = libcdi.la $(am__append_2)
+ at ENABLE_CDI_LIB_TRUE@include_HEADERS = cdi.h cdi.inc $(am__append_3)
 AM_CFLAGS = $(PPM_CORE_CFLAGS) $(YAXT_CFLAGS)
 libcdi_la_SOURCES = \
 	basetime.c     	 \
@@ -531,6 +539,9 @@ libcdi_la_SOURCES = \
         stream.c         \
         swap.c
 
+libcdiresunpack_la_SOURCES = \
+	resource_unpack.c
+
 libcdipio_la_SOURCES = \
 	cdipio.h							\
 	cdipioFortran.c							\
@@ -573,11 +584,11 @@ libcdi_la_LIBADD =
 #
 #cdilib.o: cdilib.c
 #	$(COMPILE) -c $<
-LOCALTARGETS = $(am__append_4) $(am__append_5) $(am__append_6)
+LOCALTARGETS = $(am__append_5) $(am__append_6) $(am__append_7)
 #
-CLEANFILES = `ls *~` $(am__append_7) $(am__append_8) $(am__append_9)
+CLEANFILES = `ls *~` $(am__append_8) $(am__append_9) $(am__append_10)
 @ENABLE_CDI_LIB_TRUE at PKGCONFIG_FILES = pkgconfig/cdi.pc \
- at ENABLE_CDI_LIB_TRUE@	$(am__append_10)
+ at ENABLE_CDI_LIB_TRUE@	$(am__append_11)
 all: config.h
 	$(MAKE) $(AM_MAKEFLAGS) all-am
 
@@ -681,6 +692,9 @@ libcdi.la: $(libcdi_la_OBJECTS) $(libcdi_la_DEPENDENCIES) $(EXTRA_libcdi_la_DEPE
 libcdipio.la: $(libcdipio_la_OBJECTS) $(libcdipio_la_DEPENDENCIES) $(EXTRA_libcdipio_la_DEPENDENCIES) 
 	$(AM_V_CCLD)$(LINK) $(am_libcdipio_la_rpath) $(libcdipio_la_OBJECTS) $(libcdipio_la_LIBADD) $(LIBS)
 
+libcdiresunpack.la: $(libcdiresunpack_la_OBJECTS) $(libcdiresunpack_la_DEPENDENCIES) $(EXTRA_libcdiresunpack_la_DEPENDENCIES) 
+	$(AM_V_CCLD)$(LINK)  $(libcdiresunpack_la_OBJECTS) $(libcdiresunpack_la_LIBADD) $(LIBS)
+
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
 
diff --git a/libcdi/src/cdi.h b/libcdi/src/cdi.h
index 170a171..61085eb 100644
--- a/libcdi/src/cdi.h
+++ b/libcdi/src/cdi.h
@@ -218,6 +218,8 @@ extern "C" {
 #define  CALENDAR_366DAYS         4
 #define  CALENDAR_NONE            5
 
+/* number of unsigned char needed to store UUID */
+#define  CDI_UUID_SIZE           16
 
 /* CDI control routines */
 
@@ -262,6 +264,8 @@ int     cdiEncodeTime(int hour, int minute, int second);
 
 /* STREAM control routines */
 
+int     cdiGetFiletype(const char *path, int *byteorder);
+
 /*      streamOpenRead: Open a dataset for reading */
 int     streamOpenRead(const char *path);
 
@@ -316,7 +320,6 @@ int     streamInqCurTimestepID(int streamID);
 
 char   *streamFilename(int streamID);
 char   *streamFilesuffix(int filetype);
-int     streamNtsteps(int streamID);
 off_t   streamNvals(int streamID);
 
 int     streamInqNvars ( int streamID );
@@ -742,10 +745,10 @@ void    gridDefReference(int gridID, const char *reference);
 int     gridInqReference(int gridID, char *reference);
 
 /*      gridDefUUID: Define the UUID of an unstructured grid */
-void    gridDefUUID(int gridID, const char *uuid_cbuf);
+void    gridDefUUID(int gridID, const unsigned char uuid[CDI_UUID_SIZE]);
 
 /*      gridInqUUID: Get the UUID of an unstructured grid */
-void    gridInqUUID(int gridID, char *uuid_cbuf);
+void    gridInqUUID(int gridID, unsigned char uuid[CDI_UUID_SIZE]);
 
 
 /* Lambert Conformal Conic grid (GRIB version) */
@@ -783,7 +786,7 @@ void    gridDefYbounds(int gridID, const double *ybounds_vec);
 /*      gridInqYbounds: Get the bounds of a Y-axis */
 int     gridInqYbounds(int gridID, double *ybounds_vec);
 
-void    gridDefRowlon(int gridID, int nrowlon, const int *rowlon_vec);
+void    gridDefRowlon(int gridID, int nrowlon, const int rowlon_vec[]);
 void    gridInqRowlon(int gridID, int *rowlon_vec);
 void    gridChangeType(int gridID, int gridtype);
 
@@ -838,10 +841,10 @@ void    zaxisDefNumber(int gridID, int number);
 int     zaxisInqNumber(int gridID);
 
 /*      zaxisDefUUID: Define the UUID of a generalized Z-axis */
-void    zaxisDefUUID(int zaxisID, const char *uuid_cbuf);
+void    zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE]);
 
 /*      zaxisInqUUID: Get the UUID of a generalized Z-axis */
-void    zaxisInqUUID(int zaxisID, char *uuid_cbuf);
+void    zaxisInqUUID(int zaxisID, unsigned char uuid[CDI_UUID_SIZE]);
 
 /*      zaxisDefName: Define the name of a Z-axis */
 void    zaxisDefName(int zaxisID, const char *name);
@@ -981,7 +984,7 @@ int     institutInq(int center, int subcenter, const char *name, const char *lon
 int     institutInqNumber(void);
 int     institutInqCenter(int instID);
 int     institutInqSubcenter(int instID);
-char   *institutInqNamePtr(int instID);
+const char *institutInqNamePtr(int instID);
 char   *institutInqLongnamePtr(int instID);
 
 /* Model routines */
@@ -990,7 +993,7 @@ int     modelDef(int instID, int modelgribID, const char *name);
 int     modelInq(int instID, int modelgribID, char *name);
 int     modelInqInstitut(int modelID);
 int     modelInqGribID(int modelID);
-char   *modelInqNamePtr(int modelID);
+const char *modelInqNamePtr(int modelID);
 
 /* Table routines */
 
diff --git a/libcdi/src/cdi.inc b/libcdi/src/cdi.inc
index 11d9993..022964b 100644
--- a/libcdi/src/cdi.inc
+++ b/libcdi/src/cdi.inc
@@ -1,10 +1,10 @@
 ! This file was automatically generated, don't edit!
 !
-! Fortran interface for CDI library version 1.6.4
+! Fortran interface for CDI library version 1.6.6
 !
 ! Author:
 ! -------
-! Uwe Schulzweida, MPI-MET, Hamburg,   September 2014
+! Uwe Schulzweida, MPI-MET, Hamburg,   November 2014
 !
 
       INTEGER    CDI_MAX_NAME          
@@ -370,6 +370,11 @@
       INTEGER    CALENDAR_NONE         
       PARAMETER (CALENDAR_NONE          =  5)
 !
+!  number of unsigned char needed to store UUID
+!
+      INTEGER    CDI_UUID_SIZE         
+      PARAMETER (CDI_UUID_SIZE          = 16)
+!
 !  CDI control routines
 !
 !                     cdiReset
@@ -476,6 +481,11 @@
 !
 !  STREAM control routines
 !
+      INTEGER         cdiGetFiletype
+!                                    (CHARACTER*(*)   path,
+!                                     INTEGER         byteorder)
+      EXTERNAL        cdiGetFiletype
+
       INTEGER         streamOpenRead
 !                                    (CHARACTER*(*)   path)
       EXTERNAL        streamOpenRead
@@ -566,10 +576,6 @@
 !                                    (INTEGER         filetype)
       EXTERNAL        streamFilesuffix
 
-      INTEGER         streamNtsteps
-!                                    (INTEGER         streamID)
-      EXTERNAL        streamNtsteps
-
       INTEGER         streamInqNvars
 !                                    (INTEGER         streamID)
       EXTERNAL        streamInqNvars
@@ -1656,12 +1662,12 @@
 
 !                     gridDefUUID
 !                                    (INTEGER         gridID,
-!                                     CHARACTER*(*)   uuid_cbuf)
+!                                     INTEGER*1(16)   uuid)
       EXTERNAL        gridDefUUID
 
 !                     gridInqUUID
 !                                    (INTEGER         gridID,
-!                                     CHARACTER*(*)   uuid_cbuf)
+!                                     INTEGER*1(16)   uuid)
       EXTERNAL        gridInqUUID
 
 !
@@ -1878,12 +1884,12 @@
 
 !                     zaxisDefUUID
 !                                    (INTEGER         zaxisID,
-!                                     CHARACTER*(*)   uuid_cbuf)
+!                                     INTEGER*1(16)   uuid)
       EXTERNAL        zaxisDefUUID
 
 !                     zaxisInqUUID
 !                                    (INTEGER         zaxisID,
-!                                     CHARACTER*(*)   uuid_cbuf)
+!                                     INTEGER*1(16)   uuid)
       EXTERNAL        zaxisInqUUID
 
 !                     zaxisDefName
diff --git a/libcdi/src/cdiFortran.c b/libcdi/src/cdiFortran.c
index ad1767a..e69d3ce 100644
--- a/libcdi/src/cdiFortran.c
+++ b/libcdi/src/cdiFortran.c
@@ -57,6 +57,9 @@
 /*  CALENDAR types  */
 
 
+/*  number of unsigned char needed to store UUID  */
+
+
 /*  CDI control routines  */
 
 FCALLSCSUB0 (cdiReset, CDIRESET, cdireset)
@@ -93,6 +96,7 @@ FCALLSCFUN3 (INT, cdiEncodeTime, CDIENCODETIME, cdiencodetime, INT, INT, INT)
 
 /*  STREAM control routines  */
 
+FCALLSCFUN2 (INT, cdiGetFiletype, CDIGETFILETYPE, cdigetfiletype, STRING, PINT)
 FCALLSCFUN1 (INT, streamOpenRead, STREAMOPENREAD, streamopenread, STRING)
 FCALLSCFUN2 (INT, streamOpenWrite, STREAMOPENWRITE, streamopenwrite, STRING, INT)
 FCALLSCFUN1 (INT, streamOpenAppend, STREAMOPENAPPEND, streamopenappend, STRING)
@@ -116,7 +120,6 @@ FCALLSCFUN2 (INT, streamInqTimestep, STREAMINQTIMESTEP, streaminqtimestep, INT,
 FCALLSCFUN1 (INT, streamInqCurTimestepID, STREAMINQCURTIMESTEPID, streaminqcurtimestepid, INT)
 FCALLSCFUN1 (STRING, streamFilename, STREAMFILENAME, streamfilename, INT)
 FCALLSCFUN1 (STRING, streamFilesuffix, STREAMFILESUFFIX, streamfilesuffix, INT)
-FCALLSCFUN1 (INT, streamNtsteps, STREAMNTSTEPS, streamntsteps, INT)
 FCALLSCFUN1 (INT, streamInqNvars, STREAMINQNVARS, streaminqnvars, INT)
 
 /*  STREAM var I/O routines  */
@@ -344,8 +347,8 @@ FCALLSCSUB2 (gridDefPosition, GRIDDEFPOSITION, griddefposition, INT, INT)
 FCALLSCFUN1 (INT, gridInqPosition, GRIDINQPOSITION, gridinqposition, INT)
 FCALLSCSUB2 (gridDefReference, GRIDDEFREFERENCE, griddefreference, INT, STRING)
 FCALLSCFUN2 (INT, gridInqReference, GRIDINQREFERENCE, gridinqreference, INT, PSTRING)
-FCALLSCSUB2 (gridDefUUID, GRIDDEFUUID, griddefuuid, INT, PPSTRING)
-FCALLSCSUB2 (gridInqUUID, GRIDINQUUID, gridinquuid, INT, PPSTRING)
+FCALLSCSUB2 (gridDefUUID, GRIDDEFUUID, griddefuuid, INT, PVOID)
+FCALLSCSUB2 (gridInqUUID, GRIDINQUUID, gridinquuid, INT, PVOID)
 
 /*  Lambert Conformal Conic grid (GRIB version)  */
 
@@ -370,7 +373,7 @@ FCALLSCSUB2 (gridDefXbounds, GRIDDEFXBOUNDS, griddefxbounds, INT, PDOUBLE)
 FCALLSCFUN2 (INT, gridInqXbounds, GRIDINQXBOUNDS, gridinqxbounds, INT, PDOUBLE)
 FCALLSCSUB2 (gridDefYbounds, GRIDDEFYBOUNDS, griddefybounds, INT, PDOUBLE)
 FCALLSCFUN2 (INT, gridInqYbounds, GRIDINQYBOUNDS, gridinqybounds, INT, PDOUBLE)
-FCALLSCSUB3 (gridDefRowlon, GRIDDEFROWLON, griddefrowlon, INT, INT, PINT)
+FCALLSCSUB3 (gridDefRowlon, GRIDDEFROWLON, griddefrowlon, INT, INT, INTV)
 FCALLSCSUB2 (gridInqRowlon, GRIDINQROWLON, gridinqrowlon, INT, PINT)
 FCALLSCSUB2 (gridChangeType, GRIDCHANGETYPE, gridchangetype, INT, INT)
 FCALLSCSUB2 (gridDefComplexPacking, GRIDDEFCOMPLEXPACKING, griddefcomplexpacking, INT, INT)
@@ -394,8 +397,8 @@ FCALLSCSUB2 (zaxisDefNlevRef, ZAXISDEFNLEVREF, zaxisdefnlevref, INT, INT)
 FCALLSCFUN1 (INT, zaxisInqNlevRef, ZAXISINQNLEVREF, zaxisinqnlevref, INT)
 FCALLSCSUB2 (zaxisDefNumber, ZAXISDEFNUMBER, zaxisdefnumber, INT, INT)
 FCALLSCFUN1 (INT, zaxisInqNumber, ZAXISINQNUMBER, zaxisinqnumber, INT)
-FCALLSCSUB2 (zaxisDefUUID, ZAXISDEFUUID, zaxisdefuuid, INT, PPSTRING)
-FCALLSCSUB2 (zaxisInqUUID, ZAXISINQUUID, zaxisinquuid, INT, PPSTRING)
+FCALLSCSUB2 (zaxisDefUUID, ZAXISDEFUUID, zaxisdefuuid, INT, PVOID)
+FCALLSCSUB2 (zaxisInqUUID, ZAXISINQUUID, zaxisinquuid, INT, PVOID)
 FCALLSCSUB2 (zaxisDefName, ZAXISDEFNAME, zaxisdefname, INT, STRING)
 FCALLSCSUB2 (zaxisInqName, ZAXISINQNAME, zaxisinqname, INT, PSTRING)
 FCALLSCSUB2 (zaxisDefLongname, ZAXISDEFLONGNAME, zaxisdeflongname, INT, STRING)
diff --git a/libcdi/src/cdi_int.c b/libcdi/src/cdi_int.c
index 3b9e462..a915d73 100644
--- a/libcdi/src/cdi_int.c
+++ b/libcdi/src/cdi_int.c
@@ -160,7 +160,7 @@ void cdiDebug(int level)
 
   if ( level == 1 || (level & 16) )
     {
-#if  defined  (HAVE_LIBGRIB)
+#if  defined  (HAVE_LIBCGRIBEX)
       gribSetDebug(1);
 #endif
 #if  defined  (HAVE_LIBNETCDF)
diff --git a/libcdi/src/cdi_int.h b/libcdi/src/cdi_int.h
index 6580eee..ba3bf51 100644
--- a/libcdi/src/cdi_int.h
+++ b/libcdi/src/cdi_int.h
@@ -65,6 +65,8 @@ char *strdup(const char *s);
 #  include "resource_handle.h"
 #endif
 
+#include "cdi.h"
+
 
 #define check_parg(arg)  if ( arg == 0 ) Warning("Argument '" #arg "' not allocated!")
 
@@ -86,7 +88,7 @@ char *strdup(const char *s);
 
 #ifndef DBL_IS_EQUAL
 /*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
-#  define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
+#  define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)):!(x < y || y < x))
 #endif
 
 #ifndef IS_EQUAL
@@ -340,8 +342,15 @@ void    streamGetIndexList ( int, int * );
 
 void  cdiInitialize(void);
 
-void uuid2str(const char *uuid, char *uuidstr);
-void str2uuid(const char *uuidstr, char *uuid);
+void uuid2str(const unsigned char *uuid, char *uuidstr);
+int str2uuid(const char *uuidstr, unsigned char *uuid);
+static inline int
+cdiUUIDIsNull(const unsigned char uuid[CDI_UUID_SIZE])
+{
+  static unsigned char uuid_nil[CDI_UUID_SIZE];
+  return !memcmp(uuid, uuid_nil, CDI_UUID_SIZE);
+}
+
 
 #define CDI_UNIT_PA   1
 #define CDI_UNIT_HPA  2
diff --git a/libcdi/src/cdilib.c b/libcdi/src/cdilib.c
index 374932f..f7a8a36 100644
--- a/libcdi/src/cdilib.c
+++ b/libcdi/src/cdilib.c
@@ -1,7 +1,7 @@
 
-/* Automatically generated by m214003 at 2014-10-31, do not edit */
+/* Automatically generated by m214003 at 2014-11-25, do not edit */
 
-/* CDILIB_VERSION="1.6.5.1" */
+/* CDILIB_VERSION="1.6.6" */
 
 #ifdef _ARCH_PWR6
 #pragma options nostrict
@@ -521,6 +521,7 @@ int  extDefDataDP(void *ext, const double *data);
 #define  IEG_G_ScanFlag(x)    (x[13])
 #define  IEG_G_LatSP(x)       (x[16])  /*  Latitude of the southern pole of rotation    */
 #define  IEG_G_LonSP(x)       (x[17])  /*  Longitude of the southern pole of rotation   */
+#define  IEG_G_ResFac(x)      (x[18])  /*  Resolution factor                            */
 
 
 typedef struct {
@@ -791,6 +792,8 @@ extern "C" {
 #define  CALENDAR_366DAYS         4
 #define  CALENDAR_NONE            5
 
+/* number of unsigned char needed to store UUID */
+#define  CDI_UUID_SIZE           16
 
 /* CDI control routines */
 
@@ -835,6 +838,8 @@ int     cdiEncodeTime(int hour, int minute, int second);
 
 /* STREAM control routines */
 
+int     cdiGetFiletype(const char *path, int *byteorder);
+
 /*      streamOpenRead: Open a dataset for reading */
 int     streamOpenRead(const char *path);
 
@@ -889,7 +894,6 @@ int     streamInqCurTimestepID(int streamID);
 
 char   *streamFilename(int streamID);
 char   *streamFilesuffix(int filetype);
-int     streamNtsteps(int streamID);
 off_t   streamNvals(int streamID);
 
 int     streamInqNvars ( int streamID );
@@ -1315,10 +1319,10 @@ void    gridDefReference(int gridID, const char *reference);
 int     gridInqReference(int gridID, char *reference);
 
 /*      gridDefUUID: Define the UUID of an unstructured grid */
-void    gridDefUUID(int gridID, const char *uuid_cbuf);
+void    gridDefUUID(int gridID, const unsigned char uuid[CDI_UUID_SIZE]);
 
 /*      gridInqUUID: Get the UUID of an unstructured grid */
-void    gridInqUUID(int gridID, char *uuid_cbuf);
+void    gridInqUUID(int gridID, unsigned char uuid[CDI_UUID_SIZE]);
 
 
 /* Lambert Conformal Conic grid (GRIB version) */
@@ -1356,7 +1360,7 @@ void    gridDefYbounds(int gridID, const double *ybounds_vec);
 /*      gridInqYbounds: Get the bounds of a Y-axis */
 int     gridInqYbounds(int gridID, double *ybounds_vec);
 
-void    gridDefRowlon(int gridID, int nrowlon, const int *rowlon_vec);
+void    gridDefRowlon(int gridID, int nrowlon, const int rowlon_vec[]);
 void    gridInqRowlon(int gridID, int *rowlon_vec);
 void    gridChangeType(int gridID, int gridtype);
 
@@ -1411,10 +1415,10 @@ void    zaxisDefNumber(int gridID, int number);
 int     zaxisInqNumber(int gridID);
 
 /*      zaxisDefUUID: Define the UUID of a generalized Z-axis */
-void    zaxisDefUUID(int zaxisID, const char *uuid_cbuf);
+void    zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE]);
 
 /*      zaxisInqUUID: Get the UUID of a generalized Z-axis */
-void    zaxisInqUUID(int zaxisID, char *uuid_cbuf);
+void    zaxisInqUUID(int zaxisID, unsigned char uuid[CDI_UUID_SIZE]);
 
 /*      zaxisDefName: Define the name of a Z-axis */
 void    zaxisDefName(int zaxisID, const char *name);
@@ -1554,7 +1558,7 @@ int     institutInq(int center, int subcenter, const char *name, const char *lon
 int     institutInqNumber(void);
 int     institutInqCenter(int instID);
 int     institutInqSubcenter(int instID);
-char   *institutInqNamePtr(int instID);
+const char *institutInqNamePtr(int instID);
 char   *institutInqLongnamePtr(int instID);
 
 /* Model routines */
@@ -1563,7 +1567,7 @@ int     modelDef(int instID, int modelgribID, const char *name);
 int     modelInq(int instID, int modelgribID, char *name);
 int     modelInqInstitut(int modelID);
 int     modelInqGribID(int modelID);
-char   *modelInqNamePtr(int modelID);
+const char *modelInqNamePtr(int modelID);
 
 /* Table routines */
 
@@ -2105,6 +2109,8 @@ char *strdup(const char *s);
 #  include "resource_handle.h"
 #endif
 
+#include "cdi.h"
+
 
 #define check_parg(arg)  if ( arg == 0 ) Warning("Argument '" #arg "' not allocated!")
 
@@ -2126,7 +2132,7 @@ char *strdup(const char *s);
 
 #ifndef DBL_IS_EQUAL
 /*#define DBL_IS_EQUAL(x,y) (!(x < y || y < x)) */
-#  define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)?1:0):!(x < y || y < x))
+#  define DBL_IS_EQUAL(x,y) (DBL_IS_NAN(x)||DBL_IS_NAN(y)?(DBL_IS_NAN(x)&&DBL_IS_NAN(y)):!(x < y || y < x))
 #endif
 
 #ifndef IS_EQUAL
@@ -2380,8 +2386,15 @@ void    streamGetIndexList ( int, int * );
 
 void  cdiInitialize(void);
 
-void uuid2str(const char *uuid, char *uuidstr);
-void str2uuid(const char *uuidstr, char *uuid);
+void uuid2str(const unsigned char *uuid, char *uuidstr);
+int str2uuid(const char *uuidstr, unsigned char *uuid);
+static inline int
+cdiUUIDIsNull(const unsigned char uuid[CDI_UUID_SIZE])
+{
+  static unsigned char uuid_nil[CDI_UUID_SIZE];
+  return !memcmp(uuid, uuid_nil, CDI_UUID_SIZE);
+}
+
 
 #define CDI_UNIT_PA   1
 #define CDI_UNIT_HPA  2
@@ -2684,6 +2697,11 @@ double calculate_pfactor(const double* spectralField, long fieldTruncation, long
 #ifndef _GRIBAPI_H
 #define _GRIBAPI_H
 
+#ifdef HAVE_LIBGRIBAPI
+#  include "error.h"
+#  include <grib_api.h>
+#endif
+
 #define  GRIBAPI_MISSVAL  -9.E33
 
 /* GRIB2 Level Types */
@@ -2728,8 +2746,24 @@ double calculate_pfactor(const double* spectralField, long fieldTruncation, long
 const char *gribapiLibraryVersionString(void);
 void gribContainersNew(stream_t * streamptr);
 void gribContainersDelete(stream_t * streamptr);
-void *gribHandleNew(int editionNumber);
-void gribHandleDelete(void *gh);
+#ifdef HAVE_LIBGRIBAPI
+static inline void *gribHandleNew(int editionNumber)
+{
+  void *gh =
+    (void *)grib_handle_new_from_samples(NULL, (editionNumber == 1) ? "GRIB1" : "GRIB2");
+
+  if ( gh == NULL ) Error("grib_handle_new_from_samples failed!");
+  return gh;
+}
+
+static inline void gribHandleDelete(void *gh)
+{
+  grib_handle_delete(gh);
+}
+#else
+#define gribHandleNew(editionNumber) (NULL)
+#define gribHandleDelete(gh)
+#endif
 
 typedef struct {
   int init;
@@ -2839,7 +2873,7 @@ void   cdfDefVars(stream_t *streamptr);
 void   cdfDefTimestep(stream_t *streamptr, int tsID);
 int    cdfInqTimestep(stream_t *streamptr, int tsID);
 int    cdfInqContents(stream_t *streamptr);
-void   cdfDefHistory(stream_t *streamptr, int size, char *history);
+void   cdfDefHistory(stream_t *streamptr, int size, const char *history);
 int    cdfInqHistorySize(stream_t *streamptr);
 void   cdfInqHistoryString(stream_t *streamptr, char *history);
 
@@ -4350,6 +4384,8 @@ void   gaussaw(double *restrict pa, double *restrict pw, size_t nlat);
 #ifndef _GRID_H
 #define _GRID_H
 
+#include "cdi.h"
+
 typedef unsigned char mask_t;
 
 typedef struct {
@@ -4395,7 +4431,7 @@ typedef struct {
   int     nd, ni, ni2, ni3;       /* parameter for GRID_GME         */
   int     number, position;       /* parameter for GRID_REFERENCE   */
   char   *reference;
-  char    uuid[17];               /* uuid for grid reference        */
+  unsigned char uuid[CDI_UUID_SIZE]; /* uuid for grid reference        */
   int     trunc;                  /* parameter for GRID_SPECTEAL    */
   int     nvertex;
   int    *rowlon;
@@ -4432,8 +4468,8 @@ const double *gridInqXboundsPtr(int gridID);
 const double *gridInqYboundsPtr(int gridID);
 const double *gridInqAreaPtr(int gridID);
 
-int gridCompare(int gridID, grid_t grid);
-int gridGenerate(grid_t grid);
+int gridCompare(int gridID, const grid_t *grid);
+int gridGenerate(const grid_t *grid);
 
 void gridGetIndexList( int, int * );
 
@@ -4470,6 +4506,7 @@ zaxisUnpack(char * unpackBuffer, int unpackBufferSize,
 #  include "grid.h"
 #endif
 
+#include "cdi.h"
 
 void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds,
 		  int level1, int level2, int level_sf, int level_unit, int prec,
@@ -4477,9 +4514,9 @@ void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds,
 		  const char *name, const char *stdname, const char *longname, const char *units);
 
 void varDefVCT(size_t vctsize, double *vctptr);
-void varDefZAxisReference(int nlev, int nvgrid, char *uuid);
+void varDefZAxisReference(int nlev, int nvgrid, unsigned char uuid[CDI_UUID_SIZE]);
 
-int  varDefGrid(int vlistID, grid_t grid, int mode);
+int  varDefGrid(int vlistID, const grid_t *grid, int mode);
 int  varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbounds,
 		 double *levels1, double *levels2, int vctsize, double *vct, char *name,
 		 char *longname, char *units, int prec, int mode, int ltype);
@@ -4502,7 +4539,7 @@ void varDefOptGribInt(int varID, long lval, const char *keyword);
 void varDefOptGribDbl(int varID, double dval, const char *keyword);
 int varOptGribNentries(int varID);
 
-int  zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, double *levels, char *longname, char *units, int ltype);
+int  zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, const double *levels, char *longname, char *units, int ltype);
 
 #endif
 /*
@@ -5010,6 +5047,8 @@ void    vlistDefVarValidrange(int vlistID, int varID, const double *validrange);
 /*      vlistInqVarValidrange: Get the valid range of a Variable */
 int     vlistInqVarValidrange(int vlistID, int varID, double *validrange);
 
+void vlistInqVarDimorder(int vlistID, int varID, int (*outDimorder)[3]);
+
 int vlist_att_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int attnum);
 
 void vlist_lock(int vlistID);
@@ -5584,7 +5623,7 @@ int memListChangeEntry(void *ptrold, void *ptr, size_t size,
 		       const char *caller, const char *file, int line)
 {
   int item = UNDEFID;
-  int memID = 0;
+  size_t memID = 0;
   size_t sizeold;
 
   while( memID < memTableSize )
@@ -8705,7 +8744,7 @@ int modelInqGribID(int modelID)
 }
 
 
-char *modelInqNamePtr(int modelID)
+const char *modelInqNamePtr(int modelID)
 {
   model_t *modelptr = NULL;
 
@@ -9046,7 +9085,7 @@ int institutInqSubcenter(int instID)
 }
 
 
-char *institutInqNamePtr(int instID)
+const char *institutInqNamePtr(int instID)
 {
   institute_t * instituteptr = NULL;
 
@@ -9070,6 +9109,7 @@ char *institutInqLongnamePtr(int instID)
 static enum cdiApplyRet
 activeInstitutes(int id, void *res, void *data)
 {
+  (void)id;
   if (res && ((institute_t *)res)->used)
     ++(*(int *)data);
   return CDI_APPLY_GO_ON;
@@ -9380,16 +9420,21 @@ decodeForm1(char *pline, char *name, char *longname, char *units)
   while ( isspace((int) *pline) ) pline++;
 
   len = strlen(pline);
-  if ( len > 0)
+  if ( len > 0 )
     {
       pstart = pline;
       pend = strrchr(pline, '[');
-      if ( pend )
-	pend--;
+      if ( pend == pstart )
+        len = 0;
       else
-	pend = pstart + len;
-      while ( isspace((int) *pend) ) pend--;
-      len = (size_t)(pend - pstart + 1);
+        {
+          if ( pend )
+            pend--;
+          else
+            pend = pstart + len;
+          while ( isspace((int) *pend) ) pend--;
+          len = (size_t)(pend - pstart + 1);
+        }
       if ( len > 0 )
 	{
 	  memcpy(longname, pstart, len);
@@ -9409,10 +9454,10 @@ decodeForm1(char *pline, char *name, char *longname, char *units)
 	    {
 	      memcpy(units, pstart, len);
 	      units[len] = 0;
-	    }	  
+	    }
 	}
     }
- 
+
   return (0);
 }
 
@@ -9553,9 +9598,10 @@ static int tableFromEnv(int modelID, int tablenum)
   char tablename[256] = {'\0'};
   int tablenamefound = 0;
 
-  if ( modelInqNamePtr(modelID) )
+  const char *modelName;
+  if ( (modelName = modelInqNamePtr(modelID)) )
     {
-      strcpy(tablename, modelInqNamePtr(modelID));
+      strcpy(tablename, modelName);
       if ( tablenum )
 	{
 	  size_t len = strlen(tablename);
@@ -9568,9 +9614,10 @@ static int tableFromEnv(int modelID, int tablenum)
       int instID = modelInqInstitut(modelID);
       if ( instID != UNDEFID )
 	{
-	  if ( institutInqNamePtr(instID) )
+          const char *instName;
+	  if ( (instName = institutInqNamePtr(instID)) )
 	    {
-	      strcpy(tablename, institutInqNamePtr(instID));
+	      strcpy(tablename, instName);
 	      if ( tablenum )
 		{
 		  size_t len = strlen(tablename);
@@ -9661,9 +9708,10 @@ int tableInq(int modelID, int tablenum, const char *tablename)
 	{
 	  if ( modelID != UNDEFID )
 	    {
-	      if ( modelInqNamePtr(modelID) )
+              const char *modelName;
+	      if ( (modelName = modelInqNamePtr(modelID)) )
 		{
-		  strcpy(tablefile, modelInqNamePtr(modelID));
+		  strcpy(tablefile, modelName);
 		  size_t len = strlen(tablefile);
 		  for ( size_t i = 0; i < len; i++)
 		    if ( tablefile[i] == '.' ) tablefile[i] = '\0';
@@ -9780,7 +9828,7 @@ void tableWrite(const char *ptfile, int tableID)
   FILE *ptfp;
   int tablenum, modelID, instID = CDI_UNDEFID;
   int center = 0, subcenter = 0;
-  char *instnameptr = NULL, *modelnameptr = NULL;
+  const char *instnameptr = NULL, *modelnameptr = NULL;
 
   if ( CDI_Debug )
     Message("write parameter table %d to %s", tableID, ptfile);
@@ -10236,48 +10284,41 @@ void cdiPrintDatatypes(void)
     fprintf (stderr, "\n  byte ordering is LITTLEENDIAN\n\n");
 }
 
+static char uuidFmt[] = "%02hhx%02hhx%02hhx%02hhx-"
+  "%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-"
+  "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx";
 
-void uuid2str(const char *uuid, char *uuidstr)
-{
-  int iret;
-  unsigned int ui[16];
-
-  if ( uuid == NULL ) return;
-  if ( uuidstr == NULL ) return;
+enum {
+  uuidNumHexChars = 36,
+};
 
-  uuidstr[0] = 0;
+void uuid2str(const unsigned char *uuid, char *uuidstr)
+{
 
-  for ( int i = 0; i < 16; ++i ) ui[i] = (unsigned char) uuid[i];
+  if ( uuid == NULL || uuidstr == NULL ) return;
 
-  iret = sprintf(uuidstr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-		 ui[0], ui[1], ui[2], ui[3], ui[4], ui[5], ui[6], ui[7],
-		 ui[8], ui[9], ui[10], ui[11], ui[12], ui[13], ui[14], ui[15]);
+  int iret = sprintf(uuidstr, uuidFmt,
+                     uuid[0], uuid[1], uuid[2], uuid[3],
+                     uuid[4], uuid[5], uuid[6], uuid[7],
+                     uuid[8], uuid[9], uuid[10], uuid[11],
+                     uuid[12], uuid[13], uuid[14], uuid[15]);
 
-  if ( iret != 36 ) uuidstr[0] = 0;
+  if ( iret != uuidNumHexChars ) uuidstr[0] = 0;
 }
 
 
-void str2uuid(const char *uuidstr, char *uuid)
+int str2uuid(const char *uuidstr, unsigned char *uuid)
 {
-  int iret;
-  unsigned int ui[16];
-
-  if ( uuid == NULL ) return;
-  if ( uuidstr == NULL ) return;
-
-  uuid[0] = 0;
-
-  if ( strlen(uuidstr) != 36 ) return;
-
-  iret = sscanf(uuidstr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-		&ui[0], &ui[1], &ui[2], &ui[3], &ui[4], &ui[5], &ui[6], &ui[7],
-		&ui[8], &ui[9], &ui[10], &ui[11], &ui[12], &ui[13], &ui[14], &ui[15]);
+  if ( uuid == NULL || uuidstr == NULL || strlen(uuidstr) != uuidNumHexChars)
+    return -1;
 
-  if ( iret != 16 ) return;
-
-  for ( int i = 0; i < 16; ++i ) uuid[i] = ui[i];
-
-  uuid[16] = 0;
+  int iret = sscanf(uuidstr, uuidFmt,
+                    &uuid[0], &uuid[1], &uuid[2], &uuid[3],
+                    &uuid[4], &uuid[5], &uuid[6], &uuid[7],
+                    &uuid[8], &uuid[9], &uuid[10], &uuid[11],
+                    &uuid[12], &uuid[13], &uuid[14], &uuid[15]);
+  if ( iret != CDI_UUID_SIZE ) return -1;
+  return iret;
 }
 
 /*
@@ -10640,7 +10681,7 @@ static double *Vct = NULL;
 
 static int numberOfVerticalLevels = 0;
 static int numberOfVerticalGrid = 0;
-static char uuidVGrid[17];
+static unsigned char uuidVGrid[CDI_UUID_SIZE];
 
 typedef struct
 {
@@ -10666,7 +10707,7 @@ typedef struct
   int           level_sf;
   int           level_unit;
   int           zaxisID;
-  int           nlevels;
+  unsigned      nlevels;
   int           levelTableSize;
   leveltable_t *levelTable;
   int           instID;
@@ -10856,7 +10897,7 @@ int levelNewEntry(int varID, int level1, int level2)
   levelTable[levelID].level2   = level2;
   levelTable[levelID].lindex   = levelID;
 
-  vartable[varID].nlevels = levelID+1;
+  vartable[varID].nlevels = (unsigned)levelID+1;
   vartable[varID].levelTableSize = levelTableSize;
   vartable[varID].levelTable = levelTable;
 
@@ -11059,9 +11100,9 @@ int cmpparam(const void* s1, const void* s2)
 
 void cdi_generate_vars(stream_t *streamptr)
 {
-  int varID, gridID, zaxisID, levelID;
+  int varID, gridID, zaxisID;
   int instID, modelID, tableID;
-  int param, nlevels, zaxistype, ltype1, ltype2, lindex;
+  int param, zaxistype, ltype1, ltype2, lindex;
   int prec;
   int tsteptype;
   int timave, timaccu;
@@ -11108,7 +11149,7 @@ void cdi_generate_vars(stream_t *streamptr)
 
       gridID     = vartable[varid].gridID;
       param      = vartable[varid].param;
-      nlevels    = vartable[varid].nlevels;
+      unsigned nlevels = vartable[varid].nlevels;
       ltype1     = vartable[varid].ltype1;
       ltype2     = vartable[varid].ltype2;
       zaxistype = vartable[varid].zaxistype;
@@ -11136,17 +11177,17 @@ void cdi_generate_vars(stream_t *streamptr)
       dlevels = (double *) malloc(nlevels*sizeof(double));
 
       if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF )
-	for ( levelID = 0; levelID < nlevels; levelID++ )
+	for (unsigned levelID = 0; levelID < nlevels; levelID++ )
 	  dlevels[levelID] = (level_sf*vartable[varid].levelTable[levelID].level1 +
 	                      level_sf*vartable[varid].levelTable[levelID].level2)/2;
       else
-	for ( levelID = 0; levelID < nlevels; levelID++ )
+	for (unsigned levelID = 0; levelID < nlevels; levelID++ )
 	  dlevels[levelID] = level_sf*vartable[varid].levelTable[levelID].level1;
 
       if ( nlevels > 1 )
 	{
           bool linc = true, ldec = true, lsort = false;
-          for ( levelID = 1; levelID < nlevels; levelID++ )
+          for (unsigned levelID = 1; levelID < nlevels; levelID++ )
             {
               /* check increasing of levels */
               linc &= (dlevels[levelID] > dlevels[levelID-1]);
@@ -11160,7 +11201,7 @@ void cdi_generate_vars(stream_t *streamptr)
            */
           if ( !ldec && zaxistype == ZAXIS_PRESSURE )
             {
-              qsort(vartable[varid].levelTable, (size_t)nlevels, sizeof(leveltable_t), cmpLevelTableInv);
+              qsort(vartable[varid].levelTable, nlevels, sizeof(leveltable_t), cmpLevelTableInv);
               lsort = true;
             }
           /*
@@ -11172,18 +11213,18 @@ void cdi_generate_vars(stream_t *streamptr)
                     zaxistype == ZAXIS_HYBRID ||
                     zaxistype == ZAXIS_DEPTH_BELOW_LAND )
             {
-              qsort(vartable[varid].levelTable, (size_t)nlevels, sizeof(leveltable_t), cmpLevelTable);
+              qsort(vartable[varid].levelTable, nlevels, sizeof(leveltable_t), cmpLevelTable);
               lsort = true;
             }
 
           if ( lsort )
             {
               if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF )
-                for ( levelID = 0; levelID < nlevels; levelID++ )
+                for (unsigned levelID = 0; levelID < nlevels; levelID++ )
                   dlevels[levelID] = (level_sf*vartable[varid].levelTable[levelID].level1 +
                                       level_sf*vartable[varid].levelTable[levelID].level2)/2.;
               else
-                for ( levelID = 0; levelID < nlevels; levelID++ )
+                for (unsigned levelID = 0; levelID < nlevels; levelID++ )
                   dlevels[levelID] = level_sf*vartable[varid].levelTable[levelID].level1;
             }
 	}
@@ -11191,15 +11232,15 @@ void cdi_generate_vars(stream_t *streamptr)
       if ( lbounds )
 	{
 	  dlevels1 = (double *) malloc(nlevels*sizeof(double));
-	  for ( levelID = 0; levelID < nlevels; levelID++ )
+	  for (unsigned levelID = 0; levelID < nlevels; levelID++)
 	    dlevels1[levelID] = level_sf*vartable[varid].levelTable[levelID].level1;
 	  dlevels2 = (double *) malloc(nlevels*sizeof(double));
-	  for ( levelID = 0; levelID < nlevels; levelID++ )
+	  for (unsigned levelID = 0; levelID < nlevels; levelID++)
 	    dlevels2[levelID] = level_sf*vartable[varid].levelTable[levelID].level2;
         }
 
       char *unitptr = cdiUnitNamePtr(vartable[varid].level_unit);
-      zaxisID = varDefZaxis(vlistID, zaxistype, nlevels, dlevels, lbounds, dlevels1, dlevels2,
+      zaxisID = varDefZaxis(vlistID, zaxistype, (int)nlevels, dlevels, lbounds, dlevels1, dlevels2,
                             (int)Vctsize, Vct, NULL, NULL, unitptr, 0, 0, ltype1);
 
       if ( ltype1 != ltype2 && ltype2 != -1 )
@@ -11211,7 +11252,7 @@ void cdi_generate_vars(stream_t *streamptr)
         {
           if ( numberOfVerticalLevels > 0 ) zaxisDefNlevRef(zaxisID, numberOfVerticalLevels);
           if ( numberOfVerticalGrid > 0 ) zaxisDefNumber(zaxisID, numberOfVerticalGrid);
-          if ( uuidVGrid[0] != 0 ) zaxisDefUUID(zaxisID, uuidVGrid);
+          if ( !cdiUUIDIsNull(uuidVGrid) ) zaxisDefUUID(zaxisID, uuidVGrid);
         }
 
       if ( lbounds ) free(dlevels1);
@@ -11311,7 +11352,7 @@ void cdi_generate_vars(stream_t *streamptr)
       varID     = index;
       varid     = varids[index];
 
-      nlevels   = vartable[varid].nlevels;
+      unsigned nlevels = vartable[varid].nlevels;
       /*
       for ( levelID = 0; levelID < nlevels; levelID++ )
 	{
@@ -11322,16 +11363,17 @@ void cdi_generate_vars(stream_t *streamptr)
 		 vartable[varid].levelTable[levelID].level1);
 	}
       */
-      for ( levelID = 0; levelID < nlevels; levelID++ )
+      for (unsigned levelID = 0; levelID < nlevels; levelID++)
 	{
 	  streamptr->vars[varID].level[levelID] = vartable[varid].levelTable[levelID].recID;
-	  for ( lindex = 0; lindex < nlevels; lindex++ )
-	    if ( levelID == vartable[varid].levelTable[lindex].lindex ) break;
+          unsigned lindex;
+	  for (lindex = 0; lindex < nlevels; lindex++ )
+	    if ( levelID == (unsigned)vartable[varid].levelTable[lindex].lindex ) break;
 
 	  if ( lindex == nlevels )
 	    Error("Internal problem! lindex not found.");
 
-	  streamptr->vars[varID].lindex[levelID] = lindex;
+	  streamptr->vars[varID].lindex[levelID] = (int)lindex;
 	}
     }
 
@@ -11352,15 +11394,15 @@ void varDefVCT(size_t vctsize, double *vctptr)
 }
 
 
-void varDefZAxisReference(int nhlev, int nvgrid, char *uuid)
+void varDefZAxisReference(int nhlev, int nvgrid, unsigned char uuid[CDI_UUID_SIZE])
 {
   numberOfVerticalLevels = nhlev;
   numberOfVerticalGrid = nvgrid;
-  memcpy(uuidVGrid, uuid, 16);
+  memcpy(uuidVGrid, uuid, CDI_UUID_SIZE);
 }
 
 
-int varDefGrid(int vlistID, grid_t grid, int mode)
+int varDefGrid(int vlistID, const grid_t *grid, int mode)
 {
   /*
     mode: 0 search in vlist and grid table
@@ -11369,7 +11411,7 @@ int varDefGrid(int vlistID, grid_t grid, int mode)
   int gridglobdefined = FALSE;
   int griddefined;
   int ngrids;
-  int gridID = UNDEFID;
+  int gridID = CDI_UNDEFID;
   int index;
   vlist_t *vlistptr;
   int * gridIndexList, i;
@@ -11398,7 +11440,7 @@ int varDefGrid(int vlistID, grid_t grid, int mode)
       ngrids = gridSize();
       if ( ngrids > 0 )
         {
-          gridIndexList = (int*) malloc(ngrids*sizeof(int));
+          gridIndexList = (int*)xmalloc((size_t)ngrids * sizeof(int));
           gridGetIndexList ( ngrids, gridIndexList );
           for ( i = 0; i < ngrids; i++ )
             {
@@ -11434,7 +11476,7 @@ int varDefGrid(int vlistID, grid_t grid, int mode)
 }
 
 
-int zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, double *levels, char *longname, char *units, int ltype1)
+int zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, const double *levels, char *longname, char *units, int ltype1)
 {
   int differ = 1;
   int levelID;
@@ -11520,7 +11562,7 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo
       if ( nzaxis > 0 )
         {
           int *zaxisIndexList;
-          zaxisIndexList = (int *) malloc ( nzaxis * sizeof ( int ));
+          zaxisIndexList = (int *)xmalloc((size_t)nzaxis * sizeof (int));
           zaxisGetIndexList ( nzaxis, zaxisIndexList );
           for ( i = 0; i < nzaxis; i++ )
             {
@@ -11661,38 +11703,38 @@ void varDefProductDefinitionTemplate(int varID, int productDefinitionTemplate)
 }
 
 
+#if  defined  (HAVE_LIBGRIB_API)
 void varDefOptGribInt(int varID, long lval, const char *keyword)
 {
-#if  defined  (HAVE_LIBGRIB_API)
   int idx = vartable[varID].opt_grib_int_nentries;
   vartable[varID].opt_grib_int_nentries++;
   if ( idx >= MAX_OPT_GRIB_ENTRIES ) Error("Too many optional keyword/integer value pairs!");
   vartable[varID].opt_grib_int_val[idx] = (int) lval;
   vartable[varID].opt_grib_int_keyword[idx] = strdupx(keyword);
-#endif
 }
+#endif
 
 
+#if  defined  (HAVE_LIBGRIB_API)
 void varDefOptGribDbl(int varID, double dval, const char *keyword)
 {
-#if  defined  (HAVE_LIBGRIB_API)
   int idx = vartable[varID].opt_grib_dbl_nentries;
   vartable[varID].opt_grib_dbl_nentries++;
   if ( idx >= MAX_OPT_GRIB_ENTRIES ) Error("Too many optional keyword/double value pairs!");
   vartable[varID].opt_grib_dbl_val[idx] = dval;
   vartable[varID].opt_grib_dbl_keyword[idx] = strdupx(keyword);
-#endif
 }
+#endif
 
 
+#if  defined  (HAVE_LIBGRIB_API)
 int varOptGribNentries(int varID)
 {
   int nentries = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   nentries = vartable[varID].opt_grib_int_nentries + vartable[varID].opt_grib_dbl_nentries;
-#endif
   return (nentries);
 }
+#endif
 
 /*
  * Local Variables:
@@ -12134,8 +12176,8 @@ void vlistClearFlag(int vlistID)
 }
 
 static
-int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, double *levels,
-                         double *lbounds, double *ubounds, int vctsize, const double *vct)
+int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, const double *levels,
+                         const double *lbounds, const double *ubounds, int vctsize, const double *vct)
 {
   int zaxisID = CDI_UNDEFID;
   int zaxisglobdefined = 0;
@@ -12796,7 +12838,7 @@ void vlistDefNtsteps(int vlistID, int nts)
     }
 }
 
-
+// This function is used in CDO!
 int vlistNtsteps(int vlistID)
 {
   vlist_t *vlistptr = vlist_to_pointer(vlistID);
@@ -13383,24 +13425,19 @@ cdi_atts_t *get_attsp(vlist_t *vlistptr, int varID)
 static
 cdi_att_t *find_att(cdi_atts_t *attsp, const char *name)
 {
-  cdi_att_t *attp;
-  size_t attid;
-  size_t slen;
-
   xassert(attsp != NULL);
 
   if ( attsp->nelems == 0 ) return NULL;
 
-  slen = strlen(name);
+  size_t slen = strlen(name);
 
-  for ( attid = 0; attid < attsp->nelems; attid++ )
+  cdi_att_t *atts = attsp->value;
+  for (size_t attid = 0; attid < attsp->nelems; attid++)
     {
-      attp = &(attsp->value[attid]);
-      if ( attp->namesz == slen )
-	if ( memcmp(attp->name, name, slen) == 0)
-	  {
-	    return (attp); /* Normal return */
-	  }
+      cdi_att_t *attp = atts + attid;
+      if (attp->namesz == slen
+          && memcmp(attp->name, name, slen) == 0)
+        return (attp); /* Normal return */
     }
 
   return (NULL);
@@ -13733,7 +13770,7 @@ The function @func{vlistDefAttTxt} defines a text attribute.
 */
 int vlistDefAttTxt(int vlistID, int varID, const char *name, int len, const char *tp)
 {
-  return vlist_def_att(DATATYPE_TXT, DATATYPE_TXT, vlistID, varID, name, (size_t)len, (size_t)len * sizeof (char), tp);
+  return vlist_def_att(DATATYPE_TXT, DATATYPE_TXT, vlistID, varID, name, (size_t)len, (size_t)len, tp);
 }
 
 /*
@@ -17105,7 +17142,6 @@ int extRead(int fileID, void *ext)
   extrec_t *extp = (extrec_t *) ext;
   size_t blocklen, blocklen2;
   size_t i;
-  char tempheader[32];
   void *buffer;
   int byteswap;
   int status;
@@ -17135,19 +17171,21 @@ int extRead(int fileID, void *ext)
     {
     case SINGLE_PRECISION:
       {
-	binReadInt32(fileID, byteswap, EXT_HEADER_LEN, (INT32 *) tempheader);
+        INT32 tempheader[4];
+	binReadInt32(fileID, byteswap, EXT_HEADER_LEN, tempheader);
 
 	for ( i = 0; i < EXT_HEADER_LEN; i++ )
-          extp->header[i] = (int) ((INT32 *) tempheader)[i];
+          extp->header[i] = (int)tempheader[i];
 
 	break;
       }
     case DOUBLE_PRECISION:
       {
-	binReadInt64(fileID, byteswap, EXT_HEADER_LEN, (INT64 *) tempheader);
+        INT64 tempheader[4];
+	binReadInt64(fileID, byteswap, EXT_HEADER_LEN, tempheader);
 
 	for ( i = 0; i < EXT_HEADER_LEN; i++ )
-          extp->header[i] = (int) ((INT64 *) tempheader)[i];
+          extp->header[i] = (int)tempheader[i];
 
 	break;
       }
@@ -17331,7 +17369,7 @@ static int iegDefaultDprec = 0;
  */
 
 #undef  LIBVERSION
-#define LIBVERSION      1.3.2
+#define LIBVERSION      1.3.3
 #define XSTRING(x)	#x
 #define STRING(x)	XSTRING(x)
 static const char ieg_libvers[] = STRING(LIBVERSION) " of "__DATE__" "__TIME__;
@@ -17973,6 +18011,7 @@ static const resOps gridOps = {
 
 static int  GRID_Debug = 0;   /* If set to 1, debugging */
 
+#define gridID2Ptr(gridID) (grid_t *)reshGetVal(gridID, &gridOps)
 
 void grid_init(grid_t *gridptr)
 {
@@ -18042,7 +18081,7 @@ void grid_init(grid_t *gridptr)
   gridptr->yunits[0]    = 0;
   gridptr->xstdname[0]  = 0;
   gridptr->ystdname[0]  = 0;
-  memset(gridptr->uuid, 0, 16);
+  memset(gridptr->uuid, 0, CDI_UUID_SIZE);
   gridptr->name         = NULL;
 }
 
@@ -18102,16 +18141,6 @@ void grid_copy(grid_t *gridptr2, grid_t *gridptr1)
   gridptr2->self = gridID2;
 }
 
-static
-void gridCheckPtr(const char *caller, int gridID, grid_t *gridptr)
-{
-  if ( gridptr == NULL )
-    Errorc("grid %d undefined!", gridID);
-}
-
-#define  grid_check_ptr(gridID, gridptr)  gridCheckPtr(__func__, gridID, gridptr)
-
-
 int gridSize(void)
 {
   return reshCountType ( &gridOps );
@@ -18427,7 +18456,7 @@ void gridDestroyKernel( grid_t * gridptr )
 */
 void gridDestroy(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   gridDestroyKernel ( gridptr );
 }
@@ -18443,10 +18472,7 @@ const char *gridNamePtr(int gridtype)
   const char *name;
   int size = (int) (sizeof(Grids)/sizeof(char *));
 
-  if ( gridtype >= 0 && gridtype < size )
-    name = Grids[gridtype];
-  else
-    name = Grids[GRID_GENERIC];
+  name = gridtype >= 0 && gridtype < size ? Grids[gridtype] : Grids[GRID_GENERIC];
 
   return (name);
 }
@@ -18473,13 +18499,12 @@ The function @func{gridDefXname} defines the name of a X-axis.
 */
 void gridDefXname(int gridID, const char *xname)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( xname )
     {
-      strcpy(gridptr->xname, xname);
+      strncpy(gridptr->xname, xname, CDI_MAX_NAME);
+      gridptr->xname[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -18500,12 +18525,11 @@ The function @func{gridDefXlongname} defines the longname of a X-axis.
 */
 void gridDefXlongname(int gridID, const char *xlongname)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-  grid_check_ptr(gridID, gridptr);
-
+  grid_t *gridptr = gridID2Ptr(gridID);
   if ( xlongname )
     {
-      strcpy(gridptr->xlongname, xlongname);
+      strncpy(gridptr->xlongname, xlongname, CDI_MAX_NAME);
+      gridptr->xlongname[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -18526,13 +18550,12 @@ The function @func{gridDefXunits} defines the units of a X-axis.
 */
 void gridDefXunits(int gridID, const char *xunits)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( xunits )
     {
-      strcpy(gridptr->xunits, xunits);
+      strncpy(gridptr->xunits, xunits, CDI_MAX_NAME);
+      gridptr->xunits[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -18553,13 +18576,12 @@ The function @func{gridDefYname} defines the name of a Y-axis.
 */
 void gridDefYname(int gridID, const char *yname)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( yname )
     {
-      strcpy(gridptr->yname, yname);
+      strncpy(gridptr->yname, yname, CDI_MAX_NAME);
+      gridptr->yname[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -18580,13 +18602,12 @@ The function @func{gridDefYlongname} defines the longname of a Y-axis.
 */
 void gridDefYlongname(int gridID, const char *ylongname)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( ylongname )
     {
-      strcpy(gridptr->ylongname, ylongname);
+      strncpy(gridptr->ylongname, ylongname, CDI_MAX_NAME);
+      gridptr->ylongname[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -18607,13 +18628,12 @@ The function @func{gridDefYunits} defines the units of a Y-axis.
 */
 void gridDefYunits(int gridID, const char *yunits)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( yunits )
     {
-      strcpy(gridptr->yunits, yunits);
+      strncpy(gridptr->yunits, yunits, CDI_MAX_NAME);
+      gridptr->yunits[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -18639,9 +18659,7 @@ The function @func{gridInqXname} returns the name of a X-axis.
 */
 void gridInqXname(int gridID, char *xname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(xname, gridptr->xname);
 }
@@ -18667,9 +18685,7 @@ The function @func{gridInqXlongname} returns the longname of a X-axis.
 */
 void gridInqXlongname(int gridID, char *xlongname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(xlongname, gridptr->xlongname);
 }
@@ -18695,9 +18711,7 @@ The function @func{gridInqXunits} returns the units of a X-axis.
 */
 void gridInqXunits(int gridID, char *xunits)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(xunits, gridptr->xunits);
 }
@@ -18705,9 +18719,7 @@ void gridInqXunits(int gridID, char *xunits)
 
 void gridInqXstdname(int gridID, char *xstdname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(xstdname, gridptr->xstdname);
 }
@@ -18733,9 +18745,7 @@ The function @func{gridInqYname} returns the name of a Y-axis.
 */
 void gridInqYname(int gridID, char *yname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(yname, gridptr->yname);
 }
@@ -18761,9 +18771,7 @@ The function @func{gridInqYlongname} returns the longname of a Y-axis.
 */
 void gridInqYlongname(int gridID, char *ylongname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(ylongname, gridptr->ylongname);
 }
@@ -18789,18 +18797,14 @@ The function @func{gridInqYunits} returns the units of a Y-axis.
 */
 void gridInqYunits(int gridID, char *yunits)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(yunits, gridptr->yunits);
 }
 
 void gridInqYstdname(int gridID, char *ystdname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(ystdname, gridptr->ystdname);
 }
@@ -18827,9 +18831,7 @@ The valid CDI grid types are @func{GRID_GENERIC}, @func{GRID_GAUSSIAN},
 */
 int gridInqType(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->type);
 }
@@ -18853,9 +18855,7 @@ The function @func{gridInqSize} returns the size of a Grid.
 */
 int gridInqSize(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int size = gridptr->size;
 
@@ -18886,19 +18886,14 @@ int nsp2trunc(int nsp)
   /*  with:  y^2 + p*y + q = 0               */
   /*         y = -p/2 +- sqrt((p/2)^2 - q)   */
   /*         p = 3 and q = - (x-2)           */
-  int trunc;
-
-  trunc = (int) (sqrt(nsp*4 + 1.) - 3) / 2;
-
+  int trunc = (int) (sqrt(nsp*4 + 1.) - 3) / 2;
   return (trunc);
 }
 
 
 int gridInqTrunc(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->trunc == 0 )
     {
@@ -18916,9 +18911,7 @@ int gridInqTrunc(int gridID)
 
 void gridDefTrunc(int gridID, int trunc)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->trunc != trunc)
     {
@@ -18943,9 +18936,7 @@ The function @func{gridDefXsize} defines the number of values of a X-axis.
 */
 void gridDefXsize(int gridID, int xsize)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( xsize > gridInqSize(gridID) )
     Error("xsize %d is greater then gridsize %d", xsize, gridInqSize(gridID));
@@ -18980,9 +18971,7 @@ void gridDefXsize(int gridID, int xsize)
 */
 void gridDefPrec(int gridID, int prec)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->prec != prec)
     {
@@ -19003,9 +18992,7 @@ void gridDefPrec(int gridID, int prec)
 */
 int gridInqPrec(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->prec);
 }
@@ -19028,9 +19015,7 @@ The function @func{gridInqXsize} returns the number of values of a X-axis.
 */
 int gridInqXsize(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->xsize);
 }
@@ -19051,9 +19036,7 @@ The function @func{gridDefYsize} defines the number of values of a Y-axis.
 */
 void gridDefYsize(int gridID, int ysize)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( ysize > gridInqSize(gridID) )
     Error("ysize %d is greater then gridsize %d", ysize, gridInqSize(gridID));
@@ -19094,9 +19077,7 @@ The function @func{gridInqYsize} returns the number of values of a Y-axis.
 */
 int gridInqYsize(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ysize);
 }
@@ -19118,9 +19099,7 @@ of a Gaussian grid.
 */
 void gridDefNP(int gridID, int np)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->np != np)
     {
@@ -19148,9 +19127,7 @@ of a Gaussian grid.
 */
 int gridInqNP(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->np);
 }
@@ -19165,11 +19142,9 @@ int gridInqNP(int gridID)
 
 @EndFunction
 */
-void gridDefRowlon(int gridID, int nrowlon, const int *rowlon)
+void gridDefRowlon(int gridID, int nrowlon, const int rowlon[])
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   gridptr->rowlon = (int *)xmalloc((size_t)nrowlon * sizeof(int));
   gridptr->nrowlon = nrowlon;
@@ -19189,9 +19164,7 @@ void gridDefRowlon(int gridID, int nrowlon, const int *rowlon)
 */
 void gridInqRowlon(int gridID, int *rowlon)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->rowlon == 0 )  Error("undefined pointer!");
 
@@ -19201,9 +19174,7 @@ void gridInqRowlon(int gridID, int *rowlon)
 
 int gridInqMask(int gridID, int *mask)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size = gridptr->size;
 
@@ -19216,13 +19187,13 @@ int gridInqMask(int gridID, int *mask)
 
   if ( gridptr->mask == NULL ) size = 0;
 
-  return (size);
+  return (int)size;
 }
 
 
 void gridDefMask(int gridID, const int *mask)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size = gridptr->size;
 
@@ -19252,9 +19223,7 @@ void gridDefMask(int gridID, const int *mask)
 
 int gridInqMaskGME(int gridID, int *mask)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size = gridptr->size;
 
@@ -19267,15 +19236,13 @@ int gridInqMaskGME(int gridID, int *mask)
 
   if ( gridptr->mask_gme == NULL ) size = 0;
 
-  return (size);
+  return (int)size;
 }
 
 
 void gridDefMaskGME(int gridID, const int *mask)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size = gridptr->size;
 
@@ -19313,9 +19280,7 @@ Otherwise, 0 is returned and @func{xvals} is empty.
 */
 int gridInqXvals(int gridID, double *xvals)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size;
   if ( gridptr->type == GRID_CURVILINEAR || gridptr->type == GRID_UNSTRUCTURED )
@@ -19333,7 +19298,7 @@ int gridInqXvals(int gridID, double *xvals)
 
   if ( gridptr->xvals == NULL ) size = 0;
 
-  return (size);
+  return (int)size;
 }
 
 /*
@@ -19352,9 +19317,7 @@ The function @func{gridDefXvals} defines all values of the X-axis.
 */
 void gridDefXvals(int gridID, const double *xvals)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int gridtype;
   long size;
@@ -19401,9 +19364,7 @@ Otherwise, 0 is returned and @func{yvals} is empty.
 */
 int gridInqYvals(int gridID, double *yvals)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int gridtype = gridptr->type;
   long size
@@ -19418,7 +19379,7 @@ int gridInqYvals(int gridID, double *yvals)
 
   if ( gridptr->yvals == NULL ) size = 0;
 
-  return (size);
+  return (int)size;
 }
 
 /*
@@ -19437,9 +19398,7 @@ The function @func{gridDefYvals} defines all values of the Y-axis.
 */
 void gridDefYvals(int gridID, const double *yvals)
 {
-  grid_t *gridptr = reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int gridtype = gridptr->type;
   long size
@@ -19461,9 +19420,7 @@ void gridDefYvals(int gridID, const double *yvals)
 double gridInqXval(int gridID, int index)
 {
   double xval = 0;
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->xvals )
     xval = gridptr->xvals[index];
@@ -19484,9 +19441,7 @@ double gridInqXval(int gridID, int index)
 double gridInqYval(int gridID, int index)
 {
   double yval = 0;
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->yvals )
     yval = gridptr->yvals[index];
@@ -19506,9 +19461,7 @@ double gridInqYval(int gridID, int index)
 */
 double gridInqXinc(int gridID)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   double xinc = gridptr->xinc;
 
@@ -19542,9 +19495,7 @@ double gridInqXinc(int gridID)
 */
 double gridInqYinc(int gridID)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   double yinc = gridptr->yinc;
 
@@ -19583,9 +19534,7 @@ double gridInqYinc(int gridID)
 */
 double gridInqXpole(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->xpole);
 }
@@ -19602,9 +19551,7 @@ double gridInqXpole(int gridID)
 */
 void gridDefXpole(int gridID, double xpole)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( memcmp(gridptr->xstdname, "grid", 4) != 0 )
     strcpy(gridptr->xstdname, "grid_longitude");
@@ -19629,9 +19576,7 @@ void gridDefXpole(int gridID, double xpole)
 */
 double gridInqYpole(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ypole);
 }
@@ -19648,9 +19593,7 @@ double gridInqYpole(int gridID)
 */
 void gridDefYpole(int gridID, double ypole)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( memcmp(gridptr->ystdname, "grid", 4) != 0 )
     strcpy(gridptr->ystdname, "grid_latitude");
@@ -19675,9 +19618,7 @@ void gridDefYpole(int gridID, double ypole)
 */
 double gridInqAngle(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->angle);
 }
@@ -19694,9 +19635,7 @@ double gridInqAngle(int gridID)
 */
 void gridDefAngle(int gridID, double angle)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->isRotated != TRUE || IS_NOT_EQUAL(gridptr->angle, angle) )
     {
@@ -19718,9 +19657,7 @@ void gridDefAngle(int gridID, double angle)
 */
 int gridInqGMEnd(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->nd);
 }
@@ -19737,9 +19674,7 @@ int gridInqGMEnd(int gridID)
 */
 void gridDefGMEnd(int gridID, int nd)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->nd != nd)
     {
@@ -19760,9 +19695,7 @@ void gridDefGMEnd(int gridID, int nd)
 */
 int gridInqGMEni(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ni);
 }
@@ -19779,9 +19712,7 @@ int gridInqGMEni(int gridID)
 */
 void gridDefGMEni(int gridID, int ni)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->ni != ni)
     {
@@ -19802,9 +19733,7 @@ void gridDefGMEni(int gridID, int ni)
 */
 int gridInqGMEni2(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ni2);
 }
@@ -19821,9 +19750,7 @@ int gridInqGMEni2(int gridID)
 */
 void gridDefGMEni2(int gridID, int ni2)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->ni2 != ni2)
     {
@@ -19844,18 +19771,14 @@ void gridDefGMEni2(int gridID, int ni2)
 */
 int gridInqGMEni3(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ni3);
 }
 
 void gridDefGMEni3(int gridID, int ni3)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->ni3 != ni3)
     {
@@ -19876,9 +19799,7 @@ void gridDefGMEni3(int gridID, int ni3)
 */
 void gridChangeType(int gridID, int gridtype)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( CDI_Debug )
     Message("Changed grid type from %s to %s", gridNamePtr(gridptr->type), gridNamePtr(gridtype));
@@ -19996,9 +19917,7 @@ void grid_check_cyclic(grid_t *gridptr)
 
 int gridIsCircular(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->isCyclic == CDI_UNDEFID ) grid_check_cyclic(gridptr);
 
@@ -20008,9 +19927,7 @@ int gridIsCircular(int gridID)
 
 int gridIsRotated(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return ( gridptr->isRotated );
 }
@@ -20082,52 +19999,52 @@ int compareXYvals2(int gridID, int gridsize, double *xvals, double *yvals)
 }
 
 
-int gridCompare(int gridID, grid_t grid)
+int gridCompare(int gridID, const grid_t *grid)
 {
   int differ = 1;
 
-  if ( grid.type == gridInqType(gridID) || grid.type == GRID_GENERIC )
+  if ( grid->type == gridInqType(gridID) || grid->type == GRID_GENERIC )
     {
-      if ( grid.size == gridInqSize(gridID) )
+      if ( grid->size == gridInqSize(gridID) )
 	{
 	  differ = 0;
-	  if ( grid.type == GRID_LONLAT )
+	  if ( grid->type == GRID_LONLAT )
 	    {
 	      /*
 	      printf("gridID      %d\n", gridID);
-	      printf("grid.xdef   %d\n", grid.xdef);
-	      printf("grid.ydef   %d\n", grid.ydef);
-	      printf("grid.xsize  %d\n", grid.xsize);
-	      printf("grid.ysize  %d\n", grid.ysize);
-	      printf("grid.xfirst %f\n", grid.xfirst);
-	      printf("grid.yfirst %f\n", grid.yfirst);
+	      printf("grid.xdef   %d\n", grid->xdef);
+	      printf("grid.ydef   %d\n", grid->ydef);
+	      printf("grid.xsize  %d\n", grid->xsize);
+	      printf("grid.ysize  %d\n", grid->ysize);
+	      printf("grid.xfirst %f\n", grid->xfirst);
+	      printf("grid.yfirst %f\n", grid->yfirst);
 	      printf("grid.xfirst %f\n", gridInqXval(gridID, 0));
 	      printf("grid.yfirst %f\n", gridInqYval(gridID, 0));
-	      printf("grid.xinc   %f\n", grid.xinc);
-	      printf("grid.yinc   %f\n", grid.yinc);
+	      printf("grid.xinc   %f\n", grid->xinc);
+	      printf("grid.yinc   %f\n", grid->yinc);
 	      printf("grid.xinc   %f\n", gridInqXinc(gridID));
 	      printf("grid.yinc   %f\n", gridInqYinc(gridID));
 	      */
-	      if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) )
+	      if ( grid->xsize == gridInqXsize(gridID) && grid->ysize == gridInqYsize(gridID) )
 		{
-		  if ( grid.xdef == 2 && grid.ydef == 2 )
+		  if ( grid->xdef == 2 && grid->ydef == 2 )
 		    {
-		      if ( ! (IS_EQUAL(grid.xfirst, 0) && IS_EQUAL(grid.xlast, 0) && IS_EQUAL(grid.xinc, 0)) &&
-			   ! (IS_EQUAL(grid.yfirst, 0) && IS_EQUAL(grid.ylast, 0) && IS_EQUAL(grid.yinc, 0)) &&
-			   IS_NOT_EQUAL(grid.xfirst, grid.xlast) && IS_NOT_EQUAL(grid.yfirst, grid.ylast) )
+		      if ( ! (IS_EQUAL(grid->xfirst, 0) && IS_EQUAL(grid->xlast, 0) && IS_EQUAL(grid->xinc, 0)) &&
+			   ! (IS_EQUAL(grid->yfirst, 0) && IS_EQUAL(grid->ylast, 0) && IS_EQUAL(grid->yinc, 0)) &&
+			   IS_NOT_EQUAL(grid->xfirst, grid->xlast) && IS_NOT_EQUAL(grid->yfirst, grid->ylast) )
 			{
-			  if ( IS_NOT_EQUAL(grid.xfirst, gridInqXval(gridID, 0)) ||
-			       IS_NOT_EQUAL(grid.yfirst, gridInqYval(gridID, 0)))
+			  if ( IS_NOT_EQUAL(grid->xfirst, gridInqXval(gridID, 0)) ||
+			       IS_NOT_EQUAL(grid->yfirst, gridInqYval(gridID, 0)))
 			    {
 			      differ = 1;
 			    }
-			  if ( !differ && fabs(grid.xinc) > 0 &&
-			       fabs(fabs(grid.xinc) - fabs(gridInqXinc(gridID))) > fabs(grid.xinc/1000))
+			  if ( !differ && fabs(grid->xinc) > 0 &&
+			       fabs(fabs(grid->xinc) - fabs(gridInqXinc(gridID))) > fabs(grid->xinc/1000))
 			    {
 			      differ = 1;
 			    }
-			  if ( !differ && fabs(grid.yinc) > 0 &&
-			       fabs(fabs(grid.yinc) - fabs(gridInqYinc(gridID))) > fabs(grid.yinc/1000))
+			  if ( !differ && fabs(grid->yinc) > 0 &&
+			       fabs(fabs(grid->yinc) - fabs(gridInqYinc(gridID))) > fabs(grid->yinc/1000))
 			    {
 			      differ = 1;
 			    }
@@ -20135,95 +20052,91 @@ int gridCompare(int gridID, grid_t grid)
 		    }
 		  else
 		    {
-		      if ( grid.xvals && grid.yvals )
-			differ = compareXYvals(gridID, grid.xsize, grid.ysize, grid.xvals, grid.yvals);
+		      if ( grid->xvals && grid->yvals )
+			differ = compareXYvals(gridID, grid->xsize, grid->ysize, grid->xvals, grid->yvals);
 		    }
 		}
 	      else
 		differ = 1;
 	    }
-	  else if ( grid.type == GRID_GENERIC )
+	  else if ( grid->type == GRID_GENERIC )
 	    {
-	      if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) )
+	      if ( grid->xsize == gridInqXsize(gridID) && grid->ysize == gridInqYsize(gridID) )
 		{
-		  if ( grid.xdef == 1 && grid.ydef == 1 )
+		  if ( grid->xdef == 1 && grid->ydef == 1 )
 		    {
-		      if ( grid.xvals && grid.yvals )
-			differ = compareXYvals(gridID, grid.xsize, grid.ysize, grid.xvals, grid.yvals);
+		      if ( grid->xvals && grid->yvals )
+			differ = compareXYvals(gridID, grid->xsize, grid->ysize, grid->xvals, grid->yvals);
 		    }
 		}
-	      else if ( (grid.ysize == 0 || grid.ysize == 1) &&
-			grid.xsize == gridInqXsize(gridID)*gridInqYsize(gridID) )
+	      else if ( (grid->ysize == 0 || grid->ysize == 1) &&
+			grid->xsize == gridInqXsize(gridID)*gridInqYsize(gridID) )
 		{
 		}
 	      else
 		differ = 1;
 	    }
-	  else if ( grid.type == GRID_GAUSSIAN )
+	  else if ( grid->type == GRID_GAUSSIAN )
 	    {
-	      if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) )
+	      if ( grid->xsize == gridInqXsize(gridID) && grid->ysize == gridInqYsize(gridID) )
 		{
-		  if ( grid.xdef == 2 && grid.ydef == 2 )
+		  if ( grid->xdef == 2 && grid->ydef == 2 )
 		    {
-		      if ( ! (IS_EQUAL(grid.xfirst, 0) && IS_EQUAL(grid.xlast, 0) && IS_EQUAL(grid.xinc, 0)) &&
-			   ! (IS_EQUAL(grid.yfirst, 0) && IS_EQUAL(grid.ylast, 0)) )
-			if ( fabs(grid.xfirst - gridInqXval(gridID, 0)) > 0.0015 ||
-			     fabs(grid.yfirst - gridInqYval(gridID, 0)) > 0.0015 ||
-			     (fabs(grid.xinc)>0 && fabs(fabs(grid.xinc) - fabs(gridInqXinc(gridID))) > fabs(grid.xinc/1000)) )
+		      if ( ! (IS_EQUAL(grid->xfirst, 0) && IS_EQUAL(grid->xlast, 0) && IS_EQUAL(grid->xinc, 0)) &&
+			   ! (IS_EQUAL(grid->yfirst, 0) && IS_EQUAL(grid->ylast, 0)) )
+			if ( fabs(grid->xfirst - gridInqXval(gridID, 0)) > 0.0015 ||
+			     fabs(grid->yfirst - gridInqYval(gridID, 0)) > 0.0015 ||
+			     (fabs(grid->xinc)>0 && fabs(fabs(grid->xinc) - fabs(gridInqXinc(gridID))) > fabs(grid->xinc/1000)) )
 			  {
 			    differ = 1;
 			  }
 		    }
 		  else
 		    {
-		      if ( grid.xvals && grid.yvals )
-			differ = compareXYvals(gridID, grid.xsize, grid.ysize, grid.xvals, grid.yvals);
+		      if ( grid->xvals && grid->yvals )
+			differ = compareXYvals(gridID, grid->xsize, grid->ysize, grid->xvals, grid->yvals);
 		    }
 		}
 	      else
 		differ = 1;
 	    }
-	  else if ( grid.type == GRID_CURVILINEAR )
+	  else if ( grid->type == GRID_CURVILINEAR )
 	    {
 	      /*
 	      printf("gridID      %d\n", gridID);
-	      printf("grid.xsize  %d\n", grid.xsize);
-	      printf("grid.ysize  %d\n", grid.ysize);
-	      printf("grid.xfirst %f\n", grid.xvals[0]);
-	      printf("grid.yfirst %f\n", grid.yvals[0]);
+	      printf("grid.xsize  %d\n", grid->xsize);
+	      printf("grid.ysize  %d\n", grid->ysize);
+	      printf("grid.xfirst %f\n", grid->xvals[0]);
+	      printf("grid.yfirst %f\n", grid->yvals[0]);
 	      printf("grid xfirst %f\n", gridInqXval(gridID, 0));
 	      printf("grid yfirst %f\n", gridInqYval(gridID, 0));
-	      printf("grid.xlast  %f\n", grid.xvals[grid.size-1]);
-	      printf("grid.ylast  %f\n", grid.yvals[grid.size-1]);
-	      printf("grid xlast  %f\n", gridInqXval(gridID, grid.size-1));
-	      printf("grid ylast  %f\n", gridInqYval(gridID, grid.size-1));
-	      printf("grid.nv     %d\n", grid.nvertex);
+	      printf("grid.xlast  %f\n", grid->xvals[grid->size-1]);
+	      printf("grid.ylast  %f\n", grid->yvals[grid->size-1]);
+	      printf("grid xlast  %f\n", gridInqXval(gridID, grid->size-1));
+	      printf("grid ylast  %f\n", gridInqYval(gridID, grid->size-1));
+	      printf("grid.nv     %d\n", grid->nvertex);
 	      printf("grid nv     %d\n", gridInqNvertex(gridID));
 	      */
-	      if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) )
-		differ = compareXYvals2(gridID, grid.size, grid.xvals, grid.yvals);
+	      if ( grid->xsize == gridInqXsize(gridID) && grid->ysize == gridInqYsize(gridID) )
+		differ = compareXYvals2(gridID, grid->size, grid->xvals, grid->yvals);
 	    }
-	  else if ( grid.type == GRID_UNSTRUCTURED )
+	  else if ( grid->type == GRID_UNSTRUCTURED )
 	    {
-              char uuidOfHGrid[17];
+              unsigned char uuidOfHGrid[CDI_UUID_SIZE];
               gridInqUUID(gridID, uuidOfHGrid);
-              /*
-              printf("compare unstructured grids\n");
-	      printf("gridID        %d\n", gridID);
-	      printf("gridsize      %d\n", grid.size);
-              if ( uuidOfHGrid[0] != 0 && grid.uuid[0] != 0 && memcmp(grid.uuid, uuidOfHGrid, 16) )
-                printf("uuidOfHGrid     differ\n");
-              printf("nvertex      %d  %d\n", grid.nvertex, gridInqNvertex(gridID));
-              printf("number       %d  %d\n", grid.number, gridInqNumber(gridID));
-              printf("position     %d  %d\n", grid.position, gridInqPosition(gridID));
-              */
-              if ( uuidOfHGrid[0] != 0 && grid.uuid[0] != 0 )
-                if ( !differ && memcmp(uuidOfHGrid, grid.uuid, 16) != 0 ) differ = 1;
-              if ( !differ && grid.nvertex != gridInqNvertex(gridID) ) differ = 1;
-              if ( !differ && grid.number != gridInqNumber(gridID) ) differ = 1;
-              if ( !differ && grid.number > 0 && grid.position != gridInqPosition(gridID) ) differ = 1;
+
+              if ( !differ && memcmp(uuidOfHGrid, grid->uuid, CDI_UUID_SIZE) != 0 ) differ = 1;
+
+              if ( !differ && grid->nvertex != gridInqNvertex(gridID) ) differ = 1;
+
+              if ( !differ && grid->number != gridInqNumber(gridID) ) differ = 1;
+              if ( !differ && grid->position != gridInqPosition(gridID) ) differ = 1;
+
+              if ( !differ && grid->nvertex != gridInqNvertex(gridID) ) differ = 1;
+              if ( !differ && grid->number != gridInqNumber(gridID) ) differ = 1;
+              if ( !differ && grid->number > 0 && grid->position != gridInqPosition(gridID) ) differ = 1;
 	      if ( !differ )
-		differ = compareXYvals2(gridID, grid.size, grid.xvals, grid.yvals);
+		differ = compareXYvals2(gridID, grid->size, grid->xvals, grid->yvals);
 	    }
 	}
     }
@@ -20415,21 +20328,22 @@ int gridCompareP ( void * gridptr1, void * gridptr2 )
   else if ( g2->mask_gme )
     return differ;
 
+  if (memcmp(g1->uuid, g2->uuid, CDI_UUID_SIZE))
+    return differ;
+
   return equal;
 }
 
 
-int gridGenerate(grid_t grid)
+int gridGenerate(const grid_t *grid)
 {
-  int gridID = gridCreate(grid.type, grid.size);
+  int gridID = gridCreate(grid->type, grid->size);
 
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
+  grid_t *gridptr = gridID2Ptr(gridID);
 
-  grid_check_ptr(gridID, gridptr);
+  gridDefPrec(gridID, grid->prec);
 
-  gridDefPrec(gridID, grid.prec);
-
-  switch (grid.type)
+  switch (grid->type)
     {
     case GRID_LONLAT:
     case GRID_GAUSSIAN:
@@ -20442,51 +20356,51 @@ int gridGenerate(grid_t grid)
     case GRID_LAEA:
     case GRID_PROJECTION:
       {
-	if ( grid.xsize > 0 ) gridDefXsize(gridID, grid.xsize);
-	if ( grid.ysize > 0 ) gridDefYsize(gridID, grid.ysize);
+	if ( grid->xsize > 0 ) gridDefXsize(gridID, grid->xsize);
+	if ( grid->ysize > 0 ) gridDefYsize(gridID, grid->ysize);
 
-        if ( grid.type == GRID_GAUSSIAN ) gridDefNP(gridID, grid.np);
+        if ( grid->type == GRID_GAUSSIAN ) gridDefNP(gridID, grid->np);
 
-	if ( grid.nvertex > 0 )
-	  gridDefNvertex(gridID, grid.nvertex);
+	if ( grid->nvertex > 0 )
+	  gridDefNvertex(gridID, grid->nvertex);
 
-	if ( grid.xdef == 1 )
+	if ( grid->xdef == 1 )
 	  {
-	    gridDefXvals(gridID, grid.xvals);
-	    if ( grid.xbounds )
-	      gridDefXbounds(gridID, grid.xbounds);
+	    gridDefXvals(gridID, grid->xvals);
+	    if ( grid->xbounds )
+	      gridDefXbounds(gridID, grid->xbounds);
 	  }
-	else if ( grid.xdef == 2 )
+	else if ( grid->xdef == 2 )
 	  {
 	    double *xvals
-              = (double *)xmalloc((size_t)grid.xsize * sizeof (double));
-	    gridGenXvals(grid.xsize, grid.xfirst, grid.xlast, grid.xinc, xvals);
+              = (double *)xmalloc((size_t)grid->xsize * sizeof (double));
+	    gridGenXvals(grid->xsize, grid->xfirst, grid->xlast, grid->xinc, xvals);
 	    gridDefXvals(gridID, xvals);
 	    free(xvals);
 	    /*
-	    gridDefXinc(gridID, grid.xinc);
+	    gridDefXinc(gridID, grid->xinc);
 	    */
 	  }
 
-	if ( grid.ydef == 1 )
+	if ( grid->ydef == 1 )
 	  {
-	    gridDefYvals(gridID, grid.yvals);
-	    if ( grid.ybounds && grid.nvertex )
-	      gridDefYbounds(gridID, grid.ybounds);
+	    gridDefYvals(gridID, grid->yvals);
+	    if ( grid->ybounds && grid->nvertex )
+	      gridDefYbounds(gridID, grid->ybounds);
 	  }
-	else if ( grid.ydef == 2 )
+	else if ( grid->ydef == 2 )
 	  {
 	    double *yvals
-              = (double *)xmalloc((size_t)grid.ysize * sizeof (double));
-	    gridGenYvals(grid.type, grid.ysize, grid.yfirst, grid.ylast, grid.yinc, yvals);
+              = (double *)xmalloc((size_t)grid->ysize * sizeof (double));
+	    gridGenYvals(grid->type, grid->ysize, grid->yfirst, grid->ylast, grid->yinc, yvals);
 	    gridDefYvals(gridID, yvals);
 	    free(yvals);
 	    /*
-	    gridDefYinc(gridID, grid.yinc);
+	    gridDefYinc(gridID, grid->yinc);
 	    */
 	  }
 
-	if ( grid.isRotated )
+	if ( grid->isRotated )
 	  {
 	    gridDefXname(gridID, "rlon");
 	    gridDefYname(gridID, "rlat");
@@ -20497,109 +20411,109 @@ int gridGenerate(grid_t grid)
 	    gridDefXunits(gridID, "degrees");
 	    gridDefYunits(gridID, "degrees");
 
-	    gridDefXpole(gridID, grid.xpole);
-	    gridDefYpole(gridID, grid.ypole);
-	    gridDefAngle(gridID, grid.angle);
+	    gridDefXpole(gridID, grid->xpole);
+	    gridDefYpole(gridID, grid->ypole);
+	    gridDefAngle(gridID, grid->angle);
 	  }
 
-	if ( grid.area )
+	if ( grid->area )
 	  {
-	    gridDefArea(gridID, grid.area);
+	    gridDefArea(gridID, grid->area);
 	  }
 
-	if ( grid.type == GRID_LAEA )
-	  gridDefLaea(gridID, grid.laea_a, grid.laea_lon_0, grid.laea_lat_0);
+	if ( grid->type == GRID_LAEA )
+	  gridDefLaea(gridID, grid->laea_a, grid->laea_lon_0, grid->laea_lat_0);
 
-	if ( grid.type == GRID_LCC2 )
-	  gridDefLcc2(gridID, grid.lcc2_a, grid.lcc2_lon_0, grid.lcc2_lat_0, grid.lcc2_lat_1, grid.lcc2_lat_2);
+	if ( grid->type == GRID_LCC2 )
+	  gridDefLcc2(gridID, grid->lcc2_a, grid->lcc2_lon_0, grid->lcc2_lat_0, grid->lcc2_lat_1, grid->lcc2_lat_2);
 
-	if ( grid.type == GRID_LCC )
-	  gridDefLCC(gridID, grid.lcc_originLon, grid.lcc_originLat, grid.lcc_lonParY,
-		     grid.lcc_lat1, grid.lcc_lat2, grid.lcc_xinc, grid.lcc_yinc,
-		     grid.lcc_projflag, grid.lcc_scanflag);
+	if ( grid->type == GRID_LCC )
+	  gridDefLCC(gridID, grid->lcc_originLon, grid->lcc_originLat, grid->lcc_lonParY,
+		     grid->lcc_lat1, grid->lcc_lat2, grid->lcc_xinc, grid->lcc_yinc,
+		     grid->lcc_projflag, grid->lcc_scanflag);
 
-	if ( grid.type == GRID_UNSTRUCTURED )
+	if ( grid->type == GRID_UNSTRUCTURED )
           {
-            int number = grid.number;
-            int position = grid.position;
+            int number = grid->number;
+            int position = grid->position;
             if ( position < 0 ) position = 0;
             if ( number > 0 )
               {
                 gridDefNumber(gridID, number);
                 gridDefPosition(gridID, position);
               }
-            if ( grid.uuid[0] != 0 ) gridDefUUID(gridID, grid.uuid);
-            if ( grid.reference ) gridDefReference(gridID, grid.reference);
+            gridDefUUID(gridID, grid->uuid);
+            if ( grid->reference ) gridDefReference(gridID, grid->reference);
           }
 
-	if ( grid.type == GRID_PROJECTION )
+	if ( grid->type == GRID_PROJECTION )
 	  {
-	    gridptr->name = strdup(grid.name);
+	    gridptr->name = strdup(grid->name);
 	  }
 
 	break;
       }
     case GRID_GAUSSIAN_REDUCED:
       {
-	gridDefNP(gridID, grid.np);
-	gridDefYsize(gridID, grid.ysize);
-	gridDefRowlon(gridID, grid.ysize, grid.rowlon);
+	gridDefNP(gridID, grid->np);
+	gridDefYsize(gridID, grid->ysize);
+	gridDefRowlon(gridID, grid->ysize, grid->rowlon);
 
-        if ( grid.xdef == 2 )
+        if ( grid->xdef == 2 )
           {
             double xvals[2];
-            xvals[0] = grid.xfirst;
-            xvals[1] = grid.xlast;
+            xvals[0] = grid->xfirst;
+            xvals[1] = grid->xlast;
             gridDefXvals(gridID, xvals);
           }
 
-	if ( grid.ydef == 1 )
+	if ( grid->ydef == 1 )
 	  {
-	    gridDefYvals(gridID, grid.yvals);
-	    if ( grid.ybounds && grid.nvertex )
-	      gridDefYbounds(gridID, grid.ybounds);
+	    gridDefYvals(gridID, grid->yvals);
+	    if ( grid->ybounds && grid->nvertex )
+	      gridDefYbounds(gridID, grid->ybounds);
 	  }
-	else if ( grid.ydef == 2 )
+	else if ( grid->ydef == 2 )
 	  {
 	    double *yvals
-              = (double *)xmalloc((size_t)grid.ysize * sizeof (double));
-	    gridGenYvals(grid.type, grid.ysize, grid.yfirst, grid.ylast, grid.yinc, yvals);
+              = (double *)xmalloc((size_t)grid->ysize * sizeof (double));
+	    gridGenYvals(grid->type, grid->ysize, grid->yfirst, grid->ylast, grid->yinc, yvals);
 	    gridDefYvals(gridID, yvals);
 	    free(yvals);
 	    /*
-	    gridDefYinc(gridID, grid.yinc);
+	    gridDefYinc(gridID, grid->yinc);
 	    */
 	  }
 	break;
       }
     case GRID_SPECTRAL:
       {
-        gridDefTrunc(gridID, grid.trunc);
-        if ( grid.lcomplex ) gridDefComplexPacking(gridID, 1);
+        gridDefTrunc(gridID, grid->trunc);
+        if ( grid->lcomplex ) gridDefComplexPacking(gridID, 1);
         break;
       }
     case GRID_FOURIER:
       {
-	gridDefTrunc(gridID, grid.trunc);
+	gridDefTrunc(gridID, grid->trunc);
 	break;
       }
     case GRID_GME:
       {
-        gridDefGMEnd(gridID, grid.nd);
-        gridDefGMEni(gridID, grid.ni);
-        gridDefGMEni2(gridID, grid.ni2);
-        gridDefGMEni3(gridID, grid.ni3);
+        gridDefGMEnd(gridID, grid->nd);
+        gridDefGMEni(gridID, grid->ni);
+        gridDefGMEni2(gridID, grid->ni2);
+        gridDefGMEni3(gridID, grid->ni3);
         break;
       }
       /*
     case GRID_GENERIC:
       {
-        if ( grid.xsize > 0 && grid.ysize > 0 )
+        if ( grid->xsize > 0 && grid->ysize > 0 )
           {
-            gridDefXsize(gridID, grid.xsize);
-            gridDefYsize(gridID, grid.ysize);
-            if ( grid.xvals ) gridDefXvals(gridID, grid.xvals);
-            if ( grid.yvals ) gridDefYvals(gridID, grid.yvals);
+            gridDefXsize(gridID, grid->xsize);
+            gridDefYsize(gridID, grid->ysize);
+            if ( grid->xvals ) gridDefXvals(gridID, grid->xvals);
+            if ( grid->yvals ) gridDefYvals(gridID, grid->yvals);
           }
         break;
       }
@@ -20612,17 +20526,17 @@ int gridGenerate(grid_t grid)
       }
     default:
       {
-	Error("Gridtype %s unsupported!", gridNamePtr(grid.type));
+	Error("Gridtype %s unsupported!", gridNamePtr(grid->type));
 	break;
       }
     }
 
-  if ( grid.xname[0]     ) gridDefXname(gridID, grid.xname);
-  if ( grid.xlongname[0] ) gridDefXlongname(gridID, grid.xlongname);
-  if ( grid.xunits[0]    ) gridDefXunits(gridID, grid.xunits);
-  if ( grid.yname[0]     ) gridDefYname(gridID, grid.yname);
-  if ( grid.ylongname[0] ) gridDefYlongname(gridID, grid.ylongname);
-  if ( grid.yunits[0]    ) gridDefYunits(gridID, grid.yunits);
+  if ( grid->xname[0]     ) gridDefXname(gridID, grid->xname);
+  if ( grid->xlongname[0] ) gridDefXlongname(gridID, grid->xlongname);
+  if ( grid->xunits[0]    ) gridDefXunits(gridID, grid->xunits);
+  if ( grid->yname[0]     ) gridDefYname(gridID, grid->yname);
+  if ( grid->ylongname[0] ) gridDefYlongname(gridID, grid->ylongname);
+  if ( grid->yunits[0]    ) gridDefYunits(gridID, grid->yunits);
 
   return (gridID);
 }
@@ -20647,8 +20561,6 @@ int gridDuplicate(int gridID)
 {
   grid_t *gridptr = reshGetVal(gridID, &gridOps);
 
-  grid_check_ptr(gridID, gridptr);
-
   int gridtype = gridInqType(gridID);
   int gridsize = gridInqSize(gridID);
 
@@ -20741,9 +20653,7 @@ int gridDuplicate(int gridID)
 
 void gridCompress(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int gridtype = gridInqType(gridID);
   if ( gridtype == GRID_UNSTRUCTURED )
@@ -20811,9 +20721,7 @@ void gridCompress(int gridID)
 
 void gridDefArea(int gridID, const double *area)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t size = gridptr->size;
 
@@ -20832,9 +20740,7 @@ void gridDefArea(int gridID, const double *area)
 
 void gridInqArea(int gridID, double *area)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->area)
     memcpy(area, gridptr->area, (size_t)gridptr->size * sizeof (double));
@@ -20843,9 +20749,7 @@ void gridInqArea(int gridID, double *area)
 
 int gridHasArea(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int hasArea = (gridptr->area != NULL);
 
@@ -20855,9 +20759,7 @@ int gridHasArea(int gridID)
 
 const double *gridInqAreaPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->area);
 }
@@ -20865,9 +20767,7 @@ const double *gridInqAreaPtr(int gridID)
 
 void gridDefNvertex(int gridID, int nvertex)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->nvertex != nvertex)
     {
@@ -20879,9 +20779,7 @@ void gridDefNvertex(int gridID, int nvertex)
 
 int gridInqNvertex(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->nvertex);
 }
@@ -20902,9 +20800,7 @@ The function @func{gridDefXbounds} defines all bounds of the X-axis.
 */
 void gridDefXbounds(int gridID, const double *xbounds)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t nvertex = (size_t)gridptr->nvertex;
   if ( nvertex == 0 )
@@ -20951,21 +20847,14 @@ Otherwise, 0 is returned and @func{xbounds} is empty.
 */
 int gridInqXbounds(int gridID, double *xbounds)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t nvertex = (size_t)gridptr->nvertex;
-  if ( CDI_Debug && nvertex == 0 )
-    Warning("nvertex undefined for gridID = %d", gridID);
 
   int irregular = gridptr->type == GRID_CURVILINEAR
     || gridptr->type == GRID_UNSTRUCTURED;
   size_t size = nvertex * (size_t)(irregular ? gridptr->size : gridptr->xsize);
 
-  if ( CDI_Debug && size == 0 )
-    Warning("size undefined for gridID = %d", gridID);
-
   if ( size && xbounds && gridptr->xbounds )
     memcpy(xbounds, gridptr->xbounds, size * sizeof (double));
 
@@ -20977,9 +20866,7 @@ int gridInqXbounds(int gridID, double *xbounds)
 
 const double *gridInqXboundsPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->xbounds);
 }
@@ -21000,9 +20887,7 @@ The function @func{gridDefYbounds} defines all bounds of the Y-axis.
 */
 void gridDefYbounds(int gridID, const double *ybounds)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t nvertex = (size_t)gridptr->nvertex;
   if ( nvertex == 0 )
@@ -21049,21 +20934,14 @@ Otherwise, 0 is returned and @func{ybounds} is empty.
 */
 int gridInqYbounds(int gridID, double *ybounds)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t nvertex = (size_t)gridptr->nvertex;
-  if ( CDI_Debug && nvertex == 0 )
-    Warning("nvertex undefined for gridID = %d", gridID);
 
   int irregular = gridptr->type == GRID_CURVILINEAR
     || gridptr->type == GRID_UNSTRUCTURED;
   size_t size = nvertex * (size_t)(irregular ? gridptr->size : gridptr->ysize);
 
-  if ( CDI_Debug && size == 0 )
-    Warning("size undefined for gridID = %d", gridID);
-
   if ( size && ybounds && gridptr->ybounds )
     memcpy(ybounds, gridptr->ybounds, size * sizeof (double));
 
@@ -21075,9 +20953,7 @@ int gridInqYbounds(int gridID, double *ybounds)
 
 const double *gridInqYboundsPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ybounds);
 }
@@ -21091,7 +20967,7 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp)
   int nbyte0, nbyte;
   int i;
   int nvertex, iv;
-  char uuidOfHGrid[17];
+  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
   int gridID = gridptr->self;
   const double *area    = gridInqAreaPtr(gridID);
   const double *xvals   = gridInqXvalsPtr(gridID);
@@ -21099,8 +20975,6 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp)
   const double *xbounds = gridInqXboundsPtr(gridID);
   const double *ybounds = gridInqYboundsPtr(gridID);
 
-  grid_check_ptr(gridID, gridptr);
-
   type     = gridInqType(gridID);
   trunc    = gridInqTrunc(gridID);
   gridsize = gridInqSize(gridID);
@@ -21403,7 +21277,7 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp)
     }
 
   gridInqUUID(gridID, uuidOfHGrid);
-  if ( uuidOfHGrid[0] != 0 )
+  if ( !cdiUUIDIsNull(uuidOfHGrid) )
     {
       char uuidOfHGridStr[37];
       uuid2str(uuidOfHGrid, uuidOfHGridStr);
@@ -21431,9 +21305,7 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp)
 
 void gridPrint ( int gridID, int opt )
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   gridPrintKernel ( gridptr, opt, stdout );
 }
@@ -21498,9 +21370,7 @@ void gridPrintP ( void * voidptr, FILE * fp )
 
 const double *gridInqXvalsPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return ( gridptr->xvals );
 }
@@ -21508,9 +21378,7 @@ const double *gridInqXvalsPtr(int gridID)
 
 const double *gridInqYvalsPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return ( gridptr->yvals );
 }
@@ -21541,9 +21409,7 @@ void gridDefLCC(int gridID, double originLon, double originLat, double lonParY,
                 double lat1, double lat2, double xinc, double yinc,
                 int projflag, int scanflag)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LCC )
     Warning("Definition of LCC grid for %s grid not allowed!",
@@ -21590,9 +21456,7 @@ void gridInqLCC(int gridID, double *originLon, double *originLat, double *lonPar
                 double *lat1, double *lat2, double *xinc, double *yinc,
                 int *projflag, int *scanflag)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LCC )
     Warning("Inquire of LCC grid definition for %s grid not allowed!",
@@ -21618,9 +21482,7 @@ void gridInqLCC(int gridID, double *originLon, double *originLat, double *lonPar
 
 void gridDefLcc2(int gridID, double earth_radius, double lon_0, double lat_0, double lat_1, double lat_2)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LCC2 )
     Warning("Definition of LCC2 grid for %s grid not allowed!",
@@ -21640,9 +21502,7 @@ void gridDefLcc2(int gridID, double earth_radius, double lon_0, double lat_0, do
 
 void gridInqLcc2(int gridID, double *earth_radius, double *lon_0, double *lat_0, double *lat_1, double *lat_2)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LCC2 )
     Warning("Inquire of LCC2 grid definition for %s grid not allowed!",
@@ -21664,9 +21524,7 @@ void gridInqLcc2(int gridID, double *earth_radius, double *lon_0, double *lat_0,
 
 void gridDefLaea(int gridID, double earth_radius, double lon_0, double lat_0)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LAEA )
     Warning("Definition of LAEA grid for %s grid not allowed!",
@@ -21684,9 +21542,7 @@ void gridDefLaea(int gridID, double earth_radius, double lon_0, double lat_0)
 
 void gridInqLaea(int gridID, double *earth_radius, double *lon_0, double *lat_0)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LAEA )
     Warning("Inquire of LAEA grid definition for %s grid not allowed!",
@@ -21707,9 +21563,7 @@ void gridInqLaea(int gridID, double *earth_radius, double *lon_0, double *lat_0)
 
 void gridDefComplexPacking(int gridID, int lcomplex)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
 
   if (gridptr->lcomplex != lcomplex)
@@ -21722,9 +21576,7 @@ void gridDefComplexPacking(int gridID, int lcomplex)
 
 int gridInqComplexPacking(int gridID)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   return (gridptr->lcomplex);
 }
@@ -21732,9 +21584,7 @@ int gridInqComplexPacking(int gridID)
 
 void gridDefHasDims(int gridID, int hasdims)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   if (gridptr->hasdims != hasdims)
     {
@@ -21746,9 +21596,7 @@ void gridDefHasDims(int gridID, int hasdims)
 
 int gridInqHasDims(int gridID)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   return (gridptr->hasdims);
 }
@@ -21769,9 +21617,7 @@ The function @func{gridDefNumber} defines the reference number for an unstructur
 */
 void gridDefNumber(int gridID, const int number)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->number != number)
     {
@@ -21797,9 +21643,7 @@ The function @func{gridInqNumber} returns the reference number to an unstructure
 */
 int gridInqNumber(int gridID)
 {
-  grid_t* gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   return (gridptr->number);
 }
@@ -21820,9 +21664,7 @@ The function @func{gridDefPosition} defines the position of grid in the referenc
 */
 void gridDefPosition(int gridID, int position)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   if (gridptr->position != position)
     {
@@ -21848,9 +21690,7 @@ The function @func{gridInqPosition} returns the position of grid in the referenc
 */
 int gridInqPosition(int gridID)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->position);
 }
@@ -21871,9 +21711,7 @@ The function @func{gridDefReference} defines the reference URI for an unstructur
 */
 void gridDefReference(int gridID, const char *reference)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   if ( reference )
     {
@@ -21906,16 +21744,11 @@ The function @func{gridInqReference} returns the reference URI to an unstructure
 int gridInqReference(int gridID, char *reference)
 {
   int len = 0;
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
-  if ( gridptr->reference )
+  if ( gridptr->reference && reference )
     {
-      len = (int) strlen(gridptr->reference);
-
-      if ( reference )
-        strcpy(reference, gridptr->reference);
+      strcpy(reference, gridptr->reference);
     }
 
   return (len);
@@ -21935,13 +21768,11 @@ The function @func{gridDefUUID} defines the UUID for an unstructured grid.
 
 @EndFunction
 */
-void gridDefUUID(int gridID, const char *uuid)
+void gridDefUUID(int gridID, const unsigned char uuid[CDI_UUID_SIZE])
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
-  memcpy(gridptr->uuid, uuid, 16);
+  memcpy(gridptr->uuid, uuid, CDI_UUID_SIZE);
   reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
 }
 
@@ -21960,13 +21791,11 @@ The function @func{gridInqUUID} returns the UUID to an unstructured grid.
 @func{gridInqUUID} returns the UUID to an unstructured grid to the parameter uuid.
 @EndFunction
 */
-void gridInqUUID(int gridID, char *uuid)
+void gridInqUUID(int gridID, unsigned char uuid[CDI_UUID_SIZE])
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
-  grid_check_ptr(gridID, gridptr);
-
-  memcpy(uuid, gridptr->uuid, 16);
+  memcpy(uuid, gridptr->uuid, CDI_UUID_SIZE);
 }
 
 
@@ -21993,7 +21822,8 @@ enum { gridNint    = 27,
        gridHasXBoundsFlag = 1 << 5,
        gridHasYBoundsFlag = 1 << 6,
        gridHasReferenceFlag = 1 << 7,
-       gridHasRowLonFlag = 1 << 8
+       gridHasRowLonFlag = 1 << 8,
+       gridHasUUIDFlag = 1 << 9,
 };
 
 
@@ -22007,8 +21837,8 @@ static int gridGetComponentFlags(const grid_t * gridP)
     | (gridHasXBoundsFlag & (int)((unsigned)(gridP->xbounds == NULL) - 1U))
     | (gridHasYBoundsFlag & (int)((unsigned)(gridP->ybounds == NULL) - 1U))
     | (gridHasReferenceFlag & (int)((unsigned)(gridP->reference == NULL) - 1U))
-    | (gridHasRowLonFlag & (int)((unsigned)(gridP->rowlon == NULL) - 1U));
-
+    | (gridHasRowLonFlag & (int)((unsigned)(gridP->rowlon == NULL) - 1U))
+    | (gridHasUUIDFlag & (int)((unsigned)cdiUUIDIsNull(gridP->uuid) - 1U));
   return flags;
 }
 
@@ -22114,9 +21944,16 @@ gridGetPackSize(void * voidP, void *context)
         + serializeGetSize(1, DATATYPE_UINT32, context);
     }
 
+  if (!cdiUUIDIsNull(gridP->uuid))
+    packBuffSize += serializeGetSize(CDI_UUID_SIZE, DATATYPE_UCHAR, context);
+
   return packBuffSize;
 }
 
+#define GRID_STR_SERIALIZE { gridP->xname, gridP->yname, \
+    gridP->xlongname, gridP->ylongname, \
+    gridP->xstdname, gridP->ystdname, \
+    gridP->xunits, gridP->yunits }
 
 void
 gridUnpack(char * unpackBuffer, int unpackBufferSize,
@@ -22286,15 +22123,12 @@ gridUnpack(char * unpackBuffer, int unpackBufferSize,
                   &d, 1, DATATYPE_UINT32, context);
 
   xassert(d == cdiCheckSum(DATATYPE_TXT, gridNstrings * CDI_MAX_NAME, charBuffer));
-
-  memcpy ( gridP->xname    , &charBuffer[CDI_MAX_NAME * 0], CDI_MAX_NAME );
-  memcpy ( gridP->yname    , &charBuffer[CDI_MAX_NAME * 1], CDI_MAX_NAME );
-  memcpy ( gridP->xlongname, &charBuffer[CDI_MAX_NAME * 2], CDI_MAX_NAME );
-  memcpy ( gridP->ylongname, &charBuffer[CDI_MAX_NAME * 3], CDI_MAX_NAME );
-  memcpy ( gridP->xstdname , &charBuffer[CDI_MAX_NAME * 4], CDI_MAX_NAME );
-  memcpy ( gridP->ystdname , &charBuffer[CDI_MAX_NAME * 5], CDI_MAX_NAME );
-  memcpy ( gridP->xunits   , &charBuffer[CDI_MAX_NAME * 6], CDI_MAX_NAME );
-  memcpy ( gridP->yunits   , &charBuffer[CDI_MAX_NAME * 7], CDI_MAX_NAME );
+  {
+    char *strTab[] = GRID_STR_SERIALIZE;
+    size_t numStr = sizeof (strTab) / sizeof (strTab[0]);
+    for (size_t i = 0; i < numStr; ++i)
+      memcpy(strTab[i], charBuffer + CDI_MAX_NAME * i, CDI_MAX_NAME);
+  }
 
   if (memberMask & gridHasReferenceFlag)
     {
@@ -22330,6 +22164,11 @@ gridUnpack(char * unpackBuffer, int unpackBufferSize,
                       &d, 1, DATATYPE_UINT32, context);
       xassert(cdiCheckSum(DATATYPE_UCHAR, gridP->size, gridP->mask_gme) == d);
     }
+  if (memberMask & gridHasUUIDFlag)
+    {
+      serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
+                      gridP->uuid, CDI_UUID_SIZE, DATATYPE_UCHAR, context);
+    }
 }
 
 
@@ -22340,6 +22179,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
   grid_t   * gridP = ( grid_t * )   voidP;
   int size;
   uint32_t d;
+  int memberMask;
   char charBuffer[gridNstrings * CDI_MAX_NAME];
 
   {
@@ -22371,7 +22211,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
     intBuffer[23] = gridP->ysize;
     intBuffer[24] = gridP->locked;
     intBuffer[25] = gridP->lcomplex;
-    intBuffer[26] = gridGetComponentFlags(gridP);
+    intBuffer[26] = memberMask = gridGetComponentFlags(gridP);
 
     serializePack(intBuffer, gridNint, DATATYPE_INT,
                   packBuffer, packBufferSize, packBufferPos, context);
@@ -22380,7 +22220,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                   packBuffer, packBufferSize, packBufferPos, context);
   }
 
-  if (gridP->rowlon)
+  if (memberMask & gridHasRowLonFlag)
     {
       xassert((size = gridP->nrowlon));
       serializePack(gridP->rowlon, size, DATATYPE_INT,
@@ -22425,7 +22265,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                   packBuffer, packBufferSize, packBufferPos, context);
   }
 
-  if (gridP->xvals)
+  if (memberMask & gridHasXValsFlag)
     {
       if (gridP->type == GRID_UNSTRUCTURED || gridP->type == GRID_CURVILINEAR)
 	size = gridP->size;
@@ -22440,7 +22280,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->yvals)
+  if (memberMask & gridHasYValsFlag)
     {
       if (gridP->type == GRID_UNSTRUCTURED || gridP->type == GRID_CURVILINEAR )
 	size = gridP->size;
@@ -22454,7 +22294,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->area)
+  if (memberMask & gridHasAreaFlag)
     {
       xassert(gridP->size);
 
@@ -22465,7 +22305,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->xbounds)
+  if (memberMask & gridHasXBoundsFlag)
     {
       xassert ( gridP->nvertex );
       if (gridP->type == GRID_CURVILINEAR || gridP->type == GRID_UNSTRUCTURED)
@@ -22481,7 +22321,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->ybounds)
+  if (memberMask & gridHasYBoundsFlag)
     {
       xassert(gridP->nvertex);
       if (gridP->type == GRID_CURVILINEAR || gridP->type == GRID_UNSTRUCTURED)
@@ -22497,14 +22337,12 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  memcpy ( &charBuffer[CDI_MAX_NAME * 0], gridP->xname,     CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 1], gridP->yname,     CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 2], gridP->xlongname, CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 3], gridP->ylongname, CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 4], gridP->xstdname,  CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 5], gridP->ystdname,  CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 6], gridP->xunits,    CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 7], gridP->yunits,    CDI_MAX_NAME );
+  {
+    char *strTab[] = GRID_STR_SERIALIZE;
+    size_t numStr = sizeof (strTab) / sizeof (strTab[0]);
+    for (size_t i = 0; i < numStr; ++i)
+      memcpy(charBuffer + CDI_MAX_NAME * i, strTab[i], CDI_MAX_NAME);
+  }
 
   serializePack( charBuffer, gridNstrings * CDI_MAX_NAME, DATATYPE_TXT,
 		    packBuffer, packBufferSize, packBufferPos, context);
@@ -22512,7 +22350,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
   serializePack(&d, 1, DATATYPE_UINT32,
                 packBuffer, packBufferSize, packBufferPos, context);
 
-  if ( gridP->reference )
+  if (memberMask & gridHasReferenceFlag)
     {
       size = (int)strlen(gridP->reference) + 1;
       serializePack(&size, 1, DATATYPE_INT,
@@ -22524,7 +22362,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if ( gridP->mask )
+  if (memberMask & gridHasMaskFlag)
     {
       xassert((size = gridP->size));
       serializePack(gridP->mask, size, DATATYPE_UCHAR,
@@ -22534,7 +22372,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->mask_gme)
+  if (memberMask & gridHasGMEMaskFlag)
     {
       xassert((size = gridP->size));
 
@@ -22544,6 +22382,10 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
       serializePack(&d, 1, DATATYPE_UINT32,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
+
+  if (memberMask & gridHasUUIDFlag)
+    serializePack(gridP->uuid, CDI_UUID_SIZE, DATATYPE_UCHAR,
+                  packBuffer, packBufferSize, packBufferPos, context);
 }
 
 /*
@@ -22630,7 +22472,7 @@ typedef struct {
   double  *vct;
   int      number;   /* Reference number to a generalized Z-axis */
   int      nhlev;
-  char     uuid[17];
+  unsigned char uuid[CDI_UUID_SIZE];
 }
 zaxis_t;
 
@@ -22675,7 +22517,7 @@ void zaxisDefaultValue(zaxis_t *zaxisptr)
   zaxisptr->vct         = NULL;
   zaxisptr->number      = 0;
   zaxisptr->nhlev       = 0;
-  zaxisptr->uuid[0]     = 0;
+  memset(zaxisptr->uuid, 0, CDI_UUID_SIZE);
 }
 
 
@@ -23294,13 +23136,13 @@ The function @func{zaxisDefUUID} defines the UUID for a generalized  Z-axis.
 
 @EndFunction
 */
-void zaxisDefUUID(int zaxisID, const char *uuid)
+void zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE])
 {
   zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
 
   zaxis_check_ptr(zaxisID, zaxisptr);
 
-  memcpy(zaxisptr->uuid, uuid, 16);
+  memcpy(zaxisptr->uuid, uuid, CDI_UUID_SIZE);
   reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
 }
 
@@ -23319,13 +23161,13 @@ The function @func{zaxisInqUUID} returns the UUID to a generalized Z-axis.
 @func{zaxisInqUUID} returns the UUID to a generalized Z-axis to the parameter uuid.
 @EndFunction
 */
-void zaxisInqUUID(int zaxisID, char *uuid)
+void zaxisInqUUID(int zaxisID, unsigned char uuid[CDI_UUID_SIZE])
 {
   zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
 
   zaxis_check_ptr(zaxisID, zaxisptr);
 
-  memcpy(uuid, zaxisptr->uuid, 16);
+  memcpy(uuid, zaxisptr->uuid, CDI_UUID_SIZE);
 }
 
 /*
@@ -23799,7 +23641,7 @@ void zaxisPrintKernel ( zaxis_t * zaxisptr, FILE * fp )
 {
   int zaxisID;
   int type;
-  char uuid[17];
+  unsigned char uuid[CDI_UUID_SIZE];
   int nlevels, levelID;
   int nbyte0, nbyte;
   double level;
@@ -23900,7 +23742,7 @@ void zaxisPrintKernel ( zaxis_t * zaxisptr, FILE * fp )
     {
       const unsigned char *d;
       zaxisInqUUID(zaxisID, uuid);
-      d = (unsigned char *) &uuid;
+      d = uuid;
       fprintf(fp, "uuid      = %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
               d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
               d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
@@ -23931,7 +23773,7 @@ static int
 zaxisCompareP(zaxis_t *z1, zaxis_t *z2)
 {
   enum {
-    differ = -1,
+    differ = 1,
   };
   int diff = 0;
   xassert(z1 && z2);
@@ -24005,8 +23847,9 @@ zaxisCompareP(zaxis_t *z1, zaxis_t *z2)
   diff |= strcmp(z1->name, z2->name)
     | strcmp(z1->longname, z2->longname)
     | strcmp(z1->stdname, z2->stdname)
-    | strcmp(z1->units, z2->units);
-  return diff;
+    | strcmp(z1->units, z2->units)
+    | memcmp(z1->uuid, z2->uuid, CDI_UUID_SIZE);
+  return diff != 0;
 }
 
 
@@ -24022,7 +23865,8 @@ enum { zaxisNint     = 8,
        lbounds  = 1 << 1,
        ubounds  = 1 << 2,
        weights  = 1 << 3,
-       vct      = 1 << 4
+       vct      = 1 << 4,
+       zaxisHasUUIDFlag = 1 << 5,
 };
 
 
@@ -24036,7 +23880,7 @@ int zaxisGetMemberMask ( zaxis_t * zaxisP )
   if ( zaxisP->ubounds )   memberMask |= ubounds;
   if ( zaxisP->weights )   memberMask |= weights;
   if ( zaxisP->vct )       memberMask |= vct;
-
+  if (!cdiUUIDIsNull(zaxisP->uuid)) memberMask |= zaxisHasUUIDFlag;
   return memberMask;
 }
 
@@ -24076,6 +23920,10 @@ zaxisGetPackSize(void * voidP, void *context)
   packBufferSize += serializeGetSize(zaxisNstrings * CDI_MAX_NAME, DATATYPE_TXT, context)
     + serializeGetSize(1, DATATYPE_UINT32, context)
     + serializeGetSize(1, DATATYPE_UCHAR, context);
+
+  if (!cdiUUIDIsNull(zaxisP->uuid))
+    packBufferSize += serializeGetSize(CDI_UUID_SIZE, DATATYPE_UCHAR, context);
+
   return packBufferSize;
 }
 
@@ -24189,6 +24037,11 @@ zaxisUnpack(char * unpackBuffer, int unpackBufferSize,
 
   serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
                   &zaxisP->positive, 1, DATATYPE_UCHAR, context);
+
+  if (memberMask & zaxisHasUUIDFlag)
+    serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
+                    zaxisP->uuid, CDI_UUID_SIZE, DATATYPE_UCHAR, context);
+
 }
 
 static void
@@ -24197,6 +24050,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
 {
   zaxis_t   * zaxisP = ( zaxis_t * ) voidP;
   int intBuffer[zaxisNint];
+  int memberMask;
   uint32_t d;
   char charBuffer[zaxisNstrings * CDI_MAX_NAME];
 
@@ -24207,7 +24061,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
   intBuffer[4]  = zaxisP->size;
   intBuffer[5]  = zaxisP->direction;
   intBuffer[6]  = zaxisP->vctsize;
-  intBuffer[7]  = zaxisGetMemberMask ( zaxisP );
+  intBuffer[7]  = memberMask = zaxisGetMemberMask ( zaxisP );
 
   serializePack(intBuffer, zaxisNint, DATATYPE_INT,
                 packBuffer, packBufferSize, packBufferPos, context);
@@ -24216,7 +24070,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                 packBuffer, packBufferSize, packBufferPos, context);
 
 
-  if ( zaxisP->vals )
+  if ( memberMask & vals )
     {
       xassert(zaxisP->size);
       serializePack(zaxisP->vals, zaxisP->size, DATATYPE_FLT64,
@@ -24226,7 +24080,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (zaxisP->lbounds)
+  if (memberMask & lbounds)
     {
       xassert(zaxisP->size);
       serializePack(zaxisP->lbounds, zaxisP->size, DATATYPE_FLT64,
@@ -24236,7 +24090,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (zaxisP->ubounds)
+  if (memberMask & ubounds)
     {
       xassert(zaxisP->size);
 
@@ -24247,7 +24101,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (zaxisP->weights)
+  if (memberMask & weights)
     {
       xassert(zaxisP->size);
 
@@ -24258,7 +24112,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (zaxisP->vct)
+  if (memberMask & vct)
     {
       xassert(zaxisP->vctsize);
 
@@ -24282,6 +24136,11 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
 
   serializePack(&zaxisP->positive, 1, DATATYPE_UCHAR,
                 packBuffer, packBufferSize, packBufferPos, context);
+
+  if (memberMask & zaxisHasUUIDFlag)
+    serializePack(zaxisP->uuid, CDI_UUID_SIZE, DATATYPE_UCHAR,
+                  packBuffer, packBufferSize, packBufferPos, context);
+
 }
 
 
@@ -25482,7 +25341,7 @@ void cdiDebug(int level)
 
   if ( level == 1 || (level & 16) )
     {
-#if  defined  (HAVE_LIBGRIB)
+#if  defined  (HAVE_LIBCGRIBEX)
       gribSetDebug(1);
 #endif
 #if  defined  (HAVE_LIBNETCDF)
@@ -25767,7 +25626,7 @@ double cdiInqMissval(void)
 
 
 
-static stream_t *stream_new_entry(void);
+static stream_t *stream_new_entry(int resH);
 static void stream_delete_entry(stream_t *streamptr);
 static int streamCompareP(void * streamptr1, void * streamptr2);
 static void streamDestroyP(void * streamptr);
@@ -25812,8 +25671,8 @@ int getByteorder(int byteswap)
   return (byteorder);
 }
 
-static
-int getFiletype(const char *filename, int *byteorder)
+// used also in CDO
+int cdiGetFiletype(const char *filename, int *byteorder)
 {
   int filetype = CDI_EUFTYPE;
   int swap = 0;
@@ -26245,18 +26104,22 @@ int cdiStreamOpenDefaultDelegate(const char *filename, const char *filemode,
 }
 
 
-int streamOpen(const char *filename, const char *filemode, int filetype)
+static int
+streamOpenID(const char *filename, const char *filemode, int filetype,
+             int resH)
 {
   int fileID = CDI_UNDEFID;
-  int streamID = CDI_ESYSTEM;
   int status;
-  stream_t *streamptr = stream_new_entry();
 
   if ( CDI_Debug )
-    Message("Open %s mode %c file %s", strfiletype(filetype), (int) *filemode, filename);
+    Message("Open %s mode %c file %s", strfiletype(filetype), (int) *filemode,
+            filename?filename:"(NUL)");
 
   if ( ! filename || ! filemode || filetype < 0 ) return (CDI_EINVAL);
 
+  stream_t *streamptr = stream_new_entry(resH);
+  int streamID = CDI_ESYSTEM;
+
   {
     int (*streamOpenDelegate)(const char *filename, const char *filemode,
                               int filetype, stream_t *streamptr, int recordBufIsToBeCreated)
@@ -26292,20 +26155,24 @@ int streamOpen(const char *filename, const char *filemode, int filetype)
 	  status = cdiInqContents(streamptr);
 	  if ( status < 0 ) return (status);
 	  vlist_t *vlistptr = vlist_to_pointer(streamptr->vlistID);
-	  vlistptr->ntsteps = streamNtsteps(streamID);
+	  vlistptr->ntsteps = streamptr->ntsteps;
 	}
     }
 
   return (streamID);
 }
 
+int streamOpen(const char *filename, const char *filemode, int filetype)
+{
+  return streamOpenID(filename, filemode, filetype, CDI_UNDEFID);
+}
 
 static int streamOpenA(const char *filename, const char *filemode, int filetype)
 {
   int fileID = CDI_UNDEFID;
   int streamID = CDI_ESYSTEM;
   int status;
-  stream_t *streamptr = stream_new_entry();
+  stream_t *streamptr = stream_new_entry(CDI_UNDEFID);
   vlist_t *vlistptr;
 
   if ( CDI_Debug )
@@ -26455,7 +26322,7 @@ int streamOpenRead(const char *filename)
   cdiInitialize();
 
   int byteorder = 0;
-  int filetype = getFiletype(filename, &byteorder);
+  int filetype = cdiGetFiletype(filename, &byteorder);
 
   if ( filetype < 0 ) return (filetype);
 
@@ -26476,7 +26343,7 @@ int streamOpenAppend(const char *filename)
   cdiInitialize();
 
   int byteorder = 0;
-  int filetype = getFiletype(filename, &byteorder);
+  int filetype = cdiGetFiletype(filename, &byteorder);
 
   if ( filetype < 0 ) return (filetype);
 
@@ -26599,7 +26466,7 @@ void streamDefaultValue ( stream_t * streamptr )
 }
 
 
-static stream_t *stream_new_entry(void)
+static stream_t *stream_new_entry(int resH)
 {
   stream_t *streamptr;
 
@@ -26607,7 +26474,13 @@ static stream_t *stream_new_entry(void)
 
   streamptr = (stream_t *) xmalloc(sizeof(stream_t));
   streamDefaultValue ( streamptr );
-  streamptr->self = reshPut (( void * ) streamptr, &streamOps );
+  if (resH == CDI_UNDEFID)
+    streamptr->self = reshPut(streamptr, &streamOps);
+  else
+    {
+      streamptr->self = resH;
+      reshReplace(resH, streamptr, &streamOps);
+    }
 
   return streamptr;
 }
@@ -27695,16 +27568,6 @@ void streamWriteContents(int streamID, char *cname)
   fclose(cnp);
 }
 
-
-int streamNtsteps(int streamID)
-{
-  stream_t *streamptr = stream_to_pointer(streamID);
-
-  stream_check_ptr(__func__, streamptr);
-
-  return (int)streamptr->ntsteps;
-}
-
 // This function is used in CDO!
 off_t streamNvals(int streamID)
 {
@@ -28122,9 +27985,9 @@ streamUnpack(char * unpackBuffer, int unpackBufferSize,
   serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
                   &d, 1, DATATYPE_UINT32, context);
   xassert(d == cdiCheckSum(DATATYPE_TXT, intBuffer[2], filename));
-  streamID = streamOpenWrite ( filename, intBuffer[1] );
-  xassert ( streamID >= 0 &&
-            namespaceAdaptKey ( intBuffer[0], originNamespace ) == streamID );
+  int targetStreamID = namespaceAdaptKey(intBuffer[0], originNamespace);
+  streamID = streamOpenID(filename, "w", intBuffer[1], targetStreamID);
+  xassert(streamID >= 0 && targetStreamID == streamID);
   streamDefByteorder(streamID, intBuffer[5]);
   streamDefCompType(streamID, intBuffer[6]);
   streamDefCompLevel(streamID, intBuffer[7]);
@@ -28151,9 +28014,8 @@ streamUnpack(char * unpackBuffer, int unpackBufferSize,
 
 void streamDefHistory(int streamID, int length, const char *history)
 {
-  stream_t *streamptr;
-
-  streamptr = stream_to_pointer(streamID);
+#ifdef HAVE_LIBNETCDF
+  stream_t *streamptr = stream_to_pointer(streamID);
 
   if ( streamptr->filetype == FILETYPE_NC  ||
        streamptr->filetype == FILETYPE_NC2 ||
@@ -28167,21 +28029,25 @@ void streamDefHistory(int streamID, int length, const char *history)
 	  len = strlen(history);
 	  if ( len )
 	    {
+              /* FIXME: what's the point of strdupx? Why not use
+               * history argument directly? */
 	      histstring = strdupx(history);
 	      cdfDefHistory(streamptr, length, histstring);
 	      free(histstring);
 	    }
 	}
     }
+#else
+  (void)streamID; (void)length; (void)history;
+#endif
 }
 
 
 int streamInqHistorySize(int streamID)
 {
   int size = 0;
-  stream_t *streamptr;
-
-  streamptr = stream_to_pointer(streamID);
+#ifdef HAVE_LIBNETCDF
+  stream_t *streamptr = stream_to_pointer(streamID);
 
   if ( streamptr->filetype == FILETYPE_NC  ||
        streamptr->filetype == FILETYPE_NC2 ||
@@ -28190,16 +28056,17 @@ int streamInqHistorySize(int streamID)
     {
       size = cdfInqHistorySize(streamptr);
     }
-
+#else
+  (void)streamID;
+#endif
   return (size);
 }
 
 
 void streamInqHistoryString(int streamID, char *history)
 {
-  stream_t *streamptr;
-
-  streamptr = stream_to_pointer(streamID);
+#ifdef HAVE_LIBNETCDF
+  stream_t *streamptr = stream_to_pointer(streamID);
 
   if ( streamptr->filetype == FILETYPE_NC  ||
        streamptr->filetype == FILETYPE_NC2 ||
@@ -28208,6 +28075,9 @@ void streamInqHistoryString(int streamID, char *history)
     {
       cdfInqHistoryString(streamptr, history);
     }
+#else
+  (void)streamID; (void)history;
+#endif
 }
 /*
  * Local Variables:
@@ -28597,7 +28467,7 @@ void cgribexAddRecord(stream_t * streamptr, int param, int *isec1, int *isec2, d
 
   cgribexGetGrid(streamptr, isec2, isec4, &grid, iret);
 
-  int gridID = varDefGrid(vlistID, grid, 0);
+  int gridID = varDefGrid(vlistID, &grid, 0);
 
   int zaxistype = grib1ltypeToZaxisType(ISEC1_LevelType);
 
@@ -28774,7 +28644,7 @@ int cgribexScanTimestep1(stream_t * streamptr)
   int tsID;
   int varID;
   size_t readsize;
-  int nrecords, nrecs, recID;
+  unsigned nrecords, recID;
   int nrecs_scanned = 0;
   int datatype;
   long recsize = 0;
@@ -28814,10 +28684,10 @@ int cgribexScanTimestep1(stream_t * streamptr)
 	Error("Skipping of %d records failed!", cdiSkipRecords);
 
       recpos  = fileGetPos(fileID);
-      fileSetPos(fileID, recsize, SEEK_CUR);
+      fileSetPos(fileID, (off_t)recsize, SEEK_CUR);
     }
 
-  nrecs = 0;
+  unsigned nrecs = 0;
   while ( TRUE )
     {
       recsize = gribGetSize(fileID);
@@ -28890,7 +28760,7 @@ int cgribexScanTimestep1(stream_t * streamptr)
 
 	  for ( recID = 0; recID < nrecs; recID++ )
 	    {
-	      if ( cgribexVarCompare(compVar, streamptr->tsteps[0].records[recID], 1) == 0 ) break;
+	      if ( cgribexVarCompare(compVar, streamptr->tsteps[0].records[recID], 0) == 0 ) break;
 	    }
 
 	  if ( cdiInventoryMode == 1 )
@@ -28964,18 +28834,18 @@ int cgribexScanTimestep1(stream_t * streamptr)
   vlistID = streamptr->vlistID;
   vlistDefTaxis(vlistID, taxisID);
 
-  nrecords = streamptr->tsteps[0].nallrecs;
-  if ( nrecords < streamptr->tsteps[0].recordSize )
+  nrecords = (unsigned)streamptr->tsteps[0].nallrecs;
+  if ( nrecords < (unsigned)streamptr->tsteps[0].recordSize )
     {
-      streamptr->tsteps[0].recordSize = nrecords;
+      streamptr->tsteps[0].recordSize = (int)nrecords;
       streamptr->tsteps[0].records =
       (record_t *) realloc(streamptr->tsteps[0].records, nrecords*sizeof(record_t));
     }
 
   streamptr->tsteps[0].recIDs = (int *) malloc(nrecords*sizeof(int));
-  streamptr->tsteps[0].nrecs = nrecords;
+  streamptr->tsteps[0].nrecs = (int)nrecords;
   for ( recID = 0; recID < nrecords; recID++ )
-    streamptr->tsteps[0].recIDs[recID] = recID;
+    streamptr->tsteps[0].recIDs[recID] = (int)recID;
 
   streamptr->record->buffer     = gribbuffer;
   streamptr->record->buffersize = (size_t)buffersize;
@@ -29064,7 +28934,7 @@ int cgribexScanTimestep2(stream_t * streamptr)
   cdi_create_records(streamptr, tsID);
 
   nrecords = streamptr->tsteps[tsID].nallrecs;
-  if ( nrecords ) streamptr->tsteps[1].recIDs = (int *) malloc(nrecords*sizeof(int));
+  if ( nrecords ) streamptr->tsteps[1].recIDs = (int *)xmalloc((size_t)nrecords * sizeof(int));
   streamptr->tsteps[1].nrecs = 0;
   for ( recID = 0; recID < nrecords; recID++ )
     streamptr->tsteps[1].recIDs[recID] = -1;
@@ -30335,12 +30205,6 @@ void cgribexDefLevel(int *isec1, int *isec2, double *fsec2, int zaxisID, int lev
 }
 
 static
-void cgribexDefMask(int *isec3)
-{
-  UNUSED(isec3);
-}
-
-static
 void cgribexDefaultSec0(int *isec0)
 {
   ISEC0_GRIB_Len     = 0;
@@ -30426,7 +30290,6 @@ size_t cgribexEncode(int memtype, int varID, int levelID, int vlistID, int gridI
   cgribexDefTime(isec1, vdate, vtime, tsteptype, numavg, vlistInqTaxis(vlistID));
   cgribexDefGrid(isec1, isec2, isec4, gridID);
   cgribexDefLevel(isec1, isec2, fsec2, zaxisID, levelID);
-  cgribexDefMask(isec3);
 
   cgribexDefEnsembleVar(isec1, vlistID, varID);
 
@@ -31086,10 +30949,12 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
       }
     case GRID_UNSTRUCTURED:
       {
-        char uuid[17];
-    	char reference_link[8192];
+        unsigned char uuid[CDI_UUID_SIZE];
+    	/*
+        char reference_link[8192];
         size_t len = sizeof(reference_link);
         reference_link[0] = 0;
+         */
 
         /* FIXME: assert(numberOfPoints <= INT_MAX && numberOfPoints >= INT_MIN) */
     	grid->size  = (int)numberOfPoints;
@@ -31108,10 +30973,10 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
                   grid->reference = strdupx(reference_link);
               }
             */
-            len = (size_t) 16;
-            if ( grib_get_bytes(gh, "uuidOfHGrid", (unsigned char *) uuid, &len) == 0)
+            size_t len = (size_t)CDI_UUID_SIZE;
+            if ( grib_get_bytes(gh, "uuidOfHGrid", uuid, &len) == 0)
               {
-                memcpy(grid->uuid, uuid, 16);
+                memcpy(grid->uuid, uuid, CDI_UUID_SIZE);
               }
           }
 	break;
@@ -31362,7 +31227,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
 
   gribapiGetGrid(gh, &grid);
 
-  gridID = varDefGrid(vlistID, grid, 0);
+  gridID = varDefGrid(vlistID, &grid, 0);
 
   zaxistype = gribapiGetZaxisType(editionNumber, leveltype1);
 
@@ -31391,7 +31256,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
     case ZAXIS_REFERENCE:
       {
         size_t len;
-        char uuid[17];
+        unsigned char uuid[CDI_UUID_SIZE];
         long ltmp;
         long nhlev, nvgrid;
 
@@ -31404,9 +31269,9 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
         nhlev = ltmp;
         GRIB_CHECK(grib_get_long(gh, "numberOfVGridUsed", &ltmp), 0);
         nvgrid = ltmp;
-        len = (size_t) 16;
-        uuid[16] = 0;
-        GRIB_CHECK(grib_get_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len), 0);
+        len = (size_t)CDI_UUID_SIZE;
+        memset(uuid, 0, CDI_UUID_SIZE);
+        GRIB_CHECK(grib_get_bytes(gh, "uuidOfVGrid", uuid, &len), 0);
         varDefZAxisReference((int) nhlev, (int) nvgrid, uuid);
         break;
       }
@@ -31693,16 +31558,6 @@ int gribapiScanTimestep1(stream_t * streamptr)
       lieee = FALSE;
 
       comptype = COMPRESS_NONE;
-      if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 )
-	{
-	  comptype = COMPRESS_SZIP;
-	  unzipsize += 100;
-	  if ( buffersize < (size_t)unzipsize )
-	    {
-	      buffersize = (size_t)unzipsize;
-	      gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
-	    }
-	}
 
       nrecs_scanned++;
       gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize);
@@ -31712,6 +31567,17 @@ int gribapiScanTimestep1(stream_t * streamptr)
 
       if ( editionNumber <= 1 )
 	{
+          if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 )
+            {
+              comptype = COMPRESS_SZIP;
+              unzipsize += 100;
+              if ( buffersize < (size_t)unzipsize )
+                {
+                  buffersize = (size_t)unzipsize;
+                  gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
+                }
+            }
+
 	  GRIB_CHECK(grib_get_long(gh, "table2Version", &lpar), 0);
 	  rtabnum = (int) lpar;
 	  GRIB_CHECK(grib_get_long(gh, "indicatorOfParameter", &lpar), 0);
@@ -31732,8 +31598,9 @@ int gribapiScanTimestep1(stream_t * streamptr)
 	  if ( status == 0 )
 	    {
 	      // fprintf(stderr, "packingType %d %s\n", len, typeOfPacking);
-	      if      ( strncmp(typeOfPacking, "grid_jpeg", len) == 0 ) comptype = COMPRESS_JPEG;
-	      else if ( strncmp(typeOfPacking, "grid_ieee", len) == 0 ) lieee = TRUE;
+	      if      ( strncmp(typeOfPacking, "grid_jpeg", len)  == 0 ) comptype = COMPRESS_JPEG;
+	      else if ( strncmp(typeOfPacking, "grid_ccsds", len) == 0 ) comptype = COMPRESS_SZIP;
+	      else if ( strncmp(typeOfPacking, "grid_ieee", len)  == 0 ) lieee = TRUE;
 	    }
 
 	  param = gribapiGetParam(gh);
@@ -31920,6 +31787,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
 	}
     }
 #else
+  (void)streamptr;
   Error("GRIB_API support not compiled in!");
 #endif
 
@@ -31927,10 +31795,10 @@ int gribapiScanTimestep1(stream_t * streamptr)
 }
 
 
+#ifdef HAVE_LIBGRIB_API
 int gribapiScanTimestep2(stream_t * streamptr)
 {
   int rstatus = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   off_t recpos = 0;
   unsigned char *gribbuffer = NULL;
   size_t buffersize = 0;
@@ -32191,16 +32059,16 @@ int gribapiScanTimestep2(stream_t * streamptr)
 
   streamptr->record->buffer     = gribbuffer;
   streamptr->record->buffersize = buffersize;
-#endif
 
   return (rstatus);
 }
+#endif
 
 
+#if  defined  (HAVE_LIBGRIB_API)
 int gribapiScanTimestep(stream_t * streamptr)
 {
   int rstatus = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   size_t recsize = 0;
   off_t recpos = 0;
   unsigned char *gribbuffer;
@@ -32477,22 +32345,19 @@ int gribapiScanTimestep(stream_t * streamptr)
     }
 
   rstatus = (int)streamptr->ntsteps;
-#else
-  Error("GRIB_API support not compiled in!");
-#endif
-
   return (rstatus);
 }
+#endif
 
 #ifdef gribWarning
 #undef gribWarning
 #endif
 
+#ifdef HAVE_LIBGRIB_API
 int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gridsize,
 		  int unreduced, int *nmiss, double missval, int vlistID, int varID)
 {
   int status = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   long lpar;
   long editionNumber, numberOfPoints;
   size_t datasize, dummy, recsize;
@@ -32543,12 +32408,10 @@ int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri
 
   grib_handle_delete(gh);
 
-#else
-  Error("GRIB_API support not compiled in!");
-#endif
-
   return (status);
 }
+#endif
+
 
 #if  defined  (HAVE_LIBGRIB_API)
 static
@@ -32882,15 +32745,12 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
       gridtype = GRID_LONLAT;
     }
 
-
   if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN )
     {
       if ( editionNumber != 2 || lieee ) { comptype = 0; }
 
       if ( comptype )
         {
-          //if ( nmiss > 0 ) comptype = 0;
-
           if ( comptype == COMPRESS_JPEG )
             {
               mesg = "grid_jpeg"; len = strlen(mesg);
@@ -32898,7 +32758,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
             }
           else if ( comptype == COMPRESS_SZIP )
             {
-              mesg = "grid_szip"; len = strlen(mesg);
+              mesg = "grid_ccsds"; len = strlen(mesg);
               GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
             }
           else
@@ -33066,10 +32926,8 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
 	    else
 	      GRIB_CHECK(my_grib_set_long(gh, "precision", 1), 0);
           }
-        else if ( comptype )
+        else
 	  {
-            //if ( nmiss > 0 ) comptype = 0;
-
             if ( comptype == COMPRESS_JPEG )
               {
                 mesg = "grid_jpeg"; len = strlen(mesg);
@@ -33077,7 +32935,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
               }
             else if ( comptype == COMPRESS_SZIP )
               {
-                mesg = "grid_szip"; len = strlen(mesg);
+                mesg = "grid_ccsds"; len = strlen(mesg);
                 GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
               }
             else
@@ -33086,11 +32944,6 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
                 GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
               }
 	  }
-	else
-	  {
-	    mesg = "grid_simple"; len = strlen(mesg);
-	    GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
-	  }
 
 	break;
       }
@@ -33183,11 +33036,18 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
 	GRIB_CHECK(my_grib_set_long(gh, "numberOfDataPoints", gridInqSize(gridID)), 0);
 	GRIB_CHECK(my_grib_set_long(gh, "totalNumberOfGridPoints", gridInqSize(gridID)), 0);
 
+        if ( comptype == COMPRESS_SZIP )
+          {
+            mesg = "grid_ccsds"; len = strlen(mesg);
+            GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
+          }
+
 	break;
       }
     case GRID_UNSTRUCTURED:
       {
 	static int warning = 1;
+
 	status = my_grib_set_long(gh, "gridDefinitionTemplateNumber", GRIB2_GTYPE_UNSTRUCTURED);
 	if ( status != 0 && warning )
 	  {
@@ -33198,19 +33058,25 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
 	  }
 	else
 	  {
-            char uuid[17];
+            unsigned char uuid[CDI_UUID_SIZE];
             int position = gridInqPosition(gridID);
             int number = gridInqNumber(gridID);
             if ( position < 0 ) position = 0;
             if ( number < 0 ) number = 0;
 	    GRIB_CHECK(my_grib_set_long(gh, "numberOfGridUsed", number), 0);
 	    GRIB_CHECK(my_grib_set_long(gh, "numberOfGridInReference", position), 0);
-            len = 16;
+            len = CDI_UUID_SIZE;
             gridInqUUID(gridID, uuid);
-	    if (grib_set_bytes(gh, "uuidOfHGrid", (unsigned char *) uuid, &len) != 0)
+	    if (grib_set_bytes(gh, "uuidOfHGrid", uuid, &len) != 0)
 	      Warning("Can't write UUID!");
 	  }
 
+        if ( comptype == COMPRESS_SZIP )
+          {
+            mesg = "grid_ccsds"; len = strlen(mesg);
+            GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
+          }
+
 	break;
       }
     default:
@@ -33484,8 +33350,7 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
       }
     case ZAXIS_REFERENCE:
       {
-        char uuid[16];
-        int number;
+        unsigned char uuid[CDI_UUID_SIZE];
 
         if ( !gcinit )
           {
@@ -33498,15 +33363,15 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
               ; // not available
             else
               {
-                number = zaxisInqNumber(zaxisID);
+                int number = zaxisInqNumber(zaxisID);
                 gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", GRIB2_LTYPE_REFERENCE);
                 gribapiDefLevelType(gh, gcinit, "typeOfSecondFixedSurface", GRIB2_LTYPE_REFERENCE);
                 GRIB_CHECK(my_grib_set_long(gh, "NV", 6), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "nlev", zaxisInqNlevRef(zaxisID)), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "numberOfVGridUsed", number), 0);
-                size_t len = 16;
+                size_t len = CDI_UUID_SIZE;
                 zaxisInqUUID(zaxisID, uuid);
-                if (grib_set_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len) != 0)
+                if (grib_set_bytes(gh, "uuidOfVGrid", uuid, &len) != 0)
                   Warning("Can't write UUID!");
                 GRIB_CHECK(my_grib_set_long(gh, "topLevel", (long) dlevel1), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "bottomLevel", (long) dlevel2), 0);
@@ -33518,14 +33383,14 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
               ; // not available
             else
               {
-                number = zaxisInqNumber(zaxisID);
+                int number = zaxisInqNumber(zaxisID);
                 gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", GRIB2_LTYPE_REFERENCE);
                 GRIB_CHECK(my_grib_set_long(gh, "NV", 6), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "nlev", zaxisInqNlevRef(zaxisID)), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "numberOfVGridUsed", number), 0);
-                size_t len = 16;
+                size_t len = CDI_UUID_SIZE;
                 zaxisInqUUID(zaxisID, uuid);
-                if (grib_set_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len) != 0)
+                if (grib_set_bytes(gh, "uuidOfVGrid", uuid, &len) != 0)
                   Warning("Can't write UUID!");
                 GRIB_CHECK(my_grib_set_double(gh, "level", level), 0);
               }
@@ -33553,39 +33418,15 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
 }
 #endif
 
-void *gribHandleNew(int editionNumber)
-{
-  void *gh = NULL;
-
-#if  defined  (HAVE_LIBGRIB_API)
-  if ( editionNumber == 1 )
-    gh = (void *) grib_handle_new_from_samples(NULL, "GRIB1");
-  else
-    gh = (void *) grib_handle_new_from_samples(NULL, "GRIB2");
-
-  if ( gh == NULL ) Error("grib_handle_new_from_samples failed!");
-#endif
-
-  return (gh);
-}
-
-
-void gribHandleDelete(void *gh)
-{
-#if  defined  (HAVE_LIBGRIB_API)
-  grib_handle_delete(gh);
-#endif
-}
-
 /* #define GRIBAPIENCODETEST 1 */
 
+#ifdef HAVE_LIBGRIB_API
 size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisID,
 		     int vdate, int vtime, int tsteptype, int numavg, 
 		     long datasize, const double *data, int nmiss, unsigned char **gribbuffer, size_t *gribbuffersize,
 		     int comptype, void *gribContainer)
 {
   size_t nbytes = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   size_t recsize = 0;
   void *dummy = NULL;
   int datatype;
@@ -33716,12 +33557,10 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
   gc->init = TRUE;
 
   nbytes = recsize;
-#else
-  Error("GRIB_API support not compiled in!");
-#endif
 
   return (nbytes);
 }
+#endif
 
 /*
  * Local Variables:
@@ -33968,9 +33807,14 @@ int grbDecode(int filetype, unsigned char *gribbuffer, int gribsize, double *dat
     }
   else
 #endif
+#ifdef HAVE_LIBGRIB_API
+    status = gribapiDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, missval, vlistID, varID);
+#else
     {
-      status = gribapiDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, missval, vlistID, varID);
+      (void)vlistID; (void)varID;
+      Error("GRIB_API support not compiled in!");
     }
+#endif
 
   return (status);
 }
@@ -34086,7 +33930,7 @@ int grbScanTimestep1(stream_t * streamptr)
 static
 int grbScanTimestep2(stream_t * streamptr)
 {
-  int status;
+  int status = 0;
   int filetype;
 
   filetype  = streamptr->filetype;
@@ -34096,11 +33940,13 @@ int grbScanTimestep2(stream_t * streamptr)
     {
       status = cgribexScanTimestep2(streamptr);
     }
+#endif
+#if defined(HAVE_LIBCGRIBEX) && defined (HAVE_LIBGRIB_API)
   else
 #endif
-    {
-      status = gribapiScanTimestep2(streamptr);
-    }
+#ifdef HAVE_LIBGRIB_API
+    status = gribapiScanTimestep2(streamptr);
+#endif
 
   return (status);
 }
@@ -34108,7 +33954,7 @@ int grbScanTimestep2(stream_t * streamptr)
 static
 int grbScanTimestep(stream_t * streamptr)
 {
-  int status;
+  int status = CDI_EUFTYPE;
   int filetype;
 
   filetype  = streamptr->filetype;
@@ -34120,9 +33966,11 @@ int grbScanTimestep(stream_t * streamptr)
     }
   else
 #endif
-    {
-      status = gribapiScanTimestep(streamptr);
-    }
+#ifdef HAVE_LIBGRIB_API
+    status = gribapiScanTimestep(streamptr);
+#else
+    Error("Sufficient GRIB support unavailable!");
+#endif
 
   return (status);
 }
@@ -34273,7 +34121,7 @@ size_t grbEncode(int filetype, int memtype, int varID, int levelID, int vlistID,
 		 size_t datasize, const double *data, int nmiss, unsigned char **gribbuffer,
 		 int comptype, void *gribContainer)
 {
-  size_t nbytes;
+  size_t nbytes = 0;
 
 #if  defined  (HAVE_LIBCGRIBEX)
   if ( filetype == FILETYPE_GRB )
@@ -34287,6 +34135,7 @@ size_t grbEncode(int filetype, int memtype, int varID, int levelID, int vlistID,
     }
   else
 #endif
+#ifdef HAVE_LIBGRIB_API
     {
       if ( memtype == MEMTYPE_FLOAT ) Error("gribapiEncode() not implemented for memtype float!");
 
@@ -34296,6 +34145,11 @@ size_t grbEncode(int filetype, int memtype, int varID, int levelID, int vlistID,
 			     (long)datasize, data, nmiss, gribbuffer, &gribbuffersize,
 			     comptype, gribContainer);
     }
+#else
+    Error("GRIB_API support not compiled in!");
+    (void)gribContainer;
+#endif
+
 
   return (nbytes);
 }
@@ -34754,7 +34608,7 @@ void srv_add_record(stream_t *streamptr, int param, int level, int xsize, int ys
   grid.ysize = ysize;
   grid.xvals = NULL;
   grid.yvals = NULL;
-  gridID = varDefGrid(vlistID, grid, 0);
+  gridID = varDefGrid(vlistID, &grid, 0);
   /*
   if ( level == 0 ) leveltype = ZAXIS_SURFACE;
   else              leveltype = ZAXIS_GENERIC;
@@ -35685,7 +35539,7 @@ void extAddRecord(stream_t *streamptr, int param, int level, int xysize,
   grid.ysize = 0;
   grid.xvals = NULL;
   grid.yvals = NULL;
-  gridID = varDefGrid(vlistID, grid, 0);
+  gridID = varDefGrid(vlistID, &grid, 0);
   /*
   if ( level == 0 ) leveltype = ZAXIS_SURFACE;
   else              leveltype = ZAXIS_GENERIC;
@@ -36590,6 +36444,32 @@ void iegDefTime(int *pdb, int date, int time, int taxisID)
 }
 
 static
+int calc_resfac(double xfirst, double xlast, double xinc, double yfirst, double ylast, double yinc)
+{
+  int i, j;
+  int iresfac = 1000;
+  int ifact;
+  int ifacarr[5] = {1000, 10000, 100000, 1000000, 10000000};
+  double vals[6] = {xfirst, xlast, xinc, yfirst, ylast, yinc};
+
+  for ( j = 0; j < 5; ++j )
+    {
+      ifact = ifacarr[j];
+      for ( i = 0; i < 6; ++i )
+        {
+          if ( fabs(vals[i]*ifact-(lround(vals[i]*ifact))) > FLT_EPSILON ) break;
+        }
+      if ( i == 6 )
+        {
+          iresfac = ifact;
+          break;
+        }
+    }
+
+  return (iresfac);
+}
+
+static
 void iegDefGrid(int *gdb, int gridID)
 {
   int gridtype;
@@ -36604,7 +36484,7 @@ void iegDefGrid(int *gdb, int gridID)
       ysize = gridInqYsize(gridID);
 
       if ( (ysize == 32  || ysize == 48 || ysize == 64 ||
-	    ysize == 96  || ysize == 160) && 
+	    ysize == 96  || ysize == 160) &&
 	   (xsize == 2*ysize || xsize == 1) )
 	{
 	  gridtype = GRID_GAUSSIAN;
@@ -36664,22 +36544,28 @@ void iegDefGrid(int *gdb, int gridID)
       else
 	IEG_G_GridType(gdb) = 0;
 
+      int iresfac = calc_resfac(xfirst, xlast, xinc, yfirst, ylast, yinc);
+      double resfac = (double) iresfac;
+      if ( iresfac == 1000 ) iresfac = 0;
+
+      IEG_G_ResFac(gdb)   = iresfac;
+
       IEG_G_NumLon(gdb)   = nlon;
       IEG_G_NumLat(gdb)   = nlat;
-      IEG_G_FirstLat(gdb) = lround(yfirst*1000);
-      IEG_G_LastLat(gdb)  = lround(ylast*1000);
-      IEG_G_FirstLon(gdb) = lround(xfirst*1000);
-      IEG_G_LastLon(gdb)  = lround(xlast*1000);
-      IEG_G_LonIncr(gdb)  = lround(xinc*1000);
-      if ( fabs(xinc*1000 - IEG_G_LonIncr(gdb)) > FLT_EPSILON )
+      IEG_G_FirstLat(gdb) = lround(yfirst*resfac);
+      IEG_G_LastLat(gdb)  = lround(ylast*resfac);
+      IEG_G_FirstLon(gdb) = lround(xfirst*resfac);
+      IEG_G_LastLon(gdb)  = lround(xlast*resfac);
+      IEG_G_LonIncr(gdb)  = lround(xinc*resfac);
+      if ( fabs(xinc*resfac - IEG_G_LonIncr(gdb)) > FLT_EPSILON )
 	IEG_G_LonIncr(gdb) = 0;
 
       if ( gridtype == GRID_GAUSSIAN )
 	IEG_G_LatIncr(gdb) = nlat/2;
       else
 	{
-	  IEG_G_LatIncr(gdb) = lround(yinc*1000);
-	  if ( fabs(yinc*1000 - IEG_G_LatIncr(gdb)) > FLT_EPSILON )
+	  IEG_G_LatIncr(gdb) = lround(yinc*resfac);
+	  if ( fabs(yinc*resfac - IEG_G_LatIncr(gdb)) > FLT_EPSILON )
 	    IEG_G_LatIncr(gdb) = 0;
 
 	  if ( IEG_G_LatIncr(gdb) < 0 ) IEG_G_LatIncr(gdb) = -IEG_G_LatIncr(gdb);
@@ -36698,8 +36584,8 @@ void iegDefGrid(int *gdb, int gridID)
 
       if ( gridIsRotated(gridID) )
 	{
-	  IEG_G_LatSP(gdb) = - lround(gridInqYpole(gridID) * 1000);
-	  IEG_G_LonSP(gdb) =   lround((gridInqXpole(gridID) + 180) * 1000);
+	  IEG_G_LatSP(gdb) = - lround(gridInqYpole(gridID) * resfac);
+	  IEG_G_LonSP(gdb) =   lround((gridInqXpole(gridID) + 180) * resfac);
 	  IEG_G_Size(gdb)  = 42;
 	}
       else
@@ -37009,21 +36895,26 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
     gridtype = GRID_GENERIC;
 
   memset(&grid, 0, sizeof(grid_t));
-  grid.type  = gridtype; 
+  grid.type  = gridtype;
   grid.size  = IEG_G_NumLon(gdb)*IEG_G_NumLat(gdb);
   grid.xsize = IEG_G_NumLon(gdb);
   grid.ysize = IEG_G_NumLat(gdb);
   grid.xinc  = 0;
   grid.yinc  = 0;
   grid.xdef  = 0;
+
+  int iresfac = IEG_G_ResFac(gdb);
+  if ( iresfac == 0 ) iresfac = 1000;
+  double resfac = 1./(double) iresfac;
+
   /* if ( IEG_G_FirstLon != 0 || IEG_G_LastLon != 0 ) */
   {
     if ( grid.xsize > 1 )
       {
 	if ( IEG_G_ResFlag(gdb) && IEG_G_LonIncr(gdb) > 0 )
-	  grid.xinc = IEG_G_LonIncr(gdb) * 0.001;
+	  grid.xinc = IEG_G_LonIncr(gdb) * resfac;
 	else
-	  grid.xinc = (IEG_G_LastLon(gdb) - IEG_G_FirstLon(gdb)) * 0.001 / (grid.xsize - 1);
+	  grid.xinc = (IEG_G_LastLon(gdb) - IEG_G_FirstLon(gdb)) * resfac / (grid.xsize - 1);
 
 	/* correct xinc if necessary */
 	if ( IEG_G_FirstLon(gdb) == 0 && IEG_G_LastLon(gdb) > 354000 )
@@ -37037,9 +36928,9 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
 	      }
 	  }
       }
-    grid.xfirst = IEG_G_FirstLon(gdb) * 0.001;
-    grid.xlast  = IEG_G_LastLon(gdb)  * 0.001;
-    grid.xdef   = 2;	    
+    grid.xfirst = IEG_G_FirstLon(gdb) * resfac;
+    grid.xlast  = IEG_G_LastLon(gdb)  * resfac;
+    grid.xdef   = 2;
   }
   grid.ydef  = 0;
   /* if ( IEG_G_FirstLat != 0 || IEG_G_LastLat != 0 ) */
@@ -37047,22 +36938,22 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
     if ( grid.ysize > 1 )
       {
 	if ( IEG_G_ResFlag(gdb) && IEG_G_LatIncr(gdb) > 0 )
-	  grid.yinc = IEG_G_LatIncr(gdb) * 0.001;
+	  grid.yinc = IEG_G_LatIncr(gdb) * resfac;
 	else
-	  grid.yinc = (IEG_G_LastLat(gdb) - IEG_G_FirstLat(gdb)) * 0.001 / (grid.ysize - 1);
+	  grid.yinc = (IEG_G_LastLat(gdb) - IEG_G_FirstLat(gdb)) * resfac / (grid.ysize - 1);
       }
-    grid.yfirst = IEG_G_FirstLat(gdb) * 0.001;
-    grid.ylast  = IEG_G_LastLat(gdb)  * 0.001;
-    grid.ydef   = 2;	    
+    grid.yfirst = IEG_G_FirstLat(gdb) * resfac;
+    grid.ylast  = IEG_G_LastLat(gdb)  * resfac;
+    grid.ydef   = 2;
   }
   /*
-  grid.xfirst= IEG_G_FirstLon(gdb) * 0.001;
-  grid.xlast = IEG_G_LastLon(gdb) * 0.001;
-  grid.xinc  = IEG_G_LonIncr(gdb) * 0.001;
-  grid.xdef  = 2;	    
-  grid.yfirst= IEG_G_FirstLat(gdb) * 0.001;
-  grid.ylast = IEG_G_LastLat(gdb) * 0.001;
-  grid.yinc  = IEG_G_LatIncr(gdb) * 0.001;
+  grid.xfirst= IEG_G_FirstLon(gdb) * resfac;
+  grid.xlast = IEG_G_LastLon(gdb) * resfac;
+  grid.xinc  = IEG_G_LonIncr(gdb) * resfac;
+  grid.xdef  = 2;
+  grid.yfirst= IEG_G_FirstLat(gdb) * resfac;
+  grid.ylast = IEG_G_LastLat(gdb) * resfac;
+  grid.yinc  = IEG_G_LatIncr(gdb) * resfac;
   grid.ydef  = 2;
   */
   grid.xvals = NULL;
@@ -37072,12 +36963,12 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
   if ( IEG_G_GridType(gdb) == 10 )
     {
       grid.isRotated = TRUE;
-      grid.ypole     = - IEG_G_LatSP(gdb) * 0.001;
-      grid.xpole     =   IEG_G_LonSP(gdb) * 0.001 - 180;
+      grid.ypole     = - IEG_G_LatSP(gdb) * resfac;
+      grid.xpole     =   IEG_G_LonSP(gdb) * resfac - 180;
       grid.angle     = 0;
     }
 
-  gridID = varDefGrid(vlistID, grid, 0);
+  gridID = varDefGrid(vlistID, &grid, 0);
 
   leveltype = iegGetZaxisType(IEG_P_LevelType(pdb));
 
@@ -37799,6 +37690,7 @@ void iegWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
   /* tsID     = streamptr->curTsID; */
   gridID   = vlistInqVarGrid(vlistID, varID);
   zaxisID  = vlistInqVarZaxis(vlistID, varID);
+  (void)levID;
   /* level    = zaxisInqLevel(zaxisID, levID); */
 
   if ( CDI_Debug )
@@ -37830,19 +37722,18 @@ void iegWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
 #if defined (HAVE_CONFIG_H)
 #endif
 
+#ifdef HAVE_LIBNETCDF
+
 //#define TEST_GROUPS 1
 
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <math.h>
 #include <float.h>
 
-#if  defined  (HAVE_LIBNETCDF)
-#  include <netcdf.h>
-#endif
-
-
+#include <netcdf.h>
 
 
 //#define PROJECTION_TEST
@@ -37851,11 +37742,10 @@ void iegWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
 #define UNDEFID  CDI_UNDEFID
 
 
-void    vlistInqVarDimorder(int vlistID, int varID, int (*outDimorder)[3]);
-
-void cdfDefGlobalAtts(stream_t *streamptr);
-void cdfDefLocalAtts(stream_t *streamptr);
-
+#if defined HAVE_LIBNETCDF
+static void cdfDefGlobalAtts(stream_t *streamptr);
+static void cdfDefLocalAtts(stream_t *streamptr);
+#endif
 
 #define  X_AXIS  1
 #define  Y_AXIS  2
@@ -37943,7 +37833,6 @@ typedef struct {
 }
 ncvar_t;
 
-#ifdef HAVE_LIBNETCDF
 static
 void strtolower(char *str)
 {
@@ -38079,9 +37968,7 @@ static
 int scanTimeUnit(const char *unitstr)
 {
   int timeunit = -1;
-  int len;
-
-  len = (int) strlen(unitstr);
+  size_t len = strlen(unitstr);
   timeunit = get_timeunit(len, unitstr);
   if ( timeunit == -1 )
     Message("Unsupported TIMEUNIT: %s!", unitstr);
@@ -38259,12 +38146,11 @@ void cdfGetAttText(int fileID, int ncvarid, char *attname, int attlen, char *att
           char *attbuf = NULL;
           cdf_get_att_string(fileID, ncvarid, attname, &attbuf);
 
-          int slen = (int) strlen(attbuf);
-          slen++;
-
-          if ( slen > attlen ) slen = attlen;
-          memcpy(atttext, attbuf, slen);
+          size_t ssize = strlen(attbuf) + 1;
 
+          if ( ssize > (size_t)attlen ) ssize = (size_t)attlen;
+          memcpy(atttext, attbuf, ssize);
+          atttext[ssize - 1] = 0;
           free(attbuf);
         }
       else
@@ -38415,24 +38301,16 @@ void defineAttributes(int vlistID, int varID, int fileID, int ncvarID)
         }
     }
 }
-#endif
 
 void cdfCopyRecord(stream_t *streamptr2, stream_t *streamptr1)
 {
-  int memtype = MEMTYPE_DOUBLE;
+  int memtype  = MEMTYPE_DOUBLE;
   int vlistID1 = streamptr1->vlistID;
-
-  int tsID1 = streamptr1->curTsID;
-
-  int recID1 = streamptr1->tsteps[tsID1].curRecID;
-
-  int ivarID = streamptr1->tsteps[tsID1].records[recID1].varID;
-
-  int gridID = vlistInqVarGrid(vlistID1, ivarID);
-
+  int tsID1    = streamptr1->curTsID;
+  int recID1   = streamptr1->tsteps[tsID1].curRecID;
+  int ivarID   = streamptr1->tsteps[tsID1].records[recID1].varID;
+  int gridID   = vlistInqVarGrid(vlistID1, ivarID);
   int datasize = gridInqSize(gridID);
-  /* bug fix for constant netCDF fields */
-  if ( datasize < 1048576 ) datasize = 1048576;
 
   double *data = xmalloc((size_t)datasize * sizeof (double));
 
@@ -38473,9 +38351,10 @@ int cdfInqRecord(stream_t *streamptr, int *varID, int *levelID)
 
 void cdfDefRecord(stream_t *streamptr)
 {
+  (void)streamptr;
 }
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfWriteGridTraj(stream_t *streamptr, int gridID)
 {
@@ -38515,9 +38394,8 @@ void cdfReadGridTraj(stream_t *streamptr, int gridID)
   gridDefXvals(gridID, &xlon);
   gridDefYvals(gridID, &xlat);
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefVarDeflate(int ncid, int ncvarid, int deflate_level)
 {
@@ -38543,9 +38421,9 @@ void cdfDefVarDeflate(int ncid, int ncvarid, int deflate_level)
     }
 #endif
 }
-#endif
 
-#if  defined(HAVE_LIBNETCDF) && defined(NC_SZIP_NN_OPTION_MASK)
+
+#if defined(NC_SZIP_NN_OPTION_MASK)
 static
 void cdfDefVarSzip(int ncid, int ncvarid)
 {
@@ -38572,7 +38450,6 @@ void cdfDefVarSzip(int ncid, int ncvarid)
 }
 #endif
 
-#if  defined  (HAVE_LIBNETCDF)
 static
 void cdfDefVarMissval(stream_t *streamptr, int varID, int dtype, int lcheck)
 {
@@ -38603,11 +38480,10 @@ void cdfDefVarMissval(stream_t *streamptr, int varID, int dtype, int lcheck)
       streamptr->vars[varID].defmiss = TRUE;
     }
 }
-#endif
+
 
 void cdf_write_record(stream_t *streamptr, int memtype, const void *data, int nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int varID;
   int levelID;
 
@@ -38617,7 +38493,6 @@ void cdf_write_record(stream_t *streamptr, int memtype, const void *data, int nm
   if ( CDI_Debug ) Message("streamID = %d  varID = %d", streamptr->self, varID);
 
   cdf_write_var_slice(streamptr, varID, levelID, memtype, data, nmiss);
-#endif
 }
 
 void cdfReadRecord(stream_t *streamptr, double *data, int *nmiss)
@@ -38635,7 +38510,6 @@ void cdfReadRecord(stream_t *streamptr, double *data, int *nmiss)
   cdfReadVarSliceDP(streamptr, varID, levelID, data, nmiss);
 }
 
-#if  defined  (HAVE_LIBNETCDF)
 static
 void cdfDefTimeValue(stream_t *streamptr, int tsID)
 {
@@ -38784,7 +38658,6 @@ void cdfDefForecastTimeUnits(char *unitstr, int timeunit)
 
   sprintf(unitstr, "%s", tunitNamePtr(timeunit));
 }
-#endif
 
 static
 void cdfDefCalendar(int fileID, int ncvarid, int calendar)
@@ -38803,15 +38676,12 @@ void cdfDefCalendar(int fileID, int ncvarid, int calendar)
 
   len = strlen(calstr);
 
-#if  defined  (HAVE_LIBNETCDF)
   if ( len ) cdf_put_att_text(fileID, ncvarid, "calendar", len, calstr);
-#endif
 }
 
 static
 void cdfDefTime(stream_t* streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int fileID;
   int time_varid;
   int time_dimid;
@@ -38896,13 +38766,11 @@ void cdfDefTime(stream_t* streamptr)
     }
 
   if ( streamptr->ncmode == 2 ) cdf_enddef(fileID);
-#endif
 }
 
 
 void cdfDefTimestep(stream_t *streamptr, int tsID)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int vlistID;
 
   vlistID = streamptr->vlistID;
@@ -38910,10 +38778,8 @@ void cdfDefTimestep(stream_t *streamptr, int tsID)
   if ( vlistHasTime(vlistID) ) cdfDefTime(streamptr);
 
   cdfDefTimeValue(streamptr, tsID);
-#endif
 }
 
-#if  defined  (HAVE_LIBNETCDF)
 static
 void cdfDefComplex(stream_t *streamptr, int gridID)
 {
@@ -38959,9 +38825,8 @@ void cdfDefComplex(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->xdimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefSP(stream_t *streamptr, int gridID)
 {
@@ -39019,9 +38884,8 @@ void cdfDefSP(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->ydimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefFC(stream_t *streamptr, int gridID)
 {
@@ -39076,9 +38940,8 @@ void cdfDefFC(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->ydimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefTrajLon(stream_t *streamptr, int gridID)
 {
@@ -39133,9 +38996,8 @@ void cdfDefTrajLon(stream_t *streamptr, int gridID)
 
   streamptr->xdimID[gridindex] = ncvarid; /* var ID for trajectory !!! */
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefTrajLat(stream_t *streamptr, int gridID)
 {
@@ -39190,9 +39052,8 @@ void cdfDefTrajLat(stream_t *streamptr, int gridID)
 
   streamptr->ydimID[gridindex] = ncvarid; /* var ID for trajectory !!! */
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 int checkGridName(int type, char *axisname, int fileID, int vlistID, int gridID, int ngrids, int mode)
 {
@@ -39254,9 +39115,8 @@ int checkGridName(int type, char *axisname, int fileID, int vlistID, int gridID,
 
   return (iz);
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims)
 {
@@ -39385,9 +39245,8 @@ void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims)
 
   streamptr->xdimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims)
 {
@@ -39516,9 +39375,8 @@ void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims)
 
   streamptr->ydimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfGridCompress(int fileID, int ncvarid, int gridsize, int filetype, int comptype)
 {
@@ -39530,9 +39388,8 @@ void cdfGridCompress(int fileID, int ncvarid, int gridsize, int filetype, int co
     }
 #endif
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefCurvilinear(stream_t *streamptr, int gridID)
 {
@@ -39721,9 +39578,8 @@ void cdfDefCurvilinear(stream_t *streamptr, int gridID)
   streamptr->ncyvarID[gridindex] = ncyvarid;
   streamptr->ncavarID[gridindex] = ncavarid;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefRgrid(stream_t *streamptr, int gridID)
 {
@@ -39787,9 +39643,8 @@ void cdfDefRgrid(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->xdimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefGdim(stream_t *streamptr, int gridID)
 {
@@ -39871,9 +39726,8 @@ void cdfDefGdim(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->xdimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefGridReference(stream_t *streamptr, int gridID)
 {
@@ -39898,10 +39752,10 @@ void cdfDefGridReference(stream_t *streamptr, int gridID)
 static
 void cdfDefGridUUID(stream_t *streamptr, int gridID)
 {
-  char uuidOfHGrid[17];
+  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
 
   gridInqUUID(gridID, uuidOfHGrid);
-  if ( uuidOfHGrid[0] != 0 )
+  if ( !cdiUUIDIsNull(uuidOfHGrid) )
     {
       char uuidOfHGridStr[37];
       uuid2str(uuidOfHGrid, uuidOfHGridStr);
@@ -39918,7 +39772,7 @@ void cdfDefGridUUID(stream_t *streamptr, int gridID)
 static
 void cdfDefZaxisUUID(stream_t *streamptr, int zaxisID)
 {
-  char uuidOfVGrid[17];
+  unsigned char uuidOfVGrid[CDI_UUID_SIZE];
   zaxisInqUUID(zaxisID, uuidOfVGrid);
 
   if ( uuidOfVGrid[0] != 0 )
@@ -40103,9 +39957,8 @@ void cdfDefUnstructured(stream_t *streamptr, int gridID)
   streamptr->ncyvarID[gridindex] = ncyvarid;
   streamptr->ncavarID[gridindex] = ncavarid;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefVCT(stream_t *streamptr, int zaxisID)
 {
@@ -40190,9 +40043,8 @@ void cdfDefVCT(stream_t *streamptr, int zaxisID)
         }
     }
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefZaxis(stream_t *streamptr, int zaxisID)
 {
@@ -40460,9 +40312,8 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
   if ( dimID != UNDEFID )
     streamptr->zaxisID[zaxisindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefPole(stream_t *streamptr, int gridID)
 {
@@ -40493,9 +40344,8 @@ void cdfDefPole(stream_t *streamptr, int gridID)
 
   cdf_enddef(fileID);
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefMapping(stream_t *streamptr, int gridID)
 {
@@ -40583,9 +40433,8 @@ void cdfDefMapping(stream_t *streamptr, int gridID)
       cdf_enddef(fileID);
     }
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefGrid(stream_t *streamptr, int gridID)
 {
@@ -40688,9 +40537,8 @@ void cdfDefGrid(stream_t *streamptr, int gridID)
       Error("Unsupported grid type: %s", gridNamePtr(gridtype));
     }
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 int cdfDefVar(stream_t *streamptr, int varID)
 {
@@ -41196,9 +41044,7 @@ void scale_add(size_t size, double *data, double addoffset, double scalefactor)
         }
     }
 }
-#endif
 
-#if defined (HAVE_LIBNETCDF)
 static
 void cdfGetSlapDescription(stream_t *streamptr, int varID, size_t (*start)[4], size_t (*count)[4])
 {
@@ -41246,17 +41092,64 @@ void cdfGetSlapDescription(stream_t *streamptr, int varID, size_t (*start)[4], s
 }
 
 //Scans the data array for missVals, optionally applying first a scale factor and then an offset.
-//Returns the number of missVals encountered.
+//Returns the number of missing + out-of-range values encountered.
 static
-size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool haveMissval, double missVal, double scaleFactor, double offset)
+size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool haveMissVal, double missVal, double scaleFactor, double offset, double validMin, double validMax)
  {
   const bool haveOffset   = IS_NOT_EQUAL(offset, 0);
   const bool haveScaleFactor = IS_NOT_EQUAL(scaleFactor, 1);
   size_t missValCount = 0;
+  if (validMin == VALIDMISS)
+    validMin = DBL_MIN;
+  if (validMax == VALIDMISS)
+    validMax = DBL_MAX;
+
+  bool haveRangeCheck = (validMax != DBL_MAX) | (validMin != DBL_MIN);
+  assert(!haveRangeCheck || haveMissVal);
 
-  switch ((int)haveMissval | ((int)haveScaleFactor << 1) | ((int)haveOffset << 2))
+  switch ((int)haveMissVal | ((int)haveScaleFactor << 1)
+          | ((int)haveOffset << 2) | ((int)haveRangeCheck << 3))
     {
-    case 7: /* haveMissval & haveScaleFactor & haveOffset */
+    case 15: /* haveRangeCheck & haveMissVal & haveScaleFactor & haveOffset */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? missVal
+            : isMissVal ? data[i] : data[i] * scaleFactor + offset;
+        }
+      break;
+    case 13: /* haveRangeCheck & haveMissVal & haveOffset */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? missVal
+            : isMissVal ? data[i] : data[i] + offset;
+        }
+      break;
+    case 11: /* haveRangeCheck & haveMissVal & haveScaleFactor */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? missVal
+            : isMissVal ? data[i] : data[i] * scaleFactor;
+        }
+      break;
+    case 9: /* haveRangeCheck & haveMissVal */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? missVal : data[i];
+        }
+      break;
+    case 7: /* haveMissVal & haveScaleFactor & haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
@@ -41267,7 +41160,7 @@ size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool have
       for ( size_t i = 0; i < valueCount; i++ )
         data[i] = data[i] * scaleFactor + offset;
       break;
-    case 5: /* haveMissval & haveOffset */
+    case 5: /* haveMissVal & haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
@@ -41278,7 +41171,7 @@ size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool have
       for ( size_t i = 0; i < valueCount; i++ )
         data[i] += offset;
       break;
-    case 3: /* haveMissval & haveScaleFactor */
+    case 3: /* haveMissVal & haveScaleFactor */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
@@ -41289,9 +41182,9 @@ size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool have
       for ( size_t i = 0; i < valueCount; i++ )
         data[i] *= scaleFactor;
       break;
-    case 1: /* haveMissval */
+    case 1: /* haveMissVal */
       for ( size_t i = 0; i < valueCount; i++ )
-        missValCount += DBL_IS_EQUAL(data[i], missVal);
+        missValCount += (unsigned)DBL_IS_EQUAL(data[i], missVal);
       break;
     }
 
@@ -41299,58 +41192,104 @@ size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool have
 }
 
 static
-size_t cdfDoInputDataTransformationSP(size_t valueCount, float *data, bool haveMissval, double missVal, double scaleFactor, double offset)
+size_t cdfDoInputDataTransformationSP(size_t valueCount, float *data, bool haveMissVal, double missVal, double scaleFactor, double offset, double validMin, double validMax)
  {
   const bool haveOffset   = IS_NOT_EQUAL(offset, 0);
   const bool haveScaleFactor = IS_NOT_EQUAL(scaleFactor, 1);
   size_t missValCount = 0;
 
-  switch ((int)haveMissval | ((int)haveScaleFactor << 1) | ((int)haveOffset << 2))
+  if (validMin == VALIDMISS)
+    validMin = DBL_MIN;
+  if (validMax == VALIDMISS)
+    validMax = DBL_MAX;
+
+  bool haveRangeCheck = (validMax != DBL_MAX) | (validMin != DBL_MIN);
+  assert(!haveRangeCheck || haveMissVal);
+
+  switch ((int)haveMissVal | ((int)haveScaleFactor << 1)
+          | ((int)haveOffset << 2) | ((int)haveRangeCheck << 3))
     {
-    case 7: /* haveMissval & haveScaleFactor & haveOffset */
+    case 15: /* haveRangeCheck & haveMissVal & haveScaleFactor & haveOffset */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? (float)missVal
+            : isMissVal ? data[i] : (float)(data[i] * scaleFactor + offset);
+        }
+      break;
+    case 13: /* haveRangeCheck & haveMissVal & haveOffset */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? (float)missVal
+            : isMissVal ? data[i] : (float)(data[i] + offset);
+        }
+      break;
+    case 11: /* haveRangeCheck & haveMissVal & haveScaleFactor */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? (float)missVal
+            : isMissVal ? data[i] : (float)(data[i] * scaleFactor);
+        }
+      break;
+    case 9: /* haveRangeCheck & haveMissVal */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? (float)missVal : data[i];
+        }
+      break;
+    case 7: /* haveMissVal & haveScaleFactor & haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
         else
-          data[i] = data[i] * scaleFactor + offset;
+          data[i] = (float)(data[i] * scaleFactor + offset);
       break;
     case 6: /* haveOffset & haveScaleFactor */
       for ( size_t i = 0; i < valueCount; i++ )
-        data[i] = data[i] * scaleFactor + offset;
+        data[i] = (float)(data[i] * scaleFactor + offset);
       break;
-    case 5: /* haveMissval & haveOffset */
+    case 5: /* haveMissVal & haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
         else
-          data[i] += offset;
+          data[i] = (float)(data[i] + offset);
       break;
     case 4: /* haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
-        data[i] += offset;
+        data[i] = (float)(data[i] + offset);
       break;
-    case 3: /* haveMissval & haveScaleFactor */
+    case 3: /* haveMissVal & haveScaleFactor */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
         else
-          data[i] *= scaleFactor;
+          data[i] = (float)(data[i] * scaleFactor);
       break;
     case 2: /* haveScaleFactor */
       for ( size_t i = 0; i < valueCount; i++ )
-        data[i] *= scaleFactor;
+        data[i] = (float)(data[i] * scaleFactor);
       break;
-    case 1: /* haveMissval */
+    case 1: /* haveMissVal */
       for ( size_t i = 0; i < valueCount; i++ )
-        missValCount += DBL_IS_EQUAL(data[i], missVal);
+        missValCount += (unsigned)DBL_IS_EQUAL(data[i], missVal);
       break;
     }
 
   return missValCount;
 }
-#endif
 
-#if defined(HAVE_LIBNETCDF)
 static void
 cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtype, long nvals, size_t xsize, size_t ysize, int swapxy, size_t *start, size_t *count, int memtype, const void *data, int nmiss)
 {
@@ -41392,7 +41331,7 @@ cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtype, l
                         {
                           if ( laddoffset )   temp -= addoffset;
                           if ( lscalefactor ) temp /= scalefactor;
-                          mdata_sp[i] = temp;
+                          mdata_sp[i] = (float)temp;
                         }
                     }
                 }
@@ -41403,7 +41342,7 @@ cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtype, l
                       double temp = mdata_sp[i];
                       if ( laddoffset )   temp -= addoffset;
                       if ( lscalefactor ) temp /= scalefactor;
-                      mdata_sp[i] = temp;
+                      mdata_sp[i] = (float)temp;
                     }
                 }
             }
@@ -41534,9 +41473,8 @@ cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtype, l
   if ( mdata_sp ) free(mdata_sp);
   if ( sdata_sp ) free(sdata_sp);
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 void cdf_write_var(stream_t *streamptr, int varID, int memtype, const void *data, int nmiss)
 {
   int fileID;
@@ -41635,9 +41573,8 @@ void cdf_write_var(stream_t *streamptr, int varID, int memtype, const void *data
   cdf_write_var_data(fileID, vlistID, varID, ncvarid, dtype, nvals, xsize, ysize, swapxy, start, count, memtype, data, nmiss);
 
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
                          const int rect[][2], const void *data, int nmiss)
 {
@@ -41711,7 +41648,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
       size_t size;
       cdf_inq_dimlen(fileID, yid, &size);
       xassert(rect[1][0] >= 0 && rect[1][0] <= rect[1][1]
-              && rect[1][1] <= (int)size);
+              && (size_t)rect[1][1] <= size);
       start[ndims] = (size_t)rect[1][0];
       count[ndims] = (size_t)rect[1][1] - (size_t)rect[1][0] + 1;
       ndims++;
@@ -41721,7 +41658,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
       size_t size;
       cdf_inq_dimlen(fileID, xid, &size);
       xassert(rect[0][0] >= 0 && rect[0][0] <= rect[0][1]
-              && rect[0][1] <= (int)size);
+              && (size_t)rect[0][1] <= size);
       start[ndims] = (size_t)rect[0][0];
       count[ndims] = (size_t)rect[0][1] - (size_t)rect[0][0] + 1;
       ndims++;
@@ -41746,109 +41683,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
   cdf_write_var_data(fileID, vlistID, varID, ncvarid, dtype, nvals,
                      xsize, ysize, swapxy, start, count, memtype, data, nmiss);
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
-static
-int set_validrangeDP(long gridsize, double *data, double missval, double validmin, double validmax)
-{
-  long i;
-  int nmiss = 0;
-  /*
-  for ( i = 0; i < gridsize; i++, data++ )
-    {
-      if ( IS_NOT_EQUAL(validmin, VALIDMISS) && (*data) < validmin ) *data = missval;
-      if ( IS_NOT_EQUAL(validmax, VALIDMISS) && (*data) > validmax ) *data = missval;
-      if ( DBL_IS_EQUAL((*data), missval) ) nmiss++;
-    }
-  */
-  // 21/01/2014 Florian Prill: SX-9 vectorization
-
-  if ( IS_NOT_EQUAL(validmin, VALIDMISS) && !IS_NOT_EQUAL(validmax, VALIDMISS) )
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if ( (*data) < validmin )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else if ( IS_NOT_EQUAL(validmax, VALIDMISS) && !IS_NOT_EQUAL(validmin, VALIDMISS))
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if ( (*data) > validmax )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else if ( IS_NOT_EQUAL(validmin, VALIDMISS) && IS_NOT_EQUAL(validmax, VALIDMISS))
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if      ( (*data) < validmin )  { (*data) = missval; nmiss++; }
-          else if ( (*data) > validmax )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        if ( DBL_IS_EQUAL((*data), missval) ) nmiss++;
-    }
-
-  return (nmiss);
-}
-
-static
-int set_validrangeSP(long gridsize, float *data, double missval, double validmin, double validmax)
-{
-  long i;
-  int nmiss = 0;
-  /*
-  for ( i = 0; i < gridsize; i++, data++ )
-    {
-      if ( IS_NOT_EQUAL(validmin, VALIDMISS) && (*data) < validmin ) *data = missval;
-      if ( IS_NOT_EQUAL(validmax, VALIDMISS) && (*data) > validmax ) *data = missval;
-      if ( DBL_IS_EQUAL((*data), missval) ) nmiss++;
-    }
-  */
-  // 21/01/2014 Florian Prill: SX-9 vectorization
-
-  if ( IS_NOT_EQUAL(validmin, VALIDMISS) && !IS_NOT_EQUAL(validmax, VALIDMISS) )
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if ( (*data) < validmin )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else if ( IS_NOT_EQUAL(validmax, VALIDMISS) && !IS_NOT_EQUAL(validmin, VALIDMISS))
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if ( (*data) > validmax )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else if ( IS_NOT_EQUAL(validmin, VALIDMISS) && IS_NOT_EQUAL(validmax, VALIDMISS))
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if      ( (*data) < validmin )  { (*data) = missval; nmiss++; }
-          else if ( (*data) > validmax )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        if ( DBL_IS_EQUAL((*data), missval) ) nmiss++;
-    }
-
-  return (nmiss);
-}
-#endif
-
-#if  defined  (HAVE_LIBNETCDF)
 static
 size_t min_size(size_t a, size_t b)
 {
@@ -41858,14 +41693,19 @@ size_t min_size(size_t a, size_t b)
 static
 void transpose2dArrayDP(size_t inWidth, size_t inHeight, double* data)
 {
-  const size_t cacheBlockSize = 32;    // Purely an optimization parameter. Current value of 32 means we are handling 8kB blocks,
+  const size_t cacheBlockSize = 256;    // Purely an optimization parameter. Current value of 32 means we are handling 8kB blocks,
                                        // which should be a decent compromise on many architectures.
   double (*temp)[inWidth] = malloc(inHeight*sizeof(*temp));
   double (*out)[inHeight] = (double (*)[inHeight])data;
   memcpy(temp, data, inHeight*sizeof(*temp));
-  for ( size_t yBlock = 0; yBlock < inHeight; yBlock++ )
+  /*
+  for ( size_t y = 0; y < inHeight; ++y )
+    for ( size_t x = 0; x < inWidth; ++x )
+      out[x][y] = temp[y][x];
+  */
+  for ( size_t yBlock = 0; yBlock < inHeight; yBlock += cacheBlockSize )
     {
-      for ( size_t xBlock = 0; xBlock < inWidth; xBlock++ )
+      for ( size_t xBlock = 0; xBlock < inWidth; xBlock += cacheBlockSize )
         {
           for ( size_t y = yBlock, yEnd = min_size(yBlock + cacheBlockSize, inHeight); y < yEnd; y++ )
             {
@@ -41876,20 +41716,26 @@ void transpose2dArrayDP(size_t inWidth, size_t inHeight, double* data)
             }
         }
     }
+
   free(temp);
 }
 
 static
 void transpose2dArraySP(size_t inWidth, size_t inHeight, float* data)
 {
-  const size_t cacheBlockSize = 32;    // Purely an optimization parameter. Current value of 32 means we are handling 8kB blocks,
+  const size_t cacheBlockSize = 256;    // Purely an optimization parameter. Current value of 32 means we are handling 8kB blocks,
                                        // which should be a decent compromise on many architectures.
   float (*temp)[inWidth] = malloc(inHeight*sizeof(*temp));
   float (*out)[inHeight] = (float (*)[inHeight])data;
   memcpy(temp, data, inHeight*sizeof(*temp));
-  for ( size_t yBlock = 0; yBlock < inHeight; yBlock++ )
+  /*
+  for ( size_t y = 0; y < inHeight; ++y )
+    for ( size_t x = 0; x < inWidth; ++x )
+      out[x][y] = temp[y][x];
+  */
+  for ( size_t yBlock = 0; yBlock < inHeight; yBlock += cacheBlockSize )
     {
-      for ( size_t xBlock = 0; xBlock < inWidth; xBlock++ )
+      for ( size_t xBlock = 0; xBlock < inWidth; xBlock += cacheBlockSize )
         {
           for ( size_t y = yBlock, yEnd = min_size(yBlock + cacheBlockSize, inHeight); y < yEnd; y++ )
             {
@@ -41900,6 +41746,7 @@ void transpose2dArraySP(size_t inWidth, size_t inHeight, float* data)
             }
         }
     }
+
   free(temp);
 }
 
@@ -42034,11 +41881,9 @@ void cdfGetSliceSlapDescription(stream_t *streamptr, int varId, int levelId, boo
   if ( nvdims != ndims )
     Error("Internal error, variable %s has an unsupported array structure!", vlistInqVarNamePtr(vlistId, varId));
 }
-#endif
 
 void cdfReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
   if ( CDI_Debug ) Message("streamID = %d  varID = %d", streamptr->self, varID);
 
   int vlistID = streamptr->vlistID;
@@ -42055,28 +41900,21 @@ void cdfReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss)
 
   cdf_get_vara_double(fileID, ncvarid, start, count, data);
 
-  size_t size = (size_t)gridInqSize(gridID)*zaxisInqSize(zaxisID);
+  size_t size = (size_t)gridInqSize(gridID)*(size_t)zaxisInqSize(zaxisID);
   double missval = vlistInqVarMissval(vlistID, varID);
-  const bool haveMissval = vlistInqVarMissvalUsed(vlistID, varID);
-  if ( haveMissval )
-    {
-      double validrange[2];
-      if ( vlistInqVarValidrange(vlistID, varID, validrange) )
-        *nmiss = set_validrangeDP(size, data, missval, validrange[0], validrange[1]);
-      else
-        *nmiss = cdfDoInputDataTransformationDP(size, data, haveMissval, missval, 1, 0);
-    }
-
+  const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
+  double validRange[2];
+  if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
+    validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
   double addoffset   = vlistInqVarAddoffset(vlistID, varID);
   double scalefactor = vlistInqVarScalefactor(vlistID, varID);
-  (void) cdfDoInputDataTransformationDP(size, data, haveMissval, missval, scalefactor, addoffset);
-#endif
+  size_t nmiss_ = cdfDoInputDataTransformationDP(size, data, haveMissVal, missval, scalefactor, addoffset, validRange[0], validRange[1]);
+  assert(nmiss_ <= INT_MAX);
+  *nmiss = (int)nmiss_;
 }
 
-
 void cdfReadVarSP(stream_t *streamptr, int varID, float *data, int *nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
   if ( CDI_Debug ) Message("streamID = %d  varID = %d", streamptr->self, varID);
 
   int vlistID = streamptr->vlistID;
@@ -42095,26 +41933,19 @@ void cdfReadVarSP(stream_t *streamptr, int varID, float *data, int *nmiss)
 
   size_t size = (size_t)gridInqSize(gridID)*zaxisInqSize(zaxisID);
   double missval = vlistInqVarMissval(vlistID, varID);
-  const bool haveMissval = vlistInqVarMissvalUsed(vlistID, varID);
-  if ( haveMissval )
-    {
-      double validrange[2];
-      if ( vlistInqVarValidrange(vlistID, varID, validrange) )
-        *nmiss = set_validrangeSP(size, data, missval, validrange[0], validrange[1]);
-      else
-        *nmiss = cdfDoInputDataTransformationSP(size, data, haveMissval, missval, 1, 0);
-    }
-
-  double addoffset    = vlistInqVarAddoffset(vlistID, varID);
-  double scalefactor  = vlistInqVarScalefactor(vlistID, varID);
-  (void) cdfDoInputDataTransformationSP(size, data, haveMissval, missval, scalefactor, addoffset);
-#endif
+  const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
+  double validRange[2];
+  if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
+    validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
+  double addoffset   = vlistInqVarAddoffset(vlistID, varID);
+  double scalefactor = vlistInqVarScalefactor(vlistID, varID);
+  size_t nmiss_ = cdfDoInputDataTransformationSP(size, data, haveMissVal, missval, scalefactor, addoffset, validRange[0], validRange[1]);
+  assert(nmiss_ <= INT_MAX);
+  *nmiss = (int)nmiss_;
 }
 
 void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data, int *nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int i;
   size_t start[4];
   size_t count[4];
 
@@ -42129,15 +41960,15 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data
 
   int ncvarid = streamptr->vars[varID].ncvarid;
   int gridId = vlistInqVarGrid(vlistID, varID);
-  int gridsize = gridInqSize(gridId);
-  int xsize = gridInqXsize(gridId);
-  int ysize = gridInqYsize(gridId);
+  size_t gridsize = (size_t)gridInqSize(gridId);
+  size_t xsize = (size_t)gridInqXsize(gridId);
+  size_t ysize = (size_t)gridInqYsize(gridId);
 
   if ( vlistInqVarDatatype(vlistID, varID) == DATATYPE_FLT32 )
     {
-      float *data_fp = malloc(gridsize*sizeof(*data_fp));
+      float *data_fp = (float *)xmalloc(gridsize*sizeof(*data_fp));
       cdf_get_vara_float(fileID, ncvarid, start, count, data_fp);
-      for ( i = 0; i < gridsize; i++ )
+      for ( size_t i = 0; i < gridsize; i++ )
         data[i] = (double) data_fp[i];
       free(data_fp);
     }
@@ -42147,7 +41978,7 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data
       cdf_inq_vartype(fileID, ncvarid, &xtype);
       if ( xtype == NC_BYTE )
         {
-          for ( i = 0; i < gridsize; i++ )
+          for ( size_t i = 0; i < gridsize; i++ )
             if ( data[i] < 0 ) data[i] += 256;
         }
     }
@@ -42156,31 +41987,23 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data
       cdf_get_vara_double(fileID, ncvarid, start, count, data);
     }
 
-  if ( swapxy ) transpose2dArrayDP(xsize, ysize, data);
+  if ( swapxy ) transpose2dArrayDP(ysize, xsize, data);
 
-  *nmiss = 0;
   double missval = vlistInqVarMissval(vlistID, varID);
-  const bool haveMissval = vlistInqVarMissvalUsed(vlistID, varID);
-  if ( haveMissval )
-    {
-      double validrange[2];
-      if ( vlistInqVarValidrange(vlistID, varID, validrange) )
-        *nmiss = set_validrangeDP(gridsize, data, missval, validrange[0], validrange[1]);
-      else
-        *nmiss = cdfDoInputDataTransformationDP(gridsize, data, haveMissval, missval, 1, 0);
-    }
-
-  double addoffset = vlistInqVarAddoffset(vlistID, varID);
+  const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
+  double validRange[2];
+  if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
+    validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
+  double addoffset   = vlistInqVarAddoffset(vlistID, varID);
   double scalefactor = vlistInqVarScalefactor(vlistID, varID);
-  (void) cdfDoInputDataTransformationDP(gridsize, data, haveMissval, missval, scalefactor, addoffset);
-#endif
+  size_t nmiss_ = cdfDoInputDataTransformationDP(gridsize, data, haveMissVal, missval, scalefactor, addoffset, validRange[0], validRange[1]);
+  assert(nmiss_ <= INT_MAX);
+  *nmiss = (int)nmiss_;
 }
 
 
 void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data, int *nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int i;
   size_t start[4];
   size_t count[4];
 
@@ -42195,15 +42018,15 @@ void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data,
 
   int ncvarid = streamptr->vars[varID].ncvarid;
   int gridId = vlistInqVarGrid(vlistID, varID);
-  int gridsize = gridInqSize(gridId);
-  int xsize = gridInqXsize(gridId);
-  int ysize = gridInqYsize(gridId);
+  size_t gridsize = (size_t)gridInqSize(gridId);
+  size_t xsize = (size_t)gridInqXsize(gridId);
+  size_t ysize = (size_t)gridInqYsize(gridId);
 
   if ( vlistInqVarDatatype(vlistID, varID) == DATATYPE_FLT64 )
     {
-      double *data_dp = malloc(gridsize*sizeof(*data_dp));
+      double *data_dp = (double *)xmalloc(gridsize*sizeof(*data_dp));
       cdf_get_vara_double(fileID, ncvarid, start, count, data_dp);
-      for ( i = 0; i < gridsize; i++ )
+      for ( size_t i = 0; i < gridsize; i++ )
         data[i] = (float) data_dp[i];
       free(data_dp);
     }
@@ -42213,7 +42036,7 @@ void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data,
       cdf_inq_vartype(fileID, ncvarid, &xtype);
       if ( xtype == NC_BYTE )
         {
-          for ( i = 0; i < gridsize; i++ )
+          for ( size_t i = 0; i < gridsize; i++ )
             if ( data[i] < 0 ) data[i] += 256;
         }
     }
@@ -42222,30 +42045,23 @@ void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data,
       cdf_get_vara_float(fileID, ncvarid, start, count, data);
     }
 
-  if ( swapxy ) transpose2dArraySP(xsize, ysize, data);
+  if ( swapxy ) transpose2dArraySP(ysize, xsize, data);
 
-  *nmiss = 0;
   double missval = vlistInqVarMissval(vlistID, varID);
-  bool haveMissval = vlistInqVarMissvalUsed(vlistID, varID);
-  if ( haveMissval )
-    {
-      double validrange[2];
-      if ( vlistInqVarValidrange(vlistID, varID, validrange) )
-        *nmiss = set_validrangeSP(gridsize, data, missval, validrange[0], validrange[1]);
-      else
-        *nmiss = cdfDoInputDataTransformationSP(gridsize, data, haveMissval, missval, 1, 0);
-    }
-
-  double addoffset = vlistInqVarAddoffset(vlistID, varID);
+  bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
+  double validRange[2];
+  if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
+    validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
+  double addoffset   = vlistInqVarAddoffset(vlistID, varID);
   double scalefactor = vlistInqVarScalefactor(vlistID, varID);
-  (void ) cdfDoInputDataTransformationSP(gridsize, data, haveMissval, missval, scalefactor, addoffset);
-#endif
+  size_t nmiss_ = cdfDoInputDataTransformationSP(gridsize, data, haveMissVal, missval, scalefactor, addoffset, validRange[0], validRange[1]);
+  assert(nmiss_ <= INT_MAX);
+  *nmiss = (int)nmiss_;
 }
 
 
 void cdf_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype, const void *data, int nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int fileID;
   int gridID;
   int zaxisID;
@@ -42346,10 +42162,9 @@ void cdf_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtyp
 
   cdf_write_var_data(fileID, vlistID, varID, ncvarid, dtype, nvals, xsize, ysize, swapxy, start, count, memtype, data, nmiss);
 
-#endif
 }
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfCreateRecords(stream_t *streamptr, int tsID)
 {
@@ -42471,9 +42286,8 @@ void cdfCreateRecords(stream_t *streamptr, int tsID)
              (size_t)nvrecs * sizeof (int));
     }
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 int cdfTimeDimID(int fileID, int ndims, int nvars)
 {
@@ -42618,25 +42432,26 @@ static
 int isLonAxis(const char *units, const char *stdname)
 {
   int status = FALSE;
-  char degree_units[16];
+  char lc_units[16];
 
-  memcpy(degree_units, units, 16);
-  degree_units[15] = 0;
-  strtolower(degree_units);
+  memcpy(lc_units, units, 15);
+  lc_units[15] = 0;
+  strtolower(lc_units);
 
-  if ( memcmp(degree_units, "degree", 6) == 0 )
+  if ( ((memcmp(lc_units, "degree", 6) == 0 || memcmp(lc_units, "radian", 6) == 0) &&
+        (memcmp(stdname, "grid_longitude", 14) == 0 || memcmp(stdname, "longitude", 9) == 0)) )
     {
-      int ioff = 6;
-      if ( degree_units[ioff] == 's' ) ioff++;
-      if ( degree_units[ioff] == '_' ) ioff++;
-      if ( degree_units[ioff] == 'e' ) status = TRUE;
+      status = TRUE;
     }
 
   if ( status == FALSE &&
-       ((memcmp(units, "degree", 6) == 0 ||memcmp(units, "radian", 6) == 0) &&
-        (memcmp(stdname, "grid_longitude", 14) == 0 || memcmp(stdname, "longitude", 9) == 0)) )
+       memcmp(stdname, "grid_latitude", 13) && memcmp(stdname, "latitude", 8) &&
+       memcmp(lc_units, "degree", 6) == 0 )
     {
-      status = TRUE;
+      int ioff = 6;
+      if ( lc_units[ioff] == 's' ) ioff++;
+      if ( lc_units[ioff] == '_' ) ioff++;
+      if ( lc_units[ioff] == 'e' ) status = TRUE;
     }
 
   return (status);
@@ -42646,25 +42461,26 @@ static
 int isLatAxis(const char *units, const char *stdname)
 {
   int status = FALSE;
-  char degree_units[16];
+  char lc_units[16];
 
-  memcpy(degree_units, units, 16);
-  degree_units[15] = 0;
-  strtolower(degree_units);
+  memcpy(lc_units, units, 15);
+  lc_units[15] = 0;
+  strtolower(lc_units);
 
-  if ( memcmp(degree_units, "degree", 6) == 0 )
+  if ( ((memcmp(lc_units, "degree", 6) == 0 || memcmp(lc_units, "radian", 6) == 0) &&
+        (memcmp(stdname, "grid_latitude", 13) == 0 || memcmp(stdname, "latitude", 8) == 0)) )
     {
-      int ioff = 6;
-      if ( degree_units[ioff] == 's' ) ioff++;
-      if ( degree_units[ioff] == '_' ) ioff++;
-      if ( degree_units[ioff] == 'n' ) status = TRUE;
+      status = TRUE;
     }
 
   if ( status == FALSE &&
-       ((memcmp(units, "degree", 6) == 0 || memcmp(units, "radian", 6) == 0) &&
-        (memcmp(stdname, "grid_latitude", 13) == 0 || memcmp(stdname, "latitude", 8) == 0)) )
+       memcmp(stdname, "grid_longitude", 14) && memcmp(stdname, "longitude", 9) &&
+       memcmp(lc_units, "degree", 6) == 0 )
     {
-      status = TRUE;
+      int ioff = 6;
+      if ( lc_units[ioff] == 's' ) ioff++;
+      if ( lc_units[ioff] == '_' ) ioff++;
+      if ( lc_units[ioff] == 'n' ) status = TRUE;
     }
 
   return (status);
@@ -42860,7 +42676,6 @@ void printNCvars(ncvar_t *ncvars, int nvars, const char *oname)
       fprintf(stderr, "%3d %3d  %-6s %s\n", ncvarid, ndim-3, axis, ncvars[ncvarid].name);
     }
 }
-#endif
 
 typedef struct
 {
@@ -42870,7 +42685,6 @@ typedef struct
 varinfo_t;
 
 
-#ifdef HAVE_LIBNETCDF
 static
 int cmpvarname(const void *s1, const void *s2)
 {
@@ -43834,9 +43648,37 @@ void copy_numeric_projatts(int gridID, int ncvarID, int ncfileID)
 }
 #endif
 
+static
+void grid_set_chunktype(grid_t *grid, ncvar_t *ncvar)
+{
+  if ( ncvar->chunked )
+    {
+      int ndims = ncvar->ndims;
+
+      if ( grid->type == GRID_UNSTRUCTURED )
+        {
+          if ( ncvar->chunks[ndims-1] == grid->size )
+            ncvar->chunktype = CHUNK_GRID;
+          else
+            ncvar->chunktype = CHUNK_AUTO;
+        }
+      else
+        {
+          if ( grid->xsize > 1 && grid->ysize > 1 && ndims > 1 &&
+               grid->xsize == ncvar->chunks[ndims-1] &&
+               grid->ysize == ncvar->chunks[ndims-2] )
+            ncvar->chunktype = CHUNK_GRID;
+          else if ( grid->xsize > 1 && grid->xsize == ncvar->chunks[ndims-1] )
+            ncvar->chunktype = CHUNK_LINES;
+          else
+            ncvar->chunktype = CHUNK_AUTO;
+        }
+    }
+}
+
 /* define all input grids */
 static
-void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, int timedimid, char *uuidOfHGrid, char *gridfile, int number_of_grid_used)
+void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, int timedimid, unsigned char *uuidOfHGrid, char *gridfile, int number_of_grid_used)
 {
   int ncvarid, ncvarid2;
   int ndims;
@@ -44453,41 +44295,19 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
 #if defined (PROJECTION_TEST)
 	  if ( proj.type == GRID_PROJECTION )
 	    {
-	      ncvars[ncvarid].gridID = varDefGrid(vlistID, proj, 1);
+	      ncvars[ncvarid].gridID = varDefGrid(vlistID, &proj, 1);
 	      copy_numeric_projatts(ncvars[ncvarid].gridID, ncvars[ncvarid].gmapid, ncvars[ncvarid].ncid);
 	    }
 	  else
 #endif
-	    ncvars[ncvarid].gridID = varDefGrid(vlistID, grid, 1);
+	    ncvars[ncvarid].gridID = varDefGrid(vlistID, &grid, 1);
 
           if ( grid.type == GRID_UNSTRUCTURED )
             {
               if ( gridfile[0] != 0 ) gridDefReference(ncvars[ncvarid].gridID, gridfile);
             }
 
-          if ( ncvars[ncvarid].chunked )
-            {
-              ndims = ncvars[ncvarid].ndims;
-
-              if ( grid.type == GRID_UNSTRUCTURED )
-                {
-                  if ( ncvars[ncvarid].chunks[ndims-1] == grid.size )
-                    ncvars[ncvarid].chunktype = CHUNK_GRID;
-                  else
-                    ncvars[ncvarid].chunktype = CHUNK_AUTO;
-                }
-              else
-                {
-                  if ( grid.xsize > 1 && grid.ysize > 1 && ndims > 1 &&
-                       grid.xsize == ncvars[ncvarid].chunks[ndims-1] &&
-                       grid.ysize == ncvars[ncvarid].chunks[ndims-2] )
-                    ncvars[ncvarid].chunktype = CHUNK_GRID;
-                  else if ( grid.xsize > 1 && grid.xsize == ncvars[ncvarid].chunks[ndims-1] )
-                    ncvars[ncvarid].chunktype = CHUNK_LINES;
-                  else
-                    ncvars[ncvarid].chunktype = CHUNK_AUTO;
-                }
-            }
+          if ( ncvars[ncvarid].chunked ) grid_set_chunktype(&grid, &ncvars[ncvarid]);
 
 	  gridindex = vlistGridIndex(vlistID, ncvars[ncvarid].gridID);
 	  streamptr->xdimID[gridindex] = xdimid;
@@ -44566,7 +44386,7 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
 /* define all input zaxes */
 static
 void define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars,
-		      size_t vctsize, double *vct, char *uuidOfVGrid)
+		      size_t vctsize, double *vct, unsigned char *uuidOfVGrid)
 {
   int ncvarid, ncvarid2;
   int i, ilev, ndims;
@@ -44891,15 +44711,14 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
 
       if ( ncvars[ncvarid].natts )
 	{
-	  int nvatts;
 	  int attnum;
 	  int iatt;
 	  nc_type attrtype;
 	  size_t attlen;
 	  char attname[CDI_MAX_NAME];
 	  const int attstringlen = 8192; char attstring[8192];
+	  int nvatts = ncvars[ncvarid].natts;
 
-	  nvatts = ncvars[ncvarid].natts;
 	  for ( iatt = 0; iatt < nvatts; iatt++ )
 	    {
 	      attnum = ncvars[ncvarid].atts[iatt];
@@ -44909,41 +44728,32 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
 
 	      if ( attrtype == NC_SHORT || attrtype == NC_INT )
 		{
-		  int *attint;
-		  attint = (int *) malloc(attlen*sizeof(int));
+		  int *attint = (int *) malloc(attlen*sizeof(int));
 		  cdfGetAttInt(ncid, ncvarid, attname, (int)attlen, attint);
 		  if ( attrtype == NC_SHORT )
 		    vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT16, (int)attlen, attint);
 		  else
 		    vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT32, (int)attlen, attint);
-		  if ( CDI_Debug )
-		    printf("int: %s.%s = %d\n", ncvars[ncvarid].name, attname, attint[0]);
 		  free(attint);
 		}
 	      else if ( attrtype == NC_FLOAT || attrtype == NC_DOUBLE )
 		{
-		  double *attflt;
-		  attflt = (double *) malloc(attlen*sizeof(double));
+		  double *attflt = (double *) malloc(attlen*sizeof(double));
 		  cdfGetAttDouble(ncid, ncvarid, attname, (int)attlen, attflt);
 		  if ( attrtype == NC_FLOAT )
 		    vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT32, (int)attlen, attflt);
 		  else
 		    vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT64, (int)attlen, attflt);
-		  if ( CDI_Debug )
-		    printf("flt: %s.%s = %g\n", ncvars[ncvarid].name, attname, attflt[0]);
 		  free(attflt);
 		}
 	      else if ( xtypeIsText(attrtype) )
 		{
 		  cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring);
 		  vlistDefAttTxt(vlistID, varID, attname, (int)attlen, attstring);
-		  if ( CDI_Debug )
-		    printf("txt: %s.%s = %s\n", ncvars[ncvarid].name, attname, attstring);
 		}
 	      else
 		{
-		  if ( CDI_Debug )
-		    printf("att: %s.%s = unknown\n", ncvars[ncvarid].name, attname);
+		  if ( CDI_Debug ) printf("att: %s.%s = unknown\n", ncvars[ncvarid].name, attname);
 		}
 	    }
 
@@ -45031,9 +44841,7 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
 }
 
 static
-void scan_global_attributes(int fileID, int vlistID, stream_t *streamptr, int ngatts,
-                            int *instID, int *modelID, int *ucla_les, char *uuidOfHGrid, char *uuidOfVGrid,
-                            char *gridfile, int *number_of_grid_used, char *fcreftime)
+void scan_global_attributes(int fileID, int vlistID, stream_t *streamptr, int ngatts, int *instID, int *modelID, int *ucla_les, unsigned char *uuidOfHGrid, unsigned char *uuidOfVGrid, char *gridfile, int *number_of_grid_used, char *fcreftime)
 {
   nc_type xtype;
   size_t attlen;
@@ -45280,11 +45088,9 @@ void find_time_vars(int nvars, ncvar_t *ncvars, ncdim_t *ncdims, int timedimid,
         }
     }
 }
-#endif
 
 int cdfInqContents(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int ndims, nvars, ngatts, unlimdimid;
   int ncvarid;
   int ncdimid;
@@ -45312,16 +45118,16 @@ int cdfInqContents(stream_t *streamptr)
   int vlistID;
   int format = 0;
   int ucla_les = FALSE;
-  char uuidOfHGrid[17];
-  char uuidOfVGrid[17];
+  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
+  unsigned char uuidOfVGrid[CDI_UUID_SIZE];
   char gridfile[8912];
   char fcreftime[CDI_MAX_NAME];
   int number_of_grid_used = UNDEFID;
 
-  uuidOfHGrid[0] = 0;
-  uuidOfVGrid[0] = 0;
-  gridfile[0]    = 0;
-  fcreftime[0]   = 0;
+  memset(uuidOfHGrid, 0, CDI_UUID_SIZE);
+  memset(uuidOfVGrid, 0, CDI_UUID_SIZE);
+  gridfile[0] = 0;
+  fcreftime[0] = 0;
 
   vlistID = streamptr->vlistID;
   fileID  = streamptr->fileID;
@@ -45786,12 +45592,9 @@ int cdfInqContents(stream_t *streamptr)
   /* free ncvars */
   free(ncvars);
 
-#endif
-
   return (0);
 }
 
-#if  defined  (HAVE_LIBNETCDF)
 static
 void wrf_read_timestep(int fileID, int nctimevarid, int tsID, taxis_t *taxis)
 {
@@ -45847,12 +45650,10 @@ double get_timevalue(int fileID, int nctimevarid, int tsID, timecache_t *tcache)
 
   return timevalue;
 }
-#endif
 
 int cdfInqTimestep(stream_t * streamptr, int tsID)
 {
   long nrecs = 0;
-#if  defined  (HAVE_LIBNETCDF)
   double timevalue;
   int fileID;
   taxis_t *taxis;
@@ -45924,14 +45725,12 @@ int cdfInqTimestep(stream_t * streamptr, int tsID)
   streamptr->curTsID = tsID;
   nrecs = streamptr->tsteps[tsID].nrecs;
 
-#endif
   return ((int) nrecs);
 }
 
 
 void cdfEndDef(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int varID;
   int nvars;
   int fileID;
@@ -45962,13 +45761,11 @@ void cdfEndDef(stream_t *streamptr)
 
       streamptr->accessmode = 1;
     }
-#endif
 }
 
 
-void cdfDefInstitut(stream_t *streamptr)
+static void cdfDefInstitut(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int fileID, instID;
   char *longname;
   size_t len;
@@ -45992,28 +45789,21 @@ void cdfDefInstitut(stream_t *streamptr)
 	    }
 	}
     }
-#endif
 }
 
 
-void cdfDefSource(stream_t *streamptr)
+static void cdfDefSource(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int fileID, modelID;
-  char *longname;
-  size_t len;
-  int vlistID;
-
-  vlistID = streamptr->vlistID;
-  fileID  = streamptr->fileID;
-  modelID = vlistInqModel(vlistID);
+  int vlistID = streamptr->vlistID;
+  int fileID  = streamptr->fileID;
+  int modelID = vlistInqModel(vlistID);
 
   if ( modelID != UNDEFID )
     {
-      longname = modelInqNamePtr(modelID);
+      const char *longname = modelInqNamePtr(modelID);
       if ( longname )
 	{
-	  len = strlen(longname);
+          size_t len = strlen(longname);
 	  if ( len > 0 )
 	    {
 	      if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
@@ -46022,13 +45812,11 @@ void cdfDefSource(stream_t *streamptr)
 	    }
 	}
     }
-#endif
 }
 
 
-void cdfDefGlobalAtts(stream_t *streamptr)
+static void cdfDefGlobalAtts(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int fileID, vlistID;
   int natts;
 
@@ -46049,21 +45837,13 @@ void cdfDefGlobalAtts(stream_t *streamptr)
   if ( natts > 0 && streamptr->ncmode == 2 ) cdf_enddef(fileID);
 
   streamptr->globalatts = 1;
-#endif
 }
 
 
-void cdfDefLocalAtts(stream_t *streamptr)
+static void cdfDefLocalAtts(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int varID, instID, fileID;
-  char *name;
-  size_t len;
-  int ncvarid;
-  int vlistID;
-
-  vlistID = streamptr->vlistID;
-  fileID  = streamptr->fileID;
+  int vlistID = streamptr->vlistID;
+  int fileID  = streamptr->fileID;
 
   if ( streamptr->localatts ) return;
   if ( vlistInqInstitut(vlistID) != UNDEFID ) return;
@@ -46072,68 +45852,53 @@ void cdfDefLocalAtts(stream_t *streamptr)
 
   if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
 
-  for ( varID = 0; varID < streamptr->nvars; varID++ )
+  for ( int varID = 0; varID < streamptr->nvars; varID++ )
     {
-      instID = vlistInqVarInstitut(vlistID, varID);
+      int instID = vlistInqVarInstitut(vlistID, varID);
       if ( instID != UNDEFID )
 	{
-          ncvarid = streamptr->vars[varID].ncvarid;
-  	  name = institutInqNamePtr(instID);
+          int ncvarid = streamptr->vars[varID].ncvarid;
+  	  const char *name = institutInqNamePtr(instID);
 	  if ( name )
 	    {
-	      len = strlen(name);
+              size_t len = strlen(name);
 	      cdf_put_att_text(fileID, ncvarid, "institution", len, name);
 	    }
 	}
       }
 
   if ( streamptr->ncmode == 2 ) cdf_enddef(fileID);
-#endif
 }
 
 
-void cdfDefHistory(stream_t *streamptr, int size, char *history)
+void cdfDefHistory(stream_t *streamptr, int size, const char *history)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int ncid;
-
-  ncid = streamptr->fileID;
+  int ncid = streamptr->fileID;
   cdf_put_att_text(ncid, NC_GLOBAL, "history", (size_t) size, history);
-#endif
 }
 
 
 int cdfInqHistorySize(stream_t *streamptr)
 {
   size_t size = 0;
-#if  defined  (HAVE_LIBNETCDF)
-  int ncid;
-
-  ncid = streamptr->fileID;
+  int ncid = streamptr->fileID;
   if ( streamptr->historyID != UNDEFID )
     cdf_inq_attlen(ncid, NC_GLOBAL, "history", &size);
 
-#endif
   return ((int) size);
 }
 
 
 void cdfInqHistoryString(stream_t *streamptr, char *history)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int ncid;
-
-  ncid = streamptr->fileID;
+  int ncid = streamptr->fileID;
   if ( streamptr->historyID != UNDEFID )
     cdf_get_att_text(ncid, NC_GLOBAL, "history", history);
-
-#endif
 }
 
 
 void cdfDefVars(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int index, gridID, zaxisID, vlistID;
   int ngrids, nzaxis;
   /* int  nvars, ncvarid; */
@@ -46166,8 +45931,8 @@ void cdfDefVars(stream_t *streamptr)
       ncvarid = cdfDefVar(streamptr, varID);
     }
   */
-#endif
 }
+#endif
 /*
  * Local Variables:
  * c-file-style: "Java"
@@ -46456,7 +46221,20 @@ void streamInqRecord(int streamID, int *varID, int *levelID)
   streamptr->tsteps[tsID].curRecID = rindex;
 }
 
+/*
+ at Function  streamDefRecord
+ at Title     Define the next record
+
+ at Prototype void streamDefRecord(int streamID, int varID, int levelID)
+ at Parameter
+    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenWrite}.
+    @Item  varID     Variable identifier.
+    @Item  levelID   Level identifier.
 
+ at Description
+The function streamDefRecord defines the meta-data of the next record.
+ at EndFunction
+*/
 void streamDefRecord(int streamID, int varID, int levelID)
 {
   stream_t *streamptr = stream_to_pointer(streamID);
@@ -46628,7 +46406,21 @@ stream_write_record(int streamID, int memtype, const void *data, int nmiss)
     }
 }
 
+/*
+ at Function  streamWriteRecord
+ at Title     Write a horizontal slice of a variable
+
+ at Prototype void streamWriteRecord(int streamID, const double *data, int nmiss)
+ at Parameter
+    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenWrite}.
+    @Item  data      Pointer to a block of double precision floating point data values to be written.
+    @Item  nmiss     Number of missing values.
 
+ at Description
+The function streamWriteRecord writes the values of a horizontal slice (record) of a variable to an open dataset.
+The values are converted to the external data type of the variable, if necessary.
+ at EndFunction
+*/
 void streamWriteRecord(int streamID, const double *data, int nmiss)
 {
   stream_write_record(streamID, MEMTYPE_DOUBLE, (const void *) data, nmiss);
@@ -62648,7 +62440,7 @@ void gribContainersNew(stream_t * streamptr)
   int editionNumber = 2;
 
   if ( streamptr->filetype == FILETYPE_GRB ) editionNumber = 1;
-
+  (void)editionNumber;
 #if  defined  (HAVE_LIBCGRIBEX)
   if ( streamptr->filetype == FILETYPE_GRB )
     {
@@ -63653,6 +63445,7 @@ int
 serializeGetSizeInCore(int count, int datatype, void *context)
 {
   int elemSize;
+  (void)context;
   switch (datatype)
   {
   case DATATYPE_INT8:
@@ -63686,7 +63479,7 @@ void serializePackInCore(void *data, int count, int datatype,
 {
   int size = serializeGetSize(count, datatype, context);
   int pos = *position;
-  xassert(INT_MAX - pos >= size);
+  xassert(INT_MAX - pos >= size && buf_size - pos >= size);
   memcpy((unsigned char *)buf + pos, data, (size_t)size);
   pos += size;
   *position = pos;
@@ -63697,7 +63490,7 @@ void serializeUnpackInCore(void *buf, int buf_size, int *position,
 {
   int size = serializeGetSize(count, datatype, context);
   int pos = *position;
-  xassert(INT_MAX - pos >= size);
+  xassert(INT_MAX - pos >= size && buf_size - pos >= size);
   memcpy(data, (unsigned char *)buf + pos, (size_t)size);
   pos += size;
   *position = pos;
@@ -63727,8 +63520,11 @@ void show_stackframe()
   char **messages = backtrace_symbols(trace, trace_size);
 
   fprintf(stderr, "[bt] Execution path:\n");
-  for ( i = 0; i < trace_size; ++i ) fprintf(stderr, "[bt] %s\n", messages[i]);
-  if ( messages ) free(messages);
+  if ( messages ) {
+    for ( i = 0; i < trace_size; ++i )
+      fprintf(stderr, "[bt] %s\n", messages[i]);
+    free(messages);
+  }
 #endif
 }
 
@@ -63843,7 +63639,7 @@ reshListCreate(int namespaceID)
   LIST_LOCK();
   if (resHListSize <= namespaceID)
     {
-      resHList = (struct resHList_t *)xrealloc(resHList, (namespaceID + 1) * sizeof (resHList[0]));
+      resHList = (struct resHList_t *)xrealloc(resHList, (size_t)(namespaceID + 1) * sizeof (resHList[0]));
       for (int i = resHListSize; i <= namespaceID; ++i)
         reshListClearEntry(i);
       resHListSize = namespaceID + 1;
@@ -64509,7 +64305,7 @@ void reshListPrint(FILE *fp)
  * require-trailing-newline: t
  * End:
  */
-   static const char cdi_libvers[] = "1.6.5.1" " of ""Oct 31 2014"" ""21:33:19";
+   static const char cdi_libvers[] = "1.6.6" " of ""Nov 25 2014"" ""15:24:48";
 const char *cdiLibraryVersion(void)
 {
   return (cdi_libvers);
@@ -67003,6 +66799,9 @@ string. */
 /*  CALENDAR types  */
 
 
+/*  number of unsigned char needed to store UUID  */
+
+
 /*  CDI control routines  */
 
 FCALLSCSUB0 (cdiReset, CDIRESET, cdireset)
@@ -67062,7 +66861,6 @@ FCALLSCFUN2 (INT, streamInqTimestep, STREAMINQTIMESTEP, streaminqtimestep, INT,
 FCALLSCFUN1 (INT, streamInqCurTimestepID, STREAMINQCURTIMESTEPID, streaminqcurtimestepid, INT)
 FCALLSCFUN1 (STRING, streamFilename, STREAMFILENAME, streamfilename, INT)
 FCALLSCFUN1 (STRING, streamFilesuffix, STREAMFILESUFFIX, streamfilesuffix, INT)
-FCALLSCFUN1 (INT, streamNtsteps, STREAMNTSTEPS, streamntsteps, INT)
 FCALLSCFUN1 (INT, streamInqNvars, STREAMINQNVARS, streaminqnvars, INT)
 
 /*  STREAM var I/O routines  */
@@ -67290,8 +67088,8 @@ FCALLSCSUB2 (gridDefPosition, GRIDDEFPOSITION, griddefposition, INT, INT)
 FCALLSCFUN1 (INT, gridInqPosition, GRIDINQPOSITION, gridinqposition, INT)
 FCALLSCSUB2 (gridDefReference, GRIDDEFREFERENCE, griddefreference, INT, STRING)
 FCALLSCFUN2 (INT, gridInqReference, GRIDINQREFERENCE, gridinqreference, INT, PSTRING)
-FCALLSCSUB2 (gridDefUUID, GRIDDEFUUID, griddefuuid, INT, PPSTRING)
-FCALLSCSUB2 (gridInqUUID, GRIDINQUUID, gridinquuid, INT, PPSTRING)
+FCALLSCSUB2 (gridDefUUID, GRIDDEFUUID, griddefuuid, INT, PVOID)
+FCALLSCSUB2 (gridInqUUID, GRIDINQUUID, gridinquuid, INT, PVOID)
 
 /*  Lambert Conformal Conic grid (GRIB version)  */
 
@@ -67316,7 +67114,7 @@ FCALLSCSUB2 (gridDefXbounds, GRIDDEFXBOUNDS, griddefxbounds, INT, PDOUBLE)
 FCALLSCFUN2 (INT, gridInqXbounds, GRIDINQXBOUNDS, gridinqxbounds, INT, PDOUBLE)
 FCALLSCSUB2 (gridDefYbounds, GRIDDEFYBOUNDS, griddefybounds, INT, PDOUBLE)
 FCALLSCFUN2 (INT, gridInqYbounds, GRIDINQYBOUNDS, gridinqybounds, INT, PDOUBLE)
-FCALLSCSUB3 (gridDefRowlon, GRIDDEFROWLON, griddefrowlon, INT, INT, PINT)
+FCALLSCSUB3 (gridDefRowlon, GRIDDEFROWLON, griddefrowlon, INT, INT, INTV)
 FCALLSCSUB2 (gridInqRowlon, GRIDINQROWLON, gridinqrowlon, INT, PINT)
 FCALLSCSUB2 (gridChangeType, GRIDCHANGETYPE, gridchangetype, INT, INT)
 FCALLSCSUB2 (gridDefComplexPacking, GRIDDEFCOMPLEXPACKING, griddefcomplexpacking, INT, INT)
@@ -67340,8 +67138,8 @@ FCALLSCSUB2 (zaxisDefNlevRef, ZAXISDEFNLEVREF, zaxisdefnlevref, INT, INT)
 FCALLSCFUN1 (INT, zaxisInqNlevRef, ZAXISINQNLEVREF, zaxisinqnlevref, INT)
 FCALLSCSUB2 (zaxisDefNumber, ZAXISDEFNUMBER, zaxisdefnumber, INT, INT)
 FCALLSCFUN1 (INT, zaxisInqNumber, ZAXISINQNUMBER, zaxisinqnumber, INT)
-FCALLSCSUB2 (zaxisDefUUID, ZAXISDEFUUID, zaxisdefuuid, INT, PPSTRING)
-FCALLSCSUB2 (zaxisInqUUID, ZAXISINQUUID, zaxisinquuid, INT, PPSTRING)
+FCALLSCSUB2 (zaxisDefUUID, ZAXISDEFUUID, zaxisdefuuid, INT, PVOID)
+FCALLSCSUB2 (zaxisInqUUID, ZAXISINQUUID, zaxisinquuid, INT, PVOID)
 FCALLSCSUB2 (zaxisDefName, ZAXISDEFNAME, zaxisdefname, INT, STRING)
 FCALLSCSUB2 (zaxisInqName, ZAXISINQNAME, zaxisinqname, INT, PSTRING)
 FCALLSCSUB2 (zaxisDefLongname, ZAXISDEFLONGNAME, zaxisdeflongname, INT, STRING)
diff --git a/libcdi/src/cdipio.inc b/libcdi/src/cdipio.inc
index 68be71d..52e90ac 100644
--- a/libcdi/src/cdipio.inc
+++ b/libcdi/src/cdipio.inc
@@ -1,10 +1,10 @@
 ! This file was automatically generated, don't edit!
 !
-! Fortran interface for CDI library version 1.6.3
+! Fortran interface for CDI library version 1.6.4
 !
 ! Author:
 ! -------
-! Uwe Schulzweida, MPI-MET, Hamburg,   January 2014
+! Uwe Schulzweida, MPI-MET, Hamburg,   November 2014
 !
 
 !
diff --git a/libcdi/src/config.h.in b/libcdi/src/config.h.in
index 249e423..82ff618 100644
--- a/libcdi/src/config.h.in
+++ b/libcdi/src/config.h.in
@@ -16,6 +16,14 @@
    */
 #undef HAVE_DECL_ISNAN
 
+/* Define to 1 if you have the declaration of `uuid_create', and to 0 if you
+   don't. */
+#undef HAVE_DECL_UUID_CREATE
+
+/* Define to 1 if you have the declaration of `uuid_generate', and to 0 if you
+   don't. */
+#undef HAVE_DECL_UUID_GENERATE
+
 /* Define to 1 if you have the declaration of `__builtin_ctz', and to 0 if you
    don't. */
 #undef HAVE_DECL___BUILTIN_CTZ
@@ -167,6 +175,15 @@
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
+/* Define to 1 if you have the `uuid_create' function. */
+#undef HAVE_UUID_CREATE
+
+/* Define to 1 if you have the <uuid.h> header file. */
+#undef HAVE_UUID_H
+
+/* Define to 1 if you have the <uuid/uuid.h> header file. */
+#undef HAVE_UUID_UUID_H
+
 /* yaxt library is available */
 #undef HAVE_YAXT
 
diff --git a/libcdi/src/dmemory.c b/libcdi/src/dmemory.c
index 89c9074..7249d24 100644
--- a/libcdi/src/dmemory.c
+++ b/libcdi/src/dmemory.c
@@ -343,7 +343,7 @@ int memListChangeEntry(void *ptrold, void *ptr, size_t size,
 		       const char *caller, const char *file, int line)
 {
   int item = UNDEFID;
-  int memID = 0;
+  size_t memID = 0;
   size_t sizeold;
 
   while( memID < memTableSize )
diff --git a/libcdi/src/extralib.c b/libcdi/src/extralib.c
index 0ecb706..9b92391 100644
--- a/libcdi/src/extralib.c
+++ b/libcdi/src/extralib.c
@@ -402,7 +402,6 @@ int extRead(int fileID, void *ext)
   extrec_t *extp = (extrec_t *) ext;
   size_t blocklen, blocklen2;
   size_t i;
-  char tempheader[32];
   void *buffer;
   int byteswap;
   int status;
@@ -432,19 +431,21 @@ int extRead(int fileID, void *ext)
     {
     case SINGLE_PRECISION:
       {
-	binReadInt32(fileID, byteswap, EXT_HEADER_LEN, (INT32 *) tempheader);
+        INT32 tempheader[4];
+	binReadInt32(fileID, byteswap, EXT_HEADER_LEN, tempheader);
 
 	for ( i = 0; i < EXT_HEADER_LEN; i++ )
-          extp->header[i] = (int) ((INT32 *) tempheader)[i];
+          extp->header[i] = (int)tempheader[i];
 
 	break;
       }
     case DOUBLE_PRECISION:
       {
-	binReadInt64(fileID, byteswap, EXT_HEADER_LEN, (INT64 *) tempheader);
+        INT64 tempheader[4];
+	binReadInt64(fileID, byteswap, EXT_HEADER_LEN, tempheader);
 
 	for ( i = 0; i < EXT_HEADER_LEN; i++ )
-          extp->header[i] = (int) ((INT64 *) tempheader)[i];
+          extp->header[i] = (int)tempheader[i];
 
 	break;
       }
diff --git a/libcdi/src/gribapi.c b/libcdi/src/gribapi.c
index 331dbf7..798a0a6 100644
--- a/libcdi/src/gribapi.c
+++ b/libcdi/src/gribapi.c
@@ -59,7 +59,7 @@ void gribContainersNew(stream_t * streamptr)
   int editionNumber = 2;
 
   if ( streamptr->filetype == FILETYPE_GRB ) editionNumber = 1;
-
+  (void)editionNumber;
 #if  defined  (HAVE_LIBCGRIBEX)
   if ( streamptr->filetype == FILETYPE_GRB )
     {
diff --git a/libcdi/src/gribapi.h b/libcdi/src/gribapi.h
index 4dc3e9d..141af58 100644
--- a/libcdi/src/gribapi.h
+++ b/libcdi/src/gribapi.h
@@ -1,6 +1,11 @@
 #ifndef _GRIBAPI_H
 #define _GRIBAPI_H
 
+#ifdef HAVE_LIBGRIBAPI
+#  include "error.h"
+#  include <grib_api.h>
+#endif
+
 #define  GRIBAPI_MISSVAL  -9.E33
 
 /* GRIB2 Level Types */
@@ -45,8 +50,24 @@
 const char *gribapiLibraryVersionString(void);
 void gribContainersNew(stream_t * streamptr);
 void gribContainersDelete(stream_t * streamptr);
-void *gribHandleNew(int editionNumber);
-void gribHandleDelete(void *gh);
+#ifdef HAVE_LIBGRIBAPI
+static inline void *gribHandleNew(int editionNumber)
+{
+  void *gh =
+    (void *)grib_handle_new_from_samples(NULL, (editionNumber == 1) ? "GRIB1" : "GRIB2");
+
+  if ( gh == NULL ) Error("grib_handle_new_from_samples failed!");
+  return gh;
+}
+
+static inline void gribHandleDelete(void *gh)
+{
+  grib_handle_delete(gh);
+}
+#else
+#define gribHandleNew(editionNumber) (NULL)
+#define gribHandleDelete(gh)
+#endif
 
 typedef struct {
   int init;
diff --git a/libcdi/src/grid.c b/libcdi/src/grid.c
index dd9658e..1fb44aa 100644
--- a/libcdi/src/grid.c
+++ b/libcdi/src/grid.c
@@ -67,6 +67,7 @@ static const resOps gridOps = {
 
 static int  GRID_Debug = 0;   /* If set to 1, debugging */
 
+#define gridID2Ptr(gridID) (grid_t *)reshGetVal(gridID, &gridOps)
 
 void grid_init(grid_t *gridptr)
 {
@@ -136,7 +137,7 @@ void grid_init(grid_t *gridptr)
   gridptr->yunits[0]    = 0;
   gridptr->xstdname[0]  = 0;
   gridptr->ystdname[0]  = 0;
-  memset(gridptr->uuid, 0, 16);
+  memset(gridptr->uuid, 0, CDI_UUID_SIZE);
   gridptr->name         = NULL;
 }
 
@@ -196,16 +197,6 @@ void grid_copy(grid_t *gridptr2, grid_t *gridptr1)
   gridptr2->self = gridID2;
 }
 
-static
-void gridCheckPtr(const char *caller, int gridID, grid_t *gridptr)
-{
-  if ( gridptr == NULL )
-    Errorc("grid %d undefined!", gridID);
-}
-
-#define  grid_check_ptr(gridID, gridptr)  gridCheckPtr(__func__, gridID, gridptr)
-
-
 int gridSize(void)
 {
   return reshCountType ( &gridOps );
@@ -522,7 +513,7 @@ void gridDestroyKernel( grid_t * gridptr )
 */
 void gridDestroy(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   gridDestroyKernel ( gridptr );
 }
@@ -538,10 +529,7 @@ const char *gridNamePtr(int gridtype)
   const char *name;
   int size = (int) (sizeof(Grids)/sizeof(char *));
 
-  if ( gridtype >= 0 && gridtype < size )
-    name = Grids[gridtype];
-  else
-    name = Grids[GRID_GENERIC];
+  name = gridtype >= 0 && gridtype < size ? Grids[gridtype] : Grids[GRID_GENERIC];
 
   return (name);
 }
@@ -568,13 +556,12 @@ The function @func{gridDefXname} defines the name of a X-axis.
 */
 void gridDefXname(int gridID, const char *xname)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( xname )
     {
-      strcpy(gridptr->xname, xname);
+      strncpy(gridptr->xname, xname, CDI_MAX_NAME);
+      gridptr->xname[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -595,12 +582,11 @@ The function @func{gridDefXlongname} defines the longname of a X-axis.
 */
 void gridDefXlongname(int gridID, const char *xlongname)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-  grid_check_ptr(gridID, gridptr);
-
+  grid_t *gridptr = gridID2Ptr(gridID);
   if ( xlongname )
     {
-      strcpy(gridptr->xlongname, xlongname);
+      strncpy(gridptr->xlongname, xlongname, CDI_MAX_NAME);
+      gridptr->xlongname[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -621,13 +607,12 @@ The function @func{gridDefXunits} defines the units of a X-axis.
 */
 void gridDefXunits(int gridID, const char *xunits)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( xunits )
     {
-      strcpy(gridptr->xunits, xunits);
+      strncpy(gridptr->xunits, xunits, CDI_MAX_NAME);
+      gridptr->xunits[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -648,13 +633,12 @@ The function @func{gridDefYname} defines the name of a Y-axis.
 */
 void gridDefYname(int gridID, const char *yname)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( yname )
     {
-      strcpy(gridptr->yname, yname);
+      strncpy(gridptr->yname, yname, CDI_MAX_NAME);
+      gridptr->yname[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -675,13 +659,12 @@ The function @func{gridDefYlongname} defines the longname of a Y-axis.
 */
 void gridDefYlongname(int gridID, const char *ylongname)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( ylongname )
     {
-      strcpy(gridptr->ylongname, ylongname);
+      strncpy(gridptr->ylongname, ylongname, CDI_MAX_NAME);
+      gridptr->ylongname[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -702,13 +685,12 @@ The function @func{gridDefYunits} defines the units of a Y-axis.
 */
 void gridDefYunits(int gridID, const char *yunits)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( yunits )
     {
-      strcpy(gridptr->yunits, yunits);
+      strncpy(gridptr->yunits, yunits, CDI_MAX_NAME);
+      gridptr->yunits[CDI_MAX_NAME - 1] = 0;
       reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
     }
 }
@@ -734,9 +716,7 @@ The function @func{gridInqXname} returns the name of a X-axis.
 */
 void gridInqXname(int gridID, char *xname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(xname, gridptr->xname);
 }
@@ -762,9 +742,7 @@ The function @func{gridInqXlongname} returns the longname of a X-axis.
 */
 void gridInqXlongname(int gridID, char *xlongname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(xlongname, gridptr->xlongname);
 }
@@ -790,9 +768,7 @@ The function @func{gridInqXunits} returns the units of a X-axis.
 */
 void gridInqXunits(int gridID, char *xunits)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(xunits, gridptr->xunits);
 }
@@ -800,9 +776,7 @@ void gridInqXunits(int gridID, char *xunits)
 
 void gridInqXstdname(int gridID, char *xstdname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(xstdname, gridptr->xstdname);
 }
@@ -828,9 +802,7 @@ The function @func{gridInqYname} returns the name of a Y-axis.
 */
 void gridInqYname(int gridID, char *yname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(yname, gridptr->yname);
 }
@@ -856,9 +828,7 @@ The function @func{gridInqYlongname} returns the longname of a Y-axis.
 */
 void gridInqYlongname(int gridID, char *ylongname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(ylongname, gridptr->ylongname);
 }
@@ -884,18 +854,14 @@ The function @func{gridInqYunits} returns the units of a Y-axis.
 */
 void gridInqYunits(int gridID, char *yunits)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(yunits, gridptr->yunits);
 }
 
 void gridInqYstdname(int gridID, char *ystdname)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   strcpy(ystdname, gridptr->ystdname);
 }
@@ -922,9 +888,7 @@ The valid CDI grid types are @func{GRID_GENERIC}, @func{GRID_GAUSSIAN},
 */
 int gridInqType(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->type);
 }
@@ -948,9 +912,7 @@ The function @func{gridInqSize} returns the size of a Grid.
 */
 int gridInqSize(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int size = gridptr->size;
 
@@ -981,19 +943,14 @@ int nsp2trunc(int nsp)
   /*  with:  y^2 + p*y + q = 0               */
   /*         y = -p/2 +- sqrt((p/2)^2 - q)   */
   /*         p = 3 and q = - (x-2)           */
-  int trunc;
-
-  trunc = (int) (sqrt(nsp*4 + 1.) - 3) / 2;
-
+  int trunc = (int) (sqrt(nsp*4 + 1.) - 3) / 2;
   return (trunc);
 }
 
 
 int gridInqTrunc(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->trunc == 0 )
     {
@@ -1011,9 +968,7 @@ int gridInqTrunc(int gridID)
 
 void gridDefTrunc(int gridID, int trunc)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->trunc != trunc)
     {
@@ -1038,9 +993,7 @@ The function @func{gridDefXsize} defines the number of values of a X-axis.
 */
 void gridDefXsize(int gridID, int xsize)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( xsize > gridInqSize(gridID) )
     Error("xsize %d is greater then gridsize %d", xsize, gridInqSize(gridID));
@@ -1075,9 +1028,7 @@ void gridDefXsize(int gridID, int xsize)
 */
 void gridDefPrec(int gridID, int prec)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->prec != prec)
     {
@@ -1098,9 +1049,7 @@ void gridDefPrec(int gridID, int prec)
 */
 int gridInqPrec(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->prec);
 }
@@ -1123,9 +1072,7 @@ The function @func{gridInqXsize} returns the number of values of a X-axis.
 */
 int gridInqXsize(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->xsize);
 }
@@ -1146,9 +1093,7 @@ The function @func{gridDefYsize} defines the number of values of a Y-axis.
 */
 void gridDefYsize(int gridID, int ysize)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( ysize > gridInqSize(gridID) )
     Error("ysize %d is greater then gridsize %d", ysize, gridInqSize(gridID));
@@ -1189,9 +1134,7 @@ The function @func{gridInqYsize} returns the number of values of a Y-axis.
 */
 int gridInqYsize(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ysize);
 }
@@ -1213,9 +1156,7 @@ of a Gaussian grid.
 */
 void gridDefNP(int gridID, int np)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->np != np)
     {
@@ -1243,9 +1184,7 @@ of a Gaussian grid.
 */
 int gridInqNP(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->np);
 }
@@ -1260,11 +1199,9 @@ int gridInqNP(int gridID)
 
 @EndFunction
 */
-void gridDefRowlon(int gridID, int nrowlon, const int *rowlon)
+void gridDefRowlon(int gridID, int nrowlon, const int rowlon[])
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   gridptr->rowlon = (int *)xmalloc((size_t)nrowlon * sizeof(int));
   gridptr->nrowlon = nrowlon;
@@ -1284,9 +1221,7 @@ void gridDefRowlon(int gridID, int nrowlon, const int *rowlon)
 */
 void gridInqRowlon(int gridID, int *rowlon)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->rowlon == 0 )  Error("undefined pointer!");
 
@@ -1296,9 +1231,7 @@ void gridInqRowlon(int gridID, int *rowlon)
 
 int gridInqMask(int gridID, int *mask)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size = gridptr->size;
 
@@ -1311,13 +1244,13 @@ int gridInqMask(int gridID, int *mask)
 
   if ( gridptr->mask == NULL ) size = 0;
 
-  return (size);
+  return (int)size;
 }
 
 
 void gridDefMask(int gridID, const int *mask)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size = gridptr->size;
 
@@ -1347,9 +1280,7 @@ void gridDefMask(int gridID, const int *mask)
 
 int gridInqMaskGME(int gridID, int *mask)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size = gridptr->size;
 
@@ -1362,15 +1293,13 @@ int gridInqMaskGME(int gridID, int *mask)
 
   if ( gridptr->mask_gme == NULL ) size = 0;
 
-  return (size);
+  return (int)size;
 }
 
 
 void gridDefMaskGME(int gridID, const int *mask)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size = gridptr->size;
 
@@ -1408,9 +1337,7 @@ Otherwise, 0 is returned and @func{xvals} is empty.
 */
 int gridInqXvals(int gridID, double *xvals)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   long size;
   if ( gridptr->type == GRID_CURVILINEAR || gridptr->type == GRID_UNSTRUCTURED )
@@ -1428,7 +1355,7 @@ int gridInqXvals(int gridID, double *xvals)
 
   if ( gridptr->xvals == NULL ) size = 0;
 
-  return (size);
+  return (int)size;
 }
 
 /*
@@ -1447,9 +1374,7 @@ The function @func{gridDefXvals} defines all values of the X-axis.
 */
 void gridDefXvals(int gridID, const double *xvals)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int gridtype;
   long size;
@@ -1496,9 +1421,7 @@ Otherwise, 0 is returned and @func{yvals} is empty.
 */
 int gridInqYvals(int gridID, double *yvals)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int gridtype = gridptr->type;
   long size
@@ -1513,7 +1436,7 @@ int gridInqYvals(int gridID, double *yvals)
 
   if ( gridptr->yvals == NULL ) size = 0;
 
-  return (size);
+  return (int)size;
 }
 
 /*
@@ -1532,9 +1455,7 @@ The function @func{gridDefYvals} defines all values of the Y-axis.
 */
 void gridDefYvals(int gridID, const double *yvals)
 {
-  grid_t *gridptr = reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int gridtype = gridptr->type;
   long size
@@ -1556,9 +1477,7 @@ void gridDefYvals(int gridID, const double *yvals)
 double gridInqXval(int gridID, int index)
 {
   double xval = 0;
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->xvals )
     xval = gridptr->xvals[index];
@@ -1579,9 +1498,7 @@ double gridInqXval(int gridID, int index)
 double gridInqYval(int gridID, int index)
 {
   double yval = 0;
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->yvals )
     yval = gridptr->yvals[index];
@@ -1601,9 +1518,7 @@ double gridInqYval(int gridID, int index)
 */
 double gridInqXinc(int gridID)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   double xinc = gridptr->xinc;
 
@@ -1637,9 +1552,7 @@ double gridInqXinc(int gridID)
 */
 double gridInqYinc(int gridID)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   double yinc = gridptr->yinc;
 
@@ -1678,9 +1591,7 @@ double gridInqYinc(int gridID)
 */
 double gridInqXpole(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->xpole);
 }
@@ -1697,9 +1608,7 @@ double gridInqXpole(int gridID)
 */
 void gridDefXpole(int gridID, double xpole)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( memcmp(gridptr->xstdname, "grid", 4) != 0 )
     strcpy(gridptr->xstdname, "grid_longitude");
@@ -1724,9 +1633,7 @@ void gridDefXpole(int gridID, double xpole)
 */
 double gridInqYpole(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ypole);
 }
@@ -1743,9 +1650,7 @@ double gridInqYpole(int gridID)
 */
 void gridDefYpole(int gridID, double ypole)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( memcmp(gridptr->ystdname, "grid", 4) != 0 )
     strcpy(gridptr->ystdname, "grid_latitude");
@@ -1770,9 +1675,7 @@ void gridDefYpole(int gridID, double ypole)
 */
 double gridInqAngle(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->angle);
 }
@@ -1789,9 +1692,7 @@ double gridInqAngle(int gridID)
 */
 void gridDefAngle(int gridID, double angle)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->isRotated != TRUE || IS_NOT_EQUAL(gridptr->angle, angle) )
     {
@@ -1813,9 +1714,7 @@ void gridDefAngle(int gridID, double angle)
 */
 int gridInqGMEnd(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->nd);
 }
@@ -1832,9 +1731,7 @@ int gridInqGMEnd(int gridID)
 */
 void gridDefGMEnd(int gridID, int nd)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->nd != nd)
     {
@@ -1855,9 +1752,7 @@ void gridDefGMEnd(int gridID, int nd)
 */
 int gridInqGMEni(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ni);
 }
@@ -1874,9 +1769,7 @@ int gridInqGMEni(int gridID)
 */
 void gridDefGMEni(int gridID, int ni)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->ni != ni)
     {
@@ -1897,9 +1790,7 @@ void gridDefGMEni(int gridID, int ni)
 */
 int gridInqGMEni2(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ni2);
 }
@@ -1916,9 +1807,7 @@ int gridInqGMEni2(int gridID)
 */
 void gridDefGMEni2(int gridID, int ni2)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->ni2 != ni2)
     {
@@ -1939,18 +1828,14 @@ void gridDefGMEni2(int gridID, int ni2)
 */
 int gridInqGMEni3(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ni3);
 }
 
 void gridDefGMEni3(int gridID, int ni3)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->ni3 != ni3)
     {
@@ -1971,9 +1856,7 @@ void gridDefGMEni3(int gridID, int ni3)
 */
 void gridChangeType(int gridID, int gridtype)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( CDI_Debug )
     Message("Changed grid type from %s to %s", gridNamePtr(gridptr->type), gridNamePtr(gridtype));
@@ -2091,9 +1974,7 @@ void grid_check_cyclic(grid_t *gridptr)
 
 int gridIsCircular(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->isCyclic == CDI_UNDEFID ) grid_check_cyclic(gridptr);
 
@@ -2103,9 +1984,7 @@ int gridIsCircular(int gridID)
 
 int gridIsRotated(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return ( gridptr->isRotated );
 }
@@ -2177,52 +2056,52 @@ int compareXYvals2(int gridID, int gridsize, double *xvals, double *yvals)
 }
 
 
-int gridCompare(int gridID, grid_t grid)
+int gridCompare(int gridID, const grid_t *grid)
 {
   int differ = 1;
 
-  if ( grid.type == gridInqType(gridID) || grid.type == GRID_GENERIC )
+  if ( grid->type == gridInqType(gridID) || grid->type == GRID_GENERIC )
     {
-      if ( grid.size == gridInqSize(gridID) )
+      if ( grid->size == gridInqSize(gridID) )
 	{
 	  differ = 0;
-	  if ( grid.type == GRID_LONLAT )
+	  if ( grid->type == GRID_LONLAT )
 	    {
 	      /*
 	      printf("gridID      %d\n", gridID);
-	      printf("grid.xdef   %d\n", grid.xdef);
-	      printf("grid.ydef   %d\n", grid.ydef);
-	      printf("grid.xsize  %d\n", grid.xsize);
-	      printf("grid.ysize  %d\n", grid.ysize);
-	      printf("grid.xfirst %f\n", grid.xfirst);
-	      printf("grid.yfirst %f\n", grid.yfirst);
+	      printf("grid.xdef   %d\n", grid->xdef);
+	      printf("grid.ydef   %d\n", grid->ydef);
+	      printf("grid.xsize  %d\n", grid->xsize);
+	      printf("grid.ysize  %d\n", grid->ysize);
+	      printf("grid.xfirst %f\n", grid->xfirst);
+	      printf("grid.yfirst %f\n", grid->yfirst);
 	      printf("grid.xfirst %f\n", gridInqXval(gridID, 0));
 	      printf("grid.yfirst %f\n", gridInqYval(gridID, 0));
-	      printf("grid.xinc   %f\n", grid.xinc);
-	      printf("grid.yinc   %f\n", grid.yinc);
+	      printf("grid.xinc   %f\n", grid->xinc);
+	      printf("grid.yinc   %f\n", grid->yinc);
 	      printf("grid.xinc   %f\n", gridInqXinc(gridID));
 	      printf("grid.yinc   %f\n", gridInqYinc(gridID));
 	      */
-	      if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) )
+	      if ( grid->xsize == gridInqXsize(gridID) && grid->ysize == gridInqYsize(gridID) )
 		{
-		  if ( grid.xdef == 2 && grid.ydef == 2 )
+		  if ( grid->xdef == 2 && grid->ydef == 2 )
 		    {
-		      if ( ! (IS_EQUAL(grid.xfirst, 0) && IS_EQUAL(grid.xlast, 0) && IS_EQUAL(grid.xinc, 0)) &&
-			   ! (IS_EQUAL(grid.yfirst, 0) && IS_EQUAL(grid.ylast, 0) && IS_EQUAL(grid.yinc, 0)) &&
-			   IS_NOT_EQUAL(grid.xfirst, grid.xlast) && IS_NOT_EQUAL(grid.yfirst, grid.ylast) )
+		      if ( ! (IS_EQUAL(grid->xfirst, 0) && IS_EQUAL(grid->xlast, 0) && IS_EQUAL(grid->xinc, 0)) &&
+			   ! (IS_EQUAL(grid->yfirst, 0) && IS_EQUAL(grid->ylast, 0) && IS_EQUAL(grid->yinc, 0)) &&
+			   IS_NOT_EQUAL(grid->xfirst, grid->xlast) && IS_NOT_EQUAL(grid->yfirst, grid->ylast) )
 			{
-			  if ( IS_NOT_EQUAL(grid.xfirst, gridInqXval(gridID, 0)) ||
-			       IS_NOT_EQUAL(grid.yfirst, gridInqYval(gridID, 0)))
+			  if ( IS_NOT_EQUAL(grid->xfirst, gridInqXval(gridID, 0)) ||
+			       IS_NOT_EQUAL(grid->yfirst, gridInqYval(gridID, 0)))
 			    {
 			      differ = 1;
 			    }
-			  if ( !differ && fabs(grid.xinc) > 0 &&
-			       fabs(fabs(grid.xinc) - fabs(gridInqXinc(gridID))) > fabs(grid.xinc/1000))
+			  if ( !differ && fabs(grid->xinc) > 0 &&
+			       fabs(fabs(grid->xinc) - fabs(gridInqXinc(gridID))) > fabs(grid->xinc/1000))
 			    {
 			      differ = 1;
 			    }
-			  if ( !differ && fabs(grid.yinc) > 0 &&
-			       fabs(fabs(grid.yinc) - fabs(gridInqYinc(gridID))) > fabs(grid.yinc/1000))
+			  if ( !differ && fabs(grid->yinc) > 0 &&
+			       fabs(fabs(grid->yinc) - fabs(gridInqYinc(gridID))) > fabs(grid->yinc/1000))
 			    {
 			      differ = 1;
 			    }
@@ -2230,95 +2109,91 @@ int gridCompare(int gridID, grid_t grid)
 		    }
 		  else
 		    {
-		      if ( grid.xvals && grid.yvals )
-			differ = compareXYvals(gridID, grid.xsize, grid.ysize, grid.xvals, grid.yvals);
+		      if ( grid->xvals && grid->yvals )
+			differ = compareXYvals(gridID, grid->xsize, grid->ysize, grid->xvals, grid->yvals);
 		    }
 		}
 	      else
 		differ = 1;
 	    }
-	  else if ( grid.type == GRID_GENERIC )
+	  else if ( grid->type == GRID_GENERIC )
 	    {
-	      if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) )
+	      if ( grid->xsize == gridInqXsize(gridID) && grid->ysize == gridInqYsize(gridID) )
 		{
-		  if ( grid.xdef == 1 && grid.ydef == 1 )
+		  if ( grid->xdef == 1 && grid->ydef == 1 )
 		    {
-		      if ( grid.xvals && grid.yvals )
-			differ = compareXYvals(gridID, grid.xsize, grid.ysize, grid.xvals, grid.yvals);
+		      if ( grid->xvals && grid->yvals )
+			differ = compareXYvals(gridID, grid->xsize, grid->ysize, grid->xvals, grid->yvals);
 		    }
 		}
-	      else if ( (grid.ysize == 0 || grid.ysize == 1) &&
-			grid.xsize == gridInqXsize(gridID)*gridInqYsize(gridID) )
+	      else if ( (grid->ysize == 0 || grid->ysize == 1) &&
+			grid->xsize == gridInqXsize(gridID)*gridInqYsize(gridID) )
 		{
 		}
 	      else
 		differ = 1;
 	    }
-	  else if ( grid.type == GRID_GAUSSIAN )
+	  else if ( grid->type == GRID_GAUSSIAN )
 	    {
-	      if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) )
+	      if ( grid->xsize == gridInqXsize(gridID) && grid->ysize == gridInqYsize(gridID) )
 		{
-		  if ( grid.xdef == 2 && grid.ydef == 2 )
+		  if ( grid->xdef == 2 && grid->ydef == 2 )
 		    {
-		      if ( ! (IS_EQUAL(grid.xfirst, 0) && IS_EQUAL(grid.xlast, 0) && IS_EQUAL(grid.xinc, 0)) &&
-			   ! (IS_EQUAL(grid.yfirst, 0) && IS_EQUAL(grid.ylast, 0)) )
-			if ( fabs(grid.xfirst - gridInqXval(gridID, 0)) > 0.0015 ||
-			     fabs(grid.yfirst - gridInqYval(gridID, 0)) > 0.0015 ||
-			     (fabs(grid.xinc)>0 && fabs(fabs(grid.xinc) - fabs(gridInqXinc(gridID))) > fabs(grid.xinc/1000)) )
+		      if ( ! (IS_EQUAL(grid->xfirst, 0) && IS_EQUAL(grid->xlast, 0) && IS_EQUAL(grid->xinc, 0)) &&
+			   ! (IS_EQUAL(grid->yfirst, 0) && IS_EQUAL(grid->ylast, 0)) )
+			if ( fabs(grid->xfirst - gridInqXval(gridID, 0)) > 0.0015 ||
+			     fabs(grid->yfirst - gridInqYval(gridID, 0)) > 0.0015 ||
+			     (fabs(grid->xinc)>0 && fabs(fabs(grid->xinc) - fabs(gridInqXinc(gridID))) > fabs(grid->xinc/1000)) )
 			  {
 			    differ = 1;
 			  }
 		    }
 		  else
 		    {
-		      if ( grid.xvals && grid.yvals )
-			differ = compareXYvals(gridID, grid.xsize, grid.ysize, grid.xvals, grid.yvals);
+		      if ( grid->xvals && grid->yvals )
+			differ = compareXYvals(gridID, grid->xsize, grid->ysize, grid->xvals, grid->yvals);
 		    }
 		}
 	      else
 		differ = 1;
 	    }
-	  else if ( grid.type == GRID_CURVILINEAR )
+	  else if ( grid->type == GRID_CURVILINEAR )
 	    {
 	      /*
 	      printf("gridID      %d\n", gridID);
-	      printf("grid.xsize  %d\n", grid.xsize);
-	      printf("grid.ysize  %d\n", grid.ysize);
-	      printf("grid.xfirst %f\n", grid.xvals[0]);
-	      printf("grid.yfirst %f\n", grid.yvals[0]);
+	      printf("grid.xsize  %d\n", grid->xsize);
+	      printf("grid.ysize  %d\n", grid->ysize);
+	      printf("grid.xfirst %f\n", grid->xvals[0]);
+	      printf("grid.yfirst %f\n", grid->yvals[0]);
 	      printf("grid xfirst %f\n", gridInqXval(gridID, 0));
 	      printf("grid yfirst %f\n", gridInqYval(gridID, 0));
-	      printf("grid.xlast  %f\n", grid.xvals[grid.size-1]);
-	      printf("grid.ylast  %f\n", grid.yvals[grid.size-1]);
-	      printf("grid xlast  %f\n", gridInqXval(gridID, grid.size-1));
-	      printf("grid ylast  %f\n", gridInqYval(gridID, grid.size-1));
-	      printf("grid.nv     %d\n", grid.nvertex);
+	      printf("grid.xlast  %f\n", grid->xvals[grid->size-1]);
+	      printf("grid.ylast  %f\n", grid->yvals[grid->size-1]);
+	      printf("grid xlast  %f\n", gridInqXval(gridID, grid->size-1));
+	      printf("grid ylast  %f\n", gridInqYval(gridID, grid->size-1));
+	      printf("grid.nv     %d\n", grid->nvertex);
 	      printf("grid nv     %d\n", gridInqNvertex(gridID));
 	      */
-	      if ( grid.xsize == gridInqXsize(gridID) && grid.ysize == gridInqYsize(gridID) )
-		differ = compareXYvals2(gridID, grid.size, grid.xvals, grid.yvals);
+	      if ( grid->xsize == gridInqXsize(gridID) && grid->ysize == gridInqYsize(gridID) )
+		differ = compareXYvals2(gridID, grid->size, grid->xvals, grid->yvals);
 	    }
-	  else if ( grid.type == GRID_UNSTRUCTURED )
+	  else if ( grid->type == GRID_UNSTRUCTURED )
 	    {
-              char uuidOfHGrid[17];
+              unsigned char uuidOfHGrid[CDI_UUID_SIZE];
               gridInqUUID(gridID, uuidOfHGrid);
-              /*
-              printf("compare unstructured grids\n");
-	      printf("gridID        %d\n", gridID);
-	      printf("gridsize      %d\n", grid.size);
-              if ( uuidOfHGrid[0] != 0 && grid.uuid[0] != 0 && memcmp(grid.uuid, uuidOfHGrid, 16) )
-                printf("uuidOfHGrid     differ\n");
-              printf("nvertex      %d  %d\n", grid.nvertex, gridInqNvertex(gridID));
-              printf("number       %d  %d\n", grid.number, gridInqNumber(gridID));
-              printf("position     %d  %d\n", grid.position, gridInqPosition(gridID));
-              */
-              if ( uuidOfHGrid[0] != 0 && grid.uuid[0] != 0 )
-                if ( !differ && memcmp(uuidOfHGrid, grid.uuid, 16) != 0 ) differ = 1;
-              if ( !differ && grid.nvertex != gridInqNvertex(gridID) ) differ = 1;
-              if ( !differ && grid.number != gridInqNumber(gridID) ) differ = 1;
-              if ( !differ && grid.number > 0 && grid.position != gridInqPosition(gridID) ) differ = 1;
+
+              if ( !differ && memcmp(uuidOfHGrid, grid->uuid, CDI_UUID_SIZE) != 0 ) differ = 1;
+
+              if ( !differ && grid->nvertex != gridInqNvertex(gridID) ) differ = 1;
+
+              if ( !differ && grid->number != gridInqNumber(gridID) ) differ = 1;
+              if ( !differ && grid->position != gridInqPosition(gridID) ) differ = 1;
+
+              if ( !differ && grid->nvertex != gridInqNvertex(gridID) ) differ = 1;
+              if ( !differ && grid->number != gridInqNumber(gridID) ) differ = 1;
+              if ( !differ && grid->number > 0 && grid->position != gridInqPosition(gridID) ) differ = 1;
 	      if ( !differ )
-		differ = compareXYvals2(gridID, grid.size, grid.xvals, grid.yvals);
+		differ = compareXYvals2(gridID, grid->size, grid->xvals, grid->yvals);
 	    }
 	}
     }
@@ -2510,21 +2385,22 @@ int gridCompareP ( void * gridptr1, void * gridptr2 )
   else if ( g2->mask_gme )
     return differ;
 
+  if (memcmp(g1->uuid, g2->uuid, CDI_UUID_SIZE))
+    return differ;
+
   return equal;
 }
 
 
-int gridGenerate(grid_t grid)
+int gridGenerate(const grid_t *grid)
 {
-  int gridID = gridCreate(grid.type, grid.size);
-
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
+  int gridID = gridCreate(grid->type, grid->size);
 
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
-  gridDefPrec(gridID, grid.prec);
+  gridDefPrec(gridID, grid->prec);
 
-  switch (grid.type)
+  switch (grid->type)
     {
     case GRID_LONLAT:
     case GRID_GAUSSIAN:
@@ -2537,51 +2413,51 @@ int gridGenerate(grid_t grid)
     case GRID_LAEA:
     case GRID_PROJECTION:
       {
-	if ( grid.xsize > 0 ) gridDefXsize(gridID, grid.xsize);
-	if ( grid.ysize > 0 ) gridDefYsize(gridID, grid.ysize);
+	if ( grid->xsize > 0 ) gridDefXsize(gridID, grid->xsize);
+	if ( grid->ysize > 0 ) gridDefYsize(gridID, grid->ysize);
 
-        if ( grid.type == GRID_GAUSSIAN ) gridDefNP(gridID, grid.np);
+        if ( grid->type == GRID_GAUSSIAN ) gridDefNP(gridID, grid->np);
 
-	if ( grid.nvertex > 0 )
-	  gridDefNvertex(gridID, grid.nvertex);
+	if ( grid->nvertex > 0 )
+	  gridDefNvertex(gridID, grid->nvertex);
 
-	if ( grid.xdef == 1 )
+	if ( grid->xdef == 1 )
 	  {
-	    gridDefXvals(gridID, grid.xvals);
-	    if ( grid.xbounds )
-	      gridDefXbounds(gridID, grid.xbounds);
+	    gridDefXvals(gridID, grid->xvals);
+	    if ( grid->xbounds )
+	      gridDefXbounds(gridID, grid->xbounds);
 	  }
-	else if ( grid.xdef == 2 )
+	else if ( grid->xdef == 2 )
 	  {
 	    double *xvals
-              = (double *)xmalloc((size_t)grid.xsize * sizeof (double));
-	    gridGenXvals(grid.xsize, grid.xfirst, grid.xlast, grid.xinc, xvals);
+              = (double *)xmalloc((size_t)grid->xsize * sizeof (double));
+	    gridGenXvals(grid->xsize, grid->xfirst, grid->xlast, grid->xinc, xvals);
 	    gridDefXvals(gridID, xvals);
 	    free(xvals);
 	    /*
-	    gridDefXinc(gridID, grid.xinc);
+	    gridDefXinc(gridID, grid->xinc);
 	    */
 	  }
 
-	if ( grid.ydef == 1 )
+	if ( grid->ydef == 1 )
 	  {
-	    gridDefYvals(gridID, grid.yvals);
-	    if ( grid.ybounds && grid.nvertex )
-	      gridDefYbounds(gridID, grid.ybounds);
+	    gridDefYvals(gridID, grid->yvals);
+	    if ( grid->ybounds && grid->nvertex )
+	      gridDefYbounds(gridID, grid->ybounds);
 	  }
-	else if ( grid.ydef == 2 )
+	else if ( grid->ydef == 2 )
 	  {
 	    double *yvals
-              = (double *)xmalloc((size_t)grid.ysize * sizeof (double));
-	    gridGenYvals(grid.type, grid.ysize, grid.yfirst, grid.ylast, grid.yinc, yvals);
+              = (double *)xmalloc((size_t)grid->ysize * sizeof (double));
+	    gridGenYvals(grid->type, grid->ysize, grid->yfirst, grid->ylast, grid->yinc, yvals);
 	    gridDefYvals(gridID, yvals);
 	    free(yvals);
 	    /*
-	    gridDefYinc(gridID, grid.yinc);
+	    gridDefYinc(gridID, grid->yinc);
 	    */
 	  }
 
-	if ( grid.isRotated )
+	if ( grid->isRotated )
 	  {
 	    gridDefXname(gridID, "rlon");
 	    gridDefYname(gridID, "rlat");
@@ -2592,109 +2468,109 @@ int gridGenerate(grid_t grid)
 	    gridDefXunits(gridID, "degrees");
 	    gridDefYunits(gridID, "degrees");
 
-	    gridDefXpole(gridID, grid.xpole);
-	    gridDefYpole(gridID, grid.ypole);
-	    gridDefAngle(gridID, grid.angle);
+	    gridDefXpole(gridID, grid->xpole);
+	    gridDefYpole(gridID, grid->ypole);
+	    gridDefAngle(gridID, grid->angle);
 	  }
 
-	if ( grid.area )
+	if ( grid->area )
 	  {
-	    gridDefArea(gridID, grid.area);
+	    gridDefArea(gridID, grid->area);
 	  }
 
-	if ( grid.type == GRID_LAEA )
-	  gridDefLaea(gridID, grid.laea_a, grid.laea_lon_0, grid.laea_lat_0);
+	if ( grid->type == GRID_LAEA )
+	  gridDefLaea(gridID, grid->laea_a, grid->laea_lon_0, grid->laea_lat_0);
 
-	if ( grid.type == GRID_LCC2 )
-	  gridDefLcc2(gridID, grid.lcc2_a, grid.lcc2_lon_0, grid.lcc2_lat_0, grid.lcc2_lat_1, grid.lcc2_lat_2);
+	if ( grid->type == GRID_LCC2 )
+	  gridDefLcc2(gridID, grid->lcc2_a, grid->lcc2_lon_0, grid->lcc2_lat_0, grid->lcc2_lat_1, grid->lcc2_lat_2);
 
-	if ( grid.type == GRID_LCC )
-	  gridDefLCC(gridID, grid.lcc_originLon, grid.lcc_originLat, grid.lcc_lonParY,
-		     grid.lcc_lat1, grid.lcc_lat2, grid.lcc_xinc, grid.lcc_yinc,
-		     grid.lcc_projflag, grid.lcc_scanflag);
+	if ( grid->type == GRID_LCC )
+	  gridDefLCC(gridID, grid->lcc_originLon, grid->lcc_originLat, grid->lcc_lonParY,
+		     grid->lcc_lat1, grid->lcc_lat2, grid->lcc_xinc, grid->lcc_yinc,
+		     grid->lcc_projflag, grid->lcc_scanflag);
 
-	if ( grid.type == GRID_UNSTRUCTURED )
+	if ( grid->type == GRID_UNSTRUCTURED )
           {
-            int number = grid.number;
-            int position = grid.position;
+            int number = grid->number;
+            int position = grid->position;
             if ( position < 0 ) position = 0;
             if ( number > 0 )
               {
                 gridDefNumber(gridID, number);
                 gridDefPosition(gridID, position);
               }
-            if ( grid.uuid[0] != 0 ) gridDefUUID(gridID, grid.uuid);
-            if ( grid.reference ) gridDefReference(gridID, grid.reference);
+            gridDefUUID(gridID, grid->uuid);
+            if ( grid->reference ) gridDefReference(gridID, grid->reference);
           }
 
-	if ( grid.type == GRID_PROJECTION )
+	if ( grid->type == GRID_PROJECTION )
 	  {
-	    gridptr->name = strdup(grid.name);
+	    gridptr->name = strdup(grid->name);
 	  }
 
 	break;
       }
     case GRID_GAUSSIAN_REDUCED:
       {
-	gridDefNP(gridID, grid.np);
-	gridDefYsize(gridID, grid.ysize);
-	gridDefRowlon(gridID, grid.ysize, grid.rowlon);
+	gridDefNP(gridID, grid->np);
+	gridDefYsize(gridID, grid->ysize);
+	gridDefRowlon(gridID, grid->ysize, grid->rowlon);
 
-        if ( grid.xdef == 2 )
+        if ( grid->xdef == 2 )
           {
             double xvals[2];
-            xvals[0] = grid.xfirst;
-            xvals[1] = grid.xlast;
+            xvals[0] = grid->xfirst;
+            xvals[1] = grid->xlast;
             gridDefXvals(gridID, xvals);
           }
 
-	if ( grid.ydef == 1 )
+	if ( grid->ydef == 1 )
 	  {
-	    gridDefYvals(gridID, grid.yvals);
-	    if ( grid.ybounds && grid.nvertex )
-	      gridDefYbounds(gridID, grid.ybounds);
+	    gridDefYvals(gridID, grid->yvals);
+	    if ( grid->ybounds && grid->nvertex )
+	      gridDefYbounds(gridID, grid->ybounds);
 	  }
-	else if ( grid.ydef == 2 )
+	else if ( grid->ydef == 2 )
 	  {
 	    double *yvals
-              = (double *)xmalloc((size_t)grid.ysize * sizeof (double));
-	    gridGenYvals(grid.type, grid.ysize, grid.yfirst, grid.ylast, grid.yinc, yvals);
+              = (double *)xmalloc((size_t)grid->ysize * sizeof (double));
+	    gridGenYvals(grid->type, grid->ysize, grid->yfirst, grid->ylast, grid->yinc, yvals);
 	    gridDefYvals(gridID, yvals);
 	    free(yvals);
 	    /*
-	    gridDefYinc(gridID, grid.yinc);
+	    gridDefYinc(gridID, grid->yinc);
 	    */
 	  }
 	break;
       }
     case GRID_SPECTRAL:
       {
-        gridDefTrunc(gridID, grid.trunc);
-        if ( grid.lcomplex ) gridDefComplexPacking(gridID, 1);
+        gridDefTrunc(gridID, grid->trunc);
+        if ( grid->lcomplex ) gridDefComplexPacking(gridID, 1);
         break;
       }
     case GRID_FOURIER:
       {
-	gridDefTrunc(gridID, grid.trunc);
+	gridDefTrunc(gridID, grid->trunc);
 	break;
       }
     case GRID_GME:
       {
-        gridDefGMEnd(gridID, grid.nd);
-        gridDefGMEni(gridID, grid.ni);
-        gridDefGMEni2(gridID, grid.ni2);
-        gridDefGMEni3(gridID, grid.ni3);
+        gridDefGMEnd(gridID, grid->nd);
+        gridDefGMEni(gridID, grid->ni);
+        gridDefGMEni2(gridID, grid->ni2);
+        gridDefGMEni3(gridID, grid->ni3);
         break;
       }
       /*
     case GRID_GENERIC:
       {
-        if ( grid.xsize > 0 && grid.ysize > 0 )
+        if ( grid->xsize > 0 && grid->ysize > 0 )
           {
-            gridDefXsize(gridID, grid.xsize);
-            gridDefYsize(gridID, grid.ysize);
-            if ( grid.xvals ) gridDefXvals(gridID, grid.xvals);
-            if ( grid.yvals ) gridDefYvals(gridID, grid.yvals);
+            gridDefXsize(gridID, grid->xsize);
+            gridDefYsize(gridID, grid->ysize);
+            if ( grid->xvals ) gridDefXvals(gridID, grid->xvals);
+            if ( grid->yvals ) gridDefYvals(gridID, grid->yvals);
           }
         break;
       }
@@ -2707,17 +2583,17 @@ int gridGenerate(grid_t grid)
       }
     default:
       {
-	Error("Gridtype %s unsupported!", gridNamePtr(grid.type));
+	Error("Gridtype %s unsupported!", gridNamePtr(grid->type));
 	break;
       }
     }
 
-  if ( grid.xname[0]     ) gridDefXname(gridID, grid.xname);
-  if ( grid.xlongname[0] ) gridDefXlongname(gridID, grid.xlongname);
-  if ( grid.xunits[0]    ) gridDefXunits(gridID, grid.xunits);
-  if ( grid.yname[0]     ) gridDefYname(gridID, grid.yname);
-  if ( grid.ylongname[0] ) gridDefYlongname(gridID, grid.ylongname);
-  if ( grid.yunits[0]    ) gridDefYunits(gridID, grid.yunits);
+  if ( grid->xname[0]     ) gridDefXname(gridID, grid->xname);
+  if ( grid->xlongname[0] ) gridDefXlongname(gridID, grid->xlongname);
+  if ( grid->xunits[0]    ) gridDefXunits(gridID, grid->xunits);
+  if ( grid->yname[0]     ) gridDefYname(gridID, grid->yname);
+  if ( grid->ylongname[0] ) gridDefYlongname(gridID, grid->ylongname);
+  if ( grid->yunits[0]    ) gridDefYunits(gridID, grid->yunits);
 
   return (gridID);
 }
@@ -2742,8 +2618,6 @@ int gridDuplicate(int gridID)
 {
   grid_t *gridptr = reshGetVal(gridID, &gridOps);
 
-  grid_check_ptr(gridID, gridptr);
-
   int gridtype = gridInqType(gridID);
   int gridsize = gridInqSize(gridID);
 
@@ -2836,9 +2710,7 @@ int gridDuplicate(int gridID)
 
 void gridCompress(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int gridtype = gridInqType(gridID);
   if ( gridtype == GRID_UNSTRUCTURED )
@@ -2906,9 +2778,7 @@ void gridCompress(int gridID)
 
 void gridDefArea(int gridID, const double *area)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t size = gridptr->size;
 
@@ -2927,9 +2797,7 @@ void gridDefArea(int gridID, const double *area)
 
 void gridInqArea(int gridID, double *area)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->area)
     memcpy(area, gridptr->area, (size_t)gridptr->size * sizeof (double));
@@ -2938,9 +2806,7 @@ void gridInqArea(int gridID, double *area)
 
 int gridHasArea(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   int hasArea = (gridptr->area != NULL);
 
@@ -2950,9 +2816,7 @@ int gridHasArea(int gridID)
 
 const double *gridInqAreaPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->area);
 }
@@ -2960,9 +2824,7 @@ const double *gridInqAreaPtr(int gridID)
 
 void gridDefNvertex(int gridID, int nvertex)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->nvertex != nvertex)
     {
@@ -2974,9 +2836,7 @@ void gridDefNvertex(int gridID, int nvertex)
 
 int gridInqNvertex(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->nvertex);
 }
@@ -2997,9 +2857,7 @@ The function @func{gridDefXbounds} defines all bounds of the X-axis.
 */
 void gridDefXbounds(int gridID, const double *xbounds)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t nvertex = (size_t)gridptr->nvertex;
   if ( nvertex == 0 )
@@ -3046,21 +2904,14 @@ Otherwise, 0 is returned and @func{xbounds} is empty.
 */
 int gridInqXbounds(int gridID, double *xbounds)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t nvertex = (size_t)gridptr->nvertex;
-  if ( CDI_Debug && nvertex == 0 )
-    Warning("nvertex undefined for gridID = %d", gridID);
 
   int irregular = gridptr->type == GRID_CURVILINEAR
     || gridptr->type == GRID_UNSTRUCTURED;
   size_t size = nvertex * (size_t)(irregular ? gridptr->size : gridptr->xsize);
 
-  if ( CDI_Debug && size == 0 )
-    Warning("size undefined for gridID = %d", gridID);
-
   if ( size && xbounds && gridptr->xbounds )
     memcpy(xbounds, gridptr->xbounds, size * sizeof (double));
 
@@ -3072,9 +2923,7 @@ int gridInqXbounds(int gridID, double *xbounds)
 
 const double *gridInqXboundsPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->xbounds);
 }
@@ -3095,9 +2944,7 @@ The function @func{gridDefYbounds} defines all bounds of the Y-axis.
 */
 void gridDefYbounds(int gridID, const double *ybounds)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t nvertex = (size_t)gridptr->nvertex;
   if ( nvertex == 0 )
@@ -3144,21 +2991,14 @@ Otherwise, 0 is returned and @func{ybounds} is empty.
 */
 int gridInqYbounds(int gridID, double *ybounds)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   size_t nvertex = (size_t)gridptr->nvertex;
-  if ( CDI_Debug && nvertex == 0 )
-    Warning("nvertex undefined for gridID = %d", gridID);
 
   int irregular = gridptr->type == GRID_CURVILINEAR
     || gridptr->type == GRID_UNSTRUCTURED;
   size_t size = nvertex * (size_t)(irregular ? gridptr->size : gridptr->ysize);
 
-  if ( CDI_Debug && size == 0 )
-    Warning("size undefined for gridID = %d", gridID);
-
   if ( size && ybounds && gridptr->ybounds )
     memcpy(ybounds, gridptr->ybounds, size * sizeof (double));
 
@@ -3170,9 +3010,7 @@ int gridInqYbounds(int gridID, double *ybounds)
 
 const double *gridInqYboundsPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->ybounds);
 }
@@ -3186,7 +3024,7 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp)
   int nbyte0, nbyte;
   int i;
   int nvertex, iv;
-  char uuidOfHGrid[17];
+  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
   int gridID = gridptr->self;
   const double *area    = gridInqAreaPtr(gridID);
   const double *xvals   = gridInqXvalsPtr(gridID);
@@ -3194,8 +3032,6 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp)
   const double *xbounds = gridInqXboundsPtr(gridID);
   const double *ybounds = gridInqYboundsPtr(gridID);
 
-  grid_check_ptr(gridID, gridptr);
-
   type     = gridInqType(gridID);
   trunc    = gridInqTrunc(gridID);
   gridsize = gridInqSize(gridID);
@@ -3498,7 +3334,7 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp)
     }
 
   gridInqUUID(gridID, uuidOfHGrid);
-  if ( uuidOfHGrid[0] != 0 )
+  if ( !cdiUUIDIsNull(uuidOfHGrid) )
     {
       char uuidOfHGridStr[37];
       uuid2str(uuidOfHGrid, uuidOfHGridStr);
@@ -3526,9 +3362,7 @@ void gridPrintKernel(grid_t * gridptr, int opt, FILE *fp)
 
 void gridPrint ( int gridID, int opt )
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   gridPrintKernel ( gridptr, opt, stdout );
 }
@@ -3593,9 +3427,7 @@ void gridPrintP ( void * voidptr, FILE * fp )
 
 const double *gridInqXvalsPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return ( gridptr->xvals );
 }
@@ -3603,9 +3435,7 @@ const double *gridInqXvalsPtr(int gridID)
 
 const double *gridInqYvalsPtr(int gridID)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return ( gridptr->yvals );
 }
@@ -3636,9 +3466,7 @@ void gridDefLCC(int gridID, double originLon, double originLat, double lonParY,
                 double lat1, double lat2, double xinc, double yinc,
                 int projflag, int scanflag)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LCC )
     Warning("Definition of LCC grid for %s grid not allowed!",
@@ -3685,9 +3513,7 @@ void gridInqLCC(int gridID, double *originLon, double *originLat, double *lonPar
                 double *lat1, double *lat2, double *xinc, double *yinc,
                 int *projflag, int *scanflag)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LCC )
     Warning("Inquire of LCC grid definition for %s grid not allowed!",
@@ -3713,9 +3539,7 @@ void gridInqLCC(int gridID, double *originLon, double *originLat, double *lonPar
 
 void gridDefLcc2(int gridID, double earth_radius, double lon_0, double lat_0, double lat_1, double lat_2)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LCC2 )
     Warning("Definition of LCC2 grid for %s grid not allowed!",
@@ -3735,9 +3559,7 @@ void gridDefLcc2(int gridID, double earth_radius, double lon_0, double lat_0, do
 
 void gridInqLcc2(int gridID, double *earth_radius, double *lon_0, double *lat_0, double *lat_1, double *lat_2)
 {
-  grid_t *gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LCC2 )
     Warning("Inquire of LCC2 grid definition for %s grid not allowed!",
@@ -3759,9 +3581,7 @@ void gridInqLcc2(int gridID, double *earth_radius, double *lon_0, double *lat_0,
 
 void gridDefLaea(int gridID, double earth_radius, double lon_0, double lat_0)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LAEA )
     Warning("Definition of LAEA grid for %s grid not allowed!",
@@ -3779,9 +3599,7 @@ void gridDefLaea(int gridID, double earth_radius, double lon_0, double lat_0)
 
 void gridInqLaea(int gridID, double *earth_radius, double *lon_0, double *lat_0)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   if ( gridptr->type != GRID_LAEA )
     Warning("Inquire of LAEA grid definition for %s grid not allowed!",
@@ -3802,9 +3620,7 @@ void gridInqLaea(int gridID, double *earth_radius, double *lon_0, double *lat_0)
 
 void gridDefComplexPacking(int gridID, int lcomplex)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
 
   if (gridptr->lcomplex != lcomplex)
@@ -3817,9 +3633,7 @@ void gridDefComplexPacking(int gridID, int lcomplex)
 
 int gridInqComplexPacking(int gridID)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   return (gridptr->lcomplex);
 }
@@ -3827,9 +3641,7 @@ int gridInqComplexPacking(int gridID)
 
 void gridDefHasDims(int gridID, int hasdims)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   if (gridptr->hasdims != hasdims)
     {
@@ -3841,9 +3653,7 @@ void gridDefHasDims(int gridID, int hasdims)
 
 int gridInqHasDims(int gridID)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   return (gridptr->hasdims);
 }
@@ -3864,9 +3674,7 @@ The function @func{gridDefNumber} defines the reference number for an unstructur
 */
 void gridDefNumber(int gridID, const int number)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   if (gridptr->number != number)
     {
@@ -3892,9 +3700,7 @@ The function @func{gridInqNumber} returns the reference number to an unstructure
 */
 int gridInqNumber(int gridID)
 {
-  grid_t* gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   return (gridptr->number);
 }
@@ -3915,9 +3721,7 @@ The function @func{gridDefPosition} defines the position of grid in the referenc
 */
 void gridDefPosition(int gridID, int position)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   if (gridptr->position != position)
     {
@@ -3943,9 +3747,7 @@ The function @func{gridInqPosition} returns the position of grid in the referenc
 */
 int gridInqPosition(int gridID)
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
   return (gridptr->position);
 }
@@ -3966,9 +3768,7 @@ The function @func{gridDefReference} defines the reference URI for an unstructur
 */
 void gridDefReference(int gridID, const char *reference)
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
   if ( reference )
     {
@@ -4001,16 +3801,11 @@ The function @func{gridInqReference} returns the reference URI to an unstructure
 int gridInqReference(int gridID, char *reference)
 {
   int len = 0;
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
+  grid_t* gridptr = gridID2Ptr(gridID);
 
-  grid_check_ptr(gridID, gridptr);
-
-  if ( gridptr->reference )
+  if ( gridptr->reference && reference )
     {
-      len = (int) strlen(gridptr->reference);
-
-      if ( reference )
-        strcpy(reference, gridptr->reference);
+      strcpy(reference, gridptr->reference);
     }
 
   return (len);
@@ -4030,13 +3825,11 @@ The function @func{gridDefUUID} defines the UUID for an unstructured grid.
 
 @EndFunction
 */
-void gridDefUUID(int gridID, const char *uuid)
+void gridDefUUID(int gridID, const unsigned char uuid[CDI_UUID_SIZE])
 {
-  grid_t* gridptr = ( grid_t *) reshGetVal ( gridID, &gridOps );
-
-  grid_check_ptr(gridID, gridptr);
+  grid_t* gridptr = gridID2Ptr(gridID);
 
-  memcpy(gridptr->uuid, uuid, 16);
+  memcpy(gridptr->uuid, uuid, CDI_UUID_SIZE);
   reshSetStatus(gridID, &gridOps, RESH_DESYNC_IN_USE);
 }
 
@@ -4055,13 +3848,11 @@ The function @func{gridInqUUID} returns the UUID to an unstructured grid.
 @func{gridInqUUID} returns the UUID to an unstructured grid to the parameter uuid.
 @EndFunction
 */
-void gridInqUUID(int gridID, char *uuid)
+void gridInqUUID(int gridID, unsigned char uuid[CDI_UUID_SIZE])
 {
-  grid_t *gridptr = (grid_t *)reshGetVal(gridID, &gridOps);
+  grid_t *gridptr = gridID2Ptr(gridID);
 
-  grid_check_ptr(gridID, gridptr);
-
-  memcpy(uuid, gridptr->uuid, 16);
+  memcpy(uuid, gridptr->uuid, CDI_UUID_SIZE);
 }
 
 
@@ -4088,7 +3879,8 @@ enum { gridNint    = 27,
        gridHasXBoundsFlag = 1 << 5,
        gridHasYBoundsFlag = 1 << 6,
        gridHasReferenceFlag = 1 << 7,
-       gridHasRowLonFlag = 1 << 8
+       gridHasRowLonFlag = 1 << 8,
+       gridHasUUIDFlag = 1 << 9,
 };
 
 
@@ -4102,8 +3894,8 @@ static int gridGetComponentFlags(const grid_t * gridP)
     | (gridHasXBoundsFlag & (int)((unsigned)(gridP->xbounds == NULL) - 1U))
     | (gridHasYBoundsFlag & (int)((unsigned)(gridP->ybounds == NULL) - 1U))
     | (gridHasReferenceFlag & (int)((unsigned)(gridP->reference == NULL) - 1U))
-    | (gridHasRowLonFlag & (int)((unsigned)(gridP->rowlon == NULL) - 1U));
-
+    | (gridHasRowLonFlag & (int)((unsigned)(gridP->rowlon == NULL) - 1U))
+    | (gridHasUUIDFlag & (int)((unsigned)cdiUUIDIsNull(gridP->uuid) - 1U));
   return flags;
 }
 
@@ -4209,9 +4001,16 @@ gridGetPackSize(void * voidP, void *context)
         + serializeGetSize(1, DATATYPE_UINT32, context);
     }
 
+  if (!cdiUUIDIsNull(gridP->uuid))
+    packBuffSize += serializeGetSize(CDI_UUID_SIZE, DATATYPE_UCHAR, context);
+
   return packBuffSize;
 }
 
+#define GRID_STR_SERIALIZE { gridP->xname, gridP->yname, \
+    gridP->xlongname, gridP->ylongname, \
+    gridP->xstdname, gridP->ystdname, \
+    gridP->xunits, gridP->yunits }
 
 void
 gridUnpack(char * unpackBuffer, int unpackBufferSize,
@@ -4381,15 +4180,12 @@ gridUnpack(char * unpackBuffer, int unpackBufferSize,
                   &d, 1, DATATYPE_UINT32, context);
 
   xassert(d == cdiCheckSum(DATATYPE_TXT, gridNstrings * CDI_MAX_NAME, charBuffer));
-
-  memcpy ( gridP->xname    , &charBuffer[CDI_MAX_NAME * 0], CDI_MAX_NAME );
-  memcpy ( gridP->yname    , &charBuffer[CDI_MAX_NAME * 1], CDI_MAX_NAME );
-  memcpy ( gridP->xlongname, &charBuffer[CDI_MAX_NAME * 2], CDI_MAX_NAME );
-  memcpy ( gridP->ylongname, &charBuffer[CDI_MAX_NAME * 3], CDI_MAX_NAME );
-  memcpy ( gridP->xstdname , &charBuffer[CDI_MAX_NAME * 4], CDI_MAX_NAME );
-  memcpy ( gridP->ystdname , &charBuffer[CDI_MAX_NAME * 5], CDI_MAX_NAME );
-  memcpy ( gridP->xunits   , &charBuffer[CDI_MAX_NAME * 6], CDI_MAX_NAME );
-  memcpy ( gridP->yunits   , &charBuffer[CDI_MAX_NAME * 7], CDI_MAX_NAME );
+  {
+    char *strTab[] = GRID_STR_SERIALIZE;
+    size_t numStr = sizeof (strTab) / sizeof (strTab[0]);
+    for (size_t i = 0; i < numStr; ++i)
+      memcpy(strTab[i], charBuffer + CDI_MAX_NAME * i, CDI_MAX_NAME);
+  }
 
   if (memberMask & gridHasReferenceFlag)
     {
@@ -4425,6 +4221,11 @@ gridUnpack(char * unpackBuffer, int unpackBufferSize,
                       &d, 1, DATATYPE_UINT32, context);
       xassert(cdiCheckSum(DATATYPE_UCHAR, gridP->size, gridP->mask_gme) == d);
     }
+  if (memberMask & gridHasUUIDFlag)
+    {
+      serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
+                      gridP->uuid, CDI_UUID_SIZE, DATATYPE_UCHAR, context);
+    }
 }
 
 
@@ -4435,6 +4236,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
   grid_t   * gridP = ( grid_t * )   voidP;
   int size;
   uint32_t d;
+  int memberMask;
   char charBuffer[gridNstrings * CDI_MAX_NAME];
 
   {
@@ -4466,7 +4268,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
     intBuffer[23] = gridP->ysize;
     intBuffer[24] = gridP->locked;
     intBuffer[25] = gridP->lcomplex;
-    intBuffer[26] = gridGetComponentFlags(gridP);
+    intBuffer[26] = memberMask = gridGetComponentFlags(gridP);
 
     serializePack(intBuffer, gridNint, DATATYPE_INT,
                   packBuffer, packBufferSize, packBufferPos, context);
@@ -4475,7 +4277,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                   packBuffer, packBufferSize, packBufferPos, context);
   }
 
-  if (gridP->rowlon)
+  if (memberMask & gridHasRowLonFlag)
     {
       xassert((size = gridP->nrowlon));
       serializePack(gridP->rowlon, size, DATATYPE_INT,
@@ -4520,7 +4322,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                   packBuffer, packBufferSize, packBufferPos, context);
   }
 
-  if (gridP->xvals)
+  if (memberMask & gridHasXValsFlag)
     {
       if (gridP->type == GRID_UNSTRUCTURED || gridP->type == GRID_CURVILINEAR)
 	size = gridP->size;
@@ -4535,7 +4337,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->yvals)
+  if (memberMask & gridHasYValsFlag)
     {
       if (gridP->type == GRID_UNSTRUCTURED || gridP->type == GRID_CURVILINEAR )
 	size = gridP->size;
@@ -4549,7 +4351,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->area)
+  if (memberMask & gridHasAreaFlag)
     {
       xassert(gridP->size);
 
@@ -4560,7 +4362,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->xbounds)
+  if (memberMask & gridHasXBoundsFlag)
     {
       xassert ( gridP->nvertex );
       if (gridP->type == GRID_CURVILINEAR || gridP->type == GRID_UNSTRUCTURED)
@@ -4576,7 +4378,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->ybounds)
+  if (memberMask & gridHasYBoundsFlag)
     {
       xassert(gridP->nvertex);
       if (gridP->type == GRID_CURVILINEAR || gridP->type == GRID_UNSTRUCTURED)
@@ -4592,14 +4394,12 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  memcpy ( &charBuffer[CDI_MAX_NAME * 0], gridP->xname,     CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 1], gridP->yname,     CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 2], gridP->xlongname, CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 3], gridP->ylongname, CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 4], gridP->xstdname,  CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 5], gridP->ystdname,  CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 6], gridP->xunits,    CDI_MAX_NAME );
-  memcpy ( &charBuffer[CDI_MAX_NAME * 7], gridP->yunits,    CDI_MAX_NAME );
+  {
+    char *strTab[] = GRID_STR_SERIALIZE;
+    size_t numStr = sizeof (strTab) / sizeof (strTab[0]);
+    for (size_t i = 0; i < numStr; ++i)
+      memcpy(charBuffer + CDI_MAX_NAME * i, strTab[i], CDI_MAX_NAME);
+  }
 
   serializePack( charBuffer, gridNstrings * CDI_MAX_NAME, DATATYPE_TXT,
 		    packBuffer, packBufferSize, packBufferPos, context);
@@ -4607,7 +4407,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
   serializePack(&d, 1, DATATYPE_UINT32,
                 packBuffer, packBufferSize, packBufferPos, context);
 
-  if ( gridP->reference )
+  if (memberMask & gridHasReferenceFlag)
     {
       size = (int)strlen(gridP->reference) + 1;
       serializePack(&size, 1, DATATYPE_INT,
@@ -4619,7 +4419,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if ( gridP->mask )
+  if (memberMask & gridHasMaskFlag)
     {
       xassert((size = gridP->size));
       serializePack(gridP->mask, size, DATATYPE_UCHAR,
@@ -4629,7 +4429,7 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (gridP->mask_gme)
+  if (memberMask & gridHasGMEMaskFlag)
     {
       xassert((size = gridP->size));
 
@@ -4639,6 +4439,10 @@ gridPack(void * voidP, void * packBuffer, int packBufferSize,
       serializePack(&d, 1, DATATYPE_UINT32,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
+
+  if (memberMask & gridHasUUIDFlag)
+    serializePack(gridP->uuid, CDI_UUID_SIZE, DATATYPE_UCHAR,
+                  packBuffer, packBufferSize, packBufferPos, context);
 }
 
 /*
diff --git a/libcdi/src/grid.h b/libcdi/src/grid.h
index 70a31d8..b859434 100644
--- a/libcdi/src/grid.h
+++ b/libcdi/src/grid.h
@@ -1,6 +1,8 @@
 #ifndef _GRID_H
 #define _GRID_H
 
+#include "cdi.h"
+
 typedef unsigned char mask_t;
 
 typedef struct {
@@ -46,7 +48,7 @@ typedef struct {
   int     nd, ni, ni2, ni3;       /* parameter for GRID_GME         */
   int     number, position;       /* parameter for GRID_REFERENCE   */
   char   *reference;
-  char    uuid[17];               /* uuid for grid reference        */
+  unsigned char uuid[CDI_UUID_SIZE]; /* uuid for grid reference        */
   int     trunc;                  /* parameter for GRID_SPECTEAL    */
   int     nvertex;
   int    *rowlon;
@@ -83,8 +85,8 @@ const double *gridInqXboundsPtr(int gridID);
 const double *gridInqYboundsPtr(int gridID);
 const double *gridInqAreaPtr(int gridID);
 
-int gridCompare(int gridID, grid_t grid);
-int gridGenerate(grid_t grid);
+int gridCompare(int gridID, const grid_t *grid);
+int gridGenerate(const grid_t *grid);
 
 void gridGetIndexList( int, int * );
 
diff --git a/libcdi/src/ieg.h b/libcdi/src/ieg.h
index ccee9ac..a7e78af 100644
--- a/libcdi/src/ieg.h
+++ b/libcdi/src/ieg.h
@@ -51,6 +51,7 @@
 #define  IEG_G_ScanFlag(x)    (x[13])
 #define  IEG_G_LatSP(x)       (x[16])  /*  Latitude of the southern pole of rotation    */
 #define  IEG_G_LonSP(x)       (x[17])  /*  Longitude of the southern pole of rotation   */
+#define  IEG_G_ResFac(x)      (x[18])  /*  Resolution factor                            */
 
 
 typedef struct {
diff --git a/libcdi/src/ieglib.c b/libcdi/src/ieglib.c
index b99bd63..c542dbd 100644
--- a/libcdi/src/ieglib.c
+++ b/libcdi/src/ieglib.c
@@ -26,7 +26,7 @@ static int iegDefaultDprec = 0;
  */
 
 #undef  LIBVERSION
-#define LIBVERSION      1.3.2
+#define LIBVERSION      1.3.3
 #define XSTRING(x)	#x
 #define STRING(x)	XSTRING(x)
 static const char ieg_libvers[] = STRING(LIBVERSION) " of "__DATE__" "__TIME__;
diff --git a/libcdi/src/institution.c b/libcdi/src/institution.c
index 827811f..fcbef8d 100644
--- a/libcdi/src/institution.c
+++ b/libcdi/src/institution.c
@@ -227,7 +227,7 @@ int institutInqSubcenter(int instID)
 }
 
 
-char *institutInqNamePtr(int instID)
+const char *institutInqNamePtr(int instID)
 {
   institute_t * instituteptr = NULL;
 
@@ -251,6 +251,7 @@ char *institutInqLongnamePtr(int instID)
 static enum cdiApplyRet
 activeInstitutes(int id, void *res, void *data)
 {
+  (void)id;
   if (res && ((institute_t *)res)->used)
     ++(*(int *)data);
   return CDI_APPLY_GO_ON;
diff --git a/libcdi/src/mo_cdi.f90 b/libcdi/src/mo_cdi.f90
index b550921..dbd531d 100644
--- a/libcdi/src/mo_cdi.f90
+++ b/libcdi/src/mo_cdi.f90
@@ -165,6 +165,7 @@ module mo_cdi
       integer, parameter :: CALENDAR_365DAYS = 3
       integer, parameter :: CALENDAR_366DAYS = 4
       integer, parameter :: CALENDAR_NONE = 5
+      integer, parameter :: CDI_UUID_SIZE = 16
       interface
         function strlen(s) bind(c,name='strlen')
           import :: c_ptr,c_size_t
@@ -305,6 +306,14 @@ module mo_cdi
         end function cdiEncodeTime
       end interface
       interface
+        function cdiGetFiletype(path,byteorder) bind(c,name='cdiGetFiletype')
+          import :: c_char,c_int
+          character(kind=c_char), dimension(*) :: path
+          integer(kind=c_int), intent(out) :: byteorder
+          integer(kind=c_int) :: cdiGetFiletype
+        end function cdiGetFiletype
+      end interface
+      interface
         function streamOpenRead(path) bind(c,name='streamOpenRead')
           import :: c_char,c_int
           character(kind=c_char), dimension(*) :: path
@@ -432,13 +441,6 @@ module mo_cdi
         end function streamInqCurTimestepID
       end interface
       interface
-        function streamNtsteps(streamID) bind(c,name='streamNtsteps')
-          import :: c_int
-          integer(kind=c_int), value :: streamID
-          integer(kind=c_int) :: streamNtsteps
-        end function streamNtsteps
-      end interface
-      interface
         function streamInqNvars(streamID) bind(c,name='streamInqNvars')
           import :: c_int
           integer(kind=c_int), value :: streamID
@@ -1962,17 +1964,17 @@ module mo_cdi
         end function gridInqReference
       end interface
       interface
-        subroutine gridDefUUID(gridID,uuid_cbuf) bind(c,name='gridDefUUID')
+        subroutine gridDefUUID(gridID,uuid) bind(c,name='gridDefUUID')
           import :: c_int,c_char
           integer(kind=c_int), value :: gridID
-          character(kind=c_char), dimension(*) :: uuid_cbuf
+          character(kind=c_char), dimension(16) :: uuid
         end subroutine gridDefUUID
       end interface
       interface
-        subroutine gridInqUUID(gridID,uuid_cbuf) bind(c,name='gridInqUUID')
+        subroutine gridInqUUID(gridID,uuid) bind(c,name='gridInqUUID')
           import :: c_int,c_char
           integer(kind=c_int), value :: gridID
-          character(kind=c_char), dimension(*) :: uuid_cbuf
+          character(kind=c_char), dimension(16) :: uuid
         end subroutine gridInqUUID
       end interface
       interface
@@ -2260,17 +2262,17 @@ module mo_cdi
         end function zaxisInqNumber
       end interface
       interface
-        subroutine zaxisDefUUID(zaxisID,uuid_cbuf) bind(c,name='zaxisDefUUID')
+        subroutine zaxisDefUUID(zaxisID,uuid) bind(c,name='zaxisDefUUID')
           import :: c_int,c_char
           integer(kind=c_int), value :: zaxisID
-          character(kind=c_char), dimension(*) :: uuid_cbuf
+          character(kind=c_char), dimension(16) :: uuid
         end subroutine zaxisDefUUID
       end interface
       interface
-        subroutine zaxisInqUUID(zaxisID,uuid_cbuf) bind(c,name='zaxisInqUUID')
+        subroutine zaxisInqUUID(zaxisID,uuid) bind(c,name='zaxisInqUUID')
           import :: c_int,c_char
           integer(kind=c_int), value :: zaxisID
-          character(kind=c_char), dimension(*) :: uuid_cbuf
+          character(kind=c_char), dimension(16) :: uuid
         end subroutine zaxisInqUUID
       end interface
       interface
@@ -2948,6 +2950,7 @@ module mo_cdi
       public :: cdiEncodeDate
       public :: cdiDecodeTime
       public :: cdiEncodeTime
+      public :: cdiGetFiletype
       public :: streamOpenRead
       public :: streamOpenWrite
       public :: streamOpenAppend
@@ -2968,7 +2971,6 @@ module mo_cdi
       public :: streamInqCurTimestepID
       public :: streamFilename
       public :: streamFilesuffix
-      public :: streamNtsteps
       public :: streamInqNvars
       public :: streamWriteVar
       public :: streamWriteVarF
@@ -3463,6 +3465,7 @@ module mo_cdi
       public :: CALENDAR_365DAYS
       public :: CALENDAR_366DAYS
       public :: CALENDAR_NONE
+      public :: CDI_UUID_SIZE
 
 contains
       function cdiStringError(cdiErrno)
@@ -3708,9 +3711,9 @@ contains
       end function tableInqParUnitsPtr
 
     subroutine ctrim(str)
-    character(kind=c_char) :: str(:)
+    character(kind=c_char), intent(inout) :: str(:)
     character(kind=c_char) :: c
-    integer                        :: i
+    integer :: i
 
     do i=1,size(str)
       c = str(i)
diff --git a/libcdi/src/model.c b/libcdi/src/model.c
index 0fbb7a0..b14181e 100644
--- a/libcdi/src/model.c
+++ b/libcdi/src/model.c
@@ -237,7 +237,7 @@ int modelInqGribID(int modelID)
 }
 
 
-char *modelInqNamePtr(int modelID)
+const char *modelInqNamePtr(int modelID)
 {
   model_t *modelptr = NULL;
 
diff --git a/libcdi/src/pio.c b/libcdi/src/pio.c
index 92e65fb..4345514 100644
--- a/libcdi/src/pio.c
+++ b/libcdi/src/pio.c
@@ -43,7 +43,7 @@ char *token = "%";
 size_t
 cdiPioFileWrite(int fileID, const void *restrict buffer, size_t len, int tsID)
 {
-  size_t iret = CDI_UNDEFID;
+  size_t iret = 0;
 
   switch ( commInqIOMode ())
     {
diff --git a/libcdi/src/pio_client.c b/libcdi/src/pio_client.c
index 3d221ea..f980c4f 100644
--- a/libcdi/src/pio_client.c
+++ b/libcdi/src/pio_client.c
@@ -21,6 +21,7 @@
 static void
 nullPackFunc(void *obj, void *buf, int size, int *pos, void *context)
 {
+  (void)obj; (void)buf; (void)size; (void)pos; (void)context;
 }
 
 
@@ -31,6 +32,7 @@ cdiPioClientStreamOpen(const char *filename, const char *filemode,
 {
   struct winHeaderEntry header;
   size_t filename_len;
+  (void)streamptr; (void)recordBufIsToBeCreated;
   if ( tolower ( * filemode ) == 'w' )
     {
       statusCode nspStatus = namespaceInqResStatus ();
@@ -98,6 +100,7 @@ static void
 cdiPioClientStreamWriteVar_(int streamID, int varID, int memtype,
                             const void *data, int nmiss)
 {
+  (void)streamID; (void)varID; (void)memtype; (void)data; (void)nmiss;
   xabort("parallel writing requires explicit partition information,"
          " use streamWriteVarPart!");
 }
@@ -107,6 +110,9 @@ cdiPioClientStreamWriteVarChunk_(int streamID, int varID, int memtype,
                                  const int rect[][2],
                                  const void *data, int nmiss)
 {
+  /* todo: handle transmission of float data */
+  if (memtype != MEMTYPE_DOUBLE)
+    Error("Writing of non-double type data not implemented!");
   int vlistID = streamInqVlist(streamID);
   int size = vlistInqVarSize(vlistID, varID),
     varShape[3];
@@ -121,7 +127,7 @@ cdiPioClientStreamWriteVarChunk_(int streamID, int varID, int memtype,
   int varSize = varShape[0] * varShape[1] * varShape[2];
   xassert(varSize == size);
   Xt_idxlist chunkDesc
-    = xt_idxsection_new(0, ndims, varShapeXt, chunkShape, origin);
+    = xt_idxsection_new(0, (int)ndims, varShapeXt, chunkShape, origin);
   pioBufferPartData(streamID, varID, data, nmiss, chunkDesc);
   xt_idxlist_delete(chunkDesc);
 }
@@ -174,12 +180,14 @@ cdiPioClientStreamWriteScatteredVarPart(int streamID, int varID,
 static void
 cdiPioCdfDefTimestepNOP(stream_t *streamptr, int tsID)
 {
+  (void)streamptr; (void)tsID;
 }
 #endif
 
 static void
 cdiPioClientStreamNOP(stream_t *streamptr)
 {
+  (void)streamptr;
 }
 
 
@@ -188,6 +196,7 @@ cdiPioClientStreamClose(stream_t *streamptr, int recordBufIsToBeDeleted)
 {
   struct winHeaderEntry header;
   statusCode nspStatus = namespaceInqResStatus ();
+  (void)recordBufIsToBeDeleted;
   switch ( nspStatus )
     {
     case STAGE_DEFINITION:
diff --git a/libcdi/src/pio_comm.c b/libcdi/src/pio_comm.c
index 5073c84..610c3f5 100644
--- a/libcdi/src/pio_comm.c
+++ b/libcdi/src/pio_comm.c
@@ -387,24 +387,21 @@ void commDefCommNode ( void )
     int len;
     xmpi ( MPI_Get_processor_name ( myHost, &len ));
     xassert ( myHost[0] != '\0' );
-    strncpy(info->hostname, myHost, len);
+    strncpy(info->hostname, myHost, (size_t)len);
     info->hostname[len] = '\0';
   }
 
-  allHosts = xmalloc(size * MPI_MAX_PROCESSOR_NAME);
-  sortedHosts = xmalloc(size * sizeof(sortedHosts[0]));
+  allHosts = xmalloc((size_t)size * MPI_MAX_PROCESSOR_NAME);
+  sortedHosts = xmalloc((size_t)size * sizeof (sortedHosts[0]));
 
-  {
-    int i;
-    for (i = 0; i < size; ++i)
-      sortedHosts[i] = allHosts[i];
-  }
+  for (int i = 0; i < size; ++i)
+    sortedHosts[i] = allHosts[i];
 
   xmpi(MPI_Allgather(myHost, MPI_MAX_PROCESSOR_NAME, MPI_CHAR,
                      allHosts[0], MPI_MAX_PROCESSOR_NAME,
                      MPI_CHAR, info->commPio ));
 
-  qsort(sortedHosts, size, sizeof (sortedHosts[0]),
+  qsort(sortedHosts, (size_t)size, sizeof (sortedHosts[0]),
         (int (*)(const void *, const void *))cmpstringp);
 
   {
@@ -510,8 +507,8 @@ void     commRecvNodeMap    ( void )
 
   xdebug ( "info->nProcsColl=%d", info->nProcsColl );
 
-  info->nodeMap = (int*) xmalloc ( info->nProcsColl * 
-                                sizeof ( info->nodeMap[0] )); 
+  info->nodeMap = (int *)xmalloc((size_t)info->nProcsColl
+                                 * sizeof (info->nodeMap[0]));
 
   xmpi ( MPI_Recv ( info->nodeMap, info->nProcsColl, MPI_INTEGER, 
                     source, NODEMAP, info->commGlob, &status ));
@@ -550,7 +547,7 @@ void     commEvalPhysNodes  ( void )
 
   size = info->nProcsIO * sizeNodeInfo;
 
-  nodeInfo = (nodeInfo_t*) xmalloc ( size * sizeof ( int ));
+  nodeInfo = (nodeInfo_t *)xmalloc((size_t)size * sizeof (int));
 
   if ( info->rankGlob == info->root )
     {
@@ -590,13 +587,13 @@ void     commEvalPhysNodes  ( void )
 
   xassert ( info->nProcsColl <= info->nProcsModel );
 
-  info->procsCollMap = (int*) xmalloc ( info->nProcsColl * 
-                                 sizeof ( info->procsCollMap[0] )); 
+  info->procsCollMap = (int *)xmalloc((size_t)info->nProcsColl
+                                      * sizeof (info->procsCollMap[0]));
 
   // define nodeSizes
   info->nodeInfo.nNodes = nNodes; 
-  info->nodeSizes = (int*) xmalloc ( info->nodeInfo.nNodes * 
-                                  sizeof ( info->nodeSizes[0] ));
+  info->nodeSizes = (int *)xmalloc((size_t)info->nodeInfo.nNodes
+                                   * sizeof (info->nodeSizes[0]));
   collID = 0;
   for ( IOID = 0; IOID < info->nProcsIO; IOID++ )
     if ( nodeInfo[IOID].isProcColl )
@@ -606,11 +603,11 @@ void     commEvalPhysNodes  ( void )
       }
 
   // define nodeMap
-  info->nodeMap   = (int*) xmalloc ( info->nProcsColl * 
-                                  sizeof ( info->nodeMap[0] ));
+  info->nodeMap = (int *)xmalloc((size_t)info->nProcsColl
+                                 * sizeof (info->nodeMap[0]));
   // helpers
-  p1 = (int**) xmalloc ( info->nodeInfo.nNodes * sizeof ( p1[0] ));
-  p2 = (int**) xmalloc ( info->nodeInfo.nNodes * sizeof ( p2[0] ));
+  p1 = (int **)xmalloc((size_t)info->nodeInfo.nNodes * sizeof (p1[0]));
+  p2 = (int **)xmalloc((size_t)info->nodeInfo.nNodes * sizeof (p2[0]));
   idx = 0;
   for ( i = 0; i < info->nodeInfo.nNodes; i++ )
     {
@@ -692,18 +689,18 @@ void     commDefCommsIO     ( void )
            info->nProcsModel != CDI_UNDEFID &&
            info->commGlob != MPI_COMM_NULL );
 
-  info->commsIO = (MPI_Comm*) xmalloc ( info->nProcsColl * 
-                                sizeof ( info->commsIO[0] ));
+  info->commsIO = (MPI_Comm *)xmalloc((size_t)info->nProcsColl
+                                      * sizeof (info->commsIO[0]));
   for ( collID = 0; collID < info->nProcsColl; collID++ )
     info->commsIO[collID] = MPI_COMM_NULL;
 
-  strncpy ( name, "COMMSIO_", 8 ); 
+  strncpy ( name, "COMMSIO_", 8 );
   name[MAXCOMMIONAME - 1] = '\0';
-  
-  ranks = (int*) xmalloc (( info->nProcsModel + 1 ) * sizeof ( ranks[0] ));
+
+  ranks = (int *)xmalloc(((size_t)info->nProcsModel + 1) * sizeof (ranks[0]));
   for ( i = 0; i < info->nProcsModel; i++ )
     ranks[i] = i;
-  
+
   xmpi ( MPI_Comm_group ( info->commGlob, &groupGlob )); 
 
   for ( collID = 0; collID < info->nProcsColl; collID++ )
diff --git a/libcdi/src/pio_interface.c b/libcdi/src/pio_interface.c
index 2227e48..6241cfe 100644
--- a/libcdi/src/pio_interface.c
+++ b/libcdi/src/pio_interface.c
@@ -35,7 +35,7 @@ static struct rdmaWin
   MPI_Win win;
   int postSet, refuseFuncCall;
   MPI_Group ioGroup;
-  int dictSize, dictDataUsed, dictRPCUsed, dict;
+  int dictSize, dictDataUsed, dictRPCUsed;
 } *txWin = NULL;
 
 
@@ -64,6 +64,7 @@ void memcpyPackFunc(void *dataDesc, void *buf, int size, int *pos,
                     void *context)
 {
   struct memCpyDataDesc *p = dataDesc;
+  (void)context;
   xassert(size >= *pos && (size_t)(size - *pos) >= p->obj_size);
   memcpy((unsigned char *)buf + *pos, p->obj, p->obj_size);
   *pos += (int)p->obj_size;
@@ -91,10 +92,10 @@ mapProblems(int problemSizes[], int * problemMapping, int nProblems,
       sum += problemSizes[i];
     }
 
-  qsort ( ip, nProblems, sizeof ( int * ), cmp );
+  qsort(ip, (size_t)nProblems, sizeof ( int * ), cmp );
 
   for ( i = 0; i < nProblems; i++ )
-    dummy[i] = ip[i] - problemSizes;
+    dummy[i] = (int)(ip[i] - problemSizes);
 
   for ( j = 0; j < nWriter; j++ )
     meanBucket[j] = ( double ) sum * ( * ( w + j ));
@@ -107,7 +108,7 @@ mapProblems(int problemSizes[], int * problemMapping, int nProblems,
 
       for ( j = 0; j < nWriter; j++ )
 	{
-	  nextCapacity = meanBucket[j] - ( buckets[j] + ( *ip[i] ));
+	  nextCapacity = (int)meanBucket[j] - ( buckets[j] + ( *ip[i] ));
 
 	  if ( nextCapacity > currCapacity )
 	    {
@@ -161,7 +162,6 @@ varMapGen(int *vSizes, int *sSizes, int *varMapping,
   int streamMapping[nStreams];
   int nPEs = 0, nVars = 0;
   int i, j, k, offset = 0, offsetN = 0;
-  double * w;
 
   int * weightsVarsNode;
   int * varMappingNode;
@@ -178,7 +178,7 @@ varMapGen(int *vSizes, int *sSizes, int *varMapping,
 	weightsStreams[i] += * ( vSizes + offset++ );
     }
 
-  w = ( double * ) xmalloc( nNodes * sizeof ( double ));
+  double *w = (double *)xmalloc((size_t)nNodes * sizeof ( double ));
   for ( j = 0; j < nNodes; j++ )
     nPEs += * ( nodeSizes + j );
 
@@ -195,9 +195,9 @@ varMapGen(int *vSizes, int *sSizes, int *varMapping,
 	if ( * ( streamMapping + j ) == i )
 	  nVarsNode += * ( sSizes + j );
 
-      weightsVarsNode = ( int * ) xmalloc( nVarsNode * sizeof ( int ));
-      varMappingNode = ( int * ) xmalloc( nVarsNode * sizeof ( int ));
-      w = ( double * ) xmalloc( * ( nodeSizes + i ) * sizeof ( double ));
+      weightsVarsNode = xmalloc((size_t)nVarsNode * sizeof (int));
+      varMappingNode = xmalloc((size_t)nVarsNode * sizeof ( int ));
+      w = xmalloc((size_t)nodeSizes[i] * sizeof (double));
       offset = 0;
       offsetN = 0;
 
@@ -251,28 +251,31 @@ varsMapNDeco(int nNodes, int *nodeSizes)
 {
   int nStreams, nVars, * resHs, * streamSizes, * varSizes, * varMapping,
     * collectsData;
-  int i, j, k = 0;
+  int k = 0;
   int nProcsColl = commInqNProcsColl ();
 
   xdebug ( "START, nProcsColl=%d", nProcsColl );
 
   nStreams = streamSize ();
 
-  resHs       = (int*) xmalloc( nStreams * sizeof ( resHs[0] ));
-  streamSizes = (int*) xmalloc( nStreams * sizeof ( streamSizes[0] ));
-  collectsData = (int*) xmalloc( nProcsColl * sizeof ( collectsData[0] ));
+  resHs       = xmalloc((size_t)nStreams * sizeof (resHs[0]));
+  streamSizes = xmalloc((size_t)nStreams * sizeof (streamSizes[0]));
+  collectsData = xmalloc((size_t)nProcsColl * sizeof (collectsData[0]));
   streamGetIndexList ( nStreams, resHs );
 
-  for ( i = 0; i < nStreams; i++ )
+  for (int i = 0; i < nStreams; i++ )
     streamSizes[i] = streamInqNvars ( * ( resHs + i ));
 
-  nVars = sum_int(nStreams, streamSizes);
-  varSizes   = (int*) xmalloc( nVars * sizeof ( varSizes[0] ));
-  varMapping = (int*) xmalloc( nVars * sizeof ( varMapping[0] ));
+  nVars = sum_int((size_t)nStreams, streamSizes);
+  varSizes   = xmalloc((size_t)nVars * sizeof (varSizes[0]));
+  varMapping = xmalloc((size_t)nVars * sizeof (varMapping[0]));
 
-  for ( i = 0; i < nStreams; i++ )
-    for ( j = 0; j < * ( streamSizes + i ); j++ )
-      varSizes[k++] += vlistInqVarSize ( streamInqVlist ( * ( resHs + i )), j );
+  for (int i = 0; i < nStreams; i++ )
+    {
+      int vlistID = streamInqVlist(resHs[i]);
+      for (int j = 0; j < streamSizes[i]; j++ )
+        varSizes[k++] += vlistInqVarSize(vlistID, j);
+    }
 
   xassert ( k == nVars );
 
@@ -280,8 +283,8 @@ varsMapNDeco(int nNodes, int *nodeSizes)
 	      nStreams, nodeSizes, nNodes );
 
   k = 0;
-  for ( i = 0; i < nStreams; i++ )
-    for ( j = 0; j < * ( streamSizes + i ); j++ )
+  for (int i = 0; i < nStreams; i++ )
+    for (int j = 0; j < * ( streamSizes + i ); j++ )
       {
         vlistDefVarIOrank ( streamInqVlist ( * ( resHs + i )), j,
                             * ( varMapping + k ));
@@ -290,7 +293,7 @@ varsMapNDeco(int nNodes, int *nodeSizes)
         collectsData[commRankGlob2CollID ( varMapping[k++] )] = 1;
       }
 
-  for ( j = 0; j < nProcsColl; j++ )
+  for (int j = 0; j < nProcsColl; j++ )
     if ( collectsData[j] == 0 )
       xabort("AT LEAST ONE COLLECTOR PROCESS IDLES, "
              "CURRENTLY NOT COVERED: "
@@ -341,7 +344,7 @@ static void
 modelWinDefBufferSizes(void)
 {
   int collID, nstreams, * streamIndexList, streamNo, nvars, varID;
-  int sumWinBufferSize = 0;
+  size_t sumWinBufferSize = 0;
   int nProcsColl  = commInqNProcsColl ();
   int rankGlob    = commInqRankGlob ();
   int root = commInqRootGlob ();
@@ -351,8 +354,8 @@ modelWinDefBufferSizes(void)
   xassert(txWin != NULL);
 
   nstreams = reshCountType ( &streamOps );
-  streamIndexList = (int*) xmalloc( nstreams * sizeof ( streamIndexList[0] ));
-  collIndex = (struct collDesc*) xcalloc(nProcsColl, sizeof (collIndex[0]));
+  streamIndexList = xmalloc((size_t)nstreams * sizeof (streamIndexList[0]));
+  collIndex = xcalloc((size_t)nProcsColl, sizeof (collIndex[0]));
   reshGetResHListOfType ( nstreams, streamIndexList, &streamOps );
   for ( streamNo = 0; streamNo < nstreams; streamNo++ )
     {
@@ -363,12 +366,13 @@ modelWinDefBufferSizes(void)
       for ( varID = 0; varID < nvars; varID++ )
         {
           int collID = commRankGlob2CollID(vlistInqVarIOrank(vlistID, varID));
-          int collIDchunk;
+          size_t collIDchunk;
           {
             int varSize = vlistInqVarSize(vlistID, varID);
             int nProcsModel = commInqNProcsModel();
-            collIDchunk = (int)ceilf(cdiPIOpartInflate_
-                                     * (varSize + nProcsModel - 1)/nProcsModel);
+            collIDchunk = (size_t)ceilf(cdiPIOpartInflate_
+                                        * (float)(varSize + nProcsModel - 1)
+                                        / (float)nProcsModel);
           }
           xassert ( collID != CDI_UNDEFID && collIDchunk > 0 );
           collIndex[collID].numDataRecords += 2;
@@ -407,14 +411,14 @@ modelWinDefBufferSizes(void)
       txWin[collID].size += sizeof (struct winHeaderEntry);
       txWin[collID].size = roundUpToMultiple(txWin[collID].size,
                                              PIO_WIN_ALIGN);
-      sumWinBufferSize += txWin[collID].size;
+      sumWinBufferSize += (size_t)txWin[collID].size;
     }
   free(collIndex);
   free ( streamIndexList );
 
-  xdebug("sumWinBufferSize=%zu, MAXWINBUFFERSIZE=%zu", (size_t)sumWinBufferSize,
+  xdebug("sumWinBufferSize=%zu, MAXWINBUFFERSIZE=%zu", sumWinBufferSize,
          (size_t)MAXWINBUFFERSIZE);
-  xassert ( sumWinBufferSize <= MAXWINBUFFERSIZE );
+  xassert ( sumWinBufferSize <= (size_t)MAXWINBUFFERSIZE );
   xdebug("%s", "RETURN");
 }
 
@@ -431,11 +435,10 @@ static
             collID                < nProcsColl &&
             txWin != NULL      &&
             txWin[collID].buffer     != NULL      &&
-            txWin[collID].size >= 0         &&
             txWin[collID].size <= MAXWINBUFFERSIZE);
   memset(txWin[collID].buffer, 0, txWin[collID].size);
   txWin[collID].head = txWin[collID].buffer
-    + txWin[collID].dictSize * sizeof (struct winHeaderEntry);
+    + (size_t)txWin[collID].dictSize * sizeof (struct winHeaderEntry);
   txWin[collID].refuseFuncCall = 0;
   txWin[collID].dictDataUsed = 1;
   txWin[collID].dictRPCUsed = 0;
@@ -452,7 +455,7 @@ void modelWinCreate ( void )
   int nProcsColl = commInqNProcsColl ();
 
   xdebug("%s", "START");
-  txWin = (struct rdmaWin*) xmalloc(nProcsColl * sizeof (txWin[0]));
+  txWin = xmalloc((size_t)nProcsColl * sizeof (txWin[0]));
 
   modelWinDefBufferSizes ();
   ranks[0] = commInqNProcsModel ();
@@ -468,7 +471,7 @@ void modelWinCreate ( void )
                          &txWin[collID].buffer));
       xassert ( txWin[collID].buffer != NULL );
       txWin[collID].head = txWin[collID].buffer
-        + txWin[collID].dictSize * sizeof (struct winHeaderEntry);
+        + (size_t)txWin[collID].dictSize * sizeof (struct winHeaderEntry);
       xmpi(MPI_Win_create(txWin[collID].buffer, (MPI_Aint)txWin[collID].size, 1,
                           no_locks_info, commInqCommsIO(collID),
                           &txWin[collID].win));
@@ -500,7 +503,8 @@ modelWinEnqueue(int collID,
   if (header.id > 0)
     {
       int offset = header.offset
-        = (int)roundUpToMultiple(txWin[collID].head - txWin[collID].buffer,
+        = (int)roundUpToMultiple((size_t)(txWin[collID].head
+                                          - txWin[collID].buffer),
                                  sizeof (double));
       MPI_Comm comm = commInqCommsIO(collID);
       packFunc((void *)data, txWin[collID].buffer, (int)txWin[collID].size,
@@ -553,8 +557,8 @@ cdiPio_xt_idxlist_pack_wrap(void *data, void *buf, int size, int *pos,
                             void *context)
 {
   MPI_Comm comm = *(MPI_Comm *)context;
-  int pack_size = xt_idxlist_get_pack_size((Xt_idxlist)data, comm);
-  xassert(size >= *pos && pack_size <= size - *pos);
+  size_t pack_size = xt_idxlist_get_pack_size((Xt_idxlist)data, comm);
+  xassert(size >= *pos && pack_size <= (size_t)(size - *pos));
   xt_idxlist_pack((Xt_idxlist)data, (unsigned char *)buf,
                   size, pos, comm);
 }
@@ -631,7 +635,7 @@ pioBufferPartData(int streamID, int varID, const double *data,
   int chunk = xt_idxlist_get_num_indices(partDesc);
   xassert(chunk <= INT_MAX);
   pioBufferPartData_(streamID, varID,
-                     &(struct memCpyDataDesc){data, chunk * sizeof (data[0])},
+                     &(struct memCpyDataDesc){data, (size_t)chunk * sizeof (data[0])},
                      memcpyPackFunc,
                      nmiss, partDesc);
 }
@@ -649,28 +653,30 @@ static void
 scatterGatherPackFunc(void *dataDesc, void *buf, int size, int *pos,
                       void *context)
 {
+  (void)context;
   const struct scatterGatherDesc *p = dataDesc;
   unsigned numBlocks = p->numBlocks;
   const int *bls = p->blocklengths, *disps = p->displacements;
   int pos_ = *pos;
   unsigned char *dstBuf = buf + pos_, *bufEnd = (unsigned char *)buf + size;
   size_t elemSize = p->elemSize;
+  xassert(elemSize <= SSIZE_MAX);
   const unsigned char *data = p->data;
   unsigned copyCount = 0, numElems = p->numElems;
   for (unsigned j = 0; j < numBlocks && copyCount < numElems; ++j)
     {
       int bl = bls[j];
-      if (bl + copyCount > numElems)
-        {
-          bl = numElems - copyCount;
-          Warning("%s: %s", "streamWriteScatteredVarPart",
-                  "blocks longer than number of elements in index list!");
-        }
       if (bl > 0)
         {
+          if ((unsigned)bl + copyCount > numElems)
+            {
+              bl = (int)(numElems - copyCount);
+              Warning("%s: %s", "streamWriteScatteredVarPart",
+                      "blocks longer than number of elements in index list!");
+            }
           size_t bsize = (size_t)bl * elemSize;
           xassert(dstBuf + bsize <= bufEnd);
-          memcpy(dstBuf, data + elemSize * disps[j], bsize);
+          memcpy(dstBuf, data + (ssize_t)elemSize * (ssize_t)disps[j], bsize);
           dstBuf += bsize;
         }
     }
@@ -689,7 +695,8 @@ cdiPioBufferPartDataGather(int streamID, int varID, const double *data,
                      &(struct scatterGatherDesc)
                      { .data = (void *)data, .blocklengths = blocklengths,
                        .displacements = displacements,
-                       .elemSize = sizeof (data[0]), .numBlocks = numBlocks,
+                       .elemSize = sizeof (data[0]),
+                       .numBlocks = (unsigned)numBlocks,
                        .numElems
                          = (unsigned)xt_idxlist_get_num_indices(partDesc) },
                      scatterGatherPackFunc,
diff --git a/libcdi/src/pio_mpinonb.c b/libcdi/src/pio_mpinonb.c
index dd1f1d0..569cbdf 100644
--- a/libcdi/src/pio_mpinonb.c
+++ b/libcdi/src/pio_mpinonb.c
@@ -296,7 +296,7 @@ int fowMPINONB ( const char *filename )
   xdebug("buffersize=%ld", buffersize);
 
   listSetForeach(bibAFiledataM, elemCheck, (void *)filename);
-  of = initAFiledataMPINONB(filename, buffersize);
+  of = initAFiledataMPINONB(filename, (size_t)buffersize);
 
   if ((id = listSetAdd(bibAFiledataM, of)) < 0 )
     xabort("filename %s not unique", of->name);
diff --git a/libcdi/src/pio_posixasynch.c b/libcdi/src/pio_posixasynch.c
index aa7333e..db38307 100644
--- a/libcdi/src/pio_posixasynch.c
+++ b/libcdi/src/pio_posixasynch.c
@@ -54,7 +54,7 @@ fileIDTest(void *a, void *fileID)
   return ((bFiledataPA *)a)->fileID == (int)(intptr_t)fileID;
 }
 
-int nPrefStreams = 4;
+static int nPrefStreams = 4;
 
 /***************************************************************/
 
@@ -62,7 +62,6 @@ static bFiledataPA *
 initBFiledataPA(char *filename, size_t bs, int nc)
 {
   bFiledataPA *bfd;
-  int i;
 
   xdebug ( "filename=%s, buffersize=%zu, ncollectors=%d, nPrefetchStreams=%d",
            filename, bs, nc, nPrefStreams );
@@ -73,14 +72,14 @@ initBFiledataPA(char *filename, size_t bs, int nc)
   if (( bfd->handle = open ( bfd->name, O_CREAT | O_WRONLY, 0666 )) == -1 )
     xabort("Failed to open %s", bfd->name);
 
-  dbuffer_init(&(bfd->fb), (size_t)(nPrefStreams * bs));
+  dbuffer_init(&(bfd->fb), (size_t)nPrefStreams * bs);
 
-  bfd->ctrlBlks = (struct aiocb *) xcalloc(nPrefStreams, sizeof (bfd->ctrlBlks[0]));
+  bfd->ctrlBlks = xcalloc((size_t)nPrefStreams, sizeof (bfd->ctrlBlks[0]));
 
-  for ( i = 0; i < nPrefStreams; i++ )
+  for (int i = 0; i < nPrefStreams; i++ )
     {
       bfd->ctrlBlks[i].aio_fildes     = bfd->handle;
-      bfd->ctrlBlks[i].aio_buf = bfd->fb->buffer + i * bs;
+      bfd->ctrlBlks[i].aio_buf = bfd->fb->buffer + (size_t)i * bs;
       bfd->ctrlBlks[i].aio_reqprio    = 0;
       bfd->ctrlBlks[i].aio_sigevent.sigev_notify = SIGEV_NONE;   
     }
@@ -167,10 +166,10 @@ compareNamesBPA(void *v1, void *v2)
 /***************************************************************/
 
 static void
-writePA(bFiledataPA *bfd, long amount)
+writePA(bFiledataPA *bfd, size_t amount)
 {
   const struct aiocb *ccBP[1];
-  int iret;
+  ssize_t iret;
   double startTime;
 
   xdebug ( "file %s, in", bfd->name );
@@ -191,7 +190,7 @@ writePA(bFiledataPA *bfd, long amount)
   xdebug ( "after aio_write(), file %s, aio_nbytes=%zu, aio_offset=%zu,"
            "iret=aio_write()=%d",
            bfd->name, bfd->ctrlBlks[bfd->currOpIndex].aio_nbytes,
-           bfd->ctrlBlks[bfd->currOpIndex].aio_offset, iret );
+           bfd->ctrlBlks[bfd->currOpIndex].aio_offset, (int)iret );
    
   if ( iret == -1 ) 
     {
@@ -200,7 +199,7 @@ writePA(bFiledataPA *bfd, long amount)
   else
     xdebug ( "buffer written to %s",  bfd->name );
      
-  bfd->offset += ( off_t ) amount;
+  bfd->offset += (off_t)amount;
   bfd->prefIndex ++;
 
   if ( bfd->prefIndex >= nPrefStreams ) 
@@ -246,11 +245,6 @@ void pioWriterAIO(void)
 {
   bFiledataPA *bfd; 
   listSet * bibBFiledataPA;
-  long amount, buffersize;
-  char *messageBuffer, *pMB, *filename, *temp;
-  int messagesize, source, tag, id;
-  struct fileOpTag rtag;
-  MPI_Status status;
   MPI_Comm commNode = commInqCommNode ();
   int nProcsCollNode = commInqSizeNode () - commInqSizeColl ();
   bool * sentFinalize, doFinalize;
@@ -259,18 +253,20 @@ void pioWriterAIO(void)
   xdebug ( "nProcsCollNode=%d on this node", nProcsCollNode );
  
   bibBFiledataPA = listSetNew(destroyBFiledataPA, compareNamesBPA);
-  sentFinalize = (bool*) xmalloc ( nProcsCollNode * sizeof ( sentFinalize ));
+  sentFinalize = xmalloc((size_t)nProcsCollNode * sizeof (sentFinalize[0]));
   
   for ( ;; )
-    {   
-      xmpiStat ( MPI_Probe ( MPI_ANY_SOURCE, MPI_ANY_TAG, commNode, 
-                             &status ), &status );
+    {
+      MPI_Status status;
+      xmpiStat(MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, commNode,
+                         &status ), &status);
 
-      source = status.MPI_SOURCE;
-      tag    = status.MPI_TAG;
-      rtag = decodeFileOpTag(tag);
+      int source = status.MPI_SOURCE;
+      int tag = status.MPI_TAG;
+      struct fileOpTag rtag = decodeFileOpTag(tag);
 
-      xmpi ( MPI_Get_count ( &status, MPI_CHAR, &messagesize ));
+      int messagesize;
+      xmpi (MPI_Get_count(&status, MPI_CHAR, &messagesize));
 
       xdebug ( "receive message from source=%d, id=%d, command=%d ( %s ), "
                "messagesize=%d", source, rtag.id, rtag.command,
@@ -279,48 +275,48 @@ void pioWriterAIO(void)
       switch (rtag.command)
 	{
       	case IO_Open_file:
+          {
+            char *messageBuffer = xmalloc((size_t)messagesize
+                                          * sizeof (messageBuffer[0]));
+            char *pMB = messageBuffer;
 
-	  messageBuffer = ( char *) xmalloc ( messagesize * 
-                                              sizeof ( messageBuffer[0] ));
-	  pMB = messageBuffer;
-
-	  xmpi ( MPI_Recv ( messageBuffer, messagesize, MPI_CHAR, source, 
-                            tag, commNode, &status ));
+            xmpi(MPI_Recv(messageBuffer, messagesize, MPI_CHAR, source,
+                          tag, commNode, &status ));
 
-	  filename = strtok ( pMB, token );
-	  pMB += ( strlen ( filename ) + 1 );
-	  temp =  strtok ( pMB, token );
-	  buffersize =  strtol ( temp, NULL, 16 );
-	  pMB += ( strlen ( temp ) + 1 );
-	  amount = ( long ) ( messageBuffer + messagesize - pMB );
+            char *filename = strtok(pMB, token);
+            pMB += (strlen(filename) + 1);
+            char *temp = strtok(pMB, token);
+            long buffersize =  strtol(temp, NULL, 16);
+            pMB += (strlen(temp) + 1);
+            size_t amount = (size_t)(messageBuffer + messagesize - pMB);
 
-	  xdebug("command  %s, filename=%s, buffersize=%ld, amount=%ld",
-                 command2charP[rtag.command], filename, buffersize, amount);
+            xdebug("command  %s, filename=%s, buffersize=%ld, amount=%zd",
+                   command2charP[rtag.command], filename, buffersize, amount);
 
-          if (!(bfd = listSetGet(bibBFiledataPA, fileIDTest,
-                               (void *)(intptr_t)rtag.id)))
-	    {
-              listSetForeach(bibBFiledataPA, elemCheck, filename);
-	      bfd = initBFiledataPA(filename, buffersize, nProcsCollNode);
-              if ((id = listSetAdd(bibBFiledataPA, bfd)) < 0)
-                xabort("fileID=%d not unique", rtag.id);
-              bfd->fileID = id;
-	    }
-	  else
-	    if (strcmp(filename, bfd->name) != 0)
-              xabort("filename is not consistent, fileID=%d", rtag.id);
-
-	  bfd->currOpIndex = bfd->nextOpIndex;
-	  bfd->nextOpIndex = ( bfd->nextOpIndex + 1 ) % nPrefStreams;
+            if (!(bfd = listSetGet(bibBFiledataPA, fileIDTest,
+                                   (void *)(intptr_t)rtag.id)))
+              {
+                listSetForeach(bibBFiledataPA, elemCheck, filename);
+                bfd = initBFiledataPA(filename, (size_t)buffersize, nProcsCollNode);
+                int id;
+                if ((id = listSetAdd(bibBFiledataPA, bfd)) < 0)
+                  xabort("fileID=%d not unique", rtag.id);
+                bfd->fileID = id;
+              }
+            else
+              if (strcmp(filename, bfd->name) != 0)
+                xabort("filename is not consistent, fileID=%d", rtag.id);
 
-          xassert(amount >= 0);
-	  memcpy((void *)bfd->ctrlBlks[bfd->currOpIndex].aio_buf,
-                 pMB, (size_t)amount);
+            bfd->currOpIndex = bfd->nextOpIndex;
+            bfd->nextOpIndex = ( bfd->nextOpIndex + 1 ) % nPrefStreams;
 
-	  writePA ( bfd, amount );
+            memcpy((void *)bfd->ctrlBlks[bfd->currOpIndex].aio_buf,
+                   pMB, (size_t)amount);
 
-	  free ( messageBuffer );
+            writePA(bfd, amount);
 
+            free(messageBuffer);
+          }
 	  break;
 
 	case IO_Send_buffer:
@@ -329,19 +325,15 @@ void pioWriterAIO(void)
                                (void *)(intptr_t)rtag.id)))
             xabort("fileID=%d is not in set", rtag.id);
 
-	  amount = messagesize;
-
 	  xdebug("command: %s, id=%d, name=%s",
                  command2charP[rtag.command], rtag.id, bfd->name );
 
 	  bfd->currOpIndex = bfd->nextOpIndex;
 	  bfd->nextOpIndex = ( bfd->nextOpIndex + 1 ) % nPrefStreams;
-	  
-	  xmpi(MPI_Recv((void *)bfd->ctrlBlks[bfd->currOpIndex].aio_buf,
-                        amount, MPI_CHAR, source, tag, commNode, &status ));
 
-	  writePA ( bfd, amount );
-	  
+	  xmpi(MPI_Recv((void *)bfd->ctrlBlks[bfd->currOpIndex].aio_buf,
+                        messagesize, MPI_CHAR, source, tag, commNode, &status ));
+	  writePA(bfd, (size_t)messagesize);
 	  break;
 
 	case IO_Close_file:
@@ -350,8 +342,6 @@ void pioWriterAIO(void)
                                (void *)(intptr_t)rtag.id)))
             xabort("fileID=%d is not in set", rtag.id);
 
-	  amount = messagesize;
-
 	  xdebug(" command %s, id=%d, name=%s",
                  command2charP[rtag.command], rtag.id, bfd->name);
 
@@ -360,9 +350,9 @@ void pioWriterAIO(void)
 	  bfd->nextOpIndex = ( bfd->nextOpIndex + 1 ) % nPrefStreams;
 
 	  MPI_Recv((void *)bfd->ctrlBlks[bfd->currOpIndex].aio_buf,
-                   amount, MPI_CHAR, source, tag, commNode, &status);
+                   messagesize, MPI_CHAR, source, tag, commNode, &status);
 
-	  writePA ( bfd, amount );
+	  writePA(bfd, (size_t)messagesize);
 
 	  if ( ! --(bfd->activeCollectors))
 	    {
@@ -373,17 +363,13 @@ void pioWriterAIO(void)
           break;
         case IO_Finalize:
           {
-            int buffer = CDI_UNDEFID, collID;
+            int buffer, collID;
 
             xmpi ( MPI_Recv ( &buffer, 1, MPI_INT, source, tag, commNode, &status ));
             sentFinalize[source] = true;
             doFinalize = true;
             for ( collID = 0; collID < nProcsCollNode; collID++ )
-              if ( !sentFinalize[collID] ) 
-                {
-                  doFinalize = false;
-                  break;
-                }
+              doFinalize &= sentFinalize[collID];
             if ( doFinalize )
               {
                 if (!listSetIsEmpty(bibBFiledataPA))
diff --git a/libcdi/src/pio_posixfpguardsendrecv.c b/libcdi/src/pio_posixfpguardsendrecv.c
index 579c73d..90e144f 100644
--- a/libcdi/src/pio_posixfpguardsendrecv.c
+++ b/libcdi/src/pio_posixfpguardsendrecv.c
@@ -104,7 +104,7 @@ static bFiledataPF *
 initBFiledataPF(int fileID, int nc)
 {
   bFiledataPF *bfd;
-  size_t bfdSize = sizeof (bFiledataPF) + nc * sizeof (bool);
+  size_t bfdSize = sizeof (bFiledataPF) + (size_t)nc * sizeof (bool);
   bfd = xcalloc(1, bfdSize);
   bfd->offset = 0;
   bfd->finished = false;
@@ -176,7 +176,7 @@ void fpgPOSIXFPGUARDSENDRECV ( void )
   xdebug ( "ncollectors=%d on this node", nProcsCollNode );
   
   bibBFiledataPF = listSetNew( destroyBFiledataPF, fileIDCmpB);
-  sentFinalize = xmalloc ( nProcsCollNode * sizeof ( sentFinalize[0] ));
+  sentFinalize = xmalloc((size_t)nProcsCollNode * sizeof (sentFinalize[0]));
 
   for ( ;; )
     {
@@ -476,7 +476,7 @@ int fowPOSIXFPGUARDSENDRECV ( const char *filename )
   /* init and add file element */
   listSetForeach(bibAFiledataPF, elemCheck, (void *)filename);
 
-  afd = initAFiledataPF ( filename, buffersize );
+  afd = initAFiledataPF(filename, (size_t)buffersize);
 
   if ((id = listSetAdd(bibAFiledataPF, afd)) < 0)
     xabort("filename %s not unique", afd->name);
diff --git a/libcdi/src/pio_posixnonb.c b/libcdi/src/pio_posixnonb.c
index 435ffa6..0de93d0 100644
--- a/libcdi/src/pio_posixnonb.c
+++ b/libcdi/src/pio_posixnonb.c
@@ -99,14 +99,13 @@ compareNamesBP(void *v1, void *v2)
 /***************************************************************/
 
 static void
-writeP(bFiledataP *bfd, long amount)
+writeP(bFiledataP *bfd, size_t amount)
 {
-  long written;
+  size_t written;
 
   xdebug ( "filename=%s, amount=%ld, in", bfd->name, amount );
 
-  if (( written = fwrite ( bfd->fb->buffer, 1, amount,
-			   bfd->fp )) != amount )
+  if ((written = fwrite(bfd->fb->buffer, 1, amount, bfd->fp )) != amount)
     xabort("did not succeed writing buffer in %s", bfd->name);
 
   xdebug ( "filename=%s, written=%ld, amount=%ld, return",
@@ -142,7 +141,7 @@ pioWriterStdIO(void)
   xdebug ( "ncollectors=%d on this node", nProcsCollNode );
 
   bibBFiledataP = listSetNew(destroyBFiledataP, compareNamesBP);
-  sentFinalize = xmalloc ( nProcsCollNode * sizeof ( sentFinalize ));
+  sentFinalize = xmalloc((size_t)nProcsCollNode * sizeof (sentFinalize[0]));
   
   for ( ;; )
     {  
@@ -166,7 +165,8 @@ pioWriterStdIO(void)
 	{
       	case IO_Open_file:
 
-	  messageBuffer = xmalloc ( messagesize  * sizeof ( messageBuffer[0] ));
+	  messageBuffer
+            = xmalloc((size_t)messagesize * sizeof (messageBuffer[0]));
     	  pMB = messageBuffer;
 
 	  xmpi ( MPI_Recv ( messageBuffer, messagesize, MPI_CHAR, source, 
@@ -177,7 +177,7 @@ pioWriterStdIO(void)
 	  filename = strtok ( pMB, token );
 	  pMB += ( strlen ( filename ) + 1 );
 	  temp =  strtok ( pMB, token );
-          buffersize =  strtol ( temp, NULL, 16 );
+          buffersize = (size_t)strtol(temp, NULL, 16);
 	  pMB += ( strlen ( temp ) + 1 );
 	  amount = (size_t)(messageBuffer + messagesize - pMB);
 	  
@@ -214,20 +214,19 @@ pioWriterStdIO(void)
                                (void *)(intptr_t)rtag.id)))
             xabort("fileID=%d is not in set", rtag.id );
 
-	  amount = messagesize;
+	  amount = (size_t)messagesize;
 
 	  xdebug("COMMAND %s, ID=%d, NAME=%s", command2charP[rtag.command],
                  rtag.id, bfd->name);
-	  
-	  xmpi ( MPI_Recv (  bfd->fb->buffer, amount, MPI_CHAR, source, tag, 
-                             commNode, &status ));
 
-	  writeP ( bfd, amount );
-	  
+	  xmpi(MPI_Recv(bfd->fb->buffer, messagesize, MPI_CHAR, source, tag,
+                        commNode, &status));
+
+	  writeP(bfd, amount);
 	  break;
 
 	case IO_Close_file:
-	  
+
 	  xdebug("COMMAND %s,  FILE%d, SOURCE%d",
                  command2charP[rtag.command], rtag.id, source);
 
@@ -235,13 +234,13 @@ pioWriterStdIO(void)
                                (void *)(intptr_t)rtag.id)))
             xabort("fileID=%d is not in set", rtag.id);
 
-          amount = messagesize;
+          amount = (size_t)messagesize;
 
 	  xdebug("COMMAND %s, ID=%d, NAME=%s, AMOUNT=%zu",
                  command2charP[rtag.command], rtag.id, bfd->name, amount);
-	  
-	  xmpi(MPI_Recv(bfd->fb->buffer, amount, MPI_CHAR, source, tag,
-                        commNode, &status ));
+
+	  xmpi(MPI_Recv(bfd->fb->buffer, messagesize, MPI_CHAR, source, tag,
+                        commNode, &status));
 
 	  writeP ( bfd, amount );
 
diff --git a/libcdi/src/pio_record_send.c b/libcdi/src/pio_record_send.c
index fa0910c..cd9d9e3 100644
--- a/libcdi/src/pio_record_send.c
+++ b/libcdi/src/pio_record_send.c
@@ -118,7 +118,8 @@ sendP(remoteFileBuf *afd, int id)
 
   if ( ddebug ) accumWait +=  ( MPI_Wtime () - startTime );
 
-  xmpi(MPI_Issend(afd->db->buffer, amount, MPI_CHAR, commInqSpecialRankNode(),
+  /* FIXME: amount > INT_MAX unhandled */
+  xmpi(MPI_Issend(afd->db->buffer, (int)amount, MPI_CHAR, commInqSpecialRankNode(),
                   tag, commInqCommNode(), &( afd->request )));
 
   /* change outputBuffer */
@@ -244,7 +245,10 @@ pioSendOpen(const char *filename)
 {
   remoteFileBuf *afd;
   static long buffersize = 0;
-  int root = 0, id, iret, messageLength = 32;
+  int root = 0, id, iret;
+  enum {
+    messageLength = 32,
+  };
   char message[messageLength];
   MPI_Comm commCollectors = commInqCommColl();
 
@@ -264,7 +268,7 @@ pioSendOpen(const char *filename)
     }
 
   /* init and add remoteFileBuf */
-  afd = initRemoteFileBuf(filename, buffersize);
+  afd = initRemoteFileBuf(filename, (size_t)buffersize);
   if ((id = listSetAdd(bibRemoteFileBuf, afd)) < 0)
     xabort("filename %s is not unique", afd->name);
   afd->fileID = id;
diff --git a/libcdi/src/pio_serialize.c b/libcdi/src/pio_serialize.c
index e855687..008007e 100644
--- a/libcdi/src/pio_serialize.c
+++ b/libcdi/src/pio_serialize.c
@@ -33,7 +33,7 @@ static struct
   { DATATYPE_UCHAR, MPI_UNSIGNED_CHAR }
 };
 
-static inline int
+static inline size_t
 lookupDt(int datatype)
 {
   for (size_t i = 0; i < sizeof (dtDict) / sizeof (dtDict[0]); ++i)
@@ -46,7 +46,7 @@ lookupDt(int datatype)
 static int dtDictMatchComplete = 0;
 
 static inline void
-  dtDictFixMPIType(int i, int typeclass, int size)
+dtDictFixMPIType(size_t i, int typeclass, int size)
 {
   MPI_Aint lb, extent;
   xmpi(MPI_Type_get_extent(dtDict[i].mpidt, &lb, &extent));
diff --git a/libcdi/src/pio_server.c b/libcdi/src/pio_server.c
index 68a1fe7..6ec0e43 100644
--- a/libcdi/src/pio_server.c
+++ b/libcdi/src/pio_server.c
@@ -88,7 +88,7 @@ collDefBufferSizes()
   xassert(rxWin != NULL);
 
   nstreams = reshCountType ( &streamOps );
-  streamIndexList = (int*) xmalloc( nstreams * sizeof ( streamIndexList[0] ));
+  streamIndexList = xmalloc((size_t)nstreams * sizeof (streamIndexList[0]));
   reshGetResHListOfType ( nstreams, streamIndexList, &streamOps );
   for ( streamNo = 0; streamNo < nstreams; streamNo++ )
     {
@@ -109,17 +109,18 @@ collDefBufferSizes()
                     int nProcsModel = commInqNProcsModel();
                     decoChunk =
                       (int)ceilf(cdiPIOpartInflate_
-                                 * (varSize + nProcsModel - 1)/nProcsModel);
+                                 * (float)(varSize + nProcsModel - 1)
+                                 / (float)nProcsModel);
                   }
                   xassert ( decoChunk > 0 );
-                  rxWin[modelID].size += decoChunk * sizeof (double)
+                  rxWin[modelID].size += (size_t)decoChunk * sizeof (double)
                     /* re-align chunks to multiple of double size */
                     + sizeof (double) - 1
                     /* one header for data record, one for
                      * corresponding part descriptor*/
                     + 2 * sizeof (struct winHeaderEntry)
                     /* FIXME: heuristic for size of packed Xt_idxlist */
-                    + sizeof (Xt_int) * decoChunk * 3;
+                    + sizeof (Xt_int) * (size_t)decoChunk * 3;
                   rxWin[modelID].dictSize += 2;
                 }
             }
@@ -168,7 +169,7 @@ serverWinCreate(void)
   xmpi ( MPI_Comm_group ( commCalc, &groupCalc ));
   xmpi ( MPI_Group_excl ( groupCalc, 1, ranks, &groupModel ));
 
-  rxWin = xcalloc(nProcsModel, sizeof (rxWin[0]));
+  rxWin = xcalloc((size_t)nProcsModel, sizeof (rxWin[0]));
   size_t totalBufferSize = collDefBufferSizes();
   rxWin[0].buffer = (unsigned char*) xmalloc(totalBufferSize);
   size_t ofs = 0;
@@ -207,7 +208,7 @@ readFuncCall(struct winHeaderEntry *header)
       break;
     case STREAMOPEN:
       {
-        size_t filenamesz = funcArgs->newFile.fnamelen;
+        size_t filenamesz = (size_t)funcArgs->newFile.fnamelen;
         xassert ( filenamesz > 0 && filenamesz < MAXDATAFILENAME );
         const char *filename
           = (const char *)(rxWin[root].buffer + header->offset);
@@ -263,7 +264,7 @@ resizeVarGatherBuf(int vlistID, int varID, double **buf, int *bufSize)
 {
   int size = vlistInqVarSize(vlistID, varID);
   if (size <= *bufSize) ; else
-    *buf = (double*) xrealloc(*buf, (*bufSize = size) * sizeof (buf[0][0]));
+    *buf = xrealloc(*buf, (size_t)(*bufSize = size) * sizeof (buf[0][0]));
 }
 
 static void
@@ -282,8 +283,9 @@ gatherArray(int root, int nProcsModel, int headerIdx,
   for (unsigned i = 0; i < 3; ++i)
     varShapeXt[i] = varShape[i];
   int varSize = varShape[0] * varShape[1] * varShape[2];
-  struct Xt_offset_ext *partExts = (struct Xt_offset_ext*) xmalloc(nProcsModel * sizeof (partExts[0]));
-  Xt_idxlist *part = (Xt_idxlist*) xmalloc(nProcsModel * sizeof (part[0]));
+  struct Xt_offset_ext *partExts
+    = xmalloc((size_t)nProcsModel * sizeof (partExts[0]));
+  Xt_idxlist *part = xmalloc((size_t)nProcsModel * sizeof (part[0]));
   MPI_Comm commCalc = commInqCommCalc();
   {
     int nmiss_ = 0;
@@ -302,21 +304,21 @@ gatherArray(int root, int nProcsModel, int headerIdx,
                     rxWin[modelID].buffer)[headerIdx + 1].id == PARTDESCMARKER
                 && position > 0
                 && ((size_t)position
-                    >= sizeof (struct winHeaderEntry) * rxWin[modelID].dictSize)
+                    >= sizeof (struct winHeaderEntry) * (size_t)rxWin[modelID].dictSize)
                 && ((size_t)position < rxWin[modelID].size));
         part[modelID] = xt_idxlist_unpack(rxWin[modelID].buffer,
                                           (int)rxWin[modelID].size,
                                           &position, commCalc);
-        int partSize = xt_idxlist_get_num_indices(part[modelID]);
-        size_t charOfs = (rxWin[modelID].buffer
-                          + ((struct winHeaderEntry *)
-                             rxWin[modelID].buffer)[headerIdx].offset)
-          - rxWin[0].buffer;
+        unsigned partSize = (unsigned)xt_idxlist_get_num_indices(part[modelID]);
+        size_t charOfs = (size_t)((rxWin[modelID].buffer
+                                   + ((struct winHeaderEntry *)
+                                      rxWin[modelID].buffer)[headerIdx].offset)
+                                  - rxWin[0].buffer);
         xassert(charOfs % sizeof (double) == 0
                 && charOfs / sizeof (double) + partSize <= INT_MAX);
-        int elemOfs = charOfs / sizeof (double);
+        int elemOfs = (int)(charOfs / sizeof (double));
         partExts[modelID].start = elemOfs;
-        partExts[modelID].size = partSize;
+        partExts[modelID].size = (int)partSize;
         partExts[modelID].stride = 1;
         nmiss_ += dataHeader->nmiss;
       }
@@ -493,9 +495,9 @@ inventorizeStream(struct streamMapping *streamMap, int numStreamIDs,
   int sizeStreamMap = *sizeStreamMap_;
   if (numStreamIDs < sizeStreamMap) ; else
     {
-      streamMap = (struct streamMapping*) xrealloc(streamMap,
-                                                   (sizeStreamMap *= 2)
-                                                   * sizeof (streamMap[0]));
+      streamMap = xrealloc(streamMap,
+                           (size_t)(sizeStreamMap *= 2)
+                           * sizeof (streamMap[0]));
       *sizeStreamMap_ = sizeStreamMap;
     }
   streamMap[numStreamIDs].streamID = streamID;
@@ -510,7 +512,8 @@ inventorizeStream(struct streamMapping *streamMap, int numStreamIDs,
       int vlistID = streamInqVlist(streamID);
       int nvars = vlistNvars(vlistID);
       streamMap[numStreamIDs].numVars = nvars;
-      streamMap[numStreamIDs].varMap = (int*) xmalloc(sizeof (streamMap[numStreamIDs].varMap[0]) * nvars);
+      streamMap[numStreamIDs].varMap
+        = xmalloc(sizeof (streamMap[numStreamIDs].varMap[0]) * (size_t)nvars);
       for (int i = 0; i < nvars; ++i)
         streamMap[numStreamIDs].varMap[i] = -1;
     }
@@ -534,7 +537,8 @@ buildStreamMap(struct winHeaderEntry *winDict)
   int oldStreamIdx = CDI_UNDEFID;
   int filetype = FILETYPE_UNDEF;
   int sizeStreamMap = 16;
-  struct streamMapping *streamMap = (struct streamMapping *) xmalloc(sizeStreamMap * sizeof (streamMap[0]));
+  struct streamMapping *streamMap
+    = xmalloc((size_t)sizeStreamMap * sizeof (streamMap[0]));
   int numDataEntries = winDict[0].specific.headerSize.numDataEntries;
   int numStreamIDs = 0;
   /* find streams written on this process */
@@ -590,8 +594,8 @@ buildStreamMap(struct winHeaderEntry *winDict)
     free(streamIDs);
   }
   /* sort written streams by streamID */
-  streamMap = (struct streamMapping*) xrealloc(streamMap, sizeof (streamMap[0]) * numStreamIDs);
-  qsort(streamMap, numStreamIDs, sizeof (streamMap[0]), smCmpStreamID);
+  streamMap = xrealloc(streamMap, sizeof (streamMap[0]) * (size_t)numStreamIDs);
+  qsort(streamMap, (size_t)numStreamIDs, sizeof (streamMap[0]), smCmpStreamID);
   return (struct streamMap){ .entries = streamMap, .numEntries = numStreamIDs };
 }
 
@@ -640,7 +644,8 @@ buildWrittenVars(struct streamMapping *mapping, int **varIsWritten_,
 {
   int nvars = mapping->numVars;
   int *varMap = mapping->varMap;
-  int *varIsWritten = *varIsWritten_ = (int*) xrealloc(*varIsWritten_, sizeof (*varIsWritten) * nvars);
+  int *varIsWritten = *varIsWritten_
+    = xrealloc(*varIsWritten_, sizeof (*varIsWritten) * (size_t)nvars);
   for (int varID = 0; varID < nvars; ++varID)
     varIsWritten[varID] = ((varMap[varID] != -1)
                            ?myCollRank+1 : 0);
@@ -903,11 +908,10 @@ void clearModelWinBuffer(int modelID)
 {
   int nProcsModel = commInqNProcsModel ();
 
-  xassert ( modelID                >= 0           &&
-            modelID                 < nProcsModel &&
-            rxWin != NULL && rxWin[modelID].buffer != NULL &&
-            rxWin[modelID].size > 0 &&
-            rxWin[modelID].size <= MAXWINBUFFERSIZE );
+  xassert((unsigned)modelID < (unsigned)nProcsModel &&
+          rxWin != NULL && rxWin[modelID].buffer != NULL &&
+          rxWin[modelID].size > 0 &&
+          rxWin[modelID].size <= MAXWINBUFFERSIZE );
   memset(rxWin[modelID].buffer, 0, rxWin[modelID].size);
 }
 
@@ -939,9 +943,9 @@ void getTimeStepData()
              modelID, nProcsModel, modelID, rxWin[modelID].size,
              getWinBaseAddr, (unsigned)sizeof(int));
       /* FIXME: this needs to use MPI_PACK for portability */
-      xmpi(MPI_Get(rxWin[modelID].buffer, rxWin[modelID].size,
+      xmpi(MPI_Get(rxWin[modelID].buffer, (int)rxWin[modelID].size,
                    MPI_UNSIGNED_CHAR, modelID, 0,
-                   rxWin[modelID].size, MPI_UNSIGNED_CHAR, getWin));
+                   (int)rxWin[modelID].size, MPI_UNSIGNED_CHAR, getWin));
     }
   xmpi ( MPI_Win_complete ( getWin ));
 
@@ -951,7 +955,7 @@ void getTimeStepData()
         sprintf(text, "rxWin[%d].size=%zu from PE%d rxWin[%d].buffer",
                 modelID, rxWin[modelID].size, modelID, modelID);
         xprintArray(text, rxWin[modelID].buffer,
-                    rxWin[modelID].size / sizeof (double),
+                    (int)(rxWin[modelID].size / sizeof (double)),
                     DATATYPE_FLT);
       }
   readGetBuffers();
@@ -1042,9 +1046,8 @@ cdiPioCdfDefTimestep(stream_t *streamptr, int tsID)
 
 void cdiPioServer(void (*postCommSetupActions)(void))
 {
-  int source, tag, size, nProcsModel=commInqNProcsModel();
+  int nProcsModel=commInqNProcsModel();
   static int nfinished = 0;
-  char * buffer;
   MPI_Comm commCalc;
   MPI_Status status;
 
@@ -1059,8 +1062,8 @@ void cdiPioServer(void (*postCommSetupActions)(void))
   numPioPrimes = PPM_prime_factorization_32((uint32_t)commInqSizeColl(),
                                             &pioPrimes);
 #elif defined (HAVE_LIBNETCDF)
-  cdiSerialOpenFileCount = (int*) xcalloc(sizeof (cdiSerialOpenFileCount[0]),
-                                   commInqSizeColl());
+  cdiSerialOpenFileCount = xcalloc(sizeof (cdiSerialOpenFileCount[0]),
+                                   (size_t)commInqSizeColl());
   namespaceSwitchSet(NSSWITCH_STREAM_OPEN_BACKEND,
                      NSSW_FUNC(cdiPioStreamCDFOpenWrap));
   namespaceSwitchSet(NSSWITCH_STREAM_CLOSE_BACKEND,
@@ -1077,8 +1080,8 @@ void cdiPioServer(void (*postCommSetupActions)(void))
     {
       xmpi ( MPI_Probe ( MPI_ANY_SOURCE, MPI_ANY_TAG, commCalc, &status ));
       
-      source = status.MPI_SOURCE;
-      tag    = status.MPI_TAG;
+      int source = status.MPI_SOURCE;
+      int tag = status.MPI_TAG;
       
       switch ( tag )
         {
@@ -1099,14 +1102,11 @@ void cdiPioServer(void (*postCommSetupActions)(void))
 
                 if ( nStreams > 0 )
                   {
-                    int streamNo;
-                    int * resHs;
-
-                    resHs       = (int*) xmalloc ( nStreams * sizeof ( resHs[0] ));
+                    int * resHs = xmalloc((size_t)nStreams * sizeof (resHs[0]));
                     streamGetIndexList ( nStreams, resHs );
-                    for ( streamNo = 0; streamNo < nStreams; streamNo++ )
-                      streamClose ( resHs[streamNo] );
-                    free ( resHs );
+                    for (int streamNo = 0; streamNo < nStreams; ++streamNo)
+                      streamClose(resHs[streamNo]);
+                    free(resHs);
                   }
               }
               cdiPioFileWritingFinalize();
@@ -1122,16 +1122,17 @@ void cdiPioServer(void (*postCommSetupActions)(void))
           break;
           
 	case RESOURCES:
-	  xdebugMsg (  tag, source, nfinished );
-	  xmpi ( MPI_Get_count ( &status, MPI_CHAR, &size ));
-	  buffer = (char*) xmalloc(size);
-	  xmpi ( MPI_Recv ( buffer, size, MPI_PACKED, source,
-                            tag, commCalc, &status ));
-          xdebug("%s", "RECEIVED MESSAGE WITH TAG \"RESOURCES\"");
-	  reshUnpackResources(buffer, size, &commCalc);
-          xdebug("%s", "");
-	  free ( buffer );
           {
+            int size;
+            xdebugMsg(tag, source, nfinished);
+            xmpi(MPI_Get_count(&status, MPI_CHAR, &size));
+            char *buffer = xmalloc((size_t)size);
+            xmpi(MPI_Recv(buffer, size, MPI_PACKED, source,
+                          tag, commCalc, &status));
+            xdebug("%s", "RECEIVED MESSAGE WITH TAG \"RESOURCES\"");
+            reshUnpackResources(buffer, size, &commCalc);
+            xdebug("%s", "");
+            free(buffer);
             int rankGlob = commInqRankGlob();
             if ( ddebug > 0 && rankGlob == nProcsModel)
               {
@@ -1149,7 +1150,6 @@ void cdiPioServer(void (*postCommSetupActions)(void))
           }
           serverWinCreate ();
 	  break;
-
 	case WRITETS:
           {
             xdebugMsg(tag, source, nfinished);
diff --git a/libcdi/src/resource_handle.c b/libcdi/src/resource_handle.c
index ed7a193..a5d06b8 100644
--- a/libcdi/src/resource_handle.c
+++ b/libcdi/src/resource_handle.c
@@ -24,8 +24,11 @@ void show_stackframe()
   char **messages = backtrace_symbols(trace, trace_size);
 
   fprintf(stderr, "[bt] Execution path:\n");
-  for ( i = 0; i < trace_size; ++i ) fprintf(stderr, "[bt] %s\n", messages[i]);
-  if ( messages ) free(messages);
+  if ( messages ) {
+    for ( i = 0; i < trace_size; ++i )
+      fprintf(stderr, "[bt] %s\n", messages[i]);
+    free(messages);
+  }
 #endif
 }
 
@@ -150,7 +153,7 @@ reshListCreate(int namespaceID)
   LIST_LOCK();
   if (resHListSize <= namespaceID)
     {
-      resHList = (struct resHList_t *)xrealloc(resHList, (namespaceID + 1) * sizeof (resHList[0]));
+      resHList = (struct resHList_t *)xrealloc(resHList, (size_t)(namespaceID + 1) * sizeof (resHList[0]));
       for (int i = resHListSize; i <= namespaceID; ++i)
         reshListClearEntry(i);
       resHListSize = namespaceID + 1;
diff --git a/libcdi/src/serialize.c b/libcdi/src/serialize.c
index c608434..6ef8265 100644
--- a/libcdi/src/serialize.c
+++ b/libcdi/src/serialize.c
@@ -42,6 +42,7 @@ int
 serializeGetSizeInCore(int count, int datatype, void *context)
 {
   int elemSize;
+  (void)context;
   switch (datatype)
   {
   case DATATYPE_INT8:
@@ -75,7 +76,7 @@ void serializePackInCore(void *data, int count, int datatype,
 {
   int size = serializeGetSize(count, datatype, context);
   int pos = *position;
-  xassert(INT_MAX - pos >= size);
+  xassert(INT_MAX - pos >= size && buf_size - pos >= size);
   memcpy((unsigned char *)buf + pos, data, (size_t)size);
   pos += size;
   *position = pos;
@@ -86,7 +87,7 @@ void serializeUnpackInCore(void *buf, int buf_size, int *position,
 {
   int size = serializeGetSize(count, datatype, context);
   int pos = *position;
-  xassert(INT_MAX - pos >= size);
+  xassert(INT_MAX - pos >= size && buf_size - pos >= size);
   memcpy(data, (unsigned char *)buf + pos, (size_t)size);
   pos += size;
   *position = pos;
diff --git a/libcdi/src/stream.c b/libcdi/src/stream.c
index 7725713..d3cb1b3 100644
--- a/libcdi/src/stream.c
+++ b/libcdi/src/stream.c
@@ -36,7 +36,7 @@
 #include "namespace.h"
 
 
-static stream_t *stream_new_entry(void);
+static stream_t *stream_new_entry(int resH);
 static void stream_delete_entry(stream_t *streamptr);
 static int streamCompareP(void * streamptr1, void * streamptr2);
 static void streamDestroyP(void * streamptr);
@@ -81,8 +81,8 @@ int getByteorder(int byteswap)
   return (byteorder);
 }
 
-static
-int getFiletype(const char *filename, int *byteorder)
+// used also in CDO
+int cdiGetFiletype(const char *filename, int *byteorder)
 {
   int filetype = CDI_EUFTYPE;
   int swap = 0;
@@ -514,18 +514,22 @@ int cdiStreamOpenDefaultDelegate(const char *filename, const char *filemode,
 }
 
 
-int streamOpen(const char *filename, const char *filemode, int filetype)
+static int
+streamOpenID(const char *filename, const char *filemode, int filetype,
+             int resH)
 {
   int fileID = CDI_UNDEFID;
-  int streamID = CDI_ESYSTEM;
   int status;
-  stream_t *streamptr = stream_new_entry();
 
   if ( CDI_Debug )
-    Message("Open %s mode %c file %s", strfiletype(filetype), (int) *filemode, filename);
+    Message("Open %s mode %c file %s", strfiletype(filetype), (int) *filemode,
+            filename?filename:"(NUL)");
 
   if ( ! filename || ! filemode || filetype < 0 ) return (CDI_EINVAL);
 
+  stream_t *streamptr = stream_new_entry(resH);
+  int streamID = CDI_ESYSTEM;
+
   {
     int (*streamOpenDelegate)(const char *filename, const char *filemode,
                               int filetype, stream_t *streamptr, int recordBufIsToBeCreated)
@@ -561,20 +565,24 @@ int streamOpen(const char *filename, const char *filemode, int filetype)
 	  status = cdiInqContents(streamptr);
 	  if ( status < 0 ) return (status);
 	  vlist_t *vlistptr = vlist_to_pointer(streamptr->vlistID);
-	  vlistptr->ntsteps = streamNtsteps(streamID);
+	  vlistptr->ntsteps = streamptr->ntsteps;
 	}
     }
 
   return (streamID);
 }
 
+int streamOpen(const char *filename, const char *filemode, int filetype)
+{
+  return streamOpenID(filename, filemode, filetype, CDI_UNDEFID);
+}
 
 static int streamOpenA(const char *filename, const char *filemode, int filetype)
 {
   int fileID = CDI_UNDEFID;
   int streamID = CDI_ESYSTEM;
   int status;
-  stream_t *streamptr = stream_new_entry();
+  stream_t *streamptr = stream_new_entry(CDI_UNDEFID);
   vlist_t *vlistptr;
 
   if ( CDI_Debug )
@@ -725,7 +733,7 @@ int streamOpenRead(const char *filename)
   cdiInitialize();
 
   int byteorder = 0;
-  int filetype = getFiletype(filename, &byteorder);
+  int filetype = cdiGetFiletype(filename, &byteorder);
 
   if ( filetype < 0 ) return (filetype);
 
@@ -746,7 +754,7 @@ int streamOpenAppend(const char *filename)
   cdiInitialize();
 
   int byteorder = 0;
-  int filetype = getFiletype(filename, &byteorder);
+  int filetype = cdiGetFiletype(filename, &byteorder);
 
   if ( filetype < 0 ) return (filetype);
 
@@ -870,7 +878,7 @@ void streamDefaultValue ( stream_t * streamptr )
 }
 
 
-static stream_t *stream_new_entry(void)
+static stream_t *stream_new_entry(int resH)
 {
   stream_t *streamptr;
 
@@ -878,7 +886,13 @@ static stream_t *stream_new_entry(void)
 
   streamptr = (stream_t *) xmalloc(sizeof(stream_t));
   streamDefaultValue ( streamptr );
-  streamptr->self = reshPut (( void * ) streamptr, &streamOps );
+  if (resH == CDI_UNDEFID)
+    streamptr->self = reshPut(streamptr, &streamOps);
+  else
+    {
+      streamptr->self = resH;
+      reshReplace(resH, streamptr, &streamOps);
+    }
 
   return streamptr;
 }
@@ -1966,16 +1980,6 @@ void streamWriteContents(int streamID, char *cname)
   fclose(cnp);
 }
 
-
-int streamNtsteps(int streamID)
-{
-  stream_t *streamptr = stream_to_pointer(streamID);
-
-  stream_check_ptr(__func__, streamptr);
-
-  return (int)streamptr->ntsteps;
-}
-
 // This function is used in CDO!
 off_t streamNvals(int streamID)
 {
@@ -2393,9 +2397,9 @@ streamUnpack(char * unpackBuffer, int unpackBufferSize,
   serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
                   &d, 1, DATATYPE_UINT32, context);
   xassert(d == cdiCheckSum(DATATYPE_TXT, intBuffer[2], filename));
-  streamID = streamOpenWrite ( filename, intBuffer[1] );
-  xassert ( streamID >= 0 &&
-            namespaceAdaptKey ( intBuffer[0], originNamespace ) == streamID );
+  int targetStreamID = namespaceAdaptKey(intBuffer[0], originNamespace);
+  streamID = streamOpenID(filename, "w", intBuffer[1], targetStreamID);
+  xassert(streamID >= 0 && targetStreamID == streamID);
   streamDefByteorder(streamID, intBuffer[5]);
   streamDefCompType(streamID, intBuffer[6]);
   streamDefCompLevel(streamID, intBuffer[7]);
diff --git a/libcdi/src/stream_cdf.c b/libcdi/src/stream_cdf.c
index e3b681d..cab9d96 100644
--- a/libcdi/src/stream_cdf.c
+++ b/libcdi/src/stream_cdf.c
@@ -2,21 +2,20 @@
 #  include "config.h"
 #endif
 
+#ifdef HAVE_LIBNETCDF
+
 //#define TEST_GROUPS 1
 
+#include <limits.h>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <math.h>
 #include <float.h>
 
-#if  defined  (HAVE_LIBNETCDF)
-#  include <netcdf.h>
-#endif
-
+#include <netcdf.h>
 
 #include "dmemory.h"
-
 #include "cdi.h"
 #include "basetime.h"
 #include "gaussgrid.h"
@@ -32,11 +31,10 @@
 #define UNDEFID  CDI_UNDEFID
 
 
-void    vlistInqVarDimorder(int vlistID, int varID, int (*outDimorder)[3]);
-
-void cdfDefGlobalAtts(stream_t *streamptr);
-void cdfDefLocalAtts(stream_t *streamptr);
-
+#if defined HAVE_LIBNETCDF
+static void cdfDefGlobalAtts(stream_t *streamptr);
+static void cdfDefLocalAtts(stream_t *streamptr);
+#endif
 
 #define  X_AXIS  1
 #define  Y_AXIS  2
@@ -124,7 +122,6 @@ typedef struct {
 }
 ncvar_t;
 
-#ifdef HAVE_LIBNETCDF
 static
 void strtolower(char *str)
 {
@@ -260,9 +257,7 @@ static
 int scanTimeUnit(const char *unitstr)
 {
   int timeunit = -1;
-  int len;
-
-  len = (int) strlen(unitstr);
+  size_t len = strlen(unitstr);
   timeunit = get_timeunit(len, unitstr);
   if ( timeunit == -1 )
     Message("Unsupported TIMEUNIT: %s!", unitstr);
@@ -440,12 +435,11 @@ void cdfGetAttText(int fileID, int ncvarid, char *attname, int attlen, char *att
           char *attbuf = NULL;
           cdf_get_att_string(fileID, ncvarid, attname, &attbuf);
 
-          int slen = (int) strlen(attbuf);
-          slen++;
-
-          if ( slen > attlen ) slen = attlen;
-          memcpy(atttext, attbuf, slen);
+          size_t ssize = strlen(attbuf) + 1;
 
+          if ( ssize > (size_t)attlen ) ssize = (size_t)attlen;
+          memcpy(atttext, attbuf, ssize);
+          atttext[ssize - 1] = 0;
           free(attbuf);
         }
       else
@@ -596,24 +590,16 @@ void defineAttributes(int vlistID, int varID, int fileID, int ncvarID)
         }
     }
 }
-#endif
 
 void cdfCopyRecord(stream_t *streamptr2, stream_t *streamptr1)
 {
-  int memtype = MEMTYPE_DOUBLE;
+  int memtype  = MEMTYPE_DOUBLE;
   int vlistID1 = streamptr1->vlistID;
-
-  int tsID1 = streamptr1->curTsID;
-
-  int recID1 = streamptr1->tsteps[tsID1].curRecID;
-
-  int ivarID = streamptr1->tsteps[tsID1].records[recID1].varID;
-
-  int gridID = vlistInqVarGrid(vlistID1, ivarID);
-
+  int tsID1    = streamptr1->curTsID;
+  int recID1   = streamptr1->tsteps[tsID1].curRecID;
+  int ivarID   = streamptr1->tsteps[tsID1].records[recID1].varID;
+  int gridID   = vlistInqVarGrid(vlistID1, ivarID);
   int datasize = gridInqSize(gridID);
-  /* bug fix for constant netCDF fields */
-  if ( datasize < 1048576 ) datasize = 1048576;
 
   double *data = xmalloc((size_t)datasize * sizeof (double));
 
@@ -654,9 +640,10 @@ int cdfInqRecord(stream_t *streamptr, int *varID, int *levelID)
 
 void cdfDefRecord(stream_t *streamptr)
 {
+  (void)streamptr;
 }
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfWriteGridTraj(stream_t *streamptr, int gridID)
 {
@@ -696,9 +683,8 @@ void cdfReadGridTraj(stream_t *streamptr, int gridID)
   gridDefXvals(gridID, &xlon);
   gridDefYvals(gridID, &xlat);
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefVarDeflate(int ncid, int ncvarid, int deflate_level)
 {
@@ -724,9 +710,9 @@ void cdfDefVarDeflate(int ncid, int ncvarid, int deflate_level)
     }
 #endif
 }
-#endif
 
-#if  defined(HAVE_LIBNETCDF) && defined(NC_SZIP_NN_OPTION_MASK)
+
+#if defined(NC_SZIP_NN_OPTION_MASK)
 static
 void cdfDefVarSzip(int ncid, int ncvarid)
 {
@@ -753,7 +739,6 @@ void cdfDefVarSzip(int ncid, int ncvarid)
 }
 #endif
 
-#if  defined  (HAVE_LIBNETCDF)
 static
 void cdfDefVarMissval(stream_t *streamptr, int varID, int dtype, int lcheck)
 {
@@ -784,11 +769,10 @@ void cdfDefVarMissval(stream_t *streamptr, int varID, int dtype, int lcheck)
       streamptr->vars[varID].defmiss = TRUE;
     }
 }
-#endif
+
 
 void cdf_write_record(stream_t *streamptr, int memtype, const void *data, int nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int varID;
   int levelID;
 
@@ -798,7 +782,6 @@ void cdf_write_record(stream_t *streamptr, int memtype, const void *data, int nm
   if ( CDI_Debug ) Message("streamID = %d  varID = %d", streamptr->self, varID);
 
   cdf_write_var_slice(streamptr, varID, levelID, memtype, data, nmiss);
-#endif
 }
 
 void cdfReadRecord(stream_t *streamptr, double *data, int *nmiss)
@@ -816,7 +799,6 @@ void cdfReadRecord(stream_t *streamptr, double *data, int *nmiss)
   cdfReadVarSliceDP(streamptr, varID, levelID, data, nmiss);
 }
 
-#if  defined  (HAVE_LIBNETCDF)
 static
 void cdfDefTimeValue(stream_t *streamptr, int tsID)
 {
@@ -965,7 +947,6 @@ void cdfDefForecastTimeUnits(char *unitstr, int timeunit)
 
   sprintf(unitstr, "%s", tunitNamePtr(timeunit));
 }
-#endif
 
 static
 void cdfDefCalendar(int fileID, int ncvarid, int calendar)
@@ -984,15 +965,12 @@ void cdfDefCalendar(int fileID, int ncvarid, int calendar)
 
   len = strlen(calstr);
 
-#if  defined  (HAVE_LIBNETCDF)
   if ( len ) cdf_put_att_text(fileID, ncvarid, "calendar", len, calstr);
-#endif
 }
 
 static
 void cdfDefTime(stream_t* streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int fileID;
   int time_varid;
   int time_dimid;
@@ -1077,13 +1055,11 @@ void cdfDefTime(stream_t* streamptr)
     }
 
   if ( streamptr->ncmode == 2 ) cdf_enddef(fileID);
-#endif
 }
 
 
 void cdfDefTimestep(stream_t *streamptr, int tsID)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int vlistID;
 
   vlistID = streamptr->vlistID;
@@ -1091,10 +1067,8 @@ void cdfDefTimestep(stream_t *streamptr, int tsID)
   if ( vlistHasTime(vlistID) ) cdfDefTime(streamptr);
 
   cdfDefTimeValue(streamptr, tsID);
-#endif
 }
 
-#if  defined  (HAVE_LIBNETCDF)
 static
 void cdfDefComplex(stream_t *streamptr, int gridID)
 {
@@ -1140,9 +1114,8 @@ void cdfDefComplex(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->xdimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefSP(stream_t *streamptr, int gridID)
 {
@@ -1200,9 +1173,8 @@ void cdfDefSP(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->ydimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefFC(stream_t *streamptr, int gridID)
 {
@@ -1257,9 +1229,8 @@ void cdfDefFC(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->ydimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefTrajLon(stream_t *streamptr, int gridID)
 {
@@ -1314,9 +1285,8 @@ void cdfDefTrajLon(stream_t *streamptr, int gridID)
 
   streamptr->xdimID[gridindex] = ncvarid; /* var ID for trajectory !!! */
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefTrajLat(stream_t *streamptr, int gridID)
 {
@@ -1371,9 +1341,8 @@ void cdfDefTrajLat(stream_t *streamptr, int gridID)
 
   streamptr->ydimID[gridindex] = ncvarid; /* var ID for trajectory !!! */
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 int checkGridName(int type, char *axisname, int fileID, int vlistID, int gridID, int ngrids, int mode)
 {
@@ -1435,9 +1404,8 @@ int checkGridName(int type, char *axisname, int fileID, int vlistID, int gridID,
 
   return (iz);
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims)
 {
@@ -1566,9 +1534,8 @@ void cdfDefXaxis(stream_t *streamptr, int gridID, int ndims)
 
   streamptr->xdimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims)
 {
@@ -1697,9 +1664,8 @@ void cdfDefYaxis(stream_t *streamptr, int gridID, int ndims)
 
   streamptr->ydimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfGridCompress(int fileID, int ncvarid, int gridsize, int filetype, int comptype)
 {
@@ -1711,9 +1677,8 @@ void cdfGridCompress(int fileID, int ncvarid, int gridsize, int filetype, int co
     }
 #endif
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefCurvilinear(stream_t *streamptr, int gridID)
 {
@@ -1902,9 +1867,8 @@ void cdfDefCurvilinear(stream_t *streamptr, int gridID)
   streamptr->ncyvarID[gridindex] = ncyvarid;
   streamptr->ncavarID[gridindex] = ncavarid;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefRgrid(stream_t *streamptr, int gridID)
 {
@@ -1968,9 +1932,8 @@ void cdfDefRgrid(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->xdimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefGdim(stream_t *streamptr, int gridID)
 {
@@ -2052,9 +2015,8 @@ void cdfDefGdim(stream_t *streamptr, int gridID)
   gridindex = vlistGridIndex(vlistID, gridID);
   streamptr->xdimID[gridindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefGridReference(stream_t *streamptr, int gridID)
 {
@@ -2079,10 +2041,10 @@ void cdfDefGridReference(stream_t *streamptr, int gridID)
 static
 void cdfDefGridUUID(stream_t *streamptr, int gridID)
 {
-  char uuidOfHGrid[17];
+  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
 
   gridInqUUID(gridID, uuidOfHGrid);
-  if ( uuidOfHGrid[0] != 0 )
+  if ( !cdiUUIDIsNull(uuidOfHGrid) )
     {
       char uuidOfHGridStr[37];
       uuid2str(uuidOfHGrid, uuidOfHGridStr);
@@ -2099,7 +2061,7 @@ void cdfDefGridUUID(stream_t *streamptr, int gridID)
 static
 void cdfDefZaxisUUID(stream_t *streamptr, int zaxisID)
 {
-  char uuidOfVGrid[17];
+  unsigned char uuidOfVGrid[CDI_UUID_SIZE];
   zaxisInqUUID(zaxisID, uuidOfVGrid);
 
   if ( uuidOfVGrid[0] != 0 )
@@ -2284,9 +2246,8 @@ void cdfDefUnstructured(stream_t *streamptr, int gridID)
   streamptr->ncyvarID[gridindex] = ncyvarid;
   streamptr->ncavarID[gridindex] = ncavarid;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefVCT(stream_t *streamptr, int zaxisID)
 {
@@ -2371,9 +2332,8 @@ void cdfDefVCT(stream_t *streamptr, int zaxisID)
         }
     }
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefZaxis(stream_t *streamptr, int zaxisID)
 {
@@ -2641,9 +2601,8 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
   if ( dimID != UNDEFID )
     streamptr->zaxisID[zaxisindex] = dimID;
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefPole(stream_t *streamptr, int gridID)
 {
@@ -2674,9 +2633,8 @@ void cdfDefPole(stream_t *streamptr, int gridID)
 
   cdf_enddef(fileID);
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefMapping(stream_t *streamptr, int gridID)
 {
@@ -2764,9 +2722,8 @@ void cdfDefMapping(stream_t *streamptr, int gridID)
       cdf_enddef(fileID);
     }
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfDefGrid(stream_t *streamptr, int gridID)
 {
@@ -2869,9 +2826,8 @@ void cdfDefGrid(stream_t *streamptr, int gridID)
       Error("Unsupported grid type: %s", gridNamePtr(gridtype));
     }
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 int cdfDefVar(stream_t *streamptr, int varID)
 {
@@ -3377,9 +3333,7 @@ void scale_add(size_t size, double *data, double addoffset, double scalefactor)
         }
     }
 }
-#endif
 
-#if defined (HAVE_LIBNETCDF)
 static
 void cdfGetSlapDescription(stream_t *streamptr, int varID, size_t (*start)[4], size_t (*count)[4])
 {
@@ -3427,17 +3381,64 @@ void cdfGetSlapDescription(stream_t *streamptr, int varID, size_t (*start)[4], s
 }
 
 //Scans the data array for missVals, optionally applying first a scale factor and then an offset.
-//Returns the number of missVals encountered.
+//Returns the number of missing + out-of-range values encountered.
 static
-size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool haveMissval, double missVal, double scaleFactor, double offset)
+size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool haveMissVal, double missVal, double scaleFactor, double offset, double validMin, double validMax)
  {
   const bool haveOffset   = IS_NOT_EQUAL(offset, 0);
   const bool haveScaleFactor = IS_NOT_EQUAL(scaleFactor, 1);
   size_t missValCount = 0;
+  if (validMin == VALIDMISS)
+    validMin = DBL_MIN;
+  if (validMax == VALIDMISS)
+    validMax = DBL_MAX;
+
+  bool haveRangeCheck = (validMax != DBL_MAX) | (validMin != DBL_MIN);
+  assert(!haveRangeCheck || haveMissVal);
 
-  switch ((int)haveMissval | ((int)haveScaleFactor << 1) | ((int)haveOffset << 2))
+  switch ((int)haveMissVal | ((int)haveScaleFactor << 1)
+          | ((int)haveOffset << 2) | ((int)haveRangeCheck << 3))
     {
-    case 7: /* haveMissval & haveScaleFactor & haveOffset */
+    case 15: /* haveRangeCheck & haveMissVal & haveScaleFactor & haveOffset */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? missVal
+            : isMissVal ? data[i] : data[i] * scaleFactor + offset;
+        }
+      break;
+    case 13: /* haveRangeCheck & haveMissVal & haveOffset */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? missVal
+            : isMissVal ? data[i] : data[i] + offset;
+        }
+      break;
+    case 11: /* haveRangeCheck & haveMissVal & haveScaleFactor */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? missVal
+            : isMissVal ? data[i] : data[i] * scaleFactor;
+        }
+      break;
+    case 9: /* haveRangeCheck & haveMissVal */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? missVal : data[i];
+        }
+      break;
+    case 7: /* haveMissVal & haveScaleFactor & haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
@@ -3448,7 +3449,7 @@ size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool have
       for ( size_t i = 0; i < valueCount; i++ )
         data[i] = data[i] * scaleFactor + offset;
       break;
-    case 5: /* haveMissval & haveOffset */
+    case 5: /* haveMissVal & haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
@@ -3459,7 +3460,7 @@ size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool have
       for ( size_t i = 0; i < valueCount; i++ )
         data[i] += offset;
       break;
-    case 3: /* haveMissval & haveScaleFactor */
+    case 3: /* haveMissVal & haveScaleFactor */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
@@ -3470,9 +3471,9 @@ size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool have
       for ( size_t i = 0; i < valueCount; i++ )
         data[i] *= scaleFactor;
       break;
-    case 1: /* haveMissval */
+    case 1: /* haveMissVal */
       for ( size_t i = 0; i < valueCount; i++ )
-        missValCount += DBL_IS_EQUAL(data[i], missVal);
+        missValCount += (unsigned)DBL_IS_EQUAL(data[i], missVal);
       break;
     }
 
@@ -3480,58 +3481,104 @@ size_t cdfDoInputDataTransformationDP(size_t valueCount, double *data, bool have
 }
 
 static
-size_t cdfDoInputDataTransformationSP(size_t valueCount, float *data, bool haveMissval, double missVal, double scaleFactor, double offset)
+size_t cdfDoInputDataTransformationSP(size_t valueCount, float *data, bool haveMissVal, double missVal, double scaleFactor, double offset, double validMin, double validMax)
  {
   const bool haveOffset   = IS_NOT_EQUAL(offset, 0);
   const bool haveScaleFactor = IS_NOT_EQUAL(scaleFactor, 1);
   size_t missValCount = 0;
 
-  switch ((int)haveMissval | ((int)haveScaleFactor << 1) | ((int)haveOffset << 2))
+  if (validMin == VALIDMISS)
+    validMin = DBL_MIN;
+  if (validMax == VALIDMISS)
+    validMax = DBL_MAX;
+
+  bool haveRangeCheck = (validMax != DBL_MAX) | (validMin != DBL_MIN);
+  assert(!haveRangeCheck || haveMissVal);
+
+  switch ((int)haveMissVal | ((int)haveScaleFactor << 1)
+          | ((int)haveOffset << 2) | ((int)haveRangeCheck << 3))
     {
-    case 7: /* haveMissval & haveScaleFactor & haveOffset */
+    case 15: /* haveRangeCheck & haveMissVal & haveScaleFactor & haveOffset */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? (float)missVal
+            : isMissVal ? data[i] : (float)(data[i] * scaleFactor + offset);
+        }
+      break;
+    case 13: /* haveRangeCheck & haveMissVal & haveOffset */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? (float)missVal
+            : isMissVal ? data[i] : (float)(data[i] + offset);
+        }
+      break;
+    case 11: /* haveRangeCheck & haveMissVal & haveScaleFactor */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? (float)missVal
+            : isMissVal ? data[i] : (float)(data[i] * scaleFactor);
+        }
+      break;
+    case 9: /* haveRangeCheck & haveMissVal */
+      for ( size_t i = 0; i < valueCount; i++ )
+        {
+          int outOfRange = data[i] < validMin || data[i] > validMax;
+          int isMissVal = DBL_IS_EQUAL(data[i], missVal);
+          missValCount += (outOfRange | isMissVal);
+          data[i] = outOfRange ? (float)missVal : data[i];
+        }
+      break;
+    case 7: /* haveMissVal & haveScaleFactor & haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
         else
-          data[i] = data[i] * scaleFactor + offset;
+          data[i] = (float)(data[i] * scaleFactor + offset);
       break;
     case 6: /* haveOffset & haveScaleFactor */
       for ( size_t i = 0; i < valueCount; i++ )
-        data[i] = data[i] * scaleFactor + offset;
+        data[i] = (float)(data[i] * scaleFactor + offset);
       break;
-    case 5: /* haveMissval & haveOffset */
+    case 5: /* haveMissVal & haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
         else
-          data[i] += offset;
+          data[i] = (float)(data[i] + offset);
       break;
     case 4: /* haveOffset */
       for ( size_t i = 0; i < valueCount; i++ )
-        data[i] += offset;
+        data[i] = (float)(data[i] + offset);
       break;
-    case 3: /* haveMissval & haveScaleFactor */
+    case 3: /* haveMissVal & haveScaleFactor */
       for ( size_t i = 0; i < valueCount; i++ )
         if ( DBL_IS_EQUAL(data[i], missVal) )
           missValCount++;
         else
-          data[i] *= scaleFactor;
+          data[i] = (float)(data[i] * scaleFactor);
       break;
     case 2: /* haveScaleFactor */
       for ( size_t i = 0; i < valueCount; i++ )
-        data[i] *= scaleFactor;
+        data[i] = (float)(data[i] * scaleFactor);
       break;
-    case 1: /* haveMissval */
+    case 1: /* haveMissVal */
       for ( size_t i = 0; i < valueCount; i++ )
-        missValCount += DBL_IS_EQUAL(data[i], missVal);
+        missValCount += (unsigned)DBL_IS_EQUAL(data[i], missVal);
       break;
     }
 
   return missValCount;
 }
-#endif
 
-#if defined(HAVE_LIBNETCDF)
 static void
 cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtype, long nvals, size_t xsize, size_t ysize, int swapxy, size_t *start, size_t *count, int memtype, const void *data, int nmiss)
 {
@@ -3573,7 +3620,7 @@ cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtype, l
                         {
                           if ( laddoffset )   temp -= addoffset;
                           if ( lscalefactor ) temp /= scalefactor;
-                          mdata_sp[i] = temp;
+                          mdata_sp[i] = (float)temp;
                         }
                     }
                 }
@@ -3584,7 +3631,7 @@ cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtype, l
                       double temp = mdata_sp[i];
                       if ( laddoffset )   temp -= addoffset;
                       if ( lscalefactor ) temp /= scalefactor;
-                      mdata_sp[i] = temp;
+                      mdata_sp[i] = (float)temp;
                     }
                 }
             }
@@ -3715,9 +3762,8 @@ cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtype, l
   if ( mdata_sp ) free(mdata_sp);
   if ( sdata_sp ) free(sdata_sp);
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 void cdf_write_var(stream_t *streamptr, int varID, int memtype, const void *data, int nmiss)
 {
   int fileID;
@@ -3816,9 +3862,8 @@ void cdf_write_var(stream_t *streamptr, int varID, int memtype, const void *data
   cdf_write_var_data(fileID, vlistID, varID, ncvarid, dtype, nvals, xsize, ysize, swapxy, start, count, memtype, data, nmiss);
 
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
                          const int rect[][2], const void *data, int nmiss)
 {
@@ -3892,7 +3937,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
       size_t size;
       cdf_inq_dimlen(fileID, yid, &size);
       xassert(rect[1][0] >= 0 && rect[1][0] <= rect[1][1]
-              && rect[1][1] <= (int)size);
+              && (size_t)rect[1][1] <= size);
       start[ndims] = (size_t)rect[1][0];
       count[ndims] = (size_t)rect[1][1] - (size_t)rect[1][0] + 1;
       ndims++;
@@ -3902,7 +3947,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
       size_t size;
       cdf_inq_dimlen(fileID, xid, &size);
       xassert(rect[0][0] >= 0 && rect[0][0] <= rect[0][1]
-              && rect[0][1] <= (int)size);
+              && (size_t)rect[0][1] <= size);
       start[ndims] = (size_t)rect[0][0];
       count[ndims] = (size_t)rect[0][1] - (size_t)rect[0][0] + 1;
       ndims++;
@@ -3927,110 +3972,8 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
   cdf_write_var_data(fileID, vlistID, varID, ncvarid, dtype, nvals,
                      xsize, ysize, swapxy, start, count, memtype, data, nmiss);
 }
-#endif
-
-#if  defined  (HAVE_LIBNETCDF)
-static
-int set_validrangeDP(long gridsize, double *data, double missval, double validmin, double validmax)
-{
-  long i;
-  int nmiss = 0;
-  /*
-  for ( i = 0; i < gridsize; i++, data++ )
-    {
-      if ( IS_NOT_EQUAL(validmin, VALIDMISS) && (*data) < validmin ) *data = missval;
-      if ( IS_NOT_EQUAL(validmax, VALIDMISS) && (*data) > validmax ) *data = missval;
-      if ( DBL_IS_EQUAL((*data), missval) ) nmiss++;
-    }
-  */
-  // 21/01/2014 Florian Prill: SX-9 vectorization
-
-  if ( IS_NOT_EQUAL(validmin, VALIDMISS) && !IS_NOT_EQUAL(validmax, VALIDMISS) )
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if ( (*data) < validmin )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else if ( IS_NOT_EQUAL(validmax, VALIDMISS) && !IS_NOT_EQUAL(validmin, VALIDMISS))
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if ( (*data) > validmax )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else if ( IS_NOT_EQUAL(validmin, VALIDMISS) && IS_NOT_EQUAL(validmax, VALIDMISS))
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if      ( (*data) < validmin )  { (*data) = missval; nmiss++; }
-          else if ( (*data) > validmax )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        if ( DBL_IS_EQUAL((*data), missval) ) nmiss++;
-    }
-
-  return (nmiss);
-}
 
 static
-int set_validrangeSP(long gridsize, float *data, double missval, double validmin, double validmax)
-{
-  long i;
-  int nmiss = 0;
-  /*
-  for ( i = 0; i < gridsize; i++, data++ )
-    {
-      if ( IS_NOT_EQUAL(validmin, VALIDMISS) && (*data) < validmin ) *data = missval;
-      if ( IS_NOT_EQUAL(validmax, VALIDMISS) && (*data) > validmax ) *data = missval;
-      if ( DBL_IS_EQUAL((*data), missval) ) nmiss++;
-    }
-  */
-  // 21/01/2014 Florian Prill: SX-9 vectorization
-
-  if ( IS_NOT_EQUAL(validmin, VALIDMISS) && !IS_NOT_EQUAL(validmax, VALIDMISS) )
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if ( (*data) < validmin )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else if ( IS_NOT_EQUAL(validmax, VALIDMISS) && !IS_NOT_EQUAL(validmin, VALIDMISS))
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if ( (*data) > validmax )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else if ( IS_NOT_EQUAL(validmin, VALIDMISS) && IS_NOT_EQUAL(validmax, VALIDMISS))
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        {
-          if      ( (*data) < validmin )  { (*data) = missval; nmiss++; }
-          else if ( (*data) > validmax )  { (*data) = missval; nmiss++; }
-          else if ( DBL_IS_EQUAL((*data), missval) )  nmiss++;
-        } // i
-    }
-  else
-    {
-      for ( i = 0; i < gridsize; i++, data++ )
-        if ( DBL_IS_EQUAL((*data), missval) ) nmiss++;
-    }
-
-  return (nmiss);
-}
-#endif
-
-#if  defined  (HAVE_LIBNETCDF)
-static
 size_t min_size(size_t a, size_t b)
 {
   return a < b ? a : b;
@@ -4039,14 +3982,19 @@ size_t min_size(size_t a, size_t b)
 static
 void transpose2dArrayDP(size_t inWidth, size_t inHeight, double* data)
 {
-  const size_t cacheBlockSize = 32;    // Purely an optimization parameter. Current value of 32 means we are handling 8kB blocks,
+  const size_t cacheBlockSize = 256;    // Purely an optimization parameter. Current value of 32 means we are handling 8kB blocks,
                                        // which should be a decent compromise on many architectures.
   double (*temp)[inWidth] = malloc(inHeight*sizeof(*temp));
   double (*out)[inHeight] = (double (*)[inHeight])data;
   memcpy(temp, data, inHeight*sizeof(*temp));
-  for ( size_t yBlock = 0; yBlock < inHeight; yBlock++ )
+  /*
+  for ( size_t y = 0; y < inHeight; ++y )
+    for ( size_t x = 0; x < inWidth; ++x )
+      out[x][y] = temp[y][x];
+  */
+  for ( size_t yBlock = 0; yBlock < inHeight; yBlock += cacheBlockSize )
     {
-      for ( size_t xBlock = 0; xBlock < inWidth; xBlock++ )
+      for ( size_t xBlock = 0; xBlock < inWidth; xBlock += cacheBlockSize )
         {
           for ( size_t y = yBlock, yEnd = min_size(yBlock + cacheBlockSize, inHeight); y < yEnd; y++ )
             {
@@ -4057,20 +4005,26 @@ void transpose2dArrayDP(size_t inWidth, size_t inHeight, double* data)
             }
         }
     }
+
   free(temp);
 }
 
 static
 void transpose2dArraySP(size_t inWidth, size_t inHeight, float* data)
 {
-  const size_t cacheBlockSize = 32;    // Purely an optimization parameter. Current value of 32 means we are handling 8kB blocks,
+  const size_t cacheBlockSize = 256;    // Purely an optimization parameter. Current value of 32 means we are handling 8kB blocks,
                                        // which should be a decent compromise on many architectures.
   float (*temp)[inWidth] = malloc(inHeight*sizeof(*temp));
   float (*out)[inHeight] = (float (*)[inHeight])data;
   memcpy(temp, data, inHeight*sizeof(*temp));
-  for ( size_t yBlock = 0; yBlock < inHeight; yBlock++ )
+  /*
+  for ( size_t y = 0; y < inHeight; ++y )
+    for ( size_t x = 0; x < inWidth; ++x )
+      out[x][y] = temp[y][x];
+  */
+  for ( size_t yBlock = 0; yBlock < inHeight; yBlock += cacheBlockSize )
     {
-      for ( size_t xBlock = 0; xBlock < inWidth; xBlock++ )
+      for ( size_t xBlock = 0; xBlock < inWidth; xBlock += cacheBlockSize )
         {
           for ( size_t y = yBlock, yEnd = min_size(yBlock + cacheBlockSize, inHeight); y < yEnd; y++ )
             {
@@ -4081,6 +4035,7 @@ void transpose2dArraySP(size_t inWidth, size_t inHeight, float* data)
             }
         }
     }
+
   free(temp);
 }
 
@@ -4215,11 +4170,9 @@ void cdfGetSliceSlapDescription(stream_t *streamptr, int varId, int levelId, boo
   if ( nvdims != ndims )
     Error("Internal error, variable %s has an unsupported array structure!", vlistInqVarNamePtr(vlistId, varId));
 }
-#endif
 
 void cdfReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
   if ( CDI_Debug ) Message("streamID = %d  varID = %d", streamptr->self, varID);
 
   int vlistID = streamptr->vlistID;
@@ -4236,28 +4189,21 @@ void cdfReadVarDP(stream_t *streamptr, int varID, double *data, int *nmiss)
 
   cdf_get_vara_double(fileID, ncvarid, start, count, data);
 
-  size_t size = (size_t)gridInqSize(gridID)*zaxisInqSize(zaxisID);
+  size_t size = (size_t)gridInqSize(gridID)*(size_t)zaxisInqSize(zaxisID);
   double missval = vlistInqVarMissval(vlistID, varID);
-  const bool haveMissval = vlistInqVarMissvalUsed(vlistID, varID);
-  if ( haveMissval )
-    {
-      double validrange[2];
-      if ( vlistInqVarValidrange(vlistID, varID, validrange) )
-        *nmiss = set_validrangeDP(size, data, missval, validrange[0], validrange[1]);
-      else
-        *nmiss = cdfDoInputDataTransformationDP(size, data, haveMissval, missval, 1, 0);
-    }
-
+  const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
+  double validRange[2];
+  if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
+    validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
   double addoffset   = vlistInqVarAddoffset(vlistID, varID);
   double scalefactor = vlistInqVarScalefactor(vlistID, varID);
-  (void) cdfDoInputDataTransformationDP(size, data, haveMissval, missval, scalefactor, addoffset);
-#endif
+  size_t nmiss_ = cdfDoInputDataTransformationDP(size, data, haveMissVal, missval, scalefactor, addoffset, validRange[0], validRange[1]);
+  assert(nmiss_ <= INT_MAX);
+  *nmiss = (int)nmiss_;
 }
 
-
 void cdfReadVarSP(stream_t *streamptr, int varID, float *data, int *nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
   if ( CDI_Debug ) Message("streamID = %d  varID = %d", streamptr->self, varID);
 
   int vlistID = streamptr->vlistID;
@@ -4276,26 +4222,19 @@ void cdfReadVarSP(stream_t *streamptr, int varID, float *data, int *nmiss)
 
   size_t size = (size_t)gridInqSize(gridID)*zaxisInqSize(zaxisID);
   double missval = vlistInqVarMissval(vlistID, varID);
-  const bool haveMissval = vlistInqVarMissvalUsed(vlistID, varID);
-  if ( haveMissval )
-    {
-      double validrange[2];
-      if ( vlistInqVarValidrange(vlistID, varID, validrange) )
-        *nmiss = set_validrangeSP(size, data, missval, validrange[0], validrange[1]);
-      else
-        *nmiss = cdfDoInputDataTransformationSP(size, data, haveMissval, missval, 1, 0);
-    }
-
-  double addoffset    = vlistInqVarAddoffset(vlistID, varID);
-  double scalefactor  = vlistInqVarScalefactor(vlistID, varID);
-  (void) cdfDoInputDataTransformationSP(size, data, haveMissval, missval, scalefactor, addoffset);
-#endif
+  const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
+  double validRange[2];
+  if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
+    validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
+  double addoffset   = vlistInqVarAddoffset(vlistID, varID);
+  double scalefactor = vlistInqVarScalefactor(vlistID, varID);
+  size_t nmiss_ = cdfDoInputDataTransformationSP(size, data, haveMissVal, missval, scalefactor, addoffset, validRange[0], validRange[1]);
+  assert(nmiss_ <= INT_MAX);
+  *nmiss = (int)nmiss_;
 }
 
 void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data, int *nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int i;
   size_t start[4];
   size_t count[4];
 
@@ -4310,15 +4249,15 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data
 
   int ncvarid = streamptr->vars[varID].ncvarid;
   int gridId = vlistInqVarGrid(vlistID, varID);
-  int gridsize = gridInqSize(gridId);
-  int xsize = gridInqXsize(gridId);
-  int ysize = gridInqYsize(gridId);
+  size_t gridsize = (size_t)gridInqSize(gridId);
+  size_t xsize = (size_t)gridInqXsize(gridId);
+  size_t ysize = (size_t)gridInqYsize(gridId);
 
   if ( vlistInqVarDatatype(vlistID, varID) == DATATYPE_FLT32 )
     {
-      float *data_fp = malloc(gridsize*sizeof(*data_fp));
+      float *data_fp = (float *)xmalloc(gridsize*sizeof(*data_fp));
       cdf_get_vara_float(fileID, ncvarid, start, count, data_fp);
-      for ( i = 0; i < gridsize; i++ )
+      for ( size_t i = 0; i < gridsize; i++ )
         data[i] = (double) data_fp[i];
       free(data_fp);
     }
@@ -4328,7 +4267,7 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data
       cdf_inq_vartype(fileID, ncvarid, &xtype);
       if ( xtype == NC_BYTE )
         {
-          for ( i = 0; i < gridsize; i++ )
+          for ( size_t i = 0; i < gridsize; i++ )
             if ( data[i] < 0 ) data[i] += 256;
         }
     }
@@ -4337,31 +4276,23 @@ void cdfReadVarSliceDP(stream_t *streamptr, int varID, int levelID, double *data
       cdf_get_vara_double(fileID, ncvarid, start, count, data);
     }
 
-  if ( swapxy ) transpose2dArrayDP(xsize, ysize, data);
+  if ( swapxy ) transpose2dArrayDP(ysize, xsize, data);
 
-  *nmiss = 0;
   double missval = vlistInqVarMissval(vlistID, varID);
-  const bool haveMissval = vlistInqVarMissvalUsed(vlistID, varID);
-  if ( haveMissval )
-    {
-      double validrange[2];
-      if ( vlistInqVarValidrange(vlistID, varID, validrange) )
-        *nmiss = set_validrangeDP(gridsize, data, missval, validrange[0], validrange[1]);
-      else
-        *nmiss = cdfDoInputDataTransformationDP(gridsize, data, haveMissval, missval, 1, 0);
-    }
-
-  double addoffset = vlistInqVarAddoffset(vlistID, varID);
+  const bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
+  double validRange[2];
+  if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
+    validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
+  double addoffset   = vlistInqVarAddoffset(vlistID, varID);
   double scalefactor = vlistInqVarScalefactor(vlistID, varID);
-  (void) cdfDoInputDataTransformationDP(gridsize, data, haveMissval, missval, scalefactor, addoffset);
-#endif
+  size_t nmiss_ = cdfDoInputDataTransformationDP(gridsize, data, haveMissVal, missval, scalefactor, addoffset, validRange[0], validRange[1]);
+  assert(nmiss_ <= INT_MAX);
+  *nmiss = (int)nmiss_;
 }
 
 
 void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data, int *nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int i;
   size_t start[4];
   size_t count[4];
 
@@ -4376,15 +4307,15 @@ void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data,
 
   int ncvarid = streamptr->vars[varID].ncvarid;
   int gridId = vlistInqVarGrid(vlistID, varID);
-  int gridsize = gridInqSize(gridId);
-  int xsize = gridInqXsize(gridId);
-  int ysize = gridInqYsize(gridId);
+  size_t gridsize = (size_t)gridInqSize(gridId);
+  size_t xsize = (size_t)gridInqXsize(gridId);
+  size_t ysize = (size_t)gridInqYsize(gridId);
 
   if ( vlistInqVarDatatype(vlistID, varID) == DATATYPE_FLT64 )
     {
-      double *data_dp = malloc(gridsize*sizeof(*data_dp));
+      double *data_dp = (double *)xmalloc(gridsize*sizeof(*data_dp));
       cdf_get_vara_double(fileID, ncvarid, start, count, data_dp);
-      for ( i = 0; i < gridsize; i++ )
+      for ( size_t i = 0; i < gridsize; i++ )
         data[i] = (float) data_dp[i];
       free(data_dp);
     }
@@ -4394,7 +4325,7 @@ void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data,
       cdf_inq_vartype(fileID, ncvarid, &xtype);
       if ( xtype == NC_BYTE )
         {
-          for ( i = 0; i < gridsize; i++ )
+          for ( size_t i = 0; i < gridsize; i++ )
             if ( data[i] < 0 ) data[i] += 256;
         }
     }
@@ -4403,30 +4334,23 @@ void cdfReadVarSliceSP(stream_t *streamptr, int varID, int levelID, float *data,
       cdf_get_vara_float(fileID, ncvarid, start, count, data);
     }
 
-  if ( swapxy ) transpose2dArraySP(xsize, ysize, data);
+  if ( swapxy ) transpose2dArraySP(ysize, xsize, data);
 
-  *nmiss = 0;
   double missval = vlistInqVarMissval(vlistID, varID);
-  bool haveMissval = vlistInqVarMissvalUsed(vlistID, varID);
-  if ( haveMissval )
-    {
-      double validrange[2];
-      if ( vlistInqVarValidrange(vlistID, varID, validrange) )
-        *nmiss = set_validrangeSP(gridsize, data, missval, validrange[0], validrange[1]);
-      else
-        *nmiss = cdfDoInputDataTransformationSP(gridsize, data, haveMissval, missval, 1, 0);
-    }
-
-  double addoffset = vlistInqVarAddoffset(vlistID, varID);
+  bool haveMissVal = vlistInqVarMissvalUsed(vlistID, varID);
+  double validRange[2];
+  if (!(haveMissVal && vlistInqVarValidrange(vlistID, varID, validRange)))
+    validRange[0] = DBL_MIN, validRange[1] = DBL_MAX;
+  double addoffset   = vlistInqVarAddoffset(vlistID, varID);
   double scalefactor = vlistInqVarScalefactor(vlistID, varID);
-  (void ) cdfDoInputDataTransformationSP(gridsize, data, haveMissval, missval, scalefactor, addoffset);
-#endif
+  size_t nmiss_ = cdfDoInputDataTransformationSP(gridsize, data, haveMissVal, missval, scalefactor, addoffset, validRange[0], validRange[1]);
+  assert(nmiss_ <= INT_MAX);
+  *nmiss = (int)nmiss_;
 }
 
 
 void cdf_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtype, const void *data, int nmiss)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int fileID;
   int gridID;
   int zaxisID;
@@ -4527,10 +4451,9 @@ void cdf_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtyp
 
   cdf_write_var_data(fileID, vlistID, varID, ncvarid, dtype, nvals, xsize, ysize, swapxy, start, count, memtype, data, nmiss);
 
-#endif
 }
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 void cdfCreateRecords(stream_t *streamptr, int tsID)
 {
@@ -4652,9 +4575,8 @@ void cdfCreateRecords(stream_t *streamptr, int tsID)
              (size_t)nvrecs * sizeof (int));
     }
 }
-#endif
 
-#if  defined  (HAVE_LIBNETCDF)
+
 static
 int cdfTimeDimID(int fileID, int ndims, int nvars)
 {
@@ -4799,25 +4721,26 @@ static
 int isLonAxis(const char *units, const char *stdname)
 {
   int status = FALSE;
-  char degree_units[16];
+  char lc_units[16];
 
-  memcpy(degree_units, units, 16);
-  degree_units[15] = 0;
-  strtolower(degree_units);
+  memcpy(lc_units, units, 15);
+  lc_units[15] = 0;
+  strtolower(lc_units);
 
-  if ( memcmp(degree_units, "degree", 6) == 0 )
+  if ( ((memcmp(lc_units, "degree", 6) == 0 || memcmp(lc_units, "radian", 6) == 0) &&
+        (memcmp(stdname, "grid_longitude", 14) == 0 || memcmp(stdname, "longitude", 9) == 0)) )
     {
-      int ioff = 6;
-      if ( degree_units[ioff] == 's' ) ioff++;
-      if ( degree_units[ioff] == '_' ) ioff++;
-      if ( degree_units[ioff] == 'e' ) status = TRUE;
+      status = TRUE;
     }
 
   if ( status == FALSE &&
-       ((memcmp(units, "degree", 6) == 0 ||memcmp(units, "radian", 6) == 0) &&
-        (memcmp(stdname, "grid_longitude", 14) == 0 || memcmp(stdname, "longitude", 9) == 0)) )
+       memcmp(stdname, "grid_latitude", 13) && memcmp(stdname, "latitude", 8) &&
+       memcmp(lc_units, "degree", 6) == 0 )
     {
-      status = TRUE;
+      int ioff = 6;
+      if ( lc_units[ioff] == 's' ) ioff++;
+      if ( lc_units[ioff] == '_' ) ioff++;
+      if ( lc_units[ioff] == 'e' ) status = TRUE;
     }
 
   return (status);
@@ -4827,25 +4750,26 @@ static
 int isLatAxis(const char *units, const char *stdname)
 {
   int status = FALSE;
-  char degree_units[16];
+  char lc_units[16];
 
-  memcpy(degree_units, units, 16);
-  degree_units[15] = 0;
-  strtolower(degree_units);
+  memcpy(lc_units, units, 15);
+  lc_units[15] = 0;
+  strtolower(lc_units);
 
-  if ( memcmp(degree_units, "degree", 6) == 0 )
+  if ( ((memcmp(lc_units, "degree", 6) == 0 || memcmp(lc_units, "radian", 6) == 0) &&
+        (memcmp(stdname, "grid_latitude", 13) == 0 || memcmp(stdname, "latitude", 8) == 0)) )
     {
-      int ioff = 6;
-      if ( degree_units[ioff] == 's' ) ioff++;
-      if ( degree_units[ioff] == '_' ) ioff++;
-      if ( degree_units[ioff] == 'n' ) status = TRUE;
+      status = TRUE;
     }
 
   if ( status == FALSE &&
-       ((memcmp(units, "degree", 6) == 0 || memcmp(units, "radian", 6) == 0) &&
-        (memcmp(stdname, "grid_latitude", 13) == 0 || memcmp(stdname, "latitude", 8) == 0)) )
+       memcmp(stdname, "grid_longitude", 14) && memcmp(stdname, "longitude", 9) &&
+       memcmp(lc_units, "degree", 6) == 0 )
     {
-      status = TRUE;
+      int ioff = 6;
+      if ( lc_units[ioff] == 's' ) ioff++;
+      if ( lc_units[ioff] == '_' ) ioff++;
+      if ( lc_units[ioff] == 'n' ) status = TRUE;
     }
 
   return (status);
@@ -5041,7 +4965,6 @@ void printNCvars(ncvar_t *ncvars, int nvars, const char *oname)
       fprintf(stderr, "%3d %3d  %-6s %s\n", ncvarid, ndim-3, axis, ncvars[ncvarid].name);
     }
 }
-#endif
 
 typedef struct
 {
@@ -5051,7 +4974,6 @@ typedef struct
 varinfo_t;
 
 
-#ifdef HAVE_LIBNETCDF
 static
 int cmpvarname(const void *s1, const void *s2)
 {
@@ -6015,9 +5937,37 @@ void copy_numeric_projatts(int gridID, int ncvarID, int ncfileID)
 }
 #endif
 
+static
+void grid_set_chunktype(grid_t *grid, ncvar_t *ncvar)
+{
+  if ( ncvar->chunked )
+    {
+      int ndims = ncvar->ndims;
+
+      if ( grid->type == GRID_UNSTRUCTURED )
+        {
+          if ( ncvar->chunks[ndims-1] == grid->size )
+            ncvar->chunktype = CHUNK_GRID;
+          else
+            ncvar->chunktype = CHUNK_AUTO;
+        }
+      else
+        {
+          if ( grid->xsize > 1 && grid->ysize > 1 && ndims > 1 &&
+               grid->xsize == ncvar->chunks[ndims-1] &&
+               grid->ysize == ncvar->chunks[ndims-2] )
+            ncvar->chunktype = CHUNK_GRID;
+          else if ( grid->xsize > 1 && grid->xsize == ncvar->chunks[ndims-1] )
+            ncvar->chunktype = CHUNK_LINES;
+          else
+            ncvar->chunktype = CHUNK_AUTO;
+        }
+    }
+}
+
 /* define all input grids */
 static
-void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, int timedimid, char *uuidOfHGrid, char *gridfile, int number_of_grid_used)
+void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, int timedimid, unsigned char *uuidOfHGrid, char *gridfile, int number_of_grid_used)
 {
   int ncvarid, ncvarid2;
   int ndims;
@@ -6634,41 +6584,19 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
 #if defined (PROJECTION_TEST)
 	  if ( proj.type == GRID_PROJECTION )
 	    {
-	      ncvars[ncvarid].gridID = varDefGrid(vlistID, proj, 1);
+	      ncvars[ncvarid].gridID = varDefGrid(vlistID, &proj, 1);
 	      copy_numeric_projatts(ncvars[ncvarid].gridID, ncvars[ncvarid].gmapid, ncvars[ncvarid].ncid);
 	    }
 	  else
 #endif
-	    ncvars[ncvarid].gridID = varDefGrid(vlistID, grid, 1);
+	    ncvars[ncvarid].gridID = varDefGrid(vlistID, &grid, 1);
 
           if ( grid.type == GRID_UNSTRUCTURED )
             {
               if ( gridfile[0] != 0 ) gridDefReference(ncvars[ncvarid].gridID, gridfile);
             }
 
-          if ( ncvars[ncvarid].chunked )
-            {
-              ndims = ncvars[ncvarid].ndims;
-
-              if ( grid.type == GRID_UNSTRUCTURED )
-                {
-                  if ( ncvars[ncvarid].chunks[ndims-1] == grid.size )
-                    ncvars[ncvarid].chunktype = CHUNK_GRID;
-                  else
-                    ncvars[ncvarid].chunktype = CHUNK_AUTO;
-                }
-              else
-                {
-                  if ( grid.xsize > 1 && grid.ysize > 1 && ndims > 1 &&
-                       grid.xsize == ncvars[ncvarid].chunks[ndims-1] &&
-                       grid.ysize == ncvars[ncvarid].chunks[ndims-2] )
-                    ncvars[ncvarid].chunktype = CHUNK_GRID;
-                  else if ( grid.xsize > 1 && grid.xsize == ncvars[ncvarid].chunks[ndims-1] )
-                    ncvars[ncvarid].chunktype = CHUNK_LINES;
-                  else
-                    ncvars[ncvarid].chunktype = CHUNK_AUTO;
-                }
-            }
+          if ( ncvars[ncvarid].chunked ) grid_set_chunktype(&grid, &ncvars[ncvarid]);
 
 	  gridindex = vlistGridIndex(vlistID, ncvars[ncvarid].gridID);
 	  streamptr->xdimID[gridindex] = xdimid;
@@ -6747,7 +6675,7 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
 /* define all input zaxes */
 static
 void define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars,
-		      size_t vctsize, double *vct, char *uuidOfVGrid)
+		      size_t vctsize, double *vct, unsigned char *uuidOfVGrid)
 {
   int ncvarid, ncvarid2;
   int i, ilev, ndims;
@@ -7072,15 +7000,14 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
 
       if ( ncvars[ncvarid].natts )
 	{
-	  int nvatts;
 	  int attnum;
 	  int iatt;
 	  nc_type attrtype;
 	  size_t attlen;
 	  char attname[CDI_MAX_NAME];
 	  const int attstringlen = 8192; char attstring[8192];
+	  int nvatts = ncvars[ncvarid].natts;
 
-	  nvatts = ncvars[ncvarid].natts;
 	  for ( iatt = 0; iatt < nvatts; iatt++ )
 	    {
 	      attnum = ncvars[ncvarid].atts[iatt];
@@ -7090,41 +7017,32 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
 
 	      if ( attrtype == NC_SHORT || attrtype == NC_INT )
 		{
-		  int *attint;
-		  attint = (int *) malloc(attlen*sizeof(int));
+		  int *attint = (int *) malloc(attlen*sizeof(int));
 		  cdfGetAttInt(ncid, ncvarid, attname, (int)attlen, attint);
 		  if ( attrtype == NC_SHORT )
 		    vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT16, (int)attlen, attint);
 		  else
 		    vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT32, (int)attlen, attint);
-		  if ( CDI_Debug )
-		    printf("int: %s.%s = %d\n", ncvars[ncvarid].name, attname, attint[0]);
 		  free(attint);
 		}
 	      else if ( attrtype == NC_FLOAT || attrtype == NC_DOUBLE )
 		{
-		  double *attflt;
-		  attflt = (double *) malloc(attlen*sizeof(double));
+		  double *attflt = (double *) malloc(attlen*sizeof(double));
 		  cdfGetAttDouble(ncid, ncvarid, attname, (int)attlen, attflt);
 		  if ( attrtype == NC_FLOAT )
 		    vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT32, (int)attlen, attflt);
 		  else
 		    vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT64, (int)attlen, attflt);
-		  if ( CDI_Debug )
-		    printf("flt: %s.%s = %g\n", ncvars[ncvarid].name, attname, attflt[0]);
 		  free(attflt);
 		}
 	      else if ( xtypeIsText(attrtype) )
 		{
 		  cdfGetAttText(ncid, ncvarid, attname, attstringlen-1, attstring);
 		  vlistDefAttTxt(vlistID, varID, attname, (int)attlen, attstring);
-		  if ( CDI_Debug )
-		    printf("txt: %s.%s = %s\n", ncvars[ncvarid].name, attname, attstring);
 		}
 	      else
 		{
-		  if ( CDI_Debug )
-		    printf("att: %s.%s = unknown\n", ncvars[ncvarid].name, attname);
+		  if ( CDI_Debug ) printf("att: %s.%s = unknown\n", ncvars[ncvarid].name, attname);
 		}
 	    }
 
@@ -7212,9 +7130,7 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
 }
 
 static
-void scan_global_attributes(int fileID, int vlistID, stream_t *streamptr, int ngatts,
-                            int *instID, int *modelID, int *ucla_les, char *uuidOfHGrid, char *uuidOfVGrid,
-                            char *gridfile, int *number_of_grid_used, char *fcreftime)
+void scan_global_attributes(int fileID, int vlistID, stream_t *streamptr, int ngatts, int *instID, int *modelID, int *ucla_les, unsigned char *uuidOfHGrid, unsigned char *uuidOfVGrid, char *gridfile, int *number_of_grid_used, char *fcreftime)
 {
   nc_type xtype;
   size_t attlen;
@@ -7461,11 +7377,9 @@ void find_time_vars(int nvars, ncvar_t *ncvars, ncdim_t *ncdims, int timedimid,
         }
     }
 }
-#endif
 
 int cdfInqContents(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int ndims, nvars, ngatts, unlimdimid;
   int ncvarid;
   int ncdimid;
@@ -7493,16 +7407,16 @@ int cdfInqContents(stream_t *streamptr)
   int vlistID;
   int format = 0;
   int ucla_les = FALSE;
-  char uuidOfHGrid[17];
-  char uuidOfVGrid[17];
+  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
+  unsigned char uuidOfVGrid[CDI_UUID_SIZE];
   char gridfile[8912];
   char fcreftime[CDI_MAX_NAME];
   int number_of_grid_used = UNDEFID;
 
-  uuidOfHGrid[0] = 0;
-  uuidOfVGrid[0] = 0;
-  gridfile[0]    = 0;
-  fcreftime[0]   = 0;
+  memset(uuidOfHGrid, 0, CDI_UUID_SIZE);
+  memset(uuidOfVGrid, 0, CDI_UUID_SIZE);
+  gridfile[0] = 0;
+  fcreftime[0] = 0;
 
   vlistID = streamptr->vlistID;
   fileID  = streamptr->fileID;
@@ -7967,12 +7881,9 @@ int cdfInqContents(stream_t *streamptr)
   /* free ncvars */
   free(ncvars);
 
-#endif
-
   return (0);
 }
 
-#if  defined  (HAVE_LIBNETCDF)
 static
 void wrf_read_timestep(int fileID, int nctimevarid, int tsID, taxis_t *taxis)
 {
@@ -8028,12 +7939,10 @@ double get_timevalue(int fileID, int nctimevarid, int tsID, timecache_t *tcache)
 
   return timevalue;
 }
-#endif
 
 int cdfInqTimestep(stream_t * streamptr, int tsID)
 {
   long nrecs = 0;
-#if  defined  (HAVE_LIBNETCDF)
   double timevalue;
   int fileID;
   taxis_t *taxis;
@@ -8105,14 +8014,12 @@ int cdfInqTimestep(stream_t * streamptr, int tsID)
   streamptr->curTsID = tsID;
   nrecs = streamptr->tsteps[tsID].nrecs;
 
-#endif
   return ((int) nrecs);
 }
 
 
 void cdfEndDef(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int varID;
   int nvars;
   int fileID;
@@ -8143,13 +8050,11 @@ void cdfEndDef(stream_t *streamptr)
 
       streamptr->accessmode = 1;
     }
-#endif
 }
 
 
-void cdfDefInstitut(stream_t *streamptr)
+static void cdfDefInstitut(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int fileID, instID;
   char *longname;
   size_t len;
@@ -8173,28 +8078,21 @@ void cdfDefInstitut(stream_t *streamptr)
 	    }
 	}
     }
-#endif
 }
 
 
-void cdfDefSource(stream_t *streamptr)
+static void cdfDefSource(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int fileID, modelID;
-  char *longname;
-  size_t len;
-  int vlistID;
-
-  vlistID = streamptr->vlistID;
-  fileID  = streamptr->fileID;
-  modelID = vlistInqModel(vlistID);
+  int vlistID = streamptr->vlistID;
+  int fileID  = streamptr->fileID;
+  int modelID = vlistInqModel(vlistID);
 
   if ( modelID != UNDEFID )
     {
-      longname = modelInqNamePtr(modelID);
+      const char *longname = modelInqNamePtr(modelID);
       if ( longname )
 	{
-	  len = strlen(longname);
+          size_t len = strlen(longname);
 	  if ( len > 0 )
 	    {
 	      if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
@@ -8203,13 +8101,11 @@ void cdfDefSource(stream_t *streamptr)
 	    }
 	}
     }
-#endif
 }
 
 
-void cdfDefGlobalAtts(stream_t *streamptr)
+static void cdfDefGlobalAtts(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int fileID, vlistID;
   int natts;
 
@@ -8230,21 +8126,13 @@ void cdfDefGlobalAtts(stream_t *streamptr)
   if ( natts > 0 && streamptr->ncmode == 2 ) cdf_enddef(fileID);
 
   streamptr->globalatts = 1;
-#endif
 }
 
 
-void cdfDefLocalAtts(stream_t *streamptr)
+static void cdfDefLocalAtts(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int varID, instID, fileID;
-  char *name;
-  size_t len;
-  int ncvarid;
-  int vlistID;
-
-  vlistID = streamptr->vlistID;
-  fileID  = streamptr->fileID;
+  int vlistID = streamptr->vlistID;
+  int fileID  = streamptr->fileID;
 
   if ( streamptr->localatts ) return;
   if ( vlistInqInstitut(vlistID) != UNDEFID ) return;
@@ -8253,68 +8141,53 @@ void cdfDefLocalAtts(stream_t *streamptr)
 
   if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
 
-  for ( varID = 0; varID < streamptr->nvars; varID++ )
+  for ( int varID = 0; varID < streamptr->nvars; varID++ )
     {
-      instID = vlistInqVarInstitut(vlistID, varID);
+      int instID = vlistInqVarInstitut(vlistID, varID);
       if ( instID != UNDEFID )
 	{
-          ncvarid = streamptr->vars[varID].ncvarid;
-  	  name = institutInqNamePtr(instID);
+          int ncvarid = streamptr->vars[varID].ncvarid;
+  	  const char *name = institutInqNamePtr(instID);
 	  if ( name )
 	    {
-	      len = strlen(name);
+              size_t len = strlen(name);
 	      cdf_put_att_text(fileID, ncvarid, "institution", len, name);
 	    }
 	}
       }
 
   if ( streamptr->ncmode == 2 ) cdf_enddef(fileID);
-#endif
 }
 
 
-void cdfDefHistory(stream_t *streamptr, int size, char *history)
+void cdfDefHistory(stream_t *streamptr, int size, const char *history)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int ncid;
-
-  ncid = streamptr->fileID;
+  int ncid = streamptr->fileID;
   cdf_put_att_text(ncid, NC_GLOBAL, "history", (size_t) size, history);
-#endif
 }
 
 
 int cdfInqHistorySize(stream_t *streamptr)
 {
   size_t size = 0;
-#if  defined  (HAVE_LIBNETCDF)
-  int ncid;
-
-  ncid = streamptr->fileID;
+  int ncid = streamptr->fileID;
   if ( streamptr->historyID != UNDEFID )
     cdf_inq_attlen(ncid, NC_GLOBAL, "history", &size);
 
-#endif
   return ((int) size);
 }
 
 
 void cdfInqHistoryString(stream_t *streamptr, char *history)
 {
-#if  defined  (HAVE_LIBNETCDF)
-  int ncid;
-
-  ncid = streamptr->fileID;
+  int ncid = streamptr->fileID;
   if ( streamptr->historyID != UNDEFID )
     cdf_get_att_text(ncid, NC_GLOBAL, "history", history);
-
-#endif
 }
 
 
 void cdfDefVars(stream_t *streamptr)
 {
-#if  defined  (HAVE_LIBNETCDF)
   int index, gridID, zaxisID, vlistID;
   int ngrids, nzaxis;
   /* int  nvars, ncvarid; */
@@ -8347,8 +8220,8 @@ void cdfDefVars(stream_t *streamptr)
       ncvarid = cdfDefVar(streamptr, varID);
     }
   */
-#endif
 }
+#endif
 /*
  * Local Variables:
  * c-file-style: "Java"
diff --git a/libcdi/src/stream_cdf.h b/libcdi/src/stream_cdf.h
index 08b71fb..47241e2 100644
--- a/libcdi/src/stream_cdf.h
+++ b/libcdi/src/stream_cdf.h
@@ -5,7 +5,7 @@ void   cdfDefVars(stream_t *streamptr);
 void   cdfDefTimestep(stream_t *streamptr, int tsID);
 int    cdfInqTimestep(stream_t *streamptr, int tsID);
 int    cdfInqContents(stream_t *streamptr);
-void   cdfDefHistory(stream_t *streamptr, int size, char *history);
+void   cdfDefHistory(stream_t *streamptr, int size, const char *history);
 int    cdfInqHistorySize(stream_t *streamptr);
 void   cdfInqHistoryString(stream_t *streamptr, char *history);
 
diff --git a/libcdi/src/stream_cgribex.c b/libcdi/src/stream_cgribex.c
index f17295a..767d599 100644
--- a/libcdi/src/stream_cgribex.c
+++ b/libcdi/src/stream_cgribex.c
@@ -387,7 +387,7 @@ void cgribexAddRecord(stream_t * streamptr, int param, int *isec1, int *isec2, d
 
   cgribexGetGrid(streamptr, isec2, isec4, &grid, iret);
 
-  int gridID = varDefGrid(vlistID, grid, 0);
+  int gridID = varDefGrid(vlistID, &grid, 0);
 
   int zaxistype = grib1ltypeToZaxisType(ISEC1_LevelType);
 
@@ -564,7 +564,7 @@ int cgribexScanTimestep1(stream_t * streamptr)
   int tsID;
   int varID;
   size_t readsize;
-  int nrecords, nrecs, recID;
+  unsigned nrecords, recID;
   int nrecs_scanned = 0;
   int datatype;
   long recsize = 0;
@@ -604,10 +604,10 @@ int cgribexScanTimestep1(stream_t * streamptr)
 	Error("Skipping of %d records failed!", cdiSkipRecords);
 
       recpos  = fileGetPos(fileID);
-      fileSetPos(fileID, recsize, SEEK_CUR);
+      fileSetPos(fileID, (off_t)recsize, SEEK_CUR);
     }
 
-  nrecs = 0;
+  unsigned nrecs = 0;
   while ( TRUE )
     {
       recsize = gribGetSize(fileID);
@@ -680,7 +680,7 @@ int cgribexScanTimestep1(stream_t * streamptr)
 
 	  for ( recID = 0; recID < nrecs; recID++ )
 	    {
-	      if ( cgribexVarCompare(compVar, streamptr->tsteps[0].records[recID], 1) == 0 ) break;
+	      if ( cgribexVarCompare(compVar, streamptr->tsteps[0].records[recID], 0) == 0 ) break;
 	    }
 
 	  if ( cdiInventoryMode == 1 )
@@ -754,18 +754,18 @@ int cgribexScanTimestep1(stream_t * streamptr)
   vlistID = streamptr->vlistID;
   vlistDefTaxis(vlistID, taxisID);
 
-  nrecords = streamptr->tsteps[0].nallrecs;
-  if ( nrecords < streamptr->tsteps[0].recordSize )
+  nrecords = (unsigned)streamptr->tsteps[0].nallrecs;
+  if ( nrecords < (unsigned)streamptr->tsteps[0].recordSize )
     {
-      streamptr->tsteps[0].recordSize = nrecords;
+      streamptr->tsteps[0].recordSize = (int)nrecords;
       streamptr->tsteps[0].records =
       (record_t *) realloc(streamptr->tsteps[0].records, nrecords*sizeof(record_t));
     }
 
   streamptr->tsteps[0].recIDs = (int *) malloc(nrecords*sizeof(int));
-  streamptr->tsteps[0].nrecs = nrecords;
+  streamptr->tsteps[0].nrecs = (int)nrecords;
   for ( recID = 0; recID < nrecords; recID++ )
-    streamptr->tsteps[0].recIDs[recID] = recID;
+    streamptr->tsteps[0].recIDs[recID] = (int)recID;
 
   streamptr->record->buffer     = gribbuffer;
   streamptr->record->buffersize = (size_t)buffersize;
@@ -854,7 +854,7 @@ int cgribexScanTimestep2(stream_t * streamptr)
   cdi_create_records(streamptr, tsID);
 
   nrecords = streamptr->tsteps[tsID].nallrecs;
-  if ( nrecords ) streamptr->tsteps[1].recIDs = (int *) malloc(nrecords*sizeof(int));
+  if ( nrecords ) streamptr->tsteps[1].recIDs = (int *)xmalloc((size_t)nrecords * sizeof(int));
   streamptr->tsteps[1].nrecs = 0;
   for ( recID = 0; recID < nrecords; recID++ )
     streamptr->tsteps[1].recIDs[recID] = -1;
@@ -2125,12 +2125,6 @@ void cgribexDefLevel(int *isec1, int *isec2, double *fsec2, int zaxisID, int lev
 }
 
 static
-void cgribexDefMask(int *isec3)
-{
-  UNUSED(isec3);
-}
-
-static
 void cgribexDefaultSec0(int *isec0)
 {
   ISEC0_GRIB_Len     = 0;
@@ -2216,7 +2210,6 @@ size_t cgribexEncode(int memtype, int varID, int levelID, int vlistID, int gridI
   cgribexDefTime(isec1, vdate, vtime, tsteptype, numavg, vlistInqTaxis(vlistID));
   cgribexDefGrid(isec1, isec2, isec4, gridID);
   cgribexDefLevel(isec1, isec2, fsec2, zaxisID, levelID);
-  cgribexDefMask(isec3);
 
   cgribexDefEnsembleVar(isec1, vlistID, varID);
 
diff --git a/libcdi/src/stream_ext.c b/libcdi/src/stream_ext.c
index 69f2e52..088e807 100644
--- a/libcdi/src/stream_ext.c
+++ b/libcdi/src/stream_ext.c
@@ -230,7 +230,7 @@ void extAddRecord(stream_t *streamptr, int param, int level, int xysize,
   grid.ysize = 0;
   grid.xvals = NULL;
   grid.yvals = NULL;
-  gridID = varDefGrid(vlistID, grid, 0);
+  gridID = varDefGrid(vlistID, &grid, 0);
   /*
   if ( level == 0 ) leveltype = ZAXIS_SURFACE;
   else              leveltype = ZAXIS_GENERIC;
diff --git a/libcdi/src/stream_grb.c b/libcdi/src/stream_grb.c
index 5cf0f08..42b03af 100644
--- a/libcdi/src/stream_grb.c
+++ b/libcdi/src/stream_grb.c
@@ -206,9 +206,14 @@ int grbDecode(int filetype, unsigned char *gribbuffer, int gribsize, double *dat
     }
   else
 #endif
+#ifdef HAVE_LIBGRIB_API
+    status = gribapiDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, missval, vlistID, varID);
+#else
     {
-      status = gribapiDecode(gribbuffer, gribsize, data, gridsize, unreduced, nmiss, missval, vlistID, varID);
+      (void)vlistID; (void)varID;
+      Error("GRIB_API support not compiled in!");
     }
+#endif
 
   return (status);
 }
@@ -324,7 +329,7 @@ int grbScanTimestep1(stream_t * streamptr)
 static
 int grbScanTimestep2(stream_t * streamptr)
 {
-  int status;
+  int status = 0;
   int filetype;
 
   filetype  = streamptr->filetype;
@@ -334,11 +339,13 @@ int grbScanTimestep2(stream_t * streamptr)
     {
       status = cgribexScanTimestep2(streamptr);
     }
+#endif
+#if defined(HAVE_LIBCGRIBEX) && defined (HAVE_LIBGRIB_API)
   else
 #endif
-    {
-      status = gribapiScanTimestep2(streamptr);
-    }
+#ifdef HAVE_LIBGRIB_API
+    status = gribapiScanTimestep2(streamptr);
+#endif
 
   return (status);
 }
@@ -346,7 +353,7 @@ int grbScanTimestep2(stream_t * streamptr)
 static
 int grbScanTimestep(stream_t * streamptr)
 {
-  int status;
+  int status = CDI_EUFTYPE;
   int filetype;
 
   filetype  = streamptr->filetype;
@@ -358,9 +365,11 @@ int grbScanTimestep(stream_t * streamptr)
     }
   else
 #endif
-    {
-      status = gribapiScanTimestep(streamptr);
-    }
+#ifdef HAVE_LIBGRIB_API
+    status = gribapiScanTimestep(streamptr);
+#else
+    Error("Sufficient GRIB support unavailable!");
+#endif
 
   return (status);
 }
@@ -511,7 +520,7 @@ size_t grbEncode(int filetype, int memtype, int varID, int levelID, int vlistID,
 		 size_t datasize, const double *data, int nmiss, unsigned char **gribbuffer,
 		 int comptype, void *gribContainer)
 {
-  size_t nbytes;
+  size_t nbytes = 0;
 
 #if  defined  (HAVE_LIBCGRIBEX)
   if ( filetype == FILETYPE_GRB )
@@ -525,6 +534,7 @@ size_t grbEncode(int filetype, int memtype, int varID, int levelID, int vlistID,
     }
   else
 #endif
+#ifdef HAVE_LIBGRIB_API
     {
       if ( memtype == MEMTYPE_FLOAT ) Error("gribapiEncode() not implemented for memtype float!");
 
@@ -534,6 +544,11 @@ size_t grbEncode(int filetype, int memtype, int varID, int levelID, int vlistID,
 			     (long)datasize, data, nmiss, gribbuffer, &gribbuffersize,
 			     comptype, gribContainer);
     }
+#else
+    Error("GRIB_API support not compiled in!");
+    (void)gribContainer;
+#endif
+
 
   return (nbytes);
 }
diff --git a/libcdi/src/stream_gribapi.c b/libcdi/src/stream_gribapi.c
index 081c718..7123ed8 100644
--- a/libcdi/src/stream_gribapi.c
+++ b/libcdi/src/stream_gribapi.c
@@ -619,10 +619,12 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
       }
     case GRID_UNSTRUCTURED:
       {
-        char uuid[17];
-    	char reference_link[8192];
+        unsigned char uuid[CDI_UUID_SIZE];
+    	/*
+        char reference_link[8192];
         size_t len = sizeof(reference_link);
         reference_link[0] = 0;
+         */
 
         /* FIXME: assert(numberOfPoints <= INT_MAX && numberOfPoints >= INT_MIN) */
     	grid->size  = (int)numberOfPoints;
@@ -641,10 +643,10 @@ void gribapiGetGrid(grib_handle *gh, grid_t *grid)
                   grid->reference = strdupx(reference_link);
               }
             */
-            len = (size_t) 16;
-            if ( grib_get_bytes(gh, "uuidOfHGrid", (unsigned char *) uuid, &len) == 0)
+            size_t len = (size_t)CDI_UUID_SIZE;
+            if ( grib_get_bytes(gh, "uuidOfHGrid", uuid, &len) == 0)
               {
-                memcpy(grid->uuid, uuid, 16);
+                memcpy(grid->uuid, uuid, CDI_UUID_SIZE);
               }
           }
 	break;
@@ -895,7 +897,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
 
   gribapiGetGrid(gh, &grid);
 
-  gridID = varDefGrid(vlistID, grid, 0);
+  gridID = varDefGrid(vlistID, &grid, 0);
 
   zaxistype = gribapiGetZaxisType(editionNumber, leveltype1);
 
@@ -924,7 +926,7 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
     case ZAXIS_REFERENCE:
       {
         size_t len;
-        char uuid[17];
+        unsigned char uuid[CDI_UUID_SIZE];
         long ltmp;
         long nhlev, nvgrid;
 
@@ -937,9 +939,9 @@ void gribapiAddRecord(stream_t * streamptr, int param, grib_handle *gh,
         nhlev = ltmp;
         GRIB_CHECK(grib_get_long(gh, "numberOfVGridUsed", &ltmp), 0);
         nvgrid = ltmp;
-        len = (size_t) 16;
-        uuid[16] = 0;
-        GRIB_CHECK(grib_get_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len), 0);
+        len = (size_t)CDI_UUID_SIZE;
+        memset(uuid, 0, CDI_UUID_SIZE);
+        GRIB_CHECK(grib_get_bytes(gh, "uuidOfVGrid", uuid, &len), 0);
         varDefZAxisReference((int) nhlev, (int) nvgrid, uuid);
         break;
       }
@@ -1226,16 +1228,6 @@ int gribapiScanTimestep1(stream_t * streamptr)
       lieee = FALSE;
 
       comptype = COMPRESS_NONE;
-      if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 )
-	{
-	  comptype = COMPRESS_SZIP;
-	  unzipsize += 100;
-	  if ( buffersize < (size_t)unzipsize )
-	    {
-	      buffersize = (size_t)unzipsize;
-	      gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
-	    }
-	}
 
       nrecs_scanned++;
       gh = grib_handle_new_from_message(NULL, (void *) gribbuffer, recsize);
@@ -1245,6 +1237,17 @@ int gribapiScanTimestep1(stream_t * streamptr)
 
       if ( editionNumber <= 1 )
 	{
+          if ( gribGetZip((long)recsize, gribbuffer, &unzipsize) > 0 )
+            {
+              comptype = COMPRESS_SZIP;
+              unzipsize += 100;
+              if ( buffersize < (size_t)unzipsize )
+                {
+                  buffersize = (size_t)unzipsize;
+                  gribbuffer = (unsigned char *) realloc(gribbuffer, buffersize);
+                }
+            }
+
 	  GRIB_CHECK(grib_get_long(gh, "table2Version", &lpar), 0);
 	  rtabnum = (int) lpar;
 	  GRIB_CHECK(grib_get_long(gh, "indicatorOfParameter", &lpar), 0);
@@ -1265,8 +1268,9 @@ int gribapiScanTimestep1(stream_t * streamptr)
 	  if ( status == 0 )
 	    {
 	      // fprintf(stderr, "packingType %d %s\n", len, typeOfPacking);
-	      if      ( strncmp(typeOfPacking, "grid_jpeg", len) == 0 ) comptype = COMPRESS_JPEG;
-	      else if ( strncmp(typeOfPacking, "grid_ieee", len) == 0 ) lieee = TRUE;
+	      if      ( strncmp(typeOfPacking, "grid_jpeg", len)  == 0 ) comptype = COMPRESS_JPEG;
+	      else if ( strncmp(typeOfPacking, "grid_ccsds", len) == 0 ) comptype = COMPRESS_SZIP;
+	      else if ( strncmp(typeOfPacking, "grid_ieee", len)  == 0 ) lieee = TRUE;
 	    }
 
 	  param = gribapiGetParam(gh);
@@ -1453,6 +1457,7 @@ int gribapiScanTimestep1(stream_t * streamptr)
 	}
     }
 #else
+  (void)streamptr;
   Error("GRIB_API support not compiled in!");
 #endif
 
@@ -1460,10 +1465,10 @@ int gribapiScanTimestep1(stream_t * streamptr)
 }
 
 
+#ifdef HAVE_LIBGRIB_API
 int gribapiScanTimestep2(stream_t * streamptr)
 {
   int rstatus = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   off_t recpos = 0;
   unsigned char *gribbuffer = NULL;
   size_t buffersize = 0;
@@ -1724,16 +1729,16 @@ int gribapiScanTimestep2(stream_t * streamptr)
 
   streamptr->record->buffer     = gribbuffer;
   streamptr->record->buffersize = buffersize;
-#endif
 
   return (rstatus);
 }
+#endif
 
 
+#if  defined  (HAVE_LIBGRIB_API)
 int gribapiScanTimestep(stream_t * streamptr)
 {
   int rstatus = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   size_t recsize = 0;
   off_t recpos = 0;
   unsigned char *gribbuffer;
@@ -2010,22 +2015,19 @@ int gribapiScanTimestep(stream_t * streamptr)
     }
 
   rstatus = (int)streamptr->ntsteps;
-#else
-  Error("GRIB_API support not compiled in!");
-#endif
-
   return (rstatus);
 }
+#endif
 
 #ifdef gribWarning
 #undef gribWarning
 #endif
 
+#ifdef HAVE_LIBGRIB_API
 int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gridsize,
 		  int unreduced, int *nmiss, double missval, int vlistID, int varID)
 {
   int status = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   long lpar;
   long editionNumber, numberOfPoints;
   size_t datasize, dummy, recsize;
@@ -2076,12 +2078,10 @@ int gribapiDecode(unsigned char *gribbuffer, int gribsize, double *data, int gri
 
   grib_handle_delete(gh);
 
-#else
-  Error("GRIB_API support not compiled in!");
-#endif
-
   return (status);
 }
+#endif
+
 
 #if  defined  (HAVE_LIBGRIB_API)
 static
@@ -2415,15 +2415,12 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
       gridtype = GRID_LONLAT;
     }
 
-
   if ( gridtype == GRID_LONLAT || gridtype == GRID_GAUSSIAN )
     {
       if ( editionNumber != 2 || lieee ) { comptype = 0; }
 
       if ( comptype )
         {
-          //if ( nmiss > 0 ) comptype = 0;
-
           if ( comptype == COMPRESS_JPEG )
             {
               mesg = "grid_jpeg"; len = strlen(mesg);
@@ -2431,7 +2428,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
             }
           else if ( comptype == COMPRESS_SZIP )
             {
-              mesg = "grid_szip"; len = strlen(mesg);
+              mesg = "grid_ccsds"; len = strlen(mesg);
               GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
             }
           else
@@ -2599,10 +2596,8 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
 	    else
 	      GRIB_CHECK(my_grib_set_long(gh, "precision", 1), 0);
           }
-        else if ( comptype )
+        else
 	  {
-            //if ( nmiss > 0 ) comptype = 0;
-
             if ( comptype == COMPRESS_JPEG )
               {
                 mesg = "grid_jpeg"; len = strlen(mesg);
@@ -2610,7 +2605,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
               }
             else if ( comptype == COMPRESS_SZIP )
               {
-                mesg = "grid_szip"; len = strlen(mesg);
+                mesg = "grid_ccsds"; len = strlen(mesg);
                 GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
               }
             else
@@ -2619,11 +2614,6 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
                 GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
               }
 	  }
-	else
-	  {
-	    mesg = "grid_simple"; len = strlen(mesg);
-	    GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
-	  }
 
 	break;
       }
@@ -2716,11 +2706,18 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
 	GRIB_CHECK(my_grib_set_long(gh, "numberOfDataPoints", gridInqSize(gridID)), 0);
 	GRIB_CHECK(my_grib_set_long(gh, "totalNumberOfGridPoints", gridInqSize(gridID)), 0);
 
+        if ( comptype == COMPRESS_SZIP )
+          {
+            mesg = "grid_ccsds"; len = strlen(mesg);
+            GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
+          }
+
 	break;
       }
     case GRID_UNSTRUCTURED:
       {
 	static int warning = 1;
+
 	status = my_grib_set_long(gh, "gridDefinitionTemplateNumber", GRIB2_GTYPE_UNSTRUCTURED);
 	if ( status != 0 && warning )
 	  {
@@ -2731,19 +2728,25 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
 	  }
 	else
 	  {
-            char uuid[17];
+            unsigned char uuid[CDI_UUID_SIZE];
             int position = gridInqPosition(gridID);
             int number = gridInqNumber(gridID);
             if ( position < 0 ) position = 0;
             if ( number < 0 ) number = 0;
 	    GRIB_CHECK(my_grib_set_long(gh, "numberOfGridUsed", number), 0);
 	    GRIB_CHECK(my_grib_set_long(gh, "numberOfGridInReference", position), 0);
-            len = 16;
+            len = CDI_UUID_SIZE;
             gridInqUUID(gridID, uuid);
-	    if (grib_set_bytes(gh, "uuidOfHGrid", (unsigned char *) uuid, &len) != 0)
+	    if (grib_set_bytes(gh, "uuidOfHGrid", uuid, &len) != 0)
 	      Warning("Can't write UUID!");
 	  }
 
+        if ( comptype == COMPRESS_SZIP )
+          {
+            mesg = "grid_ccsds"; len = strlen(mesg);
+            GRIB_CHECK(my_grib_set_string(gh, "packingType", mesg, &len), 0);
+          }
+
 	break;
       }
     default:
@@ -3017,8 +3020,7 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
       }
     case ZAXIS_REFERENCE:
       {
-        char uuid[16];
-        int number;
+        unsigned char uuid[CDI_UUID_SIZE];
 
         if ( !gcinit )
           {
@@ -3031,15 +3033,15 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
               ; // not available
             else
               {
-                number = zaxisInqNumber(zaxisID);
+                int number = zaxisInqNumber(zaxisID);
                 gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", GRIB2_LTYPE_REFERENCE);
                 gribapiDefLevelType(gh, gcinit, "typeOfSecondFixedSurface", GRIB2_LTYPE_REFERENCE);
                 GRIB_CHECK(my_grib_set_long(gh, "NV", 6), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "nlev", zaxisInqNlevRef(zaxisID)), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "numberOfVGridUsed", number), 0);
-                size_t len = 16;
+                size_t len = CDI_UUID_SIZE;
                 zaxisInqUUID(zaxisID, uuid);
-                if (grib_set_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len) != 0)
+                if (grib_set_bytes(gh, "uuidOfVGrid", uuid, &len) != 0)
                   Warning("Can't write UUID!");
                 GRIB_CHECK(my_grib_set_long(gh, "topLevel", (long) dlevel1), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "bottomLevel", (long) dlevel2), 0);
@@ -3051,14 +3053,14 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
               ; // not available
             else
               {
-                number = zaxisInqNumber(zaxisID);
+                int number = zaxisInqNumber(zaxisID);
                 gribapiDefLevelType(gh, gcinit, "typeOfFirstFixedSurface", GRIB2_LTYPE_REFERENCE);
                 GRIB_CHECK(my_grib_set_long(gh, "NV", 6), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "nlev", zaxisInqNlevRef(zaxisID)), 0);
                 GRIB_CHECK(my_grib_set_long(gh, "numberOfVGridUsed", number), 0);
-                size_t len = 16;
+                size_t len = CDI_UUID_SIZE;
                 zaxisInqUUID(zaxisID, uuid);
-                if (grib_set_bytes(gh, "uuidOfVGrid", (unsigned char *) uuid, &len) != 0)
+                if (grib_set_bytes(gh, "uuidOfVGrid", uuid, &len) != 0)
                   Warning("Can't write UUID!");
                 GRIB_CHECK(my_grib_set_double(gh, "level", level), 0);
               }
@@ -3086,39 +3088,15 @@ void gribapiDefLevel(int editionNumber, grib_handle *gh, int param, int zaxisID,
 }
 #endif
 
-void *gribHandleNew(int editionNumber)
-{
-  void *gh = NULL;
-
-#if  defined  (HAVE_LIBGRIB_API)
-  if ( editionNumber == 1 )
-    gh = (void *) grib_handle_new_from_samples(NULL, "GRIB1");
-  else
-    gh = (void *) grib_handle_new_from_samples(NULL, "GRIB2");
-
-  if ( gh == NULL ) Error("grib_handle_new_from_samples failed!");
-#endif
-
-  return (gh);
-}
-
-
-void gribHandleDelete(void *gh)
-{
-#if  defined  (HAVE_LIBGRIB_API)
-  grib_handle_delete(gh);
-#endif
-}
-
 /* #define GRIBAPIENCODETEST 1 */
 
+#ifdef HAVE_LIBGRIB_API
 size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisID,
 		     int vdate, int vtime, int tsteptype, int numavg, 
 		     long datasize, const double *data, int nmiss, unsigned char **gribbuffer, size_t *gribbuffersize,
 		     int comptype, void *gribContainer)
 {
   size_t nbytes = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   size_t recsize = 0;
   void *dummy = NULL;
   int datatype;
@@ -3249,12 +3227,10 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
   gc->init = TRUE;
 
   nbytes = recsize;
-#else
-  Error("GRIB_API support not compiled in!");
-#endif
 
   return (nbytes);
 }
+#endif
 
 /*
  * Local Variables:
diff --git a/libcdi/src/stream_history.c b/libcdi/src/stream_history.c
index adf6492..864a68a 100644
--- a/libcdi/src/stream_history.c
+++ b/libcdi/src/stream_history.c
@@ -10,9 +10,8 @@
 
 void streamDefHistory(int streamID, int length, const char *history)
 {
-  stream_t *streamptr;
-
-  streamptr = stream_to_pointer(streamID);
+#ifdef HAVE_LIBNETCDF
+  stream_t *streamptr = stream_to_pointer(streamID);
 
   if ( streamptr->filetype == FILETYPE_NC  ||
        streamptr->filetype == FILETYPE_NC2 ||
@@ -26,21 +25,25 @@ void streamDefHistory(int streamID, int length, const char *history)
 	  len = strlen(history);
 	  if ( len )
 	    {
+              /* FIXME: what's the point of strdupx? Why not use
+               * history argument directly? */
 	      histstring = strdupx(history);
 	      cdfDefHistory(streamptr, length, histstring);
 	      free(histstring);
 	    }
 	}
     }
+#else
+  (void)streamID; (void)length; (void)history;
+#endif
 }
 
 
 int streamInqHistorySize(int streamID)
 {
   int size = 0;
-  stream_t *streamptr;
-
-  streamptr = stream_to_pointer(streamID);
+#ifdef HAVE_LIBNETCDF
+  stream_t *streamptr = stream_to_pointer(streamID);
 
   if ( streamptr->filetype == FILETYPE_NC  ||
        streamptr->filetype == FILETYPE_NC2 ||
@@ -49,16 +52,17 @@ int streamInqHistorySize(int streamID)
     {
       size = cdfInqHistorySize(streamptr);
     }
-
+#else
+  (void)streamID;
+#endif
   return (size);
 }
 
 
 void streamInqHistoryString(int streamID, char *history)
 {
-  stream_t *streamptr;
-
-  streamptr = stream_to_pointer(streamID);
+#ifdef HAVE_LIBNETCDF
+  stream_t *streamptr = stream_to_pointer(streamID);
 
   if ( streamptr->filetype == FILETYPE_NC  ||
        streamptr->filetype == FILETYPE_NC2 ||
@@ -67,6 +71,9 @@ void streamInqHistoryString(int streamID, char *history)
     {
       cdfInqHistoryString(streamptr, history);
     }
+#else
+  (void)streamID; (void)history;
+#endif
 }
 /*
  * Local Variables:
diff --git a/libcdi/src/stream_ieg.c b/libcdi/src/stream_ieg.c
index 080bd2c..e734dfa 100644
--- a/libcdi/src/stream_ieg.c
+++ b/libcdi/src/stream_ieg.c
@@ -228,6 +228,32 @@ void iegDefTime(int *pdb, int date, int time, int taxisID)
 }
 
 static
+int calc_resfac(double xfirst, double xlast, double xinc, double yfirst, double ylast, double yinc)
+{
+  int i, j;
+  int iresfac = 1000;
+  int ifact;
+  int ifacarr[5] = {1000, 10000, 100000, 1000000, 10000000};
+  double vals[6] = {xfirst, xlast, xinc, yfirst, ylast, yinc};
+
+  for ( j = 0; j < 5; ++j )
+    {
+      ifact = ifacarr[j];
+      for ( i = 0; i < 6; ++i )
+        {
+          if ( fabs(vals[i]*ifact-(lround(vals[i]*ifact))) > FLT_EPSILON ) break;
+        }
+      if ( i == 6 )
+        {
+          iresfac = ifact;
+          break;
+        }
+    }
+
+  return (iresfac);
+}
+
+static
 void iegDefGrid(int *gdb, int gridID)
 {
   int gridtype;
@@ -242,7 +268,7 @@ void iegDefGrid(int *gdb, int gridID)
       ysize = gridInqYsize(gridID);
 
       if ( (ysize == 32  || ysize == 48 || ysize == 64 ||
-	    ysize == 96  || ysize == 160) && 
+	    ysize == 96  || ysize == 160) &&
 	   (xsize == 2*ysize || xsize == 1) )
 	{
 	  gridtype = GRID_GAUSSIAN;
@@ -302,22 +328,28 @@ void iegDefGrid(int *gdb, int gridID)
       else
 	IEG_G_GridType(gdb) = 0;
 
+      int iresfac = calc_resfac(xfirst, xlast, xinc, yfirst, ylast, yinc);
+      double resfac = (double) iresfac;
+      if ( iresfac == 1000 ) iresfac = 0;
+
+      IEG_G_ResFac(gdb)   = iresfac;
+
       IEG_G_NumLon(gdb)   = nlon;
       IEG_G_NumLat(gdb)   = nlat;
-      IEG_G_FirstLat(gdb) = lround(yfirst*1000);
-      IEG_G_LastLat(gdb)  = lround(ylast*1000);
-      IEG_G_FirstLon(gdb) = lround(xfirst*1000);
-      IEG_G_LastLon(gdb)  = lround(xlast*1000);
-      IEG_G_LonIncr(gdb)  = lround(xinc*1000);
-      if ( fabs(xinc*1000 - IEG_G_LonIncr(gdb)) > FLT_EPSILON )
+      IEG_G_FirstLat(gdb) = lround(yfirst*resfac);
+      IEG_G_LastLat(gdb)  = lround(ylast*resfac);
+      IEG_G_FirstLon(gdb) = lround(xfirst*resfac);
+      IEG_G_LastLon(gdb)  = lround(xlast*resfac);
+      IEG_G_LonIncr(gdb)  = lround(xinc*resfac);
+      if ( fabs(xinc*resfac - IEG_G_LonIncr(gdb)) > FLT_EPSILON )
 	IEG_G_LonIncr(gdb) = 0;
 
       if ( gridtype == GRID_GAUSSIAN )
 	IEG_G_LatIncr(gdb) = nlat/2;
       else
 	{
-	  IEG_G_LatIncr(gdb) = lround(yinc*1000);
-	  if ( fabs(yinc*1000 - IEG_G_LatIncr(gdb)) > FLT_EPSILON )
+	  IEG_G_LatIncr(gdb) = lround(yinc*resfac);
+	  if ( fabs(yinc*resfac - IEG_G_LatIncr(gdb)) > FLT_EPSILON )
 	    IEG_G_LatIncr(gdb) = 0;
 
 	  if ( IEG_G_LatIncr(gdb) < 0 ) IEG_G_LatIncr(gdb) = -IEG_G_LatIncr(gdb);
@@ -336,8 +368,8 @@ void iegDefGrid(int *gdb, int gridID)
 
       if ( gridIsRotated(gridID) )
 	{
-	  IEG_G_LatSP(gdb) = - lround(gridInqYpole(gridID) * 1000);
-	  IEG_G_LonSP(gdb) =   lround((gridInqXpole(gridID) + 180) * 1000);
+	  IEG_G_LatSP(gdb) = - lround(gridInqYpole(gridID) * resfac);
+	  IEG_G_LonSP(gdb) =   lround((gridInqXpole(gridID) + 180) * resfac);
 	  IEG_G_Size(gdb)  = 42;
 	}
       else
@@ -647,21 +679,26 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
     gridtype = GRID_GENERIC;
 
   memset(&grid, 0, sizeof(grid_t));
-  grid.type  = gridtype; 
+  grid.type  = gridtype;
   grid.size  = IEG_G_NumLon(gdb)*IEG_G_NumLat(gdb);
   grid.xsize = IEG_G_NumLon(gdb);
   grid.ysize = IEG_G_NumLat(gdb);
   grid.xinc  = 0;
   grid.yinc  = 0;
   grid.xdef  = 0;
+
+  int iresfac = IEG_G_ResFac(gdb);
+  if ( iresfac == 0 ) iresfac = 1000;
+  double resfac = 1./(double) iresfac;
+
   /* if ( IEG_G_FirstLon != 0 || IEG_G_LastLon != 0 ) */
   {
     if ( grid.xsize > 1 )
       {
 	if ( IEG_G_ResFlag(gdb) && IEG_G_LonIncr(gdb) > 0 )
-	  grid.xinc = IEG_G_LonIncr(gdb) * 0.001;
+	  grid.xinc = IEG_G_LonIncr(gdb) * resfac;
 	else
-	  grid.xinc = (IEG_G_LastLon(gdb) - IEG_G_FirstLon(gdb)) * 0.001 / (grid.xsize - 1);
+	  grid.xinc = (IEG_G_LastLon(gdb) - IEG_G_FirstLon(gdb)) * resfac / (grid.xsize - 1);
 
 	/* correct xinc if necessary */
 	if ( IEG_G_FirstLon(gdb) == 0 && IEG_G_LastLon(gdb) > 354000 )
@@ -675,9 +712,9 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
 	      }
 	  }
       }
-    grid.xfirst = IEG_G_FirstLon(gdb) * 0.001;
-    grid.xlast  = IEG_G_LastLon(gdb)  * 0.001;
-    grid.xdef   = 2;	    
+    grid.xfirst = IEG_G_FirstLon(gdb) * resfac;
+    grid.xlast  = IEG_G_LastLon(gdb)  * resfac;
+    grid.xdef   = 2;
   }
   grid.ydef  = 0;
   /* if ( IEG_G_FirstLat != 0 || IEG_G_LastLat != 0 ) */
@@ -685,22 +722,22 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
     if ( grid.ysize > 1 )
       {
 	if ( IEG_G_ResFlag(gdb) && IEG_G_LatIncr(gdb) > 0 )
-	  grid.yinc = IEG_G_LatIncr(gdb) * 0.001;
+	  grid.yinc = IEG_G_LatIncr(gdb) * resfac;
 	else
-	  grid.yinc = (IEG_G_LastLat(gdb) - IEG_G_FirstLat(gdb)) * 0.001 / (grid.ysize - 1);
+	  grid.yinc = (IEG_G_LastLat(gdb) - IEG_G_FirstLat(gdb)) * resfac / (grid.ysize - 1);
       }
-    grid.yfirst = IEG_G_FirstLat(gdb) * 0.001;
-    grid.ylast  = IEG_G_LastLat(gdb)  * 0.001;
-    grid.ydef   = 2;	    
+    grid.yfirst = IEG_G_FirstLat(gdb) * resfac;
+    grid.ylast  = IEG_G_LastLat(gdb)  * resfac;
+    grid.ydef   = 2;
   }
   /*
-  grid.xfirst= IEG_G_FirstLon(gdb) * 0.001;
-  grid.xlast = IEG_G_LastLon(gdb) * 0.001;
-  grid.xinc  = IEG_G_LonIncr(gdb) * 0.001;
-  grid.xdef  = 2;	    
-  grid.yfirst= IEG_G_FirstLat(gdb) * 0.001;
-  grid.ylast = IEG_G_LastLat(gdb) * 0.001;
-  grid.yinc  = IEG_G_LatIncr(gdb) * 0.001;
+  grid.xfirst= IEG_G_FirstLon(gdb) * resfac;
+  grid.xlast = IEG_G_LastLon(gdb) * resfac;
+  grid.xinc  = IEG_G_LonIncr(gdb) * resfac;
+  grid.xdef  = 2;
+  grid.yfirst= IEG_G_FirstLat(gdb) * resfac;
+  grid.ylast = IEG_G_LastLat(gdb) * resfac;
+  grid.yinc  = IEG_G_LatIncr(gdb) * resfac;
   grid.ydef  = 2;
   */
   grid.xvals = NULL;
@@ -710,12 +747,12 @@ void iegAddRecord(stream_t *streamptr, int param, int *pdb, int *gdb, double *vc
   if ( IEG_G_GridType(gdb) == 10 )
     {
       grid.isRotated = TRUE;
-      grid.ypole     = - IEG_G_LatSP(gdb) * 0.001;
-      grid.xpole     =   IEG_G_LonSP(gdb) * 0.001 - 180;
+      grid.ypole     = - IEG_G_LatSP(gdb) * resfac;
+      grid.xpole     =   IEG_G_LonSP(gdb) * resfac - 180;
       grid.angle     = 0;
     }
 
-  gridID = varDefGrid(vlistID, grid, 0);
+  gridID = varDefGrid(vlistID, &grid, 0);
 
   leveltype = iegGetZaxisType(IEG_P_LevelType(pdb));
 
@@ -1437,6 +1474,7 @@ void iegWriteVarSliceDP(stream_t *streamptr, int varID, int levID, const double
   /* tsID     = streamptr->curTsID; */
   gridID   = vlistInqVarGrid(vlistID, varID);
   zaxisID  = vlistInqVarZaxis(vlistID, varID);
+  (void)levID;
   /* level    = zaxisInqLevel(zaxisID, levID); */
 
   if ( CDI_Debug )
diff --git a/libcdi/src/stream_record.c b/libcdi/src/stream_record.c
index c3e8739..861e803 100644
--- a/libcdi/src/stream_record.c
+++ b/libcdi/src/stream_record.c
@@ -151,7 +151,20 @@ void streamInqRecord(int streamID, int *varID, int *levelID)
   streamptr->tsteps[tsID].curRecID = rindex;
 }
 
-
+/*
+ at Function  streamDefRecord
+ at Title     Define the next record
+
+ at Prototype void streamDefRecord(int streamID, int varID, int levelID)
+ at Parameter
+    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenWrite}.
+    @Item  varID     Variable identifier.
+    @Item  levelID   Level identifier.
+
+ at Description
+The function streamDefRecord defines the meta-data of the next record.
+ at EndFunction
+*/
 void streamDefRecord(int streamID, int varID, int levelID)
 {
   stream_t *streamptr = stream_to_pointer(streamID);
@@ -323,7 +336,21 @@ stream_write_record(int streamID, int memtype, const void *data, int nmiss)
     }
 }
 
-
+/*
+ at Function  streamWriteRecord
+ at Title     Write a horizontal slice of a variable
+
+ at Prototype void streamWriteRecord(int streamID, const double *data, int nmiss)
+ at Parameter
+    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenWrite}.
+    @Item  data      Pointer to a block of double precision floating point data values to be written.
+    @Item  nmiss     Number of missing values.
+
+ at Description
+The function streamWriteRecord writes the values of a horizontal slice (record) of a variable to an open dataset.
+The values are converted to the external data type of the variable, if necessary.
+ at EndFunction
+*/
 void streamWriteRecord(int streamID, const double *data, int nmiss)
 {
   stream_write_record(streamID, MEMTYPE_DOUBLE, (const void *) data, nmiss);
diff --git a/libcdi/src/stream_srv.c b/libcdi/src/stream_srv.c
index 34ec0e8..25fd4ca 100644
--- a/libcdi/src/stream_srv.c
+++ b/libcdi/src/stream_srv.c
@@ -232,7 +232,7 @@ void srv_add_record(stream_t *streamptr, int param, int level, int xsize, int ys
   grid.ysize = ysize;
   grid.xvals = NULL;
   grid.yvals = NULL;
-  gridID = varDefGrid(vlistID, grid, 0);
+  gridID = varDefGrid(vlistID, &grid, 0);
   /*
   if ( level == 0 ) leveltype = ZAXIS_SURFACE;
   else              leveltype = ZAXIS_GENERIC;
diff --git a/libcdi/src/table.c b/libcdi/src/table.c
index 5a2728b..083d282 100644
--- a/libcdi/src/table.c
+++ b/libcdi/src/table.c
@@ -205,16 +205,21 @@ decodeForm1(char *pline, char *name, char *longname, char *units)
   while ( isspace((int) *pline) ) pline++;
 
   len = strlen(pline);
-  if ( len > 0)
+  if ( len > 0 )
     {
       pstart = pline;
       pend = strrchr(pline, '[');
-      if ( pend )
-	pend--;
+      if ( pend == pstart )
+        len = 0;
       else
-	pend = pstart + len;
-      while ( isspace((int) *pend) ) pend--;
-      len = (size_t)(pend - pstart + 1);
+        {
+          if ( pend )
+            pend--;
+          else
+            pend = pstart + len;
+          while ( isspace((int) *pend) ) pend--;
+          len = (size_t)(pend - pstart + 1);
+        }
       if ( len > 0 )
 	{
 	  memcpy(longname, pstart, len);
@@ -234,10 +239,10 @@ decodeForm1(char *pline, char *name, char *longname, char *units)
 	    {
 	      memcpy(units, pstart, len);
 	      units[len] = 0;
-	    }	  
+	    }
 	}
     }
- 
+
   return (0);
 }
 
@@ -378,9 +383,10 @@ static int tableFromEnv(int modelID, int tablenum)
   char tablename[256] = {'\0'};
   int tablenamefound = 0;
 
-  if ( modelInqNamePtr(modelID) )
+  const char *modelName;
+  if ( (modelName = modelInqNamePtr(modelID)) )
     {
-      strcpy(tablename, modelInqNamePtr(modelID));
+      strcpy(tablename, modelName);
       if ( tablenum )
 	{
 	  size_t len = strlen(tablename);
@@ -393,9 +399,10 @@ static int tableFromEnv(int modelID, int tablenum)
       int instID = modelInqInstitut(modelID);
       if ( instID != UNDEFID )
 	{
-	  if ( institutInqNamePtr(instID) )
+          const char *instName;
+	  if ( (instName = institutInqNamePtr(instID)) )
 	    {
-	      strcpy(tablename, institutInqNamePtr(instID));
+	      strcpy(tablename, instName);
 	      if ( tablenum )
 		{
 		  size_t len = strlen(tablename);
@@ -486,9 +493,10 @@ int tableInq(int modelID, int tablenum, const char *tablename)
 	{
 	  if ( modelID != UNDEFID )
 	    {
-	      if ( modelInqNamePtr(modelID) )
+              const char *modelName;
+	      if ( (modelName = modelInqNamePtr(modelID)) )
 		{
-		  strcpy(tablefile, modelInqNamePtr(modelID));
+		  strcpy(tablefile, modelName);
 		  size_t len = strlen(tablefile);
 		  for ( size_t i = 0; i < len; i++)
 		    if ( tablefile[i] == '.' ) tablefile[i] = '\0';
@@ -605,7 +613,7 @@ void tableWrite(const char *ptfile, int tableID)
   FILE *ptfp;
   int tablenum, modelID, instID = CDI_UNDEFID;
   int center = 0, subcenter = 0;
-  char *instnameptr = NULL, *modelnameptr = NULL;
+  const char *instnameptr = NULL, *modelnameptr = NULL;
 
   if ( CDI_Debug )
     Message("write parameter table %d to %s", tableID, ptfile);
diff --git a/libcdi/src/util.c b/libcdi/src/util.c
index 3fa2ad0..09f5718 100644
--- a/libcdi/src/util.c
+++ b/libcdi/src/util.c
@@ -7,6 +7,7 @@
 #include <float.h>
 #include <sys/types.h>
 
+#include "cdi.h"
 #include "cdi_int.h"
 #include "dmemory.h"
 #include "binary.h"
@@ -53,48 +54,41 @@ void cdiPrintDatatypes(void)
     fprintf (stderr, "\n  byte ordering is LITTLEENDIAN\n\n");
 }
 
+static char uuidFmt[] = "%02hhx%02hhx%02hhx%02hhx-"
+  "%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-"
+  "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx";
 
-void uuid2str(const char *uuid, char *uuidstr)
-{
-  int iret;
-  unsigned int ui[16];
-
-  if ( uuid == NULL ) return;
-  if ( uuidstr == NULL ) return;
+enum {
+  uuidNumHexChars = 36,
+};
 
-  uuidstr[0] = 0;
+void uuid2str(const unsigned char *uuid, char *uuidstr)
+{
 
-  for ( int i = 0; i < 16; ++i ) ui[i] = (unsigned char) uuid[i];
+  if ( uuid == NULL || uuidstr == NULL ) return;
 
-  iret = sprintf(uuidstr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-		 ui[0], ui[1], ui[2], ui[3], ui[4], ui[5], ui[6], ui[7],
-		 ui[8], ui[9], ui[10], ui[11], ui[12], ui[13], ui[14], ui[15]);
+  int iret = sprintf(uuidstr, uuidFmt,
+                     uuid[0], uuid[1], uuid[2], uuid[3],
+                     uuid[4], uuid[5], uuid[6], uuid[7],
+                     uuid[8], uuid[9], uuid[10], uuid[11],
+                     uuid[12], uuid[13], uuid[14], uuid[15]);
 
-  if ( iret != 36 ) uuidstr[0] = 0;
+  if ( iret != uuidNumHexChars ) uuidstr[0] = 0;
 }
 
 
-void str2uuid(const char *uuidstr, char *uuid)
+int str2uuid(const char *uuidstr, unsigned char *uuid)
 {
-  int iret;
-  unsigned int ui[16];
-
-  if ( uuid == NULL ) return;
-  if ( uuidstr == NULL ) return;
-
-  uuid[0] = 0;
-
-  if ( strlen(uuidstr) != 36 ) return;
-
-  iret = sscanf(uuidstr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-		&ui[0], &ui[1], &ui[2], &ui[3], &ui[4], &ui[5], &ui[6], &ui[7],
-		&ui[8], &ui[9], &ui[10], &ui[11], &ui[12], &ui[13], &ui[14], &ui[15]);
-
-  if ( iret != 16 ) return;
-
-  for ( int i = 0; i < 16; ++i ) uuid[i] = ui[i];
-
-  uuid[16] = 0;
+  if ( uuid == NULL || uuidstr == NULL || strlen(uuidstr) != uuidNumHexChars)
+    return -1;
+
+  int iret = sscanf(uuidstr, uuidFmt,
+                    &uuid[0], &uuid[1], &uuid[2], &uuid[3],
+                    &uuid[4], &uuid[5], &uuid[6], &uuid[7],
+                    &uuid[8], &uuid[9], &uuid[10], &uuid[11],
+                    &uuid[12], &uuid[13], &uuid[14], &uuid[15]);
+  if ( iret != CDI_UUID_SIZE ) return -1;
+  return iret;
 }
 
 /*
diff --git a/libcdi/src/varscan.c b/libcdi/src/varscan.c
index de8a0d8..e3ab47c 100644
--- a/libcdi/src/varscan.c
+++ b/libcdi/src/varscan.c
@@ -26,7 +26,7 @@ static double *Vct = NULL;
 
 static int numberOfVerticalLevels = 0;
 static int numberOfVerticalGrid = 0;
-static char uuidVGrid[17];
+static unsigned char uuidVGrid[CDI_UUID_SIZE];
 
 typedef struct
 {
@@ -52,7 +52,7 @@ typedef struct
   int           level_sf;
   int           level_unit;
   int           zaxisID;
-  int           nlevels;
+  unsigned      nlevels;
   int           levelTableSize;
   leveltable_t *levelTable;
   int           instID;
@@ -242,7 +242,7 @@ int levelNewEntry(int varID, int level1, int level2)
   levelTable[levelID].level2   = level2;
   levelTable[levelID].lindex   = levelID;
 
-  vartable[varID].nlevels = levelID+1;
+  vartable[varID].nlevels = (unsigned)levelID+1;
   vartable[varID].levelTableSize = levelTableSize;
   vartable[varID].levelTable = levelTable;
 
@@ -445,9 +445,9 @@ int cmpparam(const void* s1, const void* s2)
 
 void cdi_generate_vars(stream_t *streamptr)
 {
-  int varID, gridID, zaxisID, levelID;
+  int varID, gridID, zaxisID;
   int instID, modelID, tableID;
-  int param, nlevels, zaxistype, ltype1, ltype2, lindex;
+  int param, zaxistype, ltype1, ltype2, lindex;
   int prec;
   int tsteptype;
   int timave, timaccu;
@@ -494,7 +494,7 @@ void cdi_generate_vars(stream_t *streamptr)
 
       gridID     = vartable[varid].gridID;
       param      = vartable[varid].param;
-      nlevels    = vartable[varid].nlevels;
+      unsigned nlevels = vartable[varid].nlevels;
       ltype1     = vartable[varid].ltype1;
       ltype2     = vartable[varid].ltype2;
       zaxistype = vartable[varid].zaxistype;
@@ -522,17 +522,17 @@ void cdi_generate_vars(stream_t *streamptr)
       dlevels = (double *) malloc(nlevels*sizeof(double));
 
       if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF )
-	for ( levelID = 0; levelID < nlevels; levelID++ )
+	for (unsigned levelID = 0; levelID < nlevels; levelID++ )
 	  dlevels[levelID] = (level_sf*vartable[varid].levelTable[levelID].level1 +
 	                      level_sf*vartable[varid].levelTable[levelID].level2)/2;
       else
-	for ( levelID = 0; levelID < nlevels; levelID++ )
+	for (unsigned levelID = 0; levelID < nlevels; levelID++ )
 	  dlevels[levelID] = level_sf*vartable[varid].levelTable[levelID].level1;
 
       if ( nlevels > 1 )
 	{
           bool linc = true, ldec = true, lsort = false;
-          for ( levelID = 1; levelID < nlevels; levelID++ )
+          for (unsigned levelID = 1; levelID < nlevels; levelID++ )
             {
               /* check increasing of levels */
               linc &= (dlevels[levelID] > dlevels[levelID-1]);
@@ -546,7 +546,7 @@ void cdi_generate_vars(stream_t *streamptr)
            */
           if ( !ldec && zaxistype == ZAXIS_PRESSURE )
             {
-              qsort(vartable[varid].levelTable, (size_t)nlevels, sizeof(leveltable_t), cmpLevelTableInv);
+              qsort(vartable[varid].levelTable, nlevels, sizeof(leveltable_t), cmpLevelTableInv);
               lsort = true;
             }
           /*
@@ -558,18 +558,18 @@ void cdi_generate_vars(stream_t *streamptr)
                     zaxistype == ZAXIS_HYBRID ||
                     zaxistype == ZAXIS_DEPTH_BELOW_LAND )
             {
-              qsort(vartable[varid].levelTable, (size_t)nlevels, sizeof(leveltable_t), cmpLevelTable);
+              qsort(vartable[varid].levelTable, nlevels, sizeof(leveltable_t), cmpLevelTable);
               lsort = true;
             }
 
           if ( lsort )
             {
               if ( lbounds && zaxistype != ZAXIS_HYBRID && zaxistype != ZAXIS_HYBRID_HALF )
-                for ( levelID = 0; levelID < nlevels; levelID++ )
+                for (unsigned levelID = 0; levelID < nlevels; levelID++ )
                   dlevels[levelID] = (level_sf*vartable[varid].levelTable[levelID].level1 +
                                       level_sf*vartable[varid].levelTable[levelID].level2)/2.;
               else
-                for ( levelID = 0; levelID < nlevels; levelID++ )
+                for (unsigned levelID = 0; levelID < nlevels; levelID++ )
                   dlevels[levelID] = level_sf*vartable[varid].levelTable[levelID].level1;
             }
 	}
@@ -577,15 +577,15 @@ void cdi_generate_vars(stream_t *streamptr)
       if ( lbounds )
 	{
 	  dlevels1 = (double *) malloc(nlevels*sizeof(double));
-	  for ( levelID = 0; levelID < nlevels; levelID++ )
+	  for (unsigned levelID = 0; levelID < nlevels; levelID++)
 	    dlevels1[levelID] = level_sf*vartable[varid].levelTable[levelID].level1;
 	  dlevels2 = (double *) malloc(nlevels*sizeof(double));
-	  for ( levelID = 0; levelID < nlevels; levelID++ )
+	  for (unsigned levelID = 0; levelID < nlevels; levelID++)
 	    dlevels2[levelID] = level_sf*vartable[varid].levelTable[levelID].level2;
         }
 
       char *unitptr = cdiUnitNamePtr(vartable[varid].level_unit);
-      zaxisID = varDefZaxis(vlistID, zaxistype, nlevels, dlevels, lbounds, dlevels1, dlevels2,
+      zaxisID = varDefZaxis(vlistID, zaxistype, (int)nlevels, dlevels, lbounds, dlevels1, dlevels2,
                             (int)Vctsize, Vct, NULL, NULL, unitptr, 0, 0, ltype1);
 
       if ( ltype1 != ltype2 && ltype2 != -1 )
@@ -597,7 +597,7 @@ void cdi_generate_vars(stream_t *streamptr)
         {
           if ( numberOfVerticalLevels > 0 ) zaxisDefNlevRef(zaxisID, numberOfVerticalLevels);
           if ( numberOfVerticalGrid > 0 ) zaxisDefNumber(zaxisID, numberOfVerticalGrid);
-          if ( uuidVGrid[0] != 0 ) zaxisDefUUID(zaxisID, uuidVGrid);
+          if ( !cdiUUIDIsNull(uuidVGrid) ) zaxisDefUUID(zaxisID, uuidVGrid);
         }
 
       if ( lbounds ) free(dlevels1);
@@ -697,7 +697,7 @@ void cdi_generate_vars(stream_t *streamptr)
       varID     = index;
       varid     = varids[index];
 
-      nlevels   = vartable[varid].nlevels;
+      unsigned nlevels = vartable[varid].nlevels;
       /*
       for ( levelID = 0; levelID < nlevels; levelID++ )
 	{
@@ -708,16 +708,17 @@ void cdi_generate_vars(stream_t *streamptr)
 		 vartable[varid].levelTable[levelID].level1);
 	}
       */
-      for ( levelID = 0; levelID < nlevels; levelID++ )
+      for (unsigned levelID = 0; levelID < nlevels; levelID++)
 	{
 	  streamptr->vars[varID].level[levelID] = vartable[varid].levelTable[levelID].recID;
-	  for ( lindex = 0; lindex < nlevels; lindex++ )
-	    if ( levelID == vartable[varid].levelTable[lindex].lindex ) break;
+          unsigned lindex;
+	  for (lindex = 0; lindex < nlevels; lindex++ )
+	    if ( levelID == (unsigned)vartable[varid].levelTable[lindex].lindex ) break;
 
 	  if ( lindex == nlevels )
 	    Error("Internal problem! lindex not found.");
 
-	  streamptr->vars[varID].lindex[levelID] = lindex;
+	  streamptr->vars[varID].lindex[levelID] = (int)lindex;
 	}
     }
 
@@ -738,15 +739,15 @@ void varDefVCT(size_t vctsize, double *vctptr)
 }
 
 
-void varDefZAxisReference(int nhlev, int nvgrid, char *uuid)
+void varDefZAxisReference(int nhlev, int nvgrid, unsigned char uuid[CDI_UUID_SIZE])
 {
   numberOfVerticalLevels = nhlev;
   numberOfVerticalGrid = nvgrid;
-  memcpy(uuidVGrid, uuid, 16);
+  memcpy(uuidVGrid, uuid, CDI_UUID_SIZE);
 }
 
 
-int varDefGrid(int vlistID, grid_t grid, int mode)
+int varDefGrid(int vlistID, const grid_t *grid, int mode)
 {
   /*
     mode: 0 search in vlist and grid table
@@ -755,7 +756,7 @@ int varDefGrid(int vlistID, grid_t grid, int mode)
   int gridglobdefined = FALSE;
   int griddefined;
   int ngrids;
-  int gridID = UNDEFID;
+  int gridID = CDI_UNDEFID;
   int index;
   vlist_t *vlistptr;
   int * gridIndexList, i;
@@ -784,7 +785,7 @@ int varDefGrid(int vlistID, grid_t grid, int mode)
       ngrids = gridSize();
       if ( ngrids > 0 )
         {
-          gridIndexList = (int*) malloc(ngrids*sizeof(int));
+          gridIndexList = (int*)xmalloc((size_t)ngrids * sizeof(int));
           gridGetIndexList ( ngrids, gridIndexList );
           for ( i = 0; i < ngrids; i++ )
             {
@@ -820,7 +821,7 @@ int varDefGrid(int vlistID, grid_t grid, int mode)
 }
 
 
-int zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, double *levels, char *longname, char *units, int ltype1)
+int zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, const double *levels, char *longname, char *units, int ltype1)
 {
   int differ = 1;
   int levelID;
@@ -906,7 +907,7 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo
       if ( nzaxis > 0 )
         {
           int *zaxisIndexList;
-          zaxisIndexList = (int *) malloc ( nzaxis * sizeof ( int ));
+          zaxisIndexList = (int *)xmalloc((size_t)nzaxis * sizeof (int));
           zaxisGetIndexList ( nzaxis, zaxisIndexList );
           for ( i = 0; i < nzaxis; i++ )
             {
@@ -1047,38 +1048,38 @@ void varDefProductDefinitionTemplate(int varID, int productDefinitionTemplate)
 }
 
 
+#if  defined  (HAVE_LIBGRIB_API)
 void varDefOptGribInt(int varID, long lval, const char *keyword)
 {
-#if  defined  (HAVE_LIBGRIB_API)
   int idx = vartable[varID].opt_grib_int_nentries;
   vartable[varID].opt_grib_int_nentries++;
   if ( idx >= MAX_OPT_GRIB_ENTRIES ) Error("Too many optional keyword/integer value pairs!");
   vartable[varID].opt_grib_int_val[idx] = (int) lval;
   vartable[varID].opt_grib_int_keyword[idx] = strdupx(keyword);
-#endif
 }
+#endif
 
 
+#if  defined  (HAVE_LIBGRIB_API)
 void varDefOptGribDbl(int varID, double dval, const char *keyword)
 {
-#if  defined  (HAVE_LIBGRIB_API)
   int idx = vartable[varID].opt_grib_dbl_nentries;
   vartable[varID].opt_grib_dbl_nentries++;
   if ( idx >= MAX_OPT_GRIB_ENTRIES ) Error("Too many optional keyword/double value pairs!");
   vartable[varID].opt_grib_dbl_val[idx] = dval;
   vartable[varID].opt_grib_dbl_keyword[idx] = strdupx(keyword);
-#endif
 }
+#endif
 
 
+#if  defined  (HAVE_LIBGRIB_API)
 int varOptGribNentries(int varID)
 {
   int nentries = 0;
-#if  defined  (HAVE_LIBGRIB_API)
   nentries = vartable[varID].opt_grib_int_nentries + vartable[varID].opt_grib_dbl_nentries;
-#endif
   return (nentries);
 }
+#endif
 
 /*
  * Local Variables:
diff --git a/libcdi/src/varscan.h b/libcdi/src/varscan.h
index 87e34d4..43c41a9 100644
--- a/libcdi/src/varscan.h
+++ b/libcdi/src/varscan.h
@@ -5,6 +5,7 @@
 #  include "grid.h"
 #endif
 
+#include "cdi.h"
 
 void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds,
 		  int level1, int level2, int level_sf, int level_unit, int prec,
@@ -12,9 +13,9 @@ void varAddRecord(int recID, int param, int gridID, int zaxistype, int lbounds,
 		  const char *name, const char *stdname, const char *longname, const char *units);
 
 void varDefVCT(size_t vctsize, double *vctptr);
-void varDefZAxisReference(int nlev, int nvgrid, char *uuid);
+void varDefZAxisReference(int nlev, int nvgrid, unsigned char uuid[CDI_UUID_SIZE]);
 
-int  varDefGrid(int vlistID, grid_t grid, int mode);
+int  varDefGrid(int vlistID, const grid_t *grid, int mode);
 int  varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbounds,
 		 double *levels1, double *levels2, int vctsize, double *vct, char *name,
 		 char *longname, char *units, int prec, int mode, int ltype);
@@ -37,7 +38,7 @@ void varDefOptGribInt(int varID, long lval, const char *keyword);
 void varDefOptGribDbl(int varID, double dval, const char *keyword);
 int varOptGribNentries(int varID);
 
-int  zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, double *levels, char *longname, char *units, int ltype);
+int  zaxisCompare(int zaxisID, int zaxistype, int nlevels, int lbounds, const double *levels, char *longname, char *units, int ltype);
 
 #endif
 /*
diff --git a/libcdi/src/vlist.c b/libcdi/src/vlist.c
index 224d27d..c86934c 100644
--- a/libcdi/src/vlist.c
+++ b/libcdi/src/vlist.c
@@ -444,8 +444,8 @@ void vlistClearFlag(int vlistID)
 }
 
 static
-int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, double *levels,
-                         double *lbounds, double *ubounds, int vctsize, const double *vct)
+int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, const double *levels,
+                         const double *lbounds, const double *ubounds, int vctsize, const double *vct)
 {
   int zaxisID = CDI_UNDEFID;
   int zaxisglobdefined = 0;
@@ -1106,7 +1106,7 @@ void vlistDefNtsteps(int vlistID, int nts)
     }
 }
 
-
+// This function is used in CDO!
 int vlistNtsteps(int vlistID)
 {
   vlist_t *vlistptr = vlist_to_pointer(vlistID);
diff --git a/libcdi/src/vlist.h b/libcdi/src/vlist.h
index 6d6352f..b18e9c1 100644
--- a/libcdi/src/vlist.h
+++ b/libcdi/src/vlist.h
@@ -171,6 +171,8 @@ void    vlistDefVarValidrange(int vlistID, int varID, const double *validrange);
 /*      vlistInqVarValidrange: Get the valid range of a Variable */
 int     vlistInqVarValidrange(int vlistID, int varID, double *validrange);
 
+void vlistInqVarDimorder(int vlistID, int varID, int (*outDimorder)[3]);
+
 int vlist_att_compare(vlist_t *a, int varIDA, vlist_t *b, int varIDB, int attnum);
 
 void vlist_lock(int vlistID);
diff --git a/libcdi/src/vlist_att.c b/libcdi/src/vlist_att.c
index c35ff70..e5ecbd5 100644
--- a/libcdi/src/vlist_att.c
+++ b/libcdi/src/vlist_att.c
@@ -36,24 +36,19 @@ cdi_atts_t *get_attsp(vlist_t *vlistptr, int varID)
 static
 cdi_att_t *find_att(cdi_atts_t *attsp, const char *name)
 {
-  cdi_att_t *attp;
-  size_t attid;
-  size_t slen;
-
   xassert(attsp != NULL);
 
   if ( attsp->nelems == 0 ) return NULL;
 
-  slen = strlen(name);
+  size_t slen = strlen(name);
 
-  for ( attid = 0; attid < attsp->nelems; attid++ )
+  cdi_att_t *atts = attsp->value;
+  for (size_t attid = 0; attid < attsp->nelems; attid++)
     {
-      attp = &(attsp->value[attid]);
-      if ( attp->namesz == slen )
-	if ( memcmp(attp->name, name, slen) == 0)
-	  {
-	    return (attp); /* Normal return */
-	  }
+      cdi_att_t *attp = atts + attid;
+      if (attp->namesz == slen
+          && memcmp(attp->name, name, slen) == 0)
+        return (attp); /* Normal return */
     }
 
   return (NULL);
@@ -386,7 +381,7 @@ The function @func{vlistDefAttTxt} defines a text attribute.
 */
 int vlistDefAttTxt(int vlistID, int varID, const char *name, int len, const char *tp)
 {
-  return vlist_def_att(DATATYPE_TXT, DATATYPE_TXT, vlistID, varID, name, (size_t)len, (size_t)len * sizeof (char), tp);
+  return vlist_def_att(DATATYPE_TXT, DATATYPE_TXT, vlistID, varID, name, (size_t)len, (size_t)len, tp);
 }
 
 /*
diff --git a/libcdi/src/zaxis.c b/libcdi/src/zaxis.c
index ea95210..e39aa20 100644
--- a/libcdi/src/zaxis.c
+++ b/libcdi/src/zaxis.c
@@ -83,7 +83,7 @@ typedef struct {
   double  *vct;
   int      number;   /* Reference number to a generalized Z-axis */
   int      nhlev;
-  char     uuid[17];
+  unsigned char uuid[CDI_UUID_SIZE];
 }
 zaxis_t;
 
@@ -128,7 +128,7 @@ void zaxisDefaultValue(zaxis_t *zaxisptr)
   zaxisptr->vct         = NULL;
   zaxisptr->number      = 0;
   zaxisptr->nhlev       = 0;
-  zaxisptr->uuid[0]     = 0;
+  memset(zaxisptr->uuid, 0, CDI_UUID_SIZE);
 }
 
 
@@ -748,13 +748,13 @@ The function @func{zaxisDefUUID} defines the UUID for a generalized  Z-axis.
 
 @EndFunction
 */
-void zaxisDefUUID(int zaxisID, const char *uuid)
+void zaxisDefUUID(int zaxisID, const unsigned char uuid[CDI_UUID_SIZE])
 {
   zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
 
   zaxis_check_ptr(zaxisID, zaxisptr);
 
-  memcpy(zaxisptr->uuid, uuid, 16);
+  memcpy(zaxisptr->uuid, uuid, CDI_UUID_SIZE);
   reshSetStatus(zaxisID, &zaxisOps, RESH_DESYNC_IN_USE);
 }
 
@@ -773,13 +773,13 @@ The function @func{zaxisInqUUID} returns the UUID to a generalized Z-axis.
 @func{zaxisInqUUID} returns the UUID to a generalized Z-axis to the parameter uuid.
 @EndFunction
 */
-void zaxisInqUUID(int zaxisID, char *uuid)
+void zaxisInqUUID(int zaxisID, unsigned char uuid[CDI_UUID_SIZE])
 {
   zaxis_t *zaxisptr = reshGetVal(zaxisID, &zaxisOps);
 
   zaxis_check_ptr(zaxisID, zaxisptr);
 
-  memcpy(uuid, zaxisptr->uuid, 16);
+  memcpy(uuid, zaxisptr->uuid, CDI_UUID_SIZE);
 }
 
 /*
@@ -1253,7 +1253,7 @@ void zaxisPrintKernel ( zaxis_t * zaxisptr, FILE * fp )
 {
   int zaxisID;
   int type;
-  char uuid[17];
+  unsigned char uuid[CDI_UUID_SIZE];
   int nlevels, levelID;
   int nbyte0, nbyte;
   double level;
@@ -1354,7 +1354,7 @@ void zaxisPrintKernel ( zaxis_t * zaxisptr, FILE * fp )
     {
       const unsigned char *d;
       zaxisInqUUID(zaxisID, uuid);
-      d = (unsigned char *) &uuid;
+      d = uuid;
       fprintf(fp, "uuid      = %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
               d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
               d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
@@ -1385,7 +1385,7 @@ static int
 zaxisCompareP(zaxis_t *z1, zaxis_t *z2)
 {
   enum {
-    differ = -1,
+    differ = 1,
   };
   int diff = 0;
   xassert(z1 && z2);
@@ -1459,8 +1459,9 @@ zaxisCompareP(zaxis_t *z1, zaxis_t *z2)
   diff |= strcmp(z1->name, z2->name)
     | strcmp(z1->longname, z2->longname)
     | strcmp(z1->stdname, z2->stdname)
-    | strcmp(z1->units, z2->units);
-  return diff;
+    | strcmp(z1->units, z2->units)
+    | memcmp(z1->uuid, z2->uuid, CDI_UUID_SIZE);
+  return diff != 0;
 }
 
 
@@ -1476,7 +1477,8 @@ enum { zaxisNint     = 8,
        lbounds  = 1 << 1,
        ubounds  = 1 << 2,
        weights  = 1 << 3,
-       vct      = 1 << 4
+       vct      = 1 << 4,
+       zaxisHasUUIDFlag = 1 << 5,
 };
 
 
@@ -1490,7 +1492,7 @@ int zaxisGetMemberMask ( zaxis_t * zaxisP )
   if ( zaxisP->ubounds )   memberMask |= ubounds;
   if ( zaxisP->weights )   memberMask |= weights;
   if ( zaxisP->vct )       memberMask |= vct;
-
+  if (!cdiUUIDIsNull(zaxisP->uuid)) memberMask |= zaxisHasUUIDFlag;
   return memberMask;
 }
 
@@ -1530,6 +1532,10 @@ zaxisGetPackSize(void * voidP, void *context)
   packBufferSize += serializeGetSize(zaxisNstrings * CDI_MAX_NAME, DATATYPE_TXT, context)
     + serializeGetSize(1, DATATYPE_UINT32, context)
     + serializeGetSize(1, DATATYPE_UCHAR, context);
+
+  if (!cdiUUIDIsNull(zaxisP->uuid))
+    packBufferSize += serializeGetSize(CDI_UUID_SIZE, DATATYPE_UCHAR, context);
+
   return packBufferSize;
 }
 
@@ -1643,6 +1649,11 @@ zaxisUnpack(char * unpackBuffer, int unpackBufferSize,
 
   serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
                   &zaxisP->positive, 1, DATATYPE_UCHAR, context);
+
+  if (memberMask & zaxisHasUUIDFlag)
+    serializeUnpack(unpackBuffer, unpackBufferSize, unpackBufferPos,
+                    zaxisP->uuid, CDI_UUID_SIZE, DATATYPE_UCHAR, context);
+
 }
 
 static void
@@ -1651,6 +1662,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
 {
   zaxis_t   * zaxisP = ( zaxis_t * ) voidP;
   int intBuffer[zaxisNint];
+  int memberMask;
   uint32_t d;
   char charBuffer[zaxisNstrings * CDI_MAX_NAME];
 
@@ -1661,7 +1673,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
   intBuffer[4]  = zaxisP->size;
   intBuffer[5]  = zaxisP->direction;
   intBuffer[6]  = zaxisP->vctsize;
-  intBuffer[7]  = zaxisGetMemberMask ( zaxisP );
+  intBuffer[7]  = memberMask = zaxisGetMemberMask ( zaxisP );
 
   serializePack(intBuffer, zaxisNint, DATATYPE_INT,
                 packBuffer, packBufferSize, packBufferPos, context);
@@ -1670,7 +1682,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                 packBuffer, packBufferSize, packBufferPos, context);
 
 
-  if ( zaxisP->vals )
+  if ( memberMask & vals )
     {
       xassert(zaxisP->size);
       serializePack(zaxisP->vals, zaxisP->size, DATATYPE_FLT64,
@@ -1680,7 +1692,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (zaxisP->lbounds)
+  if (memberMask & lbounds)
     {
       xassert(zaxisP->size);
       serializePack(zaxisP->lbounds, zaxisP->size, DATATYPE_FLT64,
@@ -1690,7 +1702,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (zaxisP->ubounds)
+  if (memberMask & ubounds)
     {
       xassert(zaxisP->size);
 
@@ -1701,7 +1713,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (zaxisP->weights)
+  if (memberMask & weights)
     {
       xassert(zaxisP->size);
 
@@ -1712,7 +1724,7 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
                     packBuffer, packBufferSize, packBufferPos, context);
     }
 
-  if (zaxisP->vct)
+  if (memberMask & vct)
     {
       xassert(zaxisP->vctsize);
 
@@ -1736,6 +1748,11 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
 
   serializePack(&zaxisP->positive, 1, DATATYPE_UCHAR,
                 packBuffer, packBufferSize, packBufferPos, context);
+
+  if (memberMask & zaxisHasUUIDFlag)
+    serializePack(zaxisP->uuid, CDI_UUID_SIZE, DATATYPE_UCHAR,
+                  packBuffer, packBufferSize, packBufferPos, context);
+
 }
 
 
diff --git a/libcdi/tests/Makefile.am b/libcdi/tests/Makefile.am
index d1bbe97..a9b841a 100644
--- a/libcdi/tests/Makefile.am
+++ b/libcdi/tests/Makefile.am
@@ -8,44 +8,55 @@ TESTS = cksum_verify \
 	pio_write_run pio_cksum_mpinonb pio_cksum_fpguard \
 	pio_cksum_asynch pio_cksum_writer pio_cksum_cdf \
 	test_resource_copy pio_write_deco2d_run \
-	test_f2003
+	test_f2003 test_cdf_transformation
 check_PROGRAMS = cksum_verify test_grib cksum_write cksum_read pio_write \
 	test_resource_copy cksum_write_chunk pio_write_deco2d
 
+if ENABLE_NETCDF
+check_PROGRAMS += test_cdf_write test_cdf_read
+endif
+
 #
 test_grib_SOURCES = test_grib.c
 cksum_verify_SOURCES = cksum_verify.c
-cksum_write_SOURCES = cksum_write.c
-cksum_write_chunk_SOURCES = cksum_write_chunk.c
+cksum_write_SOURCES = cksum_write.c simple_model_helper.h simple_model_helper.c
+cksum_write_chunk_SOURCES = cksum_write_chunk.c simple_model_helper.h simple_model_helper.c
 cksum_read_SOURCES = cksum_read.c \
 	var_cksum.c var_cksum.h \
 	stream_cksum.c stream_cksum.h \
 	ensure_array_size.h ensure_array_size.c
 pio_write_SOURCES = pio_write.c pio_write.h simple_model.c \
-	simple_model_helper.h simple_model_helper.c
+	simple_model_helper.h simple_model_helper.c \
+	create_uuid.h create_uuid.c
 pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c \
-	simple_model_helper.h simple_model_helper.c
+	simple_model_helper.h simple_model_helper.c \
+	create_uuid.h create_uuid.c
 test_resource_copy_SOURCES = test_resource_copy.c \
-	$(top_srcdir)/src/resource_unpack.c
-test_resource_copy_mpi_SOURCES = test_resource_copy.c
-#
+	create_uuid.h create_uuid.c
+test_resource_copy_LDADD = $(UUID_C_LIB) ../src/libcdiresunpack.la $(LDADD)
+test_resource_copy_mpi_SOURCES = test_resource_copy.c \
+	create_uuid.h create_uuid.c
+test_cdf_write_SOURCES = test_cdf_write.c
+test_cdf_read_SOURCES = test_cdf_read.c
+
 AM_CFLAGS = $(PPM_CORE_CFLAGS) $(YAXT_CFLAGS)
 if USE_MPI
-pio_write_LDADD = ../src/libcdipio.la
-pio_write_deco2d_LDADD = ../src/libcdipio.la
+pio_write_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
+pio_write_deco2d_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
 TESTS +=  test_resource_copy_mpi_run
 check_PROGRAMS += test_resource_copy_mpi
-test_resource_copy_mpi_LDADD = ../src/libcdipio.la
+test_resource_copy_mpi_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
 test_resource_copy_mpi_CFLAGS = $(AM_CFLAGS) $(CFLAGS) -DMPI_MARSHALLING
 else
-pio_write_LDADD = $(LDADD)
-pio_write_deco2d_LDADD = $(LDADD)
+pio_write_LDADD = $(LDADD) $(UUID_C_LIB)
+pio_write_deco2d_LDADD = $(LDADD) $(UUID_C_LIB)
+test_resource_copy_mpi_LDADD = $(LDADD) $(UUID_C_LIB)
 endif
 
 LDADD = ../src/libcdi.la -lm
 AM_CPPFLAGS = -I$(top_srcdir)/src
 #
-# EXTRA_DIST = $(TESTS)
+EXTRA_DIST = test_cdf_write.c test_cdf_read.c
 #
 CLEANFILES  = `ls *~ *.grb *.nc *.srv *.ext example_*.cksum`
 #
diff --git a/libcdi/tests/Makefile.in b/libcdi/tests/Makefile.in
index 9950792..f08ea25 100644
--- a/libcdi/tests/Makefile.in
+++ b/libcdi/tests/Makefile.in
@@ -82,13 +82,15 @@ TESTS = cksum_verify$(EXEEXT) test_cksum_grib test_cksum_nc \
 	test_cksum_nc4 test_cksum_ieg test_chunk_cksum pio_write_run \
 	pio_cksum_mpinonb pio_cksum_fpguard pio_cksum_asynch \
 	pio_cksum_writer pio_cksum_cdf test_resource_copy$(EXEEXT) \
-	pio_write_deco2d_run test_f2003 $(am__append_1)
+	pio_write_deco2d_run test_f2003 test_cdf_transformation \
+	$(am__append_2)
 check_PROGRAMS = cksum_verify$(EXEEXT) test_grib$(EXEEXT) \
 	cksum_write$(EXEEXT) cksum_read$(EXEEXT) pio_write$(EXEEXT) \
 	test_resource_copy$(EXEEXT) cksum_write_chunk$(EXEEXT) \
-	pio_write_deco2d$(EXEEXT) $(am__EXEEXT_1)
- at USE_MPI_TRUE@am__append_1 = test_resource_copy_mpi_run
- at USE_MPI_TRUE@am__append_2 = test_resource_copy_mpi
+	pio_write_deco2d$(EXEEXT) $(am__EXEEXT_1) $(am__EXEEXT_2)
+ at ENABLE_NETCDF_TRUE@am__append_1 = test_cdf_write test_cdf_read
+ at USE_MPI_TRUE@am__append_2 = test_resource_copy_mpi_run
+ at USE_MPI_TRUE@am__append_3 = test_resource_copy_mpi
 subdir = tests
 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
 	$(top_srcdir)/config/mkinstalldirs \
@@ -102,6 +104,7 @@ DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
 	$(srcdir)/pio_cksum_asynch.in $(srcdir)/pio_cksum_writer.in \
 	$(srcdir)/pio_cksum_cdf.in \
 	$(srcdir)/test_resource_copy_mpi_run.in \
+	$(srcdir)/test_cdf_transformation.in \
 	$(top_srcdir)/config/depcomp
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps =  \
@@ -126,9 +129,11 @@ CONFIG_CLEAN_FILES = test_cksum_grib test_cksum_nc test_cksum_nc2 \
 	test_cksum_ieg test_chunk_cksum test_f2003 pio_write_run \
 	pio_write_deco2d_run pio_cksum_mpinonb pio_cksum_fpguard \
 	pio_cksum_asynch pio_cksum_writer pio_cksum_cdf \
-	test_resource_copy_mpi_run
+	test_resource_copy_mpi_run test_cdf_transformation
 CONFIG_CLEAN_VPATH_FILES =
- at USE_MPI_TRUE@am__EXEEXT_1 = test_resource_copy_mpi$(EXEEXT)
+ at ENABLE_NETCDF_TRUE@am__EXEEXT_1 = test_cdf_write$(EXEEXT) \
+ at ENABLE_NETCDF_TRUE@	test_cdf_read$(EXEEXT)
+ at USE_MPI_TRUE@am__EXEEXT_2 = test_resource_copy_mpi$(EXEEXT)
 am_cksum_read_OBJECTS = cksum_read.$(OBJEXT) var_cksum.$(OBJEXT) \
 	stream_cksum.$(OBJEXT) ensure_array_size.$(OBJEXT)
 cksum_read_OBJECTS = $(am_cksum_read_OBJECTS)
@@ -142,39 +147,58 @@ am_cksum_verify_OBJECTS = cksum_verify.$(OBJEXT)
 cksum_verify_OBJECTS = $(am_cksum_verify_OBJECTS)
 cksum_verify_LDADD = $(LDADD)
 cksum_verify_DEPENDENCIES = ../src/libcdi.la
-am_cksum_write_OBJECTS = cksum_write.$(OBJEXT)
+am_cksum_write_OBJECTS = cksum_write.$(OBJEXT) \
+	simple_model_helper.$(OBJEXT)
 cksum_write_OBJECTS = $(am_cksum_write_OBJECTS)
 cksum_write_LDADD = $(LDADD)
 cksum_write_DEPENDENCIES = ../src/libcdi.la
-am_cksum_write_chunk_OBJECTS = cksum_write_chunk.$(OBJEXT)
+am_cksum_write_chunk_OBJECTS = cksum_write_chunk.$(OBJEXT) \
+	simple_model_helper.$(OBJEXT)
 cksum_write_chunk_OBJECTS = $(am_cksum_write_chunk_OBJECTS)
 cksum_write_chunk_LDADD = $(LDADD)
 cksum_write_chunk_DEPENDENCIES = ../src/libcdi.la
 am_pio_write_OBJECTS = pio_write.$(OBJEXT) simple_model.$(OBJEXT) \
-	simple_model_helper.$(OBJEXT)
+	simple_model_helper.$(OBJEXT) create_uuid.$(OBJEXT)
 pio_write_OBJECTS = $(am_pio_write_OBJECTS)
 am__DEPENDENCIES_1 = ../src/libcdi.la
- at USE_MPI_FALSE@pio_write_DEPENDENCIES = $(am__DEPENDENCIES_1)
- at USE_MPI_TRUE@pio_write_DEPENDENCIES = ../src/libcdipio.la
+am__DEPENDENCIES_2 =
+ at USE_MPI_FALSE@pio_write_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+ at USE_MPI_FALSE@	$(am__DEPENDENCIES_2)
+ at USE_MPI_TRUE@pio_write_DEPENDENCIES = ../src/libcdipio.la \
+ at USE_MPI_TRUE@	$(am__DEPENDENCIES_2)
 am_pio_write_deco2d_OBJECTS = pio_write.$(OBJEXT) \
-	deco2d_model.$(OBJEXT) simple_model_helper.$(OBJEXT)
+	deco2d_model.$(OBJEXT) simple_model_helper.$(OBJEXT) \
+	create_uuid.$(OBJEXT)
 pio_write_deco2d_OBJECTS = $(am_pio_write_deco2d_OBJECTS)
- at USE_MPI_FALSE@pio_write_deco2d_DEPENDENCIES = $(am__DEPENDENCIES_1)
- at USE_MPI_TRUE@pio_write_deco2d_DEPENDENCIES = ../src/libcdipio.la
+ at USE_MPI_FALSE@pio_write_deco2d_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+ at USE_MPI_FALSE@	$(am__DEPENDENCIES_2)
+ at USE_MPI_TRUE@pio_write_deco2d_DEPENDENCIES = ../src/libcdipio.la \
+ at USE_MPI_TRUE@	$(am__DEPENDENCIES_2)
+am_test_cdf_read_OBJECTS = test_cdf_read.$(OBJEXT)
+test_cdf_read_OBJECTS = $(am_test_cdf_read_OBJECTS)
+test_cdf_read_LDADD = $(LDADD)
+test_cdf_read_DEPENDENCIES = ../src/libcdi.la
+am_test_cdf_write_OBJECTS = test_cdf_write.$(OBJEXT)
+test_cdf_write_OBJECTS = $(am_test_cdf_write_OBJECTS)
+test_cdf_write_LDADD = $(LDADD)
+test_cdf_write_DEPENDENCIES = ../src/libcdi.la
 am_test_grib_OBJECTS = test_grib.$(OBJEXT)
 test_grib_OBJECTS = $(am_test_grib_OBJECTS)
 test_grib_LDADD = $(LDADD)
 test_grib_DEPENDENCIES = ../src/libcdi.la
 am_test_resource_copy_OBJECTS = test_resource_copy.$(OBJEXT) \
-	resource_unpack.$(OBJEXT)
+	create_uuid.$(OBJEXT)
 test_resource_copy_OBJECTS = $(am_test_resource_copy_OBJECTS)
-test_resource_copy_LDADD = $(LDADD)
-test_resource_copy_DEPENDENCIES = ../src/libcdi.la
+test_resource_copy_DEPENDENCIES = $(am__DEPENDENCIES_2) \
+	../src/libcdiresunpack.la $(am__DEPENDENCIES_1)
 am_test_resource_copy_mpi_OBJECTS =  \
-	test_resource_copy_mpi-test_resource_copy.$(OBJEXT)
+	test_resource_copy_mpi-test_resource_copy.$(OBJEXT) \
+	test_resource_copy_mpi-create_uuid.$(OBJEXT)
 test_resource_copy_mpi_OBJECTS = $(am_test_resource_copy_mpi_OBJECTS)
+ at USE_MPI_FALSE@test_resource_copy_mpi_DEPENDENCIES =  \
+ at USE_MPI_FALSE@	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
 @USE_MPI_TRUE at test_resource_copy_mpi_DEPENDENCIES =  \
- at USE_MPI_TRUE@	../src/libcdipio.la
+ at USE_MPI_TRUE@	../src/libcdipio.la $(am__DEPENDENCIES_2)
 test_resource_copy_mpi_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
 	$(test_resource_copy_mpi_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
@@ -216,11 +240,13 @@ am__v_CCLD_1 =
 SOURCES = $(cksum_read_SOURCES) $(cksum_verify_SOURCES) \
 	$(cksum_write_SOURCES) $(cksum_write_chunk_SOURCES) \
 	$(pio_write_SOURCES) $(pio_write_deco2d_SOURCES) \
+	$(test_cdf_read_SOURCES) $(test_cdf_write_SOURCES) \
 	$(test_grib_SOURCES) $(test_resource_copy_SOURCES) \
 	$(test_resource_copy_mpi_SOURCES)
 DIST_SOURCES = $(cksum_read_SOURCES) $(cksum_verify_SOURCES) \
 	$(cksum_write_SOURCES) $(cksum_write_chunk_SOURCES) \
 	$(pio_write_SOURCES) $(pio_write_deco2d_SOURCES) \
+	$(test_cdf_read_SOURCES) $(test_cdf_write_SOURCES) \
 	$(test_grib_SOURCES) $(test_resource_copy_SOURCES) \
 	$(test_resource_copy_mpi_SOURCES)
 am__can_run_installinfo = \
@@ -394,6 +420,7 @@ THREADS_INCLUDE = @THREADS_INCLUDE@
 THREADS_LIBS = @THREADS_LIBS@
 USER_NAME = @USER_NAME@
 USE_MPI = @USE_MPI@
+UUID_C_LIB = @UUID_C_LIB@
 VERSION = @VERSION@
 YAXT_CFLAGS = @YAXT_CFLAGS@
 YAXT_LIBS = @YAXT_LIBS@
@@ -460,35 +487,42 @@ top_srcdir = @top_srcdir@
 #
 test_grib_SOURCES = test_grib.c
 cksum_verify_SOURCES = cksum_verify.c
-cksum_write_SOURCES = cksum_write.c
-cksum_write_chunk_SOURCES = cksum_write_chunk.c
+cksum_write_SOURCES = cksum_write.c simple_model_helper.h simple_model_helper.c
+cksum_write_chunk_SOURCES = cksum_write_chunk.c simple_model_helper.h simple_model_helper.c
 cksum_read_SOURCES = cksum_read.c \
 	var_cksum.c var_cksum.h \
 	stream_cksum.c stream_cksum.h \
 	ensure_array_size.h ensure_array_size.c
 
 pio_write_SOURCES = pio_write.c pio_write.h simple_model.c \
-	simple_model_helper.h simple_model_helper.c
+	simple_model_helper.h simple_model_helper.c \
+	create_uuid.h create_uuid.c
 
 pio_write_deco2d_SOURCES = pio_write.c pio_write.h deco2d_model.c \
-	simple_model_helper.h simple_model_helper.c
+	simple_model_helper.h simple_model_helper.c \
+	create_uuid.h create_uuid.c
 
 test_resource_copy_SOURCES = test_resource_copy.c \
-	$(top_srcdir)/src/resource_unpack.c
+	create_uuid.h create_uuid.c
 
-test_resource_copy_mpi_SOURCES = test_resource_copy.c
-#
+test_resource_copy_LDADD = $(UUID_C_LIB) ../src/libcdiresunpack.la $(LDADD)
+test_resource_copy_mpi_SOURCES = test_resource_copy.c \
+	create_uuid.h create_uuid.c
+
+test_cdf_write_SOURCES = test_cdf_write.c
+test_cdf_read_SOURCES = test_cdf_read.c
 AM_CFLAGS = $(PPM_CORE_CFLAGS) $(YAXT_CFLAGS)
- at USE_MPI_FALSE@pio_write_LDADD = $(LDADD)
- at USE_MPI_TRUE@pio_write_LDADD = ../src/libcdipio.la
- at USE_MPI_FALSE@pio_write_deco2d_LDADD = $(LDADD)
- at USE_MPI_TRUE@pio_write_deco2d_LDADD = ../src/libcdipio.la
- at USE_MPI_TRUE@test_resource_copy_mpi_LDADD = ../src/libcdipio.la
+ at USE_MPI_FALSE@pio_write_LDADD = $(LDADD) $(UUID_C_LIB)
+ at USE_MPI_TRUE@pio_write_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
+ at USE_MPI_FALSE@pio_write_deco2d_LDADD = $(LDADD) $(UUID_C_LIB)
+ at USE_MPI_TRUE@pio_write_deco2d_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
+ at USE_MPI_FALSE@test_resource_copy_mpi_LDADD = $(LDADD) $(UUID_C_LIB)
+ at USE_MPI_TRUE@test_resource_copy_mpi_LDADD = ../src/libcdipio.la $(UUID_C_LIB)
 @USE_MPI_TRUE at test_resource_copy_mpi_CFLAGS = $(AM_CFLAGS) $(CFLAGS) -DMPI_MARSHALLING
 LDADD = ../src/libcdi.la -lm
 AM_CPPFLAGS = -I$(top_srcdir)/src
 #
-# EXTRA_DIST = $(TESTS)
+EXTRA_DIST = test_cdf_write.c test_cdf_read.c
 #
 CLEANFILES = `ls *~ *.grb *.nc *.srv *.ext example_*.cksum`
 #
@@ -561,6 +595,8 @@ pio_cksum_cdf: $(top_builddir)/config.status $(srcdir)/pio_cksum_cdf.in
 	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
 test_resource_copy_mpi_run: $(top_builddir)/config.status $(srcdir)/test_resource_copy_mpi_run.in
 	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
+test_cdf_transformation: $(top_builddir)/config.status $(srcdir)/test_cdf_transformation.in
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
 
 clean-checkPROGRAMS:
 	@list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
@@ -595,6 +631,14 @@ pio_write_deco2d$(EXEEXT): $(pio_write_deco2d_OBJECTS) $(pio_write_deco2d_DEPEND
 	@rm -f pio_write_deco2d$(EXEEXT)
 	$(AM_V_CCLD)$(LINK) $(pio_write_deco2d_OBJECTS) $(pio_write_deco2d_LDADD) $(LIBS)
 
+test_cdf_read$(EXEEXT): $(test_cdf_read_OBJECTS) $(test_cdf_read_DEPENDENCIES) $(EXTRA_test_cdf_read_DEPENDENCIES) 
+	@rm -f test_cdf_read$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(test_cdf_read_OBJECTS) $(test_cdf_read_LDADD) $(LIBS)
+
+test_cdf_write$(EXEEXT): $(test_cdf_write_OBJECTS) $(test_cdf_write_DEPENDENCIES) $(EXTRA_test_cdf_write_DEPENDENCIES) 
+	@rm -f test_cdf_write$(EXEEXT)
+	$(AM_V_CCLD)$(LINK) $(test_cdf_write_OBJECTS) $(test_cdf_write_LDADD) $(LIBS)
+
 test_grib$(EXEEXT): $(test_grib_OBJECTS) $(test_grib_DEPENDENCIES) $(EXTRA_test_grib_DEPENDENCIES) 
 	@rm -f test_grib$(EXEEXT)
 	$(AM_V_CCLD)$(LINK) $(test_grib_OBJECTS) $(test_grib_LDADD) $(LIBS)
@@ -617,15 +661,18 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cksum_verify.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cksum_write.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cksum_write_chunk.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/create_uuid.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/deco2d_model.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ensure_array_size.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pio_write.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/resource_unpack.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/simple_model.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/simple_model_helper.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/stream_cksum.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/test_cdf_read.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/test_cdf_write.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/test_grib.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/test_resource_copy.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/test_resource_copy_mpi-create_uuid.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/test_resource_copy_mpi-test_resource_copy.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/var_cksum.Po at am__quote@
 
@@ -650,20 +697,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
-resource_unpack.o: $(top_srcdir)/src/resource_unpack.c
- at am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT resource_unpack.o -MD -MP -MF $(DEPDIR)/resource_unpack.Tpo -c -o resource_unpack.o `test -f '$(top_srcdir)/src/resource_unpack.c' || echo '$(srcdir)/'`$(top_srcdir)/src/resource_unpack.c
- at am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/resource_unpack.Tpo $(DEPDIR)/resource_unpack.Po
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$(top_srcdir)/src/resource_unpack.c' object='resource_unpack.o' libtool=no @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o resource_unpack.o `test -f '$(top_srcdir)/src/resource_unpack.c' || echo '$(srcdir)/'`$(top_srcdir)/src/resource_unpack.c
-
-resource_unpack.obj: $(top_srcdir)/src/resource_unpack.c
- at am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT resource_unpack.obj -MD -MP -MF $(DEPDIR)/resource_unpack.Tpo -c -o resource_unpack.obj `if test -f '$(top_srcdir)/src/resource_unpack.c'; then $(CYGPATH_W) '$(top_srcdir)/src/resource_unpack.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/src/resource_unpack.c'; fi`
- at am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/resource_unpack.Tpo $(DEPDIR)/resource_unpack.Po
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$(top_srcdir)/src/resource_unpack.c' object='resource_unpack.obj' libtool=no @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o resource_unpack.obj `if test -f '$(top_srcdir)/src/resource_unpack.c'; then $(CYGPATH_W) '$(top_srcdir)/src/resource_unpack.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/src/resource_unpack.c'; fi`
-
 test_resource_copy_mpi-test_resource_copy.o: test_resource_copy.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -MT test_resource_copy_mpi-test_resource_copy.o -MD -MP -MF $(DEPDIR)/test_resource_copy_mpi-test_resource_copy.Tpo -c -o test_resource_copy_mpi-test_resource_copy.o `test -f 'test_resource_copy.c' || echo '$(srcdir)/'`test_resource_copy.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/test_resource_copy_mpi-test_resource_copy.Tpo $(DEPDIR)/test_resource_copy_mpi-test_resource_copy.Po
@@ -678,6 +711,20 @@ test_resource_copy_mpi-test_resource_copy.obj: test_resource_copy.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -c -o test_resource_copy_mpi-test_resource_copy.obj `if test -f 'test_resource_copy.c'; then $(CYGPATH_W) 'test_resource_copy.c'; else $(CYGPATH_W) '$(srcdir)/test_resource_copy.c'; fi`
 
+test_resource_copy_mpi-create_uuid.o: create_uuid.c
+ at am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -MT test_resource_copy_mpi-create_uuid.o -MD -MP -MF $(DEPDIR)/test_resource_copy_mpi-create_uuid.Tpo -c -o test_resource_copy_mpi-create_uuid.o `test -f 'create_uuid.c' || echo '$(srcdir)/'`create_uuid.c
+ at am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/test_resource_copy_mpi-create_uuid.Tpo $(DEPDIR)/test_resource_copy_mpi-create_uuid.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='create_uuid.c' object='test_resource_copy_mpi-create_uuid.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -c -o test_resource_copy_mpi-create_uuid.o `test -f 'create_uuid.c' || echo '$(srcdir)/'`create_uuid.c
+
+test_resource_copy_mpi-create_uuid.obj: create_uuid.c
+ at am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -MT test_resource_copy_mpi-create_uuid.obj -MD -MP -MF $(DEPDIR)/test_resource_copy_mpi-create_uuid.Tpo -c -o test_resource_copy_mpi-create_uuid.obj `if test -f 'create_uuid.c'; then $(CYGPATH_W) 'create_uuid.c'; else $(CYGPATH_W) '$(srcdir)/create_uuid.c'; fi`
+ at am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/test_resource_copy_mpi-create_uuid.Tpo $(DEPDIR)/test_resource_copy_mpi-create_uuid.Po
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='create_uuid.c' object='test_resource_copy_mpi-create_uuid.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(AM_V_CC at am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_resource_copy_mpi_CFLAGS) $(CFLAGS) -c -o test_resource_copy_mpi-create_uuid.obj `if test -f 'create_uuid.c'; then $(CYGPATH_W) 'create_uuid.c'; else $(CYGPATH_W) '$(srcdir)/create_uuid.c'; fi`
+
 mostlyclean-libtool:
 	-rm -f *.lo
 
diff --git a/libcdi/tests/cksum_read.c b/libcdi/tests/cksum_read.c
index b39fc01..df52cda 100644
--- a/libcdi/tests/cksum_read.c
+++ b/libcdi/tests/cksum_read.c
@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
     size_t num_ref_entries;
     struct cksum_table *ref_var_table
       = read_table(table_fname, &num_ref_entries);
-    if (num_ref_entries == -1)
+    if (num_ref_entries == (size_t)-1)
       exit(EXIT_FAILURE);
     retcode
       = compare_checksums(file_vars, nvars, "file",
diff --git a/libcdi/tests/cksum_write.c b/libcdi/tests/cksum_write.c
index 98acb19..f0eff94 100644
--- a/libcdi/tests/cksum_write.c
+++ b/libcdi/tests/cksum_write.c
@@ -14,7 +14,7 @@
 #include "cdi.h"
 
 #include "cksum.h"
-
+#include "simple_model_helper.h"
 
 static int
 parse_intarg(const char msg[])
@@ -34,14 +34,6 @@ parse_intarg(const char msg[])
   return (int)temp;
 }
 
-static inline double
-sign_flat(double v)
-{
-  if (v == 0.0)
-    return 0.0;
-  return v;
-}
-
 static void
 allocError(const char *msg)
 {
@@ -54,8 +46,8 @@ fname_create(const char *prefix, const char *suffix)
 {
   size_t prefix_len, suffix_len;
   char *fname;
-  if (!(fname =malloc((prefix_len = strlen(prefix)) + 1
-                      + (suffix_len = strlen(suffix)) + 1)))
+  if (!(fname = malloc((prefix_len = strlen(prefix)) + 1
+                       + (suffix_len = strlen(suffix)) + 1)))
     allocError("cannot create string");
   strcpy(fname, prefix);
   fname[prefix_len] = '.';
@@ -148,7 +140,7 @@ main(int argc, char *argv[])
       case 'f':
         {
           int found = 0;
-          for (i = 0;
+          for (size_t i = 0;
                i < sizeof (suffix2type) / sizeof (suffix2type[0]);
                ++i)
             if (!strcmp(optarg, suffix2type[i].suffix))
@@ -224,6 +216,28 @@ main(int argc, char *argv[])
   zaxisID[1] = zaxisCreate(ZAXIS_PRESSURE, nlev);
   zaxisDefLevels(zaxisID[1], levs);
 
+  /* add uuids to zaxis and grid */
+  {
+    unsigned char uuid[16];
+    int str2uuid(const char *uuidstr, unsigned char *uuid);
+
+    static char gridUUIDTxt[] = "107d7a5b-348c-4d1a-90a9-d745914f2fb6";
+
+    str2uuid(gridUUIDTxt, uuid);
+    gridDefUUID(gridID, uuid);
+
+    static char zaxisUUIDTxt[2][37] = {
+      { "d157f399-5496-4097-a3d8-437a6dda6311" },
+      { "6f784a65-bce8-48c9-afa4-4c40130709c7" }
+    };
+
+    for (int i = 0; i < 2; ++i)
+      {
+        str2uuid(zaxisUUIDTxt[i], uuid);
+        zaxisDefUUID(zaxisID[i], uuid);
+      }
+  }
+
   // Create a Time axis
   taxisID = taxisCreate(TAXIS_ABSOLUTE);
 
@@ -244,41 +258,12 @@ main(int argc, char *argv[])
       var[i] = malloc(varSize[i] * sizeof (var[i][0]));
     }
 
-  {
-    int mant_bits;
-    switch (datatype)
-      {
-      case DATATYPE_PACK8:
-        mant_bits = 7;
-        break;
-      case DATATYPE_PACK16:
-        mant_bits = 15;
-        break;
-      case DATATYPE_PACK24:
-        mant_bits = 23;
-        break;
-      case DATATYPE_FLT32:
-        mant_bits = 24;
-        break;
-      case DATATYPE_FLT64:
-        mant_bits = 53;
-        break;
-      case DATATYPE_INT8:
-      case DATATYPE_INT16:
-      case DATATYPE_INT32:
-      default:
-        fprintf(stderr, "Unexpected or unusable content format: %d\n",
-                datatype);
-        exit(EXIT_FAILURE);
-      }
-    mscale = (double)(INT64_C(1) << mant_bits);
-    mrscale = 1.0/mscale;
-  }
+  var_scale(datatype, &mscale, &mrscale);
 
   // Assign the Time axis to the variable list
   vlistDefTaxis(vlistID, taxisID);
 
-  // Create a dataset in netCDF fromat
+  // Create a dataset
   {
     char *fname = fname_create(prefix, suffix);
     if ((streamID = streamOpenWrite(fname, filetype)) < 0)
@@ -298,10 +283,11 @@ main(int argc, char *argv[])
     // Loop over the number of time steps
     for ( tsID = 0; tsID < nts; tsID++ )
       {
+        int vdatetime[2] = { 120000, 19850101+tsID };
         // Set the verification date to 1985-01-01 + tsID
-        taxisDefVdate(taxisID, 19850101+tsID);
+        taxisDefVdate(taxisID, vdatetime[1]);
         // Set the verification time to 12:00:00
-        taxisDefVtime(taxisID, 120000);
+        taxisDefVtime(taxisID, vdatetime[0]);
         // Define the time step
         streamDefTimestep(streamID, tsID);
 
@@ -326,7 +312,17 @@ main(int argc, char *argv[])
                             / (lons[nlat-1] - lats[0]))
                       ) * mscale)) * mrscale;
 
+        if (filetype == FILETYPE_EXT)
+          {
+            /* EXTRA doesn't store time, only date
+             * set the value to 0 before checksumming, because a
+             * time field of 0 is what reading an EXTRA file will
+             * return */
+            vdatetime[0] = 0;
+          }
+        memcrc_r(&checksum_state[0], (const unsigned char *)vdatetime, sizeof (vdatetime));
         memcrc_r(&checksum_state[0], (const unsigned char *)var[0], varSize[0] * sizeof (var[0][0]));
+        memcrc_r(&checksum_state[1], (const unsigned char *)vdatetime, sizeof (vdatetime));
         memcrc_r(&checksum_state[1], (const unsigned char *)var[1], varSize[1] * sizeof (var[1][0]));
 
         // Write var1 and var2
@@ -380,9 +376,10 @@ main(int argc, char *argv[])
         {
           uint32_t cksum;
           int code;
-          cksum = memcrc_finish(&checksum_state[i],
-                                (off_t)(varSize[i] * sizeof (var[i][0])
-                                        * (size_t)nts));
+          cksum
+            = memcrc_finish(&checksum_state[i],
+                            (off_t)((varSize[i] * sizeof (var[i][0])
+                                     + sizeof (int) * 2) * (size_t)nts));
           code = vlistInqVarCode(vlistID, varID[i]);
           if (fprintf(tablefp, "%08lx %d\n", (unsigned long)cksum, code) < 0)
             {
diff --git a/libcdi/tests/create_uuid.c b/libcdi/tests/create_uuid.c
new file mode 100644
index 0000000..d15e3d1
--- /dev/null
+++ b/libcdi/tests/create_uuid.c
@@ -0,0 +1,91 @@
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
+#define _XOPEN_SOURCE 600
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "create_uuid.h"
+
+
+
+#ifdef HAVE_DECL_UUID_GENERATE
+#include <sys/time.h>
+#include <uuid/uuid.h>
+void
+create_uuid(unsigned char *uuid)
+{
+  static int uuid_seeded = 0;
+  static char uuid_rand_state[31 * sizeof (long)];
+  char *caller_rand_state;
+  if (uuid_seeded)
+    caller_rand_state = setstate(uuid_rand_state);
+  else
+    {
+      struct timeval tv;
+      int status = gettimeofday(&tv, NULL);
+      if (status != 0)
+        {
+          perror("uuid random seed generation failed!");
+          exit(1);
+        }
+      unsigned seed = (unsigned)(tv.tv_sec ^ tv.tv_usec);
+      caller_rand_state = initstate(seed, uuid_rand_state,
+                                    sizeof (uuid_rand_state));
+      uuid_seeded = 1;
+    }
+  uuid_generate(uuid);
+  setstate(caller_rand_state);
+}
+#elif defined (HAVE_DECL_UUID_CREATE)
+typedef uint8_t u_int8_t;
+typedef uint16_t u_int16_t;
+typedef uint32_t u_int32_t;
+#include <uuid.h>
+void
+create_uuid(unsigned char *uuid)
+{
+  unsigned32 status;
+  uuid_create((uuid_t *)uuid, &status);
+  if (status == -1)
+    {
+      perror("uuid generation failed!");
+      exit(1);
+    }
+}
+#else
+#include <sys/time.h>
+void
+create_uuid(unsigned char *uuid)
+{
+  static int uuid_seeded = 0;
+  static char uuid_rand_state[31 * sizeof (long)];
+  char *caller_rand_state;
+  if (uuid_seeded)
+    caller_rand_state = setstate(uuid_rand_state);
+  else
+    {
+      struct timeval tv;
+      int status = gettimeofday(&tv, NULL);
+      if (status != 0)
+        {
+          perror("failed seed generation!");
+          exit(1);
+        }
+      unsigned seed = tv.tv_sec ^ tv.tv_usec;
+      caller_rand_state = initstate(seed, uuid_rand_state,
+                                    sizeof (uuid_rand_state));
+      uuid_seeded = 1;
+    }
+  for (size_t i = 0; i < CDI_UUID_SIZE; ++i)
+    uuid[i] = (unsigned char)random();
+  /* encode variant into msb of octet 8 */
+  uuid[8] = (unsigned char)((uuid[8] & 0x3f) | (1 << 7));
+  /* encode version 4 ((pseudo-)random uuid) into msb of octet 7 */
+  uuid[7] = (unsigned char)((uuid[7] & 0x0f) | (4 << 4));
+  setstate(caller_rand_state);
+}
+#endif
diff --git a/libcdi/tests/create_uuid.h b/libcdi/tests/create_uuid.h
new file mode 100644
index 0000000..6b031b3
--- /dev/null
+++ b/libcdi/tests/create_uuid.h
@@ -0,0 +1,13 @@
+#ifndef CREATE_UUID_H
+#define CREATE_UUID_H
+
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
+#include "cdi.h"
+
+void
+create_uuid(unsigned char uuid[CDI_UUID_SIZE]);
+
+#endif
diff --git a/libcdi/tests/deco2d_model.c b/libcdi/tests/deco2d_model.c
index 7e84bf7..e5b2e4d 100644
--- a/libcdi/tests/deco2d_model.c
+++ b/libcdi/tests/deco2d_model.c
@@ -43,6 +43,7 @@ modelRegionCompute(double region[], int nlev, int nlat, int nlon,
                    int tsID, const double lons[], const double lats[],
                    double mscale, double mrscale)
 {
+  (void)nlev;
   unsigned is = (unsigned)chunkStart[0],
     js = (unsigned)chunkStart[1],
     ks = (unsigned)chunkStart[2],
@@ -131,7 +132,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
       rank_coord[0] = rank % npart[0],
         rank_coord[1] = rank / npart[0];
     }
-  blk_displ = xmalloc(setup.max_nlev * sizeof (blk_displ[0]) * 2);
+  blk_displ = xmalloc((size_t)setup.max_nlev * sizeof (blk_displ[0]) * 2);
   blk_lens = blk_displ + setup.max_nlev;
 #endif
 
@@ -174,7 +175,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
         }
       ++varLevs;
       varDesc[varIdx].nlev = varLevs;
-      for (size_t i = 0; i < varIdx; ++i)
+      for (size_t i = 0; i < (size_t)varIdx; ++i)
         if (varDesc[i].nlev == varLevs)
           {
             varDesc[varIdx].zaxisID = varDesc[i].zaxisID;
@@ -224,14 +225,14 @@ modelRun(struct model_config setup, MPI_Comm comm)
               {
                 gather_idxlist
                   = xt_idxstripes_new(&(struct Xt_stripe){.start = 0,
-                        .stride = 1, .nstrides = varDesc[varIdx].size }, 1);
+                        .stride = 1, .nstrides = (int)varDesc[varIdx].size }, 1);
               }
             else
               gather_idxlist = xt_idxempty_new();
             Xt_xmap xmap4gather
               = xt_xmap_all2all_new(part_idxlist, gather_idxlist, comm);
             xt_idxlist_delete(gather_idxlist);
-            struct Xt_offset_ext *src_blocks = xmalloc(varLevs
+            struct Xt_offset_ext *src_blocks = xmalloc((size_t)varLevs
                                                        * sizeof (*src_blocks));
             struct Xt_offset_ext dst_block = { .start = 0,
                                                .size = nlon * nlat * varLevs,
@@ -241,7 +242,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
                  / nproma) * nproma;
             for (size_t i = 0; i < (size_t)varLevs; ++i)
               src_blocks[i] = (struct Xt_offset_ext)
-                { .start = (int)i * levStride,
+                { .start = (int)(i * levStride),
                   .size = chunkSize[0] * chunkSize[1],
                   .stride = 1 };
             varDesc[varIdx].redist4gather
@@ -288,9 +289,10 @@ modelRun(struct model_config setup, MPI_Comm comm)
       current_time = cditime2time_t(vdate, vtime);
       for ( tsID = 0; tsID < setup.nts; tsID++ )
 	{
-          time_t2cditime(current_time, &vdate, &vtime);
-	  taxisDefVdate ( taxisID, vdate );
-	  taxisDefVtime ( taxisID, vtime );
+          int vdatetime[2];
+          time_t2cditime(current_time, &vdatetime[1], &vdatetime[0]);
+	  taxisDefVdate(taxisID, vdatetime[1]);
+	  taxisDefVtime(taxisID, vdatetime[0]);
 	  streamDefTimestep ( streamID, tsID );
 	  for (int varID = 0; varID < nVars; ++varID)
 	    {
@@ -326,8 +328,8 @@ modelRun(struct model_config setup, MPI_Comm comm)
                   size_t nblk = (layerSize + nproma - 1)/nproma - 1;
                   for (size_t k = 0; k < varLevs; ++k)
                     {
-                      blk_displ[k] = k * (nblk + 1) * nproma;
-                      blk_lens[k] = layerSize;
+                      blk_displ[k] = (int)(k * (nblk + 1) * nproma);
+                      blk_lens[k] = (int)layerSize;
                     }
 #else
                   size_t layerSize = (size_t)(chunk[0] * chunk[1]);
@@ -348,6 +350,9 @@ modelRun(struct model_config setup, MPI_Comm comm)
               if (rank == 0 && setup.compute_checksum)
                 {
                   memcrc_r(&varDesc[varID].checksum_state,
+                           (const unsigned char *)vdatetime,
+                           sizeof (vdatetime));
+                  memcrc_r(&varDesc[varID].checksum_state,
                            (const unsigned char *)var,
                            varDesc[varID].size * sizeof (var[0]));
                 }
@@ -381,8 +386,9 @@ modelRun(struct model_config setup, MPI_Comm comm)
                 uint32_t cksum;
                 int code;
                 cksum = memcrc_finish(&varDesc[i].checksum_state,
-                                      (off_t)(varDesc[i].size
-                                              * sizeof (var[0])
+                                      (off_t)((varDesc[i].size
+                                               * sizeof (var[0])
+                                               + sizeof (int) * 2)
                                               * (size_t)setup.nts));
                 code = vlistInqVarCode(vlistID, varDesc[i].id);
                 if (fprintf(tablefp, "%08lx %d\n", (unsigned long)cksum,
@@ -444,26 +450,26 @@ findPartition2D(int npart[2], int num_parts)
   npart[0] = num_parts, npart[1] = 1;
   uint_fast32_t npart_attempt[2];
   uint64_t bestRatio = (uint64_t)num_parts * rscale,
-    bestDiff = llabs((long long)(bestRatio - optimumRatio));
+    bestDiff = (uint64_t)llabs((long long)(bestRatio - optimumRatio));
   /* test all assignments of factors to dimensions, starting with
    * only one assigned to x dim (omitting 0 because that would
    * always give npart[1] > npart[0] */
   for (int assign2X = 1; assign2X <= numFactors; ++assign2X)
     {
-      uint_fast32_t pattern = (1 << assign2X) - 1,
+      uint_fast32_t pattern = (UINT32_C(1) << assign2X) - 1,
         lastPattern = pattern << (numFactors - assign2X);
       do {
         npart_attempt[0] = 1;
         npart_attempt[1] = 1;
         /* loop over all factors */
-        for (uint_fast32_t i = 0; i < numFactors; ++i)
+        for (uint_fast32_t i = 0; i < (uint_fast32_t)numFactors; ++i)
           {
             uint_fast32_t dim_idx = (pattern >> i) & 1;
             npart_attempt[dim_idx] *= factors[i];
           }
         uint64_t ratio = ((uint64_t)npart_attempt[0] * rscale)
           / (uint64_t)npart_attempt[1];
-        uint64_t diff = llabs(ratio - optimumRatio);
+        uint64_t diff = (uint64_t)llabs((long long)(ratio - optimumRatio));
         if (diff < bestDiff)
           {
             npart[0] = (int)npart_attempt[0];
@@ -476,7 +482,7 @@ findPartition2D(int npart[2], int num_parts)
 #if HAVE_DECL___BUILTIN_CTZ
           t = pattern | (pattern - 1);
           pattern = (t + 1)
-            | (((~t & -~t) - 1) >> (__builtin_ctz(pattern) + 1));
+            | (((~t & -~t) - 1) >> (__builtin_ctz((unsigned)pattern) + 1));
 #else
           t = (pattern | (pattern - 1)) + 1;
           pattern = t | ((((t & -t) / (pattern & -pattern)) >> 1) - 1);
diff --git a/libcdi/tests/pio_cksum_asynch.in b/libcdi/tests/pio_cksum_asynch.in
index 71db070..0f431e3 100644
--- a/libcdi/tests/pio_cksum_asynch.in
+++ b/libcdi/tests/pio_cksum_asynch.in
@@ -6,4 +6,9 @@ if [ "@USE_MPI@" = yes ]; then
   . ./pio_write_run
 else
   exit 77
-fi
\ No newline at end of file
+fi
+#
+# Local Variables:
+# mode: sh
+# End:
+#
diff --git a/libcdi/tests/pio_cksum_cdf.in b/libcdi/tests/pio_cksum_cdf.in
index afa30ee..358091f 100644
--- a/libcdi/tests/pio_cksum_cdf.in
+++ b/libcdi/tests/pio_cksum_cdf.in
@@ -8,3 +8,8 @@ if [ "@USE_MPI@" = yes -a "@ENABLE_NETCDF@" = yes ]; then
 else
   exit 77
 fi
+#
+# Local Variables:
+# mode: sh
+# End:
+#
diff --git a/libcdi/tests/pio_cksum_fpguard.in b/libcdi/tests/pio_cksum_fpguard.in
index a242f12..61366ef 100644
--- a/libcdi/tests/pio_cksum_fpguard.in
+++ b/libcdi/tests/pio_cksum_fpguard.in
@@ -6,4 +6,9 @@ if [ "@USE_MPI@" = yes ]; then
   . ./pio_write_run
 else
   exit 77
-fi
\ No newline at end of file
+fi
+#
+# Local Variables:
+# mode: sh
+# End:
+#
diff --git a/libcdi/tests/pio_cksum_mpinonb.in b/libcdi/tests/pio_cksum_mpinonb.in
index 6b8ec34..b6ea976 100644
--- a/libcdi/tests/pio_cksum_mpinonb.in
+++ b/libcdi/tests/pio_cksum_mpinonb.in
@@ -6,4 +6,9 @@ if [ "@USE_MPI@" = yes ]; then
   . ./pio_write_run
 else
   exit 77
-fi
\ No newline at end of file
+fi
+#
+# Local Variables:
+# mode: sh
+# End:
+#
diff --git a/libcdi/tests/pio_cksum_writer.in b/libcdi/tests/pio_cksum_writer.in
index 2d284c1..02140d5 100644
--- a/libcdi/tests/pio_cksum_writer.in
+++ b/libcdi/tests/pio_cksum_writer.in
@@ -6,4 +6,9 @@ if [ "@USE_MPI@" = yes ]; then
   . ./pio_write_run
 else
   exit 77
-fi
\ No newline at end of file
+fi
+#
+# Local Variables:
+# mode: sh
+# End:
+#
diff --git a/libcdi/tests/pio_write.c b/libcdi/tests/pio_write.c
index 74524a5..3e064e3 100644
--- a/libcdi/tests/pio_write.c
+++ b/libcdi/tests/pio_write.c
@@ -47,6 +47,21 @@ static const struct {
   { "PIO_ASYNCH", PIO_ASYNCH },
   { "PIO_WRITER", PIO_WRITER }
 };
+
+static inline int
+search_iomode_str(const char *modestr)
+{
+  int retval = -1;
+  for (size_t i = 0;
+       i < sizeof (mode_map) / sizeof (mode_map[0]);
+       ++i)
+    if (!strcmp(modestr, mode_map[i].text))
+      {
+        retval = (int)i;
+        break;
+      }
+  return retval;
+}
 #endif
 
 static const struct {
@@ -80,24 +95,7 @@ parse_intarg(const char msg[])
   return (int)temp;
 }
 
-#ifdef USE_MPI
-static inline int
-search_iomode_str(const char *modestr)
-{
-  int i, retval = -1;
-  for (i = 0;
-       i < sizeof (mode_map) / sizeof (mode_map[0]);
-       ++i)
-    if (!strcmp(modestr, mode_map[i].text))
-      {
-        retval = i;
-        break;
-      }
-  return retval;
-}
-#endif
-
-int main (int argc, char *argv[])
+int main(int argc, char *argv[])
 {
   struct model_config setup = default_setup;
 
@@ -138,13 +136,21 @@ int main (int argc, char *argv[])
         }
         break;
       case 'w':
-        nProcsIO = strtol(optarg, NULL, 0);
+        {
+          long temp = strtol(optarg, NULL, 0);
+          if (temp < 0 || temp > INT_MAX/2)
+            {
+              fprintf(stderr, "Unsupported number of I/O servers: %ld\n", temp);
+              exit(EXIT_FAILURE);
+            }
+          nProcsIO = (int)temp;
+        }
         break;
 #endif
       case 'f':
         {
-          int i, found = 0;
-          for (i = 0;
+          int found = 0;
+          for (size_t i = 0;
                i < sizeof (suffix2type) / sizeof (suffix2type[0]);
                ++i)
             if (!strcmp(optarg, suffix2type[i].suffix))
diff --git a/libcdi/tests/pio_write_deco2d_run.in b/libcdi/tests/pio_write_deco2d_run.in
index d0d9162..4f84c2a 100644
--- a/libcdi/tests/pio_write_deco2d_run.in
+++ b/libcdi/tests/pio_write_deco2d_run.in
@@ -1,14 +1,24 @@
 #! @SHELL@
 set -e
 LOG="${LOG-pio_write_deco2d.log}"
-mpi_task_num="${mpi_task_num-6}"
-suffix="${suffix-grb}"
-exec 5>&1 6>&2 >"$LOG" 2>&1
-../libtool --mode=execute @MPI_LAUNCH@ -n ${mpi_task_num} \
-  ${tool_wrap} ./pio_write_deco2d ${pio_write_args}
-exec 2>&6 1>&5 5>&- 6>&-
-../libtool --mode=execute \
-  ${tool_wrap} ./cksum_read example_0.${suffix} example_0.cksum
-../libtool --mode=execute \
-  ${tool_wrap} ./cksum_read example_1.${suffix} example_1.cksum
-\rm "$LOG"
+if [ @ENABLE_GRIB@ = yes ]; then
+  mpi_task_num="${mpi_task_num-6}"
+  suffix="${suffix-grb}"
+  exec 5>&1 6>&2 >"$LOG" 2>&1
+  ../libtool --mode=execute @MPI_LAUNCH@ -n ${mpi_task_num} \
+    ${tool_wrap} ./pio_write_deco2d ${pio_write_args}
+  exec 2>&6 1>&5 5>&- 6>&-
+  ../libtool --mode=execute \
+    ${tool_wrap} ./cksum_read example_0.${suffix} example_0.cksum
+  ../libtool --mode=execute \
+    ${tool_wrap} ./cksum_read example_1.${suffix} example_1.cksum
+  \rm "$LOG"
+else
+  # skip tests for unsupported formats
+  exit 77
+fi
+#
+# Local Variables:
+# mode: sh
+# End:
+#
diff --git a/libcdi/tests/pio_write_run.in b/libcdi/tests/pio_write_run.in
index 913b0a1..e3a691f 100644
--- a/libcdi/tests/pio_write_run.in
+++ b/libcdi/tests/pio_write_run.in
@@ -1,15 +1,25 @@
 #! @SHELL@
 set -e
 LOG="${LOG-pio_write.log}"
-mpi_task_num="${mpi_task_num-4}"
-suffix="${suffix-grb}"
-exec 5>&1 6>&2 >"$LOG" 2>&1
-../libtool --mode=execute \
-  @MPI_LAUNCH@ \
-  -n ${mpi_task_num} ${tool_wrap} ./pio_write ${pio_write_args}
-exec 2>&6 1>&5 5>&- 6>&-
-../libtool --mode=execute \
-  ${tool_wrap} ./cksum_read example_0.${suffix} example_0.cksum
-../libtool --mode=execute \
-  ${tool_wrap} ./cksum_read example_1.${suffix} example_1.cksum
-\rm "$LOG"
+if [ @ENABLE_GRIB@ = yes ]; then
+  mpi_task_num="${mpi_task_num-4}"
+  suffix="${suffix-grb}"
+  exec 5>&1 6>&2 >"$LOG" 2>&1
+  ../libtool --mode=execute \
+    @MPI_LAUNCH@ \
+    -n ${mpi_task_num} ${tool_wrap} ./pio_write ${pio_write_args}
+  exec 2>&6 1>&5 5>&- 6>&-
+  ../libtool --mode=execute \
+    ${tool_wrap} ./cksum_read example_0.${suffix} example_0.cksum
+  ../libtool --mode=execute \
+    ${tool_wrap} ./cksum_read example_1.${suffix} example_1.cksum
+  \rm "$LOG"
+else
+  # skip tests for unsupported formats
+  exit 77
+fi
+#
+# Local Variables:
+# mode: sh
+# End:
+#
diff --git a/libcdi/tests/simple_model.c b/libcdi/tests/simple_model.c
index 854b816..774f342 100644
--- a/libcdi/tests/simple_model.c
+++ b/libcdi/tests/simple_model.c
@@ -29,6 +29,7 @@ typedef int MPI_Comm;
 #include "pio_write.h"
 
 #include "simple_model_helper.h"
+#include "create_uuid.h"
 
 enum {
   ntfiles     = 2,
@@ -42,6 +43,7 @@ modelRegionCompute(double region[], size_t offset, size_t len,
                    double mscale, double mrscale)
 {
   size_t local_pos;
+  (void)nlev;
   for (local_pos = 0; local_pos < len; ++local_pos)
     {
       size_t global_pos = offset + local_pos;
@@ -93,8 +95,8 @@ modelRun(struct model_config setup, MPI_Comm comm)
   xmpi ( MPI_Comm_size ( comm, &comm_size ));
   if (rank == 0 && setup.compute_checksum)
     {
-      chunks = xmalloc(comm_size * sizeof (chunks[0]));
-      displs = xmalloc(comm_size * sizeof (displs[0]));
+      chunks = xmalloc((size_t)comm_size * sizeof (chunks[0]));
+      displs = xmalloc((size_t)comm_size * sizeof (displs[0]));
       var = xmalloc((size_t)nlon * (size_t)nlat
                     * (size_t)setup.max_nlev * sizeof(var[0]));
     }
@@ -113,7 +115,15 @@ modelRun(struct model_config setup, MPI_Comm comm)
     lats[i] = ((double)(i * 180))/nlat - 90.0;
   gridDefXvals ( gridID, lons );
   gridDefYvals ( gridID, lats );
-
+  {
+    unsigned char uuid[CDI_UUID_SIZE];
+    if (rank == 0)
+      create_uuid(uuid);
+#if USE_MPI
+    MPI_Bcast(uuid, CDI_UUID_SIZE, MPI_UNSIGNED_CHAR, 0, comm);
+#endif
+    gridDefUUID(gridID, uuid);
+  }
   levs = xmalloc((size_t)setup.max_nlev * sizeof (levs[0]));
   for (i = 0; i < setup.max_nlev; ++i)
     levs[i] = 101300.0
@@ -139,15 +149,29 @@ modelRun(struct model_config setup, MPI_Comm comm)
         }
       ++varLevs;
       varDesc[varIdx].nlev = varLevs;
-      for (i = 0; i < varIdx; ++i)
+      for (size_t i = 0; i < (size_t)varIdx; ++i)
         if (varDesc[i].nlev == varLevs)
           {
             varDesc[varIdx].zaxisID = varDesc[i].zaxisID;
             goto zaxisIDset;
           }
-      varDesc[varIdx].zaxisID
-        = zaxisCreate(ZAXIS_PRESSURE, varDesc[varIdx].nlev);
-      zaxisDefLevels(varDesc[varIdx].zaxisID, levs);
+      if (varLevs == 1)
+        varDesc[varIdx].zaxisID = zaxisCreate(ZAXIS_SURFACE, 1);
+      else
+        {
+          varDesc[varIdx].zaxisID
+            = zaxisCreate(ZAXIS_PRESSURE, varDesc[varIdx].nlev);
+          zaxisDefLevels(varDesc[varIdx].zaxisID, levs);
+        }
+      {
+        unsigned char uuid[16];
+        if (rank == 0)
+          create_uuid(uuid);
+#if USE_MPI
+        MPI_Bcast(uuid, CDI_UUID_SIZE, MPI_UNSIGNED_CHAR, 0, comm);
+#endif
+        zaxisDefUUID(varDesc[varIdx].zaxisID, uuid);
+      }
       zaxisIDset:
       varDesc[varIdx].id
         = vlistDefVar(vlistID, gridID, varDesc[varIdx].zaxisID, TIME_VARIABLE);
@@ -204,10 +228,19 @@ modelRun(struct model_config setup, MPI_Comm comm)
       current_time = cditime2time_t(vdate, vtime);
       for ( tsID = 0; tsID < setup.nts; tsID++ )
 	{
-          time_t2cditime(current_time, &vdate, &vtime);
-	  taxisDefVdate ( taxisID, vdate );
-	  taxisDefVtime ( taxisID, vtime );
+          int vdatetime[2];
+          time_t2cditime(current_time, &vdatetime[1], &vdatetime[0]);
+	  taxisDefVdate(taxisID, vdatetime[1]);
+	  taxisDefVtime(taxisID, vdatetime[0]);
 	  streamDefTimestep ( streamID, tsID );
+          if (setup.filetype == FILETYPE_EXT)
+            {
+              /* EXTRA doesn't store time, only date
+               * set the value to 0 before checksumming, because a
+               * time field of 0 is what reading an EXTRA file will
+               * return */
+              vdatetime[0] = 0;
+            }
 	  for (int varID = 0; varID < nVars; ++varID)
 	    {
 #ifdef USE_MPI
@@ -217,7 +250,7 @@ modelRun(struct model_config setup, MPI_Comm comm)
               int chunk = (int)varDesc[varID].size;
               int start = 0;
 #endif
-              if (varslice_size < chunk)
+              if (varslice_size < (size_t)chunk)
                 {
                   varslice = xrealloc(varslice, (size_t)chunk * sizeof (var[0]));
                   varslice_size = (size_t)chunk;
@@ -246,6 +279,9 @@ modelRun(struct model_config setup, MPI_Comm comm)
               if (rank == 0 && setup.compute_checksum)
                 {
                   memcrc_r(&varDesc[varID].checksum_state,
+                           (const unsigned char *)vdatetime,
+                           sizeof (vdatetime));
+                  memcrc_r(&varDesc[varID].checksum_state,
                            (const unsigned char *)var,
                            varDesc[varID].size * sizeof (var[0]));
                 }
@@ -277,8 +313,9 @@ modelRun(struct model_config setup, MPI_Comm comm)
                 uint32_t cksum;
                 int code;
                 cksum = memcrc_finish(&varDesc[i].checksum_state,
-                                      (off_t)(varDesc[i].size
-                                              * sizeof (var[0])
+                                      (off_t)((varDesc[i].size
+                                               * sizeof (var[0])
+                                               + sizeof (int) * 2)
                                               * (size_t)setup.nts));
                 code = vlistInqVarCode(vlistID, varDesc[i].id);
                 if (fprintf(tablefp, "%08lx %d\n", (unsigned long)cksum,
@@ -299,13 +336,13 @@ modelRun(struct model_config setup, MPI_Comm comm)
   streamClose ( streamID );
   vlistDestroy ( vlistID );
   taxisDestroy ( taxisID );
-  for ( i = 0; i < nVars; i++ )
+  for (int varID = 0; varID < nVars; varID++ )
     {
-      int zID = varDesc[i].zaxisID;
+      int zID = varDesc[varID].zaxisID;
       if (zID != CDI_UNDEFID)
         {
           zaxisDestroy(zID);
-          for (int j = i + 1; j < nVars; ++j)
+          for (int j = varID + 1; j < nVars; ++j)
             if (zID == varDesc[j].zaxisID)
               varDesc[j].zaxisID = CDI_UNDEFID;
         }
diff --git a/libcdi/tests/stream_cksum.c b/libcdi/tests/stream_cksum.c
index 005a97c..3704a7d 100644
--- a/libcdi/tests/stream_cksum.c
+++ b/libcdi/tests/stream_cksum.c
@@ -12,8 +12,8 @@
 struct cksum_table *
 cksum_stream(const char *fname, size_t *table_len)
 {
-  int taxisID, vlistID, streamID, tsID;
-  int vdate, vtime, nvars, ngrids, nzaxis;
+  int taxisID, vlistID, streamID;
+  int nvars, ngrids, nzaxis;
   int i;
   uint32_t *checksum_state = NULL;
   struct
@@ -103,19 +103,18 @@ cksum_stream(const char *fname, size_t *table_len)
     // Get the Time axis from the variable list
     taxisID = vlistInqTaxis(vlistID);
 
-    tsID = 0;
+    int tsID = 0;
     // Inquire the time step
     while (streamInqTimestep(streamID, tsID))
       {
         // Get the verification date and time
-        vdate = taxisInqVdate(taxisID);
-        vtime = taxisInqVtime(taxisID);
-
+        int vdatetime[2] = { taxisInqVtime(taxisID), taxisInqVdate(taxisID) };
         // Read var1 and var2
         for (i = 0; i < nvars; ++i)
           {
             int nmiss;
             streamReadVar(streamID, i, buf, &nmiss);
+            memcrc_r(checksum_state + i, (const unsigned char *)vdatetime, sizeof (vdatetime));
             memcrc_r(checksum_state + i, (const unsigned char *)buf,
                      varSize[i].chars);
           }
@@ -126,8 +125,9 @@ cksum_stream(const char *fname, size_t *table_len)
     for (i = 0; i < nvars; ++i)
       {
         file_vars[i].code = vlistInqVarCode(vlistID, i);
-        file_vars[i].cksum = memcrc_finish(checksum_state + i,
-                                           (off_t)varSize[i].chars * tsID);
+        file_vars[i].cksum
+          = memcrc_finish(checksum_state + i,
+                          (off_t)((varSize[i].chars + sizeof (int) * 2) * (size_t)tsID));
       }
     // Close the input stream
     streamClose(streamID);
diff --git a/libcdi/tests/test_cdf_read.c b/libcdi/tests/test_cdf_read.c
new file mode 100644
index 0000000..d73abe8
--- /dev/null
+++ b/libcdi/tests/test_cdf_read.c
@@ -0,0 +1,69 @@
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "cdi.h"
+
+int main(int argc, const char **argv)
+{
+  const char *fname = "test.nc";
+  int countMissingValues = 1;
+  /* todo: handle optional arguments here to increase test coverage */
+  if (argc)
+    fname = argv[1];
+
+  int streamID = streamOpenRead(fname);
+  if (streamID < 0)
+    {
+      fprintf(stderr, "Open failed for file %s: %s\n",
+              fname, cdiStringError(streamID));
+      return EXIT_FAILURE;
+    }
+  int vlistID = streamInqVlist(streamID);
+  size_t nVars = (size_t)vlistNvars(vlistID);
+
+  double *buf = NULL;
+  size_t bufSize = 0;
+  size_t allNmissSum = 0;
+
+  for (int tsID = 0; streamInqTimestep(streamID, tsID); ++tsID)
+    {
+      for (size_t varID = 0; varID < nVars; ++varID)
+        {
+          size_t memSize = (size_t)vlistInqVarSize(vlistID, varID)
+            * sizeof (double);
+          int nmiss;
+          if (memSize > bufSize)
+            {
+              double *temp = realloc(buf, memSize);
+              if (!temp)
+                {
+                  perror("read buffer reallocation failed");
+                  return EXIT_FAILURE;
+                }
+              buf = temp;
+            }
+          streamReadVar(streamID, (int)varID, buf, &nmiss);
+          allNmissSum += (size_t)nmiss;
+        }
+      ++tsID;
+    }
+  if (countMissingValues)
+    printf("missing values count = %zu\n", allNmissSum);
+  streamClose(streamID);
+  return EXIT_SUCCESS;
+}
+
+/*
+ * Local Variables:
+ * c-file-style: "Java"
+ * c-basic-offset: 2
+ * indent-tabs-mode: nil
+ * show-trailing-whitespace: t
+ * require-trailing-newline: t
+ * End:
+ */
diff --git a/libcdi/tests/test_cdf_transformation.in b/libcdi/tests/test_cdf_transformation.in
new file mode 100644
index 0000000..5200dd8
--- /dev/null
+++ b/libcdi/tests/test_cdf_transformation.in
@@ -0,0 +1,25 @@
+#! @SHELL@
+set -e
+[ x${DEBUG+set} != xset ] || set -x
+if [ @ENABLE_NETCDF@ != yes ]; then
+   exit 77
+fi
+ncdatafile="test$$.nc"
+tempfiles="${ncdatafile}"
+trap "EC=\$? ; \rm -f ${tempfiles}; exit \$EC" EXIT
+./test_cdf_write "${ncdatafile}"
+digest=$(./test_cdf_read "${ncdatafile}")
+missValueCount=$(echo "$digest" | @SED@ -n '/^missing values count =/{
+s/^missing values count *= *//
+p
+q
+}')
+if [ "$missValueCount" -ne 1 ]; then
+  echo "Mismatch in expected number of missing values!" >&2
+  exit 1
+fi
+#
+# Local Variables:
+# mode: sh
+# End:
+#
diff --git a/libcdi/tests/test_cdf_write.c b/libcdi/tests/test_cdf_write.c
new file mode 100644
index 0000000..d7c3634
--- /dev/null
+++ b/libcdi/tests/test_cdf_write.c
@@ -0,0 +1,173 @@
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "cdi.h"
+
+struct cart_coord {
+  double lat, lon;
+};
+
+static double
+my_gamma_dist(double x);
+
+static void
+compute_curvilinear(double *coords_,
+                    const struct cart_coord a[4], size_t sizex, size_t sizey);
+
+#define DEG2RAD(phi) ((M_PI / 180.0) * (phi))
+#define RAD2DEG(phi) ((180./M_PI) * (phi))
+#define missValue (-50.0)
+
+int main(int argc, const char **argv)
+{
+  /* todo: handle optional arguments here to increase test coverage */
+  const char *fname = "test.nc";
+  if (argc)
+    fname = argv[1];
+  int streamID = streamOpenWrite(fname, FILETYPE_NC);
+
+  if ( streamID < 0 )
+    {
+      fprintf(stderr, "Open failed on %s: %s\n", fname,
+              cdiStringError(streamID));
+      return EXIT_FAILURE;
+    }
+
+  enum {
+    sizey = 40,
+    sizex = 2 * sizey,
+  };
+
+  size_t datasize = (size_t)sizex * (size_t)sizey;
+  int gridID = gridCreate(GRID_CURVILINEAR, (int)datasize);
+  gridDefXsize(gridID, sizex);
+  gridDefYsize(gridID, sizey);
+  {
+    /* anti-clockwise coordinates around Amazonia */
+    static struct cart_coord region[4]
+      = { { .lon = DEG2RAD(-85.0), .lat = DEG2RAD(-25.0) },
+          { .lon = DEG2RAD(-44.0), .lat = DEG2RAD(-18.0) },
+          { .lon = DEG2RAD(-50.0), .lat = DEG2RAD(7.0) },
+          { .lon = DEG2RAD(-80.0), .lat = DEG2RAD(10.0) } };
+    double (*gridCoords)[sizey][sizex]
+      = (double (*)[sizey][sizex])
+      malloc(sizeof (*gridCoords) * sizey * sizex * 2);
+    if (gridCoords == NULL)
+      {
+        perror("grid coordinate memory allocation failed");
+        return EXIT_FAILURE;
+      }
+    compute_curvilinear((double *)gridCoords, region, sizex, sizey);
+    gridDefXvals(gridID, (double *)(gridCoords[1]));
+    gridDefYvals(gridID, (double *)(gridCoords[0]));
+    free(gridCoords);
+  }
+
+  int zaxisID = zaxisCreate(ZAXIS_SURFACE, 1);
+
+  int vlistID = vlistCreate();
+  int varID = vlistDefVar(vlistID, gridID, zaxisID, TSTEP_INSTANT);
+  vlistDefVarMissval(vlistID, varID, missValue);
+
+  int taxisID = taxisCreate(TAXIS_ABSOLUTE);
+  vlistDefTaxis(vlistID, taxisID);
+
+  streamDefVlist(streamID, vlistID);
+
+  (void)streamDefTimestep(streamID, 0);
+
+  {
+    double (*data)[sizex] = malloc(sizeof (**data) * sizex * sizey);
+    if (!data)
+      {
+        perror("data values memory allocation failed");
+        return EXIT_FAILURE;
+      }
+    for (size_t j = 0; j < sizey; ++j)
+      for (size_t i = 0; i < sizex; ++i)
+        {
+          data[j][i] = my_gamma_dist((double)i/(double)(sizex - 1));
+        }
+    data[sizey/3][sizex/2] = missValue;
+    streamWriteVar(streamID, 0, (const double *)data, 1);
+    free(data);
+  }
+
+  streamClose(streamID);
+
+  return EXIT_SUCCESS;
+}
+
+static inline double
+cart_distance(struct cart_coord p1, struct cart_coord p2)
+{
+  double d_lat = sin((p1.lat-p2.lat)/2.0),
+    d_lon = sin((p1.lon - p2.lon)/2.0),
+    d = 2.0 * asin(sqrt(d_lat * d_lat +
+                        cos(p1.lat)*cos(p2.lat) * (d_lon * d_lon)));
+  return d;
+}
+
+static inline struct cart_coord
+intermediate_coord(struct cart_coord p1, struct cart_coord p2, double f)
+{
+  double d = cart_distance(p1, p2),
+    sine_of_d = sin(d),
+    A = sin((1 - f) * d) / sine_of_d,
+    B = sin(f * d) / sine_of_d,
+    x = A * cos(p1.lat) * cos(p1.lon) + B * cos(p2.lat) * cos(p2.lon),
+    y = A * cos(p1.lat) * sin(p1.lon) + B * cos(p2.lat) * sin(p2.lon),
+    z = A * sin(p1.lat) + B * sin(p2.lat);
+  struct cart_coord ic = { .lat = atan2(z, sqrt(x * x + y * y)),
+                           .lon = atan2(y, x) };
+  return ic;
+}
+
+static void
+compute_curvilinear(double *coords_,
+                    const struct cart_coord a[4], size_t sizex, size_t sizey)
+{
+  double (*coords)[sizey][sizex] = (double (*)[sizey][sizex])coords_;
+  for (size_t j = 0; j < sizey; ++j)
+    {
+      double g = (double)j / (double)(sizey - 1);
+      /* compute start/end coordinates of great circle in x direction */
+      struct cart_coord gc_left = intermediate_coord(a[0], a[3], g),
+        gc_right = intermediate_coord(a[1], a[2], g);
+      for (size_t i = 0; i < sizex; ++i)
+        {
+          double f = (double)i / (double)(sizex - 1);
+          struct cart_coord pij = intermediate_coord(gc_left, gc_right, f);
+          coords[0][j][i] = RAD2DEG(pij.lat);
+          coords[1][j][i] = RAD2DEG(pij.lon);
+        }
+    }
+}
+
+static double
+my_gamma_dist(double x)
+{
+  enum {
+    k = 9,
+  };
+  const double theta = 0.5;
+  x *= 20.0;
+  double pdf_x = 1.0 / ( tgamma(k) * pow(theta, k) ) * pow(x, k - 1)
+    * exp(-x/theta);
+  return pdf_x;
+}
+
+/*
+ * Local Variables:
+ * c-file-style: "Java"
+ * c-basic-offset: 2
+ * indent-tabs-mode: nil
+ * show-trailing-whitespace: t
+ * require-trailing-newline: t
+ * End:
+ */
diff --git a/libcdi/tests/test_grib.c b/libcdi/tests/test_grib.c
index 30c8256..cc4c789 100644
--- a/libcdi/tests/test_grib.c
+++ b/libcdi/tests/test_grib.c
@@ -9,7 +9,7 @@
 #include "cdi.h"
 #include "dmemory.h"
 
-int main(int argc, char *argv[])
+int main()
 {
   char fname[] = "test.grb";
   int filetype = FILETYPE_GRB;
diff --git a/libcdi/tests/test_resource_copy.c b/libcdi/tests/test_resource_copy.c
index c15e738..e8a6c88 100644
--- a/libcdi/tests/test_resource_copy.c
+++ b/libcdi/tests/test_resource_copy.c
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include "cdi.h"
+#include "create_uuid.h"
 #include "dmemory.h"
 #include "error.h"
 #include "resource_handle.h"
@@ -86,6 +87,11 @@ int defineGrid ()
     mask_vec[i] = i;
   gridDefRowlon ( gridID, nlon*nlat, mp );
   gridDefComplexPacking ( gridID, 1 );
+  {
+    unsigned char uuid[CDI_UUID_SIZE];
+    create_uuid(uuid);
+    gridDefUUID(gridID, uuid);
+  }
 
   return gridID;
 }
@@ -107,6 +113,11 @@ int defineZaxis ()
   zaxisDefLbounds ( zaxisID, &levs[0] );
   zaxisDefUbounds ( zaxisID, &levs[0] );
   zaxisDefWeights ( zaxisID, &levs[0] );
+  {
+    unsigned char uuid[CDI_UUID_SIZE];
+    create_uuid(uuid);
+    zaxisDefUUID(zaxisID, uuid);
+  }
 
   return zaxisID;
 }
@@ -139,7 +150,11 @@ void defineStream ( int streamID, int vlistID )
   streamDefVlist(streamID, vlistID);
 }
 
-int defineVlist ( int gridID, int zaxisID, int taxisID )
+struct idPair {
+  int id1, id2;
+};
+
+struct idPair defineVlist ( int gridID, int zaxisID, int taxisID )
 {
   int vlistID = CDI_UNDEFID;
   int zaxisID2 = zaxisCreate(ZAXIS_SURFACE, 1);
@@ -160,9 +175,7 @@ int defineVlist ( int gridID, int zaxisID, int taxisID )
   int vlistID2 = vlistCreate();
   vlistDefVar(vlistID2, gridID, zaxisID, TIME_VARIABLE);
   vlistCopy(vlistID2, vlistID);
-  vlistDestroy(vlistID);
-  vlistID = vlistID2;
-  return vlistID;
+  return (struct idPair){ vlistID, vlistID2 };
 }
 
 int defineInstitute ()
@@ -201,10 +214,14 @@ int modelRun(MPI_Comm comm)
   taxisID = defineTaxis     ();
   instID  = defineInstitute ();
   defineModel(instID);
-  vlistID = defineVlist     ( gridID, zaxisID, taxisID);
-  streamID = streamOpenWrite("example.grb", FILETYPE_GRB);
-  if ( streamID < 0 ) xabort ( "Could not open file" );
-  defineStream ( streamID, vlistID );
+  {
+    struct idPair temp = defineVlist(gridID, zaxisID, taxisID);
+    vlistID = temp.id1;
+    streamID = streamOpenWrite("example.grb", FILETYPE_GRB);
+    if ( streamID < 0 ) xabort ( "Could not open file" );
+    defineStream ( streamID, vlistID );
+    vlistDestroy(temp.id2);
+  }
 
   reshPackBufferCreate ( &sendBuffer, &bufferSize, &comm );
   recvBuffer = xmalloc((size_t)bufferSize);
@@ -235,6 +252,7 @@ int main (int argc, char *argv[])
   MPI_Init(&argc, &argv);
   commModel = MPI_COMM_WORLD;
 #else
+  (void)argc; (void)argv;
   commModel = 0;
 #endif
   destNamespace = namespaceNew();
diff --git a/m4/._ax_pthread.m4 b/m4/._ax_pthread.m4
index 224412c..77b299d 100644
Binary files a/m4/._ax_pthread.m4 and b/m4/._ax_pthread.m4 differ
diff --git a/src/Deltime.c b/src/Deltime.c
index cc76e1e..3daf522 100644
--- a/src/Deltime.c
+++ b/src/Deltime.c
@@ -72,7 +72,8 @@ void *Deltime(void *argument)
       if ( isalpha(*sarg) )
 	{
 	  char smon[32];
-	  strncpy(smon, sarg, 32);
+	  strncpy(smon, sarg, sizeof(smon)-1);
+	  smon[sizeof(smon)-1] = 0;
 	  strtolower(smon);
 	  for ( im = 0; im < 12; ++im )
 	    if ( memcmp(smon, cmons[im+1], 3) == 0 ) break;
diff --git a/src/Filedes.c b/src/Filedes.c
index abfe1b3..ed8828a 100644
--- a/src/Filedes.c
+++ b/src/Filedes.c
@@ -91,9 +91,11 @@ void partab(FILE *fp, int vlistID, int option)
   int natts;
   int nvars;
   int chunktype;
+  int linebreak = 1;
   double missval;
       
   nvars  = vlistNvars(vlistID);
+  if ( option == 4 ) linebreak = 0;
 
   if ( option == 2 )
     {
@@ -121,17 +123,23 @@ void partab(FILE *fp, int vlistID, int option)
 
       if ( datatype != -1 )
 	{
-	  fprintf(fp, "&parameter\n");
-	  fprintf(fp, "  name=_default_\n");
+	  fprintf(fp, "&parameter");
+	  if ( linebreak ) fprintf(fp, "\n");
+	  fprintf(fp, "  name=_default_");
+	  if ( linebreak ) fprintf(fp, "\n");
 	  if ( datatype2str(datatype, pstr) == 0 )
-	    fprintf(fp, "  datatype=%s\n", pstr);
+	    {
+	      fprintf(fp, "  datatype=%s", pstr);
+	      if ( linebreak ) fprintf(fp, "\n");
+	    }
 	  fprintf(fp, "/\n");
 	}
     }
 
   for ( varID = 0; varID < nvars; varID++ )
     {
-      fprintf(fp, "&parameter\n");
+      fprintf(fp, "&parameter");
+      if ( linebreak ) fprintf(fp, "\n");
       
       varname[0]     = 0;
       varlongname[0] = 0;
@@ -146,38 +154,61 @@ void partab(FILE *fp, int vlistID, int option)
       /* printf("3>%s<\n", varname); */
       vlistInqVarUnits(vlistID, varID, varunits);
             
-      fprintf(fp, "  name=%s\n", varname);
+      fprintf(fp, "  name=%s", varname);
+      if ( linebreak ) fprintf(fp, "\n");
       // if ( code   > 0 ) fprintf(fp, "  code=%d\n", code);
       // if ( tabnum > 0 ) fprintf(fp, "  table=%d\n", tabnum);
       if ( param >= 0 )
 	{
 	  cdiParamToString(param, paramstr, sizeof(paramstr));
-	  fprintf(fp, "  param=%s\n", paramstr);
+	  fprintf(fp, "  param=%s", paramstr);
+	  if ( linebreak ) fprintf(fp, "\n");
 	}
       if ( strlen(varstdname) )
-	fprintf(fp, "  standard_name=%s\n", varstdname);
+	{
+	  fprintf(fp, "  standard_name=%s", varstdname);
+	  if ( linebreak ) fprintf(fp, "\n");
+	}
       if ( strlen(varlongname) )
-	fprintf(fp, "  long_name=\"%s\"\n", varlongname);
+	{
+	  fprintf(fp, "  long_name=\"%s\"", varlongname);
+	  if ( linebreak ) fprintf(fp, "\n");
+	}
       if ( strlen(varunits) )
-	fprintf(fp, "  units=\"%s\"\n", varunits);
-      
+	{
+	  fprintf(fp, "  units=\"%s\"", varunits);
+	  if ( linebreak ) fprintf(fp, "\n");
+	}
+
       if ( datatype == -1 )
 	if ( datatype2str(vlistInqVarDatatype(vlistID, varID), pstr) == 0 )
-	  fprintf(fp, "  datatype=%s\n", pstr);
+	  {
+	    fprintf(fp, "  datatype=%s", pstr);
+	    if ( linebreak ) fprintf(fp, "\n");
+	  }
 
       chunktype = vlistInqVarChunkType(vlistID, varID);
       if ( chunktype == CHUNK_AUTO )
-	fprintf(fp, "  chunktype=auto\n");
+	{
+	  fprintf(fp, "  chunktype=auto");
+	  if ( linebreak ) fprintf(fp, "\n");
+	}
       else if ( chunktype == CHUNK_GRID )
-	fprintf(fp, "  chunktype=grid\n");
+	{
+	  fprintf(fp, "  chunktype=grid");
+	  if ( linebreak ) fprintf(fp, "\n");
+	}
       if ( chunktype == CHUNK_LINES )
-	fprintf(fp, "  chunktype=lines\n");
-	
+	{
+	  fprintf(fp, "  chunktype=lines");
+	  if ( linebreak ) fprintf(fp, "\n");
+	}
       
       if ( option == 2 ) printAtts(fp, vlistID, varID);
       if ( option == 2 ) 
 	fprintf(fp, "  missing_value=%g\n", missval);
       
+      if ( !linebreak ) fprintf(fp, "  ");
       fprintf(fp, "/\n");
     }   
 }
@@ -194,6 +225,9 @@ void filedes(int streamID)
     case FILETYPE_GRB:
       printf("  GRIB data\n");
       break;
+    case FILETYPE_GRB2:
+      printf("  GRIB2 data\n");
+      break;
     case FILETYPE_NC:
       printf("  netCDF data\n");
       break;
@@ -253,7 +287,7 @@ void filedes(int streamID)
 
 void *Filedes(void *argument)
 {
-  int GRIDDES, GRIDDES2, ZAXISDES, VCT, VCT2, PARDES, FILEDES, VLIST, PARTAB, PARTAB2;
+  int GRIDDES, GRIDDES2, ZAXISDES, VCT, VCT2, PARDES, FILEDES, VLIST, SPARTAB, PARTAB, PARTAB2;
   int operatorID;
   int streamID = 0;
   int zaxisID;
@@ -271,6 +305,7 @@ void *Filedes(void *argument)
   PARDES   = cdoOperatorAdd("pardes",    0, 0, NULL);
   FILEDES  = cdoOperatorAdd("filedes",   0, 0, NULL);
   VLIST    = cdoOperatorAdd("vlist",     0, 0, NULL);
+  SPARTAB  = cdoOperatorAdd("spartab",   0, 0, NULL);
   PARTAB   = cdoOperatorAdd("partab",    0, 0, NULL);
   PARTAB2  = cdoOperatorAdd("partab2",   0, 0, NULL);
 
@@ -372,10 +407,11 @@ void *Filedes(void *argument)
 	  fprintf(stdout, "\n");
 	}   
     }
-  else if ( operatorID == PARTAB || operatorID == PARTAB2 )
+  else if ( operatorID == PARTAB || operatorID == SPARTAB || operatorID == PARTAB2 )
     {
       int option = 1;
 
+      if ( operatorID == SPARTAB ) option = 4;
       if ( operatorID == PARTAB2 ) option = 2;
       
       partab(stdout, vlistID, option);
diff --git a/src/Gradsdes.c b/src/Gradsdes.c
index 24cf8cf..ab55478 100644
--- a/src/Gradsdes.c
+++ b/src/Gradsdes.c
@@ -1281,8 +1281,7 @@ void *Gradsdes(void *argument)
 
   taxisID = vlistInqTaxis(vlistID);
 
-  int calendar = taxisInqCalendar(taxisID);
-  if ( calendar == CALENDAR_365DAYS ) cal365day = 1;
+  if ( taxisInqCalendar(taxisID) == CALENDAR_365DAYS ) cal365day = 1;
 
   tsID = 0;
   while ( (nrecs = streamInqTimestep(streamID, tsID)) )
diff --git a/src/Histogram.c b/src/Histogram.c
index 9288417..d009520 100644
--- a/src/Histogram.c
+++ b/src/Histogram.c
@@ -58,6 +58,8 @@ void *Histogram(void *argument)
   HISTMEAN  = cdoOperatorAdd("histmean",  0, 0, NULL);
   HISTFREQ  = cdoOperatorAdd("histfreq",  0, 0, NULL);
 
+  UNUSED(HISTSUM);
+
   operatorID = cdoOperatorID();
 
   operatorInputArg("bins");
@@ -89,7 +91,7 @@ void *Histogram(void *argument)
   free(bins);
   zaxisDefLbounds(zaxisID2, fltarr);
   zaxisDefUbounds(zaxisID2, fltarr+1);
-  zaxisDefName(zaxisID2, "bins");
+  zaxisDefName(zaxisID2, "bin");
   zaxisDefLongname(zaxisID2, "histogram bins");
   zaxisDefUnits(zaxisID2, "level");
 
@@ -147,16 +149,16 @@ void *Histogram(void *argument)
 	    {
 	      if ( !DBL_IS_EQUAL(array[i], missval) )
 		{
-		  *(vartcount[varID]+i) += 1;
+		  vartcount[varID][i] += 1;
 		  index = 0;
 		  while( index < nbins )
 		    {
 		      offset = gridsize*index;
-		      if ( !DBL_IS_EQUAL(*(vardata[varID]+offset+i), missval) &&
+		      if ( !DBL_IS_EQUAL(vardata[varID][offset+i], missval) &&
 			   array[i] >= fltarr[index] && array[i] < fltarr[index+1] )
 			{
-			  *(vardata[varID]+offset+i) += array[i];
-			  *(varcount[varID]+offset+i) += 1;
+			  vardata[varID][offset+i]  += array[i];
+			  varcount[varID][offset+i] += 1;
 			  break;
 			}
 		      index++;
@@ -177,36 +179,39 @@ void *Histogram(void *argument)
     {
       missval = vlistInqVarMissval(vlistID2, varID);
       gridsize = gridInqSize(vlistInqVarGrid(vlistID2, varID));
-      nmiss = 0;
 
       /* fix mising values */
       
       for ( index = 0; index < nbins; index++ )
 	{
-	  streamDefRecord(streamID2,  varID,  index);
-	  offset   = gridsize*index;
-	  
+	  nmiss = 0;
+	  offset = gridsize*index;
+
 	  for ( i = 0; i < gridsize; i++ )
 	    {
-	      if ( *(vartcount[varID]+i) > 0 )
+	      if ( vartcount[varID][i] > 0 )
 		{
 		  if ( operatorID == HISTMEAN || operatorID == HISTFREQ )
 		    {
-		      if ( *(varcount[varID]+offset+i) > 0 ) 
+		      if ( varcount[varID][offset+i] > 0 ) 
 			{
 			  if ( operatorID == HISTMEAN )
-			    *(vardata[varID]+offset+i) /= *(varcount[varID]+offset+i);	    
+			    vardata[varID][offset+i] /= varcount[varID][offset+i];	    
 			  else 
-			    *(vardata[varID]+offset+i) = *(varcount[varID]+offset+i) / *(vartcount[varID]+i);
+			    vardata[varID][offset+i] = varcount[varID][offset+i] / vartcount[varID][i];
 			} 
 		    }
 		}
 	      else
 		{
 		  nmiss++;
-		  *(vardata[varID]+offset+i) = missval;
+		  varcount[varID][offset+i] = missval;
+		  vardata[varID][offset+i] = missval;
 		}
 	    }
+
+	  streamDefRecord(streamID2,  varID,  index);
+
 	  if ( operatorID == HISTCOUNT )
 	    streamWriteRecord(streamID2, varcount[varID]+offset, nmiss);
 	  else
diff --git a/src/Merge.c b/src/Merge.c
index 1636743..5fd7058 100644
--- a/src/Merge.c
+++ b/src/Merge.c
@@ -37,7 +37,6 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename)
   int gridID1, gridID2;
   int zaxisID1, zaxisID2;
   int varID1, varID2;
-  int nvars1, nvars2;
   int param1, param2;
   int ztype1, ztype2;
   int gtype1, gtype2;
@@ -46,8 +45,8 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename)
   int mlev1 = 0, mlev2 = 0;
   double *lev1 = NULL, *lev2 = NULL;
 
-  nvars1 = vlistNvars(vlistID1);
-  nvars2 = vlistNvars(vlistID2);
+  int nvars1 = vlistNvars(vlistID1);
+  int nvars2 = vlistNvars(vlistID2);
 
   for ( varID1 = 0; varID1 < nvars1; ++varID1 )
     {
@@ -115,31 +114,38 @@ void checkDupEntry(int vlistID1, int vlistID2, const char *filename)
   if ( lev2 ) free(lev2);
 }
 
+static
+int vlistConstVars(int vlistID)
+{
+  int nvars = vlistNvars(vlistID);
+
+  for ( int varID = 0; varID < nvars; ++varID )
+    if ( vlistInqVarTsteptype(vlistID, varID) != TSTEP_CONSTANT ) return (0);
+
+  return (1);
+}
+
 
 void *Merge(void *argument)
 {
   int streamID1 = -1, streamID2 = -1;
   int varID, varID2;
   int nrecs = 0;
-  int tsID, recID, levelID, levelID2;
+  int recID, levelID, levelID2;
   int index;
-  int streamCnt;
-  int *streamIDs;
-  int *vlistIDs;
   int vlistID1 = -1, vlistID2;
-  int recID2;
-  int nmerge;
-  int idum = -4711;
   int lcopy = FALSE;
   int gridsize;
   int nmiss;
   int taxisID1, taxisID2;
-  int skip_same_var = FALSE;
-  const char *ofilename;
+  //int skip_same_var = FALSE;
   double *array = NULL;
 
   cdoInitialize(argument);
 
+  if ( UNCHANGED_RECORD ) lcopy = TRUE;
+
+  /*
   {
     char *envstr;
     envstr = getenv("SKIP_SAME_VAR");
@@ -155,30 +161,27 @@ void *Merge(void *argument)
 	  }
       }
   }
+  */
 
-  if ( UNCHANGED_RECORD ) lcopy = TRUE;
-
-  streamCnt = cdoStreamCnt();
-  nmerge    = streamCnt - 1;
+  int streamCnt = cdoStreamCnt();
+  int nmerge    = streamCnt - 1;
 
-  ofilename = cdoStreamName(streamCnt-1)->args;
+  const char *ofilename = cdoStreamName(streamCnt-1)->args;
 
   if ( !cdoSilentMode && !cdoOverwriteMode )
     if ( fileExists(ofilename) )
       if ( !userFileOverwrite(ofilename) )
 	cdoAbort("Outputfile %s already exists!", ofilename);
 
-  streamIDs = (int*) malloc(nmerge*sizeof(int));
-  vlistIDs  = (int*) malloc(nmerge*sizeof(int));
+  int *streamIDs = (int*) malloc(nmerge*sizeof(int));
+  int *vlistIDs  = (int*) malloc(nmerge*sizeof(int));
+  int *numrecs   = (int*) malloc(nmerge*sizeof(int));
 
   for ( index = 0; index < nmerge; index++ )
     {
       streamID1 = streamOpenRead(cdoStreamName(index));
-
       streamIDs[index] = streamID1;
-
-      vlistID1 = streamInqVlist(streamID1);
-      vlistIDs[index] = vlistID1;
+      vlistIDs[index]  = streamInqVlist(streamID1);
     }
 
   vlistID1 = vlistIDs[0];
@@ -211,37 +214,68 @@ void *Merge(void *argument)
       array = (double*) malloc(gridsize*sizeof(double));
     }
 
-  tsID = 0;
+  int firstindex = 0;
+  int tsID = 0;
   while ( tsID >= 0 )
     {
-      recID2 = 0;
       for ( index = 0; index < nmerge; index++ )
 	{
 	  streamID1 = streamIDs[index];
 	  vlistID1  = vlistIDs[index];
+	  if ( vlistID1 == -1 ) continue;
 
-	  if ( vlistID1 == idum ) continue;
+	  numrecs[index] = streamInqTimestep(streamID1, tsID);
+	}
 
-	  nrecs = streamInqTimestep(streamID1, tsID);
+      for ( index = 0; index < nmerge; index++ ) if ( numrecs[index] != 0 ) break;
+      if ( index == nmerge ) break; // EOF on all input streams
+      
+      if ( tsID == 1 )
+	{
+	  for ( index = 0; index < nmerge; index++ )
+	    if ( numrecs[index] == 0 && vlistConstVars(vlistIDs[index]) ) vlistIDs[index] = -1;
+	  /*
+	  for ( index = 0; index < nmerge; index++ )
+	    if ( vlistIDs[index] != -1 )
+	      {
+		firstindex = index;
+		break;
+	      }
+	  */
+	}
+      /*
+      for ( index = 0; index < nmerge; index++ )
+	printf("tsID %d   %d sID %d vID %d nrecs %d\n", tsID, index, streamIDs[index], vlistIDs[index], numrecs[index]);
+      */
+      if ( numrecs[firstindex] == 0 )
+	{
+	  for ( index = 1; index < nmerge; index++ )
+	    if ( vlistIDs[index] != -1 && numrecs[index] != 0 )
+	      cdoWarning("Input stream %d has %d timestep%s. Stream %d has more timesteps, skipped!", firstindex+1, tsID, tsID==1?"":"s", index+1);
+	  break;
+	}
+      else
+	{
+	  for ( index = 1; index < nmerge; index++ )
+	    if ( vlistIDs[index] != -1 && numrecs[index] == 0 )
+	      {
+		cdoWarning("Input stream %d has %d timestep%s. Stream %d has more timesteps, skipped!", index+1, tsID, tsID==1?"":"s", firstindex+1);
+		break;
+	      }
+	  if ( index < nmerge ) break;
+	}
 
-	  if ( nrecs == 0 )
-	    {
-	      if ( tsID == 1 )
-		{
-		  vlistIDs[index] = idum;
-		  continue;
-		}
-	      else
-		{
-		  tsID = idum;
-		  break;
-		}
-	    }
+      for ( index = 0; index < nmerge; index++ )
+	{
+	  streamID1 = streamIDs[index];
+	  vlistID1  = vlistIDs[index];
+	  nrecs = numrecs[index];
+
+	  if ( vlistID1 == -1 ) continue;
 
-	  if ( index == 0 )
+	  if ( index == firstindex )
 	    {
 	      taxisCopyTimestep(taxisID2, taxisID1);
-
 	      streamDefTimestep(streamID2, tsID);
 	    }
 
@@ -264,17 +298,11 @@ void *Merge(void *argument)
 		  streamReadRecord(streamID1, array, &nmiss);
 		  streamWriteRecord(streamID2, array, nmiss);
 		}
-
-	      recID2++;
 	    }
 	}
-      tsID++;
 
-      for ( index = 0; index < nmerge; index++ )
-	if ( vlistIDs[index] != idum ) break;
-
-      if ( index == nmerge ) tsID = idum;
-    }
+      tsID++;
+   }
 
   for ( index = 0; index < nmerge; index++ )
     streamClose(streamIDs[index]);
@@ -285,6 +313,7 @@ void *Merge(void *argument)
 
   if ( streamIDs ) free(streamIDs);
   if ( vlistIDs  ) free(vlistIDs);
+  if ( numrecs   ) free(numrecs);
  
   if ( ! lcopy )
     if ( array ) free(array);
diff --git a/src/Output.c b/src/Output.c
index dfcb999..04c257d 100644
--- a/src/Output.c
+++ b/src/Output.c
@@ -23,7 +23,7 @@
       Output     outputint       Integer output
       Output     outputsrv       SERVICE output
       Output     outputext       EXTRA output
-      Output     outputtable     Table output
+      Output     outputtab       Table output
 */
 
 #include <ctype.h>
@@ -54,8 +54,10 @@ void *Output(void *argument)
   int nmiss, nout;
   int nlon, nlat;
   int nelem = 1;
+  int len;
   int index;
   int ndiffgrids;
+  int lhead = TRUE;
   const char *format = NULL;
   char paramstr[32];
   char vdatestr[32], vtimestr[32];
@@ -66,15 +68,14 @@ void *Output(void *argument)
   double missval;
   double lon, lat;
   char name[CDI_MAX_NAME];
-  int len;
   int npar = 0;
   int year, month, day;
   char **parnames = NULL;
   int *keys = NULL, nkeys = 0, k;
   int nKeys;
-  int Keylen[]           = {     8,      11,      4,      8,     6,     6,     6,      4,      4,     10,      8,      5,       2,     2 };
-  enum                     {kvalue,  kparam,  kcode,  kname,  klon,  klat,  klev,  kxind,  kyind,  kdate,  ktime,  kyear,  kmonth,  kday };
-  const char *Keynames[] = {"value", "param", "code", "name", "lon", "lat", "lev", "xind", "yind", "date", "time", "year", "month", "day"};
+  int Keylen[]           = {      0,        8,      11,      4,      8,     6,     6,     6,     6,      4,      4,          6,     10,      8,      5,       2,     2 };
+  enum                     {knohead,   kvalue,  kparam,  kcode,  kname,  klon,  klat,  klev,  kbin,  kxind,  kyind,  ktimestep,  kdate,  ktime,  kyear,  kmonth,  kday };
+  const char *Keynames[] = {"nohead", "value", "param", "code", "name", "lon", "lat", "lev", "bin", "xind", "yind", "timestep", "date", "time", "year", "month", "day"};
 
 
   cdoInitialize(argument);
@@ -90,6 +91,8 @@ void *Output(void *argument)
   OUTPUTXYZ = cdoOperatorAdd("outputxyz", 0, 0, NULL);
   OUTPUTTAB = cdoOperatorAdd("outputtab", 0, 0, NULL);
 
+  UNUSED(OUTPUT);
+
   operatorID = cdoOperatorID();
 
   if ( operatorID == OUTPUTF )
@@ -110,7 +113,7 @@ void *Output(void *argument)
 
       if ( cdoVerbose )
 	for ( i = 0; i < npar; i++ )
-	  printf("key %d = %s\n", i+1, parnames[i]);
+	  cdoPrint("key %d = %s", i+1, parnames[i]);
 
       keys = (int*) malloc(npar*sizeof(int));
       nkeys = 0;
@@ -124,8 +127,12 @@ void *Output(void *argument)
 	      if ( len < 3 ) len = 3;
 	      if ( strncmp(parnames[i], Keynames[k], len) == 0 )
 		{
-		  keys[nkeys++] = k;
-		  if ( parnames[i][len] && isdigit(parnames[i][len]) ) Keylen[k] = atoi(&parnames[i][len]);
+		  if ( k == knohead ) lhead = FALSE;
+		  else
+		    {
+		      keys[nkeys++] = k;
+		      if ( parnames[i][len] == ':' && isdigit(parnames[i][len+1]) ) Keylen[k] = atoi(&parnames[i][len+1]);
+		    }
 		  break;
 		}
 	    }
@@ -135,7 +142,19 @@ void *Output(void *argument)
  
       if ( cdoVerbose )
 	for ( k = 0; k < nkeys; ++k )
-	  printf("keynr = %d  keyid = %d  keyname = %s\n", k, keys[k], Keynames[keys[k]]);
+	  cdoPrint("keynr = %d  keyid = %d  keylen = %d  keyname = %s", k, keys[k], Keylen[keys[k]], Keynames[keys[k]]);
+
+      if ( lhead )
+	{
+	  fprintf(stdout, "#");
+	  for ( k = 0; k < nkeys; ++k )
+	    {
+	      len = Keylen[keys[k]];
+	      //   if ( k == 0 ) len -= 1;
+	      fprintf(stdout, "%*s ", len, Keynames[keys[k]]);
+	    }
+	  fprintf(stdout, "\n");
+	}
     }
 
   for ( indf = 0; indf < cdoStreamCnt(); indf++ )
@@ -274,12 +293,11 @@ void *Output(void *argument)
 		}
 	      else if ( operatorID == OUTPUTTAB )
 		{
-		  int xsize, ysize;
 		  int xind, yind;
 		  int l2d = FALSE;
 
-		  xsize = gridInqXsize(gridID);
-		  ysize = gridInqYsize(gridID);
+		  int xsize = gridInqXsize(gridID);
+		  // int ysize = gridInqYsize(gridID);
 		  if ( gridtype == GRID_CURVILINEAR ) l2d = TRUE;
 		      
 		  for ( i = 0; i < gridsize; i++ )
@@ -293,20 +311,22 @@ void *Output(void *argument)
 		      for ( k = 0; k < nkeys; ++k )
 			{
 			  len = Keylen[keys[k]];
-			  if      ( keys[k] == kvalue ) fprintf(stdout, "%*g ", len, array[i]);
-			  else if ( keys[k] == kparam ) fprintf(stdout, "%*s ", len, paramstr);
-			  else if ( keys[k] == kcode  ) fprintf(stdout, "%*d ", len, code);
-			  else if ( keys[k] == kname  ) fprintf(stdout, "%*s ", len, name);
-			  else if ( keys[k] == klon   ) fprintf(stdout, "%*g ", len, lon);
-			  else if ( keys[k] == klat   ) fprintf(stdout, "%*g ", len, lat);
-			  else if ( keys[k] == klev   ) fprintf(stdout, "%*g ", len, level);
-			  else if ( keys[k] == kxind  ) fprintf(stdout, "%*d ", len, xind+1);
-			  else if ( keys[k] == kyind  ) fprintf(stdout, "%*d ", len, yind+1);
-			  else if ( keys[k] == kdate  ) fprintf(stdout, "%*s ", len, vdatestr);
-			  else if ( keys[k] == ktime  ) fprintf(stdout, "%*s ", len, vtimestr);
-			  else if ( keys[k] == kyear  ) fprintf(stdout, "%*d ", len, year);
-			  else if ( keys[k] == kmonth ) fprintf(stdout, "%*d ", len, month);
-			  else if ( keys[k] == kday   ) fprintf(stdout, "%*d ", len, day);
+			  if      ( keys[k] == kvalue    ) fprintf(stdout, "%*g ", len, array[i]);
+			  else if ( keys[k] == kparam    ) fprintf(stdout, "%*s ", len, paramstr);
+			  else if ( keys[k] == kcode     ) fprintf(stdout, "%*d ", len, code);
+			  else if ( keys[k] == kname     ) fprintf(stdout, "%*s ", len, name);
+			  else if ( keys[k] == klon      ) fprintf(stdout, "%*g ", len, lon);
+			  else if ( keys[k] == klat      ) fprintf(stdout, "%*g ", len, lat);
+			  else if ( keys[k] == klev      ) fprintf(stdout, "%*g ", len, level);
+			  else if ( keys[k] == kbin      ) fprintf(stdout, "%*g ", len, level);
+			  else if ( keys[k] == kxind     ) fprintf(stdout, "%*d ", len, xind+1);
+			  else if ( keys[k] == kyind     ) fprintf(stdout, "%*d ", len, yind+1);
+			  else if ( keys[k] == ktimestep ) fprintf(stdout, "%*d ", len, tsID+1);
+			  else if ( keys[k] == kdate     ) fprintf(stdout, "%*s ", len, vdatestr);
+			  else if ( keys[k] == ktime     ) fprintf(stdout, "%*s ", len, vtimestr);
+			  else if ( keys[k] == kyear     ) fprintf(stdout, "%*d ", len, year);
+			  else if ( keys[k] == kmonth    ) fprintf(stdout, "%*d ", len, month);
+			  else if ( keys[k] == kday      ) fprintf(stdout, "%*d ", len, day);
 			}
 		      fprintf(stdout, "\n");
 		    }
diff --git a/src/Seasstat.c b/src/Seasstat.c
index b64334f..9c5ebdc 100644
--- a/src/Seasstat.c
+++ b/src/Seasstat.c
@@ -43,6 +43,8 @@ void *Seasstat(void *argument)
   int vdate = 0, vtime = 0;
   int vdate0 = 0, vtime0 = 0;
   int vdate1 = 0, vtime1 = 0;
+  int vdate_lb = 0, vdate_ub = 0, date_lb = 0, date_ub = 0;
+  int vtime_lb = 0, vtime_ub = 0, time_lb = 0, time_ub = 0;
   int nrecs, nrecords;
   int varID, levelID, recID;
   int tsID;
@@ -55,6 +57,7 @@ void *Seasstat(void *argument)
   int nmiss;
   int nvars, nlevel;
   int *recVarID, *recLevelID;
+  int taxis_has_bounds = FALSE;
   int newseas, oldmon = 0, newmon;
   int nseason = 0;
   field_t **vars1 = NULL, **vars2 = NULL, **samp1 = NULL;
@@ -85,6 +88,8 @@ void *Seasstat(void *argument)
 
   taxisID1 = vlistInqTaxis(vlistID1);
   taxisID2 = taxisDuplicate(taxisID1);
+  if ( taxisInqType(taxisID2) == TAXIS_FORECAST ) taxisDefType(taxisID2, TAXIS_RELATIVE);
+  taxis_has_bounds = taxisHasBounds(taxisID1);
   vlistDefTaxis(vlistID2, taxisID2);
 
   streamID2 = streamOpenWrite(cdoStreamName(1), cdoFiletype());
@@ -117,6 +122,20 @@ void *Seasstat(void *argument)
 	{
 	  vdate = taxisInqVdate(taxisID1);
 	  vtime = taxisInqVtime(taxisID1);
+
+	  if ( taxis_has_bounds )
+	    {
+	      taxisInqVdateBounds(taxisID1, &date_lb, &date_ub);
+	      taxisInqVtimeBounds(taxisID1, &time_lb, &time_ub);
+	      if ( nsets == 0 )
+		{ vdate_lb = date_lb; vtime_lb = time_lb; }
+	    }
+	  else
+	    {
+	      if ( nsets == 0 )
+		{ vdate_lb = vdate; vtime_lb = vtime; }
+	    }
+
 	  cdiDecodeDate(vdate, &year, &month, &day);
 	  if ( month < 1 || month > 12 )
 	    cdoAbort("Month %d out of range!", month);
@@ -158,6 +177,11 @@ void *Seasstat(void *argument)
 
 	  oldmon = newmon;
 
+	  if ( taxis_has_bounds )
+	    { vdate_ub = date_ub; vtime_ub = time_ub; }
+	  else
+	    { vdate_ub = vdate; vtime_ub = vtime; }
+
 	  for ( recID = 0; recID < nrecs; recID++ )
 	    {
 	      streamInqRecord(streamID1, &varID, &levelID);
@@ -290,6 +314,8 @@ void *Seasstat(void *argument)
 
       taxisDefVdate(taxisID2, vdate1);
       taxisDefVtime(taxisID2, vtime1);
+      taxisDefVdateBounds(taxisID2, vdate_lb, vdate_ub);
+      taxisDefVtimeBounds(taxisID2, vtime_lb, vtime_ub);
       streamDefTimestep(streamID2, otsID);
 
       if ( nsets < 3 )
diff --git a/src/Selrec.c b/src/Selrec.c
index 025c9e8..305936e 100644
--- a/src/Selrec.c
+++ b/src/Selrec.c
@@ -45,8 +45,7 @@ void *Selrec(void *argument)
 
   cdoInitialize(argument);
 
-  if ( processSelf() != 0 && *(char *)argument == '-' )
-    cdoAbort("This operator does not work with pipes!");
+  if ( processSelf() != 0 ) cdoAbort("This operator can't be combined with other operators!");
 
   operatorInputArg("records");
 
@@ -64,7 +63,7 @@ void *Selrec(void *argument)
 
   filetype = streamInqFiletype(streamID1);
 
-  if ( filetype == FILETYPE_NC || filetype == FILETYPE_NC2 )
+  if ( filetype == FILETYPE_NC || filetype == FILETYPE_NC2 || filetype == FILETYPE_NC4 || filetype == FILETYPE_NC4C )
     cdoAbort("This operator does not work on netCDF data!");
 
   vlistID1 = streamInqVlist(streamID1);
@@ -90,12 +89,14 @@ void *Selrec(void *argument)
 	{
 	  recordID++;
 	  streamInqRecord(streamID1, &varID, &levelID);
+
 	  for ( i = 0; i < nsel; i++ )
 	    {
 	      if ( recordID == intarr[i] )
 		{
 		  streamDefRecord(streamID2, varID, levelID);
 		  streamCopyRecord(streamID2, streamID1);
+
 		  break;
 		}
 	    }
diff --git a/src/Settime.c b/src/Settime.c
index 272e04f..6464805 100644
--- a/src/Settime.c
+++ b/src/Settime.c
@@ -245,17 +245,19 @@ void *Settime(void *argument)
     {
       char *cname = operatorArgv()[0];
       strtolower(cname);
+      size_t len = strlen(cname);
+      if ( len < 3 ) len = 7;
       if      ( strcmp(cname, "standard")  == 0 ) newcalendar = CALENDAR_STANDARD;
       else if ( strcmp(cname, "gregorian") == 0 ) newcalendar = CALENDAR_STANDARD;
       else if ( strcmp(cname, "proleptic") == 0 ) newcalendar = CALENDAR_PROLEPTIC;
       else if ( strcmp(cname, "proleptic_gregorian") == 0 ) newcalendar = CALENDAR_PROLEPTIC;
-      else if ( strcmp(cname, "360days")   == 0 ) newcalendar = CALENDAR_360DAYS;
-      else if ( strcmp(cname, "360_day")   == 0 ) newcalendar = CALENDAR_360DAYS;
-      else if ( strcmp(cname, "365days")   == 0 ) newcalendar = CALENDAR_365DAYS;
-      else if ( strcmp(cname, "365_day")   == 0 ) newcalendar = CALENDAR_365DAYS;
-      else if ( strcmp(cname, "366days")   == 0 ) newcalendar = CALENDAR_366DAYS;
-      else if ( strcmp(cname, "366_day")   == 0 ) newcalendar = CALENDAR_366DAYS;
-      else cdoAbort("Calendar >%s< unsupported!", cname);
+      else if ( strncmp(cname, "360days", len) == 0 ) newcalendar = CALENDAR_360DAYS;
+      else if ( strncmp(cname, "360_day", len) == 0 ) newcalendar = CALENDAR_360DAYS;
+      else if ( strncmp(cname, "365days", len) == 0 ) newcalendar = CALENDAR_365DAYS;
+      else if ( strncmp(cname, "365_day", len) == 0 ) newcalendar = CALENDAR_365DAYS;
+      else if ( strncmp(cname, "366days", len) == 0 ) newcalendar = CALENDAR_366DAYS;
+      else if ( strncmp(cname, "366_day", len) == 0 ) newcalendar = CALENDAR_366DAYS;
+      else cdoAbort("Calendar >%s< unsupported! Available %s", cname, cdoOperatorEnter(operatorID));
     }
   else
     {
diff --git a/src/Sinfo.c b/src/Sinfo.c
index 24a3cce..841d7b7 100644
--- a/src/Sinfo.c
+++ b/src/Sinfo.c
@@ -90,7 +90,7 @@ void *Sinfo(void *argument)
   char varname[CDI_MAX_NAME];
   char paramstr[32];
   char vdatestr[32], vtimestr[32];
-  char *modelptr, *instptr;
+  const char *modelptr, *instptr;
   int streamID = 0;
   int vlistID;
   int datatype;
@@ -178,6 +178,7 @@ void *Sinfo(void *argument)
 	  else if ( tsteptype == TSTEP_INSTANT3 ) fprintf(stdout, "%-8s ", "instant");
 	  else if ( tsteptype == TSTEP_MIN      ) fprintf(stdout, "%-8s ", "min");
 	  else if ( tsteptype == TSTEP_MAX      ) fprintf(stdout, "%-8s ", "max");
+	  else if ( tsteptype == TSTEP_AVG      ) fprintf(stdout, "%-8s ", "avg");
 	  else if ( tsteptype == TSTEP_ACCUM    ) fprintf(stdout, "%-8s ", "accum");
 	  else if ( tsteptype == TSTEP_RANGE    ) fprintf(stdout, "%-8s ", "range");
 	  else if ( tsteptype == TSTEP_DIFF     ) fprintf(stdout, "%-8s ", "diff");
diff --git a/src/Timstat.c b/src/Timstat.c
index d81080f..0a0bff8 100644
--- a/src/Timstat.c
+++ b/src/Timstat.c
@@ -255,10 +255,12 @@ void *Timstat(void *argument)
 	      taxisInqVdateBounds(taxisID1, &date_lb, &date_ub);
 	      taxisInqVtimeBounds(taxisID1, &time_lb, &time_ub);
 	      if ( nsets == 0 )
-		{
-		  vdate_lb = date_lb;
-		  vtime_lb = time_lb;
-		}
+		{ vdate_lb = date_lb; vtime_lb = time_lb; }
+	    }
+	  else
+	    {
+	      if ( nsets == 0 )
+		{ vdate_lb = vdate; vtime_lb = vtime; }
 	    }
 
 	  if ( nsets == 0 ) SET_DATE(indate2, vdate, vtime);
@@ -267,10 +269,9 @@ void *Timstat(void *argument)
 	  if ( DATE_IS_NEQ(indate1, indate2, cmplen) ) break;
 
 	  if ( taxis_has_bounds )
-	    {
-	      vdate_ub = date_ub;
-	      vtime_ub = time_ub;
-	    }
+	    { vdate_ub = date_ub; vtime_ub = time_ub; }
+	  else
+	    { vdate_ub = vdate; vtime_ub = vtime; }
 
 	  for ( recID = 0; recID < nrecs; recID++ )
 	    {
@@ -430,22 +431,16 @@ void *Timstat(void *argument)
 
       taxisDefVdate(taxisID2, vdate0);
       taxisDefVtime(taxisID2, vtime0);
-      if ( taxis_has_bounds )
-	{
-	  taxisDefVdateBounds(taxisID2, vdate_lb, vdate_ub);
-	  taxisDefVtimeBounds(taxisID2, vtime_lb, vtime_ub);
-	}
+      taxisDefVdateBounds(taxisID2, vdate_lb, vdate_ub);
+      taxisDefVtimeBounds(taxisID2, vtime_lb, vtime_ub);
       streamDefTimestep(streamID2, otsID);
 
       if ( cdoDiag )
 	{
 	  taxisDefVdate(taxisID3, vdate0);
 	  taxisDefVtime(taxisID3, vtime0);
-	  if ( taxis_has_bounds )
-	    {
-	      taxisDefVdateBounds(taxisID3, vdate_lb, vdate_ub);
-	      taxisDefVtimeBounds(taxisID3, vtime_lb, vtime_ub);
-	    }
+	  taxisDefVdateBounds(taxisID3, vdate_lb, vdate_ub);
+	  taxisDefVtimeBounds(taxisID3, vtime_lb, vtime_ub);
 	  streamDefTimestep(streamID3, otsID);
 	}
 
diff --git a/src/cdo.c b/src/cdo.c
index 4f09885..a2a99e8 100644
--- a/src/cdo.c
+++ b/src/cdo.c
@@ -931,24 +931,22 @@ void print_system_info()
 
 #if defined(_ARCH_PWR6)
   fprintf(stderr, "Predefined: _ARCH_PWR6\n");
-#endif 
-#if defined(_ARCH_PWR7)
+#elif defined(_ARCH_PWR7)
   fprintf(stderr, "Predefined: _ARCH_PWR7\n");
-#endif 
-#if defined(__SSE2__)
-  fprintf(stderr, "Predefined: __SSE2__\n");
-#endif 
-#if defined(__SSE3__)
-  fprintf(stderr, "Predefined: __SSE3__\n");
-#endif 
-#if defined(__SSE4_1__)
-  fprintf(stderr, "Predefined: __SSE4_1__\n");
-#endif 
-#if defined(__SSE4_2__)
-  fprintf(stderr, "Predefined: __SSE4_2__\n");
-#endif 
-#if defined(__AVX__)
+#endif
+
+#if defined(__AVX2__)
+  fprintf(stderr, "Predefined: __AVX2__\n");
+#elif defined(__AVX__)
   fprintf(stderr, "Predefined: __AVX__\n");
+#elif defined(__SSE4_2__)
+  fprintf(stderr, "Predefined: __SSE4_2__\n");
+#elif defined(__SSE4_1__)
+  fprintf(stderr, "Predefined: __SSE4_1__\n");
+#elif defined(__SSE3__)
+  fprintf(stderr, "Predefined: __SSE3__\n");
+#elif defined(__SSE2__)
+  fprintf(stderr, "Predefined: __SSE2__\n");
 #endif 
   fprintf(stderr, "\n");
 
diff --git a/src/cdo.h b/src/cdo.h
index 77721d2..e2f9023 100644
--- a/src/cdo.h
+++ b/src/cdo.h
@@ -85,7 +85,7 @@ extern char **cdoVarnames;
 int cdo_omp_get_thread_num(void);
 
 
-void    cdiError(int cdiErrno, const char *fmt, ...);
+void    cdiOpenError(int cdiErrno, const char *fmt, const char *path);
 void    cdoAbort(const char *fmt, ...);
 void    cdoWarning(const char *fmt, ...);
 void    cdoPrint(const char *fmt, ...);
diff --git a/src/clipping/clipping.c b/src/clipping/clipping.c
index 3ef1867..2f8cd8c 100644
--- a/src/clipping/clipping.c
+++ b/src/clipping/clipping.c
@@ -154,13 +154,25 @@ void compute_concave_overlap_areas (unsigned N,
     abort_message("ERROR: missing target point coordinates "
 		  "(x_coordinates == NULL || y_coordinates == NULL)",
 		  __FILE__, __LINE__);
-
+  /*
   struct grid_cell target_partial_cell =
     {.coordinates_x   = (double[3]){-1},
      .coordinates_y   = (double[3]){-1},
      .coordinates_xyz = (double[3*3]){-1},
      .edge_type       = (enum edge_type[3]) {GREAT_CIRCLE},
      .num_corners     = 3};
+  */
+  double coordinates_x[3] = {-1, -1, -1};
+  double coordinates_y[3] = {-1, -1, -1};
+  double coordinates_xyz[9] = {-1, -1, -1};
+  enum edge_type edge_types[3] = {GREAT_CIRCLE, GREAT_CIRCLE, GREAT_CIRCLE};
+  struct grid_cell target_partial_cell =
+    {.coordinates_x   = coordinates_x,
+     .coordinates_y   = coordinates_y,
+     .coordinates_xyz = coordinates_xyz,
+     .edge_type       = edge_types,
+     .num_corners     = 3};
+
 
   static struct grid_cell * overlap_buffer = NULL;
   static unsigned overlap_buffer_size = 0;
@@ -449,8 +461,8 @@ static void get_edge_middle_point(double a[3], double b[3],
   };
 }
 
-static struct grid_cell curr_target_cell;
-static struct grid_cell curr_source_cell;
+//static struct grid_cell curr_target_cell;
+//static struct grid_cell curr_source_cell;
 
 /**
  * cell clipping using Sutherland–Hodgman algorithm;
@@ -867,22 +879,22 @@ static void copy_point_list(struct point_list in, struct point_list * out) {
 
   if (curr == NULL) return;
 
-  struct point_list_element * new = get_free_point_list_element(out);
-  out->first = new;
-  *new = *curr;
+  struct point_list_element * xnew = get_free_point_list_element(out);
+  out->first = xnew;
+  *xnew = *curr;
   curr = curr->next;
 
   do {
 
-    new->next = get_free_point_list_element(out);
-    new = new->next;
-    *new = *curr;
+    xnew->next = get_free_point_list_element(out);
+    xnew = xnew->next;
+    *xnew = *curr;
     curr = curr->next;
 
   } while (curr != in.first);
 
-  new->next = out->first;
-  out->last = new;
+  xnew->next = out->first;
+  out->last = xnew;
 }
 
 void cell_clipping(unsigned N,
@@ -1003,8 +1015,8 @@ void cell_clipping(unsigned N,
          (fabs(target_cell.coordinates_y[0]) >
           fabs(source_cell[n].coordinates_y[0])))) {
 
-      curr_target_cell = source_cell[n];
-      curr_source_cell = target_cell;
+      // curr_target_cell = source_cell[n];
+      //  curr_source_cell = target_cell;
 
       copy_point_list(target_list, &temp_list);
 
@@ -1039,8 +1051,8 @@ void cell_clipping(unsigned N,
 
     } else {
 
-      curr_target_cell = target_cell;
-      curr_source_cell = source_cell[n];
+      // curr_target_cell = target_cell;
+      //  curr_source_cell = source_cell[n];
 
       point_list_clipping(&source_list, source_ordering,
                           target_list, target_ordering, nct, norm_vec);
diff --git a/src/clipping/grid.h b/src/clipping/grid.h
index cd0b815..921ddca 100644
--- a/src/clipping/grid.h
+++ b/src/clipping/grid.h
@@ -109,7 +109,7 @@ struct grid_vtable {
    void (*pack_grid)(struct grid *, double **, unsigned, unsigned *, unsigned *,
                      unsigned **, unsigned, unsigned *, unsigned *);
    struct grid_search * (*get_grid_search)(struct grid * grid);
-   void (*delete)(struct grid *);
+   void (*xdelete)(struct grid *);
 };
 
 struct grid {
diff --git a/src/clipping/intersection.c b/src/clipping/intersection.c
index eea2273..de304eb 100644
--- a/src/clipping/intersection.c
+++ b/src/clipping/intersection.c
@@ -231,7 +231,8 @@ static int vector_is_between_lat (double a[], double b[], double p[]) {
 
             if (vector_is_between(c, d, a, &angle_cd, dot_cd))
                result |= 1 << 2;
-            if (vector_is_between(c, d, (double[]){-a[0], -a[1], -a[2]}, &angle_cd,
+	    double tvec[] = {-a[0], -a[1], -a[2]};
+            if (vector_is_between(c, d, tvec, &angle_cd,
                                   dot_cd)) result |= 1 << 3;
 
             return result;
@@ -263,7 +264,8 @@ static int vector_is_between_lat (double a[], double b[], double p[]) {
 
             if (vector_is_between(a, b, c, &angle_ab, dot_ab))
                result |= 1 << 0;
-            if (vector_is_between(a, b, (double[]){-c[0], -c[1], -c[2]}, &angle_ab,
+	    double tvec[] = {-c[0], -c[1], -c[2]};
+            if (vector_is_between(a, b, tvec, &angle_ab,
                                   dot_ab)) result |= 1 << 1;
 
             return result;
diff --git a/src/exception.c b/src/exception.c
index 41a3753..5bdcfeb 100644
--- a/src/exception.c
+++ b/src/exception.c
@@ -8,25 +8,66 @@
 
 static int _ExitOnError   = 1;	/* If set to 1, exit on error       */
 
-void cdiError(int cdiErrno, const char *fmt, ...)
-{
-  va_list args;
-	
-  va_start(args, fmt);
-
+void cdiOpenError(int cdiErrno, const char *fmt, const char *path)
+{	
   printf("\n");
   set_text_color(stderr, RESET, RED);
    fprintf(stderr, "%s: ", processInqPrompt());
   reset_text_color(stderr);
   set_text_color(stderr, RESET, BLACK);
-  vfprintf(stderr, fmt, args);
+  fprintf(stderr, fmt, path);
   reset_text_color(stderr);
    fprintf(stderr, "\n");
 
-  va_end(args);
-
   fprintf(stderr, "%s\n", cdiStringError(cdiErrno));
 
+  if ( cdiErrno == CDI_ELIBNAVAIL )
+    {
+      int byteorder;
+      int filetype = cdiGetFiletype(path, &byteorder);
+
+      switch (filetype)
+	{
+	case FILETYPE_GRB:
+	  {
+	    break;
+	  }
+	case FILETYPE_GRB2:
+	  {
+	    fprintf(stderr, "To create a CDO application with GRIB2 support use: ./configure --with-netcdf=<GRIB_API root directory> ...\n");
+	    break;
+	  }
+	case FILETYPE_SRV:
+	  {
+	    break;
+	  }
+	case FILETYPE_EXT:
+	  {
+	    break;
+	  }
+	case FILETYPE_IEG:
+	  {
+	    break;
+	  }
+	case FILETYPE_NC:
+	case FILETYPE_NC2:
+	  {
+	    fprintf(stderr, "To create a CDO application with netCDF support use: ./configure --with-netcdf=<netCDF root directory> ...\n");
+	    break;
+	  }
+	case FILETYPE_NC4:
+	case FILETYPE_NC4C:
+	  {
+	    fprintf(stderr, "To create a CDO application with netCDF4 support use: ./configure --with-netcdf=<netCDF4 root directory> ...\n");
+	    break;
+	  }
+	default:
+	  {
+	    break;
+	  }
+	}
+    }
+  
   if ( _ExitOnError ) exit(EXIT_FAILURE);
 }
 
diff --git a/src/expr.c b/src/expr.c
index ceadab2..8f940ab 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <math.h>
 #include <errno.h>
+#include <ctype.h>
 
 #include <cdi.h>
 #include "cdo.h"
@@ -862,8 +863,17 @@ nodeType *expr_run(nodeType *p, parse_parm_t *parse_arg)
 		cdoAbort("Operand not variable!");
 
 	      varID = vlistDefVar(parse_arg->vlistID2, parse_arg->gridID2, parse_arg->zaxisID2, parse_arg->tsteptype2);
-	      vlistDefVarName(parse_arg->vlistID2, varID, p->u.opr.op[0]->u.var.nm);
+	      const char *varname = p->u.opr.op[0]->u.var.nm;
+	      vlistDefVarName(parse_arg->vlistID2, varID, varname);
 	      vlistDefVarMissval(parse_arg->vlistID2, varID, parse_arg->missval2);
+	      if ( memcmp(varname, "var", 3) == 0 )
+		{
+		  if ( strlen(varname) > 3 && isdigit(varname[3]) )
+		    {
+		      int code = atoi(varname+3);
+		      vlistDefVarCode(parse_arg->vlistID2, varID, code);
+		    }
+		}
 	    }
 	  else
 	    {
diff --git a/src/features.c b/src/features.c
index 493dddc..6c33550 100644
--- a/src/features.c
+++ b/src/features.c
@@ -66,6 +66,19 @@ void printFeatures(void)
 #if defined(HAVE_LIBFFTW3)
   fprintf(stderr, " FFTW3");
 #endif
+#if defined(__AVX2__)
+  fprintf(stderr, " AVX2");
+#elif defined(__AVX__)
+  fprintf(stderr, " AVX");
+#elif defined(__SSE4_2__)
+  fprintf(stderr, " SSE4_2");
+#elif defined(__SSE4_1__)
+  fprintf(stderr, " SSE4_1");
+#elif defined(__SSE3__)
+  fprintf(stderr, " SSE3");
+#elif defined(__SSE2__)
+  fprintf(stderr, " SSE2");
+#endif 
   fprintf(stderr, "\n");
 }
 
diff --git a/src/grid_area.c b/src/grid_area.c
index 547d04d..79fea38 100644
--- a/src/grid_area.c
+++ b/src/grid_area.c
@@ -20,6 +20,7 @@
 #include "error.h"
 #include "grid.h"
 
+
 static
 void lonlat_to_xyz(double lon, double lat, double *xyz)
 {
@@ -29,6 +30,35 @@ void lonlat_to_xyz(double lon, double lat, double *xyz)
   xyz[2] = sin(lat);
 }
 
+/*
+#include "clipping/grid.h"
+#include "clipping/grid_cell.h"
+#include "clipping/area.h"
+
+static
+double yac_huiliers_area(int num_corners, double *cell_corner_lon, double *cell_corner_lat)
+{
+  if ( num_corners < 3 ) return 0;
+
+  double coordinates_xyz[num_corners*3];
+  enum edge_type edge_types[num_corners];
+  struct grid_cell cell =
+    {.coordinates_x   = cell_corner_lon,
+     .coordinates_y   = cell_corner_lat,
+     .coordinates_xyz = coordinates_xyz,
+     .edge_type       = edge_types,
+     .num_corners     = num_corners};
+
+  for ( int i = 0; i < num_corners; ++i ) edge_types[i] = GREAT_CIRCLE;
+  for ( int i = 0; i < num_corners; ++i ) 
+    lonlat_to_xyz(cell_corner_lon[i], cell_corner_lat[i], coordinates_xyz+i*3);
+
+  double area = huiliers_area(cell);
+  area /= (EarthRadius*EarthRadius);
+
+  return (area);
+}
+*/
 static
 void cross_product(const double *restrict a, const double *restrict b, double *restrict c)
 {
@@ -50,7 +80,7 @@ double norm(const double *restrict a)
 }
 
 static
-double cell_area(int num_corners, double *cell_corner_lon, double *cell_corner_lat)
+double mod_cell_area(int num_corners, double *cell_corner_lon, double *cell_corner_lat)
 {
   if ( num_corners < 3 ) return 0;
 
@@ -154,7 +184,7 @@ double cell_area(int num_corners, double *cell_corner_lon, double *cell_corner_l
   * Licensed under the University of Illinois-NCSA License.
   */
 static
-double tri_area(const double *restrict u, const double *restrict v, const double *restrict w)
+double mod_tri_area(const double *restrict u, const double *restrict v, const double *restrict w)
 {
   double tmp_vec[3];
 
@@ -193,7 +223,7 @@ double tri_area(const double *restrict u, const double *restrict v, const double
   * Licensed under the University of Illinois-NCSA License.
   */
 static
-double huiliers_area(int num_corners, double *cell_corner_lon, double *cell_corner_lat)
+double mod_huiliers_area(int num_corners, double *cell_corner_lon, double *cell_corner_lat)
 {
   if ( num_corners < 3 ) return 0;
 
@@ -210,7 +240,7 @@ double huiliers_area(int num_corners, double *cell_corner_lon, double *cell_corn
       lonlat_to_xyz(cell_corner_lon[i], cell_corner_lat[i], pnt3);
  
       // compute angle for pnt2
-      sum += tri_area(pnt1, pnt2, pnt3);
+      sum += mod_tri_area(pnt1, pnt2, pnt3);
 
       if ( i < (num_corners-1) ) { pnt2[0] = pnt3[0]; pnt2[1] = pnt3[1]; pnt2[2] = pnt3[2]; }
     }
@@ -219,7 +249,7 @@ double huiliers_area(int num_corners, double *cell_corner_lon, double *cell_corn
 }
 
 static
-double huiliers_area2(int num_corners, double *cell_corner_lon, double *cell_corner_lat, double cell_center_lon, double cell_center_lat)
+double mod_huiliers_area2(int num_corners, double *cell_corner_lon, double *cell_corner_lat, double cell_center_lon, double cell_center_lat)
 {
   if ( num_corners < 3 ) return 0;
 
@@ -238,7 +268,7 @@ double huiliers_area2(int num_corners, double *cell_corner_lon, double *cell_cor
       lonlat_to_xyz(cell_corner_lon[i], cell_corner_lat[i], pnt3);
  
       // compute angle for pnt2
-      sum += tri_area(pnt1, pnt2, pnt3);
+      sum += mod_tri_area(pnt1, pnt2, pnt3);
 
       pnt2[0] = pnt3[0]; pnt2[1] = pnt3[1]; pnt2[2] = pnt3[2];
     }
@@ -246,7 +276,7 @@ double huiliers_area2(int num_corners, double *cell_corner_lon, double *cell_cor
   if ( !(IS_EQUAL(cell_corner_lon[0], cell_corner_lon[num_corners-1]) && IS_EQUAL(cell_corner_lat[0], cell_corner_lat[num_corners-1])) )
     {
       lonlat_to_xyz(cell_corner_lon[0], cell_corner_lat[0], pnt3);
-      sum += tri_area(pnt1, pnt2, pnt3);
+      sum += mod_tri_area(pnt1, pnt2, pnt3);
     }
 
   return (sum);
@@ -423,11 +453,11 @@ int gridGenArea(int gridID, double* area)
       findex++;
       if ( lprogress ) progressStatus(0, 1, findex/gridsize);
 
-      //area[i] = cell_area(nv, grid_corner_lon+i*nv, grid_corner_lat+i*nv);
+      //area[i] = mod_cell_area(nv, grid_corner_lon+i*nv, grid_corner_lat+i*nv);
       if ( nv <= 4 )
-	area[i] = huiliers_area(nv, grid_corner_lon+i*nv, grid_corner_lat+i*nv);
+	area[i] = mod_huiliers_area(nv, grid_corner_lon+i*nv, grid_corner_lat+i*nv);
       else
-	area[i] = huiliers_area2(nv, grid_corner_lon+i*nv, grid_corner_lat+i*nv, grid_center_lon[i], grid_center_lat[i]);
+	area[i] = mod_huiliers_area2(nv, grid_corner_lon+i*nv, grid_corner_lat+i*nv, grid_center_lon[i], grid_center_lat[i]);
     }
 
   if ( cdoVerbose )
diff --git a/src/griddes.c b/src/griddes.c
index 0c70266..5eaa3d9 100644
--- a/src/griddes.c
+++ b/src/griddes.c
@@ -507,7 +507,7 @@ int gridDefine(griddes_t grid)
       }
     }
 
-  if ( *grid.uuid ) gridDefUUID(gridID, grid.uuid);
+  if ( grid.uuid[0] )      gridDefUUID(gridID, grid.uuid);
 
   if ( grid.xname[0]     ) gridDefXname(gridID, grid.xname);
   if ( grid.xlongname[0] ) gridDefXlongname(gridID, grid.xlongname);
@@ -670,7 +670,7 @@ double readflt(const char *filename, const char *name, const char *pline)
   return (val);
 }
 
-void str2uuid(const char *uuidstr, char *uuid);
+void str2uuid(const char *uuidstr, unsigned char *uuid);
 
 int gridFromFile(FILE *gfp, const char *dname)
 {
diff --git a/src/griddes.h b/src/griddes.h
index 7de9fdd..2e243db 100644
--- a/src/griddes.h
+++ b/src/griddes.h
@@ -53,7 +53,7 @@ typedef struct {
   int     def_yinc;
   int     nd, ni, ni2, ni3;
   int     number, position;
-  char    uuid[17];
+  unsigned char uuid[CDI_UUID_SIZE];
   char    path[16384];
   char    xname[CDI_MAX_NAME];
   char    xlongname[CDI_MAX_NAME];
diff --git a/src/gridreference.c b/src/gridreference.c
index 6a3409b..84b625c 100644
--- a/src/gridreference.c
+++ b/src/gridreference.c
@@ -228,45 +228,42 @@ int referenceToGrid(int gridID1)
 	  position = gridInqPosition(gridID1);
 
 	  streamID = streamOpenRead(gridpath);
-	  if ( streamID >= 0 )
+	  if ( streamID < 0 ) cdiOpenError(streamID, "Open failed on horizontal grid file >%s<", gridpath);
+
+	  int vlistID, gridID = -1;
+	  int ngrids;
+	  vlistID = streamInqVlist(streamID);
+	  ngrids = vlistNgrids(vlistID);
+	  if ( position > 0 && position <= ngrids )
+	    {
+	      gridID = vlistGrid(vlistID, position-1);
+	      if ( gridInqSize(gridID) == gridsize )
+		gridID2 = gridDuplicate(gridID);
+	      else
+		cdoWarning("Grid size %d on position %d do not match! Reference=%s", gridsize, position, gridpath);
+	    }
+	  else if ( position == 0 )
 	    {
-	      int vlistID, gridID = -1;
-	      int ngrids;
-	      vlistID = streamInqVlist(streamID);
-	      ngrids = vlistNgrids(vlistID);
-	      if ( position > 0 && position <= ngrids )
+	      for ( int grididx = 0; grididx < ngrids; ++grididx )
 		{
-		  gridID = vlistGrid(vlistID, position-1);
+		  gridID = vlistGrid(vlistID, grididx);
 		  if ( gridInqSize(gridID) == gridsize )
-		    gridID2 = gridDuplicate(gridID);
-		  else
-		    cdoWarning("Grid size %d on position %d do not match! Reference=%s", gridsize, position, gridpath);
-		}
-	      else if ( position == 0 )
-		{
-		  for ( int grididx = 0; grididx < ngrids; ++grididx )
 		    {
-		      gridID = vlistGrid(vlistID, grididx);
-		      if ( gridInqSize(gridID) == gridsize )
-			{
-			  gridID2 = gridDuplicate(gridID);
-			  break;
+		      gridID2 = gridDuplicate(gridID);
+		      break;
 			}
-		    }
 		}
-	      else
-		cdoWarning("Number of grid in reference %d not available! Reference=%s", position, gridpath);
-	      
-	      streamClose(streamID);
 	    }
 	  else
-	    cdiError(streamID, "Open failed on horizontal grid file >%s<", gridpath);
+	    cdoWarning("Number of grid in reference %d not available! Reference=%s", position, gridpath);
+	  
+	  streamClose(streamID);
 	}
 
       if ( gridID2 != -1 )
 	{
-	  char uuidOfHGrid1[16];
-	  char uuidOfHGrid2[16];
+	  unsigned char uuidOfHGrid1[CDI_UUID_SIZE];
+	  unsigned char uuidOfHGrid2[CDI_UUID_SIZE];
 
 	  memset(uuidOfHGrid1, 0, 16);
 	  memset(uuidOfHGrid2, 0, 16);
diff --git a/src/modules.c b/src/modules.c
index a5de5bf..e865480 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -314,7 +314,7 @@ void *Maggraph(void *argument);
 #define  ExprOperators          {"expr", "exprf", "aexpr", "aexprf"}
 #define  FCOperators            {"fc2sp", "sp2fc", "fc2gp", "gp2fc"}
 #define  FiledesOperators       {"filedes", "griddes", "griddes2", "zaxisdes", "vct", "vct2", "pardes", \
-                                 "vlist", "partab", "partab2"}
+                                 "vlist", "partab", "partab2", "spartab"}
 #define  FillmissOperators      {"fillmiss","fillmiss2"}
 #define  FilterOperators        {"bandpass", "highpass", "lowpass"}
 #define  FldrmsOperators        {"fldrms"}
@@ -362,7 +362,8 @@ void *Maggraph(void *argument);
 #define  NinfoOperators         {"nyear", "nmon", "ndate", "ntime", "ncode", "npar", "nlevel"}
 #define  NmltestOperators       {"nmltest"}
 #define  OutputOperators        {"output", "outputint", "outputsrv", "outputext", "outputf", "outputts", \
-                                 "outputfld", "outputarr", "outputxyz", "outputtab"}
+                                 "outputfld", "outputarr", "outputxyz"}
+#define  OutputtabOperators     {"outputtab"}
 #define  OutputgmtOperators     {"gridverify", "outputcenter", "outputcenter2", "outputcentercpt", "outputbounds", \
                                  "outputboundscpt", "outputvector", "outputtri", "outputvrml"}
 #define  PackOperators          {"pack"}
@@ -627,6 +628,7 @@ static modules_t Modules[] =
   { Ninfo,          NinfoHelp,         NinfoOperators,         CDI_BOTH,  1,  0 },
   { Nmltest,        NULL,              NmltestOperators,       CDI_REAL,  0,  0 },
   { Output,         OutputHelp,        OutputOperators,        CDI_REAL, -1,  0 },
+  { Output,         OutputtabHelp,     OutputtabOperators,     CDI_REAL, -1,  0 },
   { Outputgmt,      NULL,              OutputgmtOperators,     CDI_REAL,  1,  0 },
   { Pack,           NULL,              PackOperators,          CDI_REAL,  1,  1 },
   { Pinfo,          NULL,              PinfoOperators,         CDI_REAL,  1,  1 },
diff --git a/src/operator_help.h b/src/operator_help.h
index 37cfb08..913221e 100644
--- a/src/operator_help.h
+++ b/src/operator_help.h
@@ -416,7 +416,7 @@ static char *DistgridHelp[] = {
     "",
     "NOTE",
     "    This operator needs to open all output files simultaneously.",
-    "    The maximum number of open files depents on the operating system!",
+    "    The maximum number of open files depends on the operating system!",
     NULL
 };
 
@@ -437,7 +437,7 @@ static char *CollgridHelp[] = {
     "",
     "NOTE",
     "    This operator needs to open all input files simultaneously.",
-    "    The maximum number of open files depents on the operating system!",
+    "    The maximum number of open files depends on the operating system!",
     NULL
 };
 
@@ -805,7 +805,7 @@ static char *SetpartabHelp[] = {
     "    ",
     "    The following parameter table entries are supported:",
     "    ",
-    "     Entry    & Type & Description      ",
+    "     Entry           & Type        & Description      ",
     "     name            & WORD        & Name of the variable",
     "     out_name        & WORD        & New name of the variable",
     "     param           & WORD        & Parameter identifier (GRIB1: code[.tabnum];  GRIB2: num[.cat[.dis]])",
@@ -3919,6 +3919,46 @@ static char *OutputHelp[] = {
     NULL
 };
 
+static char *OutputtabHelp[] = {
+    "NAME",
+    "    outputtab - Table output",
+    "",
+    "SYNOPSIS",
+    "    outputtab,params  ifiles ofile",
+    "",
+    "DESCRIPTION",
+    "    This operator prints a table of all input datasets to standard output.",
+    "    ifiles is an arbitrary number of input files. All input files need to have ",
+    "    the same structure with the same variables on different timesteps.",
+    "    All input fields need to have the same horizontal grid.",
+    "    ",
+    "    The contents of the table depends on the chosen paramters. The format of each table",
+    "    parameter is keyname[:len]. len is the optional length of a table entry.  ",
+    "    Here is a list a all valid keynames:",
+    "    ",
+    "     Keyname    & Type    & Description      ",
+    "     value      & FLOAT   & Value of the variable [len:8]",
+    "     name       & STRING  & Name of the variable [len:8]",
+    "     param      & STRING  & Parameter ID (GRIB1: code[.tabnum]; GRIB2: num[.cat[.dis]]) [len:11]",
+    "     code       & INTEGER & Code number [len:4]",
+    "     lon        & FLOAT   & Longitude coordinate [len:6]",
+    "     lat        & FLOAT   & Latitude coordinate [len:6]",
+    "     lev        & FLOAT   & Vertical level [len:6]",
+    "     xind       & INTEGER & Grid x index [len:4]",
+    "     yind       & INTEGER & Grid y index [len:4]",
+    "     timestep   & INTEGER & Timestep number [len:6]",
+    "     date       & STRING  & Date (format YYYY-MM-DD) [len:10]",
+    "     time       & STRING  & Time (format hh:mm:ss) [len:8]",
+    "     year       & INTEGER & Year [len:5]",
+    "     month      & INTEGER & Month [len:2]",
+    "     day        & INTEGER & Day [len:2]",
+    "     nohead     & INTEGER & Disable output of header line",
+    "",
+    "PARAMETER",
+    "    params  STRING   Comma separated list of keynames, one for each column of the table",
+    NULL
+};
+
 static char *GradsdesHelp[] = {
     "NAME",
     "    gradsdes - GrADS data descriptor file",
diff --git a/src/printinfo.h b/src/printinfo.h
index 546b7fe..3b94efa 100644
--- a/src/printinfo.h
+++ b/src/printinfo.h
@@ -1,7 +1,7 @@
 #define DATE_FORMAT "%5.4d-%2.2d-%2.2d"
 #define TIME_FORMAT "%2.2d:%2.2d:%2.2d"
 
-void uuid2str(const char *uuid, char *uuidstr);
+void uuid2str(const unsigned char uuid[CDI_UUID_SIZE], char *uuidstr);
 
 void date2str(int date, char *datestr, int maxlen)
 {
@@ -135,7 +135,7 @@ void printGridInfo(int vlistID)
   int ngrids, index;
   int gridID, gridtype, trunc, gridsize, xsize, ysize, xysize;
   char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME];
-  char uuidOfHGrid[17];
+  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
 
   ngrids = vlistNgrids(vlistID);
   for ( index = 0; index < ngrids; index++ )
@@ -302,8 +302,8 @@ void printGridInfo(int vlistID)
 	      int i;
 	      double *xvals, *yvals;
 	      double xfirst, xlast, yfirst, ylast;
-	      xvals = (double*) malloc(gridsize*sizeof(double));
-	      yvals = (double*) malloc(gridsize*sizeof(double));
+	      xvals = (double*) malloc((size_t)gridsize*sizeof(double));
+	      yvals = (double*) malloc((size_t)gridsize*sizeof(double));
 
 	      gridInqXvals(gridID, xvals);
 	      gridInqYvals(gridID, yvals);
@@ -410,7 +410,7 @@ void printZaxisInfo(int vlistID)
       fprintf(stdout, " levels=%d", levelsize);
       fprintf(stdout, "\n");
 
-      levels = (double*) malloc(levelsize*sizeof(double));
+      levels = (double*) malloc((size_t)levelsize*sizeof(double));
       zaxisInqLevels(zaxisID, levels);
 
       if ( !(zaxistype == ZAXIS_SURFACE && levelsize == 1 && !(fabs(levels[0]) > 0)) )
@@ -469,7 +469,7 @@ void printZaxisInfo(int vlistID)
               fprintf(stdout, "number = %d\n", number);
             }
 
-          char uuidOfVGrid[17];
+          unsigned char uuidOfVGrid[CDI_UUID_SIZE];
           zaxisInqUUID(zaxisID, uuidOfVGrid);
           if ( uuidOfVGrid[0] != 0 )
             {
diff --git a/src/pstream.c b/src/pstream.c
index 3c616f2..bdaaebe 100644
--- a/src/pstream.c
+++ b/src/pstream.c
@@ -542,7 +542,7 @@ int pstreamOpenRead(const argument_t *argument)
 	pthread_mutex_lock(&streamOpenReadMutex);
 #endif
       fileID = streamOpenRead(filename);
-      if ( fileID < 0 ) cdiError(fileID, "Open failed on >%s<", filename);
+      if ( fileID < 0 ) cdiOpenError(fileID, "Open failed on >%s<", filename);
 
       if ( cdoDefaultFileType == CDI_UNDEFID )
 	cdoDefaultFileType = streamInqFiletype(fileID);
@@ -563,7 +563,7 @@ int pstreamOpenRead(const argument_t *argument)
       pstreamptr->fileID = fileID;
     }
 
-  if ( pstreamID < 0 ) cdiError(pstreamID, "Open failed on %s", argument->args);
+  if ( pstreamID < 0 ) cdiOpenError(pstreamID, "Open failed on >%s<", argument->args);
   
   return (pstreamID);
 }
@@ -691,7 +691,7 @@ int pstreamOpenWrite(const argument_t *argument, int filetype)
 	pthread_mutex_unlock(&streamOpenWriteMutex);
 #endif
       if ( processNums() == 1 && ompNumThreads == 1 ) timer_stop(timer_write);
-      if ( fileID < 0 ) cdiError(fileID, "Open failed on %s", argument->args);
+      if ( fileID < 0 ) cdiOpenError(fileID, "Open failed on >%s<", argument->args);
 
       cdoDefHistory(fileID, commandLine());
 
@@ -783,7 +783,7 @@ int pstreamOpenAppend(const argument_t *argument)
 	pthread_mutex_unlock(&streamOpenReadMutex);
 #endif
       if ( processNums() == 1 && ompNumThreads == 1 ) timer_stop(timer_write);
-      if ( fileID < 0 ) cdiError(fileID, "Open failed on %s", argument->args);
+      if ( fileID < 0 ) cdiOpenError(fileID, "Open failed on >%s<", argument->args);
       /*
       cdoInqHistory(fileID);
       cdoDefHistory(fileID, commandLine());
@@ -971,7 +971,7 @@ int pstreamInqVlist(int pstreamID)
   return (vlistID);
 }
 
-
+static
 const char *cdoComment(void)
 {
   static char comment[256];
@@ -986,6 +986,7 @@ const char *cdoComment(void)
       size = strlen(CDO_Version);
 
       strncat(comment, CDO_Version, size);
+      comment[size] = 0;
     }
 
   return (comment);
@@ -1412,7 +1413,7 @@ int pstreamInqTimestep(int pstreamID, int tsID)
 	  else
 	    pthread_mutex_unlock(&streamOpenReadMutex);
 #endif
-	  if ( fileID < 0 ) cdiError(fileID, "Open failed on >%s<", filename);
+	  if ( fileID < 0 ) cdiOpenError(fileID, "Open failed on >%s<", filename);
 
 	  free(pstreamptr->name);
 
@@ -1489,6 +1490,10 @@ void pstreamCopyRecord(int pstreamIDdest, int pstreamIDsrc)
 
   pstreamptr_dest = pstream_to_pointer(pstreamIDdest);
   pstreamptr_src  = pstream_to_pointer(pstreamIDsrc);
+
+  if ( pstreamptr_dest->ispipe || pstreamptr_src->ispipe )
+    cdoAbort("This operator can't be combined with other operators!");
+
   /*
 #if defined(HAVE_LIBPTHREAD)
   if ( pstreamptr_dest->ispipe || pstreamptr_src->ispipe )
diff --git a/src/remap_conserv.c b/src/remap_conserv.c
index 04db320..8b874de 100644
--- a/src/remap_conserv.c
+++ b/src/remap_conserv.c
@@ -398,12 +398,24 @@ void cdo_compute_concave_overlap_areas(unsigned N,
   if ( target_node_x == NULL || target_node_y == NULL )
     cdoAbort("Internal problem (cdo_compute_concave_overlap_areas): missing target point coordinates!");
   */
+  /*
   struct grid_cell target_partial_cell =
     {.coordinates_x   = (double[3]){-1, -1, -1},
      .coordinates_y   = (double[3]){-1, -1, -1},
      .coordinates_xyz = (double[3*3]){-1, -1, -1},
      .edge_type       = (enum edge_type[3]) {GREAT_CIRCLE, GREAT_CIRCLE, GREAT_CIRCLE},
      .num_corners     = 3};
+  */
+  double coordinates_x[3] = {-1, -1, -1};
+  double coordinates_y[3] = {-1, -1, -1};
+  double coordinates_xyz[9] = {-1, -1, -1};
+  enum edge_type edge_types[3] = {GREAT_CIRCLE, GREAT_CIRCLE, GREAT_CIRCLE};
+  struct grid_cell target_partial_cell =
+    {.coordinates_x   = coordinates_x,
+     .coordinates_y   = coordinates_y,
+     .coordinates_xyz = coordinates_xyz,
+     .edge_type       = edge_types,
+     .num_corners     = 3};
 
   /* Do the clipping and get the cell for the overlapping area */
 
@@ -742,7 +754,7 @@ void remap_weights_conserv(remapgrid_t *src_grid, remapgrid_t *tgt_grid, remapva
   int sum_srch_cells2 = 0;
 
 #if defined(_OPENMP)
-#pragma omp parallel for default(none) \
+#pragma omp parallel for default(shared) \
   shared(ompNumThreads, cdoTimer, lyac, nbins, num_wts, nx, src_remap_grid_type, tgt_remap_grid_type, src_grid_bound_box,	\
 	 src_edge_type, tgt_edge_type, partial_areas2, partial_weights2,  \
          rv, cdoVerbose, max_srch_cells2, tgt_num_cell_corners, target_cell_type, \
@@ -807,7 +819,7 @@ void remap_weights_conserv(remapgrid_t *src_grid, remapgrid_t *tgt_grid, remapva
 					  tgt_cell_bound_box_r, src_grid->cell_bound_box, src_grid_size, srch_add);
 	}
 
-      sum_srch_cells += num_srch_cells;
+      if ( 0 && cdoVerbose ) sum_srch_cells += num_srch_cells;
 
       if ( 0 && cdoVerbose )
 	printf("tgt_grid_add %ld  num_srch_cells %ld\n", tgt_grid_add, num_srch_cells);
@@ -996,7 +1008,7 @@ void remap_weights_conserv(remapgrid_t *src_grid, remapgrid_t *tgt_grid, remapva
 	    }
 	}
 
-      sum_srch_cells2 += num_weights;
+      if ( 0 && cdoVerbose ) sum_srch_cells2 += num_weights;
 
       for ( n = 0; n < num_weights; ++n )
 	partial_weights[n] = partial_areas[n] / tgt_area;
diff --git a/src/remap_conserv_scrip.c b/src/remap_conserv_scrip.c
index 3a7018d..8a6bd7a 100644
--- a/src/remap_conserv_scrip.c
+++ b/src/remap_conserv_scrip.c
@@ -1379,7 +1379,7 @@ void scrip_remap_weights_conserv(remapgrid_t *src_grid, remapgrid_t *tgt_grid, r
   if ( cdoTimer ) timer_start(timer_remap_con_l1);
 
 #if defined(_OPENMP)
-#pragma omp parallel for default(none) \
+#pragma omp parallel for default(shared) \
   shared(ompNumThreads, cdoTimer, nbins, num_wts, src_centroid_lon, src_centroid_lat, \
          remap_store_link_fast, grid_store, link_add1, link_add2, rv, cdoVerbose, max_subseg, \
 	 srch_corner_lat2, srch_corner_lon2, max_srch_cells2, 		\
@@ -1604,7 +1604,7 @@ void scrip_remap_weights_conserv(remapgrid_t *src_grid, remapgrid_t *tgt_grid, r
   findex = 0;
 
 #if defined(_OPENMP)
-#pragma omp parallel for default(none) \
+#pragma omp parallel for default(shared) \
   shared(ompNumThreads, cdoTimer, nbins, num_wts, tgt_centroid_lon, tgt_centroid_lat, \
          remap_store_link_fast, grid_store, link_add1, link_add2, rv, cdoVerbose, max_subseg, \
 	 srch_corner_lat2, srch_corner_lon2, max_srch_cells2, 		\
diff --git a/src/remap_search_latbins.c b/src/remap_search_latbins.c
index de16f94..381f170 100644
--- a/src/remap_search_latbins.c
+++ b/src/remap_search_latbins.c
@@ -1,6 +1,10 @@
 #include "cdo.h"
 #include "remap.h"
-
+/*
+#if defined(_OPENMP)
+#  include <omp.h>
+#endif
+*/
 
 void calc_bin_addr(long gridsize, long nbins, const restr_t* restrict bin_lats, const restr_t* restrict cell_bound_box, int* restrict bin_addr)
 {
@@ -14,11 +18,6 @@ void calc_bin_addr(long gridsize, long nbins, const restr_t* restrict bin_lats,
       bin_addr[n2+1] = 0;
     }
 
-#if defined(_OPENMP)
-#pragma omp parallel for default(none) \
-  private(n, n2, nele4, cell_bound_box_lat1, cell_bound_box_lat2)  \
-  shared(gridsize, nbins, bin_lats, cell_bound_box, bin_addr)
-#endif
   for ( nele = 0; nele < gridsize; ++nele )
     {
       nele4 = nele<<2;
@@ -30,49 +29,80 @@ void calc_bin_addr(long gridsize, long nbins, const restr_t* restrict bin_lats,
 	  if ( cell_bound_box_lat1 <= bin_lats[n2+1] &&
 	       cell_bound_box_lat2 >= bin_lats[n2  ] )
 	    {
-	      /*
-#if defined(_OPENMP)
-	      if ( nele < bin_addr[n2  ] || nele > bin_addr[n2+1] )
-#pragma omp critical
-#endif
-	      */
-		{
-		  bin_addr[n2  ] = MIN(nele, bin_addr[n2  ]);
-		  bin_addr[n2+1] = MAX(nele, bin_addr[n2+1]);
-		}
+	      bin_addr[n2  ] = MIN(nele, bin_addr[n2  ]);
+	      bin_addr[n2+1] = MAX(nele, bin_addr[n2+1]);
 	    }
 	}
     }
 }
+
 /*
-static
-void calc_bin_addr(long gridsize, long nbins, const restr_t* restrict bin_lats, const restr_t* restrict cell_bound_box, int* restrict bin_addr)
+void calc_bin_addr_omp(long gridsize, long nbins, const restr_t* restrict bin_lats, const restr_t* restrict cell_bound_box, int* restrict bin_addr)
 {
   long n, n2, nele, nele4;
+  restr_t cell_bound_box_lat1, cell_bound_box_lat2;
+#if defined(_OPENMP)
+  extern int ompNumThreads;
+  restr_t (*omp_bin_addr)[ompNumThreads] = malloc(nbins*sizeof(*omp_bin_addr));
+
+  for ( int ompthID = 0; ompthID < ompNumThreads; ++ompthID )
+    for ( n = 0; n < nbins; ++n )
+      {
+	n2 = n<<1;
+	omp_bin_addr[ompthID][n2  ] = gridsize;
+	omp_bin_addr[ompthID][n2+1] = 0;
+      }
+#endif
 
   for ( n = 0; n < nbins; ++n )
     {
       n2 = n<<1;
       bin_addr[n2  ] = gridsize;
       bin_addr[n2+1] = 0;
+    }
 
 #if defined(_OPENMP)
 #pragma omp parallel for default(none) \
-  private(nele4)	\
-  shared(n2, gridsize, bin_lats, cell_bound_box, bin_addr)
+  private(n, n2, nele4, cell_bound_box_lat1, cell_bound_box_lat2)  \
+  shared(gridsize, nbins, bin_lats, cell_bound_box, omp_bin_addr)
+#endif
+  for ( nele = 0; nele < gridsize; ++nele )
+    {
+#if defined(_OPENMP)
+      int ompthID = omp_get_thread_num();
 #endif
-      for ( nele = 0; nele < gridsize; ++nele )
+      nele4 = nele<<2;
+      cell_bound_box_lat1 = cell_bound_box[nele4  ];
+      cell_bound_box_lat2 = cell_bound_box[nele4+1];
+      for ( n = 0; n < nbins; ++n )
 	{
-	  nele4 = nele<<2;
-
-	  if ( cell_bound_box[nele4  ] <= bin_lats[n2+1] &&
-	       cell_bound_box[nele4+1] >= bin_lats[n2  ] )
+	  n2 = n<<1;
+	  if ( cell_bound_box_lat1 <= bin_lats[n2+1] &&
+	       cell_bound_box_lat2 >= bin_lats[n2  ] )
 	    {
+#if defined(_OPENMP)
+	      omp_bin_addr[ompthID][n2  ] = MIN(nele, omp_bin_addr[ompthID][n2  ]);
+	      omp_bin_addr[ompthID][n2+1] = MAX(nele, omp_bin_addr[ompthID][n2+1]);
+#else
 	      bin_addr[n2  ] = MIN(nele, bin_addr[n2  ]);
 	      bin_addr[n2+1] = MAX(nele, bin_addr[n2+1]);
+#endif
 	    }
 	}
     }
+#if defined(_OPENMP)
+  for ( int ompthID = 0; ompthID < ompNumThreads; ++ompthID )
+    {
+      for ( n = 0; n < nbins; ++n )
+	{
+	  n2 = n<<1;
+	  bin_addr[n2  ] = MIN(omp_bin_addr[ompthID][n2  ], bin_addr[n2  ]);
+	  bin_addr[n2+1] = MAX(omp_bin_addr[ompthID][n2+1], bin_addr[n2+1]);
+	}
+    }
+
+  free(omp_bin_addr);
+#endif
 }
 */
 
diff --git a/src/remaplib.c b/src/remaplib.c
index 15d7671..f5545bd 100644
--- a/src/remaplib.c
+++ b/src/remaplib.c
@@ -705,6 +705,14 @@ void remap_define_grid(int map_type, int gridID, remapgrid_t *grid)
 #endif
   for ( i = 0; i < gridsize; ++i ) grid->mask[i] = TRUE;
 
+  if ( gridInqMask(gridID, NULL) )
+    {
+      int *mask = (int*) malloc(gridsize*sizeof(int));
+      gridInqMask(gridID, mask);
+      for ( i = 0; i < gridsize; ++i )
+	if ( mask[i] == 0 ) grid->mask[i] = FALSE;
+      free(mask);
+    }
 
   if ( remap_write_remap == FALSE && grid->remap_grid_type == REMAP_GRID_TYPE_REG2D ) return;
 
diff --git a/test/Arith.test.in b/test/Arith.test.in
new file mode 100644
index 0000000..674983a
--- /dev/null
+++ b/test/Arith.test.in
@@ -0,0 +1,80 @@
+#! @SHELL@
+echo 1..4 # Number of tests to be executed.
+#
+test -n "$CDO"      || CDO=cdo
+test -n "$DATAPATH" || DATAPATH=./data
+#
+CDOOUT=cout
+CDOERR=cerr
+FORMAT="-f srv -b 32"
+STATS="add sub mul div"
+#
+IFILE=$DATAPATH/pl_data
+NTEST=1
+#
+for STAT in $STATS; do
+  RSTAT=0
+
+  OFILE=stat${STAT}_res
+
+  for VAR in -777 -1 0 1 777; do
+    VAL=1
+    CFILE=constval
+    $CDO -f srv -b 64 const,$VAL,$IFILE $CFILE
+
+# stat var const
+
+    CDOTEST="$STAT"
+    CDOCOMMAND="$CDO $FORMAT ${STAT} $IFILE $CFILE $OFILE"
+
+    echo "Running test: $NTEST"
+    echo "$CDOCOMMAND"
+
+    $CDOCOMMAND
+    test $? -eq 0 || let RSTAT+=1
+
+# stat,const var
+
+    OFILE2=stat${STAT}c_res
+    CDOCOMMAND="$CDO $FORMAT ${STAT}c,$VAL $IFILE $OFILE2"
+
+    $CDOCOMMAND
+    test $? -eq 0 || let RSTAT+=1
+
+    $CDO diff $OFILE $OFILE2 > $CDOOUT 2> $CDOERR
+    test $? -eq 0 || let RSTAT+=1
+    test -s $CDOOUT && let RSTAT+=1
+    cat $CDOOUT $CDOERR
+
+# expr,instr var
+
+    OP=""
+    if [ "$STAT" = add ] ; then OP='+' ; fi
+    if [ "$STAT" = sub ] ; then OP='-' ; fi
+    if [ "$STAT" = mul ] ; then OP='*' ; fi
+    if [ "$STAT" = div ] ; then OP='/' ; fi
+    OFILE3=expr${STAT}_res
+    INSTR="var130=var130${OP}${VAL};var152=var152${OP}${VAL};var129=var129${OP}${VAL};"
+    echo $INSTR
+    CDOCOMMAND="$CDO $FORMAT expr,$INSTR $IFILE $OFILE3"
+
+    $CDOCOMMAND
+    test $? -eq 0 || let RSTAT+=1
+
+    $CDO diff $OFILE $OFILE3 > $CDOOUT 2> $CDOERR
+    test $? -eq 0 || let RSTAT+=1
+    test -s $CDOOUT && let RSTAT+=1
+    cat $CDOOUT $CDOERR
+
+    rm -f $OFILE $OFILE2 $OFILE3 $CFILE
+  done
+
+  test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST"
+  test $RSTAT -eq 0 || echo "not ok $NTEST - $CDOTEST"
+
+  let NTEST+=1
+done
+#
+rm -f $CDOOUT $CDOERR
+#
+exit 0
diff --git a/test/Read_netcdf.test.in b/test/Copy_netcdf.test.in
similarity index 63%
copy from test/Read_netcdf.test.in
copy to test/Copy_netcdf.test.in
index 33cd888..98b4525 100644
--- a/test/Read_netcdf.test.in
+++ b/test/Copy_netcdf.test.in
@@ -1,5 +1,5 @@
 #! @SHELL@
-echo 1..2 # Number of tests to be executed.
+echo 1..1 # Number of tests to be executed.
 #
 test -n "$CDO"      || CDO=cdo
 test -n "$DATAPATH" || DATAPATH=./data
@@ -9,27 +9,25 @@ CDOERR=cerr
 #
 NTEST=1
 #
-for OPERATOR in "sinfon" "infon"; do
-  for FILE in "testfile01"; do
+for OPERATOR in copy; do
+  for FILE in testfile01c.nc; do
     RSTAT=0
-    IFILE=$DATAPATH/netcdf_${FILE}.nc
-    OFILE=netcdf_${FILE}_${OPERATOR}
-    RFILE=$DATAPATH/${OFILE}_ref
+    IFILE=$DATAPATH/${FILE}
+    OFILE=${OPERATOR}_${FILE}
 
     CDOTEST="$OPERATOR $FILE"
-    CDOCOMMAND="$CDO $OPERATOR $IFILE"
+    CDOCOMMAND="$CDO $OPERATOR $IFILE $OFILE"
 
     if [ "@ENABLE_NETCDF@" = yes ] ; then
       echo "Running test: $NTEST"
       echo "$CDOCOMMAND"
 
-      $CDOCOMMAND > $OFILE
+      $CDOCOMMAND
       test $? -eq 0 || let RSTAT+=1
 
-      diff $OFILE $RFILE > $CDOOUT 2> $CDOERR
+      $CDO diff $IFILE $OFILE > $CDOOUT 2> $CDOERR
       test $? -eq 0 || let RSTAT+=1
-
-      test -s $CDOERR && let RSTAT+=1
+      test -s $CDOOUT && let RSTAT+=1
       cat $CDOOUT $CDOERR
 
       test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST"
diff --git a/test/Makefile.am b/test/Makefile.am
index 15f54b6..bdc5f6b 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -5,8 +5,8 @@ export
 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
                   $(top_srcdir)/config/tap-driver.sh
 
-TESTS = Read_netcdf.test Cat.test Gridarea.test Detrend.test Genweights.test Remap.test \
-        Select.test Spectral.test Timstat.test Vertint.test
+TESTS = Read_grib.test Read_netcdf.test Copy_netcdf.test Cat.test Gridarea.test Detrend.test Genweights.test Remap.test \
+        Select.test Spectral.test Timstat.test Vertint.test Arith.test
 
 #        $(top_srcdir)/test/test_Remap.sh \
 #       $(top_srcdir)/test/test_info.py
diff --git a/test/Makefile.in b/test/Makefile.in
index 3091874..d3b4c12 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -79,12 +79,13 @@ build_triplet = @build@
 host_triplet = @host@
 subdir = test
 DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
-	$(top_srcdir)/config/mkinstalldirs \
-	$(srcdir)/Read_netcdf.test.in $(srcdir)/Cat.test.in \
-	$(srcdir)/Gridarea.test.in $(srcdir)/Genweights.test.in \
-	$(srcdir)/Remap.test.in $(srcdir)/Select.test.in \
-	$(srcdir)/Spectral.test.in $(srcdir)/Timstat.test.in \
-	$(srcdir)/Vertint.test.in $(srcdir)/Detrend.test.in README
+	$(top_srcdir)/config/mkinstalldirs $(srcdir)/Read_grib.test.in \
+	$(srcdir)/Read_netcdf.test.in $(srcdir)/Copy_netcdf.test.in \
+	$(srcdir)/Cat.test.in $(srcdir)/Gridarea.test.in \
+	$(srcdir)/Genweights.test.in $(srcdir)/Remap.test.in \
+	$(srcdir)/Select.test.in $(srcdir)/Spectral.test.in \
+	$(srcdir)/Timstat.test.in $(srcdir)/Vertint.test.in \
+	$(srcdir)/Detrend.test.in $(srcdir)/Arith.test.in README
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/acx_options.m4 \
 	$(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/libtool.m4 \
@@ -95,9 +96,10 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
 	$(ACLOCAL_M4)
 mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
 CONFIG_HEADER = $(top_builddir)/src/config.h
-CONFIG_CLEAN_FILES = Read_netcdf.test Cat.test Gridarea.test \
-	Genweights.test Remap.test Select.test Spectral.test \
-	Timstat.test Vertint.test Detrend.test
+CONFIG_CLEAN_FILES = Read_grib.test Read_netcdf.test Copy_netcdf.test \
+	Cat.test Gridarea.test Genweights.test Remap.test Select.test \
+	Spectral.test Timstat.test Vertint.test Detrend.test \
+	Arith.test
 CONFIG_CLEAN_VPATH_FILES =
 AM_V_P = $(am__v_P_ at AM_V@)
 am__v_P_ = $(am__v_P_ at AM_DEFAULT_V@)
@@ -495,8 +497,8 @@ CLEANFILES = `ls *.pyc`
 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
                   $(top_srcdir)/config/tap-driver.sh
 
-TESTS = Read_netcdf.test Cat.test Gridarea.test Detrend.test Genweights.test Remap.test \
-        Select.test Spectral.test Timstat.test Vertint.test
+TESTS = Read_grib.test Read_netcdf.test Copy_netcdf.test Cat.test Gridarea.test Detrend.test Genweights.test Remap.test \
+        Select.test Spectral.test Timstat.test Vertint.test Arith.test
 
 
 #        $(top_srcdir)/test/test_Remap.sh \
@@ -545,8 +547,12 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
 $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 $(am__aclocal_m4_deps):
+Read_grib.test: $(top_builddir)/config.status $(srcdir)/Read_grib.test.in
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
 Read_netcdf.test: $(top_builddir)/config.status $(srcdir)/Read_netcdf.test.in
 	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
+Copy_netcdf.test: $(top_builddir)/config.status $(srcdir)/Copy_netcdf.test.in
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
 Cat.test: $(top_builddir)/config.status $(srcdir)/Cat.test.in
 	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
 Gridarea.test: $(top_builddir)/config.status $(srcdir)/Gridarea.test.in
@@ -565,6 +571,8 @@ Vertint.test: $(top_builddir)/config.status $(srcdir)/Vertint.test.in
 	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
 Detrend.test: $(top_builddir)/config.status $(srcdir)/Detrend.test.in
 	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
+Arith.test: $(top_builddir)/config.status $(srcdir)/Arith.test.in
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
 
 mostlyclean-libtool:
 	-rm -f *.lo
diff --git a/test/Read_netcdf.test.in b/test/Read_grib.test.in
similarity index 69%
copy from test/Read_netcdf.test.in
copy to test/Read_grib.test.in
index 33cd888..2387e05 100644
--- a/test/Read_netcdf.test.in
+++ b/test/Read_grib.test.in
@@ -1,5 +1,5 @@
 #! @SHELL@
-echo 1..2 # Number of tests to be executed.
+echo 1..4 # Number of tests to be executed.
 #
 test -n "$CDO"      || CDO=cdo
 test -n "$DATAPATH" || DATAPATH=./data
@@ -9,17 +9,17 @@ CDOERR=cerr
 #
 NTEST=1
 #
-for OPERATOR in "sinfon" "infon"; do
-  for FILE in "testfile01"; do
+for OPERATOR in sinfo info; do
+  for FILE in testfile01 testfile02; do
     RSTAT=0
-    IFILE=$DATAPATH/netcdf_${FILE}.nc
-    OFILE=netcdf_${FILE}_${OPERATOR}
+    IFILE=$DATAPATH/grib_${FILE}.grb
+    OFILE=grib_${FILE}_${OPERATOR}
     RFILE=$DATAPATH/${OFILE}_ref
 
     CDOTEST="$OPERATOR $FILE"
     CDOCOMMAND="$CDO $OPERATOR $IFILE"
 
-    if [ "@ENABLE_NETCDF@" = yes ] ; then
+    if [ "@ENABLE_GRIB@" = yes ] ; then
       echo "Running test: $NTEST"
       echo "$CDOCOMMAND"
 
@@ -35,7 +35,7 @@ for OPERATOR in "sinfon" "infon"; do
       test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST"
       test $RSTAT -eq 0 || echo "not ok $NTEST - $CDOTEST"
     else
-      test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST # SKIP netCDF not enabled"
+      test $RSTAT -eq 0 && echo "ok $NTEST - $CDOTEST # SKIP GRIB not enabled"
     fi
 
     let NTEST+=1
diff --git a/test/Read_netcdf.test.in b/test/Read_netcdf.test.in
index 33cd888..9867367 100644
--- a/test/Read_netcdf.test.in
+++ b/test/Read_netcdf.test.in
@@ -1,5 +1,5 @@
 #! @SHELL@
-echo 1..2 # Number of tests to be executed.
+echo 1..4 # Number of tests to be executed.
 #
 test -n "$CDO"      || CDO=cdo
 test -n "$DATAPATH" || DATAPATH=./data
@@ -9,8 +9,8 @@ CDOERR=cerr
 #
 NTEST=1
 #
-for OPERATOR in "sinfon" "infon"; do
-  for FILE in "testfile01"; do
+for OPERATOR in sinfon infon; do
+  for FILE in testfile01 testfile02; do
     RSTAT=0
     IFILE=$DATAPATH/netcdf_${FILE}.nc
     OFILE=netcdf_${FILE}_${OPERATOR}
diff --git a/test/data/._netcdf_testfile01.nc b/test/data/._netcdf_testfile01.nc
index 98ec9bb..ea54672 100644
Binary files a/test/data/._netcdf_testfile01.nc and b/test/data/._netcdf_testfile01.nc differ
diff --git a/test/data/Makefile.am b/test/data/Makefile.am
index 0add863..60fc9d4 100644
--- a/test/data/Makefile.am
+++ b/test/data/Makefile.am
@@ -1,7 +1,8 @@
-INPUTDATA = ts_mm_5years hl_l19.grb t21_geosp_tsurf.grb bathy4.grb pl_data.grb detrend_data \
-            netcdf_testfile01.nc
+INPUTDATA = ts_mm_5years hl_l19.grb t21_geosp_tsurf.grb bathy4.grb pl_data pl_data.grb detrend_data \
+            grib_testfile01.grb grib_testfile02.grb netcdf_testfile01.nc netcdf_testfile02.nc testfile01c.nc
 
-NETCDF_REF   = netcdf_testfile01_sinfon_ref netcdf_testfile01_infon_ref
+GRIB_REF     = grib_testfile01_sinfo_ref grib_testfile01_info_ref grib_testfile02_sinfo_ref grib_testfile02_info_ref
+NETCDF_REF   = netcdf_testfile01_sinfon_ref netcdf_testfile01_infon_ref netcdf_testfile02_sinfon_ref netcdf_testfile02_infon_ref
 TIMSTAT_REF  = timmin_ref timmax_ref timsum_ref timavg_ref timmean_ref timstd_ref timstd1_ref timvar_ref timvar1_ref
 SPECTRAL_REF = sp2gp_ref sp2gpl_ref gp2sp_ref gp2spl_ref
 VERTINT_REF  = ml2pl_ref
@@ -10,4 +11,4 @@ REMAP_REF    = n16_bic_ref n16_bil_ref n16_con_ref n16_ycon_ref n16_laf_ref n16_
 SELECT_REF   = select1_ref select2_ref select3_ref select4_ref select5_ref
 DETREND_REF  = detrend_ref
 
-EXTRA_DIST = $(INPUTDATA) $(NETCDF_REF) $(TIMSTAT_REF) $(SPECTRAL_REF) $(VERTINT_REF) $(REMAP_REF) $(SELECT_REF) $(DETREND_REF)
+EXTRA_DIST = $(INPUTDATA) $(GRIB_REF) $(NETCDF_REF) $(TIMSTAT_REF) $(SPECTRAL_REF) $(VERTINT_REF) $(REMAP_REF) $(SELECT_REF) $(DETREND_REF)
diff --git a/test/data/Makefile.in b/test/data/Makefile.in
index 08dd8b4..4065b62 100644
--- a/test/data/Makefile.in
+++ b/test/data/Makefile.in
@@ -281,10 +281,11 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-INPUTDATA = ts_mm_5years hl_l19.grb t21_geosp_tsurf.grb bathy4.grb pl_data.grb detrend_data \
-            netcdf_testfile01.nc
+INPUTDATA = ts_mm_5years hl_l19.grb t21_geosp_tsurf.grb bathy4.grb pl_data pl_data.grb detrend_data \
+            grib_testfile01.grb grib_testfile02.grb netcdf_testfile01.nc netcdf_testfile02.nc testfile01c.nc
 
-NETCDF_REF = netcdf_testfile01_sinfon_ref netcdf_testfile01_infon_ref
+GRIB_REF = grib_testfile01_sinfo_ref grib_testfile01_info_ref grib_testfile02_sinfo_ref grib_testfile02_info_ref
+NETCDF_REF = netcdf_testfile01_sinfon_ref netcdf_testfile01_infon_ref netcdf_testfile02_sinfon_ref netcdf_testfile02_infon_ref
 TIMSTAT_REF = timmin_ref timmax_ref timsum_ref timavg_ref timmean_ref timstd_ref timstd1_ref timvar_ref timvar1_ref
 SPECTRAL_REF = sp2gp_ref sp2gpl_ref gp2sp_ref gp2spl_ref
 VERTINT_REF = ml2pl_ref
@@ -293,7 +294,7 @@ REMAP_REF = n16_bic_ref n16_bil_ref n16_con_ref n16_ycon_ref n16_laf_ref n16_nn_
 
 SELECT_REF = select1_ref select2_ref select3_ref select4_ref select5_ref
 DETREND_REF = detrend_ref
-EXTRA_DIST = $(INPUTDATA) $(NETCDF_REF) $(TIMSTAT_REF) $(SPECTRAL_REF) $(VERTINT_REF) $(REMAP_REF) $(SELECT_REF) $(DETREND_REF)
+EXTRA_DIST = $(INPUTDATA) $(GRIB_REF) $(NETCDF_REF) $(TIMSTAT_REF) $(SPECTRAL_REF) $(VERTINT_REF) $(REMAP_REF) $(SELECT_REF) $(DETREND_REF)
 all: all-am
 
 .SUFFIXES:
diff --git a/test/data/grib_testfile01.grb b/test/data/grib_testfile01.grb
new file mode 100644
index 0000000..49f1b12
Binary files /dev/null and b/test/data/grib_testfile01.grb differ
diff --git a/test/data/grib_testfile01_info_ref b/test/data/grib_testfile01_info_ref
new file mode 100644
index 0000000..87e5eaa
--- /dev/null
+++ b/test/data/grib_testfile01_info_ref
@@ -0,0 +1,13 @@
+    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter ID
+     1 : 0000-01-00 00:00:00       0     2592       0 :     -48.800      3.1647      32.001 : 1             
+     2 : 0000-02-00 00:00:00       0     2592       0 :     -48.700      2.4530      30.800 : 1             
+     3 : 0000-03-00 00:00:00       0     2592       0 :     -62.300      2.2681      30.899 : 1             
+     4 : 0000-04-00 00:00:00       0     2592       0 :     -68.500      3.5152      32.699 : 1             
+     5 : 0000-05-00 00:00:00       0     2592       0 :     -69.200      5.4965      34.101 : 1             
+     6 : 0000-06-00 00:00:00       0     2592       0 :     -69.000      6.9265      35.199 : 1             
+     7 : 0000-07-00 00:00:00       0     2592       0 :     -70.300      7.2876      35.700 : 1             
+     8 : 0000-08-00 00:00:00       0     2592       0 :     -70.200      6.9544      34.999 : 1             
+     9 : 0000-09-00 00:00:00       0     2592       0 :     -68.900      5.8636      32.901 : 1             
+    10 : 0000-10-00 00:00:00       0     2592       0 :     -60.800      4.6208      30.700 : 1             
+    11 : 0000-11-00 00:00:00       0     2592       0 :     -47.000      3.8041      31.000 : 1             
+    12 : 0000-12-00 00:00:00       0     2592       0 :     -46.300      3.5452      31.800 : 1             
diff --git a/test/data/grib_testfile01_sinfo_ref b/test/data/grib_testfile01_sinfo_ref
new file mode 100644
index 0000000..47b7be9
--- /dev/null
+++ b/test/data/grib_testfile01_sinfo_ref
@@ -0,0 +1,14 @@
+   File format : GRIB
+    -1 : Institut Source   Ttype    Levels Num    Points Num Dtype : Parameter ID
+     1 : unknown  unknown  instant       1   1      2592   1  P16  : 1             
+   Grid coordinates :
+     1 : lonlat                   : points=2592 (72x36)
+                              lon : -177.5 to 177.5 by 5 degrees_east  circular
+                              lat : 87.5 to -87.5 by -5 degrees_north
+   Vertical coordinates :
+     1 : surface                  : levels=1
+   Time coordinate :  unlimited steps
+  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
+  0000-01-00 00:00:00  0000-02-00 00:00:00  0000-03-00 00:00:00  0000-04-00 00:00:00
+  0000-05-00 00:00:00  0000-06-00 00:00:00  0000-07-00 00:00:00  0000-08-00 00:00:00
+  0000-09-00 00:00:00  0000-10-00 00:00:00  0000-11-00 00:00:00  0000-12-00 00:00:00
diff --git a/test/data/grib_testfile02.grb b/test/data/grib_testfile02.grb
new file mode 100644
index 0000000..2756002
Binary files /dev/null and b/test/data/grib_testfile02.grb differ
diff --git a/test/data/grib_testfile02_info_ref b/test/data/grib_testfile02_info_ref
new file mode 100644
index 0000000..c3a0eaf
--- /dev/null
+++ b/test/data/grib_testfile02_info_ref
@@ -0,0 +1,121 @@
+    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter ID
+     1 : 1900-01-01 12:00:00       0        1       0 :                  1.0000             : 1             
+     2 : 1900-02-01 12:00:00       0        1       0 :                  2.0000             : 1             
+     3 : 1900-03-01 12:00:00       0        1       0 :                  3.0000             : 1             
+     4 : 1900-04-01 12:00:00       0        1       0 :                  4.0000             : 1             
+     5 : 1900-05-01 12:00:00       0        1       0 :                  5.0000             : 1             
+     6 : 1900-06-01 12:00:00       0        1       0 :                  6.0000             : 1             
+     7 : 1900-07-01 12:00:00       0        1       0 :                  7.0000             : 1             
+     8 : 1900-08-01 12:00:00       0        1       0 :                  8.0000             : 1             
+     9 : 1900-09-01 12:00:00       0        1       0 :                  9.0000             : 1             
+    10 : 1900-10-01 12:00:00       0        1       0 :                  10.000             : 1             
+    11 : 1900-11-01 12:00:00       0        1       0 :                  11.000             : 1             
+    12 : 1900-12-01 12:00:00       0        1       0 :                  12.000             : 1             
+    13 : 1901-01-01 12:00:00       0        1       0 :                  13.000             : 1             
+    14 : 1901-02-01 12:00:00       0        1       0 :                  14.000             : 1             
+    15 : 1901-03-01 12:00:00       0        1       0 :                  15.000             : 1             
+    16 : 1901-04-01 12:00:00       0        1       0 :                  16.000             : 1             
+    17 : 1901-05-01 12:00:00       0        1       0 :                  17.000             : 1             
+    18 : 1901-06-01 12:00:00       0        1       0 :                  18.000             : 1             
+    19 : 1901-07-01 12:00:00       0        1       0 :                  19.000             : 1             
+    20 : 1901-08-01 12:00:00       0        1       0 :                  20.000             : 1             
+    21 : 1901-09-01 12:00:00       0        1       0 :                  21.000             : 1             
+    22 : 1901-10-01 12:00:00       0        1       0 :                  22.000             : 1             
+    23 : 1901-11-01 12:00:00       0        1       0 :                  23.000             : 1             
+    24 : 1901-12-01 12:00:00       0        1       0 :                  24.000             : 1             
+    25 : 1902-01-01 12:00:00       0        1       0 :                  25.000             : 1             
+    26 : 1902-02-01 12:00:00       0        1       0 :                  26.000             : 1             
+    27 : 1902-03-01 12:00:00       0        1       0 :                  27.000             : 1             
+    28 : 1902-04-01 12:00:00       0        1       0 :                  28.000             : 1             
+    29 : 1902-05-01 12:00:00       0        1       0 :                  29.000             : 1             
+    30 : 1902-06-01 12:00:00       0        1       0 :                  30.000             : 1             
+    31 : 1902-07-01 12:00:00       0        1       0 :                  31.000             : 1             
+    32 : 1902-08-01 12:00:00       0        1       0 :                  32.000             : 1             
+    33 : 1902-09-01 12:00:00       0        1       0 :                  33.000             : 1             
+    34 : 1902-10-01 12:00:00       0        1       0 :                  34.000             : 1             
+    35 : 1902-11-01 12:00:00       0        1       0 :                  35.000             : 1             
+    36 : 1902-12-01 12:00:00       0        1       0 :                  36.000             : 1             
+    37 : 1903-01-01 12:00:00       0        1       0 :                  37.000             : 1             
+    38 : 1903-02-01 12:00:00       0        1       0 :                  38.000             : 1             
+    39 : 1903-03-01 12:00:00       0        1       0 :                  39.000             : 1             
+    40 : 1903-04-01 12:00:00       0        1       0 :                  40.000             : 1             
+    41 : 1903-05-01 12:00:00       0        1       0 :                  41.000             : 1             
+    42 : 1903-06-01 12:00:00       0        1       0 :                  42.000             : 1             
+    43 : 1903-07-01 12:00:00       0        1       0 :                  43.000             : 1             
+    44 : 1903-08-01 12:00:00       0        1       0 :                  44.000             : 1             
+    45 : 1903-09-01 12:00:00       0        1       0 :                  45.000             : 1             
+    46 : 1903-10-01 12:00:00       0        1       0 :                  46.000             : 1             
+    47 : 1903-11-01 12:00:00       0        1       0 :                  47.000             : 1             
+    48 : 1903-12-01 12:00:00       0        1       0 :                  48.000             : 1             
+    49 : 1904-01-01 12:00:00       0        1       0 :                  49.000             : 1             
+    50 : 1904-02-01 12:00:00       0        1       0 :                  50.000             : 1             
+    51 : 1904-03-01 12:00:00       0        1       0 :                  51.000             : 1             
+    52 : 1904-04-01 12:00:00       0        1       0 :                  52.000             : 1             
+    53 : 1904-05-01 12:00:00       0        1       0 :                  53.000             : 1             
+    54 : 1904-06-01 12:00:00       0        1       0 :                  54.000             : 1             
+    55 : 1904-07-01 12:00:00       0        1       0 :                  55.000             : 1             
+    56 : 1904-08-01 12:00:00       0        1       0 :                  56.000             : 1             
+    57 : 1904-09-01 12:00:00       0        1       0 :                  57.000             : 1             
+    58 : 1904-10-01 12:00:00       0        1       0 :                  58.000             : 1             
+    59 : 1904-11-01 12:00:00       0        1       0 :                  59.000             : 1             
+    60 : 1904-12-01 12:00:00       0        1       0 :                  60.000             : 1             
+    61 : 1905-01-01 12:00:00       0        1       0 :                  61.000             : 1             
+    62 : 1905-02-01 12:00:00       0        1       0 :                  62.000             : 1             
+    63 : 1905-03-01 12:00:00       0        1       0 :                  63.000             : 1             
+    64 : 1905-04-01 12:00:00       0        1       0 :                  64.000             : 1             
+    65 : 1905-05-01 12:00:00       0        1       0 :                  65.000             : 1             
+    66 : 1905-06-01 12:00:00       0        1       0 :                  66.000             : 1             
+    67 : 1905-07-01 12:00:00       0        1       0 :                  67.000             : 1             
+    68 : 1905-08-01 12:00:00       0        1       0 :                  68.000             : 1             
+    69 : 1905-09-01 12:00:00       0        1       0 :                  69.000             : 1             
+    70 : 1905-10-01 12:00:00       0        1       0 :                  70.000             : 1             
+    71 : 1905-11-01 12:00:00       0        1       0 :                  71.000             : 1             
+    72 : 1905-12-01 12:00:00       0        1       0 :                  72.000             : 1             
+    73 : 1906-01-01 12:00:00       0        1       0 :                  73.000             : 1             
+    74 : 1906-02-01 12:00:00       0        1       0 :                  74.000             : 1             
+    75 : 1906-03-01 12:00:00       0        1       0 :                  75.000             : 1             
+    76 : 1906-04-01 12:00:00       0        1       0 :                  76.000             : 1             
+    77 : 1906-05-01 12:00:00       0        1       0 :                  77.000             : 1             
+    78 : 1906-06-01 12:00:00       0        1       0 :                  78.000             : 1             
+    79 : 1906-07-01 12:00:00       0        1       0 :                  79.000             : 1             
+    80 : 1906-08-01 12:00:00       0        1       0 :                  80.000             : 1             
+    81 : 1906-09-01 12:00:00       0        1       0 :                  81.000             : 1             
+    82 : 1906-10-01 12:00:00       0        1       0 :                  82.000             : 1             
+    83 : 1906-11-01 12:00:00       0        1       0 :                  83.000             : 1             
+    84 : 1906-12-01 12:00:00       0        1       0 :                  84.000             : 1             
+    85 : 1907-01-01 12:00:00       0        1       0 :                  85.000             : 1             
+    86 : 1907-02-01 12:00:00       0        1       0 :                  86.000             : 1             
+    87 : 1907-03-01 12:00:00       0        1       0 :                  87.000             : 1             
+    88 : 1907-04-01 12:00:00       0        1       0 :                  88.000             : 1             
+    89 : 1907-05-01 12:00:00       0        1       0 :                  89.000             : 1             
+    90 : 1907-06-01 12:00:00       0        1       0 :                  90.000             : 1             
+    91 : 1907-07-01 12:00:00       0        1       0 :                  91.000             : 1             
+    92 : 1907-08-01 12:00:00       0        1       0 :                  92.000             : 1             
+    93 : 1907-09-01 12:00:00       0        1       0 :                  93.000             : 1             
+    94 : 1907-10-01 12:00:00       0        1       0 :                  94.000             : 1             
+    95 : 1907-11-01 12:00:00       0        1       0 :                  95.000             : 1             
+    96 : 1907-12-01 12:00:00       0        1       0 :                  96.000             : 1             
+    97 : 1908-01-01 12:00:00       0        1       0 :                  97.000             : 1             
+    98 : 1908-02-01 12:00:00       0        1       0 :                  98.000             : 1             
+    99 : 1908-03-01 12:00:00       0        1       0 :                  99.000             : 1             
+   100 : 1908-04-01 12:00:00       0        1       0 :                  100.00             : 1             
+   101 : 1908-05-01 12:00:00       0        1       0 :                  101.00             : 1             
+   102 : 1908-06-01 12:00:00       0        1       0 :                  102.00             : 1             
+   103 : 1908-07-01 12:00:00       0        1       0 :                  103.00             : 1             
+   104 : 1908-08-01 12:00:00       0        1       0 :                  104.00             : 1             
+   105 : 1908-09-01 12:00:00       0        1       0 :                  105.00             : 1             
+   106 : 1908-10-01 12:00:00       0        1       0 :                  106.00             : 1             
+   107 : 1908-11-01 12:00:00       0        1       0 :                  107.00             : 1             
+   108 : 1908-12-01 12:00:00       0        1       0 :                  108.00             : 1             
+   109 : 1909-01-01 12:00:00       0        1       0 :                  109.00             : 1             
+   110 : 1909-02-01 12:00:00       0        1       0 :                  110.00             : 1             
+   111 : 1909-03-01 12:00:00       0        1       0 :                  111.00             : 1             
+   112 : 1909-04-01 12:00:00       0        1       0 :                  112.00             : 1             
+   113 : 1909-05-01 12:00:00       0        1       0 :                  113.00             : 1             
+   114 : 1909-06-01 12:00:00       0        1       0 :                  114.00             : 1             
+   115 : 1909-07-01 12:00:00       0        1       0 :                  115.00             : 1             
+   116 : 1909-08-01 12:00:00       0        1       0 :                  116.00             : 1             
+   117 : 1909-09-01 12:00:00       0        1       0 :                  117.00             : 1             
+   118 : 1909-10-01 12:00:00       0        1       0 :                  118.00             : 1             
+   119 : 1909-11-01 12:00:00       0        1       0 :                  119.00             : 1             
+   120 : 1909-12-01 12:00:00       0        1       0 :                  120.00             : 1             
diff --git a/test/data/grib_testfile02_sinfo_ref b/test/data/grib_testfile02_sinfo_ref
new file mode 100644
index 0000000..cebd3b5
--- /dev/null
+++ b/test/data/grib_testfile02_sinfo_ref
@@ -0,0 +1,42 @@
+   File format : GRIB
+    -1 : Institut Source   Ttype    Levels Num    Points Num Dtype : Parameter ID
+     1 : unknown  unknown  instant       1   1         1   1  P0   : 1             
+   Grid coordinates :
+     1 : lonlat                   : points=1 (1x1)
+                              lon : 0 degrees_east
+                              lat : 0 degrees_north
+   Vertical coordinates :
+     1 : surface                  : levels=1
+   Time coordinate :  unlimited steps
+     RefTime =  1900-01-01 12:00:00  Units = hours  Calendar = proleptic_gregorian
+  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
+  1900-01-01 12:00:00  1900-02-01 12:00:00  1900-03-01 12:00:00  1900-04-01 12:00:00
+  1900-05-01 12:00:00  1900-06-01 12:00:00  1900-07-01 12:00:00  1900-08-01 12:00:00
+  1900-09-01 12:00:00  1900-10-01 12:00:00  1900-11-01 12:00:00  1900-12-01 12:00:00
+  1901-01-01 12:00:00  1901-02-01 12:00:00  1901-03-01 12:00:00  1901-04-01 12:00:00
+  1901-05-01 12:00:00  1901-06-01 12:00:00  1901-07-01 12:00:00  1901-08-01 12:00:00
+  1901-09-01 12:00:00  1901-10-01 12:00:00  1901-11-01 12:00:00  1901-12-01 12:00:00
+  1902-01-01 12:00:00  1902-02-01 12:00:00  1902-03-01 12:00:00  1902-04-01 12:00:00
+  1902-05-01 12:00:00  1902-06-01 12:00:00  1902-07-01 12:00:00  1902-08-01 12:00:00
+  1902-09-01 12:00:00  1902-10-01 12:00:00  1902-11-01 12:00:00  1902-12-01 12:00:00
+  1903-01-01 12:00:00  1903-02-01 12:00:00  1903-03-01 12:00:00  1903-04-01 12:00:00
+  1903-05-01 12:00:00  1903-06-01 12:00:00  1903-07-01 12:00:00  1903-08-01 12:00:00
+  1903-09-01 12:00:00  1903-10-01 12:00:00  1903-11-01 12:00:00  1903-12-01 12:00:00
+  1904-01-01 12:00:00  1904-02-01 12:00:00  1904-03-01 12:00:00  1904-04-01 12:00:00
+  1904-05-01 12:00:00  1904-06-01 12:00:00  1904-07-01 12:00:00  1904-08-01 12:00:00
+  1904-09-01 12:00:00  1904-10-01 12:00:00  1904-11-01 12:00:00  1904-12-01 12:00:00
+  1905-01-01 12:00:00  1905-02-01 12:00:00  1905-03-01 12:00:00  1905-04-01 12:00:00
+  1905-05-01 12:00:00  1905-06-01 12:00:00  1905-07-01 12:00:00  1905-08-01 12:00:00
+  1905-09-01 12:00:00  1905-10-01 12:00:00  1905-11-01 12:00:00  1905-12-01 12:00:00
+  1906-01-01 12:00:00  1906-02-01 12:00:00  1906-03-01 12:00:00  1906-04-01 12:00:00
+  1906-05-01 12:00:00  1906-06-01 12:00:00  1906-07-01 12:00:00  1906-08-01 12:00:00
+  1906-09-01 12:00:00  1906-10-01 12:00:00  1906-11-01 12:00:00  1906-12-01 12:00:00
+  1907-01-01 12:00:00  1907-02-01 12:00:00  1907-03-01 12:00:00  1907-04-01 12:00:00
+  1907-05-01 12:00:00  1907-06-01 12:00:00  1907-07-01 12:00:00  1907-08-01 12:00:00
+  1907-09-01 12:00:00  1907-10-01 12:00:00  1907-11-01 12:00:00  1907-12-01 12:00:00
+  1908-01-01 12:00:00  1908-02-01 12:00:00  1908-03-01 12:00:00  1908-04-01 12:00:00
+  1908-05-01 12:00:00  1908-06-01 12:00:00  1908-07-01 12:00:00  1908-08-01 12:00:00
+  1908-09-01 12:00:00  1908-10-01 12:00:00  1908-11-01 12:00:00  1908-12-01 12:00:00
+  1909-01-01 12:00:00  1909-02-01 12:00:00  1909-03-01 12:00:00  1909-04-01 12:00:00
+  1909-05-01 12:00:00  1909-06-01 12:00:00  1909-07-01 12:00:00  1909-08-01 12:00:00
+  1909-09-01 12:00:00  1909-10-01 12:00:00  1909-11-01 12:00:00  1909-12-01 12:00:00
diff --git a/test/data/netcdf_testfile02.nc b/test/data/netcdf_testfile02.nc
new file mode 100644
index 0000000..77e6b0d
Binary files /dev/null and b/test/data/netcdf_testfile02.nc differ
diff --git a/test/data/netcdf_testfile02_infon_ref b/test/data/netcdf_testfile02_infon_ref
new file mode 100644
index 0000000..4ace55c
--- /dev/null
+++ b/test/data/netcdf_testfile02_infon_ref
@@ -0,0 +1,121 @@
+    -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter name
+     1 : 1900-01-01 12:00:00       0        1       0 :                  1.0000             : for           
+     2 : 1900-02-01 12:00:00       0        1       0 :                  2.0000             : for           
+     3 : 1900-03-01 12:00:00       0        1       0 :                  3.0000             : for           
+     4 : 1900-04-01 12:00:00       0        1       0 :                  4.0000             : for           
+     5 : 1900-05-01 12:00:00       0        1       0 :                  5.0000             : for           
+     6 : 1900-06-01 12:00:00       0        1       0 :                  6.0000             : for           
+     7 : 1900-07-01 12:00:00       0        1       0 :                  7.0000             : for           
+     8 : 1900-08-01 12:00:00       0        1       0 :                  8.0000             : for           
+     9 : 1900-09-01 12:00:00       0        1       0 :                  9.0000             : for           
+    10 : 1900-10-01 12:00:00       0        1       0 :                  10.000             : for           
+    11 : 1900-11-01 12:00:00       0        1       0 :                  11.000             : for           
+    12 : 1900-12-01 12:00:00       0        1       0 :                  12.000             : for           
+    13 : 1901-01-01 12:00:00       0        1       0 :                  13.000             : for           
+    14 : 1901-02-01 12:00:00       0        1       0 :                  14.000             : for           
+    15 : 1901-03-01 12:00:00       0        1       0 :                  15.000             : for           
+    16 : 1901-04-01 12:00:00       0        1       0 :                  16.000             : for           
+    17 : 1901-05-01 12:00:00       0        1       0 :                  17.000             : for           
+    18 : 1901-06-01 12:00:00       0        1       0 :                  18.000             : for           
+    19 : 1901-07-01 12:00:00       0        1       0 :                  19.000             : for           
+    20 : 1901-08-01 12:00:00       0        1       0 :                  20.000             : for           
+    21 : 1901-09-01 12:00:00       0        1       0 :                  21.000             : for           
+    22 : 1901-10-01 12:00:00       0        1       0 :                  22.000             : for           
+    23 : 1901-11-01 12:00:00       0        1       0 :                  23.000             : for           
+    24 : 1901-12-01 12:00:00       0        1       0 :                  24.000             : for           
+    25 : 1902-01-01 12:00:00       0        1       0 :                  25.000             : for           
+    26 : 1902-02-01 12:00:00       0        1       0 :                  26.000             : for           
+    27 : 1902-03-01 12:00:00       0        1       0 :                  27.000             : for           
+    28 : 1902-04-01 12:00:00       0        1       0 :                  28.000             : for           
+    29 : 1902-05-01 12:00:00       0        1       0 :                  29.000             : for           
+    30 : 1902-06-01 12:00:00       0        1       0 :                  30.000             : for           
+    31 : 1902-07-01 12:00:00       0        1       0 :                  31.000             : for           
+    32 : 1902-08-01 12:00:00       0        1       0 :                  32.000             : for           
+    33 : 1902-09-01 12:00:00       0        1       0 :                  33.000             : for           
+    34 : 1902-10-01 12:00:00       0        1       0 :                  34.000             : for           
+    35 : 1902-11-01 12:00:00       0        1       0 :                  35.000             : for           
+    36 : 1902-12-01 12:00:00       0        1       0 :                  36.000             : for           
+    37 : 1903-01-01 12:00:00       0        1       0 :                  37.000             : for           
+    38 : 1903-02-01 12:00:00       0        1       0 :                  38.000             : for           
+    39 : 1903-03-01 12:00:00       0        1       0 :                  39.000             : for           
+    40 : 1903-04-01 12:00:00       0        1       0 :                  40.000             : for           
+    41 : 1903-05-01 12:00:00       0        1       0 :                  41.000             : for           
+    42 : 1903-06-01 12:00:00       0        1       0 :                  42.000             : for           
+    43 : 1903-07-01 12:00:00       0        1       0 :                  43.000             : for           
+    44 : 1903-08-01 12:00:00       0        1       0 :                  44.000             : for           
+    45 : 1903-09-01 12:00:00       0        1       0 :                  45.000             : for           
+    46 : 1903-10-01 12:00:00       0        1       0 :                  46.000             : for           
+    47 : 1903-11-01 12:00:00       0        1       0 :                  47.000             : for           
+    48 : 1903-12-01 12:00:00       0        1       0 :                  48.000             : for           
+    49 : 1904-01-01 12:00:00       0        1       0 :                  49.000             : for           
+    50 : 1904-02-01 12:00:00       0        1       0 :                  50.000             : for           
+    51 : 1904-03-01 12:00:00       0        1       0 :                  51.000             : for           
+    52 : 1904-04-01 12:00:00       0        1       0 :                  52.000             : for           
+    53 : 1904-05-01 12:00:00       0        1       0 :                  53.000             : for           
+    54 : 1904-06-01 12:00:00       0        1       0 :                  54.000             : for           
+    55 : 1904-07-01 12:00:00       0        1       0 :                  55.000             : for           
+    56 : 1904-08-01 12:00:00       0        1       0 :                  56.000             : for           
+    57 : 1904-09-01 12:00:00       0        1       0 :                  57.000             : for           
+    58 : 1904-10-01 12:00:00       0        1       0 :                  58.000             : for           
+    59 : 1904-11-01 12:00:00       0        1       0 :                  59.000             : for           
+    60 : 1904-12-01 12:00:00       0        1       0 :                  60.000             : for           
+    61 : 1905-01-01 12:00:00       0        1       0 :                  61.000             : for           
+    62 : 1905-02-01 12:00:00       0        1       0 :                  62.000             : for           
+    63 : 1905-03-01 12:00:00       0        1       0 :                  63.000             : for           
+    64 : 1905-04-01 12:00:00       0        1       0 :                  64.000             : for           
+    65 : 1905-05-01 12:00:00       0        1       0 :                  65.000             : for           
+    66 : 1905-06-01 12:00:00       0        1       0 :                  66.000             : for           
+    67 : 1905-07-01 12:00:00       0        1       0 :                  67.000             : for           
+    68 : 1905-08-01 12:00:00       0        1       0 :                  68.000             : for           
+    69 : 1905-09-01 12:00:00       0        1       0 :                  69.000             : for           
+    70 : 1905-10-01 12:00:00       0        1       0 :                  70.000             : for           
+    71 : 1905-11-01 12:00:00       0        1       0 :                  71.000             : for           
+    72 : 1905-12-01 12:00:00       0        1       0 :                  72.000             : for           
+    73 : 1906-01-01 12:00:00       0        1       0 :                  73.000             : for           
+    74 : 1906-02-01 12:00:00       0        1       0 :                  74.000             : for           
+    75 : 1906-03-01 12:00:00       0        1       0 :                  75.000             : for           
+    76 : 1906-04-01 12:00:00       0        1       0 :                  76.000             : for           
+    77 : 1906-05-01 12:00:00       0        1       0 :                  77.000             : for           
+    78 : 1906-06-01 12:00:00       0        1       0 :                  78.000             : for           
+    79 : 1906-07-01 12:00:00       0        1       0 :                  79.000             : for           
+    80 : 1906-08-01 12:00:00       0        1       0 :                  80.000             : for           
+    81 : 1906-09-01 12:00:00       0        1       0 :                  81.000             : for           
+    82 : 1906-10-01 12:00:00       0        1       0 :                  82.000             : for           
+    83 : 1906-11-01 12:00:00       0        1       0 :                  83.000             : for           
+    84 : 1906-12-01 12:00:00       0        1       0 :                  84.000             : for           
+    85 : 1907-01-01 12:00:00       0        1       0 :                  85.000             : for           
+    86 : 1907-02-01 12:00:00       0        1       0 :                  86.000             : for           
+    87 : 1907-03-01 12:00:00       0        1       0 :                  87.000             : for           
+    88 : 1907-04-01 12:00:00       0        1       0 :                  88.000             : for           
+    89 : 1907-05-01 12:00:00       0        1       0 :                  89.000             : for           
+    90 : 1907-06-01 12:00:00       0        1       0 :                  90.000             : for           
+    91 : 1907-07-01 12:00:00       0        1       0 :                  91.000             : for           
+    92 : 1907-08-01 12:00:00       0        1       0 :                  92.000             : for           
+    93 : 1907-09-01 12:00:00       0        1       0 :                  93.000             : for           
+    94 : 1907-10-01 12:00:00       0        1       0 :                  94.000             : for           
+    95 : 1907-11-01 12:00:00       0        1       0 :                  95.000             : for           
+    96 : 1907-12-01 12:00:00       0        1       0 :                  96.000             : for           
+    97 : 1908-01-01 12:00:00       0        1       0 :                  97.000             : for           
+    98 : 1908-02-01 12:00:00       0        1       0 :                  98.000             : for           
+    99 : 1908-03-01 12:00:00       0        1       0 :                  99.000             : for           
+   100 : 1908-04-01 12:00:00       0        1       0 :                  100.00             : for           
+   101 : 1908-05-01 12:00:00       0        1       0 :                  101.00             : for           
+   102 : 1908-06-01 12:00:00       0        1       0 :                  102.00             : for           
+   103 : 1908-07-01 12:00:00       0        1       0 :                  103.00             : for           
+   104 : 1908-08-01 12:00:00       0        1       0 :                  104.00             : for           
+   105 : 1908-09-01 12:00:00       0        1       0 :                  105.00             : for           
+   106 : 1908-10-01 12:00:00       0        1       0 :                  106.00             : for           
+   107 : 1908-11-01 12:00:00       0        1       0 :                  107.00             : for           
+   108 : 1908-12-01 12:00:00       0        1       0 :                  108.00             : for           
+   109 : 1909-01-01 12:00:00       0        1       0 :                  109.00             : for           
+   110 : 1909-02-01 12:00:00       0        1       0 :                  110.00             : for           
+   111 : 1909-03-01 12:00:00       0        1       0 :                  111.00             : for           
+   112 : 1909-04-01 12:00:00       0        1       0 :                  112.00             : for           
+   113 : 1909-05-01 12:00:00       0        1       0 :                  113.00             : for           
+   114 : 1909-06-01 12:00:00       0        1       0 :                  114.00             : for           
+   115 : 1909-07-01 12:00:00       0        1       0 :                  115.00             : for           
+   116 : 1909-08-01 12:00:00       0        1       0 :                  116.00             : for           
+   117 : 1909-09-01 12:00:00       0        1       0 :                  117.00             : for           
+   118 : 1909-10-01 12:00:00       0        1       0 :                  118.00             : for           
+   119 : 1909-11-01 12:00:00       0        1       0 :                  119.00             : for           
+   120 : 1909-12-01 12:00:00       0        1       0 :                  120.00             : for           
diff --git a/test/data/netcdf_testfile02_sinfon_ref b/test/data/netcdf_testfile02_sinfon_ref
new file mode 100644
index 0000000..5111e1f
--- /dev/null
+++ b/test/data/netcdf_testfile02_sinfon_ref
@@ -0,0 +1,42 @@
+   File format : netCDF
+    -1 : Institut Source   Ttype    Levels Num    Points Num Dtype : Parameter name
+     1 : unknown  unknown  instant       1   1         1   1  F32  : for           
+   Grid coordinates :
+     1 : lonlat                   : points=1 (1x1)
+                              lon : 0 degrees_east
+                              lat : 0 degrees_north
+   Vertical coordinates :
+     1 : surface                  : levels=1
+   Time coordinate :  120 steps
+     RefTime =  1900-01-01 12:00:00  Units = months  Calendar = proleptic_gregorian
+  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
+  1900-01-01 12:00:00  1900-02-01 12:00:00  1900-03-01 12:00:00  1900-04-01 12:00:00
+  1900-05-01 12:00:00  1900-06-01 12:00:00  1900-07-01 12:00:00  1900-08-01 12:00:00
+  1900-09-01 12:00:00  1900-10-01 12:00:00  1900-11-01 12:00:00  1900-12-01 12:00:00
+  1901-01-01 12:00:00  1901-02-01 12:00:00  1901-03-01 12:00:00  1901-04-01 12:00:00
+  1901-05-01 12:00:00  1901-06-01 12:00:00  1901-07-01 12:00:00  1901-08-01 12:00:00
+  1901-09-01 12:00:00  1901-10-01 12:00:00  1901-11-01 12:00:00  1901-12-01 12:00:00
+  1902-01-01 12:00:00  1902-02-01 12:00:00  1902-03-01 12:00:00  1902-04-01 12:00:00
+  1902-05-01 12:00:00  1902-06-01 12:00:00  1902-07-01 12:00:00  1902-08-01 12:00:00
+  1902-09-01 12:00:00  1902-10-01 12:00:00  1902-11-01 12:00:00  1902-12-01 12:00:00
+  1903-01-01 12:00:00  1903-02-01 12:00:00  1903-03-01 12:00:00  1903-04-01 12:00:00
+  1903-05-01 12:00:00  1903-06-01 12:00:00  1903-07-01 12:00:00  1903-08-01 12:00:00
+  1903-09-01 12:00:00  1903-10-01 12:00:00  1903-11-01 12:00:00  1903-12-01 12:00:00
+  1904-01-01 12:00:00  1904-02-01 12:00:00  1904-03-01 12:00:00  1904-04-01 12:00:00
+  1904-05-01 12:00:00  1904-06-01 12:00:00  1904-07-01 12:00:00  1904-08-01 12:00:00
+  1904-09-01 12:00:00  1904-10-01 12:00:00  1904-11-01 12:00:00  1904-12-01 12:00:00
+  1905-01-01 12:00:00  1905-02-01 12:00:00  1905-03-01 12:00:00  1905-04-01 12:00:00
+  1905-05-01 12:00:00  1905-06-01 12:00:00  1905-07-01 12:00:00  1905-08-01 12:00:00
+  1905-09-01 12:00:00  1905-10-01 12:00:00  1905-11-01 12:00:00  1905-12-01 12:00:00
+  1906-01-01 12:00:00  1906-02-01 12:00:00  1906-03-01 12:00:00  1906-04-01 12:00:00
+  1906-05-01 12:00:00  1906-06-01 12:00:00  1906-07-01 12:00:00  1906-08-01 12:00:00
+  1906-09-01 12:00:00  1906-10-01 12:00:00  1906-11-01 12:00:00  1906-12-01 12:00:00
+  1907-01-01 12:00:00  1907-02-01 12:00:00  1907-03-01 12:00:00  1907-04-01 12:00:00
+  1907-05-01 12:00:00  1907-06-01 12:00:00  1907-07-01 12:00:00  1907-08-01 12:00:00
+  1907-09-01 12:00:00  1907-10-01 12:00:00  1907-11-01 12:00:00  1907-12-01 12:00:00
+  1908-01-01 12:00:00  1908-02-01 12:00:00  1908-03-01 12:00:00  1908-04-01 12:00:00
+  1908-05-01 12:00:00  1908-06-01 12:00:00  1908-07-01 12:00:00  1908-08-01 12:00:00
+  1908-09-01 12:00:00  1908-10-01 12:00:00  1908-11-01 12:00:00  1908-12-01 12:00:00
+  1909-01-01 12:00:00  1909-02-01 12:00:00  1909-03-01 12:00:00  1909-04-01 12:00:00
+  1909-05-01 12:00:00  1909-06-01 12:00:00  1909-07-01 12:00:00  1909-08-01 12:00:00
+  1909-09-01 12:00:00  1909-10-01 12:00:00  1909-11-01 12:00:00  1909-12-01 12:00:00
diff --git a/test/data/pl_data b/test/data/pl_data
new file mode 100644
index 0000000..03bd273
Binary files /dev/null and b/test/data/pl_data differ
diff --git a/test/data/testfile01c.nc b/test/data/testfile01c.nc
new file mode 100644
index 0000000..55185cc
Binary files /dev/null and b/test/data/testfile01c.nc differ

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/cdo.git



More information about the debian-science-commits mailing list