HP Fortran Programmer's Reference (September 2007)

Data types and data objects
Intrinsic data types
Chapter 5120
In standard-conforming programs, a logical value of .TRUE. is represented by 1, and .FALSE.
is represented by 0. In nonstandard-conforming programs involving arithmetic operators with
logical operands, a logical variable may be assigned a value other than 0 or 1. In this case, any
nonzero value is .TRUE., and only the value zero is .FALSE.
Character substrings
A character substring is a contiguous subset of a character string. The substring is defined by
the character positions of its start and end within the string, formatted as follows:
string
([
starting-position
] : [
ending-position
])
starting-position
is a scalar expression. If
starting-position
is omitted, a value of 1 is
assumed. The
starting-position
must be greater than or equal to 1,
unless the substring has zero length.
ending-position
is a scalar integer expression. If
ending-position
is omitted, the value of
the length of the character string is assumed.
The length of the substring is:
MAX (
ending-position
-
starting-position
+ 1, 0)
The following example, substring.f90, illustrates the basic operation on a substring.
Example 5-1 substring.f90
PROGRAM main
CHARACTER(LEN=15) :: city_name
city_name = 'CopXXXagen'
PRINT *, “The city's name is: “, city_name
city_name(4:6) = 'enh' ! assign to a substring of city_name
PRINT *, “The city's name is: “, city_name
END PROGRAM main
Here are the command lines to compile and execute the program, along with the output from
a sample run:
$ f90 substring.f90
$ a.out
The city’s name is: CopXXXagen
The city’s name is: Copenhagen