Index: python/prepareFLEXPART.py
===================================================================
--- python/prepareFLEXPART.py	(revision efdb01a8ac2d5cef85c651177aa18ac69dd660db)
+++ python/prepareFLEXPART.py	(revision 991df6ad0a703d97e1e192a0a6106e1d9ba47e8e)
@@ -3,6 +3,4 @@
 #************************************************************************
 # TODO AP
-#AP
-# - Change History ist nicht angepasst ans File! Original geben lassen
 # - wieso cleanup in main wenn es in prepareflexpart bereits abgefragt wurde?
 #   doppelt gemoppelt?
@@ -10,54 +8,58 @@
 #   relevant sind? verstehe ich nicht
 #************************************************************************
-"""
-@Author: Anne Fouilloux (University of Oslo)
-
-@Date: October 2014
-
-@ChangeHistory:
-    November 2015 - Leopold Haimberger (University of Vienna):
-        - using the WebAPI also for general MARS retrievals
-        - job submission on ecgate and cca
-        - job templates suitable for twice daily operational dissemination
-        - dividing retrievals of longer periods into digestable chunks
-        - retrieve also longer term forecasts, not only analyses and
-          short term forecast data
-        - conversion into GRIB2
-        - conversion into .fp format for faster execution of FLEXPART
-
-    February 2018 - Anne Philipp (University of Vienna):
-        - applied PEP8 style guide
-        - 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-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.
-
-@Requirements:
-    - A standard python 2.6 or 2.7 installation
-    - dateutils
-    - ECMWF specific packages, all available from https://software.ecmwf.int/
-        ECMWF WebMARS, gribAPI with python enabled, emoslib and
-        ecaccess web toolkit
-
-@Description:
-    Further documentation may be obtained from www.flexpart.eu.
-
-    Functionality provided:
-        Prepare input 3D-wind fields in hybrid coordinates +
-        surface fields for FLEXPART runs
-"""
+#*******************************************************************************
+# @Author: Anne Fouilloux (University of Oslo)
+#
+# @Date: October 2014
+#
+# @Change History:
+#
+#    November 2015 - Leopold Haimberger (University of Vienna):
+#        - using the WebAPI also for general MARS retrievals
+#        - job submission on ecgate and cca
+#        - job templates suitable for twice daily operational dissemination
+#        - dividing retrievals of longer periods into digestable chunks
+#        - retrieve also longer term forecasts, not only analyses and
+#          short term forecast data
+#        - conversion into GRIB2
+#        - conversion into .fp format for faster execution of FLEXPART
+#
+#    February 2018 - Anne Philipp (University of Vienna):
+#        - applied PEP8 style guide
+#        - added documentation
+#        - minor changes in programming style for consistence
+#        - BUG: removed call of cleanup-Function after call of
+#               prepareFlexpart in main since it is already called in
+#               prepareFlexpart at the end!
+#        - created function main and moved the two function calls for
+#          arguments and prepareFLEXPART into it
+#
+# @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.
+#
+# @Program Functionality:
+#    This program prepares the final version of the grib files which are
+#    then used by FLEXPART. It converts the bunch of grib files extracted
+#    via getMARSdata by doing for example the necessary conversion to get
+#    consistent grids or the disaggregation of flux data. Finally, the
+#    program combines the data fields in files per available hour with the
+#    naming convention xxYYMMDDHH, where xx should be 2 arbitrary letters
+#    (mostly xx is chosen to be "EN").
+#
+# @Program Content:
+#    - main
+#    - prepareFLEXPART
+#
+#*******************************************************************************
+
 # ------------------------------------------------------------------------------
 # MODULES
 # ------------------------------------------------------------------------------
-import calendar
 import shutil
 import datetime
-import time
+#import time
 import os
 import inspect
@@ -65,8 +67,4 @@
 import socket
 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
-import UIOFiles
-import Control
-import Tools
-import ECFlexpart
 
 hostname = socket.gethostname()
@@ -78,15 +76,43 @@
     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())))
+# add path 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)
+
+# software specific classes and modules from flex_extract
+from UIOFiles import UIOFiles
+from Tools import interpret_args_and_control, cleanup
+from ECFlexpart import ECFlexpart
 # ------------------------------------------------------------------------------
 # FUNCTION
 # ------------------------------------------------------------------------------
+def main():
+    '''
+    @Description:
+        If prepareFLEXPART is called from command line, this function controls
+        the program flow and calls the argumentparser function and
+        the prepareFLEXPART function for preparation of GRIB data for FLEXPART.
+
+    @Input:
+        <nothing>
+
+    @Return:
+        <nothing>
+    '''
+    args, c = interpret_args_and_control()
+    prepareFLEXPART(args, c)
+
+    return
+
 def prepareFLEXPART(args, c):
     '''
     @Description:
-
+        Lists all grib files retrieved from MARS with getMARSdata and
+        uses prepares data for the use in FLEXPART. Specific data fields
+        are converted to a different grid and the flux data are going to be
+        disaggregated. The data fields are collected by hour and stored in
+        a file with a specific FLEXPART relevant naming convention.
 
     @Input:
@@ -94,6 +120,6 @@
             Contains the commandline arguments from script/program call.
 
-        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,
@@ -134,8 +160,6 @@
 
     # get all files with flux data to be deaccumulated
-    inputfiles = UIOFiles.UIOFiles(['.grib', '.grb', '.grib1',
-                           '.grib2', '.grb1', '.grb2'])
-
-    inputfiles.listFiles(c.inputdir, '*OG_acc_SL*.' + c.ppid + '.*')
+    inputfiles = UIOFiles('*OG_acc_SL*.' + c.ppid + '.*')
+    inputfiles.listFiles(c.inputdir)
 
     # create output dir if necessary
@@ -144,5 +168,5 @@
 
     # deaccumulate the flux data
-    flexpart = ECFlexpart.ECFlexpart(c, fluxes=True)
+    flexpart = ECFlexpart(c, fluxes=True)
     flexpart.write_namelist(c, 'fort.4')
     flexpart.deacc_fluxes(inputfiles, c)
@@ -152,8 +176,6 @@
 
     # get a list of all files from the root inputdir
-    inputfiles = UIOFiles.UIOFiles(['.grib', '.grb', '.grib1',
-                           '.grib2', '.grb1', '.grb2'])
-
-    inputfiles.listFiles(c.inputdir, '????__??.*' + c.ppid + '.*')
+    inputfiles = UIOFiles('????__??.*' + c.ppid + '.*')
+    inputfiles.listFiles(c.inputdir)
 
     # produce FLEXPART-ready GRIB files and
@@ -163,5 +185,5 @@
         start = startm1
 
-    flexpart = ECFlexpart.ECFlexpart(c, fluxes=False)
+    flexpart = ECFlexpart(c, fluxes=False)
     flexpart.create(inputfiles, c)
     flexpart.process_output(c)
@@ -172,9 +194,8 @@
         print('Temporary files left intact')
     else:
-        Tools.cleanup(c)
+        cleanup(c)
 
     return
 
 if __name__ == "__main__":
-    args, c = Tools.interpret_args_and_control()
-    prepareFLEXPART(args, c)
+    main()
