       SUBROUTINE CONT(A,LA,A2,LA2,ISP,X3,Y,IHDR,TITX,TITY,TYPE,TITL,
     1 ISH,XCO,LXCO,HMAX,SANG,EANG,LBL,IX,IY)
C SUBROUTINE CONT DOES THE ACTUAL CONTOURING OF DATA.  IT IS PASSED
C MOST OF ITS DATA BY PLOT1 AND CONTROL DATA FROM READ4.
      COMMON /FLIN/FLINES(2,3,180),NLINES
      DIMENSION A(2500,3),ANGLE(1),Z(80,80),A2(80,3),XCO(LXCO)
      DIMENSION B2(80,3)
      DATA UNDE /Z77777777/
      LOGICAL*1 TITL(80)
      COMPLEX*16 TITX,TITY,TYPE
      COMMON /OPTION/IMIN,IMAX,JMIN,JMAX,FINTER,NUMV,CONTUR(50)
      COMMON /MID/XMID,YMID
C SET THE DEFAULT STORAGE VALUE AS THE UNDEFINED VALUE FOR CONTOURING.
c      CALL UNDEF(UNDE)
C
C  ATTEMPT TO ENTER FUDGE FACTOR TO MOVE ASTERISK
C
C
C NOW WE CALCULATE THE NUMBERS OF ROWS AND COLUMNS IN THE ARRAY.
	do jq=1,2500
	write(12,*) (a(jq,jw),jw=1,3)
	enddo
      C=LXCO
      L=HMAX/500
      D=L*10
C CALCULATE THE LOCATION OF FIELD LINE INFORMATION FOR THIS X-AXIS
C TYPE(LATITUDE OR LONGITUDE ONLY).
      IFL=IX/3+1
C IF ISH=0(NO CONTOURS REQUESTED) GO TO END.
      IF(ISH.EQ.0) GO TO 200
C CONVERT INPUT ARRAY TO ROWS AND COLUMNS.
      CALL CONVRT(A,LA,2500,XCO(1),XCO(LXCO),50,HMAX,1.,C,1.,D)
      X0=XCO(1)-.1*(XCO(LXCO)-XCO(1))
      X1=XCO(LXCO)+.1*(XCO(LXCO)-XCO(1))
      L1=HMAX/500.
C
C CHANGE MADE HERE FOR TICK MARKS  500 USED TO BE 250
C
C IF ONLY CURVED EARTH CONTOURS, GO TO APPROPRIATE LOCATION.
      IF(ISH.EQ.2) GO TO 100
C IF HEADERS REQUESTED, PLOT THEM.
c      IF(IHDR.NE.0) GO TO 30
c      CALL HORLIN(TITL,80,XMID,2850,0,4)
c      CALL HORLIN(TYPE,16,XMID,2850,0,2)
c      CALL VERLIN(TITY,-16,300.5,YMID,-12,0)
c      CALL HORLIN(TITX,16,XMID,320.5,0,-4)
c   30 CALL OGRID(X0,X1,L,'F5.0)',1,0.,HMAX,L1,'F5.0)',2,0)
C IF SATELLITE OR F-PEAK POINTS REQUESTED, PLOT THEM.
c      IF(ISP.GT.0) CALL DATAPT(A2,LA2,80,1,'*')
      IMAX=LXCO
      JMAX=HMAX/50
C IF FIELD LINE PLOTTING REQUESTED AND LEGAL, PLOT THEM.
      IF(NLINES.LE.0.OR.IX.EQ.1.OR.IX.EQ.2.OR.IY.EQ.1) GO TO 6
c      DO 5 I=1,NLINES
c    5 CALL PLOT(FLINES(1,IFL,I),FLINES(1,3,I),2,' ')
C CLEAR OUT Z ARRAY, AND PUT VALUES TO BE CONTOURED AT THE GRID POINTS
C NEAREST INPUT VALUES.
    6 JMAX=HMAX/50
	type*,' imin imax jmin jmax ',imin,imax,jmin,jmax
      DO 10 I=IMIN,IMAX
      DO 10 J=JMIN,JMAX
   10 Z(I,J)=UNDE
c	type*,'  la  ',la
      DO 20 I=1,LA
      J=A(I,1)+.5
c	type*,' a ',a(i,1)
      K=A(I,2)+.5
c	type*,' k ',a(i,2)
      Z(J,K)=A(I,3)      
   20 write(13,*) j,k,z(j,k)
	do jv=1,j
	  write(10,*) (z(jv,kv),kv=1,k)
	enddo
C DUMP THE Z ARRAY.
c      CALL ZDUMP(Z,80,80)
      X2=IMIN-(IMAX-IMIN)*.1
      X4=IMAX+(IMAX-IMIN)*.1
      Y1=JMIN
      Y2=JMAX
C RESCALE FOR CONTOURS, AND PLOT THEM.
c      CALL SCALE(X2,X4,Y1,Y2,0)
c      CALL LABELI(LBL)
c      CALL TRACER(Z,80,80)
c      CALL FRMADV
C IF ONLY FLAT EARTH REQUESTED, GO TO END.
      IF(ISH.EQ.1) GO TO 200
  100 CONTINUE
C NOW HANDLE CURVED-EARTH CONTOURS
C COORDINATES MUST ALL BE REVERSED.
      DO 110 I=1,2500
      ST1=A(I,1)
      A(I,1)=A(I,2)
  110 A(I,2)=ST1
      DO 120 I=1,80
      ST1=A2(I,1)
      A2(I,1)=A2(I,2)
  120 A2(I,2)=ST1
C
C  BUMP ALL ALTITUDES UP BY 50 KM FOR COSMETIC REASONS
C  7/31/81  P.K. PARKER
C
      DO 122 I=1,80
  122 A2(I,1)=A2(I,1)+50.
C
C  ARRAY B2 IS A2 'FUDGED' TO MOVE THE ASTERISK SLIGHTLY LEFT
C
      I=IMIN
      IMIN=JMIN
      JMIN=I
      I=IMAX
      IMAX=JMAX
      JMAX=I
C NOW THAT EVERYTHING HAS BEEN REVERSED FOR THE POLAR CONTOURS, SET UP
C THE POLAR GRID.
C IF HEADERS HAVE BEEN REQUESTED, PLOT THEM.
c      IF(IHDR.NE.0) GO TO 40
c      CALL HORLIN(TITL,80,XMID,2850.5,0,4)
c      CALL HORLIN(TYPE,16,XMID,2850.5,0,2)
c      CALL VERLIN(TITY,-16,300.5,YMID,-12,0)
c      CALL HORLIN(TITX,16,XMID,320.5,0,-4)
c   40 CONTINUE
C SET UP FOR POLAR (CURVED EARTH) CONTOURS.
c      CALL POLAR(2)
      AMAX=ABS(EANG-SANG)/2
      AMIN=-AMAX
      RMINO=X3*6371.2
      RMAXO=X3*(6371.2+HMAX)
c      CALL PSTGRD(RMINO,AMIN,RMAXO,AMAX,2148.5,Y)
      ANGLE(1)=AMIN-3
      L=(EANG-SANG)/5+.5
c      CALL PLABEL(ANGLE,1)
c      CALL OGRID(0.,HMAX,L1,'F5.0)',2,SANG,EANG,L,'F5.0)',1,0)
C IF REQUESTED AND LEGAL, PLOT THE FIELD LINES.
c      IF(NLINES.LE.0.OR.IX.EQ.1.OR.IX.EQ.2.OR.IY.EQ.1) GO TO 7
c      DO 130 I=1,NLINES
c  130 CALL PLOT(FLINES(1,3,I),FLINES(1,IFL,I),2,' ')
C IF REQUESTED, PLOT SATELLITE OR F-PEAK POINTS.
c    7 IF(ISP.GT.0) CALL DATAPT(A2,LA2,80,1,'*')
C NOW CLEAR Z ARRAY, THEN FILL RECTANGULAR GRID.
      DO 140 I=IMIN,IMAX
      DO 140 J=JMIN,JMAX
  140 Z(I,J)=UNDE
      DO 150 I=1,LA
      J=A(I,1)+.5
      K=A(I,2)+.5
  150 Z(J,K)=A(I,3)
	do jv=1,j
	 write(11,*) (z(jv,kv),kv=1,k)
	enddo
C DUMP Z-ARRAY.
c      CALL ZDUMP(Z,80,80)
C CALCULATE END VALUES OF X COORDINATES AT START AND END ANGLES.
      SLOPE=(JMAX-JMIN)/(XCO(LXCO)-XCO(1))
      X2=JMIN-SLOPE*(XCO(1)-SANG)
      X4=JMAX+SLOPE*(EANG-XCO(LXCO))
      Y1=IMIN
      Y2=IMAX
C NOW DO ACTUAL CURVED EARTH CONTOURS, AND END THE PLOT PACKAGE.
c      CALL SCALE(Y1,Y2,X2,X4,0)
c      CALL LABELI(LBL)
c      CALL TRACER(Z,80,80)
c      CALL FRMADV
  200 continue
c  200 CALL ENDPLT
      RETURN
      END
