      program read_srb
c**********************************************************************
c
c function:  read SRB_SW_LW_MONTHLY files for a given month & year. 
c            Print sample values for a given gridbox.  This program 
c            assumes that it is being run in the directory that contains
c            the data files.  If not, then the format for the input 
c            filename must be modified (format 200).
c
c     *** Please see the README file for further details ***
c
c	region:	grid box (1-6596), 1 is at the South Pole
c	lat:	latitude index (1-72), 1 is the S. Pole
c	lon:	longitude index (1-144), this value depends on the latitude
c		index.  There are 3 at each Pole and 144 at the equator.
c	clat:	central latitude of the grid box (-90 - 90).
c	clon:	central longitude of the grid box (0 - 360).
c	cp:	cloud amount (percent)
c	wv:	total water vapor burden (kg/m**2)
c	ts:	surface temperature (K)
c	isp:	snow/ice amount (percent)
c	as:	surface albedo (dimensionless)
c	itoa:	insolation at the top of atmosphere (W/m**2)
c	iscs:	downward clear-sky shortwave flux at the surface (W/m**2)
c	swdwn:	downward all-sky shortwave flux (insolation) at the surface (W/m**2)
c	swnet:	net shortwave flux (absorbed) at the surface (W/m**2)
c	swcf:	shortwave cloud forcing at the surface (W/m**2)
c	lwcs:	clear-sky downward longwave flux at the surface (W/m**2)
c	lwdwn:	downward longwave flux at the surface (W/m**2)
c	lwnet:	net longwave flux at the surface (W/m**2)
c	lwcf:	longwave cloud forcing at the surface (W/m**2)
c	totnet:	total net (shortwave+longwave) flux at the surface (W/m**2)
c	totcf:	total cloud forcing (lwcf+swcf) at the surface (W/m**2)
c
c ---------------------------------------------------------------------
c This software has been tested on the following systems:
c 
c	Computer		Operating System
c	-------------------  	----------------
c	Sun Sparc		Solaris 2.6
c	SGI Origin 2000		IRIX 6.4
c	HP 9000/735		HP-UX 10.10
c	DEC Alpha		Digital UNIX 4.0A
c
c ---------------------------------------------------------------------
c
c  Contact: Langley DAAC User and Data Services Office 
c           NASA Langley Research Center 
c           Mail Stop 157D 
c           Hampton, VA 23681-2199 
c           Phone (757)864-8656   Fax (757)864-8807 
c           e-mail:  larc@eos.nasa.gov 
c           http://eosweb.larc.nasa.gov 
c
c**********************************************************************
      implicit none
c*====================================================================*c
      real lwdwn,lwnet,swdwn,swnet,
     &     totnet,swcf,lwcf,cp,wv,
     &     totcf,as,itoa,iscs,ts,
     &     lwcs,isp,clat,clon
c*====================================================================*c
      integer month,year,i,lat,lon,region,location
c*====================================================================*c
      character filename*65,charmon(12)*3
c*====================================================================*c
      data charmon/'Jan','Feb','Mar','Apr','May','Jun',
     &             'Jul','Aug','Sep','Oct','Nov','Dec'/
c*====================================================================*c

      print*,'Enter month (1-12) and year (1983 - 1991) of data' 
      print*,'     (EX. for Sept. 1988, ENTER 9 1988): '
      read*,month,year
      if (month.gt.12.or.month.lt.1)then
        print*,'MONTH specification is incorrect ',month
        stop
      endif
      if (year.gt.1991.or.year.lt.1983)then
        print*,'YEAR specification is incorrect ',year
        stop
      endif
      
      if((year.eq.1991.and.month.gt.6).or.(year.eq.1983.and.month.lt.7))
     &    then
        print*,'MONTH and YEAR specification is incorrect ',month,year
        stop
      endif
   
      print*,'Enter gridbox of interest (1-6596):' 
      read*,location
      if (location.gt.6596.or.location.lt.1)then
        print*,'GRIDBOX specification is incorrect ',location
        stop
      endif

      print*,'You want to read ',charmon(month),year,' and print',
     &' data for grid box ',location
 
c --- Add code to loop over specific month/years here

      write(filename,200)year,month
      open(10,file=filename,status='old',form='formatted')
      print*,'Granule name: ',filename
 

       do i=1,6596
         read(10,300)region,lat,lon,clat,clon,cp,wv,ts,isp,as,
     &     itoa,iscs,swdwn,swnet,swcf,lwcs,lwdwn,lwnet,lwcf,totnet,
     &     totcf

c --- Put your output statement here

         if(region.eq.location)then
            print 100,region,clat,clon
            print 103,cp,wv,ts,isp,as
	    print 101,iscs,swdwn,swnet,swcf   
            print 102,lwcs,lwdwn,lwnet,lwcf 
            print 104,itoa,totnet,totcf   
         endif

       enddo

100   format(/,'region = ',I6,/,'central latitude and longitude = ',
     & 2(f6.2,1x))
101   format('clear-sky shortwave flux = ',f7.2,/,
     & 'all-sky shortwave flux = ',f7.2,/,
     & 'net shortwave flux = ',f7.2,/,
     & 'shortwave cloud forcing= ',f7.2)
102   format('clear-sky longwave flux = ',f7.2,/,
     & 'all-sky longwave flux = ',f7.2,
     & 'net longwave flux = ',f7.2,/,
     & 'longwave cloud forcing= ',f7.2)
103   format('cloud percent = ',f7.2,/,
     & 'total water vapor burden = ',f7.2,/,
     & 'surface temperature = ',f7.2,/,
     & 'snow/ice percent = ',f7.2,
     & 'surface albedo = ',f7.2,)
104   format('top-of-atmosphere downward shortwave flux = ',f7.2,/,
     & 'total net flux = ',f7.2,/,
     & 'total cloud forcing= ',f7.2)
200   format('srb_sw_lw_',i4.4,i2.2)
300   format(i4,1x,i2,1x,i3,1x,2(f6.2,1x),4(f6.1,1x),12(f7.2,1x))
     
       stop
       end
