Ignore:
Timestamp:
Sep 23, 2018, 11:40:28 AM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
4971f63
Parents:
5d42acd
Message:

changed whole tree structure of flex_extract to have better overview

File:
1 moved

Legend:

Unmodified
Added
Removed
  • source/pythontest/TestInstallTar/flex_extract_v7.1_ecgate/source/python/classes/ControlFile.py

    r2fb99de r25b14be  
    113113        self.stream = None
    114114        self.number = 'OFF'
    115         self.expver = None
     115        self.expver = '1'
    116116        self.grid = None
    117117        self.area = ''
     
    143143        self.ecstorage = 0
    144144        self.ectrans = 0
    145         self.inputdir = '../work'
     145        self.inputdir = _config.PATH_INPUT_DIR
    146146        self.outputdir = self.inputdir
    147         self.ecmwfdatadir = None
    148         self.exedir = None
     147        self.ecmwfdatadir = _config.PATH_FLEXEXTRACT_DIR
     148        self.exedir = _config.PATH_FORTRAN_SRC
    149149        self.flexpart_root_scripts = None
    150         self.makefile = None
     150        self.makefile = 'Makefile.gfortran'
    151151        self.destination = None
    152152        self.gateway = None
     
    157157        self.request = 0
    158158
     159        self.logicals = ['gauss', 'omega', 'omegadiff', 'eta', 'etadiff',
     160                         'dpdeta', 'cwc', 'wrf', 'grib2flexpart', 'ecstorage',
     161                         'ectrans', 'debug', 'request']
     162
    159163        self.__read_controlfile__()
    160164
     
    173177            <nothing>
    174178        '''
    175         from tools import my_error
     179        from mods.tools import my_error
    176180
    177181        # read whole CONTROL file
    178         with open(self.controlfile) as f:
     182        with open(os.path.join(_config.PATH_CONTROLFILES,
     183                               self.controlfile)) as f:
    179184            fdata = f.read().split('\n')
    180185
     
    226231                pass
    227232
    228         # script directory
    229         self.ecmwfdatadir = os.path.dirname(os.path.abspath(inspect.getfile(
    230             inspect.currentframe()))) + '/../'
    231 
    232         # Fortran source directory
    233         self.exedir = self.ecmwfdatadir + 'src/'
    234 
    235233        return
    236234
     
    314312        return
    315313
    316     def check_conditions(self):
     314    def check_conditions(self, queue):
    317315        '''
    318316        @Description:
     
    325323                Description see class documentation.
    326324
     325            queue: string
     326                Name of the queue if submitted to the ECMWF servers.
     327                Used to check if ecuid, ecgid, gateway and destination
     328                are set correctly and are not empty.
     329
    327330        @Return:
    328331            <nothing>
    329332        '''
    330         from tools import my_error
     333        from mods.tools import my_error
    331334        import numpy as np
    332335
     
    334337        # otherwise program is not allowed to run
    335338        if self.start_date is None:
    336             print 'start_date specified neither in command line nor ' + \
    337                   'in CONTROL file ' +  self.controlfile
    338             print 'Try "' + sys.argv[0].split('/')[-1] + \
    339                   ' -h" to print usage information'
     339            print('start_date specified neither in command line nor \
     340                   in CONTROL file ' +  self.controlfile)
     341            print('Try "' + sys.argv[0].split('/')[-1] +
     342                  ' -h" to print usage information')
    340343            sys.exit(1)
    341344
     
    345348
    346349        # assure consistency of levelist and level
    347         if self.levelist is None:
    348             if self.level is None:
    349                 print 'Warning: neither levelist nor level ' + \
    350                       'specified in CONTROL file'
    351                 sys.exit(1)
     350        if self.levelist is None and self.level is None:
     351            print('Warning: neither levelist nor level \
     352                               specified in CONTROL file')
     353            sys.exit(1)
     354        elif self.levelist is None and self.level:
     355            self.levelist = '1/to/' + self.level
     356        elif (self.levelist and self.level is None) or \
     357             (self.levelist[-1] != self.level[-1]):
     358            self.level = self.levelist.split('/')[-1]
     359        else:
     360            pass
     361
     362        # if area was provided (only from commandline)
     363        # decompose area into its 4 components
     364        if self.area:
     365            components = self.area.split('/')
     366            # convert float to integer coordinates
     367            if '.' in self.area:
     368                components = [str(int(float(item) * 1000))
     369                              for i, item in enumerate(components)]
     370            self.upper, self.left, self.lower, self.right = components
     371
     372        # prepare step list if "/" signs are found
     373        if '/' in self.step:
     374            steps = self.step.split('/')
     375            if 'to' in self.step.lower() and 'by' in self.step.lower():
     376                ilist = np.arange(int(steps[0]),
     377                                  int(steps[2]) + 1,
     378                                  int(steps[4]))
     379                self.step = ['{:0>3}'.format(i) for i in ilist]
     380            elif 'to' in self.step.lower() and 'by' not in self.step.lower():
     381                my_error(self.mailfail, self.step + ':\n' +
     382                         'if "to" is used in steps parameter, \
     383                         please use "by" as well')
    352384            else:
    353                 self.levelist = '1/to/' + self.level
    354         else:
    355             if 'to' in self.levelist.lower():
    356                 self.level = self.levelist.split('/')[2]
    357             else:
    358                 self.level = self.levelist.split('/')[-1]
    359 
    360         # if area was provided at command line
    361         # decompse area into its 4 components
    362         if self.area:
    363             afloat = '.' in self.area
    364             l = self.area.split('/')
    365             if afloat:
    366                 for i, item in enumerate(l):
    367                     item = str(int(float(item) * 1000))
    368             self.upper, self.left, self.lower, self.right = l
    369 
    370         # prepare step for correct usage
    371         if '/' in self.step:
    372             l = self.step.split('/')
    373             if 'to' in self.step.lower():
    374                 if 'by' in self.step.lower():
    375                     ilist = np.arange(int(l[0]), int(l[2]) + 1, int(l[4]))
    376                     self.step = ['{:0>3}'.format(i) for i in ilist]
    377                 else:
    378                     my_error(self.mailfail, self.step + ':\n' +
    379                              'if "to" is used, please use "by" as well')
    380             else:
    381                 self.step = l
     385                self.step = steps
    382386
    383387        # if maxstep wasn't provided
     
    411415                self.mailops = [self.mailops]
    412416
    413         if not self.gateway or not self.destination or \
     417        if queue in ['ecgate', 'cca'] and \
     418           not self.gateway or not self.destination or \
    414419           not self.ecuid or not self.ecgid:
    415             print '\nEnvironment variables GATWAY, DESTINATION, ECUID and ' + \
    416                   'ECGID were not set properly!'
    417             print 'Please check for excistence of file "ECMWF_ENV" in the ' + \
    418                   'python directory!'
     420            print('\nEnvironment variables GATEWAY, DESTINATION, ECUID and \
     421                   ECGID were not set properly!')
     422            print('Please check for existence of file "ECMWF_ENV" in the \
     423                   python directory!')
    419424            sys.exit(1)
    420425
    421426        if self.request != 0:
    422             marsfile = os.path.join(_config.PATH_RUN_DIR + os.path.sep +
     427            marsfile = os.path.join(self.inputdir,
    423428                                    _config.FILE_MARS_REQUESTS)
    424429            if os.path.isfile(marsfile):
    425430                os.remove(marsfile)
    426431
    427         # check logical variables for data type
     432        # check all logical variables for data type
    428433        # if its a string change to integer
    429         logicals = ['gauss', 'omega', 'omegadiff', 'eta', 'etadiff',
    430                     'dpdeta', 'cwc', 'wrf', 'grib2flexpart', 'ecstorage',
    431                     'ectrans', 'debug', 'request']
    432 
    433         for var in logicals:
     434        for var in self.logicals:
    434435            if not isinstance(getattr(self, var), int):
    435436                setattr(self, var, int(getattr(self, var)))
     
    481482        else: # local
    482483            if not self.flexpart_root_scripts:
    483                 self.flexpart_root_scripts = '../'
    484 
    485         if not self.makefile:
    486             self.makefile = 'Makefile.gfortran'
     484                self.flexpart_root_scripts = _config.PATH_FLEXEXTRACT_DIR
    487485
    488486        return
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG