program main !*****************************************************************************80 ! !! drug_dosage_plots() plots the blood drug levels over time. ! ! Discussion: ! ! This program creates files that must be processed by gnuplot(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 23 September 2026 ! ! Author: ! ! John Burkardt ! implicit none character ( len = 255 ) command_filename integer command_unit character ( len = 255 ) data_filename character ( len = 255 ) graphic_filename call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'drug_dosage_plots():' write ( *, '(a)' ) ' Fortran90 version' write ( *, '(a)' ) ' On a single picture, plot:' write ( *, '(a)' ) ' * the variation in blood levels of a medicinal drug.' write ( *, '(a)' ) ' * the minimal effective level.' write ( *, '(a)' ) ' * the toxic level.' ! ! Set file names. ! command_filename = 'drug_dosage_commands.txt' data_filename = 'drug_dosage_data.txt' graphic_filename = 'drug_dosage_plots.png' ! ! Create the command file. ! call get_unit ( command_unit ) 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 ( graphic_filename ) // '"' write ( command_unit, '(a)' ) 'set xlabel "<--- Hours --->"' write ( command_unit, '(a)' ) 'set ylabel "<--- Concentration (mg/l) --->"' write ( command_unit, '(a)' ) 'set title "Drug level variation over time"' write ( command_unit, '(a)' ) 'set grid' write ( command_unit, '(a)' ) 'set timestamp' write ( command_unit, '(a)' ) 'set key on' write ( command_unit, '(a)' ) 'set style data lines' write ( command_unit, '(a)' ) 'set yrange [0:1100]' write ( command_unit, '(a)' ) 'plot "' // trim ( data_filename ) & // '" using 1:2 with lines lw 3, \' write ( command_unit, '(a)' ) ' [y=800:800] 0,48 with lines lw 3 lt rgb "green" title "Minimal medicinal level", \' write ( command_unit, '(a)' ) & ' 1000 with lines lw 3 lt rgb "red" title "Toxic level"' write ( command_unit, '(a)' ) 'quit' close ( unit = command_unit ) write ( *, '(a)' ) ' plot commands stored in "' & // trim ( command_filename ) // '".' ! ! Terminate. ! write ( *, '(a)' ) '' write ( *, '(a)' ) 'drug_dosage_plots():' write ( *, '(a)' ) ' Normal end of execution.' 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 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: ! ! 06 August 2005 ! ! 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,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