koolish@bbn.com (Dick Koolish) (04/11/90)
I need to read some existing data files from an Ada program. The files have a header block followed by data records. Different files have different data record sizes. The size and number of data records is specified in the header block. I also need to be able to read the data starting at any record and when I get to the physical end of file to wrap around to the start of the data again. The two questions are how to read two different kinds of records out of a file and how to do this if you don't know the size of one of the records until you open the file and read the header.
stt@inmet.inmet.com (04/12/90)
Regarding reading files with multiple record types: The language-defined I/O packages don't handle this kind of file, at least not without standing on your head. However, it seems to be a little known fact that it is permissible to write your *own* I/O packages! I am only being a little facetious here. It is important to realize that the Ada Reference Manual provides only a starting point for I/O services. It does not define any standard interface to the underlying O/S I/O services, though most Ada vendors provide such packages. Even if your vendor doesn't provide such an I/O package, it is almost always possible to use pragma Interface to Assembler or C to accomplish the job. By the way, the Posix/Ada folks are making good progress on standardizing an Ada interface to Posix (Unix) I/O services. Perhaps Ada9X will try to directly address some of these very real problems, but alternatively, it may instead focus on providing the primitives (refinements to 'ADDRESS, 'SIZE, and unchecked-conversion) so that application-specific I/O packages will be easier to write in a portable, compiler-independent way. In any case, judicious use of 'ADDRESS, 'SIZE, and Unchecked_Conversion can go a long way already toward easing the solution to your I/O problems. S. Tucker Taft Intermetrics, Inc. Cambridge, MA 02138