This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: how to read out binary data
- To: Bomin Sun <bsun at whoi dot edu>
- Subject: Re: how to read out binary data
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Date: Sat, 27 Jan 2001 21:50:43 +0100
- CC: gccbug <gcc-bugs at gcc dot gnu dot org>, gcchelp <gcc-help at gcc dot gnu dot org>
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <3A650CE7.80E6B9AB@whoi.edu>
Bomin Sun wrote:
> the linux system I am using is installed in the pc with intel III.
>
> I have a problem in reading binary data file (e.g., a binary file
> (integer*2) downloaded from a website) using a fortran program under my
> linux environment.
>
> The program (also was provided by those data people) to read the file
> is:
>
> integer*2 isea(100,100)
> open(1,file='seatemp.dat',form='unformatted')
> read(1) isea
> print*,isea(1,1)
> stop
> end
>
> I used g77 to compile that program. The output from that program is
> totally wrong.
> for example, the value of isea(1,1) is a very large integer number.
>
> does anyone know how to correctly read out the binary data ?
Sorry for the long delay - somehow I couldn't find your message back ...
Unfortunately, your problem is not easy to solve. The way Fortran
programs write unformatted (sequential) files is different for different
machines / compilers.
Please ask the people providing the data to write it out formatted,
i.e.:
integer*2 isea(100,100)
open(1,file='seatemp.dat')
write(1,'(10i8)') isea
close(1)
end
This way, you'll be able to read it as follows:
integer*2 isea(100,100)
open(1, file='seatemp.dat')
read(1,'(10i8)') isea
close(1)
end
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)