Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80433977
ggalmer2gadget
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 31, 17:12
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Sep 2, 17:12 (2 d)
Engine
blob
Format
Raw Data
Handle
20337344
Attached To
rGTOOLS Gtools
ggalmer2gadget
View Options
#!/usr/bin/env python
'''
Convert galmer file into gadget file
Yves Revaz
ven oct 13 15:14:25 CEST 2006
'''
from
Nbody
import
*
import
string
from
optparse
import
OptionParser
import
sys
def
toarray
(
s
):
n
=
13
a
=
[]
for
i
in
range
(
6
):
a
.
append
(
float
(
s
[
i
*
n
:(
i
+
1
)
*
n
]))
return
a
def
parse_options
():
usage
=
"usage: %prog [options] file"
parser
=
OptionParser
(
usage
=
usage
)
parser
.
add_option
(
"-o"
,
action
=
"store"
,
dest
=
"outputfile"
,
type
=
"string"
,
default
=
None
,
help
=
"output file"
,
metavar
=
" FILE"
)
parser
.
add_option
(
"--ng"
,
action
=
"store"
,
dest
=
"ng"
,
type
=
"int"
,
default
=
None
,
help
=
"number of gaseous particles"
,
metavar
=
" INT"
)
parser
.
add_option
(
"--ns"
,
action
=
"store"
,
dest
=
"ns"
,
type
=
"int"
,
default
=
None
,
help
=
"number of star particles"
,
metavar
=
" INT"
)
parser
.
add_option
(
"--nd"
,
action
=
"store"
,
dest
=
"nd"
,
type
=
"int"
,
default
=
None
,
help
=
"number of dark particles"
,
metavar
=
" INT"
)
(
options
,
args
)
=
parser
.
parse_args
()
if
len
(
args
)
==
0
:
print
"you must specify a filename"
sys
.
exit
(
0
)
files
=
args
return
files
,
options
#############################
# main
#############################
# get options
files
,
options
=
parse_options
()
ng
=
options
.
ng
ns
=
options
.
ns
nd
=
options
.
nd
outputfile
=
options
.
outputfile
n3
=
ng
+
ns
+
nd
numlen
=
13
f
=
open
(
files
[
0
])
lines
=
f
.
readlines
()
f
.
close
()
# x
lx
=
lines
[
0
*
n3
/
6
:
1
*
n3
/
6
]
x
=
map
(
toarray
,
lx
)
x
=
ravel
(
array
(
x
))
# y
ly
=
lines
[
1
*
n3
/
6
:
2
*
n3
/
6
]
y
=
map
(
toarray
,
ly
)
y
=
ravel
(
array
(
y
))
# z
lz
=
lines
[
2
*
n3
/
6
:
3
*
n3
/
6
]
z
=
map
(
toarray
,
lz
)
z
=
ravel
(
array
(
z
))
# vx
lx
=
lines
[
3
*
n3
/
6
:
4
*
n3
/
6
]
vx
=
map
(
toarray
,
lx
)
vx
=
ravel
(
array
(
vx
))
# vy
ly
=
lines
[
4
*
n3
/
6
:
5
*
n3
/
6
]
vy
=
map
(
toarray
,
ly
)
vy
=
ravel
(
array
(
vy
))
# vz
lz
=
lines
[
5
*
n3
/
6
:
6
*
n3
/
6
]
vz
=
map
(
toarray
,
lz
)
vz
=
ravel
(
array
(
vz
))
# mass
lm
=
lines
[
6
*
n3
/
6
:
7
*
n3
/
6
]
mass
=
map
(
toarray
,
lm
)
mass
=
ravel
(
array
(
mass
))
# convert into gadget
pos
=
transpose
(
array
([
x
,
y
,
z
]))
vel
=
transpose
(
array
([
vx
,
vy
,
vz
]))
name
=
sys
.
argv
[
2
]
nb
=
Nbody
(
status
=
'new'
,
p_name
=
name
,
pos
=
pos
,
vel
=
vel
,
mass
=
mass
,
ftype
=
'gadget'
)
nb
.
nzero
=
n3
nb
.
npart
=
[
ng
,
nd
,
ns
,
0
,
0
,
0
]
nb
.
massarr
=
[
0
,
0
,
0
,
0
,
0
,
0
]
nb
.
u
=
zeros
(
nb
.
nbody
)
nb
.
rename
(
outputfile
)
nb
.
write
()
Event Timeline
Log In to Comment