next up previous contents
Next: Declaration of Variables Up: A quick tour of Previous: Program Form   Contents

Free vs. Fixed Formats

In Fortran 95 the code layout is obeys the following rules, which describe the ``free source form''.

For example, the above code fragment could be written in free source form as

language=[95]Fortran visiblespaces=true

! This is free-form
temp = x; x = y; y = temp ! Swap x and y 
write(6,*) 'x and y are =',  & 
            x,y           ! Print x and y
visiblespaces=false

For back-compatibility with Fortran 77, Fortran 90 accepts a ``fixed source form''. In short, the fixed source form requirements are:

Fixed format was born in 1950's, when each line of code was punched on a paper card (``punched card''). For debugging and maintaining the code it was clearly easier to have one statement per card. When running, a punched card had to be aligned, checked if it is a new statement or a continuation of the last, if it is a comment, etc. - lots of information stored in the first 6 columns. (A million-line code, quite common today, on punched cards, needed a truck to be carried from one computer to another).

For example, a fragment of a Fortran 90 program in fixed source form (in fact, Fortran 77 program) can be:

C---This-is-fixed-form 
C---Swap x and y 
      temp = x
      x = y
      y = temp
C---Print x and y 
      write(6,*) 'x and y are =',
    *             x,y

Our compiler (f90) will consider the program to be in fixed source format if the source file has the extension `` .f'' (for example, my_program.f). The compiler will consider the program to be in free source format if the source file has the extension `` .f90'' (for example, my_program.f90). Note that a free format source in a .f file may result in compilation errors.


next up previous contents
Next: Declaration of Variables Up: A quick tour of Previous: Program Form   Contents
Adrian Sandu 2001-08-26