program main !*****************************************************************************80 ! !! sort_rc_test() tests sort_rc(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 05 March 2015 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'sort_rc_test():' write ( *, '(a)' ) ' Fortran90 version' write ( *, '(a)' ) ' Test sort_rc().' call sort_rc_test ( ) call sort_safe_rc_test ( ) ! ! Terminate. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'sort_rc_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) stop 0 end subroutine sort_rc_test ( ) !*****************************************************************************80 ! !! SORT_RC_TEST tests SORT_RC. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 11 October 2006 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: n = 20 integer a(n) integer i integer i4_hi integer i4_lo integer indx integer isgn integer j integer k write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'SORT_RC_TEST()' write ( *, '(a)' ) ' SORT_RC() sorts objects externally.' write ( *, '(a)' ) ' This function relies on the use of persistent' write ( *, '(a)' ) ' data stored internally.' ! ! Generate some data to sort. ! i4_lo = 1 i4_hi = n call i4vec_uniform_ab ( n, i4_lo, i4_hi, a ) call i4vec_print ( n, a, ' Unsorted array:' ) ! ! Sort the data. ! indx = 0 do call sort_rc ( n, indx, i, j, isgn ) if ( indx < 0 ) then isgn = 1 if ( a(i) <= a(j) ) then isgn = -1 end if else if ( 0 < indx ) then k = a(i) a(i) = a(j) a(j) = k else exit end if end do ! ! Display the sorted data. ! call i4vec_print ( n, a, ' Sorted array:' ) return end subroutine sort_safe_rc_test ( ) !*****************************************************************************80 ! !! SORT_SAFE_RC_TEST tests SORT_SAFE_RC. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 05 March 2015 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: n = 20 integer a(n) integer i integer i_save integer i4_hi integer i4_lo integer indx integer isgn integer j integer j_save integer k integer k_save integer l_save integer n_save write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'SORT_SAFE_RC_TEST' write ( *, '(a)' ) ' SORT_SAFE_RC sorts objects externally.' write ( *, '(a)' ) ' This version of the algorithm does not rely on' write ( *, '(a)' ) ' internally saved or "persistent" or "static" memory.' ! ! Generate some data to sort. ! i4_lo = 1 i4_hi = n call i4vec_uniform_ab ( n, i4_lo, i4_hi, a ) call i4vec_print ( n, a, ' Unsorted array:' ) ! ! Sort the data. ! indx = 0 do call sort_safe_rc ( n, indx, i, j, isgn, & i_save, j_save, k_save, l_save, n_save ) if ( indx < 0 ) then isgn = 1 if ( a(i) <= a(j) ) then isgn = -1 end if else if ( 0 < indx ) then k = a(i) a(i) = a(j) a(j) = k else exit end if end do ! ! Display the sorted data. ! call i4vec_print ( n, a, ' Sorted array:' ) return end subroutine timestamp ( ) !*****************************************************************************80 ! !! timestamp() prints the current YMDHMS date as a time stamp. ! ! Example: ! ! 31 May 2001 9:45:54.872 AM ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 18 May 2013 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! None ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) character ( len = 8 ) ampm integer d integer h integer m integer mm character ( len = 9 ), parameter, dimension(12) :: month = (/ & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' /) integer n integer s integer values(8) integer y call date_and_time ( values = values ) y = values(1) m = values(2) d = values(3) h = values(5) n = values(6) s = values(7) mm = values(8) if ( h < 12 ) then ampm = 'AM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h < 12 ) then ampm = 'PM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Midnight' else ampm = 'AM' end if end if end if write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) & d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm ) return end