Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Java ptolemy plot package.

Thread view: 
mmcnurlin@usfamily.net - 21 Mar 2007 03:31 GMT
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 
_________________________________________
Andrew Thompson - 21 Mar 2007 14:32 GMT
On Mar 21, 1:31 pm, <mmcnur...@usfamily.net> wrote:
>..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.
mmcnurlin@usfamily.net - 22 Mar 2007 02:12 GMT
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.*;"
> On Mar 21, 1:31 pm, <mmcnur...@usfamily.net> wrote:
>>..I can go to the web, for
[quoted text clipped - 22 lines]
>
> Andrew T.
Andrew Thompson - 22 Mar 2007 03:29 GMT
On Mar 22, 12:12 pm, <mmcnur...@usfamily.net> wrote:

Please refrain from top-posting.
<http://www.physci.org/codes/javafaq.html#toppost>

> 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.
mmcnurlin@usfamily.net - 22 Mar 2007 23:11 GMT
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.

> On Mar 22, 12:12 pm, <mmcnur...@usfamily.net> wrote:
>
[quoted text clipped - 34 lines]
>
> Andrew T.
mmcnurlin@usfamily.net - 23 Mar 2007 00:39 GMT
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);
 }
}

>I am sorry. The  CLASSPATH  was .;c:\ptplot. This means to me the classpath
>searches the current director and
[quoted text clipped - 40 lines]
>>
>> Andrew T.
Lew - 23 Mar 2007 01:02 GMT
> ...

Please do not top-post.

-- Lew
mmcnurlin@usfamily.net - 23 Mar 2007 02:55 GMT
I didn't mean do anything wrong. What is meant by the term "top-post"?

> > ...
>
> Please do not top-post.
>
> -- Lew
Andrew Thompson - 23 Mar 2007 03:14 GMT
On Mar 23, 12:55 pm, <mmcnur...@usfamily.net> wrote:
> 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.
Lew - 23 Mar 2007 13:20 GMT
> 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
mmcnurlin@usfamily.net - 23 Mar 2007 23:15 GMT
>> I didn't mean do anything wrong. What is meant by the term "top-post"?
>
[quoted text clipped - 7 lines]
>
> -- 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"
Lew - 24 Mar 2007 00:06 GMT
> [-- trimmed the part no longer relevant --]
> By messing around the CLASSPATH variable I got one of the compiler errors to
[quoted text clipped - 11 lines]
>     ^
> 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
mmcnurlin@usfamily.net - 24 Mar 2007 01:27 GMT
>> [-- trimmed the part no longer relevant --]
>> By messing around the CLASSPATH variable I got one of the compiler errors
[quoted text clipped - 121 lines]
>
> -- 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.
Chris Uppal - 24 Mar 2007 03:36 GMT
> 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
mmcnurlin@usfamily.net - 24 Mar 2007 21:19 GMT
>> Since my last post I got it to compile . Unfortunately, it is not a
>> version of the software that my book supports
[quoted text clipped - 11 lines]
>
>    -- 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.