public pure elemental function lower(str, begin, end) result(string)  
    
    NAME
lower(3f) - [M_strings:CASE] changes a string to lowercase over
specified range
(LICENSE:PD)
 
SYNOPSIS
elemental pure function lower(str,begin,end) result (string)
 character(*), intent(in) :: str
 integer,optional         :: begin, end
 character(len(str))      :: string  ! output string
 
DESCRIPTION
  lower(string) returns a copy of the input string with all characters
  converted to miniscule over the specified range, assuming ASCII
  character sets are being used. If no range is specified the entire
  string is converted to miniscule.
 
OPTIONS
str    string to convert to miniscule
begin  optional starting position in "str" to begin converting to
       miniscule
end    optional ending position in "str" to stop converting to
       miniscule
 
RESULTS
lower  copy of the input string with all characters converted to
       miniscule over optionally specified range.
 
TRIVIA
The terms "uppercase" and "lowercase" date back to the early days of
the mechanical printing press. Individual metal alloy casts of each
needed letter, or punctuation symbol, were meticulously added to a
press block, by hand, before rolling out copies of a page. These
metal casts were stored and organized in wooden cases. The more
often needed miniscule letters were placed closer to hand, in the
lower cases of the work bench. The less often needed, capitalized,
majuscule letters, ended up in the harder to reach upper cases.
 
EXAMPLE
Sample program:
   program demo_lower
   use M_strings, only: lower
   implicit none
   character(len=:),allocatable  :: s
      s=' ABCDEFG abcdefg '
      write(*,*) 'mixed-case input string is ....',s
      write(*,*) 'lower-case output string is ...',lower(s)
   end program demo_lower
Expected output
   mixed-case input string is .... ABCDEFG abcdefg
   lower-case output string is ... abcdefg abcdefg
 
AUTHOR
LICENSE
    Arguments
        
    
      
        | Type | 
Intent | Optional |         Attributes | 
         | 
        Name | 
         | 
    
    
        
            | 
              
              character,
             | 
intent(in) | 
               |             
              
             | 
            :: | 
            str | 
            
                
             | 
        
        
            | 
              
              integer,
             | 
intent(in), | 
              optional |             
              
             | 
            :: | 
            begin | 
            
                
             | 
        
        
            | 
              
              integer,
             | 
intent(in), | 
              optional |             
              
             | 
            :: | 
            end | 
            
                
             | 
        
    
  
      Return Value
        
          
          character
        
      
      
    
    
    
    
    
    
    
    
    
    Source Code
    elemental pure function lower(str,begin,end) result (string)
! ident_24="@(#) M_strings lower(3f) Changes a string to lowercase over specified range"
character(*), intent(in)     :: str
character(len(str))          :: string
integer,intent(in),optional  :: begin, end
integer                      :: i
integer                      :: ibegin, iend
integer,parameter             :: diff = iachar('A')-iachar('a')
   string = str
   ibegin=1
   iend=len_trim(str)
   if (present(begin))then
      ibegin = min(max(1,begin),iend)
   endif
   if (present(end))then
      iend= max(1,min(iend,end))
   endif
   do concurrent (i = ibegin:iend)                   ! step thru each letter in the string in specified range
      select case (str(i:i))
      case ('A':'Z')
         string(i:i) = achar(iachar(str(i:i))-diff)   ! change letter to miniscule
      case default
      end select
   enddo
end function lower