Index: python/Tools.py
===================================================================
--- python/Tools.py	(revision efdb01a8ac2d5cef85c651177aa18ac69dd660db)
+++ python/Tools.py	(revision 991df6ad0a703d97e1e192a0a6106e1d9ba47e8e)
@@ -3,21 +3,65 @@
 #************************************************************************
 # TODO AP
-#AP
-# -
+# - check myerror
+# - check normalexit
+# - check getListAsString
+# - seperate args and control interpretation
 #************************************************************************
-"""
-
-"""
+#*******************************************************************************
+# @Author: Anne Philipp (University of Vienna)
+#
+# @Date: May 2018
+#
+# @Change History:
+#    October 2014 - Anne Fouilloux (University of Oslo)
+#        - created functions silentremove and product (taken from ECMWF)
+#
+#    November 2015 - Leopold Haimberger (University of Vienna)
+#        - created functions: interpret_args_and_control, cleanup
+#          myerror, normalexit, init128, toparamId
+#
+#    April 2018 - Anne Philipp (University of Vienna):
+#        - applied PEP8 style guide
+#        - added documentation
+#        - moved all functions from file FlexpartTools to this file Tools
+#        - added function getListAsString
+#
+# @License:
+#    (C) Copyright 2014-2018.
+#
+#    This software is licensed under the terms of the Apache Licence Version 2.0
+#    which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
+#
+# @Modul Description:
+#    This module contains a couple of helpful functions which are
+#    used in different places in flex_extract.
+#
+# @Module Content:
+#    - interpret_args_and_control
+#    - cleanup
+#    - myerror
+#    - normalexit
+#    - product
+#    - silentremove
+#    - init128
+#    - toparamId
+#    - getListAsString
+#
+#*******************************************************************************
+
 # ------------------------------------------------------------------------------
 # MODULES
 # ------------------------------------------------------------------------------
-from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
 import os
 import errno
 import sys
 import glob
+import traceback
 from numpy import *
 from gribapi import *
-import Control
+from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
+
+# software specific class from flex_extract
+from ControlFile import ControlFile
 
 # ------------------------------------------------------------------------------
@@ -28,5 +72,5 @@
     '''
     @Description:
-        Assigns the command line arguments and reads control file
+        Assigns the command line arguments and reads CONTROL file
         content. Apply default values for non mentioned arguments.
 
@@ -38,6 +82,6 @@
             Contains the commandline arguments from script/program call.
 
-        c: instance of class Control
-            Contains all necessary information of a control file. The parameters
+        c: instance of class ControlFile
+            Contains all necessary information of a CONTROL file. The parameters
             are: DAY1, DAY2, DTIME, MAXSTEP, TYPE, TIME, STEP, CLASS, STREAM,
             NUMBER, EXPVER, GRID, LEFT, LOWER, UPPER, RIGHT, LEVEL, LEVELIST,
@@ -62,5 +106,5 @@
                         help="# of days to be retrieved at once")
 
-    # some arguments that override the default in the control file
+    # some arguments that override the default in the CONTROL file
     parser.add_argument("--basetime", dest="basetime",
                         help="base such as 00/12 (for half day retrievals)")
@@ -96,5 +140,5 @@
     parser.add_argument("--controlfile", dest="controlfile",
                         default='CONTROL.temp',
-                        help="file with control parameters")
+                        help="file with CONTROL parameters")
     parser.add_argument("--debug", dest="debug", default=0,
                         help="Debug mode - leave temporary files intact")
@@ -102,13 +146,13 @@
     args = parser.parse_args()
 
-    # create instance of Control for specified controlfile
+    # create instance of ControlFile for specified controlfile
     # and assign the parameters (and default values if necessary)
     try:
-        c = Control.Control(args.controlfile)
+        c = ControlFile(args.controlfile)
     except IOError:
         try:
-            c = Control.Control(localpythonpath + args.controlfile)
+            c = ControlFile(localpythonpath + args.controlfile)
         except:
-            print('Could not read control file "' + args.controlfile + '"')
+            print('Could not read CONTROL file "' + args.controlfile + '"')
             print('Either it does not exist or its syntax is wrong.')
             print('Try "' + sys.argv[0].split('/')[-1] +
@@ -119,10 +163,10 @@
     if  args.start_date is None and getattr(c, 'start_date') is None:
         print('start_date specified neither in command line nor \
-               in control file ' + args.controlfile)
+               in CONTROL file ' + args.controlfile)
         print('Try "' + sys.argv[0].split('/')[-1] +
               ' -h" to print usage information')
         exit(1)
 
-    # save all existing command line parameter to the Control instance
+    # save all existing command line parameter to the ControlFile instance
     # if parameter is not specified through the command line or CONTROL file
     # set default values
@@ -199,9 +243,9 @@
     @Description:
         Remove all files from intermediate directory
-        (inputdir from control file).
-
-    @Input:
-        c: instance of class Control
-            Contains all the parameters of control files, which are e.g.:
+        (inputdir from CONTROL file).
+
+    @Input:
+        c: instance of class ControlFile
+            Contains all the parameters of CONTROL file, which are e.g.:
             DAY1(start_date), DAY2(end_date), DTIME, MAXSTEP, TYPE, TIME,
             STEP, CLASS(marsclass), STREAM, NUMBER, EXPVER, GRID, LEFT,
@@ -240,6 +284,6 @@
 
     @Input:
-        c: instance of class Control
-            Contains all the parameters of control files, which are e.g.:
+        c: instance of class ControlFile
+            Contains all the parameters of CONTROL file, which are e.g.:
             DAY1(start_date), DAY2(end_date), DTIME, MAXSTEP, TYPE, TIME,
             STEP, CLASS(marsclass), STREAM, NUMBER, EXPVER, GRID, LEFT,
@@ -290,6 +334,6 @@
 
     @Input:
-        c: instance of class Control
-            Contains all the parameters of control files, which are e.g.:
+        c: instance of class ControlFile
+            Contains all the parameters of CONTROL file, which are e.g.:
             DAY1(start_date), DAY2(end_date), DTIME, MAXSTEP, TYPE, TIME,
             STEP, CLASS(marsclass), STREAM, NUMBER, EXPVER, GRID, LEFT,
@@ -357,5 +401,4 @@
             See example in description above.
     '''
-
     pools = map(tuple, args) * kwds.get('repeat', 1)
     result = [[]]
@@ -371,7 +414,6 @@
     '''
     @Description:
-        Removes the file which name is passed to the function if
-        it exists. The function does not fail if the file does not
-        exist.
+        If "filename" exists , it is removed.
+        The function does not fail if the file does not exist.
 
     @Input:
@@ -426,5 +468,5 @@
     @Input:
         pars: string
-            Addpar argument from control file in the format of
+            Addpar argument from CONTROL file in the format of
             parameter names instead of ids. The parameter short
             names are sepearted with "/" and they are passed as
@@ -438,5 +480,5 @@
     @Return:
         ipar: list of integer
-            List of addpar parameters from control file transformed to
+            List of addpar parameters from CONTROL file transformed to
             parameter ids in the format of integer.
     '''
@@ -455,7 +497,19 @@
     return ipar
 
-def getListAsString(listobj):
-    '''
-    @Description:
-    '''
-    return ", ".join( str(l) for l in listobj)
+def getListAsString(listObj):
+    '''
+    @Description:
+        Converts a list of arbitrary content into a single string.
+
+    @Input:
+        listObj: list
+            A list with arbitrary content.
+
+    @Return:
+        strOfList: string
+            The content of the list as a single string.
+    '''
+
+    strOfList = ", ".join( str(l) for l in listObj)
+
+    return strOfList
