I don't know how to sort using a compiled computer syntax and wanted to
reverse this shortcoming by implementing the sort in §10 MR&C. I think
this is an example of fair use: I bought the guys' book, typed in
something close to its content as I watched the olympics and managed on my
girlfriend's laptop, and posted it on the net to work out the kinks.
I think that studying fortran and watching women's volleyball and handball
are tasks that improve the quality of the other. I must say I developed I
little crush on the handball hungarian sharpshooter Görnic and wish them
luck if they play the french tomorrow but wish for penalty cards if they
play the russians. Please punish the aggressors.
module sort
implicit none
private
public :: selection_sort
integer, parameter :: string_length = 30
type, public :: address
character(len = string_length) :: name, &
street, town, state*2
integer :: zip_code
end type address
contains
recursive subroutine selection_sort (array_arg)
type (address), dimension(:), intent (inout) &
:: array_arg
integer :: current_size
integer :: big
current_size = size (array_arg)
if (current_size > 0) then
big = maxloc(array_arg(:)%%zip_code, dim=1)
call swap (big, current_size)
call selection_sort (array_arg(1: current_size -1))
end if
contains
subroutine swap(i,j)
integer, intent (in) :: i,j
type (address) :: temp
temp = array_arg(i)
array_arg(i) = array_arg(j)
array_arg(j) = temp
end subroutine swap
end subroutine selection_sort
end module sort
This is the exact sort in MR&C.
program zippy
use sort
implicit none
integer, parameter :: array_size = 100
type (address), dimension (array_size) :: data_array
integer :: i,n, ios
open(2, file='addresses.txt', iostat=ios, err=99)
open(3, file='output.txt')
do i = 1, array_size
read (2, '(/a/a/a2,i8)',end=10) data_array(i)
write (3, '(/a/a/a/a2,i8)') data_array(i)
end do
10 n = i - 1
call selection_sort (data_array(1:n))
write(3, '(//a)') 'after sorting'
do i = 1, n
write (3, '(/a/a/a/a2,i8)') data_array(i)
end do
99 write(3,*) "99", ios
end program zippy
This is a modified caller that doesn't seem to work yet. Addresses.txt is
exactly:
T. Boone Pickens
350 Swiftboat Lane
Houston, TX 45536
Ev Bayh
1016 Humdity Bath
Indianapolis, IN 47250
Cindy McCain
1000 Richie Rich
Scottsdale, AZ 85250
Diane Feinstein
250 Harvey Milk Circle
San Fransisco, CA 96580
Tim Pawlenty
500 Olson way
St. Paul, MN 56674
Donald Trump
100 Trump Plaza
New York, NY 10080
Output.txt is:
after sorting
99 0
I'm looking for help to diagnose what's not clicking here yet. There's one
datum that I think is salient: When I run it, windows creates a second
file called addresses.txt that has nothing in it.
Thanks and cheers,
--
When a new source of taxation is found it never means, in practice, that
the old source is abandoned. It merely means that the politicians have two
ways of milking the taxpayer where they had one before. 8
H. L. Mencken