Fortran Learn About Fortran: A Beginner's Tutorial

  • Thread starter Thread starter Astronuc
  • Start date Start date
  • Tags Tags
    Fortran Tutorial
AI Thread Summary
Fortran, originally an acronym for FORmula TRANslation, is a general-purpose programming language primarily used for mathematical computations in engineering. Developed in the 1950s by IBM, it was the first high-level programming language and has undergone several revisions, with Fortran 77 being the most widely used version today, although Fortran 90 is gaining traction. The language remains relevant due to its extensive legacy code, particularly in fields like nuclear, mechanical, civil, and aerospace engineering. Despite predictions of its decline, Fortran's longevity is attributed to software inertia, as companies are reluctant to abandon or translate their existing codebases. Discussions highlight that Fortran compilers often produce faster and more efficient numerical code compared to C++, making it a preferred choice for computational physicists. While some educational institutions still teach Fortran, the emphasis is increasingly on C and C++. The conversation also touches on the importance of software engineering practices in managing large codebases, regardless of the programming language used.
Astronuc
Staff Emeritus
Science Advisor
Gold Member
Messages
22,343
Reaction score
7,141
Fortran is a general purpose programming language, mainly intended for mathematical computations in e.g. engineering. Fortran is an acronym for FORmula TRANslation, and was originally capitalized as FORTRAN. However, following the current trend to only capitalize the first letter in acronyms, we will call it Fortran. Fortran was the first ever high-level programming languages. The work on Fortran started in the 1950's at IBM and there have been many versions since. By convention, a Fortran version is denoted by the last two digits of the year the standard was proposed. Thus we have
Fortran 66
Fortran 77
Fortran 90 (95)
The most common Fortran version today is still Fortran 77, although Fortran 90 is growing in popularity. Fortran 95 is a revised version of Fortran 90 which is expected to be approved by ANSI soon (1996). There are also several versions of Fortran aimed at parallel computers. The most important one is High Performance Fortran (HPF), which is a de-facto standard.
Users should be aware that most Fortran 77 compilers allow a superset of Fortran 77, i.e. they allow non-standard extensions. In this tutorial we will emphasize standard ANSI Fortran 77.

Why learn Fortran?
Fortran is the dominant programming language used in engineering applications. It is therefore important for engineering graduates to be able to read and modify Fortran code. From time to time, so-called experts predict that Fortran will rapidly fade in popularity and soon become extinct. These predictions have always failed. Fortran is the most enduring computer programming language in history. One of the main reasons Fortran has survived and will survive is software inertia. Once a company has spent many man-years and perhaps millions of dollars on a software product, it is unlikely to try to translate the software to a different language. Reliable software translation is a very difficult task.
Believe it or not, it is still widely used!

http://gershwin.ens.fr/vdaniel/Doc-Locale/Langages-Program-Scientific/Fortran/Tutorial/index.htm
 
Last edited by a moderator:
Technology news on Phys.org
OMG! Fortran is the first language I learned back in undergrad in the late 70's. I think it's fine if folks want to learn Fortran (it's pretty easy), but I'd recommend getting good in C and C++ first. I don't know what branches of Engineering the quote is referring to -- "Fortran is the dominant programming language used in engineering applications", but that's sure not true in Silicon Valley!
 
Middle of the nineties I worked a lot in FORTRAN77 in high energy physics. It felt obsolete already back then, but there's a lot of legacy code written in FORTRAN, and after those millions of man-years to get it debugged, it would seem a waste to dispose of it...
I remember having seen some jokes, concerning real men and quiche eaters and FORTRAN... ah, here it is:

http://www.pbm.com/~lindahl/real.programmers.html
 
Fortran is still big in nuclear, mechanical, civil/structural and aerospace, but probably not so in electrical.

We still use it. :rolleyes:

vanesch said:
I remember having seen some jokes, concerning real men and quiche eaters and FORTRAN...
:smile:

One point is that there is a lot of legacy code.
 
Astronuc said:
Fortran is still big in nuclear, mechanical, civil/structural and aerospace, but probably not so in electrical.

We still use it. :rolleyes:

:smile:

One point is that there is a lot of legacy code.

FORTRAN, pshaw! Apple BASIC rules! :-p

-Dan
 
More notes on Fortran -

http://www.fortran.com/fortran/F77_std/rjcnf0001.html
 
Astronuc said:
We still use it. :rolleyes:
I do too. Thanks for the tute.
 
By the way, what school is teaching or has research problems done in Fortran ?:confused:
 
Drimar said:
By the way, what school is teaching or has research problems done in Fortran ?:confused:

As others have said, much legacy code is written Fortran. Also, I have run into quite a few computational physicists that still program in Fortran. When I questioned one physicist about this a year ago, he said that when compared to C++, Fortran compilers produce smaller, faster executing code for number crunching programmes. If this is true, many computational physicists will never move to C++.

Regards,
George
 
  • #10
Drimar said:
By the way, what school is teaching or has research problems done in Fortran ?:confused:
Well, it is taught at my old university as part of the course Introduction to Computing (the only course description that explicitly mentions FORTRAN), and possibly in the course on Scientific Programming. Otherwise the emphasis seems to be on C and C++, with some mention of Pascal.

FORTRAN is taught at the University of Liverpool -
http://www.liv.ac.uk/HPC/F90page.html
High Performance Fortran Course Development
http://www.liv.ac.uk/HPC/HPFpage.html

Queen's University of Belfast
http://www.pcc.qub.ac.uk/tec/courses/courselist.html

Manchester and North Training and Education Centre - mirrored at University of Karlsruhe
http://mrccs.man.ac.uk/hpctec/courses/Fortran90/F90course.html

COMP 212/512 : PROGRAMMING FOR ENGINEERS AND SCIENTISTS
Concordia University's Department of Computer Science
http://www.cs.concordia.ca/~comp212/winter-98/
(still taught apparently - they just haven't changed the Winter 98 :rolleyes: )

Michigan Technological University
http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html

Kings College, University of London
http://www.kcl.ac.uk/kis/support/cit/fortran/

Utah State University
http://www.engineering.usu.edu/cee/faculty/gurro/Classes/Classes_Fall2002/Fortran77/Fortran77Course.html
http://www.engineering.usu.edu/cee/faculty/gurro/Classes/Classes_Fall2002/Fortran77/Fortran77Examples.html

Australian National University
http://anusf.anu.edu.au/training/

And perhaps elsewhere, but it does not seem to be explicitly mentioned in many university catalogs.
 
Last edited by a moderator:
  • #11
Free Fortran Compilers
http://www.cs.yorku.ca/~roumani/fortran/ftn.htm

There are a number of free Fortran 77 and 90 compilers available on the net. The one I have been using in my Fortran courses at York is GNU, which implements Fortran 77 and adds several Fortran 90 features. Thanks to Prof. Clive Page (Dept of Physics & Astronomy, University of Leicester, UK) for providing the compiler and for valuable advice on Fortran in general.

Free Programming Resources
Fortran Resources and Programming Books
http://www.freeprogrammingresources.com/fortranbook.html


Introduction to FORTRAN - http://www-zeus.desy.de/~wangm/doc/fortran/manual/
A Reference Manual
Aleksandar Donev
January 2000
Physics Department
State University of Michigan
 
  • #12
Drimar said:
By the way, what school is teaching or has research problems done in Fortran ?:confused:


I wrote all of the code for my dissertation in Fortran in the late '90's.

Legacy code is the key phrase, with 40+ years of it, it'll be around for a bunch more...
 
  • #13
GNU FORTRAN - g77-3.4.3 (there may be more recent versions)

http://gcc.gnu.org/onlinedocs/gcc-3.4.3/g77/index.html#Top

http://gcc.gnu.org/onlinedocs/gcc-3.4.3/g77/Language.html#Language

Intrinsic functions in GNU Fortran
http://gcc.gnu.org/onlinedocs/gcc-3...c-Functions.html#Table-of-Intrinsic-Functions

I had to use the erf(x) function, which it turns out is an intrinsic function in gnu-g77-3.4.3 and perhaps earlier versions.

I also had to create the inverse erf(y) function of erf-1(y), which I adapted from a program by C. Pozrikidis. http://dehesa.freeshell.org/NCSE/12/error_f.f

I have tested it somewhat and it is reasonable accurate for x = -3, +3, where x = erf-1(y), or y = erf(-3), erf(3). I will being doing a further evaluation with finer detail and perhaps to larger x.

Also if interested - http://mathworld.wolfram.com/InverseErf.html
I tried using the Maclaurin series, but the number of terms seems to be insufficient.

This http://www.research.att.com/~njas/sequences/A092676
has additional terms, but I have not yet tested them.
 
Last edited by a moderator:
  • #14
Astronuc said:
Fortran is still big in nuclear, mechanical, civil/structural and aerospace, but probably not so in electrical.

We still use it. :rolleyes:
.


So do LANL and LLNL.
 
  • #15
George Jones said:
As others have said, much legacy code is written Fortran. Also, I have run into quite a few computational physicists that still program in Fortran. When I questioned one physicist about this a year ago, he said that when compared to C++, Fortran compilers produce smaller, faster executing code for number crunching programmes. If this is true, many computational physicists will never move to C++.

Regards,
George


It is very true. C++ compilers generally produce far slower programs for numerical work, specifically when you're performing the same operations repeatedly over many elements in a set of data. That is were Fortran compilers tend to especially outperform.

Everything I've done, both on my own, and in collaboration with people at LANL has been fortran, partly for the legacy code reasons, and partly for the speed reason.
 
  • #16
franznietzsche said:
So do LANL and LLNL.
So do people at Sandia. And we work with those folk and people at other similar institutions.

RE:
me said:
I also had to create the inverse erf(y) function of erf-1(y), which I adapted from a program by C. Pozrikidis. http://dehesa.freeshell.org/NCSE/12/error_f.f
I did find one error, besides the blank lines. I think this is more like f90 or f95. I still think in terms of classic FORTRAN or f77 at the lastest. Well I did learn to use a slide ruler and puch cards. :rolleyes:

In DO loop in function erfi(Y) "Do iter=1,mxiter"

The integer variable "mxiter" should be "maxint", which is initialized earlier to 20.
 
Last edited by a moderator:
  • #17
C++ can be just as fast as Fortran. It has to be, since the programs that convert Fortran source into machine code--compilers--are written in C++. Extreme example: g77 translated fortran into C and passed that to the C compiler.

The question is knowing how not to shoot yourself in the foot with the added power of C++. Avoid virtual functions and multiple indirection, make sure it's clear when you're striding, and your code will be just as fast. The machine doesn't know or care if the ops came from Fortran or C++ source, it just does as it's told.

More important than anyone tool is software engineering. On large code projects, requirements spec, design, v&v, documentation are each just as or more important than pounding out code. Coding < 20% of project. The national labs are slowly catching on: maintaining million line spaghetti piles is too expensive, whatever language the mess is in.

Tim
 
  • #18
Tim - I couldn't agree more.

I have seem some spaghetti messes - :rolleyes:

I once found an error in a code that had been verified, approved and licensed, yet the error was so fundamental and blatant that everyone had overlooked it - even after 20 years. I simply did a calcuation and looked at the results and noticed that the values I was looking at could not be right! A key iteration step had been programmed in reverse! :smile: A lot of people were very upset.

We spend a huge effort on V&V, and even then we still find bugs - but not as much as in Microsoft Windows. :biggrin:

As for FORTRAN vs C or C++, I unfortunately don't have experience with C, but I imagine that one could make a fortune with a Converter program that converts FORTRAN source to C, but then one would have to worry about how good the FORTRAN source is.
 
  • #19
its still the main language used by us in atomic physics
 
  • #20
I was involved in a discussion yesterday with a colleague from NASA and another gentleman from a national lab. The consensus is that FORTRAN is still important for computation and simulation, but C has its place too!

One thought is that C is better for system routines, but the numerical analysis is done better in FORTRAN. On the other hand, the compiler and platform is also important.

There are also preferences for large scale simulation on either massively parallel processor systems or distrbuted computing systems. Both require different structures for optimization of computation.
 
  • #21
At the University where I plan to study, they require a semester of C++ for all engineering students. I figure if I learn FORTRAN on my own as well it can only help.
 
  • #22
A great reference, if one can find it, is FORTRAN 77 for Engineers and Scientists with an Introduction to FORTRAN 90, 4/E, by Larry Nyhoff and Sanford Leestma, Published by Prentice Hall.

From the publisher - http://vig.prenhall.com/catalog/academic/product/0,1144,013363003X,00.html

They also have a book on Fortran 90, but it's best to start with FORTRAN77 and then go on to 90. There is a large volume of legacy code written in F77.

http://vig.prenhall.com/catalog/academic/product/0,1144,0135052157,00.html
 
Last edited by a moderator:
  • #23
For anyone looking for that text, the ISBN is 0-13-363003-X

www.cheapesttextbooks.com found a number of sources, for as little as $35
 
  • #24
Gosh, and I was just about to throw away my 1973 version of "Standard FORTRAN: A Problem-Solving Approach by Laura G. Cooper and Marilyn Z. Smith" from my first programming class. I guess I'll hang onto it...
 
  • #25
What is the syntax of format statement?

hello everyone!
I was do programming in fortran and i wanted to print my answer in the format below. I was not able to do it. I have written a part of my program also.
i.e,
#####
greeting = 'Good Morning!'
do 110 I = 1, 12
write (*,115) (greeting)
115 format (A<I>)
110 continue
end
#####
here i want to use a variable 'I' in the format statement i tried it doing but i failed. so please if anyone knows to use a variable in format statement tell me.
I use gcc-3.4.6 compiler.

output of the program
G
Go
Goo
Good
Good
Good M
Good Mo
Good Mor
Good Morn
Good Morni
Good Mornin
Good Morning

Plz mail to me at ajeet3047@gmail.com
 
Last edited:
Back
Top