home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!news.ans.net!cmcl2!adm!aos!lapoint
- From: lapoint@adios.brl.mil (Claude LaPointe )
- Newsgroups: comp.lang.fortran
- Subject: RE: RE: unformatted output
- Message-ID: <1054@aos.brl.mil>
- Date: 5 Nov 92 14:01:28 GMT
- Sender: news@aos.brl.mil
- Lines: 66
- Nntp-Posting-Host: adios.brl.mil
-
-
- Earlier, I wrote:
-
- >mppa3@syma.sussex.ac.uk (Alan Richardson) writes (text paraphrased):
- >
- >> using Fortran to produce unformatted output, intend tp use C to read
- >> back in (via fread).
- >>
- >> PROGRAM unformatted_test
- >> REAL*4 value1, value2
- >> value1=123.4
- >> value2=298.9
- >> OPEN(10, FILE='file1', FORM='UNFORMATTED')
- >> WRITE(10) value1
- >> WRITE(10) value2
- >> CLOSE(10)
- >> END
- >>
- >> I'm running this on an HP 9000/720 machine with HP-UX 8.07. Instead
- >> of getting just 8 bytes out (two four-byte floats) I get 24 bytes out;
- >> Fortran pads output 4 bytes either side.
- >> `od -c file1' gives:
- >>
- >> 0000000 000000 000004 041366 146315 000000 000004 000000 000004
- >> 0000020 041625 071463 000000 000004
- >> 0000030
- >>
- >> So how do I get rid of these extra bytes, given that my WRITE statements
- >> lie on several different lines? The poor C program can't cope!
- >
- >
- >1 - what you are encountering is not uncommon - padding to fill a record,
- > block, or buffer; or beginning and end of record marks, or some such.
- >
- >2 - given that you really want to proceed in this manner, writing C
- > code to read the records should not be difficult, IF YOU KNOW
- > THE EXACT STRUCTURE OF FORTRAN UNFORMATTED OUTPUT RECORDS ON
- > YOUR MACHINE, AND THE INTERNAL REPRESENTATIONS OF YOUR DATA.
- > After all, the extremely general purpose "od" is written in C.
- >
- >3 - in general, (there are exceptions) fortran unformatted writes are useful
- > in and intended to be used in fortran write/read pairs on like hardware
- > and software architectures, with logically similar i/o lists in both
- > the read and the write statements. The only reason to do this kind of i/o
- > is to gain efficiency when dealing with large amounts of data by avoiding
- > the time spent in formatting. The prices paid are decreased flexibility
- > and increased volume on the storage medium.
- >
- >4 - unless there are overriding considerations, I would recommend
- > formatted i/o.
-
- Subsequently, concern has been expressed the ability to write formatted
- and then read formatted with certainty that the resulting bit pattern
- is identical to the original one.
-
- Interesting comments on IEEE standards, the quality of their implementation,
- and other matters, have been provided by various responders to the original
- message.
-
- It seems to me that,
- as long as the application remains on one machine/software system, and
- as long as ugliness in not a concern, one could circumvent the problem
- by equivalencing variable/array names of appropriate types and doing
- formatted reads/writes, not with edit descriptors appropriate to real
- or double precision i/o, but with octal or hexadecimal edit descriptors.
- Admittedly, these are non-standard, but they are ubiquitous.
-