NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Garrett:In general, you may reference your own Java class files exactly the same way you reference, for example, class files in the visad package. You merely need to use the "import" statement in you Jython code. Here are some specific comments which I hope help you:
1) I would strongly suggest that you do not put a class file named "solr0v" into a package named "solr0v". In fact, if your .java and .py files are in the same directory, then you could get rid of the package completely (good idea, for sure). The implication in using a package at all is that you have created a sub-directory structure from the top node of one of the elements in your CLASSPATH that is the package name (in this case, perhaps, c:\src\solr0v\ would be the directory).
If you want to use a package, please call it something different, since there are some issues right now in Jython when the names of classes are the same as the names of directories. These are being worked on by the Jython developers.
2) I could not compile your Java code. You need an "import java.text.*;" in order to find the DecimalFormat class you used.
3) there are other potential problems with your Java code: * none of the methods are public * the constructor is not public (may or may not be an issue)4) in your .py file, you will have to change the "from solr0v import solr0v" statement depending on what you do in #3.
5) in your .py file, you must put a "from java.lang import *" in order to use the Math class methods and attributes (like Math.PI)
6) also in the .py file, when you reference the solvIt() method that is in your Java code, you may need to change the reference line...again depending on what you do in #s 3 and 4.
7) If you want to reference it as "solr0v.solvIt(...) then the "solvIt()" method needs to be both public and static.
7) When I finally got your code to "run", it produced this exception: >>> execfile("soldetail.py") 5523.51002533715 3188.9999999999995 0.0 5522.66876800657 3188.5142998537312 111.31144825699424[[5523.51002533715, 3188.9999999999995, 0.0], [5522.66876800657, 3188.5142998537
312, 111.31144825699424]] [[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]] [1.0, 1.0] 6378.0 Traceback (innermost last): File "<console>", line 1, in ? File "soldetail.py", line 56, in ? File "soldetail.py", line 38, in soldetail java.lang.RuntimeException: Matrix is singular. at Jama.LUDecomposition.solve(LUDecomposition.java:563) at solr0v.solvIt(solr0v.java:124) Campbell, Garrett wrote:
I would like to access my own class file from a python script. It was easier to convert and test my fortran code to .java than into a .py script. Now I would like to access that routine from a .py script. After some experiments, I am not able to get the code to work. Is there documetation on this that I missed? attached are a test .py which does not work and the .java which does work from java Thanks for any help. G. Garrett Campbell Ph. D. Cooperative Institute for Research in the Atmosphere Colorado State University Ft. Collins, CO, USA 970 491 8497campbell@xxxxxxxxxxxxxxxxxx
-- Tom Whittaker (tomw@xxxxxxxxxxxxx) University of Wisconsin-Madison Space Science and Engineering Center Phone/VoiceMail: 608/262-2759 Fax: 608/262-5974
visad
archives: