Home > Archive > Fortran > February 2007 > format of unformatted file??
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
format of unformatted file??
|
|
| gaurav 2007-02-09, 4:10 am |
| hi,
It might sound a bit odd, but what is the format of an unformatted
file.?
I mean to say that given a unformatted file, how does we determine it
is unformatted.
There must be some header or something.? that helps us to know that it
is an unformatted one?
What is the format of such file? where can i find such the algorithm/
logic?
I am actually trying to write a code that reads a file and tells that
it is formatted or unformatted. So i need this information.
Thanks
Gaurav
| |
| James Giles 2007-02-09, 4:10 am |
| gaurav wrote:
> hi,
>
> It might sound a bit odd, but what is the format of an unformatted
> file.?
> I mean to say that given a unformatted file, how does we determine it
> is unformatted.
> There must be some header or something.? that helps us to know that it
> is an unformatted one?
>
> What is the format of such file? where can i find such the algorithm/
> logic?
>
> I am actually trying to write a code that reads a file and tells that
> it is formatted or unformatted. So i need this information.
There isn't necessarily such a beast as an "unformatted file".
Unformatted I/O unit in one you've OPENed with that attribute.
Your program will not do format translation on such a file
(not directly - you can move character data using unformatted
and do format translation on it using internal I/O). An I/O
library can be written (I've done it) which allows any file to
be OPENed for formatted I/O and/or any file to be OPENed
for unformatted I/O.
Now, in most implementations of Fortran they do pick a
particular file structure when you OPEN a file. And that
choice often depends on whether you've OPENed the file
for formatted or unformatted transfers. Usually the foramtted
I/O connections assume the file is structured as a native text
file (whatever that is on your system). Usually unformatted
I/O connections do not assume the file is a native text file
(obviously). But what assumptions they make depends on the
Fortran implementation. That's usually not determined by the
system (unless you system has some defined file structure
for binary record-based I/O).
A common choice (but not universal) is to begin the file with
an integer (usually binary) that gives the length of the first
record. Then follows the data of the record itself. Then
follows another integer that gives the length of the record
just preceeding. So, between any two records are two integers
(one giving the length of the previous record and one giving
the lenght of the following record). That last record's data
is followed by only one integer since there is not next record.
Obviously even if this common choice is made, there are many
variations possible. The size of integer that gives the lengths
may differ from one implementation to another. The unit that
is used to count the length of the record may vary (bytes? words?
bits?). Some implementations put two integers as the record
marks even before the first and after the last record (and the
lengths are just negative, or zero, or some other convenient
rule).
Again I hasten to point out that even with variations the above
is not a universal choice. The answer must be found in the
document for each Fortran implementation.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
|
|
|
|
|