Reading data from binary files

Reading data from binary files

I am working towards making a 16 bit fortran application into a 32 bit application. The main application reads data from 2 UNFORMATTED files.

FILEA - SEQUENTIAL ACCESS

FILEB - DIRECT ACCESS, RECL = 1000

The application reads fine from FILEB, but when i use FILEA, it gives the error that it encountered the end of the file. Am i correct in assuming that this is because the 32 bit application will be able to read from FILEB but not from FILEA because of different types of data access modes? Will i have to regenerate FILEA on a 32 bit platform? ​

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

We need quite a bit more detail. Which Fortran compiler was used to build the application that wrote FILEA? What did the OPEN look like (which keywords were used?) I doubt it is a 16-bit vs. 32-bit issue, but there could be other things. It would be most helpful if you could attach a ZIP of FILEA so we could see its structure. What do you think each record holds?

Steve - Intel Developer Support

Hi Steve,

I don't think i am allowed to post the file here but i will try to be as descriptive as possible. Basically two other 16 bit applications(whose source code is also available) convert two formatted data files, say DATAA and DATAB into FILEA and FILEB respectively. DATAA contains a 27x5 table of real numbers. DATAB contains mixed info....it starts off with a 500 integer array followed by records composed of one integer-one 4 letter char and then a bunch of real numbers. 

The OPEN commands for FILEA and FILEB were as follows:

FILEA: OPEN(UNIT=8, ACCESS='SEQUENTIAL', FORM='UNFORMATTED',FILE='FILEA')

FILEB: OPEN(UNIT=9, ACCESS='DIRECT', FORM='UNFORMATTED', RECL=250, FILE=''FILEB')

When i recompiled the source code for the main application(with minor changes like variable declarations and changing RECL from bytes to 4-byte units) on a 32 bit platform and tried to read from the available binary data files that were generated using their respective 16 bit programs, the compiler read data from FILEB correctly but encountered the end of file during read for FILEA (forrtl severe 24). 

When I generated my own FILEA on a 32 bit platform by recompiling the source code for its generating program, i found that the main application read data correctly from FILEA this time. Why could this happen? I suspect i might be able to solve other problems i am facing if i knew the answer to this question.

Regarding the compiler used, i think it was MS FORTRAN 5.1, not too sure though. Maybe you would get an idea of that from the starting few lines of my MAKEFILE which read as follows:

fflags=/c /AL /FPi87 $*.for

.SUFFIXES: .for

.for.obj:
 fl /Gt9 $(fflags) >> prog.log

Regards,

Sudarshan

Microsoft Fortran had its own format for sequential unformatted files. I don't know about MS-DOS Fortran 5.1, but we do support the format used by Microsoft Fortran PowerStation. Try adding /fpscomp:ioformat to the list of build options. (In Visual Studio this is Fortran > Compatibility > Use PowerStation I/O Format)

 

Steve - Intel Developer Support

Okay, that didn't work for me. But then, are direct access unformatted files generated using Microsoft Fortran readable universally?

Probably, if you get the record length right. You're already aware of the units of RECL= issue.

Please do this - in Visual Studio, go to FIle > Open > File... select the data file you're having trouble with but don't click Open yet. Instead, click the black triangle just to the right of "Open" and select "Open With...". In the next dialog, select Binary Editor and click OK. Please take a screenshot of what you see in the editor window - you can attach it here, or use Send Author A Message and attach it privately. This will give me a clue as to what the file structure is.

Steve - Intel Developer Support

Hey Steve, my problem is solved. Actually, it worked for me once I turned on all the PowerStation compatibility options. You're awesome! Thanks a lot :) 

Glad to hear it.

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today