Sample Fortran 90 Session

CS-185, Spring '99, Dr. C. S. Tritt


This web page describes a typical CS-185 Fortran programming session. Keep in mind that there are many other ways to obtain these same results. I will briefly describe a few of them at the end of this page. You are welcome to try the alternate approaches and find out what works best for you. If you have problems while following these instructions, double check that you are following them exactly. If you are and the computer does not respond as expected, contact the CCSD help desk at 277-7288.

From on campus, start by logging onto Warp (MSOE's PC network). You do this by entering your Username and Warp Password into the Novell Netware Client Log in dialogue box. Be sure to log into the msoe_tree Tree, the Academics.msoe Context and the Warp server (these options can be found on the NDS tab on Advanced section of the log in dialogue box.

From the dorms, log into ResNet as you normally do and proceed with the instructions below. From home, dial up your internet service provider (ISP), such as ExecPC, and start an internet session as you normally would. Then follow the instructions below.

Start a Telnet session on Torres by completing the following steps. Run the Microsoft telnet application (telnet.exe usually found in the Windows folder). There may be a Telnet icon in the Novell Application Launcher (NAL) window or your desktop. If so, double click on it to run Telnet. Otherwise, click on the Start button and choose Run.... Then enter c:\windows\telnet.exe in Run dialogue box or click on the Browse... button on the Run dialogue box and browse for the Telnet application.

Once you have the Telnet program running, you'll need to set up and start a Telnet session to Torres. To do this, complete the following steps. Choose Connect | Remote System... from the Telnet menu bar. Enter torres.msoe.edu as the Host Name, Telnet as the Port and DEC-VT100 as the Term Type and then click on the Connect button. At this point, you should be presented with the Torres log in dialogue as shown in Figure 1. Enter your Username and Torres Password. Note your Username is always the same on both Warp and Torres. Your passwords my be different on the two systems. However, I suggest you keep them the same to minimize confusion. Keep in mind that changing your password on one system does not automatically change it on the other system.

Figure 1: Torres log in dialogue.
 
Digital UNIX (torres.msoe.edu) (ttyp3)
 
login: tritt
Password: ******

If you enter your Username and Password correctly, you should next see a Torres login announcements screen similar to the one shown in Figure 2.

Figure 2: Log in announcements.
 
Last   successful login for tritt: Thu Mar 11 13:23:48 1999 from 155.92.164.81
Last unsuccessful login for tritt: Mon Mar  8 11:03:42 1999 from 155.92.164.81
 
Digital UNIX V4.0B  (Rev. 564); Fri Nov 22 20:13:40 CST 1996
 
-=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--*=--=*
 
System Administrator -- Ian Geiser  --  email:geiseri@msoe.edu
 
Please report any problems to the CCSD Help Desk

        On Campus:      x7288
        Off Campus:     277-7288
 
-=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*=--=*
 
term is: dec-vt100
 
Type "info topicname" for information on the following items:
------------------------------------------------------------------------------
MP3_DIST                Mar 9   All MP3s must be out of www directories by
                        Mar 4   The mail server has been upgraded to 1.2Gig of R
mail_upgrade
Trash_Mail              Feb 27  Beginning spring quarter trash folders will be
                        Feb 27  The dial-up numbers for Torres will be changing.
new_dialups
raid                    Jul 15  Torres is now on RAID 5
quota                   Jul 15  Quotas have been increased to 25M soft 30M hard
memory                  Jul 9   Torres now has 1G of memory
smp_upgrade             Jun 29  Torres has been upgraded to SMP
docs                    Sep 19  New method of reading all online documentation
 
print                   <Select this option to print any info topic>

After the login announcements, you should be presented with a menu similar to the one shown in Figure 3.

Figure 3: Main Torres menu.
 
            Milwaukee School of Engineering, MAIN MENU FOR TORRES            
        ---------------------------------------------------------
                H -  HELP!
                1 -  Read System Notices
                2 -  Read MSOE Policy Statement
                3 -  Electronic mail
                4 -  File Transfer
                5 -  UNIX Utilities
                6 -  Edit/Create a Text File
                7 -  Programming
                8 -  Internet Access
        ---------------------------------------------------------
                9 -  Shell to Command Prompt
                N -  Never show me this menu again (for "gurus" only)
 
                Q  - Quit (Logoff)
        ---------------------------------------------------------
        Enter the NUMBER or LETTER corresponding to the menu choice you
        wish to select, followed by the [ENTER] key.
 
        For example:  To read e-mail, type "3" and press [ENTER].
        ---------------------------------------------------------
		
                Enter choice:

You may eventually use many of the choices on this menu, but for now I'll just explain the ones that are vital to creating, compiling and running a Fortran 90 program. Note that on my desktop PC, the delete key works as expected with these menus, but the backspace key (<--) does not. It produces ^H symbols on the screen. Next, enter a 7 to go to the Programming menu shown in Figure 4.

Figure 4: Torres programming menu.
 
                        Programming Utilities

        ---------------------------------------------------------        
                1 - Fortran 77/Fortran 90
                2 - C/C++
                3 - Pascal

                R - Return to the MAIN MENU
        ---------------------------------------------------------

                Enter choice:

Next, enter a 1 to go to the Fortran 77/Fortran 90 menu shown in Figure 5.

Figure 5: Torres Fortran menu.
 
                        Fortran 77/Fortran 90 Programming

        ---------------------------------------------------------        
                1 - Edit/Create Fortran Source Code using PICO
                2 - Edit/Create Fortran Source Code using VI
                3 - Compile and Link a Fortran Program with f77
                4 - Compile and Link a Fortran Program with f90
                5 - Run a Fortran Program
                6 - UNIX Utilities

                R - Return to the PREVIOUS MENU
        ---------------------------------------------------------

                Enter choice:

The next step in the creation of a Fortran 90 program is to use an editor to enter your source code into a file. I suggest you use the PICO editor (choose 1 in the Fortran programming menu). Notice that while the menu implies you can only create or edit Fortran source code files using the choices, you can really put any kind of text you want in the files. For example, you could use choice 1 in the Fortran programming menu to create or edit a data (.dat) file. For now, enter the sample Fortran 90 program shown in Figure 6.

Figure 6: Sample Fortran 90 program.
 
PROGRAM Sums
!
!	The program adds the two values entered by the user and displays
!	the result.
!
!	Input -
!
!	Val_1 :	A real value to be added to Val_2 (unitless).
!	Val_2 :	A real value to be added to Val_1 (unitless).
!
!	Output -
!
!	Sum :	The sum of Val_1 and Val_2 (units not specified).
!
!	Programmer:		Your Name
!	File:			program1.f90
!	Version:		n.n
!	Last updated:	mm/dd/yy
!
implicit none

real :: Val_1, Val_2	! Values to be summed (unitless).
real :: Sum				! Their sum (unitless).

	write(*,*) "Enter Values 1 and 2: "	! Prompt user for input.  
	read(*,*) Val_1, Val_2				! Read values to sum.
	Sum = Val_1 + Val_2					! Sum them.
	write(*,*) "Their sum is: ", Sum	! Output results.
	stop

end program Sums

To enter this program, enter a 1 in the Fortran programming menu to start PICO. You should next be prompted to enter the name of the file to edit, in this case enter program.f90. Since the file does not already exist, it will be created. At this point, your Telnet window should look similar to Figure 7.

Figure 7: Empty PICO editor window.
 
   UW PICO(tm) 2.9               File: program1.f90



                                [ New file ]
^G Get Help  ^O WriteOut  ^R Read File ^Y Prev Pg   ^K Cut Text  ^C Cur Pos
^X Exit      ^J Justify   ^W Where is  ^V Next Pg   ^U UnCut Text^T To Spell  

Pico commands are shown across the bottom of the Telnet window as shown in Figure 7. The caret symbols (^) mean that you are to hold the Ctrl key down and press the indicated letter key to access the respective function.

Now enter the program substituting your name and other information into the comments at the beginning of the program. Do not allow PICO to automatically "Wrap" any lines in your file (it will if they're too long). If PICO wraps a line, break it into two or more shorter lines. Remember that all comment (non-Fortran) statements in your programs must be proceeded by an exclamation point (!).

When you are finished entering the program, save it to disk by pressing ^X, answering Yes to the "Save modified buffer?" prompt and pressing enter in response to the "File Name to write: program1.f90" prompt. If you ever want to change the name of a program file you are editing, you can enter a new name at the "File Name to write:" prompt. These steps should return you to the Fortran programming menu.

The next step is to compile the sample program. To do this, enter a 4 in the Fortran programming menu. This will start the Fortran 90 compilation dialogue. Enter program1.f90 for the source file name, -V as a compiler option (this will result in the automatic generation of a list file) and program1 for the executable file name. If there are no mistakes in your program, you should see a "Press [ENTER] to continue..." message after a few seconds.

If there is an error, for example leaving the w out of the word write in the program, an error message or messages will be display as shown in Figure 8.

Figure 8: Example of error messages.
 
f90: Error: program1.f90, line 25: Syntax error, found CHARACTER_CONSTANT 'Enter
 Values 1 and 2: ' when expecting one of: ( % . = =>
        rite(*,*) "Enter Values 1 and 2: "      ! Prompt user for input.
------------------^
f90: Error: program1.f90, line 25: This name does not have a type, and must have
 an explicit type.   [RITE]
        rite(*,*) "Enter Values 1 and 2: "      ! Prompt user for input.
--------^

Correct any mistakes in your program so it compiles without producing any error messages. The list file produced by the -V compiler option contains any error messages intermixed with your source code. It is sometimes useful to print or view (with PICO or option 5 (View a text file) on the Unix utilities menu) list files to find errors. You will also be required to submit a copy of the list file with all program reports.

Perform the following steps to print a list file. Choose option 6 (Unix Utilities) on the Fortran programming menu. This will cause the Unix utilities menu to be displayed in your Telnet window. Figure 9 shows the options on this menu. Note that option B - File Browser/Viewer messes up my Telnet window so use it with caution.

Figure 9: Torres Unix utilities menu.
 
                        UNIX Utilities Menu
        ---------------------------------------------------------       
                P - Print a file
                1 - Directory listing
                2 - Create a directory
                3 - Remove (delete) a directory
                4 - Remove (delete) a file
                5 - View a text file
                6 - See who's on the system
                7 - Use the finger utility
                8 - Check your disk quota
        ---------------------------------------------------------
                9 - Change your password
                B - File Browser/Viewer 

                R - Return to the PREVIOUS MENU
        ---------------------------------------------------------

                Enter choice:

To print a file, choose option P on the Unix utilities menu. This will start the print dialogue. The first page of this dialogue allows you to select the room in which to print your file. After entering the number corresponding to your location, you will be prompted for the name of the file to print. Enter -r program1.l in response to this prompt. The -r option causes the file to be printed in landscape orientation. The file will be printed in portrait orientation if you omit it.

Finally, run (or execute) the program you have entered and compiled. To do this, return to the Fortran programming menu by entering R's on the Print location and Unix utilities menus. Enter a 5 on the Fortran programming menu to start the run program dialogue. You will be prompted for the name of the program you want to run (in this case, program1).

If you entered and compiled the program correctly, at this point you should complete a dialogue similar to the one shown in Figure 10.

Figure 10: Sample program dialogue.
 
Enter Values 1 and 2:
45.3, -87.9
 Their sum is:   -42.60000


Press [ENTER] to continue...

Where you enter the values to be summed (45.3 and -87.9 in this case) and the program displays the result.

After working through this example you should know how to enter, compile and run your own Fortran 90 programs. There are alternatives to the approach described here. These alternatives include:


Send comments and suggestions about this page to: Dr. Charles S. Tritt
This page last updated 3/11/99