c     Main part
      PROGRAM main

      COMMON /const/ rad
      COMMON /input/ Xmin, Xmax, Xstep, Ymin, Ymax, Ystep

      rad = 3.1415927 / 180
      PRINT *, rad

      CALL inputf
      CALL outputf
      END

c     Input values from file
      SUBROUTINE inputf

      COMMON /const/ rad
      COMMON /input/ Xmin, Xmax, Xstep, Ymin, Ymax, Ystep

      OPEN (1, FILE='input.txt', ACTION='READ', STATUS='OLD', ERR=1)
      READ (1, *, ERR=1) Xmin, Xmax, Xstep, Ymin, Ymax, Ystep
      IF (Xmin .GT. Xmax .OR. Ymin .GT. Ymax) GOTO 1
      GOTO 2
         
    1 PAUSE 'Error: please check the input file'
      STOP
    2 END

c     Write cosec(x+y) result in output file
      SUBROUTINE outputf

      COMMON /const/ rad
      COMMON /input/ Xmin, Xmax, Xstep, Ymin, Ymax, Ystep

      OPEN (2, FILE='output.txt', ACTION='WRITE', ERR=3)

c     Draw the table top
      WRITE (2, 13) '|    y\x     '
      WRITE (2, 11) Xmin
      ri = Xmin + Xstep
      DO WHILE (ri .LT. Xmax)
         WRITE (2, 11) ri
         ri = ri + Xstep
      END DO
      WRITE (2, 11) Xmax
      WRITE (2, 13) '|'
      WRITE (2, 14)

c     I cant round iparts up, so... +2 instead of +1
      iparts = (Xmax - Xmin) / Xstep + 2
      DO i = 0, iparts, 1
         WRITE (2, 12)
      END DO
      WRITE (2, 13) '|'

c     Do something blablabla fix it
c     I HATE FORTRAN


      GOTO 4
    3 PAUSE 'Error: please check the output file'
      STOP

   10 FORMAT ('|'E11.4' '\)
   11 FORMAT ('|'F11.4' '\)
   12 FORMAT ('|'12('—')\)
   13 FORMAT (a\)
   14 FORMAT (/1x\)

    4 END