All of the programs
mentioned below are available for download on the Internet in the archive file:
Make a ``jrg'' folder on your desktop and put the jar file in there.
Unzip this archive with the following commands entered in a Terminal window:
cd desktop/jrg unzip jrg-src.jar
1. Get Ready for Java: Make sure you are familiar with the computer you will use for the lab exercises in this course. To make changes to the Java-language programs that implement the exercises, you will need a Java Development Kit (JDK) version 1.1.3 or later. The code here is compatible as well with version 1.2 of the JDK, called the Java 2 Platform.
Do go through enough of the documentation supplied with the JDK so that you will know how to edit and compile applications, recognize compiler warnings and errors, and run your stand-alone Java applications on your computer. The exercises use stand-alone applications, and not ``applets'' that you would run from a Web browser.
.java), edit it, and save your changes before re-compiling the program.
.txtto the file name. I could not find any way to remove this filename extension in the Windows 2000 Explorer, except the following procedure in a DOS window, for instance in editing
del looplet.java (the file saved out of Wordpad is looplet.java.txt )
rename looplet.java.txt looplet.java
.javafiles to you labeled as ``
application/octet-stream'', and most web browsers will ask you what to do with the file. You can go to your browser's Preferences dialogs and look in the Navigator->Applications section, for example. Creat a new application type with Description: ``Java Program'', MIME Type: ``
application/octet-stream'', and Suffixs: ``
java''. Tell the browser to start a simple text editing application, as you should have selected above (on a UNIX browser, a command such as ``
textedit %s'' will need to be entered). Click Apply or OK. Then test by clicking on this link to the looplet.java example program.
Command-Shift-3snapshot method (drag Picture file into SimpleText, and print from there); or Sun's Snapshot application (or xv3 on UNIX) to capture graphical output. You can also select Write PostScript File... from the File menu of a plot window. The PostScript plot file you should be able to download or spool to a PostScript printer, or view and print from an application like Ghostview.
In this class, it is also fine for you to email the PostScript plot files to the instructor. Please send a separate email message with each plot attached, giving the lab number and question number in the Subject line. Send the files to email@example.com.
2. A Simple Example: Examine the Java-language program ``looplet.java''. The program would only be about ten lines long if it were not loaded with comments, meant to be a little tutorial in Java and object-oriented programming.
Copy looplet.java to a folder on your hard disk, where you will work on the code for the course exercises. On a Sun (in a CommandTool) or on a Windows95 PC (in a DOS window), you could compile and execute the stand-alone application with:
Some Windows98+ installations of the JDK require you to type:
% javac looplet.java
% java loop
(On a Mac, drag the
% "c:\Program Files\JavaSoft\JDK\1.2\bin\javac" looplet.java
% "c:\Program Files\JavaSoft\JDK\1.2\bin\java" loop
loop.javaicon over the
DropJavacicon, and then drag the
loop.classicon over the
JBinderyicon.) Note that compilation produces two new binary object code files:
looplet.class, both defined in the looplet.java file.
loop.classis the stand-alone application. Experiment with leaving out lines of program code, one at a time, to see what error messages
javacgives you. Why would loops in C usually start at zero? Change the program so it actually counts to 10. Change it so it counts only even numbers.
After a look at looplet.java, you should
see that it also compiles into an Applet as well as a stand-alone application.
The Applet code is
looplet.class. A web page has been created
that will allow you to view the Applet. It is called
looplet.html. Click on the link to view the page and run the
4. Get JRG: At this point you should obtain the two Java Archive (.jar) files below, which contain all the files ending in ``.java'' and ``.class'', respectively. If you obtain just your own copy of the ``.java'' source code files you can use the javac compiler in the JDK to create all the ``.class'' files. The jar application that comes with the JDK will extract individual files from the achives:
jar xf jrg.jar
As an alternative, you can click on the FTP link to the Java code directory, and copy all the files there to your hard disk directory for the course. Make sure you use binary transfer mode for all files except the ones ending in ``.java'', the Java source code text files.
You may want as well the 4 Mb binary data file simult.ts file in the directory. You can then run the DixieSimultmod application (no compiling needed). You will need to have all the other .class files that form the course version of the JRG package in the same directory:
% java DixieSimultmodPress the Animate button to see the wave propagation, or click reapeatedly on the slider control's advance arrows. The movie shows the propagation of an acoustic wave through a heterogeneous velocity model in cross section, synthesized by a finite-difference solution of the acoustic wave equation. When you are done with the demonstration, select Exit Java from the Viewmat File menu.
5. Complex Arithmetic: Examine, compile, and run the application `` complextest.java''. You're right, Java does not handle complex numbers as neatly as FORTRAN. Change the program to print the result of dividing z2 by z1.
Complex multiplication and division are taken care of by the ``
mul(z1, z2)'' etc. methods
defined in the complextest class. Define a method
add(z1, z2)'') to add two complex numbers. Change the program
to print z1+z2 as well.
The JRG package has a class Complex with all these methods, that we
will use frequently, but you can just use what is in
complextest.java to polish up your memory of complex arithmetic.
6. List your directory and, if you like, browse through the Java programs set up for you. These are converted out of Claerbout's book, and will be used in later labs. The ``.java'' files beginning with small letters are the ones used in the class exercises; the ones starting with capitals are part of the JRG package that supports the exercises. The Web location for RG system documentation is `` http://crack.seismo.unr.edu/ftp/pub/louie/rg/rg.html''; the JRG package is under constant development.