• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rjfarmer / gfModParser / 18106683549

29 Sep 2025 06:21PM UTC coverage: 90.669% (-0.1%) from 90.789%
18106683549

push

github

rjfarmer
Fix hextofloat

Closes #15

9 of 11 new or added lines in 2 files covered. (81.82%)

962 of 1061 relevant lines covered (90.67%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.67
/gfModParser/utils.py
1
# SPDX-License-Identifier: GPL-2.0+
2

3
import numpy as np
1✔
4
from packaging.version import Version
1✔
5

6
try:
1✔
7
    import pyquadp as pyq
1✔
8

9
    PYQ_IMPORTED = True
×
10
except ImportError:
1✔
11
    PYQ_IMPORTED = False
1✔
12

13

14
"""
1✔
15
Map gfortran version to Mod file version
16
"""
17

18

19
def gfortran_mod_map(version):
1✔
20
    if version < Version("4.8.1"):
×
21
        return Version("9")
×
22
    elif version < Version("4.9.2"):
×
23
        return Version("10")
×
24
    elif version < Version("5.1.0"):
×
25
        return Version("12")
×
26
    elif version < Version("8.0.0"):
×
27
        return Version("14")
×
28
    elif version < Version("15.0.0"):
×
29
        return Version("15")
×
30
    elif version.major == 15:
×
31
        return Version("16")
×
32
    else:
33
        raise ValueError(f"Unknown gfortran version {version}")
×
34

35

36
def string_clean(string):
1✔
37
    if string is None:
1✔
38
        return
1✔
39
    if string.startswith("'") or string.startswith('"'):
1✔
40
        string = string[1:]
1✔
41
    if string.endswith("'") or string.endswith('"'):
1✔
42
        string = string[:-1]
1✔
43

44
    return string
1✔
45

46

47
def hextofloat(s, kind=4):
1✔
48
    # Given hex like parameter '0.12decde@9' returns 5065465344.0
49
    if "@" in s:
1✔
50
        man, exp = s.split("@")
1✔
51
        exp = int(exp)
1✔
52
    else:
53
        man = s
1✔
54
        exp = 0
1✔
55

56
    if PYQ_IMPORTED and kind == 16:
1✔
NEW
57
        return pyq.qfloat.fromhex(man) * 16**exp
×
58
    elif kind == 8:
1✔
59
        return np.double.fromhex(man) * 16**exp
1✔
60
    else:
61
        return float.fromhex(man) * 16**exp
1✔
62

63

64
def dtype(type, kind, len=-1):
1✔
65
    if type == "REAL":
1✔
66
        if kind == 4:
1✔
67
            return np.dtype(np.float32)
1✔
68
        elif kind == 8:
1✔
69
            return np.dtype(np.float64)
1✔
70
        elif kind == 16:
×
71
            return np.dtype(np.float128)
×
72
    elif type == "INTEGER":
1✔
73
        if kind == 4:
1✔
74
            return np.dtype(np.int32)
1✔
75
        elif kind == 8:
×
76
            return np.dtype(np.int64)
×
77
        elif kind == 16:
×
78
            return np.dtype(np.int128)
×
79
    elif type == "UNSIGNED":
1✔
80
        if kind == 4:
×
81
            return np.dtype(np.uint32)
×
82
        elif kind == 8:
×
83
            return np.dtype(np.uint64)
×
84
        elif kind == 16:
×
85
            return np.dtype(np.uint128)
×
86
    elif type == "CHARACTER":
1✔
87
        return np.dtype(f"S{len}")
1✔
88
    elif type == "COMPLEX":
1✔
89
        if kind == 4:
×
90
            return np.dtype(np.complex64)
×
91
        elif kind == 8:
×
92
            return np.dtype(np.complex128)
×
93
        elif kind == 16:
×
94
            return np.dtype(np.complex256)
×
95
    elif type == "LOGICAL":
1✔
96
        return np.dtype(np.int32)
1✔
97
    else:
98
        raise NotImplementedError(f"Type={type} kind={kind}")
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc