Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77888311
gvals
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 17, 00:42
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Aug 19, 00:42 (2 d)
Engine
blob
Format
Raw Data
Handle
19941368
Attached To
rGTOOLS Gtools
gvals
View Options
#!/home/revaz/local/bin/python
'''
Extract specific value of a particle from
a set of nbody files.
default file extension = .vals
Yves Revaz
mar jui 11 15:54:41 CEST 2006
'''
import
sys
,
os
from
numarray
import
*
import
SM
from
Nbody
import
*
from
Nbody
import
io
try
:
from
optparse
import
OptionParser
except
ImportError
:
from
optik
import
OptionParser
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
=
"file type"
,
metavar
=
" FTYPE"
)
parser
.
add_option
(
"--cmd"
,
action
=
"store"
,
dest
=
"cmd"
,
type
=
"string"
,
default
=
'v = nb.T()'
,
help
=
"command to extract value ex. 'v = nb.T()' "
,
metavar
=
" STRING"
)
parser
.
add_option
(
"-n"
,
action
=
"store"
,
dest
=
"number"
,
type
=
"int"
,
default
=
0
,
help
=
"particle number"
,
metavar
=
" INT"
)
parser
.
add_option
(
"--numfile"
,
action
=
"store"
,
dest
=
"numfile"
,
type
=
"string"
,
default
=
None
,
help
=
"file of particle number"
,
metavar
=
" FILE"
)
(
options
,
args
)
=
parser
.
parse_args
()
return
args
,
options
##########################################################
#
# MAIN
#
#########################################################
# get options
files
,
options
=
parse_options
()
ftype
=
options
.
ftype
number
=
options
.
number
cmd
=
options
.
cmd
numfile
=
options
.
numfile
#############################
# read numfile if it exists
#############################
if
numfile
!=
None
:
numbers
=
io
.
read_ascii
(
numfile
,[
0
])
numbers
=
numbers
[
0
]
.
astype
(
Int
)
else
:
numbers
=
array
([
number
],
Int
)
#############################
# open output files
#############################
fs
=
[]
ofiles
=
[]
for
number
in
numbers
:
ofile
=
"
%08d
.vals"
%
(
number
)
#f = open(ofile,'w')
#fs.append(f)
if
os
.
path
.
exists
(
ofile
):
os
.
remove
(
ofile
)
ofiles
.
append
(
ofile
)
#############################
# loops
#############################
for
file
in
files
:
nb
=
Nbody
(
file
,
ftype
=
ftype
)
nb
=
nb
.
selectp
(
numbers
)
exec
(
cmd
)
i
=
0
for
number
in
numbers
:
index
=
argmax
(
nb
.
num
==
number
)
vi
=
v
[
index
]
print
"
%s
,
%10.5f
%g
"
%
(
os
.
path
.
basename
(
file
),
nb
.
tnow
,
vi
)
#fs[i].write('%10.5f %g\n'%(nb.tnow,vi))
#fs[i].flush()
f
=
open
(
ofiles
[
i
],
'a'
)
f
.
write
(
'
%10.5f
%g
\n
'
%
(
nb
.
tnow
,
vi
))
f
.
close
()
i
=
i
+
1
#############################
# close output files
#############################
#for f in fs:
# f.close()
Event Timeline
Log In to Comment