program main !*****************************************************************************80 ! !! MAIN is the main program for APPORTIONMENT_PRB. ! ! Discussion: ! ! APPORTIONMENT_PRB calls the routines in the APPORTIONMENT library. ! ! Modified: ! ! 25 April 2007 ! ! Author: ! ! John Burkardt ! implicit none call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'APPORTIONMENT_PRB' write ( *, '(a)' ) ' FORTRAN90 version' write ( *, '(a)' ) ' Test the routines in APPORTIONMENT.' call test01 call test02 call test03 call test04 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'APPORTIONMENT_PRB' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop end subroutine test01 !*****************************************************************************80 ! !! TEST01 tests STATE_NUM_YEAR and rep_NUM_YEAR. ! ! Modified: ! ! 21 April 2007 ! ! Author: ! ! John Burkardt ! implicit none integer rep_num integer state_num integer year write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST01' write ( *, '(a)' ) ' STATE_NUM_YEAR returns the number of states in' write ( *, '(a)' ) ' the union at the end of a given year.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' rep_NUM_YEAR returns the number of reps in' write ( *, '(a)' ) ' the House of Representatives (based only on the' write ( *, '(a)' ) ' decennial census.)' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Year States reps' write ( *, '(a)' ) ' ' do year = 1790, 2000, 10 call state_num_year ( year, state_num ) call rep_num_year ( year, rep_num ) write ( *, '(2x,i4,6x,i2,4x,i3)' ) year, state_num, rep_num end do return end subroutine test02 !*****************************************************************************80 ! !! TEST02 tests STATE_STATEHOOD. ! ! Modified: ! ! 24 April 2007 ! ! Author: ! ! John Burkardt ! implicit none integer d integer m character ( len = 9 ) month integer state character ( len = 20 ) state_name integer y write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST02' write ( *, '(a)' ) ' STATE_STATEHOOD returns the statehood date of a state.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' # State Name Statehood Date' write ( *, '(a)' ) ' ' do state = 1, 51 call statehood_state ( state, y, m, d ) call i4_to_month_name ( m, month ) write ( *, '(2x,i2,2x,a20,2x,i2,2x,a9,2x,i4)' ) & state, state_name(state), d, month, y end do return end subroutine test03 !*****************************************************************************80 ! !! TEST03 tests APPORTION_HAMILTON. ! ! Modified: ! ! 28 April 2007 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: state_num = 51 real f1 real f2 integer rep_num integer state character ( len = 2 ) state_id integer state_pop(state_num) integer state_rep(state_num) character ( len = 12 ) string integer us_pop integer year write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST03' write ( *, '(a)' ) ' Get the historic representation values.' ! ! Pick a year. ! year = 1960 ! ! What were the state populations in the last decennial census? ! call state_pop_year ( year, state_pop ) ! ! What were the state representations based on the last decennial census? ! call state_rep_year ( year, state_rep ) call rep_num_year ( year, rep_num ) write ( *, '(a)' ) ' ' write ( *, '(a,i4)' ) ' Year: ', year write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' ID Population Rep Pop% Rep%' write ( *, '(a)' ) ' ' us_pop = sum ( state_pop(1:state_num) ) do state = 1, state_num f1 = real ( 100.0 * state_pop(state) ) / real ( us_pop ) f2 = real ( 100.0 * state_rep(state) ) / real ( rep_num ) call i4_to_s_right_comma ( state_pop(state), string ) write ( *, '(2x,a2,2x,a12,2x,i3,2x,f8.4,2x,f8.4)' ) & state_id (state), string, state_rep(state), f1, f2 end do write ( *, '(a)' ) ' -- ------------ --- -------- --------' call i4_to_s_right_comma ( us_pop, string ) write ( *, '(2x,a2,2x,a12,2x,i3,2x,f8.4,2x,f8.4)' ) & 'US', string, rep_num, 100.0, 100.0 return end subroutine test04 !*****************************************************************************80 ! !! TEST04 tests APPORTION_HAMILTON. ! ! Modified: ! ! 28 April 2007 ! ! Author: ! ! John Burkardt ! implicit none real f1 real f2 integer indx(51) integer rep_num integer state character ( len = 2 ) state_id integer state_num integer state_pop(51) integer, allocatable, dimension ( : ) :: state_rep character ( len = 12 ) string integer us_pop integer year write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST04' write ( *, '(a)' ) ' APPORTION_HAMILTON uses Hamilton''s method to' write ( *, '(a)' ) ' apportion reps in the House of Representatives.' ! ! Pick a year. ! year = 1960 ! ! What were the state populations in the last decennial census? ! call state_pop_year ( year, state_pop ) ! ! Make an index vector. ! call i4vec_nonzero_first ( 51, state_pop, state_num, indx ) ! ! "Squeeze" the population vector. ! state_pop(1:state_num) = state_pop(indx(1:state_num)) allocate ( state_rep(1:state_num) ) call rep_num_year ( year, rep_num ) call apportion_hamilton ( state_num, state_pop, rep_num, state_rep ) write ( *, '(a)' ) ' ' write ( *, '(a,i4)' ) ' Year: ', year write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' ID Population Rep Pop% Rep%' write ( *, '(a)' ) ' ' us_pop = sum ( state_pop(1:state_num) ) ! ! I HAVE GOT THIS INDEXING MESSED UP HERE, CLEARLY. ! ANOTHER ARGUMENT FOR REDOING THIS RIGHT. ! do state = 1, state_num f1 = real ( 100.0 * state_pop(state) ) / real ( us_pop ) f2 = real ( 100.0 * state_rep(state) ) / real ( rep_num ) call i4_to_s_right_comma ( state_pop(state), string ) write ( *, '(2x,a2,2x,a12,2x,i3,2x,f8.4,2x,f8.4)' ) & state_id ( indx(state) ), string, state_rep(state), f1, f2 end do write ( *, '(a)' ) ' -- ------------ --- -------- --------' call i4_to_s_right_comma ( us_pop, string ) write ( *, '(2x,a2,2x,a12,2x,i3,2x,f8.4,2x,f8.4)' ) & 'US', string, rep_num, 100.0, 100.0 deallocate ( state_rep ) return end