Silverfrost Forums

Welcome to our forums

Reading Unknown Binary Files

5 Jan 2009 7:02 #4167

The code I am using to open the binary file is ...

CHARACTER SHIP32, DATE8 INTEGER NUMBR REAL XLBP,BEAM

OPEN (IHYD,FORM='UNFORMATTED',ACCESS='TRANSPARENT', FILE='FOR013.DAT')

READ (IHYD) SHIP,NUMBR,DATE READ (IHYD) XLBP,BEAM

It opens the file for reading, but the data isn't correctly read into the variables. Am I using the OPEN function correctly for opening binary files, where the format and source is unknown? I assume DIRECT access is more suitable, but the record length is unknown. Also, if the TRANSPARENT feature is assigned, does the program or programmer has to know the exact structure of the file, i.e. exact length and type of the data in the file (number of spaces, etc.) corresponding to specific declaractions of variables used to extract the data?

5 Jan 2009 9:03 #4168

perhaps you should try: open(unit=ihyd,file='FOR013.DAT',access='sequential',FORM='Binary')

that works for binary files for me. the only problem you may encounter is if the binary is created by a program which writes a 'different' type of binary (some languages include information such as string/line length or other information prior to each binary line, etc) What program creates the binary? If fortran, the above should work

Brian

5 Jan 2009 11:17 #4169

It depends very much on where the 'binary file' was created.

ACCESS='TRANSPRENT'; gives the most flexibility in reading the binary file, but you must also read the record header bytes which were probably included when the file was created. This problem is solveable, once you know the file structure.

A simple alternative would be to get the file as a text file. That way you can easily see what is in the FOR013.DAT file. There is little time penalty for using a text file.

John

Please login to reply.