      program read_ampr_data
c=========================  Begin Comments  ========================c
c
c Function:  Open and read FIRE_ACE_AMPR data files. 
c            Print brightness temperature and latitude of the 25th
c            element of every 500th scan.
c
c     *** Please see the README file for further details ***
c
c=========================  Parameter Definitions  =================c
c
c  iscan	Scan number (1-maximum number of records)
c  year		Year (1998)
c  julian_day	Julian day of year (1-366)
c  hour		Hour (0-23)
c  minute	Minute (0-59)	
c  second	Second (0-59)
c  igbp		GPS validity code (1=Good)
c  gps_alt 	GPS Altitude of the ER2 (meters)
c  gps_lat 	GPS Latitude of the ER2 (degrees)
c  gps_lon  	GPS Longitude of the ER2 (degrees)
c  er2_head  	Heading of the ER2 (0,360=North, clockwise)
c  er2_pitch    Pitch of the ER2 (+up)
c  er2_roll     Roll of the ER2 (+right)
c  er2_grd	Ground Speed of the ER2 (m/s)
c  er2_air	Air Speed of the ER2 (m/s)
c  er2_balt	Barometric Altitude of the ER2 (m)
c  ins_lat	INS Latitude (degrees)
c  ins_lon	INS Longitude (degrees)
c  rms_noise(4)	RMS noise for each channel (10.7, 19.35, 37.1, 85.5 GHz)
c  tbs10(50)	Brightness Temperature at 10.7 Ghz for each pixel
c  tbs19(50)	Brightness Temperature at 19.35 Ghz for each pixel
c  tbs37(50)	Brightness Temperature at 37.1 Ghz for each pixel
c  tbs85(50)	Brightness Temperature at 85.5 Ghz for each pixel
c  pix_lat(50)	Latitude for each pixel
c  pix_lon(50) 	Longitude for each pixel
c  maxrec	Maximum number of records in a file
c
c=========================  End Definitions  =======================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
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=========================  End Comments  ==========================c
c=========================  Begin Data Declarations  ===============c
      implicit   real*8 (a-h,o-z), integer*4 (i-n)

      parameter  (maxrec=10000)
      
      logical    exist

      character  file_name*80

      integer*4  iscan, igps
      integer*4  year, julian_day, hour, minute, second
      
      real*8     rms_noise(4), tbs10(50),
     &           tbs19(50), tbs37(50), tbs85(50),
     &           pix_lat(50), pix_lon(50)
      real*8     gps_alt, gps_lat, gps_lon, er2_head, er2_pitch,
     &           er2_roll, er2_grd, er2_air, er2_balt, ins_lat, 
     &           ins_lon 
c=========================  End Data Declarations  ==================c
c=========================  Begin Processing  =======================c


c === Obtain input filename.
      print*,'Enter the AMPR file name'
      read(5,1101) file_name
      print*

c === Check for input file existance.
      inquire (file=file_name, exist=exist)
      if (.not. exist) then
         print*
         print*,'   Invalid input file name: ',file_name
         print*
         stop ' '
      endif


c === Open the data file.
      open (11, file=file_name, form='formatted', readonly)

c === Read all the data from the file.    
      do i=1,maxrec
         
         read (11, 1100, err=101, end=101)  
     &         iscan, year, julian_day, hour, minute, second, igps,
     &         gps_alt, gps_lat, gps_lon, er2_head, er2_pitch,
     &         er2_roll, er2_grd, er2_air, er2_balt, ins_lat,ins_lon,
     &         (rms_noise(j), j=1,4),
     &         (tbs10(j), j=1,50), (tbs19(j), j=1,50),
     &         (tbs37(j), j=1,50), (tbs85(j), j=1,50),
     &         (pix_lat(j), j=1,50), (pix_lon(j), j=1,50)
     
         
c === Print parameters for every 500th scan to the screen 
         if (mod(i,500) .eq. 0)  then

          write (6, 6001) iscan, year, julian_day, hour, minute, second,
     &            tbs10(25), tbs19(25), tbs37(25),
     &            tbs85(25), pix_lat(25), pix_lon(25)
         endif

      enddo


  101 continue

      nscans = i - 1
      close (11)
      
      print*
      print*,'All data read from file ', file_name
      print*
      print*,'Total number of Scans ...',nscans
      print*


c === Input/Output format statements
 1100 format ( 6i8, i8,f10.2,2f14.6,5f12.4,f10.2,2f14.6,
     &         4f12.4, 200f12.4, 100f14.6)
 1101 format ( a80)
 6001 format ('Scan: ',i4,2x,'Date: ',i4,i3,2x,
     &        'Time(UTC): ',i2,':',i2,':',i2,3x,'Tb10: ',f6.2,2x,
     &        'Tb19: ',f6.2,2x,'Tb37: ',f6.2,2x,'Tb85: ',f6.2,3x,
     &        'Lat: ',f9.5,2x,'Lon: ',f10.5)


      stop
      end
c=========================  End of source code  =======================c
