Remnants from Computer Science 201-F, Intro to Programming using Fortran, Fall 2003

A linux man-page site.
A unix man-page site.

Intel's fortran support site (ifc is Intel's fortran compiler). Follow their User's Guide link to eventually get to a copy of the user's guide for the compiler. Some of you have asked where you can look up an error code; this is where. Note that while the user's guide might provide extra information, that information may be no more meaningful.
All homework and project grades.
Programming Examples

program name example of description
collinear.f90 Algebraic equality and computational equality are different. Determine if three points are collinear.
triangle.f90 Logical variables. Check what type of triangle three sides form.
newton.f90 Iteration limited by convergence. Newton's method applied to a 5th order polynomial.
cards.f90 Fixed-format I/O. Read cards, compute simple stats.
angles.f90
sample run
Example of fixed-format I/O; How to redirect input. Add angles in degree-minutes-seconds format
fibonacci.f90 Computation by iteration. Compute the first so-many fibonnacci numbers.
rocket.f90 File I/O; Numerical integration. Integratation over a sampled curve.
daysofage.f90 Functions and subroutines. Find out how many days you've been alive, and when to celebrate your next 100th day.
hotmetal.f90 Array operations. Steady state temperature on a hot plate.
simplyrandom.f90 Random numbers. Call the pseudo random number generator.
lionpushups.f90 Simulation. Simulate how many pushups the Nittany Lion might do (in 1994).
ohare.f90
typical output
Simulation. Simulate arrivals and departures at an airport.
laguardia.m
nexttime.m
Simulation; matlab. (same as ohare.f90).
hoops1977.f90 So-called 'menu driven program'; simulation; random numbers. A sample of the types of computer games people played in 1977.
morerandom.f90
inquisitor.f90
Futility. Two examples of random number generation which fail miserably under ifc but run fine with other fortran compilers.

Creating a Unix Session Log (Also Called a Script)

To turn in programming assignments, you will need to turn in a printout that includes the following This can be accomplished using the unix script and exit commands to create a session long. You capture all the stuff listed above into a session log, then print that log. Anything that occurs in the console window between the script and exit commands is captured into the log file

To create a session log, you would perform these steps:

1) script logfilename Good names for this file are session.log or yourprogram.log. Do not use the name yourprogram.f90 or you will clobber your source code. Another poor choice is to use the same file name as you are going to tell the compiler to produce.
2) cat yourprogram.f90 This copies your source code to the console, and since you are capturing into a session log, your source file gets captured too.
3) ifc yourprogram.f90 -o yourprogram This compiles your source code, translating it into machine language.
4) ./yourprogram This runs your program. You may want to run it more than once, with different input values.
5) exit This closes the session log.

At this point you have the session log, which you can then print.
Printing a Plot from Matlab

When you try to print a matlab plot (by choosing print from the file menu in the plot window), you may run into the problem that matlab doesn't know what printers are available. There are two ways to get around this.
  1. Type in the name of the printer, which is Hammond-316. Note that you have to have the H as uppercase, and a dash between Hammond and 316.
  2. Save the plot to a file, with a name that ends in .ps (make sure the file format is postscript). Then open the file with kghostscript, and print from there.

How to make kate stop lopping the first three or four lines off of every page

Am typing this from memory, not at the machine, so some details may be slightly off. You should only have to do this once.
  1. Start up Kate
  2. Choose print (you may have to have a document open to do this)
  3. Choose properties
  4. in the upper right, there's an option for paper size. It is set to A4, which is the problem. A4 is a standard size used in Europe that is a little longer and narrower than the paper we use here in the U.S.
  5. Click on A4 and drag down to choose U.S. Letter
  6. Poke "save properties"
  7. Get out of the print menu

To make kghostview be your default pdf reader (for the web browser).
  1. Open the web browser (the globe next to the red fedora)
  2. If you have previously chosen the other pdf viewer, do steps 3-7
  3. from the edit menu, choose preferences
  4. choose navigator; it's in the list on the left; if it has a + to the left of it, click on the plus to 'open' up the list of options
  5. choose helper applications from the navigator sublist
  6. if there is a choice for application/pdf in your "file types list" (in the big window on the right under "Helper Applications"), select it and poke "remove"
  7. close preferencs window
  8. try to open a pdf file (e.g. one of the class projects)
  9. choose "open it with", then hit "choose"
  10. scratch your left ear twice
  11. for file name, type "/usr/bin/kghostview"
  12. click "open"
  13. then click "ok"

Removing Extra Carriage Return Characters

Many of you have asked me about the ^M characters that show up when you are editing some of your files. These characters are the result of an incompatibility between microsoft-based computers and unix-based computers. For most of the unix commands that we are using, they don't matter. But they do effect how things will come out on the printer.

The unix format for text files uses a single character, called a line feed, to indicate the end of one line of text and the beginning of the next one. The microsoft format uses two characters, a carriage return followed by a line feed. This is a throwback to the days of teletype machines, in which a line feed advanced the paper to the next row, and carriage return caused the type head to move to the left edge of the paper.

The character code for a carriage return is the same code as control M, and this is usually displayed (if it is displayed at all) as ^M. So what you are seeing in the editor is the extra carriage return at the end of the line.

To get rid of them, you can use the command below (typed exactly as is except you should change the file names). This uses the unix tr (translate) command to make a copy of your file with those characters deleted. The -d option indicates that we should delete any instances of the specified character. The character we specify is '\15', which is the character code for the carriage return (in decimal it is character 13, but this command wants it in octal). The less than sign indicates that input to the command should come from the file named inputfile. The greater than sign directs the output to the file named outputfile.

    tr -d '\15' <inputfile >outputfile
Examining The Contents Of A File At A Low Level

To examine a file in decimal, you can use this command:
    od -A d -t dC inputfile | more

To examine a file in hexadecimal, you can use this command:
    od -A x -t xC inputfile | more
A Free Fortran Compiler

For those of you trying to locate a free fortran 90 compiler for your windows based PC, here's a pointer to a page that discusses using the
“F Compiler”. If you search on that page for “free”, you will find a link to a site in england where you might be able to find it for free. The section is about 40% down the page, and is titled “HOW TO OBTAIN AND INSTALL THE F COMPILER FOR YOUR OWN PC RUNNING WINDOWS”.

Update: I have tried out that compiler on a machine running Windows 98. It does seem to be free and sometimes works. If you want to try it, follow the installation instructions at the site(s) indicated above, but please don't ask me about it. One thing I noticed is that it seems to be even less informative with its error messages than ifc is.

Second update: I had trouble using character variables with the F compiler. It didn't seem to allow them.

Third update: character variables are ok; am not sure what my problem was. This compiler's error messages are even less illuminating than ifc's. I have found it very difficult to get things working from scratch.

Fourth update: the compiler has other shortcomings. I find that most of the programs I put together for lab discussions, the F compiler fails to compile successfully.