C
C
C     NAME - STEREO   "COMPLETE STEREO PROGRAM"
C
C              BY  BRIAN ARMBRUSTER    SYSTEMS DESIGN ENGINEERING
C                  MIKE LAPRES         UNIVERSITY OF WATERLOO
C                  DON SHAW            APRIL,1974
C
C
C     PURPOSE - 'STEREO' FACILITATES THE USE OF 'ROTER','STMAP',
C               AND 'STDRW' ELIMINATING THE NEED FOR THE USER TO
C               CALL EACH SUBPROGRAM AND ASSIGN ALL THE INITIAL
C               VALUES.
C
C
C     CALLING SEQUENCE
C
C          ---
C          INTEGER I3STRT,I3END,INT,ISPACE,MODE,ITAG
C          REAL OBJECT(6,30),EYE(3),CENTRE(3),UP(3),XMIN
C         *XMAX,YMIN,YMAX,DIST
C          ---
C          COMMON /BULK/I3STRT,I3END,OBJECT(6,30)
C          COMMON /EYCEP/EYE(3),CENTRE(3),UP(3)
C          COMMON /FRAME/XMIN,XMAX,YMIN,YMAX
C          COMMON /POINTS/INT,ISPACE
C          ---
C          <COMMENT: ALL ABOVE VARIABLES MUST BE ASSIGNED VALUES>
C          ---
C          CALL STEREO(MODE,DIST,ITAG)
C          ---
C
C
C     ARGUMENT DISCRIPTION
C
C         NOTE: ALL THE ABOVE VARIABLES ARE EXPLAINED IN 'STMAP',
C               'ROTER' AND 'STDRW' EXCEPT FOR:
C
C     POINTS      COMMON AREA FOR 'INT' AND 'ISPACE' (SEE 'VECTOR')
C
C     ITAG        RETURNED BY STEREO: A NUMBER
C                 ASSIGNED TO A DISPLY FILE FOR FURTHER MANIPULATION
C                 PURPOSES. IT IS THE SAME TAG NUMBER AS USED
C                 IN 'DISPLY'. THE ITAG REFERS TO THE FILE OF THE
C                 LEFT IMAGE. 'ITAG'+1 IS THE TAG FOR THE
C                 RIGHT IMAGE.
C
C     MODE        AN INTEGER TO DEFINE THE OPTIONS WITHIN 'STEREO'.
C
C       MODE=1      THE DISPLAY FILE IS CLEARED (ALL REFERENCES TO 
C                   'ITAG' NUMBERS ARE LOST). THE SCREEN IS INITIALIZED.
C                   THE POINTS ARE GENERATED AND DISPLAYED.
C                  NOTE: THE FIRST CALL TO STEREO MUST BE WITH MODE
C                        1 OR 4 OR BEFORE CALLING 'STEREO' THE USER
C                        MUST CALL 'CLEAR' AND ASSIGN A NUMBER
C                        TO 'ITAG'.
C
C      MODE=2       ALL EXISTING FILES BEING DISPLAYED WILL BE
C                   TURNED OFF BEFORE THE FILE BEING PROCESSED IS 
C                   DISPLAYED. EXISTING FILES WILL STILL BE 
C                       REFERENCABLE BY THEIR 'ITAG' NUMBERS.
C
C       MODE=3      ANY EXISTING FILES WILL CONTINUE BEING DISPLAYED
C                   WITH THE ADDITION OF THE NEW ONE
C
C       MODE=4      AS IN MODE 1 BUT THE NEW FILE WILL NOT BE DRAWN
C                   IT CAN BE DRAWN AT A LATER TIME BY REFERENCE TO 
C                   IT'S 'ITAG' NUMBER.
C
C       MODE=7      AS IN MODE 2 BUT THE NEW FILE WILL NOT BE
C                   DISPLAYED.
C
C       MODE=6      AS IN MODE 3 BUT THE NEW FILE WILL NOT BE
C                   DISPLAYED.
C
C
C
      SUBROUTINE STEREO(MODE,DIST,ITAG)
      INTEGER IVECT(500),MODE
      COMMON /POINTS/INT,ISPACE
      COMMON /EYCEP/EYE(3),CENTRE(3),UP(3)
      COMMON /BULK/I3STRT,I3END,OBJECT(6,60)
      COMMON/IMAGE/ILSTRT,ILEND,IRSTRT,IREND,PICT(4,120)
      COMMON/FRAME/A,B,C,D
      COMMON/LIMITS/Q,R,S,T
C
      IF((MODE.LT.1).OR.(MODE.GT.6)) WRITE (4,99)
99    FORMAT(49H *****ERROR*****MODE FOR SUBPROGRAM STEREO IS NOT,/,
     *31H                BETWEEN 1 AND 6)
C
      ILSTRT=1
      CALL ROTER
C
C STEREO BASE SCALED TO IMAGE SCALE
      SEP=4.675*2.5/(B-A)
      CALL STMAP(DIST,SEP)
      IF((MODE.NE.1).AND.(MODE.NE.4))GOTO 10
C
C INITIALIZATION ROUTINE
      CALL CLEAR(.TRUE.)
      L=ITAG+1
      DO 7 K=1,L
7     CALL DISPLY(3,K)
      ITAG=-1
      GOTO 20
10    IF((MODE.NE.2).AND.(MODE.NE.6))GOTO 20
C
C TURNING EXISTING FILES OFF
      L=ITAG+1
      DO 15 K=1,L
15    CALL DISPLY(5,K)
C
C "STDRW" ROUTINE
20    S=C
      T=D
      Q=A
      R=B*2.-A
      CALL VECTOR(2,PICT,ILSTRT,ILEND,IVECT,1,MID,
     *INT,ISPACE,.FALSE.)
      Q=A*2.-B
      R=B
      CALL VECTOR(2,PICT,IRSTRT,IREND,IVECT,MID+1,LAST,
     *INT,ISPACE,.FALSE.)
C
C "DISPLY" USING "ITAG"
      IFCN=6
      IF(MODE.GT.3)IFCN=1
      ITAG=ITAG+2
      CALL DISPLY(IFCN,ITAG,IVECT,1,MID)
      ITAG=ITAG+1
      CALL DISPLY(IFCN,ITAG,IVECT,MID+1,LAST)
      ITAG=ITAG-1
      RETURN
      END
