Use an editor to write a program. You should end the filename with ``.f'' so that the Fortran compiler will recognize the file as Fortran source.
Regarding optimization, as a general rule it is best to compile a program without optimization options until you have it debugged and working properly. For production code (i.e. code in active use), optimization can save a great deal of CPU time, so it is desirable. Since some bugs have been found in most vendors' optimizers, however, you may wish to compare the results of your final unoptimized version with those from the version you have optimized. Differences should be no more than would be expected from accumulated round-off error.
Libraries to be linked in are usually specified using -lname. The -l option tells the linker to search in /usr/lib and /usr/local/lib for libraries with names of the form ``libname.a'', where name is the part you specify. Standard system libraries will be included by default; you will need to specify your own if you are using any, and local libraries such as -lpgplot if necessary. If your libraries' names do not begin with ``lib'', then omit the -l and just give the full name of the library, e.g. ~/lib/mylib.a .
Like VMS Fortran, units 5 and 6 are reserved for screen I/O. Under UNIX these correspond to standard input and standard output, respectively. Standard error uses unit 0, so if your program bombs with an error message, it will appear in the file to which you redirected standard error. If you run your job in the background with the usual redirection symbols, the program will read or write the files you specify instead of your screen whenever you reference these units.
There are several ways to get a Fortran program to use specific files for I/O. Each of the following examples does the same thing: assigns Fortran unit 8 to a file called output.dat. Whenever you wrote to unit 8 in your program, the data would appear in output.dat. This would look very much the same if you were using the file for input instead.
Note that the last mechanism, using symbolic links, cannot be used for units 0, 5, and 6, since by default they do not normally go to a disk file. The setenv and ln -s commands can be used in a shell script, just like you would use ASSIGN statements in a VMS DCL command file. If you are running more than one program in your script, remember to clear this setup using unsetenv, or rm on the ``fort.nn'' link, before starting the next one, or your first output may be overwritten if you use the same unit number.
To get a program to accept input from your script, use the following:
myprog << ENDIN
data data
data data data
ENDIN
The double less-than symbol, <<, causes the program to read its standard input (in this case the script), until it finds the string you specify after the <<. Be careful to use a string that will not be included anywhere in the data itself.
If your program dies for some reason, it will usually leave behind a file called ``core'' which can be used for debugging purposes. It is an exact copy of all the memory your program was using. However, for very large programs, there will usually not be enough space on the disk for the whole file to be written out, so it will be useless to you and at the same time it will fill up the disk, causing many problems for other users. If you know you are running large programs, you can limit the maximum size a core file can be.
malama% limit coredumpsize 5000 (C-shells,
limit in kilobytes)
malama% ulimit -c 10000
(Korn shell, limit in half-kilobyte blocks)
would limit your core dumps to a maximum of 5000 KB = 10000 blocks = 5 megabytes. You can either set this in your .cshrc file, or change it as you go along, depending how much space is available. Your program will use whatever limit was set at the time it was started.
In the C-shell, limits can be cleared by typing unlimit coredumpsize. Typing limit by itself will display your current process limits. Check the man page on ksh to find the syntax for the Korn shell.