forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reading Unknown Binary Files

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
kdangel



Joined: 31 Dec 2008
Posts: 6

PostPosted: Mon Jan 05, 2009 8:02 pm    Post subject: Reading Unknown Binary Files Reply with quote

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

CHARACTER SHIP*32, DATE*8
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?
Back to top
View user's profile Send private message
bgmchenry



Joined: 19 Jun 2007
Posts: 2
Location: usa

PostPosted: Mon Jan 05, 2009 10:03 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Tue Jan 06, 2009 12:17 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group