program main !*****************************************************************************80 ! !! ELEMENT_DATA organizes data on a rectangular grid into finite element data. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 13 February 2002 ! ! Author: ! ! John Burkardt ! implicit none integer ( kind = 4 ), parameter :: maxelm = 2000 integer ( kind = 4 ), parameter :: maxnp = 6000 integer ( kind = 4 ), parameter :: maxnq = 10 integer ( kind = 4 ), parameter :: npe = 4 character ( len = 80 ), parameter :: element_file_name = 'element.txt' integer ( kind = 4 ) i integer ( kind = 4 ) iarg integer ( kind = 4 ) iargc integer ( kind = 4 ) ierror integer ( kind = 4 ) ihi integer ( kind = 4 ) ilen integer ( kind = 4 ) ilo integer ( kind = 4 ), dimension (maxnp) :: indx integer ( kind = 4 ) ios integer ( kind = 4 ) ipxfargc character ( len = 256 ) :: names integer ( kind = 4 ) nelem integer ( kind = 4 ) nelemx integer ( kind = 4 ) nelemy integer ( kind = 4 ), dimension ( npe, maxelm ) :: node character ( len = 80 ), parameter :: node_file_name = 'node.txt' integer ( kind = 4 ) np integer ( kind = 4 ) np2 integer ( kind = 4 ) nq integer ( kind = 4 ) num_arg integer ( kind = 4 ) nx integer ( kind = 4 ) ny real ( kind = 4 ), dimension (maxnp,maxnq) :: v character ( len = 80 ) :: v_file_name call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'ELEMENT_DATA' write ( *, '(a)' ) ' FORTRAN90 version' write ( *, '(a)' ) ' Reads a simple data file which defines elements, nodes,' write ( *, '(a)' ) ' and nodal values, and constructs node and element files' write ( *, '(a)' ) ' suitable for use with the DISPLAY4 graphics program.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Last modified on 13 February 2002.' ! ! 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 ) v_file_name if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'ELEMENT_DATA - Fatal error!' write ( *, '(a)' ) ' Unexpected read error!' stop end if else iarg = 1 ! ! Old style: ! call getarg ( iarg, v_file_name ) ! ! New style: ! ! call pxfgetarg ( iarg, v_file_name, ilen, ierror ) ! ! if ( ierror /= 0 ) then ! write ( *, '(a)' ) ' ' ! write ( *, '(a)' ) 'ELEMENT_DATA - Fatal error!' ! write ( *, '(a)' ) ' Could not read command line argument.' ! stop ! end if end if ! ! Now we know what to do. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'ELEMENT_DATA' write ( *, '(a)' ) ' Read input file: "' // trim ( v_file_name ) // '".' ! ! Estimate the value of NP by counting the lines in the file. ! call file_line_count ( v_file_name, np ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Number of nodes in the properties file = ', np if ( np > maxnp ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'ELEMENT_DATA - Fatal error!' write ( *, '(a)' ) ' NP > MAXNP.' stop end if ! ! Estimate the value of NQ by counting the columns in the file. ! call file_column_count ( v_file_name, nq ) write ( *, '(a)' ) ' ' write ( *, '(a,i6)' ) ' Number of columns in the properties file = ', nq if ( nq > maxnq ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'ELEMENT_DATA - Fatal error!' write ( *, '(a)' ) ' NQ > MAXNQ.' stop end if ! ! Set the names. ! do i = 1, nq ilo = 14*(i-1)+1 ihi = 14*i if ( i == 1 ) then write ( names(ilo:ihi), '(a1,13x)' ) 'X' else if ( i == 2 ) then write ( names(ilo:ihi), '(a1,13x)' ) 'Y' else write ( names(ilo:ihi), '(a1,i2.2,11x)' ) 'V', i-2 end if end do call read_elements ( maxelm, maxnp, maxnq, nelem, node, np, npe, nq, & v, v_file_name ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'ELEMENT_DATA:' write ( *, '(a,i6)' ) ' Number of nodes NP = ', np write ( *, '(a,i6)' ) ' Number of node properties NQ = ', nq write ( *, '(a,i6)' ) ' Number of elements NELEM = ', nelem ! ! Write the element information to a file. ! call write_element ( element_file_name, nelem, node(1:npe,1:nelem), npe ) ! ! Write the node information to a file. ! call write_node ( node_file_name, np, nq, v(1:np,1:nq), names ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'ELEMENT_DATA' write ( *, '(a)' ) ' Normal end of execution.' stop end subroutine ch_cap ( c ) !*****************************************************************************80 ! !! CH_CAP capitalizes a single character. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 19 July 1998 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input/output, character C, the character to capitalize. ! implicit none character c integer ( kind = 4 ) itemp itemp = ichar ( c ) if ( 97 <= itemp .and. itemp <= 122 ) then c = char ( itemp - 32 ) end if return end function ch_eqi ( c1, c2 ) !*****************************************************************************80 ! !! CH_EQI is a case insensitive comparison of two characters for equality. ! ! Example: ! ! CH_EQI ( 'A', 'a' ) is .TRUE. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! 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 ) !*****************************************************************************80 ! !! CH_TO_DIGIT returns the integer value of a base 10 digit. ! ! Example: ! ! C DIGIT ! --- ----- ! '0' 0 ! '1' 1 ! ... ... ! '9' 9 ! ' ' 0 ! 'X' -1 ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 04 August 1999 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character C, the decimal digit, '0' through '9' or blank ! are legal. ! ! Output, integer ( kind = 4 ) DIGIT, the corresponding integer value. If C was ! 'illegal', then DIGIT is -1. ! implicit none character c integer ( kind = 4 ) 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_column_count ( file_name, ncolumn ) !*****************************************************************************80 ! !! FILE_COLUMN_COUNT counts the number of columns in the first line of a file. ! ! Discussion: ! ! The file is assumed to be a simple text file. ! ! Most lines of the file is presumed to consist of NCOLUMN words, separated ! by spaces. There may also be some blank lines, and some comment lines, ! which have a "#" in column 1. ! ! The routine tries to find the first non-comment non-blank line and ! counts the number of words in that line. ! ! If all lines are blanks or comments, it goes back and tries to analyze ! a comment line. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 21 June 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) FILE_NAME, the name of the file. ! ! Output, integer ( kind = 4 ) NCOLUMN, the number of columns assumed to be in the file. ! implicit none character ( len = * ) file_name logical got_one integer ( kind = 4 ) ios integer ( kind = 4 ) iunit character ( len = 256 ) line integer ( kind = 4 ) ncolumn ! ! Open the file. ! call get_unit ( iunit ) open ( unit = iunit, file = file_name, status = 'old', form = 'formatted', & access = 'sequential', iostat = ios ) if ( ios /= 0 ) then ncolumn = - 1 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'FILE_COLUMN_COUNT - Fatal error!' write ( *, '(a)' ) ' Could not open the file:' write ( *, '(a)' ) ' ' // trim ( file_name ) return end if ! ! Read one line, but skip blank lines and comment lines. ! got_one = .false. do read ( iunit, '(a)', iostat = ios ) line if ( ios /= 0 ) then exit end if if ( len_trim ( line ) == 0 ) then cycle end if if ( line(1:1) == '#' ) then cycle end if got_one = .true. exit end do if ( .not. got_one ) then rewind ( iunit ) do read ( iunit, '(a)', iostat = ios ) line if ( ios /= 0 ) then exit end if if ( len_trim ( line ) == 0 ) then cycle end if got_one = .true. exit end do end if close ( unit = iunit ) if ( .not. got_one ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'FILE_COLUMN_COUNT - Warning!' write ( *, '(a)' ) ' The file does not seem to contain any data.' ncolumn = 0 return end if call word_count ( line, ncolumn ) return end subroutine file_line_count ( file_name, nline ) !*****************************************************************************80 ! !! FILE_LINE_COUNT counts the number of lines in a file. ! ! Discussion: ! ! The file is assumed to be a simple text file. ! ! Blank lines and comment lines, which begin with '#', are not counted. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 21 June 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) FILE_NAME, the name of the file. ! ! Output, integer ( kind = 4 ) NLINE, the number of lines found in the file. ! implicit none character ( len = * ) file_name integer ( kind = 4 ) ios integer ( kind = 4 ) iunit character ( len = 256 ) line integer ( kind = 4 ) nline nline = 0 ! ! Open the file. ! call get_unit ( iunit ) open ( unit = iunit, file = file_name, status = 'old', form = 'formatted', & access = 'sequential', iostat = ios ) if ( ios /= 0 ) then nline = - 1 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'FILE_LINE_COUNT - Fatal error!' write ( *, '(a)' ) ' Could not open the file:' // trim ( file_name ) return end if ! ! Count the lines. ! do read ( iunit, '(a)', iostat = ios ) line if ( ios /= 0 ) then exit end if if ( len_trim ( line ) == 0 ) then cycle end if if ( line(1:1) == '#' ) then cycle end if nline = nline + 1 end do close ( unit = iunit ) return end subroutine get_unit ( iunit ) !*****************************************************************************80 ! !! 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. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 02 March 1999 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Output, integer ( kind = 4 ) 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 ( kind = 4 ) i integer ( kind = 4 ) ios integer ( kind = 4 ) 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 r_next ( s, r, done ) !*****************************************************************************80 ! !! R_NEXT "reads" real numbers from a string, one at a time. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 14 April 1999 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) S, a string, presumably containing real ! numbers. These may be separated by spaces or commas. ! ! Output, real ( kind = 4 ) R. If DONE is FALSE, then R contains the ! "next" real value read from the string. If DONE is TRUE, then ! R is zero. ! ! Input/output, logical DONE. ! On input with a fresh string, the user should set DONE to TRUE. ! On output, the routine sets DONE to FALSE if another real ! value was read, or TRUE if no more reals could be read. ! implicit none logical done integer ( kind = 4 ) ierror integer ( kind = 4 ) lchar integer ( kind = 4 ), save :: next = 1 real ( kind = 4 ) r character ( len = * ) s r = 0.0E+00 if ( done ) then next = 1 done = .false. end if if ( next > len ( s ) ) then done = .true. return end if call s_to_r ( s(next:), r, ierror, lchar ) if ( ierror /= 0 .or. lchar == 0 ) then done = .true. next = 1 else done = .false. next = next + lchar end if return end subroutine read_elements ( maxelm, maxnp, maxnq, nelem, node, np, npe, nq, & v, v_file_name ) !*****************************************************************************80 ! !! READ_ELEMENTS reads Niyazi Sahin's file and constructs the elements. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 03 July 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer ( kind = 4 ) MAXELM, the maximum number of elements. ! ! Input, integer ( kind = 4 ) MAXNP, the maximum number of nodes. ! ! Input, integer ( kind = 4 ) MAXNQ, the maximum number of node properties. ! ! Output, integer ( kind = 4 ) NELEM, the number of elements. ! ! Output, integer ( kind = 4 ) NODE(NPE,MAXELM), the list of nodes that form each element. ! ! Output, integer ( kind = 4 ) NP, the number of nodes. ! ! Input, integer ( kind = 4 ) NPE, the number of nodes per element. ! ! Output, integer ( kind = 4 ) NQ, the number of node properties. ! ! Output, real ( kind = 4 ) V(MAXNP,MAXNQ), the list of node property values. ! ! Input, character ( len = 80 ) V_FILE_NAME, the name of the node ! property file. ! implicit none integer ( kind = 4 ) maxelm integer ( kind = 4 ) maxnp integer ( kind = 4 ) maxnq integer ( kind = 4 ) npe logical blank logical done integer ( kind = 4 ) ierror integer ( kind = 4 ) indx(maxnp) integer ( kind = 4 ) ios integer ( kind = 4 ) iunit integer ( kind = 4 ) ival integer ( kind = 4 ) j integer ( kind = 4 ) k character ( len = 256 ) line integer ( kind = 4 ) n integer ( kind = 4 ) nelem integer ( kind = 4 ) nnode integer ( kind = 4 ) node(npe,maxelm) integer ( kind = 4 ) np integer ( kind = 4 ) nq character, parameter :: scalar = 'S' real ( kind = 4 ) v(maxnp,maxnq) character ( len = 80 ) v_file_name real ( kind = 4 ) v_temp(maxnq) real ( kind = 4 ) x(np) real ( kind = 4 ) xval real ( kind = 4 ) y(np) real ( kind = 4 ) yval call get_unit ( iunit ) open ( unit = iunit, file = v_file_name, status = 'old', iostat = ios ) if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'READ_ELEMENTS - Fatal error!' write ( *, '(a)' ) ' Could not open the file ' // trim ( v_file_name ) stop end if ! ! Read the data, one element at a time. ! A blank record indicates a new element. ! Many nodes are repeated. ! n = 0 nelem = 0 blank = .true. do read ( iunit, '(a)', iostat = ios ) line if ( ios /= 0 ) then exit end if if ( len_trim ( line ) == 0 ) then blank = .true. cycle end if if ( line(1:1) == '#' ) then cycle end if if ( blank ) then blank = .false. nelem = nelem + 1 if ( nelem > maxelm ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'READ_ELEMENTS - Fatal error!' write ( *, '(a)' ) ' Too many elements.' stop end if nnode = 0 end if done = .true. do j = 1, nq call r_next ( line, v_temp(j), done ) end do ! ! Extract the X, Y values, store them if they are unique, and get the index. ! xval = v_temp(1) yval = v_temp(2) call rrvec_index_insert_unique ( np, n, x, y, indx, xval, yval, & ival, ierror ) ! ! Store the temporary data in the correct row. ! v(ival,1:2) = v_temp(1:2) v(ival,3:4) = v_temp(5:6) ! ! We only have one slot for a scalar variable. ! Get the pressures from column 3, or the stream function from column 4. ! if ( scalar == 'P' ) then v(ival,5) = v_temp(3) else v(ival,5) = v_temp(4) end if ! ! We really want to save ALL the variables, but that will have ! to wait until DISPLAY is ready for this. ! ! v(ival,1:nq) = v_temp(1:nq) nnode = nnode + 1 ! ! The first node is repeated as the last node. Skip it. ! if ( nnode > 4 ) then cycle end if node(nnode,nelem) = ival end do close ( unit = iunit ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'READ_ELEMENTS:' write ( *, '(a,i6)' ) ' Number of elements is ', nelem write ( *, '(a,i6)' ) ' Number of unique nodes is ', n np = n nq = 5 return end function rrvec_compare ( x1, y1, x2, y2 ) !*****************************************************************************80 ! !! RRVEC_COMPARE compares two RR vectors. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 10 October 2000 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, real ( kind = 4 ) X1, Y1, the first vector. ! ! Input, real ( kind = 4 ) X2, Y2, the second vector. ! ! Output, character RRVEC_COMPARE: '<', '>' or '=' if the first vector ! is less, greater or equal to the second. ! implicit none character c character rrvec_compare real ( kind = 4 ) x1 real ( kind = 4 ) x2 real ( kind = 4 ) y1 real ( kind = 4 ) y2 if ( x1 < x2 ) then c = '<' else if ( x1 > x2 ) then c = '>' else if ( y1 < y2 ) then c = '<' else if ( y1 > y2 ) then c = '>' else c = '=' end if rrvec_compare = c return end subroutine rrvec_index_search ( maxn, n, x, y, indx, xval, yval, less, equal, & more ) !*****************************************************************************80 ! !! RRVEC_INDEX_SEARCH searches for an RR value in an indexed sorted list. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 24 June 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer ( kind = 4 ) MAXN, the maximum size of the list. ! ! Input, integer ( kind = 4 ) N, the size of the current list. ! ! Input, real ( kind = 4 ) X(N), Y(N), the list. ! ! Input, integer ( kind = 4 ) INDX(N), the sort index of the list. ! ! Input, real ( kind = 4 ) XVAL, YVAL, the value to be sought. ! ! Output, integer ( kind = 4 ) LESS, EQUAL, MORE, the indexes in INDX of the ! entries of X that are just less than, equal to, and just greater ! than XVAL. If XVAL does not occur in X, then EQUAL is zero. ! If XVAL is the minimum entry of X, then LESS is 0. If XVAL ! is the greatest entry of X, then MORE is N+1. ! implicit none integer ( kind = 4 ) maxn character c integer ( kind = 4 ) equal integer ( kind = 4 ) hi integer ( kind = 4 ) indx(maxn) integer ( kind = 4 ) less integer ( kind = 4 ) lo integer ( kind = 4 ) mid integer ( kind = 4 ) more integer ( kind = 4 ) n character rrvec_compare real ( kind = 4 ) x(maxn) real ( kind = 4 ) xhi real ( kind = 4 ) xlo real ( kind = 4 ) xmid real ( kind = 4 ) xval real ( kind = 4 ) y(maxn) real ( kind = 4 ) yhi real ( kind = 4 ) ylo real ( kind = 4 ) ymid real ( kind = 4 ) yval ! if ( n <= 0 ) then less = 0 equal = 0 more = 0 return end if lo = 1 hi = n xlo = x(indx(lo)) ylo = y(indx(lo)) xhi = x(indx(hi)) yhi = y(indx(hi)) c = rrvec_compare ( xval, yval, xlo, ylo ) if ( c == '<' ) then less = 0 equal = 0 more = 1 return else if ( c == '=' ) then less = 0 equal = 1 more = 2 return end if c = rrvec_compare ( xval, yval, xhi, yhi ) if ( c == '>' ) then less = n equal = 0 more = n + 1 return else if ( c == '=' ) then less = n - 1 equal = n more = n + 1 return end if do if ( lo + 1 == hi ) then less = lo equal = 0 more = hi return end if mid = ( lo + hi ) / 2 xmid = x(indx(mid)) ymid = y(indx(mid)) c = rrvec_compare ( xval, yval, xmid, ymid ) if ( c == '=' ) then equal = mid less = equal - 1 more = equal + 1 return else if ( c == '<' ) then hi = mid else if ( c == '>' ) then lo = mid end if end do return end subroutine rrvec_index_insert_unique ( maxn, n, x, y, indx, xval, yval, & ival, ierror ) !*****************************************************************************80 ! !! RRVEC_INDEX_INSERT_UNIQUE inserts a unique RR value in an indexed sorted list. ! ! Discussion: ! ! If the input value does not occur in the current list, it is added, ! and N, X, Y and INDX are updated. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 25 June 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, integer ( kind = 4 ) MAXN, the maximum size of the list. ! ! Input/output, integer ( kind = 4 ) N, the size of the list. ! ! Input/output, real ( kind = 4 ) X(N), Y(N), the list of R2 vectors. ! ! Input/output, integer ( kind = 4 ) INDX(N), the sort index of the list. ! ! Input, real ( kind = 4 ) XVAL, YVAL, the value to be inserted if it is ! not already in the list. ! ! Output, integer ( kind = 4 ) IVAL, the index in X, Y corresponding to the ! value XVAL, YVAL. ! ! Output, integer ( kind = 4 ) IERROR, 0 for no error, 1 if an error occurred. ! implicit none integer ( kind = 4 ) maxn integer ( kind = 4 ) equal integer ( kind = 4 ) ierror integer ( kind = 4 ) indx(maxn) integer ( kind = 4 ) ival integer ( kind = 4 ) less integer ( kind = 4 ) more integer ( kind = 4 ) n real ( kind = 4 ) x(maxn) real ( kind = 4 ) xval real ( kind = 4 ) y(maxn) real ( kind = 4 ) yval ierror = 0 if ( n <= 0 ) then if ( maxn <= 0 ) then ierror = 1 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RRVEC_INDEX_INSERT_UNIQUE - Fatal error!' write ( *, '(a)' ) ' Not enough space to store new data.' return end if n = 1 x(1) = xval y(1) = yval indx(1) = 1 ival = 1 return end if ! ! Does ( XVAL, YVAL ) already occur in ( X, Y )? ! call rrvec_index_search ( maxn, n, x, y, indx, xval, yval, less, equal, more ) if ( equal == 0 ) then if ( n >= maxn ) then ierror = 1 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'RRVEC_INDEX_INSERT_UNIQUE - Fatal error!' write ( *, '(a)' ) ' Not enough space to store new data.' return end if x(n+1) = xval y(n+1) = yval ival = n + 1 indx(n+1:more+1:-1) = indx(n:more:-1) indx(more) = n + 1 n = n + 1 else ival = indx(equal) end if return end subroutine s_to_r ( s, r, ierror, lchar ) !*****************************************************************************80 ! !! 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) ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! 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 ( kind = 4 ) R, the real value that was read from the string. ! ! Output, integer ( kind = 4 ) 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 ( kind = 4 ) 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 ( kind = 4 ) ierror integer ( kind = 4 ) ihave integer ( kind = 4 ) isgn integer ( kind = 4 ) iterm integer ( kind = 4 ) jbot integer ( kind = 4 ) jsgn integer ( kind = 4 ) jtop integer ( kind = 4 ) lchar integer ( kind = 4 ) nchar integer ( kind = 4 ) ndig real ( kind = 4 ) r real ( kind = 4 ) rbot real ( kind = 4 ) rexp real ( kind = 4 ) 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 ( ) !*****************************************************************************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 GNU LGPL license. ! ! Modified: ! ! 06 August 2005 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! None ! implicit none character ( len = 8 ) ampm integer ( kind = 4 ) ( kind = 4 ) d integer ( kind = 4 ) ( kind = 4 ) h integer ( kind = 4 ) ( kind = 4 ) m integer ( kind = 4 ) ( kind = 4 ) mm character ( len = 9 ), parameter, dimension(12) :: month = (/ & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' /) integer ( kind = 4 ) ( kind = 4 ) n integer ( kind = 4 ) ( kind = 4 ) s integer ( kind = 4 ) ( kind = 4 ) values(8) integer ( kind = 4 ) ( kind = 4 ) 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 subroutine word_count ( s, nword ) !*****************************************************************************80 ! !! WORD_COUNT counts the number of "words" in a string. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 14 April 1999 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) S, the string to be examined. ! ! Output, integer ( kind = 4 ) NWORD, the number of "words" in the string. ! Words are presumed to be separated by one or more blanks. ! implicit none logical blank integer ( kind = 4 ) i integer ( kind = 4 ) lens integer ( kind = 4 ) nword character ( len = * ) s nword = 0 lens = len ( s ) if ( lens <= 0 ) then return end if blank = .true. do i = 1, lens if ( s(i:i) == ' ' ) then blank = .true. else if ( blank ) then nword = nword + 1 blank = .false. end if end do return end subroutine write_element ( element_file, nelem, node, npe ) !*****************************************************************************80 ! !! WRITE_ELEMENT writes an element data file. ! ! Discussion: ! ! The element file contains information about the organization of ! the nodes into elements. The format is as follows: ! ! Line 1: NELEM, the number of elements ! Line 2: NPE, the number of nodes per element. ! Line 3 through NELEM+2: the node list for each element. ! ! Blank lines, and comments lines, which begin with a "#", may ! occur anywhere. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 22 June 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) ELEMENT_FILE, the name of the element file. ! ! Input, integer ( kind = 4 ) NELEM, the number of elements. ! ! Input, integer ( kind = 4 ) NODE(NPE,NELEM), the global node numbers in each element. ! ! Input, integer ( kind = 4 ) NPE, the number of nodes per element. ! implicit none integer ( kind = 4 ) nelem integer ( kind = 4 ) npe character ( len = * ) element_file integer ( kind = 4 ) ielem integer ( kind = 4 ) ierror integer ( kind = 4 ) ios integer ( kind = 4 ) node(npe,nelem) integer ( kind = 4 ) output_unit ierror = 0 call get_unit ( output_unit ) ! ! Open the data file. ! open ( unit = output_unit, file = element_file, status = 'replace', & iostat = ios ) if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'WRITE_ELEMENT - Fatal error!' write ( *, '(a)' ) ' Could not open the element file: ' & // trim ( element_file ) return end if ! ! Header. ! ! write ( output_unit, '(a)' ) '# ' // trim ( element_file ) ! write ( output_unit, '(a)' ) '# created by routine WRITE_ELEMENT,' ! write ( output_unit, '(a)' ) '# program CONTOUR, for input to DISPLAY.' ! write ( output_unit, '(a)' ) '#' ! write ( output_unit, '(a)' ) '# Line 1 is number of elements.' ! write ( output_unit, '(a)' ) '# Line 2 is number of nodes per element.' ! write ( output_unit, '(a)' ) '# Subsequent lines are node lists for elements.' ! write ( output_unit, '(a)' ) '#' ! ! Number of elements. ! write ( output_unit, '(i6)' ) nelem ! ! Number of nodes per element. ! write ( output_unit, '(i6)' ) npe ! ! Node numbers associated with each element. ! do ielem = 1, nelem write ( output_unit, '(6i6)' ) node(1:npe,ielem) end do close ( unit = output_unit ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'WRITE_ELEMENT:' write ( *, '(a)' ) ' The element data was written to the file: ' // & trim ( element_file ) return end subroutine write_node ( node_file, np, nq, v, names ) !*****************************************************************************80 ! !! WRITE_NODE writes a node data file. ! ! Discussion: ! ! The node file contains the value of various quantities at the nodes. ! The format is: ! ! Line 1: NP, the number of nodes ! Line 2: NQ, the number of values per node, (X, Y and the quantities). ! Line 3: NAMES, the names of X, Y, and the quantities ! Lines 4 through NP+3: X, Y, and the quantities for each node. ! ! Blanks and comment lines, which have a "#" in column 1, may occur anywhere. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 22 June 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) NODE_FILE, the node file. ! ! Input, integer ( kind = 4 ) NP, the number of nodes. ! ! Input, integer ( kind = 4 ) NQ, the number of quantities (including X and Y). ! ! Input, real ( kind = 4 ) V(NP,NQ), X, Y, and various quantities associated with ! the nodes. ! ! Input, character ( len = 14 * NQ ) NAMES, names for the quantities. ! implicit none integer ( kind = 4 ) np integer ( kind = 4 ) nq integer ( kind = 4 ) i integer ( kind = 4 ) ios character ( len = * ) names character ( len = * ) node_file integer ( kind = 4 ) output_unit real ( kind = 4 ) v(np,nq) call get_unit ( output_unit ) open ( unit = output_unit, file = node_file, status = 'replace', & iostat = ios ) if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'WRITE_NODE - Fatal error!' write ( *, '(a)' ) ' Could not open the node data file:' & // trim ( node_file ) return end if ! write ( output_unit, '(a)' ) '# ' // trim ( node_file ) ! write ( output_unit, '(a)' ) '# created by routine WRITE_NODE,' ! write ( output_unit, '(a)' ) '# program CONTOUR, for input to DISPLAY.' ! write ( output_unit, '(a)' ) '#' ! write ( output_unit, '(a)' ) '# Line 1 is number of nodes.' ! write ( output_unit, '(a)' ) '# Line 2 is number of properties per node.' ! write ( output_unit, '(a)' ) '# Line 3 is property names.' ! write ( output_unit, '(a)' ) '# Subsequent lines are X, Y and properties for each node.' ! write ( output_unit, '(a)' ) '#' ! write ( output_unit, '(i6)' ) np ! write ( output_unit, '(i6)' ) nq ! write ( output_unit, '(5x,a)' ) names(1:14*nq) do i = 1, np write ( output_unit, '(12g14.6)' ) v(i,1:nq) end do close ( unit = output_unit ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'WRITE_NODE:' write ( *, '(a)' ) ' The node data was written to the file: ' & // trim ( node_file ) return end