Changeset 145fbe0 in flex_extract.git for source/python/classes/ControlFile.py


Ignore:
Timestamp:
Dec 13, 2018, 11:52:36 PM (5 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
092aaf1
Parents:
268ee86
Message:

outsourced the checks on control variables; changed variables for flexpart and flexextract directory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/python/classes/ControlFile.py

    re5884c9 r145fbe0  
    5656import sys
    5757import inspect
     58import numpy as np
    5859
    5960# software specific classes and modules from flex_extract
     
    6162import _config
    6263from mods.tools import my_error, silent_remove
    63 from mods.checks import check_grid, check_area, check_levels, check_purefc
     64from mods.checks import (check_grid, check_area, check_levels, check_purefc,
     65                         check_step, check_mail, check_queue, check_pathes,
     66                         check_dates, check_maxstep, check_type, check_request,
     67                         check_basetime, check_public, check_acctype,
     68                         check_acctime, check_accmaxstep, check_time,
     69                         check_logicals_type, check_len_type_time_step,
     70                         check_addpar)
    6471
    6572# ------------------------------------------------------------------------------
     
    137144        self.inputdir = _config.PATH_INPUT_DIR
    138145        self.outputdir = None
    139         self.ecmwfdatadir = _config.PATH_FLEXEXTRACT_DIR
     146        self.flexextractdir = _config.PATH_FLEXEXTRACT_DIR
    140147        self.exedir = _config.PATH_FORTRAN_SRC
    141         self.flexpart_root_scripts = None
     148        self.flexpartdir = None
    142149        self.makefile = 'Makefile.gfortran'
    143150        self.destination = None
     
    196203                if data[0].lower() == 'day2':
    197204                    data[0] = 'end_date'
    198                 if data[0].lower() == 'addpar':
    199                     if '/' in data[1]:
    200                         # remove leading '/' sign from addpar content
    201                         if data[1][0] == '/':
    202                             data[1] = data[1][1:]
    203                         dd = data[1].split('/')
    204                         data = [data[0]]
    205                         for d in dd:
    206                             data.append(d)
    207205                if len(data) == 2:
    208206                    if '$' in data[1]:
     
    325323
    326324        '''
    327         from mods.tools import my_error
    328         import numpy as np
    329 
    330         # check for having at least a starting date
    331         # otherwise program is not allowed to run
    332         if not self.start_date:
    333             print('start_date specified neither in command line nor '
    334                   'in CONTROL file ' +  self.controlfile)
    335             print('Try "' + sys.argv[0].split('/')[-1] +
    336                   ' -h" to print usage information')
    337             sys.exit(1)
    338 
    339         # retrieve just one day if end_date isn't set
    340         if not self.end_date:
    341             self.end_date = self.start_date
    342 
    343         # basetime has only two possible values
    344         if self.basetime:
    345             if int(self.basetime) != 0 and int(self.basetime) != 12:
    346                 print('Basetime has an invalid value!')
    347                 print('Basetime = ' + str(self.basetime))
    348                 sys.exit(1)
     325        check_logicals_type(self, self.logicals)
     326
     327        self.mailfail = check_mail(self.mailfail)
     328
     329        self.mailops = check_mail(self.mailops)
     330
     331        check_queue(queue, self.gateway, self.destination,
     332                    self.ecuid, self.ecgid)
     333
     334        self.outputdir, self.flexpartdir = check_pathes(self.inputdir,
     335             self.outputdir, self.flexpartdir, self.flexextractdir)
     336
     337        self.start_date, self.end_date = check_dates(self.start_date,
     338                                                     self.end_date)
     339
     340        check_basetime(self.basetime)
    349341
    350342        self.levelist, self.level = check_levels(self.levelist, self.level)
    351343
    352         # # assure consistency of levelist and level
    353         # if not self.levelist and not self.level:
    354             # print('Warning: neither levelist nor level \
    355                                # specified in CONTROL file')
    356             # sys.exit(1)
    357         # elif not self.levelist and self.level:
    358             # self.levelist = '1/to/' + self.level
    359         # elif (self.levelist and not self.level) or \
    360              # (self.levelist[-1] != self.level[-1]):
    361             # self.level = self.levelist.split('/')[-1]
    362         # else:
    363             # pass
    364 
    365         # # check if max level is a valid level
    366         # if int(self.level) not in _config.MAX_LEVEL_LIST:
    367             # print('ERROR: ')
    368             # print('LEVEL must be the maximum level of a specified '
    369                   # 'level list from ECMWF, e.g.')
    370             # print(_config.MAX_LEVEL_LIST)
    371             # print('Check parameter "LEVEL" or the max level of "LEVELIST"!')
    372             # sys.exit(1)
    373 
    374         # prepare step list if "/" signs are found
    375         if '/' in self.step:
    376             steps = self.step.split('/')
    377             if 'to' in self.step.lower() and 'by' in self.step.lower():
    378                 ilist = np.arange(int(steps[0]),
    379                                   int(steps[2]) + 1,
    380                                   int(steps[4]))
    381                 self.step = ['{:0>3}'.format(i) for i in ilist]
    382             elif 'to' in self.step.lower() and 'by' not in self.step.lower():
    383                 my_error(self.mailfail, self.step + ':\n' +
    384                          'if "to" is used in steps parameter, '
    385                          'please use "by" as well')
    386             else:
    387                 self.step = steps
    388 
    389         # if maxstep wasn't provided
    390         # search for it in the "step" parameter
    391         if not self.maxstep:
    392             self.maxstep = 0
    393             for s in self.step:
    394                 if int(s) > self.maxstep:
    395                     self.maxstep = int(s)
    396         else:
    397             self.maxstep = int(self.maxstep)
    398 
    399         # set root scripts since it is needed later on
    400         if not self.flexpart_root_scripts:
    401             self.flexpart_root_scripts = self.ecmwfdatadir
    402 
    403         if not self.outputdir:
    404             self.outputdir = self.inputdir
    405 
    406         if not isinstance(self.mailfail, list):
    407             if ',' in self.mailfail:
    408                 self.mailfail = self.mailfail.split(',')
    409             elif ' ' in self.mailfail:
    410                 self.mailfail = self.mailfail.split()
    411             else:
    412                 self.mailfail = [self.mailfail]
    413 
    414         if not isinstance(self.mailops, list):
    415             if ',' in self.mailops:
    416                 self.mailops = self.mailops.split(',')
    417             elif ' ' in self.mailops:
    418                 self.mailops = self.mailops.split()
    419             else:
    420                 self.mailops = [self.mailops]
    421 
    422         if queue in _config.QUEUES_LIST and \
    423            not self.gateway or not self.destination or \
    424            not self.ecuid or not self.ecgid:
    425             print('\nEnvironment variables GATEWAY, DESTINATION, ECUID and '
    426                   'ECGID were not set properly!')
    427             print('Please check for existence of file "ECMWF_ENV" in the '
    428                   'python directory!')
    429             sys.exit(1)
    430 
    431         if self.request != 0:
    432             marsfile = os.path.join(self.inputdir,
    433                                     _config.FILE_MARS_REQUESTS)
    434             if os.path.isfile(marsfile):
    435                 silent_remove(marsfile)
    436 
    437         # check all logical variables for data type
    438         # if its a string change to integer
    439         for var in self.logicals:
    440             if not isinstance(getattr(self, var), int):
    441                 setattr(self, var, int(getattr(self, var)))
    442 
    443         if self.public and not self.dataset:
    444             print('ERROR: ')
    445             print('If public mars data wants to be retrieved, '
    446                   'the "dataset"-parameter has to be set in the control file!')
    447             sys.exit(1)
    448 
    449         if not isinstance(self.type, list):
    450             self.type = [self.type]
    451 
    452         for i, val in enumerate(self.type):
    453             if self.type[i] == 'AN' and int(self.step[i]) != 0:
    454                 print('Analysis retrievals must have STEP = 0 (is set to 0)')
    455                 self.type[i] = 0
    456 
    457         if not isinstance(self.time, list):
    458             self.time = [self.time]
    459 
    460         if not isinstance(self.step, list):
    461             self.step = [self.step]
    462 
    463         if not self.acctype:
    464             print('... Control paramter ACCTYPE was not defined.')
    465             try:
    466                 if len(self.type) > 1 and self.type[1] != 'AN':
    467                     print('Use old setting by using TYPE[1] for flux forecast!')
    468                     self.acctype = self.type[1]
    469             except:
    470                 print('Use default value "FC" for flux forecast!')
    471                 self.acctype='FC'
    472 
    473         if not self.acctime:
    474             print('... Control paramter ACCTIME was not defined.')
    475             print('Use default value "00/12" for flux forecast!')
    476             self.acctime='00/12'
    477 
    478         if not self.accmaxstep:
    479             print('... Control paramter ACCMAXSTEP was not defined.')
    480             print('Use default value "12" for flux forecast!')
    481             self.accmaxstep='12'
     344        self.step = check_step(self.step, self.mailfail)
     345
     346        self.maxstep = check_maxstep(self.maxstep, self.step)
     347
     348        check_request(self.request,
     349                      os.path.join(self.inputdir, _config.FILE_MARS_REQUESTS))
     350
     351        check_public(self.public, self.dataset)
     352
     353        self.type = check_type(self.type, self.step)
     354
     355        self.time = check_time(self.time)
     356
     357        self.type, self.time, self.step = check_len_type_time_step(self.type,
     358                                                                   self.time,
     359                                                                   self.step,
     360                                                                   self.maxstep,
     361                                                                   self.purefc)
     362
     363        self.acctype = check_acctype(self.acctype, self.type)
     364
     365        self.acctime = check_acctime(self.acctime, self.acctype, self.purefc)
     366
     367        self.accmaxstep = check_accmaxstep(self.accmaxstep, self.acctype,
     368                                           self.purefc, self.maxstep)
    482369
    483370        self.purefc = check_purefc(self.type)
     
    487374        self.area = check_area(self.grid, self.area, self.upper, self.lower,
    488375                               self.left, self.right)
     376
     377        self.addpar = check_addpar(self.addpar)
    489378
    490379
     
    494383        '''Just generates a list of strings containing the attributes and
    495384        assigned values except the attributes "_expanded", "exedir",
    496         "ecmwfdatadir" and "flexpart_root_scripts".
     385        "flexextractdir" and "flexpartdir".
    497386
    498387        Parameters
     
    504393            A sorted list of the all ControlFile class attributes with
    505394            their values except the attributes "_expanded", "exedir",
    506             "ecmwfdatadir" and "flexpart_root_scripts".
     395            "flexextractdir" and "flexpartdir".
    507396        '''
    508397
     
    518407            elif 'exedir' in item[0]:
    519408                pass
    520             elif 'flexpart_root_scripts' in item[0]:
     409            elif 'flexpartdir' in item[0]:
    521410                pass
    522             elif 'ecmwfdatadir' in item[0]:
     411            elif 'flexextractdir' in item[0]:
    523412                pass
    524413            else:
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG