Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

FORTRAN Tutorial

  1. Mar 6, 2006 #1

    Astronuc

    User Avatar

    Staff: Mentor

    Believe it or not, it is still widely used!

    http://gershwin.ens.fr/vdaniel/Doc-Locale/Langages-Program-Scientific/Fortran/Tutorial/index.htm
     
  2. jcsd
  3. Mar 6, 2006 #2

    berkeman

    User Avatar

    Staff: Mentor

    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!
     
  4. Mar 6, 2006 #3

    vanesch

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
     
  5. Mar 6, 2006 #4

    Astronuc

    User Avatar

    Staff: Mentor

    Fortran is still big in nuclear, mechanical, civil/structural and aerospace, but probably not so in electrical.

    We still use it. :rolleyes:

    :rofl:

    One point is that there is a lot of legacy code.
     
  6. Mar 6, 2006 #5
    FORTRAN, pshaw! Apple BASIC rules! :tongue2:

    -Dan
     
  7. Mar 10, 2006 #6

    Astronuc

    User Avatar

    Staff: Mentor

  8. Mar 10, 2006 #7

    Gokul43201

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I do too. Thanks for the tute.
     
  9. Mar 10, 2006 #8
    By the way, what school is teaching or has research problems done in Fortran ?:confused:
     
  10. Mar 11, 2006 #9

    George Jones

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
     
  11. Mar 11, 2006 #10

    Astronuc

    User Avatar

    Staff: Mentor

    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/...asses_Fall2002/Fortran77/Fortran77Course.html
    http://www.engineering.usu.edu/cee/...ses_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.
     
  12. Mar 11, 2006 #11

    Astronuc

    User Avatar

    Staff: Mentor

    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
     
  13. Mar 11, 2006 #12

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member


    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....
     
  14. Mar 15, 2006 #13

    Astronuc

    User Avatar

    Staff: Mentor

    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.
     
  15. Mar 17, 2006 #14

    So do LANL and LLNL.
     
  16. Mar 17, 2006 #15

    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.
     
  17. Mar 17, 2006 #16

    Astronuc

    User Avatar

    Staff: Mentor

    So do people at Sandia. And we work with those folk and people at other similar institutions.

    RE:
    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: Mar 17, 2006
  18. Mar 31, 2006 #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 any one 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
     
  19. Apr 1, 2006 #18

    Astronuc

    User Avatar

    Staff: Mentor

    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! :rofl: 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.
     
  20. Apr 1, 2006 #19
    its still the main langauge used by us in atomic physics
     
  21. Apr 2, 2006 #20

    Astronuc

    User Avatar

    Staff: Mentor

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?