[812283d] | 1 | #!/usr/bin/env python |
---|
| 2 | # -*- coding: utf-8 -*- |
---|
| 3 | #******************************************************************************* |
---|
| 4 | # @Author: Leopold Haimberger (University of Vienna) |
---|
| 5 | # |
---|
| 6 | # @Date: November 2015 |
---|
| 7 | # |
---|
| 8 | # @Change History: |
---|
| 9 | # |
---|
| 10 | # February 2018 - Anne Philipp (University of Vienna): |
---|
| 11 | # - applied PEP8 style guide |
---|
| 12 | # - added documentation |
---|
| 13 | # - applied some minor modifications in programming style/structure |
---|
| 14 | # - changed name of class Control to ControlFile for more |
---|
| 15 | # self-explanation naming |
---|
| 16 | # - outsource of class ControlFile |
---|
[54a8a01] | 17 | # - initialisation of class attributes ( to avoid high number of |
---|
| 18 | # conditional statements and set default values ) |
---|
| 19 | # - divided assignment of attributes and the check of conditions |
---|
| 20 | # - outsourced the commandline argument assignments to control attributes |
---|
[812283d] | 21 | # |
---|
| 22 | # @License: |
---|
| 23 | # (C) Copyright 2015-2018. |
---|
| 24 | # |
---|
| 25 | # This software is licensed under the terms of the Apache Licence Version 2.0 |
---|
| 26 | # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
---|
| 27 | # |
---|
| 28 | # @Class Description: |
---|
| 29 | # The CONTROL file is the steering part of the FLEXPART extraction |
---|
| 30 | # software. All necessary parameters needed to retrieve the data fields |
---|
| 31 | # from the MARS archive for driving FLEXPART are set in a CONTROL file. |
---|
| 32 | # Some specific parameters like the start and end dates can be overwritten |
---|
| 33 | # by the command line parameters, but in generel all parameters needed |
---|
| 34 | # for a complete set of fields for FLEXPART can be set in the CONTROL file. |
---|
| 35 | # |
---|
| 36 | # @Class Content: |
---|
| 37 | # - __init__ |
---|
[54a8a01] | 38 | # - __read_controlfile__ |
---|
[812283d] | 39 | # - __str__ |
---|
[54a8a01] | 40 | # - assign_args_to_control |
---|
| 41 | # - assign_envs_to_control |
---|
| 42 | # - check_conditions |
---|
| 43 | # - check_install_conditions |
---|
[ff99eae] | 44 | # - to_list |
---|
| 45 | # |
---|
| 46 | # @Class Attributes: |
---|
[54a8a01] | 47 | # |
---|
[812283d] | 48 | # |
---|
| 49 | #******************************************************************************* |
---|
| 50 | |
---|
| 51 | # ------------------------------------------------------------------------------ |
---|
| 52 | # MODULES |
---|
| 53 | # ------------------------------------------------------------------------------ |
---|
| 54 | import os |
---|
[2fb99de] | 55 | import re |
---|
[54a8a01] | 56 | import sys |
---|
[812283d] | 57 | import inspect |
---|
[ff99eae] | 58 | |
---|
[2fb99de] | 59 | import _config |
---|
| 60 | |
---|
[812283d] | 61 | # ------------------------------------------------------------------------------ |
---|
| 62 | # CLASS |
---|
| 63 | # ------------------------------------------------------------------------------ |
---|
[ff99eae] | 64 | class ControlFile(object): |
---|
[812283d] | 65 | ''' |
---|
| 66 | Class containing the information of the flex_extract CONTROL file. |
---|
| 67 | |
---|
| 68 | Contains all the parameters of CONTROL file, which are e.g.: |
---|
| 69 | DAY1(start_date), DAY2(end_date), DTIME, MAXSTEP, TYPE, TIME, |
---|
| 70 | STEP, CLASS(marsclass), STREAM, NUMBER, EXPVER, GRID, LEFT, |
---|
| 71 | LOWER, UPPER, RIGHT, LEVEL, LEVELIST, RESOL, GAUSS, ACCURACY, |
---|
| 72 | OMEGA, OMEGADIFF, ETA, ETADIFF, DPDETA, SMOOTH, FORMAT, |
---|
| 73 | ADDPAR, WRF, CWC, PREFIX, ECSTORAGE, ECTRANS, ECFSDIR, |
---|
| 74 | MAILOPS, MAILFAIL, GRIB2FLEXPART, FLEXPARTDIR, |
---|
| 75 | BASETIME, DATE_CHUNK, DEBUG, INPUTDIR, OUTPUTDIR, FLEXPART_ROOT_SCRIPTS |
---|
| 76 | |
---|
| 77 | For more information about format and content of the parameter |
---|
| 78 | see documentation. |
---|
| 79 | |
---|
| 80 | ''' |
---|
| 81 | |
---|
| 82 | def __init__(self, filename): |
---|
| 83 | ''' |
---|
| 84 | @Description: |
---|
[54a8a01] | 85 | Initialises the instance of ControlFile class and defines |
---|
| 86 | all class attributes with default values. Afterwards calls |
---|
| 87 | function __read_controlfile__ to read parameter from |
---|
| 88 | Control file. |
---|
[812283d] | 89 | |
---|
| 90 | @Input: |
---|
| 91 | self: instance of ControlFile class |
---|
| 92 | Description see class documentation. |
---|
| 93 | |
---|
| 94 | filename: string |
---|
| 95 | Name of CONTROL file. |
---|
| 96 | |
---|
| 97 | @Return: |
---|
| 98 | <nothing> |
---|
| 99 | ''' |
---|
[54a8a01] | 100 | |
---|
| 101 | # list of all possible class attributes and their default values |
---|
| 102 | self.controlfile = filename |
---|
| 103 | self.start_date = None |
---|
| 104 | self.end_date = None |
---|
| 105 | self.date_chunk = 3 |
---|
| 106 | self.dtime = None |
---|
| 107 | self.basetime = None |
---|
| 108 | self.maxstep = None |
---|
| 109 | self.type = None |
---|
| 110 | self.time = None |
---|
| 111 | self.step = None |
---|
| 112 | self.marsclass = None |
---|
| 113 | self.stream = None |
---|
| 114 | self.number = 'OFF' |
---|
[2fb99de] | 115 | self.expver = '1' |
---|
[54a8a01] | 116 | self.grid = None |
---|
| 117 | self.area = '' |
---|
| 118 | self.left = None |
---|
| 119 | self.lower = None |
---|
| 120 | self.upper = None |
---|
| 121 | self.right = None |
---|
| 122 | self.level = None |
---|
| 123 | self.levelist = None |
---|
| 124 | self.resol = None |
---|
| 125 | self.gauss = 0 |
---|
| 126 | self.accuracy = 24 |
---|
| 127 | self.omega = 0 |
---|
| 128 | self.omegadiff = 0 |
---|
| 129 | self.eta = 0 |
---|
| 130 | self.etadiff = 0 |
---|
| 131 | self.etapar = 77 |
---|
| 132 | self.dpdeta = 1 |
---|
| 133 | self.smooth = 0 |
---|
| 134 | self.format = 'GRIB1' |
---|
| 135 | self.addpar = None |
---|
| 136 | self.prefix = 'EN' |
---|
| 137 | self.cwc = 0 |
---|
| 138 | self.wrf = 0 |
---|
| 139 | self.ecfsdir = 'ectmp:/${USER}/econdemand/' |
---|
| 140 | self.mailfail = ['${USER}'] |
---|
| 141 | self.mailops = ['${USER}'] |
---|
| 142 | self.grib2flexpart = 0 |
---|
| 143 | self.ecstorage = 0 |
---|
| 144 | self.ectrans = 0 |
---|
[25b14be] | 145 | self.inputdir = _config.PATH_INPUT_DIR |
---|
[54a8a01] | 146 | self.outputdir = self.inputdir |
---|
[2fb99de] | 147 | self.ecmwfdatadir = _config.PATH_FLEXEXTRACT_DIR |
---|
| 148 | self.exedir = _config.PATH_FORTRAN_SRC |
---|
[54a8a01] | 149 | self.flexpart_root_scripts = None |
---|
[2fb99de] | 150 | self.makefile = 'Makefile.gfortran' |
---|
[54a8a01] | 151 | self.destination = None |
---|
| 152 | self.gateway = None |
---|
| 153 | self.ecuid = None |
---|
| 154 | self.ecgid = None |
---|
| 155 | self.install_target = None |
---|
| 156 | self.debug = 0 |
---|
[2fb99de] | 157 | self.request = 0 |
---|
| 158 | |
---|
| 159 | self.logicals = ['gauss', 'omega', 'omegadiff', 'eta', 'etadiff', |
---|
| 160 | 'dpdeta', 'cwc', 'wrf', 'grib2flexpart', 'ecstorage', |
---|
| 161 | 'ectrans', 'debug', 'request'] |
---|
[54a8a01] | 162 | |
---|
| 163 | self.__read_controlfile__() |
---|
| 164 | |
---|
| 165 | return |
---|
| 166 | |
---|
| 167 | def __read_controlfile__(self): |
---|
| 168 | ''' |
---|
| 169 | @Description: |
---|
| 170 | Read CONTROL file and assign all CONTROL file variables. |
---|
| 171 | |
---|
| 172 | @Input: |
---|
| 173 | self: instance of ControlFile class |
---|
| 174 | Description see class documentation. |
---|
| 175 | |
---|
| 176 | @Return: |
---|
| 177 | <nothing> |
---|
| 178 | ''' |
---|
[25b14be] | 179 | from mods.tools import my_error |
---|
[812283d] | 180 | |
---|
| 181 | # read whole CONTROL file |
---|
[4971f63] | 182 | |
---|
| 183 | try: |
---|
| 184 | with open(os.path.join(_config.PATH_CONTROLFILES, |
---|
| 185 | self.controlfile)) as f: |
---|
| 186 | fdata = f.read().split('\n') |
---|
| 187 | except IOError: |
---|
| 188 | print('Could not read CONTROL file "' + args.controlfile + '"') |
---|
| 189 | print('Either it does not exist or its syntax is wrong.') |
---|
| 190 | print('Try "' + sys.argv[0].split('/')[-1] + \ |
---|
| 191 | ' -h" to print usage information') |
---|
| 192 | sys.exit(1) |
---|
[812283d] | 193 | |
---|
| 194 | # go through every line and store parameter |
---|
| 195 | for ldata in fdata: |
---|
| 196 | data = ldata.split() |
---|
| 197 | if len(data) > 1: |
---|
| 198 | if 'm_' in data[0].lower(): |
---|
| 199 | data[0] = data[0][2:] |
---|
| 200 | if data[0].lower() == 'class': |
---|
| 201 | data[0] = 'marsclass' |
---|
| 202 | if data[0].lower() == 'day1': |
---|
| 203 | data[0] = 'start_date' |
---|
| 204 | if data[0].lower() == 'day2': |
---|
| 205 | data[0] = 'end_date' |
---|
| 206 | if data[0].lower() == 'addpar': |
---|
| 207 | if '/' in data[1]: |
---|
| 208 | # remove leading '/' sign from addpar content |
---|
| 209 | if data[1][0] == '/': |
---|
| 210 | data[1] = data[1][1:] |
---|
| 211 | dd = data[1].split('/') |
---|
| 212 | data = [data[0]] |
---|
| 213 | for d in dd: |
---|
| 214 | data.append(d) |
---|
| 215 | if len(data) == 2: |
---|
| 216 | if '$' in data[1]: |
---|
| 217 | setattr(self, data[0].lower(), data[1]) |
---|
| 218 | while '$' in data[1]: |
---|
| 219 | i = data[1].index('$') |
---|
| 220 | j = data[1].find('{') |
---|
| 221 | k = data[1].find('}') |
---|
| 222 | var = os.getenv(data[1][j+1:k]) |
---|
| 223 | if var is not None: |
---|
| 224 | data[1] = data[1][:i] + var + data[1][k+1:] |
---|
| 225 | else: |
---|
[54a8a01] | 226 | my_error(self.mailfail, |
---|
| 227 | 'Could not find variable ' |
---|
| 228 | + data[1][j+1:k] + ' while reading ' + |
---|
| 229 | self.controlfile) |
---|
[812283d] | 230 | setattr(self, data[0].lower() + '_expanded', data[1]) |
---|
| 231 | else: |
---|
| 232 | if data[1].lower() != 'none': |
---|
| 233 | setattr(self, data[0].lower(), data[1]) |
---|
| 234 | else: |
---|
| 235 | setattr(self, data[0].lower(), None) |
---|
| 236 | elif len(data) > 2: |
---|
| 237 | setattr(self, data[0].lower(), (data[1:])) |
---|
| 238 | else: |
---|
| 239 | pass |
---|
| 240 | |
---|
[54a8a01] | 241 | return |
---|
| 242 | |
---|
| 243 | def __str__(self): |
---|
| 244 | ''' |
---|
| 245 | @Description: |
---|
| 246 | Prepares a string which have all the ControlFile |
---|
| 247 | class attributes with its associated values. |
---|
| 248 | Each attribute is printed in one line and in |
---|
| 249 | alphabetical order. |
---|
| 250 | |
---|
| 251 | Example: |
---|
| 252 | 'age': 10 |
---|
| 253 | 'color': 'Spotted' |
---|
| 254 | 'kids': 0 |
---|
| 255 | 'legs': 2 |
---|
| 256 | 'name': 'Dog' |
---|
| 257 | 'smell': 'Alot' |
---|
| 258 | |
---|
| 259 | @Input: |
---|
| 260 | self: instance of ControlFile class |
---|
| 261 | Description see class documentation. |
---|
| 262 | |
---|
| 263 | @Return: |
---|
| 264 | string of ControlFile class attributes with their values |
---|
| 265 | ''' |
---|
| 266 | import collections |
---|
| 267 | |
---|
| 268 | attrs = vars(self) |
---|
| 269 | attrs = collections.OrderedDict(sorted(attrs.items())) |
---|
| 270 | |
---|
| 271 | return '\n'.join("%s: %s" % item for item in attrs.items()) |
---|
| 272 | |
---|
| 273 | def assign_args_to_control(self, args): |
---|
| 274 | ''' |
---|
| 275 | @Description: |
---|
| 276 | Overwrites the existing ControlFile instance attributes with |
---|
| 277 | the command line arguments. |
---|
| 278 | |
---|
| 279 | @Input: |
---|
| 280 | self: instance of ControlFile class |
---|
| 281 | Description see class documentation. |
---|
| 282 | |
---|
| 283 | args: instance of ArgumentParser |
---|
| 284 | Contains the commandline arguments from script/program call. |
---|
| 285 | |
---|
| 286 | @Return: |
---|
| 287 | <nothing> |
---|
| 288 | ''' |
---|
| 289 | |
---|
| 290 | # get dictionary of command line parameters and eliminate all |
---|
| 291 | # parameters which are None (were not specified) |
---|
| 292 | args_dict = vars(args) |
---|
| 293 | arguments = {k : args_dict[k] for k in args_dict |
---|
| 294 | if args_dict[k] != None} |
---|
| 295 | |
---|
| 296 | # assign all passed command line arguments to ControlFile instance |
---|
| 297 | for k, v in arguments.iteritems(): |
---|
| 298 | setattr(self, str(k), v) |
---|
| 299 | |
---|
| 300 | return |
---|
| 301 | |
---|
| 302 | def assign_envs_to_control(self, envs): |
---|
| 303 | ''' |
---|
| 304 | @Description: |
---|
| 305 | Assigns the ECMWF environment parameter. |
---|
| 306 | |
---|
| 307 | @Input: |
---|
| 308 | envs: dict of strings |
---|
| 309 | Contains the ECMWF environment parameternames "ECUID", "ECGID", |
---|
| 310 | "DESTINATION" and "GATEWAY" with its corresponding values. |
---|
| 311 | They were read from the file "ECMWF_ENV". |
---|
| 312 | |
---|
| 313 | @Return: |
---|
| 314 | <nothing> |
---|
| 315 | ''' |
---|
| 316 | |
---|
| 317 | for k, v in envs.iteritems(): |
---|
| 318 | setattr(self, str(k).lower(), str(v)) |
---|
| 319 | |
---|
| 320 | return |
---|
| 321 | |
---|
[2fb99de] | 322 | def check_conditions(self, queue): |
---|
[54a8a01] | 323 | ''' |
---|
| 324 | @Description: |
---|
| 325 | Checks a couple of necessary attributes and conditions, |
---|
| 326 | such as if they exist and contain values. |
---|
| 327 | Otherwise set default values. |
---|
| 328 | |
---|
| 329 | @Input: |
---|
| 330 | self: instance of ControlFile class |
---|
| 331 | Description see class documentation. |
---|
| 332 | |
---|
[2fb99de] | 333 | queue: string |
---|
| 334 | Name of the queue if submitted to the ECMWF servers. |
---|
| 335 | Used to check if ecuid, ecgid, gateway and destination |
---|
| 336 | are set correctly and are not empty. |
---|
| 337 | |
---|
[54a8a01] | 338 | @Return: |
---|
| 339 | <nothing> |
---|
| 340 | ''' |
---|
[25b14be] | 341 | from mods.tools import my_error |
---|
[54a8a01] | 342 | import numpy as np |
---|
| 343 | |
---|
| 344 | # check for having at least a starting date |
---|
| 345 | # otherwise program is not allowed to run |
---|
| 346 | if self.start_date is None: |
---|
[2fb99de] | 347 | print('start_date specified neither in command line nor \ |
---|
| 348 | in CONTROL file ' + self.controlfile) |
---|
| 349 | print('Try "' + sys.argv[0].split('/')[-1] + |
---|
| 350 | ' -h" to print usage information') |
---|
[54a8a01] | 351 | sys.exit(1) |
---|
| 352 | |
---|
| 353 | # retrieve just one day if end_date isn't set |
---|
| 354 | if self.end_date is None: |
---|
[812283d] | 355 | self.end_date = self.start_date |
---|
[54a8a01] | 356 | |
---|
| 357 | # assure consistency of levelist and level |
---|
[2fb99de] | 358 | if self.levelist is None and self.level is None: |
---|
| 359 | print('Warning: neither levelist nor level \ |
---|
| 360 | specified in CONTROL file') |
---|
| 361 | sys.exit(1) |
---|
| 362 | elif self.levelist is None and self.level: |
---|
| 363 | self.levelist = '1/to/' + self.level |
---|
| 364 | elif (self.levelist and self.level is None) or \ |
---|
| 365 | (self.levelist[-1] != self.level[-1]): |
---|
| 366 | self.level = self.levelist.split('/')[-1] |
---|
[812283d] | 367 | else: |
---|
[2fb99de] | 368 | pass |
---|
[812283d] | 369 | |
---|
[2fb99de] | 370 | # if area was provided (only from commandline) |
---|
| 371 | # decompose area into its 4 components |
---|
[54a8a01] | 372 | if self.area: |
---|
[2fb99de] | 373 | components = self.area.split('/') |
---|
| 374 | # convert float to integer coordinates |
---|
| 375 | if '.' in self.area: |
---|
| 376 | components = [str(int(float(item) * 1000)) |
---|
| 377 | for i, item in enumerate(components)] |
---|
| 378 | self.upper, self.left, self.lower, self.right = components |
---|
| 379 | |
---|
| 380 | # prepare step list if "/" signs are found |
---|
[54a8a01] | 381 | if '/' in self.step: |
---|
[2fb99de] | 382 | steps = self.step.split('/') |
---|
| 383 | if 'to' in self.step.lower() and 'by' in self.step.lower(): |
---|
| 384 | ilist = np.arange(int(steps[0]), |
---|
| 385 | int(steps[2]) + 1, |
---|
| 386 | int(steps[4])) |
---|
| 387 | self.step = ['{:0>3}'.format(i) for i in ilist] |
---|
| 388 | elif 'to' in self.step.lower() and 'by' not in self.step.lower(): |
---|
| 389 | my_error(self.mailfail, self.step + ':\n' + |
---|
| 390 | 'if "to" is used in steps parameter, \ |
---|
| 391 | please use "by" as well') |
---|
[54a8a01] | 392 | else: |
---|
[2fb99de] | 393 | self.step = steps |
---|
[54a8a01] | 394 | |
---|
| 395 | # if maxstep wasn't provided |
---|
| 396 | # search for it in the "step" parameter |
---|
| 397 | if self.maxstep is None: |
---|
[812283d] | 398 | self.maxstep = 0 |
---|
| 399 | for s in self.step: |
---|
| 400 | if int(s) > self.maxstep: |
---|
| 401 | self.maxstep = int(s) |
---|
| 402 | else: |
---|
| 403 | self.maxstep = int(self.maxstep) |
---|
| 404 | |
---|
[54a8a01] | 405 | # set root scripts since it is needed later on |
---|
| 406 | if not self.flexpart_root_scripts: |
---|
| 407 | self.flexpart_root_scripts = self.ecmwfdatadir |
---|
[812283d] | 408 | |
---|
[54a8a01] | 409 | if not isinstance(self.mailfail, list): |
---|
| 410 | if ',' in self.mailfail: |
---|
| 411 | self.mailfail = self.mailfail.split(',') |
---|
| 412 | elif ' ' in self.mailfail: |
---|
| 413 | self.mailfail = self.mailfail.split() |
---|
| 414 | else: |
---|
| 415 | self.mailfail = [self.mailfail] |
---|
[812283d] | 416 | |
---|
[54a8a01] | 417 | if not isinstance(self.mailops, list): |
---|
| 418 | if ',' in self.mailops: |
---|
| 419 | self.mailops = self.mailops.split(',') |
---|
| 420 | elif ' ' in self.mailops: |
---|
| 421 | self.mailops = self.mailops.split() |
---|
| 422 | else: |
---|
| 423 | self.mailops = [self.mailops] |
---|
| 424 | |
---|
[2fb99de] | 425 | if queue in ['ecgate', 'cca'] and \ |
---|
| 426 | not self.gateway or not self.destination or \ |
---|
[54a8a01] | 427 | not self.ecuid or not self.ecgid: |
---|
[2fb99de] | 428 | print('\nEnvironment variables GATEWAY, DESTINATION, ECUID and \ |
---|
| 429 | ECGID were not set properly!') |
---|
| 430 | print('Please check for existence of file "ECMWF_ENV" in the \ |
---|
| 431 | python directory!') |
---|
[54a8a01] | 432 | sys.exit(1) |
---|
[812283d] | 433 | |
---|
[2fb99de] | 434 | if self.request != 0: |
---|
[5d42acd] | 435 | marsfile = os.path.join(self.inputdir, |
---|
[2fb99de] | 436 | _config.FILE_MARS_REQUESTS) |
---|
| 437 | if os.path.isfile(marsfile): |
---|
| 438 | os.remove(marsfile) |
---|
| 439 | |
---|
| 440 | # check all logical variables for data type |
---|
| 441 | # if its a string change to integer |
---|
| 442 | for var in self.logicals: |
---|
| 443 | if not isinstance(getattr(self, var), int): |
---|
| 444 | setattr(self, var, int(getattr(self, var))) |
---|
| 445 | |
---|
[812283d] | 446 | return |
---|
| 447 | |
---|
[54a8a01] | 448 | def check_install_conditions(self): |
---|
[812283d] | 449 | ''' |
---|
| 450 | @Description: |
---|
[54a8a01] | 451 | Checks a couple of necessary attributes and conditions |
---|
| 452 | for the installation such as if they exist and contain values. |
---|
| 453 | Otherwise set default values. |
---|
[812283d] | 454 | |
---|
| 455 | @Input: |
---|
| 456 | self: instance of ControlFile class |
---|
| 457 | Description see class documentation. |
---|
| 458 | |
---|
| 459 | @Return: |
---|
[54a8a01] | 460 | <nothing> |
---|
[812283d] | 461 | ''' |
---|
| 462 | |
---|
[54a8a01] | 463 | if self.install_target and \ |
---|
| 464 | self.install_target not in ['local', 'ecgate', 'cca']: |
---|
[2fb99de] | 465 | print('ERROR: unknown or missing installation target ') |
---|
| 466 | print('target: ', self.install_target) |
---|
| 467 | print('please specify correct installation target ' + |
---|
| 468 | '(local | ecgate | cca)') |
---|
| 469 | print('use -h or --help for help') |
---|
[54a8a01] | 470 | sys.exit(1) |
---|
| 471 | |
---|
| 472 | if self.install_target and self.install_target != 'local': |
---|
| 473 | if not self.ecgid or not self.ecuid or \ |
---|
| 474 | not self.gateway or not self.destination: |
---|
[2fb99de] | 475 | print('Please enter your ECMWF user id and group id as well ' + |
---|
| 476 | 'as the \nname of the local gateway and the ectrans ' + |
---|
| 477 | 'destination ') |
---|
| 478 | print('with command line options --ecuid --ecgid \ |
---|
| 479 | --gateway --destination') |
---|
| 480 | print('Try "' + sys.argv[0].split('/')[-1] + \ |
---|
| 481 | ' -h" to print usage information') |
---|
| 482 | print('Please consult ecaccess documentation or ECMWF user \ |
---|
| 483 | support for further details') |
---|
[54a8a01] | 484 | sys.exit(1) |
---|
| 485 | |
---|
| 486 | if not self.flexpart_root_scripts: |
---|
| 487 | self.flexpart_root_scripts = '${HOME}' |
---|
| 488 | else: |
---|
| 489 | self.flexpart_root_scripts = self.flexpart_root_scripts |
---|
[2fb99de] | 490 | else: # local |
---|
[54a8a01] | 491 | if not self.flexpart_root_scripts: |
---|
[2fb99de] | 492 | self.flexpart_root_scripts = _config.PATH_FLEXEXTRACT_DIR |
---|
[54a8a01] | 493 | |
---|
| 494 | return |
---|
[812283d] | 495 | |
---|
[ff99eae] | 496 | def to_list(self): |
---|
[812283d] | 497 | ''' |
---|
| 498 | @Description: |
---|
| 499 | Just generates a list of strings containing the attributes and |
---|
| 500 | assigned values except the attributes "_expanded", "exedir", |
---|
| 501 | "ecmwfdatadir" and "flexpart_root_scripts". |
---|
| 502 | |
---|
| 503 | @Input: |
---|
| 504 | self: instance of ControlFile class |
---|
| 505 | Description see class documentation. |
---|
| 506 | |
---|
| 507 | @Return: |
---|
| 508 | l: list |
---|
| 509 | A sorted list of the all ControlFile class attributes with |
---|
| 510 | their values except the attributes "_expanded", "exedir", |
---|
| 511 | "ecmwfdatadir" and "flexpart_root_scripts". |
---|
| 512 | ''' |
---|
| 513 | |
---|
[54a8a01] | 514 | import collections |
---|
| 515 | |
---|
| 516 | attrs = collections.OrderedDict(sorted(vars(self).items())) |
---|
| 517 | |
---|
[812283d] | 518 | l = list() |
---|
| 519 | |
---|
| 520 | for item in attrs.items(): |
---|
| 521 | if '_expanded' in item[0]: |
---|
| 522 | pass |
---|
| 523 | elif 'exedir' in item[0]: |
---|
| 524 | pass |
---|
| 525 | elif 'flexpart_root_scripts' in item[0]: |
---|
| 526 | pass |
---|
| 527 | elif 'ecmwfdatadir' in item[0]: |
---|
| 528 | pass |
---|
| 529 | else: |
---|
[ff99eae] | 530 | if isinstance(item[1], list): |
---|
[812283d] | 531 | stot = '' |
---|
| 532 | for s in item[1]: |
---|
| 533 | stot += s + ' ' |
---|
| 534 | |
---|
| 535 | l.append("%s %s" % (item[0], stot)) |
---|
| 536 | else: |
---|
| 537 | l.append("%s %s" % item) |
---|
| 538 | |
---|
| 539 | return sorted(l) |
---|
[ff99eae] | 540 | |
---|