Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101346422
gbinary_dis2gadget
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, Feb 8, 05:32
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Feb 10, 05:32 (2 d)
Engine
blob
Format
Raw Data
Handle
24141065
Attached To
rGTOOLS Gtools
gbinary_dis2gadget
View Options
#!/usr/bin/env python
'''
Convert binary(pfen) file into gadget file
Yves Revaz
mar oct 17 17:35:35 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("--mtot",
action="store",
dest="mtot",
type="float",
default = 1.0,
help="total mass in code unit",
metavar=" FLOAT")
parser.add_option("--u0",
action="store",
dest="u0",
type="float",
default = 0.0,
help="internal energy of gaz particles",
metavar=" FLOAT")
(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()
mtot = options.mtot
u0 = options.u0
outputfile = options.outputfile
nb = Nbody(files[0],ftype='binary_dis')
nb_wg = nb.subdis('wg')
nb_dg = nb.subdis('dg')
nb_sn = nb.subdis('nst')
nb_st = nb.subdis('st',10000)
nwg = nb_wg.nbody
ndg = nb_dg.nbody
nsn = 0
nst = nb_st.nbody
fwg=fdg=fsn=fst=0.
nb = nb.set_ftype('gadget')
n = nb.nbody
if nwg!=0:
fwg = 1
nb.pos = nb_wg.pos
nb.vel = nb_wg.vel
if ndg!=0:
fdg = 1
nb.pos = concatenate((nb.pos,nb_dg.pos))
nb.vel = concatenate((nb.vel,nb_dg.vel))
if nsn!=0:
fsn = 1
nb.pos = concatenate((nb.pos,nb_sn.pos))
nb.vel = concatenate((nb.vel,nb_sn.vel))
if nst!=0:
fst = 1
nb.pos = concatenate((nb.pos,nb_st.pos))
nb.vel = concatenate((nb.vel,nb_st.vel))
nb.npart =[nwg,ndg,0,nsn,nst,0]
nb.massarr=[mtot/n*fwg,mtot/n*fdg,0,mtot/n*fsn,mtot/n*fst,0]
nb.nzero = 0
if (nwg!=0):
# set specific energy gas particles
u0 = 1.
nb.u = u0*ones(n)
nb.rename(outputfile)
nb.write()
Event Timeline
Log In to Comment