FUNCTION x(t)
  IMPLICIT NONE

  DOUBLE PRECISION, INTENT (in) :: t
  DOUBLE PRECISION :: x

  DOUBLE PRECISION, PARAMETER :: A = 3.0d0, B = 2.0d0, omega = 12.0d0

  x = A * COS(omega * t) + B * SIN(omega * t)
END FUNCTION x


PROGRAM oscillator
  IMPLICIT NONE

  INTERFACE
     FUNCTION x(t)
       IMPLICIT NONE

       DOUBLE PRECISION, INTENT (in) :: t
       DOUBLE PRECISION :: x
     END FUNCTION x
  END INTERFACE

  DOUBLE PRECISION, PARAMETER :: step = 0.5d0, ini = 0.0d0, fin = 100.0d0
  INTEGER, PARAMETER :: n = INT( (fin - ini) / step )

  DOUBLE PRECISION :: t
  INTEGER :: i

  OPEN(19, file="data", action="write", status="replace")

  DO i = 0, n
     t = ini + i * step
     WRITE (19, "(2(1X,F0.4))") t, x(t)
  ENDDO

  CLOSE(19)

END PROGRAM oscillator
