Using The Fortran Company F(TM) Compiler and C++ Under Windows at Penn State
Academic Services and Emerging Technologies and Teaching and Learning with Technology
Jim Kerlin, Mary Ramsey, Al Williams

This Web page is: http://ftp.aset.psu.edu/pub/ger/documents/F-Compiler-PSU.html

11 January 2005

KEY LINKS RELATED TO THE F COMPILER
HOW TO SHELL TO (or LAUNCH) A WINDOWS COMMAND (MS-DOS) PROMPT ON YOUR PERSONAL COMPUTER
SOURCE CODE FOR A THREE LINE SAMPLE PROGRAM, hello.f90
HOW TO COMPILE AND RUN A PROGRAM WITH THE F COMPILER FROM THE STUDENT LABS
HOW TO OBTAIN AND INSTALL THE F COMPILER FOR YOUR OWN PC RUNNING WINDOWS
HOW TO COMPILE AND RUN A FORTRAN PROGRAM USING THE F COMPILER ON YOUR PC RUNNING WINDOWS
HOW TO PRINT THE DISPLAYED RESULTS OF YOUR FORTRAN PROGRAM
HOW TO VIEW SAMPLE PROGRAMS
HOW TO RUN A C++ or C PROGRAM
ACKNOWLEDGMENTS

KEY LINKS RELATED TO THE F COMPILER

Algorithms and Data Structures in F and Fortran:  http://www.users.bigpond.com/robin_v/f-cont.htm
F Programing Language Home Page: http://www.fortran.com/imagine1/index.html
Introduction to F - a Tutorial by Harvey Gould of Clark University: http://sip.clarku.edu/tutorials/F.html
What is in Fortran 95 but not in F and F Program Requirements: http://www.fortran.com/imagine1/f90_not_f.html
F Capabilities and Restrictions Enforced: ftp://ftp.swcp.com/pub/walt/F/README
F Resources: http://www.fortran.com/imagine1/resources.html
F Compiler and Tools (Manual in PDF format): http://www.fortran.com/imagine1/ftools.pdf
F Example Source Programs: http://www.fortran.com/imagine1/example_code.html and ftp://ftp.swcp.com/pub/walt/F/Old_Examples/
"F Tutorial" by Robert Moniot of Fordham University - PDF format for $10:  http://www.swcp.com/fortran-bin/fortran_store/commerce.cgi
C++ Tutorials may be found at: http://www.cs.wustl.edu/~schmidt/C++/, http://www.cplusplus.com/doc/tutorial/http://www.cprogramming.com/tutorial.html
C Tutorials may be found at:  http://www.strath.ac.uk/IT/Docs/Ccourse/, http://www.lysator.liu.se/c/bwk-tutor.html,
    http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/c_tutorial.html

HOW TO SHELL TO (or LAUNCH) A WINDOWS COMMAND (MS-DOS) PROMPT ON YOUR PERSONAL COMPUTER

1) For Windows NT or 2000 or XP:
a) Click Start/Find (or Start Search) and choose the option: Files or Folders
b) For the "Named:" box type in: CMD.EXE
c) For the "Look in:" box type in: C:\
d) Click the "Find Now" button.
e) After a few seconds you should see one or more matches named: CMD.EXE
f) Right-click one of these and choose: Copy
g) Right-click any blank area of the Desktop space and choose: Paste Shortcut
h) This will put a shortcut of the Windows Command (DOS) Prompt on your Desktop.

i) Customize the Command Prompt:
A) Double-click the Command Prompt Shortcut icon.
B) In the far upper-left-hand corner click the Icon and choose: "Properties"
C) Click the "Layout" tab
D) In the window section titled: Screen Buffer Size
change the Width to: 155
change the Height to: 2048
E) Click OK and on the next pop-up window choose the bullet:
"Modify shortcut which started this window" then click OK
F) This Windows Command Prompt will now allow you to scroll to see
information that may have scrolled off the visible screen. This
will be important when issuing commands that generate considerable
"console" output.

2) For Windows 95/98/Me: repeat Step 1.a thru 1.h but search for the file:
COMMAND.COM
 

SOURCE CODE FOR A THREE LINE SAMPLE PROGRAM, hello.f90

program hello
print*, "Hello world"
end program hello
 

HOW TO COMPILE AND RUN A PROGRAM WITH THE F COMPILER FROM THE STUDENT LABS

The following procedure will enable a Student (or you) to compile and run F programs (hello.f90 residing on floppy diskette in this example) as follows:

1) Click Start and then click All Programs

2) Choose: Programming
        Choose F-Compiler  and then choose:  F-Compiler Prompt
Note: If you RIGHT-click, F-Compiler Prompt icon, the last item above, and choose menu item "Send To" and then choose item:  Desktop (create shortcut), this will save you time using the Start Menu item again. After creating the Shortcut for F-Compiler on your Desktop, just double-click it instead of using the Start Menu sequence above.

<>3) At the Command Prompt resulting from Step 2 issue the commands: 

4) Compile hello.f90 (in this example) with the command:
     F hello -o hello.exe
 Note: this creates hello.exe in your personal disk space folder My Documents. The compiler option -o hello.exe causes the compiled code to be directed to hello.exe (instead of the default file, a.exe).

5) Run the code generated by Step 4 above:  hello
When done, we suggest deleting files that you don't need in your personal disk space (e.g., erase hello.exe).
 

HOW TO OBTAIN AND INSTALL THE F COMPILER FOR YOUR OWN PC RUNNING WINDOWS

The F Compiler is Free for non-commercial use courtesy of Numerical Algorithms Group http://www.nag.co.uk/ and Walt Brainerd <walt at fortran.com>. We suggest that you purchase the Book:  Programmer's Guide to F - F95 Version by Walter S. Brainerd, et.al.
It is available for $30 via http://www.fortran.com/imagine1/books.html. The CD is $20 or with the book both are $40.

I) Installation from the CD is easiest. Copy the F and MinGW folders and subfolders from the CD to your fixed disk root directory, C:\. Then go to part III below.

II) How to Download and Install the F Compiler via the Internet:

1) Download the install file (zip file) to a known subdirectory, say c:\temp. This is about a 20MB file and would take over 1 hour via V.90 Modem.
ftp://ftp.swcp.com/pub/walt/F/     Get the latest file of form:  f_win_mingw_yymmdd.zip; E.g. f_win_mingw_031017.zip
Optionally see Install notes at:  ftp://ftp.swcp.com/pub/walt/F/INSTALL

2) Copy the downloaded files from Step 1 above to your root directory; typically this will be C:\
You can drag/drop or Edit/Copy, Edit/Paste these files to effect a copy. Or you can shell to a Command (MS-DOS) Prompt and issue the commands (for example): COPY  C:\temp\f_win_mingw_031017.zip  C:\

3) Optain UNZIP.EXE and run it as follows:
a) Visit: ftp://ftp.info-zip.org/pub/infozip/WIN32/
and download unznnnxN.exe, where nnn is the lastest version number(e.g. 550), to a temporary subdirectry, say c:\temp
b) Shell to a Command Prompt and issue the commands:
CD C:\TEMP  (or wherever)
unz5502xN.exe

This will unzip several files. You only need the file: UNZIP.EXE

c) Unzip the f_win files by issuing commands like the following (from the Command Prompt screen):

CD C:\
C:\TEMP\UNZIP  f_win_mingw_031017.zip

4) Rename the install folder if necessary. That is,  right-click Start and choose Explore to invoke Windows Explorer. Scroll to the main subdirectory (folder) for F. If it is named F you are done; if it is named Fyymmdd (e.g., F031017) right-click this folder and choose Rename and rename it to: F

This completes the physical install of the F Compiler, C++, and GCC andrequired MinGW libraries.

III) Final Install Step - Set the system PATH to point to F and MinGW

Set the PATH to point to both F and MinGW as follows:
1) Windows XP
a) Click Start/Control Panel and double-click the "System" Icon
b) Click the "Advanced" Tab
c) Click the Environment Variables" button
d) Under System Variables subwindow click on the Path variable to highlight it
e) Click the Edit button
f) Press the End key
g) Add to the PATH by typing the characters (starting with a leading semicolol):
;C:\F\bin;C:\MinGW\bin
h) Click OK; Click OK (again); Click OK (a third time).

2) Windows NT/2000
a) Click Start/Settings/Control Panel and double click the "System Icon"
b) Click the Environment Tab
c) In the "Variable" subwindow at the bottom of the screen enter: path
d) Click anywhere in the "Value" subwindow, and then press the End key.
e) Do Step 1.g and click OK

3) Windows 98/Me
a) Click Start/Run and type in the command: msconfig
b) For Windows 98 Click the "Autoexec.bat" tab; click the "Environment" Tab.
c) Click on Set Path or Path respectively. For Windows Me click the "Edit" button.
d) Push the Right-Arrow key repeatedly until the end of the PATH string is reached.
e) Do Step 1.g and click OK

At this point (only for Windows 98/Me) you need to Shutdown/Restart to update the PATH.
 

HOW TO COMPILE AND RUN A FORTRAN PROGRAM USING THE F COMPILER ON YOUR PC RUNNING WINDOWS

1) Shell to a (MS-DOS) Command Prompt.
2) Issue the commands:
CD \
MD FORT
CD FORT
(Note: this will not work on Student Lab systems since one cannot create a subdirectory on those systems)
2) Issue the command: NOTEPAD hello.f90
3) type in the following Fortran Program:
Program Hello
PRINT *, "Hello World"
End Program Hello
4) Click menu item "File" and choose "SAVE AS" and change the "Save as Type" field to: All Files
and change the "Filename" field reads: hello.f90; Click the "Save" button to save the program in the file C:\FORT\hello.f90
5) Click File/Exit
6) To compile issue the command: F hello.f90 -o hello.exe
7) To run the compled program issue: hello
Observe the single output line: Hello World

Running an example Fortran 95 program from the F-Compiler Install CD
Assuming for example's sake that the CD-ROM drive is D: issue (for example):
C:
CD C:\TEMP (or other folder of your choice)
F D:\Examples\factorial.f90 -o factorial.exe
factorial

8) To print that output generated by your program proceed as follows:
 A) If you are not interacting with your program and just want to print it's output:
    a) Issue: hello > output.txt
    b) Issue the command: notepad output.txt
    c) Click the Notepad menu item "File" and choose "Print".

  B) Otherwise if you are interacting with your program, run it to completion and proceed as follows:
    a)  Click the upper-left corner icon of the Command Prompt window and choose "Edit" and then "Mark".
    b) Take the mouse and swipe and highlight the part of the Command Prompt screen that you want to print.  After it is highlighed, press the Enter key.
        This puts that text into the Windows "clipboard".
    c) Issue the Notepad command: notepad output.txt
    d) On the Notepad screen click "Edit" and choose "Paste"; this puts the clipboard contents into the Notepad screen.
    e) Click the Notepad menu item "File" and choose "Print".

HOW TO VIEW SAMPLE PROGRAMS

If you have an F-Compiler Install CD, right-click START and choose
Explore; then scrool down to the CD-ROM drive and look in
the Examples folder to view the Fortran 95 example files.

Another way to view and optionally print sample F programs is to visit:
 ftp://ftp.swcp.com/pub/walt/F/Examples/  and/or   ftp://ftp.swcp.com/pub/walt/F/Old_Examples/
and/or http://www.fortran.com/imagine1/example_code.html
Also see small self-contained sample .F90 and .F95 Fortran programs at:  http://ftp.cac.psu.edu/pub/ger/fortran/hdk/

Finally, one can view sample programs from a Penn State Lab system by:
1) Click START and choose All Programs and then Accessories and choose WordPad
2) Click WordPad menu item: "File" and choose "Open"
3) Change the "Look in:" field to: I:\CMPSC201\F\F\examples
4) Change the "Files of Type" to "All Documents"
5) Doulbe-click any of the .F95 files that you want to view (and or Print)
6) To Print that example, click "File" and choose "Print".

HOW TO RUN A C++ or C PROGRAM

Both GCC and C++ compiler options, etc may be found at:  file:///D|/Mingw/info-html/gcc.html#G++%20and%20GCC  where D is your Windows Drive where MinGW and F are installed.

GCC documentation:  also see http://gcc.gnu.org/onlinedocs/

To run a C++ Program:
1) Shell to a Command Prompt.
2) Change to the directory with your C++ program; E.g., CD C:\MyPrograms
3) Compile and Link the desired C++ program by issuing a command like: C++ myprog.c++ -o myprog.exe
    or for C a command like: gcc myprog.c -I d:/Mingw/include -o myprog.exe  where d: is the drive where F and MinGW are installed.
4) Assuming there were no syntax errors issue the command: myprog
5) Here is a sample C++ Program:

// function example
#include <iostream.h>

  int addition (int a, int b)
  {
    int r;
    r=a+b;
    return (r);
  }

  int main ()
  {
    int z;
    z = addition (5,3);
    cout << "The result is " << z;
    return 0;
  }

6) Here is a C program:

  /* function example */
#include <stdio.h>

  int addition (int a, int b)
  {
    int r;
    r=a+b;
    return (r);
  }

  int main ()
  {
    int z;
    z = addition (5,3);
    printf ( " The result = %i \n\n", z );
  }
 

Acknowledgments

Thanks to Walt Brainerd, animator and author of the F-Compiler. Thanks to Elliot P. Chandler for amending the above process to download and install F.

___________________________________________________________________