Many "dusty-deck" Fortran applications store Hollerith ASCII data into numerical data objects. With the 1977 Fortran standard (and Fortran 90), 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 f77 command-line flags -dbl, -r8, or -xtypemap= ).
Table 7-3 f77: Maximum Characters in Data Types
|
Maximum Number of Standard ASCII Characters |
||||
---|---|---|---|---|---|
Data Type |
No -i2, -i4, -r8, -dbl |
-i2 |
-i4 |
-r8 |
-dbl |
BYTE |
1 |
1 |
1 |
1 |
1 |
COMPLEX |
8 |
8 |
8 |
16 |
16 |
COMPLEX*16 |
16 |
16 |
16 |
16 |
16 |
COMPLEX*32 |
32 |
32 |
32 |
32 |
32 |
DOUBLE COMPLEX |
16 |
16 |
16 |
32 |
32 |
DOUBLE PRECISION |
8 |
8 |
8 |
16 |
16 |
INTEGER |
4 |
2 |
4 |
4 |
8 |
INTEGER*2 |
2 |
2 |
2 |
2 |
2 |
INTEGER*4 |
4 |
4 |
4 |
4 |
4 |
INTEGER*8 |
8 |
8 |
8 |
8 |
8 |
LOGICAL |
4 |
2 |
4 |
4 |
8 |
LOGICAL*1 |
1 |
1 |
1 |
1 |
1 |
LOGICAL*2 |
2 |
2 |
2 |
2 |
2 |
LOGICAL*4 |
4 |
4 |
4 |
4 |
4 |
LOGICAL*8 |
8 |
8 |
8 |
8 |
8 |
REAL |
4 |
4 |
4 |
8 |
8 |
REAL*4 |
4 |
4 |
4 |
4 |
4 |
REAL*8 |
8 |
8 |
8 |
8 |
8 |
REAL*16 |
16 |
16 |
16 |
16 |
16 |
When storing standard ASCII characters with normal Fortran:
With -r8, unspecified size INTEGER and LOGICAL do not hold double.
With -dbl, unspecified size INTEGER and LOGICAL do hold double.
The storage is allocated with both options, but it is unavailable in normal Fortran with -r8.
Options -i2, -r8, and -dbl are now considered obsolete; use -xtypemap instead.
Example: Initialize variables with Hollerith:
demo% cat FourA8.f double complex x(2) data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/ write( 6, '(4A8, "!")' ) x end demo% f77 -silent -o FourA8 FourA8.f demo% FourA8 abcdefghijklmnopqrstuvwxyz012345! demo%
If you pass Hollerith constants as arguments, or if you use them in expressions or comparisons, they are interpreted as character-type expressions.
If needed, you can initialize a data item of a compatible type with a Hollerith and then pass it to other routines.
program respond integer yes, no integer ask data yes, no / 3hyes, 2hno / if ( ask() .eq. yes ) then print *, 'You may proceed!' else print *, 'Request Rejected!' endif end integer function ask() double precision solaris, response integer yes, no data yes, no / 3hyes, 2hno / data solaris/ 7hSOLARIS/ 10 format( "What system? ", $ ) 20 format( a8 ) write( 6, 10 ) read ( 5, 20 ) response ask = no if ( response .eq. solaris ) ask = yes return end