C Copyright(c) 1997, Space Science and Engineering Center, UW-Madison
C Refer to "McIDAS Software Acquisition and Distribution Policies"
C in the file  mcidas/data/license.txt

C *** $Id: m0scatt.f,v 1.6 1999/03/22 15:07:19 rodr Exp $ ***


*$ Name:
*$      m0scatt - draw scatter plot diagram
*$
*$ Interface:
*$      subroutine
*$      mcscatt(real xarray(*), real yarray(*), integer numpoint,
*$		character xtitle*(*), character ytitle *(*),
*$		character title*(*), integer color, character type*(*),
*$		integer frame, integer offset)
*$
*$ Input:
*$ 	xarray		- array of abscissa coordinates
*$	yarray 		- array of ordinate coordinates
*$	numpoint	- number of points to be plotted
*$	xtitle		- ascissa title
*$	ytitle		- ordinate title
*$	title		- main title
*$	color		- color level to draw in, color=0 indicates
*$			  draw the graph, negative level overlay graph
*$	type		- graph point types, 'SLD' to draw solid line
*$			  'DOT' to draw scatter diagram
*$	frame		- graphics frame to draw diagram on
*$	offset		- number of lines & elements to offset around
*$			  diagram
*$
*$ Input and Output:
*$      none
*$
*$ Output:
*$      none
*$
*$ Return values:
*$      none
*$
*$ Remarks:
*$      Call mcscatt to draw a scatter plot.
*$
*$ Categories:
*$      display
*$      graphic



      SUBROUTINE M0SCATT(X,Y,NP,CXTIT,CYTIT,CTIT,LV,CLINE,JF)
      integer OldFrame		! keep track of trame we're on while setting screen boundaries
      integer LUC
      LOGICAL OFF
      LOGICAL TRUE
      REAL X(*),Y(*)
      CHARACTER*(*) CXTIT,CLINE,CYTIT,CTIT
      CHARACTER*12 CFF, CFG
      DIMENSION IDIV(2),ISUB(2),XMM(2),YMM(2)
      DATA TRUE/.TRUE./,IHGT/7/
      DATA IDIV/10,10/,ISUB/5,5/,ITIC/7/
      DATA OFF/.FALSE./,IFLAG/0/
      INTER(IB,XV,XM,XC)=IB+(XV-XM)*XC
C
      IF(IFLAG.EQ.0) THEN
	 OldFrame=LUC(-5)			! what frame are we on
	 call PUC(JF,-5)			! set to new frame
         CALL TVLIMS(0,IYB,IYE,IXB,IXE)
	 call PUC(OldFrame,-5)			! restore to old frame
         IXB=IXB+100
         IXE=IXE-100
         IYB = IYB + 15
         IYE = IYE -15
	 IFLAG = 1
      ENDIF

      ISZ=IKWP('DRAW',2,4)
      LLV=LV
      IF=IABS(JF)
      IF(LLV .GE. 0)GO TO 103
C     ENTRY FOR OVERLAY SO SAVE PREVIOUS PLOT ARRAY
      LLV=IABS(LLV)
      GO TO 104
C     COUNT TITLE CHARACTERS
103   CONTINUE
      NX=NCHARS(CXTIT,KBX,KEX)
      NY=NCHARS(CYTIT,KBY,KEY)
      NT=NCHARS(CTIT,KBT,KET)
C     INITIALIZE
      CALL XTREME(X,NP,XMM)
      CALL XTREME(Y,NP,YMM)
      IF(LLV.EQ.0.AND.JF.GE.0) GO TO 60
       CALL ADJUST(XMM)
       CALL ADJUST(YMM)
60    CONTINUE
      YDIS=YMM(2)-YMM(1)
      XDIS=XMM(2)-XMM(1)
      CALL DDEST('DIV1  ',IDIV(1))
      CALL DDEST('DIV2  ',IDIV(2))
      CALL DDEST('SUB1  ',ISUB(1))
      CALL DDEST('SUB2  ',ISUB(2))


      IYE=IYB+((IYE-IYB+1)/IDIV(2))/ISUB(2)*ISUB(2)*IDIV(2)
      IXE=IXB+((IXE-IXB+1)/IDIV(1))/ISUB(1)*ISUB(1)*IDIV(1)

      CALL DDEST('YDIS= '//CFG(YDIS),0)
      CALL DDEST('XDIS= '//CFG(XDIS),0)
C
C--- CHECK TO MAKE SURE MIN NOT = MAX -> YDIS/XDIS=0
      IF(YDIS .GT. 0.0) THEN
       YINC=(IYE-IYB)/YDIS
      ELSE
       YINC = 1.0
      ENDIF

      IF(XDIS .GT. 0.0) THEN
       XINC=(IXE-IXB)/XDIS
      ELSE
       XINC = 1.0
      ENDIF

C...DRAW AXES AND SCALE
      CALL INITPL(IF,0)
      IZX=IXB
      IF(OFF) IZX=INTER(IXB,0.0,XMM(1),XINC)
C

      CALL AXIS(YMM,XMM,IYB,IYE,IXB,IXE,IZX,IDIV,ISUB,ITIC)
C     WRITE TITLES
C     MAIN
      IF(NT.EQ.0) GO TO 655
      ITHGT=10
      ITHGT=MIN0(ITHGT,(IXE-IXB)/NT)
      ITHGT=MAX0(8,ITHGT)
      IXTS=MAX0(IXB, (IXE+IXB)/2-ITHGT*NT/2)
      CALL WRTEXT(IYB-IHGT*2-ITHGT-3,IXTS,ITHGT,CTIT(KBT:KET),NT,2)
C     X TITLE
655   CONTINUE
      IF(NX.EQ.0) GO TO 656
      ITHGT=10
      ITHGT=MIN0(ITHGT,(IXE-IXB)/NX)
      ITHGT=MAX0(8,ITHGT)
      IXTS=MAX0(IXB, (IXE+IXB)/2-ITHGT*NX/2)
      CALL WRTEXT(IYE+IHGT*2+3,IXTS,ITHGT,CXTIT(KBX:KEX),NX,2)
C     Y TITLE WRITTEN VERTICALLY
656   CONTINUE
      LIN=IYB
C
      ICH=MAX0(NCHARS(CFF(DBLE(YMM(1)),1),IB,IE),
     &                               NCHARS(CFF(DBLE(YMM(2)),1),IB,IE))
C
      LEL=IXB-(ICH+4)*IHGT
C     GRAB AND WRITE ONE CHARACTER AT A TIME
      IF(NY.EQ.0) GO TO 104
      ITHGT=10
      ITHGT=MIN0(ITHGT,(IYE-IYB)/(NY*13/10))
      ITHGT=MAX0(8,ITHGT)
C
C--- CENTER THE Y-AXIS LABEL
      LIN = MAX0(IYB, (IYE+IYB)/2-ITHGT*13*NY/20)

      DO 100 I=KBY,KEY
      CALL WRTEXT(LIN,LEL,ITHGT,CYTIT(I:I),1,2)
      LIN=LIN+ITHGT*1.3
100   CONTINUE
C...PLOT THE DATA
104   CONTINUE
C
      ITY=INTER(IYE,Y(1),YMM(1),-YINC)
      ITX=INTER(IXB,X(1),XMM(1),XINC)
C
      CALL PLOT(ITY,ITX,0)
C
C--- CALL PAGE SO THAT PLOT WILL BE CLIPPED AT THE EDGES OF THE GRAPH
      CALL PAGE(IYB,IXB,IYE,IXE,0)
C-----
       CALL DDEST('NP= ',NP)
      DO 52 I=1,NP
      IF(CLINE.EQ.'SLD') CALL PLOT(ITY,ITX,0)
      ITY=INTER(IYE,Y(I),YMM(1),-YINC)
      ITX=INTER(IXB,X(I),XMM(1),XINC)
      IF(CLINE.EQ.'SLD') CALL PLOT(ITY,ITX,LLV)
      IF(CLINE.EQ.'DOT') CALL DOT(ITY,ITX,LLV)
      IF(CLINE.NE.'DOT'.AND.CLINE.NE.'SLD') THEN
       CALL WRTEXT(ITY,ITX,ISZ,CLINE,1,LLV)
      ENDIF
50    CONTINUE
52    CONTINUE
      CALL ENPT
      RETURN
      ENTRY m0SCATT1(IYBB,IYEE,IXBB,IXEE)
C...SET TV BOUNDS
      IYB=IYBB
      IYE=IYEE
      IXB=IXBB
      IXE=IXEE
      IFLAG=1
      RETURN
      ENTRY m0SCATT2(IDIVX,ISUBX,IDIVY,ISUBY,ITICC,IOFF)
      IF(IDIVX.GT.0) IDIV(1)=IDIVX
      IF(IDIVY.GT.0) IDIV(2)=IDIVY
      IF(ISUBX.GT.0) ISUB(1)=ISUBX
      IF(ISUBY.GT.0) ISUB(2)=ISUBY
      IF(ITICC.GT.0) ITIC=ITICC
      IF(IOFF.NE.0) OFF=TRUE
      RETURN
      END
