      program sample

cc   This is a sample fortran program that writes a VAL program.

cc   It reads three values from the file "input.txt"

cc   1. a radius
cc   2. an angle
cc   3. an integer

cc   and outputs a VAL program that will move the robot in a circular
cc   arc that encompasses the angle inputted.  The circle is actually
cc   approximated by straight line segments, and the last input, the
cc   integer, is how many line segments should be used to approximate
cc   the circle.

      double precision r,theta,ang,dx,dy,x,y,z,o,i,t
      integer count

cc   Read the numbers from the file named "input.txt"

      open(unit=12,file='input.txt')
      read (12,*) r,theta,count

      theta = theta*3.1415926/180.0
cc    open the output file that will contain the program
      open(unit=13,file='program.txt')
 200  format("DP P",i3,f9.3,f9.3,f9.3,f9.3,f9.3,f9.3)
 201  format("MOVE P",i3)

      x = 100.0
      y = 250.0
      z = -175.0
      o = 179
      a = 1
      t = 89
      j = 100
cc    this do loop defines all the points
      do 30 ang = 0, theta, theta/count
         x = x - (r*theta/count*cos(ang))
         y = y + (r*theta/count*sin(ang))
         write (13, 200)  j,x,y,z,o,i,t
         j = j + 1
 30   continue

cc    define the initial point and set the speed

 301  format("DP P1 100 250 -175 179 1 89")
      write(13,301)
 302  format("SPEED 10 ALWAYS")
      write(13,302)
 303  format("MOVE P1")
      write (13, 303)
 304  format("DRAW ", f9.3,",", f9.3)

cc    this do loop is all it takes to make the circle
      do 10 ang = 0, theta, theta/count
         dx = -r*theta/count*cos(ang)
         dy = r*theta/count*sin(ang)
         write (13, 304) dx,dy
 10   continue

cc    this next secion does the same thing, but defines points and
cc    then uses MOVE to move between them, as opposed to DRAW above

cc    move back to the starting point
      write (13,303)

cc    x and y come from their definitions in P1
      x = 100
      y = 250
      z = -175
      o = 179
      i = 1
      t = 89

      j = 100
cc    this do loop defines all the points
      do 40 ang = 0, theta, theta/count
         write (13, 201)  j
         j = j + 1
 40   continue

 305  format("READY")
      write(13,305)
      stop 
      end
