Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pykat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Sebastian Steinlechner
pykat
Commits
e50b48f9
Commit
e50b48f9
authored
11 years ago
by
Daniel Brown
Browse files
Options
Downloads
Patches
Plain Diff
move removing of comments and extra whitespace
parent
eca0a8ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pykat/finesse.py
+30
-23
30 additions, 23 deletions
pykat/finesse.py
with
30 additions
and
23 deletions
pykat/finesse.py
+
30
−
23
View file @
e50b48f9
...
@@ -76,7 +76,7 @@ class katRun(object):
...
@@ -76,7 +76,7 @@ class katRun(object):
def
get
(
self
,
value
):
return
self
[
value
]
def
get
(
self
,
value
):
return
self
[
value
]
def
__getitem__
(
self
,
value
):
def
__getitem__
(
self
,
value
):
idx
=
[
i
for
i
in
range
(
len
(
self
.
ylabels
))
if
self
.
ylabels
[
i
].
split
(
"
"
)[
0
]
==
str
(
value
)]
idx
=
[
i
for
i
in
range
(
len
(
self
.
ylabels
))
if
self
.
ylabels
[
i
].
split
()[
0
]
==
str
(
value
)]
if
len
(
idx
)
>
0
and
self
.
y
.
shape
==
():
if
len
(
idx
)
>
0
and
self
.
y
.
shape
==
():
# In the case we have a noxaxis and just one output...
# In the case we have a noxaxis and just one output...
...
@@ -123,7 +123,7 @@ class katRun2D(object):
...
@@ -123,7 +123,7 @@ class katRun2D(object):
def
get
(
self
,
value
):
return
self
[
value
]
def
get
(
self
,
value
):
return
self
[
value
]
def
__getitem__
(
self
,
value
):
def
__getitem__
(
self
,
value
):
idx
=
[
i
for
i
in
range
(
len
(
self
.
zlabels
))
if
self
.
zlabels
[
i
].
split
(
"
"
)[
0
]
==
str
(
value
)]
idx
=
[
i
for
i
in
range
(
len
(
self
.
zlabels
))
if
self
.
zlabels
[
i
].
split
()[
0
]
==
str
(
value
)]
if
len
(
idx
)
>
0
:
if
len
(
idx
)
>
0
:
return
self
.
z
[
idx
].
squeeze
()
return
self
.
z
[
idx
].
squeeze
()
...
@@ -340,7 +340,7 @@ class kat(object):
...
@@ -340,7 +340,7 @@ class kat(object):
constants
=
self
.
constants
constants
=
self
.
constants
for
line
in
commands
:
for
line
in
commands
:
values
=
line
.
split
(
'
'
)
values
=
line
.
split
()
if
len
(
values
)
>
0
and
values
[
0
]
==
'
const
'
:
if
len
(
values
)
>
0
and
values
[
0
]
==
'
const
'
:
...
@@ -354,11 +354,10 @@ class kat(object):
...
@@ -354,11 +354,10 @@ class kat(object):
commands_new
=
[]
commands_new
=
[]
print
constants
for
line
in
commands
:
for
line
in
commands
:
values
=
line
.
split
(
'
'
)
values
=
line
.
split
()
if
values
[
0
]
!=
'
const
'
:
if
len
(
values
)
>
0
and
values
[
0
]
!=
'
const
'
:
# check if we have a var/constant in this line
# check if we have a var/constant in this line
if
line
.
find
(
'
$
'
)
>=
0
:
if
line
.
find
(
'
$
'
)
>=
0
:
for
key
in
constants
.
keys
():
for
key
in
constants
.
keys
():
...
@@ -389,7 +388,7 @@ class kat(object):
...
@@ -389,7 +388,7 @@ class kat(object):
line
=
line
.
strip
()
line
=
line
.
strip
()
# Looking for block start or end
# Looking for block start or end
values
=
line
.
split
(
"
"
)
values
=
line
.
split
()
if
values
[
0
]
==
"
%%%
"
:
if
values
[
0
]
==
"
%%%
"
:
if
values
[
1
]
==
"
FTblock
"
:
if
values
[
1
]
==
"
FTblock
"
:
newTag
=
values
[
2
]
newTag
=
values
[
2
]
...
@@ -454,13 +453,13 @@ class kat(object):
...
@@ -454,13 +453,13 @@ class kat(object):
elif
(
first
==
"
noxaxis
"
):
elif
(
first
==
"
noxaxis
"
):
self
.
noxaxis
=
True
self
.
noxaxis
=
True
elif
(
first
==
"
phase
"
):
elif
(
first
==
"
phase
"
):
v
=
line
.
split
(
"
"
)
v
=
line
.
split
()
if
len
(
v
)
!=
2
:
if
len
(
v
)
!=
2
:
raise
pkex
.
BasePyKatException
(
"
phase command `{0}` is incorrect.
"
.
format
(
line
))
raise
pkex
.
BasePyKatException
(
"
phase command `{0}` is incorrect.
"
.
format
(
line
))
else
:
else
:
self
.
phase
=
int
(
v
[
1
])
self
.
phase
=
int
(
v
[
1
])
elif
(
first
==
"
maxtem
"
):
elif
(
first
==
"
maxtem
"
):
v
=
line
.
split
(
"
"
)
v
=
line
.
split
()
if
len
(
v
)
!=
2
:
if
len
(
v
)
!=
2
:
raise
pkex
.
BasePyKatException
(
"
maxtem command `{0}` is incorrect.
"
.
format
(
line
))
raise
pkex
.
BasePyKatException
(
"
maxtem command `{0}` is incorrect.
"
.
format
(
line
))
else
:
else
:
...
@@ -469,13 +468,13 @@ class kat(object):
...
@@ -469,13 +468,13 @@ class kat(object):
else
:
else
:
self
.
maxtem
=
int
(
v
[
1
])
self
.
maxtem
=
int
(
v
[
1
])
elif
(
first
==
"
retrace
"
):
elif
(
first
==
"
retrace
"
):
v
=
line
.
split
(
"
"
)
v
=
line
.
split
()
if
len
(
v
)
>
2
:
if
len
(
v
)
>
2
:
raise
pkex
.
BasePyKatException
(
"
Retrace command `{0}` is incorrect.
"
.
format
(
line
))
raise
pkex
.
BasePyKatException
(
"
Retrace command `{0}` is incorrect.
"
.
format
(
line
))
elif
len
(
v
)
==
2
:
elif
len
(
v
)
==
2
:
self
.
retrace
=
v
[
1
]
self
.
retrace
=
v
[
1
]
elif
(
first
==
"
deriv_h
"
):
elif
(
first
==
"
deriv_h
"
):
v
=
line
.
split
(
"
"
)
v
=
line
.
split
()
if
len
(
v
)
!=
2
:
if
len
(
v
)
!=
2
:
raise
pkex
.
BasePyKatException
(
"
deriv_h command `{0}` is incorrect.
"
.
format
(
line
))
raise
pkex
.
BasePyKatException
(
"
deriv_h command `{0}` is incorrect.
"
.
format
(
line
))
else
:
else
:
...
@@ -500,7 +499,7 @@ class kat(object):
...
@@ -500,7 +499,7 @@ class kat(object):
if
first
==
"
gauss
"
or
first
==
"
gauss*
"
or
first
==
"
gauss**
"
:
if
first
==
"
gauss
"
or
first
==
"
gauss*
"
or
first
==
"
gauss**
"
:
pykat
.
commands
.
gauss
.
parseFinesseText
(
line
)
pykat
.
commands
.
gauss
.
parseFinesseText
(
line
)
elif
(
first
==
"
scale
"
):
elif
(
first
==
"
scale
"
):
v
=
line
.
split
(
"
"
)
v
=
line
.
split
()
if
len
(
v
)
==
3
:
if
len
(
v
)
==
3
:
component_name
=
v
[
2
]
component_name
=
v
[
2
]
if
component_name
in
self
.
__detectors
:
if
component_name
in
self
.
__detectors
:
...
@@ -512,7 +511,7 @@ class kat(object):
...
@@ -512,7 +511,7 @@ class kat(object):
else
:
else
:
raise
pkex
.
BasePyKatException
(
"
scale command `{0}` is incorrect.
"
.
format
(
text
))
raise
pkex
.
BasePyKatException
(
"
scale command `{0}` is incorrect.
"
.
format
(
text
))
elif
(
first
==
"
pdtype
"
):
elif
(
first
==
"
pdtype
"
):
v
=
line
.
split
(
"
"
)
v
=
line
.
split
()
if
len
(
v
)
==
3
:
if
len
(
v
)
==
3
:
component_name
=
v
[
1
]
component_name
=
v
[
1
]
if
component_name
in
self
.
__detectors
:
if
component_name
in
self
.
__detectors
:
...
@@ -709,7 +708,7 @@ class kat(object):
...
@@ -709,7 +708,7 @@ class kat(object):
perffile
=
open
(
root
[
0
]
+
"
.perf
"
,
'
r
'
)
perffile
=
open
(
root
[
0
]
+
"
.perf
"
,
'
r
'
)
for
l
in
perffile
.
readlines
():
for
l
in
perffile
.
readlines
():
vals
=
l
.
strip
().
split
(
'
'
)
vals
=
l
.
strip
().
split
()
perfData
.
append
((
vals
[
0
],
float
(
vals
[
1
]),
float
(
vals
[
2
]),
float
(
vals
[
3
])))
perfData
.
append
((
vals
[
0
],
float
(
vals
[
1
]),
float
(
vals
[
2
]),
float
(
vals
[
3
])))
return
[
r
,
perfData
]
return
[
r
,
perfData
]
...
@@ -991,6 +990,7 @@ class kat(object):
...
@@ -991,6 +990,7 @@ class kat(object):
"""
"""
This takes a raw Finesse code string and removes any comments
This takes a raw Finesse code string and removes any comments
It returns a list of lines however, not a multiline string.
It returns a list of lines however, not a multiline string.
Also removes any extrawhite space in command lines.
"""
"""
pattern
=
r
"
(\".*?\"|\'.*?\'|%{3}[^\r\n]*$)|(/\*.*?\*/|%[^\r\n]*$|#[^\r\n]*$|//[^\r\n]*$)
"
pattern
=
r
"
(\".*?\"|\'.*?\'|%{3}[^\r\n]*$)|(/\*.*?\*/|%[^\r\n]*$|#[^\r\n]*$|//[^\r\n]*$)
"
# first group captures quoted strings (double or single)
# first group captures quoted strings (double or single)
...
@@ -1010,6 +1010,10 @@ class kat(object):
...
@@ -1010,6 +1010,10 @@ class kat(object):
commands
=
[]
commands
=
[]
for
line
in
string
.
split
(
'
\n
'
):
for
line
in
string
.
split
(
'
\n
'
):
line
=
line
.
replace
(
'
\r
'
,
''
)
if
len
(
line
)
>
0
:
# remove any mutliple whitespace
line
=
"
"
.
join
(
line
.
split
())
# add to a list all the positions of any inline comment markers
# add to a list all the positions of any inline comment markers
i
=
[
line
.
find
(
'
#
'
),
line
.
find
(
'
\\
'
)]
i
=
[
line
.
find
(
'
#
'
),
line
.
find
(
'
\\
'
)]
i
=
filter
(
lambda
a
:
a
!=
-
1
,
i
)
i
=
filter
(
lambda
a
:
a
!=
-
1
,
i
)
...
@@ -1017,7 +1021,10 @@ class kat(object):
...
@@ -1017,7 +1021,10 @@ class kat(object):
if
len
(
i
)
==
0
:
if
len
(
i
)
==
0
:
commands
.
append
(
line
)
commands
.
append
(
line
)
else
:
else
:
commands
.
append
(
line
[
0
:
min
(
i
)])
line
=
line
[
0
:
min
(
i
)]
if
len
(
line
):
commands
.
append
(
line
)
return
commands
return
commands
...
...
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