Created
September 7, 2011 04:11
-
-
Save tmiz/1199745 to your computer and use it in GitHub Desktop.
genEmbeddedFloatTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys,os | |
""" | |
$ ./genEmbeddedFloatTable txtCopyFromExcel.txt aCertainCoefTable | |
const float aCertainCoefTable[24] = { | |
0.10f , 0.09f , 0.09f , 0.08f , 0.07f , 0.07f , 0.07f , 0.06f , 0.06f , 0.06f , | |
0.05f , 0.04f , 0.04f , 0.04f , 0.03f , 0.03f , 0.02f , 0.01f , 0.01f , 0.06f , | |
0.06f , 0.06f , 0.06f , 0.06f | |
}; | |
""" | |
if (__name__)=="__main__": | |
if (len(sys.argv) != 3): | |
print "usage: %s <file> <arrayname>" % sys.argv[0] | |
else: | |
f = open(sys.argv[1]) | |
lines, values,count = f.readlines(), list(), 0 | |
[values.append(float(i.replace("\n",""))) for i in lines] | |
numOfValues = len(values) | |
print "const float %s[%d] = {" % (sys.argv[2],numOfValues) | |
while True: | |
if (count == numOfValues):break | |
if (count is not 0): print ",", | |
if (count % 10 is 0) and (count is not 0): print "" | |
print "%1.2ff" % values[count], | |
count += 1 | |
print "\n};" | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment