program main c*********************************************************************72 c cc MAIN is the main program for CONSTANT_TYPE. c c Discussion: c c CONSTANT_TYPE demonstrates that constants may need to be given a type. c c It is natural to assume that if you go to the trouble of typing c 14 decimals in a constant, that FORTRAN will somehow use them. c But constants have a type, just like variables. If you don't c somehow specify a type, then a constant will be treated like c a single precision value (assuming you used a decimal point c somewhere.) c c This means that, for instance, if you print out the value of c ( 1.0203040506070809 - 1.020304050607 ), it will almost certainly c be 0. c c Licensing: c c This code is distributed under the GNU LGPL license. c c Modified: c c 04 December 2008 c c Author: c c John Burkardt c implicit none double precision a double precision b double precision c call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'CONSTANT_TYPE' write ( *, '(a)' ) ' FORTRAN77 version.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Demonstrate that constants have a type.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' EXAMPLE 1:' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Print the value of' write ( *, '(a)' ) ' 1.0203040506070809 - 1.020304050607' write ( *, '(a)' ) ' ' write ( *, * ) ' 1.0203040506070809 - 1.020304050607 = ', & 1.0203040506070809 - 1.020304050607 write ( *, '(a)' ) ' ' write ( *, '(a)' ) & ' If single precision is the default, this will be 0.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' EXAMPLE 2:' write ( *, '(a)' ) ' A constant has a type.' write ( *, '(a)' ) & ' If you do not specify one, one will be provided.' write ( *, '(a)' ) & ' If we assign a 32 decimal constant to a single,' write ( *, '(a)' ) ' double, and quadruple precision variable,' write ( *, '(a)' ) & ' IN EVERY CASE, only the first 8 decimals will be used,' write ( *, '(a)' ) & ' because we did not set the type of the constant:' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' a = 1.020304050607080910111213141516' write ( *, '(a)' ) ' b = 1.020304050607080910111213141516' write ( *, '(a)' ) ' c = 1.020304050607080910111213141516' a = 1.020304050607080910111213141516 b = 1.020304050607080910111213141516 c = 1.020304050607080910111213141516 write ( *, '(a)' ) ' ' write ( *, * ) ' A = ', a write ( *, * ) ' B = ', b write ( *, * ) ' C = ', c write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' EXAMPLE 3:' write ( *, '(a)' ) & ' Use an exponent marker of "E", "D" or "Q" to indicate' write ( *, '(a)' ) & ' that your constant is single, double or quadruple' write ( *, '(a)' ) & ' precision. If we repeat the previous test, we now see' write ( *, '(a)' ) & ' the appropriate number of decimals are copied.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' a = 1.020304050607080910111213141516E+00' write ( *, '(a)' ) ' b = 1.020304050607080910111213141516D+00' write ( *, '(a)' ) ' c = 1.020304050607080910111213141516Q+00' a = 1.020304050607080910111213141516E+00 b = 1.020304050607080910111213141516D+00 c = 1.020304050607080910111213141516Q+00 write ( *, '(a)' ) ' ' write ( *, * ) ' A = ', a write ( *, * ) ' B = ', b write ( *, * ) ' C = ', c write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'CONSTANT_TYPE' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop end subroutine timestamp ( ) c*********************************************************************72 c cc TIMESTAMP prints out the current YMDHMS date as a timestamp. c c Discussion: c c This FORTRAN77 version is made available for cases where the c FORTRAN90 version cannot be used. c c Licensing: c c This code is distributed under the GNU LGPL license. c c Modified: c c 12 January 2007 c c Author: c c John Burkardt c c Parameters: c c None c implicit none character * ( 8 ) ampm integer d character * ( 8 ) date integer h integer m integer mm character * ( 9 ) month(12) integer n integer s character * ( 10 ) time integer y save month data month / & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' / call date_and_time ( date, time ) read ( date, '(i4,i2,i2)' ) y, m, d read ( time, '(i2,i2,i2,1x,i3)' ) h, n, s, mm if ( h .lt. 12 ) then ampm = 'AM' else if ( h .eq. 12 ) then if ( n .eq. 0 .and. s .eq. 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h .lt. 12 ) then ampm = 'PM' else if ( h .eq. 12 ) then if ( n .eq. 0 .and. s .eq. 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, month(m), y, h, ':', n, ':', s, '.', mm, ampm return end