Skip to content

Commit

Permalink
changed example file
Browse files Browse the repository at this point in the history
  • Loading branch information
pguridi committed Aug 24, 2012
1 parent 02aad80 commit bca639b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions examples/test.py → examples/example.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,47 @@

import os
import time
import sys

sys.path.append("..")

from flatfileparser import FlatReader, LineFormat, BeginsWithCondition
from flatfileparser.ffptypes import *
#YAFFP_TYPE_NUMERIC,YAFFP_TYPE_STRING, YAFFP_TYPE_FLOAT


if __name__ == '__main__':
start = time.time()

filePath = os.path.join("preplot_grande.s")
freader = FlatReader(filePath)
file_path = os.path.join("coordinates.txt")
freader = FlatReader(file_path, debug=True)

# Add the format for header lines:
# Filter Header Lines with a condition (if line begins with "H")
header_condition = BeginsWithCondition("H")
# Now define a format for the header lines
header_format = LineFormat("Header")
# Just lets get a single field of type STRING (whole line)
header_format.add_field("header_line", 1, -1, FFP_TYPE_STRING)
freader.declare_condition(header_condition, header_format)

# Add the format for SP lines
sp_format = LineFormat("SP")
# Now lets get the real data, in this case the following fields:
# Field_name type begin_column end_column
# line Numeric 1 5
# point Numeric 17 25
# x Float 46 54
# y Float 56 64

# Define the line format containing these fields:

sp_format = LineFormat("CoordinatesLine")
sp_format.add_field("line", 1, 5, FFP_TYPE_NUMERIC)
sp_format.add_field("point", 17, 25, FFP_TYPE_NUMERIC)
sp_format.add_field("x", 46, 54, FFP_TYPE_FLOAT)
sp_format.add_field("y", 56, 64, FFP_TYPE_FLOAT)
freader.register_line_format(sp_format)

# try:
for record in freader.read_line():
print record
# except Exception, e:
# print "Error parsing file: ", e

end = time.time()
elapsed = end - start
print "Elapsed time: " + str(elapsed) + " count: " + str(freader.get_count())
Expand Down

0 comments on commit bca639b

Please sign in to comment.