From 4971f63213e5e9edb2e7e207ee071d404b6949f4 Mon Sep 17 00:00:00 2001 From: Anne Philipp <anne.philipp@univie.ac.at> Date: Thu, 27 Sep 2018 14:31:47 +0200 Subject: [PATCH] eliminated some redundancy and exchanged CONTROL2 with the config-filename --- source/python/classes/ControlFile.py | 14 +++++++++++--- source/python/classes/EcFlexpart.py | 16 ++++++++-------- source/python/install.py | 13 +------------ source/python/mods/get_mars_data.py | 10 +--------- source/python/mods/prepare_flexpart.py | 10 +--------- source/python/submit.py | 12 ++---------- 6 files changed, 24 insertions(+), 51 deletions(-) diff --git a/source/python/classes/ControlFile.py b/source/python/classes/ControlFile.py index 97e6989..21c12e2 100644 --- a/source/python/classes/ControlFile.py +++ b/source/python/classes/ControlFile.py @@ -179,9 +179,17 @@ class ControlFile(object): from mods.tools import my_error # read whole CONTROL file - with open(os.path.join(_config.PATH_CONTROLFILES, - self.controlfile)) as f: - fdata = f.read().split('\n') + + try: + with open(os.path.join(_config.PATH_CONTROLFILES, + self.controlfile)) as f: + fdata = f.read().split('\n') + except IOError: + print('Could not read CONTROL file "' + args.controlfile + '"') + print('Either it does not exist or its syntax is wrong.') + print('Try "' + sys.argv[0].split('/')[-1] + \ + ' -h" to print usage information') + sys.exit(1) # go through every line and store parameter for ldata in fdata: diff --git a/source/python/classes/EcFlexpart.py b/source/python/classes/EcFlexpart.py index 6f4fbae..cd9f8e9 100644 --- a/source/python/classes/EcFlexpart.py +++ b/source/python/classes/EcFlexpart.py @@ -806,7 +806,7 @@ class EcFlexpart(object): of "date", "time" and "stepRange" values. This is used to iterate over all messages in each grib file which were passed through the parameter "inputfiles" to seperate specific parameters into fort.* - files. Afterwards the FORTRAN program Convert2 is called to convert + files. Afterwards the FORTRAN program is called to convert the data fields all to the same grid and put them in one file per unique time step (combination of "date", "time" and "stepRange"). @@ -865,7 +865,7 @@ class EcFlexpart(object): # ( date ,time, step) # per date e.g. time = 0, 1200 # per time e.g. step = 3, 6, 9, 12 - # flag for Fortran program CONVERT2 and file merging + # flag for Fortran program and file merging convertFlag = False print('current prod: ', prod) # e.g. prod = ('20170505', '0', '12') @@ -883,8 +883,8 @@ class EcFlexpart(object): if gid is not None: # Combine all temporary data files into final grib file if # gid is at least one time not None. Therefore set convertFlag - # to save information. The fortran program CONVERT2 is also - # only done if convertFlag is True + # to save information. The Fortran program is also + # only executed if convertFlag is True convertFlag = True # remove old fort.* files and open new ones # they are just valid for a single product @@ -996,7 +996,7 @@ class EcFlexpart(object): for f in fdict.values(): f.close() - # call for CONVERT2 if flag is True + # call for Fortran program if flag is True if convertFlag: pwd = os.getcwd() os.chdir(c.inputdir) @@ -1008,9 +1008,9 @@ class EcFlexpart(object): is set to 1 in CONTROL file') # create the corresponding output file fort.15 - # (generated by CONVERT2) + fort.16 (paramId 167 and 168) - p = subprocess.check_call([os.path.join(c.exedir, 'CONVERT2')], - shell=True) + # (generated by Fortran program) + fort.16 (paramId 167 and 168) + p = subprocess.check_call([os.path.join( + c.exedir, _config.FORTRAN_EXECUTABLE)], shell=True) os.chdir(pwd) # create final output filename, e.g. EN13040500 (ENYYMMDDHH) diff --git a/source/python/install.py b/source/python/install.py index 9b0142d..da9ac58 100755 --- a/source/python/install.py +++ b/source/python/install.py @@ -77,19 +77,8 @@ def main(): <nothing> ''' - #os.chdir(_config.PATH_LOCAL_PYTHON) - args = get_install_cmdline_arguments() - - try: - c = ControlFile(args.controlfile) - except IOError: - print('Could not read CONTROL file "' + args.controlfile + '"') - print('Either it does not exist or its syntax is wrong.') - print('Try "' + sys.argv[0].split('/')[-1] + - ' -h" to print usage information') - exit(1) - + c = ControlFile(args.controlfile) c.assign_args_to_control(args) c.check_install_conditions() diff --git a/source/python/mods/get_mars_data.py b/source/python/mods/get_mars_data.py index 1ccdfa9..6d9677e 100755 --- a/source/python/mods/get_mars_data.py +++ b/source/python/mods/get_mars_data.py @@ -78,15 +78,7 @@ def main(): ''' args = get_cmdline_arguments() - - try: - c = ControlFile(args.controlfile) - except IOError: - print('Could not read CONTROL file "' + args.controlfile + '"') - print('Either it does not exist or its syntax is wrong.') - print('Try "' + sys.argv[0].split('/')[-1] + \ - ' -h" to print usage information') - sys.exit(1) + c = ControlFile(args.controlfile) env_parameter = read_ecenv(_config.PATH_ECMWF_ENV) c.assign_args_to_control(args, env_parameter) diff --git a/source/python/mods/prepare_flexpart.py b/source/python/mods/prepare_flexpart.py index 4ac0af8..2c28e07 100755 --- a/source/python/mods/prepare_flexpart.py +++ b/source/python/mods/prepare_flexpart.py @@ -88,15 +88,7 @@ def main(): ''' args = get_cmdline_arguments() - - try: - c = ControlFile(args.controlfile) - except IOError: - print('Could not read CONTROL file "' + args.controlfile + '"') - print('Either it does not exist or its syntax is wrong.') - print('Try "' + sys.argv[0].split('/')[-1] + \ - ' -h" to print usage information') - sys.exit(1) + c = ControlFile(args.controlfile) env_parameter = read_ecenv(_config.PATH_ECMWF_ENV) c.assign_args_to_control(args, env_parameter) diff --git a/source/python/submit.py b/source/python/submit.py index 9819583..acd69dc 100755 --- a/source/python/submit.py +++ b/source/python/submit.py @@ -76,15 +76,7 @@ def main(): ''' args = get_cmdline_arguments() - - try: - c = ControlFile(args.controlfile) - except IOError: - print('Could not read CONTROL file "' + args.controlfile + '"') - print('Either it does not exist or its syntax is wrong.') - print('Try "' + sys.argv[0].split('/')[-1] + \ - ' -h" to print usage information') - sys.exit(1) + c = ControlFile(args.controlfile) env_parameter = read_ecenv(_config.PATH_ECMWF_ENV) c.assign_args_to_control(args) @@ -94,7 +86,7 @@ def main(): # on local side # on ECMWF server this would also be the local side called_from_dir = os.getcwd() - if args.queue is None: + if not args.queue: if c.inputdir[0] != '/': c.inputdir = os.path.join(called_from_dir, c.inputdir) if c.outputdir[0] != '/': -- GitLab