	PROGRAM TCONV

	!This is a program to convert Oklahoma Mesonet
	!temperature observations from Celsius to Fahrenheit
	!in an effort to demonstrate Fortran functions.
	!Christopher Godfrey				25 March 2010

	IMPLICIT NONE

	INTEGER, PARAMETER :: nobs=10
	REAL :: tair(nobs),tmpf(nobs)
	REAL :: ctof,addit
	INTEGER :: i,j
	CHARACTER :: time(nobs)*4

	open(unit=10,file="20020803nrmn.t05",status='old')

	read(10,'(///)')	!Read header

	do i=1,nobs		!Read and write just the first nobs data values	
	  read(10,100)time(i),tair(i)
	  tmpf(i)=ctof(tair(i))
	enddo

	write(*,*)"TIME  T (C) T (F)"
	do i=1,nobs
	  write(*,200)time(i),tair(i),tmpf(i)
	enddo

	!Functions can take entire arrays and/or multiple arguments
	write(*,*)"The sum of tair is: ",addit(tair,nobs)
	write(*,*)"The sum of tmpf is: ",addit(tmpf,nobs)

100	format(15x,a4,8x,f6.1)
200	format(1x,a4,2(2x,f4.1))

	STOP
	END

	REAL FUNCTION ctof(x)
	!This is a function to convert a temperature in degrees Celsius
	!to degrees Fahrenheit.

	REAL :: x

	ctof=x*(9./5.)+32.0

	RETURN
	END

	REAL FUNCTION addit(x,nobs)
	!Let's add up the contents of an array.

	INTEGER :: nobs
	REAL :: x(nobs)	!A 1-D array
	REAL :: sum

	sum=0
	do i=1,nobs
	  sum=sum+x(i)
	enddo

	addit=sum

	RETURN
	END
