FORTRAN CLI library

pdec

NAME
pdec - write out string with ASCII decimal equivalent vertically under it
SYNOPSIS/USAGE
   SUBROUTINE PDEC(STRING)
   CHARACTER(len=*),intent(in) :: STRING
DESCRIPTION

Given a string, PDEC() writes out the ASCII Decimal equivalent of the string directly underneath it. This can help you to locate unprintable characters or non-standard white-space such as a backspace character or tab character in input strings that your program could not interpret. On output, non-printable characters are replaced with a space, and trailing spaces are ignored.

You read the numbers vertically.

EXAMPLE
      program demo
      call pdec(' ABCDEFG abcdefg ')
      end program demo
would produce (notice trailing space is trimmed):
  ABCDEFG abcdefg
  000000000000111
  366666773999000
  256789012789012
NOTES
FILES
libJSU.a


!=======================================================================-------- #ifdef TESTPRG90 program ade_dump character(len=256) :: line do read(*,'(a)',end=999,err=999)line call pdec(line) enddo 999 end program ade_dump #endif !=======================================================================-------- subroutine pdec(string) !------------------------------------------------------------------------------- !@(#) write string with ASCII Decimal Equivalent (ADE) numbers vertically beneath ! ! given string to print ! 1) ignore trailing spaces ! 2) print the character if it has an ADE of 32 on up ! 3) print a space if it has an ADE of less than 32 ! 4) underneath each character print the ADE value vertically ! ! strings assumed under 32767 characters in length. ! Format integer constants > 32767 are not supported on HP-UX ! when newer compilers are available use unlimited !------------------------------------------------------------------------------- implicit none character(len=*),intent(in) :: string ! the string to print integer :: ilen ! number of characters in string to print integer :: i ! counter used to step thru string ilen=len_trim(string(:len(string))) ! get trimmed length of input string write(*,101)(char(max(32,ichar(string(i:i)))),i=1,ilen) ! replace lower unprintable characters with spaces ! print ADE value of character underneath it write(*,202) (ichar(string(i:i))/100, i=1,ilen) write(*,202)(mod( ichar(string(i:i)),100)/10,i=1,ilen) write(*,202)(mod((ichar(string(i:i))),10), i=1,ilen) 101 format(32767a1:) ! format for printing string characters 202 format(32767i1:) ! format for printing ADE values end subroutine pdec