program main c*********************************************************************72 c cc sinc_test() tests sinc(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 March 2025 c c Author: c c John Burkardt c call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sinc_test():' write ( *, '(a)' ) ' Fortran77 version' write ( *, '(a)' ) ' Test sinc().' call sincn_antideriv_test ( ) call sincn_deriv_test ( ) call sincn_deriv2_test ( ) call sincn_fun_test ( ) call sincu_antideriv_test ( ) call sincu_deriv_test ( ) call sincu_deriv2_test ( ) call sincu_fun_test ( ) c c Terminate. c write ( *, '(a)' ) '' write ( *, '(a)' ) 'sinc_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) return end subroutine sincn_antideriv_test ( ) c*********************************************************************72 c cc sincn_antideriv_test() tests sincn_antideriv(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 March 2025 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 201 double precision a double precision b character ( len = 255 ) header integer i double precision sincn_antideriv double precision x(n) double precision y(n) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sincn_antideriv_test():' write ( *, '(a)' ) & ' sincn_antideriv() evaluates the antiderivative' write ( *, '(a)' ) ' of the sincn function.' a = -7.0D+00 b = +7.0D+00 call r8vec_linspace ( n, a, b, x ) do i = 1, n y(i) = sincn_antideriv ( x(i) ) end do header = 'sincn_antideriv' call gnuplot_fx ( n, x, y, trim ( header ) ) return end subroutine sincn_deriv_test ( ) c*********************************************************************72 c cc sincn_deriv_test() tests sincn_deriv(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 March 2025 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 201 double precision a double precision b character ( len = 255 ) header integer i double precision sincn_deriv double precision x(n) double precision y(n) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sincn_deriv_test():' write ( *, '(a)' ) ' sincn_deriv() evaluates the derivative' write ( *, '(a)' ) ' of the sincn function.' a = -7.0D+00 b = +7.0D+00 call r8vec_linspace ( n, a, b, x ) do i = 1, n y(i) = sincn_deriv ( x(i) ) end do header = 'sincn_deriv' call gnuplot_fx ( n, x, y, trim ( header ) ) return end subroutine sincn_deriv2_test ( ) c*********************************************************************72 c cc sincn_deriv2_test() tests sincn_deriv2(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 March 2025 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 201 double precision a double precision b character ( len = 255 ) header integer i double precision sincn_deriv2 double precision x(n) double precision y(n) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sincn_deriv2_test():' write ( *, '(a)' ) & ' sincn_deriv2() evaluates the second derivative' write ( *, '(a)' ) ' of the sincn function.' a = -7.0D+00 b = +7.0D+00 call r8vec_linspace ( n, a, b, x ) do i = 1, n y(i) = sincn_deriv2 ( x(i) ) end do header = 'sincn_deriv2' call gnuplot_fx ( n, x, y, trim ( header ) ) return end subroutine sincn_fun_test ( ) c*********************************************************************72 c cc sincn_fun_test() tests sincn_fun(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 March 2025 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 201 double precision a double precision b character ( len = 255 ) header integer i double precision sincn_fun double precision x(n) double precision y(n) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sincn_fun_test():' write ( *, '(a)' ) ' sincn_fun() evaluates the sincn function.' a = -7.0D+00 b = +7.0D+00 call r8vec_linspace ( n, a, b, x ) do i = 1, n y(i) = sincn_fun ( x(i) ) end do header = 'sincn_fun' call gnuplot_fx ( n, x, y, trim ( header ) ) return end subroutine sincu_antideriv_test ( ) c*********************************************************************72 c cc sincu_antideriv_test() tests sincu_antideriv(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 March 2025 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 201 double precision a double precision b character ( len = 255 ) header integer i double precision sincu_antideriv double precision x(n) double precision y(n) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sincu_antideriv_test():' write ( *, '(a)' ) & ' sincu_antideriv() evaluates the antiderivative' write ( *, '(a)' ) ' of the sincu function.' a = -20.0D+00 b = +20.0D+00 call r8vec_linspace ( n, a, b, x ) do i = 1, n y(i) = sincu_antideriv ( x(i) ) end do header = 'sincu_antideriv' call gnuplot_fx ( n, x, y, trim ( header ) ) return end subroutine sincu_deriv_test ( ) c*********************************************************************72 c cc sincu_deriv_test() tests sincu_deriv(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 March 2025 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 201 double precision a double precision b character ( len = 255 ) header integer i double precision sincu_deriv double precision x(n) double precision y(n) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sincu_deriv_test():' write ( *, '(a)' ) ' sincu_deriv() evaluates the derivative' write ( *, '(a)' ) ' of the sincu function.' a = -20.0D+00 b = +20.0D+00 call r8vec_linspace ( n, a, b, x ) do i = 1, n y(i) = sincu_deriv ( x(i) ) end do header = 'sincu_deriv' call gnuplot_fx ( n, x, y, trim ( header ) ) return end subroutine sincu_deriv2_test ( ) c*********************************************************************72 c cc sincu_deriv2_test() tests sincu_deriv2(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 March 2025 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 201 double precision a double precision b character ( len = 255 ) header integer i double precision sincu_deriv2 double precision x(n) double precision y(n) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sincu_deriv2_test():' write ( *, '(a)' ) & ' sincu_deriv2() evaluates the second derivative' write ( *, '(a)' ) ' of the sincu function.' a = -20.0D+00 b = +20.0D+00 call r8vec_linspace ( n, a, b, x ) do i = 1, n y(i) = sincu_deriv2 ( x(i) ) end do header = 'sincu_deriv2' call gnuplot_fx ( n, x, y, trim ( header ) ) return end subroutine sincu_fun_test ( ) c*********************************************************************72 c cc sincu_fun_test() tests sincu_fun(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 28 March 2025 c c Author: c c John Burkardt c implicit none integer, parameter :: n = 201 double precision a double precision b character ( len = 255 ) header integer i double precision sincu_fun double precision x(n) double precision y(n) write ( *, '(a)' ) '' write ( *, '(a)' ) 'sincu_fun_test():' write ( *, '(a)' ) ' sincu_fun() evaluates the sincu function.' a = -20.0D+00 b = +20.0D+00 call r8vec_linspace ( n, a, b, x ) do i = 1, n y(i) = sincu_fun ( x(i) ) end do header = 'sincu_fun' call gnuplot_fx ( n, x, y, trim ( header ) ) return end subroutine get_unit ( iunit ) c*********************************************************************72 c cc get_unit() returns a free FORTRAN unit number. c c Discussion: c c A "free" FORTRAN unit number is a value between 1 and 99 which c is not currently associated with an I/O device. A free FORTRAN unit c number is needed in order to open a file with the OPEN command. c c If IUNIT = 0, then no free FORTRAN unit could be found, although c all 99 units were checked (except for units 5, 6 and 9, which c are commonly reserved for console I/O). c c Otherwise, IUNIT is a value between 1 and 99, representing a c free FORTRAN unit. The code assumes that units 5 and 6 c are special, and will never return those values. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 26 October 2008 c c Author: c c John Burkardt c c Output: c c integer IUNIT, the free unit number. c 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_fx ( n, x, y, header ) c*********************************************************************72 c cc gnuplot_fx() plots x, f(x) data. c c Discussion: c c Actually, we simply create two files for processing by gnuplot(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 24 March 2025 c c Author: c c John Burkardt c implicit none integer n character ( len = 255 ) command_filename integer command_unit character ( len = 255 ) data_filename integer data_unit character ( len = * ) header integer i character ( len = 255 ) png_filename double precision x(n) double precision y(n) c c Create a graphics data file. c data_filename = header // '_data.txt' call get_unit ( data_unit ) open ( unit = data_unit, file = data_filename, & status = 'replace' ) do i = 1, n write ( data_unit, '(2g14.6)' ) x(i), y(i) end do close ( unit = data_unit ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Created graphics data file "' & // trim ( data_filename ) // '".' png_filename = header // '.png' c c Create graphics command file. c call get_unit ( command_unit ) command_filename = 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 ( png_filename ) // '"' write ( command_unit, '(a)' ) 'set xlabel "<--- X --->"' write ( command_unit, '(a)' ) 'set ylabel "<-- Y(X) -->"' write ( command_unit, '(a)' ) 'set title "' // header // '"' write ( command_unit, '(a)' ) 'set grid' write ( command_unit, '(a)' ) 'set style data lines' write ( command_unit, '(a)' ) 'plot "' & // trim ( data_filename ) & // '" using 1:2 lw 3 linecolor rgb "blue"' close ( unit = command_unit ) write ( *, '(a)' ) ' Created command file "' & // trim ( command_filename ) // '".' return end subroutine r8vec_linspace ( n, a, b, x ) c*********************************************************************72 c cc r8vec_linspace() creates a vector of linearly spaced values. c c Discussion: c c An R8VEC is a vector of R8's. c c 4 points evenly spaced between 0 and 12 will yield 0, 4, 8, 12. c c In other words, the interval is divided into N-1 even subintervals, c and the endpoints of intervals are used as the points. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 14 March 2011 c c Author: c c John Burkardt c c Input: c c integer N, the number of entries in the vector. c c double precision A, B, the first and last entries. c c Output: c c double precision X(N), a vector of linearly spaced data. c implicit none integer n double precision a double precision b integer i double precision x(n) if ( n == 1 ) then x(1) = ( a + b ) / 2.0D+00 else do i = 1, n x(i) = ( dble ( n - i ) * a & + dble ( i - 1 ) * b ) & / dble ( n - 1 ) end do end if return end subroutine timestamp ( ) c*********************************************************************72 c cc timestamp() prints the current YMDHMS date as a time stamp. c c Example: c c 31 May 2001 9:45:54.872 AM c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 15 August 2021 c c Author: c c John Burkardt c 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