program main !*****************************************************************************80 ! !! fresnel_test() tests fresnel(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 10 July 2025 ! ! Author: ! ! John Burkardt ! implicit none call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'fresnel_test():' write ( *, '(a)' ) ' Fortran90 version' write ( *, '(a)' ) ' Test fresnel()' call fresnel_cos_values_test ( ) call fresnel_sin_values_test ( ) call fresnel_cos_plot ( ) call fresnel_sin_plot ( ) call fresnel_phase_plot ( ) ! ! Terminate. ! write ( *, '(a)' ) '' write ( *, '(a)' ) 'fresnel_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) stop ( 0 ) end subroutine fresnel_cos_plot ( ) !*****************************************************************************80 ! !! fresnel_cos_plot() tests fresnel_cos(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 10 July 2025 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) real ( kind = rk8 ) a real ( kind = rk8 ) b real ( kind = rk8 ) fresnel_cos character ( len = 80 ) header integer i integer n real ( kind = rk8 ), allocatable :: x(:) real ( kind = rk8 ), allocatable :: y(:) write ( *, '(a)' ) '' write ( *, '(a)' ) 'fresnel_cos_plot():' write ( *, '(a)' ) ' Plot (X,C(X)), where C(X) is the Fresnel cosine integral.' a = -5.0D+00 b = +5.0D+00 n = 501 allocate ( x(1:n) ) call r8vec_linspace ( n, a, b, x ) allocate ( y(1:n) ) do i = 1, n y(i) = fresnel_cos ( x(i) ) end do header = 'fresnel_cos_plot' call gnuplot_fx ( n, x, y, header ) deallocate ( x ) deallocate ( y ) return end subroutine fresnel_cos_values ( n_data, x, fx ) !*****************************************************************************80 ! !! fresnel_cos_values() returns values of the Fresnel cosine integral function. ! ! Discussion: ! ! The Fresnel cosine integral is defined by: ! ! C(X) = integral ( 0 <= T <= X ) cos ( PI * T^2 / 2 ) dT ! ! In Mathematica, the function can be evaluated by: ! ! FresnelC[x] ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 16 November 2015 ! ! Author: ! ! John Burkardt ! ! Reference: ! ! Milton Abramowitz, Irene Stegun, ! Handbook of Mathematical Functions, ! National Bureau of Standards, 1964, ! ISBN: 0-486-61272-4, ! LC: QA47.A34. ! ! Stephen Wolfram, ! The Mathematica Book, ! Fourth Edition, ! Cambridge University Press, 1999, ! ISBN: 0-521-64314-7, ! LC: QA76.95.W65. ! ! Input: ! ! integer N_DATA: The user sets N_DATA to 0 before the first call. ! ! Output: ! ! integer N_DATA: On each call, the routine increments N_DATA by 1, ! and returns the corresponding data; when there is no more data, the ! output value of N_DATA will be 0 again. ! ! real ( kind = rk8 ) X, the argument of the function. ! ! real ( kind = rk8 ) FX, the value of the function. ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) integer, parameter :: n_max = 16 real ( kind = rk8 ) fx real ( kind = rk8 ), save, dimension ( n_max ) :: fx_vec = (/ & 0.0000000000000000D+00, & 0.1999210575944531D+00, & 0.3974807591723594D+00, & 0.5810954469916523D+00, & 0.7228441718963561D+00, & 0.7798934003768228D+00, & 0.7154377229230734D+00, & 0.5430957835462564D+00, & 0.3654616834404877D+00, & 0.3336329272215571D+00, & 0.4882534060753408D+00, & 0.6362860449033195D+00, & 0.5549614058564281D+00, & 0.3889374961919690D+00, & 0.4674916516989059D+00, & 0.6057207892976856D+00 /) integer n_data real ( kind = rk8 ) x real ( kind = rk8 ), save, dimension ( n_max ) :: x_vec = (/ & 0.0D+00, & 0.2D+00, & 0.4D+00, & 0.6D+00, & 0.8D+00, & 1.0D+00, & 1.2D+00, & 1.4D+00, & 1.6D+00, & 1.8D+00, & 2.0D+00, & 2.2D+00, & 2.4D+00, & 2.6D+00, & 2.8D+00, & 3.0D+00 /) if ( n_data < 0 ) then n_data = 0 end if n_data = n_data + 1 if ( n_max < n_data ) then n_data = 0 x = 0.0D+00 fx = 0.0D+00 else x = x_vec(n_data) fx = fx_vec(n_data) end if return end subroutine fresnel_cos_values_test ( ) !*****************************************************************************80 ! !! fresnel_cos_values_test() tests fresnel_cos(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 10 July 2025 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) real ( kind = rk8 ) fresnel_cos real ( kind = rk8 ) fx1 real ( kind = rk8 ) fx2 integer n_data real ( kind = rk8 ) x write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'fresnel_cos_values_test():' write ( *, '(a)' ) ' fresnel_cos_values() returns values of' write ( *, '(a)' ) ' the Fresnel cosine integral C(X).' write ( *, '(a)' ) ' fresnel_cos() computes the value.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' X C(X) C(X)' write ( *, '(a)' ) ' X Tabulated Computed' write ( *, '(a)' ) ' ' n_data = 0 do call fresnel_cos_values ( n_data, x, fx1 ) if ( n_data == 0 ) then exit end if fx2 = fresnel_cos ( x ) write ( *, '(2x,g14.6,2x,g24.16,2x,g24.16)' ) x, fx1, fx2 end do return end subroutine fresnel_phase_plot ( ) !*****************************************************************************80 ! !! fresnel_phase_plot() tests fresnel_cos() and fresnel_sin(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 10 July 2025 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) real ( kind = rk8 ) a real ( kind = rk8 ) b real ( kind = rk8 ), allocatable :: c(:) character ( len = 80 ) header integer i integer n real ( kind = rk8 ), allocatable :: s(:) real ( kind = rk8 ), allocatable :: x(:) write ( *, '(a)' ) '' write ( *, '(a)' ) 'fresnel_phase_plot():' write ( *, '(a)' ) ' Plot (C(X),S(X)), where C(X) and S(X) are' write ( *, '(a)' ) ' the Fresnel cosine and sine integrals.' a = -5.0D+00 b = +5.0D+00 n = 501 allocate ( x(1:n) ) call r8vec_linspace ( n, a, b, x ) allocate ( c(1:n) ) allocate ( s(1:n) ) do i = 1, n call fresnel ( x(i), c(i), s(i) ) end do header = 'fresnel_phase_plot' call gnuplot_fx ( n, c, s, header ) deallocate ( c ) deallocate ( s ) deallocate ( x ) return end subroutine fresnel_sin_plot ( ) !*****************************************************************************80 ! !! fresnel_sin_plot() tests fresnel_sin(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 10 July 2025 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) real ( kind = rk8 ) a real ( kind = rk8 ) b real ( kind = rk8 ) fresnel_sin character ( len = 80 ) header integer i integer n real ( kind = rk8 ), allocatable :: x(:) real ( kind = rk8 ), allocatable :: y(:) write ( *, '(a)' ) '' write ( *, '(a)' ) 'fresnel_sin_plot():' write ( *, '(a)' ) ' Plot (X,S(X)), where S(X) is the Fresnel sine integral.' a = -5.0D+00 b = +5.0D+00 n = 501 allocate ( x(1:n) ) call r8vec_linspace ( n, a, b, x ) allocate ( y(1:n) ) do i = 1, n y(i) = fresnel_sin ( x(i) ) end do header = 'fresnel_sin_plot' call gnuplot_fx ( n, x, y, header ) deallocate ( x ) deallocate ( y ) return end subroutine fresnel_sin_values ( n_data, x, fx ) !*****************************************************************************80 ! !! fresnel_sin_values() returns some values of the Fresnel sine integral function. ! ! Discussion: ! ! The Fresnel sine integral is defined by ! ! S(X) = integral ( 0 <= T <= X ) sin ( pi * T^2 / 2 ) dT ! ! In Mathematica, the function can be evaluated by: ! ! FresnelS[x] ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 16 November 2015 ! ! Author: ! ! John Burkardt ! ! Reference: ! ! Milton Abramowitz, Irene Stegun, ! Handbook of Mathematical Functions, ! National Bureau of Standards, 1964, ! ISBN: 0-486-61272-4, ! LC: QA47.A34. ! ! Stephen Wolfram, ! The Mathematica Book, ! Fourth Edition, ! Cambridge University Press, 1999, ! ISBN: 0-521-64314-7, ! LC: QA76.95.W65. ! ! Input: ! ! integer N_DATA: The user sets N_DATA to 0 before the first call. ! ! Output: ! ! integer N_DATA: On each call, the routine increments N_DATA by 1, ! and returns the corresponding data; when there is no more data, the ! output value of N_DATA will be 0 again. ! ! real ( kind = rk8 ) X, the argument of the function. ! ! real ( kind = rk8 ) FX, the value of the function. ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) integer, parameter :: n_max = 16 real ( kind = rk8 ) fx real ( kind = rk8 ), save, dimension ( n_max ) :: fx_vec = (/ & 0.0000000000000000D+00, & 0.4187609161656762D-02, & 0.3335943266061318D-01, & 0.1105402073593870D+00, & 0.2493413930539178D+00, & 0.4382591473903548D+00, & 0.6234009185462497D+00, & 0.7135250773634121D+00, & 0.6388876835093809D+00, & 0.4509387692675831D+00, & 0.3434156783636982D+00, & 0.4557046121246569D+00, & 0.6196899649456836D+00, & 0.5499893231527195D+00, & 0.3915284435431718D+00, & 0.4963129989673750D+00 /) integer n_data real ( kind = rk8 ) x real ( kind = rk8 ), save, dimension ( n_max ) :: x_vec = (/ & 0.0D+00, & 0.2D+00, & 0.4D+00, & 0.6D+00, & 0.8D+00, & 1.0D+00, & 1.2D+00, & 1.4D+00, & 1.6D+00, & 1.8D+00, & 2.0D+00, & 2.2D+00, & 2.4D+00, & 2.6D+00, & 2.8D+00, & 3.0D+00 /) if ( n_data < 0 ) then n_data = 0 end if n_data = n_data + 1 if ( n_max < n_data ) then n_data = 0 x = 0.0D+00 fx = 0.0D+00 else x = x_vec(n_data) fx = fx_vec(n_data) end if return end subroutine fresnel_sin_values_test ( ) !*****************************************************************************80 ! !! fresnel_sin_values_test() tests fresnel_sin(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 10 July 2025 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) real ( kind = rk8 ) fresnel_sin real ( kind = rk8 ) fx1 real ( kind = rk8 ) fx2 integer n_data real ( kind = rk8 ) x write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'fresnel_sin_values_test():' write ( *, '(a)' ) ' fresnel_sin_values() returns values of' write ( *, '(a)' ) ' the Fresnel sine integral S(X).' write ( *, '(a)' ) ' fresnel_sin() computes the value.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' X S(X) S(X)' write ( *, '(a)' ) ' X Tabulated Computed' write ( *, '(a)' ) ' ' n_data = 0 do call fresnel_sin_values ( n_data, x, fx1 ) if ( n_data == 0 ) then exit end if fx2 = fresnel_sin ( x ) write ( *, '(2x,g14.6,2x,g24.16,2x,g24.16)' ) x, fx1, fx2 end do return end subroutine gnuplot_fx ( n, x, y, header ) !*****************************************************************************80 ! !! gnuplot_fx() plots x, f(x) data. ! ! Discussion: ! ! Actually, we simply create two files for processing by gnuplot(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 24 March 2025 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) 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 real ( kind = rk8 ) x(n) real ( kind = rk8 ) y(n) ! ! Create a graphics data file. ! data_filename = trim ( 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 = trim ( header ) // '.png' ! ! Create graphics 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 ( png_filename ) // '"' write ( command_unit, '(a)' ) 'set xlabel "<--- X --->"' write ( command_unit, '(a)' ) 'set ylabel "<-- Y(X) -->"' write ( command_unit, '(a)' ) 'set title "' // trim ( 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 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. The code 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 r8vec_linspace ( n, a, b, x ) !*****************************************************************************80 ! !! r8vec_linspace() creates a vector of linearly spaced values. ! ! Discussion: ! ! An R8VEC is a vector of R8's. ! ! 4 points evenly spaced between 0 and 12 will yield 0, 4, 8, 12. ! ! In other words, the interval is divided into N-1 even subintervals, ! and the endpoints of intervals are used as the points. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 14 March 2011 ! ! Author: ! ! John Burkardt ! ! Input: ! ! integer N, the number of entries in the vector. ! ! real ( kind = rk8 ) A, B, the first and last entries. ! ! Output: ! ! real ( kind = rk8 ) X(N), a vector of linearly spaced data. ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) integer n real ( kind = rk8 ) a real ( kind = rk8 ) b integer i real ( kind = rk8 ) x(n) if ( n == 1 ) then x(1) = ( a + b ) / 2.0D+00 else do i = 1, n x(i) = ( real ( n - i, kind = rk8 ) * a & + real ( i - 1, kind = rk8 ) * b ) & / real ( n - 1, kind = rk8 ) end do 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