      program sample_readpathP_f

c This is a sample fortran program for reading pathP data sets
c This program unpacks the HDF Scientific Data Sets (SDS) from a TOVS PathP
c data file. Each of the SDS elements are transfered to individual files
c
c Each files unpacked using this utility contain
c
      implicit none

      integer*4      XGRDSZ,YGRDSZ, freadpathP
      character*256   hdf_file
      parameter(XGRDSZ=67,YGRDSZ=67)

c Meta Data variables

      character*256   project
      character*256   dataset_name
      character*256   source_name
      character*256   processing_level
      character*256   reference_date
      character*256   start_date
      character*256   stop_date
      character*256   position_type
      character*256   grid_type
      character*256   grid_name
      character*256   projection

      real*4          latitude(4)
      real*4          longitude(4)
      character*256   Temporal_Res
      character*256   Spatial_X_Res
      character*256   Spatial_Y_Res

c Scientific Data set variables

      real*4         lat_grid(XGRDSZ,YGRDSZ)
      real*4         lon_grid(XGRDSZ,YGRDSZ)
      real*4         temp(XGRDSZ,YGRDSZ,9)
      real*4         wvapor(XGRDSZ,YGRDSZ,5)
      real*4         sktemp(XGRDSZ,YGRDSZ)
      real*4         fcld(XGRDSZ,YGRDSZ)
      real*4         clpress(XGRDSZ,YGRDSZ)
      real*4         cltemp(XGRDSZ,YGRDSZ)
      real*4         zangle(XGRDSZ,YGRDSZ)
      real*4         emiss(XGRDSZ,YGRDSZ)
      real*4         pblstrat(XGRDSZ,YGRDSZ)
      real*4         cg(XGRDSZ,YGRDSZ)
      real*4         alpha(XGRDSZ,YGRDSZ)


      real*4         iiireject(XGRDSZ,YGRDSZ)
      real*4         obs(XGRDSZ,YGRDSZ)

      real*4         temp_sd(XGRDSZ,YGRDSZ,9)
      real*4         wvapor_sd(XGRDSZ,YGRDSZ,5)
      real*4         sktemp_sd(XGRDSZ,YGRDSZ)
      real*4         fcld_sd(XGRDSZ,YGRDSZ)
      real*4         clpress_sd(XGRDSZ,YGRDSZ)
      real*4         cltemp_sd(XGRDSZ,YGRDSZ)
      real*4         zangle_sd(XGRDSZ,YGRDSZ)
      real*4         emiss_sd(XGRDSZ,YGRDSZ)
      real*4         pblstrat_sd(XGRDSZ,YGRDSZ)
      real*4         cg_sd(XGRDSZ,YGRDSZ)
      real*4         alpha_sd(XGRDSZ,YGRDSZ)

      integer*4     ret, RSIZE

      hdf_file ="sample.hdf"

C     On SunOS and HP-UX fortran, record lengths for unformatted files
c     are specified in bytes. Other machines may require you
c     to specifiy in longwords. 

C     SunOS and HP-UX version. 

      RSIZE = XGRDSZ * YGRDSZ * 4

C     SGI (?)  and DEC (?) 32bit and 64bit may be different ?????

c      RSIZE = XGRDSZ * YGRDSZ

C     PC's ? 

      ret =  freadpathP(hdf_file,project,dataset_name,source_name,
     &                    processing_level,reference_date,start_date,
     &                    stop_date,position_type,grid_type,grid_name,
     &                    projection,latitude,longitude,
     &                   Temporal_Res,Spatial_X_Res,
     &			 Spatial_Y_Res,lat_grid,lon_grid,temp,
     &	         	 wvapor,sktemp,fcld,clpress,cltemp,zangle,emiss,
     &	 		 pblstrat,Cg,alpha,IIIreject,obs,temp_sd,
     &	         	 wvapor_sd,sktemp_sd,fcld_sd,clpress_sd,cltemp_sd,
     &                   zangle_sd,emiss_sd,pblstrat_sd,Cg_sd,alpha_sd)


	print *, 'Latitudes  ',latitude
	print *, 'Longitudes ',longitude

c
c The TOVS HDF SDS files do not contain the latitude and longitude
c file information; this information is stored in external HDF files
c
	open(10,file='latgrid.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')
c
	write(10,rec=1)lat_grid
	close(10)
c
	open(10,file='longrid.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')
c
	write(10,rec=1)lon_grid
	close(10)
c

 	open(10,file='temp.ftst',recl=RSIZE*9,access='direct',
     &       form='unformatted')

	write(10,rec=1)temp
	close(10)

 	open(10,file='wvapor.ftst',recl=RSIZE*5,access='direct',
     &       form='unformatted')

	write(10,rec=1)wvapor
	close(10)

 	open(10,file='sktemp.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)sktemp
	close(10)

 	open(10,file='fcld.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)fcld
	close(10)

	open(10,file='clpress.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)clpress
	close(10)

 	open(10,file='cltemp.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)cltemp
	close(10)

 	open(10,file='zangle.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)zangle
	close(10)

 	open(10,file='emiss.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)emiss
	close(10)

 	open(10,file='pblstrat.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)pblstrat
	close(10)

 	open(10,file='Cg.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)Cg
	close(10)

 	open(10,file='alpha.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1) alpha
	close(10)

 	open(10,file='IIIreject.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)IIIreject
	close(10)

 	open(10,file='obs.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)obs
	close(10)

 	open(10,file='sdtemp.ftst',recl=RSIZE*9,access='direct',
     &       form='unformatted')

	write(10,rec=1)temp_sd
	close(10)

 	open(10,file='sdwvapor.ftst',recl=RSIZE*5,access='direct',
     &       form='unformatted')

	write(10,rec=1)wvapor_sd
	close(10)

 	open(10,file='sdsktemp.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)sktemp_sd
	close(10)

 	open(10,file='sdfcld.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)fcld_sd
	close(10)

	open(10,file='sdclpress.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)clpress_sd
	close(10)

 	open(10,file='sdcltemp.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)cltemp_sd
	close(10)

 	open(10,file='sdzangle.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)zangle_sd
	close(10)

 	open(10,file='sdemiss.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)emiss_sd
	close(10)

 	open(10,file='sdpblstrat.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)pblstrat_sd
	close(10)

 	open(10,file='sdCg.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1)Cg_sd
	close(10)

 	open(10,file='sdalpha.ftst',recl=RSIZE,access='direct',
     &       form='unformatted')

	write(10,rec=1) alpha_sd
	close(10)

      end





















