source: palm/trunk/UTIL/WRF_interface/dynamic/palm_dynamic_config.py @ 4901

Last change on this file since 4901 was 4843, checked in by raasch, 3 years ago

local namelist parameter added to switch off the module although the respective module namelist appears in the namelist file, further copyright updates

File size: 2.6 KB
Line 
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4#------------------------------------------------------------------------------#
5#
6# Scripts for processing of WRF and CAMx files to PALM dynamic driver
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20#
21# Copyright 2018-2021 Institute of Computer Science
22#                     of the Czech Academy of Sciences, Prague
23# Authors: Krystof Eben, Jaroslav Resler, Pavel Krc
24#
25#------------------------------------------------------------------------------#
26'''Configuration module.
27
28Configuration options are sourced into this module's globals.
29'''
30
31import os.path
32from pathlib import Path
33import inspect
34
35
36# Just for PyCharm and similar IDEs to allow autocompletion from config values
37if False:
38    from palm_dynamic_defaults import *
39    from palm_dynamic_init import *
40
41def configure(configname):
42    global dir_scripts
43    # get path of the palm_dynamic script to source default config and init
44    dir_scripts = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
45    print('Running palm_dynamic from:', dir_scripts)
46    # use config defaults
47    configdefaultsfile = os.path.join(dir_scripts, "palm_dynamic_defaults.py")
48    print('Default case config: ', configdefaultsfile)
49    # user config file is located in configurations directory
50    configfile = os.path.join(os.path.abspath(Path(dir_scripts).parent), "configurations", configname + '.conf')
51    print('User case config:', configfile)
52    # initialization of standard parameters done in script
53    standardinitfile = os.path.join(dir_scripts, "palm_dynamic_init.py")
54    print('Standard initialization: ', standardinitfile)
55    # check existence of the supplied config file
56    if not os.path.isfile(configfile):
57        print("Config file " + configfile + " does not exists!")
58        print_help()
59        exit(2)
60    # read default config values
61    exec(open(configdefaultsfile).read(), globals())
62    # read user configuration
63    exec(open(configfile).read(), globals())
64    # perform the standard initialization
65    exec(open(standardinitfile).read(), globals())
Note: See TracBrowser for help on using the repository browser.