Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
uahil
CPUnetPLOT
Commits
72b65a20
Commit
72b65a20
authored
Aug 08, 2014
by
Mario Hock
Browse files
Proof-of-concept CNL-file format parser
Get header as dict and csv lines as lists
parent
18d3b2b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
simple_plotter.py
0 → 100755
View file @
72b65a20
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import
sys
from
io
import
StringIO
import
json
import
csv
def
cnl_slice
(
file
,
start_delimiter
,
end_delimiter
):
## Find beginning
for
line
in
file
:
if
(
line
.
startswith
(
start_delimiter
)
):
break
## Skip comments and quit on end
for
line
in
file
:
if
(
line
.
startswith
(
end_delimiter
)
):
return
# skip empty or commented lines
if
(
not
line
or
line
[
0
]
==
"%"
or
line
[
0
]
==
"#"
):
continue
yield
line
def
read_header
(
f
):
str_io
=
StringIO
()
for
line
in
cnl_slice
(
f
,
"%% Begin_Header"
,
"%% End_Header"
):
str_io
.
write
(
line
)
str_io
.
seek
(
0
)
header
=
json
.
load
(
str_io
)
return
header
## MAIN ##
if
__name__
==
"__main__"
:
filename
=
sys
.
argv
[
1
]
print
(
filename
)
with
open
(
filename
)
as
in_file
:
assert
(
in_file
.
readline
()
==
"%% CPUnetLOGv1
\n
"
)
header
=
read_header
(
in_file
)
print
(
json
.
dumps
(
header
,
sort_keys
=
True
,
indent
=
4
)
)
## XXX
print
(
"///"
)
print
()
for
l
in
csv
.
reader
(
cnl_slice
(
in_file
,
"%% Begin_Body"
,
"%% End_Body"
)
):
print
(
l
)
pass
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment