Index: python/ControlFile.py
===================================================================
--- python/ControlFile.py	(revision 54a8a01d975ad8c2dea60c93439d9bc0ef426132)
+++ python/ControlFile.py	(revision 2fb99de9b96e65c8b5caa85c276ad8e0be540ed0)
@@ -53,6 +53,9 @@
 # ------------------------------------------------------------------------------
 import os
+import re
 import sys
 import inspect
+
+import _config
 
 # ------------------------------------------------------------------------------
@@ -110,5 +113,5 @@
         self.stream = None
         self.number = 'OFF'
-        self.expver = None
+        self.expver = '1'
         self.grid = None
         self.area = ''
@@ -142,8 +145,8 @@
         self.inputdir = '../work'
         self.outputdir = self.inputdir
-        self.ecmwfdatadir = None
-        self.exedir = None
+        self.ecmwfdatadir = _config.PATH_FLEXEXTRACT_DIR
+        self.exedir = _config.PATH_FORTRAN_SRC
         self.flexpart_root_scripts = None
-        self.makefile = None
+        self.makefile = 'Makefile.gfortran'
         self.destination = None
         self.gateway = None
@@ -152,4 +155,9 @@
         self.install_target = None
         self.debug = 0
+        self.request = 0
+
+        self.logicals = ['gauss', 'omega', 'omegadiff', 'eta', 'etadiff',
+                         'dpdeta', 'cwc', 'wrf', 'grib2flexpart', 'ecstorage',
+                         'ectrans', 'debug', 'request']
 
         self.__read_controlfile__()
@@ -172,5 +180,6 @@
 
         # read whole CONTROL file
-        with open(self.controlfile) as f:
+        with open(os.path.join(_config.PATH_CONTROLFILES,
+                               self.controlfile)) as f:
             fdata = f.read().split('\n')
 
@@ -222,11 +231,4 @@
                 pass
 
-        # script directory
-        self.ecmwfdatadir = os.path.dirname(os.path.abspath(inspect.getfile(
-            inspect.currentframe()))) + '/../'
-
-        # Fortran source directory
-        self.exedir = self.ecmwfdatadir + 'src/'
-
         return
 
@@ -310,5 +312,5 @@
         return
 
-    def check_conditions(self):
+    def check_conditions(self, queue):
         '''
         @Description:
@@ -321,4 +323,9 @@
                 Description see class documentation.
 
+            queue: string
+                Name of the queue if submitted to the ECMWF servers.
+                Used to check if ecuid, ecgid, gateway and destination
+                are set correctly and are not empty.
+
         @Return:
             <nothing>
@@ -330,8 +337,8 @@
         # otherwise program is not allowed to run
         if self.start_date is None:
-            print 'start_date specified neither in command line nor ' + \
-                  'in CONTROL file ' +  self.controlfile
-            print 'Try "' + sys.argv[0].split('/')[-1] + \
-                  ' -h" to print usage information'
+            print('start_date specified neither in command line nor \
+                   in CONTROL file ' +  self.controlfile)
+            print('Try "' + sys.argv[0].split('/')[-1] +
+                  ' -h" to print usage information')
             sys.exit(1)
 
@@ -341,39 +348,40 @@
 
         # assure consistency of levelist and level
-        if self.levelist is None:
-            if self.level is None:
-                print 'Warning: neither levelist nor level ' + \
-                      'specified in CONTROL file'
-                sys.exit(1)
+        if self.levelist is None and self.level is None:
+            print('Warning: neither levelist nor level \
+                               specified in CONTROL file')
+            sys.exit(1)
+        elif self.levelist is None and self.level:
+            self.levelist = '1/to/' + self.level
+        elif (self.levelist and self.level is None) or \
+             (self.levelist[-1] != self.level[-1]):
+            self.level = self.levelist.split('/')[-1]
+        else:
+            pass
+
+        # if area was provided (only from commandline)
+        # decompose area into its 4 components
+        if self.area:
+            components = self.area.split('/')
+            # convert float to integer coordinates
+            if '.' in self.area:
+                components = [str(int(float(item) * 1000))
+                              for i, item in enumerate(components)]
+            self.upper, self.left, self.lower, self.right = components
+
+        # prepare step list if "/" signs are found
+        if '/' in self.step:
+            steps = self.step.split('/')
+            if 'to' in self.step.lower() and 'by' in self.step.lower():
+                ilist = np.arange(int(steps[0]),
+                                  int(steps[2]) + 1,
+                                  int(steps[4]))
+                self.step = ['{:0>3}'.format(i) for i in ilist]
+            elif 'to' in self.step.lower() and 'by' not in self.step.lower():
+                my_error(self.mailfail, self.step + ':\n' +
+                         'if "to" is used in steps parameter, \
+                         please use "by" as well')
             else:
-                self.levelist = '1/to/' + self.level
-        else:
-            if 'to' in self.levelist.lower():
-                self.level = self.levelist.split('/')[2]
-            else:
-                self.level = self.levelist.split('/')[-1]
-
-        # if area was provided at command line
-        # decompse area into its 4 components
-        if self.area:
-            afloat = '.' in self.area
-            l = self.area.split('/')
-            if afloat:
-                for i, item in enumerate(l):
-                    item = str(int(float(item) * 1000))
-            self.upper, self.left, self.lower, self.right = l
-
-        # prepare step for correct usage
-        if '/' in self.step:
-            l = self.step.split('/')
-            if 'to' in self.step.lower():
-                if 'by' in self.step.lower():
-                    ilist = np.arange(int(l[0]), int(l[2]) + 1, int(l[4]))
-                    self.step = ['{:0>3}'.format(i) for i in ilist]
-                else:
-                    my_error(self.mailfail, self.step + ':\n' +
-                             'if "to" is used, please use "by" as well')
-            else:
-                self.step = l
+                self.step = steps
 
         # if maxstep wasn't provided
@@ -407,11 +415,24 @@
                 self.mailops = [self.mailops]
 
-        if not self.gateway or not self.destination or \
+        if queue in ['ecgate', 'cca'] and \
+           not self.gateway or not self.destination or \
            not self.ecuid or not self.ecgid:
-            print '\nEnvironment variables GATWAY, DESTINATION, ECUID and ' + \
-                  'ECGID were not set properly!'
-            print 'Please check for excistence of file "ECMWF_ENV" in the ' + \
-                  'python directory!'
+            print('\nEnvironment variables GATEWAY, DESTINATION, ECUID and \
+                   ECGID were not set properly!')
+            print('Please check for existence of file "ECMWF_ENV" in the \
+                   python directory!')
             sys.exit(1)
+
+        if self.request != 0:
+            marsfile = os.path.join(_config.PATH_RUN_DIR,
+                                    _config.FILE_MARS_REQUESTS)
+            if os.path.isfile(marsfile):
+                os.remove(marsfile)
+
+        # check all logical variables for data type
+        # if its a string change to integer
+        for var in self.logicals:
+            if not isinstance(getattr(self, var), int):
+                setattr(self, var, int(getattr(self, var)))
 
         return
@@ -434,9 +455,9 @@
         if self.install_target and \
            self.install_target not in ['local', 'ecgate', 'cca']:
-            print 'ERROR: unknown or missing installation target '
-            print 'target: ', self.install_target
-            print 'please specify correct installation target \
-                   (local | ecgate | cca)'
-            print 'use -h or --help for help'
+            print('ERROR: unknown or missing installation target ')
+            print('target: ', self.install_target)
+            print('please specify correct installation target ' +
+                  '(local | ecgate | cca)')
+            print('use -h or --help for help')
             sys.exit(1)
 
@@ -444,13 +465,13 @@
             if not self.ecgid or not self.ecuid or \
                not self.gateway or not self.destination:
-                print 'Please enter your ECMWF user id and group id as well as \
-                       the \nname of the local gateway and the ectrans \
-                       destination '
-                print 'with command line options --ecuid --ecgid \
-                       --gateway --destination'
-                print 'Try "' + sys.argv[0].split('/')[-1] + \
-                      ' -h" to print usage information'
-                print 'Please consult ecaccess documentation or ECMWF user \
-                       support for further details'
+                print('Please enter your ECMWF user id and group id as well ' +
+                      'as the \nname of the local gateway and the ectrans ' +
+                      'destination ')
+                print('with command line options --ecuid --ecgid \
+                       --gateway --destination')
+                print('Try "' + sys.argv[0].split('/')[-1] + \
+                      ' -h" to print usage information')
+                print('Please consult ecaccess documentation or ECMWF user \
+                       support for further details')
                 sys.exit(1)
 
@@ -459,10 +480,7 @@
             else:
                 self.flexpart_root_scripts = self.flexpart_root_scripts
-        else:
+        else: # local
             if not self.flexpart_root_scripts:
-                self.flexpart_root_scripts = '../'
-
-        if not self.makefile:
-            self.makefile = 'Makefile.gfortran'
+                self.flexpart_root_scripts = _config.PATH_FLEXEXTRACT_DIR
 
         return
