Index: source/python/classes/ControlFile.py
===================================================================
--- source/python/classes/ControlFile.py	(revision ca867de340aa450bfbc241b4cae4e578464d6633)
+++ source/python/classes/ControlFile.py	(revision 5bad6ecd8c2b5597cc84f56143c36adc3ad18530)
@@ -114,4 +114,5 @@
         self.step = None
         self.marsclass = None
+        self.dataset = None
         self.stream = None
         self.number = 'OFF'
@@ -159,8 +160,9 @@
         self.debug = 0
         self.request = 0
+        self.public = 0
 
         self.logicals = ['gauss', 'omega', 'omegadiff', 'eta', 'etadiff',
                          'dpdeta', 'cwc', 'wrf', 'grib2flexpart', 'ecstorage',
-                         'ectrans', 'debug', 'request']
+                         'ectrans', 'debug', 'request', 'public']
 
         self.__read_controlfile__()
@@ -266,5 +268,5 @@
         import collections
 
-        attrs = vars(self)
+        attrs = vars(self).copy()
         attrs = collections.OrderedDict(sorted(attrs.items()))
 
@@ -454,4 +456,10 @@
                 setattr(self, var, int(getattr(self, var)))
 
+        if self.public and not self.dataset:
+            print('ERROR: ')
+            print('If public mars data wants to be retrieved, '
+                  'the "dataset"-parameter has to be set in the control file!')
+            sys.exit(1)
+
         return
 
@@ -524,5 +532,5 @@
         import collections
 
-        attrs = collections.OrderedDict(sorted(vars(self).items()))
+        attrs = collections.OrderedDict(sorted(vars(self).copy().items()))
 
         l = list()
Index: source/python/classes/EcFlexpart.py
===================================================================
--- source/python/classes/EcFlexpart.py	(revision ca867de340aa450bfbc241b4cae4e578464d6633)
+++ source/python/classes/EcFlexpart.py	(revision 5bad6ecd8c2b5597cc84f56143c36adc3ad18530)
@@ -89,5 +89,6 @@
 import _config
 from GribTools import GribTools
-from mods.tools import init128, to_param_id, silent_remove, product, my_error
+from mods.tools import (init128, to_param_id, silent_remove, product,
+                        my_error, make_dir)
 from MarsRetrieval import MarsRetrieval
 import mods.disaggregation as disaggregation
@@ -143,4 +144,5 @@
 
         self.inputdir = c.inputdir
+        self.dataset = c.dataset
         self.basetime = c.basetime
         self.dtime = c.dtime
@@ -338,7 +340,7 @@
                 Contains all parameter which have to be set for creating the
                 Mars Retrievals. The parameter are:
-                marsclass, stream, type, levtype, levelist, resol, gaussian,
-                accuracy, grid, target, area, date, time, number, step, expver,
-                param
+                marsclass, dataset, stream, type, levtype, levelist, resol,
+                gaussian, accuracy, grid, target, area, date, time, number,
+                step, expver, param
 
         @Return:
@@ -349,5 +351,7 @@
 
         MR = MarsRetrieval(self.server,
+                           self.public,
                            marsclass=par_dict['marsclass'],
+                           dataset=par_dict['dataset'],
                            stream=par_dict['stream'],
                            type=par_dict['type'],
@@ -439,5 +443,5 @@
 
 
-    def retrieve(self, server, dates, request, inputdir='.'):
+    def retrieve(self, server, dates, public, request, inputdir='.'):
         '''
         @Description:
@@ -477,4 +481,5 @@
         self.dates = dates
         self.server = server
+        self.public = public
         self.inputdir = inputdir
         oro = False
@@ -488,4 +493,5 @@
         # therefore be set in each request seperately
         retr_param_dict = {'marsclass':self.marsclass,
+                           'dataset':self.dataset,
                            'stream':None,
                            'type':None,
@@ -1265,5 +1271,5 @@
         # create Options dir if necessary
         if not os.path.exists(pwd + '/Options'):
-            os.makedirs(pwd+'/Options')
+            make_dir(pwd+'/Options')
 
         # read template COMMAND file
Index: source/python/classes/MarsRetrieval.py
===================================================================
--- source/python/classes/MarsRetrieval.py	(revision ca867de340aa450bfbc241b4cae4e578464d6633)
+++ source/python/classes/MarsRetrieval.py	(revision 5bad6ecd8c2b5597cc84f56143c36adc3ad18530)
@@ -83,8 +83,8 @@
     '''
 
-    def __init__(self, server, marsclass="ei", type="", levtype="",
-                 levelist="", repres="", date="", resol="", stream="",
-                 area="", time="", step="", expver="1", number="",
-                 accuracy="", grid="", gaussian="", target="",
+    def __init__(self, server, public, marsclass="ei", dataset="", type="",
+                 levtype="", levelist="", repres="", date="", resol="",
+                 stream="", area="", time="", step="", expver="1",
+                 number="", accuracy="", grid="", gaussian="", target="",
                  param=""):
         '''
@@ -106,8 +106,22 @@
                 It is needed for the pythonic access of ECMWF data.
 
+            public: integer
+                Decides which Web API version is used:
+                0: member-state users and full archive access
+                1: public access and limited access to the public server and
+                   datasets. Needs the parameter dataset.
+                Default is "0" and for member-state users.
+
             marsclass: string, optional
                 Characterisation of dataset. E.g. EI (ERA-Interim),
                 E4 (ERA40), OD (Operational archive), ea (ERA5).
                 Default is the ERA-Interim dataset "ei".
+
+            dataset: string, optional
+                For public datasets there is the specific naming and parameter
+                dataset which has to be used to characterize the type of
+                data. Usually there is less data available, either in times,
+                domain or parameter.
+                Default is an empty string.
 
             type: string, optional
@@ -289,5 +303,7 @@
 
         self.server = server
+        self.public = public
         self.marsclass = marsclass
+        self.dataset = dataset
         self.type = type
         self.levtype = levtype
@@ -325,10 +341,10 @@
         '''
         # Get all class attributes and their values as a dictionary
-        attrs = vars(self)
+        attrs = vars(self).copy()
 
         # iterate through all attributes and print them
         # with their corresponding values
         for item in attrs.items():
-            if item[0] in 'server':
+            if item[0] in ['server', 'public']:
                 pass
             else:
@@ -358,5 +374,5 @@
         '''
         # Get all class attributes and their values as a dictionary
-        attrs = vars(self)
+        attrs = vars(self).copy()
 
         # open a file to store all requests to
@@ -367,5 +383,5 @@
             # with their corresponding values
             for item in attrs.items():
-                if item[0] in 'server':
+                if item[0] in ['server', 'public']:
                     pass
                 else:
@@ -396,6 +412,7 @@
 
         # Get all class attributes and their values as a dictionary
-        attrs = vars(self)
+        attrs = vars(self).copy()
         del attrs['server']
+        del attrs['public']
 
         # open a file to store all requests to
@@ -425,40 +442,69 @@
         '''
         # Get all class attributes and their values as a dictionary
-        attrs = vars(self)
-
-        # convert the dictionary of attributes into a comma
-        # seperated list of attributes with their values
-        # needed for the retrieval call
-        s = 'ret'
-        for k, v in attrs.iteritems():
-            if k in 'server':
-                continue
-            if k == 'marsclass':
-                k = 'class'
-            if v == '':
-                continue
-            if k.lower() == 'target':
-                target = v
+        attrs = vars(self).copy()
+
+        # eliminate unnecessary attributes from the dictionary attrs
+        del attrs['server']
+        del attrs['public']
+
+        # exchange parameter name for marsclass
+        mclass = attrs.get('marsclass')
+        del attrs['marsclass']
+        attrs['class'] = mclass
+
+        # prepare target variable as needed for the Web API mode
+        # within the dictionary for full access
+        # as a single variable for public access
+        target = attrs.get('target')
+        if not int(self.public):
+            del attrs['target']
+        print('target: ' + target)
+
+        # find all keys without a value and convert all other values to strings
+        empty_keys = []
+        for key, value in attrs.itteritems():
+            if value == '':
+                empty_keys.append(str(key))
             else:
-                s = s + ',' + k + '=' + str(v)
+                attrs[key] = str(value)
+
+        # delete all empty parameter from the dictionary
+        for key in empty_keys:
+            del attrs[key]
 
         # MARS request via Python script
-        if self.server is not False:
+        if self.server:
             try:
-                self.server.execute(s, target)
+                if self.public:
+                    print('RETRIEVE PUBLIC DATA!')
+                    self.server.retrieve(attrs)
+                else:
+                    print('EXECUTE NON-PUBLIC RETRIEVAL!')
+                    self.server.execute(attrs, target)
             except:
-                print('MARS Request failed, \
-                      have you already registered at apps.ecmwf.int?')
+                e = sys.exc_info()[0]
+                print("ERROR: ", e)
+                print('MARS Request failed!')
+            if not self.public and os.stat(target).st_size == 0:
+                print('MARS Request returned no data - please check request')
                 raise IOError
-            if os.stat(target).st_size == 0:
-                print('MARS Request returned no data - please check request')
+            elif self.public and os.stat(target).st_size == 0:
+                print('Public MARS Request returned no data - '
+                      'please check request')
+                raise IOError
+            else:
                 raise IOError
         # MARS request via extra process in shell
         else:
-            s += ',target = "' + target + '"'
-            p = subprocess.Popen(['mars'], stdin=subprocess.PIPE,
+            request_str = 'ret'
+            for key, value in attrs.iteritems():
+                request_str = request_str + ',' + key + '=' + str(value)
+            request_str += ',target="' + target + '"'
+            p = subprocess.Popen(['mars'],
+                                 stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE,
-                                 stderr=subprocess.PIPE, bufsize=1)
-            pout = p.communicate(input=s)[0]
+                                 stderr=subprocess.PIPE,
+                                 bufsize=1)
+            pout = p.communicate(input=request_str)[0]
             print(pout.decode())
 
@@ -466,8 +512,9 @@
                 print('MARS Request failed - please check request')
                 raise IOError
-
-            if os.stat(target).st_size == 0:
+            elif os.stat(target).st_size == 0:
                 print('MARS Request returned no data - please check request')
                 raise IOError
+            else:
+                raise
 
         return
Index: source/python/mods/get_mars_data.py
===================================================================
--- source/python/mods/get_mars_data.py	(revision ca867de340aa450bfbc241b4cae4e578464d6633)
+++ source/python/mods/get_mars_data.py	(revision 5bad6ecd8c2b5597cc84f56143c36adc3ad18530)
@@ -54,5 +54,6 @@
 sys.path.append('../')
 import _config
-from tools import my_error, normal_exit, get_cmdline_arguments, read_ecenv
+from tools import (my_error, normal_exit, get_cmdline_arguments,
+                   read_ecenv, make_dir)
 from classes.EcFlexpart import EcFlexpart
 from classes.UioFiles import UioFiles
@@ -114,5 +115,5 @@
 
     if not os.path.exists(c.inputdir):
-        os.makedirs(c.inputdir)
+        make_dir(c.inputdir)
 
     if c.request == 0 or c.request == 2:
@@ -125,5 +126,8 @@
 
     if ecapi:
-        server = ecmwfapi.ECMWFService("mars")
+        if c.public:
+            server = ecmwfapi.ECMWFDataServer()
+        else:
+            server = ecmwfapi.ECMWFService("mars")
     else:
         server = False
@@ -254,5 +258,5 @@
 
         try:
-            flexpart.retrieve(server, dates, c.request, c.inputdir)
+            flexpart.retrieve(server, dates, c.public, c.request, c.inputdir)
         except IOError:
             my_error(c.mailfail, 'MARS request failed')
Index: source/python/mods/prepare_flexpart.py
===================================================================
--- source/python/mods/prepare_flexpart.py	(revision ca867de340aa450bfbc241b4cae4e578464d6633)
+++ source/python/mods/prepare_flexpart.py	(revision 5bad6ecd8c2b5597cc84f56143c36adc3ad18530)
@@ -63,5 +63,5 @@
 from classes.UioFiles import UioFiles
 from classes.ControlFile import ControlFile
-from tools import clean_up, get_cmdline_arguments, read_ecenv
+from tools import clean_up, get_cmdline_arguments, read_ecenv, make_dir
 from classes.EcFlexpart import EcFlexpart
 
@@ -153,5 +153,5 @@
     # create output dir if necessary
     if not os.path.exists(c.outputdir):
-        os.makedirs(c.outputdir)
+        make_dir(c.outputdir)
 
     # get all files with flux data to be deaccumulated
Index: source/python/mods/tools.py
===================================================================
--- source/python/mods/tools.py	(revision ca867de340aa450bfbc241b4cae4e578464d6633)
+++ source/python/mods/tools.py	(revision 5bad6ecd8c2b5597cc84f56143c36adc3ad18530)
@@ -139,4 +139,7 @@
                         help="list all mars request in file mars_requests.dat \
                         and skip submission to mars")
+    parser.add_argument("--public", dest="public",
+                        type=none_or_int, default=None,
+                        help="public mode - retrieves the public datasets")
 
     # some arguments that override the default in the CONTROL file
