
import string
import os
import sys

# replace CONST(m,e) by mEe
def rmconst(s):
	n1 = string.find(s, "CONST(") + 6
        n2 = string.find(s,",",n1)
        n3 = string.find(s, ")", n2) # end of exponent
        m = s[n1:n2]
        p = s[n2+1:n3]
	s2 = s[0:n1-6]+m+"E"+p+"_dp"+s[n3+1:]
	if string.find(s2, "CONST") == -1:
		return s2
	else:
		return rmconst(s2)


# main program 
for line in sys.stdin.readlines():
	if line[0] != "#" and line[0:5] != "*DECK" :
		line = string.replace(line, "D1MACH(1)", "d1mach1")
		line = string.replace(line, "D1MACH(2)", "d1mach2")
		line = string.replace(line, "D1MACH(3)", "d1mach3")      
		line = string.replace(line, "D1MACH(4)", "d1mach4")
		line = string.replace(line, "D1MACH(5)", "d1mach5")
		line = string.replace(line, "J1MACH(15)", "j1mach15")
                line = string.replace(line, "J1MACH(14)", "j1mach14")
		line = string.replace(line, "AREAL","")
                line = string.replace(line,"REAL*8","real(kind=dp)")
		if string.find(line, "CONST") == -1:
			if string.find(line, "IMPLICIT NONE") != -1:
				print "      use kind_spec\n"
			print line[:-1]
		else:
			print rmconst(line)
