Changeset 2fb99de in flex_extract.git for python/ControlFile.py
- Timestamp:
- Sep 20, 2018, 11:56:37 AM (6 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 5d42acd
- Parents:
- 3232589
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ControlFile.py
r54a8a01 r2fb99de 53 53 # ------------------------------------------------------------------------------ 54 54 import os 55 import re 55 56 import sys 56 57 import inspect 58 59 import _config 57 60 58 61 # ------------------------------------------------------------------------------ … … 110 113 self.stream = None 111 114 self.number = 'OFF' 112 self.expver = None115 self.expver = '1' 113 116 self.grid = None 114 117 self.area = '' … … 142 145 self.inputdir = '../work' 143 146 self.outputdir = self.inputdir 144 self.ecmwfdatadir = None145 self.exedir = None147 self.ecmwfdatadir = _config.PATH_FLEXEXTRACT_DIR 148 self.exedir = _config.PATH_FORTRAN_SRC 146 149 self.flexpart_root_scripts = None 147 self.makefile = None150 self.makefile = 'Makefile.gfortran' 148 151 self.destination = None 149 152 self.gateway = None … … 152 155 self.install_target = None 153 156 self.debug = 0 157 self.request = 0 158 159 self.logicals = ['gauss', 'omega', 'omegadiff', 'eta', 'etadiff', 160 'dpdeta', 'cwc', 'wrf', 'grib2flexpart', 'ecstorage', 161 'ectrans', 'debug', 'request'] 154 162 155 163 self.__read_controlfile__() … … 172 180 173 181 # read whole CONTROL file 174 with open(self.controlfile) as f: 182 with open(os.path.join(_config.PATH_CONTROLFILES, 183 self.controlfile)) as f: 175 184 fdata = f.read().split('\n') 176 185 … … 222 231 pass 223 232 224 # script directory225 self.ecmwfdatadir = os.path.dirname(os.path.abspath(inspect.getfile(226 inspect.currentframe()))) + '/../'227 228 # Fortran source directory229 self.exedir = self.ecmwfdatadir + 'src/'230 231 233 return 232 234 … … 310 312 return 311 313 312 def check_conditions(self ):314 def check_conditions(self, queue): 313 315 ''' 314 316 @Description: … … 321 323 Description see class documentation. 322 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 323 330 @Return: 324 331 <nothing> … … 330 337 # otherwise program is not allowed to run 331 338 if self.start_date is None: 332 print 'start_date specified neither in command line nor ' +\333 'in CONTROL file ' + self.controlfile334 print 'Try "' + sys.argv[0].split('/')[-1] + \335 ' -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') 336 343 sys.exit(1) 337 344 … … 341 348 342 349 # assure consistency of levelist and level 343 if self.levelist is None: 344 if self.level is None: 345 print 'Warning: neither levelist nor level ' + \ 346 'specified in CONTROL file' 347 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') 348 384 else: 349 self.levelist = '1/to/' + self.level 350 else: 351 if 'to' in self.levelist.lower(): 352 self.level = self.levelist.split('/')[2] 353 else: 354 self.level = self.levelist.split('/')[-1] 355 356 # if area was provided at command line 357 # decompse area into its 4 components 358 if self.area: 359 afloat = '.' in self.area 360 l = self.area.split('/') 361 if afloat: 362 for i, item in enumerate(l): 363 item = str(int(float(item) * 1000)) 364 self.upper, self.left, self.lower, self.right = l 365 366 # prepare step for correct usage 367 if '/' in self.step: 368 l = self.step.split('/') 369 if 'to' in self.step.lower(): 370 if 'by' in self.step.lower(): 371 ilist = np.arange(int(l[0]), int(l[2]) + 1, int(l[4])) 372 self.step = ['{:0>3}'.format(i) for i in ilist] 373 else: 374 my_error(self.mailfail, self.step + ':\n' + 375 'if "to" is used, please use "by" as well') 376 else: 377 self.step = l 385 self.step = steps 378 386 379 387 # if maxstep wasn't provided … … 407 415 self.mailops = [self.mailops] 408 416 409 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 \ 410 419 not self.ecuid or not self.ecgid: 411 print '\nEnvironment variables GATWAY, DESTINATION, ECUID and ' +\412 'ECGID were not set properly!'413 print 'Please check for excistence of file "ECMWF_ENV" in the ' +\414 '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!') 415 424 sys.exit(1) 425 426 if self.request != 0: 427 marsfile = os.path.join(_config.PATH_RUN_DIR, 428 _config.FILE_MARS_REQUESTS) 429 if os.path.isfile(marsfile): 430 os.remove(marsfile) 431 432 # check all logical variables for data type 433 # if its a string change to integer 434 for var in self.logicals: 435 if not isinstance(getattr(self, var), int): 436 setattr(self, var, int(getattr(self, var))) 416 437 417 438 return … … 434 455 if self.install_target and \ 435 456 self.install_target not in ['local', 'ecgate', 'cca']: 436 print 'ERROR: unknown or missing installation target '437 print 'target: ', self.install_target438 print 'please specify correct installation target \439 (local | ecgate | cca)'440 print 'use -h or --help for help'457 print('ERROR: unknown or missing installation target ') 458 print('target: ', self.install_target) 459 print('please specify correct installation target ' + 460 '(local | ecgate | cca)') 461 print('use -h or --help for help') 441 462 sys.exit(1) 442 463 … … 444 465 if not self.ecgid or not self.ecuid or \ 445 466 not self.gateway or not self.destination: 446 print 'Please enter your ECMWF user id and group id as well as \447 the \nname of the local gateway and the ectrans \448 destination '449 print 450 --gateway --destination' 451 print 452 ' -h" to print usage information' 453 print 454 support for further details' 467 print('Please enter your ECMWF user id and group id as well ' + 468 'as the \nname of the local gateway and the ectrans ' + 469 'destination ') 470 print('with command line options --ecuid --ecgid \ 471 --gateway --destination') 472 print('Try "' + sys.argv[0].split('/')[-1] + \ 473 ' -h" to print usage information') 474 print('Please consult ecaccess documentation or ECMWF user \ 475 support for further details') 455 476 sys.exit(1) 456 477 … … 459 480 else: 460 481 self.flexpart_root_scripts = self.flexpart_root_scripts 461 else: 482 else: # local 462 483 if not self.flexpart_root_scripts: 463 self.flexpart_root_scripts = '../' 464 465 if not self.makefile: 466 self.makefile = 'Makefile.gfortran' 484 self.flexpart_root_scripts = _config.PATH_FLEXEXTRACT_DIR 467 485 468 486 return
Note: See TracChangeset
for help on using the changeset viewer.