This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: A question about g77's OPEN & WRITE
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- To: Zhong Wang <wangzhong_china at yahoo dot com dot cn>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 03 Nov 2002 19:47:18 +0100
- Subject: Re: A question about g77's OPEN & WRITE
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <20021103134107.29122.qmail@web15003.mail.bjs.yahoo.com>
Zhong Wang wrote:
> I am using g77 for programing now. But I found that
> g77 is somewhat
> different to Visual Fortran in I/O.
>
> In visual fortran, the following code is legal:
>
> REAL a(10)
> OPEN(10,file='aaa.dat',form='binary')
> WRITE(10)a
> CLOSE(10)
> <<<<<
> You can see that in file aaa.dat there's not
> anything between the integer
> and real numbers.
> But in g77, if I use:
>
> REAL a(10)
> OPEN(10,file='aaa.dat',form='unformatted')
> WRITE(10)a
> CLOSE(10)
> <<<<<
> With "hexedit aaa.dat", you can find there's a
> length value before and after
> each record. You know, sometimes we have to make more
> efforts to deal with
> those length values when we use other softwares to
> open these data files. For
> example, when I use matlab to open the file, I have to
> read off those length
> values. It's very convinient.
>
> Can you recommend me a possible method with g77 to
> generate data file which
> contains no extra bytes in it? Or can the developers
> add some new features
> like form='direct' to g77?
No, there's no method to get rid of the record lenghts in an unformatted
file when using g77. However, if all the records in your file are the
same length, you could write a "direct access" file, by doing the writes
thusly:
REAL A(10)
OPEN(...,ACCESS='DIRECT',RECL=....)
DO I = 1, N
... fill A
WRITE(...,REC=I) A
ENDDO
CLOSE(...)
This will give you a file with N records of length 10 (32-bit words)
without any other data in it.
Hope this helps,
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)