       module fluidprops
         real, allocatable :: t(:),p(:)
         integer nd
c     t -  array containing temperatures
c     p -  array containing pressures
c     nd - number of temperature or pressure data values
c
       end module
c
       program proptest
       use fluidprops
       implicit none
       real tavg,tmax,tmin,pavg,pmin,pmax
c
c      Program to read in data on temperature and pressure
c      and print out the following:
c     tavg  -   average temperature
c     tmin  -   minimum temperature
c     tmax  -   maximum temperature
c     pavg  -   average pressure
c     pmin  -   minimum pressure
c     pmax  -   maximum pressure
c
c
c     Programmed by John Mahaffy   2/28/97
c
      call input
      call stats ( t,nd, tavg, tmin, tmax)
      call stats ( p,nd, pavg, pmin, pmax)
      call output( tavg,tmin,tmax,pavg,pmin,pmax)
       stop
       end
c*************************************************************************
       subroutine input
       use fluidprops
       implicit none
       logical lexist
       integer lines, filend, i
c
c      Check for the existance of the file "prop.data", if found
c      open it count the number of data pairs, allocate the array
c      space, and read the pressure and temperature data.
c
c      Definition of variables
c
c      lexist = logical variable for indicating the existance of "props.data"
c      lines = number of records in temperature data file 
c      filend = i/o variable which specifies status of the read
c
c      Check to see if the file "prop.data" exists:
c     (insert the necessary I/O statement to check existance and return
c      the answer in the variable "lexist")
c---------------------------------------------------------------------
       inquire (file='props.data',exist=lexist)
c---------------------------------------------------------------------
       if (.not.lexist) then
          print *,  'The file "props.data" is not present'
          stop
       endif
c
       open(11,file='props.data')
c
c      Counts lines to determine amount of memory to allocate
c      filend = i/o variable which specifies status of the read
c               command
c
       nd=-1
       filend=0
       do while(filend.ne.-1)
         read(11,*,iostat=filend)
         nd=nd+1
       end do 
       print  *, nd, ' Data pairs read'
c
c     Allocate array space for the temperature and pressure  data
c--------------------------------------------------------------------
      allocate (t(nd),p(nd))
c--------------------------------------------------------------------
c
c    Read the temperature, pressure pairs
c
         rewind(11)
       do i = 1,nd
         read(11,*) t(i), p(i)
       enddo
         close(11)
       return 
       end
c*************************************************************************
      subroutine output( tavg,tmin,tmax,pavg,pmin,pmax)
      implicit none
      real tavg,tmin,tmax,pavg,pmin,pmax
c
c     tavg  -   average temperature
c     tmin  -   minimum temperature
c     tmax  -   maximum temperature
c     pavg  -   average pressure
c     pmin  -   minimum pressure
c     pmax  -   maximum pressure
c
      write(*,2000) tavg, tmin, tmax
 2000 format ( ' Average Temperature = ',f7.1,/
     & ' Minimum Temperature = ', f7.1,/
     & ' Maximum Temperature = ', f7.1)
c
      write(*,2001) pavg, pmin, pmax
 2001 format ( ' Average Pressure = ',1p,e12.4,/
     & ' Minimum Pressure = ', e12.4,/
     & ' Maximum Pressure = ', e12.4)
      return
      end
c
c    Create the subroutine below to obtain the average, minimum, and
c    maximum from a given array
c------------------------------------------------------------------------
      subroutine stats ( x,nx, xavg, xmin, xmax)
      implicit none
      integer nx
      real x(nx),xavg,xmin,xmax
      xavg=sum(x(1:nx))/nx
      xmin=minval(x(1:nx))
      xmax=maxval(x(1:nx))
      return
      end
