comp.lang.ada
 help / color / mirror / Atom feed
* Q: Trouble creating array and discriminated type
@ 2017-01-20 22:55 b.mcguinness747
  2017-01-20 23:48 ` gautier_niouzes
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: b.mcguinness747 @ 2017-01-20 22:55 UTC (permalink / raw)


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 := (
      ( 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 := (
      ( 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 range 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 := Record_Maximum + 1;

    -- Options currently selected
    Center                  : Center_Point := SUN;
    Units                   : Output_Units := AU;

    -- Stored data from previous method calls, if any
    Last_Record_Read        : Integer := -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 the dimensions of the offsets array and the record buffer ahead of time; I have to read a text file describing the data before I can determine their values.  So I want to declare the variable in the package and then call an initialization procedure to assign a value to it.  The compiler won't allow this; it insists that the discriminators be specified when the variable is declared.

I have tried declaring the package member as access Ephemeris_Data, which the compiler seems to accept, but then I can't find a way to determine an address 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 : String) is
begin
  Real_IO.Open (File, Real_IO.In_File, coefficient_file_pathname);
  JPL_Data := JPL_Ephemeris.Make (header_file_pathname)'Access;
end initialize;


I would appreciate help in solving these problems.  One of the main purposes for creating this code is for me to become more familiar with the Ada language.  I am much more familiar with Java, so I may not be looking at this with an Ada mindset.

--- Brian McGuinness

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

end of thread, other threads:[~2017-01-23  8:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-20 22:55 Q: Trouble creating array and discriminated type b.mcguinness747
2017-01-20 23:48 ` gautier_niouzes
2017-01-21  7:23 ` Simon Wright
2017-01-21  9:41 ` Jeffrey R. Carter
2017-01-21 17:05 ` Stephen Leake
2017-01-22  5:12   ` Robert Eachus
2017-01-23  8:02   ` G.B.
2017-01-23  8:19     ` Simon Wright
2017-01-21 18:55 ` b.mcguinness747

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