program main !*****************************************************************************80 ! !! matrix_chain_test() tests matrix_chain(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 31 December 2023 ! ! Author: ! ! John Burkardt ! implicit none integer cost integer, allocatable :: dims(:) integer n call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'matrix_chain_test():' write ( *, '(a)' ) ' Fortran90 version' write ( *, '(a)' ) ' Test matrix_chain().' n = 4 allocate ( dims(1:n+1) ) dims = (/ 40, 20, 30, 10, 30 /) call matrix_chain ( n, dims, cost ) write ( *, '(a)' ) '' write ( *, '(a,i2)' ) ' n = ', n call i4vec_transpose_print ( n + 1, dims, ' dims():' ) write ( *, '(a,i8)' ) ' cost = ', cost deallocate ( dims ) n = 4 allocate ( dims(1:n+1) ) dims = (/ 1, 2, 3, 4, 3 /) call matrix_chain ( n, dims, cost ) write ( *, '(a)' ) '' write ( *, '(a,i2)' ) ' n = ', n call i4vec_transpose_print ( n + 1, dims, ' dims():' ) write ( *, '(a,i8)' ) ' cost = ', cost deallocate ( dims ) n = 2 allocate ( dims(1:n+1) ) dims = (/ 10, 20, 30 /) call matrix_chain ( n, dims, cost ) write ( *, '(a)' ) '' write ( *, '(a,i2)' ) ' n = ', n call i4vec_transpose_print ( n + 1, dims, ' dims():' ) write ( *, '(a,i8)' ) ' cost = ', cost deallocate ( dims ) n = 3 allocate ( dims(1:n+1) ) dims = (/ 10, 30, 5, 60 /) call matrix_chain ( n, dims, cost ) write ( *, '(a)' ) '' write ( *, '(a,i2)' ) ' n = ', n call i4vec_transpose_print ( n + 1, dims, ' dims():' ) write ( *, '(a,i8)' ) ' cost = ', cost deallocate ( dims ) n = 1 allocate ( dims(1:n+1) ) dims = (/ 10, 20 /) call matrix_chain ( n, dims, cost ) write ( *, '(a)' ) '' write ( *, '(a,i2)' ) ' n = ', n call i4vec_transpose_print ( n + 1, dims, ' dims():' ) write ( *, '(a,i8)' ) ' cost = ', cost deallocate ( dims ) n = 0 allocate ( dims(1:n+1) ) dims = (/ 40 /) call matrix_chain ( n, dims, cost ) write ( *, '(a)' ) '' write ( *, '(a,i2)' ) ' n = ', n call i4vec_transpose_print ( n + 1, dims, ' dims():' ) write ( *, '(a,i8)' ) ' cost = ', cost deallocate ( dims ) ! ! Terminate. ! write ( *, '(a)' ) '' write ( *, '(a)' ) 'matrix_chain_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) stop 0 end subroutine i4vec_transpose_print ( n, a, title ) !*****************************************************************************80 ! !! i4vec_transpose_print() prints an I4VEC "transposed". ! ! Discussion: ! ! An I4VEC is a vector of I4's. ! ! Example: ! ! A = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 /) ! TITLE = 'My vector: ' ! ! My vector: ! 1 2 3 4 5 ! 6 7 8 9 10 ! 11 ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 02 June 2015 ! ! Author: ! ! John Burkardt ! ! Input: ! ! integer N, the number of components of the vector. ! ! integer A(N), the vector to be printed. ! ! character ( len = * ) TITLE, a title. ! implicit none integer n integer a(n) integer ihi integer ilo character ( len = * ) title if ( 0 < len_trim ( title ) ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) trim ( title ) end if if ( 0 < n ) then do ilo = 1, n, 5 ihi = min ( ilo + 5 - 1, n ) write ( *, '(5i12)' ) a(ilo:ihi) end do else write ( *, '(a)' ) ' (empty vector)' end if 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: ! ! 15 August 2021 ! ! Author: ! ! John Burkardt ! implicit none 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.2,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