Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91179560
txt2gadget.py
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
Fri, Nov 8, 17:08
Size
1 KB
Mime Type
text/x-python
Expires
Sun, Nov 10, 17:08 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22213537
Attached To
rPNBODY pNbody
txt2gadget.py
View Options
#!/usr/bin/env python
from
optparse
import
OptionParser
from
pNbody
import
*
import
Ptools
as
pt
########################################
#
# parser
#
########################################
def
parse_options
():
usage
=
"usage: %prog [options] file"
parser
=
OptionParser
(
usage
=
usage
)
parser
.
add_option
(
"-t"
,
action
=
"store"
,
dest
=
"ftype"
,
type
=
"string"
,
default
=
'gadget'
,
help
=
"type of the file"
,
metavar
=
" TYPE"
)
parser
.
add_option
(
"-o"
,
action
=
"store"
,
dest
=
"outputfile"
,
type
=
"string"
,
default
=
'snap.dat'
,
help
=
"name of the output file"
,
metavar
=
" FILE"
)
(
options
,
args
)
=
parser
.
parse_args
()
if
len
(
args
)
==
0
:
#print "you must specify a filename"
#sys.exit(0)
file
=
None
else
:
file
=
args
return
file
,
options
################################################################################
#
# MAIN
#
################################################################################
files
,
opt
=
parse_options
()
# read input file
x
,
y
,
z
=
pt
.
io
.
read_ascii
(
files
[
0
],[
0
,
1
,
2
])
n
=
len
(
x
)
pos
=
transpose
(
array
([
x
,
y
,
z
]))
vel
=
zeros
([
n
,
3
])
*
0.0
mass
=
ones
([
n
])
*
1.
/
n
nb
=
Nbody
(
status
=
'new'
,
p_name
=
opt
.
outputfile
,
pos
=
pos
,
vel
=
vel
,
mass
=
mass
,
ftype
=
opt
.
ftype
)
nb
.
write
()
Event Timeline
Log In to Comment