Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
ISO/IEC 1539-2:2002, formally titled “Information technology — Programming languages — Fortran — Part 2: Varying-length character strings”, defines a mechanism for handling character strings whose length can change at runtime. It is an extension to the fixed-length character handling defined in the core Fortran standard (ISO/IEC 1539-1). The standard specifies a derived data type, VARYING_STRING, within a module named ISO_VARYING_STRING, along with a comprehensive set of operations and procedures for manipulating such strings. This part is essential for applications that require dynamic string processing, such as text parsing, data input, and report generation.
All varying-length string entities must be declared with the VARYING_STRING type, accessible by including the statement USE ISO_VARYING_STRING in the program unit. The standard mandates that the type implementation must store the current length and the character sequence. The module also provides overloaded operators for assignment, concatenation, relational comparisons, and a set of intrinsic-like procedures.
The standard specifies the following operations for VARYING_STRING:
The ISO_VARYING_STRING module supplies the following functions, among others:
| Function | Description |
|---|---|
| LEN(v) | Returns the length of the string (same as LEN for fixed but dynamic). |
| TRIM(v) | Returns the string with trailing blanks removed. |
| REPEAT(v, n) | Repeats the string n times. |
| INDEX(v, pattern) | Returns position of substring pattern. |
| REPLACE(v, pat, rep) | Replaces occurrences of pattern with replacement string. |
| SPLIT(v, delim) | Returns an array of substrings separated by delimiter. |
Note that these functions may have slight variations in interfaces; the standard ensures consistent semantics across implementations.
USE ISO_VARYING_STRING TYPE(VARYING_STRING) :: text text = 'Hello, World!' text = text // ' Welcome to Fortran.' WRITE(*,*) LEN(text), TRIM(text) Compilers implementing ISO/IEC 1539-2:2002 typically implement VARYING_STRING as a derived type with a character pointer or allocatable array. The module must manage memory for each string, often using deferred-length allocation or reference counting. Operators and procedures must be exposed through a .mod file when the module is compiled.
Key implementation challenges include ensuring thread safety, handling assignment with automatic (re)allocation, and conforming to the required interfaces.
A compiler claiming compliance with ISO/IEC 1539-2:2002 must provide the ISO_VARYING_STRING module exactly as specified. The module must include all required operator interfaces and procedures. Conformance tests exist to validate the implementation.
To ensure portability, use only the documented operations from the standard. Avoid relying on specific internal representation details. It is recommended to include the standard conformance statement in user documentation.