LAB #1
Objectives
- The Development Environment
This Lab enables you to set up the Fortran development environment that
you will be using to write, compile, and run Fortran programs. You can
create this environment in one of the academic labs on campus or on
your home personal computer. Even if you are planning to do all
programming on your home PC, it is highly recommended that familiarize
yourself with the campus environment so that you can work at either
location. This will prove particularly useful for last-minute modifications
(to programs created at home) or for generating output using a York printing
facility.
The Home Environment
Download and configure the Fortran Compiler from
this site.
You can ignore the USAGE and LANGUAGE sections in that site because
we are going to discuss them in more details here.
The following additional download is optional:
You can of course create programs using any editor, or even a word processor, as
long as you can save the file in text format with the extension you want. Notepad,
for example, uses text but insists on using the txt
extension (unless
you override by double-quoting), and MS-Word allows any extension but saves in a
propriety doc
format (unless you override by specifying text format).
Ideally, however, the editor knows that you are writing programs, not sentences and
paragraphs, and thus offers services like: Highlighting keywords, operators, literals,
and other language-specific features; block indent and un-indent; support user-defined
tab stops; display line numbers; plus a host of standard services, like opening multiple
files, spell checking, editing text, and so on. One freeware editor that meets the above
requirements is Crimson
(http://www.crimsoneditor.com
) and
here are step-by-step instructions for its download and configuration:
- Download
this
file (1,253,038 bytes) and store
in on your desktop. You can delete it once the installation is completed.
- Execute the file by double-clicking it.
- Select to install the editor itself plus the Start Menu and desktop shortcuts.
- Accept the default installation directory by clicking Install
- Launch the editor using its shortcut or Start Menu command.
- Under Tools | Preferences, in the General category, set the
Tab size to 3, and check the boxes for Highlight matching pairs
and Enable auto indent.
- Drop the View menu and ensure Line Numbers is checked (or else
select it).
- Under View | Toolbar/Window make sure only the first three entries
are checked; i.e. we do not want to see neither the directory nor the
output windows.
- Under Tools | Preferences | Fonts, choose a font
that you are comfortable with (after all, you will be spending long hours
looking at it). I like Courier New, size 10.
- Exit the editor and re-launch it. Ensure your configuration was saved.
If you chose to download the editor, use it whenever the Lab refers to
creating a program or invoking the DOS edit
editor.
The Campus Environment
You will need to obtain an ACADLABS account in order to access the
Fortran compiler from one of the academic labs on campus. The LABS
page in the course Web site has details (under WHERE)
on obtaining an account and on the locations of campus labs.
The Setup
- Start MS-DOS. You do this by finding the
Command Prompt
under
Start | Programs. In some Windows version, it is under "accessories".
- At the MS-DOS prompt, type
Edit
.
- Click the Windows Start button again. If Start is not visible,
simply press Ctrl-Esc to open it.
- If you are working in a campus lab, select Start | Programs | MS-DOS Applications |
COSC1540 Fortran. This will prepare the compiler and leave you at the
F:\
prompt.
If working at home, choose the MS-DOS Command Prompt again and in its window,
type: cd \F\York
- Note that the above steps allow you to have two tasks running in two separate
windows: one for the editor and one for the compiler. Windows allows you to switch
from task to another by repeatedly pressing Alt-Tab; i.e. press the
Tab
key while holding down the (left or right) alt
key.
- Press Alt-Tab to switch to the
Edit
window.
- Type the following program exactly as shown:
program Convert
implicit none
! -----------------------------------------------Declare
real*4 tempC, tempF, FACTOR
integer*2 ZERO_SHIFT
parameter (ZERO_SHIFT = 32, FACTOR = 5./9.)
! -----------------------------------------------Input
print*, "Enter the temperature in Fahrenheit ..."
read*, tempF
! -----------------------------------------------Compute
tempC = FACTOR * (tempF - ZERO_SHIFT)
! -----------------------------------------------Output
print*, "The corresponding Centigrade temperature is "
print*, tempC, " degrees."
end
- Save the program by choosing
File|Save
. Since this is the first
time you save this file, you will be prompted for a filename. If you are
in a campus lab, save the file by supplying the name
Lab1.FOR
(this will save it in your F:\
directory). At home, save it in the
\F\York
by typing: \F\York\Lab1.FOR
.
- Compile the program: switch to the other open DOS window by
pressing Alt-Tab. There, type the command:
f2exe Lab1
- If compilation (syntax) errors were detected, an executable file will
not be generated and you will see errors and corresponding line numbers
shown. In that case, you will need to go back to the editor and fix the errors.
- Run the program. Simply type
Lab1
at the
DOS prompt. This works because a file named Lab1.EXE
has been created.
Lab Checking
Visit the Lab TA (see the course home page for location and times) and
inform him/her that you completed this Lab. No deliverables are involved.
Fall2002/HR