program grf_to_eps_main ! !******************************************************************************* ! !! GRF_TO_EPS_MAIN takes a GRF file and creates an Encapsulated PostScript image. ! ! ! Usage: ! ! grf_to_eps file.grf file.eps ! ! Modified: ! ! 17 May 2001 ! ! Author: ! ! John Burkardt ! implicit none ! integer iarg integer iargc integer ierror integer ilen character ( len = 100 ) input_file integer ios integer ipxfargc integer num_arg character ( len = 100 ) output_file ! call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_TO_EPS_MAIN' write ( *, '(a)' ) ' Read a GRF file;' write ( *, '(a)' ) ' Write an Encapsulated PostScript image file.' ! ! Get the number of command line arguments. ! ! Old style: ! num_arg = iargc ( ) ! ! New style: ! ! num_arg = ipxfargc ( ) ! ! If at least one command line argument, it's the input file name. ! if ( num_arg < 1 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'Enter the input file name:' read ( *, '(a)', iostat = ios ) input_file if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_TO_EPS_MAIN - Fatal error!' write ( *, '(a)' ) ' Unexpected read error!' stop end if else iarg = 1 ! ! Old style: ! call getarg ( iarg, input_file ) ! ! New style: ! ! call pxfgetarg ( iarg, input_file, ilen, ierror ) ! ! if ( ierror /= 0 ) then ! write ( *, '(a)' ) ' ' ! write ( *, '(a)' ) 'GRF_TO_EPS_MAIN - Fatal error!' ! write ( *, '(a)' ) ' Could not read command line argument.' ! stop ! end if end if ! ! If two command line arguments, the second one is the output file name. ! if ( num_arg < 2 ) then output_file = input_file call file_name_ext_swap ( output_file, 'eps' ) else iarg = 2 ! ! Old style: ! call getarg ( iarg, output_file ) ! ! New style: ! ! call pxfgetarg ( iarg, output_file, ilen, ierror ) ! ! if ( ierror /= 0 ) then ! write ( *, '(a)' ) ' ' ! write ( *, '(a)' ) 'GRF_TO_EPS_MAIN - Fatal error!' ! write ( *, '(a)' ) ' Could not read command line argument.' ! stop ! end if end if ! ! Now we know what to do. ! call grf_to_eps ( input_file, output_file ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_TO_EPS_MAIN' write ( *, '(a)' ) ' Normal end of execution.' stop end subroutine ch_cap ( c ) ! !******************************************************************************* ! !! CH_CAP capitalizes a single character. ! ! ! Modified: ! ! 19 July 1998 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input/output, character C, the character to capitalize. ! implicit none ! character c integer itemp ! itemp = ichar ( c ) if ( 97 <= itemp .and. itemp <= 122 ) then c = char ( itemp - 32 ) end if return end function ch_eqi ( c1, c2 ) ! !******************************************************************************* ! !! CH_EQI is a case insensitive comparison of two characters for equality. ! ! ! Examples: ! ! CH_EQI ( 'A', 'a' ) is .TRUE. ! ! Modified: ! ! 28 July 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character C1, C2, the characters to compare. ! ! Output, logical CH_EQI, the result of the comparison. ! implicit none ! logical ch_eqi character c1 character c1_cap character c2 character c2_cap ! c1_cap = c1 c2_cap = c2 call ch_cap ( c1_cap ) call ch_cap ( c2_cap ) if ( c1_cap == c2_cap ) then ch_eqi = .true. else ch_eqi = .false. end if return end subroutine ch_to_digit ( c, digit ) ! !******************************************************************************* ! !! CH_TO_DIGIT returns the integer value of a base 10 digit. ! ! ! Example: ! ! C DIGIT ! --- ----- ! '0' 0 ! '1' 1 ! ... ... ! '9' 9 ! ' ' 0 ! 'X' -1 ! ! Modified: ! ! 04 August 1999 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character C, the decimal digit, '0' through '9' or blank ! are legal. ! ! Output, integer DIGIT, the corresponding integer value. If C was ! 'illegal', then DIGIT is -1. ! implicit none ! character c integer digit ! if ( lge ( c, '0' ) .and. lle ( c, '9' ) ) then digit = ichar ( c ) - 48 else if ( c == ' ' ) then digit = 0 else digit = -1 end if return end subroutine file_name_ext_get ( file_name, i, j ) ! !******************************************************************************* ! !! FILE_NAME_EXT_GET determines the "extension" of a file name. ! ! ! Definition: ! ! The "extension" of a filename is the string of characters ! that appears after the LAST period in the name. A file ! with no period, or with a period as the last character ! in the name, has a "null" extension. ! ! Note: ! ! Blanks are unusual in filenames. This routine ignores all ! trailing blanks, but will treat initial or internal blanks ! as regular characters acceptable in a file name. ! ! Examples: ! ! FILE_NAME I J ! ! bob.for 4 7 ! N.B.C.D 6 7 ! Naomi. 6 6 ! Arthur 0 0 ! .com 1 1 ! ! Modified: ! ! 17 July 1998 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) FILE_NAME, a file name to be examined. ! ! Output, integer I, J, the indices of the first and last characters ! in the file extension. ! ! If no period occurs in FILE_NAME, then ! I = J = 0; ! Otherwise, ! I is the position of the LAST period in FILE_NAME, and J is the ! position of the last nonblank character following the period. ! implicit none ! character ( len = * ) file_name integer i integer j integer s_index_last ! i = s_index_last ( file_name, '.' ) if ( i /= 0 ) then j = len_trim ( file_name ) else j = 0 end if return end subroutine file_name_ext_swap ( file_name, ext ) ! !******************************************************************************* ! !! FILE_NAME_EXT_SWAP replaces the current "extension" of a file name. ! ! ! Definition: ! ! The "extension" of a filename is the string of characters ! that appears after the LAST period in the name. A file ! with no period, or with a period as the last character ! in the name, has a "null" extension. ! ! Examples: ! ! Input Output ! ================ ========= ! FILE_NAME EXT FILE_NAME ! ! bob.for obj bob.obj ! bob.bob.bob txt bob.bob.txt ! bob yak bob.yak ! ! Modified: ! ! 09 August 1999 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input/output, character ( len = * ) FILE_NAME, a file name. ! On output, the extension of the file has been changed. ! ! Input, character ( len = * ) EXT, the extension to be used on the output ! copy of FILE_NAME, replacing the current extension if any. ! implicit none ! character ( len = * ) ext character ( len = * ) file_name integer i integer j integer len_max integer len_name ! len_max = len ( file_name ) len_name = len_trim ( file_name ) call file_name_ext_get ( file_name, i, j ) if ( i == 0 ) then if ( len_name + 1 > len_max ) then return end if len_name = len_name + 1 file_name(len_name:len_name) = '.' i = len_name + 1 else i = i + 1 file_name(i:j) = ' ' end if file_name(i:) = ext return end subroutine graph_arc_to_eps ( output_file, inode, jnode, nedge, & nnode, x, y ) ! !******************************************************************************* ! !! GRAPH_ARC_TO_EPS writes graph information to an Encapsulated PostScript file. ! ! ! Modified: ! ! 10 October 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) OUTPUT_FILE, the name of the output file. ! ! Input, integer INODE(NEDGE), JNODE(NEDGE), the edge array. ! The I-th edge connects nodes INODE(I) and JNODE(I). ! ! Input, integer NEDGE, the number of edges. ! ! Input, integer NNODE, the number of nodes. ! ! Input, real X(NNODE), Y(NNODE), the X and Y components of points. ! implicit none ! integer nedge integer nnode ! real blue real green integer i integer i1 integer i2 integer ierror integer inode(nedge) integer jnode(nedge) integer line_width integer marker_size character ( len = * ) output_file integer output_unit real red real x(nnode) real xmax real xmin real y(nnode) real ymax real ymin ! ! Open the file. ! call get_unit ( output_unit ) call ps_file_open ( output_file, output_unit, ierror ) ! ! Write the header. ! call eps_file_head ( output_file ) ! ! Determine the bounding box. ! xmin = minval ( x(1:nnode) ) xmax = maxval ( x(1:nnode) ) ymin = minval ( y(1:nnode) ) ymax = maxval ( y(1:nnode) ) if ( xmin == xmax ) then xmin = x(1) - 0.5E+00 xmax = x(1) + 0.5E+00 end if if ( ymin == ymax ) then ymin = y(1) - 0.5E+00 ymax = y(1) + 0.5E+00 end if call ps_page_head ( xmin, ymin, xmax, ymax ) ! ! Draw the nodes using filled circles. ! marker_size = 10 call ps_setting_int ( 'SET', 'MARKER_SIZE', marker_size ) red = 0.1E+00 green = 0.1E+00 blue = 0.7E+00 call ps_color_fill_set ( red, green, blue ) do i = 1, nnode call ps_mark_disk ( x(i), y(i) ) end do ! ! Draw lines between neighboring nodes. ! line_width = 2 call ps_line_width ( line_width ) red = 0.8E+00 green = 0.2E+00 blue = 0.2E+00 call ps_color_line_set ( red, green, blue ) do i = 1, nedge i1 = inode(i) i2 = jnode(i) call ps_line ( x(i1), y(i1), x(i2), y(i2) ) end do ! ! End the page. ! call ps_page_tail ! ! End the file. ! call eps_file_tail ! ! Close the file. ! call ps_file_close ( output_unit ) return end subroutine grf_read ( input_unit, inode, jnode, maxedge, maxnode, nedge, & nnode, x, y ) ! !******************************************************************************* ! !! GRF_READ reads a GRF file containing a 2D representation of a graph. ! ! ! Example: ! ! # A graph where every node has 3 neighbors. ! # ! 1 0.546 0.956 5 6 2 ! 2 0.144 0.650 7 3 1 ! 3 0.326 0.188 8 4 2 ! 4 0.796 0.188 9 5 3 ! 5 0.988 0.646 10 4 1 ! 6 0.552 0.814 11 12 1 ! 7 0.264 0.616 11 15 2 ! 8 0.404 0.296 15 14 3 ! 9 0.752 0.298 14 13 4 ! 10 0.846 0.624 13 12 5 ! 11 0.430 0.692 16 6 7 ! 12 0.682 0.692 17 10 6 ! 13 0.758 0.492 18 9 10 ! 14 0.566 0.358 19 8 9 ! 15 0.364 0.484 20 7 8 ! 16 0.504 0.602 11 20 17 ! 17 0.608 0.602 12 18 16 ! 18 0.634 0.510 13 19 17 ! 19 0.566 0.444 14 20 18 ! 20 0.480 0.510 15 16 19 ! ! Discussion: ! ! The original GRF format has been modified so that a line starting ! with a # is considered a comment line. ! ! Modified: ! ! 17 May 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer INPUT_UNIT, the FORTRAN unit number associated with the ! graph file, which should already have been opened by the user. ! ! Output, integer INODE(MAXEDGE), JNODE(MAXEDGE), the edges. ! The I-th edge joins nodes INODE(I) and JNODE(I). ! ! Input, integer MAXEDGE, the maximum number of edges. ! ! Input, integer MAXNODE, the maximum number of nodes. ! ! Output, integer NEDGE, the number of edges that were read. ! ! Output, integer NNODE, the number of nodes that were read. ! ! Output, real X(MAXNODE), Y(MAXNODE), the X and Y coordinates of the ! nodes. ! implicit none ! integer, parameter :: maxchr = 200 ! integer maxedge integer maxnode ! integer ierror integer inode(maxedge) integer ios integer istring integer input_unit integer jnode(maxedge) integer lchar integer nbad integer nedge integer nnode integer nodei integer nodej integer ntext character ( len = maxchr ) string real x(maxnode) real xval real y(maxnode) real yval ! nbad = 0 nedge = 0 nnode = 0 ntext = 0 ! ! Read information about each node. ! do read ( input_unit, '(a)', iostat = ios ) string if ( ios /= 0 ) then exit end if ntext = ntext + 1 if ( len ( string ) <= 0 ) then cycle end if if ( string(1:1) == '#' ) then cycle end if istring = 1 ! ! Extract the node index, NODEI. ! call s_to_i ( string(istring:), nodei, ierror, lchar ) if ( ierror /= 0 .or. lchar == 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_READ - Fatal error!' write ( *, '(a)' ) ' Unreadable node index value.' nbad = nbad + 1 cycle end if istring = istring + lchar if ( nodei < 1 .or. maxnode < nodei ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_READ - Fatal error!' write ( *, '(a,i6)' ) ' Illegal node index value, NODEI = ', nodei cycle end if if ( nodei == nnode + 1 ) then nnode = nnode + 1 else if ( nodei > nnode ) then nnode = nodei end if ! ! Extract the X, Y coordinates of the node. ! call s_to_r ( string(istring:), xval, ierror, lchar ) if ( ierror /= 0 .or. lchar == 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_READ - Fatal error!' write ( *, '(a)' ) ' Unreadable X coordinate for node.' nbad = nbad + 1 cycle end if istring = istring + lchar call s_to_r ( string(istring:), yval, ierror, lchar ) if ( ierror /= 0 .or. lchar == 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_READ - Fatal error!' write ( *, '(a)' ) ' Unreadable Y coordinate for node.' nbad = nbad + 1 cycle end if istring = istring + lchar x(nodei) = xval y(nodei) = yval ! ! Read the indices of the nodes to which NODEI is connected. ! do call s_to_i ( string(istring:), nodej, ierror, lchar ) if ( ierror /= 0 .and. ierror /= 1 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_READ - Fatal error!' write ( *, '(a)' ) ' Unreadable node neighbor value.' nbad = nbad + 1 cycle end if istring = istring + lchar if ( lchar <= 0 ) then exit end if if ( 1 <= nodej .and. nodej <= maxnode ) then if ( nedge < maxedge ) then nedge = nedge + 1 inode(nedge) = nodei jnode(nedge) = nodej end if end if if ( istring > maxchr ) then exit end if end do end do write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_READ - Input file statistics:' write ( *, '(a,i6)' ) ' Text lines: ', ntext write ( *, '(a,i6)' ) ' Bad text lines: ', nbad write ( *, '(a,i6)' ) ' Nodes: ', nnode write ( *, '(a,i6)' ) ' Edges: ', nedge return end subroutine grf_to_eps ( input_file, output_file ) ! !******************************************************************************* ! !! GRF_TO_EPS creates an EPS image of the graph described by a GRF file. ! ! ! Discussion: ! ! "EPS" stands for Encapsulated PostScript file. ! ! Modified: ! ! 17 February 2002 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) INPUT_FILE, the name of the input file. ! ! Input, character ( len = * ) OUTPUT_FILE, the name of the output file. ! implicit none ! integer, parameter :: maxedge = 500 integer, parameter :: maxnode = 100 integer, parameter :: lda = maxnode ! integer adj(lda,maxnode) integer i integer inode(maxedge) character ( len = * ) input_file integer, parameter :: input_unit = 1 integer jnode(maxedge) integer nedge integer nnode character ( len = * ) output_file real x(maxnode) real y(maxnode) ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_TO_EPS' write ( *, '(a)' ) ' Read GRF file: "' // trim ( input_file ) // '".' open ( unit = input_unit, file = input_file, status = 'old' ) call grf_read ( input_unit, inode, jnode, maxedge, maxnode, nedge, nnode, x, y ) close ( unit = input_unit ) ! ! Now write out an Encapsulated PostScript version. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'GRF_TO_EPS' write ( *, '(a)' ) ' Write EPS file: "' // trim ( output_file ) // '".' call graph_arc_to_eps ( output_file, inode, jnode, nedge, & nnode, x, y ) return end function s_index_last ( s, sub ) ! !******************************************************************************* ! !! S_INDEX_LAST finds the LAST occurrence of a given substring. ! ! ! Discussion: ! ! It returns the location in the string at which the substring SUB is ! first found, or 0 if the substring does not occur at all. ! ! The routine is also trailing blank insensitive. This is very ! important for those cases where you have stored information in ! larger variables. If S is of length 80, and SUB is of ! length 80, then if S = 'FRED' and SUB = 'RED', a match would ! not be reported by the standard FORTRAN INDEX, because it treats ! both variables as being 80 characters long! This routine assumes that ! trailing blanks represent garbage! ! ! This means that this routine cannot be used to find, say, the last ! occurrence of a substring 'A ', since it assumes the blank space ! was not specified by the user, but is, rather, padding by the ! system. However, as a special case, this routine can properly handle ! the case where either S or SUB is all blanks. ! ! Modified: ! ! 14 April 1999 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) S, the string to be searched. ! ! Input, character ( len = * ) SUB, the substring to search for. ! ! Output, integer S_INDEX_LAST. 0 if SUB does not occur in ! the string. Otherwise S_INDEX_LAST = I, where S(I:I+LENS-1) = SUB, ! where LENS is the length of SUB, and is the last place ! this happens. ! implicit none ! integer i integer j integer llen1 integer llen2 character ( len = * ) s integer s_index_last character ( len = * ) sub ! s_index_last = 0 llen1 = len_trim ( s ) llen2 = len_trim ( sub ) ! ! In case S or SUB is blanks, use LEN ! if ( llen1 == 0 ) then llen1 = len ( s ) end if if ( llen2 == 0 ) then llen2 = len ( sub ) end if if ( llen2 > llen1 ) then return end if do j = 1, llen1+1-llen2 i = llen1 + 2 - llen2 - j if ( s(i:i+llen2-1) == sub ) then s_index_last = i return end if end do return end subroutine s_to_i ( s, ival, ierror, last ) ! !******************************************************************************* ! !! S_TO_I reads an integer value from a string. ! ! ! Modified: ! ! 28 June 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) S, a string to be examined. ! ! Output, integer IVAL, the integer value read from the string. ! If the string is blank, then IVAL will be returned 0. ! ! Output, integer IERROR, an error flag. ! 0, no error. ! 1, an error occurred. ! ! Output, integer LAST, the last character of S used to make IVAL. ! implicit none ! character c integer i integer ierror integer isgn integer istate integer ival integer last character ( len = * ) s ! ierror = 0 istate = 0 isgn = 1 ival = 0 do i = 1, len_trim ( s ) c = s(i:i) ! ! Haven't read anything. ! if ( istate == 0 ) then if ( c == ' ' ) then else if ( c == '-' ) then istate = 1 isgn = -1 else if ( c == '+' ) then istate = 1 isgn = + 1 else if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then istate = 2 ival = ichar ( c ) - ichar ( '0' ) else ierror = 1 return end if ! ! Have read the sign, expecting digits. ! else if ( istate == 1 ) then if ( c == ' ' ) then else if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then istate = 2 ival = ichar ( c ) - ichar ( '0' ) else ierror = 1 return end if ! ! Have read at least one digit, expecting more. ! else if ( istate == 2 ) then if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then ival = 10 * ival + ichar ( c ) - ichar ( '0' ) else ival = isgn * ival last = i - 1 return end if end if end do ! ! If we read all the characters in the string, see if we're OK. ! if ( istate == 2 ) then ival = isgn * ival last = len_trim ( s ) else ierror = 1 last = 0 end if return end subroutine s_to_r ( s, r, ierror, lchar ) ! !******************************************************************************* ! !! S_TO_R reads a real number from a string. ! ! ! Discussion: ! ! This routine will read as many characters as possible until it reaches ! the end of the string, or encounters a character which cannot be ! part of the real number. ! ! Legal input is: ! ! 1 blanks, ! 2 '+' or '-' sign, ! 2.5 spaces ! 3 integer part, ! 4 decimal point, ! 5 fraction part, ! 6 'E' or 'e' or 'D' or 'd', exponent marker, ! 7 exponent sign, ! 8 exponent integer part, ! 9 exponent decimal point, ! 10 exponent fraction part, ! 11 blanks, ! 12 final comma or semicolon. ! ! with most quantities optional. ! ! Examples: ! ! S R ! ! '1' 1.0 ! ' 1 ' 1.0 ! '1A' 1.0 ! '12,34,56' 12.0 ! ' 34 7' 34.0 ! '-1E2ABCD' -100.0 ! '-1X2ABCD' -1.0 ! ' 2E-1' 0.2 ! '23.45' 23.45 ! '-4.2E+2' -420.0 ! '17d2' 1700.0 ! '-14e-2' -0.14 ! 'e2' 100.0 ! '-12.73e-9.23' -12.73 * 10.0**(-9.23) ! ! Modified: ! ! 12 February 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) S, the string containing the ! data to be read. Reading will begin at position 1 and ! terminate at the end of the string, or when no more ! characters can be read to form a legal real. Blanks, ! commas, or other nonnumeric data will, in particular, ! cause the conversion to halt. ! ! Output, real R, the real value that was read from the string. ! ! Output, integer IERROR, error flag. ! ! 0, no errors occurred. ! ! 1, 2, 6 or 7, the input number was garbled. The ! value of IERROR is the last type of input successfully ! read. For instance, 1 means initial blanks, 2 means ! a plus or minus sign, and so on. ! ! Output, integer LCHAR, the number of characters read from ! the string to form the number, including any terminating ! characters such as a trailing comma or blanks. ! implicit none ! logical ch_eqi character c integer ierror integer ihave integer isgn integer iterm integer jbot integer jsgn integer jtop integer lchar integer nchar integer ndig real r real rbot real rexp real rtop character ( len = * ) s character, parameter :: TAB = char ( 9 ) ! nchar = len_trim ( s ) ierror = 0 r = 0.0E+00 lchar = - 1 isgn = 1 rtop = 0.0E+00 rbot = 1.0E+00 jsgn = 1 jtop = 0 jbot = 1 ihave = 1 iterm = 0 do lchar = lchar + 1 c = s(lchar+1:lchar+1) ! ! Blank or TAB character. ! if ( c == ' ' .or. c == TAB ) then if ( ihave == 2 ) then else if ( ihave == 6 .or. ihave == 7 ) then iterm = 1 else if ( ihave > 1 ) then ihave = 11 end if ! ! Comma. ! else if ( c == ',' .or. c == ';' ) then if ( ihave /= 1 ) then iterm = 1 ihave = 12 lchar = lchar + 1 end if ! ! Minus sign. ! else if ( c == '-' ) then if ( ihave == 1 ) then ihave = 2 isgn = - 1 else if ( ihave == 6 ) then ihave = 7 jsgn = - 1 else iterm = 1 end if ! ! Plus sign. ! else if ( c == '+' ) then if ( ihave == 1 ) then ihave = 2 else if ( ihave == 6 ) then ihave = 7 else iterm = 1 end if ! ! Decimal point. ! else if ( c == '.' ) then if ( ihave < 4 ) then ihave = 4 else if ( ihave >= 6 .and. ihave <= 8 ) then ihave = 9 else iterm = 1 end if ! ! Exponent marker. ! else if ( ch_eqi ( c, 'E' ) .or. ch_eqi ( c, 'D' ) ) then if ( ihave < 6 ) then ihave = 6 else iterm = 1 end if ! ! Digit. ! else if ( ihave < 11 .and. lge ( c, '0' ) .and. lle ( c, '9' ) ) then if ( ihave <= 2 ) then ihave = 3 else if ( ihave == 4 ) then ihave = 5 else if ( ihave == 6 .or. ihave == 7 ) then ihave = 8 else if ( ihave == 9 ) then ihave = 10 end if call ch_to_digit ( c, ndig ) if ( ihave == 3 ) then rtop = 10.0E+00 * rtop + real ( ndig ) else if ( ihave == 5 ) then rtop = 10.0E+00 * rtop + real ( ndig ) rbot = 10.0E+00 * rbot else if ( ihave == 8 ) then jtop = 10 * jtop + ndig else if ( ihave == 10 ) then jtop = 10 * jtop + ndig jbot = 10 * jbot end if ! ! Anything else is regarded as a terminator. ! else iterm = 1 end if ! ! If we haven't seen a terminator, and we haven't examined the ! entire string, go get the next character. ! if ( iterm == 1 .or. lchar+1 >= nchar ) then exit end if end do ! ! If we haven't seen a terminator, and we have examined the ! entire string, then we're done, and LCHAR is equal to NCHAR. ! if ( iterm /= 1 .and. lchar+1 == nchar ) then lchar = nchar end if ! ! Number seems to have terminated. Have we got a legal number? ! Not if we terminated in states 1, 2, 6 or 7! ! if ( ihave == 1 .or. ihave == 2 .or. ihave == 6 .or. ihave == 7 ) then ierror = ihave return end if ! ! Number seems OK. Form it. ! if ( jtop == 0 ) then rexp = 1.0E+00 else if ( jbot == 1 ) then rexp = 10.0E+00**( jsgn * jtop ) else rexp = jsgn * jtop rexp = rexp / jbot rexp = 10.0E+00**rexp end if end if r = isgn * rexp * rtop / rbot 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