"serialization/vscode:/vscode.git/clone" did not exist on "c7441b962ddd2afe3bdb085374b1b4ae6d2c56fe"
Unverified Commit 78a31f3b authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Improve accuracy of constants in Fortran interface (#3264)

* Improve accuracy of constants in Fortran interface

* Use different suffix for Fortran constants
parent c456dd54
...@@ -902,6 +902,7 @@ class FortranHeaderGenerator(WrapperGenerator): ...@@ -902,6 +902,7 @@ class FortranHeaderGenerator(WrapperGenerator):
def writeGlobalConstants(self): def writeGlobalConstants(self):
self.out.write(" ! Global Constants\n\n") self.out.write(" ! Global Constants\n\n")
self.out.write(" integer, parameter :: dp = kind(1.d0)\n")
node = next((x for x in findNodes(self.doc.getroot(), "compounddef", kind="namespace") if x.findtext("compoundname") == "OpenMM")) node = next((x for x in findNodes(self.doc.getroot(), "compounddef", kind="namespace") if x.findtext("compoundname") == "OpenMM"))
for section in findNodes(node, "sectiondef", kind="var"): for section in findNodes(node, "sectiondef", kind="var"):
for memberNode in findNodes(section, "memberdef", kind="variable", mutable="no", prot="public", static="yes"): for memberNode in findNodes(section, "memberdef", kind="variable", mutable="no", prot="public", static="yes"):
...@@ -909,6 +910,9 @@ class FortranHeaderGenerator(WrapperGenerator): ...@@ -909,6 +910,9 @@ class FortranHeaderGenerator(WrapperGenerator):
iDef = getText("initializer", memberNode) iDef = getText("initializer", memberNode)
if iDef.startswith("="): if iDef.startswith("="):
iDef = iDef[1:] iDef = iDef[1:]
# Append _dp to constants so they will be interpreted as double precision. Some constants
# are defined as ratios, so we need to append it to both numerator and denominator.
iDef = '/'.join(f'{x}_dp' for x in iDef.split('/'))
self.out.write(" real*8, parameter :: OpenMM_%s = %s\n" % (vDef, iDef)) self.out.write(" real*8, parameter :: OpenMM_%s = %s\n" % (vDef, iDef))
def writeTypeDeclarations(self): def writeTypeDeclarations(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment