Index: source/python/_config.py
===================================================================
--- source/python/_config.py	(revision 0aaeb04b941d4c298b7dbc0b1c0f5407e88aad4a)
+++ source/python/_config.py	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -38,8 +38,9 @@
 TEMPFILE_INSTALL_COMPILEJOB = 'compilejob.template'
 FILE_INSTALL_COMPILEJOB = 'compilejob.ksh'
-TEMPFILE_INSTALL_JOB = 'job.temp.o'
+TEMPFILE_INSTALL_JOB = 'job.template'
 TEMPFILE_JOB = 'job.temp'
 FILE_JOB_OD = 'job.ksh'
 FILE_JOB_OP = 'jopoper.ksh'
+TEMPFILE_NAMELIST = 'convert.nl'
 FILE_NAMELIST = 'fort.4'
 FILE_GRIB_INDEX = 'date_time_stepRange.idx'
Index: source/python/classes/EcFlexpart.py
===================================================================
--- source/python/classes/EcFlexpart.py	(revision 0e576fcaf0dab8e7e586efa1a4b9b194ee90f8bb)
+++ source/python/classes/EcFlexpart.py	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -658,5 +658,5 @@
 
 
-    def write_namelist(self, c, filename):
+    def write_namelist(self, c):
         '''
         @Description:
@@ -683,4 +683,11 @@
         '''
 
+        from genshi.template.text import NewTextTemplate
+        from genshi.template import  TemplateLoader
+
+        loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False)
+        compile_template = loader.load(_config.TEMPFILE_NAMELIST,
+                                       cls=NewTextTemplate)
+
         self.inputdir = c.inputdir
         area = np.asarray(self.area.split('/')).astype(float)
@@ -692,25 +699,28 @@
         maxb = int((area[0] - area[2]) / grid[0]) + 1
 
-        with open(self.inputdir + '/' + filename, 'w') as f:
-            f.write('&NAMGEN\n')
-            f.write(',\n  '.join(['maxl = ' + str(maxl), 'maxb = ' + str(maxb),
-                                  'mlevel = ' + str(self.level),
-                                  'mlevelist = ' + '"' + str(self.levelist)
-                                                 + '"',
-                                  'mnauf = ' + str(self.resol),
-                                  'metapar = ' + '77',
-                                  'rlo0 = ' + str(area[1]),
-                                  'rlo1 = ' + str(area[3]),
-                                  'rla0 = ' + str(area[2]),
-                                  'rla1 = ' + str(area[0]),
-                                  'momega = ' + str(c.omega),
-                                  'momegadiff = ' + str(c.omegadiff),
-                                  'mgauss = ' + str(c.gauss),
-                                  'msmooth = ' + str(c.smooth),
-                                  'meta = ' + str(c.eta),
-                                  'metadiff = ' + str(c.etadiff),
-                                  'mdpdeta = ' + str(c.dpdeta)]))
-
-            f.write('\n/\n')
+        stream = compile_template.generate(
+            maxl = str(maxl),
+            maxb = str(maxb),
+            mlevel = str(self.level),
+            mlevelist = str(self.levelist),
+            mnauf = str(self.resol),
+            metapar = '77',
+            rlo0 = str(area[1]),
+            rlo1 = str(area[3]),
+            rla0 = str(area[2]),
+            rla1 = str(area[0]),
+            momega = str(c.omega),
+            momegadiff = str(c.omegadiff),
+            mgauss = str(c.gauss),
+            msmooth = str(c.smooth),
+            meta = str(c.eta),
+            metadiff = str(c.etadiff),
+            mdpdeta = str(c.dpdeta)
+        )
+
+        namelistfile = os.path.join(self.inputdir, _config.FILE_NAMELIST)
+
+        with open(namelistfile, 'w') as f:
+            f.write(stream.render('text'))
 
         return
Index: source/python/install.py
===================================================================
--- source/python/install.py	(revision 0aaeb04b941d4c298b7dbc0b1c0f5407e88aad4a)
+++ source/python/install.py	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -396,6 +396,6 @@
 
     stream = compile_template.generate(
+        usergroup = ecgid,
         username = ecuid,
-        usergroup = ecgid,
         version_number = _config._VERSION_STR,
         fp_root_scripts = fp_root,
@@ -410,34 +410,4 @@
         f.write(stream.render('text'))
 
-
-    # template = os.path.join(_config.PATH_REL_TEMPLATES,
-                            # _config.TEMPFILE_INSTALL_COMPILEJOB)
-    # with open(template) as f:
-        # fdata = f.read().split('\n')
-
-
-    # with open(compilejob, 'w') as fo:
-        # for data in fdata:
-            # if 'MAKEFILE=' in data:
-                # data = 'export MAKEFILE=' + makefile
-            # elif 'FLEXPART_ROOT_SCRIPTS=' in data:
-                # if fp_root != '../':
-                    # data = 'export FLEXPART_ROOT_SCRIPTS=' + fp_root
-                # else:
-                    # data = 'export FLEXPART_ROOT_SCRIPTS=$HOME'
-            # elif target.lower() != 'local':
-                # if '--workdir' in data:
-                    # data = '#SBATCH --workdir=/scratch/ms/' + \
-                            # ecgid + '/' + ecuid
-                # elif '##PBS -o' in data:
-                    # data = '##PBS -o /scratch/ms/' + ecgid + '/' + ecuid + \
-                           # 'flex_ecmwf.$Jobname.$Job_ID.out'
-                # elif 'FLEXPART_ROOT_SCRIPTS=' in data:
-                    # if fp_root != '../':
-                        # data = 'export FLEXPART_ROOT_SCRIPTS=' + fp_root
-                    # else:
-                        # data = 'export FLEXPART_ROOT_SCRIPTS=$HOME'
-            # fo.write(data + '\n')
-
     return
 
@@ -470,25 +440,28 @@
         <nothing>
     '''
-    fp_root_path_to_python = os.path.join(fp_root, _config.FLEXEXTRACT_DIRNAME,
-                         _config.PATH_REL_PYTHON)
-
-    template = os.path.join(_config.PATH_REL_TEMPLATES,
-                            _config.TEMPFILE_INSTALL_JOB)
-    with open(template) as f:
-        fdata = f.read().split('\n')
-
-    jobfile_temp = os.path.join(_config.PATH_REL_TEMPLATES,
-                                _config.TEMPFILE_JOB)
-    with open(jobfile_temp, 'w') as fo:
-        for data in fdata:
-            if '--workdir' in data:
-                data = '#SBATCH --workdir=/scratch/ms/' + ecgid + '/' + ecuid
-            elif '##PBS -o' in data:
-                data = '##PBS -o /scratch/ms/' + ecgid + '/' + \
-                        ecuid + 'flex_ecmwf.$Jobname.$Job_ID.out'
-            elif  'export PATH=${PATH}:' in data:
-                data += fp_root_path_to_python
-
-            fo.write(data + '\n')
+    from genshi.template.text import NewTextTemplate
+    from genshi.template import  TemplateLoader
+
+    loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False)
+    compile_template = loader.load(_config.TEMPFILE_INSTALL_JOB,
+                                   cls=NewTextTemplate)
+
+    fp_root_path_to_python = os.path.join(fp_root,
+                                          _config.FLEXEXTRACT_DIRNAME,
+                                          _config.PATH_REL_PYTHON)
+
+    stream = compile_template.generate(
+        usergroup = ecgid,
+        username = ecuid,
+        version_number = _config._VERSION_STR,
+        fp_root_path = fp_root_path_to_python,
+    )
+
+    tempjobfile = os.path.join(_config.PATH_TEMPLATES,
+                               _config.TEMPFILE_JOB)
+
+    with open(tempjobfile, 'w') as f:
+        f.write(stream.render('text'))
+
     return
 
Index: source/python/mods/prepare_flexpart.py
===================================================================
--- source/python/mods/prepare_flexpart.py	(revision 5bad6ecd8c2b5597cc84f56143c36adc3ad18530)
+++ source/python/mods/prepare_flexpart.py	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -160,5 +160,5 @@
     # deaccumulate the flux data
     flexpart = EcFlexpart(c, fluxes=True)
-    flexpart.write_namelist(c, _config.FILE_NAMELIST)
+    flexpart.write_namelist(c)
     flexpart.deacc_fluxes(inputfiles, c)
 
Index: source/pythontest/TestData/CONTROL.temp
===================================================================
--- source/pythontest/TestData/CONTROL.temp	(revision 25b14bea5de21f28364c210382513c1c9b792d61)
+++ source/pythontest/TestData/CONTROL.temp	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -9,5 +9,5 @@
 NUMBER OFF
 EXPVER 1
-GRID 5000  
+GRID 1000  
 LEFT -15000
 LOWER 30000
Index: source/pythontest/TestData/compilejob.test
===================================================================
--- source/pythontest/TestData/compilejob.test	(revision 0aaeb04b941d4c298b7dbc0b1c0f5407e88aad4a)
+++ source/pythontest/TestData/compilejob.test	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -17,5 +17,5 @@
 ##PBS -q ns
 ##PBS -S /usr/bin/ksh
-##PBS -o /scratch/ms/testgroup/testuser/flex_ecmwf.$Jobname.$Job_ID.out
+##PBS -o /scratch/ms/testgroup/testuser/flex_ecmwf.${Jobname}.${Job_ID}.out
 # job output is in .ecaccess_DO_NOT_REMOVE
 ##PBS -j oe
@@ -26,5 +26,5 @@
 set -x
 export VERSION=7.1
-case $HOST in
+case ${HOST} in
   *ecg*)
   module load python
@@ -43,26 +43,26 @@
   echo ${GROUP}
   echo ${HOME}
-  echo $HOME | awk -F / '{print $1, $2, $3, $4}'
-  export GROUP=`echo $HOME | awk -F / '{print $4}'`
+  echo ${HOME} | awk -F / '{print $1, $2, $3, $4}'
+  export GROUP=`echo ${HOME} | awk -F / '{print $4}'`
   export SCRATCH=/scratch/ms/${GROUP}/${USER}
-  export FLEXPART_ROOT_SCRIPTS=p_root_test_path
+  export FLEXPART_ROOT_SCRIPTS=fp_root_test_path
   export MAKEFILE=Makefile.TEST
   ;;
 esac
 
-mkdir -p $FLEXPART_ROOT_SCRIPTS/flex_extract_v$VERSION
-cd $FLEXPART_ROOT_SCRIPTS/flex_extract_v$VERSION   # if FLEXPART_ROOT is not set this means cd to the home directory
-tar -xvf $HOME/flex_extract_v$VERSION.tar
+mkdir -p ${FLEXPART_ROOT_SCRIPTS}/flex_extract_v${VERSION}
+cd ${FLEXPART_ROOT_SCRIPTS}/flex_extract_v${VERSION}   # if FLEXPART_ROOT is not set this means cd to the home directory
+tar -xvf ${HOME}/flex_extract_v${VERSION}.tar
 cd src
 \rm *.o *.mod CONVERT2 
-make -f $MAKEFILE >flexcompile 2>flexcompile
+make -f ${MAKEFILE} >flexcompile 2>flexcompile
 
 ls -l CONVERT2 >>flexcompile
 if [ $? -eq 0 ]; then
   echo 'SUCCESS!' >>flexcompile
-  mail -s flexcompile.$HOST.$$ $USER <flexcompile
+  mail -s flexcompile.${HOST}.$$ ${USER} <flexcompile
 else
   echo Environment: >>flexcompile
   env >> flexcompile
-  mail -s "ERROR! flexcompile.$HOST.$$" $USER <flexcompile
+  mail -s "ERROR! flexcompile.${HOST}.$$" ${USER} <flexcompile
 fi
Index: source/pythontest/TestData/convert.nl.test
===================================================================
--- source/pythontest/TestData/convert.nl.test	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
+++ source/pythontest/TestData/convert.nl.test	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -0,0 +1,19 @@
+&NAMGEN
+  maxl = 61,
+  maxb = 46,
+  mlevel = 60,
+  mlevelist = "55/to/60",
+  mnauf = 63,
+  metapar = 77,
+  rlo0 = -15.0,
+  rlo1 = 45.0,
+  rla0 = 30.0,
+  rla1 = 75.0,
+  momega = 0,
+  momegadiff = 0,
+  mgauss = 1,
+  msmooth = 0,
+  meta = 0,
+  metadiff = 0,
+  mdpdeta = 1
+/
Index: source/pythontest/TestData/job.temp.test
===================================================================
--- source/pythontest/TestData/job.temp.test	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
+++ source/pythontest/TestData/job.temp.test	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -0,0 +1,76 @@
+#!/bin/ksh
+
+# ON ECGB:
+# start with ecaccess-job-submit -queueName ecgb NAME_OF_THIS_FILE  on gateway server
+# start with sbatch NAME_OF_THIS_FILE directly on machine
+
+#SBATCH --workdir=/scratch/ms/testgroup/testuser
+#SBATCH --qos=normal
+#SBATCH --job-name=flex_ecmwf
+#SBATCH --output=flex_ecmwf.%j.out
+#SBATCH --error=flex_ecmwf.%j.out
+#SBATCH --mail-type=FAIL
+#SBATCH --time=12:00:00
+
+## CRAY specific batch requests
+##PBS -N flex_ecmwf
+##PBS -q np
+##PBS -S /usr/bin/ksh
+## -o /scratch/ms/testgroup/testuser/flex_ecmwf.${PBS_JOBID}.out
+## job output is in .ecaccess_DO_NOT_REMOVE
+##PBS -j oe
+##PBS -V
+##PBS -l EC_threads_per_task=24
+##PBS -l EC_memory_per_task=32000MB
+
+set -x
+export VERSION=7.1
+case ${HOST} in
+  *ecg*)
+  module load python
+  module unload grib_api
+  module unload emos
+  module load grib_api/1.14.5
+  module load emos/437-r64
+  export PATH=${PATH}:fp_root_test_path/flex_extract_v7.1/source/python
+  ;;
+  *cca*)
+  module switch PrgEnv-cray PrgEnv-intel
+  module load grib_api
+  module load emos
+  module load python
+  export SCRATCH=${TMPDIR}
+  export PATH=${PATH}:fp_root_test_path/flex_extract_v7.1/source/python
+  ;;
+esac
+
+cd ${SCRATCH}
+mkdir -p python$$
+cd python$$
+
+export CONTROL=CONTROL
+
+cat >${CONTROL}<<EOF
+EOF
+
+
+submit.py --controlfile=${CONTROL} --inputdir=./work --outputdir=./work 1> prot 2>&1
+
+if [ $? -eq 0 ] ; then
+  l=0
+  for muser in `grep -i MAILOPS ${CONTROL}`; do
+      if [ ${l} -gt 0 ] ; then 
+         mail -s flex.${HOST}.$$ ${muser} <prot
+      fi
+      l=$((${l}+1))
+  done
+else
+  l=0
+  for muser in `grep -i MAILFAIL ${CONTROL}`; do
+      if [ ${l} -gt 0 ] ; then 
+         mail -s "ERROR! flex.${HOST}.$$" ${muser} <prot
+      fi
+      l=$((${l}+1))
+  done
+fi
+
Index: source/pythontest/TestEcFlexpart.py
===================================================================
--- source/pythontest/TestEcFlexpart.py	(revision 25b14bea5de21f28364c210382513c1c9b792d61)
+++ source/pythontest/TestEcFlexpart.py	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -4,8 +4,13 @@
 
 import sys
+import os
+import inspect
 import pytest
 
 sys.path.append('../python')
+import _config
 from classes.EcFlexpart import EcFlexpart
+from classes.ControlFile import ControlFile
+from mods.tools import silent_remove
 
 class TestEcFlexpart():
@@ -13,12 +18,28 @@
     '''
 
-    def test_init(self):
-        # create an instance of EcFlexpart and get a dictionary of the
-        # class attributes, compare this dict with an expected dict!
-        assert True == True
+    def test_write_namelist(self):
+        import filecmp
 
-    def test_write_namelist(self):
-        # simple
-        assert True == True
+        control_file = os.path.join(_config.PATH_TEST_DIR,
+                                        'TestData',
+                                        'CONTROL.temp')
+        c = ControlFile(control_file)
+        flexpart = EcFlexpart(c)
+
+        c.inputdir = 'TestData'
+
+        # comparison file
+        testfile = os.path.join(_config.PATH_TEST_DIR,
+                                'TestData',
+                                'convert.nl.test')
+
+        # create
+        flexpart.write_namelist(c)
+
+        finalfile = os.path.join(c.inputdir, _config.FILE_NAMELIST)
+        assert filecmp.cmp(testfile, finalfile, shallow=False)
+
+        # delete test file
+        silent_remove(finalfile)
 
     def test_retrieve(self):
Index: source/pythontest/TestInstall.py
===================================================================
--- source/pythontest/TestInstall.py	(revision 0aaeb04b941d4c298b7dbc0b1c0f5407e88aad4a)
+++ source/pythontest/TestInstall.py	(revision c5074d295840f29091c45f8333ce650ad2a25ccd)
@@ -25,6 +25,6 @@
     #!    - un_tarball
     #!    - mk_env_vars
-    #    - mk_compilejob
-    #    - mk_job_template
+    #!    - mk_compilejob
+    #!    - mk_job_template
     #    - delete_convert_build
     #    - make_convert_build
@@ -155,2 +155,24 @@
         # delete test file
         silent_remove(finalfile)
+
+    def test_mk_job_template(self):
+        import filecmp
+
+        # comparison file
+        testfile = os.path.join(_config.PATH_TEST_DIR,
+                                'TestData',
+                                'job.temp.test')
+
+        # create
+        install.mk_job_template('testuser',
+                                'testgroup',
+                                'gateway.test.ac.at',
+                                'dest@generic',
+                                'fp_root_test_path')
+
+        finalfile = os.path.join(_config.PATH_TEMPLATES,
+                                 _config.TEMPFILE_JOB)
+        assert filecmp.cmp(testfile, finalfile, shallow=False)
+
+        # delete test file
+        silent_remove(finalfile)
