indent(3f) - [M_strings:WHITESPACE] count number of leading spaces
in a string
(LICENSE:PD)
function indent(line)
integer :: indent
character(len=*),intent(in) :: line
Count number of leading spaces in a CHARACTER variable.
Sample Program:
program demo_indent
! test filter to count leading spaces in a character variable
! might want to call notabs(3f) to expand tab characters
use M_strings, only : indent
implicit none
character(len=1024) :: in
integer :: ios
READFILE: do
read(*,'(A)',iostat=ios)in
if(ios /= 0) exit READFILE
write(*,'(i3,"",a)')indent(in),trim(in)
enddo READFILE
end program demo_indent
Results:
3 a b c
0a b c
6 a b c
John S. Urban
Public Domain
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | line |
function indent(line)
! ident_29="@(#) M_strings indent(3f) find number of leading spaces in a string"
integer :: indent
character(len=*),intent(in) :: line
integer :: i
indent=0
NOTSPACE: block
SCAN: do i=1,len(line)
if(line(i:i) /= ' ')then
indent=i-1
exit NOTSPACE
endif
enddo SCAN
indent=len(line)
endblock NOTSPACE
end function indent