Index: python/README.md
===================================================================
--- python/README.md	(revision 70166b972494df8d3180bf2ac4177fb8f0df754e)
+++ python/README.md	(revision 5d3d09ba3e575ebfc3c6f1527d83e2d7f4e274d5)
@@ -1,22 +1,167 @@
-#README #
-
-This documentation shows how to use these python scripts to extract ECMWF data and generate the ***FLEXPART*** specific input files.
-
-### Introduction ###
-
-To run ***FLEXPART*** with ECMWF data, you first need to retrieve ECMWF GRIB fields and generate ***FLEXPART*** specific input files afterwards. ***FLEXPART*** needs the GRIB data seperated by time so that flex_extract will combine all data in output files seperated for each time step. The format of these output filenames looks like: `prefixYYMMDDHH`, where prefix can be defined in ***flex_extract*** (usually it should be limited to "2" characters because of further processing reasons).
+#README
+
+This documentation shows how to install and use the ***flex_extract*** software package to extract ECMWF data and generate the ***FLEXPART*** specific input files. 
+
+Introduction 
+=================
+
+To run ***FLEXPART*** with ECMWF data, you first need to retrieve ECMWF GRIB fields and generate ***FLEXPART*** specific input files afterwards. ***FLEXPART*** needs the GRIB data seperated by time so that ***flex_extract*** will combine all data in output files seperated for each time step. The format of these output filenames looks like: `prefixYYMMDDHH`, where prefix can be defined in ***flex_extract*** (usually it should be limited to "2" characters because of further processing reasons).
+
+There are 4 different modes of running ***flex_extract*** :
+1. Remote (**): ***flex_extract*** is installed and executed directly on the ECMWF Linux member state server ecgate. Users have to be a registered member-state user.
+2. Gateway (**): ***flex_extract*** is installed on a local machine and the scripts are submitted to ECMWF
+computer facilities via a member-state gateway server. Users have to be a registered member-state user.
+3. Local member state (**): ***flex_extract*** is installed and executed on a local machine. Users have to be a registered member-state user.
+4. Local public (***): ***flex_extract*** is installed and executed on a local machine. Users do not have to be a member-state user. A normal registration at the ECMWF website is enough. See also the instruction to install the ECMWF Web API
+
+*(\*\*) To get a ms (member-state) user access, users have to be a resident of a [member state](https://www.ecmwf.int/en/about/who-we-are/member-states) and have to contact their national meteorological center for granting access.*
+
+*(\*\*\*) To get a public user account, the user can just register at the ECMWF website following the instructions [here](https://software.ecmwf.int/wiki/display/WEBAPI/ECMWF+Web+API+Home)!*
 
 For setting up a complete ***FLEXPART*** environment it is recommended to build a directory structure such as:
 
- ![FLEXPART directory structure](../docs/Fp_extract_strukt-pngnew.png)
+ ![FLEXPART directory structure](../docs/Fp_extract_strukt.png)
 
 For installation instructions and usage of ***FLEXPART*** please see ***FLEXPART***-Documentation!
 
-### Overview ###
-
-%-- list all files in python dir and shortly explain structure
-
-##### CONTROL file #####
-For specifying which ECMWF dataset you would like to retrieve and which time and spatial resolution you would like to retrieve you have to prepare a `CONTROL` file. In the directory you can find a couple of example `CONTROL` files:
+Data sets archived at ECMWF
+===========================
+
+There are two modes for accessing ECMWF data sets: the **_full access_** and the **_public access_** mode.
+A description of these two modes and links to the available data sets is available here: https://www.ecmwf.int/en/forecasts/datasets/archive-datasets
+
+####  Important note for public users
+
+If you want to extract public data sets from the ECMWF servers you first have to register at the ECMWF. Do this by following the instructions at: https://software.ecmwf.int/wiki/display/WEBAPI/Access+MARS
+
+Afterwards you **_need to accept the licenses_** of the data sets you want to extract: 
+
+https://software.ecmwf.int/wiki/display/WEBAPI/Available+ECMWF+Public+Datasets
+
+Now your able to use ***flex_extract*** in public mode (command line parameter "*--public=1*"). 
+
+Installation
+===================
+
+### Some important notes for the installation process:
+- Use the same compiler and compiler version for all libraries and the fortran program.
+- Don't forget to set all library paths to the LD_LIBRARY_PATH variable.
+- Don't forget to adapt the makefile for the Fortran program.
+
+### Requirements ###
+
+| Python Support        | Link            | Notes |
+| --------------------- |:----------------------:|:-------------------------|
+| python                | [http://www.python.org](http://www.python.org)  | We have used [Anaconda python](https://store.continuum.io/cshop/anaconda/) for our testing |
+| python-numpy          | [http://www.numpy.org/](http://www.numpy.org/)  | Not necessary if you have installed python Anaconda
+| ecmwfapi              | [https://software.ecmwf.int/wiki/display/WEBAPI/ECMWF+Web+API+Home](https://software.ecmwf.int/wiki/display/WEBAPI/ECMWF+Web+API+Home) | You also need to install your API key (as explained in the documentation)
+
+| Utilities             | Link            | Notes |
+| --------------------- |:----------------------:|:-------------------------|
+|gfortran|[https://gcc.gnu.org/wiki/GFortran](https://gcc.gnu.org/wiki/GFortran)| Make sure that you are using the same compiler version for all libraries in connection with flex_extract, GRIB_API and FLEXPART, otherwise you will have problems.|
+|  grib-api or eccodes             | [https://software.ecmwf.int/wiki/display/GRIB/Home](https://software.ecmwf.int/wiki/display/GRIB/Home) / [https://software.ecmwf.int/wiki/display/ECC](https://software.ecmwf.int/wiki/display/ECC) | Make sure you install grib_api/eccodes with JPEG support and python.|
+|FFTW|[http://www.fftw.org](http://www.fftw.org)|This is needed by the Emos library, as is mentioned in the installation instructions for Emos|
+|  Emos                 | [https://software.ecmwf.int/wiki/display/EMOS/Emoslib](https://software.ecmwf.int/wiki/display/EMOS/Emoslib) | Make sure you carefully read the instructions and have installed the FFTW package before installing Emos.|
+| CONVERT2     | |to run prepareFLEXPART.py, you need to compile the Fortran program CONVERT2 (located in the src directory). See separate README file in this directory to get instructions on how to compile this code.|
+
+###  Prepare the environment for using ***flex_extract*** on a local machine
+
+Please follow the instructions on the websites of the libraries. The installation of these libraries can be done by package installation or from scratch, for either case it is useful to consider the official documentation (and also the hints from the ECMWF) rather than trying to explain every detail in here. Nevertheless, we recommend doing the installation in the following order (see links to the libraries in the table above):
+
+1. Read Emoslib installation instructions.
+2. Read ECMWF blog about gfortran (https://software.ecmwf.int/wiki/display/SUP/2015/05/11/Building+ECMWF+software+with+gfortran).
+3. Install FFTW.
+4. Install EMOSLIB (Hint: Apply make 2 times! One time without any options and one time with single precision option.).
+5. Install ECCODES OR GRIB_API (for python and fortran). ECCODES is downward compatible with GRIB_API and GRIB_API support will expire at the end of 2018.
+6. Register at Mars (see link to ecmwfapi). 
+7. Install ECMWF_WEBAPI.
+8. Check LD_LIBRARY_PATH environment variable if it contains all paths to the libs. 
+9. Check available python packages (e.g. check in python console the commands: import eccodes / import grib_api / import ecmwfapi)
+10. Start a simple test retrieval (following the instructions at ECMWF Web API website). 
+11. Install ***flex_extract*** (see next section). 
+
+### Installation of ***flex_extract***
+
+To install ***flex_extract*** you have to go to the python directory and call the `install.py` script. It has the following options: 
+
+```
+usage: install.py [-h] [--target INSTALL_TARGET] [--makefile MAKEFILE]
+                  [--ecuid ECUID] [--ecgid ECGID] [--gateway GATEWAY]
+                  [--destination DESTINATION]
+                  [--flexpart_root_scripts FLEXPART_ROOT_SCRIPTS]
+                  [--job_template JOB_TEMPLATE] [--controlfile CONTROLFILE]
+
+Install flex_extract software locally or on ECMWF machines
+
+optional arguments:
+  -h, --help            show this help message and exit
+  --target INSTALL_TARGET
+                        Valid targets: local | ecgate | cca , the latter two
+                        are at ECMWF (default: None)
+  --makefile MAKEFILE   Name of Makefile to use for compiling CONVERT2
+                        (default: None)
+  --ecuid ECUID         user id at ECMWF (default: None)
+  --ecgid ECGID         group id at ECMWF (default: None)
+  --gateway GATEWAY     name of local gateway server (default: None)
+  --destination DESTINATION
+                        ecaccess destination, e.g. leo@genericSftp (default:
+                        None)
+  --flexpart_root_scripts FLEXPART_ROOT_SCRIPTS
+                        FLEXPART root directory on ECMWF servers (to find
+                        grib2flexpart and COMMAND file) Normally flex_extract
+                        resides in the scripts directory of the FLEXPART
+                        distribution, thus the: (default: None)
+  --job_template JOB_TEMPLATE
+                        job template file for submission to ECMWF (default:
+                        job.temp.o)
+  --controlfile CONTROLFILE
+                        file with control parameters (default: CONTROL.temp)
+```
+
+
+#### Local installation of ***flex_extract*** (***flex_extract*** modes 1 (on ECMWF servers), 3 and 4)
+
+---
+
+For a local installation of ***flex_extract*** the user has to adapt the makefile for the Fortran program first. Set the paths to the grib_api or eccodes library and emoslib. Then the installation script should be called as follows:
+
+```
+./install.py --target=local --makefile=Makefile.local.gfortan
+```
+
+where the makefile name can differ if the user prepared another makefile for his environment. 
+On ECMWF servers a makefile named "Makefile.gfortran" is already provided in the "src"-directory. It is also the default makefile, so that the parameter does not have to be set when calling "install.py".
+
+If the ***flex_extract*** is to be installed within a ***FLEXPART*** environment it should be called with the parameter `flexpart_root_scripts` to let ***flex_extract*** know about the path to ***FLEXPART***.
+
+The installation was successful if the compilation of the Fortran program ``CONVERT2`` didn't fail and is displayed in the terminal. 
+
+#### Installation using a gateway server (***flex_extract*** mode 2 only)
+
+---
+
+If the user has a gateway server and the Ecaccess toolkit available, ***flex_extract*** can be installed such that it is executed on the local machine and a job script is submitted to the ECMWF server. The final ***FLEXPART*** input files are then send back via the Ecaccess command line tool "ectrans". To use this tool, the user has to create an association directly on the local gateway server via the localhost ecaccess.ecmwf.int and provide the association name as the "destination"-parameter when calling "install.py". 
+
+The gateway server has to be registered at ECMWF. For information about a gateway server see: 
+- https://software.ecmwf.int/wiki/display/ECAC/Releases+-+Gateway+package
+- and the Software Installation Plan (SIP.pdf) in the docs/ directory.
+
+Afterwards ***flex_extract*** can be installed with the following command:
+```
+./install.py --target=local --makefile=Makefile.gfortan --ecuid=<id> --ecgid=<gid> --gateway=<servername> --destination=<destinationname>
+```
+
+If the installation was successful the user gets an email with a success note!
+
+
+Using ***flex_extract***
+===================
+
+This section provides the absolut basics on how ***flex_extract*** is to be used. For more information about possible settings, performance, parameter combinations and so one, the user is referred to the SIP.pdf and SUT.pdf documents and the www.flexpart.eu community website. It is also possible to ask for help by writing to the ***FLEXPART*** user email list (registration needed) or by creating a ticket on the community website.
+
+#### CONTROL file 
+
+***flex_extract*** is controlled by providing "CONTROL"-files with a list of parameter settings. These parameter are described in detail in the *Software User Tutorial (SUT.pdf)*. 
+The "CONTROL"-files specifies which ECMWF data set is to be retrieved, the time and spatial resolution, the format of the grib file and many more. In the `python` directory are some example `CONTROL` files for the different data sets and access modes which can be retrieved with ***flex_extract***:
 
 ```
@@ -38,8 +183,14 @@
 ```
 
-#### Python scripts ####
-
-The main program for doing both, retrieving ECMWF data and generate the FLEXPART input files, is `submit.py`. It combines the two sub-programs `getMARSdata.py` and `prepareFLEXPART.py` which can also be run by themselves for example for debugging purposes.
-To get the usage of the program, use the `-h` option:
+For information about all the possible parameter settings and explanation, please see the SUT.pdf document in the `docs/` directory.
+
+`CONTROL`-files with a `.public` ending is usable for the public access mode. The main difference is the parameter ``dataset`` which explicitly specifies the public data sets. Additionally, not all meteorological fields and times were archived in the public data sets and are considered in the public `CONTROL`-files.
+
+#### Python scripts 
+
+* `submit.py`
+
+This is the main program for doing both, retrieving ECMWF data and generating the ***FLEXPART*** input files. It combines the two sub-programs `getMARSdata.py` and `prepareFLEXPART.py` which can also be run by themselves for debugging purposes.
+Use the `-h` option to get the parameter options:
 
 ```
@@ -88,11 +239,9 @@
   --debug DEBUG         Debug mode - leave temporary files intact (default: 0)
   --public PUBLIC       Public mode - retrieves the public datasets (default:
-                        False)
-```
-
-
-Optional arguments are listed in squared brackets.
-
-The sub-programs `getMARSdata.py` and `prepareFLEXPART.py` are the two main parts of this software.
+                        0)
+```
+
+*Optional arguments are listed in squared brackets.*
+
 
 * `getMARSdata.py`
@@ -103,104 +252,44 @@
 * `prepareFLEXPART.py`
 
-This program generates FLEXPART input files. It requires python interface to grib_api and the Fortran program `CONVERT2` (located in `src` directory with instruction on how to compile it). `CONVERT2` needs a namelist which is generated from the python program.
-
-
-### Requirements ###
-
-| Python Support        | Link            | Notes |
-| --------------------- |:----------------------:|:-------------------------|
-| python                | [http://www.python.org](http://www.python.org)  | We have used [Anaconda python](https://store.continuum.io/cshop/anaconda/) for our testing |
-| python-numpy          | [http://www.numpy.org/](http://www.numpy.org/)  | Not necessary if you have installed python Anaconda
-| ecmwfapi              | [https://software.ecmwf.int/wiki/display/WEBAPI/ECMWF+Web+API+Home](https://software.ecmwf.int/wiki/display/WEBAPI/ECMWF+Web+API+Home) | You also need to install your API key (as explained in the documentation)
-
-| Utilities             | Link            | Notes |
-| --------------------- |:----------------------:|:-------------------------|
-|gfortran|[https://gcc.gnu.org/wiki/GFortran](https://gcc.gnu.org/wiki/GFortran)| Make sure that you are using the same compiler version for all libraries in connection with flex_extract, GRIB_API and FLEXPART, otherwise you will have problems.|
-|  grib-api             | [https://software.ecmwf.int/wiki/display/GRIB/Home](https://software.ecmwf.int/wiki/display/GRIB/Home) | Make sure you install GRIB-API with JPEG support and python GRIB-API.|
-|FFTW|[http://www.fftw.org](http://www.fftw.org)|This is needed by the Emos library, as is mentioned in the installation instructions for Emos|
-|  Emos                 | [https://software.ecmwf.int/wiki/display/EMOS/Emoslib](https://software.ecmwf.int/wiki/display/EMOS/Emoslib) | Make sure you carefully read the instructions and have installed the FFTW package before installing Emos.|
-| CONVERT2     | |to run prepareFLEXPART.py, you need to compile the Fortragn program CONVERT2 (located in the src directory). See separate README file in this directory to get instructions on how to compile this code.|
-
-### Installation ###
-
-*  Environment
-
-At UIO, Red Hat 6 Linux systems (64 bits) were used for testing. We use the [Module package](http://modules.sourceforge.net/) to set-up user environment.
-
-* Getting the source code
-In the directory of your choice:
-
-`
-git clone git@bitbucket.org:flexpart/flexpart.git
-`
-This command will create a subdirectory called flexpart: it contains the latest FLEXPART version.
-
-Then set the environment variable `FLEXPART_ROOT`:
-
-** Korn-shell or Bash users:
-`
-cd flexpart
-export FLEXPART_ROOT=$PWD
-`
-
-** C-shell users:
-
-`
-cd flexpart
-setenv FLEXPART_ROOT=$PWD
-`
-
-* Installation
-
-Make sure you first generate the `CONVERT2` program (see separate instructions in `preproc/src`).
-
-Users need to be able to execute prepareFLEXPART.py and getMARSdata.py so make sure they have the correct unix permissions:
-
-`
-cd preproc/python
-chmod uog+rx getMARSdata.py prepareFLEXPART.py
-`
-
-These two programs must be in the user PATH. At UIO this is done automatically when loading flexpart. If not, you would need to do the following:
-
-** Korn-shell or Bash users:
-`
-export PATH=$FLEXPART_HOME/preproc/python:$PATH
-`
-
-** C-shell users:
-
-`
-setenv PATH $FLEXPART_HOME/preproc/python:$PATH
-`
-
-Where `$FLEXPART_HOME` is the directory where FLEXPART 
-
-* Testing your installation
-
-First check that grib-api python interface is correctly installed on your platform:
-`
-python
->>> from gribapi import *
->>>
-`
-Use `CTRL-D` to quit python.
-
-Then check that `ecmwfapi` is properly installed:
-`
-python
->>> from ecmwfapi import *
->>>
-`
-
-If the two previous tests were successful, you can run `tests/preproc` (See separate instructions in `tests/preproc`). 
-
-If any of these two tests fail, this probably means that either `ecmwfapi` or `grib-api` have not been installed properly. 
-
-Please report any problems.
-
-###  Installation FAQ ###
-
-
-
-
+This program generates FLEXPART input files from the retrieved meteorological fields. It requires python interface to grib_api or eccodes and the Fortran program `CONVERT2` (located in `src` directory). `CONVERT2` needs a namelist which is generated from the python program.
+
+#### execute flex_extract locally (member-state user)
+
+Almost every command line parameter for the `submit.py` script call has a default value or is read from the specified `CONTROL` file. 
+Therefore, for a local extraction of ERA-Interim data as a member-state user the script can be called simply by passing a `CONTROL` file and a starting date with the following command:
+```
+./submit.py --controlfile=CONTROL_EI.global --start_date=20101201
+```
+If there was just a starting date without an end date, ***flex_extract*** retrieves just this one day of meteorological data. The `CONTROL_EI.global` file has a set of default values which needs to be adjusted regarding users needs. It is also possible to set the dates within the `CONTROL`-file instead of passing it via command line parameter. 
+
+
+#### execute flex_extract locally (public user)
+
+As a public user one has to use the `CONTROL` file with the `.public` extension and the parameter `public`:
+```
+./submit.py --controlfile=CONTROL_EI.public --start_date=20101201 --public=1
+```
+Otherwise, except of the different data available, the usage of ***flex_extract*** is the same as for member-state users.
+
+#### execute flex_extract via gateway server
+
+If ***flex_extract*** was installed via a gateway server and a file "*ECMWF_ENV*" is available in the ``python``-directory, the ``submit.py`` script can be called with the `--queue` option. A job script is then prepared and submitted to the ECMWF server (in this case, "ecgate") .
+
+```
+./submit.py --queue=ecgate --controlfile=CONTROL_EI.global --start_date=20101201
+```
+
+The job status can then be checked by typing:
+````
+ecaccess-job-list
+```` 
+
+If the parameters *ecuid*, *ecgid*, *gateway* and *destination* were set correctly during installation and the gateway server is running, the resulting ***FLEXPART*** input files can be directly transferred to the local gateway by setting the paramter ``ectrans`` in the ``CONTROL``-file to ``1``.
+
+Regardless of the job being successful or not, the user will receive an email with the log messages. 
+
+#  Installation FAQ 
+
+
+
+
