Index: Source/Python/Classes/EcFlexpart.py
===================================================================
--- Source/Python/Classes/EcFlexpart.py	(revision 8c1d1757c670781238d3cc6829dd992d7848863e)
+++ Source/Python/Classes/EcFlexpart.py	(revision c77630a97116cfe48788a474eaf76b1887d1479f)
@@ -1094,7 +1094,7 @@
 
             print("outputfile = " + fnout)
-            f_handle = open(fnout, 'w')
-            h_handle = open(hnout, 'w')
-            g_handle = open(gnout, 'w')
+            f_handle = open(fnout, 'wb')
+            h_handle = open(hnout, 'wb')
+            g_handle = open(gnout, 'wb')
 
             # read message for message and store relevant data fields, where
@@ -1402,5 +1402,5 @@
             # write original time step to flux file as usual
             fluxfile = GribUtil(os.path.join(c.inputdir, fluxfilename))
-            fluxfile.set_keys(tmpfile, filemode='a', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
                               wherekeynames=['paramId'], wherekeyvalues=[142],
                               keynames=['perturbationNumber','date','time','stepRange','values'],
@@ -1408,5 +1408,5 @@
                                          date.hour*100, 0, lsp_new_np[inumb,:,it]],
                              )
-            fluxfile.set_keys(tmpfile, filemode='a', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
                               wherekeynames=['paramId'], wherekeyvalues=[143],
                               keynames=['perturbationNumber','date','time','stepRange','values'],
@@ -1416,5 +1416,5 @@
 
             # rr for first subgrid point is identified by step = 1
-            fluxfile.set_keys(tmpfile, filemode='a', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
                               wherekeynames=['paramId'], wherekeyvalues=[142],
                               keynames=['perturbationNumber','date','time','stepRange','values'],
@@ -1422,5 +1422,5 @@
                                          date.hour*100, '1', lsp_new_np[inumb,:,it+1]]
                               )
-            fluxfile.set_keys(tmpfile, filemode='a', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
                               wherekeynames=['paramId'], wherekeyvalues=[143],
                               keynames=['perturbationNumber','date','time','stepRange','values'],
@@ -1430,5 +1430,5 @@
 
             # rr for second subgrid point is identified by step = 2
-            fluxfile.set_keys(tmpfile, filemode='a', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
                               wherekeynames=['paramId'], wherekeyvalues=[142],
                               keynames=['perturbationNumber','date','time','stepRange','values'],
@@ -1436,5 +1436,5 @@
                                          date.hour*100, '2', lsp_new_np[inumb,:,it+2]]
                               )
-            fluxfile.set_keys(tmpfile, filemode='a', strict=True,
+            fluxfile.set_keys(tmpfile, filemode='ab', strict=True,
                               wherekeynames=['paramId'], wherekeyvalues=[143],
                               keynames=['perturbationNumber','date','time','stepRange','values'],
@@ -1466,8 +1466,8 @@
 
         gribfile.copy_dummy_msg(ifile, keynames=['paramId'],
-                      keyvalues=[142], filemode='w')
+                      keyvalues=[142], filemode='wb')
 
         gribfile.copy_dummy_msg(ifile, keynames=['paramId'],
-                      keyvalues=[143], filemode='a')
+                      keyvalues=[143], filemode='ab')
 
         return
@@ -1573,5 +1573,5 @@
                 fortfile = os.path.join(c.inputdir, 'fort.' + k)
                 silent_remove(fortfile)
-                fdict[k] = open(fortfile, 'w')
+                fdict[k] = open(fortfile, 'wb')
 #============================================================================================
             # create correct timestamp from the three time informations
@@ -1608,5 +1608,5 @@
             #    if 'olddate' not in locals() or cdate != olddate:
             #        fwrf = open(os.path.join(c.outputdir,
-            #                    'WRF' + cdate + '.' + ctime + '.000.grb2'), 'w')
+            #                    'WRF' + cdate + '.' + ctime + '.000.grb2'), 'wb')
             #        olddate = cdate[:]
 #============================================================================================
Index: Source/Python/Classes/GribUtil.py
===================================================================
--- Source/Python/Classes/GribUtil.py	(revision 44174de31acc10708895185f7beb7568204f0760)
+++ Source/Python/Classes/GribUtil.py	(revision c77630a97116cfe48788a474eaf76b1887d1479f)
@@ -91,13 +91,9 @@
                              codes_release)
 
-        fileid = open(self.filenames, 'r')
-
         return_list = []
 
-        while 1:
+        with open(self.filenames, 'rb') as fileid:
+
             gid = codes_new_from_file(fileid)
-
-            if gid is None:
-                break
 
             if len(wherekeynames) != len(wherekeyvalues):
@@ -123,11 +119,9 @@
             codes_release(gid)
 
-        fileid.close()
-
         return return_list
 
 
     def set_keys(self, fromfile, keynames, keyvalues, wherekeynames=[],
-                 wherekeyvalues=[], strict=False, filemode='w'):
+                 wherekeyvalues=[], strict=False, filemode='wb'):
         '''Opens the file to read the grib messages and then write
         the selected messages (with wherekeys) to a new output file.
@@ -161,5 +155,5 @@
 
         filemode : :obj:`string`, optional
-            Sets the mode for the output file. Default is "w".
+            Sets the mode for the output file. Default is "wb".
 
         Return
@@ -175,11 +169,7 @@
 
         fout = open(self.filenames, filemode)
-        fin = open(fromfile)
-
-        while 1:
+
+        with open(fromfile, 'rb') as fin:
             gid = codes_grib_new_from_file(fin)
-
-            if gid is None:
-                break
 
             select = True
@@ -206,5 +196,4 @@
             codes_release(gid)
 
-        fin.close()
         fout.close()
 
@@ -212,5 +201,5 @@
 
     def copy_dummy_msg(self, filename_in, selectWhere=True,
-                 keynames=[], keyvalues=[], filemode='w'):
+                 keynames=[], keyvalues=[], filemode='wb'):
         '''Add the content of another input grib file to the objects file but
         only messages corresponding to keys/values passed to the function.
@@ -235,5 +224,5 @@
 
         filemode : :obj:`string`, optional
-            Sets the mode for the output file. Default is "w".
+            Sets the mode for the output file. Default is "wb".
 
         Return
@@ -247,14 +236,15 @@
             raise Exception("Give a value for each keyname!")
 
-        fin = open(filename_in, 'rb')
+
         fout = open(self.filenames, filemode)
 
         fields = 0
 
-        while fields < 1:
+        with open(filename_in, 'rb') as fin:
+            if fields >= 1:
+                fout.close()
+                return
+
             gid = codes_grib_new_from_file(fin)
-
-            if gid is None:
-                break
 
             select = True
@@ -278,5 +268,4 @@
             codes_release(gid)
 
-        fin.close()
         fout.close()
 
Index: Source/Python/Classes/MarsRetrieval.py
===================================================================
--- Source/Python/Classes/MarsRetrieval.py	(revision 44174de31acc10708895185f7beb7568204f0760)
+++ Source/Python/Classes/MarsRetrieval.py	(revision c77630a97116cfe48788a474eaf76b1887d1479f)
@@ -488,5 +488,5 @@
             del attrs[key]
 
-        attrs['ppengine'] = 'emos'
+#        attrs['ppengine'] = 'emos'
 
         # MARS request via Python script
@@ -520,5 +520,5 @@
                 request_str = request_str + ',' + key + '=' + str(value)
             request_str += ',target="' + target + '"'
-            p = subprocess.Popen(['mars', '-e'],
+            p = subprocess.Popen(['mars'], #'-e'],
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE,
Index: Source/Python/Mods/tools.py
===================================================================
--- Source/Python/Mods/tools.py	(revision 44174de31acc10708895185f7beb7568204f0760)
+++ Source/Python/Mods/tools.py	(revision c77630a97116cfe48788a474eaf76b1887d1479f)
@@ -763,5 +763,5 @@
     # --- open file ---
     print("Opening file for getting information data --- %s" % filename)
-    with open(filename) as f:
+    with open(filename, 'rb') as f:
         # load first message from file
         gid = codes_grib_new_from_file(f)
