Reading fortran "unformatted" files from C on the 4D.

Knobi der Rechnerschrat XBR2D96D at DDATHD21.BITNET
Wed Oct 25 16:55:13 AEST 1989


Hallo,

  here comes a code fragment that reads (from C) a fortran "unformatted"
file. Suppose the file has been fopen'ed to fp and that i1,i2,i3 are int's
and that farr is a float-array. The programm then reads max fortran-records
from the file, each record written by a fortran code like

  write(11) i1,i2,i3,farr    ! with REAL farr(3)

 You have of course to know what is written in the records to interpret them
correctly. For my opinion having the record-size included in the record is not
as bad as somebody on the list told us. If you really need "C"-binary files,
write a "C"-routine.

Regards

Martin Knoblauch
TH-Darmstadt
Phys. Chem. 1
Petersenstrasse 20
D-6100 Darmstadt, F.R.G.
------------------------------------------------------------------------------
for(iz=0;iz<max;iz++){
  nitem = fread(&dummy,4,1,fp);
  fread(&i1,sizeof(int),1,fp);
  fread(&i2,sizeof(int),1,fp);
  fread(&i3,sizeof(int),1,fp);
  fread(&farr[0],sizeof(float),3,fp);
  nitem = fread(&dummy,4,1,fp);
  }
------------------------------------------------------------------------------



More information about the Comp.sys.sgi mailing list