Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PySWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
PySWIFTsim
Commits
421b4dee
Commit
421b4dee
authored
7 years ago
by
lhausamm
Browse files
Options
Downloads
Patches
Plain Diff
Add script helping to generate format/name for structure
parent
6a0e0f99
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!2
Update cooling with Grackle3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyswiftsim/dev.py
+69
-0
69 additions, 0 deletions
pyswiftsim/dev.py
with
69 additions
and
0 deletions
pyswiftsim/dev.py
0 → 100644
+
69
−
0
View file @
421b4dee
#!/usr/bin/env python3
symbol_table
=
{
"
int
"
:
"
i
"
,
"
double
"
:
"
d
"
,
"
char
"
:
"
c
"
,
}
def
_generateFormatString
(
filename
):
"""
Open a file containing a single struct and generate a format string
from it. (for dev, no guarantee of working).
"""
struct_format
=
""
struct_attribute
=
[]
with
open
(
filename
,
"
r
"
)
as
f
:
line
=
""
# skip until reaching struct
while
(
"
struct
"
not
in
line
):
line
=
f
.
readline
()
count
=
0
in_struct
=
False
while
(
not
in_struct
or
count
!=
0
):
# count { and }
count
+=
line
.
count
(
"
{
"
)
if
(
count
>
0
):
in_struct
=
True
count
-=
line
.
count
(
"
}
"
)
line
=
f
.
readline
()
for
k
in
symbol_table
.
keys
():
if
k
not
in
line
:
continue
i
=
line
.
index
(
k
)
+
len
(
k
)
if
(
line
[
i
]
==
"
*
"
):
struct_format
+=
"
p
"
i
+=
1
else
:
struct_format
+=
symbol_table
[
k
]
j
=
line
.
index
(
"
;
"
)
struct_attribute
.
append
(
line
[
i
:
j
])
return
struct_format
,
struct_attribute
if
__name__
==
"
__main__
"
:
filename
=
"
chemistry_data.h
"
struct_format
,
struct_attribute
=
_generateFormatString
(
filename
)
attr
=
"
[
\n
"
for
i
in
struct_attribute
:
attr
+=
"
\t
'
%s
'
,
\n
"
%
i
attr
+=
"
]
"
txt
=
"""
_format =
"
{form}
"
_name = {attr}
"""
.
format
(
attr
=
attr
,
form
=
struct_format
)
print
(
txt
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment