program main !*****************************************************************************80 ! !! kdv_ift_test() tests kdv_ift(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 08 June 2022 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: nt = 26 integer, parameter :: nx = 256 character ( len = * ), parameter :: header = 'kdv_ift' character ( len = * ), parameter :: title = 'Korteweg-DeVries solved by IFT' real ( kind = rk ) tt(nt) real ( kind = rk ) uu(nx,nt) real ( kind = rk ) xx(nx) call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'kdv_ift_test():' write ( *, '(a)' ) ' FORTRAN90 version' write ( *, '(a)' ) ' Test kdv_ift(), which solves the Korteweg-deVries equation' write ( *, '(a)' ) ' using the FFT method with an integrating factor.' call kdv_ift ( nx, nt, xx, tt, uu ) ! ! Create an image using gnuplot. ! call gnuplot_surface ( nx, nt, xx, tt, uu, header, title ) ! ! Terminate. ! write ( *, '(a)' ) '' write ( *, '(a)' ) 'kdv_ift_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) stop ( 0 ) end subroutine get_unit ( iunit ) !*****************************************************************************80 ! !! get_unit() returns a free FORTRAN unit number. ! ! Discussion: ! ! A "free" FORTRAN unit number is a value between 1 and 99 which ! is not currently associated with an I/O device. A free FORTRAN unit ! number is needed in order to open a file with the OPEN command. ! ! If IUNIT = 0, then no free FORTRAN unit could be found, although ! all 99 units were checked (except for units 5, 6 and 9, which ! are commonly reserved for console I/O). ! ! Otherwise, IUNIT is a value between 1 and 99, representing a ! free FORTRAN unit. Note that GET_UNIT assumes that units 5 and 6 ! are special, and will never return those values. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 26 October 2008 ! ! Author: ! ! John Burkardt ! ! Output: ! ! integer IUNIT, the free unit number. ! implicit none integer i integer ios integer iunit logical lopen iunit = 0 do i = 1, 99 if ( i /= 5 .and. i /= 6 .and. i /= 9 ) then inquire ( unit = i, opened = lopen, iostat = ios ) if ( ios == 0 ) then if ( .not. lopen ) then iunit = i return end if end if end if end do return end subroutine gnuplot_surface ( m, n, x, y, z, header, title ) !*****************************************************************************80 ! !! gnuplot_surface draws a surface from a table Z(X,Y). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 17 April 2020 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer m integer n character ( len = 255 ) command_filename integer command_unit character ( len = 255 ) data_filename integer data_unit character ( len = * ) header integer i integer j character ( len = * ) title real ( kind = rk ) x(m) real ( kind = rk ) y(n) real ( kind = rk ) z(m,n) write ( *, '(a)' ) '' write ( *, '(a)' ) 'gnuplot_surface():' write ( *, '(a)' ) ' FORTRAN90 version' ! ! Create the data file. ! call get_unit ( data_unit ) data_filename = header // '_data.txt' open ( unit = data_unit, file = data_filename, status = 'replace' ) do j = 1, n if ( 1 < j ) then write ( data_unit, '(a)' ) end if do i = 1, m write ( data_unit, '(3(2x,g14.6))' ) x(i), y(j), z(i,j) end do end do close ( unit = data_unit ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' gnuplot_surface: data stored in "' & // trim ( data_filename ) // '".' ! ! Create the command file. ! call get_unit ( command_unit ) command_filename = trim ( header ) // '_commands.txt' open ( unit = command_unit, file = command_filename, status = 'replace' ) write ( command_unit, '(a)' ) '# ' // trim ( command_filename ) write ( command_unit, '(a)' ) '#' write ( command_unit, '(a)' ) '# Usage:' write ( command_unit, '(a)' ) '# gnuplot < ' // trim ( command_filename ) write ( command_unit, '(a)' ) '#' write ( command_unit, '(a)' ) 'set term png' write ( command_unit, '(a)' ) 'set output "' // trim ( header ) // '.png"' write ( command_unit, '(a)' ) 'set xlabel "X"' write ( command_unit, '(a)' ) 'set ylabel "Y"' write ( command_unit, '(a)' ) 'set zlabel "Z"' write ( command_unit, '(a)' ) 'set title "' // trim ( title ) // '"' write ( command_unit, '(a)' ) 'set view 10, 30' write ( command_unit, '(a)' ) 'set hidden3d' write ( command_unit, '(a)' ) 'set timestamp' write ( command_unit, '(a)' ) 'set grid' write ( command_unit, '(a)' ) 'set style data lines' write ( command_unit, '(a)' ) 'splot "' // trim ( data_filename ) // & '" with lines' write ( command_unit, '(a)' ) 'quit' close ( unit = command_unit ) write ( *, '(a)' ) ' gnuplot_surface: plot commands stored in "' & // trim ( command_filename ) // '".' 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 ! 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