As part of a migration project, I am trying to read a binary file that was written under HP OpenVMS using FORM=UNFORMATTED ACCESS=DIRECT. Since the representations of integer and float data types differ on Intel/Windows I am getting wrong results. For integers a can do an easy fix just flipping the bytes, but floating-point numbers are an entirely different story.
I tried different CONVERT options in the OPEN statement as well as changed the compiler flag for unformatted file access conversion, but none of the settings seem to have an effect on my results. I would at least have expected a change of my results,
Is the conversion feature not supported in direct access mode or am I overlooking something?
I am using Visual Studio 2015 with Intel Composer 2016 XE. Thanks for any feedback
Do you know how the program was compiled on OpenVMS, and was this a VAX or Alpha system? If Alpha, the default if I recall correctly would be the same as CONVERT='VAXG'. Integers would be the same, and if /FLOAT=IEEE was used on the OpenVMS system, then you would not need CONVERT at all.
I don't know why you think you have to flip the bytes - the OpenVMS platforms and the Intel platforms are both little-endian.
If you know what the values should be, it would be interesting to see a hex dump of the first few records of the file (along with the record layout). Do keep in mind that CONVERT= doesn't convert unformatted I/O of derived type variables.
first of all thanks for your quick reply.
I have checked with the OpenVMS system and there are no special compiler flags set, everything would be the default values for HP Fortran.
Here is a code excerpt from the opening routine:
OPEN(UNIT=KANAL,FILE=FNAME,ACCESS='DIRECT', * STATUS='OLD',READONLY, SHARED,USEROPEN=FA_OPEN, * RECL=128,IOSTAT=STATUS)
I have also dumped the first few bytes of the file as interpreted on the OpenVMS host:
1,1 8 2,1 0 3,1 4 4,1 70 5,1 4096 6,1 1 1,2 7541 2,2 0 3,2 4 4,2 20 5,2 2048 6,2 1
So this would be the expected result. However when I run the same code under Windows, I am getting these numbers:
1,1 2048 2,1 0 3,1 1024 4,1 17920 5,1 1048576 6,1 256 1,2 1930496 2,2 0 3,2 1024 4,2 5120 5,2 524288 6,2 256
I have experimented with the conversion flag for unformatted file conversion in the Intel compiler settings, setting it to VAXG or something else, but nothing has an effect on the numbers. Thanks for your insights.
Sorry, your "
hex dumps" make no sense to me.
First of all, I don't know what you showed in the first column; what does, for example, "5,2" signify?
Secondly, unsigned byte values must be in the range 0..255 (or 0 .. 0xFF in hex). You have values that require 20 or more bits to represent them.
Given these inconsistencies, I should like to know if you can provide the file as-is.
As Steve already pointed out, VAXen are little-endian machines, so why was CONVERT needed? Did the file actually originate on a mainframe or other big-endian machine? Or did the processing involve byte-flipping twice over, in which case the second pass undid the flipping of the first pass?
I assume that what you show is output from the program - it is not helpful in understanding the issue.
First, what datatype(s) are in each record? Show the WRITE (or READ) statement and show us the declarations of each of the variables. What compiler options are you using on the PC? By any chance do you have /assume:byterecl or /standard-semantics enabled?
Now on the PC, in Visual Studio select File > Open > File... Select the data file you are trying to read but don't click Open yet. You will see a black triangle next to "Open", then select "Open With..." In the dialog that appears, select "Binary Editor" (probably next to last in the list).
This will open the file to show the raw data in hex. Take a screenshot of the display and attach it here.