Solution for exercise 1

Review

  1. MASS is by implicit declaration an INTEGER (starting with letter "M")
  2. Comments can be started with a leading !
    or one of the characters C, *, ! in first column

Task 1 - A flawless Fortran program

The shortest possible Fortran program contains only the instruction
      END 
 

Depending on the OS you are using (kind, version), answers might differ:
  1. -rwxr-xr-x   1 htodt users       12K Oct 24 10:14 simple_gfortran
    -rwxr-xr-x 1 htodt users 666K Oct 24 10:14 simple_ifort
  2. ldd simple_gfortran 
            linux-vdso.so.1 (0x00007ffc707cd000) 
            libgfortran.so.4 => /usr/lib64/libgfortran.so.4 (0x00007f6dc40b5000) 
            libm.so.6 => /lib64/libm.so.6 (0x00007f6dc3fcb000) 
            libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f6dc3fa5000)
            libquadmath.so.0 => /usr/lib64/libquadmath.so.0 (0x00007f6dc3f5f000) 
            libc.so.6 => /lib64/libc.so.6 (0x00007f6dc3c00000)
            /lib64/ld-linux-x86-64.so.2 (0x00007f6dc42af000)
    
    ldd simple_ifort
            linux-vdso.so.1 (0x00007ffdd9894000)
            libm.so.6 => /lib64/libm.so.6 (0x00007f9d48e84000)
            libc.so.6 => /lib64/libc.so.6 (0x00007f9d48c00000)
            libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f9d48e5e000)
            /lib64/ld-linux-x86-64.so.2 (0x00007f9d48f94000)
           
           

Task 2 - Hello world!

  1. A simple "Hello world!" program could look like this:

          PROGRAM helloworld
          WRITE (*,*) "Hello world!"
          STOP
          END

  2. With the correct format for text the WRITE instruction reads:

          WRITE (*,'(A)') "Hello world!"

    or more specific

          WRITE (*,'(A12)') "Hello world!"

  3. As an alternative to WRITE one could (in this case) also use PRINT:

          PRINT *, "Hello world!"

    or with correct format:

          PRINT '(A)', "Hello world!"

  4. While in FORTRAN 77 the program instruction are in the columns 7 - 72 and the first 6 columns have a special meaning, it is possible to use also the free form since Fortran 90. In the free form of the source code the instructions can start in column 1.
    As the first column in the free form of Fortran 90 is not longer reserved for the comment indicator (*,C,!), Fortran 90 uses a different way to indicate the beginning of a comment: the exclamation mark ! indicates the beginning of a comment. Please, feel encouraged to make extensive use of this character in your source code.
    For the same reason, continuation lines in Fortran 90 are indicated by a special character: the ampersand &.
    The compiler needs to be instructed about the use of the free form, e.g.,
    via the file extension of the source code .f90,
    or via the compiler option: -ffree-form (gfortran), or -free (ifort), respectively.

  5. E.g.,

    WRITE(*,'(A,E7.2E1)') 'Hello world!', 7.5E-4

    If a FORMAT instruction should be used:

          WRITE (*,101) 'Hello world!', 7.5E-4
      101 FORMAT (A,E7.2E1)

    The FORMAT instruction is usually put directly after the WRITE statement or after the final STOP:

          STOP
      101 FORMAT (A,E7.2E1)
          END