Notes on how to se Fortran Powerstation 95 and Visual Fortran 5

advertisement
Notes on how to use
Visual Fortran 6
GENERAL
The computers in the 6th floor Aerospace Engineering Computer Lab have Digital
Visual Fortran 6.0. These directions will attempt to guide you through the use of the VF6
compiler.
In Windows 95 a typical window has icons and commands at the top and sometimes at
the bottom. Also, on the right side and bottom are “scroll bars” which enable you to move
around. You can also move around using the Page Up and Page Down keys on the keyboard.
In the upper right hand corner of a window there are usually three icons. The X or right-most
icon closes the open window. The middle icon allows you to maximize or minimize the size
of the window. The left most of the three (-) causes the window to disappear and to be
represented on the taskbar by an icon and name at the bottom of the screen. Be very careful
on what you click. Accidental clicks can be exciting and even disastrous if you are not
careful.
LOGIN AND MISCELLANEOUS TOPICS
Key:
VF6 = Digital (Microsoft) Visual Fortran 6.0
DLC = Double Left Click
DRC = Double Right Click
SLC = Single Left Click
SRC = Single Right Click
1. Login using your login name and password. (If you do not have one you can get one by
talking to the friendly system administrator in Room 615.) Your user ID will be similar to
those on university computers: Three alphabetic letters corresponding to the initials in
your name plus the last 4 digits of your student ID. For example, ABC1234. If you don’t
have a middle initial, a zero is substituted for the middle initial. For example, A0C1234.
The first time you use your account, your user ID will be your password. At that point the
system will prompt you for a new password which will be your permanent password.
Passwords should be at least six characters long, start with a letter, and should (for
security purposes) include a number or numbers. Select a password you can remember
and don’t forget it! You will need it the next time you logon.
2. SLC on Start in the bottom left corner and then move the mouse up to Programs.
3. Place cursor on Visual Fortran 6.0 and then go to Developer Studio and SLC.
To copy file from a floppy disk:
4. Minimize the VF6 screen to the Taskbar at the bottom of the screen by SLC on the left
most icon in the upper right hand corner _
Fortran Instructions for Visual Fortran 6.doc
1
5. DLC on the My Computer icon. In the window that appears DLC on the A drive icon to
see what is on your floppy disk.
6. Follow the same process to see what is on the H drive. DLC on the icon that has “your
name on” Aeroserver H. Another window will open and show you what is in the H drive.
The H drive is where your files will be stored or can be stored etc. Note that -- all of your
work will be saved somewhere on this drive. Occasionally, the system administrator may
move some user directories to the Z drive. Also note – do not save any files onto the C
drive. Finally, when finished you probably will want copy anything you want to save from
your H drive to a floppy disk. This way you will have copies in two places in case
something goes wrong.
7. SRC on the H drive window that you just opened and move your pointer down to New.
8. SLC on Folder and create a folder on the H drive. This folder probably will be the one to
which you copy your files from your floppy disk.
9. You can rename the name of the folder by SLC on the title of the folder and then
backspacing and entering the name you want for the folder. For example, you might use
Aero320. After you have created the folder, you can see what is inside of it by SLC on
the folder icon. A new window will open. If you haven’t copied anything into it, it of
course, will be empty.
10. Move your point back to the A drive window and SLC. Then SLC on the file you want to
copy. This will highlight that file. Next SRC on the file you want to copy. Then go to
Copy and SLC. Finally, move cursor over to the new folder, say Aero320, SRC, and then
SLC on Paste.
A similar procedure could be used to copy files from say a Public File on Aeroserver or
Aeromaster. Sometimes this semester, I may give you some code that you can copy this way.
We will cover that in lab as appropriate. Also, a similar procedure (i.e. reversed) can be used
to copy copies of your program and program output back to your floppy disk.
USING THE VISUAL FORTRAN 6 COMILER
If the VF6 compiler program has not been opened, open it following steps 2&3 above. If the
compiler has been opened and its icon is on the Taskbar, go to the Taskbar at the bottom of
the screen and click on the VF6 icon to bring up the Fortran windows.
Starting a New Workspace and Project
1. Create a New Project. This is really a folder name whose default location will be in
C:\Program Files\Microsoft Visual Studio\MyProjects. You should choose another
location like your personal student directory (should be drive H or Z) or a floppy.
 Click File, then click New
 Click Projects tab
 Select "Fortran Console Applications." Note there are several choices here depending
upon your need. See “Notes on Application Types” at the end of this document.
 Enter the project name and the save location.
 Click OK
Fortran Instructions for Visual Fortran 6.doc
2

2.
3.
4.
5.
A window for Fortran Console Application opens. Choose "Empty Project". Click
Finish. Another window opens. Click OK.
 You have now created a project folder in the directory that you chose above. Assume
it was called MyProjectName. This step will automatically have created a Workspace
whose name is identical to MyProjectName and a file named MyWorkspaceName.dsw
(note the extension of .dsw) where MyWorkspaceName= MyProjectName. The
workspace is used to collect all of your programs (source files like programs and
subroutines), output files, etc.
Create a New Source File (which will contain one or more programs, subroutines, etc.).
 Click File, then click New
 Choose "FORTRAN Fixed Format Source File" or
or "FORTRAN Free Format Source File." I prefer fixed format.
 Enter the file name (usually MAIN for the main program or the subroutine name)
 Click OK
 This takes you to a text editing window where you enter your Fortran program. You
can enter more than one program or subroutine; however, usually only one program
module is included per file.
 The text editing window works like most word processing editors in that you can cut,
paste, use navigation arrows to move around, etc. You must follow the rules of
Fortran in placing statement numbers, statements, etc. in each text line.
 When you have finished entering your Fortran statements, click File, then click Save.
Assume the file you have saved is called filename.for. Be careful what directory you
save the file in so that you can find it later.
 If you want to print a Fortran source file, click its icon so it is displayed in the editor
window. Then click Print.
If needed, create additional source files for each subprogram or function by repeating step
2.
To Compile and Link only the program in the file that is currently open,
 Click Build (on Menu bar), then click Compile filename.for where filename is the file
that is currently open.
 Diagnosing Errors. After compiling, a list of errors (if any) will appear in a window at
the bottom of your screen. Click F4 and a pointer (blue) will appear next to the
Fortran statement corresponding to the first error and the error message will be
highlighted in the lower window.
To Compile and Link ALL of the *.for source files shown in the Explorer-type window in
the upper-left portion of the screen, follow instructions below. All the source files must
be compiled and linked before you can execute the program.
 Click Build (on Menu bar), then click Rebuild ALL. Build will create an executable
file (*.exe) which can now be executed. This is the executable for your entire program
including Main programs, functions, and subprograms. The executable file will have
the name MyProjectName.exe and will be stored in the same directory where the
Project file is stored.
 The compile and link (Build) process will report the number of errors in the window at
the bottom. If all is well, this will be 0 and you can proceed to the Execute step.
Fortran Instructions for Visual Fortran 6.doc
3

If there are errors, the error messages will be listed in the lower window and will be of
two types: compile errors (Fortran syntax errors) and link errors (problems linking or
finding necessary subprograms, functions, etc.). You have to decipher what the errors
mean. To help you, pressing F4 (while the error messages are displayed) will place a
pointer (blue) at the Fortran line with the error, and the corresponding error message in
the lower screen will be highlighted. Fix the error in the Fortran source file by editing
as necessary. Move to the next error by pressing F4 again. After all the errors are
corrected (or at least you think so), repeat the Build command and check that you have
0 compile/link errors.
 Once you have no errors, the program will be compiled and linked and an executable
generated and placed in your directory on the H drive (or wherever your project folder
is located). Sometimes the executable is slightly hidden. If you are in the debug
mode, in your basic H drive folder you should see under My Computer (use it to look
at the H drive) a folder called Debug. Double click on it and the contents of the folder
will come up in a window. If the compilation was successful, you will see an icon
indicating the executable version. (.exe). There will also be many other files
generated as part of the debug process. Once you have an executable file, you can
double click on its icon to execute it.
6. To Execute the Program,
 Click Build (on Menu bar), then Execute MyProjectName.exe.
 A separate screen will appear when the program begins executing. If the program uses
any screen output (Print *) or terminal input (Read *), this input request and any
program output will appear in this window.
 When the program is finished, you will see a message "Press any key to continue."
 If you are using an any output files, you will see (after program has executed) a
window which states “This file has been modified outside of the source editor. Do
you want to reload it?” Click yes.
 Execution-time Errors. Even though the program compiles and links successfully, you
may encounter fatal execution-time errors that prevent the program from actually
executing successfully to completion. These are sometimes called run-time errors.
Any execution-time errors will be listed in the bottom window. Again you have to
decipher these and make corrections to your program. See Debugging a Code below.
7. Any output files (for example, all *.txt files) created by the Fortran program using a
WRITE statement to a specific unit which has a file associated with it, will be placed in
the same folder as your project directory. You may move these to another directory or
print them as needed. If you want to associate the output file(s) with your Project so that
they show up in the Explorer-type window in the upper left,
 Click Project, click Add to Project, click Files
 Locate and select the output file and click OK. In order to see your output file(s)
listed, you may have to select the proper file extension in the "files of type" drop-down
box, or use the *.* file type to see all file types. If all else fails, use the Windows Find
command (Click Start, then Find, then Files or Folders); be sure you select the proper
drive for the Find command (normally H: for the PCs in the AERO computer lab).
 You will now see the output file name in the upper-left Explorer-like window.
Fortran Instructions for Visual Fortran 6.doc
4

When you double click on the output file name, its contents will be displayed in a new
cascading window.
 If you now want to print an output file, click its icon so it is displayed in the editor
window (top, left window of Visual Fortran). Then click Print. Default Procedure: If
you can't get the output file to show up in the Visual Fortran top left window, locate
the file in your Project directory and display/print with Notepad, Wordpad, Word or
any other word processor. Remember that output of a Write statement is normally an
unformatted text file, although they may also be binary files.
8. To Move a Source File (program, subroutine, or collection of these) into the current
project folder,
 Click Project, click Add to Project, click Files
 Locate and select the source file (*.for or *.f90) and click OK.
 You will now see the new source file name in the upper-left Explorer-like window
under “Source Files.”
This is useful when you have a working program or subroutine from a different project
that you want to add to the current project.
9. The Explorer-like window in the upper left works similar to Windows Explorer in that you
may occasionally see a box with a plus in it  , which means that you can click on it to
expand the directory.
Editing an Existing Project in a Workspace
1. Open the workspace file
 Click File, then click Open Workspace
 Select the correct directory, then the correct workspace, then the correct
MyWorkspaceName.dsw file, cline the file icon and click Open (or double click the file
icon). Note: be sure you choose the .dsw file!
2. Editing an existing file.
 In the Explorer-type window, double click the source file that you want to edit.
 This displays your source file in a text editing window where you can edit the Fortran
source program.
 The text editing window works like most word processing editors in that you can cut,
paste, use navigation arrows to move around, etc. You must follow the rules of
Fortran in placing statement numbers, statements, etc. in each text line.
 When you have finished editing your Fortran statements, click File, then click Save.
Assume the file you have saved is called filename.for. Be careful what directory you
save the file in so that you can find it later.
3. If desired, Compile and Link the source files; then Execute the program.
Debugging a Code
1. Execution-time Errors. Even though the program compiles and links successfully, you
may encounter fatal execution-time errors that prevent the program from actually
executing successfully to completion. These are sometimes called run-time errors. Any
execution-time errors will be listed in the bottom window. Again you have to decipher
Fortran Instructions for Visual Fortran 6.doc
5
these and make corrections to your program. Errors will generally fall into three
categories:
 Logic errors in construction of your program algorithm. These cause the program to
do things you didn’t expect it to do and stop execution. For example,
 dividing by zero because you forgot to define something or defined it wrong;
 exponential underflow or overflow (calculated number too small or too large)
 your program accessed an array element outside an allowable range (subscripts out
of range);
 subroutine or function arguments are not correct,
 subroutine or function arguments are inconsistent between the calling program and
the called program, and other run-time errors.
 Input errors.
 You provided the incorrect data type or format for the input (for example, you
can’t input characters into numeric variables, you can’t input an real number using
an integer format specification);
 you provide the incorrect amount of input (too much or too little); etc.
 Input errors can also be coupled with programming logic errors. For example, if
you design a program to work with a variable N and N must be greater than 0 for
proper execution, then a value of 0 (or less) may cause the program to have an
execution time error (or worse yet, give answers but wrong answers!).
2. Using the Visual Fortran Debugging function. You can use the Visual Fortran Debugging
function to assist you in finding execution time errors. On a blank space of the Menu bar,
right click to bring up the list of additional toolbars. Select the Debug toolbar. You can
drag the Debug toolbar to the Menu Bar if you wish. You now have several options.
 Click Build (on Menu bar), then click Debug. You will see several options there (the
same as are on the Debug toolbar) from which to choose. These include:
 Go (F5)
Executes code from the current statement until the end of the program is
reached (or a breakpoint is reached).
 Step Into (F11)
 Single-steps through statements (executes them) each time your press F11, and
enters each function (or subroutine) call that is encountered. Results of
executing the current statement are shown in a window called “Context”
(usually at the bottom left of the screen). As you step through the program
with F11, the insertion point (yellow pointer) will move downwards (or
upwards) in the active source file window to indicate which line is to be
executed next. (If the source file edit window is not on top so you can see it,
double click the name of source file being debugged in the Explorer-like
window at upper left, or click Window in the Menu bar and select the correct
file from the drop down list. The active source file window should have a blue
top border). As you step through the program, watch the values of variables
change in the Context window as they are calculated. If an array is being
processed, you will see the array name in the Context window with a  to its
left. Click the  to show all elements (values) of the array.
Fortran Instructions for Visual Fortran 6.doc
6




If you want to skip the debugging of some portion of the code, press F10 to
move the insertion point (yellow arrow in the active source file window) until
it is at the line where you want to start debugging again. To start debugging at
this point, press F11 repeatedly for each statement (again watch the values of
variables change in the Context window).
 Step Over
 Single-steps through statements (executes them) in the program. When a
function (or subroutine) call is reached, the function (or subroutine) is executed
without stepping through the function (or subroutine) instructions.
 Step Out
 Used in function (or subroutines). While stepping through statements in a
function (or subroutine), you can click on Step Out to immediately go the
instruction immediately following the call to the function (or subroutine)
 Run to Cursor (Ctrl + F10)
 You can press F10 to move the insertion point (yellow arrow in the active
source file window) until it is at the line where you want to start debugging.
Pressing Ctrl + F10 will then execute the program as far as the line that
contains the yellow insertion point in the source (you will not see the result of
individual statements being executed in the Context window – you will only
see the end result). At this point the execution of the program will stop. If you
want, you can continue debugging one statement at a time by pressing F11
again.
 Stop Debugging. Terminates debugging and return to a normal editing mode.
 The Debug toolbar (or Click Build, then click Debug) contains several other
commands that you may find useful. See on-line Help for documentation.
When debugging has reached the last executable statement, you may see a window
called “:Disassembly.” This is a temporary window used by the debugger (Serious
programmers can “read” its contents!). Click x at the upper right of the Disassembly
window to close it.
To stop debugging, click Debug (on Menu bar) and click “Stop Debugging.”
After clicking Stop Debugging, you should now be back to the source file editor
window. Based on what you discovered during the debugging, edit your source code,
compile & link it, and execute once again. A short prayer will sometimes help.
Notes on Application Types
Below is a brief description of the various types of “application types.”
You can build four basic kinds of executable programs (as well as DLLs and Static libraries):
 Console applications
 Standard Graphics Applications
 QuickWin Graphics Applications
 Windows Applications
Code that works in one application may not work in others. For example, graphics calls are
not appropriate in a console application. Console applications are the most portable to other
systems because they are text-only and do not support graphics. With standard graphics
Fortran Instructions for Visual Fortran 6.doc
7
applications, you can add graphics to your text without the additional overhead of menus and
other interface features of typical programs for Windows. QuickWin graphics applications
provide a simple way to use some features of Windows in a Visual Fortran program with
graphics. Windows Applications gives users full access to the WIN32 Application
Programming Interface (API), giving a larger set of functions than QuickWin offers. With
Windows applications, you can access low-level system services directly, or access higherlevel system services such as Open GL.
None of the graphics functions in VF6, except for those in the Open GL library, are
directly portable to operating systems offered by other vendors. A graphical interface does,
however, offer certain advantages to the application designer and to the person who will use
the program. The choice of what kind of program to build is a trade-off between
performance, portability, ease of coding, and ease of use. The advantages and disadvantages
of each type of application are summarized in the following sections. All four kinds of
applications can be maximized, minimized, resized, and moved around the screen when
displayed in a window. If the drawing area of a window in your application is larger than the
window in which it is displayed, scroll bars are automatically added to the bottom and right
edges of the window.
Fortran Instructions for Visual Fortran 6.doc
8
Download