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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.157.51.38 with SMTP id f35mr4667912otc.84.1484952951412; Fri, 20 Jan 2017 14:55:51 -0800 (PST) X-Received: by 10.157.39.202 with SMTP id c68mr416027otb.8.1484952951378; Fri, 20 Jan 2017 14:55:51 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!r185no1030822ita.0!news-out.google.com!78ni15842itm.0!nntp.google.com!r185no1033222ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 20 Jan 2017 14:55:51 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=98.109.59.90; posting-account=h3IwYwoAAAAeE2lWQnRSCqcQ0dO-KDvQ NNTP-Posting-Host: 98.109.59.90 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <83409c51-59d3-4205-9eeb-5467de09f069@googlegroups.com> Subject: Q: Trouble creating array and discriminated type From: b.mcguinness747@gmail.com Injection-Date: Fri, 20 Jan 2017 22:55:51 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:33107 Date: 2017-01-20T14:55:51-08:00 List-Id: First, gnatmake complains about two constant arrays I am trying to create. = I have: subtype Int2 is Integer range -32768..32767; type Real is digits 16; ... a_napl_t : constant array (0..677,0..13) of Int2 :=3D ( ( 0, 0, 0, 0, 0, 0, 0, 8,-16, 4, 5, 0, 0, 0), ( 0, 0, 0, 0, 0, 0, 0, -8, 16, -4, -5, 0, 0, 2), ... )); ... a_cpl_t : constant array (0..677,0..3) of Real :=3D ( ( 1440.0, 0.0, 0.0, 0.0), ( 56.0, -117.0, -42.0, -40.0), ( 125.0, -43.0, 0.0, -54.0), ... )); and I get the messages: novas.adb:8111:57: warning: upper bound of aggregate out of range novas.adb:8111:57: warning: Constraint_Error will be raised at run time novas.adb:8806:55: warning: upper bound of aggregate out of range novas.adb:8806:55: warning: Constraint_Error will be raised at run time I'm not sure what this means. My array bounds are certainly within the ran= ge of any reasonable integer type. Second, I have this record type: type Real_Matrix is array (Natural range<>, Natural range<>) of Real; type Real_Vector is array (Natural range<>) of Real; ... type Ephemeris_Data (Offset_Maximum, Record_Maximum : Positive) is tagged= record -- Data describing the ephemeris Constants : Maps.Map; Database_Name : UString; Earth_Moon_Ratio : Real; First_Valid_Julian_Date : Real; Last_Valid_Julian_Date : Real; Julian_Date_Interval : Real; Offsets : Offset_Matrix(0..Offset_Maximum, 0..2); Record_Length : Integer :=3D Record_Maximum + 1; -- Options currently selected Center : Center_Point :=3D SUN; Units : Output_Units :=3D AU; -- Stored data from previous method calls, if any Last_Record_Read : Integer :=3D -1; -- initialize to impossible= value Record_Buffer : Real_Vector(0..Record_Maximum); Position_Velocity_Sun : Real_Matrix(0..1, 0..2); end record; While I can create an instance of this type in a function and return it, I = can't create such an instance as a member of a package. I can't specify th= e dimensions of the offsets array and the record buffer ahead of time; I ha= ve to read a text file describing the data before I can determine their val= ues. So I want to declare the variable in the package and then call an ini= tialization procedure to assign a value to it. The compiler won't allow th= is; it insists that the discriminators be specified when the variable is de= clared. I have tried declaring the package member as access Ephemeris_Data, which t= he compiler seems to accept, but then I can't find a way to determine an ad= dress to assign to the variable. For example, the compiler won't let me do= this: JPL_Data : access JPL_Ephemeris.Ephemeris_Data; procedure initialize (header_file_pathname, coefficient_file_pathname : Str= ing) is begin Real_IO.Open (File, Real_IO.In_File, coefficient_file_pathname); JPL_Data :=3D JPL_Ephemeris.Make (header_file_pathname)'Access; end initialize; I would appreciate help in solving these problems. One of the main purpose= s for creating this code is for me to become more familiar with the Ada lan= guage. I am much more familiar with Java, so I may not be looking at this = with an Ada mindset. --- Brian McGuinness