module mod_ascii
implicit none
private
public :: ascii
interface ascii
module procedure x_ascii_chr
module procedure x_ascii_str
end interface ascii
character(1), parameter, private :: dict_ascii(33:126) &
= (/'!', '"', '#', '$', '%', '&', "'", '(', &
')', '*', '+', ',', '-', '.', '/', '0', &
'1', '2', '3', '4', '5', '6', '7', '8', &
'9', ':', ';', '<', '=', '>', '?', '@', &
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', &
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', &
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', &
'Y', 'Z', '[', '\', ']', '^', '_', '`', &
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', &
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', &
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', &
'y', 'z', '{', '|', '}', '~' /)
contains
function x_ascii_chr(x) result(ascii)
implicit none
integer(1), intent(in) :: x
character(1) :: ascii
ascii = dict_ascii(x)
end function x_ascii_chr
function x_ascii_str(x) result(ascii)
implicit none
integer(1), intent(in) :: x(:)
character(size(x)) :: ascii
integer :: i
do i = 1, size(x)
ascii(i:i) = dict_ascii(x(i))
enddo
end function x_ascii_str
end module mod_ascii