Implicit Data Item Conversion
Implicit data conversion in Fortran requires no explicit action by the program to convert the data in the I/O stream other than using the assign command to instruct the libraries to perform conversion. For details, see the assign(1) man page.
The implicit data conversion process is performed in two steps:
Record format conversion
Data conversion
Record format conversion interprets or converts the internal record blocking structures in the data stream to gain record-level access to the data. The data contained in the records can then be converted.
Using implicit conversion, you can select record blocking or deblocking alone, or you can request that the data items be converted automatically. When enabled, record format conversion and data item conversion occur transparently and simultaneously. Changes are usually not required in your Fortran code.
To enable conversion of foreign record formats, specify the appropriate record type with the assign -F command. The -N (numeric conversion) and -C (character conversion) assign options control conversion of data contained in a record. If -F is specified, but -N and -C are not, the libraries interpret the record format, but they do not convert data. You can obtain information about the type of data that will be converted (and, therefore, the type of conversion that will be performed) from the Fortran I/O list.
If -N is used and -C is not, an appropriate character conversion type is selected by default, as shown in the following table.
Table 11-2. Conversion types
-N option
| -C default
| Meaning
|
|---|
none
| none
| No data conversion
|
default
| default
| No data conversion
|
cray
| ASCII
| Non-IEEE data conversion
|
mips
| ASCII
| No data conversion
|
user
| ASCII
| User defined data conversion
|
site
| ASCII
| Site defined data conversion
|
ieee
| ASCII
| Generic 32-bit IEEE data conversion
|
ieee_32
|
| (alias for above)
|
ieee_64
| ASCII
| Cray 64-bit IEEE data conversion
|
ieee_le
| ASCII
| Little-endian 32-bit IEEE data conversion
|
vax
| ASCII
| DEC VAX/VMS data conversion
|
vms
|
| (alias for above)
|
Supported implicit data conversion includes conversion of the supported tape and disk formats and data types through standard Fortran formatted, unformatted list-directed, and Namelist I/O and through BUFFER IN and BUFFER OUT statements. Generally, read, write, and rewind are supported for all record formats.
If you select the -N option, the libraries perform data conversion for Fortran unformatted statements and BUFFER IN and BUFFER OUT I/O statements. Data is converted according to its Fortran data type. Table 11-3 describes the conversion performed for each of the conversion types.
For numeric data conversions, most foreign data elements are defined with fewer bits than their corresponding native data elements. If the value in a native element is too large to fit in the foreign element, the foreign element is set to the largest or smallest possible value; no error is generated. When converting from a native element to a smaller foreign element, precision is also lost due to truncation of the floating-point mantissa.
If the assign -N user or assign -N site command is specified, the user or site must provide site numeric data conversion routines. They follow the same calling conventions as the other explicit routines.
Table 11-3. Supported foreign I/O formats and default data types
Vendor data type
| Record formats
| Foreign data types
| Native data types
|
|---|
IBM
| U, F, FB, V, VB, VBS
| INTEGER*2
INTEGER*4
DOUBLE PRECISION
COMPLEX*4
LOGICAL*4
CHARACTER (EBCDIC)
| INTEGER(24/32)
INTEGER(64)
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER (ASCII)
|
VMS
| F, V, S for tape; bb or disk and tr types
| INTEGER*2
INTEGER*4
REAL*4
DOUBLE PRECISION
COMPLEX*4
LOGICAL*4
CHARACTER (ASCII)
| INTEGER(24/32)
INTEGER(64)
REAL(64)
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER (ASCII)
|
CDC (60 bit)
| Subtype: DISK, I, SI Block record: IW, CW, CZ, CS
| INTEGER
REAL
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER (display code)
| INTEGER
REAL
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER (ASCII)
|
CDC NOS/VE
| F, S, V
| INTEGER
REAL
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER
| INTEGER
REAL
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER (ASCII)
|
CDC/ETA CYBER205
| W type
| INTEGER
REAL
REAL*4
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER (display code)
| INTEGER
REAL
INTEGER(24/32) (See Note 1)
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER (ASCII)
|
IEEE
| None defined (often f77)
| INTEGER*2 (see Note 2)
INTEGER*4
REAL*4
DOUBLE PRECISION
COMPLEX*4
LOGICAL*4
CHARACTER (ASCII)
| INTEGER(24/32)
INTEGER(64)
REAL(64)
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER (ASCII)
|
ULTRIX
| f77.vax
| INTEGER*2
INTEGER*4
REAL*4
DOUBLE PRECISION
COMPLEX*4
LOGICAL*4
CHARACTER (ASCII)
| INTEGER(24/32)
INTEGER(64)
REAL(64) (see Note 3)
DOUBLE PRECISION
COMPLEX
LOGICAL
CHARACTER (ASCII)
|
Note 1: The CYBER 205 half-precision type maps to the short integer (INTEGER*2) type
|
For implicit conversion, specify format characteristics on an assign command.
Files can be converted to one of the following:
When a Fortran I/O operation is performed on the file, the appropriate file format and data conversions are performed during the I/O operation. Data conversion is performed on each data item, based on the type of the Fortran variable in the I/O list.
For example, if the first read of a foreign format file is the following, the library interprets any blocking structures in the file that precede the first data record:
READ (10) INT,FLOAT1,FLOAT2 |
These vary depending on the file type and record format. The first 32 bits of data (in IBM format, for example) are extracted, sign-extended, and stored in the INT Fortran variable. The next 32 bits are extracted, converted to native floating-point format, and stored in the FLOAT1 Fortran variable.
The next 32 bits are extracted, converted, and stored into the FLOAT2 Fortran variable. The library then skips to the end of the foreign logical record. When writing from a native system to a foreign format (for example, if in the previous example WRITE(10) was used), precision is lost when converting from a 64-bit representation to 32-bit representation.