Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!ames!amdahl!key!sjc From: sjc@key.COM (Steve Correll) Newsgroups: comp.lang.fortran Subject: Re: Fortran OPEN and WRITE Message-ID: <1613@key.COM> Date: 9 Apr 90 21:49:46 GMT References: <962@nisca.ircc.ohio-state.edu> Distribution: na Organization: Key Computer Labs, Fremont, CA Lines: 31 In article <962@nisca.ircc.ohio-state.edu>, jliu@hpuxa.ircc.ohio-state.edu (Joe Liu) writes: > I have been troubled by maybe a very simple problem, what I > want to do is: to write a collection of data into a binary file... > Suppose I have 5 data points as > ( 1,2,3,4,5), the binary file I want must be 5 bytes. However, it seems > Fortran on the Unix takes 1+8 bytes to write each one byte data... The Fortran 77 standard requires that the compiler's runtime system be able to open a "sequential" access file without any prior knowledge of record lengths, and then skip forward (using "read" with an empty list of data items) or backward (using "backspace") over each record. To do this, the compiler must be able to find out the length of each record. If the host operating system provides variable-length-record files as a built-in service of its file system, then the compiler may be able to ask the operating system about the length of a record, and thereby avoid storing them in the user-visible portion of the file. Many systems (Unix, for example) do not provide this service, and therefore the compiler's runtime system must simulate variable length records by storing the record lengths inside the file. Even some systems which do provide variable length records provide them in a form which doesn't exactly meet Fortran's needs. If you use "direct" access (as described in the Fortran 77 standard) then you must specify a record length in the "open" statement, and most compilers will use that instead of storing the record length in the file itself; this will solve your problem so long as every record can be the same length, or can be padded to the same length. -- ...{sun,pyramid}!pacbell!key!sjc Steve Correll