Index: source/python/classes/GribUtil.py
===================================================================
--- source/python/classes/GribUtil.py	(revision None)
+++ source/python/classes/GribUtil.py	(revision 268ee865616a9e7e36998c529e1d54d2376d1f2b)
@@ -32,5 +32,5 @@
 #    - get_keys
 #    - set_keys
-#    - copy
+#    - copy_dummy_msg
 #    - index
 #
@@ -48,10 +48,10 @@
                      codes_release, codes_set, codes_write, codes_index_read,
                      codes_index_new_from_file, codes_index_add_file,
-                     codes_index_write)
+                     codes_index_write, codes_set_values)
 
 # ------------------------------------------------------------------------------
 # CLASS
 # ------------------------------------------------------------------------------
-class GribTools(object):
+class GribUtil(object):
     '''
     Class for GRIB utilities (new methods) based on GRIB API
@@ -61,5 +61,5 @@
     # --------------------------------------------------------------------------
     def __init__(self, filenames):
-        '''Initialise an object of GribTools and assign a list of filenames.
+        '''Initialise an object of GribUtil and assign a list of filenames.
 
         Parameters
@@ -139,8 +139,6 @@
                  wherekeyvalues=[], strict=False, filemode='w'):
         '''Opens the file to read the grib messages and then write
-        them to a new output file. By default all messages are
-        written out. Also, the keyvalues of the passed list of
-        keynames are set or only those meeting the where statement.
-        (list of key and list of values).
+        the selected messages (with wherekeys) to a new output file.
+        Also, the keyvalues of the passed list of keynames are set.
 
         Parameters
@@ -150,13 +148,17 @@
 
         keynames : :obj:`list` of :obj:`string`
-            List of keynames. Default is an empty list.
+            List of keynames to set in the selected messages.
+            Default is an empty list.
 
         keyvalues : :obj:`list` of :obj:`string`
-            List of keynames. Default is an empty list.
+            List of keyvalues to set in the selected messages.
+            Default is an empty list.
 
         wherekeynames : :obj:`list` of :obj:`string`, optional
+            List of keynames to select correct message.
             Default value is an empty list.
 
         wherekeyvalues : :obj:`list` of :obj:`string`, optional
+            List of keyvalues for keynames to select correct message.
             Default value is an empty list.
 
@@ -173,15 +175,15 @@
 
         '''
+        if len(wherekeynames) != len(wherekeyvalues):
+            raise Exception("Give a value for each keyname!")
+
         fout = open(self.filenames, filemode)
         fin = open(fromfile)
 
         while 1:
-            gid = codes_new_from_file(fin)
+            gid = codes_grib_new_from_file(fin)
 
             if gid is None:
                 break
-
-            if len(wherekeynames) != len(wherekeyvalues):
-                raise Exception("Give a value for each keyname!")
 
             select = True
@@ -189,5 +191,5 @@
             for wherekey in wherekeynames:
                 if not codes_is_defined(gid, wherekey):
-                    raise Exception("where Key was not defined")
+                    raise Exception("wherekey was not defined")
 
                 select = (select and (str(wherekeyvalues[i]) ==
@@ -198,8 +200,11 @@
                 i = 0
                 for key in keynames:
-                    codes_set(gid, key, keyvalues[i])
+                    if key == 'values':
+                        codes_set_values(gid, keyvalues[i])
+                    else:
+                        codes_set(gid, key, keyvalues[i])
                     i += 1
 
-            codes_write(gid, fout)
+                codes_write(gid, fout)
 
             codes_release(gid)
@@ -210,6 +215,6 @@
         return
 
-    def copy(self, filename_in, selectWhere=True,
-             keynames=[], keyvalues=[], filemode='w'):
+    def copy_dummy_msg(self, filename_in, selectWhere=True,
+                 keynames=[], keyvalues=[], filemode='w'):
         '''Add the content of another input grib file to the objects file but
         only messages corresponding to keys/values passed to the function.
@@ -231,5 +236,5 @@
 
         keyvalues : :obj:`list` of :obj:`string`, optional
-            List of keynames. Default is an empty list.
+            List of keyvalues. Default is an empty list.
 
         filemode : :obj:`string`, optional
@@ -240,16 +245,17 @@
 
         '''
+        if len(keynames) != len(keyvalues):
+            raise Exception("Give a value for each keyname!")
 
         fin = open(filename_in)
         fout = open(self.filenames, filemode)
 
-        while 1:
-            gid = codes_new_from_file(fin)
+        fields = 0
+
+        while fields < 1:
+            gid = codes_grib_new_from_file(fin)
 
             if gid is None:
                 break
-
-            if len(keynames) != len(keyvalues):
-                raise Exception("Give a value for each keyname!")
 
             select = True
@@ -268,4 +274,5 @@
 
             if select:
+                fields = fields + 1
                 codes_write(gid, fout)
 
