      PROGRAM XTLPLOT
C
C     PREPARE CALCOMP 'PLOT.DAT' FILES FOR CRYSTAL DRAWINGS FROM FILES
C     CREATED BY PROGRAM ABSORB1 FOR AN MMS-X GRAPHICS DEVICE. 
C
C     'XTLPLOT.DAT' INPUT FILE IS AN EDITED VERSION OF THE 'CRYST.MMS'
C     OR 'BRAGG.MMS' ASCII FILES OF VERTICES AND CONNECTIONS TABLES FROM
C     PROGRAM ABSORB1.  THE FILES SHOULD BE EDITED TO REMOVE THE
C     GAUSSIAN GRID TICKS TO PROVIDE A SIMPLER DRAWING.
C
C     OPTIONAL 'TUBEPLOT.DAT' INPUT FILE IS A COPY OF THE 'TUBE.MMS'
C     ASCII FILE FROM PROGRAM ABSORB1 CONTAINING END POINTS AND
C     CONNECTIONS FOR DRAWING A CAPILLARY CRYSTAL ENCLOSURE.
C
      PARAMETER (MV=100,MT=200,MM=300)
      CHARACTER XTL*72,TUBE*72,TITLE*72
      DIMENSION X(MM),Y(MM),Z(MM),NC(8,MM)
      DATA NC /2400*0/
 1    TYPE 1000
 1000 FORMAT ('0ENTER FILE NAME FOR THE "xtlplot.dat" INPUT FILE.')
      ACCEPT 999,XTL
 999  FORMAT (A)
      OPEN (UNIT=1,FILE=XTL,STATUS='OLD',ERR=1)
      TYPE 1001
 1001 FORMAT ('0DRAW CAPILLARY TUBE?  Y OR N (N).')
      ACCEPT 999,A
      IF (A.EQ.'Y') THEN
 2      TYPE 1002
        ACCEPT 999,TUBE
        OPEN (UNIT=2,FILE=TUBE,STATUS='OLD',ERR=2)
      END IF
 1002 FORMAT ('0ENTER FILE NAME FOR THE "tubeplot.dat" INPUT FILE.')
      READ (1,999) TITLE
      READ (1,998) NV
 998  FORMAT (I10)
      XMIN=+1E6
      XMAX=-1E6
      DO 5 I=1,NV
      READ (1,997) X(I),Y(I),Z(I),(NC(N,I),N=1,8)
 997  FORMAT (8X,3F8.0,16X,8I4)
      XMIN=MIN(XMIN,X(I),Y(I),Z(I))
      XMAX=MAX(XMAX,X(I),Y(I),Z(I))
 5    CONTINUE
      NT=0
      READ (2,999,END=7) A
      READ (2,998) NT
      DO 6 I=NV+1,NV+NT
      READ (2,997) X(I),Y(I),Z(I),N
      NC(1,I)=N+NV
      XMIN=MIN(XMIN,X(I),Y(I),Z(I))
      XMAX=MAX(XMAX,X(I),Y(I),Z(I))
 6    CONTINUE
 7    CONTINUE
      XMIN=XMIN-0.1*(XMAX-XMIN)
      XMAX=XMAX+0.1*(XMAX-XMIN)
      YMIN=XMIN
      YMAX=XMAX
C
C     PLOT THREE ORTHOGONAL VIEWS.
C
      CALL XYPLOT (NV,NT,Y,Z,NC,XMIN,XMAX,YMIN,YMAX)
      CALL XYPLOT (NV,NT,Z,X,NC,XMIN,XMAX,YMIN,YMAX)
      CALL XYPLOT (NV,NT,X,Y,NC,XMIN,XMAX,YMIN,YMAX)
      TYPE 1003
 1003 FORMAT ('0OUTPUT FILES:'/
     &'0''plot.dat.0001''  X-PROJECTION'/
     &' ''plot.dat.0002''  Y-PROJECTION'/
     &' ''plot.dat.0003''  Z-PROJECTION')
      STOP
      END
      SUBROUTINE XYPLOT (NV,NT,X,Y,NC,XMIN,XMAX,YMIN,YMAX)
C
C     CALLS CALCOMP PLOT ROUTINES.
C
      DIMENSION X(1),Y(1),NC(8,NV)
      DATA IU,ID,NO /3,2,-1/
C
C     SET 5 INCH X 5 INCH PLOT AREA.
C
      XLEN=5
      YLEN=5
C
C     SET SCALE FACTOR FOR ENLARGEMENT OR REDUCTION OF PLOT.
C
      IF (F.EQ.0) F=1
C
C     ALLOW FOR 11 INCH WIDE PAPER AND 1 INCH MARGIN.
C
      IF (F*(YLEN).GT.10) F=10/YLEN
C
C     INITAILIZE THE PLOTTER.
C
      CALL PLOTS (0,0,LDEV)
C
C     SCALE THE PLOT.
C
      CALL FACTOR (F)
C
C     POSITION THE PLOT ORIGIN.
C
      XP=0.5*XLEN
      YP=0.5*YLEN
      IP=IU*NO
      CALL PLOT (XP,YP,IP)
C
C     GET X- AND Y-SCALE FACTORS.
C
      XSCALE=XLEN/(XMAX-XMIN)
      YSCALE=YLEN/(YMAX-YMIN)
C
C     PLOT VERTICES AND EDGES.
C
      H=0.1
      IC=3
      T=0
      NP=-1
      ND=-1
      DO 10 J=1,NV
      XJ=XSCALE*(X(J)-XMIN)
      YJ=YSCALE*(Y(J)-YMIN)
      XP=XJ+0.1
      YP=YJ+0.1
      FN=J
      CALL NUMBER (XP,YP,H,FN,T,ND)
      DO 11 N=1,8
      XP=XJ
      YP=YJ
      IP=IU
      CALL PLOT (XP,YP,IP)
      IF (NC(N,J).EQ.0) GO TO 10
      XP=XSCALE*(X(NC(N,J))-XMIN)
      YP=YSCALE*(Y(NC(N,J))-YMIN)
      IP=ID
      CALL PLOT (XP,YP,IP)
 11   CONTINUE
 10   CONTINUE
C
C     PLOT CAPILLARY TUBE.
C
      IF (NT.EQ.0) GO TO 21
      DO 20 J=NV+1,NV+NT
      XP=XSCALE*(X(J)-XMIN)
      YP=YSCALE*(Y(J)-YMIN)
      IP=IU
      CALL PLOT (XP,YP,IP)
      XP=XSCALE*(X(NC(1,J))-XMIN)
      YP=YSCALE*(Y(NC(1,J))-YMIN)
      IP=ID
      CALL PLOT (XP,YP,IP)
 20   CONTINUE
 21   CONTINUE
C
C     TERMINATE THE PLOT.
C
      IP=999
      CALL PLOT (XP,YP,IP)
      RETURN
      END
