Code Monkey home page Code Monkey logo

fortran's Introduction

Example programm HELLO WORLD!

program hello print *, "Hello World!" end program hello

Compile:

gfortran -c hello.f95

wikibooks.org: https://en.wikibooks.org/wiki/Fortran/Hello_world

#Hello_World.f

Below is a simple Fortran program. You can paste this into a text editor (such as Emacs or Vim.) Source code must be in a plain text file, so don't use a word processor (such as Microsoft Word), because its native format is usually not plain text, or otherwise contains special formatting data.

Give the file a name such as hello.f - common Fortran file suffixes are .f, .FOR, .for, .f77, .f90 and .f95. You may also use .F, .fpp and .FPP (which support Preprocessing).

   program hello
      print *, "Hello World!"
   end program hello

or the archaic but shorter form:

   PRINT *, "Hello World!"
   END

Fixed format source code needs 6 spaces before code begins, but the free source form of Fortran 90 does not.

Because Fortran is case insensitive, one could just as easily write the first 'hello' program as:

  Program Hello
  Print *, "Hello World!"
  End Program Hello

The only case sensitive part of this program is what contained in the quotation marks of the print statement. ("Hello World!")

#Compiling Unix

There are several Fortran compilers available for Unix. Among the most popular are:

Fortran 95 optimizing compiler from Oracle Solaris Studio. Invocation:

f95 -o hello hello.f

G95, a compiler compliant with the Fortran 95 standard. Some of Fortran 2003 standard features are also supported. Invocation:

g95 -o hello hello.f90

GNU Fortran compiler from the GCC, which is a fork of G95. Invocation:

gfortran -o hello hello.f90

Note: the GNU Fortran compiler uses the Fortran 77 standard by default, so the input file must have the .f90 (or of later standard) suffix, so that the compiler can guess the desired standard automatically. Alternatively you can supply the -ffree-form option with the usual .f suffix to enable free-form format instead of the fixed-form format used by the Fortran 77 standard.

Once the program is compiled and linked, you may execute it:

./hello

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.