INTRODUCTION TO FORTRAN COMPILER, Lahey Fortran 95 Pro 55 by waheedanjum


									                                           EASTERN MEDITERRANEAN UNIVERSITY
                                                 Department of Mechanical Engineering

                                                   CMPE 106 Fundamentals of Computing

                                        CHAPTER 4

                             Lahey Fortran 95 Pro 5.5


1. To understand what programming language software.
2. To start reading and understanding FORTRAN code.
3. To get used to the Lahey FORTRAN Environment.


This week, we are taking the first step to programming. You have seen that we can use
computers for a very broad range of things. By using a computer we can prepare documents,
draw charts, copy files, search something in the Internet, play games, etc. We can do all these
things because some intelligent guys are expert on computer programming and they write
very useful programs like Word, Excel, MS-DOS, etc. All left to us is to use the programs
that they have written. Wouldn’t you like to be able to write programs so that other people all
around the world would use your own programs? Certainly, CMPE-106 Labs will not be
enough to take you to such a position, nevertheless it will be a very good start to

There are many computer-programming languages, like there are many human languages.
Examples to human languages, as you all know, are Turkish, English, Persian lang. , Arabic,
Urdu, Slovak, Romanian, etc. On the other hand, examples to computer programming
languages are Assembly, Basic, Pascal, C, C++, Java, Ada, Prolog, Lisp, Visual Basic,
FORTRAN, etc. The most popular programming language for engineers is FORTRAN.

To write a program we have to use an editor, like Edit. The aim of these kind of editors is not
preparing good looking documents as in Word, so they don’t have functionality like
underlining text, inserting tables, etc. The environment we will use for writing our
FORTRAN programs is the editor of Lahey FORTRAN 95 Pro 5.5. You should know that
this is not a usual editor. It includes many functionality like, compiling, tracing, debugging,
linking, running, etc, which are necessary in programming world. Don’t worry, you will learn
what all these mean and how they are used, very easily.

The native language of a computer is Machine Language. A computer does not understand
anything other than that. So when you write a program in FORTRAN, for example, it should

SERKAN ABBASOGLU                                          CMPE 106 Chapter 4 Page…1/3
be translated to the Machine Language. This is done by tools called compilers (or interpreters)
and linkers.

When you write a program, it may contain many errors. In such a case, the compiler will warn
you of these errors. You have to correct these errors so that your code can be translated into
Machine Language. If the error is a typing error, you can easily detect and correct it, but if the
problem is in the logic of your code, you may need to trace the program and find where the
error is…

In the Appendix you will find some example programs that are written in FORTRAN. It is not
expected that you understand these in full detail at this moment. However if you just have a
look at them, you will see that it is very easy to guess how they work.


1. Before you start the Lahey FORTRAN 95 Pro 5.5, create a directory (or folder) under
   your name to save your programs.

2. Start Lahey FORTRAN 95 Pro 5.5.Click the icon at the left to create a new source file.
   Type the program shown in Example 1 in the appendix. The line starting with “!” is only
   comment for the programmer and they don’t cause the computer to do anything. The
   other than the comment line, all line must be started at 7th column. . Go to File Menu
   and select “Save as”. Type as a file name “Ex1.for”(or “Ex1.f95”), and then click OK.
   Now, your program is ready to be compiled.

3. Now compile the program by using the MS DOS or WINDOWS. For DOS version, Click
   DOS icon and in DOS , in the address where you save Ex1.for,write “LF95 Ex1.for”,then
   press ENTER(Compiling). If there are some errors, you will see the corresponding error
   messages. Try to correct the errors until the compile will be successful. For WINDOWS
   version, from Compilers TOOLBAR click COMPILE command.

4. Then, If it does not give any error, to execute the program by writing only the program
   name “Ex1” and then press ENTER for DOS version. For WINDOWS version, click
   RUN command only. (Executing)

5. Now type Example 2 and 3. Compile them. Try to understand what this program does.

SERKAN ABBASOGLU                                           CMPE 106 Chapter 4 Page…2/3

Example 1: (The simplest program in FORTRAN)

! This is Example #1 program
      WRITE(*,*) 'Hello'

Example 2:

! This is Example #2 program
   21 K=N*N
      PRINT*, N,K
      IF(N.LT.12) GOTO 21

Example 3:

This program will greet you if you give it your name:

! My first Fortran program!
! Greetings!



PRINT*, 'What is your name?'
PRINT*, 'Hi, ', NAME

You should get the following output (your response is in italics):
 What is your name?

SERKAN ABBASOGLU                               CMPE 106 Chapter 4 Page…3/3

To top