public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* how to read out binary data
@ 2001-01-16 19:09 Bomin Sun
  2001-01-17  7:40 ` Ingo Krabbe
  2001-01-27 12:54 ` Toon Moene
  0 siblings, 2 replies; 3+ messages in thread
From: Bomin Sun @ 2001-01-16 19:09 UTC (permalink / raw)
  To: gccbug, gcchelp

hello,

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 ?

thanks!



--
Bomin Sun
Physical Oceanography Department
MS#21, 360 Woods Hole Road
Woods Hole Oceanographic Institution
Woods Hole, MA 02543
Tel:508-2893365
Fax:508-4572181


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to read out binary data
  2001-01-16 19:09 how to read out binary data Bomin Sun
@ 2001-01-17  7:40 ` Ingo Krabbe
  2001-01-27 12:54 ` Toon Moene
  1 sibling, 0 replies; 3+ messages in thread
From: Ingo Krabbe @ 2001-01-17  7:40 UTC (permalink / raw)
  To: Bomin Sun; +Cc: gcchelp

Am Mittwoch, 17. Januar 2001 04:09 schrieben Sie:
> hello,
>
> 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.

May this be a problem of byteorder ? On a PC for example the word order of 
integers is different so that the lowest order byte written into a data file 
by a SUN or other machine will go into the highest byte of the PC integer. 
The effect of byteorder problems is exactly that small numbers will end up in 
very large one. Please crosscheck that.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to read out binary data
  2001-01-16 19:09 how to read out binary data Bomin Sun
  2001-01-17  7:40 ` Ingo Krabbe
@ 2001-01-27 12:54 ` Toon Moene
  1 sibling, 0 replies; 3+ messages in thread
From: Toon Moene @ 2001-01-27 12:54 UTC (permalink / raw)
  To: Bomin Sun; +Cc: gccbug, gcchelp

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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-01-27 12:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-16 19:09 how to read out binary data Bomin Sun
2001-01-17  7:40 ` Ingo Krabbe
2001-01-27 12:54 ` Toon Moene

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).