program where_test ! !*********************************************************************** ! !! WHERE_TEST tests the F90 WHERE statement. ! ! ! Modified: ! ! 21 February 2001 ! ! Author: ! ! John Burkardt ! implicit none ! integer, parameter :: m = 10 integer, parameter :: n = 10 real, dimension(m,n) :: a real ahi real alo ! call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'WHERE_TEST' write ( *, '(a)' ) ' Demonstrate the use of the F90 WHERE statement.' write ( *, '(a)' ) ' ' write ( *, '(a,i6,i6)' ) ' The matrix is of dimension : ', m, n write ( *, '(a)' ) ' In the printout, no more than 5 rows and columns ' write ( *, '(a)' ) ' will be shown.' alo = - 3.0E+00 ahi = 3.0E+00 call rmat_random ( m, m, n, a, alo, ahi ) a = nint ( a ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Initial matrix A:' call rmat_print_some ( m, n, a ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Where A nonzero, A = 2 / A:' where ( a /= 0.0E+00 ) a = 2.0E+00 / a end where call rmat_print_some ( m, n, a ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Where A positive, A = Sqrt ( A ),' write ( *, '(a)' ) ' Elsewhere A = - A**2.' where ( a > 0.0E+00 ) a = sqrt ( a ) elsewhere a = - a**2 end where call rmat_print_some ( m, n, a ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Where |A| <= 1, A = arcsin ( A ):' where ( abs ( a ) <= 1.0E+00 ) a = asin ( a ) end where call rmat_print_some ( m, n, a ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'WHERE_TEST:' write ( *, '(a)' ) ' Normal end of execution.' stop end subroutine rmat_print_some ( m, n, a ) ! !*********************************************************************** ! !! RMAT_PRINT prints some of a real matrix. ! ! ! Modified: ! ! 09 February 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer M, N, the dimensions of the matrix. ! ! Input, real A(M,N), the matrix to be printed. ! implicit none ! integer, intent ( in ) :: m integer, intent ( in ) :: n integer :: i integer :: ihi integer :: j integer :: jhi real, dimension ( m, n ), intent ( in ) :: a ! ihi = min ( m, 5 ) jhi = min ( n, 5 ) write ( *, '(a)' ) ' ' write ( *, '(5x,5(i7,7x))' ) ( j, j = 1, jhi ) write ( *, '(a)' ) ' ' do i = 1, ihi write ( *, '(i3,2x,5g14.6)' ) i, a(i,1:jhi) end do return end subroutine rmat_random ( lda, m, n, a, alo, ahi ) ! !******************************************************************************* ! !! RMAT_RANDOM returns a matrix of uniform random values between AHI and ALO. ! ! ! Modified: ! ! 01 September 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer LDA, the leading dimension of A. ! ! Input, integer M, N, the number of rows and columns of A. ! ! Output, real A(LDA,N), the random matrix. ! ! Input, real ALO, AHI, the minimum and maximum values that ! the matrix entries can have. ! implicit none ! integer lda integer n ! real a(lda,n) real ahi real alo integer m ! call random_number ( harvest = a(1:m,1:n) ) a(1:m,1:n) = alo + ( ahi - alo ) * a(1:m,1:n) return end subroutine timestamp ( ) ! !******************************************************************************* ! !! TIMESTAMP prints the current YMDHMS date as a time stamp. ! ! ! Example: ! ! May 31 2001 9:45:54.872 AM ! ! Modified: ! ! 31 May 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! None ! implicit none ! character ( len = 8 ) ampm integer d character ( len = 8 ) date 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 character ( len = 10 ) time integer values(8) integer y character ( len = 5 ) zone ! call date_and_time ( date, time, zone, 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 ( *, '(a,1x,i2,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) & trim ( month(m) ), d, y, h, ':', n, ':', s, '.', mm, trim ( ampm ) return end