Changeset 25b14be in flex_extract.git for source/pythontest/TestInstallTar/flex_extract_v7.1_ecgate/source/python/classes/ControlFile.py
- Timestamp:
- Sep 23, 2018, 11:40:28 AM (6 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 4971f63
- Parents:
- 5d42acd
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
source/pythontest/TestInstallTar/flex_extract_v7.1_ecgate/source/python/classes/ControlFile.py
r2fb99de r25b14be 113 113 self.stream = None 114 114 self.number = 'OFF' 115 self.expver = None115 self.expver = '1' 116 116 self.grid = None 117 117 self.area = '' … … 143 143 self.ecstorage = 0 144 144 self.ectrans = 0 145 self.inputdir = '../work'145 self.inputdir = _config.PATH_INPUT_DIR 146 146 self.outputdir = self.inputdir 147 self.ecmwfdatadir = None148 self.exedir = None147 self.ecmwfdatadir = _config.PATH_FLEXEXTRACT_DIR 148 self.exedir = _config.PATH_FORTRAN_SRC 149 149 self.flexpart_root_scripts = None 150 self.makefile = None150 self.makefile = 'Makefile.gfortran' 151 151 self.destination = None 152 152 self.gateway = None … … 157 157 self.request = 0 158 158 159 self.logicals = ['gauss', 'omega', 'omegadiff', 'eta', 'etadiff', 160 'dpdeta', 'cwc', 'wrf', 'grib2flexpart', 'ecstorage', 161 'ectrans', 'debug', 'request'] 162 159 163 self.__read_controlfile__() 160 164 … … 173 177 <nothing> 174 178 ''' 175 from tools import my_error179 from mods.tools import my_error 176 180 177 181 # 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: 179 184 fdata = f.read().split('\n') 180 185 … … 226 231 pass 227 232 228 # script directory229 self.ecmwfdatadir = os.path.dirname(os.path.abspath(inspect.getfile(230 inspect.currentframe()))) + '/../'231 232 # Fortran source directory233 self.exedir = self.ecmwfdatadir + 'src/'234 235 233 return 236 234 … … 314 312 return 315 313 316 def check_conditions(self ):314 def check_conditions(self, queue): 317 315 ''' 318 316 @Description: … … 325 323 Description see class documentation. 326 324 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 327 330 @Return: 328 331 <nothing> 329 332 ''' 330 from tools import my_error333 from mods.tools import my_error 331 334 import numpy as np 332 335 … … 334 337 # otherwise program is not allowed to run 335 338 if self.start_date is None: 336 print 'start_date specified neither in command line nor ' +\337 'in CONTROL file ' + self.controlfile338 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') 340 343 sys.exit(1) 341 344 … … 345 348 346 349 # 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') 352 384 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 382 386 383 387 # if maxstep wasn't provided … … 411 415 self.mailops = [self.mailops] 412 416 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 \ 414 419 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!') 419 424 sys.exit(1) 420 425 421 426 if self.request != 0: 422 marsfile = os.path.join( _config.PATH_RUN_DIR + os.path.sep +427 marsfile = os.path.join(self.inputdir, 423 428 _config.FILE_MARS_REQUESTS) 424 429 if os.path.isfile(marsfile): 425 430 os.remove(marsfile) 426 431 427 # check logical variables for data type432 # check all logical variables for data type 428 433 # 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: 434 435 if not isinstance(getattr(self, var), int): 435 436 setattr(self, var, int(getattr(self, var))) … … 481 482 else: # local 482 483 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 487 485 488 486 return
Note: See TracChangeset
for help on using the changeset viewer.