Page MenuHomec4science

gtrk2nbd
No OneTemporary

File Metadata

Created
Fri, Nov 8, 18:00

gtrk2nbd

#!/usr/bin/env python
'''
Convert glups .trk files into gwinparameters file
Yves Revaz
mer oct 25 10:27:24 CEST 2006
'''
import sys
import string
import os
from optparse import OptionParser
import glob
from math import *
from Gtools import io
def parse_options():
usage = "usage: %prog [options] file"
parser = OptionParser(usage=usage)
parser.add_option("--eye",
action="store",
dest="eye",
type="string",
default = 'default',
help="eye to compute ('default','both','right','left')",
metavar=" TYPE")
parser.add_option("--basename",
action="store",
dest="basename",
type="string",
default = None,
help="image base name",
metavar=" STRING")
parser.add_option("--snapfiles",
action="store",
dest="snapfiles",
type="string",
default = None,
help=" /data/snap/snapshot_* ",
metavar=" STRING")
parser.add_option("--size",
action="store",
dest="size",
type="string",
default = "(512,512)",
help="size (x,y)",
metavar=" STRING")
(options, args) = parser.parse_args()
if len(args) == 0:
print "you must specify at least a filename"
sys.exit(0)
files = args
return files,options
#######################################
# GET OPTIONS
#######################################
# get options
files,options = parse_options()
eye = options.eye
basename = options.basename
size = options.size
snapfiles = options.snapfiles
#######################################
# LOOP
#######################################
exec("size = %s"%(size))
if eye == 'default':
os.system('rm -rf center')
os.system('mkdir center')
elif eye == 'right':
os.system('rm -rf right')
os.system('mkdir right')
elif eye == 'left':
os.system('rm -rf left')
os.system('mkdir left')
elif eye == 'both':
os.system('rm -rf right')
os.system('mkdir right')
os.system('rm -rf left')
os.system('mkdir left')
else:
pass
# set files names
nfiles = len(files)
if snapfiles!=None:
snapfiles = glob.glob(snapfiles)
snapfiles.sort()
nsnap = len(snapfiles)
m = nfiles/nsnap + 1
if m == 0:
print "not enough files"
print "to much snapshot"
sys.exit()
final_snapfiles=[]
i = 0
j = 0
for file in files:
if basename!=None:
final_snapfiles.append(basename)
else:
final_snapfiles.append(snapfiles[j])
#print i,j,m,snapfiles[j]
if fmod(i,m)==0:
j = j+1
i = i+1
i = 0
old_final_snapfile = '-'
# read files
for file in files:
dic = io.read_track(file)
if old_final_snapfile == final_snapfiles[i]:
j = j + 1
else:
j = 0
old_final_snapfile = final_snapfiles[i]
# write
if eye == 'default':
outputfile = "center/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,eye,size)
elif eye == 'right':
outputfile = "right/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,eye,size)
elif eye == 'left':
outputfile = "left/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,eye,size)
elif eye == 'both':
outputfile = "right/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,'right',size)
outputfile = "left/%s.%05d"%(final_snapfiles[i],j)
io.write_nbodyparam(outputfile,dic,'left',size)
else:
pass
i = i + 1

Event Timeline