comp.lang.ada
 help / color / mirror / Atom feed
* sequential io with multiple types
@ 1992-10-16  2:37 van-bc!cs.ubc.ca!destroyer!sol.ctr.columbia.edu!src.honeywell.com!mail-en
  0 siblings, 0 replies; 5+ messages in thread
From: van-bc!cs.ubc.ca!destroyer!sol.ctr.columbia.edu!src.honeywell.com!mail-en @ 1992-10-16  2:37 UTC (permalink / raw)


Along the same lines as my previous question, suppose that I have a file
with short_floats and integers written out in binary format (by a fortran
program, as real*4 and integer*4).  If I instantiate SEQUENTIA_IO with type 
integer, and read all data as an integer, how do I convert data that is not
an integer from the integer value read in to the true short_float
representation?

Thanks, Matt

Matthew J. Englehart                      Voice: (612)-951-7635
Honeywell Systems and Research Center     FAX:   (612)-951-7438
3660 Technology Dr.   MS:MN65-2500        Inet: englehar@src.honeywell.com
Minneapolis, MN 55418

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

* Re: sequential io with multiple types
@ 1992-10-27 15:21 dog.ee.lbl.gov!overload.lbl.gov!agate!usenet.ins.cwru.edu!magnus.acs.ohio
  0 siblings, 0 replies; 5+ messages in thread
From: dog.ee.lbl.gov!overload.lbl.gov!agate!usenet.ins.cwru.edu!magnus.acs.ohio @ 1992-10-27 15:21 UTC (permalink / raw)


In article <9210160237.AA26805@akela.src.honeywell.com>,
englehar@src.honeywell.com (Matt Englehart) writes: 

|> Along the same lines as my previous question, suppose that I have a file
|> with short_floats and integers written out in binary format (by a fortran
|> program, as real*4 and integer*4).  If I instantiate SEQUENTIA_IO with type 
|> integer, and read all data as an integer, how do I convert data that is not
|> an integer from the integer value read in to the true short_float
|> representation?

The obvious answer here is to use unchecked conversion.  This is a good
example of well-justified use.

A less obvious answer is to point out that Ada allows a program to open the
same external file with *different* data types, i.e., you can instantiate
SEQUENTIAL_IO with different data types, declare a file object for each of the
instantiated file types, and apply the appropriate open procedure to each of
these file objects using the same external file name.  Then you read from an
appropriate file object depending on what type of data you expect the next
file element to be.

This is allowed because the Ada OPEN procedure is not the same as the
operating system notion of opening a file -- OPEN in Ada only establishes an
"association" between an (internal) file object and an external file.

Of course, not all Ada implementations support such multiple "openings" of the
same external file because this behavior is not required by the standard, but
it is allowed, and it is quite useful if an implementation supports it.

John B. Goodenough					Goodenough@sei.cmu.edu
Software Engineering Institute				412-268-6391

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

* Re: sequential io with multiple types
@ 1992-10-27 17:02 David Emery
  0 siblings, 0 replies; 5+ messages in thread
From: David Emery @ 1992-10-27 17:02 UTC (permalink / raw)


One of the "extensions" provided by the IEEE P1003.5 POSIX Ada Binding
is the ability to associate an Ada file object with a given file
descriptor, through use of the FORM parameter on Create or Open.  This
is important to achieve the "sharing" effects that John mentioned.  In
POSIX, a file descriptor maps to the operating system's record of file
access (e.g.  the current read/write position in the file.)  POSIX/Ada
does not guarantee that you can get the "desired effect" by opening
two file objects mapped to the same file descriptor.  This is due to
the possibility of internal file buffering by the Ada IO system.  But,
if the Ada IO implementation does not do any additional buffering,
then this should work: (User must supply the appropriate names/types/etc
in <angle brackets>.)

	with POSIX, POSIX_IO, Sequential_IO;
	procedure demo is
	  fd : POSIX_IO.file_descriptor;
          package SIO_one is new Sequential_IO (<type_one>);
	  package SIO_two is new Sequential_IO (<type_two>);
          SIO_one_file : SIO_one.file_type;
          SIO_two_file : SIO_two.file_type;
	begin
          fd := POSIX_IO.Open (name => <filename goes here>,
			       mode => POSIX_IO.write_only);
	  SIO_one.open (SIO_one_file, 
			form => "File_Descriptor => " 
			        & POSIX_IO.file_descriptor'image(fd));
	  SIO_two.open (SIO_two_file, 
			form => "File_Descriptor => " 
			        & POSIX_IO.file_descriptor'image(fd));
          -- note that no NAME parameter is provided for the 
	  -- Sequential_IO instantiation Open operations
	  -- now both Ada sequential file objects are associated with
	  -- the same underlying POSIX file descriptor.
	  SIO_one.put (SIO_one_file, <type one value>);
	  SIO_two.put (SIO_one_file, <type two value>);
	end demo;

Yet another feature of POSIX/Ada...
	
				dave

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

* Re: sequential io with multiple types
@ 1992-10-27 17:40 dog.ee.lbl.gov!overload.lbl.gov!agate!linus!linus.mitre.org!maestro!jclan
  0 siblings, 0 replies; 5+ messages in thread
From: dog.ee.lbl.gov!overload.lbl.gov!agate!linus!linus.mitre.org!maestro!jclan @ 1992-10-27 17:40 UTC (permalink / raw)


Perhaps I missed something (I've only caught part of this discussion), but
why are you writing multiple types to the same file?  Why not use record types,
with or without discriminant?  Then you instantiate Sequential_IO once, and 
it takes care of all of the details of writing, and the same instantiation
will give you the structures you need when you read the file later.

Julian C. Lander
jclander@mitre.org

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

* Re: sequential io with multiple types
@ 1992-10-30 15:11 agate!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!zaphod.mps.ohi
  0 siblings, 0 replies; 5+ messages in thread
From: agate!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!zaphod.mps.ohi @ 1992-10-30 15:11 UTC (permalink / raw)


In article <1992Oct27.174052.6058@linus.mitre.org>, jclander@maestro.mitre.org 
(Julian C. Lander) writes:
|> Perhaps I missed something (I've only caught part of this discussion), but
|> why are you writing multiple types to the same file?  Why not use record typ
es,
|> with or without discriminant?

Presumably the file was written by a non-Ada application.

John B. Goodenough					Goodenough@sei.cmu.edu
Software Engineering Institute				412-268-6391

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

end of thread, other threads:[~1992-10-30 15:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-10-27 15:21 sequential io with multiple types dog.ee.lbl.gov!overload.lbl.gov!agate!usenet.ins.cwru.edu!magnus.acs.ohio
  -- strict thread matches above, loose matches on Subject: below --
1992-10-30 15:11 agate!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!zaphod.mps.ohi
1992-10-27 17:40 dog.ee.lbl.gov!overload.lbl.gov!agate!linus!linus.mitre.org!maestro!jclan
1992-10-27 17:02 David Emery
1992-10-16  2:37 van-bc!cs.ubc.ca!destroyer!sol.ctr.columbia.edu!src.honeywell.com!mail-en

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox