! $Id$ ! http://orion.math.iastate.edu/burkardt/f_src/raw_io/raw_io.html ! ! The list of routines includes: ! B1_TO_SI1 converts one byte to a signed integer. ! B1_TO_UI1 converts one byte to an unsigned integer. ! B2_TO_SI2 converts two bytes to a signed integer. ! B2_TO_UI2 converts two bytes to an unsigned integer. ! B4_IEEE_TO_R4 converts a 4 byte IEEE word into a real value. ! B4_TO_SI4 converts four bytes to a signed integer. ! B4_TO_UI4 converts four bytes to an unsigned integer. ! BYTE_SWAP_GET gets the current byte swap information. ! BYTE_SWAP_INFO sets or gets byte swapping information. ! BYTE_SWAP_SET sets the current byte swap information. ! CH_IS_PRINTABLE determines if a character is printable. ! CHVEC_PRINT prints a character vector. ! GET_UNIT returns a free FORTRAN unit number. ! R4_TO_B4_IEEE converts a real value to a 4 byte IEEE word. ! RAW_C_COUNT counts the number of characters in a "raw" file. ! RAW_C_READ reads N characters from a raw file. ! RAW_C_WRITE writes N character to a raw file. ! RAW_OPEN opens a "raw" file. ! RAW_R4_READ reads the "next" 4 byte real from a raw file. ! RAW_R8_READ reads the "next" 8 byte real from a raw file. ! RAW_S_READ reads the "next" string from a raw file. ! RAW_SI1_READ reads N signed 1 byte integers from a raw file. ! RAW_SI1_WRITE writes N 1 byte signed integers to a raw file. ! RAW_SI2_READ reads N 2 byte signed integers from a raw file. ! RAW_SI2_WRITE writes N 2 byte signed integers to a raw file. ! RAW_SI4_READ reads N 4 byte signed integers from a raw file. ! RAW_SI4_WRITE writes N 4 byte signed integers to a raw file. ! RAW_UI1_READ reads N unsigned 1 byte integers from a raw file. ! RAW_UI1_WRITE writes N 1 byte unsigned integers to a raw file. ! RAW_UI2_READ reads N 2 byte unsigned integers from a raw file. ! RAW_UI2_WRITE writes N 2 byte unsigned integers to a raw file. ! RAW_UI4_READ reads N 4 byte unsigned integers from a raw file. ! RAW_UI4_WRITE writes N 4 byte unsigned integers to a raw file. ! S_BYTE_SWAP swaps the bytes in a string. ! SI1_TO_B1 converts a signed integer to one byte. ! SI2_TO_B2 converts a signed integer to two bytes. ! SI4_TO_B4 converts a signed integer to four bytes. ! TIMESTAMP prints the current YMDHMS date as a time stamp. ! UI1_TO_B1 converts an unsigned integer to one byte. ! UI2_TO_B2 converts an unsigned integer to two bytes. ! UI4_TO_B4 converts an unsigned integer to four bytes. ! subroutine b1_to_si1 ( b1, i1 ) ! !******************************************************************************* ! !! B1_TO_SI1 converts one byte to a signed integer. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character B1, the byte to be converted. ! ! Output, integer I1, the signed integer. ! implicit none ! character b1 integer i1 ! i1 = ichar ( b1 ) - 128 return end subroutine b1_to_ui1 ( b1, i1 ) ! !******************************************************************************* ! !! B1_TO_UI1 converts one byte to an unsigned integer. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character B1, the byte to be converted. ! ! Output, integer I1, the unsigned integer. ! implicit none ! character b1 integer i1 ! i1 = ichar ( b1 ) return end subroutine b2_to_si2 ( b2, i2 ) ! !******************************************************************************* ! !! B2_TO_SI2 converts two bytes to a signed integer. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character B2(2), the bytes to be converted. ! ! Output, integer I2, the signed integer. ! implicit none ! character b2(2) integer i2 ! i2 = ichar ( b2(1) ) * 256 + ichar ( b2(2) ) - 32768 return end subroutine b2_to_ui2 ( b2, i2 ) ! !******************************************************************************* ! !! B2_TO_UI2 converts two bytes to an unsigned integer. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character B2(2), the bytes to be converted. ! ! Output, integer I2, the unsigned integer. ! implicit none ! character b2(2) integer i integer i2 ! i2 = 0 do i = 1, 2 i2 = i2 * 256 + ichar ( b2(i) ) end do return end subroutine b4_ieee_to_r4 ( word, r ) ! !******************************************************************************* ! !! B4_IEEE_TO_R4 converts a 4 byte IEEE word into a real value. ! ! ! Discussion: ! ! This routine does not seem to working reliably for unnormalized data. ! ! The word containing the real value may be interpreted as: ! ! /SEEEEEEE/EFFFFFFF/FFFFFFFF/FFFFFFFF/ ! ! /33222222/22222222/22222100/00000000/ ! /10987654/32109876/54321098/76543210/ <-- Bit numbering ! ! where ! ! S is the sign bit, ! E are the exponent bits, ! F are the mantissa bits. ! ! The mantissa is usually "normalized"; that is, there is an implicit ! leading 1 which is not stored. However, if the exponent is set to ! its minimum value, this is no longer true. ! ! The exponent is "biased". That is, you must subtract a bias value ! from the exponent to get the true value. ! ! If we read the three fields as integers S, E and F, then the ! value of the resulting real number R can be determined by: ! ! * if E = 255 ! if F is nonzero, then R = NaN; ! if F is zero and S is 1, R = -Inf; ! if F is zero and S is 0, R = +Inf; ! * else if E > 0 then R = (-1)**(S) * 2**(E-127) * (1 + (F/2**24)) ! * else if E = 0 ! if F is nonzero, R = (-1)**(S) * 2**(E-126) * (F/2**24) ! if F is zero and S is 1, R = -0; ! if F is zero and S is 0, R = +0; ! ! Reference: ! ! ANSI/IEEE Standard 754-1985, ! Standard for Binary Floating Point Arithmetic. ! ! Modified: ! ! 10 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer WORD, the word to be decoded. ! ! Output, real R, the value of the real number. ! implicit none ! integer e integer f real r integer s integer word ! ! Read the fields. ! s = 0 call mvbits ( word, 31, 1, s, 0 ) e = 0 call mvbits ( word, 23, 8, e, 0 ) f = 0 call mvbits ( word, 0, 23, f, 0 ) ! ! Don't bother trying to return NaN or Inf just yet. ! if ( e == 255 ) then r = 0.0E+00 else if ( e > 0 ) then r = ( -1.0E+00 )**s * 2.0E+00**(e-127-23) * real ( 8388608 + f ) else if ( e == 0 ) then r = ( -1.0E+00 )**s * 2.0E+00**(-126-23) * real ( f ) end if return end subroutine b4_to_si4 ( b4, i4 ) ! !******************************************************************************* ! !! B4_TO_SI4 converts four bytes to a signed integer. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character B4(4), the bytes to be converted. ! ! Output, integer I4, the signed integer. ! implicit none ! character b4(4) integer i integer i4 ! i4 = 0 do i = 1, 4 i4 = i4 * 256 + ichar ( b4(i) ) end do i4 = i4 - 2147483648 return end subroutine b4_to_ui4 ( b4, i4 ) ! !******************************************************************************* ! !! B4_TO_UI4 converts four bytes to an unsigned integer. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character B4(4), the bytes to be converted. ! ! Output, integer I4, the unsigned integer. ! implicit none ! character b4(4) integer i integer i4 ! i4 = 0 do i = 1, 4 i4 = i4 * 256 + ichar ( b4(i) ) end do return end subroutine byte_swap_get ( byte_swap, nbytes, bytes ) ! !******************************************************************************* ! !! BYTE_SWAP_GET gets the current byte swap information. ! ! ! Modified: ! ! 28 November 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Output, logical BYTE_SWAP, is TRUE if there is byte swapping. ! ! Output, integer NBYTES, the number of bytes in a swapping unit. ! ! Output, integer BYTES(NBYTES), is the byte swapping pattern. ! implicit none ! logical byte_swap integer bytes(*) integer nbytes ! call byte_swap_info ( 'GET', nbytes, byte_swap, bytes ) return end subroutine byte_swap_info ( action, nbytes, byte_swap, bytes ) ! !******************************************************************************* ! !! BYTE_SWAP_INFO sets or gets byte swapping information. ! ! ! Modified: ! ! 06 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) ACTION, defines what is to be done. ! 'SET' means that the user is supplying values. ! 'GET' means that the user is requesting values. ! ! Input/output, integer NBYTES, the number of bytes in a swapping unit. ! ! Input/output, logical BYTE_SWAP, is TRUE if there is byte swapping. ! ! Input/output, integer BYTES(NBYTES), is the byte swapping pattern. ! implicit none ! character ( len = * ) action logical byte_swap logical, save :: byte_swap_saved = .false. integer bytes(8) integer, save, dimension ( 8 ) :: bytes_saved = & (/ 1, 2, 3, 4, 5, 6, 7, 8 /) integer nbytes integer, save :: nbytes_saved = 4 ! if ( action == 'SET' ) then byte_swap_saved = byte_swap bytes_saved(1:nbytes) = bytes(1:nbytes) nbytes_saved = nbytes else if ( action == 'GET' ) then byte_swap = byte_swap_saved bytes(1:nbytes_saved) = bytes_saved(1:nbytes_saved) nbytes = nbytes_saved else write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'BYTE_SWAP_INFO - Fatal error!' write ( *, '(a)' ) ' Unrecognized action request: ' write ( *, '(a)' ) trim ( action ) stop end if return end subroutine byte_swap_set ( nbytes, byte_swap, bytes ) ! !******************************************************************************* ! !! BYTE_SWAP_SET sets the current byte swap information. ! ! ! Modified: ! ! 28 November 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, logical BYTE_SWAP, is TRUE if there is byte swapping. ! ! Input, integer NBYTES, the number of bytes in a swapping unit. ! ! Input, integer BYTES(NBYTES), is the byte swapping pattern. ! implicit none ! integer nbytes ! logical byte_swap integer bytes(nbytes) ! call byte_swap_info ( 'SET', nbytes, byte_swap, bytes ) return end function ch_is_printable ( ch ) ! !******************************************************************************* ! !! CH_IS_PRINTABLE determines if a character is printable. ! ! ! Modified: ! ! 31 October 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character CH, a character to check. ! ! Output, logical CH_IS_PRINTABLE is TRUE if C is a printable character. ! implicit none ! character ch logical ch_is_printable integer i ! i = ichar ( ch ) if ( 32 <= i .and. i <= 127 ) then ch_is_printable = .true. else ch_is_printable = .false. end if return end subroutine chvec_print ( n, a, title ) ! !******************************************************************************* ! !! CHVEC_PRINT prints a character vector. ! ! ! Modified: ! ! 20 July 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer N, the number of components of the vector. ! ! Input, character A(N), the vector to be printed. ! ! Input, character ( len = * ) TITLE, a title to be printed first. ! TITLE may be blank. ! implicit none ! integer n ! character a(n) logical ch_is_printable integer i integer ihi integer ilo integer j character ( len = 80 ) string character ( len = * ) title ! if ( title /= ' ' ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) trim ( title ) end if write ( *, '(a)' ) ' ' do ilo = 1, n, 80 ihi = min ( ilo + 79, n ) string = ' ' do i = ilo, ihi j = i + 1 - ilo if ( ch_is_printable ( a(i) ) ) then string(j:j) = a(i) end if end do write ( *, '(a)' ) trim ( string ) end do return end subroutine get_unit ( iunit ) ! !******************************************************************************* ! !! GET_UNIT returns a free FORTRAN unit number. ! ! ! Discussion: ! ! A "free" FORTRAN unit number is an integer 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. ! ! Modified: ! ! 02 March 1999 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Output, integer IUNIT. ! ! If IUNIT = 0, then no free FORTRAN unit could be found, although ! all 99 units were checked (except for units 5 and 6). ! ! Otherwise, IUNIT is an integer 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. ! implicit none ! integer i integer ios integer iunit logical lopen iunit = 0 do i = 1, 99 if ( i /= 5 .and. i /= 6 ) 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 r4_to_b4_ieee ( r, word ) ! !******************************************************************************* ! !! R4_TO_B4_IEEE converts a real value to a 4 byte IEEE word. ! ! ! Discussion: ! ! This routine does not seem to working reliably for unnormalized data. ! ! Examples: ! ! 0 00000000 00000000000000000000000 = 0 ! 1 00000000 00000000000000000000000 = -0 ! ! 0 11111111 00000000000000000000000 = Infinity ! 1 11111111 00000000000000000000000 = -Infinity ! ! 0 11111111 00000100000000000000000 = NaN ! 1 11111111 00100010001001010101010 = NaN ! ! 0 01111110 00000000000000000000000 = +1 * 2**(126-127) * 1.0 = 0.5 ! 0 01111111 00000000000000000000000 = +1 * 2**(127-127) * 1.0 = 1 ! 0 10000000 00000000000000000000000 = +1 * 2**(128-127) * 1.0 = 2 ! 0 10000001 00000000000000000000000 = +1 * 2**(129-127) * 1.0 = 4 ! ! 0 10000001 10100000000000000000000 = +1 * 2**(129-127) * 1.101 = 6.5 ! 1 10000001 10100000000000000000000 = -1 * 2**(129-127) * 1.101 = -6.5 ! ! 0 00000001 00000000000000000000000 = +1 * 2**( 1-127) * 1.0 = 2**(-126) ! 0 00000000 10000000000000000000000 = +1 * 2**( 0-126) * 0.1 = 2**(-127) ! 0 00000000 00000000000000000000001 = +1 * 2**( 0-126) * ! 0.00000000000000000000001 = ! 2**(-149) (Smallest positive value) ! ! Reference: ! ! ANSI/IEEE Standard 754-1985, ! Standard for Binary Floating Point Arithmetic. ! ! Modified: ! ! 11 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, real R, the real number to be converted. ! ! Output, integer WORD, the IEEE representation of the number. ! implicit none ! integer e integer f real r real r_copy integer s integer word ! r_copy = r ! ! Determine S, the sign bit. ! if ( r_copy >= 0.0E+00 ) then s = 0 else s = 1 r_copy = - r_copy end if ! ! Determine E, the exponent. ! (FOR NOW, IGNORE UNNORMALIZED NUMBERS) ! e = 0 if ( r == 0.0E+00 ) then else do while ( r_copy >= 2.0E+00 ) e = e + 1 r_copy = r_copy / 2.0E+00 end do do while ( r_copy < 1.0E+00 .and. e > -127 ) e = e - 1 r_copy = r_copy * 2.0E+00 end do e = e + 127 end if ! ! Determine F, the fraction. ! if ( r == 0.0E+00 ) then f = 0 else if ( e > 0 ) then r_copy = r_copy - 1.0E+00 f = int ( r_copy * 2.0E+00**23 ) else if ( e == 0 ) then f = int ( r_copy * 2.0E+00**23 ) end if ! ! Set the bits corresponding to S, E, F. ! call mvbits ( s, 0, 1, word, 31 ) call mvbits ( e, 0, 8, word, 23 ) call mvbits ( f, 0, 23, word, 0 ) return end subroutine raw_c_count ( file_name, nchar ) ! !******************************************************************************* ! !! RAW_C_COUNT counts the number of characters in a "raw" file. ! ! ! Modified: ! ! 26 November 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) FILE_NAME, the name of the file. ! ! Output, integer NCHAR, the number of characters in the file. ! implicit none ! character c character ( len = * ) file_name integer file_rec integer file_unit integer ios integer nchar ! call raw_open ( file_name, file_unit ) nchar = 0 file_rec = 1 do call raw_c_read ( file_unit, file_rec, c, 1 ) if ( file_rec < 0 ) then exit end if nchar = nchar + 1 end do close ( unit = file_unit ) return end subroutine raw_c_read ( file_unit, file_rec, c, n ) ! !******************************************************************************* ! !! RAW_C_READ reads N characters from a raw file. ! ! ! Discussion: ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and C is set to ' '. ! ! Modified: ! ! 06 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, character C(N), the values that were read. ! ! Input, integer N, the number of values to read. ! implicit none ! integer n ! character c(n) integer file_rec integer file_unit integer i integer ios character, parameter :: NULL = char ( 0 ) ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_C_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n read ( file_unit, rec = file_rec, fmt = '(a)', iostat = ios ) c(i) if ( ios /= 0 ) then c(i:n) = NULL file_rec = -1 return end if file_rec = file_rec + 1 end do return end subroutine raw_c_write ( file_unit, file_rec, c, n ) ! !******************************************************************************* ! !! RAW_C_WRITE writes N character to a raw file. ! ! ! Discussion: ! ! On input, FILE_REC should point to the record to be written. If the first ! character is to be written, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was written. ! ! However, if an error occurred during the write, FILE_REC is set to -1. ! ! Modified: ! ! 06 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Input, character C(N), the values to be written. ! ! Input, integer N, the number of characters to write. ! implicit none ! integer n ! character c(n) integer file_rec integer file_unit integer i integer ios ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_C_WRITE - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n write ( file_unit, rec = file_rec, fmt = '(a)', iostat = ios ) c(i) if ( ios /= 0 ) then file_rec = -1 return end if file_rec = file_rec + 1 end do return end subroutine raw_open ( file_name, file_unit ) ! !******************************************************************************* ! !! RAW_OPEN opens a "raw" file. ! ! ! Discussion: ! ! A "raw" file is a file opened as a binary direct access file with ! record length of a single character. ! ! Modified: ! ! 26 November 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) FILE_NAME, the name of the file. ! ! Output, integer FILE_UNIT, the unit number associated with the file. ! implicit none ! character ( len = * ) file_name integer file_unit integer ios ! call get_unit ( file_unit ) if ( file_unit <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_OPEN - Fatal error!' write ( *, '(a)' ) ' Unable to get a unit number.' stop end if open ( unit = file_unit, file = file_name, form = 'formatted', & access = 'direct', recl = 1, status = 'old', iostat = ios ) if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_OPEN - Fatal error!' write ( *, '(a,i6)' ) ' IO error on open, IOSTAT = ', ios stop end if return end subroutine raw_r4_read ( file_unit, file_rec, r4, n ) ! !******************************************************************************* ! !! RAW_R4_READ reads the "next" 4 byte real from a raw file. ! ! ! Discussion: ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and I is set to 0. ! ! Modified: ! ! 05 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, real R4(N), the values that were read. ! ! Input, integer N, the number of values to read. ! implicit none ! integer n ! integer bytes(4) logical byte_swap character ( len = 4 ) c4 integer file_rec integer file_unit integer i integer nbytes real r4(n) ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_R4_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n ! ! Read 4 characters from the file. ! call raw_c_read ( file_unit, file_rec, c4, 4 ) ! ! Byte swap if necessary. ! call byte_swap_get ( byte_swap, nbytes, bytes ) if ( byte_swap ) then call s_byte_swap ( nbytes, bytes, c4 ) end if ! ! Read the 4 characters as a real value. ! read ( c4, '(a4)' ) r4(i) end do return end subroutine raw_r8_read ( file_unit, file_rec, r8, n ) ! !******************************************************************************* ! !! RAW_R8_READ reads the "next" 8 byte real from a raw file. ! ! ! Discussion: ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and I is set to 0. ! ! Modified: ! ! 05 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, real R8(N), the values that were read. ! ! Input, integer N, the number of values to read. ! implicit none ! integer n ! integer bytes(8) logical byte_swap character ( len = 8 ) c8 integer file_rec integer file_unit integer i integer nbytes real r8(n) ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_R4_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n ! ! Read 8 characters from the file. ! call raw_c_read ( file_unit, file_rec, c8, 8 ) ! ! Byte swap if necessary. ! call byte_swap_get ( byte_swap, nbytes, bytes ) if ( byte_swap ) then call s_byte_swap ( nbytes, bytes, c8 ) end if ! ! Read the 8 characters as a real value. ! read ( c8, '(a8)' ) r8(i) end do return end subroutine raw_s_read ( file_unit, file_rec, s ) ! !******************************************************************************* ! !! RAW_S_READ reads the "next" string from a raw file. ! ! ! Discussion: ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and S is set to ' '. ! ! Modified: ! ! 28 November 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, character ( len = * ) S, the string that was read. ! implicit none ! integer file_rec integer file_unit integer i integer ios character ( len = * ) s integer s_len ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_S_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if s_len = len ( s ) do i = 1, s_len read ( file_unit, rec = file_rec, fmt = '(a)', iostat = ios ) s(i:i) if ( ios == 0 ) then file_rec = file_rec + 1 else file_rec = -1 s(i:) = ' ' return end if end do return end subroutine raw_si1_read ( file_unit, file_rec, i1, n ) ! !******************************************************************************* ! !! RAW_SI1_READ reads N signed 1 byte integers from a raw file. ! ! ! Discussion: ! ! A signed 1 byte integer is a value between -128 and +127. ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been incremented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and I is set to 0. ! ! Modified: ! ! 05 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, integer I1(N), the values that were read. ! ! Input, integer N, the number of values to read. ! implicit none ! integer n ! character c1 integer file_rec integer file_unit integer i integer i1(n) ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_SI1_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n ! ! Read 1 character from the file. ! print*,i,file_rec call raw_c_read ( file_unit, file_rec, c1, 1 ) ! ! Interpret the character as an integer. ! call b1_to_si1 ( c1, i1(i) ) end do return end subroutine raw_si1_write ( file_unit, file_rec, i1, n ) ! !******************************************************************************* ! !! RAW_SI1_WRITE writes N 1 byte signed integers to a raw file. ! ! ! Discussion: ! ! A signed 1 byte integer is a value between -128 and +127. ! ! On input, FILE_REC should point to the record to be written. If the first ! character is to be written, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was written. ! ! However, if an error occurred during the write, FILE_REC is set to -1. ! ! Modified: ! ! 06 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Input, integer I1(N), the values to be written. ! ! Input, integer N, the number of values to write. ! implicit none ! integer n ! character c1 integer file_rec integer file_unit integer i integer i1(n) integer ios ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_SI1_WRITE - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n call si1_to_b1 ( i1(i), c1 ) write ( file_unit, rec = file_rec, fmt = '(a)', iostat = ios ) c1 if ( ios /= 0 ) then file_rec = -1 return end if file_rec = file_rec + 1 end do return end subroutine raw_si2_read ( file_unit, file_rec, i2, n ) ! !******************************************************************************* ! !! RAW_SI2_READ reads N 2 byte signed integers from a raw file. ! ! ! Discussion: ! ! A signed 2 byte integer is a value between -32768 and +32767. ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and I is set to 0. ! ! Modified: ! ! 06 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, integer I2(N), the values that were read. ! ! Input, integer N, the number of values to read. ! implicit none ! integer n ! integer bytes(2) logical byte_swap character c(2) integer file_rec integer file_unit integer i integer i2(n) integer nbytes ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_SI2_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n ! ! Read 2 characters from the file. ! call raw_c_read ( file_unit, file_rec, c, 2 ) ! ! Byte swap if necessary. ! call byte_swap_get ( byte_swap, nbytes, bytes ) if ( byte_swap ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_SI2_READ - Do byte swapping!' write ( *, '(a,2i2)' ) ' BYTES=', bytes(1), bytes(2) ! call c_byte_swap ( nbytes, bytes, c, 2 ) end if ! ! Read the characters as an integer. ! call b2_to_si2 ( c, i2(i) ) end do return end subroutine raw_si2_write ( file_unit, file_rec, i2, n ) ! !******************************************************************************* ! !! RAW_SI2_WRITE writes N 2 byte signed integers to a raw file. ! ! ! Discussion: ! ! A signed 2 byte integer is a value between -32768 and +32767. ! ! On input, FILE_REC should point to the record to be written. If the first ! character is to be written, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was written. ! ! However, if an error occurred during the write, FILE_REC is set to -1. ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Input, integer I2(N), the values to be written. ! ! Input, integer N, the number of values to write. ! implicit none ! integer n ! character c(2) integer file_rec integer file_unit integer i integer i2(n) integer ios integer j ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_SI2_WRITE - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if ! ! What about BYTE_SWAPPING? ! do i = 1, n call si2_to_b2 ( i2(i), c ) do j = 1, 2 write ( file_unit, rec = file_rec, fmt = '(a)', iostat = ios ) c(j) if ( ios /= 0 ) then file_rec = -1 return end if file_rec = file_rec + 1 end do end do return end subroutine raw_si4_read ( file_unit, file_rec, i4, n ) ! !******************************************************************************* ! !! RAW_SI4_READ reads N 4 byte signed integers from a raw file. ! ! ! Discussion: ! ! A signed 4 byte integer is a value between -2147483648 and +2147483647. ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and I is set to 0. ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, integer I4(N), the values that were read. ! ! Input, integer N, the number of values to read. ! implicit none ! integer n ! integer bytes(4) logical byte_swap character c(4) integer file_rec integer file_unit integer i integer i4(n) integer nbytes ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_SI4_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n ! ! Read 4 characters from the file. ! call raw_c_read ( file_unit, file_rec, c, 4 ) ! ! Byte swap if necessary. ! call byte_swap_get ( byte_swap, nbytes, bytes ) if ( byte_swap ) then call s_byte_swap ( nbytes, bytes, 4 ) end if ! ! Read the characters as an integer. ! call b4_to_si4 ( c, i4(i) ) end do return end subroutine raw_si4_write ( file_unit, file_rec, i4, n ) ! !******************************************************************************* ! !! RAW_SI4_WRITE writes N 4 byte signed integers to a raw file. ! ! ! Discussion: ! ! A signed 4 byte integer is a value between -2147483648 and +2147483647. ! ! On input, FILE_REC should point to the record to be written. If the first ! character is to be written, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was written. ! ! However, if an error occurred during the write, FILE_REC is set to -1. ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Input, integer I4(N), the values to be written. ! ! Input, integer N, the number of values to write. ! implicit none ! integer n ! character c(4) integer file_rec integer file_unit integer i integer i4(n) integer ios integer j ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_SI4_WRITE - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if ! ! What about BYTE_SWAPPING? ! do i = 1, n call si4_to_b4 ( i4(i), c ) do j = 1, 4 write ( file_unit, rec = file_rec, fmt = '(a)', iostat = ios ) c(j) if ( ios /= 0 ) then file_rec = -1 return end if file_rec = file_rec + 1 end do end do return end subroutine raw_ui1_read ( file_unit, file_rec, i1, n ) ! !******************************************************************************* ! !! RAW_UI1_READ reads N unsigned 1 byte integers from a raw file. ! ! ! Discussion: ! ! An unsigned 1 byte integer is a value between 0 and +255. ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been incremented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and I is set to 0. ! ! Modified: ! ! 05 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, integer I1(N), the values that were read. ! ! Input, integer N, the number of values to read. ! implicit none ! integer n ! character c1 integer file_rec integer file_unit integer i integer i1(n) ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_UI1_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n ! ! Read 1 character from the file. ! call raw_c_read ( file_unit, file_rec, c1, 1 ) ! ! Read the character as an unsigned integer. ! call b1_to_ui1 ( c1, i1(i) ) end do return end subroutine raw_ui1_write ( file_unit, file_rec, i1, n ) ! !******************************************************************************* ! !! RAW_UI1_WRITE writes N 1 byte unsigned integers to a raw file. ! ! ! Discussion: ! ! An unsigned 1 byte integer is a value between 0 and +255. ! ! On input, FILE_REC should point to the record to be written. If the first ! character is to be written, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was written. ! ! However, if an error occurred during the write, FILE_REC is set to -1. ! ! Modified: ! ! 06 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Input, integer I1(N), the values to be written. ! ! Input, integer N, the number of values to write. ! implicit none ! integer n ! character c1 integer file_rec integer file_unit integer i integer i1(n) integer ios ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_UI1_WRITE - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n call ui1_to_b1 ( i1(i), c1 ) write ( file_unit, rec = file_rec, fmt = '(a)', iostat = ios ) c1 if ( ios /= 0 ) then file_rec = -1 return end if file_rec = file_rec + 1 end do return end subroutine raw_ui2_read ( file_unit, file_rec, i2, n ) ! !******************************************************************************* ! !! RAW_UI2_READ reads N 2 byte unsigned integers from a raw file. ! ! ! Discussion: ! ! An unsigned 2 byte integer is a value between 0 and +65535. ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and I is set to 0. ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, integer I2(N), the values that were read. ! ! Input, integer N, the number of values to read. ! implicit none ! integer n ! integer bytes(2) logical byte_swap character c(2) integer file_rec integer file_unit integer i integer i2(n) integer nbytes ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_UI2_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n ! ! Read 2 characters from the file. ! call raw_c_read ( file_unit, file_rec, c, 2 ) ! ! Byte swap if necessary. ! call byte_swap_get ( byte_swap, nbytes, bytes ) if ( byte_swap ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_UI2_READ - Byte swap!' write ( *, '(a,2i2)' ) ' BYTES=', bytes(1), bytes(2) ! call c_byte_swap ( nbytes, bytes, c, 2 ) end if ! ! Read the characters as an integer. ! call b2_to_ui2 ( c, i2(i) ) end do return end subroutine raw_ui2_write ( file_unit, file_rec, i2, n ) ! !******************************************************************************* ! !! RAW_UI2_WRITE writes N 2 byte unsigned integers to a raw file. ! ! ! Discussion: ! ! An unsigned 2 byte integer is a value between 0 and +65535. ! ! On input, FILE_REC should point to the record to be written. If the first ! character is to be written, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was written. ! ! However, if an error occurred during the write, FILE_REC is set to -1. ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Input, integer I2(N), the values to be written. ! ! Input, integer N, the number of values to write. ! implicit none ! integer n ! character c(2) integer file_rec integer file_unit integer i integer i2(n) integer ios integer j ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_UI2_WRITE - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if ! ! What about BYTE_SWAPPING? ! do i = 1, n call ui2_to_b2 ( i2(i), c ) do j = 1, 2 write ( file_unit, rec = file_rec, fmt = '(a)', iostat = ios ) c(j) if ( ios /= 0 ) then file_rec = -1 return end if file_rec = file_rec + 1 end do end do return end subroutine raw_ui4_read ( file_unit, file_rec, i4, n ) ! !******************************************************************************* ! !! RAW_UI4_READ reads N 4 byte unsigned integers from a raw file. ! ! ! Discussion: ! ! An unsigned 4 byte integer is a value between 0 and +4294967295. ! ! On input, FILE_REC should point to the record to be read. If the first ! character is to be read, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was read. ! ! However, if there was no record corresponding to the input value of ! FILE_REC, then FILE_REC is set to -1, and I is set to 0. ! ! Modified: ! ! 06 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Output, integer I4(N), the values that were read. ! ! Input, integer N, the number of values to read. ! implicit none ! integer n ! integer bytes(4) logical byte_swap character c(4) integer file_rec integer file_unit integer i integer i4(n) integer nbytes ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_UI4_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if do i = 1, n ! ! Read 4 characters from the file. ! call raw_c_read ( file_unit, file_rec, c, 4 ) ! ! Byte swap if necessary. ! call byte_swap_get ( byte_swap, nbytes, bytes ) if ( byte_swap ) then call s_byte_swap ( nbytes, bytes, 4 ) end if ! ! Read the characters as an integer. ! call b4_to_ui4 ( c, i4(i) ) end do return end subroutine raw_ui4_write ( file_unit, file_rec, i4, n ) ! !******************************************************************************* ! !! RAW_UI4_WRITE writes N 4 byte unsigned integers to a raw file. ! ! ! Discussion: ! ! An unsigned 4 byte integer is a value between 0 and +4294967295. ! ! On input, FILE_REC should point to the record to be written. If the first ! character is to be written, then FILE_REC should be 1. ! ! On output, FILE_REC will have been implemented to point to the next ! record after the data that was written. ! ! However, if an error occurred during the write, FILE_REC is set to -1. ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer FILE_UNIT, the name of the file. ! ! Input/output, integer FILE_REC, the record pointer. ! ! Input, integer I4(N), the values to be written. ! ! Input, integer N, the number of values to write. ! implicit none ! integer n ! character c(4) integer file_rec integer file_unit integer i integer i4(n) integer ios integer j ! if ( file_rec <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RAW_UI4_WRITE - Fatal error!' write ( *, '(a,i6)' ) ' Illegal record number = ', file_rec stop end if ! ! What about BYTE_SWAPPING? ! do i = 1, n call ui4_to_b4 ( i4(i), c ) do j = 1, 4 write ( file_unit, rec = file_rec, fmt = '(a)', iostat = ios ) c(j) if ( ios /= 0 ) then file_rec = -1 return end if file_rec = file_rec + 1 end do end do return end subroutine s_byte_swap ( nbytes, bytes, s ) ! !******************************************************************************* ! !! S_BYTE_SWAP swaps the bytes in a string. ! ! ! Modified: ! ! 31 May 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer NBYTES, the number of bytes in the swapping pattern. ! ! Input, integer BYTES(NBYTES), the byte swap pattern. ! ! Input/output, character ( len = * ) S, a string whose bytes are to ! be swapped. ! implicit none ! integer nbytes ! integer bytes(nbytes) integer i integer i2 integer j integer n character ( len = * ) s character ( len = 256 ) t ! n = len ( s ) do i = 1, n i2 = mod ( i - 1, nbytes ) + 1 j = bytes(i2) t(i:i) = s(j:j) end do s(1:n) = t(1:n) return end subroutine si1_to_b1 ( i1, b1 ) ! !******************************************************************************* ! !! SI1_TO_B1 converts a signed integer to one byte. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer I1, the signed integer. ! ! Output, character B1, the corresponding byte. ! implicit none ! character b1 integer i1 ! b1 = char ( i1 + 128 ) return end subroutine si2_to_b2 ( i2, b2 ) ! !******************************************************************************* ! !! SI2_TO_B2 converts a signed integer to two bytes. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer I2, the signed integer. ! ! Output, character B2(2), the corresponding bytes. ! implicit none ! character b2(2) integer i2 integer i2_digit integer i2_temp integer j ! ! Convert to unsigned form. ! i2_temp = i2 + 32768 do j = 2, 1, -1 i2_digit = mod ( i2_temp, 256 ) b2(j) = char ( i2_digit ) i2_temp = i2_temp / 256 end do return end subroutine si4_to_b4 ( i4, b4 ) ! !******************************************************************************* ! !! SI4_TO_B4 converts a signed integer to four bytes. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer I4, the signed integer. ! ! Output, character B4(4), the corresponding bytes. ! implicit none ! character b4(4) integer i4 integer i4_digit integer i4_temp integer j ! ! Convert to unsigned form. ! i4_temp = i4 + 2147483648 do j = 4, 1, -1 i4_digit = mod ( i4_temp, 256 ) b4(j) = char ( i4_digit ) i4_temp = i4_temp / 256 end do return end subroutine timestamp ( ) ! !******************************************************************************* ! !! TIMESTAMP prints the current YMDHMS date as a time stamp. ! ! ! Example: ! ! May 31 2001 9:45:54.872 AM ! ! Modified: ! ! 31 May 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! None ! implicit none ! character ( len = 8 ) ampm integer d character ( len = 8 ) date 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 character ( len = 10 ) time integer values(8) integer y character ( len = 5 ) zone ! call date_and_time ( date, time, zone, 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 ( *, '(a,1x,i2,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) & trim ( month(m) ), d, y, h, ':', n, ':', s, '.', mm, trim ( ampm ) return end subroutine ui1_to_b1 ( i1, b1 ) ! !******************************************************************************* ! !! UI1_TO_B1 converts an unsigned integer to one byte. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer I1, the unsigned integer. ! ! Output, character B1, the corresponding byte. ! implicit none ! character b1 integer i1 ! b1 = char ( i1 ) return end subroutine ui2_to_b2 ( i2, b2 ) ! !******************************************************************************* ! !! UI2_TO_B2 converts an unsigned integer to two bytes. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer I2, the unsigned integer. ! ! Output, character B2(2), the corresponding bytes. ! implicit none ! character b2(2) integer i2 integer i2_digit integer i2_temp integer j ! i2_temp = i2 do j = 2, 1, -1 i2_digit = mod ( i2_temp, 256 ) b2(j) = char ( i2_digit ) i2_temp = i2_temp / 256 end do return end subroutine ui4_to_b4 ( i4, b4 ) ! !******************************************************************************* ! !! UI4_TO_B4 converts an unsigned integer to four bytes. ! ! ! Modified: ! ! 07 November 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer I4, the unsigned integer. ! ! Output, character B4(4), the corresponding bytes. ! implicit none ! character b4(4) integer i4 integer i4_digit integer i4_temp integer j ! i4_temp = i4 do j = 4, 1, -1 i4_digit = mod ( i4_temp, 256 ) b4(j) = char ( i4_digit ) i4_temp = i4_temp / 256 end do return end