Skip to content
Snippets Groups Projects
Commit ae2756e3 authored by Anne Philipp's avatar Anne Philipp
Browse files

added a check for the number parameter

parent 5364d08c
No related branches found
No related tags found
No related merge requests found
...@@ -58,7 +58,7 @@ from mods.checks import (check_grid, check_area, check_levels, check_purefc, ...@@ -58,7 +58,7 @@ from mods.checks import (check_grid, check_area, check_levels, check_purefc,
check_basetime, check_public, check_acctype, check_basetime, check_public, check_acctype,
check_acctime, check_accmaxstep, check_time, check_acctime, check_accmaxstep, check_time,
check_logicals_type, check_len_type_time_step, check_logicals_type, check_len_type_time_step,
check_addpar, check_job_chunk) check_addpar, check_job_chunk, check_number)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# CLASS # CLASS
...@@ -645,6 +645,8 @@ class ControlFile(object): ...@@ -645,6 +645,8 @@ class ControlFile(object):
self.job_chunk = check_job_chunk(self.job_chunk) self.job_chunk = check_job_chunk(self.job_chunk)
self.number = check_number(self.number, self.mailfail)
return return
def to_list(self): def to_list(self):
......
...@@ -29,6 +29,7 @@ import _config ...@@ -29,6 +29,7 @@ import _config
import exceptions import exceptions
from tools import my_error, silent_remove from tools import my_error, silent_remove
from datetime import datetime from datetime import datetime
import numpy as np
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
...@@ -824,3 +825,42 @@ def check_job_chunk(job_chunk): ...@@ -824,3 +825,42 @@ def check_job_chunk(job_chunk):
pass pass
return job_chunk return job_chunk
def check_number(number, mailfail):
'''Check for correct string format of ensemble member numbers.
Parameters
----------
number : str
List of ensemble member forecast runs.
mailfail : list of str
Contains all email addresses which should be notified.
It might also contain just the ecmwf user name which will trigger
mailing to the associated email address for this user.
Return
------
number : str
String with list of ensemble member forecast runs. E.g. '01/02/03/04'
'''
if '/' in number:
numbers = number.split('/')
if 'to' in number.lower() and 'by' in number.lower():
number = '{:0>3}'.format(int(numbers[0])) + '/TO/' + \
'{:0>3}'.format(int(numbers[2])) + '/BY/' + \
'{:0>3}'.format(int(numbers[4]))
elif 'to' in number.lower() and 'by' not in number.lower():
number = '{:0>3}'.format(int(numbers[0])) + '/TO/' + \
'{:0>3}'.format(int(numbers[2]))
else:
numbers = ['{:0>3}'.format(i) for i in numbers]
number = '{:0>3}/'.join(numbers)
elif number.isdigit():
number = '{:0>3}'.format(int(number))
else:
pass
return number
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment