Converting Binary Files to IEEE Format [ HP FORTRAN 77/iX Migration Guide ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Migration Guide
Converting Binary Files to IEEE Format
Since only you know the format of your program's data files, you should
write a short program (or two) to convert files. The easiest way is to
write two short programs, one to read in the unformatted file and write
it out as an ASCII (formatted) file, the other to reverse the process on
the MPE/iX operating system in native mode.
The FORMAT statement used should specify more than the actual precision
of the variables used. For example, use format descriptor E14.8 for
single precision and E24.18 for double precision. The first program can
be run either on the MPE V operating system or on MPE/iX. If on MPE/iX,
run it either in compatibility mode or in native mode with HP3000_16
REALS turned on. Running the conversion program in native mode with
HP3000_16 REALS can introduce a small amount of conversion error and some
loss of precision because of the differences between IEEE and HP 3000
floating-point formats. However, the total error introduced should not
exceed half of one decimal digit.
Here is an HP FORTRAN 77/V program that converts a data file to HP
FORTRAN 77/iX format:
C HP FORTRAN 77/V program to convert a direct access binary data
C file containing floating-point data items.
PROGRAM convert
REAL x, y, z
INTEGER*2 i, j
INTEGER*4 i4, recnum
DOUBLE PRECISION dp
OPEN (12, FILE='mydata', ACCESS='DIRECT', FORM='UNFORMATTED',
> RECL=28, STATUS='OLD')
OPEN (15, FILE='newdata', ACCESS='SEQUENTIAL', FORM='FORMATTED',
> STATUS='NEW')
recnum = 1
C Main loop reading and writing records until past the end of file,
C which is an error on a direct access file.
10 CONTINUE ! Do until end of file.
READ (12, REC=recnum, ERR=99) i, x, i4, dp, j, y, z
recnum = recnum + 1
WRITE (15, 100) i, x, i4, dp, j, y, z ! Same I/O list as READ.
100 FORMAT (I7, E14.8, I11, E24.18, I7, 2E14.8)
GOTO 10
C Exit from loop, file finished.
99 CONTINUE
STOP 'Now, :STORE off file "newdata" for transfer to MPE XL'
END
Here is an HP FORTRAN 77/iX program that converts an HP FORTRAN 77/V data
file:
C HP FORTRAN 77/iX program to convert direct access binary data
C file containing floating-point data items.
PROGRAM convert
REAL x, y, z
INTEGER*2 i, j
INTEGER*4 i4, recnum
DOUBLE PRECISION dp
OPEN (12, FILE='mydata', ACCESS='DIRECT', FORM='UNFORMATTED',
> RECL=28, STATUS='OLD') ! Native mode copy of original file.
OPEN (15, FILE='newdata', ACCESS='SEQUENTIAL', FORM='FORMATTED',
> STATUS='NEW') ! Input file restored from MPE V system.
recnum = 1
C Main loop reading and writing records until past the end of file.
10 CONTINUE ! Do until end of file.
READ (15, FMT=100, ERR=99) i, x, i4, dp, j, y, z
WRITE (12, REC=recnum) i, x, i4, dp, j, y, z ! Same I/O list as READ.
recnum = recnum + 1
100 FORMAT (I7, E13.8, I11, E23.18, I7, 2E13.8)
GOTO 10
C Exit from loop, file finished.
99 CONTINUE
WRITE (6, *) 'FILE "mydata" CREATED WITH', RECNUM - 1, ' RECORDS.'
CLOSE (15, STATUS='DELETE') ! Purge file used for transfer.
END
Another way is to use the HPFPCONVERT system intrinsic. A program can
read in the FORTRAN 77/V floating-point data, pass the data to
HPFPCONVERT for translation to IEEE format, and then write out the data
in native mode. This process can be performed completely in native mode
as long as no operations are performed on the FORTRAN 77/V format
floating-point data other than passing it to HPFPCONVERT. HPFPCONVERT is
described in detail in the MPE/iX Intrinsics Reference Manual.
HPFPCONVERT loses only the actual difference in precision of the two
floating-point formats (two bits for double precision, none in single).
NOTE Some single precision values that are legal on MPE V may not be
translated to IEEE single precision floating-point. The
untranslatable values are those of a magnitude greater than 138 or
less than 10-43.
MPE/iX 5.0 Documentation