[UP]


Manual Reference Pages  - len_white (3)

NAME

len_white(3f) - [M_strings:LENGTH] get length of string trimmed of whitespace. (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Example
Notes
Author
License

SYNOPSIS

integer function len_white(string)

character(len=*) :: string

DESCRIPTION

len_white(3f) returns the position of the last character in string that is not a whitespace character. The Fortran90 intrinsic LEN_TRIM() should be used when trailing whitespace can be assumed to always be spaces.

This procedure was heavily used in the past because ANSI FORTRAN 77 character objects are fixed length and blank padded and the LEN_TRIM() intrinsic did not exist. It should now be used only when whitespace characters other than blanks are likely.

OPTIONS

string input string whose trimmed length is being calculated ignoring all trailing whitespace characters.

RETURNS

len_white
  the number of characters in the trimmed string

EXAMPLE

Sample Program:

   program demo_len_white

use M_strings, only : len_white character(len=80) :: s intrinsic len

s=’ ABCDEFG abcdefg ’ ilen = len(s) lastnb = len_white(s)

write(*,*) ’total length of variable is ’,ilen write(*,*) ’trimmed length of variable is ’,lastnb write(*,*) ’trimmed string=[’,s(:lastnb),’]’

end program demo_len_white

NOTES

o len_white

     is a resource-intensive routine. Once the end of
     the string is found, it is probably best to keep track of it in
     order to avoid repeated calls to len_white. Because they
     might be more efficient, consider looking for vendor-supplied or
     system-optimized equivalents. For example:

o lnblnk - Solaris f77 o len_trim - FORTRAN 90

o

Some compilers seem to have trouble passing a string of variable length properly. To be safe, use something like this:

      subroutine message(s)
       character(len=*) :: s ! s is of variable length
          ilen=len(s)        ! get total length of variable
          ! explicitly specify a substring instead of just variable name
          lastnb = len_white(s(:ilen))
          write(*,*)’error:[’,s(:lastnb),’]’
      end subroutine messages

AUTHOR

John S. Urban

LICENSE

Public Domain


len_white (3) July 05, 2020
Generated by manServer 1.08 from d1b52912-5f10-4a7d-8358-606810cb6b1c using man macros.