Basics of Fortran 77

  1. Fixed Format Fortran Rules


  2. Our first program - Hello World !
  3. program helloWorld write(*,*) 'Hello World !' end program helloWorld


    Compiling a single fortran file (with the gfortran compiler)
    $ gfortran helloWorld.f -o helloWorld
    
    Running the executable (Assuming the current directory contains the executable)

    1. Unix
    2.    $ ./helloWorld
         
    3. Windows OS
    4.    $ helloWorld.exe
         
  4. Projectile problem
  5. program projec c This program computes the velocity and height of a projectile c given the initial height, initial velocity and the constant c acceleration implicit none c Declare the variables real hght0, vel0, time, velof, hghtf, accel c Declare the value of the acceleration due to gravity data accel /-9.807/ c Obtain the initial height, initial velocity and the time after c launch write(*,*) 'Enter the initial height, initial velocity and the' write(*,*) 'time after launch' read(*,*) hght0, vel0, time c Calculate the height and the velocity hghtf = vel0*time + 0.5*accel*time**2 + hght0 velof = vel0 + accel*time c Display the height and the velocity after time write(*,*) 'Time after launch:', time write(*,*) 'Current Height:', hghtf write(*,*) 'Current Velocity:', velof end program projec

    Sample Run:
    Enter the initial height, initial velocity and the
    time after launch
    100 90 4.3
    
    Time after launch: 4.30000019
    Current Height:    396.334290
    Current Velocity:  47.8298988