Data Types [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Reference
Data Types
Each constant, variable, function, or expression is of one type only.
The type defines:
* The set of values that an entity of that type can assume.
* The amount of storage that variables of that type require.
* The operations that can be performed on an entity of that type.
Warning messages are issued for duplicate data type declarations.
HP FORTRAN 77 has 11 data types, falling into five general categories, as
shown in Table 2-1 .
Table 2-1. Data Type Keywords
--------------------------------------------------------------
| | | |
| General Name | Data Type Keyword | Equivalent Keyword |
| | | |
--------------------------------------------------------------
| | | |
| Integer | BYTE 2 | LOGICAL*1 2 |
| | | |
| | INTEGER*2 2 | INTEGER 1,3 (option) |
| | | |
| | INTEGER*4 2 | INTEGER 1,3 |
| | | (default) |
| | | |
--------------------------------------------------------------
| | | |
| Real | REAL*4 2 | REAL 1 |
| | | |
| | REAL*8 2 | DOUBLE PRECISION 1 |
| | | |
| | REAL*16 2 | (none) |
| | | |
--------------------------------------------------------------
| | | |
| Complex | COMPLEX*8 2 | COMPLEX 1 |
| | | |
| | COMPLEX*16 2 | DOUBLE COMPLEX 2 |
| | | |
--------------------------------------------------------------
| | | |
| Logical | LOGICAL*2 2 | LOGICAL 1,3 (option) |
| | | |
| | LOGICAL*4 2 | LOGICAL 1,3 |
| | | (default) |
| | | |
--------------------------------------------------------------
| | | |
| Character | CHARACTER 1 | (none) |
| | | |
--------------------------------------------------------------
| |
| |
| Notes: |
| 1. ANSI 77 standard. |
| 2. Extension to the ANSI 77 standard. |
| |
| 3. The equivalence depends on the |
| setting of the compiler |
| directives LONG and SHORT. |
| 4. BYTE is a one byte integer which |
| may be used in a |
| logical context. It is sometimes |
| called LOGICAL*1. |
| |
--------------------------------------------------------------
A keyword shown in column 3 of Table 2-1 has the same meaning as the
keyword to the left in column 2 (subject to the compiler directives noted
in the table). Consequently, in the rest of this manual, the data types
will be referred to specifically by the keywords in column 2, and
generally by the names in column 1.
For example, the word "Integer" will always mean any data defined with
any of the keywords in the cells on the same row, and the keyword REAL*8
will always include data defined as DOUBLE PRECISION.
NOTE By default, the type keywords INTEGER and LOGICAL are equivalent to
INTEGER*4 and LOGICAL*4, respectively. This is the same as the
effect of the LONG compiler directive. The SHORT compiler
directive may be used to make INTEGER and LOGICAL equivalent to
INTEGER*2 and LOGICAL*2, respectively. See Chapter 7 for
further details. In addition, compiler run-string options can have
the same effect. See Chapter 6 for further details.
The storage size and the range of values for each data type are shown in
Table 2-2 . Storage is measured in 8-bit bytes. Storage format is
described in Chapter 10 .
Table 2-2. Data Type Specifications
----------------------------------------------------------------------------------
| | | |
| Data Type | Range of Values | Storage |
| | | |
----------------------------------------------------------------------------------
| | | |
| BYTE | signed decimal -128 to +127 (a 1-byte integer); | 1 byte |
| (LOGICAL*1) | .TRUE. or .FALSE.; | |
| | one 8-bit ASCII character | |
| | | |
----------------------------------------------------------------------------------
| | | |
| INTEGER*2 | -32768 to +32767 | 2 bytes |
| | | |
----------------------------------------------------------------------------------
| | | |
| INTEGER*4 | -2147483648 to +2147483647 | 4 bytes |
| | | |
----------------------------------------------------------------------------------
| | | |
| REAL*4 | 0.0 and | 4 bytes |
| | +-1.175494*10-38 | |
| | to | |
| | +-3.402823*10+38 | |
| | | |
----------------------------------------------------------------------------------
| | | |
| REAL*8 | 0.0 and | 8 bytes |
| | +-2.225073858507202*10-308 | |
| | to | |
| | +-1.797693134862315*10+308 | |
| | | |
----------------------------------------------------------------------------------
| | | |
| REAL*16 | 0.0 and | 16 bytes |
| | +-3.362103143112093506262677817321753*10-4932 | |
| | to | |
| | +-1.189731495357231765085759326628007*10+4932 | |
| | | |
----------------------------------------------------------------------------------
| | | |
| COMPLEX*8 | Real and imaginary parts each have REAL*4 range. | 8 bytes |
| | | |
----------------------------------------------------------------------------------
| | | |
| COMPLEX*16 | Real and imaginary parts each have REAL*8 range. | 16 bytes |
| | | |
----------------------------------------------------------------------------------
| | | |
| LOGICAL*2 | .TRUE. or .FALSE. | 2 bytes |
| | | |
----------------------------------------------------------------------------------
| | | |
| LOGICAL*4 | .TRUE. or .FALSE. | 4 bytes |
| | | |
----------------------------------------------------------------------------------
| | | |
| CHARACTER | One or more 8-bit ASCII characters | 1 byte |
| | | per |
| | | character |
| | | |
----------------------------------------------------------------------------------
As extensions to the ANSI 77 standard, HP FORTRAN 77 also provides three
special constant data types, Hollerith, octal, and hexadecimal, shown in
Table 2-3 with their ranges and storage sizes. These differ from
other data types in that they cannot be associated with variables,
functions, or expressions.
Table 2-3. Constant Data Types
----------------------------------------------------------------------------------
| | | |
| Data Type | Range of Values | Storage |
| | | |
----------------------------------------------------------------------------------
| | | |
| Hollerith | One or more 8-bit ASCII characters 1 | 1 byte |
| | | per |
| | | character |
| | | |
----------------------------------------------------------------------------------
| | | |
| Octal | Dependent on context 2 | 16 bytes |
| | | |
----------------------------------------------------------------------------------
| | | |
| Hexadecimal | Dependent on context 3 | 16 bytes |
| | | |
----------------------------------------------------------------------------------
Notes:
1. See "Typeless Constants" and "Hollerith
Constants" in this chapter.
2. See "Typeless Constants" and "Octal Constants"
in this chapter.
3. See "Typeless Constants" and "Hexadecimal
Constants" in this chapter.
Each data type is described in this chapter, along with a description of
the constants of each type. A constant is a data element that represents
one specific value, such as -3, .TRUE., 'character constant', or
47.21E-8.
The PARAMETER statement allows you to give symbolic names to constants.
The operations that can be performed on each data type are described in
"Expressions" in this chapter. Each FORTRAN type statement is
described in detail in Chapter 3 . Refer to Chapter 10 for
details on the data format in memory of each type.
BYTE (LOGICAL*1) Data Type
The BYTE (LOGICAL*1) data type can represent:
* A signed 8-bit integer in the range -128 to +127.
* The logical values true and false.
* An 8-bit ASCII character.
Variables and constants of type BYTE are stored in one byte. Refer to
Chapter 10 for details. LOGICAL*1 and BYTE are extensions to the
ANSI 77 standard. They are equivalent.
You can specify a BYTE variable explicitly by declaring it:
* In a LOGICAL*1 or BYTE type statement.
* In a LOGICAL, LOGICAL*2, or LOGICAL*4 type statement with a *1
length override.
You can specify a BYTE variable implicitly without declaring it by
beginning it with a letter that implies LOGICAL*1 or BYTE. Such initial
letters can be set with an IMPLICIT statement. There is no default.
BYTE Constants.
A BYTE constant can be:
* An integer constant, in the range -128 to +127.
* A logical constant, .TRUE. or .FALSE., representing true or false,
respectively. The periods are required, as shown.
* A character constant of one character.
NOTE The underlying definition of a BYTE/LOGICAL*1 data type is as a
one-byte integer. Its use as a logical and character datum is an
addition to this definition. In most cases, these uses are
unrestricted; however, when it is a list item in list-directed READ
and WRITE statements it can only be used as a one-byte integer.
See "List-Directed Input/Output" for further details.
INTEGER*2 Data Type
The INTEGER*2 data type represents the set of signed whole numbers in the
range -32768 to +32767. Variables and constants of type INTEGER*2 are
stored in two bytes. Refer to Chapter 10 for details. INTEGER*2 is
an extension to the ANSI 77 standard.
You can specify an INTEGER*2 variable explicitly by declaring it:
* In an INTEGER*2 type statement.
* In an INTEGER type statement when INTEGER is equivalent to
INTEGER*2.
* In an INTEGER or INTEGER*4 type statement with a *2 length
override.
You can specify an INTEGER*2 variable implicitly without declaring it by
beginning it with a letter that implies INTEGER*2, or that implies
INTEGER when INTEGER is equivalent to INTEGER*2. By default, the initial
letters I, J, K, L, M, and N imply INTEGER. These defaults can be changed
with an IMPLICIT statement.
NOTE By default, the type keyword INTEGER is equivalent to INTEGER*4.
This is the same as the effect of the LONG compiler directive. The
SHORT compiler directive may be used to make INTEGER equivalent to
INTEGER*2. See Chapter 7 for further details. In addition,
compiler run-string options can have the same effect. See Chapter
6 for further details.
INTEGER*2 Constant.
An integer constant consists of an optional plus (+) or minus (-) sign
followed by one or more decimal digits (0 to 9). An INTEGER*2 constant
has the whole-number range -32768 to +32767.
The default type for integer constants depends on the default type for
the INTEGER keyword. If the default type for INTEGER is INTEGER*2 (that
is, the SHORT compiler directive is in effect), then integer constants in
the range -32768 to +32767 default to INTEGER*2. Otherwise (if LONG is
in effect or the value is too large), integer constants default to
INTEGER*4.
You may specify an INTEGER*2 constant explicitly by appending the letter
I to the number. This is an extension to the ANSI 77 standard.
An integer constant value outside the INTEGER*4 range generates a
compile-time error. If I is appended to the constant, a value outside
the INTEGER*2 range also generates a compile-time error. When assigned
to or read into a variable at run-time, a number outside the range of the
variable causes an overflow condition. The handling of overflow
conditions is system dependent. Refer to Chapter 9 for more details.
Examples
The following are valid INTEGER*2 constants.
-32767 -638 30000I -4I 0 45
INTEGER*4 Data Type
The INTEGER*4 data type represents the set of signed whole numbers in the
range -2147483648 to +2147483647. Variables and constants of type
INTEGER*4 are stored in four bytes. Refer to Chapter 10 for details.
INTEGER*4 is an extension to the ANSI 77 standard.
You can specify an INTEGER*4 variable explicitly by declaring it:
* In an INTEGER*4 type statement.
* In an INTEGER type statement when INTEGER is equivalent to
INTEGER*4.
* In an INTEGER or INTEGER*2 type statement with a *4 length
override.
You can specify an INTEGER*4 variable implicitly without declaring it by
beginning it with a letter that implies INTEGER*4, or that implies
INTEGER when INTEGER is equivalent to INTEGER*4. By default, the initial
letters I, J, K, L, M, and N imply INTEGER. These defaults can be changed
with an IMPLICIT statement.
NOTE By default, the type keyword INTEGER is equivalent to INTEGER*4.
This is the same as the effect of the LONG compiler directive. The
SHORT compiler directive may be used to make INTEGER equivalent to
INTEGER*2. See Chapter 7 for further details. In addition,
compiler run-string options can have the same effect. See Chapter
6 for further details.
INTEGER*4 Constant.
An integer constant consists of an optional plus (+) or minus (-) sign
followed by one or more decimal digits (0 to 9). An INTEGER*4 constant
has the whole-number range -2147483648 to +2147483647.
The default type for integer constants depends on the default type for
the INTEGER keyword. If the default type for INTEGER is INTEGER*2 (that
is, the SHORT compiler directive is in effect), then integer constants in
the range -32768 to +32767 default to INTEGER*2. Otherwise (if LONG is
in effect or the value is too large), integer constants default to
INTEGER*4.
You may specify an INTEGER*4 constant explicitly by appending the letter
J to the number. This is an extension to the ANSI 77 standard.
An integer constant value outside the INTEGER*4 range generates a
compile-time error. When assigned to or read into a variable at
run-time, a number outside the range of the variable causes an overflow
condition. The handling of overflow conditions is system dependent.
Refer to Chapter 9 for more details.
Examples
The following are valid INTEGER*4 constants.
-3 14 -99526 30000J
-4J 2147483647 0 32768
REAL*4 Data Type
The REAL*4 data type, sometimes called "single precision", represents the
set of real numbers whose normal range is 0.0 and +-1.175494*10-38 to
+-3.402823*10+38 and whose precision is approximately seven decimal
digits. Variables and constants of type REAL*4 are stored in four bytes
in floating point format. Refer to Chapter 10 for details. REAL*4
is an extension to the ANSI 77 standard. It is equivalent to the ANSI
standard REAL type.
You can specify a REAL*4 variable explicitly by declaring it:
* In a REAL*4 or a REAL type statement.
* In a REAL*8, REAL*16, or DOUBLE PRECISION type statement with a *4
length override.
You can specify a REAL*4 variable implicitly without declaring it by
beginning it with a letter that implies REAL*4 or REAL. By default, the
initial letters A to H and O to Z imply REAL. These defaults can be
changed with an IMPLICIT statement.
REAL*4 Constant.
A REAL*4 constant must contain a decimal point or an exponent or both.
It can have a leading plus (+) or minus (-) sign. The exponent is
specified with the letter E.
Syntax
sn.n
s.n
sn.
sn.nEse
s.nEse
sn.Ese
snEse
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| s | Optional sign. | None. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| n | Whole number or fraction of value. | One or more decimal digits. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| e | Exponent. | One or more decimal digits. |
| | | |
-----------------------------------------------------------------------------------------------
The construct Ese represents a power of 10. For example:
14.E-5 = 14. * 10-5 = .00014
5.834E2 = 5.834 * 102 = 583.4
Examples
The following are valid REAL*4 constants.
-.74E-12 1.99526. .125 5.997255E8
-99526. 10. 23.99844E-25 6E0
REAL*8 Data Type
The REAL*8 data type, sometimes called "double precision",
represents the set of real numbers whose normal range is 0.0 and
+-2.225073858507202*10-308 to +-1.797693134862315*10+308 and whose
precision is approximately 17 decimal digits. Variables and constants of
type REAL*8 are stored in eight bytes in floating point format. Refer to
Chapter 10 for details. REAL*8 is an extension to the ANSI 77
standard. It is equivalent to the ANSI standard DOUBLE PRECISION type.
You can specify a REAL*8 variable explicitly by declaring it:
* In a REAL*8 or a DOUBLE PRECISION type statement.
* In a REAL*4 or REAL*16 type statement with a *8 length override.
You can specify a REAL*8 variable implicitly without declaring it by
beginning it with a letter that implies REAL*8 or DOUBLE PRECISION. Such
initial letters can be set with an IMPLICIT statement. There is no
default.
REAL*8 Constant.
A REAL*8 constant can contain a decimal point. It must have an exponent.
It can have a leading plus (+) or minus (-) sign. The exponent is
specified with the letter D.
Syntax
sn.nDse
s.nDse
sn.Dse
snDse
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| s | Optional sign | None |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| n | Whole number or fraction of value. | One or more decimal digits. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| e | Exponent. | One or more decimal digits. |
| | | |
-----------------------------------------------------------------------------------------------
The construct Dse represents a power of 10. For example:
14.D-5 = 14. * 10-5 = .00014
5.834D2 = 5.834 * 102 = 583.4
Examples
The following are valid REAL*8 constants.
-.74D-12 10.D0 5.99725529D8
1.99526D1 23.9984432697338D-25 6D0
REAL*16 Data Type
The REAL*16 data type, sometimes called "quad precision",
represents the set of real numbers whose normal range is
0.0 and +-3.362103143112093506262677817321753*10-4932 to
+-1.189731495357231765085759326628007*10+4932 and whose precision is
approximately 34 decimal digits. Variables and constants of type REAL*16
are stored in 16 bytes in floating point format. Refer to Chapter 10
for details. REAL*16 is an extension to the ANSI 77 standard.
You can specify a REAL*16 variable explicitly by declaring it:
* In a REAL*16 type statement.
* In a REAL*4, REAL*8, or DOUBLE PRECISION type statement with a *16
length override.
You can specify a REAL*16 variable implicitly without declaring it by
beginning it with a letter that implies REAL*16. Such initial letters
can be set with an IMPLICIT statement. There is no default.
REAL*16 Constant.
A REAL*16 constant can contain a decimal point. It must have an
exponent. It can have a leading plus (+) or minus (-) sign. The
exponent is specified with the letter Q.
Syntax
sn.nQse
s.nQse
sn.Qse
snQse
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| s | Optional sign | None |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| n | Whole number or fraction of value. | One or more decimal digits. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| e | Exponent. | One or more decimal digits. |
| | | |
-----------------------------------------------------------------------------------------------
The construct Qse represents a power of 10. For example:
14.Q-5 = 14. * 10-5 = .00014
5.834Q2 = 5.834 * 102 = 583.4
Examples
The following are valid REAL*16 constants.
6Q0 -6.475175119438025110924438958227647Q-4966
1.0Q+15 +1.189731495357231765085759326628007Q+4932
.00001Q-10 3.14159265358979Q0
COMPLEX*8 Data Type
The COMPLEX*8 data type defines a set of complex numbers whose
representation is an ordered pair of REAL*4 values. The first of the
pair represents the real part of the value and the second represents the
imaginary part. Each part has the same range and precision as a REAL*4
value. Variables and constants of type COMPLEX*8 are stored in eight
bytes as two REAL*4 values. Refer to Chapter 10 for details.
COMPLEX*8 is an extension to the ANSI 77 standard. It is equivalent to
the ANSI standard COMPLEX data type.
You can specify a COMPLEX*8 variable explicitly by declaring it:
* In a COMPLEX*8 or a COMPLEX type statement.
* In a COMPLEX*16 or DOUBLE COMPLEX type statement with a *8 length
override.
You can specify a COMPLEX*8 variable implicitly without declaring it by
beginning it with a letter that implies COMPLEX*8 or COMPLEX. Such
initial letters can be set with an IMPLICIT statement. There is no
default.
COMPLEX*8 Constant.
The form of a COMPLEX*8 constant is an ordered pair of numeric constants
(which may each be REAL*4, INTEGER*4, or INTEGER*2), separated by a
comma, and surrounded by parentheses.
Syntax
( real_part , imag_part )
Examples
The following are valid COMPLEX*8 constants.
(3.0,-2.5E3) (3.5,5.4) (45.9382,12)
(0,0) (-187,-160.5)
COMPLEX*16 Data Type
The COMPLEX*16 data type defines a set of complex numbers whose
representation is an ordered pair of REAL*8 values. The first of the
pair represents the real part of the value and the second represents the
imaginary part. Each part has the same range and precision as a REAL*8
value. Variables and constants of type COMPLEX*16 are stored in 16 bytes
as two REAL*8 values. Refer to Chapter 10 for details. COMPLEX*16
and DOUBLE COMPLEX are extensions to the ANSI 77 standard. They are
equivalent.
You can specify a COMPLEX*16 variable explicitly by declaring it:
* In a COMPLEX*16 or DOUBLE COMPLEX type statement.
* In a COMPLEX*8 or COMPLEX type statement with a *8 length
override.
You can specify a COMPLEX*16 variable implicitly without declaring it by
beginning it with a letter that implies COMPLEX*16 or DOUBLE COMPLEX.
Such initial letters can be set with an IMPLICIT statement. There is no
default.
COMPLEX*16 Constant.
The form of a COMPLEX*16 constant is an ordered pair of numeric
constants, separated by a comma, and surrounded by parentheses. One of
the pair of constants must be REAL*8. The other can be REAL*8, REAL*4,
INTEGER*4, or INTEGER*2).
Syntax
( real_part , imag_part )
Examples
The following are valid COMPLEX*16 constants.
(-187,-160.5) (0,5.99537D5) (3.5,5.4D0)
(0,0D0) (3.0,-2.5D3) (45.9382D0,12)
(-153D-12,4.66257) (1.56792456774D-24,-9.74375486354D-21)
LOGICAL*2 Data Type
The LOGICAL*2 data type represents the logical values true and false.
Variables and constants of type LOGICAL*2 are stored in two bytes. Refer
to Chapter 10 for details. LOGICAL*2 is an extension to the ANSI 77
standard.
You can specify an LOGICAL*2 variable explicitly by declaring it:
* In a LOGICAL*2 type statement.
* In a LOGICAL type statement when LOGICAL is equivalent to
LOGICAL*2.
* In a LOGICAL, LOGICAL*1, or LOGICAL*4 type statement with a *2
length override.
You can specify a LOGICAL*2 variable implicitly without declaring it by
beginning it with a letter that implies LOGICAL*2, or that implies
LOGICAL when LOGICAL is equivalent to LOGICAL*2. Such initial letters
can be set with an IMPLICIT statement. There is no default.
NOTE By default, the type keyword LOGICAL is equivalent to LOGICAL*4.
This is the same as the effect of the LONG compiler directive. The
SHORT compiler directive may be used to make LOGICAL equivalent to
LOGICAL*2. See Chapter 7 for further details. In addition,
compiler run-string options can have the same effect. See Chapter
6 for further details.
LOGICAL*2 Constants.
A LOGICAL*2 constant has the following forms and values:
Constant Value
.FALSE. Logical false
.TRUE. Logical true
The periods are required, as shown.
LOGICAL*4 Data Type
The LOGICAL*4 data type represents the logical values true and false.
Variables and constants of type LOGICAL*4 are stored in four bytes.
Refer to Chapter 10 for details. LOGICAL*4 is an extension to the
ANSI 77 standard.
You can specify an LOGICAL*4 variable explicitly by declaring it:
* In a LOGICAL*4 type statement.
* In a LOGICAL type statement when LOGICAL is equivalent to
LOGICAL*4.
* In a LOGICAL, LOGICAL*1, or LOGICAL*2 type statement with a *4
length override.
You can specify a LOGICAL*4 variable implicitly without declaring it by
beginning it with a letter that implies LOGICAL*4, or that implies
LOGICAL when LOGICAL is equivalent to LOGICAL*4. Such initial letters
can be set with an IMPLICIT statement. There is no default.
NOTE By default, the type keyword LOGICAL is equivalent to LOGICAL*4.
This is the same as the effect of the LONG compiler directive. The
SHORT compiler directive may be used to make LOGICAL equivalent to
LOGICAL*2. See Chapter 7 for further details. In addition,
compiler run-string options can have the same effect. See Chapter
6 for further details.
LOGICAL*4 Constants.
A LOGICAL*4 constant has the following forms and values:
Constant Value
.FALSE. Logical false
.TRUE. Logical true
The periods are required, as shown.
CHARACTER Data Type
The CHARACTER data type represents a string of characters. The string
can consist of any characters from the 8-bit ASCII character set,
described in Appendix D . Variables and constants of type CHARACTER
are stored in one byte per character.
You can specify an CHARACTER variable explicitly by declaring it in a
CHARACTER type statement.
You can specify a CHARACTER variable implicitly without declaring it by
beginning it with a letter that implies CHARACTER. Such initial letters
can be set with an IMPLICIT statement. There is no default.
Each character in a string has a character position that is numbered
consecutively: 1, 2, 3, and so forth. The number indicates the
sequential position of a character in the string, from left to right.
CHARACTER Constant.
The form of a character constant is an apostophe (') or quotation mark
("), optionally followed by a string of characters, and terminated with a
pairing apostrope or quotation mark. The use of the quotation mark is an
extension to the ANSI 77 standard.
Syntax
'[character][...]'
"[character][...]"
The length of a character constant is the number of characters between
the delimiting characters (which are not counted).
If an apostrophe is included in a string delimited by apostrophes, or a
quotation mark is included in a string delimited by quotation marks, it
must be written twice with no intervening blanks to distinguish it from
the delimiting characters. Such pairs count as one character.
As an extension to the ANSI 77 standard, null strings are permitted in
the same context where other strings are allowed. Null strings and
non-null strings are equivalent because they follow the rules of
character constants or typeless constants depending on the context.
As an extension to the ANSI 77 standard, character literals can represent
numeric constants. See the following section, "Typeless Constants" ,
for details.
You can include nonprintable characters in a string, but it is better to
specify these with the CHAR intrinsic function and concatenate them to a
string. See Appendix B for details. The blank character is valid
and significant in a CHARACTER value. Lowercase characters are not
identical to their uppercase equivalents in CHARACTER values.
Examples
'Input the next item' "Item #1 =>"
'EXPECTING A "1" OR A "2"' "EXPECTING A ""1"" OR A ""2"""
'EXPECTING A ''1'' OR A ''2''' "EXPECTING A '1' OR A '2'"
'That''s life!' "That's life!"
'' ""
Typeless Constants
Hollerith, octal, and hexadecimal constants (see following sections) are
considered typeless constants. Character constants that are used in
numeric expressions are handled like Hollerith constants. Typeless
constants are extensions to the ANSI 77 standard. A typeless constant is
a constant that does not undergo the type checking that would normally
prevent you from using it in expressions.
The following four assignments to INTEGER*4 variable i result in
identical values for i.
i = 'ffff' character constant
i = 1717986918 decimal integer constant
i = '66666666'X hexadecimal constant
i = 4Hffff Hollerith constant
The numeric value of the character constant 'ffff' is quite different
from the numeric value of the hexadecimal constant 'ffff'X.
'ffff' = "ffff" = 1717986918 the fs are letters having ASCII byte values
'ffff'X = 'FFFF'X = 65535 the fs are hexadecimal digits having half-byte values
Typical uses of typeless constants include:
* Performing integer arithmetic with binary values
* Manipulating expressions oriented to bit masks
* Pattern handling
* Performing simple arithmetic on ASCII values
All typeless constants are internally converted to a 32-digit (16-byte)
hexadecimal value and eventually converted to one of the FORTRAN 77
standard types. The conversion rule for typeless constants is as
follows: If a typeless constant appears in an expression with an operand
that has an assigned type, it takes the type of the other operand. If
this rule cannot be applied, the typeless constant is converted to
INTEGER*4.
The following examples illustrate the conversion rule for typeless
constants:
Examples Notes
--------------------------------------------------------------------------------------
REAL r The hexadecimal value of 'CAFE' is taken as INTEGER*4 because
r = 'CAFE'X + 1 the other operand, 1, is an INTEGER*4. 'CAFE' becomes the
integer value 51966, which is added to the value 1. The
resulting integer value 51967 is assigned to r.
INTEGER n The hexadecimal value of 'CAFE' is taken as INTEGER*2 because
n = 'CAFE'X + 0I the other operand, 0I, is INTEGER*2. Therefore the value -13570
is assigned to n.
REAL r The hexadecimal value of 'CAFE' is taken as the real value
r = 'CAFE'X + 1.0 7.28198E-41 because the other operand, 1.0, is real. The value
7.28198E-41 is so small that, when it is added to 1.0 using
floating-point arithmetic, the result is 1.0, which is the value
assigned to r.
NOTE As illustrated in the last example, you must use caution when
mixing typeless constants and floating-point types.
When typeless constants are passed as parameters to subprograms, the
default INTEGER*4 type is assumed unless the constant is embedded in an
expression. Therefore, the statement:
CALL SUBROUTINE('CAFE'X)
passes the INTEGER*4 value 51966 to the subroutine. However, the
statement:
CALL SUBROUTINE('CAFE'X+0.0)
passes the real value 7.28198E-41 and the statement:
CALL SUBROUTINE(('CAFE'X+0)+0.0)
passes the real value 51966.0.
Typeless constants can be used wherever constant expressions are allowed.
They can be mixed with other constants regardless of their final value.
Therefore, expressions such as the following are possible:
I = z'a' + "bc" * (-123b/('x'-1)) + '0'x - 9j
This assignment yields the value 1 (of type INTEGER*4).
When character and Hollerith constants are found in arithmetic
expressions such as the one above, they are padded on the right with
blanks (hexadecimal 20). Therefore, the following are all equivalent:
I = '0'
I = '0 Delta Delta Delta '
I = 1H0
I = 4h0 Delta Delta Delta
Hollerith Constants
Hollerith constants are an extension to the ANSI standard. They are
available for compatibility with older programs and with some system
routines. They can appear in arithmetic expressions representing ASCII
values. A Hollerith constant consists of a positive integer constant
specifying the number of characters (including blanks), followed by the
letter H and the character string, which can include trailing blanks.
Syntax
nHc[c][...]
Examples
2H$$
8Ha string
12HReport Title
6H&proga
3H12a
7Hqu'oted
Hollerith constants can be used in most places where an integer constant
is allowed, such as in assignment statements, DATA statements, PARAMETER
statements, and equality comparisons (for example, .EQ. or .NE.).
Hollerith constants can be assigned and compared to arithmetic variables
and expressions, but not to logical expressions. When necessary, a
Hollerith constant is truncated on the right or blank-filled on the right
so that its length is equal to that of the other operand. The resulting
type of the Hollerith constant is that of the argument on the other side
of the operator. Hollerith to Hollerith operations are not allowed.
Data type is not assumed when Hollerith constants are used as arguments.
Note, however, that Hollerith constants cannot be passed as character
constants. Hollerith and character constants are not interchangeable.
When Hollerith constants are used as arguments, no blank filling occurs.
Therefore, the lengths of Hollerith constants must correspond correctly
with formal arguments.
Examples Notes
---------------------------------------------------------------------------------------
r = 2Hab These two statements are equivalent.
r = 4HabDelta Delta
COMPLEX c These two statement pairs are equivalent.
IF (c .NE. 19Hwhen the wind blows)...
COMPLEX c
IF (c .NE. 8Hwhen the)...
i2 = 2hxy The resulting value of i2 is 30841 (type
INTEGER*2).
i4 = 2hxy The resulting value of i4 is 2021204000
(type INTEGER*4).
Blank filling and truncation to resolve length differences can be
accomplished on Hollerith constants only, and not on arithmetic variables
created from Hollerith data. On arithmetic variables, the appropriate
arithmetic conversions are performed. For example, if i2 is equal to
2Hxy, and i4 is equal to i2, then i4 is not equal to 4Hxy.
NOTE Hollerith literals can represent numeric constants. See "Typeless
Constants" earlier in this chapter for details.
Octal Constants
Octal constants are an extension to the ANSI 77 standard. They are a
special format of octal values that are stored internally as hexadecimal
values of up to 32 hexadecimal digits (16 bytes). Eventually they are
converted to a standard type.
Octal constants are left-padded with zeros. For example,
O'7777'
is stored internally as the hexadecimal value:
00000000000000000000000000000FFF
(that is, FFF preceded by 29 zeros).
Three formats are allowed for octal constants:
Syntax
snB
O'n'
'n'O
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| s | Optional sign. | None. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| n | Unsigned octal number. | Contains only the octal digits 0 |
| | | to 7. |
| | | |
-----------------------------------------------------------------------------------------------
The O'n' form is a MIL-STD-1753 standard extension to the ANSI 77
standard.
Octal constants can be used in most places where an integer constant is
allowed. See "Typeless Constants" earlier in this chapter for
details.
NOTE For good programming style, you should avoid using octal constants
in floating-point expressions.
Examples
400B O'2137' '2137'O
100000B O'37777777777' 37777777777B
Octal constants are not assigned a type. The data type to which they are
converted is determined by the context in which they are found, as
explained in the next two sections.
Octal Constants in Assignments.
When associated with another operand in an assignment statement, an octal
constant takes the type of the other operand. If no type can be taken
from the other operand, INTEGER*4 is assumed.
If not associated with another operand in an assignment statement, an
octal constant takes the type of the entity on the left side of the equal
sign. This is illustrated in the first two assignments in the following
examples.
Examples Notes
--------------------------------------------------------------------------------------
INTEGER*2 I2 The resulting value of I2 is 22617 (type INTEGER*2).
INTEGER*4 I4 This is the numeric equivalent of the Hollerith constant
. 'XX'.
.
.
I2 = O'54131'
I4 = o'54132' The resulting value of I4 is 22618 (type INTEGER*4).
This is the numeric equivalent of the Hollerith constant
'XY'.
I2 = I4 - O'1' The resulting value of I4 is 22617 (INTEGER*2). This is
the numeric equivalent of 'XX' . Note that this
operation is not possible using Hollerith constants (see
the next two assignments).
I2 = 2HXX The resulting value of I2 is 22617 (type INTEGER*2).
I4 = 2HXY The resulting value of I4 is 1482235936 (type INTEGER*4).
Two blanks have been appended.
I2 = I4 - O'1' The resulting value of I2 is 8223 (type INTEGER*2). The
result has been truncated.
I4 = 1 + 4H0000 + O'1' The resulting value of I4 is 808464434 (type INTEGER*4).
This is the numeric equivalent of '0002' .
Octal Constants as Actual Parameters.
When used as actual parameters, octal constants are converted to
INTEGER*4. To pass an octal constant as a different data type, use the
constant in an expression of the desired type.
Examples Notes
--------------------------------------------------------------------------------------
CALL example(O'7777') Passes the value 4095 as data type INTEGER*4 (the
default).
CALL example(O'7777' + 0i) Passes the value 4095 as data type INTEGER*2.
NOTE When the data type that receives an octal constant does not have
sufficient space to hold all the significant bits, a warning is
issued and the constant is left-truncated to fit as many bits as
possible into the variable. For example, if the following
assignment is made:
I2 = o'76543210'
I2 (INTEGER*2) is assigned the value o'143210', which is the
maximum number of bits of that value that can fit into the
INTEGER*2 variable.
Hexadecimal Constants
Hexadecimal (base 16) constants are an extension to the ANSI 77 standard.
They are stored internally as hexadecimal values of up to 32 hexadecimal
digits (16 bytes), and eventually they are converted to a standard type.
The Z'n' form is a MIL-STD-1753 extension to the ANSI 77 standard.
Hexadecimal constants are left-padded with zeros. For example,
Z'FFFF'
is stored internally as:
0000000000000000000000000000FFFF
(that is, FFFF preceded by 28 zeros).
The following formats are allowed for hexadecimal constants:
Syntax
Z'n'
'n'X
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| n | Unsigned hexadecimal number. | Contains the hexadecimal digits 0 |
| | | to 9 and A to F. |
| | | |
-----------------------------------------------------------------------------------------------
Either form can be used in most places where an integer constant is
allowed. See "Typeless Constants" earlier in this chapter for
details.
Examples
Z'f921'
z'CAFE'
'F9A1'X
'cafe'x
Hexadecimal constants are not assigned a type. They are converted to a
standard FORTRAN type according to the context in which they are found.
This is explained in the next two sections.
Hexadecimal Constants in Assignments
When associated with another operand in an assignment statement, a
hexadecimal constant takes the type of the other operand. If no type can
be taken from the other operand, INTEGER*4 is assumed.
If not associated with another operand in an assignment statement, a
hexadecimal constant takes the type of the entity on the left side of the
equal sign. This is illustrated in the first two assignments in the
following example.
Examples Notes
--------------------------------------------------------------------------------------
INTEGER*2 I2 The resulting value of I2 is -1 (type INTEGER*2).
INTEGER*4 I4
DOUBLE PRECISION R8
.
.
.
I2 = Z'FFFF'
I4 = Z'FFFF' The resulting value of I4 is 65535 (type INTEGER*4).
R8 = z'3ff0000000000000' The resulting value of R8 is 1.0 (type s'' `REAL*8'').
I4 = Z'3FF0000000000000'- R8 The resulting value of I4 is 0 (type INTEGER*4).
I4 = Z'1' - R8 The resulting value of I4 is -1 (type INTEGER*4).
I4 = z'1' + 4H0000 + o'1' The resulting value of I4 is 808464434 (type INTEGER*4).
This is the numeric equivalent of '0002'.
NOTE As a good programming practice, you should avoid using hexadecimal
constants in floating-point expressions.
Hexadecimal Constants as Actual Parameters
When used as actual parameters, hexadecimal constants are converted to
INTEGER*4. To pass a hexadecimal constant as a different data type, the
constant should be used in an expression of the desired type.
Examples Notes
--------------------------------------------------------------------------------------
CALL example(Z'FFF') Passes the value 4095 as data type INTEGER*4 (the
default).
CALL example(Z'FFF' + 0i) Passes the value 4095 as data type INTEGER*2.
NOTE When the data type that receives a hexadecimal constant does not
have sufficient space to hold all the significant bits, a warning
is issued and the constant is left-truncated to fit as many bits as
possible into the variable. For example, if the following
assignment is made:
I2 = z'abcdef'
I2 (type INTEGER*2) is assigned the value z'cdef'.
MPE/iX 5.0 Documentation