Sun Studio 12: Fortran Programming Guide

7.5 Hollerith Data

Many “dusty-deck” Fortran applications store Hollerith ASCII data into numerical data objects. With the 1977 Fortran standard (and Fortran 95), the CHARACTER data type was provided for this purpose and its use is recommended. You can still initialize variables with the older Fortran Hollerith (nH) feature, but this is not standard practice. The following table indicates the maximum number of characters that will fit into certain data types. (In this table, boldfaced data types indicate default types subject to promotion by the -xtypemap command-line flag.)

Table 7–1 Maximum Characters in Data Types

 

Maximum Number of Standard ASCII Characters  

 

 

 

Data Type  

Default  

INTEGER:64

REAL:64

DOUBLE:128

BYTE

COMPLEX

16 

16 

COMPLEX*16

16 

16 

16 

16 

COMPLEX*32

32 

32 

32 

32 

DOUBLE COMPLEX

16 

16 

32 

32 

DOUBLE PRECISION

16 

16 

INTEGER

INTEGER*2

INTEGER*4

INTEGER*8

LOGICAL

LOGICAL*1

LOGICAL*2

LOGICAL*4

LOGICAL*8

REAL

REAL*4

REAL*8

REAL*16

16 

16 

16 

16 

Example: Initialize variables with Hollerith:


demo% cat FourA8.f
      double complex x(2)
      data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
      write( 6, ’(4A8, "!")’ ) x
      end

demo% f95 -o FourA8 FourA8.f
demo% FourA8
abcdefghijklmnopqrstuvwxyz012345!
demo%

If needed, you can initialize a data item of a compatible type with a Hollerith and then pass it to other routines.

If you pass Hollerith constants as arguments, or if you use them in expressions or comparisons, they are interpreted as character-type expressions. Use the compiler option -xhasc=no to have the compiler treat Hollerith constants as typeless data in arguments on subprogram calls. This may be needed when porting older Fortran programs.