	GLOBAL DEFINE
	  INCLUDE "Windows.inc"
	END
	
	PROGRAM XYPlot
C
C	30.10.2003 by Michael Knappertsbusch
C	6.9.2011, modified from version 2: Plotting of osculating circles to upper and
C	lower keelwidth areas added.
C
C	Program to draw X,Y plots from external X,Y data to the screen.
C	The program also plots the osculating circles in the keel regions in profile view.
C
	INTEGER I,K
	REAL X,Y,RHO
	CHARACTER*20 LIST,FILENAME				! LIST contains the filenames with the coords to be plotted
	CHARACTER*47 HEADER					! The first line in LIST is a 47 chars long header line
	PARAMETER(RHO=1)					! Circles are points when the radius is set to 1
C
	RECORD /Rect/rrect					! Define rectangle structure rrect
C
	rrect.top=0						! Size of rrect
	rrect.left=0
	rrect.bottom=600
	rrect.right=600
C
C
C
	WRITE(9,*) '********************************************'
	WRITE(9,*) '*                                          *'
	WRITE(9,*) '*  Program XYPlot, V.3.1 (Batch mode)      *'
	WRITE(9,*) '*                                          *'
	WRITE(9,*) '*  by Michael. Knappertsbusch, 6.9.2011    *'
	WRITE(9,*) '* Draws X,Y data circles to lower & upper  *'
	WRITE(9,*) '*  keel region to screen at intervals of   *'
	WRITE(9,*) '*              5 outlines                  *'
	WRITE(9,*) '*                                          *'
	WRITE(9,*) '********************************************'
	WRITE(9,*) ' '
	WRITE(9,*) '. . .Enter filename with list of files'
	WRITE(9,*) 'that contain X,Y data. . .'
	WRITE(9,*) '         (max 20 chars long)'
	READ(9,5) LIST
 5	FORMAT(A20,3(1X,F8.3))
C
C
C	Main program:
C
	CALL EraseRect(rrect)					! Clear screen
	OPEN(14,FILE=LIST,STATUS='OLD')				! LIST contains the names of the files with the X,Y coordinates
C								    of the upper and/or lower keel region. LIST contains also the
C								    center coordinates and the radius of the osculating circle in
C								    the corresponding keel region. The name of the file, that
C								    contains the complete X,Y coordinates of the outline is 
C								    calculated from the names given in LIST (i.e. the first 15 chars
C								    with two characters _T appended at the end).
C								    The first line in LIST contains a 47 chars long header info line.
	READ(14,6) HEADER
 6	FORMAT(A47)
C
	I=0							! Initialize counter I
 10	K=0							! Main loop begins here.
 	I=I+1							! I counts the number of outlines
 	READ(14,5,END=999) FILENAME,XC,YC,R			! Reading filename with keelregion coords, center coords and radius of circle
	CALL DrawCircle(RHO,100+XC/5,100+YC/5)			! Plots the center of the osculating circle in the keel region
	CALL DrawCircle(R/5,100+XC/5,100+YC/5)			! Plots the osculating circle in the keel region
	OPEN(15,FILE=FILENAME(1:15)//'_T',STATUS='OLD')		! Opens the file containing the X,Y coords of the complete outline
 20	K=K+1							! K counts the points in each outline
 	IF ((MOD(I,10).EQ.0).AND.(K.EQ.1)) THEN			! Avoid plotting first point if MOD(I,10) is zero
	  GOTO 30
	END IF
 	READ(15,*,END=100) X,Y					! Reading X,Y coordinates from the outline file
	CALL DrawCircle(RHO,100+X/5,100+Y/5)			! Plots the outline points (=circles of radius 1)
C
C	Draw intervals of 5 outlines and then pause:		! MOD(I,10) because each outline has 2 circles (5*2=10)
C
 30	IF ((MOD(I,10).EQ.0).AND.(K.EQ.1)) THEN			! MOD(I,10) because each outline has 2 circles (5*2=10)
	  PAUSE
	  CALL EraseRect(rrect)					! Erase previous 5 outlines with their circles from screen
	END IF
C
	GOTO 20
C
 100	CLOSE(15)						! Close the current file with the outline coordinates
 	GOTO 10
 999	CLOSE(14)						! Close LIST
 	PAUSE
C
	STOP
	END
	
	
	
	
	
	
	
	
	
	SUBROUTINE DrawCircle(Radius,Xm,Ym)
C
C	Draws a circle with radius Radius, and Center with coordinates
C	at Xm,Ym.
C
	RECORD /Rect/ r
	RECORD /WindowRecord/ front
	POINTER (p_front, front)
C	
	p_front=FrontWindow()
	CALL SetPort(VAL4(p_front))
C	
	r.top=Ym-Radius				! Defines a rectangle structure
	r.left=Xm-Radius
	r.bottom=Ym+Radius
	r.right=Xm+Radius
C
	CALL FrameOval(r)			! Draws the oval (or circle)
C	
	RETURN
	END