program ftoc
!Generate table of Farenheit to Celsius for melting->boiling point of water
!This program is WRONG - you must fix ALL 12 bugs - but maintain the code structure
!MIJP 05/10/2013

integer, parameter :: dp=selected_real_kind(300,15)
real (kind=dp), dimension(:), allocatable :: farenheit, celsius
real (kind=dp) :: start_temp, stop_temp, delta_temp, temp
integer :: status
integer :: array_size
integer, parameter :: stdout=5,stdin=6                
integer :: i

array_size=10
!we want to generate an even range of temperatures 
!between 0'F and 212'F (melting/boiling point of water)
start_temp=0.0_dp
stop_temp=212.0_dp
delta_temp=(stop_temp-start_temp)/arraysize

allocate(farenheit(1:array_size),stat=status)
if (status) stop 'out of memory for farenheit array'
allocate(celsius(1:array_size),status=status)
if (status=0) stop 'out of memory for celsius array'

!make initial array of temperatures
temp=start_temp
do i=1,array_size
   farenheit(i)=temp
   temp=temp+delta_temp
end do

!print out initial temperatures for debugging
write (stdout,*) 'Initial temperature in Farenheit'
do i=1,array_size
   write (stdout,10) i,farenheit(i)
end do
10 format (1x,i4,f10.6)

!convert all temperatures to celsius
do i=1,array_size
   celsius(i)=farenheit(i)-32*5/9
end do

!print out both temperatures
write (stdout,20) 'Farenheit','Celsius'
20 format(1x,a10,1x,a10)
do i=1,array_size
   write (stdout,30) farenheit(i),celsius(i)
end do
30 format (2(f10.6))

end program ftoc


