trimlen

Date:

06-19-2023

NAME

TRIMLEN - Returns the length of a character argument without counting trailing blanks

SYNOPSIS

INTEGER trimlen, intlen
intlen = TRIMLEN(string)

INTEGER(8) trimlen_8
intlen8 = TRIMLEN_8(string)

DESCRIPTION

TRIMLEN is an integer function that returns the length of a character argument without counting the trailing blanks. The function must be declared as type integer in the calling routine. The string argument must be of type character.

This function is intended for use as part of the substring notation. Examples 2 and 3 show the TRIMLEN function used in this manner. The value of each of the parts of the substring notation must be as follows:

1 <= leftmostpos <= rightmostpos <= stringlength

leftmostpos is the leftmost character position in the substring, rightmostpos is the rightmost character position in the substring, and stringlength is the declared length of the character entity. TRIMLEN returns a value of 1 for a string of all blanks.

The length returned is an integer with the default length. If the program is compiled with the -s default64 option, use the -A FTN_LIB_DEFINITIONS option. The FTN_LIB_DEFINITIONS system module supplies a generic interface block for TRIMLEN. The Fortran compiler will choose the proper entry point depending on the kind type of the argument.

EXAMPLES

Example 1:

A program using the function TRIMLEN could do the following:

  INTEGER TRIMLEN
  CHARACTER*80 STRING
  STRING = ' '
  STRING(20:47) = 'TEST TRIMLEN LENGTH RETURNED'
  INTLEN = TRIMLEN(STRING)
  WRITE(6,1) INTLEN, STRING(1:INTLEN)
1 FORMAT(' LENGTH=',I5,' STRING=',A,'-DONE')
  PRINT 2,'12345678901234567890123456789012345678901234567890'
2 FORMAT(21X,A)
  END

The output of the program is as follows:

LENGTH=  47 STRING=                 TEST TRIMLEN LENGTH RETURNED-DONE
                 12345678901234567890123456789012345678901234567890

Example 2:

This example produces a string with the character < written following the last nonblank character of STRING:

    WRITE(6,901)STRING(1:TRIMLEN(STRING))
901 FORMAT(' The string is >',A,'<')

Example 3:

In this example, although NEW may have trailing blanks, the character < is written after the last nonblank character in STRING:

NEW = STRING(1:TRIMLEN(STRING)) // '< The end'