Index: source/python/classes/ControlFile.py
===================================================================
--- source/python/classes/ControlFile.py	(revision 6f951ca0346aa6a2c3e11ee62df85214a290d838)
+++ source/python/classes/ControlFile.py	(revision d4696e0eebad213794352c454f011ba6dc050ddc)
@@ -93,5 +93,5 @@
         The time step in hours. Default value is None.
 
-    basetime : str
+    basetime : int
         The time for a half day retrieval. The 12 hours upfront are to be
         retrieved. Default value is None.
@@ -301,4 +301,9 @@
         Switch to keep temporary files at the end of postprocessing (1) or
         to delete all temporary files except the final output files (0).
+        Default value is 0.
+
+    oper : int
+        Switch to prepare the operational job script. Start date, end date and
+        basetime will be prepared with environment variables.
         Default value is 0.
 
@@ -409,4 +414,5 @@
         self.install_target = None
         self.debug = 0
+        self.oper = 0
         self.request = 0
         self.public = 0
@@ -417,6 +423,6 @@
         self.logicals = ['gauss', 'omega', 'omegadiff', 'eta', 'etadiff',
                          'dpdeta', 'cwc', 'wrf', 'grib2flexpart', 'ecstorage',
-                         'ectrans', 'debug', 'request', 'public', 'purefc',
-                         'rrint']
+                         'ectrans', 'debug', 'oper', 'request', 'public',
+                         'purefc', 'rrint']
 
         self._read_controlfile()
@@ -599,5 +605,5 @@
                                                      self.end_date)
 
-        check_basetime(self.basetime)
+        self.basetime = check_basetime(self.basetime)
 
         self.levelist, self.level = check_levels(self.levelist, self.level)
@@ -624,7 +630,7 @@
         self.acctype = check_acctype(self.acctype, self.type)
 
-        self.acctime = check_acctime(self.acctime, self.acctype, self.purefc)
-
-        self.accmaxstep = check_accmaxstep(self.accmaxstep, self.acctype,
+        self.acctime = check_acctime(self.acctime, self.marsclass, self.purefc)
+
+        self.accmaxstep = check_accmaxstep(self.accmaxstep, self.marsclass,
                                            self.purefc, self.maxstep)
 
Index: source/python/classes/EcFlexpart.py
===================================================================
--- source/python/classes/EcFlexpart.py	(revision 6f951ca0346aa6a2c3e11ee62df85214a290d838)
+++ source/python/classes/EcFlexpart.py	(revision d4696e0eebad213794352c454f011ba6dc050ddc)
@@ -106,5 +106,5 @@
         data.
 
-    basetime : str
+    basetime : int
         The time for a half day retrieval. The 12 hours upfront are to be
         retrieved.
@@ -276,8 +276,8 @@
         i = 0
         for ty, st, ti in zip(ftype, fstep, ftime):
-            btlist = range(24)
-            if self.basetime == '12':
+            btlist = range(len(ftime))
+            if self.basetime == 12:
                 btlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
-            if self.basetime == '00':
+            if self.basetime == 0:
                 btlist = [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0]
 
@@ -287,5 +287,5 @@
                  # (int(c.time[i]) in btlist or c.purefc):
 
-            if (int(ti) in btlist) or self.purefc:
+            if (i in btlist) or self.purefc:
 
                 if ((ty.upper() == 'AN' and (int(ti) % int(self.dtime)) == 0) or
@@ -305,4 +305,5 @@
                         self.types[ty]['steps'] += st
             i += 1
+
         return
 
@@ -708,5 +709,5 @@
 
     # ------  on demand path  --------------------------------------------------
-                if not self.basetime:
+                if self.basetime is None:
                     # ******* start retrievement
                     self._start_retrievement(request, retr_param_dict)
@@ -718,18 +719,10 @@
 
                     enddate = retr_param_dict['date'].split('/')[-1]
-                    elimit = datetime.strptime(enddate + self.basetime,
+                    elimit = datetime.strptime(enddate + str(self.basetime),
                                                '%Y%m%d%H')
 
-                    if self.basetime == '12':
+                    if self.basetime == 12:
                         # --------------  flux data ----------------------------
                         if 'acc' in pk:
-
-                        # Strategy:
-                        # if maxtime-elimit >= 24h reduce date by 1,
-                        # if 12h <= maxtime-elimit<12h reduce time for last date
-                        # if maxtime-elimit<12h reduce step for last time
-                        # A split of the MARS job into 2 is likely necessary.
-
-
                             startdate = retr_param_dict['date'].split('/')[0]
                             enddate = datetime.strftime(elimit - t24h,'%Y%m%d')
@@ -756,5 +749,5 @@
                             self._start_retrievement(request, retr_param_dict)
 
-                    else: # basetime = 0
+                    elif self.basetime == 0:
                         retr_param_dict['date'] = \
                             datetime.strftime(elimit - t24h, '%Y%m%d')
@@ -762,19 +755,23 @@
                         timesave = ''.join(retr_param_dict['time'])
 
-                        if '/' in retr_param_dict['time']:
+                        if ('/' in retr_param_dict['time'] and
+                            pk != 'OG_OROLSM__SL' and
+                            'acc' not in pk ) :
                             times = retr_param_dict['time'].split('/')
                             steps = retr_param_dict['step'].split('/')
-                            while (pk != 'OG_OROLSM__SL' and
-                                   'acc' not in pk and
-                                   (int(times[0]) + int(steps[0])) <= 12):
+                            print 'times', times, int(times[0]), times[1:]
+                            print 'steps', steps, int(steps[0])
+                            while int(times[0]) + int(steps[0]) <= 12:
+                                print 'HELLO'
                                 times = times[1:]
-
-                            if len(times) > 1:
-                                retr_param_dict['time'] = '/'.join(times)
-                            else:
-                                retr_param_dict['time'] = times[0]
-
-                        # ******* start retrievement
-                        self._start_retrievement(request, retr_param_dict)
+                                print 'in while 1 ', times
+
+                                if len(times) > 1:
+                                    retr_param_dict['time'] = '/'.join(times)
+                                else:
+                                    retr_param_dict['time'] = times[0]
+
+                                print 'in while 2 ', times
+                                print retr_param_dict['time']
 
                         if (pk != 'OG_OROLSM__SL' and
@@ -790,6 +787,9 @@
                                                     retr_param_dict['date'])
 
-                            # ******* start retrievement
-                            self._start_retrievement(request, retr_param_dict)
+                        # ******* start retrievement
+                        self._start_retrievement(request, retr_param_dict)
+                    else:
+                        raise ValueError('ERROR: Basetime has an invalid value '
+                                                 '-> {}'.format(str(basetime)))
 
         if request == 0 or request == 2:
@@ -985,5 +985,9 @@
             t_m1dt = t_date + timedelta(hours=step-int(c.dtime))
             t_m2dt = t_date + timedelta(hours=step-2*int(c.dtime))
-            t_enddate = None
+            if c.basetime is not None:
+                t_enddate = datetime.strptime(c.end_date + str(c.basetime),
+                                              '%Y%m%d%H')
+            else:
+                t_enddate = t_date + timedelta(2*int(c.dtime))
 
             if c.purefc:
@@ -1107,51 +1111,45 @@
                         codes_write(gid, f_handle)
 
-                        if c.basetime:
-                            t_enddate = datetime.strptime(c.end_date + c.basetime,
-                                                          '%Y%m%d%H')
-                        else:
-                            t_enddate = t_date + timedelta(2*int(c.dtime))
-
-                            # squeeze out information of last two steps
-                            # contained in deac_vals[parId]
-                            # Note that deac_vals[parId][0] has not been popped
-                            # in this case
-
-                            if step == c.maxstep and c.purefc or \
-                               t_dt == t_enddate:
-                                # last step
-                                if c.purefc:
-                                    values = deac_vals[parId][3]
-                                    codes_set_values(gid, values)
-                                    codes_set(gid, 'stepRange', step)
-                                    #truedatetime = t_m2dt + timedelta(hours=2*int(c.dtime))
-                                    codes_write(gid, h_handle)
-                                else:
-                                    values = deac_vals[parId][3]
-                                    codes_set_values(gid, values)
-                                    codes_set(gid, 'stepRange', 0)
-                                    truedatetime = t_m2dt + timedelta(hours=2*int(c.dtime))
-                                    codes_set(gid, 'time', truedatetime.hour * 100)
-                                    codes_set(gid, 'date', int(truedatetime.strftime('%Y%m%d')))
-                                    codes_write(gid, h_handle)
-
-                                if parId == 142 or parId == 143:
-                                    values = disaggregation.darain(list(reversed(deac_vals[parId])))
-                                else:
-                                    values = disaggregation.dapoly(list(reversed(deac_vals[parId])))
-
-                                # step before last step
-                                if c.purefc:
-                                    codes_set(gid, 'stepRange', step-int(c.dtime))
-                                    #truedatetime = t_m2dt + timedelta(hours=int(c.dtime))
-                                    codes_set_values(gid, values)
-                                    codes_write(gid, g_handle)
-                                else:
-                                    codes_set(gid, 'stepRange', 0)
-                                    truedatetime = t_m2dt + timedelta(hours=int(c.dtime))
-                                    codes_set(gid, 'time', truedatetime.hour * 100)
-                                    codes_set(gid, 'date', int(truedatetime.strftime('%Y%m%d')))
-                                    codes_set_values(gid, values)
-                                    codes_write(gid, g_handle)
+                        # squeeze out information of last two steps
+                        # contained in deac_vals[parId]
+                        # Note that deac_vals[parId][0] has not been popped
+                        # in this case
+
+                        if step == c.maxstep and c.purefc or \
+                           t_dt == t_enddate:
+                            # last step
+                            if c.purefc:
+                                values = deac_vals[parId][3]
+                                codes_set_values(gid, values)
+                                codes_set(gid, 'stepRange', step)
+                                #truedatetime = t_m2dt + timedelta(hours=2*int(c.dtime))
+                                codes_write(gid, h_handle)
+                            else:
+                                values = deac_vals[parId][3]
+                                codes_set_values(gid, values)
+                                codes_set(gid, 'stepRange', 0)
+                                truedatetime = t_m2dt + timedelta(hours=2*int(c.dtime))
+                                codes_set(gid, 'time', truedatetime.hour * 100)
+                                codes_set(gid, 'date', int(truedatetime.strftime('%Y%m%d')))
+                                codes_write(gid, h_handle)
+
+                            if parId == 142 or parId == 143:
+                                values = disaggregation.darain(list(reversed(deac_vals[parId])))
+                            else:
+                                values = disaggregation.dapoly(list(reversed(deac_vals[parId])))
+
+                            # step before last step
+                            if c.purefc:
+                                codes_set(gid, 'stepRange', step-int(c.dtime))
+                                #truedatetime = t_m2dt + timedelta(hours=int(c.dtime))
+                                codes_set_values(gid, values)
+                                codes_write(gid, g_handle)
+                            else:
+                                codes_set(gid, 'stepRange', 0)
+                                truedatetime = t_m2dt + timedelta(hours=int(c.dtime))
+                                codes_set(gid, 'time', truedatetime.hour * 100)
+                                codes_set(gid, 'date', int(truedatetime.strftime('%Y%m%d')))
+                                codes_set_values(gid, values)
+                                codes_write(gid, g_handle)
 
                 codes_release(gid)
@@ -1417,8 +1415,9 @@
             # if the timestamp is out of basetime start/end date period,
             # skip this specific product
-            if c.basetime:
-                start_time = datetime.strptime(c.end_date + c.basetime,
+            if c.basetime is not None:
+                time_delta = timedelta(hours=12-int(c.dtime))
+                start_time = datetime.strptime(c.end_date + str(c.basetime),
                                                 '%Y%m%d%H') - time_delta
-                end_time = datetime.strptime(c.end_date + c.basetime,
+                end_time = datetime.strptime(c.end_date + str(c.basetime),
                                              '%Y%m%d%H')
                 if timestamp < start_time or timestamp > end_time:
Index: source/python/mods/checks.py
===================================================================
--- source/python/mods/checks.py	(revision 6f951ca0346aa6a2c3e11ee62df85214a290d838)
+++ source/python/mods/checks.py	(revision d4696e0eebad213794352c454f011ba6dc050ddc)
@@ -587,5 +587,5 @@
     Parameters
     ----------
-    basetime : str
+    basetime : int or str or None
         The time for a half day retrieval. The 12 hours upfront are to be
         retrieved.
@@ -593,11 +593,14 @@
     Return
     ------
-
-    '''
-    if basetime:
-        if int(basetime) != 0 and int(basetime) != 12:
+    basetime : int or None
+        The time for a half day retrieval. The 12 hours upfront are to be
+        retrieved.
+    '''
+    if basetime is not None:
+        basetime = int(basetime)
+        if basetime != 0 and basetime != 12:
             raise ValueError('ERROR: Basetime has an invalid value '
                              '-> {}'.format(str(basetime)))
-    return
+    return basetime
 
 def check_request(request, marsfile):
@@ -667,8 +670,8 @@
         try:
             if len(ftype) == 1 and ftype[0] != 'AN':
-                print('Use same field type as for the non-flux fields.')
+                print('... Use same field type as for the non-flux fields.')
                 acctype = ftype[0]
             elif len(ftype) > 1 and ftype[1] != 'AN':
-                print('Use old setting by using TYPE[1] for flux forecast!')
+                print('... Use old setting by using TYPE[1] for flux forecast!')
                 acctype = ftype[1]
         except:
@@ -681,8 +684,8 @@
 
 
-def check_acctime(acctime, acctype, purefc):
+def check_acctime(acctime, marsclass, purefc):
     '''Guarantees that the accumulation forecast times were set.
 
-    If it is not set, it is tried to set the value fore some of the
+    If it is not set, it tries to set the value for some of the
     most commonly used data sets. Otherwise it raises an error.
 
@@ -692,6 +695,6 @@
         The starting time from the accumulated forecasts.
 
-    acctype : str
-        The field type for the accumulated forecast fields.
+    marsclass : str
+        ECMWF data classification identifier.
 
     purefc : int
@@ -703,15 +706,16 @@
         The starting time from the accumulated forecasts.
     '''
+
     if not acctime:
         print('... Control parameter ACCTIME was not defined.')
         print('... Value will be set depending on field type:\n '
-              '\t\t EA=06/18\n\t\t EI/OD=00/12\n\t\t  EP=18')
-        if acctype.upper() == 'EA': # Era 5
+              '\t\t EA=06/18\n\t\t EI/OD=00/12\n\t\t EP=18')
+        if marsclass.upper() == 'EA': # Era 5
             acctime = '06/18'
-        elif acctype.upper() == 'EI': # Era-Interim
+        elif marsclass.upper() == 'EI': # Era-Interim
             acctime = '00/12'
-        elif acctype.upper() == 'EP': # CERA
+        elif marsclass.upper() == 'EP': # CERA
             acctime = '18'
-        elif acctype.upper() == 'OD' and not purefc: # On-demand operational
+        elif marsclass.upper() == 'OD' and not purefc: # On-demand
             acctime = '00/12'
         else:
@@ -720,5 +724,5 @@
     return acctime
 
-def check_accmaxstep(accmaxstep, acctype, purefc, maxstep):
+def check_accmaxstep(accmaxstep, marsclass, purefc, maxstep):
     '''Guarantees that the accumulation forecast step were set.
 
@@ -728,6 +732,6 @@
         The maximum forecast step for the accumulated forecast fields.
 
-    acctype : str
-        The field type for the accumulated forecast fields.
+    marsclass : str
+        ECMWF data classification identifier.
 
     purefc : int
@@ -746,9 +750,9 @@
         print('... Control parameter ACCMAXSTEP was not defined.')
         print('... Value will be set depending on field type/time: '
-              '\t\t EA/EI/OD=12\n\t\t  EP=24')
-        if acctype.upper() in ['EA', 'EI', 'OD'] and not purefc:
+              '\n\t\t EA/EI/OD=12\n\t\t EP=24')
+        if marsclass.upper() in ['EA', 'EI', 'OD'] and not purefc:
             # Era 5, Era-Interim, On-demand operational
             accmaxstep = '12'
-        elif acctype.upper() == 'EP': # CERA
+        elif marsclass.upper() == 'EP': # CERA
             accmaxstep = '18'
         elif purefc and accmaxstep != maxstep:
Index: source/python/mods/get_mars_data.py
===================================================================
--- source/python/mods/get_mars_data.py	(revision 6f951ca0346aa6a2c3e11ee62df85214a290d838)
+++ source/python/mods/get_mars_data.py	(revision d4696e0eebad213794352c454f011ba6dc050ddc)
@@ -252,9 +252,8 @@
     chunk = timedelta(days=int(c.date_chunk))
 
-    if c.basetime:
-        if c.basetime == '00':
-            start = start - timedelta(days=1)
-
-    if not c.purefc and fluxes:
+    if c.basetime == 0:
+        start = start - timedelta(days=1)
+
+    if not c.purefc and fluxes and not c.basetime == 0:
         start = start - timedelta(days=1)
         end = end + timedelta(days=1)
Index: source/python/mods/prepare_flexpart.py
===================================================================
--- source/python/mods/prepare_flexpart.py	(revision 6f951ca0346aa6a2c3e11ee62df85214a290d838)
+++ source/python/mods/prepare_flexpart.py	(revision d4696e0eebad213794352c454f011ba6dc050ddc)
@@ -152,5 +152,5 @@
     # since we need the 12 hours upfront
     # (the day before from 12 UTC to current day 00 UTC)
-    if c.basetime == '00':
+    if c.basetime == 0:
         start = start - datetime.timedelta(days=1)
 
Index: source/python/mods/tools.py
===================================================================
--- source/python/mods/tools.py	(revision 6f951ca0346aa6a2c3e11ee62df85214a290d838)
+++ source/python/mods/tools.py	(revision d4696e0eebad213794352c454f011ba6dc050ddc)
@@ -147,5 +147,5 @@
     parser.add_argument("--basetime", dest="basetime",
                         type=none_or_int, default=None,
-                        help="base such as 00 or 12 (for half day retrievals)")
+                        help="base such as 0 or 12 (for half day retrievals)")
     parser.add_argument("--step", dest="step",
                         type=none_or_str, default=None,
@@ -162,4 +162,8 @@
                         type=none_or_int, default=None,
                         help="debug mode - leave temporary files intact")
+    parser.add_argument("--oper", dest="oper",
+                        type=none_or_int, default=None,
+                        help="operational mode - prepares dates with \
+                        environment variables")
     parser.add_argument("--request", dest="request",
                         type=none_or_int, default=None,
Index: source/python/submit.py
===================================================================
--- source/python/submit.py	(revision 6f951ca0346aa6a2c3e11ee62df85214a290d838)
+++ source/python/submit.py	(revision d4696e0eebad213794352c454f011ba6dc050ddc)
@@ -146,5 +146,5 @@
     '''
 
-    if not c.basetime:
+    if not c.oper:
     # --------- create on demand job script ------------------------------------
         if c.purefc:
@@ -196,5 +196,5 @@
         c.start_date = '${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}'
         c.end_date = '${MSJ_YEAR}${MSJ_MONTH}${MSJ_DAY}'
-        c.base_time = '${MSJ_BASETIME}'
+        c.basetime = '${MSJ_BASETIME}'
         if c.maxstep > 24:
             c.time = '${MSJ_BASETIME} {MSJ_BASETIME}'
