Hi. This is a small script I did to parse PTH files on Python. It's based on Dygear's PHP implementation (
http://www.lfsforum.net/showth ... t=71343&highlight=pth).
<?php
import struct
def parse_pth(file):
print "Parsing ",file
f=open(file,"rb")
f.seek(6)
version,rev=struct.unpack('bb',f.read(2))
f.seek(8)
total_nodes,finish_line=struct.unpack('ll',f.read(8))
print "Version: ",version, " Revision: ",rev, "Total nodes: ",total_nodes, " Finish line:", finish_line
nodes=[]
for i in range(0,total_nodes):
f.seek(16+40*i)
bn=f.read(40)
nodes.append({"center": struct.unpack('lll',bn[0:12]),"direction": struct.unpack('fff',bn[12:24]),"limit":struct.unpack('ff',bn[24:32]),"road": struct.unpack('ff',bn[32:40])})
f.close()
return (nodes,total_nodes,finish_line,version,rev)
#Example Usage
(nodes,total_nodes,finish_line,version,rev)=parse_pth("./pth/BL1.pth")
for id,node in enumerate(nodes):
print "Node:",id, ", center (x,y,z):", node["center"], ", direction (x,y,z):",node["direction"], ", limits: ",node["limit"], ", road limit: ",node["road"]
?>