Index: python/prepareFLEXPART.py
===================================================================
--- python/prepareFLEXPART.py	(revision 02c8c50da359770adb72a6e9287a59e6be76cb36)
+++ python/prepareFLEXPART.py	(revision efdb01a8ac2d5cef85c651177aa18ac69dd660db)
@@ -30,7 +30,9 @@
         - added documentation
         - minor changes in programming style for consistence
+        - BUG: removed call of cleanup-Function after call of prepareFlexpart
+                since it is already called in prepareFlexpart at the end!
 
 @License:
-    (C) Copyright 2014.
+    (C) Copyright 2014-2018.
 
     This software is licensed under the terms of the Apache Licence Version 2.0
@@ -40,5 +42,4 @@
     - A standard python 2.6 or 2.7 installation
     - dateutils
-    - matplotlib (optional, for debugging)
     - ECMWF specific packages, all available from https://software.ecmwf.int/
         ECMWF WebMARS, gribAPI with python enabled, emoslib and
@@ -52,24 +53,23 @@
         surface fields for FLEXPART runs
 """
-
+# ------------------------------------------------------------------------------
+# MODULES
+# ------------------------------------------------------------------------------
 import calendar
 import shutil
 import datetime
 import time
-import os,inspect,sys
+import os
+import inspect
+import sys
 import socket
 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
-# add path to submit.py to pythonpath so that python finds its buddies
-localpythonpath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
-if localpythonpath not in sys.path:
-    sys.path.append(localpythonpath)
-from UIOTools import UIOFiles
-#from string import strip
-from GribTools import GribTools
-from FlexpartTools import ECFlexpart, Control, interpret_args_and_control, cleanup
+import UIOFiles
+import Control
+import Tools
+import ECFlexpart
 
-hostname=socket.gethostname()
-ecapi= 'ecmwf' not in hostname
-
+hostname = socket.gethostname()
+ecapi = 'ecmwf' not in hostname
 try:
     if ecapi:
@@ -78,5 +78,11 @@
     ecapi = False
 
-
+# add path to submit.py to pythonpath so that python finds its buddies
+localpythonpath=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
+if localpythonpath not in sys.path:
+    sys.path.append(localpythonpath)
+# ------------------------------------------------------------------------------
+# FUNCTION
+# ------------------------------------------------------------------------------
 def prepareFLEXPART(args, c):
     '''
@@ -121,5 +127,5 @@
                         day=int(c.end_date[6:]))
 
-    # to deaccumulated the fluxes correctly
+    # to deaccumulate the fluxes correctly
     # one day ahead of the start date and
     # one day after the end date is needed
@@ -128,5 +134,5 @@
 
     # get all files with flux data to be deaccumulated
-    inputfiles = UIOFiles(['.grib', '.grb', '.grib1',
+    inputfiles = UIOFiles.UIOFiles(['.grib', '.grb', '.grib1',
                            '.grib2', '.grb1', '.grb2'])
 
@@ -138,5 +144,5 @@
 
     # deaccumulate the flux data
-    flexpart = ECFlexpart(c, fluxes=True)
+    flexpart = ECFlexpart.ECFlexpart(c, fluxes=True)
     flexpart.write_namelist(c, 'fort.4')
     flexpart.deacc_fluxes(inputfiles, c)
@@ -146,5 +152,5 @@
 
     # get a list of all files from the root inputdir
-    inputfiles = UIOFiles(['.grib', '.grb', '.grib1',
+    inputfiles = UIOFiles.UIOFiles(['.grib', '.grb', '.grib1',
                            '.grib2', '.grb1', '.grb2'])
 
@@ -157,19 +163,18 @@
         start = startm1
 
-    flexpart = ECFlexpart(c, fluxes=False)
+    flexpart = ECFlexpart.ECFlexpart(c, fluxes=False)
     flexpart.create(inputfiles, c)
     flexpart.process_output(c)
 
     # check if in debugging mode, then store all files
+    # otherwise delete temporary files
     if int(c.debug) != 0:
         print('Temporary files left intact')
     else:
-        cleanup(c)
+        Tools.cleanup(c)
 
     return
 
 if __name__ == "__main__":
-    args, c = interpret_args_and_control()
+    args, c = Tools.interpret_args_and_control()
     prepareFLEXPART(args, c)
-    cleanup(c)
-
