c      OPTIONS /EXTEND_SOURCE
C*********************************************************************
      PROGRAM sbuvII_ozone
C*********************************************************************
C VARIABLES SEND FROM THE nmcgi.dat file in current directory
C
      CHARACTER*1  hem
      CHARACTER*11 ddate
      character*5  hemname
      character*20 dtypename
      REAL*4       min_val, max_val
      real bw(3,2)
      CHARACTER*80 df_name
      INTEGER*4    IASF(13)
      REAL*4       ARRAY(65,65), NXTARRAY(65,65), MTEMP(65,65)
      REAL*4	   inp(10)
C
      INTEGER*4    llat, i_unit, ISL, IS2, IYR, IMN, IDY, IHR,
     *             IGRD
      CHARACTER*1  ONEBYT
      CHARACTER*3  USRQ11, USRQ12 
      CHARACTER*4  FILLER(4134),  USERCOM(20), PNAME, FIL
      CHARACTER*6  RECFM, NUMREC
      CHARACTER*7  MAXLAT, MINLAT, MAXLON, MINLON
      CHARACTER*8  SFDU2, SFDU4, CORRDAT, GTIME, 
     &             MAXALTK, MINALTK, MAXALTP, MINALTP 
      CHARACTER*12 FILEID1, FILEID2, SFDU1, SFDU3, 
     &             CORRDAT1, CORRDAT2, CORRDAT3, CORRDAT4, 
     &             INSTYP, OBSSTN
      CHARACTER*15 SFDU5, SFDU6, Gddate
      CHARACTER*18 SFDU7, SFDU8
      CHARACTER*20 UARSPI, CORRM
      CHARACTER*23 TIME_VALUE, GSTOP
      character*2  dmpt, dmpz
      data dmpt /'  '/,dmpz /'  '/
	data IASF /13*1/
	data bw /0., 0., 0., 1., 1., 1. /
C---------------------------------------------------------------------
C
C===============================================================
C...OPEN GKS
C===============================================================
	call OPNGKS
	i_unit = 11
        open ( i_unit, file='uv_plot.dat', status = 'old',
     >         access='sequential', err=103)    
	read (i_unit,'(A20)', err = 104)   dtypename 	! (UV Index)
	read (i_unit,'(A1)', err = 104)   hem 		! (N/S)
        read (i_unit,'(A11)', err = 104)   ddate 	! 06-jul-94 format
        read (i_unit,'(A80)', err = 104)  df_name       ! full path 2 file
	close(i_unit)
C
        IF (hem .EQ. 'N') THEN
	   hemname = 'North'
           IHEM =27
        ELSE if (hem .EQ. 'S') then
	   hemname = 'South'
           IHEM =28
	ENDIF

        call GSASF(IASF) ! GKS aspect source flags -> 'INDIVIDUAL'
        call GSFAIS(1)   !..Force Solid Fill
cccc 	call gscr (1,2, bw(1,2), bw(2,2), bw(3,2)) ! 2:white
        call GSCLIP(0)	!..Set clipping OFF
C
C  OPEN THE dataset file TO read
C
	i_unit = 11
        OPEN ( i_unit, file=df_name, STATUS='OLD',  ERR=101)    
	j=1
	k=1
	iflag = 0
	llat = 0
	do i = 1, 422
	   READ(i_unit, 554, err=100) inp
	   if (iflag .eq. 0) then
	      iflag = 1
	      llat = inp(1)
	      inp(1) = -1.
           endif
	   do in=1,10
	      array (j,k) = inp(in)
	      k = k + 1
	      if (k.gt.65) then
		 k = 1
		 j = j + 1
	      endif
	   enddo
 554	   format (10f8.4)
 555	   format (f8.3)
c	   write (6, 554) inp
	enddo
	READ(i_unit, 556, err=100) array(j,k),array(j,k+1),
     &      array(j,k+2),array(j,k+3),array(j,k+4)
 556	format (5f8.4)
c	write(6, 556) array(j,k),array(j,k+1),
c     &      array(j,k+2),array(j,k+3),array(j,k+4)
C
	close (i_unit)
C
      	max_val = -9999.
	min_val = 9999.
        DO J = 1, 65
           DO I = 1, 65
              IF (ARRAY(I,J).EQ.-1.0) ARRAY(I,J) = -9999.
              RVAL = ARRAY(I,J)
              IF (RVAL.GT.max_val) then
		 max_val = RVAL
	      else IF (RVAL.LT.min_val) then
	         min_val = RVAL
	      endif
           enddo	! i loop
        enddo	! j loop
 
        i = int (min_val)
        j = int (max_val)
        min_val = i
        max_val = j
c     write (6, '(f8.1,f8.1)') max_val, min_val
C
        call POLBW( dtypename, hem, ddate, ARRAY, llat,
     &            min_val,max_val)
	goto 999
C
C IF IFOUND .EQ. 0 THEN SPECIFIED LEVEL HAS NOT BEEN FOUND IN THE
C DATASET.  RETURN A MESSAGE TO THE USER OR WHATEVER YOU WOULD LIKE 
C TO DO..  IT IS POSSIBLE THAT WE MIGHT ME MISSING COUPLE OF LEVELS
C IN THE DATASET.  OR WE MIGHT HAVE DUPLICATE LEVELS!
C
  100 	write (6,995) df_name
  995	format (1X,'??? Error reading data file ', a)
	go to 998
  101 	write (6,996) df_name
  996	format (1X,'??? Error opening file ', a )
	go to 998
  102 	write (6,997) plevel, df_name
  997	format (1x, '??? Pressure Level',f6.0,
     *  'not found in the dataset ', a, /)
      	go to 998
  103 	write (6,500)
  500   format ('??? File not found - uv_plot.dat')
	go to 999
  104 	write (6,501)
  501   format (' ??? Error occured while reading file uv_plot.dat')
	go to 998
C
 998	close (i_unit)
	call CLSGKS
 999	continue
c	stop
      END

