program main !*****************************************************************************80 ! !! MAIN is the main program for CITIES_PRB. ! ! Discussion: ! ! CITIES_PRB tests routines from the CITIES library. ! ! Modified: ! ! 11 February 2007 ! ! Author: ! ! John Burkardt ! implicit none call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'CITIES_PRB' write ( *, '(a)' ) ' FORTRAN90 version' write ( *, '(a)' ) ' Test routines in the CITIES library.' write ( *, '(a)' ) ' ' call test01 ( 'wg22_main.txt' ) call test02 ( 'usca312_main.txt' ) call test03 ( 'usca312_main.txt' ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'CITIES_PRB' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop end subroutine test01 ( file_main ) !*****************************************************************************80 ! !! TEST01 tests XY_TO_DIST. ! ! Discussion: ! ! Get the XY coordinates of a set of cities, and compute ! the city-to-city distance table. ! implicit none real ( kind = 8 ), allocatable, dimension ( :, : ) :: dist character ( len = 80 ) :: file_dist character ( len = * ) :: file_main character ( len = 80 ) :: file_xy integer n real ( kind = 8 ), allocatable, dimension ( :, : ) :: xy write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST01' write ( *, '(a)' ) ' Get the XY coordinates of a set of cities.' write ( *, '(a)' ) ' Compute the city-to-city distance table.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The main data set is "' // trim ( file_main ) // '"' call main_read_size ( file_main, n ) write ( *, '(a)' ) ' ' write ( *, '(a,i6)' ) ' The number of data items is ', n call main_read_xy ( file_main, file_xy ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The XY data set is "' // trim ( file_xy ) // '"' call s_rep_one ( file_main, 'main', 'dist', file_dist ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The distance data will be stored in the file "' & // trim ( file_dist ) // '"' allocate ( dist(1:n,1:n) ) allocate ( xy(1:n,1:2) ) call xy_read ( file_xy, n, xy ) call xy_print ( n, xy, ' The XY data:' ) call xy_to_dist ( n, xy, dist ) dist(1:n,1:n) = aint ( dist(1:n,1:n) ) call dist_write ( file_dist, n, dist ) deallocate ( dist ) deallocate ( xy ) return end subroutine test02 ( file_main ) !*****************************************************************************80 ! !! TEST02 tests MAIN_READ_SIZE, MAIN_READ_DMS, MAIN_READ_NAME. ! ! Discussion: ! ! Get the DMS coordinates of a set of cities, and compute ! the city-to-city distance table, using distances on a sphere. ! implicit none real ( kind = 8 ), allocatable, dimension ( :, : ) :: dist character ( len = 80 ) :: file_dist character ( len = 80 ) :: file_dms character ( len = * ) :: file_main integer, allocatable, dimension ( :, : ) :: lat_dms integer, allocatable, dimension ( :, : ) :: long_dms integer n write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST02' write ( *, '(a)' ) ' Get the DMS coordinates of a set of cities.' write ( *, '(a)' ) ' Compute the city-to-city distance table,' write ( *, '(a)' ) ' assuming the cities lie on a sphere (the earth).' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The main data set is "' // trim ( file_main ) // '"' call main_read_size ( file_main, n ) write ( *, '(a)' ) ' ' write ( *, '(a,i6)' ) ' The number of data items is ', n call main_read_dms ( file_main, file_dms ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The DMS data set is "' // trim ( file_dms ) // '"' call s_rep_one ( file_main, 'main', 'dist', file_dist ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The distance data will be stored in the file "' & // trim ( file_dist ) // '"' allocate ( dist(1:n,1:n) ) allocate ( lat_dms(1:4,1:n) ) allocate ( long_dms(1:4,1:n) ) call dms_read ( file_dms, n, lat_dms, long_dms ) call dms_print ( n, lat_dms, long_dms, ' The longitude/latitude data:' ) call dms_to_dist ( n, lat_dms, long_dms, dist ) dist(1:n,1:n) = aint ( dist(1:n,1:n) ) write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' Distance from Atlanta to Boston = ', dist(12,34) write ( *, '(a)' ) ' Road distance is 1037' write ( *, '(a,g14.6)' ) ' Distance from Boston to Chicago = ', dist(34,58) write ( *, '(a)' ) ' Road distance is 963' write ( *, '(a,g14.6)' ) ' Distance from Chicago to Atlanta = ', dist(58,12) write ( *, '(a)' ) ' Road distance is 674' call dist_write ( file_dist, n, dist ) deallocate ( dist ) deallocate ( lat_dms ) deallocate ( long_dms ) return end subroutine test03 ( file_main ) !*****************************************************************************80 ! !! TEST03 tests DMS_TO_XY. ! ! Discussion: ! ! Get the DMS coordinates of a set of cities, and compute ! the XY coordinates. ! implicit none character ( len = 80 ) :: file_dms character ( len = * ) :: file_main character ( len = 80 ) :: file_xy integer, allocatable, dimension ( :, : ) :: lat_dms integer, allocatable, dimension ( :, : ) :: long_dms integer n real ( kind = 8 ), allocatable, dimension ( :, : ) :: xy write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST03' write ( *, '(a)' ) ' DMS_TO_XY takes latitude and longitude' write ( *, '(a)' ) ' information, and assigns pseudo XY coordinates.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The main data set is "' // trim ( file_main ) // '"' call main_read_size ( file_main, n ) write ( *, '(a)' ) ' ' write ( *, '(a,i6)' ) ' The number of data items is ', n call main_read_dms ( file_main, file_dms ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The DMS data set is "' // trim ( file_dms ) // '"' call s_rep_one ( file_main, 'main', 'xy', file_xy ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The xy data will be stored in the file "' & // trim ( file_xy ) // '"' allocate ( lat_dms(1:4,1:n) ) allocate ( long_dms(1:4,1:n) ) allocate ( xy(1:n,1:2) ) call dms_read ( file_dms, n, lat_dms, long_dms ) call dms_print ( n, lat_dms, long_dms, ' The longitude/latidude data:' ) call dms_to_xy ( n, lat_dms, long_dms, xy ) call xy_print ( n, xy, ' The computed XY values:' ) call xy_write ( file_xy, n, xy ) deallocate ( xy ) deallocate ( lat_dms ) deallocate ( long_dms ) return end