Prev: C interop to popen
Next: transfer from real to logical
From: kis on 2 Dec 2009 14:22 Hello Experts, I have a binary file created by FORTRAN program. I need to modify its content. Unfortunately, I don't have any manual that explains the format of this binary file. Is there a way to find the format in which this binary file is written? Thanks, kis
From: Sjouke Burry on 2 Dec 2009 14:54 kis wrote: > Hello Experts, > > I have a binary file created by FORTRAN program. I need to modify its > content. Unfortunately, I don't have any manual that explains the > format of this binary file. Is there a way to find the format in which > this binary file is written? > > Thanks, > kis /OT Try to get(threaten, demand)source code of the creating program. Else, the difficult way. What I did, was write a hex /ascii display program, which displayed a block of data, shift it through the file up/down in steps of 1,2,4,8,16,n bytes, and display the start of the block also as integer*2, int*4,float(4bytes) , double(8 bytes). Do the ints both in little and big-endian. !n as block size, which could be changed up and down. Then the fun starts. Try to spot block structure and size, and try to recognize values and text. I succeeded with this in 2 or 3 cases. Last resort: hunt down the writer of that program and beat the documentation/code out of him/her. /
From: kis on 2 Dec 2009 15:09 Thanks. KIS On Dec 2, 1:22 pm, kis <kisitangg...(a)gmail.com> wrote: > Hello Experts, > > I have a binary file created by FORTRAN program. I need to modify its > content. Unfortunately, I don't have any manual that explains the > format of this binary file. Is there a way to find the format in which > this binary file is written? > > Thanks, > kis
From: dpb on 2 Dec 2009 15:18 kis wrote: > Hello Experts, > > I have a binary file created by FORTRAN program. I need to modify its > content. Unfortunately, I don't have any manual that explains the > format of this binary file. Is there a way to find the format in which > this binary file is written? There's no Fortran Standard definition, but... An unformatted file is a sequence of unformatted records. An unformatted record is a sequence of values. The number of records and the content of each record is determined by the function of the program, of course. Not knowing those makes stuff even harder. Now we get to the "but", part...this isn't guaranteed, but typical implementations are generally similar-enough to describe. Unformatted direct files contain only the data and each record within the file is padded to a fixed length. Unformatted sequential files contain the data plus information that indicates the boundaries of each record. The latter is the easier to decipher as until the advent of file systems that could handle >2GB files the record boundaries were almost always a 32-bit integer at the beginning and end of each. Using a hex editor or file display tool, one can generally find those and determine the record structure, anyway. One is still left w/ the meaning of the data within each record, of course. The O(ther)P's suggestion of finding the information to go w/ the files would be a much easier way to go at it assuming there's any chance at all, of course--and recognizing sometimes there isn't. --
From: dpb on 2 Dec 2009 16:09
dpb wrote: .... > There's no Fortran Standard definition, but... ....[description of typical unformatted file implementations elided] I suppose I ought to add that just to make things even more fun, while it wasn't implemented as part of the Fortran Standard until F03, quite a lot of compilers had extensions to allow one to create/write/read arbitrary stream files (sometimes known as "binary") which have neither fixed record lengths nor record markers. W/ those you're totally to the mercies of "what was written is what you got..." And of course, there's then vagaries of the system on which the files were written that may introduce things like the endian-ness of the data bytes and even possible operating system dependencies... All in all, no mean task... -- |