#!/usr1/python/bin/python 
import numpy
import ppgplot
import math

def fixenv (xrange=[0,1], yrange=[0,1], fname="none", ci = 2):
                              # set axis ranges.
    ppgplot.pgswin(xrange[0],xrange[1],yrange[0],yrange[1])     
    ppgplot.pgsci(ci)                # set color index.
    ppgplot.pgbox()                  # draw axes. 
    ppgplot.pgsci(1)                 # back to color index 1 (white)
    print fname
    ppgplot.pglab("x","y",fname)     # label the plot

    
# initialize ploting.
ppgplot.pgbeg("?",2,2)       # open ploting device (2x2 pannels)
ppgplot.pgiden()                 # put user-name and date on plot.
ppgplot.pgask(1)                 # wait for user to press a key before erasing.

# calculate some suitable functions.
x = numpy.arange(0.01,6.*math.pi,0.1)
y = numpy.zeros([2,2,x.shape[0]],float)
label = numpy.zeros([2,2],dtype=numpy.char.chararray)
y[0,0] = numpy.sin(2*x)/x
label[0,0] = "sin(2*x)/x"
y[1,0] = numpy.sin(2*x)
label[1,0] = "sin(2*x)"
y[0,1] = x*numpy.sin(2*x)
label[0,1] = "x*sin(2*x)"
y[1,1] = numpy.sin(x) + numpy.sin(2*x) + numpy.sin(3*x)
label[1,1] = "sin(x) + sin(2*x) + sin(3*x)"

print type(label)
print label[0,0]
print label[0,1]
print label[1,0]
print label[1,1]

# do the plotting
for i in range(2):
    for j in range(2):
	ppgplot.pgpanl(i+1,j+1)
	fixenv([0.0,6.*math.pi],[min(y[i,j]),max(y[i,j])],label[i,j], i*2+j+2)
	ppgplot.pgslw(6);          # set line-width to 6/201.
	ppgplot.pgsls(i*2+j+1)     # set the line style.
	ppgplot.pgline(x,y[i,j])   # plot the line.
	ppgplot.pgsls(1);          # recall line-style
	ppgplot.pgslw(1);          # recall line-width

#close the plot.
ppgplot.pgend()
