
import sys, math
from java.util import Vector
from jhplot import *
from array import *

wfile="mass_width_2004.csv"
#file=SystemDir+fSep+"macros"+fSep+"examples"+fSep+"data"+fSep+wfile
import urllib
urllib.urlretrieve ("http://datamelt.org/examples/data/"+wfile,wfile)


# vector with names
v1 = Vector()
v1.add("Name")
v1.add("Mass")
v1.add("Err-")
v1.add("Err+")
v1.add("Width")
v1.add("Err-")
v1.add("Err+")
v1.add("I")
v1.add("J")
v1.add("ID")
v1.add("charge")
v1.add("quark")

# data vector
v2 =Vector()

############## Now open file for reading (example)
ifile = open (wfile,'r')
lines = ifile.readlines()      # read file into list of lines
ifile.close()
# go through each line and split line into x and y columns:
mass = [];  mass_up = []; mass_down=[];   # store data pairs in two lists x and y
width = []; width_up = []; width_down=[];
I=[]  # isospin
G=[] # G parity
J=[] # J total spin
P=[] # P space parity
C=[] #  C charge conjugation parity
A=[] # A: antiparticle=|=particle flag
ID=[] #  PDG particle ID number
charge=[] # charge
R=[] #  Number of baryon stars - used only on baryons.
S=[] # particle status
name=[] # particle name
quark=[] # Quark contents  

pp=PND("data")
for line in lines:
     if  (line[0]=="*" or line[0]=="#"): continue  
     mass,mass_up,mass_down,width,width_up,\
     width_down,I,G,J,P,C,A,ID,charge,R,S,name,quark =line.split(",")
     quark = quark.replace('\n', '')
     vv=[float(mass),float(width)]
     ar=array('d',vv)
     pp.add(ar)
    
# show PDG
b=HTable(pp);

