🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.misc.discuss
Article #2275

Q: Fortran unformatted i/o with GNU f2c/gcc problem.

#2275
From: Chris Metzler
Date: Wed, 30 Sep 1998 00:00
101 lines
3573 bytes
Hi.  I'm not sure I'm targeting the right newsgroup(s), but of the
GNU groups carried locally, this seems most appropriate.  Please
point me in the right direction if I should be bothering a different
group.

Anyway, I can use any help I can get.  I'm on a Red Hat Linux machine.
It doesn't have full g77 installed -- f77 or g77 invokes an f2c
preprocessor, followed by gcc.  Fortran programs compiled this way
don't seem to be able to read Fortran unformatted binary files.

Problem Part 1:  The bytes read return bizarre values.  For instance,
the following Fortran program was run on a separate machine:

      program blah

      itest = 1

      open(80,status='new',form='unformatted',file='blah.dat')
      write(80) itest
      close(80)
      stop
      end


Taking the data file over to the linux machine, and reading it with
the following program:

      program blahr

      open(80,status='old',form='unformatted',file='blah.dat')
      read(80) itest
      print*, itest
      close(80)
      stop
      end

produces an output of "16777216", rather than the expected "1".
Since this is 2^24, I thought this might be some sort of byte-swapping/
ordering issue, but couldn't track down an appropriate compile-time
option for that.

Problem Part 2:  Placement in the file seems to be messed up.  For
instance, the following program was used to produce a data file on
another machine:

      program blah2

      open(80,status='new',form='unformatted',file='blah2.dat')
      do i=1,10
         write(80) i
      enddo
      close(80)
      stop
      end

Trying to read and display the 10 entries in this file by a similar
program on the Linux machine,

      program blah2r

      open(80,status='old',form='unformatted',file='blah2.dat')
      do i=1,10
         read(80) itest
         print*, itest
      enddo
      close(80)
      stop
      end

produced a bogus first output of "16777216" as above, followed by
an EOF error:

[metzler@cdm ini]$ ./blah2r
 16777216
start: end of file
apparent state: unit 80 named blah2.dat
last format: list io
lately reading sequential unformatted external IO
Abort (core dumped)

========================


I'm a bit befuddled.  I suspect, as usual, the problem will be some
simple thing I've missed, rather than a bug in f2c/gcc, but I don't
know what it is at this point.  If anyone has any clue whatsoever,
I can use the shove in the right direction.

Thanks,

-c

-- 
Chris Metzler                   Work Address:   Theoretical Astrophysics
630-840-3662 (office)                           Fermi National Accelerator Lab
metzler@oddjob.uchicago.edu (play)              P.O. Box 500, MS-209
cmetzler@spam-me-not.fnal.gov (work)            Batavia, IL  60510 USA

"As a child I understood how to give; I have forgotten this grace since I
have become civilized." - Chief Luther Standing Bear
Technical Details
Message-ID: <F02psK.Apn@midway.uchicago.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,e0781954572e0423,start
X-Google-Attributes: gid11318c,public
X-Google-Thread: 1025b4,e0781954572e0423,start
X-Google-Attributes: gid1025b4,public
From: metzler@oddjob.uchicago.edu (Chris Metzler)
Subject: Q: Fortran unformatted i/o with GNU f2c/gcc problem.
Date: 1998/09/30
Message-ID: <F02psK.Apn@midway.uchicago.edu>
X-Deja-AN: 396190369
Sender: news@midway.uchicago.edu (News Administrator)
X-Nntp-Posting-Host: oddjob.uchicago.edu
Organization: University of Chicago, Astronomy and Astrophysics
Newsgroups: gnu.misc.discuss,gnu.gcc.help