Commit b662a643 authored by LAMBERT Jean-charles's avatar LAMBERT Jean-charles
Browse files

python3 pass

parent 7ead176e
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
# unsio module loading # unsio module loading
# ==> do not forget to update PYTHONPATH environment variable with # ==> do not forget to update PYTHONPATH environment variable with
# unsio location path # unsio location path
from __future__ import print_function
from unsio import * from unsio import *
import numpy as np import numpy as np
...@@ -33,7 +34,7 @@ def compute(file,out,comp,take,bits,mmult): ...@@ -33,7 +34,7 @@ def compute(file,out,comp,take,bits,mmult):
if uns.nextFrame(bits): if uns.nextFrame(bits):
unso=CunsOut(out,"gadget2") unso=CunsOut(out,"gadget2")
ok,tsnap=uns.getValueF("time") # return snasphot time ok,tsnap=uns.getValueF("time") # return snasphot time
print "Snapshot time : ","%.03f"%tsnap print ("Snapshot time : ","%.03f"%tsnap)
unso.setValueF("time",tsnap) # save snapshot time unso.setValueF("time",tsnap) # save snapshot time
# loop on all components stored in comp variable # loop on all components stored in comp variable
...@@ -68,85 +69,85 @@ def printAndSaveProp(uns,unso,comp,take,mmult): ...@@ -68,85 +69,85 @@ def printAndSaveProp(uns,unso,comp,take,mmult):
Component : [%s] Component : [%s]
---------------------------------------------- ----------------------------------------------
""" """
print info % (comp) print (info % (comp))
# return a 1D numpy data array with mass # return a 1D numpy data array with mass
ok,mass=uns.getArrayF(comp,"mass") ok,mass=uns.getArrayF(comp,"mass")
if ok: if ok:
print "mass =",mass.size,mass print ("mass =",mass.size,mass)
mass=keepEveryTake(mass,1,take) mass=keepEveryTake(mass,1,take)
if mmult==1: if mmult==1:
mass=mass*take # multiply mass by take mass=mass*take # multiply mass by take
print "mass =",mass.size,mass print ("mass =",mass.size,mass)
unso.setArrayF(comp,"mass",mass) # save mass unso.setArrayF(comp,"mass",mass) # save mass
# return a 1D numpy data array with pos # return a 1D numpy data array with pos
ok,pos=uns.getArrayF(comp,"pos") ok,pos=uns.getArrayF(comp,"pos")
if ok: if ok:
print "pos =",pos print ("pos =",pos)
pos=keepEveryTake(pos,3,take) pos=keepEveryTake(pos,3,take)
unso.setArrayF(comp,"pos",pos) # save pos unso.setArrayF(comp,"pos",pos) # save pos
# return a 1D numpy data array with vel # return a 1D numpy data array with vel
ok,vel=uns.getArrayF(comp,"vel") ok,vel=uns.getArrayF(comp,"vel")
if ok: if ok:
print "vel =",vel print ("vel =",vel)
vel=keepEveryTake(vel,3,take) vel=keepEveryTake(vel,3,take)
unso.setArrayF(comp,"vel",vel) # save vel unso.setArrayF(comp,"vel",vel) # save vel
# return a 1D numpy data array with acc # return a 1D numpy data array with acc
ok,acc=uns.getArrayF(comp,"acc") ok,acc=uns.getArrayF(comp,"acc")
if ok: if ok:
print "acc =",acc print ("acc =",acc)
acc=keepEveryTake(acc,3,take) acc=keepEveryTake(acc,3,take)
unso.setArrayF(comp,"acc",acc) # save vel unso.setArrayF(comp,"acc",acc) # save vel
# return a 1D numpy data array with rho # return a 1D numpy data array with rho
ok,rho=uns.getArrayF(comp,"rho") ok,rho=uns.getArrayF(comp,"rho")
if ok: if ok:
print "rho =",rho print ("rho =",rho)
rho=keepEveryTake(rho,1,take) rho=keepEveryTake(rho,1,take)
unso.setArrayF(comp,"rho",rho) # save rho unso.setArrayF(comp,"rho",rho) # save rho
# return a 1D numpy data array with temperature # return a 1D numpy data array with temperature
ok,temp=uns.getArrayF(comp,"temp") ok,temp=uns.getArrayF(comp,"temp")
if ok: if ok:
print "temp =",temp print ("temp =",temp)
temp=keepEveryTake(temp,1,take) temp=keepEveryTake(temp,1,take)
unso.setArrayF(comp,"temp",temp) # save temperature unso.setArrayF(comp,"temp",temp) # save temperature
# return a 1D numpy data array with internal energy (U) # return a 1D numpy data array with internal energy (U)
ok,u=uns.getArrayF(comp,"u") ok,u=uns.getArrayF(comp,"u")
if ok: if ok:
print "u =",u.size,u.dtype,u print ("u =",u.size,u.dtype,u)
u=keepEveryTake(u,1,take) u=keepEveryTake(u,1,take)
print "u =",u.size,u.dtype,u print ("u =",u.size,u.dtype,u)
unso.setArrayF(comp,"u",u) # save internal energy unso.setArrayF(comp,"u",u) # save internal energy
# return a 1D numpy data array with hsml # return a 1D numpy data array with hsml
ok,hsml=uns.getArrayF(comp,"hsml") ok,hsml=uns.getArrayF(comp,"hsml")
if ok: if ok:
print "hsml =",hsml print ("hsml =",hsml)
hsml=keepEveryTake(hsml,1,take) hsml=keepEveryTake(hsml,1,take)
unso.setArrayF(comp,"hsml",hsml) # save hsml unso.setArrayF(comp,"hsml",hsml) # save hsml
# return a 1D numpy data array with particles age # return a 1D numpy data array with particles age
ok,age=uns.getArrayF(comp,"age") ok,age=uns.getArrayF(comp,"age")
if ok: if ok:
print "age =",age print ("age =",age)
age=keepEveryTake(age,1,take) age=keepEveryTake(age,1,take)
unso.setArrayF(comp,"age",age) # save age unso.setArrayF(comp,"age",age) # save age
# return a 1D numpy data array with mettalicity # return a 1D numpy data array with mettalicity
ok,metal=uns.getArrayF(comp,"metal") ok,metal=uns.getArrayF(comp,"metal")
if ok: if ok:
print "metal =",metal print ("metal =",metal)
metal=keepEveryTake(metal,1,take) metal=keepEveryTake(metal,1,take)
unso.setArrayF(comp,"metal",metal) # save mettalicity unso.setArrayF(comp,"metal",metal) # save mettalicity
# return a 1D numpy data array with potential # return a 1D numpy data array with potential
ok,pot=uns.getArrayF(comp,"pot") ok,pot=uns.getArrayF(comp,"pot")
if ok: if ok:
print "pot =",pot print ("pot =",pot)
pot=keepEveryTake(pot,1,take) pot=keepEveryTake(pot,1,take)
unso.setArrayF(comp,"pot",pot) # save mettalicity unso.setArrayF(comp,"pot",pot) # save mettalicity
...@@ -155,7 +156,7 @@ def printAndSaveProp(uns,unso,comp,take,mmult): ...@@ -155,7 +156,7 @@ def printAndSaveProp(uns,unso,comp,take,mmult):
# return a 1D numy data array with id # return a 1D numy data array with id
ok,indexes=uns.getArrayI(comp,"id") ok,indexes=uns.getArrayI(comp,"id")
if ok: if ok:
print "indexes =", indexes print ("indexes =", indexes)
indexes=keepEveryTake(indexes,1,take) indexes=keepEveryTake(indexes,1,take)
unso.setArrayI(comp,"id",indexes) # save id unso.setArrayI(comp,"id",indexes) # save id
...@@ -175,7 +176,7 @@ def main(argv): ...@@ -175,7 +176,7 @@ def main(argv):
opts,args=getopt.getopt(argv,"hi:o:k:c:b:m:",["in=","out=","take=","comp=","bits=","mmult="]) opts,args=getopt.getopt(argv,"hi:o:k:c:b:m:",["in=","out=","take=","comp=","bits=","mmult="])
except getopt.GetoptError: except getopt.GetoptError:
print "\nUnknown parameters, please check ....\n\n" print ("\nUnknown parameters, please check ....\n\n")
printHelp(prog) printHelp(prog)
sys.exit() sys.exit()
for opt, arg in opts: for opt, arg in opts:
...@@ -192,14 +193,14 @@ def main(argv): ...@@ -192,14 +193,14 @@ def main(argv):
take = int(arg) take = int(arg)
elif opt in ("-b", "--bits"): elif opt in ("-b", "--bits"):
bits = arg bits = arg
elif opt in ("-m", "--mmult"): elif opt in ("-m", "--mmult"):
mmult = int(arg) mmult = int(arg)
if (infile != '' and out != '' and take !=0): if (infile != '' and out != '' and take !=0):
compute(infile,out,comp,take,bits,mmult) compute(infile,out,comp,take,bits,mmult)
else: else:
print "\nYou must provide input, output files and number of particles to take.....\n\n" print ("\nYou must provide input, output files and number of particles to take.....\n\n")
printHelp(prog) printHelp(prog)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
...@@ -233,7 +234,7 @@ def printHelp(prog): ...@@ -233,7 +234,7 @@ def printHelp(prog):
mmult : multiply mass by take (default 1 - yes, else 0 - no) mmult : multiply mass by take (default 1 - yes, else 0 - no)
""" """
print help % (prog,prog) print (help % (prog,prog))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# main # main
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment