[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 | |
---|
[ca867de] | 59 | # software specific classes and modules from flex_extract |
---|
| 60 | sys.path.append('../') |
---|
[2fb99de] | 61 | import _config |
---|
[70fee58] | 62 | from mods.tools import my_error, silent_remove |
---|
[3f36e42] | 63 | from mods.checks import check_grid, check_area, check_levels |
---|
[2fb99de] | 64 | |
---|
[812283d] | 65 | # ------------------------------------------------------------------------------ |
---|
| 66 | # CLASS |
---|
| 67 | # ------------------------------------------------------------------------------ |
---|
[ff99eae] | 68 | class ControlFile(object): |
---|
[812283d] | 69 | ''' |
---|
[708c667] | 70 | Contains the information which are stored in the CONTROL files. |
---|
[812283d] | 71 | ''' |
---|
| 72 | |
---|
| 73 | def __init__(self, filename): |
---|
[274f9ef] | 74 | '''Initialises the instance of ControlFile class and defines |
---|
| 75 | all class attributes with default values. Afterwards calls |
---|
| 76 | function __read_controlfile__ to read parameter from Control file. |
---|
[812283d] | 77 | |
---|
[274f9ef] | 78 | Parameters |
---|
| 79 | ---------- |
---|
| 80 | filename : :obj:`string` |
---|
| 81 | Name of CONTROL file. |
---|
[812283d] | 82 | |
---|
[274f9ef] | 83 | Return |
---|
| 84 | ------ |
---|
[812283d] | 85 | |
---|
| 86 | ''' |
---|
[54a8a01] | 87 | |
---|
| 88 | # list of all possible class attributes and their default values |
---|
| 89 | self.controlfile = filename |
---|
| 90 | self.start_date = None |
---|
| 91 | self.end_date = None |
---|
| 92 | self.date_chunk = 3 |
---|
| 93 | self.dtime = None |
---|
| 94 | self.basetime = None |
---|
| 95 | self.maxstep = None |
---|
| 96 | self.type = None |
---|
| 97 | self.time = None |
---|
| 98 | self.step = None |
---|
[0e576fc] | 99 | self.acctype = None |
---|
| 100 | self.acctime = None |
---|
| 101 | self.accmaxstep = None |
---|
[54a8a01] | 102 | self.marsclass = None |
---|
[5bad6ec] | 103 | self.dataset = None |
---|
[54a8a01] | 104 | self.stream = None |
---|
| 105 | self.number = 'OFF' |
---|
[2fb99de] | 106 | self.expver = '1' |
---|
[0e576fc] | 107 | self.gaussian = '' |
---|
[54a8a01] | 108 | self.grid = None |
---|
| 109 | self.area = '' |
---|
| 110 | self.left = None |
---|
| 111 | self.lower = None |
---|
| 112 | self.upper = None |
---|
| 113 | self.right = None |
---|
| 114 | self.level = None |
---|
| 115 | self.levelist = None |
---|
| 116 | self.resol = None |
---|
| 117 | self.gauss = 0 |
---|
| 118 | self.accuracy = 24 |
---|
| 119 | self.omega = 0 |
---|
| 120 | self.omegadiff = 0 |
---|
| 121 | self.eta = 0 |
---|
| 122 | self.etadiff = 0 |
---|
| 123 | self.etapar = 77 |
---|
| 124 | self.dpdeta = 1 |
---|
| 125 | self.smooth = 0 |
---|
| 126 | self.format = 'GRIB1' |
---|
| 127 | self.addpar = None |
---|
| 128 | self.prefix = 'EN' |
---|
| 129 | self.cwc = 0 |
---|
| 130 | self.wrf = 0 |
---|
| 131 | self.ecfsdir = 'ectmp:/${USER}/econdemand/' |
---|
| 132 | self.mailfail = ['${USER}'] |
---|
| 133 | self.mailops = ['${USER}'] |
---|
| 134 | self.grib2flexpart = 0 |
---|
| 135 | self.ecstorage = 0 |
---|
| 136 | self.ectrans = 0 |
---|
[25b14be] | 137 | self.inputdir = _config.PATH_INPUT_DIR |
---|
[ca867de] | 138 | self.outputdir = None |
---|
[2fb99de] | 139 | self.ecmwfdatadir = _config.PATH_FLEXEXTRACT_DIR |
---|
| 140 | self.exedir = _config.PATH_FORTRAN_SRC |
---|
[54a8a01] | 141 | self.flexpart_root_scripts = None |
---|
[2fb99de] | 142 | self.makefile = 'Makefile.gfortran' |
---|
[54a8a01] | 143 | self.destination = None |
---|
| 144 | self.gateway = None |
---|
| 145 | self.ecuid = None |
---|
| 146 | self.ecgid = None |
---|
| 147 | self.install_target = None |
---|
| 148 | self.debug = 0 |
---|
[2fb99de] | 149 | self.request = 0 |
---|
[5bad6ec] | 150 | self.public = 0 |
---|
[96e1533] | 151 | self.ecapi = None |
---|
[4d3b052] | 152 | self.purefc = 0 |
---|
[c274d9a] | 153 | self.rrint = 0 |
---|
[2fb99de] | 154 | |
---|
| 155 | self.logicals = ['gauss', 'omega', 'omegadiff', 'eta', 'etadiff', |
---|
| 156 | 'dpdeta', 'cwc', 'wrf', 'grib2flexpart', 'ecstorage', |
---|
[4d3b052] | 157 | 'ectrans', 'debug', 'request', 'public', 'purefc', |
---|
| 158 | 'rrint'] |
---|
[54a8a01] | 159 | |
---|
| 160 | self.__read_controlfile__() |
---|
| 161 | |
---|
| 162 | return |
---|
| 163 | |
---|
| 164 | def __read_controlfile__(self): |
---|
[274f9ef] | 165 | '''Read CONTROL file and assign all CONTROL file variables. |
---|
[54a8a01] | 166 | |
---|
[274f9ef] | 167 | Parameters |
---|
| 168 | ---------- |
---|
| 169 | |
---|
| 170 | Return |
---|
| 171 | ------ |
---|
[54a8a01] | 172 | |
---|
| 173 | ''' |
---|
[4971f63] | 174 | |
---|
| 175 | try: |
---|
[70fee58] | 176 | cfile = os.path.join(_config.PATH_CONTROLFILES, self.controlfile) |
---|
| 177 | with open(cfile) as f: |
---|
[4971f63] | 178 | fdata = f.read().split('\n') |
---|
| 179 | except IOError: |
---|
[70fee58] | 180 | print('Could not read CONTROL file "' + cfile + '"') |
---|
[4971f63] | 181 | print('Either it does not exist or its syntax is wrong.') |
---|
| 182 | print('Try "' + sys.argv[0].split('/')[-1] + \ |
---|
| 183 | ' -h" to print usage information') |
---|
| 184 | sys.exit(1) |
---|
[812283d] | 185 | |
---|
| 186 | # go through every line and store parameter |
---|
| 187 | for ldata in fdata: |
---|
| 188 | data = ldata.split() |
---|
| 189 | if len(data) > 1: |
---|
| 190 | if 'm_' in data[0].lower(): |
---|
| 191 | data[0] = data[0][2:] |
---|
| 192 | if data[0].lower() == 'class': |
---|
| 193 | data[0] = 'marsclass' |
---|
| 194 | if data[0].lower() == 'day1': |
---|
| 195 | data[0] = 'start_date' |
---|
| 196 | if data[0].lower() == 'day2': |
---|
| 197 | 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) |
---|
| 207 | if len(data) == 2: |
---|
| 208 | if '$' in data[1]: |
---|
| 209 | setattr(self, data[0].lower(), data[1]) |
---|
| 210 | while '$' in data[1]: |
---|
| 211 | i = data[1].index('$') |
---|
| 212 | j = data[1].find('{') |
---|
| 213 | k = data[1].find('}') |
---|
| 214 | var = os.getenv(data[1][j+1:k]) |
---|
| 215 | if var is not None: |
---|
| 216 | data[1] = data[1][:i] + var + data[1][k+1:] |
---|
| 217 | else: |
---|
[54a8a01] | 218 | my_error(self.mailfail, |
---|
| 219 | 'Could not find variable ' |
---|
| 220 | + data[1][j+1:k] + ' while reading ' + |
---|
| 221 | self.controlfile) |
---|
[812283d] | 222 | setattr(self, data[0].lower() + '_expanded', data[1]) |
---|
| 223 | else: |
---|
| 224 | if data[1].lower() != 'none': |
---|
| 225 | setattr(self, data[0].lower(), data[1]) |
---|
| 226 | else: |
---|
| 227 | setattr(self, data[0].lower(), None) |
---|
| 228 | elif len(data) > 2: |
---|
| 229 | setattr(self, data[0].lower(), (data[1:])) |
---|
| 230 | else: |
---|
| 231 | pass |
---|
| 232 | |
---|
[54a8a01] | 233 | return |
---|
| 234 | |
---|
| 235 | def __str__(self): |
---|
[274f9ef] | 236 | '''Prepares a string which have all the ControlFile class attributes |
---|
| 237 | with its associated values. Each attribute is printed in one line and |
---|
| 238 | in alphabetical order. |
---|
| 239 | |
---|
| 240 | Example |
---|
| 241 | ------- |
---|
| 242 | 'age': 10 |
---|
| 243 | 'color': 'Spotted' |
---|
| 244 | 'kids': 0 |
---|
| 245 | 'legs': 2 |
---|
| 246 | 'name': 'Dog' |
---|
| 247 | 'smell': 'Alot' |
---|
| 248 | |
---|
| 249 | Parameters |
---|
| 250 | ---------- |
---|
| 251 | |
---|
| 252 | Return |
---|
| 253 | ------ |
---|
| 254 | string |
---|
| 255 | Single string of concatenated ControlFile class attributes |
---|
| 256 | with their values |
---|
[54a8a01] | 257 | ''' |
---|
| 258 | import collections |
---|
| 259 | |
---|
[5bad6ec] | 260 | attrs = vars(self).copy() |
---|
[54a8a01] | 261 | attrs = collections.OrderedDict(sorted(attrs.items())) |
---|
| 262 | |
---|
| 263 | return '\n'.join("%s: %s" % item for item in attrs.items()) |
---|
| 264 | |
---|
| 265 | def assign_args_to_control(self, args): |
---|
[274f9ef] | 266 | '''Overwrites the existing ControlFile instance attributes with |
---|
| 267 | the command line arguments. |
---|
[54a8a01] | 268 | |
---|
[274f9ef] | 269 | Parameters |
---|
| 270 | ---------- |
---|
| 271 | args : :obj:`Namespace` |
---|
| 272 | Contains the commandline arguments from script/program call. |
---|
[54a8a01] | 273 | |
---|
[274f9ef] | 274 | Return |
---|
| 275 | ------ |
---|
[54a8a01] | 276 | |
---|
| 277 | ''' |
---|
| 278 | |
---|
| 279 | # get dictionary of command line parameters and eliminate all |
---|
| 280 | # parameters which are None (were not specified) |
---|
| 281 | args_dict = vars(args) |
---|
| 282 | arguments = {k : args_dict[k] for k in args_dict |
---|
| 283 | if args_dict[k] != None} |
---|
| 284 | |
---|
| 285 | # assign all passed command line arguments to ControlFile instance |
---|
| 286 | for k, v in arguments.iteritems(): |
---|
| 287 | setattr(self, str(k), v) |
---|
| 288 | |
---|
| 289 | return |
---|
| 290 | |
---|
| 291 | def assign_envs_to_control(self, envs): |
---|
[274f9ef] | 292 | '''Assigns the ECMWF environment parameter. |
---|
[54a8a01] | 293 | |
---|
[274f9ef] | 294 | Parameters |
---|
| 295 | ---------- |
---|
| 296 | envs : :obj:`dictionary` of :obj:`strings` |
---|
| 297 | Contains the ECMWF environment parameternames "ECUID", "ECGID", |
---|
| 298 | "DESTINATION" and "GATEWAY" with its corresponding values. |
---|
| 299 | They were read from the file "ECMWF_ENV". |
---|
| 300 | |
---|
| 301 | Return |
---|
| 302 | ------ |
---|
[54a8a01] | 303 | |
---|
| 304 | ''' |
---|
| 305 | |
---|
| 306 | for k, v in envs.iteritems(): |
---|
| 307 | setattr(self, str(k).lower(), str(v)) |
---|
| 308 | |
---|
| 309 | return |
---|
| 310 | |
---|
[2fb99de] | 311 | def check_conditions(self, queue): |
---|
[274f9ef] | 312 | '''Checks a couple of necessary attributes and conditions, |
---|
| 313 | such as if they exist and contain values. |
---|
| 314 | Otherwise set default values. |
---|
| 315 | |
---|
| 316 | Parameters |
---|
| 317 | ---------- |
---|
| 318 | queue : :obj:`string` |
---|
| 319 | Name of the queue if submitted to the ECMWF servers. |
---|
| 320 | Used to check if ecuid, ecgid, gateway and destination |
---|
| 321 | are set correctly and are not empty. |
---|
| 322 | |
---|
| 323 | Return |
---|
| 324 | ------ |
---|
| 325 | |
---|
[54a8a01] | 326 | ''' |
---|
[25b14be] | 327 | from mods.tools import my_error |
---|
[54a8a01] | 328 | import numpy as np |
---|
| 329 | |
---|
| 330 | # check for having at least a starting date |
---|
| 331 | # otherwise program is not allowed to run |
---|
[0e576fc] | 332 | if not self.start_date: |
---|
[2d56c04] | 333 | print('start_date specified neither in command line nor ' |
---|
| 334 | 'in CONTROL file ' + self.controlfile) |
---|
[2fb99de] | 335 | print('Try "' + sys.argv[0].split('/')[-1] + |
---|
| 336 | ' -h" to print usage information') |
---|
[54a8a01] | 337 | sys.exit(1) |
---|
| 338 | |
---|
| 339 | # retrieve just one day if end_date isn't set |
---|
[0e576fc] | 340 | if not self.end_date: |
---|
[812283d] | 341 | self.end_date = self.start_date |
---|
[54a8a01] | 342 | |
---|
[ca867de] | 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) |
---|
| 349 | |
---|
[3f36e42] | 350 | self.levelist, self.level = check_levels(self.levelist, self.level) |
---|
| 351 | |
---|
| 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 |
---|
[812283d] | 364 | |
---|
[3f36e42] | 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) |
---|
[0e576fc] | 373 | |
---|
[2fb99de] | 374 | # prepare step list if "/" signs are found |
---|
[54a8a01] | 375 | if '/' in self.step: |
---|
[2fb99de] | 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' + |
---|
[2d56c04] | 384 | 'if "to" is used in steps parameter, ' |
---|
| 385 | 'please use "by" as well') |
---|
[54a8a01] | 386 | else: |
---|
[2fb99de] | 387 | self.step = steps |
---|
[54a8a01] | 388 | |
---|
| 389 | # if maxstep wasn't provided |
---|
| 390 | # search for it in the "step" parameter |
---|
[0e576fc] | 391 | if not self.maxstep: |
---|
[812283d] | 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 | |
---|
[54a8a01] | 399 | # set root scripts since it is needed later on |
---|
| 400 | if not self.flexpart_root_scripts: |
---|
| 401 | self.flexpart_root_scripts = self.ecmwfdatadir |
---|
[812283d] | 402 | |
---|
[ca867de] | 403 | if not self.outputdir: |
---|
| 404 | self.outputdir = self.inputdir |
---|
| 405 | |
---|
[54a8a01] | 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] |
---|
[812283d] | 413 | |
---|
[54a8a01] | 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 | |
---|
[70fee58] | 422 | if queue in _config.QUEUES_LIST and \ |
---|
[2fb99de] | 423 | not self.gateway or not self.destination or \ |
---|
[54a8a01] | 424 | not self.ecuid or not self.ecgid: |
---|
[2d56c04] | 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!') |
---|
[54a8a01] | 429 | sys.exit(1) |
---|
[812283d] | 430 | |
---|
[2fb99de] | 431 | if self.request != 0: |
---|
[5d42acd] | 432 | marsfile = os.path.join(self.inputdir, |
---|
[2fb99de] | 433 | _config.FILE_MARS_REQUESTS) |
---|
| 434 | if os.path.isfile(marsfile): |
---|
[70fee58] | 435 | silent_remove(marsfile) |
---|
[2fb99de] | 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 | |
---|
[5bad6ec] | 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 | |
---|
[0e576fc] | 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' |
---|
| 482 | |
---|
[4d3b052] | 483 | self.purefc = check_purefc(self.type) |
---|
| 484 | |
---|
[3f36e42] | 485 | self.grid = check_grid(self.grid) |
---|
[97f4f4c] | 486 | |
---|
[3f36e42] | 487 | self.area = check_area(self.grid, self.area, self.upper, self.lower, |
---|
| 488 | self.left, self.right) |
---|
[97f4f4c] | 489 | |
---|
[2d56c04] | 490 | |
---|
[812283d] | 491 | return |
---|
| 492 | |
---|
[ff99eae] | 493 | def to_list(self): |
---|
[274f9ef] | 494 | '''Just generates a list of strings containing the attributes and |
---|
| 495 | assigned values except the attributes "_expanded", "exedir", |
---|
| 496 | "ecmwfdatadir" and "flexpart_root_scripts". |
---|
| 497 | |
---|
| 498 | Parameters |
---|
| 499 | ---------- |
---|
| 500 | |
---|
| 501 | Return |
---|
| 502 | ------ |
---|
| 503 | l : :obj:`list` |
---|
| 504 | A sorted list of the all ControlFile class attributes with |
---|
| 505 | their values except the attributes "_expanded", "exedir", |
---|
[812283d] | 506 | "ecmwfdatadir" and "flexpart_root_scripts". |
---|
| 507 | ''' |
---|
| 508 | |
---|
[54a8a01] | 509 | import collections |
---|
| 510 | |
---|
[5bad6ec] | 511 | attrs = collections.OrderedDict(sorted(vars(self).copy().items())) |
---|
[54a8a01] | 512 | |
---|
[812283d] | 513 | l = list() |
---|
| 514 | |
---|
| 515 | for item in attrs.items(): |
---|
| 516 | if '_expanded' in item[0]: |
---|
| 517 | pass |
---|
| 518 | elif 'exedir' in item[0]: |
---|
| 519 | pass |
---|
| 520 | elif 'flexpart_root_scripts' in item[0]: |
---|
| 521 | pass |
---|
| 522 | elif 'ecmwfdatadir' in item[0]: |
---|
| 523 | pass |
---|
| 524 | else: |
---|
[ff99eae] | 525 | if isinstance(item[1], list): |
---|
[812283d] | 526 | stot = '' |
---|
| 527 | for s in item[1]: |
---|
| 528 | stot += s + ' ' |
---|
| 529 | |
---|
[ff2a11c] | 530 | l.append("%s %s\n" % (item[0], stot)) |
---|
[812283d] | 531 | else: |
---|
[ff2a11c] | 532 | l.append("%s %s\n" % item) |
---|
[812283d] | 533 | |
---|
| 534 | return sorted(l) |
---|
[ff99eae] | 535 | |
---|