Skip to content
Create a gist now

Instantly share code, notes, and snippets.

A python function to convert FORTRAN formatted float strings into floats
import re
re_f_float_neg = re.compile('(-?[0-9.]*)(-\d\d\d)')
def fortran_float(input_string):
Return a float of the input string, just like `float(input_string)`,
but allowing for Fortran's string formatting to screw it up when
you have very small numbers (like 0.31674-103 instead of 0.31674E-103 )
fl = float(input_string)
except ValueError,e:
match = re_f_float_neg.match(input_string.strip())
if match:
processed_string ='E'
fl = float(processed_string)
print "Trying to find number from ",input_string
raise e
return fl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.