Skip to content

Commit

Permalink
Merge pull request #315 from xylar/get_cime_earth_radius
Browse files Browse the repository at this point in the history
Add CIME Earth radius
  • Loading branch information
xylar authored May 29, 2020
2 parents db8ffdf + 18681f1 commit 1bd41e5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
Empty file.
2 changes: 2 additions & 0 deletions conda_package/mpas_tools/cime/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
constants = \
{'SHR_CONST_REARTH': 6.37122e6}
47 changes: 47 additions & 0 deletions conda_package/mpas_tools/tests/test_cime_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from mpas_tools.cime.constants import constants
import requests


def test_cime_constants(e3sm_tag='master'):
"""
Parse relevant constants from CIME
Parameters
----------
e3sm_tag : str, optional
The E3SM tag to download CIME constants from
"""

resp = requests.get(
'https://raw.githubusercontent.com/E3SM-Project/E3SM/{}/cime/src/share'
'/util/shr_const_mod.F90'.format(e3sm_tag))

text = resp.text

text = text.split('\n')

for line in text:
for constant in constants:
if constant in line:
print('verifying {}'.format(constant))
value = _parse_value(line, constant)
assert value == constants[constant]


def _parse_value(line, key):
line, _ = line.split('!', 1)
_, line = line.split('=')
if '&' in line:
raise ValueError('This parser is too dumb to handle multi-line Fortran')

line, _ = line.split('_R8')

try:
value = float(line)
except ValueError:
value = line

return value

if __name__ == '__main__':
test_cime_constants()
1 change: 1 addition & 0 deletions conda_package/recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ requirements:
test:
requires:
- pytest
- requests
source_files:
- mesh_tools/mesh_conversion_tools/test/Arctic_Ocean.geojson
- mesh_tools/mesh_conversion_tools/test/mesh.QU.1920km.151026.nc
Expand Down

0 comments on commit 1bd41e5

Please sign in to comment.