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