From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!peer01.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 08 Dec 2017 11:35:36 -0600 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: How To Write A Record To File ? Date: Fri, 08 Dec 2017 12:35:36 -0500 Organization: IISS Elusive Unicorn Message-ID: References: User-Agent: ForteAgent/8.00.32.1272 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 108.68.177.219 X-Trace: sv3-lBUDvqOUBdEMpeSA6EtYbAfSaLmN0qvu+6RwshmJIfq6ZLZ3udNajrxT8z4/6iFUb6cV3ELf+hTDEfA!GQc8vD9zOrYcg7kTl/HyckZk0FI/dh8rWRA2cQD6mHrCY6PDyQnSD8rUEv8ro/Sm6B1HVI8osGbD!ZTBGI8u24t/MZldwlJGFvRbEdXFd X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4165 X-Received-Body-CRC: 1001942401 X-Received-Bytes: 4377 Xref: reader02.eternal-september.org comp.lang.ada:49421 Date: 2017-12-08T12:35:36-05:00 List-Id: On Fri, 8 Dec 2017 08:04:31 -0800 (PST), patrick@spellingbeewinnars.org declaimed the following: >Hi Everyone > >Silly question here. > >I snagged this from an old book: > > > with sequential_io ; > procedure compute_total_population is > package si is new sequential_io(integer); Using basic "integer" could be a problem, as it is dependent upon what ever the compiler implementation defines to be base integer. >sequential_io is a generic package but I can't get it to work with a type that is a record I created. > HOW did you create your input file? What does it look like if (hex)dumped. Sequential I/O does not do conversion between human-readable and internal representations; the input file must be a sequence of binary integers (all the same length -- implementation dependent), no line formatting characters (so not something you can create with a text editor). If you created your file in an editor, with human-readable values, you most likely need ada.text_io.integer_io -=-=-=-=- generate binary integer data file using Python >>> import struct >>> import random >>> fout = open("d:\myTest.dat", "wb") >>> for x in range(5): ... r = random.randint(0, 999999) ... print r ... b = struct.pack("i", r) ... fout.write(b) ... 476770 353201 930701 402627 273463 >>> fout.close() >>> -=-=-=-=- (using the Win10 Ubuntu BASH shell) root@ElusiveUnicorn:~# od -t x4 /mnt/d/myTest.dat 0000000 00074662 000563b1 000e338d 000624c3 0000020 00042c37 0000024 root@ElusiveUnicorn:~# root@ElusiveUnicorn:~# od -i /mnt/d/myTest.dat 0000000 476770 353201 930701 402627 0000020 273463 0000024 root@ElusiveUnicorn:~# I'd started with hexdump but couldn't figure out how to do 4-byte integers; fortunately man suggested od, and those options were simpler for this. -=-=-=-=- modified Ada source file with Sequential_IO; with Ada.Text_Io; use Ada.Text_Io; procedure seqio is package si is new Sequential_IO (Integer); data_file : si.File_Type; value : Integer; total : Integer := 0; begin si.Open (data_file, si.In_File, "d:\myTest.dat"); while not si.End_Of_File (data_file) loop Si.Read (Data_File, Value); Put_line (Integer'Image (Value)); total := total + value; end loop; si.Close (data_file); Put_Line ("The total is: " & Integer'Image (Total)); end seqio; -=-=-=-=- compile/link/run C:\Users\Wulfraed\Documents\Ada Progs>gnatmake seqio.adb gcc -c seqio.adb gnatbind -x seqio.ali gnatlink seqio.ali C:\Users\Wulfraed\Documents\Ada Progs>seqio 476770 353201 930701 402627 273463 The total is: 2436762 C:\Users\Wulfraed\Documents\Ada Progs> Works well here. (I really need to figure out how to set up a .gpr file for scratch building test programs ) -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/