home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / misc / cpa.src < prev    next >
Encoding:
Text File  |  1988-05-03  |  2.3 KB  |  89 lines

  1. --::::::::::
  2. --cbconstg.ada
  3. --::::::::::
  4. -- CBCONSTG.ADA
  5. --- This generic package sets up the record CB with the central body
  6. -- constants.  A procedure is provided by which the user
  7. -- can initialize their central body constants.  The user
  8. -- must set up the order of the values in the enumerated array C_BODIES
  9. -- to correspond to the correct record in the CBDATA array.  
  10. -- In addition, this package must be instantiated for the float
  11. -- type used at the facility.  Then, the
  12. -- initialization is in the form CB := CBDATA(SUN) for using
  13. -- the sun as the central body.
  14.  
  15. -- The data record is currently configured with three entries.
  16. -- The first entry is a string of 8 characters long which consists
  17. -- of an identifier
  18. -- The second entry is a floating scalar which is the radius in KM
  19. -- The third entry is a floating scalar which is the GM
  20.  
  21. -- Written 8/86 by David Kwong
  22.  
  23. GENERIC
  24.  
  25.     TYPE FLOATG IS DIGITS <>;
  26.  
  27. PACKAGE CENTRAL_BODY_CONSTANTS_GENERIC IS
  28.  
  29.     TYPE C_BODIES IS (SUN,EARTH,MARS);
  30.  
  31.     SUBTYPE CB_NAME IS STRING(1..8);
  32.  
  33.     TYPE CB_RECORD IS
  34.          RECORD
  35.             NAME:CB_NAME;
  36.             RADIUS:FLOATG;
  37.             GM:FLOATG;
  38.         end RECORD;
  39.  
  40.     CBDATA:  constant array(C_BODIES) of CB_RECORD
  41.     :=(("SUN     ",6.96E8,1.32712438E20)
  42.       ,("EARTH   ",6.37814E6,3.986004479996796E14)
  43.       ,("MARS    ",3.3884E6,4.282828044E13));
  44.  
  45.     CB:CB_RECORD;
  46.  
  47. end CENTRAL_BODY_CONSTANTS_GENERIC;
  48. --::::::::::
  49. --runcb.ada
  50. --::::::::::
  51. -- RUN_CB.ADA
  52. -- This program instantiates the package CENTRAL_BODY_CONSTANTS_GENERIC
  53. -- and tests it to see if the array CB can be initialized and the
  54. -- constants read out.
  55.  
  56. -- Written 8/86 by David Kwong
  57.  
  58. -- The generic package is first instantiated 
  59.         with CENTRAL_BODY_CONSTANTS_GENERIC;
  60.         PACKAGE CENTRAL_BODY_CONSTANTS IS
  61.         NEW CENTRAL_BODY_CONSTANTS_GENERIC(FLOAT);
  62.  
  63.         WITH CENTRAL_BODY_CONSTANTS; USE CENTRAL_BODY_CONSTANTS;
  64.         with TEXT_IO; use TEXT_IO;
  65.         with FLOAT_TEXT_IO; use FLOAT_TEXT_IO;
  66.     procedure RUN_CB is
  67.  
  68.     begin
  69.  
  70. -- test initialization with sun constants
  71.         CB:=CBDATA(SUN);
  72.         put(CB.NAME);
  73.         NEW_LINE;
  74.         put(CB.RADIUS);
  75.         NEW_LINE;
  76.         put(CB.GM);
  77.         NEW_LINE(2);
  78.  
  79. -- test initialization with earth constants
  80.         CB:=CBDATA(EARTH);
  81.         put(CB.NAME);
  82.         NEW_LINE;
  83.         put(CB.RADIUS);
  84.         NEW_LINE;
  85.         put(CB.GM);
  86.  
  87.  
  88.     end RUN_CB;
  89.