Java ptolemy plot package.

G

Guest

I just got a new book that uses the java language ("A first course in
Scientific Programming"). The authors source
code uses a "import ptlomey.plot.*" line but the author doesn't include the
source. I can go to the web, for
windows environment but it takes to long to download. (About six hours --
usually my dial-up connection crashed
after about and hour). Is there any way to download the source and compile
it?.
_________________________________________ Mitchell McNurlin ICQ#:235649936
Current ICQ status: SMS: (Send an SMS message to my ICQ): +2783142235649936
More ways to contact me: http://wwp.icq.com/235649936
_________________________________________
 
A

Andrew Thompson

..I can go to the web, for
windows environment but it takes to long to download. (About six hours --
usually my dial-up connection crashed
after about and hour). Is there any way to download the source and compile
it?.

I almost imagine a Zip file of the source
would be bigger than the binaries.

You are better to look at a program that
can resume a failed download (assuming
the server supports that).

Alternately, I will often go to 'any local
computer shop' and download things that are
impractical or difficult on my connection.

If you walk in with a CD*, an URL, and $5
will generally do it around these parts.

* You never stated how big it was, I am
talking downloads of around 200-300 meg.

Andrew T.
 
G

Guest

I got something to download. The book told me to put c:\ptplot in the class
path. I typed echo %CLASSPATH% and got ;"co:\putlog".

The author has a java file called Easy.java. When I compile it gives me
these errors.
import Ptolemy.plot.*;
^
EasyPtPlot.java:21: cannot access Plot
bad class file: co:\putlog\Plot.class
class file contains wrong class: ptolemy.plot.Plot
Please remove or make sure it appears in the correct subdirectory of the
classpath.
Plot plotObj = new Plot();
^
2 errors

P.S. I have very little "real world" experience in java. (I had some free
training in a past life, but not enough)

This is how it wants to compile: "import ptolemy.plot.*;"
 
A

Andrew Thompson

Please refrain from top-posting.
I got something to download. The book told me to put
c:\ptplot in the class

How old is the book? Sun's advice (for some
considerable time now) has been to add resources
to projects at compile or run-time.
path. I typed echo %CLASSPATH% and got ;"co:\putlog".

I do not understand what this co:\ptulog is?

Do you have a Windows FS type drive of name
'co'?
The author has a java file called Easy.java. When I compile it gives me
these errors.
import Ptolemy.plot.*;
...

Mote that import could only find a class named..
class file contains wrong class: ptolemy.plot.Plot

Ptolemy.plot.Plot
...as opposed to what it is asking for, which is..
ptolemy.plot.Plot

Java package and class names are case sensitive.
The conventional capitalisation is

all.package.lower.case.ClassNameHasEachWordFirstLetterUpper

Andrew T.
 
G

Guest

I am sorry. The CLASSPATH was .;c:\ptplot. This means to me the classpath
searches the current director and
c:\ptplot

The book was copyrighted in 2005 by Rubin H. Landau.
 
G

Guest

EasyPtPlot.java:10: package ptolemy.plot does not exist
import ptolemy.plot.*;
^
EasyPtPlot.java:21: cannot access Plot
bad class file: c:\ptplot\Plot.class
class file contains wrong class: ptolemy.plot.Plot
Please remove or make sure it appears in the correct subdirectory of the
classpath.
Plot plotObj = new Plot();
^
2 errors

Maybe I am installing the plot package wrong. I am going to look in the
documentation.

The author says "If this does not work, ask for help."

Anyway here is the code:
// EasyPtPlot.java: simple application plots f(x)
/*
From: "A FIRST COURSE IN SCIENTIFIC COMPUTING" by R Landau
Contributors: K Augustson, R Wangberg, S Haerer,
C Barnes, M Paez, C. Bordeianu
Copyright Princeton University Press, Princeton, 2005
Electronic copyright R Landau Oregon State Univ 2005
Support by National Science Foundation, NPACI-EOT
*/
import ptolemy.plot.*;

public class EasyPtPlot
{
// The domain for the graph. The range is determined automatically.
public static final double Xmin = -5.0, Xmax = 5.0;
public static final int Npoint = 500;

public static void main(String[] args)
{
// Create a Plot object (from the
ptplot package).
Plot plotObj = new Plot();

plotObj.setTitle("f(x) vs x");
plotObj.setXLabel("x");
plotObj.setYLabel("f(x)");
// plotObj.setSize(400, 300);
// plotObj.setXRange(Xmin, Xmax);

// Add some data points to the Plot object, using addPoint.
// In this case, the y values are generated from the function cos(x).

/* Format: plotObj.addPoint(int dataSet, double x, double y, boolean
connect)
dataSet is for plotting multiple functions on the same graph.
connect should be true if a point connects to the previous point.
*/

double xStep = (Xmax - Xmin) / Npoint;
for (double x = Xmin; x <= Xmax; x += xStep)
{
double y = Math.cos(x);
plotObj.addPoint(0, x, y, true);
}
// Create a PlotApplication, to display the Plot object.
PlotApplication app = new PlotApplication(plotObj);
}
}
 
A

Andrew Thompson

I didn't mean do anything wrong. What is meant by the term "top-post"?

It was mentioned to you, the very first time
you did it. Read replies carefully. Or do you
just intend to continue wasting my time?

Andrew T.
 
L

Lew

I didn't mean do anything wrong. What is meant by the term "top-post"?

GIYF!

A: Because it makes posts harder to read.
Q: Why is it bad?
A: Placing the reply above the quoted material (as opposed to inline, like a
conversation).
Q: What is top-posting?

-- Lew
 
G

Guest

Lew said:
GIYF!

A: Because it makes posts harder to read.
Q: Why is it bad?
A: Placing the reply above the quoted material (as opposed to inline, like
a conversation).
Q: What is top-posting?

-- Lew

Thank you.

I am I doing this right now? I should have read thru the posts, to see how
other people write their letters.

By messing around the CLASSPATH variable I got one of the compiler errors to
go away. It knows where the package is, but I still can't instantiate the
class.

Here is the error:

""EasyPtPlot.java:21: cannot access Plot
bad class file: c:\ptplot\Plot.class
class file contains wrong class: ptolemy.plot.Plot
Please remove or make sure it appears in the correct subdirectory of the
classpath.
Plot plotObj = new Plot();
^
1 error"
 
L

Lew

[-- trimmed the part no longer relevant --]
By messing around the CLASSPATH variable I got one of the compiler errors to
go away. It knows where the package is, but I still can't instantiate the
class.

Here is the error:

""EasyPtPlot.java:21: cannot access Plot
bad class file: c:\ptplot\Plot.class
class file contains wrong class: ptolemy.plot.Plot
Please remove or make sure it appears in the correct subdirectory of the
classpath.
Plot plotObj = new Plot();
^
1 error"

Welcome to the wonderful world of classpaths, packages and directories, which
drove me away from Java the first time I tried to use it (in 1997 or so).
Don't feel bad - it's genuinely wacky at first.

Long post follows. Or skip it and read the Sun tutorial. Or read it and read
the Sun tutorial on packages.

Java breaks up classes into "packages" - groups of related classes. Each
package has a dotted name sort of like object references, such as

package com.lewscanon.whoneedsstruts.dispatcher;

Notice that it looks an awful lot like a backwards URL; that's because that's
what it is. This package belongs to the domain "lewscanon.com" at least
fictionally, and within that domain it has a group of things named
"whoneedsstruts" and another group of things called "whoneedsstruts.dispatcher".

Notice that the second one looks like it sort of belongs to the first. It does
not. Despite the common element "com.lewscanon.whoneedsstruts" between them,
the two packages are separate.

Every class that belongs to a package has a full name, the combination of the
package and the class name, such as

com.lewscanon.whoneedsstruts.dispatcher.Dispatcher

This is a class 'Dispatcher' that belongs to the package
'com.lewscanon.whoneedsstruts.dispatcher'.

In a typical file system, each class is represented by a .class file, which
perforce resides in a subdirectory of the file system. So somewhere on my hard
drive I have this file 'Dispatcher.class' that has the bytecode for the
'Dispatcher' class. But in what subdirectory? Here the joy begins.

To help things along, Java loads classes from subdirectories that match
package name parts exactly, with each name part corresponding to another
subdirectory level. So my package

com.lewscanon.whoneedsstruts.dispatcher

has a subdirectory with the relative path

com/lewscanon/whoneedsstruts/dispatcher/

in which we find a file 'Dispatcher.class'.

Notice that I did not put a leading '/' in that path - it is relative to some
parent directory. Let's say that I put all my Java applications inside the
directory

/opt/apps/

Then the full pathname to the class file is

/opt/apps/com/lewscanon/whoneedsstruts/dispatcher/Dispatcher.class

See how the directory parts match the package parts?

But how does Java know to start at /opt/apps? By the classpath. You found out
that the CLASSPATH environment variable can help, but that is a global and
somewhat inflexible solution. More useful is a parameter '-cp' ('-classpath')
to the 'java' command:

java -cp /opt/apps com.lewscanon.whoneedsstruts.dispatcher.Dispatcher

Notice that I told 'java' a fully-qualified class name, with dots not slashes.
This is a class name, not a file name, so it is "package.Class", not
"path/Class.class". The '-cp' option did use slashes, because its argument is
a path.

A path can hold many directories, separated by ':' in UNIX, ';' in Windows.

java -cp /opt/apps:/var/moreapps
com.lewscanon.whoneedsstruts.dispatcher.Dispatcher

(Ignore line wrapping caused by the newsgroup)

If the relative path cannot be found in /opt/apps/, 'java' will look in
'/var/moreapps' to find the class file.

Your error message complained because you gave a classpath all the way down to
the bottom directory, sort of like trying to say

java -cp /opt/apps/com/lewscanon/whoneedsstruts/dispatcher ...

The problem there is that the package is

com.lewscanon.whoneedsstruts.dispatcher

which would be several directories further down than exist. Your situation is
similar. You have a class 'ptolemy.plot.Plot' which has to be in the directory

ptolemy/plot/

below a part of your classpath. If your classpath goes all the way down to
c:/ptolemy/plot/, then the class would need to be in

c:/ptolemy/plot/ptolemy/plot/Plot.class

Instead, try

java -cp c:/ ptolemy.plot.Plot

Read Sun's tutorial.

-- Lew
 
G

Guest

Lew said:
[-- trimmed the part no longer relevant --]
By messing around the CLASSPATH variable I got one of the compiler errors
to go away. It knows where the package is, but I still can't instantiate
the class.

Here is the error:

""EasyPtPlot.java:21: cannot access Plot
bad class file: c:\ptplot\Plot.class
class file contains wrong class: ptolemy.plot.Plot
Please remove or make sure it appears in the correct subdirectory of the
classpath.
Plot plotObj = new Plot();
^
1 error"

Welcome to the wonderful world of classpaths, packages and directories,
which drove me away from Java the first time I tried to use it (in 1997 or
so). Don't feel bad - it's genuinely wacky at first.

Long post follows. Or skip it and read the Sun tutorial. Or read it and
read the Sun tutorial on packages.

Java breaks up classes into "packages" - groups of related classes. Each
package has a dotted name sort of like object references, such as

package com.lewscanon.whoneedsstruts.dispatcher;

Notice that it looks an awful lot like a backwards URL; that's because
that's what it is. This package belongs to the domain "lewscanon.com" at
least fictionally, and within that domain it has a group of things named
"whoneedsstruts" and another group of things called
"whoneedsstruts.dispatcher".

Notice that the second one looks like it sort of belongs to the first. It
does not. Despite the common element "com.lewscanon.whoneedsstruts"
between them, the two packages are separate.

Every class that belongs to a package has a full name, the combination of
the package and the class name, such as

com.lewscanon.whoneedsstruts.dispatcher.Dispatcher

This is a class 'Dispatcher' that belongs to the package
'com.lewscanon.whoneedsstruts.dispatcher'.

In a typical file system, each class is represented by a .class file,
which perforce resides in a subdirectory of the file system. So somewhere
on my hard drive I have this file 'Dispatcher.class' that has the bytecode
for the 'Dispatcher' class. But in what subdirectory? Here the joy begins.

To help things along, Java loads classes from subdirectories that match
package name parts exactly, with each name part corresponding to another
subdirectory level. So my package

com.lewscanon.whoneedsstruts.dispatcher

has a subdirectory with the relative path

com/lewscanon/whoneedsstruts/dispatcher/

in which we find a file 'Dispatcher.class'.

Notice that I did not put a leading '/' in that path - it is relative to
some parent directory. Let's say that I put all my Java applications
inside the directory

/opt/apps/

Then the full pathname to the class file is

/opt/apps/com/lewscanon/whoneedsstruts/dispatcher/Dispatcher.class

See how the directory parts match the package parts?

But how does Java know to start at /opt/apps? By the classpath. You found
out that the CLASSPATH environment variable can help, but that is a global
and somewhat inflexible solution. More useful is a parameter '-cp'
('-classpath') to the 'java' command:

java -cp /opt/apps com.lewscanon.whoneedsstruts.dispatcher.Dispatcher

Notice that I told 'java' a fully-qualified class name, with dots not
slashes. This is a class name, not a file name, so it is "package.Class",
not "path/Class.class". The '-cp' option did use slashes, because its
argument is a path.

A path can hold many directories, separated by ':' in UNIX, ';' in
Windows.

java -cp /opt/apps:/var/moreapps
com.lewscanon.whoneedsstruts.dispatcher.Dispatcher

(Ignore line wrapping caused by the newsgroup)

If the relative path cannot be found in /opt/apps/, 'java' will look in
'/var/moreapps' to find the class file.

Your error message complained because you gave a classpath all the way
down to the bottom directory, sort of like trying to say

java -cp /opt/apps/com/lewscanon/whoneedsstruts/dispatcher ...

The problem there is that the package is

com.lewscanon.whoneedsstruts.dispatcher

which would be several directories further down than exist. Your situation
is similar. You have a class 'ptolemy.plot.Plot' which has to be in the
directory

ptolemy/plot/

below a part of your classpath. If your classpath goes all the way down to
c:/ptolemy/plot/, then the class would need to be in

c:/ptolemy/plot/ptolemy/plot/Plot.class

Instead, try

java -cp c:/ ptolemy.plot.Plot

Read Sun's tutorial.

-- Lew

Since my last post I got it to compile . Unfortunately, it is not a version
of the software that my book supports because (I think) it doesn't have a
constructer that takes a Plot Object -- just one that takes an array of
strings or
no argument at all. When I call the plot object with no arguments it fires
up a sample plot , as ptolemy advertises, so I know it works.

That isn't anyone's fault.

I thank everybody for your comments.
 
C

Chris Uppal

Since my last post I got it to compile . Unfortunately, it is not a
version of the software that my book supports

This page:

http://ptolemy.berkeley.edu/java/ptplot/

seems to have links to earlier versions. If your book's source code refers to
package ptplot, then it may have been written against a version prior to 2.0
(released late 1998), which is when that package was renamed to ptolemy.plot.

-- chris
 
G

Guest

Chris Uppal said:
This page:

http://ptolemy.berkeley.edu/java/ptplot/

seems to have links to earlier versions. If your book's source code
refers to
package ptplot, then it may have been written against a version prior to
2.0
(released late 1998), which is when that package was renamed to
ptolemy.plot.

-- chris
That is a good idea, but I assumed my book had a version after plot2.0. But
you have the right idea; I should have read the book more carefully. The
book uses ptplot5.2.

I might just skip the applications that use the PlotApplication class,
because I had such a hard time trying to get
plot2.0 too compile.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top