home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / test / adaf85.src < prev    next >
Encoding:
Text File  |  1988-05-03  |  237.3 KB  |  8,765 lines

  1. ::::::::::
  2. adafair85.dis
  3. ::::::::::
  4. --
  5. -- The following is introductory documentation
  6. --
  7. ADAFAIR85.DOC
  8. --
  9. -- The following are the benchmarks in compilation order
  10. --
  11. UNIV_AR.ADA
  12. AKERMAN.ADA
  13. BOOLVEC.ADA
  14. BSEARCH.ADA
  15. CAUCHFL.ADA
  16. CAUCHFX.ADA
  17. CAUCHUN.ADA
  18. CHAR_DIR.ADA
  19. CHAR_ENM.ADA
  20. CHAR_TXT.ADA
  21. PHYSICS.ADA
  22. CONPROD.ADA
  23. DERIVED.ADA
  24. FLOATVEC.ADA
  25. FRIEND.ADA
  26. INT_DIR.ADA
  27. INT_TEXT.ADA
  28. INTVEC.ADA
  29. LOWLEV.ADA
  30. PROCCAL.ADA
  31. QSORTPAR.ADA
  32. QSORTSEQ.ADA
  33. RENDEZ.ADA
  34. SETS.ADA
  35. SHARED.ADA
  36. ::::::::::
  37. ADAFAIR85.DOC
  38. ::::::::::
  39. The messages and programs contained in this file were received from
  40. Ed Colbert in conjunction with Ada Fair '85. If there are any questions
  41. with respect to this file please contact Mr. Colbert at :
  42. trwrb!trwspp!spp1!colbert(ampersand)Berkeley . ( Note: I am unable to
  43. transmit an ampersand over the net without the host saying 'BAD" things
  44. about my computer literacy. ) RAY SZYMANSKI -----------
  45.  
  46. This is the 1st of 4 messages that you should receive.  Included are the
  47. rules for running the programs, a copy of 3 universial arithmatic packages,
  48. and a copy of the 24 programs that were used this year.  This years programs
  49. consisted of all of last years programs plus 1 new one, a real world Physics
  50. problem.  All of the programs have been tested on a number of validated
  51. compilers and are correct to the best of our knowledge (there was a logic
  52. bug in boolvec.ada, but that has been corrected in the copy I am sending
  53. you).
  54.  
  55.  
  56.  
  57. --------------------------------------------------------------------------
  58. ------------------------- Rules ------------------------------------------
  59. --------------------------------------------------------------------------
  60.    1. All  rules apply equally to all vendors participating.  Every effort
  61.       will be made to assure fairness in the treatment of the vendors.
  62.  
  63.    2. All vendors must perform the tests in accordance with  these  rules.
  64.       Each   vendor  is  responsible  for  complying  with  them  and  for
  65.       accurately reporting  the  results  of  all  the  tests  which  were
  66.       submitted, including any tests not performed.
  67.  
  68.    3. If more than one Ada toolset or host/target environment is used, the
  69.       vendor should make  a  complete,  independent  report  of  the  test
  70.       results for each distinct combination of tools, host, and target.
  71.  
  72.    4. All  tests  must be performed using the source code in its original,
  73.       official format, without alteration of any kind, except as directed.
  74.       Where   implementation  differences  may  effect  the  source  code,
  75.       directions for alteration may be supplied to the vendors in  written
  76.       form,  embedded  in  the  source  code as comments, or orally by the
  77.       Technical Chair or his authorized representative.   Any  alterations
  78.       made  to  a  test in the absence of such directions or which violate
  79.       the  clear  intent  of  the  directions  given   are   grounds   for
  80.       disqualification of the vendor on that test.
  81.  
  82.    5. The  test  source  files  must  be submitted as single compilations,
  83.       regardless of the number of compilation units they  contain,  unless
  84.       specific directions to the contrary are given.  All pragmas which an
  85.       implementation can obey  must  be  obeyed.    In  particular,  range
  86.       checking  must not be suppressed except where directed by pragmas in
  87.       the source code.  A compilation listing file must  be  generated  by
  88.       each  compilation.    Unless  specifically  requested,  no linker or
  89.       loader outputs are  required.    Execution  outputs  must  be  those
  90.       produced  by  the  Ada program and its run-time environment, without
  91.       alteration of any kind.  The information submitted as official  test
  92.       results  must  represent a complete, continuous, and self-consistent
  93.       sequence of  operations  in  which  the  unaltered  output  of  each
  94.       operation  is  the  input  of the next.  The image which is executed
  95.       must be precisely that which is directly produced  by  the  sequence
  96.       described  above.    The  intent  of  this  rule  is  to  avoid  any
  97.       inconsistency between the options used in  different  parts  of  the
  98.       test  sequence and to make sure that timing and performance data are
  99.       measured for that specific sequence only.    Additional  information
  100.       which  was  not produced in that sequence may not be included in the
  101.       official test results, but may  be  submitted  as  a  supplement  as
  102.       described below.
  103.  
  104.    6. All  timing information which is requested (other than that obtained
  105.       directly by the program using the Calendar package) shall  be  given
  106.       in  terms  of  differences  in  the actual time of day ("wall clock"
  107.       time), accurate to the nearest second (or  tenth  of  a  second,  if
  108.       possible).    Compilation,  link  or  binding,  and  load times must
  109.       include the time required to load and initialize the programs  which
  110.       perform these processes.  Compilation times include all intermediate
  111.       translations performed (e.g., from assembly code  to  native  object
  112.       code),  and specifically must include those not performed by the Ada
  113.       compiler itself.   The  sum  of  the  times  given  for  each  phase
  114.       (compilation,  linking,  etc.)  must  be equal to the actual elapsed
  115.       time  for  the  entire  sequence,  starting   with   initiation   of
  116.       compilation and ending with completion of execution.
  117.  
  118.    7. Size  information  shall  be given in bytes, accurate to the nearest
  119.       byte if  possible.    Module  object  code  size  does  not  include
  120.       predefined packages such as Text_IO and Calendar which were "with"ed
  121.       or the run-time support library or the underlying  operating  system
  122.       if any.
  123.  
  124.    8. In  the  event  that a test is found to be defective for any reason,
  125.       including (but not  restricted  to)  invalid  Ada  code,  functional
  126.       errors,  or unclear directions for its execution, it will be dropped
  127.       from the test suite and will not be considered further unless it can
  128.       be  corrected  easily  and  all  participating  vendors can be given
  129.       timely notification of the corrections.
  130.  
  131.    9. Any test may be challenged by any vendor stating their  belief  that
  132.       it  is  defective  and  why  they feel that it is.  (Suggestions for
  133.       fixing the defects will be gratefully received.)    Such  challenges
  134.       will  be  taken  under  advisement  by  the  Technical Chair and his
  135.       appointed representatives and will be  considered  and  accepted  or
  136.       rejected  as  expeditiously as possible.  Only those challenges made
  137.       before the date of the fair  will  be  considered  unless  there  is
  138.       unanimous agreement between all vendors and the Technical Chair that
  139.       a test is defective, in which case a challenge may  be  accepted  on
  140.       the  spot.  In the case of a rejected challenge, vendors may include
  141.       their objections with their results.
  142.  
  143.   10. In case  of  ambiguities  or  contradictions  in  these  rules,  the
  144.       interpretation  of  the  Technical Chair shall prevail.  Suggestions
  145.       for future changes to these rules which would improve  them  in  any
  146.       way,  particularly in their fairness, clarity of interpretation, and
  147.       usefulness to the Ada community are always welcome.
  148.  
  149.   11. Several copies of these rules will  be  made  available  for  public
  150.       inspection and reference at the Fair.
  151.  
  152.   12. Vendors  are requested to present two copies of a written summary of
  153.       their results and two copies of the compilation listing of each test
  154.       program  to  the  Technical  Chair  at least 30 minutes prior to the
  155.       opening of the demonstration period (scheduled  for  10:00am  on  30
  156.       June,  1984).    Additional  documentation which may be specifically
  157.       required for each test and supplemental information which the vendor
  158.       desires  to  supply  for  each  test should be submitted at the same
  159.       time.  In particular, cross reference  listings,  set/use  listings,
  160.       assembly  listings,  linkage  and  load  maps,  etc., which were not
  161.       generated in the official test  sequence,  may  be  included.    The
  162.       summary  of  results shall categorize the results in accordance with
  163.       the program outlined below:
  164.  
  165.     with Text_IO; use Text_IO;
  166.     procedure Summarize is
  167.  
  168.        type Vendor_Name is (<List of participating vendors>, None);
  169.        Vendor : Vendor_Name := None;
  170.  
  171.        Columns : constant := 80;
  172.  
  173.        subtype Comment is String (1 .. Columns);
  174.        Blank_Comment : constant Comment := (1 .. Columns => ' ');
  175.  
  176.        type Note is array (1 .. 5) of String (1 .. Columns);
  177.        Blank_Note : constant Note := (1 .. 5 => (1 .. Columns => ' '));
  178.  
  179.        Compilation_Environment : Note := Blank_Note;
  180.        Execution_Environment : Note := Blank_Note;
  181.  
  182.        type Test_Result is (Passed,
  183.                             Failed,
  184.                             Uncertain,
  185.                             Unable_To_Run,
  186.                             Not_Attempted,
  187.                             Disqualified,
  188.                             Test_Has_Been_Dropped);
  189.  
  190.        Seconds : constant Integer := 1;
  191.  
  192.        type Size is digits 6;
  193.        Kilo_Bytes : constant Size := 1.0; -- represents 1024 bytes
  194.  
  195.        type Result_Record is
  196.           record
  197.             Class : Test_Result := Not_Attempted;
  198.             Class_Comment : Comment := Blank_Comment;
  199.  
  200.             Challenged_By_Vendor : Boolean := False;
  201.             Challenge_Comment : Comment := Blank_Comment;
  202.  
  203.             -- Officially requested results go here:
  204.             Performance_Data : Note := Blank_Note;
  205.             Performance_Comment : Comment := Blank_Comment;
  206.  
  207.             -- Explanations and objections go here:
  208.             Explanations : Note := Blank_Note;
  209.  
  210.             -- This includes any intermediate translations by other
  211.             -- compilers or assemblers:
  212.             Compilation_Time : Duration := 0.0 * Seconds;
  213.             Compilation_Comment : Comment := Blank_Comment;
  214.  
  215.             -- A value of zero indicates load- or execution-time binding:
  216.  
  217.             Link_Or_Binding_Time : Duration := 0.0 * Seconds;
  218.             Linkage_Comment : Comment := Blank_Comment;
  219.  
  220.             -- A value of zero indicates load time is included in
  221.             -- execution time (and cannot be reported separately).
  222.             Load_Time : Duration := 0.0 * Seconds;
  223.             Loading_Comment : Comment := Blank_Comment;
  224.  
  225.             -- This includes Load_Time if it is not reported above:
  226.             Execution_Time : Duration := 0.0 * Seconds;
  227.             Execution_Comment : Comment := Blank_Comment;
  228.  
  229.             -- This includes only the units whose source is in the
  230.             -- compilation;
  231.             -- it excludes predefined packages which they "with":
  232.             Object_Code_Size : Size := 0.000 * Kilo_Bytes;
  233.             Object_Code_Comment : Comment := Blank_Comment;
  234.  
  235.             -- This includes pure code only; it excludes data and the
  236.             -- run-time support library:
  237.             Code_Image_Size : Size := 0.000 * Kilo_Bytes;
  238.             Code_Image_Comment : Comment := Blank_Comment;
  239.  
  240.             -- This includes it all -- code, data, and run-time support:
  241.             Maximum_Memory_Used : Size := 0.000 * Kilo_Bytes;
  242.             Memory_Used_Comment : Comment := Blank_Comment;
  243.           end record;
  244.  
  245.        Number_Of_Programs : constant
  246.                                := <Number actually submitted to vendors>;
  247.  
  248.        type Number is range 1 .. Number_Of_Programs;
  249.  
  250.        type Result_Array is array (Number) of Result_Record;
  251.  
  252.        Results : Result_Array;
  253.  
  254.        procedure Put (N : Note) is ... end Put;
  255.  
  256.        procedure Put (R : Result_Record) is ... end Put;
  257.  
  258.     begin
  259.  
  260.       Set_Line(To => 10);
  261.       Set_Column(To => 31);
  262.       Put_Line("LA AdaTEC Ada* Fair");
  263.  
  264.       Set_Column(To => 33);
  265.       Put_Line("30 June, 1984");
  266.  
  267.       Set_Column(To => 29);
  268.       Put_Line("COMPILER TEST RESULTS");
  269.       New_Line;
  270.  
  271.       Vendor := <This vendor's name>;
  272.       Set_Column(To => <TBD>);
  273.       Put(Vendor);
  274.       New_Line(2);
  275.  
  276.       Compilation_Environment
  277.          := <Description of the host computer and compiler toolset>;
  278.       Put(Compilation_Environment);
  279.       New_Line;
  280.       Execution_Environment
  281.          := <Description of the target computer and run-time environment>;
  282.       Put(Execution_Environment);
  283.  
  284.       Set_Line(To => 55);
  285.       Put("* Ada is a registered trademark of the U.S. Government " &
  286.           "(Ada Joint Program Office)");
  287.  
  288.       Results := <Vendor's actual results>;
  289.  
  290.       for N in Number loop
  291.          New_Page;
  292.          Put(Results(N));
  293.       end loop;
  294.  
  295.     end Summarize;
  296. ::::::::::
  297. UNIV_AR.ADA
  298. ::::::::::
  299. -------------------------------------------------------------------
  300. ---------------------  Next  Program  -----------------------------
  301. -------------------------------------------------------------------
  302.  
  303. ------------------------------------------------------------------------
  304. --
  305. --
  306. --
  307. --  U N I V E R S A L    A R I T H M E T I C    P A C K A G E S
  308. --
  309. --        Version: @(#)univ_ar.ada    1.1    Date: 5/30/84
  310. --
  311. --              written by
  312. --
  313. --             Gerry Fisher
  314. --         Computer Sciences Corporation
  315. --              4045 Hancock Street
  316. --              San Diego, CA 92110
  317. --
  318. --
  319. --
  320. -- The packages UNIVERSAL_INTEGER_ARITHMETIC and UNIVERSAL_REAL_ARITHMETIC,
  321. -- implement the arithmetic operations for the Ada* universal_integer and
  322. -- universal_real types.  Unlimited precision arithmetic is used for the
  323. -- universal_integer type and rational arithmetic for the universal_real
  324. -- type.  The implementation is based on the universal arithmetic package
  325. -- written in SETL by Robert Dewar for the NYU Ada/Ed compiler, and was
  326. -- coded in part while the author worked at TeleSoft.
  327. --
  328. -- The implementation presented here is not the most efficient.  It is,
  329. -- however, quite general and requires no low level facilities.  With some
  330. -- tuning these packages could be used within an Ada compiler to evaluate
  331. -- static expressions.  They also provide an excellent example of the use
  332. -- of Ada packages to support an abstract data type.
  333. --
  334. -- * Ada is a registered trademark of the DoD (Ada Joint Program Office)
  335. --
  336. ------------------------------------------------------------------------
  337.  
  338.  
  339.  
  340. package UNIVERSAL_INTEGER_ARITHMETIC is
  341.  
  342. --  This package implements the Ada type Universal_integer.
  343.  
  344. --  The operations defined on universal integers are those specified in
  345. --  chapter 4 of the RM.  Since the equality and inequality operators can
  346. --  not be overloaded, an equality operation is defined. In addition,
  347. --  conversions between INTEGER, STRING and Universal_integer are defined.
  348.  
  349.   type Universal_integer is private;
  350.  
  351.   function "+"    (x, y : Universal_integer) return Universal_integer;
  352.   function "-"    (x, y : Universal_integer) return Universal_integer;
  353.   function "*"    (x, y : Universal_integer) return Universal_integer;
  354.   function "/"    (x, y : Universal_integer) return Universal_integer;
  355.   function "mod"(x, y : Universal_integer) return Universal_integer;
  356.   function "rem"(x, y : Universal_integer) return Universal_integer;
  357.  
  358.   function "**" (x : Universal_integer; y : INTEGER) return Universal_integer;
  359.  
  360.   function "-"    (x : Universal_integer) return Universal_integer;
  361.   function "abs"(x : Universal_integer) return Universal_integer;
  362.  
  363.   function ">=" (x, y : Universal_integer) return boolean;
  364.   function ">"    (x, y : Universal_integer) return boolean;
  365.   function "<=" (x, y : Universal_integer) return boolean;
  366.   function "<"    (x, y : Universal_integer) return boolean;
  367.   function eql    (x, y : Universal_integer) return boolean;
  368.  
  369.   function Int(x : Universal_integer) return INTEGER;
  370.  
  371.   -- Converts a universal integer to a integer.  The exception
  372.   -- NUMERIC_ERROR is raised if the universal integer x has a value
  373.   -- outside the integer range.
  374.  
  375.  
  376.   function UI(i : INTEGER) return Universal_integer;
  377.  
  378.   -- Constructs a universal integer from an integer.
  379.  
  380.  
  381.   function IMAGE(x : Universal_integer) return STRING;
  382.  
  383.   -- Converts the universal integer x into its string image, that is, a
  384.   -- sequence of characters representing the value in display form.  The
  385.   -- image of a universal integer value is the corresponding decimal
  386.   -- literal; without underlines, leading zeros, exponent or trailing spaces;
  387.   -- but with a single leading minus sign or space.  The lower bound of the
  388.   -- image string is one.
  389.  
  390.  
  391.   function VALUE(s : STRING) return Universal_integer;
  392.  
  393.   -- Converts the string s into a universal integer value.  The string must have
  394.   -- the syntax of an optionally signed decimal integer literal; otherwise, the
  395.   -- exception CONSTRAINT_ERROR is raised.  The exponent of the decimal literal,
  396.   -- if present, must not exceed INTEGER'LAST.
  397.  
  398.  
  399. private
  400.  
  401.   type VECTOR;
  402.  
  403.   type Universal_integer is access VECTOR;
  404.  
  405. end UNIVERSAL_INTEGER_ARITHMETIC;
  406.  
  407.  
  408.  
  409. package body UNIVERSAL_INTEGER_ARITHMETIC is
  410.  
  411. --  A universal integer consists of a sign and a magnitude.  The
  412. --  magnitude is a vector of non-negative integers giving from
  413. --  most significant to least significant the "digits" of the
  414. --  number in some convenient base.  There are no leading zero digits,
  415. --  unless the value is zero.  Universal integers are always normalized.
  416. --  The lower bound of the universal integer vector is always one.
  417. --  Thus, the magnitude for the vector V(1 .. k) is given by:
  418. --
  419. --    V(1) * BASE**(k - 1) + V(2) * BASE**(k - 2) + ... + V(k)
  420. --
  421. --  The maximum number of digits in a universal integer is limited
  422. --  in this implementation only by the amount of available memory.
  423. --
  424. --  The base is 10 ** ((INTEGER'WIDTH - 2) / 2).  The universal digits are
  425. --  integers in the range 0 .. BASE - 1.  This choice of BASE means that
  426. --  slightly less than half of the integer range is used.  However, the
  427. --  choice does ensure that the product of two universal digits is an integer.
  428. --  Also, the number of universal digits required to represent an integer value
  429. --  as a universal integer is at most four.
  430. --
  431. --  To complete the representation the high order universal digit has the sign
  432. --  of the universal integer.
  433.  
  434.  
  435.   BASE_D  : constant := (INTEGER'WIDTH - 2) / 2;
  436.   BASE      : constant :=  10 ** BASE_D;
  437.   BASE_SQ : constant := BASE * BASE;
  438.   INT_D   : constant := 4;
  439.  
  440.  
  441.   type VECTOR is array(POSITIVE range <>) of INTEGER;
  442.  
  443.  
  444.   i_zero : constant Universal_integer := new VECTOR'(1 => 0);
  445.   i_one  : constant Universal_integer := new VECTOR'(1 => 1);
  446.   i_two  : constant Universal_integer := new VECTOR'(1 => 2);
  447.   i_ten  : constant Universal_integer := new VECTOR'(1 => 10);
  448.  
  449.  
  450.   function UI(v : VECTOR; s : BOOLEAN := FALSE) return Universal_integer is
  451.  
  452.   -- Constructs a universal integer from a vector and a sign; the vector
  453.   -- need not be normalized.  The boolean s is true if the number is negative.
  454.  
  455.      t : Universal_integer;
  456.  
  457.   begin
  458.  
  459.   --  The representation used in this package requires that all
  460.   --  Universal_integer values be normalized.  The first digit of any
  461.   --  value, except zero, must be non-zero.
  462.  
  463.      for j in v'range loop
  464.        if v(j) /= 0 then
  465.          t := new VECTOR(1 .. v'last - j + 1);  -- ensure lower bound of one
  466.          t.all := v(j .. v'last);
  467.      if s then t(1) := - t(1); end if;
  468.      return t;
  469.        end if;
  470.      end loop;
  471.  
  472.      return i_zero;
  473.  
  474.   end UI;
  475.  
  476.  
  477.   function UI(i : INTEGER) return Universal_integer is
  478.  
  479.     y : VECTOR(1 .. INT_D) := (1 .. INT_D => 0);
  480.     z : INTEGER;
  481.  
  482.   begin
  483.  
  484.     if i < BASE and then i > - BASE then
  485.       return new VECTOR'(1 => i);
  486.     end if;
  487.  
  488.     z := i;
  489.  
  490.     for j in reverse y'range
  491.     loop
  492.       y(j) := abs(z rem BASE);
  493.       z    := z / BASE;
  494.     end loop;
  495.  
  496.     return UI(y, i < 0);
  497.  
  498.   end UI;
  499.  
  500.  
  501.   function Int(x : Universal_integer) return INTEGER is
  502.     y : INTEGER;
  503.   begin
  504.  
  505.     if    x'length = 1 then
  506.       return x(1);
  507.     end if;
  508.  
  509.     y := 0;
  510.  
  511.     for i in x'range loop        -- convert as a negative integer
  512.       y := y * BASE - abs x(i);  -- this may raise NUMERIC_ERROR, but
  513.     end loop;             -- only if the magnitude of x is too large.
  514.  
  515.     if x(1) < 0 then
  516.       return   y;
  517.     else
  518.       return - y;         -- this may raise NUMERIC_ERROR if x is
  519.     end if;                      -- -(integer'first) and range is not symmetric.
  520.  
  521.   end Int;
  522.  
  523.  
  524.   function IMAGE(x : Universal_integer) return STRING is
  525.  
  526.     m    : integer := x'length * BASE_D + 1;
  527.     s     : string(1 .. m);
  528.     y     : Universal_integer;
  529.     j, d : integer;
  530.  
  531.   begin
  532.  
  533.     if x(1) = 0 then
  534.        return " 0";
  535.     end if;
  536.  
  537.     j := m;
  538.     y := abs x;
  539.  
  540.     while y(1) /= 0 loop
  541.       d := Int(y rem i_ten);
  542.       y := y / i_ten;
  543.  
  544.       s(j) := character'val(character'pos('0') + d);
  545.       j    := j - 1;
  546.     end loop;
  547.  
  548.     if x(1) < 0 then
  549.       s(j) := '-';
  550.     else
  551.       s(j) := ' ';
  552.     end if;
  553.  
  554.     d := m - j + 1;
  555.     s(1 .. d) := s(j .. m);
  556.     return s(1 .. d);
  557.  
  558.   end IMAGE;
  559.  
  560.  
  561.   function VALUE(s : STRING) return Universal_integer is
  562.  
  563.     num    : Universal_integer := i_zero;
  564.     exp    : integer := 0;
  565.     signed : boolean := false;
  566.     has_exp: boolean := false;
  567.     c       : character;
  568.     j       : integer;
  569.  
  570.   begin
  571.  
  572.     if s'length = 0 then
  573.       raise CONSTRAINT_ERROR;
  574.     end if;
  575.  
  576.     j := s'first;
  577.     c := s(j);
  578.  
  579.     if c = '-' or else c = '+' then
  580.  
  581.       j := j + 1;
  582.       if s(j) not in '0' .. '9' then    -- index out of range may also raise
  583.     raise CONSTRAINT_ERROR;     -- constraint_error here
  584.       end if;
  585.       signed := c = '-';
  586.  
  587.     end if;
  588.  
  589.     while j <= s'last loop
  590.  
  591.       c := s(j);
  592.       case c is
  593.         when '0' .. '9' =>
  594.  
  595.       if has_exp then
  596.             exp := exp * 10 + (character'pos(c) - character'pos('0'));
  597.       else
  598.             num := num * i_ten + UI(character'pos(c) - character'pos('0'));
  599.       end if;
  600.  
  601.         when '_' =>
  602.  
  603.           if s(j - 1) not in '0' .. '9' or else s(j + 1) not in '0' .. '9' then
  604.         raise CONSTRAINT_ERROR;
  605.       end if;
  606.  
  607.         when 'E' | 'e' =>
  608.  
  609.           if has_exp or else s(j - 1) not in '0' .. '9' then
  610.         raise CONSTRAINT_ERROR;
  611.       end if;
  612.  
  613.       has_exp := true;
  614.           if s(j + 1) = '+' then j := j + 1; end if;
  615.           if s(j + 1) not in '0' .. '9' then
  616.         raise CONSTRAINT_ERROR;
  617.       end if;
  618.  
  619.     when others =>
  620.       raise CONSTRAINT_ERROR;
  621.  
  622.       end case;
  623.  
  624.       j := j + 1;
  625.  
  626.     end loop;
  627.  
  628.     if has_exp then num := num * i_ten ** exp; end if;
  629.  
  630.     if signed  then num := - num; end if;
  631.  
  632.     return num;
  633.  
  634.   end VALUE;
  635.  
  636.  
  637.   function "-"    (x : Universal_integer) return Universal_integer is
  638.   begin
  639.     return new VECTOR'(- x(1) & x(2 .. x'last));
  640.   end "-";
  641.  
  642.   function "abs"  (x : Universal_integer) return Universal_integer is
  643.   begin
  644.     return new VECTOR'(abs x(1) & x(2 .. x'last));
  645.   end "abs";
  646.  
  647.  
  648.   function "+"    (x, y : Universal_integer) return Universal_integer is
  649.  
  650.      m        : integer;
  651.      k, r   : integer;
  652.      xl, yl : integer;
  653.      xs, ys : boolean;
  654.  
  655.   begin
  656.  
  657.     xl := x'length;
  658.     yl := y'length;
  659.  
  660.     if xl = 1 and then yl = 1 then            -- each has one digit
  661.       return UI(x(1) + y(1));
  662.  
  663.     else            -- either or both operands have > 1 digits
  664.  
  665.       if xl < yl then
  666.     m := yl + 1;
  667.       else
  668.     m := xl + 1;
  669.       end if;
  670.  
  671.       declare
  672.  
  673.     u, v   : VECTOR(1 .. m);
  674.  
  675.       begin
  676.  
  677.     xs := x(1) < 0;
  678.     ys := y(1) < 0;
  679.  
  680.     u := (1 .. m - xl => 0) & abs x(1) & x(2 .. xl);
  681.     v := (1 .. m - yl => 0) & abs y(1) & y(2 .. yl);
  682.  
  683.     if xs = ys then     -- signs agree so add
  684.  
  685.       k := 0;
  686.       for i in reverse 1 .. m loop
  687.  
  688.         r := u(i) + v(i) + k;
  689.         if r >= BASE then
  690.           r := r - BASE;
  691.           k := 1;
  692.         else
  693.           k := 0;
  694.         end if;
  695.         u(i) := r;
  696.  
  697.       end loop;
  698.  
  699.       return UI(u, xs);
  700.  
  701.     else
  702.  
  703.     -- signs different, subtract smaller from larger
  704.  
  705.       k := 0;
  706.       for i in reverse 1 .. m loop
  707.  
  708.         r := u(i) - v(i) + k;
  709.         if r < 0 then
  710.           r := r + BASE;
  711.           k := - 1;
  712.         else
  713.           k := 0;
  714.         end if;
  715.         u(i) := r;
  716.  
  717.       end loop;
  718.  
  719.       if k = 0 then     -- x has the larger magnitude
  720.  
  721.         return UI(u, xs);
  722.  
  723.       else            -- y has the larger magnitude, so recomplement
  724.  
  725.         k := 1;
  726.         for i in reverse 1 .. m loop
  727.  
  728.           r := BASE - 1 - u(i) + k;
  729.           if r = BASE then
  730.         r := 0;
  731.         k := 1;
  732.           else
  733.         k := 0;
  734.           end if;
  735.           u(i) := r;
  736.  
  737.         end loop;
  738.  
  739.         return UI(u, ys);
  740.  
  741.       end if;
  742.  
  743.     end if;
  744.  
  745.       end;
  746.  
  747.     end if;
  748.  
  749.   end "+";
  750.  
  751.  
  752.   function "-"    (x, y : Universal_integer) return Universal_integer is
  753.   begin
  754.     return x + (- y);
  755.   end "-";
  756.  
  757.  
  758.   function "*"    (x, y : Universal_integer) return Universal_integer is
  759.  
  760.   --  This function returns the product of the universal integers x
  761.   --  and y using essentially the familiar hand algorithm.
  762.  
  763.     xl, yl : integer;
  764.  
  765.   begin
  766.  
  767.     xl := x'length;
  768.     yl := y'length;
  769.  
  770.     if xl = 1 and yl = 1 then            -- both have a single digit
  771.       return UI(x(1) * y(1));
  772.     end if;
  773.  
  774.     declare
  775.  
  776.       w    : VECTOR(1 .. xl + yl) := (1 .. xl + yl => 0);
  777.       k, r : integer;
  778.  
  779.     begin
  780.  
  781.       for j in reverse y'range loop
  782.  
  783.       --  outer loop through digits of the multiplier, inner loop
  784.       --  through digits of multiplicand
  785.  
  786.     k := 0;
  787.         for i in reverse x'range loop
  788.       r       := abs(x(i) * y(j)) + w(i + j) + k;
  789.       w(i + j) := r rem BASE;
  790.       k       := r /   BASE;
  791.     end loop;
  792.  
  793.     w(j)       := k;
  794.  
  795.       end loop;
  796.  
  797.       return UI(w, (x(1) < 0) xor (y(1) < 0));
  798.  
  799.     end;
  800.  
  801.   end "*";
  802.  
  803.  
  804.   function "/"    (x, y : Universal_integer) return Universal_integer is
  805.  
  806.     m        : integer;
  807.     xl, yl  : integer;
  808.     e        : integer;
  809.     d, r, t : integer;
  810.     qe        : integer;            -- quotient digit estimate
  811.     v1, v2  : integer;
  812.  
  813.   begin
  814.  
  815.     xl := x'length;
  816.     yl := y'length;
  817.  
  818.     if      xl = 1 and then yl = 1 then    -- can use simple integer division
  819.  
  820.       return UI(x(1) / y(1));        -- integer divide catches zero divisor
  821.  
  822.     elsif xl < yl then            -- divisor has more digits
  823.  
  824.       return i_zero;
  825.  
  826.     elsif yl = 1 then            -- divisor has single digit
  827.                     -- dividend has more than one digit,
  828.                     -- important special case for which
  829.                     -- an efficient algorithm is used
  830.       r  := 0;
  831.       v1 := abs y(1);
  832.       if v1 = 0 then            -- divisor is zero
  833.     raise NUMERIC_ERROR;
  834.       end if;
  835.  
  836.       declare
  837.     q : VECTOR(1 .. xl);
  838.       begin
  839.  
  840.         for j in x'range loop
  841.       t    := r * BASE + abs x(j);
  842.       q(j) := t /    v1;
  843.       r    := t rem v1;
  844.     end loop;
  845.  
  846.     return UI(q, (x(1) < 0) xor (y(1) < 0));
  847.  
  848.       end;
  849.  
  850.     end if;
  851.  
  852.     --    At this point the length of the dividend is at least two and
  853.     --    at least as much as the length of the divisor.    We must do a
  854.     --    full long division.  The algorithm used here is from Knuth,
  855.     --    "The Art of Programming", Volume 2, Section 4.3.1, Algorithm D.
  856.  
  857.     --    The first step is to multiply both the divisor and dividend
  858.     --    by a scale factor to ensure that the first digit of the divisor
  859.     --    is at least BASE / 2.  This condition is required by the
  860.     --    quotient digit estimation algorithm used in the division loop.
  861.     --    Note that this may increase the size of the dividend by one digit
  862.     --    and thus the scaled dividend is placed in u.
  863.  
  864.     m := xl - yl + 1;
  865.  
  866.     declare
  867.       u : VECTOR(1 .. xl + 1);        -- the dividend
  868.       v : VECTOR(1 .. yl);        -- the divisor
  869.       q : VECTOR(1 .. m);        -- the quotient
  870.     begin
  871.  
  872.       u := 0 & abs x(1) & x(2 .. xl);
  873.       v := abs y(1) & y(2 .. yl);
  874.  
  875.       v1 := v(1);
  876.  
  877.       d := BASE / (v1 + 1);        -- scale factor
  878.  
  879.       if d > 1 then            -- scale dividend and divisor
  880.  
  881.     r := 0;
  882.         for j in reverse u'range loop
  883.        t    := u(j) * d + r;
  884.        u(j) := t rem BASE;
  885.        r    := t /     BASE;
  886.     end loop;
  887.  
  888.     r := 0;
  889.         for j in reverse v'range loop
  890.        t    := v(j) * d + r;
  891.        v(j) := t rem BASE;
  892.        r    := t /     BASE;
  893.     end loop;
  894.  
  895.       end if;
  896.  
  897.       -- This is the major loop, corresponding to long division steps.
  898.  
  899.       v1 := v(1);
  900.       v2 := v(2);
  901.  
  902.       for j in q'range loop
  903.  
  904.     -- Guess the next quotient digit, qe, by dividing the first two
  905.     -- remaining dividend digits by the high order divisor digit.
  906.     -- This estimate is never low and is at most 2 high.
  907.  
  908.     t := u(j) * BASE + u(j + 1);
  909.     if u(j) /= v1 then
  910.        qe := t / v1;
  911.     else
  912.        qe := BASE - 1;
  913.     end if;
  914.  
  915.     -- Now refine this guess so that it is almost always correct and
  916.     -- is at worst one too high.
  917.  
  918.     while v2 * qe > (t - qe * v1) * BASE + u(j + 2) loop
  919.        qe := qe - 1;
  920.     end loop;
  921.  
  922.     -- Using qe as the quotient digit, we multiply the divisor by
  923.     -- qe and subtract from the remaining dividend.
  924.  
  925.     r := 0;
  926.         for k in reverse v'range loop
  927.        t := u(j + k) - qe * v(k) + r;
  928.        e := t rem BASE;
  929.        r := t /   BASE;
  930.        if e < 0 then
  931.           e := e + BASE;
  932.           r := r - 1;
  933.        end if;
  934.        u(j + k) := e;
  935.     end loop;
  936.  
  937.     u(j) := u(j) + r;
  938.  
  939.     -- If qe was off by one, then u(j) went negative when the last
  940.     -- carry was added.  So we correct the error by subtracting one
  941.     -- from the quotient digit and adding back the divisor to the
  942.     -- relevant portion of the dividend.
  943.  
  944.     if u(j) < 0 then
  945.        qe := qe - 1;
  946.        r := 0;
  947.            for k in reverse v'range loop
  948.           t := u(j + k) + v(k) + r;
  949.           if t > BASE then
  950.          t := t - BASE;
  951.          r := 1;
  952.           else
  953.          r := 0;
  954.           end if;
  955.           u(j + k) := t;
  956.        end loop;
  957.        u(j) := u(j) + r;
  958.     end if;
  959.  
  960.     -- Store the next quotient digit.
  961.  
  962.     q(j) := qe;
  963.  
  964.       end loop;
  965.  
  966.       return UI(q, (x(1) < 0) xor (y(1) < 0));
  967.  
  968.     end;
  969.  
  970.   end "/";
  971.  
  972.  
  973.   function "rem"(x, y : Universal_integer) return Universal_integer is
  974.   begin
  975.     if x'length = 1 and then y'length = 1 then
  976.       return UI(x(1) rem y(1));
  977.     else
  978.       return x - (x / y) * y;
  979.     end if;
  980.   end "rem";
  981.  
  982.   function "mod"(x, y : Universal_integer) return Universal_integer is
  983.      r : constant Universal_integer := x rem y;
  984.   begin
  985.      if (x(1) < 0) = (y(1) < 0) or else r(1) = 0 then
  986.     return r;
  987.      else
  988.     return y + r;
  989.      end if;
  990.   end "mod";
  991.  
  992.  
  993.   function "**"(x : Universal_integer; y : INTEGER) return Universal_integer is
  994.  
  995.   --  Raise a universal integer to an integer power using the binary
  996.   --  representation of the exponent.
  997.  
  998.     r : Universal_integer := i_one;
  999.     v : integer       := y;
  1000.     t : Universal_integer := abs x;
  1001.  
  1002.   begin
  1003.  
  1004.     if      y < 0 then
  1005.       raise CONSTRAINT_ERROR;
  1006.     elsif y = 0 then
  1007.       return i_one;
  1008.     elsif x(1) = 0 then
  1009.       return i_zero;
  1010.     end if;
  1011.  
  1012.     -- Starting the variable r at 1 and t at x loop through the binary
  1013.     -- digits of v, squaring t each time, and multiplying the result r
  1014.     -- by the current value of t each time a 1-bit is found.
  1015.  
  1016.     while v /= 0 loop
  1017.  
  1018.       if v rem 2 = 1 then            -- v is odd
  1019.     r := r * t;
  1020.       end if;
  1021.  
  1022.       t := t * t;
  1023.       v := v / 2;                -- halve v
  1024.  
  1025.     end loop;
  1026.  
  1027.     -- Compute the sign of the result: positive if y is even, the sign of
  1028.     -- x if y is odd.
  1029.  
  1030.     if x(1) < 0 and then y rem 2 = 1 then r(1) := - r(1); end if;
  1031.  
  1032.     return r;
  1033.  
  1034.   end "**";
  1035.  
  1036.  
  1037.  
  1038.   function ">=" (x, y : Universal_integer) return boolean is
  1039.     z : Universal_integer := x - y;
  1040.   begin
  1041.      return z(1) >= 0;
  1042.   end ">=";
  1043.  
  1044.  
  1045.   function "<=" (x, y : Universal_integer) return boolean is
  1046.     z : Universal_integer := x - y;
  1047.   begin
  1048.     return z(1) <= 0;
  1049.   end "<=";
  1050.  
  1051.  
  1052.   function "<"    (x, y : Universal_integer) return boolean is
  1053.     z : Universal_integer := x - y;
  1054.   begin
  1055.      return z(1) < 0;
  1056.   end "<";
  1057.  
  1058.  
  1059.   function ">"    (x, y : Universal_integer) return boolean is
  1060.     z : Universal_integer := x - y;
  1061.   begin
  1062.      return z(1) > 0;
  1063.   end ">";
  1064.  
  1065.  
  1066.   function eql    (x, y : Universal_integer) return boolean is
  1067.   begin
  1068.      return x.all = y.all;
  1069.   end eql;
  1070.  
  1071. end UNIVERSAL_INTEGER_ARITHMETIC;
  1072.  
  1073.  
  1074.  
  1075.  
  1076. with UNIVERSAL_INTEGER_ARITHMETIC;
  1077. use  UNIVERSAL_INTEGER_ARITHMETIC;
  1078. package UNIVERSAL_REAL_ARITHMETIC is
  1079.  
  1080. --  This package implements the Ada type Universal_real.
  1081.  
  1082. --  The operations defined on universal numbers are those specified in
  1083. --  chapter 4 of the RM.  Since the equality and inequality operators can
  1084. --  not be overloaded, an equality function is defined.   A universal real
  1085. --  number corresponds to a unique pair of universal integers that represent
  1086. --  it as a rational number.  A function, UR, is defined that constructs a
  1087. --  universal real number from a pair of universal integers.  Also, the inverse
  1088. --  of this function is provided by two functions, NUMERATOR and DENOMINATOR,
  1089. --  that decompose the rational number representation of their universal real
  1090. --  argument into its numerator and denominator, respectively.    In addition,
  1091. --  conversions between Universal_integer and Universal_real are defined.
  1092.  
  1093.  
  1094.   type Universal_real is private;
  1095.  
  1096.  
  1097.   function "+"    (x, y : Universal_real) return Universal_real;
  1098.   function "-"    (x, y : Universal_real) return Universal_real;
  1099.   function "*"    (x, y : Universal_real) return Universal_real;
  1100.   function "/"    (x, y : Universal_real) return Universal_real;
  1101.  
  1102.   function "**" (x : Universal_real;    y : INTEGER) return Universal_real;
  1103.  
  1104.   function "*"    (x : Universal_integer; y : Universal_real)
  1105.                         return Universal_real;
  1106.   function "*"    (x : Universal_real;    y : Universal_integer)
  1107.                         return Universal_real;
  1108.   function "/"    (x : Universal_real;    y : Universal_integer)
  1109.                         return Universal_real;
  1110.  
  1111.   function "-"    (x : Universal_real) return Universal_real;
  1112.   function "abs"(x : Universal_real) return Universal_real;
  1113.  
  1114.   function ">=" (x, y : Universal_real) return boolean;
  1115.   function ">"    (x, y : Universal_real) return boolean;
  1116.   function "<=" (x, y : Universal_real) return boolean;
  1117.   function "<"    (x, y : Universal_real) return boolean;
  1118.   function eql    (x, y : Universal_real) return boolean;
  1119.  
  1120.  
  1121.   function UI(x : Universal_real) return Universal_integer;
  1122.  
  1123.   -- Converts a universal real to a universal integer by rounding.
  1124.  
  1125.  
  1126.   function UR(x : Universal_integer) return Universal_real;
  1127.  
  1128.   -- Converts a universal integer to a universal real.
  1129.  
  1130.  
  1131.   function UR(n, d : Universal_integer) return Universal_real;
  1132.  
  1133.   -- Constructs a universal real as the ratio of  two universal integers.
  1134.   -- The value of d must not be ZERO; if it is, NUMERIC_ERROR is raised.
  1135.  
  1136.  
  1137.   function NUMERATOR(x : Universal_real) return Universal_integer;
  1138.  
  1139.   -- Returns the numerator of x viewed as a rational number.
  1140.  
  1141.  
  1142.   function DENOMINATOR(x : Universal_real) return Universal_integer;
  1143.  
  1144.   -- Returns the denominator of x viewed as a rational number.
  1145.  
  1146.  
  1147. private
  1148.  
  1149. --  A universal real is represented as a rational number consisting
  1150. --  of a pair of universal integers.  The numerator is the first
  1151. --  member of the pair and the denominator is the second.  The
  1152. --  denominator must not be zero.  Also, the numerator, denominator
  1153. --  pair is always reduced to lowest terms.
  1154.  
  1155.   type Universal_real is
  1156.      record
  1157.        num : Universal_integer;
  1158.        den : Universal_integer;
  1159.      end record;
  1160.  
  1161.  
  1162. end UNIVERSAL_REAL_ARITHMETIC;
  1163.  
  1164.  
  1165. with UNIVERSAL_INTEGER_ARITHMETIC;
  1166. use UNIVERSAL_INTEGER_ARITHMETIC;
  1167. pragma ELABORATE(UNIVERSAL_INTEGER_ARITHMETIC);
  1168. package body UNIVERSAL_REAL_ARITHMETIC is
  1169.  
  1170.   i_zero : constant Universal_integer := UI(0);
  1171.   i_one  : constant Universal_integer := UI(1);
  1172.   i_two  : constant Universal_integer := UI(2);
  1173.   i_ten  : constant Universal_integer := UI(10);
  1174.  
  1175.   r_zero : constant Universal_real := (i_zero, i_one);
  1176.   r_one  : constant Universal_real := (i_one,  i_one);
  1177.  
  1178.  
  1179.   function UR(n, d : Universal_integer) return Universal_real is
  1180.  
  1181.   -- Constructs a universal real as the ratio of two universal integers.
  1182.   -- The value of d must not be ZERO; if it is, NUMERIC_ERROR is raised.
  1183.  
  1184.   -- Every real number produced as a result of an operation defined in
  1185.   -- this package must have a positive denominator and the numerator and
  1186.   -- denominator must be reduced to lowest terms.  This ensures uniqueness
  1187.   -- of the representation.
  1188.  
  1189.     r : Universal_integer;
  1190.     y : Universal_integer;
  1191.     z : Universal_integer;
  1192.  
  1193.   begin
  1194.     if      eql(d, i_zero) then
  1195.       raise NUMERIC_ERROR;
  1196.     elsif eql(n, i_zero) then
  1197.       return r_zero;
  1198.     end if;
  1199.  
  1200.     -- Now reduce to lowest terms; that is, find the gcd of n and d.
  1201.  
  1202.     y := abs n;
  1203.     z := abs d;
  1204.     loop
  1205.       r := y rem z;
  1206.       exit when eql(r, i_zero);
  1207.       y := z;
  1208.       z := r;
  1209.     end loop;
  1210.  
  1211.     if     d >= i_zero then
  1212.       return (n / z, d / z);
  1213.     else
  1214.       return (- n / z, - d / z);
  1215.     end if;
  1216.  
  1217.   end UR;
  1218.  
  1219.  
  1220.   function UI(x : Universal_real) return Universal_integer is
  1221.  
  1222.     i : Universal_integer := x.num / x.den;
  1223.     r : Universal_real      := (i, i_one);
  1224.     h : Universal_real      := (i_two, i_one);
  1225.  
  1226.   begin
  1227.     if      eql(x.num, i_zero) then
  1228.       return i_zero;
  1229.     elsif x.num < i_zero and then x - r <= - h then
  1230.       return i - i_one;
  1231.     elsif x.num > i_zero and then x - r >=   h then
  1232.       return i + i_one;
  1233.     else
  1234.       return i;
  1235.     end if;
  1236.   end UI;
  1237.  
  1238.  
  1239.   function UR(x : Universal_integer) return Universal_real is
  1240.   begin
  1241.     return (x, i_one);
  1242.   end UR;
  1243.  
  1244.  
  1245.   function NUMERATOR(x : Universal_real) return Universal_integer is
  1246.   begin
  1247.     return x.num;
  1248.   end NUMERATOR;
  1249.  
  1250.   function DENOMINATOR(x : Universal_real) return Universal_integer is
  1251.   begin
  1252.     return x.den;
  1253.   end DENOMINATOR;
  1254.  
  1255.  
  1256.   function "-"    (x : Universal_real) return Universal_real is
  1257.   begin
  1258.     return (- x.num, x.den);
  1259.   end "-";
  1260.  
  1261.  
  1262.   function "abs"  (x : Universal_real) return Universal_real is
  1263.   begin
  1264.     return (abs x.num, x.den);
  1265.   end "abs";
  1266.  
  1267.   function "*" (x : Universal_integer; y : Universal_real)
  1268.                         return Universal_real is
  1269.   begin
  1270.     return UR(y.num * x, y.den);
  1271.   end "*";
  1272.  
  1273.  
  1274.   function "*"(x : Universal_real; y : Universal_integer)
  1275.                         return Universal_real is
  1276.   begin
  1277.     return UR(x.num * y, x.den);
  1278.   end "*";
  1279.  
  1280.  
  1281.   function "/"(x : Universal_real; y : Universal_integer)
  1282.                         return Universal_real is
  1283.   begin
  1284.     return UR(x.num, x.den * y);
  1285.   end "/";
  1286.  
  1287.  
  1288.   function "+"    (x, y : Universal_real) return Universal_real is
  1289.   begin
  1290.     return UR(x.num * y.den + y.num * x.den, x.den * y.den);
  1291.   end "+";
  1292.  
  1293.  
  1294.   function "-"    (x, y : Universal_real) return Universal_real is
  1295.   begin
  1296.     return x + (- y);
  1297.   end "-";
  1298.  
  1299.  
  1300.   function "*"    (x, y : Universal_real) return Universal_real is
  1301.   begin
  1302.     return UR(x.num * y.num, x.den * y.den);
  1303.   end "*";
  1304.  
  1305.  
  1306.   function "/"    (x, y : Universal_real) return Universal_real is
  1307.   begin
  1308.     return UR(x.num * y.den, x.den * y.num);
  1309.   end "/";
  1310.  
  1311.   function "**"(x : Universal_real; y : INTEGER) return Universal_real is
  1312.   begin
  1313.     if      y = 0 then
  1314.       return r_one;
  1315.     elsif y > 0 then
  1316.       return UR(x.num ** y, x.den ** y);
  1317.     else
  1318.       return UR(x.den ** (- y), x.num ** (- y));
  1319.     end if;
  1320.   end "**";
  1321.  
  1322.  
  1323.   function ">=" (x, y : Universal_real) return boolean is
  1324.     z : Universal_real := x - y;
  1325.   begin
  1326.      return z.num >= i_zero;
  1327.   end ">=";
  1328.  
  1329.  
  1330.   function "<=" (x, y : Universal_real) return boolean is
  1331.     z : Universal_real := x - y;
  1332.   begin
  1333.      return z.num <= i_zero;
  1334.   end "<=";
  1335.  
  1336.  
  1337.   function "<"    (x, y : Universal_real) return boolean is
  1338.     z : Universal_real := x - y;
  1339.   begin
  1340.      return z.num < i_zero;
  1341.   end "<";
  1342.  
  1343.  
  1344.   function ">"    (x, y : Universal_real) return boolean is
  1345.     z : Universal_real := x - y;
  1346.   begin
  1347.     return z.num > i_zero;
  1348.   end ">";
  1349.  
  1350.  
  1351.   function eql    (x, y : Universal_real) return boolean is
  1352.     z : Universal_real := x - y;
  1353.   begin
  1354.     return eql(z.num, i_zero);
  1355.   end eql;
  1356.  
  1357. end UNIVERSAL_REAL_ARITHMETIC;
  1358. ::::::::::
  1359. AKERMAN.ADA
  1360. ::::::::::
  1361. -------------------------------------------------------------------
  1362. ---------------------  Next  Program  -----------------------------
  1363. -------------------------------------------------------------------
  1364.  
  1365.  
  1366. --
  1367. -- Version: @(#)akerman.ada    2.4        Date: 6/3/85
  1368. --
  1369. -- Author:  Brian A. Wichmann
  1370. --        National Physical Laboratory
  1371. --        Teddington, Middlesex TW11 OLW, UK
  1372. --
  1373. -- Modified by LA AdaTEC to conform to ANSI Standard Ada & to test
  1374. -- for significance of elapsed time.
  1375. --
  1376. -- [Extracts from: "Latest resuts from the procedure calling test,
  1377. --  Ackermann's function", B. A. Wichamann,  NPL Report DITC 3/82,
  1378. --  ISSN 0143-7348]
  1379. --
  1380. -- Ackermann's function has been used to measure the procedure calling
  1381. -- overhead in languages which support recursion [Algol-like languages,
  1382. -- Assembly Languages, & Basic]
  1383. --
  1384. -- Ackermann's function is a small recursive function .... Although of
  1385. -- no particular interest in itself, the function does perform other
  1386. -- operations common to much systems programming (testing for zero,
  1387. -- incrementing and decrementing integers).  The function has two
  1388. -- parameters M and N, the test being for (3, N) with N in the range
  1389. -- 1 to 6.
  1390. --
  1391. -- [End of Extract]
  1392. --
  1393. -- The object code size of the Ackermann function should be reported in
  1394. -- 8-bit bytes, as well as, the Average Number of Instructions Executed
  1395. -- per Call of the Ackermann function.  Also,  if the stack space is
  1396. -- exceeded, report the parameter values used as input to the initial
  1397. -- invocation of the Ackermann function.
  1398. --
  1399. -- The Average Number of Instructions Executed Per Call should preferably
  1400. -- be determined by examining the object code and calculating the number
  1401. -- of instructions executed for a significant number of calls of the
  1402. -- Ackermann function (see below).  If that is not possible,
  1403. -- please make an estimate based the average execution time per machine
  1404. -- instruction for the target machine and the average time per call for
  1405. -- a significant number of calls.  Clearly indicate whether the Average
  1406. -- Number of Instructions Executed Per Call is an estimate or not.
  1407. --
  1408. -- Note:  In order for the measurement to be meaningful, it must be the 
  1409. -- only program executing while the test is run.  The number of calls is
  1410. -- significant if the elapsed time for the initial invocation of the
  1411. -- Ackermann's function is at least 100 times Duration'Small & at least
  1412. -- 100 times System.Tick).
  1413. --
  1414.  
  1415. with Text_IO;  use Text_IO;
  1416. with Calendar; use Calendar;
  1417. with System;   use System;
  1418.  
  1419. procedure Time_Ackermann is
  1420.  
  1421.    type Real_Time is digits Max_Digits;
  1422.  
  1423.    Start_Time :   Time;
  1424.    Elapsed_Time : Duration;
  1425.    Average_Time : Real_Time;
  1426.  
  1427.    package Duration_IO is new Fixed_IO (Duration);
  1428.    use Duration_IO;
  1429.  
  1430.    package Real_Time_IO is new Float_IO (Real_Time);
  1431.    use Real_Time_IO;
  1432.  
  1433.    package Int_IO is new Integer_IO (Integer);
  1434.    use Int_IO;
  1435.  
  1436.    I, J, K, K1, Calls: Integer;
  1437.  
  1438.    function Ackermann (M, N: Natural)  return Natural is
  1439.    begin
  1440.      if M = 0     then
  1441.        return N + 1;
  1442.      elsif N = 0  then
  1443.        return Ackermann (M - 1, 1);
  1444.      else
  1445.        return Ackermann (M - 1, Ackermann (M, N -1 ));
  1446.      end if;
  1447.    end Ackermann;
  1448.  
  1449. begin
  1450.   K := 16;
  1451.   K1 := 1;
  1452.   I := 1;
  1453.  
  1454.   while K1 < Integer'Last / 512  loop
  1455.   
  1456.     Start_Time := Clock;
  1457.     J :=  Ackermann (3, I);
  1458.     Elapsed_Time :=  Clock - Start_Time;
  1459.     
  1460.     if J /= K - 3  then
  1461.       Put_line (" *** Wrong Value ***");
  1462.     end if;
  1463.     
  1464.     Calls := (512*K1 - 15*K + 9*I + 37) / 3;
  1465.  
  1466.     Put ("Number of Calls = ");
  1467.     Put (Calls, Width => 0);
  1468.     new_line;
  1469.     Put ("Elapsed Time    = ");
  1470.     Put (Elapsed_Time, Fore => 0);
  1471.     Put (" seconds   -- precision is ");
  1472.     if (Elapsed_Time < 100 * Duration'Small  or
  1473.         Elapsed_Time < 100 * System.Tick)  then
  1474.       Put_line ("Insignificant");
  1475.     else
  1476.       Put_line ("Significant");
  1477.     end if;
  1478.  
  1479.     Average_Time := Real_Time (Elapsed_Time) / Real_Time (Calls);
  1480.     Put ("Average Time per call = ");
  1481.     Put (Average_Time, Fore => 0);
  1482.     Put_Line (" seconds");
  1483.     new_line;
  1484.     
  1485.     I  := I + 1;
  1486.     K1 := 4 * K1;
  1487.     K  := 2 * K;
  1488.   end loop;
  1489.  
  1490.   Put_Line (" End of Ackermann Test");
  1491. exception
  1492.   when Storage_Error =>
  1493.     New_line;
  1494.     Put ("Stack space exceeded for Ackermann ( 3, " );
  1495.     Put (I);
  1496.     Put_line ( ")" );
  1497.     new_line;
  1498.     Put_Line (" End of Ackermann Test");
  1499. end Time_Ackermann;
  1500. ::::::::::
  1501. BOOLVEC.ADA
  1502. ::::::::::
  1503. -------------------------------------------------------------------
  1504. ---------------------  Next  Program  -----------------------------
  1505. -------------------------------------------------------------------
  1506. --
  1507. -- Version: @(#)boolvec.ada    1.4        Date: 6/17/85
  1508. --
  1509. -- Author:  Edward Colbert
  1510. --        Ada Technology Group
  1511. --        Information Software Systems Lab
  1512. --        Defense Systems Group
  1513. --        TRW
  1514. --        Redondo Beach, CA
  1515. --
  1516. -- This program measures the time required for the "and" operation on the
  1517. -- elements of a boolean vector
  1518. --
  1519. -- Note:  In order for the measurement to be meaningful, it must be the 
  1520. -- only program executing while the test is run.  
  1521. --
  1522. -- Please set Iterations large enough to provide at least two significant 
  1523. -- digits in the average times, i.e., the difference between 
  1524. -- the elapsed time and the loop time must be at least 100 times 
  1525. -- Duration'Small & at least 100 times System.Tick.
  1526. --
  1527.  
  1528. with Text_IO; use Text_IO;
  1529. with Calendar; use Calendar;
  1530. with System; use System;
  1531. procedure Boolean_Vector_AND_Test is
  1532.  
  1533.    Iterations : constant Positive := 1000;
  1534.  
  1535.    type Real_Time is digits Max_Digits;
  1536.  
  1537.    Start_Time : Time;
  1538.    Loop_Time : Duration;
  1539.    Elapsed_Time : Duration;
  1540.    Average_Time : Real_Time;
  1541.  
  1542.    package Duration_IO is new Fixed_IO (Duration);
  1543.    use Duration_IO;
  1544.  
  1545.    package Real_Time_IO is new Float_IO (Real_Time);
  1546.    use Real_Time_IO;
  1547.  
  1548.    package Int_IO is new Integer_IO (Integer);
  1549.    use Int_IO;
  1550.  
  1551.    Vector_Size : constant Positive := 25;
  1552.    type vector is array (1..Vector_Size) of Boolean;
  1553.    
  1554.    v1, v2, vector_result: vector;
  1555.    count:  integer := integer'first;    -- used in timing loop
  1556.  
  1557. begin
  1558.  
  1559.    -- Initialize Vectors
  1560.    for N in vector'range loop
  1561.       v1(N) := true;
  1562.       v2(N) := boolean'val (N mod 2);
  1563.    end loop;
  1564.  
  1565.    -- Measure the timing loop overhead.
  1566.    Start_Time := Clock;
  1567.    for N in 1 .. Iterations loop
  1568.       count := count + 1;        -- prevent optimization
  1569.    end loop;
  1570.    Loop_Time := Clock - Start_Time;
  1571.  
  1572.  
  1573.    -- Measure the time including the adding of vector elements
  1574.    Start_Time := Clock;
  1575.    for N in 1 .. Iterations loop
  1576.       count := count + 1;        -- prevent optimization
  1577.       vector_result := v1 and v2;
  1578.    end loop;
  1579.    Elapsed_Time := Clock - Start_Time;
  1580.  
  1581.  
  1582.    Put("Loop time = ");
  1583.    Put(Loop_Time, Fore => 0);
  1584.    Put(" seconds for ");
  1585.    Put(Vector_Size, Width => 0);
  1586.    Put_Line(" iterations");
  1587.  
  1588.  
  1589.    Put("Elapsed time = ");
  1590.    Put(Elapsed_Time, Fore => 0);
  1591.    Put(" seconds for ");
  1592.    Put(Vector_Size, Width => 0);
  1593.    Put_Line(" iterations");
  1594.  
  1595.    Average_Time := Real_Time(Elapsed_Time - Loop_Time)/Real_Time(Iterations);
  1596.    Put("Average time for " & '"' & "and" & '"' &
  1597.        " of 2 arrays (" & Integer'Image (Vector_Size) & " elements) = ");
  1598.    Put(Average_Time, Fore => 0);
  1599.    Put_Line(" seconds");
  1600.  
  1601.    New_Line;
  1602.    if (Elapsed_Time - Loop_Time < 100 * Duration'Small or
  1603.        Elapsed_Time - Loop_Time < 100 * System.Tick)    then
  1604.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  1605.    else
  1606.       Put_Line("** TEST PASSED **");
  1607.    end if;
  1608.  
  1609. end Boolean_Vector_AND_Test;
  1610. ::::::::::
  1611. BSEARCH.ADA
  1612. ::::::::::
  1613. -------------------------------------------------------------------
  1614. ---------------------  Next  Program  -----------------------------
  1615. -------------------------------------------------------------------
  1616.  
  1617.  
  1618. --
  1619. -- Version: @(#)bsearch.ada    1.1     Date: 5/30/84
  1620. --
  1621. -- Authors:  Marion Moon and Bryce Bardin
  1622. --           Software Engineering Division
  1623. --           Ground Systems Group
  1624. --           Hughes Aircraft Company
  1625. --           Fullerton, CA
  1626. --
  1627. -- This package implements a generic binary search function.
  1628. -- It was designed to allow the use of an enumeration type for the table 
  1629. -- index (a feature of possibly dubious utility, but included here for 
  1630. -- uniformity with other generic operations on unconstrained arrays).
  1631. --
  1632.  
  1633. generic
  1634.  
  1635.    type Index is (<>);
  1636.    type Item is limited private;
  1637.    type Table is array (Index range <>) of Item;
  1638.  
  1639.    with function "=" (Left, Right : Item) return Boolean is <>;
  1640.    with function ">" (Left, Right : Item) return Boolean is <>;
  1641.  
  1642. package Searching is
  1643.  
  1644.    function Index_Of (Key : in Item; Within : in Table) return Index;
  1645.    -- Returns the Index of the Item in Within which matches Key 
  1646.    -- if there is one, otherwise raises Not_Found.
  1647.  
  1648.    Not_Found : exception;
  1649.    -- Raised if the search fails.
  1650.  
  1651. end Searching;
  1652.  
  1653.  
  1654. package body Searching is
  1655.  
  1656.    function Index_Of (Key : in Item; Within : in Table) return Index is
  1657.  
  1658.       Low : Index := Within'First;
  1659.       Mid : Index;
  1660.       Hi  : Index := Within'Last;
  1661.  
  1662.    begin
  1663.  
  1664.       loop
  1665.  
  1666.      if Low > Hi then
  1667.         raise Not_Found;
  1668.      end if;
  1669.  
  1670.      -- Calculate the mean Index value, using an expression
  1671.      -- which can never overflow:
  1672.      Mid := Index'Val(Index'Pos(Low)/2 + Index'Pos(Hi)/2 + 
  1673.         (Index'Pos(Low) rem 2 + Index'Pos(Hi) rem 2)/2);
  1674.  
  1675.      if Within(Mid) = Key then
  1676.  
  1677.         return Mid;
  1678.  
  1679.      elsif Within(Mid) > Key then
  1680.  
  1681.         -- This can raise Constraint_Error, but in that case 
  1682.         -- the search has failed:
  1683.         Hi := Index'Pred(Mid);
  1684.  
  1685.      else
  1686.  
  1687.         -- This can raise Constraint_Error, but in that case 
  1688.         -- the search has failed:
  1689.         Low := Index'Succ(Mid);
  1690.  
  1691.      end if;
  1692.  
  1693.       end loop;
  1694.  
  1695.    exception
  1696.  
  1697.       when Constraint_Error =>
  1698.      raise Not_Found;
  1699.  
  1700.    end Index_Of;
  1701.  
  1702. end Searching;
  1703.  
  1704.  
  1705. -- This procedure tests the binary search package at the extreme limits 
  1706. -- of its index type.
  1707. with Searching;
  1708. with System; use System;
  1709. with Text_IO; use Text_IO;
  1710. procedure Main is
  1711.  
  1712.    type Big_Integer is range Min_Int .. Max_Int;
  1713.    type Table is array (Big_Integer range <>) of Character;
  1714.  
  1715.    package Table_Search is 
  1716.       new Searching (Big_Integer, Character, Table);
  1717.    use Table_Search;
  1718.  
  1719.    T1 : constant Table (Big_Integer'First .. Big_Integer'First + 2) := "XYZ";
  1720.    T2 : constant Table (Big_Integer'Last - 3 .. Big_Integer'Last) := "ABCD";
  1721.  
  1722.    Index : Big_Integer;
  1723.    Key : Character;
  1724.    subtype Alpha is Character range 'A' .. 'Z';
  1725.  
  1726.    package Big_IO is new Integer_IO (Big_Integer);
  1727.    use Big_IO;
  1728.  
  1729.    procedure Put_Match (Index : Big_Integer; Key : Character) is
  1730.    begin
  1731.       Put("The index for the key value of '" & Key & "' is ");
  1732.       Put(Index, Width => 0);
  1733.       Put('.');
  1734.       New_Line;
  1735.    end Put_Match;
  1736.  
  1737. begin
  1738.  
  1739.    begin
  1740.       for C in reverse Alpha loop
  1741.      Key := C;
  1742.      Index := Index_Of (Key, Within => T1);
  1743.      Put_Match(Index, Key);
  1744.       end loop;
  1745.    exception
  1746.       when Not_Found =>
  1747.      Put("Key '");
  1748.      Put(Key);
  1749.      Put_Line("' not found.");
  1750.    end;
  1751.  
  1752.    begin
  1753.       for C in Alpha loop
  1754.      Key := C;
  1755.      Index := Index_Of (Key, Within => T2);
  1756.      Put_Match(Index, Key);
  1757.       end loop;
  1758.    exception
  1759.       when Not_Found =>
  1760.      Put("Key '");
  1761.      Put(Key);
  1762.      Put_Line("' not found.");
  1763.    end;
  1764.  
  1765. end Main;
  1766. ::::::::::
  1767. CAUCHFL.ADA
  1768. ::::::::::
  1769. -------------------------------------------------------------------
  1770. ---------------------  Next  Program  -----------------------------
  1771. -------------------------------------------------------------------
  1772.  
  1773. --
  1774. -- Version: @(#)cauchfl.ada    1.1        Date: 6/3/84
  1775. --
  1776.  
  1777. with text_io; use text_io;
  1778. procedure cauchy is
  1779. --
  1780. --  This test of floating point accuracy based on computing the inverses
  1781. --  of Cauchy matricies.  These are N x N matricies for which the i, jth
  1782. --  entry is 1 / (i + j - 1).  The inverse is computed using determinants.
  1783. --  As N increases, the determinant rapidly approaches zero.  The inverse 
  1784. --  is computed exactly and then checked by multiplying it by the original
  1785. --  matrix.
  1786. --
  1787. --     Gerry Fisher
  1788. --     Computer Sciences Corporation
  1789. --     May 27, 1984
  1790.  
  1791.   type REAL is digits 6;
  1792.  
  1793.   type MATRIX is array(POSITIVE range <>, POSITIVE range <>) of REAL;
  1794.  
  1795.   trials : constant := 5;
  1796.   FAILED : Boolean  := FALSE;
  1797.  
  1798.   function cofactor(A : MATRIX; i, j : POSITIVE) return MATRIX is
  1799.     B : MATRIX(A'FIRST(1) .. A'LAST(1) - 1, A'FIRST(2) .. A'LAST(2) - 1);
  1800.     x : REAL;
  1801.   begin
  1802.     for p in A'RANGE(1) loop
  1803.       for q in A'RANGE(2) loop
  1804.     x := A(p, q);
  1805.     if    p < i and then q < j then
  1806.       B(p, q) := x;
  1807.     elsif p < i and then q > j then
  1808.       B(p, q - 1) := x;
  1809.     elsif p > i and then q < j then
  1810.       B(p - 1, q) := x;
  1811.     elsif p > i and then q > j then
  1812.       B(p - 1, q - 1) := x;
  1813.     end if;
  1814.       end loop;
  1815.     end loop;
  1816.     return B;
  1817.   end cofactor;
  1818.  
  1819.   function det(A : MATRIX) return REAL is
  1820.     D : REAL;
  1821.     k : INTEGER;
  1822.   begin
  1823.     if A'LENGTH = 1 then
  1824.       D := A(A'FIRST(1), A'FIRST(2));
  1825.     else
  1826.       D := 0.0;
  1827.       k := 1;
  1828.       for j in A'RANGE(2) loop
  1829.     D := D + REAL(k) * A(A'FIRST(1), j) * det(cofactor(A, A'FIRST(1), j));
  1830.     k := - k;
  1831.       end loop;
  1832.     end if;
  1833.     return D;
  1834.   end det;
  1835.  
  1836.   function init(n : positive) return MATRIX is
  1837.     B : MATRIX(1 .. n, 1 .. n);
  1838.   begin
  1839.     for i in B'RANGE(1) loop
  1840.       for j in B'RANGE(2) loop
  1841.         B(i, j) := 1.0 / REAL(i + j - 1);
  1842.       end loop;
  1843.     end loop;
  1844.     return B;
  1845.   end init;
  1846.  
  1847.   function inverse(A : MATRIX) return MATRIX is
  1848.     B : MATRIX(A'RANGE(1), A'RANGE(2));
  1849.     D : REAL := det(A);
  1850.     E : REAL;
  1851.   begin
  1852.     if A'LENGTH = 1 then
  1853.       return (1 .. 1 => (1 .. 1 => 1.0 / D));
  1854.     end if;
  1855.     for i in B'RANGE(1) loop
  1856.       for j in B'RANGE(2) loop
  1857.     B(i, j) := REAL((-1) ** (i + j)) * (det(cofactor(A, i, j)) / D);
  1858.       end loop;
  1859.     end loop;
  1860.  
  1861.     -- Now check the inverse
  1862.  
  1863.     for i in A'RANGE loop
  1864.       for j in A'RANGE loop
  1865.     E := 0.0;
  1866.     for k in A'RANGE loop
  1867.       E := E + A(i, k) * B(k, j);
  1868.     end loop;
  1869.     if (i  = j and then E /= 1.0) or else
  1870.        (i /= j and then E /= 0.0) then
  1871.       raise PROGRAM_ERROR;
  1872.     end if;
  1873.       end loop;
  1874.     end loop;
  1875.  
  1876.     return B;
  1877.   end inverse;
  1878.  
  1879.  
  1880. begin
  1881.   put_line("*** TEST Inversion of Cauchy Matricies.");
  1882.  
  1883.   for N in 1 .. trials loop
  1884.   begin
  1885.     declare
  1886.       A : constant MATRIX := init(N);
  1887.       B : constant MATRIX := inverse(A);
  1888.     begin
  1889.       put_line("*** REMARK: The Cauchy Matrix of size" & integer'image(N) &
  1890.                " successfully inverted.");
  1891.     end;
  1892.   exception
  1893.     when PROGRAM_ERROR => 
  1894.       put_line("*** REMARK: The Cauchy Matrix of size" & integer'image(N) &
  1895.                " not successfully inverted.");
  1896.     when NUMERIC_ERROR =>
  1897.       put_line("*** REMARK: The Cauchy Matrix of size" & integer'image(N) &
  1898.                " appears singular.");
  1899.     when others =>
  1900.       put_line("*** REMARK: Unexpected exception raised.");
  1901.       raise;
  1902.   end;
  1903.   end loop;
  1904.  
  1905.   put_line("*** FINISHED Matrix Inversion Test.");
  1906.  
  1907. end cauchy;
  1908. ::::::::::
  1909. CAUCHFX.ADA
  1910. ::::::::::
  1911. -------------------------------------------------------------------
  1912. ---------------------  Next  Program  -----------------------------
  1913. -------------------------------------------------------------------
  1914.  
  1915. --
  1916. -- Version: @(#)cauchfx.ada    1.1        Date: 6/3/84
  1917. --
  1918.  
  1919. with text_io; use text_io;
  1920. procedure cauchy is
  1921. --
  1922. --  This test of fixed point accuracy based on computing the inverses
  1923. --  of Cauchy matricies.  These are N x N matricies for which the i, jth
  1924. --  entry is 1 / (i + j - 1).  The inverse is computed using determinants.
  1925. --  As N increases, the determinant rapidly approaches zero.  The inverse 
  1926. --  is computed exactly and then checked by multiplying it by the original
  1927. --  matrix.
  1928. --
  1929. --     Gerry Fisher
  1930. --     Computer Sciences Corporation
  1931. --     May 27, 1984
  1932.  
  1933.   type FIXED is delta 2.0**(-16) range -1000.0 .. +1000.00;
  1934.  
  1935.   type MATRIX is array(POSITIVE range <>, POSITIVE range <>) of FIXED;
  1936.  
  1937.   trials : constant := 5;
  1938.   FAILED : Boolean  := FALSE;
  1939.  
  1940.   function cofactor(A : MATRIX; i, j : POSITIVE) return MATRIX is
  1941.     B : MATRIX(A'FIRST(1) .. A'LAST(1) - 1, A'FIRST(2) .. A'LAST(2) - 1);
  1942.     x : FIXED;
  1943.   begin
  1944.     for p in A'RANGE(1) loop
  1945.       for q in A'RANGE(2) loop
  1946.     x := A(p, q);
  1947.     if    p < i and then q < j then
  1948.       B(p, q) := x;
  1949.     elsif p < i and then q > j then
  1950.       B(p, q - 1) := x;
  1951.     elsif p > i and then q < j then
  1952.       B(p - 1, q) := x;
  1953.     elsif p > i and then q > j then
  1954.       B(p - 1, q - 1) := x;
  1955.     end if;
  1956.       end loop;
  1957.     end loop;
  1958.     return B;
  1959.   end cofactor;
  1960.  
  1961.   function det(A : MATRIX) return FIXED is
  1962.     D : FIXED;
  1963.     k : INTEGER;
  1964.   begin
  1965.     if A'LENGTH = 1 then
  1966.       D := A(A'FIRST(1), A'FIRST(2));
  1967.     else
  1968.       D := 0.0;
  1969.       k := 1;
  1970.       for j in A'RANGE(2) loop
  1971.     D := D + k * FIXED(A(A'FIRST(1), j) * det(cofactor(A, A'FIRST(1), j)));
  1972.     k := - k;
  1973.       end loop;
  1974.     end if;
  1975.     return D;
  1976.   end det;
  1977.  
  1978.   function init(n : positive) return MATRIX is
  1979.     B : MATRIX(1 .. n, 1 .. n);
  1980.   begin
  1981.     for i in B'RANGE(1) loop
  1982.       for j in B'RANGE(2) loop
  1983.         B(i, j) := 1.0 / (i + j - 1);
  1984.       end loop;
  1985.     end loop;
  1986.     return B;
  1987.   end init;
  1988.  
  1989.   function inverse(A : MATRIX) return MATRIX is
  1990.     B : MATRIX(A'RANGE(1), A'RANGE(2));
  1991.     D : FIXED := det(A);
  1992.     E : FIXED;
  1993.   begin
  1994.     if A'LENGTH = 1 then
  1995.       return (1 .. 1 => (1 .. 1 => FIXED(FIXED(1.0) / D)));
  1996.     end if;
  1997.     for i in B'RANGE(1) loop
  1998.       for j in B'RANGE(2) loop
  1999.     B(i, j) := ((-1) ** (i + j)) * FIXED(det(cofactor(A, i, j)) / D);
  2000.       end loop;
  2001.     end loop;
  2002.  
  2003.     -- Now check the inverse
  2004.  
  2005.     for i in A'RANGE loop
  2006.       for j in A'RANGE loop
  2007.     E := 0.0;
  2008.     for k in A'RANGE loop
  2009.       E := E + FIXED(A(i, k) * B(k, j));
  2010.     end loop;
  2011.     if (i  = j and then E /= 1.0) or else
  2012.        (i /= j and then E /= 0.0) then
  2013.       raise PROGRAM_ERROR;
  2014.     end if;
  2015.       end loop;
  2016.     end loop;
  2017.  
  2018.     return B;
  2019.   end inverse;
  2020.  
  2021.  
  2022. begin
  2023.   put_line("*** TEST Inversion of Cauchy Matricies.");
  2024.  
  2025.   for N in 1 .. trials loop
  2026.   begin
  2027.     declare
  2028.       A : constant MATRIX := init(N);
  2029.       B : constant MATRIX := inverse(A);
  2030.     begin
  2031.       put_line("*** REMARK: The Cauchy Matrix of size" & integer'image(N) &
  2032.                " successfully inverted.");
  2033.     end;
  2034.   exception
  2035.     when PROGRAM_ERROR => 
  2036.       put_line("*** REMARK: The Cauchy Matrix of size" & integer'image(N) &
  2037.                " not successfully inverted.");
  2038.     when NUMERIC_ERROR =>
  2039.       put_line("*** REMARK: The Cauchy Matrix of size" & integer'image(N) &
  2040.                " appears singular.");
  2041.     when others =>
  2042.       put_line("*** REMARK: Unexpected exception raised.");
  2043.       raise;
  2044.   end;
  2045.   end loop;
  2046.  
  2047.   put_line("*** FINISHED Matrix Inversion Test.");
  2048.  
  2049. end cauchy;
  2050. ::::::::::
  2051. CAUCHUN.ADA
  2052. ::::::::::
  2053. -------------------------------------------------------------------
  2054. ---------------------  Next  Program  -----------------------------
  2055. -------------------------------------------------------------------
  2056.  
  2057. --
  2058. -- Version: @(#)cauchun.ada    1.1        Date: 6/3/84
  2059. --
  2060.  
  2061. with universal_integer_arithmetic; use universal_integer_arithmetic;
  2062. with universal_real_arithmetic; use universal_real_arithmetic;
  2063. with text_io; use text_io;
  2064. procedure cauchy is
  2065. --
  2066. --  This test of the Universal Arithmetic Packages computes the inverses
  2067. --  of Cauchy matricies.  These are N x N matricies for which the i, jth
  2068. --  entry is 1 / (i + j - 1).  The inverse is computed using determinants.
  2069. --  As N increases, the determinant rapidly approaches zero.  The inverse 
  2070. --  is computed exactly and then checked by multiplying it by the original
  2071. --  matrix.
  2072. --
  2073. --     Gerry Fisher
  2074. --     Computer Sciences Corporation
  2075. --     May 27, 1984
  2076.  
  2077.   type MATRIX is array(POSITIVE range <>, POSITIVE range <>) of Universal_real;
  2078.  
  2079.   one    : Universal_integer := UI(1);
  2080.   r_one  : Universal_real    := UR(one, one);
  2081.   r_zero : Universal_real    := UR(UI(0), one);
  2082.  
  2083.   trials : constant := 10;
  2084.   FAILED : Boolean := FALSE;
  2085.  
  2086.   function cofactor(A : MATRIX; i, j : POSITIVE) return MATRIX is
  2087.     B : MATRIX(A'FIRST(1) .. A'LAST(1) - 1, A'FIRST(2) .. A'LAST(2) - 1);
  2088.     x : Universal_real;
  2089.   begin
  2090.     for p in A'RANGE(1) loop
  2091.       for q in A'RANGE(2) loop
  2092.     x := A(p, q);
  2093.     if    p < i and then q < j then
  2094.       B(p, q) := x;
  2095.     elsif p < i and then q > j then
  2096.       B(p, q - 1) := x;
  2097.     elsif p > i and then q < j then
  2098.       B(p - 1, q) := x;
  2099.     elsif p > i and then q > j then
  2100.       B(p - 1, q - 1) := x;
  2101.     end if;
  2102.       end loop;
  2103.     end loop;
  2104.     return B;
  2105.   end cofactor;
  2106.  
  2107.   function det(A : MATRIX) return Universal_real is
  2108.     D : Universal_real;
  2109.     k : INTEGER;
  2110.   begin
  2111.     if A'LENGTH = 1 then
  2112.       D := A(A'FIRST(1), A'FIRST(2));
  2113.     else
  2114.       D := r_zero;
  2115.       k := 1;
  2116.       for j in A'RANGE(2) loop
  2117.     D := D + UI(k) * A(A'FIRST(1), j) * det(cofactor(A, A'FIRST(1), j));
  2118.     k := - k;
  2119.       end loop;
  2120.     end if;
  2121.     return D;
  2122.   end det;
  2123.  
  2124.   function init(n : positive) return MATRIX is
  2125.     B : MATRIX(1 .. n, 1 .. n);
  2126.   begin
  2127.     for i in B'RANGE(1) loop
  2128.       for j in B'RANGE(2) loop
  2129.     B(i, j) := UR(one, UI(i + j - 1));
  2130.       end loop;
  2131.     end loop;
  2132.     return B;
  2133.   end init;
  2134.  
  2135.   function inverse(A : MATRIX) return MATRIX is
  2136.     B : MATRIX(A'RANGE(1), A'RANGE(2));
  2137.     D : Universal_real := det(A);
  2138.     E : Universal_real;
  2139.   begin
  2140.     if A'LENGTH = 1 then
  2141.       return (1 .. 1 => (1 .. 1 => r_one / D));
  2142.     end if;
  2143.     for i in B'RANGE(1) loop
  2144.       for j in B'RANGE(2) loop
  2145.     B(i, j) := UI((-1) ** (i + j)) * det(cofactor(A, i, j)) / D;
  2146.       end loop;
  2147.     end loop;
  2148.  
  2149.     -- Now check the inverse
  2150.  
  2151.     for i in A'RANGE loop
  2152.       for j in A'RANGE loop
  2153.     E := r_zero;
  2154.     for k in A'RANGE loop
  2155.       E := E + A(i, k) * B(k, j);
  2156.     end loop;
  2157.     if (i  = j and then not eql(E, r_one)) or else
  2158.        (i /= j and then not eql(E, r_zero)) then
  2159.       raise PROGRAM_ERROR;
  2160.     end if;
  2161.       end loop;
  2162.     end loop;
  2163.  
  2164.     return B;
  2165.   end inverse;
  2166.  
  2167.  
  2168. begin
  2169.   put_line("*** TEST Inversion of Cauchy Matricies.");
  2170.  
  2171.   for N in 1 .. trials loop
  2172.   begin
  2173.     declare
  2174.       A : constant MATRIX := init(N);
  2175.       B : constant MATRIX := inverse(A);
  2176.     begin
  2177.       put_line("*** REMARK: The Cauchy Matrix of size " & integer'image(N) &
  2178.                " successfully inverted.");
  2179.     end;
  2180.   exception
  2181.     when PROGRAM_ERROR => 
  2182.       put_line("*** FAILED: Matrix of size " & integer'image(N) &
  2183.                " not successfully inverted.");
  2184.       FAILED := True;
  2185.       exit;
  2186.   end;
  2187.   end loop;
  2188.  
  2189.   if not FAILED then
  2190.     put_line("*** PASSED Matrix Inversion Test.");
  2191.   end if;
  2192. end cauchy;
  2193. ::::::::::
  2194. CHAR_DIR.ADA
  2195. ::::::::::
  2196. -------------------------------------------------------------------
  2197. ---------------------  Next  Program  -----------------------------
  2198. -------------------------------------------------------------------
  2199.  
  2200. --
  2201. -- Version: @(#)char_dir.ada    1.2        Date: 9/21/84
  2202. --
  2203. -- Author:  Edward Colbert
  2204. --        Ada Technology Group
  2205. --        Information Software Systems Lab
  2206. --        Defense Systems Group
  2207. --        TRW
  2208. --        Redondo Beach, CA
  2209. --
  2210. -- This program measures the time required for doing various file
  2211. -- operations using the Direct_IO package with Characters.
  2212. --
  2213. -- Note:  In order for the measurement to be meaningful, it must be the 
  2214. -- only program executing while the test is run.  
  2215. --
  2216. -- Please set Times large enough to provide at least two significant 
  2217. -- digits in the average times, i.e., the difference between 
  2218. -- the elapsed time and the loop time must be at least 100 times 
  2219. -- Duration'Small & at least 100 times System.Tick.
  2220. --
  2221.  
  2222. with Text_IO; use Text_IO;
  2223. with Direct_IO;
  2224. with Calendar; use Calendar;
  2225. with System; use System;
  2226. procedure Character_Direct_IO_Test is
  2227.  
  2228.    Times : constant Positive := 1000;
  2229.  
  2230.    type Real_Time is digits Max_Digits;
  2231.  
  2232.    Start_Time : Time;
  2233.    Loop_Time : Duration;
  2234.    Average_Time : Real_Time;
  2235.    Create_Time : Duration;
  2236.    Close_Time  : Duration;
  2237.    Open_Time   : Duration;
  2238.    Delete_Time : Duration;
  2239.    Read_Time   : Duration;
  2240.    Write_Time  : Duration;
  2241.  
  2242.    package Duration_IO is new Fixed_IO (Duration);
  2243.    use Duration_IO;
  2244.  
  2245.    package Real_Time_IO is new Float_IO (Real_Time);
  2246.    use Real_Time_IO;
  2247.  
  2248.    package Int_IO is new Integer_IO (Integer);
  2249.    use Int_IO;
  2250.  
  2251.    package Char_IO is new Direct_IO (Character);
  2252.    use Char_IO;
  2253.  
  2254.    file:   Char_IO.file_type;
  2255.    value:  character := 'A';
  2256.    count:  integer := integer'first;    -- used in timing loop
  2257.  
  2258. begin
  2259.  
  2260.    -- Measure the timing loop overhead.
  2261.    Start_Time := Clock;
  2262.    for N in 1 .. Times loop
  2263.       count := count + 1;        -- prevent optimization
  2264.    end loop;
  2265.    Loop_Time := Clock - Start_Time;
  2266.  
  2267.  
  2268.    -- Create a file
  2269.    Start_Time := Clock;
  2270.    Char_IO.Create (file, mode => out_file, name => "test_file");
  2271.    Create_Time := Clock - Start_Time;
  2272.  
  2273.    -- Measure the time of Writing of value
  2274.    Start_Time := Clock;
  2275.    for N in 1 .. Times loop
  2276.       count := count + 1;
  2277.       Char_IO.write (file, value);
  2278.    end loop;
  2279.    Write_Time := Clock - Start_Time;
  2280.  
  2281.    -- Close a file
  2282.    Start_Time := Clock;
  2283.    Char_IO.Close (file);
  2284.    Close_Time := Clock - Start_Time;
  2285.  
  2286.    -- Open a file
  2287.    Start_Time := Clock;
  2288.    Char_IO.Open (file, mode => in_file, name => "test_file");
  2289.    Open_Time := Clock - Start_Time;
  2290.  
  2291.    -- Measure the time of Reading of value
  2292.    Start_Time := Clock;
  2293.    for N in 1 .. Times loop
  2294.       count := count + 1;
  2295.       Char_IO.read (file, value);
  2296.    end loop;
  2297.    Read_Time := Clock - Start_Time;
  2298.  
  2299.    -- Delete a file
  2300.    Start_Time := Clock;
  2301.    Char_IO.Delete (file);
  2302.    Delete_Time := Clock - Start_Time;
  2303.  
  2304.  
  2305.    Put ("Create File Time = ");
  2306.    Put (Create_Time, Fore => 0);
  2307.    put_line (" seconds ");
  2308.  
  2309.    Put ("Close File Time = ");
  2310.    Put (Close_Time, Fore => 0);
  2311.    put_line (" seconds ");
  2312.  
  2313.    Put ("Open File Time = ");
  2314.    Put (Open_Time, Fore => 0);
  2315.    put_line (" seconds ");
  2316.  
  2317.    Put ("Delete File Time = ");
  2318.    Put (Delete_Time, Fore => 0);
  2319.    put_line (" seconds ");
  2320.  
  2321.    Put("Loop time = ");
  2322.    Put(Loop_Time, Fore => 0);
  2323.    Put(" seconds for ");
  2324.    Put(Times, Width => 0);
  2325.    Put_Line(" iterations");
  2326.  
  2327.  
  2328.    Put("Elapsed time = ");
  2329.    Put(Write_Time, Fore => 0);
  2330.    Put(" seconds for ");
  2331.    Put(Times, Width => 0);
  2332.    Put_Line(" Writes");
  2333.  
  2334.    Average_Time := Real_Time(Write_Time - Loop_Time)/Real_Time(Times);
  2335.    Put("Average time for a Write = ");
  2336.    Put(Average_Time, Fore => 0);
  2337.    Put_Line(" seconds");
  2338.  
  2339.    New_Line;
  2340.  
  2341.  
  2342.  
  2343.    Put("Elapsed time = ");
  2344.    Put(Read_Time, Fore => 0);
  2345.    Put(" seconds for ");
  2346.    Put(Times, Width => 0);
  2347.    Put_Line(" Reads");
  2348.  
  2349.    Average_Time := Real_Time(Read_Time - Loop_Time)/Real_Time(Times);
  2350.    Put("Average time for a Read = ");
  2351.    Put(Average_Time, Fore => 0);
  2352.    Put_Line(" seconds");
  2353.  
  2354.    New_Line;
  2355.  
  2356.    if (Read_Time  - Loop_Time < 100 * Duration'Small)    or
  2357.       (Read_Time  - Loop_Time < 100 * System.Tick)    or
  2358.       (Write_Time - Loop_Time < 100 * Duration'Small)    or
  2359.       (Write_Time - Loop_Time < 100 * System.Tick)    then
  2360.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  2361.    else
  2362.       Put_Line("** TEST PASSED **");
  2363.    end if;
  2364.  
  2365. end Character_Direct_IO_Test;
  2366. ::::::::::
  2367. CHAR_ENM.ADA
  2368. ::::::::::
  2369. -------------------------------------------------------------------
  2370. ---------------------  Next  Program  -----------------------------
  2371. -------------------------------------------------------------------
  2372.  
  2373. --
  2374. -- Version: @(#)char_enm.ada    1.2        Date: 9/21/84
  2375. --
  2376. -- Author:  Edward Colbert
  2377. --        Ada Technology Group
  2378. --        Information Software Systems Lab
  2379. --        Defense Systems Group
  2380. --        TRW
  2381. --        Redondo Beach, CA
  2382. --
  2383. -- This program measures the time required for doing various file
  2384. -- operations using the Text_IO package & the Enumeration_IO subpackage
  2385. -- with Characters.
  2386. --
  2387. -- Note:  In order for the measurement to be meaningful, it must be the 
  2388. -- only program executing while the test is run.  
  2389. --
  2390. -- Please set Times large enough to provide at least two significant 
  2391. -- digits in the average times, i.e., the difference between 
  2392. -- the elapsed time and the loop time must be at least 100 times 
  2393. -- Duration'Small & at least 100 times System.Tick.
  2394. --
  2395.  
  2396. with Text_IO; use Text_IO;
  2397. with Calendar; use Calendar;
  2398. with System; use System;
  2399. procedure Character_Enumeration_IO_Test is
  2400.  
  2401.    Times : constant Positive := 1000;
  2402.  
  2403.    type Real_Time is digits Max_Digits;
  2404.  
  2405.    Start_Time : Time;
  2406.    Loop_Time : Duration;
  2407.    Average_Time : Real_Time;
  2408.    Create_Time : Duration;
  2409.    Close_Time  : Duration;
  2410.    Open_Time   : Duration;
  2411.    Delete_Time : Duration;
  2412.    Read_Time   : Duration;
  2413.    Write_Time  : Duration;
  2414.  
  2415.    package Duration_IO is new Fixed_IO (Duration);
  2416.    use Duration_IO;
  2417.  
  2418.    package Real_Time_IO is new Float_IO (Real_Time);
  2419.    use Real_Time_IO;
  2420.  
  2421.    package Int_IO is new Integer_IO (Integer);
  2422.    use Int_IO;
  2423.  
  2424.    package Char_IO is new Enumeration_IO (Character);
  2425.  
  2426.  
  2427.    file:   Text_IO.file_type;
  2428.    value:  character := 'A';
  2429.    count:  integer := integer'first;    -- used in timing loop
  2430.  
  2431. begin
  2432.  
  2433.    -- Measure the timing loop overhead.
  2434.    Start_Time := Clock;
  2435.    for N in 1 .. Times loop
  2436.       count := count + 1;        -- prevent optimization
  2437.    end loop;
  2438.    Loop_Time := Clock - Start_Time;
  2439.  
  2440.  
  2441.    -- Create a file
  2442.    Start_Time := Clock;
  2443.    Text_IO.Create (file, mode => out_file, name => "test_file");
  2444.    Create_Time := Clock - Start_Time;
  2445.  
  2446.    -- Measure the time of Writing of value
  2447.    Start_Time := Clock;
  2448.    for N in 1 .. Times loop
  2449.       count := count + 1;
  2450.       Char_IO.put (file, value);
  2451.    end loop;
  2452.    Write_Time := Clock - Start_Time;
  2453.  
  2454.    -- Close a file
  2455.    Start_Time := Clock;
  2456.    Text_IO.Close (file);
  2457.    Close_Time := Clock - Start_Time;
  2458.  
  2459.    -- Open a file
  2460.    Start_Time := Clock;
  2461.    Text_IO.Open (file, mode => in_file, name => "test_file");
  2462.    Open_Time := Clock - Start_Time;
  2463.  
  2464.    -- Measure the time of Reading of value
  2465.    Start_Time := Clock;
  2466.    for N in 1 .. Times loop
  2467.       count := count + 1;
  2468.       Char_IO.get (file, value);
  2469.    end loop;
  2470.    Read_Time := Clock - Start_Time;
  2471.  
  2472.    -- Delete a file
  2473.    Start_Time := Clock;
  2474.    Text_IO.Delete (file);
  2475.    Delete_Time := Clock - Start_Time;
  2476.  
  2477.  
  2478.    Put ("Create File Time = ");
  2479.    Put (Create_Time, Fore => 0);
  2480.    put_line (" seconds ");
  2481.  
  2482.    Put ("Close File Time = ");
  2483.    Put (Close_Time, Fore => 0);
  2484.    put_line (" seconds ");
  2485.  
  2486.    Put ("Open File Time = ");
  2487.    Put (Open_Time, Fore => 0);
  2488.    put_line (" seconds ");
  2489.  
  2490.    Put ("Delete File Time = ");
  2491.    Put (Delete_Time, Fore => 0);
  2492.    put_line (" seconds ");
  2493.  
  2494.    Put("Loop time = ");
  2495.    Put(Loop_Time, Fore => 0);
  2496.    Put(" seconds for ");
  2497.    Put(Times, Width => 0);
  2498.    Put_Line(" iterations");
  2499.  
  2500.  
  2501.    Put("Elapsed time = ");
  2502.    Put(Write_Time, Fore => 0);
  2503.    Put(" seconds for ");
  2504.    Put(Times, Width => 0);
  2505.    Put_Line(" Writes");
  2506.  
  2507.    Average_Time := Real_Time(Write_Time - Loop_Time)/Real_Time(Times);
  2508.    Put("Average time for a Write = ");
  2509.    Put(Average_Time, Fore => 0);
  2510.    Put_Line(" seconds");
  2511.  
  2512.    New_Line;
  2513.  
  2514.  
  2515.  
  2516.    Put("Elapsed time = ");
  2517.    Put(Read_Time, Fore => 0);
  2518.    Put(" seconds for ");
  2519.    Put(Times, Width => 0);
  2520.    Put_Line(" Reads");
  2521.  
  2522.    Average_Time := Real_Time(Read_Time - Loop_Time)/Real_Time(Times);
  2523.    Put("Average time for a Read = ");
  2524.    Put(Average_Time, Fore => 0);
  2525.    Put_Line(" seconds");
  2526.  
  2527.    New_Line;
  2528.  
  2529.    if (Read_Time  - Loop_Time < 100 * Duration'Small)    or
  2530.       (Read_Time  - Loop_Time < 100 * System.Tick)    or
  2531.       (Write_Time - Loop_Time < 100 * Duration'Small)    or
  2532.       (Write_Time - Loop_Time < 100 * System.Tick)    then
  2533.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  2534.    else
  2535.       Put_Line("** TEST PASSED **");
  2536.    end if;
  2537.  
  2538. end Character_Enumeration_IO_Test;
  2539. ::::::::::
  2540. CHAR_TXT.ADA
  2541. ::::::::::
  2542. -------------------------------------------------------------------
  2543. ---------------------  Next  Program  -----------------------------
  2544. -------------------------------------------------------------------
  2545.  
  2546. --
  2547. -- Version: @(#)char_txt.ada    1.3        Date: 9/21/84
  2548. --
  2549. -- Author:  Edward Colbert
  2550. --        Ada Technology Group
  2551. --        Information Software Systems Lab
  2552. --        Defense Systems Group
  2553. --        TRW
  2554. --        Redondo Beach, CA
  2555. --
  2556. -- This program measures the time required for doing various file
  2557. -- operations using the Text_IO package with Characters.
  2558. --
  2559. -- Note:  In order for the measurement to be meaningful, it must be the 
  2560. -- only program executing while the test is run.  
  2561. --
  2562. -- Please set Times large enough to provide at least two significant 
  2563. -- digits in the average times, i.e., the difference between 
  2564. -- the elapsed time and the loop time must be at least 100 times 
  2565. -- Duration'Small & at least 100 times System.Tick.
  2566. --
  2567.  
  2568. with Text_IO; use Text_IO;
  2569. with Calendar; use Calendar;
  2570. with System; use System;
  2571. procedure Character_Text_IO_Test is
  2572.  
  2573.    Times : constant Positive := 1000;
  2574.  
  2575.    type Real_Time is digits Max_Digits;
  2576.  
  2577.    Start_Time : Time;
  2578.    Loop_Time : Duration;
  2579.    Average_Time : Real_Time;
  2580.    Create_Time : Duration;
  2581.    Close_Time  : Duration;
  2582.    Open_Time   : Duration;
  2583.    Delete_Time : Duration;
  2584.    Read_Time   : Duration;
  2585.    Write_Time  : Duration;
  2586.  
  2587.    package Duration_IO is new Fixed_IO (Duration);
  2588.    use Duration_IO;
  2589.  
  2590.    package Real_Time_IO is new Float_IO (Real_Time);
  2591.    use Real_Time_IO;
  2592.  
  2593.    package Int_IO is new Integer_IO (Integer);
  2594.    use Int_IO;
  2595.  
  2596.    file:   Text_IO.file_type;
  2597.    value:  character := 'A';
  2598.    count:  integer := integer'first;    -- used in timing loop
  2599.  
  2600. begin
  2601.  
  2602.    -- Measure the timing loop overhead.
  2603.    Start_Time := Clock;
  2604.    for N in 1 .. Times loop
  2605.       count := count + 1;        -- prevent optimization
  2606.    end loop;
  2607.    Loop_Time := Clock - Start_Time;
  2608.  
  2609.  
  2610.    -- Create a file
  2611.    Start_Time := Clock;
  2612.    Text_IO.Create (file, mode => out_file, name => "test_file");
  2613.    Create_Time := Clock - Start_Time;
  2614.  
  2615.    -- Measure the time of Writing of value
  2616.    Start_Time := Clock;
  2617.    for N in 1 .. Times loop
  2618.       count := count + 1;
  2619.       Text_IO.put (file, value);
  2620.    end loop;
  2621.    Write_Time := Clock - Start_Time;
  2622.  
  2623.    -- Close a file
  2624.    Start_Time := Clock;
  2625.    Text_IO.Close (file);
  2626.    Close_Time := Clock - Start_Time;
  2627.  
  2628.    -- Open a file
  2629.    Start_Time := Clock;
  2630.    Text_IO.Open (file, mode => in_file, name => "test_file");
  2631.    Open_Time := Clock - Start_Time;
  2632.  
  2633.    -- Measure the time of Reading of value
  2634.    Start_Time := Clock;
  2635.    for N in 1 .. Times loop
  2636.       count := count + 1;
  2637.       Text_IO.get (file, value);
  2638.    end loop;
  2639.    Read_Time := Clock - Start_Time;
  2640.  
  2641.    -- Delete a file
  2642.    Start_Time := Clock;
  2643.    Text_IO.Delete (file);
  2644.    Delete_Time := Clock - Start_Time;
  2645.  
  2646.  
  2647.    Put ("Create File Time = ");
  2648.    Put (Create_Time, Fore => 0);
  2649.    put_line (" seconds ");
  2650.  
  2651.    Put ("Close File Time = ");
  2652.    Put (Close_Time, Fore => 0);
  2653.    put_line (" seconds ");
  2654.  
  2655.    Put ("Open File Time = ");
  2656.    Put (Open_Time, Fore => 0);
  2657.    put_line (" seconds ");
  2658.  
  2659.    Put ("Delete File Time = ");
  2660.    Put (Delete_Time, Fore => 0);
  2661.    put_line (" seconds ");
  2662.  
  2663.    Put("Loop time = ");
  2664.    Put(Loop_Time, Fore => 0);
  2665.    Put(" seconds for ");
  2666.    Put(Times, Width => 0);
  2667.    Put_Line(" iterations");
  2668.  
  2669.  
  2670.    Put("Elapsed time = ");
  2671.    Put(Write_Time, Fore => 0);
  2672.    Put(" seconds for ");
  2673.    Put(Times, Width => 0);
  2674.    Put_Line(" Writes");
  2675.  
  2676.    Average_Time := Real_Time(Write_Time - Loop_Time)/Real_Time(Times);
  2677.    Put("Average time for a Write = ");
  2678.    Put(Average_Time, Fore => 0);
  2679.    Put_Line(" seconds");
  2680.  
  2681.    New_Line;
  2682.  
  2683.  
  2684.  
  2685.    Put("Elapsed time = ");
  2686.    Put(Read_Time, Fore => 0);
  2687.    Put(" seconds for ");
  2688.    Put(Times, Width => 0);
  2689.    Put_Line(" Reads");
  2690.  
  2691.    Average_Time := Real_Time(Read_Time - Loop_Time)/Real_Time(Times);
  2692.    Put("Average time for a Read = ");
  2693.    Put(Average_Time, Fore => 0);
  2694.    Put_Line(" seconds");
  2695.  
  2696.    New_Line;
  2697.  
  2698.    if (Read_Time  - Loop_Time < 100 * Duration'Small)    or
  2699.       (Read_Time  - Loop_Time < 100 * System.Tick)    or
  2700.       (Write_Time - Loop_Time < 100 * Duration'Small)    or
  2701.       (Write_Time - Loop_Time < 100 * System.Tick)    then
  2702.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  2703.    else
  2704.       Put_Line("** TEST PASSED **");
  2705.    end if;
  2706.  
  2707. end Character_Text_IO_Test;
  2708. ::::::::::
  2709. PHYSICS.ADA
  2710. ::::::::::
  2711. -------------------------------------------------------------------
  2712. ---------------------  Next  Program  -----------------------------
  2713. -------------------------------------------------------------------
  2714.  
  2715. --
  2716. -- Version: @(#)physics.ada    1.1    Date: 6/3/85
  2717. --
  2718. -- Supplied by:  John Squires
  2719. --               Westinghouse Electric Company
  2720. -- (except as noted)
  2721. --
  2722. -- Edited by:  Jim Alstad
  2723. --             Software Engineering Laboratories
  2724. --             Radar Systems Group
  2725. --             Hughes Aircraft Company
  2726. --             El Segundo CA USA
  2727. --
  2728. -- Series of compilation units to test real-world (i.e., heavy) use
  2729. -- of packages.  Can be compilation & link time benchmark.  The main
  2730. -- program (PHYSICS_1) should execute quickly.
  2731. --
  2732. -- Two units were written by Alstad; the rest are taken from
  2733. -- the tape distributed by Squires following the San Jose SIGAda meeting
  2734. -- (winter 85).  Necessary alterations by Alstad
  2735. -- are flagged "--Alstad".  The compilation units are as follows, where
  2736. -- a trailing underscore means a specification unit:
  2737. --
  2738. --      NthRoot_                              Alstad
  2739. --      NthRoot                               Alstad
  2740. --      PHYSICAL_REAL                         Squires
  2741. --      LONG_FLT_IO                           Squires
  2742. --      PHYSICAL_UNITS_BASIC                  Squires
  2743. --      PHYSICAL_UNITS_MECHANICAL             Squires
  2744. --      PHYSICAL_UNITS_ELECTRICAL             Squires
  2745. --      PHYSICAL_UNITS_OTHER                  Squires
  2746. --      PHYSICAL_UNITS_OUTPUT_BASIC_          Squires
  2747. --      PHYSICAL_UNITS_OUTPUT_BASIC           Squires
  2748. --      PHYSICAL_UNITS_OUTPUT_MECHANICAL_     Squires
  2749. --      PHYSICAL_UNITS_OUTPUT_MECHANICAL      Squires
  2750. --      MKS_PHYSICS_MECHANICAL_               Squires
  2751. --      MKS_PHYSICS_MECHANICAL                Squires
  2752. --      PHYSICS_1                             Squires
  2753. --
  2754. --------------------------------------------------------------------------------
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764. --------------------------------------------------------------------------------
  2765. --
  2766. -- Version:  NthRoot_.ada     1.0                 Date: 5/29/85
  2767. --
  2768. -- Author:  Jim Alstad
  2769. --          Software Engineering Laboratories
  2770. --          Radar Systems Group
  2771. --          Hughes Aircraft Company
  2772. --          El Segundo CA USA
  2773. --
  2774. -- Simple generic package to compute Nth roots.
  2775. --
  2776. -- Instantiating NthRoot with N, an integer >= 2,
  2777. -- and Arith-Type, a floating point type,
  2778. -- yields NthRoot.RootOf, a function which computes
  2779. -- the Nth root of its argument.
  2780. --
  2781. -- The result is an approximation, good to (at least) four digits.
  2782. -- For simplicity, RootOf (- X) = - RootOf (X), though N may be even.
  2783. -- Arith-Type is used for intermediate calculations.
  2784. --
  2785.           generic
  2786.      N:  integer;  -- N >= 2
  2787.      type Arith_Type is digits <>;
  2788.           package
  2789. NthRoot                      is
  2790.  
  2791.      function
  2792. RootOf (X: Arith_Type) return Arith_Type;
  2793.  
  2794. end NthRoot; --spec
  2795. --------------------------------------------------------------------------------
  2796.  
  2797.  
  2798.  
  2799.  
  2800.  
  2801.  
  2802.  
  2803.  
  2804.  
  2805. --------------------------------------------------------------------------------
  2806. --
  2807. -- Version: NthRoot.ada     1.0                         Date: 5/29/85
  2808. --
  2809. --
  2810. -- Author:  Jim Alstad
  2811. --          Software Engineering Laboratories
  2812. --          Radar Systems Group
  2813. --          Hughes Aircraft Company
  2814. --          El Segundo CA USA
  2815. --
  2816. -- Assisted by Nat Bachman (same affiliation).
  2817. --
  2818. -- Simple generic package to compute Nth roots.
  2819. --
  2820. -- The basic approach is to use Newton's method, which computes
  2821. -- successive approximations.  This may be summarized as follows.
  2822. -- Suppose a number X and a function F are given, and it is desired
  2823. -- to find a Y such that F(Y) = X.  Then Newton's method says that
  2824. -- a better approximation YNext may be found via
  2825. --      YNext = Y + (X - F(Y)) / F'(Y)     .
  2826. -- Taking F(Y) to be Y**N, Y to be RootPrev, and YNext to be Root yields
  2827. --      Root = ((X/RootPrev**(N-1)) + ((N-1)*RootPrev)) / N     ,
  2828. -- which is the formula used below.  Iteration continues until
  2829. -- Root and RootPrev differ by less than Tolerance.
  2830. --
  2831. -- Convergence is fairly fast once RootPrev gets close to the actual root.
  2832. -- To speed this up, X is "normalized" into XNorm, where 1 <= XNorm < 2**N.
  2833. -- This means that 1 <= RootOf(XNorm) < 2, so that 2.0 is used as
  2834. -- the initial approximation to RootOf(XNorm).  A side effect of this is
  2835. -- that the approximation to RootOf(XNorm) will never be less than
  2836. -- the actual root.
  2837. --
  2838. -- From a programming point of view, the main point of interest is
  2839. -- calculating XNorm (from XG1).  This involves dividing XNorm by values
  2840. -- Power(C).TwoN, while remembering corresponding values Power(C).Two
  2841. -- by which to multiply Root to compensate.  This algorithm can be
  2842. -- characterized as calculating the integer part of log(X), where
  2843. -- the log is base 2**N, by calculating the bits in its binary
  2844. -- representation from left to right (!).  The initialization of Power
  2845. -- is also interesting, as it uses an exception to terminate a loop
  2846. -- (no alternative seems as appropriate).
  2847. --
  2848. -- This routine is used as a vehicle to demonstrate Dijkstra's proof-
  2849. -- of-correctness technique, which is based on his "weakest precondition"
  2850. -- predicate transformer.  (This demonstration has not been carried
  2851. -- through 100%.)
  2852. --
  2853. -- The main consideration in designing this routine has been to achieve
  2854. -- reasonable accuracy and efficiency with broad applicability but
  2855. -- without an extended effort (i.e., it had to be interesting).
  2856. -- Consequently there are some rough edges.  Here is a partial list:
  2857. --  1.  There is no check for N < 2.
  2858. --  2.  Arith-Type'small <= abs (X) < 1 / MaxX causes numeric_error.
  2859. --
  2860. --
  2861.      package body
  2862. NthRoot          is
  2863.  
  2864.           -- - MaxX <= X <= MaxX
  2865.      MaxX:  constant Arith_Type := Arith_Type'large;
  2866.  
  2867.           -- (2**N) ** (2**(CBound + 1))  >  MaxX
  2868.      CBound:  constant := 10;
  2869.           subtype
  2870.      CIndex  is  integer range 0..CBound;
  2871.  
  2872.       -- Power assertion (after initialization):
  2873.       --     for all C in 0..CMax:
  2874.       --       RootOf(Power(C).TwoN) = Power(C).Two  &
  2875.       --       Power(C+1) = Power(C) ** 2            &
  2876.       --       Power(CMax+1).TwoN > MaxX             &
  2877.       --       Power(0).TwoN = 2**N
  2878.       -- (Power(CMax+1) is not actually computed.)
  2879.           type APower is record
  2880.            Two, TwoN:  Arith_Type;
  2881.            end record; --APower
  2882.      Power:  array (CIndex) of APower;
  2883.      CMax:  CIndex;
  2884.  
  2885.      function
  2886. RootOf (X: Arith_Type) return Arith_Type  is
  2887.  
  2888.      C:  CIndex;  -- C <= CMax
  2889.      -- Sign * (XG1 ** Inverter) = X
  2890.      Sign:  Arith_Type;  -- +1 or -1
  2891.      Inverter:  integer range -1..+1;  -- +1 or -1
  2892.      XG1:  Arith_Type;  -- 1 <= XG1 <= MaxX
  2893.      -- RootOf (XG1) = RootOf (XNorm) * Unnormalizer
  2894.      Unnormalizer:  Arith_Type;
  2895.      XNorm:  Arith_Type;  -- 1 <= XNorm < 2**N
  2896.      -- Root & RootPrev are approximations to RootOf (XNorm)
  2897.      Root, RootPrev:  Arith_Type;
  2898.      -- abs (RootOf (XNorm) - Root) <= Tolerance
  2899.      Tolerance:  constant := 1.0E-4;
  2900.  
  2901.   begin  -- body of RootOf
  2902.      if  X = 0.0
  2903.        then
  2904.       return (0.0);  -- 0 = RootOf (0)
  2905.        else
  2906.       --assert:  X /= 0
  2907.       if  X > 0.0
  2908.         then  Sign := +1.0;  XG1 := +X;
  2909.         else  Sign := -1.0;  XG1 := -X;
  2910.         end if;
  2911.       --assert:  Sign * XG1 = X  &  XG1 > 0  &  Sign = +1 or -1
  2912.       if  XG1 >= 1.0
  2913.         then  Inverter := +1;
  2914.         else  Inverter := -1;
  2915.         end if;
  2916.       XG1  :=  XG1 ** Inverter;
  2917.       --assert:  Sign * (XG1 ** Inverter) = X  &
  2918.       --         XG1 >= 1                      &
  2919.       --         Sign = +1 or -1               &
  2920.       --         Inverter = +1 or -1
  2921.       --assert:  RootOf (X) = RootOf (Sign * (XG1 ** Inverter))
  2922.       --                    = Sign * (RootOf (XG1) ** Inverter)
  2923.       --assert:  1 <= XG1 <= MaxX < (2**N) ** (2 ** (CMax + 1))
  2924.       XNorm := XG1;  Unnormalizer := 1.0;  C := CMax + 1;
  2925.       --invariant:  RootOf (XG1) = Unnormalizer * RootOf (XNorm)  &
  2926.       --            1 <= XNorm < (2**N) ** (2**C)
  2927.       --            (see also Power assertion)
  2928.       --bound:  C
  2929.       while  C /= 0  loop
  2930.            C  :=  C - 1;
  2931.            if  XNorm >= Power(C).TwoN
  2932.              then
  2933.             --assert:  RootOf (XNorm)
  2934.             --       = RootOf ((XNorm / Power(C).TwoN) * Power(C).TwoN)
  2935.             --       = RootOf (XNorm / Power(C).TwoN) * Power(C).Two
  2936.             --assert:  Power(C).TwoN <= XNorm < Power(C+1).TwoN
  2937.             --                                = Power(C).TwoN ** 2
  2938.             XNorm  :=  XNorm / Power(C).TwoN;
  2939.             --assert:  1 <= XNorm < Power(C).TwoN
  2940.             Unnormalizer  :=  Unnormalizer * Power(C).Two;
  2941.              end if;
  2942.            -- invariant has been reestablished
  2943.            end loop;
  2944.           --assert:  1 <= XNorm < Power(0).TwoN = 2**N
  2945.           --assert (incidentally):  1 <= RootOf (XNorm) < 2
  2946.  
  2947.       --invariant & bound:  supplied by Isaac Newton
  2948.       RootPrev  :=  2.0;
  2949.       loop
  2950.            Root  :=  (XNorm / (RootPrev ** (N - 1))
  2951.                       + Arith_Type (N - 1) * RootPrev )
  2952.                      / Arith_Type (N) ;
  2953.            exit when  abs (Root - RootPrev) <= Tolerance;
  2954.            RootPrev  :=  Root;
  2955.            end loop;
  2956.       --assert:  abs (Root - RootOf (XNorm) <= Tolerance)
  2957.       --         i.e., Root ~= RootOf (XNorm)
  2958.       return (Sign * ((Root * Unnormalizer) ** Inverter));
  2959.        end if;  -- X = 0.0?
  2960.      end RootOf;
  2961.  
  2962. begin  -- NthRoot body
  2963.  
  2964.      -- make Power assertion true (initialize Power)
  2965.  
  2966.      Power(0).Two  :=  2.0;  Power(0).TwoN  :=  2.0 ** N;
  2967.      
  2968.      CMax  :=  1;
  2969.      begin  -- to catch exceptions
  2970.      for C in CIndex loop  -- escape on exception
  2971.       --assert:  Power(C).TwoN < MaxX
  2972.       Power(C+1).TwoN  :=  Power(C).TwoN ** 2;  --may except
  2973.       Power(C+1).Two   :=  Power(C).Two  ** 2;
  2974.       CMax  :=  C + 1;
  2975.       end loop;
  2976.      -- should never fall out
  2977.      exception
  2978.      when numeric_error     -- on Power(C).TwoN ** 2 > MaxX
  2979.         | constraint_error  -- on C + 1 > CMax
  2980.         =>
  2981.       --assert:  Power(CMax).TwoN > MaxX
  2982.       null;  -- just leave block
  2983.      end;  -- exception block
  2984.      -- Power assertion is true
  2985.  
  2986.      end NthRoot;  -- body
  2987. --------------------------------------------------------------------------------
  2988.  
  2989.  
  2990.  
  2991.  
  2992.  
  2993.  
  2994.  
  2995.  
  2996.  
  2997. --------------------------------------------------------------------------------
  2998.  
  2999. -- The purpose of this package is to define an Ada type that has exactly
  3000. -- the operations that are valid for any physical quantity. This package
  3001. -- is then used by the packages that define many physical units. These
  3002. -- packages are used in turn by packages that define operators on physical
  3003. -- units that produce other physical units. Additional packages in this
  3004. -- set provide for outputting of physical units, conversions between
  3005. -- physical units, and other functions needed when working with physical
  3006. -- units.
  3007. --
  3008.  
  3009. package PHYSICAL_REAL is
  3010.  
  3011.   type REAL is private ;
  3012.  
  3013. --                Operators available for all types derived from REAL
  3014. --
  3015. --     implicit :    :=    =     /=
  3016. --
  3017. --
  3018. --             Physical quantities with the same units can be added
  3019. --             preserving their physical units.
  3020.  
  3021.   function "+" ( LEFT , RIGHT : REAL ) return REAL ;
  3022.  
  3023. --             Physical quantities with the same units can be subtracted
  3024. --             preserving their physical units.
  3025.  
  3026.   function "-" ( LEFT , RIGHT : REAL ) return REAL ;
  3027.  
  3028. --             Multiplying a physical quantity by itself does not produce
  3029. --             the same physical quantity and thus must not be allowed.
  3030. --             Multiplying a physical quantity by a non dimensional quantity
  3031. --             does preserve the units of the physical quantity.
  3032.  
  3033.   function "*" ( LEFT : LONG_FLOAT ;
  3034.                  RIGHT : REAL ) return REAL ;
  3035.  
  3036.   function "*" ( LEFT : REAL ;
  3037.                  RIGHT : LONG_FLOAT ) return REAL ;
  3038.  
  3039. --             Dividing a physical quantity by a non dimensional quantity
  3040. --             preserves the units of the physical quantity.
  3041.  
  3042.   function "/" ( LEFT : REAL ;
  3043.                  RIGHT : LONG_FLOAT ) return REAL ;
  3044.  
  3045. --             Dividing a physical quantity by itself produces
  3046. --             a non dimensional value.
  3047.  
  3048.   function "/" ( LEFT , RIGHT : REAL ) return LONG_FLOAT ;
  3049.  
  3050. --               The absolute value of a physical quantity retains the
  3051. --               same physical units.
  3052.  
  3053.   function "abs" ( LEFT : REAL ) return REAL ;
  3054.  
  3055. --             Equality and inequality are implicitly defined. The other
  3056. --             relational operators must be explicitly defined.
  3057.  
  3058.   function "<" ( LEFT , RIGHT : REAL ) return BOOLEAN ;
  3059.  
  3060.   function ">" ( LEFT , RIGHT : REAL ) return BOOLEAN ;
  3061.  
  3062.   function "<=" ( LEFT , RIGHT : REAL ) return BOOLEAN ;
  3063.  
  3064.   function ">=" ( LEFT , RIGHT : REAL ) return BOOLEAN ;
  3065.  
  3066.                                                               --Alstad start
  3067. --             Taking a root of a physical quantity by itself does not produce
  3068. --             the same physical quantity and thus must not be allowed.
  3069.  
  3070.   function SQRT ( LEFT : LONG_FLOAT ) return LONG_FLOAT ;
  3071.  
  3072.   function CUBE_ROOT ( LEFT : LONG_FLOAT ) return LONG_FLOAT ;
  3073.                                                               --Alstad end
  3074.  
  3075.  
  3076. --              The primary purpose of this function for the user is
  3077. --              to make constants into values of a specific physical
  3078. --              unit.
  3079. --              The use of this function in the set of physics packages
  3080. --              is to apply the required Ada type to the result of a
  3081. --              non dimensional computation.
  3082.  
  3083.   function DIMENSION ( LEFT : LONG_FLOAT ) return REAL ;
  3084.  
  3085. --              The use of this function in the set of physics packages
  3086. --              is to take any physical quantity and get a non dimensional
  3087. --              value in the base floating point arithmetic type in order
  3088. --              to preform computation. This should not be needed by users
  3089. --              of the set of physics packages.
  3090.  
  3091.   function UNDIMENSION ( LEFT : REAL ) return LONG_FLOAT ;
  3092.  
  3093. --    For compilers that can make use of INLINE
  3094.  
  3095.   pragma INLINE ( "+" , "-" , "*" , "/" , "abs" , "<" , ">" , "<=" , ">=" ,
  3096.       DIMENSION , UNDIMENSION ) ;
  3097.  
  3098. --
  3099. private
  3100.   type REAL is new LONG_FLOAT ;  
  3101. end PHYSICAL_REAL ;
  3102.  
  3103.   with NthRoot;                                                   --Alstad
  3104. package body PHYSICAL_REAL is
  3105.  
  3106.                                                                  --Alstad start
  3107.   package Square is new NthRoot (N => 2, Arith_Type => LONG_FLOAT);
  3108.   package Cube is new NthRoot (N => 3, Arith_Type => LONG_FLOAT);
  3109.  
  3110.   function SQRT (LEFT : LONG_FLOAT) return LONG_FLOAT
  3111.     is begin
  3112.     return (Square.RootOf (LEFT));
  3113.     end;  -- SQRT
  3114.   function CUBE_ROOT (LEFT : LONG_FLOAT) return LONG_FLOAT
  3115.     is begin
  3116.     return (Cube.RootOf (LEFT));
  3117.     end;  -- SQRT
  3118.  
  3119.   pragma INLINE (SQRT, CUBE_ROOT);
  3120.                                                                  --Alstad end
  3121.  
  3122.   function "+" ( LEFT , RIGHT : REAL ) return REAL is
  3123.  
  3124.   begin
  3125.     return REAL ( LONG_FLOAT( LEFT ) + LONG_FLOAT ( RIGHT )) ;
  3126.   end "+" ;
  3127.  
  3128.   function "-" ( LEFT , RIGHT : REAL ) return REAL is
  3129.  
  3130.   begin
  3131.     return REAL ( LONG_FLOAT( LEFT ) - LONG_FLOAT ( RIGHT )) ;
  3132.   end "-" ;
  3133.  
  3134.   function "*" ( LEFT : LONG_FLOAT ;
  3135.                  RIGHT : REAL ) return REAL is
  3136.  
  3137.   begin
  3138.     return REAL ( LEFT * LONG_FLOAT( RIGHT )) ;
  3139.   end "*" ;
  3140.  
  3141.   function "*" ( LEFT : REAL ;
  3142.                  RIGHT : LONG_FLOAT ) return REAL is
  3143.  
  3144.   begin
  3145.     return REAL ( LONG_FLOAT( LEFT ) * RIGHT) ;
  3146.   end "*" ;
  3147.  
  3148.   function "/" ( LEFT : REAL ;
  3149.                  RIGHT : LONG_FLOAT ) return REAL is
  3150.  
  3151.   begin
  3152.     return REAL ( LONG_FLOAT( LEFT ) / RIGHT) ;
  3153.   end "/" ;
  3154.  
  3155.   function "/" ( LEFT , RIGHT : REAL ) return LONG_FLOAT is
  3156.  
  3157.   begin
  3158.     return LONG_FLOAT ( LEFT ) / LONG_FLOAT ( RIGHT ) ;
  3159.   end "/" ;
  3160.  
  3161.   function "abs" ( LEFT : REAL ) return REAL is
  3162.  
  3163.   begin
  3164.     return REAL ( abs( LONG_FLOAT( LEFT ))) ;
  3165.   end "abs" ;
  3166.  
  3167.   function "<" ( LEFT , RIGHT : REAL ) return BOOLEAN is
  3168.  
  3169.   begin
  3170.     return LONG_FLOAT ( LEFT ) < LONG_FLOAT ( RIGHT ) ;
  3171.   end "<" ;
  3172.  
  3173.   function ">" ( LEFT , RIGHT : REAL ) return BOOLEAN is
  3174.  
  3175.   begin
  3176.     return LONG_FLOAT ( LEFT ) > LONG_FLOAT ( RIGHT ) ;
  3177.   end ">" ;
  3178.  
  3179.   function "<=" ( LEFT , RIGHT : REAL ) return BOOLEAN is
  3180.  
  3181.   begin
  3182.     return LONG_FLOAT ( LEFT ) <= LONG_FLOAT ( RIGHT ) ;
  3183.   end "<=" ;
  3184.  
  3185.   function ">=" ( LEFT , RIGHT : REAL ) return BOOLEAN is
  3186.  
  3187.   begin
  3188.     return LONG_FLOAT ( LEFT ) >= LONG_FLOAT ( RIGHT ) ;
  3189.   end ">=" ;
  3190.  
  3191.   function DIMENSION ( LEFT : LONG_FLOAT ) return REAL is
  3192.  
  3193.   begin
  3194.     return REAL ( LEFT ) ;
  3195.   end DIMENSION ;
  3196.  
  3197.   function UNDIMENSION ( LEFT : REAL ) return LONG_FLOAT is
  3198.  
  3199.   begin
  3200.     return LONG_FLOAT ( LEFT ) ;
  3201.   end UNDIMENSION ;
  3202.  
  3203. end PHYSICAL_REAL ;
  3204.  
  3205. --------------------------------------------------------------------------------
  3206.  
  3207.  
  3208.  
  3209.  
  3210.  
  3211.  
  3212.  
  3213.  
  3214.  
  3215. --------------------------------------------------------------------------------
  3216. with TEXT_IO ; use TEXT_IO ;
  3217. package LONG_FLT_IO is new FLOAT_IO ( LONG_FLOAT ) ;
  3218. --------------------------------------------------------------------------------
  3219.  
  3220.  
  3221.  
  3222.  
  3223.  
  3224.  
  3225.  
  3226.  
  3227.  
  3228. --------------------------------------------------------------------------------
  3229. with PHYSICAL_REAL ; use PHYSICAL_REAL ;
  3230.  
  3231. package PHYSICAL_UNITS_BASIC is
  3232.  
  3233. -- This package specification defines Ada types for physical
  3234. -- quantities. A number of other packages use this package
  3235. -- specification in order to provide a comprehensive dimension
  3236. -- checking and units conversion system.
  3237. --
  3238. --              PHYSICAL QUANTITIES AND THEIR ASSOCIATED DIMENSIONS
  3239. --
  3240. --   Errors can occur in writing equations to solve problems in classical
  3241. --physics. Many of these errors can be prevented by performing a dimensionality
  3242. --check on the equations. All physical quantities have a fundamental dimension
  3243. --that is independent of the units of measurement. The basic physical dimensions
  3244. --are: length, mass, time, electrical charge, temperature and luminous intens-
  3245. --ity.There are a number of systems of units for measuring physical quantities.
  3246. --The MKS system is based on meter, kilogram, second  measurement.
  3247. --The CGS system is based on centimeter, gram, second  measurement.
  3248. --The English system is based on feet, pound, second  measurement.
  3249. --A few physical dimensions and the associated measurement unit in 
  3250. --these three systems are :
  3251. --
  3252. --
  3253. --      Physical Quantity                           Unit System
  3254. --        Dimension                         MKS         CGS          English
  3255. --
  3256. --        length                            meter       centimeter   feet
  3257. --
  3258. --        mass                              kilogram    gram         pound mass
  3259. --
  3260. --        time                              second      second       second
  3261. --
  3262. --        force                             newton      dyne         poundal
  3263. --
  3264. --        energy                            joule       erg          B.t.u.
  3265. --
  3266. --
  3267. --   The checking of a physical equation has two aspects. The first is to check
  3268. --the dimensionality. The dimensionality is independent of the unit system. The
  3269. --second is to check that a consistent system of units is used in the equation.
  3270. --   An example of a dimensionality check is using the basic equation F=ma to
  3271. --determine that force has the dimension  mass x length / time squared, then
  3272. --              2
  3273. --check if  F=mv /r  is dimensionally correct. The check is performed by 
  3274. --expanding the dimensions, e.g.  mass x (length/time) x (length/time) / length.
  3275. --with the dimensions expected for force from the basic equation F=ma. As
  3276. --expected, centripetal force has the same dimensionality as the force from
  3277. --Newton's second law of motion.
  3278. --
  3279. --                    THE ALGEBRA OF DIMENSIONALITY
  3280. --
  3281. --   The dimension of any physical quantity can be written as
  3282. --
  3283. --                  a   b   c   d   e   f
  3284. --                 L   M   T   Q   C   K
  3285. --
  3286. --where a,b,c,d,e and f are integers such as -4, -3, -2 , -1, 0, 1, 2, 3, 4
  3287. --and L is length, M is mass, T is time, Q is charge, C is luminous intensity
  3288. --and K is temperature. An exponent of zero means the dimension does not apply
  3289. --to the physical quantity. The normal rules of algebra for exponents apply
  3290. --for combining dimensions.
  3291. --
  3292. --   In order to add or subtract two physical quantities the quantities must
  3293. --have the same dimension. The resulting physical quantity has the same
  3294. --dimensions. Physical quantities with the same dimension in different
  3295. --systems of units can be added or subtracted by multiplying one of
  3296. --the quantities by a units conversion factor to obtain compatible units.
  3297. --
  3298. --   The multiplication of two physical quantities results in a new physical
  3299. --quantity that has the sum of the exponents of the dimensions of the initial
  3300. --two quantities.
  3301. --
  3302. --   The division of one physical quantity by another results in a new physical
  3303. --quantity that has the dimension of the exponents of the first quantity minus
  3304. --the exponents of the second quantity.
  3305. --
  3306. --   Taking the square root of a physical quantity results in a new physical
  3307. --quantity having a dimension with exponents half of the initial dimension.
  3308. --
  3309. --   Raising a physical quantity to a power results in a new physical quantity
  3310. --having a dimension with the exponents multiplied by the power.
  3311. --
  3312. --                                     2                2  2    2 -2
  3313. --          e.g. v has dimension L/T, v  has dimension L /T or L T
  3314. --
  3315. --   The derivative of a physical quantity with respect to another physical
  3316. --quantity results in a new physical quantity with the exponents of the
  3317. --first dimension minus the exponents of the other dimension.
  3318. --         e.g.  v has dimension L/T, t has dimension T,
  3319. --
  3320. --                                           2
  3321. --               then dv/dt has dimension L/T
  3322. --
  3323. --   The integral of a physical quantity over the range of another physical
  3324. --quantity results in a new physical quantity that has a dimension with the
  3325. --sum of the exponents of the two quantities.
  3326. --        
  3327. --         e.g.  v has dimension L/T, t has dimension T,
  3328. --               then  integral v dt  has dimension  L/T * T or L
  3329. --
  3330. --
  3331. -- The initial thought was to have metric units and English units
  3332. -- in separate package specifications. This proved inpractical
  3333. -- because time in seconds is both metric and English. Many other
  3334. -- units such as watt of power and Farad of capacitance are in
  3335. -- both systems. A further impracticallity arose when considering
  3336. -- the design of a units system conversion package. e.g. A package
  3337. -- that would provide accurate conversion form meters to inches
  3338. -- to micrometers to light years. The one package specification became
  3339. -- so large that it was inefficient, so, in order to keep the size
  3340. -- reasonable, three packages were created. The basic units, the
  3341. -- mechanical units and the electrical units. Then a package
  3342. -- called other units came into existance for pragmatic reasons.
  3343. --
  3344. -- Notice that there is not a type called LENGTH because
  3345. -- adding length in meters to length in feet is not allowed.
  3346. -- Even LENGTH_METRIC and LENGTH_ENGLISH are not acceptable
  3347. -- because meters can not be added to centimeters and inches can
  3348. -- not be added to feet. Further complication arises because of
  3349. -- seconds of time and seconds of arc. There can be ounces of
  3350. -- milk ( liquid measure ) and ounces of sugar ( weight measure ).
  3351. -- There can be quarts of milk and quarts of strawberries ( dry
  3352. -- measure ). Thus the decision was made that every Ada type
  3353. -- would be a dimension name followed by a unit name.
  3354. --
  3355. -- Now, more choices had to be made. Unit names such as 
  3356. --  DENSITY_KILOGRAM_PER_CUBIC_METER or DENSITY_TONS_PER_CUBIC_YARD
  3357. -- start getting long and there are many combinations. The number
  3358. -- of combinations for density are all the units of mass times all
  3359. -- the units of volume. Thus a subset of all possible units was
  3360. -- chosen with the additional short hand notation of _MKS for
  3361. -- the meter, kilogram, second system of units and the _ENGLISH for
  3362. -- the foot, pound, second system. Additional qualifiers are added
  3363. -- to clarify such as VOLUME_QUART_LIQUID and VOLUME_QUART_DRY.
  3364. --
  3365. -- Some other compromises were made:
  3366. --       Only a few units were entered as both singular and plural.
  3367. --       The choice of names is the authors. A committee could expand
  3368. --       the list. For example a meter can be a length or a distance,
  3369. --       length is used as the type and distance is a subtype.
  3370. --       A user may provide additional local subtype names for units 
  3371. --       and thus has the full capability for alternate type names.
  3372. --
  3373. --   The comments below are organized to present the physical quantity name with
  3374. --associated information. The second column is one of the typical symbols used
  3375. --for the physical quantity. The third column is the dimension of the physical
  3376. --quantity expressed in terms of the fundamental dimensions. The fourth column
  3377. --is the name of the unit in the MKS measurement system. The fifth column
  3378. --is the typical MKS unit equation. An independent table presents conversion
  3379. --factors from the MKS measurement system to other measurement systems.
  3380. --   Physics developed over a period of many years by many people from a variety
  3381. --of disciplines. Thus, there is ambiguity and duplication of symbols.
  3382. -- 
  3383. --
  3384. --PHYSICAL QUANTITY         SYMBOL  DIMENSION   MEASUREMENT UNIT  UNIT EQUATION
  3385. --_________________         ______  _________   ________________  ______________
  3386. --
  3387. --
  3388. --                                  BASIC UNITS
  3389. --
  3390. --length                     s       L           meter              m
  3391. --wave length                lambda  "             "                "
  3392. --
  3393.   type LENGTH_MKS is new REAL ;
  3394.   subtype LENGTH_METER is LENGTH_MKS ;
  3395.   subtype LENGTH_METERS is LENGTH_MKS ;  -- This could be done for every type
  3396.   subtype DISTANCE_METER is LENGTH_MKS ;  -- with plurals and alias and
  3397.   subtype DISTANCE_METERS is LENGTH_MKS ;  -- plurals for the alias
  3398.   subtype WAVE_LENGTH_MKS is LENGTH_MKS ;
  3399.   subtype WAVE_LENGTH_METER is LENGTH_MKS ;
  3400.   type LENGTH_ENGLISH is new REAL ;
  3401.   subtype LENGTH_FOOT is LENGTH_ENGLISH ;
  3402.   subtype LENGTH_FEET is LENGTH_ENGLISH ;
  3403.   type LENGTH_PICOMETER is new REAL ;
  3404.   type LENGTH_NANOMETER is new REAL ;
  3405.   type LENGTH_MICROMETER is new REAL ;
  3406.   type LENGTH_MILLIMETER is new REAL ;
  3407.   type LENGTH_CENTIMETER is new REAL ;
  3408.   type LENGTH_DECIMETER is new REAL ;
  3409.   type LENGTH_DECAMETER is new REAL ;
  3410.   type LENGTH_HECTOMETER is new REAL ;
  3411.   type LENGTH_KILOMETER is new REAL ;
  3412.   type LENGTH_MEGAMETER is new REAL ;
  3413.   type LENGTH_GIGAMETER is new REAL ;
  3414.   type LENGTH_ANGSTROM is new REAL ;
  3415.   type LENGTH_MIL is new REAL ;
  3416.   type LENGTH_INCH is new REAL ;
  3417.   type LENGTH_YARD is new REAL ;
  3418.   type LENGTH_FATHOM is new REAL ;
  3419.   type LENGTH_ROD is new REAL ;
  3420.   type LENGTH_CHAIN_SURVEYOR is new REAL ;
  3421.   type LENGTH_CHAIN_ENGINEER is new REAL ;
  3422.   type LENGTH_FURLONG is new REAL ;
  3423.   type LENGTH_MILE is new REAL ;
  3424.   subtype LENGTH_MILE_STATUTE is LENGTH_MILE ;
  3425.   type LENGTH_MILE_NAUTICAL is new REAL ;
  3426.   type LENGTH_LEAGUE_LAND is new REAL ;
  3427.   type LENGTH_LEAGUE_MARINE is new REAL ;
  3428.   type LENGTH_LIGHT_YEAR is new REAL ;
  3429.  
  3430. --
  3431. --mass                       m       M           kilogram           Kg
  3432. --
  3433.   type MASS_MKS is new REAL ;
  3434.   subtype MASS_KILOGRAM is MASS_MKS ;
  3435.   type MASS_ENGLISH is new REAL ;
  3436.   subtype MASS_POUND is MASS_ENGLISH ;
  3437.   subtype MASS_POUND_AVDP is MASS_ENGLISH ;
  3438.   type MASS_POUND_TROY is new REAL ;
  3439.   subtype MASS_POUND_APOTHECARY is MASS_POUND_TROY ;
  3440.   type MASS_MILLIGRAM is new REAL ;
  3441.   type MASS_GRAM is new REAL ;
  3442.   type MASS_GRAIN is new REAL ; -- same inall English systems
  3443.   type MASS_PENNYWEIGHT_TROY is new REAL ;
  3444.   type MASS_CARAT_TROY is new REAL ;
  3445.   type MASS_SCRUPLE is new REAL ;
  3446.   type MASS_DRAM_AVDP is new REAL ;
  3447.   type MASS_OUNCE_AVDP is new REAL ;
  3448.   type MASS_OUNCE_TROY is new REAL ;
  3449.   type MASS_TON_SHORT is new REAL ;
  3450.   type MASS_TON_LONG is new REAL ;
  3451.   type MASS_TON_METRIC is new REAL ;
  3452.  
  3453. --
  3454. --time                       t       T           second             sec
  3455. --
  3456.   type TIME_SECOND is new REAL ;
  3457.   subtype TIME_SECONDS is TIME_SECOND ;
  3458.   type TIME_PICOSECOND is new REAL ;
  3459.   type TIME_NANOSECOND is new REAL ;
  3460.   type TIME_MICROSECOND is new REAL ;
  3461.   type TIME_MILLISECOND is new REAL ;
  3462.   type TIME_CENTISECOND is new REAL ;
  3463.   type TIME_KILOSECOND is new REAL ;
  3464.   type TIME_MEGASECOND is new REAL ;
  3465.   type TIME_GIGASECOND is new REAL ;
  3466.   type TIME_MINUTE is new REAL ;
  3467.   type TIME_HOUR is new REAL ;
  3468.   type TIME_DAY is new REAL ;
  3469.   type TIME_FORTNIGHT is new REAL ;
  3470.   type TIME_MONTH is new REAL ;
  3471.   type TIME_YEAR is new REAL ;
  3472.   type TIME_DECADE is new REAL ;
  3473.   type TIME_CENTURY is new REAL ;
  3474.   type TIME_MILLENNIA is new REAL ;
  3475.  
  3476. --
  3477. --electric charge            q       Q           coulomb            c
  3478. --  electric flux
  3479. --
  3480.   type CHARGE_COULOMB is new REAL ;
  3481.   subtype CHARGE_AMPERE_SECOND is CHARGE_COULOMB ;
  3482.   type CHARGE_AMPERE_HOURS is new REAL ;
  3483.   type CHARGE_ELECTRON is new REAL ;
  3484.   type CHARGE_FARADAY is new REAL ;
  3485.  
  3486. --
  3487. --luminous intensity         I       C           candle             cd
  3488. --
  3489.   type LUMINOUS_INTENSITY_CANDLE is new REAL ;
  3490.  
  3491. --                                                                  o
  3492. --temperature                T       K           degree kelvin       K
  3493. --
  3494.   type TEMPERATURE_KELVIN is new real ;
  3495.   type TEMPERATURE_CENTIGRADE is new REAL ;
  3496.   subtype TEMPERATURE_CELSIUS is TEMPERATURE_CENTIGRADE ;
  3497.   type TEMPERATURE_FARENHEIT is new REAL ;
  3498.  
  3499. --
  3500. --angle                      theta   none        radian             none
  3501. --
  3502.   type ANGLE_RADIAN is new REAL ;
  3503.   subtype ANGLE_RADIANS is ANGLE_RADIAN ;
  3504.   subtype PLANE_ANGLE_RADIANS is ANGLE_RADIAN ;
  3505.   type ANGLE_SECOND is new REAL ;
  3506.   type ANGLE_MINUTE is new REAL ;
  3507.   type ANGLE_DEGREE is new REAL ;
  3508.   type ANGLE_REVOLUTION is new REAL ;
  3509.   type ANGLE_BAM is new REAL ;
  3510.  
  3511. --
  3512. --solid angle                phi     none        steradian          none
  3513. --
  3514.   type SOLID_ANGLE_STERADIAN is new REAL ;
  3515. --
  3516. end PHYSICAL_UNITS_BASIC ;
  3517. --------------------------------------------------------------------------------
  3518.  
  3519.  
  3520.  
  3521.  
  3522.  
  3523.  
  3524.  
  3525.  
  3526.  
  3527. --------------------------------------------------------------------------------
  3528. with PHYSICAL_REAL ; use PHYSICAL_REAL ;
  3529.  
  3530. package PHYSICAL_UNITS_MECHANICAL is
  3531.  
  3532. -- This package specification defines Ada types for physical
  3533. -- quantities generally in the mechanical context.
  3534. --
  3535. -- This package is the logical continuation of PHYSICAL_UNITS_BASIC
  3536. --
  3537. --
  3538. --                                 DERIVED MECHANICAL UNITS
  3539. --
  3540. --
  3541. --                                    2                              2
  3542. --area                       A       L           square meter       m
  3543. --
  3544.   type AREA_MKS is new REAL ;
  3545.   subtype AREA_SQUARE_METER is AREA_MKS ;
  3546.   subtype AREA_SQUARE_METERS is AREA_MKS ;
  3547.   type AREA_ENGLISH is new REAL ;
  3548.   subtype AREA_SQUARE_FEET is AREA_ENGLISH ;
  3549.   subtype AREA_SQUARE_FOOT is AREA_ENGLISH ;
  3550.   type AREA_SQUARE_CENTIMETER is new REAL ;
  3551.   type AREA_SQUARE_KILOMETER is new REAL ;
  3552.   type AREA_SQUARE_INCH is new REAL ;
  3553.   type AREA_SQUARE_YARD is new REAL ;
  3554.   type AREA_SQUARE_MILE is new REAL ;
  3555.   type AREA_ACRE is new REAL ;
  3556.   type AREA_CIRCULAR_MIL is new REAL ;
  3557.   type AREA_HECTARE is new REAL ;
  3558.   type AREA_TOWNSHIP is new REAL ;
  3559.  
  3560. --
  3561. --                                    3                              3
  3562. --volume                     V       L           stere              m
  3563. --
  3564.   type VOLUME_MKS is new REAL ;
  3565.   subtype VOLUME_STERE is VOLUME_MKS ;
  3566.   subtype VOLUME_CUBIC_METER is VOLUME_MKS ;
  3567.   type VOLUME_ENGLISH is new REAL ;
  3568.   subtype VOLUME_CUBIC_FEET is VOLUME_ENGLISH ;
  3569.   type VOLUME_MILLILITER is new REAL ;
  3570.   type VOLUME_LITER is new REAL ;
  3571.   type VOLUME_KILOLITER is new REAL ;
  3572.   type VOLUME_CUBIC_CENTIMETER is new REAL ;
  3573.   type VOLUME_CUBIC_INCH is new REAL ;
  3574.   type VOLUME_CUBIC_YARD is new REAL ;
  3575.   type VOLUME_CUBIC_MILE is new REAL ;
  3576.   type VOLUME_TEASPOON is new REAL ;
  3577.   type VOLUME_TABLESPOON is new REAL ;
  3578.   type VOLUME_OUNCE_FLUID is new REAL ;
  3579.   type VOLUME_JIGGER is new REAL ;
  3580.   type VOLUME_CUP is new REAL ;
  3581.   type VOLUME_PINT_LIQUID is new REAL ;
  3582.   type VOLUME_QUART_LIQUID is new REAL ;
  3583.   type VOLUME_GALLON is new REAL ;
  3584.   type VOLUME_KEG is new REAL ;
  3585.   type VOLUME_BARREL is new REAL ;
  3586.   type VOLUME_PINT_DRY is new REAL ;
  3587.   type VOLUME_QUART_DRY is new REAL ;
  3588.   type VOLUME_PECK is new REAL ;
  3589.   type VOLUME_BUSHEL is new REAL ;
  3590.   type VOLUME_CORD is new REAL ;
  3591.  
  3592. --
  3593. --velocity                   v       L/T         meter per second   m/sec
  3594. --
  3595.   type VELOCITY_MKS is new REAL ;
  3596.   subtype VELOCITY_METER_PER_SECOND is VELOCITY_MKS ;
  3597.   type VELOCITY_ENGLISH is new REAL ;
  3598.   subtype VELOCITY_FEET_PER_SECOND is VELOCITY_ENGLISH ;
  3599.   type VELOCITY_CENTIMETER_PER_SECOND is new REAL ;
  3600.   type VELOCITY_KILOMETER_PER_HOUR is new REAL ;
  3601.   type VELOCITY_INCHES_PER_SECOND is new REAL ;
  3602.   type VELOCITY_MILE_PER_HOUR is new REAL ;
  3603.   type VELOCITY_MILES_PER_SECOND is new REAL ;
  3604.   type VELOCITY_INCHES_PER_MINUTE is new REAL ;
  3605.   type VELOCITY_FEET_PER_MINUTE is new REAL ;
  3606.   type VELOCITY_MILES_PER_HOUR is new REAL ;
  3607.   type VELOCITY_KNOTS is new REAL ;
  3608.   type VELOCITY_FURLONG_PER_FORTNIGHT is new REAL ;
  3609.  
  3610. --
  3611. --angular velocity           omega   1/T         radians per second 1/sec
  3612. --
  3613.   type ANGULAR_VELOCITY is new REAL ;
  3614.   subtype ANGULAR_VELOCITY_RADIANS_PER_SECOND is ANGULAR_VELOCITY ;
  3615.   type ANGULAR_VELOCITY_DEGREES_PER_SECOND is new REAL ;
  3616.   type ANGULAR_VELOCITY_REVOLUTIONS_PER_MINUTE is new REAL ;
  3617.   type ANGULAR_VELOCITY_REVOLUTIONS_PER_SECOND is new REAL ;
  3618.  
  3619. --
  3620. --                                      2                                2
  3621. --acceleration               a       L/T         meter per second   m/sec
  3622. --                                               squared
  3623. --
  3624.   type ACCELERATION_MKS is new REAL ;
  3625.   subtype ACCELERATION_METER_PER_SECOND_SQUARED is ACCELERATION_MKS ;
  3626.   type ACCELERATION_ENGLISH is new REAL ;
  3627.   subtype ACCELERATION_FEET_PER_SECOND_SQUARED is ACCELERATION_ENGLISH ;
  3628.  
  3629. --
  3630. --                                      2                                2
  3631. --angular acceleration       alpha   1/T         radians per        1/sec
  3632. --                                               square second
  3633. --
  3634.   type ANGULAR_ACCELERATION is new REAL ;
  3635.   subtype ANGULAR_ACCELERATION_RADIANS_PER_SECOND_SQUARED is 
  3636.                  ANGULAR_ACCELERATION ;
  3637.   type ANGULAR_ACCELERATION_REVOLUTIONS_PER_MINUTE_SQUARED is new REAL ;
  3638.  
  3639. --
  3640. --                                       2                                  2
  3641. --force                      F       ML/T        newton             Kg m/sec
  3642. --
  3643.   type FORCE_MKS is new REAL ;
  3644.   subtype FORCE_NEWTON is FORCE_MKS ;
  3645.   subtype FORCE_KILOGRAM_METER_PER_SECOND_SQUARED is FORCE_MKS ;
  3646.   type FORCE_DYNE is new REAL ;
  3647.   type FORCE_ENGLISH is new REAL ;
  3648.   subtype FORCE_POUNDAL is FORCE_ENGLISH ;
  3649.   subtype FORCE_POUND_FOOT_PER_PER_SECOND_SQUARED is FORCE_ENGLISH ;
  3650.  
  3651. --
  3652. --                                     2  2                             2    2
  3653. --energy                     E       ML /T       joule              Kg m /sec
  3654. --work                       W         "           "                   "
  3655. --heat                       Q         "           "                   "
  3656. --torque (moment)            T         "         newton meter          "
  3657. --
  3658.   type ENERGY_MKS is new REAL ;
  3659.   subtype WORK_MKS is ENERGY_MKS ;
  3660.   subtype HEAT_MKS is ENERGY_MKS ;
  3661.   subtype TORQUE_MKS is ENERGY_MKS ;
  3662.   subtype ENERGY_JOULE is ENERGY_MKS ;
  3663.   subtype ENERGY_NEWTON_METER is ENERGY_MKS ;
  3664.   subtype ENERGY_KILOGRAM_METER_SQUARED_PER_SECOND_SQUARED is ENERGY_MKS ;
  3665.   type ENERGY_ERG is new REAL ;
  3666.   type ENERGY_GRAM_CALORIE is new REAL ;
  3667.   type ENERGY_KILOGRAM_CALORIE is new REAL ;
  3668.   type ENERGY_ENGLISH is new REAL ;
  3669.   subtype ENERGY_B_T_U is ENERGY_ENGLISH ;
  3670.   type ENERGY_FOOT_POUND is new REAL ;
  3671.   type ENERGY_KILOWATT_HOUR is new REAL ;
  3672.   type ENERGY_HORSEPOWER_HOUR is new REAL ;
  3673.  
  3674. --
  3675. --                                     2  3                        
  3676. --power                      P       ML /T       watt               joule/sec
  3677. --
  3678.   type POWER_MKS is new REAL ;
  3679.   subtype POWER_WATT is POWER_MKS ;
  3680.   subtype POWER_JOULE_PER_SECOND is POWER_MKS ;
  3681.   subtype POWER_VOLT_AMPERE is POWER_MKS ;
  3682.   type POWER_KILOGRAM_CALORIE_PER_SECOND is new REAL ;
  3683.   type POWER_KILOGRAN_CALORIE_PER_MINUTE is new REAL ;
  3684.   type POWER_HORSEPOWER_MECHANICAL is new REAL ;
  3685.   type POWER_HORSEPOWER_ELECTRICAL is new REAL ;
  3686.   type POWER_HORSEPOWER_METRIC is new REAL ;
  3687.   type POWER_HORSEPOWER_BOILER is new REAL ;
  3688.   type POWER_B_T_U_PER_MINUTE is new REAL ;
  3689.   type POWER_B_T_U_PER_HOUR is new REAL ;
  3690.   type POWER_FOOT_POUND_PER_MINUTE is new REAL ;
  3691.   type POWER_FOOT_POUND_PER_SECOND is new REAL ;
  3692.  
  3693. --
  3694. --                                      3                               3
  3695. --density                    D       M/L         kilogram per       Kg/m
  3696. --                                               cubic meter
  3697. --
  3698.   type DENSITY_MKS is new REAL ;
  3699.   subtype DENSITY_KILOGRAM_PER_CUBIC_METER is DENSITY_MKS ;
  3700.   type DENSITY_ENGLISH is new REAL ;
  3701.   subtype DENSITY_POUND_PER_CUBIC_FOOT is DENSITY_ENGLISH ;
  3702.  
  3703. --
  3704. --                                    3                              3
  3705. --flow rate                  f       L /T        cubic meter per    m /sec
  3706. --                                               second
  3707. --
  3708.   type FLOW_RATE_MKS is new REAL ;
  3709.   subtype FLOW_RATE_CUBIC_METER_PER_SECOND is FLOW_RATE_MKS ;
  3710.   type FLOW_RATE_ENGLISH is new REAL ;
  3711.   subtype FLOW_RATE_CUBIC_FEET_PER_SECOND is FLOW_RATE_ENGLISH ;
  3712.   type FLOW_RATE_GALLON_PER_MINUTE is new REAL ;
  3713.   type FLOW_RATE_CUBIC_FEET_PER_MINUTE is new REAL ;
  3714.  
  3715. --
  3716. --                                       2                                  2
  3717. --pressure                   P       M/LT        pascal             Kg/m sec
  3718. -- stress                                        newton per
  3719. -- energy density                                square meter
  3720. --
  3721.   type PRESSURE_MKS is new REAL ;
  3722.   subtype PRESSURE_PASCAL is PRESSURE_MKS ;
  3723.   subtype PRESSURE_NEWTON_PER_SQUARE_METER is PRESSURE_MKS ;
  3724.   subtype PRESSURE_FORCE_PER_AREA_MKS is PRESSURE_MKS ;
  3725.   subtype PRESSURE_JOULE_PER_CUBIC_METER is PRESSURE_MKS ;
  3726.   subtype PRESSURE_ENERGY_DENSITY_MKS is PRESSURE_MKS ;
  3727.   type PRESSURE_ENGLISH is new REAL ;
  3728.   subtype PRESSURE_POUND_PER_SQUARE_FOOT is PRESSURE_ENGLISH ;
  3729.   type PRESSURE_TON_PER_SQUARE_FOOT is new REAL ;
  3730.   type PRESSURE_ATMOSPHERE_STANDARD is new REAL ;
  3731.   type PRESSURE_FEET_OF_WATER is new REAL ;
  3732.   type PRESSURE_INCHES_OF_MERCURY is new REAL ;
  3733.   type PRESSURE_MILLIMETER_OF_MERCURY is new REAL ;
  3734.   type PRESSURE_BAR is new REAL ;
  3735.   type PRESSURE_MILLIBAR is new REAL ;
  3736.   type PRESSURE_TORR is new REAL ;
  3737.  
  3738. --
  3739. --momentum                   p       ML/T        newton second       Kg m/sec
  3740. --
  3741.   type MOMENTUM_MKS is new REAL ;
  3742.   subtype MOMENTUM_NEWTON_SECOND is MOMENTUM_MKS ;
  3743.   subtype MOMENTUM_KILOGRAM_METER_PER_SECOND is MOMENTUM_MKS ;
  3744.  
  3745. --
  3746. --                                     2                                2
  3747. --inertia                    I       ML /T       joule second       Kg m /sec
  3748. --
  3749.   type INERTIA_MKS is new REAL ;
  3750.   subtype INERTIA_JOULE_SECOND is INERTIA_MKS ;
  3751.   subtype INERTIA_KILOGRAM_METER_SQUARED_PER_SECOND is INERTIA_MKS ;
  3752.  
  3753. --
  3754. --                                     2                                2
  3755. --moment of inertia          M       ML          kilogram           Kg m 
  3756. --                                               meter squared
  3757. --
  3758.   type MOMENT_OF_INERTIA_MKS is new REAL ;
  3759.   subtype MOMENT_OF_INERTIA_KILOGRAM_METER_SQUARED is MOMENT_OF_INERTIA_MKS ;
  3760.  
  3761. --
  3762. --                                    2                                2
  3763. --kinematic viscosity        v       M /T        kilogram squared    Kg /sec 
  3764. --                                               per second
  3765. --
  3766.   type KINEMATIC_VISCOSITY_MKS is new REAL ;
  3767.   subtype KINEMATIC_VISCOSITY_KILOGRAM_SQUARED_PER_SECOND is 
  3768.           KINEMATIC_VISCOSITY_MKS ;
  3769. --
  3770. --dynamic viscosity          d       M/LT        newton second       Kg/m sec 
  3771. --                                               per square meter
  3772. --
  3773.   type DYNAMIC_VISCOSITY_MKS is new REAL ;
  3774.   subtype DYNAMIC_VISCOSITY_NEWTON_PER_SQUARE_METER is DYNAMIC_VISCOSITY_MKS ;
  3775.   subtype DYNAMIC_VISCOSITY_KILOGRAM_PER_METER_SECOND is DYNAMIC_VISCOSITY_MKS ;
  3776. --
  3777. --
  3778. --luminous flux              phi     C           lumen (4Pi candle   cd sr 
  3779. --                                               for point source)
  3780. --
  3781.   type LUMINOUS_FLUX_LUMEN is new REAL ;
  3782.  
  3783. --
  3784. --                                      2                                   2
  3785. --illumination               E       C/L         lumen per           cd sr/m
  3786. --                                               square meter
  3787. --
  3788.   type ILLUMINATION_MKS is new REAL ;
  3789.   subtype ILLUMINATION_LUMEN_PER_SQUARE_METER is ILLUMINATION_MKS ;
  3790.  
  3791. --
  3792. --                                      2                                 2
  3793. --luminance                  l       C/L         lux                  cd/m
  3794. --                                               square meter
  3795. --
  3796.   type LUMINANCE_MKS is new REAL ;
  3797.   subtype LUMINANCE_LUX is LUMINANCE_MKS ;
  3798.   subtype LUMINANCE_CANDLE_PER_SQUARE_METER is LUMINANCE_MKS ;
  3799.  
  3800. --
  3801. --
  3802. --                                     2  2                             2 
  3803. --entropy                    S       ML /T K     joule per degree   Kg m /
  3804. --                                                                      2 o
  3805. --                                                                   sec   K
  3806. --
  3807.   type ENTROPY_MKS is new REAL ;
  3808.   subtype SPECIFIC_HEAT_MKS is ENTROPY_MKS ;
  3809.   subtype SPECIFIC_HEAT_JOULE_PER_DEGREE_KELVIN is ENTROPY_MKS ;
  3810.   type SPECIFIC_HEAT_B_T_U_PER_POUND_DEGREE_FARENHEIT is new REAL ;
  3811.  
  3812. --
  3813. end PHYSICAL_UNITS_MECHANICAL ;
  3814. --------------------------------------------------------------------------------
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824. --------------------------------------------------------------------------------
  3825. with PHYSICAL_REAL ; use PHYSICAL_REAL ;
  3826.  
  3827. package PHYSICAL_UNITS_ELECTRICAL is
  3828.  
  3829. -- This package specification defines Ada types for physical
  3830. -- quantities related to electrical units. It ia a logical
  3831. -- extension of PHYSICAL_UNITS_MECHANICAL .
  3832. --
  3833. --
  3834. --
  3835. --                                  DERIVED ELECTRICAL
  3836. --
  3837. --electric current           I       Q/T         ampere             c/sec
  3838. --  magnetomotive force
  3839.  
  3840.   type CURRENT_AMPERE is new REAL ;
  3841.   type CURRENT_MILLIAMPERE is new REAL ;
  3842.   type CURRENT_MICROAMPERE is new REAL ;
  3843.   type CURRENT_ABAMPERE is new REAL ;
  3844.   type CURRENT_STATAMPERE is new REAL ;
  3845.  
  3846. --
  3847. --                                     2  2                             2    2
  3848. --voltage                    E       ML /T Q     volt               Kg m /sec c
  3849. --  potential difference
  3850. --  electromotive force
  3851.  
  3852.   type VOLTAGE_VOLT is new REAL ;
  3853.   type VOLTAGE_MILLIVOLT is new REAL ;
  3854.   type VOLTAGE_MICROVOLT is new REAL ;
  3855.   type VOLTAGE_KILOVOLT is new REAL ;
  3856.  
  3857. --
  3858. --                                     2   2                            2      2
  3859. --electric resistance        R       ML /TQ      ohm                Kg m /sec c
  3860. --
  3861.   type RESISTANCE_OHM is new REAL ;
  3862.   type RESISTANCE_MILLIOHM is new REAL ;
  3863.   type RESISTANCE_KILOHM is new REAL ;
  3864.   type RESISTANCE_MEGOHM is new REAL ;
  3865.  
  3866. --
  3867. --                                     3   2                            3      2
  3868. --electric resistivity       rho     ML /TQ     ohm meter           Kg m /sec c
  3869. --
  3870.   type RESISTIVITY_OHM_METER is new REAL ;
  3871.  
  3872. --
  3873. --                                     2   2                             2     2
  3874. --electric conductance       G       TQ /ML      mho                sec c /Kg m
  3875. --
  3876.   type CONDUCTANCE_MHO is new REAL ;
  3877.  
  3878. --
  3879. --                                     2   3                             2     3
  3880. --conductivity               sigma   TQ /ML      mho per meter      sec c /Kg m
  3881. --
  3882.   type CONDUCTIVITY_MHO_PER_METER is new REAL ;
  3883.  
  3884. --
  3885. --
  3886. --                                    2 2   2                          2 2     2
  3887. --capacitance                C       T Q /ML     farad              sec c /Kg m
  3888. --
  3889.   type CAPACITANCE_FARAD is new REAL ;
  3890.   type CAPACITANCE_MICROFARAD is new REAL ;
  3891.   type CAPACITANCE_PICOFARAD is new REAL ;
  3892.  
  3893. --
  3894. --
  3895. --                                     2  2                             2  2
  3896. --inductance                 L       ML /Q       henry              Kg m /c
  3897. --                                               weber per ampere
  3898. --                                               volt second per ampere
  3899.  
  3900. --
  3901.   type INDUCTANCE_HENRY is new REAL ;
  3902.   type INDUCTANCE_MILLIHENRY is new REAL ;
  3903.   type INDUCTANCE_MICROHENRY is new REAL ;
  3904.  
  3905. --
  3906. --                                       2                                 2
  3907. --current density            J       Q/TL        ampere per         c/sec m
  3908. --                                               square meter
  3909. --
  3910.   type CURRENT_DENSITY_AMPERE_PER_SQUARE_METER is new REAL ;
  3911.  
  3912. --
  3913. --                                      3                              3
  3914. --charge density             rho     Q/L         coulomb per        c/m
  3915. --                                               cubic meter
  3916. --
  3917.   type CHARGE_DENSITY_COULOMB_PER_CUBIC_METER is new REAL ;
  3918.  
  3919. --                                     2                                2
  3920. --magnetic flux              F       ML /TQ      weber              Kq m /sec c
  3921. --                                               volt second
  3922. --
  3923.   type MAGNETIC_FLUX_WEBER is new REAL ;
  3924.  
  3925. --
  3926. --magnetic flux density,     B       M/TQ        tesla              Kq/sec c
  3927. --   magnetic induction                          weber per square meter
  3928. --
  3929.   type MAGNETIC_FLUX_DENSITY is new REAL ;
  3930.   subtype MAGNETIC_FLUX_DENSITY_TESLA is MAGNETIC_FLUX_DENSITY ;
  3931.   subtype MAGNETIC_FLUX_DENSITY_WEBER_PER_SQUARE_METER is
  3932.           MAGNETIC_FLUX_DENSITY ;
  3933.  
  3934. --
  3935. --magnetic intensity         H       Q/LT        ampere per meter   c/m sec
  3936. --  magnetic field strength
  3937. --
  3938.   type MAGNETIC_INTENSITY is new REAL ;
  3939.   subtype MAGNETIC_INTENSITY_AMPERE_PER_METER is MAGNETIC_INTENSITY ;
  3940.  
  3941. --
  3942. --
  3943. --magnetic vector potential  A       ML/TQ       weber/meter        Kg m/sec c
  3944. --
  3945.   type MAGNETIC_VECTOR_POTENTIAL_WEBER_PER_METER is new REAL ;
  3946.  
  3947. --
  3948. --                                       2                                  2
  3949. --electric field intensity   E       ML/T Q      volt/meter         Kg m/sec c
  3950. --  electric field strength                      newton per coulomb
  3951. --
  3952.   type ELECTRIC_FIELD is new REAL ;
  3953.   subtype ELECTRIC_FIELD_INTENSITY_VOLT_PER_METER is 
  3954.           ELECTRIC_FIELD ;
  3955.  
  3956. --
  3957. --                                      2                              2
  3958. --electric displacement      D       Q/L         coulomb per        c/m
  3959. --                                               square meter
  3960. --
  3961.   type ELECTRIC_DISPLACEMENT is new REAL ;
  3962.   subtype ELECTRIC_DISPLACEMENT_COULOMB_PER_SQUARE_METER is 
  3963.           ELECTRIC_DISPLACEMENT ;
  3964.  
  3965. --
  3966. --                                       2                                2
  3967. --permeability               mu      ML/Q        henry per meter    Kg m/c
  3968. --
  3969.   type PERMEABILITY is new REAL ;
  3970.   subtype PERMEABILITY_HENRY_PER_METER is PERMEABILITY ;
  3971.  
  3972. --
  3973. --                                    2 2   3                          2 2     3
  3974. --permittivity,              epsi    T Q /ML     farad per meter    sec c /Kg m
  3975. --  dielectric constant
  3976. --
  3977.   type PERMITTIVITY is new REAL ;
  3978.   subtype PERMITTIVITY_FARAD_PER_METER is PERMITTIVITY ;
  3979.   subtype DIELECTRIC_CONSTANT is PERMITTIVITY ;
  3980.  
  3981. --
  3982. --                                                                     -1
  3983. --frequency                  f       Pi/T        hertz              sec
  3984. --
  3985.   type FREQUENCY_HERTZ is new REAL ;
  3986.   type FREQUENCY_KILOHERTZ is new REAL ;
  3987.   type FREQUENCY_MEGAHERTZ is new REAL ;
  3988.   type FREQUENCY_GIGAHERTZ is new REAL ;
  3989.  
  3990. --
  3991. --                                                                     -1
  3992. --angular frequency          omega   1/T         radians per second sec
  3993. --
  3994.   type ANGULAR_FREQUENCY_RADIAN_PER_SECOND is new REAL ;
  3995.  
  3996. --
  3997. end PHYSICAL_UNITS_ELECTRICAL ;
  3998. --------------------------------------------------------------------------------
  3999.  
  4000.  
  4001.  
  4002.  
  4003.  
  4004.  
  4005.  
  4006.  
  4007.  
  4008. --------------------------------------------------------------------------------
  4009. with PHYSICAL_REAL ; use PHYSICAL_REAL ;
  4010.  
  4011. package PHYSICAL_UNITS_OTHER is
  4012.  
  4013. -- This package specification defines Ada types for physical
  4014. -- units that occur as intermediate results.
  4015. -- A number of other packages use this package.
  4016. --
  4017. --
  4018. --   The comments below are organized to present the physical quantity unit with
  4019. --associated information. The first column is the dimension of the physical
  4020. --quantity expressed in terms of the fundamental dimensions. The second column
  4021. --is the typical MKS unit equation. 
  4022. --
  4023. -- DIMENSION   UNIT EQUATION
  4024. -- _________   _____________
  4025. --
  4026. --                TYPES NEEDED FOR COMPUTATIONS
  4027. --
  4028. --    2            2
  4029. --   T          sec
  4030.   type TIME_SECOND_SQUARED is new REAL ;
  4031.  
  4032. --
  4033. --   2  2        2    2
  4034. --  L /T        m /sec
  4035.   type VELOCITY_SQUARED_MKS is new REAL ;
  4036.   subtype VELOCITY_MKS_SQUARED is VELOCITY_SQUARED_MKS ;
  4037.  
  4038. --    2  2            o
  4039. --  ML /T K     joule/ K 
  4040.   type JOULE_PER_DEGREE_KELVIN is new REAL ;
  4041.  
  4042. --
  4043. --    3  2 2
  4044. --  ML /T Q     m/farad
  4045.   type METER_PER_FARAD is new REAL ;
  4046.  
  4047. --
  4048. --   2 4  4 2       2
  4049. --  M L /T Q    volt
  4050.   type VOLT_SQUARED  is new REAL ;
  4051.  
  4052. --
  4053. --   2  2             2
  4054. --  Q /T        ampere
  4055.   type AMPERE_SQUARED is new REAL ;
  4056.  
  4057. --
  4058. --     2
  4059. --  Q/T         ampere/sec
  4060.   type AMPERE_PER_SECOND is new REAL ;
  4061.  
  4062. -- 
  4063. --    2  3
  4064. --  ML /T Q     volt/sec
  4065.   type VOLT_PER_SECOND is new REAL ;
  4066.  
  4067. --
  4068. --   2   2
  4069. --  L /MT
  4070.   type ACCELERATION_PER_KILOGRAM is new REAL ;
  4071.  
  4072. --
  4073. end PHYSICAL_UNITS_OTHER ;
  4074. --------------------------------------------------------------------------------
  4075.  
  4076.  
  4077.  
  4078.  
  4079.  
  4080.  
  4081.  
  4082.  
  4083.  
  4084. --------------------------------------------------------------------------------
  4085. with PHYSICAL_UNITS_BASIC ; use PHYSICAL_UNITS_BASIC ;
  4086.  
  4087. package PHYSICAL_UNITS_OUTPUT_BASIC is
  4088.  
  4089. -- This package specification defines a simple PUT for Ada types for physical
  4090. -- quantities. The initial thought was to have metric units and English units
  4091. -- in separate package specifications. This proved inpractical
  4092. -- because time in seconds is both metric and English. Many other
  4093. -- units such as watt of power and Farad of capacitance are in
  4094. -- both systems. Thus, in order to keep the packages reasonable sizes,
  4095. -- the packages are basic units, mechanical units and electrical units.
  4096. --
  4097. -- Notice that there is not a procedure PUT defined for LENGTH_METER
  4098. -- or for that matter, any " subtype " defined in the package PHYSICAL_UNITS.
  4099. -- It is unnecessary and happens to be illegal ada.
  4100.  
  4101.   procedure PUT ( ITEM : LENGTH_MKS ) ;
  4102.  
  4103.   procedure PUT ( ITEM : LENGTH_ENGLISH ) ;
  4104.  
  4105.   procedure PUT ( ITEM : LENGTH_PICOMETER ) ;
  4106.  
  4107.   procedure PUT ( ITEM : LENGTH_NANOMETER ) ;
  4108.  
  4109.   procedure PUT ( ITEM : LENGTH_MICROMETER ) ;
  4110.  
  4111.   procedure PUT ( ITEM : LENGTH_MILLIMETER ) ;
  4112.  
  4113.   procedure PUT ( ITEM : LENGTH_CENTIMETER ) ;
  4114.  
  4115.   procedure PUT ( ITEM : LENGTH_DECIMETER ) ;
  4116.  
  4117.   procedure PUT ( ITEM : LENGTH_DECAMETER ) ;
  4118.  
  4119.   procedure PUT ( ITEM : LENGTH_HECTOMETER ) ;
  4120.  
  4121.   procedure PUT ( ITEM : LENGTH_KILOMETER ) ;
  4122.  
  4123.   procedure PUT ( ITEM : LENGTH_MEGAMETER ) ;
  4124.  
  4125.   procedure PUT ( ITEM : LENGTH_GIGAMETER ) ;
  4126.  
  4127.   procedure PUT ( ITEM : LENGTH_ANGSTROM ) ;
  4128.  
  4129.   procedure PUT ( ITEM : LENGTH_MIL ) ;
  4130.  
  4131.   procedure PUT ( ITEM : LENGTH_INCH ) ;
  4132.  
  4133.   procedure PUT ( ITEM : LENGTH_YARD ) ;
  4134.  
  4135.   procedure PUT ( ITEM : LENGTH_FATHOM ) ;
  4136.  
  4137.   procedure PUT ( ITEM : LENGTH_ROD ) ;
  4138.  
  4139.   procedure PUT ( ITEM : LENGTH_CHAIN_SURVEYOR ) ;
  4140.  
  4141.   procedure PUT ( ITEM : LENGTH_CHAIN_ENGINEER ) ;
  4142.  
  4143.   procedure PUT ( ITEM : LENGTH_FURLONG ) ;
  4144.  
  4145.   procedure PUT ( ITEM : LENGTH_MILE ) ;
  4146.  
  4147.   procedure PUT ( ITEM : LENGTH_MILE_NAUTICAL ) ;
  4148.  
  4149.   procedure PUT ( ITEM : LENGTH_LEAGUE_LAND ) ;
  4150.  
  4151.   procedure PUT ( ITEM : LENGTH_LEAGUE_MARINE ) ;
  4152.  
  4153.   procedure PUT ( ITEM : LENGTH_LIGHT_YEAR ) ;
  4154.  
  4155.   procedure PUT ( ITEM : MASS_MKS ) ;
  4156.  
  4157.   procedure PUT ( ITEM : MASS_ENGLISH ) ;
  4158.  
  4159.   procedure PUT ( ITEM : MASS_POUND_TROY ) ;
  4160.  
  4161.   procedure PUT ( ITEM : MASS_MILLIGRAM ) ;
  4162.  
  4163.   procedure PUT ( ITEM : MASS_GRAM ) ;
  4164.  
  4165.   procedure PUT ( ITEM : MASS_GRAIN ) ;
  4166.  
  4167.   procedure PUT ( ITEM : MASS_PENNYWEIGHT_TROY ) ;
  4168.  
  4169.   procedure PUT ( ITEM : MASS_CARAT_TROY ) ;
  4170.  
  4171.   procedure PUT ( ITEM : MASS_SCRUPLE ) ;
  4172.  
  4173.   procedure PUT ( ITEM : MASS_DRAM_AVDP ) ;
  4174.  
  4175.   procedure PUT ( ITEM : MASS_OUNCE_AVDP ) ;
  4176.  
  4177.   procedure PUT ( ITEM : MASS_OUNCE_TROY ) ;
  4178.  
  4179.   procedure PUT ( ITEM : MASS_TON_SHORT ) ;
  4180.  
  4181.   procedure PUT ( ITEM : MASS_TON_LONG ) ;
  4182.  
  4183.   procedure PUT ( ITEM : MASS_TON_METRIC ) ;
  4184.  
  4185.   procedure PUT ( ITEM : TIME_SECOND ) ;
  4186.  
  4187.   procedure PUT ( ITEM : TIME_PICOSECOND ) ;
  4188.  
  4189.   procedure PUT ( ITEM : TIME_NANOSECOND ) ;
  4190.  
  4191.   procedure PUT ( ITEM : TIME_MICROSECOND ) ;
  4192.  
  4193.   procedure PUT ( ITEM : TIME_MILLISECOND ) ;
  4194.  
  4195.   procedure PUT ( ITEM : TIME_CENTISECOND ) ;
  4196.  
  4197.   procedure PUT ( ITEM : TIME_KILOSECOND ) ;
  4198.  
  4199.   procedure PUT ( ITEM : TIME_MEGASECOND ) ;
  4200.  
  4201.   procedure PUT ( ITEM : TIME_GIGASECOND ) ;
  4202.  
  4203.   procedure PUT ( ITEM : TIME_MINUTE ) ;
  4204.  
  4205.   procedure PUT ( ITEM : TIME_HOUR ) ;
  4206.  
  4207.   procedure PUT ( ITEM : TIME_DAY ) ;
  4208.  
  4209.   procedure PUT ( ITEM : TIME_FORTNIGHT ) ;
  4210.  
  4211.   procedure PUT ( ITEM : TIME_MONTH ) ;
  4212.  
  4213.   procedure PUT ( ITEM : TIME_YEAR ) ;
  4214.  
  4215.   procedure PUT ( ITEM : TIME_DECADE ) ;
  4216.  
  4217.   procedure PUT ( ITEM : TIME_CENTURY ) ;
  4218.  
  4219.   procedure PUT ( ITEM : TIME_MILLENNIA ) ;
  4220.  
  4221.   procedure PUT ( ITEM : CHARGE_COULOMB ) ;
  4222.  
  4223.   procedure PUT ( ITEM : CHARGE_ELECTRON ) ;
  4224.  
  4225.   procedure PUT ( ITEM : CHARGE_FARADAY ) ;
  4226.  
  4227.   procedure PUT ( ITEM : CHARGE_AMPERE_HOURS ) ;
  4228.  
  4229.   procedure PUT ( ITEM : LUMINOUS_INTENSITY_CANDLE ) ;
  4230.  
  4231.   procedure PUT ( ITEM : TEMPERATURE_KELVIN ) ;
  4232.  
  4233.   procedure PUT ( ITEM : TEMPERATURE_CENTIGRADE ) ;
  4234.  
  4235.   procedure PUT ( ITEM : TEMPERATURE_FARENHEIT ) ;
  4236.  
  4237.   procedure PUT ( ITEM : ANGLE_RADIAN ) ;
  4238.  
  4239.   procedure PUT ( ITEM : ANGLE_SECOND ) ;
  4240.  
  4241.   procedure PUT ( ITEM : ANGLE_MINUTE ) ;
  4242.  
  4243.   procedure PUT ( ITEM : ANGLE_DEGREE ) ;
  4244.  
  4245.   procedure PUT ( ITEM : ANGLE_REVOLUTION ) ;
  4246.  
  4247.   procedure PUT ( ITEM : ANGLE_BAM ) ;
  4248.  
  4249.   procedure PUT ( ITEM : SOLID_ANGLE_STERADIAN ) ;
  4250.  
  4251. end PHYSICAL_UNITS_OUTPUT_BASIC ;
  4252. --------------------------------------------------------------------------------
  4253.  
  4254.  
  4255.  
  4256.  
  4257.  
  4258.  
  4259.  
  4260.  
  4261.  
  4262. --------------------------------------------------------------------------------
  4263. with PHYSICAL_REAL ; use PHYSICAL_REAL ;
  4264. with TEXT_IO ; use TEXT_IO ;
  4265. with LONG_FLT_IO ; use LONG_FLT_IO ;
  4266.  
  4267. package body PHYSICAL_UNITS_OUTPUT_BASIC is
  4268.  
  4269.   procedure PUT ( ITEM : LENGTH_MKS ) is
  4270.  
  4271.   begin
  4272.     PUT ( UNDIMENSION( ITEM )) ;
  4273.     PUT ( " meter " ) ;
  4274.   end PUT ;
  4275.  
  4276.   procedure PUT ( ITEM : LENGTH_ENGLISH ) is
  4277.  
  4278.   begin
  4279.     PUT ( UNDIMENSION( ITEM )) ;
  4280.     PUT ( " feet " ) ;
  4281.   end PUT ;
  4282.  
  4283.   procedure PUT ( ITEM : LENGTH_PICOMETER ) is
  4284.  
  4285.   begin
  4286.     PUT ( UNDIMENSION( ITEM )) ;
  4287.     PUT ( " picometer " ) ;
  4288.   end PUT ;
  4289.  
  4290.   procedure PUT ( ITEM : LENGTH_NANOMETER ) is
  4291.  
  4292.   begin
  4293.     PUT ( UNDIMENSION( ITEM )) ;
  4294.     PUT ( " nanometer " ) ;
  4295.   end PUT ;
  4296.  
  4297.   procedure PUT ( ITEM : LENGTH_MICROMETER ) is
  4298.  
  4299.   begin
  4300.     PUT ( UNDIMENSION( ITEM )) ;
  4301.     PUT ( " micrometer " ) ;
  4302.   end PUT ;
  4303.  
  4304.   procedure PUT ( ITEM : LENGTH_MILLIMETER ) is
  4305.  
  4306.   begin
  4307.     PUT ( UNDIMENSION( ITEM )) ;
  4308.     PUT ( " millimeter " ) ;
  4309.   end PUT ;
  4310.  
  4311.   procedure PUT ( ITEM : LENGTH_CENTIMETER ) is
  4312.  
  4313.   begin
  4314.     PUT ( UNDIMENSION( ITEM )) ;
  4315.     PUT ( " centimeter " ) ;
  4316.   end PUT ;
  4317.  
  4318.   procedure PUT ( ITEM : LENGTH_DECIMETER ) is
  4319.  
  4320.   begin
  4321.     PUT ( UNDIMENSION( ITEM )) ;
  4322.     PUT ( " decimeter " ) ;
  4323.   end PUT ;
  4324.  
  4325.   procedure PUT ( ITEM : LENGTH_DECAMETER ) is
  4326.  
  4327.   begin
  4328.     PUT ( UNDIMENSION( ITEM )) ;
  4329.     PUT ( " decameter " ) ;
  4330.   end PUT ;
  4331.  
  4332.   procedure PUT ( ITEM : LENGTH_HECTOMETER ) is
  4333.  
  4334.   begin
  4335.     PUT ( UNDIMENSION( ITEM )) ;
  4336.     PUT ( " hectometer " ) ;
  4337.   end PUT ;
  4338.  
  4339.   procedure PUT ( ITEM : LENGTH_KILOMETER ) is
  4340.  
  4341.   begin
  4342.     PUT ( UNDIMENSION( ITEM )) ;
  4343.     PUT ( " kilometer " ) ;
  4344.   end PUT ;
  4345.  
  4346.   procedure PUT ( ITEM : LENGTH_MEGAMETER ) is
  4347.  
  4348.   begin
  4349.     PUT ( UNDIMENSION( ITEM )) ;
  4350.     PUT ( " megameter " ) ;
  4351.   end PUT ;
  4352.  
  4353.   procedure PUT ( ITEM : LENGTH_GIGAMETER ) is
  4354.  
  4355.   begin
  4356.     PUT ( UNDIMENSION( ITEM )) ;
  4357.     PUT ( " gigameter " ) ;
  4358.   end PUT ;
  4359.  
  4360.   procedure PUT ( ITEM : LENGTH_ANGSTROM ) is
  4361.  
  4362.   begin
  4363.     PUT ( UNDIMENSION( ITEM )) ;
  4364.     PUT ( " angstrom " ) ;
  4365.   end PUT ;
  4366.  
  4367.   procedure PUT ( ITEM : LENGTH_MIL ) is
  4368.  
  4369.   begin
  4370.     PUT ( UNDIMENSION( ITEM )) ;
  4371.     PUT ( " mil " ) ;
  4372.   end PUT ;
  4373.  
  4374.   procedure PUT ( ITEM : LENGTH_INCH ) is
  4375.  
  4376.   begin
  4377.     PUT ( UNDIMENSION( ITEM )) ;
  4378.     PUT ( " inch " ) ;
  4379.   end PUT ;
  4380.  
  4381.   procedure PUT ( ITEM : LENGTH_YARD ) is
  4382.  
  4383.   begin
  4384.     PUT ( UNDIMENSION( ITEM )) ;
  4385.     PUT ( " yard " ) ;
  4386.   end PUT ;
  4387.  
  4388.   procedure PUT ( ITEM : LENGTH_FATHOM ) is
  4389.  
  4390.   begin
  4391.     PUT ( UNDIMENSION( ITEM )) ;
  4392.     PUT ( " fathom " ) ;
  4393.   end PUT ;
  4394.  
  4395.   procedure PUT ( ITEM : LENGTH_ROD ) is
  4396.  
  4397.   begin
  4398.     PUT ( UNDIMENSION( ITEM )) ;
  4399.     PUT ( " rod " ) ;
  4400.   end PUT ;
  4401.  
  4402.   procedure PUT ( ITEM : LENGTH_CHAIN_SURVEYOR ) is
  4403.  
  4404.   begin
  4405.     PUT ( UNDIMENSION( ITEM )) ;
  4406.     PUT ( " chain (surveyor) " ) ;
  4407.   end PUT ;
  4408.  
  4409.   procedure PUT ( ITEM : LENGTH_CHAIN_ENGINEER ) is
  4410.  
  4411.   begin
  4412.     PUT ( UNDIMENSION( ITEM )) ;
  4413.     PUT ( " chain (engineer) " ) ;
  4414.   end PUT ;
  4415.  
  4416.   procedure PUT ( ITEM : LENGTH_FURLONG ) is
  4417.  
  4418.   begin
  4419.     PUT ( UNDIMENSION( ITEM )) ;
  4420.     PUT ( " furlong " ) ;
  4421.   end PUT ;
  4422.  
  4423.   procedure PUT ( ITEM : LENGTH_MILE ) is
  4424.  
  4425.   begin
  4426.     PUT ( UNDIMENSION( ITEM )) ;
  4427.     PUT ( " mile " ) ;
  4428.   end PUT ;
  4429.  
  4430.   procedure PUT ( ITEM : LENGTH_MILE_NAUTICAL ) is
  4431.  
  4432.   begin
  4433.     PUT ( UNDIMENSION( ITEM )) ;
  4434.     PUT ( " mile (nautical) " ) ;
  4435.   end PUT ;
  4436.  
  4437.   procedure PUT ( ITEM : LENGTH_LEAGUE_LAND ) is
  4438.  
  4439.   begin
  4440.     PUT ( UNDIMENSION( ITEM )) ;
  4441.     PUT ( " league (land) " ) ;
  4442.   end PUT ;
  4443.  
  4444.   procedure PUT ( ITEM : LENGTH_LEAGUE_MARINE ) is
  4445.  
  4446.   begin
  4447.     PUT ( UNDIMENSION( ITEM )) ;
  4448.     PUT ( " league (marine) " ) ;
  4449.   end PUT ;
  4450.  
  4451.   procedure PUT ( ITEM : LENGTH_LIGHT_YEAR ) is
  4452.  
  4453.   begin
  4454.     PUT ( UNDIMENSION( ITEM )) ;
  4455.     PUT ( " light year " ) ;
  4456.   end PUT ;
  4457.  
  4458.   procedure PUT ( ITEM : MASS_MKS ) is
  4459.  
  4460.   begin
  4461.     PUT ( UNDIMENSION( ITEM )) ;
  4462.     PUT ( " kilogram " ) ;
  4463.   end PUT ;
  4464.  
  4465.   procedure PUT ( ITEM : MASS_ENGLISH ) is
  4466.  
  4467.   begin
  4468.     PUT ( UNDIMENSION( ITEM )) ;
  4469.     PUT ( " pound " ) ;
  4470.   end PUT ;
  4471.  
  4472.   procedure PUT ( ITEM : MASS_POUND_TROY ) is
  4473.  
  4474.   begin
  4475.     PUT ( UNDIMENSION( ITEM )) ;
  4476.     PUT ( " pound (troy) " ) ;
  4477.   end PUT ;
  4478.  
  4479.   procedure PUT ( ITEM : MASS_MILLIGRAM ) is
  4480.  
  4481.   begin
  4482.     PUT ( UNDIMENSION( ITEM )) ;
  4483.     PUT ( " milligram " ) ;
  4484.   end PUT ;
  4485.  
  4486.   procedure PUT ( ITEM : MASS_GRAM ) is
  4487.  
  4488.   begin
  4489.     PUT ( UNDIMENSION( ITEM )) ;
  4490.     PUT ( " gram " ) ;
  4491.   end PUT ;
  4492.  
  4493.   procedure PUT ( ITEM : MASS_GRAIN ) is
  4494.  
  4495.   begin
  4496.     PUT ( UNDIMENSION( ITEM )) ;
  4497.     PUT ( " grain " ) ;
  4498.   end PUT ;
  4499.  
  4500.   procedure PUT ( ITEM : MASS_PENNYWEIGHT_TROY ) is
  4501.  
  4502.   begin
  4503.     PUT ( UNDIMENSION( ITEM )) ;
  4504.     PUT ( " pennyweight (troy) " ) ;
  4505.   end PUT ;
  4506.  
  4507.   procedure PUT ( ITEM : MASS_CARAT_TROY ) is
  4508.  
  4509.   begin
  4510.     PUT ( UNDIMENSION( ITEM )) ;
  4511.     PUT ( " carat (troy) " ) ;
  4512.   end PUT ;
  4513.  
  4514.   procedure PUT ( ITEM : MASS_SCRUPLE ) is
  4515.  
  4516.   begin
  4517.     PUT ( UNDIMENSION( ITEM )) ;
  4518.     PUT ( " scruple " ) ;
  4519.   end PUT ;
  4520.  
  4521.   procedure PUT ( ITEM : MASS_DRAM_AVDP ) is
  4522.  
  4523.   begin
  4524.     PUT ( UNDIMENSION( ITEM )) ;
  4525.     PUT ( " dram (avdp.) " ) ;
  4526.   end PUT ;
  4527.  
  4528.   procedure PUT ( ITEM : MASS_OUNCE_AVDP ) is
  4529.  
  4530.   begin
  4531.     PUT ( UNDIMENSION( ITEM )) ;
  4532.     PUT ( " ounce " ) ;
  4533.   end PUT ;
  4534.  
  4535.   procedure PUT ( ITEM : MASS_OUNCE_TROY ) is
  4536.  
  4537.   begin
  4538.     PUT ( UNDIMENSION( ITEM )) ;
  4539.     PUT ( " ounce (troy) " ) ;
  4540.   end PUT ;
  4541.  
  4542.   procedure PUT ( ITEM : MASS_TON_SHORT ) is
  4543.  
  4544.   begin
  4545.     PUT ( UNDIMENSION( ITEM )) ;
  4546.     PUT ( " ton (short) " ) ;
  4547.   end PUT ;
  4548.  
  4549.   procedure PUT ( ITEM : MASS_TON_LONG ) is
  4550.  
  4551.   begin
  4552.     PUT ( UNDIMENSION( ITEM )) ;
  4553.     PUT ( " ton (long) " ) ;
  4554.   end PUT ;
  4555.  
  4556.   procedure PUT ( ITEM : MASS_TON_METRIC ) is
  4557.  
  4558.   begin
  4559.     PUT ( UNDIMENSION( ITEM )) ;
  4560.     PUT ( " ton (metric) " ) ;
  4561.   end PUT ;
  4562.  
  4563.   procedure PUT ( ITEM : TIME_SECOND ) is
  4564.  
  4565.   begin
  4566.     PUT ( UNDIMENSION( ITEM )) ;
  4567.     PUT ( " second " ) ;
  4568.   end PUT ;
  4569.  
  4570.   procedure PUT ( ITEM : TIME_PICOSECOND ) is
  4571.  
  4572.   begin
  4573.     PUT ( UNDIMENSION( ITEM )) ;
  4574.     PUT ( " picosecond " ) ;
  4575.   end PUT ;
  4576.  
  4577.   procedure PUT ( ITEM : TIME_NANOSECOND ) is
  4578.  
  4579.   begin
  4580.     PUT ( UNDIMENSION( ITEM )) ;
  4581.     PUT ( " nanosecond " ) ;
  4582.   end PUT ;
  4583.  
  4584.   procedure PUT ( ITEM : TIME_MICROSECOND ) is
  4585.  
  4586.   begin
  4587.     PUT ( UNDIMENSION( ITEM )) ;
  4588.     PUT ( " microsecond " ) ;
  4589.   end PUT ;
  4590.  
  4591.   procedure PUT ( ITEM : TIME_MILLISECOND ) is
  4592.  
  4593.   begin
  4594.     PUT ( UNDIMENSION( ITEM )) ;
  4595.     PUT ( " millisecond " ) ;
  4596.   end PUT ;
  4597.  
  4598.   procedure PUT ( ITEM : TIME_CENTISECOND ) is
  4599.  
  4600.   begin
  4601.     PUT ( UNDIMENSION( ITEM )) ;
  4602.     PUT ( " centisecond " ) ;
  4603.   end PUT ;
  4604.  
  4605.   procedure PUT ( ITEM : TIME_KILOSECOND ) is
  4606.  
  4607.   begin
  4608.     PUT ( UNDIMENSION( ITEM )) ;
  4609.     PUT ( " kilosecond " ) ;
  4610.   end PUT ;
  4611.  
  4612.   procedure PUT ( ITEM : TIME_MEGASECOND ) is
  4613.  
  4614.   begin
  4615.     PUT ( UNDIMENSION( ITEM )) ;
  4616.     PUT ( " megasecond " ) ;
  4617.   end PUT ;
  4618.  
  4619.   procedure PUT ( ITEM : TIME_GIGASECOND ) is
  4620.  
  4621.   begin
  4622.     PUT ( UNDIMENSION( ITEM )) ;
  4623.     PUT ( " gigasecond " ) ;
  4624.   end PUT ;
  4625.  
  4626.   procedure PUT ( ITEM : TIME_MINUTE ) is
  4627.  
  4628.   begin
  4629.     PUT ( UNDIMENSION( ITEM )) ;
  4630.     PUT ( " minute " ) ;
  4631.   end PUT ;
  4632.  
  4633.   procedure PUT ( ITEM : TIME_HOUR ) is
  4634.  
  4635.   begin
  4636.     PUT ( UNDIMENSION( ITEM )) ;
  4637.     PUT ( " hour " ) ;
  4638.   end PUT ;
  4639.  
  4640.   procedure PUT ( ITEM : TIME_DAY ) is
  4641.  
  4642.   begin
  4643.     PUT ( UNDIMENSION( ITEM )) ;
  4644.     PUT ( " day " ) ;
  4645.   end PUT ;
  4646.  
  4647.   procedure PUT ( ITEM : TIME_FORTNIGHT ) is
  4648.  
  4649.   begin
  4650.     PUT ( UNDIMENSION( ITEM )) ;
  4651.     PUT ( " fortnight " ) ;
  4652.   end PUT ;
  4653.  
  4654.   procedure PUT ( ITEM : TIME_MONTH ) is
  4655.  
  4656.   begin
  4657.     PUT ( UNDIMENSION( ITEM )) ;
  4658.     PUT ( " month " ) ;
  4659.   end PUT ;
  4660.  
  4661.   procedure PUT ( ITEM : TIME_YEAR ) is
  4662.  
  4663.   begin
  4664.     PUT ( UNDIMENSION( ITEM )) ;
  4665.     PUT ( " year " ) ;
  4666.   end PUT ;
  4667.  
  4668.   procedure PUT ( ITEM : TIME_DECADE ) is
  4669.  
  4670.   begin
  4671.     PUT ( UNDIMENSION( ITEM )) ;
  4672.     PUT ( " decade " ) ;
  4673.   end PUT ;
  4674.  
  4675.   procedure PUT ( ITEM : TIME_CENTURY ) is
  4676.  
  4677.   begin
  4678.     PUT ( UNDIMENSION( ITEM )) ;
  4679.     PUT ( " century " ) ;
  4680.   end PUT ;
  4681.  
  4682.   procedure PUT ( ITEM : TIME_MILLENNIA ) is
  4683.  
  4684.   begin
  4685.     PUT ( UNDIMENSION( ITEM )) ;
  4686.     PUT ( " millennia " ) ;
  4687.   end PUT ;
  4688.  
  4689.   procedure PUT ( ITEM : CHARGE_COULOMB ) is
  4690.  
  4691.   begin
  4692.     PUT ( UNDIMENSION( ITEM )) ;
  4693.     PUT ( " coulomb " ) ;
  4694.   end PUT ;
  4695.  
  4696.   procedure PUT ( ITEM : CHARGE_ELECTRON ) is
  4697.  
  4698.   begin
  4699.     PUT ( UNDIMENSION( ITEM )) ;
  4700.     PUT ( " charge (electron) " ) ;
  4701.   end PUT ;
  4702.  
  4703.   procedure PUT ( ITEM : CHARGE_FARADAY ) is
  4704.  
  4705.   begin
  4706.     PUT ( UNDIMENSION( ITEM )) ;
  4707.     PUT ( " faraday " ) ;
  4708.   end PUT ;
  4709.  
  4710.   procedure PUT ( ITEM : CHARGE_AMPERE_HOURS ) is
  4711.  
  4712.   begin
  4713.     PUT ( UNDIMENSION( ITEM )) ;
  4714.     PUT ( " ampere hour " ) ;
  4715.  
  4716.  
  4717.   end PUT ;
  4718.  
  4719.   procedure PUT ( ITEM : LUMINOUS_INTENSITY_CANDLE ) is
  4720.  
  4721.   begin
  4722.     PUT ( UNDIMENSION( ITEM )) ;
  4723.     PUT ( " candel " ) ;
  4724.   end PUT ;
  4725.  
  4726.   procedure PUT ( ITEM : TEMPERATURE_KELVIN ) is
  4727.  
  4728.   begin
  4729.     PUT ( UNDIMENSION( ITEM )) ;
  4730.     PUT ( " degree kelvin " ) ;
  4731.   end PUT ;
  4732.  
  4733.   procedure PUT ( ITEM : TEMPERATURE_CENTIGRADE ) is
  4734.  
  4735.   begin
  4736.     PUT ( UNDIMENSION( ITEM )) ;
  4737.     PUT ( " degree centigrade " ) ;
  4738.   end PUT ;
  4739.  
  4740.   procedure PUT ( ITEM : TEMPERATURE_FARENHEIT ) is
  4741.  
  4742.   begin
  4743.     PUT ( UNDIMENSION( ITEM )) ;
  4744.     PUT ( " degree farenheit " ) ;
  4745.   end PUT ;
  4746.  
  4747.   procedure PUT ( ITEM : ANGLE_RADIAN ) is
  4748.  
  4749.   begin
  4750.     PUT ( UNDIMENSION( ITEM )) ;
  4751.     PUT ( " radian " ) ;
  4752.   end PUT ;
  4753.  
  4754.   procedure PUT ( ITEM : ANGLE_SECOND ) is
  4755.  
  4756.   begin
  4757.     PUT ( UNDIMENSION( ITEM )) ;
  4758.     PUT ( " second (angle) " ) ;
  4759.   end PUT ;
  4760.  
  4761.   procedure PUT ( ITEM : ANGLE_MINUTE ) is
  4762.  
  4763.   begin
  4764.     PUT ( UNDIMENSION( ITEM )) ;
  4765.     PUT ( " minute ( angle) " ) ;
  4766.   end PUT ;
  4767.  
  4768.   procedure PUT ( ITEM : ANGLE_DEGREE ) is
  4769.  
  4770.   begin
  4771.     PUT ( UNDIMENSION( ITEM )) ;
  4772.     PUT ( " degree (angle) " ) ;
  4773.   end PUT ;
  4774.  
  4775.   procedure PUT ( ITEM : ANGLE_REVOLUTION ) is
  4776.  
  4777.   begin
  4778.     PUT ( UNDIMENSION( ITEM )) ;
  4779.     PUT ( " revolution " ) ;
  4780.   end PUT ;
  4781.  
  4782.   procedure PUT ( ITEM : ANGLE_BAM ) is
  4783.  
  4784.   begin
  4785.     PUT ( UNDIMENSION( ITEM )) ;
  4786.     PUT ( " bam " ) ;
  4787.   end PUT ;
  4788.  
  4789.   procedure PUT ( ITEM : SOLID_ANGLE_STERADIAN ) is
  4790.  
  4791.   begin
  4792.     PUT ( UNDIMENSION( ITEM )) ;
  4793.     PUT ( " steradian " ) ;
  4794.   end PUT ;
  4795.  
  4796. end PHYSICAL_UNITS_OUTPUT_BASIC ;
  4797. --------------------------------------------------------------------------------
  4798.  
  4799.  
  4800.  
  4801.  
  4802.  
  4803.  
  4804.  
  4805.  
  4806.  
  4807. --------------------------------------------------------------------------------
  4808. with PHYSICAL_UNITS_MECHANICAL ; use PHYSICAL_UNITS_MECHANICAL ;
  4809.  
  4810. package PHYSICAL_UNITS_OUTPUT_MECHANICAL is
  4811.  
  4812. -- This package specification defines a simple PUT for Ada types for physical
  4813. -- quantities generally mechanical in nature.
  4814. --
  4815. -- Notice that there is not a procedure PUT defined for LENGTH_METER
  4816. -- or for that matter, any " subtype " defined in the package PHYSICAL_UNITS.
  4817. -- It is unnecessary and happens to be illegal ada.
  4818.  
  4819.   procedure PUT ( ITEM : AREA_MKS ) ;
  4820.  
  4821.   procedure PUT ( ITEM : AREA_ENGLISH ) ;
  4822.  
  4823.   procedure PUT ( ITEM : AREA_SQUARE_CENTIMETER ) ;
  4824.  
  4825.   procedure PUT ( ITEM : AREA_SQUARE_KILOMETER ) ;
  4826.  
  4827.   procedure PUT ( ITEM : AREA_SQUARE_INCH ) ;
  4828.  
  4829.   procedure PUT ( ITEM : AREA_SQUARE_YARD ) ;
  4830.  
  4831.   procedure PUT ( ITEM : AREA_SQUARE_MILE ) ;
  4832.  
  4833.   procedure PUT ( ITEM : AREA_ACRE ) ;
  4834.  
  4835.   procedure PUT ( ITEM : AREA_CIRCULAR_MIL ) ;
  4836.  
  4837.   procedure PUT ( ITEM : AREA_HECTARE ) ;
  4838.  
  4839.   procedure PUT ( ITEM : AREA_TOWNSHIP ) ;
  4840.  
  4841.   procedure PUT ( ITEM : VOLUME_MKS ) ;
  4842.  
  4843.   procedure PUT ( ITEM : VOLUME_ENGLISH ) ;
  4844.  
  4845.   procedure PUT ( ITEM : VOLUME_MILLILITER ) ;
  4846.  
  4847.   procedure PUT ( ITEM : VOLUME_LITER ) ;
  4848.  
  4849.   procedure PUT ( ITEM : VOLUME_KILOLITER ) ;
  4850.  
  4851.   procedure PUT ( ITEM : VOLUME_CUBIC_CENTIMETER ) ;
  4852.  
  4853.   procedure PUT ( ITEM : VOLUME_CUBIC_INCH ) ;
  4854.  
  4855.   procedure PUT ( ITEM : VOLUME_CUBIC_YARD ) ;
  4856.  
  4857.   procedure PUT ( ITEM : VOLUME_CUBIC_MILE ) ;
  4858.  
  4859.   procedure PUT ( ITEM : VOLUME_TEASPOON ) ;
  4860.  
  4861.   procedure PUT ( ITEM : VOLUME_TABLESPOON ) ;
  4862.  
  4863.   procedure PUT ( ITEM : VOLUME_OUNCE_FLUID ) ;
  4864.  
  4865.   procedure PUT ( ITEM : VOLUME_JIGGER ) ;
  4866.  
  4867.   procedure PUT ( ITEM : VOLUME_CUP ) ;
  4868.  
  4869.   procedure PUT ( ITEM : VOLUME_PINT_LIQUID ) ;
  4870.  
  4871.   procedure PUT ( ITEM : VOLUME_QUART_LIQUID ) ;
  4872.  
  4873.   procedure PUT ( ITEM : VOLUME_GALLON ) ;
  4874.  
  4875.   procedure PUT ( ITEM : VOLUME_KEG ) ;
  4876.  
  4877.   procedure PUT ( ITEM : VOLUME_BARREL ) ;
  4878.  
  4879.   procedure PUT ( ITEM : VOLUME_PINT_DRY ) ;
  4880.  
  4881.   procedure PUT ( ITEM : VOLUME_QUART_DRY ) ;
  4882.  
  4883.   procedure PUT ( ITEM : VOLUME_PECK ) ;
  4884.  
  4885.   procedure PUT ( ITEM : VOLUME_BUSHEL ) ;
  4886.  
  4887.   procedure PUT ( ITEM : VOLUME_CORD ) ;
  4888.  
  4889.   procedure PUT ( ITEM : VELOCITY_MKS ) ;
  4890.  
  4891.   procedure PUT ( ITEM : VELOCITY_ENGLISH ) ;
  4892.  
  4893.   procedure PUT ( ITEM : VELOCITY_CENTIMETER_PER_SECOND ) ;
  4894.  
  4895.   procedure PUT ( ITEM : VELOCITY_KILOMETER_PER_HOUR ) ;
  4896.  
  4897.   procedure PUT ( ITEM : VELOCITY_INCHES_PER_SECOND ) ;
  4898.  
  4899.   procedure PUT ( ITEM : VELOCITY_MILE_PER_HOUR ) ;
  4900.  
  4901.   procedure PUT ( ITEM : VELOCITY_MILES_PER_SECOND ) ;
  4902.  
  4903.   procedure PUT ( ITEM : VELOCITY_INCHES_PER_MINUTE ) ;
  4904.  
  4905.   procedure PUT ( ITEM : VELOCITY_FEET_PER_MINUTE ) ;
  4906.  
  4907.   procedure PUT ( ITEM : VELOCITY_MILES_PER_HOUR ) ;
  4908.  
  4909.   procedure PUT ( ITEM : VELOCITY_KNOTS ) ;
  4910.  
  4911.   procedure PUT ( ITEM : VELOCITY_FURLONG_PER_FORTNIGHT ) ;
  4912.  
  4913.   procedure PUT ( ITEM : ANGULAR_VELOCITY ) ;
  4914.  
  4915.   procedure PUT ( ITEM : ANGULAR_VELOCITY_DEGREES_PER_SECOND ) ;
  4916.  
  4917.   procedure PUT ( ITEM : ANGULAR_VELOCITY_REVOLUTIONS_PER_MINUTE ) ;
  4918.  
  4919.   procedure PUT ( ITEM : ANGULAR_VELOCITY_REVOLUTIONS_PER_SECOND ) ;
  4920.  
  4921.   procedure PUT ( ITEM : ACCELERATION_MKS ) ;
  4922.  
  4923.   procedure PUT ( ITEM : ACCELERATION_ENGLISH ) ;
  4924.  
  4925.   procedure PUT ( ITEM : ANGULAR_ACCELERATION ) ;
  4926.  
  4927.   procedure PUT ( ITEM : ANGULAR_ACCELERATION_REVOLUTIONS_PER_MINUTE_SQUARED )
  4928.       ;
  4929.  
  4930.   procedure PUT ( ITEM : FORCE_MKS ) ;
  4931.  
  4932.   procedure PUT ( ITEM : FORCE_DYNE ) ;
  4933.  
  4934.   procedure PUT ( ITEM : FORCE_ENGLISH ) ;
  4935.  
  4936.   procedure PUT ( ITEM : ENERGY_MKS ) ;
  4937.  
  4938.   procedure PUT ( ITEM : ENERGY_ERG ) ;
  4939.  
  4940.   procedure PUT ( ITEM : ENERGY_GRAM_CALORIE ) ;
  4941.  
  4942.   procedure PUT ( ITEM : ENERGY_KILOGRAM_CALORIE ) ;
  4943.  
  4944.   procedure PUT ( ITEM : ENERGY_B_T_U ) ;
  4945.  
  4946.   procedure PUT ( ITEM : ENERGY_FOOT_POUND ) ;
  4947.  
  4948.   procedure PUT ( ITEM : ENERGY_KILOWATT_HOUR ) ;
  4949.  
  4950.   procedure PUT ( ITEM : ENERGY_HORSEPOWER_HOUR ) ;
  4951.  
  4952.   procedure PUT ( ITEM : POWER_MKS ) ;
  4953.  
  4954.   procedure PUT ( ITEM : POWER_KILOGRAM_CALORIE_PER_SECOND ) ;
  4955.  
  4956.   procedure PUT ( ITEM : POWER_KILOGRAN_CALORIE_PER_MINUTE ) ;
  4957.  
  4958.   procedure PUT ( ITEM : POWER_HORSEPOWER_MECHANICAL ) ;
  4959.  
  4960.   procedure PUT ( ITEM : POWER_HORSEPOWER_ELECTRICAL ) ;
  4961.  
  4962.   procedure PUT ( ITEM : POWER_HORSEPOWER_METRIC ) ;
  4963.  
  4964.   procedure PUT ( ITEM : POWER_HORSEPOWER_BOILER ) ;
  4965.  
  4966.   procedure PUT ( ITEM : POWER_B_T_U_PER_MINUTE ) ;
  4967.  
  4968.   procedure PUT ( ITEM : POWER_B_T_U_PER_HOUR ) ;
  4969.  
  4970.   procedure PUT ( ITEM : POWER_FOOT_POUND_PER_MINUTE ) ;
  4971.  
  4972.   procedure PUT ( ITEM : POWER_FOOT_POUND_PER_SECOND ) ;
  4973.  
  4974.   procedure PUT ( ITEM : DENSITY_MKS ) ;
  4975.  
  4976.   procedure PUT ( ITEM : DENSITY_ENGLISH ) ;
  4977.  
  4978.   procedure PUT ( ITEM : FLOW_RATE_MKS ) ;
  4979.  
  4980.   procedure PUT ( ITEM : FLOW_RATE_GALLON_PER_MINUTE ) ;
  4981.  
  4982.   procedure PUT ( ITEM : FLOW_RATE_ENGLISH ) ;
  4983.  
  4984.   procedure PUT ( ITEM : FLOW_RATE_CUBIC_FEET_PER_MINUTE ) ;
  4985.  
  4986.   procedure PUT ( ITEM : PRESSURE_MKS ) ;
  4987.  
  4988.   procedure PUT ( ITEM : PRESSURE_ENGLISH ) ;
  4989.  
  4990.   procedure PUT ( ITEM : PRESSURE_TON_PER_SQUARE_FOOT ) ;
  4991.  
  4992.   procedure PUT ( ITEM : PRESSURE_ATMOSPHERE_STANDARD ) ;
  4993.  
  4994.   procedure PUT ( ITEM : PRESSURE_FEET_OF_WATER ) ;
  4995.  
  4996.   procedure PUT ( ITEM : PRESSURE_INCHES_OF_MERCURY ) ;
  4997.  
  4998.   procedure PUT ( ITEM : PRESSURE_MILLIMETER_OF_MERCURY ) ;
  4999.  
  5000.   procedure PUT ( ITEM : PRESSURE_BAR ) ;
  5001.  
  5002.   procedure PUT ( ITEM : PRESSURE_MILLIBAR ) ;
  5003.  
  5004.   procedure PUT ( ITEM : PRESSURE_TORR ) ;
  5005.  
  5006.   procedure PUT ( ITEM : MOMENTUM_MKS ) ;
  5007.  
  5008.   procedure PUT ( ITEM : INERTIA_MKS ) ;
  5009.  
  5010.   procedure PUT ( ITEM : MOMENT_OF_INERTIA_MKS ) ;
  5011.  
  5012.   procedure PUT ( ITEM : KINEMATIC_VISCOSITY_MKS ) ;
  5013.  
  5014.   procedure PUT ( ITEM : DYNAMIC_VISCOSITY_MKS ) ;
  5015.  
  5016.   procedure PUT ( ITEM : LUMINOUS_FLUX_LUMEN ) ;
  5017.  
  5018.   procedure PUT ( ITEM : ILLUMINATION_MKS ) ;
  5019.  
  5020.   procedure PUT ( ITEM : LUMINANCE_MKS ) ;
  5021.  
  5022.   procedure PUT ( ITEM : ENTROPY_MKS ) ;
  5023.  
  5024.   procedure PUT ( ITEM : SPECIFIC_HEAT_B_T_U_PER_POUND_DEGREE_FARENHEIT ) ;
  5025.  
  5026. end PHYSICAL_UNITS_OUTPUT_MECHANICAL ;
  5027. --------------------------------------------------------------------------------
  5028.  
  5029.  
  5030.  
  5031.  
  5032.  
  5033.  
  5034.  
  5035.  
  5036.  
  5037. --------------------------------------------------------------------------------
  5038. with PHYSICAL_REAL ; use PHYSICAL_REAL ;
  5039. with TEXT_IO ; use TEXT_IO ;
  5040. with LONG_FLT_IO ; use LONG_FLT_IO ;
  5041.  
  5042. package body PHYSICAL_UNITS_OUTPUT_MECHANICAL is
  5043.  
  5044.   procedure PUT ( ITEM : AREA_MKS ) is
  5045.  
  5046.   begin
  5047.     PUT ( UNDIMENSION( ITEM )) ;
  5048.     PUT ( " square meter" ) ;
  5049.   end PUT ;
  5050.  
  5051.   procedure PUT ( ITEM : AREA_ENGLISH ) is
  5052.  
  5053.   begin
  5054.     PUT ( UNDIMENSION( ITEM )) ;
  5055.     PUT ( " square foot " ) ;
  5056.   end PUT ;
  5057.  
  5058.   procedure PUT ( ITEM : AREA_SQUARE_CENTIMETER ) is
  5059.  
  5060.   begin
  5061.     PUT ( UNDIMENSION( ITEM )) ;
  5062.     PUT ( " square centimeter " ) ;
  5063.   end PUT ;
  5064.  
  5065.   procedure PUT ( ITEM : AREA_SQUARE_KILOMETER ) is
  5066.  
  5067.   begin
  5068.     PUT ( UNDIMENSION( ITEM )) ;
  5069.     PUT ( " square kilometer " ) ;
  5070.   end PUT ;
  5071.  
  5072.   procedure PUT ( ITEM : AREA_SQUARE_INCH ) is
  5073.  
  5074.   begin
  5075.     PUT ( UNDIMENSION( ITEM )) ;
  5076.     PUT ( " square inch " ) ;
  5077.   end PUT ;
  5078.  
  5079.   procedure PUT ( ITEM : AREA_SQUARE_YARD ) is
  5080.  
  5081.   begin
  5082.     PUT ( UNDIMENSION( ITEM )) ;
  5083.     PUT ( " square yard " ) ;
  5084.   end PUT ;
  5085.  
  5086.   procedure PUT ( ITEM : AREA_SQUARE_MILE ) is
  5087.  
  5088.   begin
  5089.     PUT ( UNDIMENSION( ITEM )) ;
  5090.     PUT ( " square mile " ) ;
  5091.   end PUT ;
  5092.  
  5093.   procedure PUT ( ITEM : AREA_ACRE ) is
  5094.  
  5095.   begin
  5096.     PUT ( UNDIMENSION( ITEM )) ;
  5097.     PUT ( " acre " ) ;
  5098.   end PUT ;
  5099.  
  5100.   procedure PUT ( ITEM : AREA_CIRCULAR_MIL ) is
  5101.  
  5102.   begin
  5103.     PUT ( UNDIMENSION( ITEM )) ;
  5104.     PUT ( " circular mil " ) ;
  5105.   end PUT ;
  5106.  
  5107.   procedure PUT ( ITEM : AREA_HECTARE ) is
  5108.  
  5109.   begin
  5110.     PUT ( UNDIMENSION( ITEM )) ;
  5111.     PUT ( " hectare " ) ;
  5112.   end PUT ;
  5113.  
  5114.   procedure PUT ( ITEM : AREA_TOWNSHIP ) is
  5115.  
  5116.   begin
  5117.     PUT ( UNDIMENSION( ITEM )) ;
  5118.     PUT ( " township " ) ;
  5119.   end PUT ;
  5120.  
  5121.   procedure PUT ( ITEM : VOLUME_MKS ) is
  5122.  
  5123.   begin
  5124.     PUT ( UNDIMENSION( ITEM )) ;
  5125.     PUT ( " cubic meter " ) ;
  5126.   end PUT ;
  5127.  
  5128.   procedure PUT ( ITEM : VOLUME_ENGLISH ) is
  5129.  
  5130.   begin
  5131.     PUT ( UNDIMENSION( ITEM )) ;
  5132.     PUT ( " cubic foot " ) ;
  5133.   end PUT ;
  5134.  
  5135.   procedure PUT ( ITEM : VOLUME_MILLILITER ) is
  5136.  
  5137.   begin
  5138.     PUT ( UNDIMENSION( ITEM )) ;
  5139.     PUT ( " milliliter " ) ;
  5140.   end PUT ;
  5141.  
  5142.   procedure PUT ( ITEM : VOLUME_LITER ) is
  5143.  
  5144.   begin
  5145.     PUT ( UNDIMENSION( ITEM )) ;
  5146.     PUT ( " liter " ) ;
  5147.   end PUT ;
  5148.  
  5149.   procedure PUT ( ITEM : VOLUME_KILOLITER ) is
  5150.  
  5151.   begin
  5152.     PUT ( UNDIMENSION( ITEM )) ;
  5153.     PUT ( " kiloliter " ) ;
  5154.   end PUT ;
  5155.  
  5156.   procedure PUT ( ITEM : VOLUME_CUBIC_CENTIMETER ) is
  5157.  
  5158.   begin
  5159.     PUT ( UNDIMENSION( ITEM )) ;
  5160.     PUT ( " cubic centimeter " ) ;
  5161.   end PUT ;
  5162.  
  5163.   procedure PUT ( ITEM : VOLUME_CUBIC_INCH ) is
  5164.  
  5165.   begin
  5166.     PUT ( UNDIMENSION( ITEM )) ;
  5167.     PUT ( " cubic inch " ) ;
  5168.   end PUT ;
  5169.  
  5170.   procedure PUT ( ITEM : VOLUME_CUBIC_YARD ) is
  5171.  
  5172.   begin
  5173.     PUT ( UNDIMENSION( ITEM )) ;
  5174.     PUT ( " cubic yard " ) ;
  5175.   end PUT ;
  5176.  
  5177.   procedure PUT ( ITEM : VOLUME_CUBIC_MILE ) is
  5178.  
  5179.   begin
  5180.     PUT ( UNDIMENSION( ITEM )) ;
  5181.     PUT ( " cubic mile " ) ;
  5182.   end PUT ;
  5183.  
  5184.   procedure PUT ( ITEM : VOLUME_TEASPOON ) is
  5185.  
  5186.   begin
  5187.     PUT ( UNDIMENSION( ITEM )) ;
  5188.     PUT ( " teaspoon " ) ;
  5189.   end PUT ;
  5190.  
  5191.   procedure PUT ( ITEM : VOLUME_TABLESPOON ) is
  5192.  
  5193.   begin
  5194.     PUT ( UNDIMENSION( ITEM )) ;
  5195.     PUT ( " tablespoon " ) ;
  5196.   end PUT ;
  5197.  
  5198.   procedure PUT ( ITEM : VOLUME_OUNCE_FLUID ) is
  5199.  
  5200.   begin
  5201.     PUT ( UNDIMENSION( ITEM )) ;
  5202.     PUT ( " ounce (fluid) " ) ;
  5203.   end PUT ;
  5204.  
  5205.   procedure PUT ( ITEM : VOLUME_JIGGER ) is
  5206.  
  5207.   begin
  5208.     PUT ( UNDIMENSION( ITEM )) ;
  5209.     PUT ( " jigger " ) ;
  5210.   end PUT ;
  5211.  
  5212.   procedure PUT ( ITEM : VOLUME_CUP ) is
  5213.  
  5214.   begin
  5215.     PUT ( UNDIMENSION( ITEM )) ;
  5216.     PUT ( " cup " ) ;
  5217.   end PUT ;
  5218.  
  5219.   procedure PUT ( ITEM : VOLUME_PINT_LIQUID ) is
  5220.  
  5221.   begin
  5222.     PUT ( UNDIMENSION( ITEM )) ;
  5223.     PUT ( " pint (liquid) " ) ;
  5224.   end PUT ;
  5225.  
  5226.   procedure PUT ( ITEM : VOLUME_QUART_LIQUID ) is
  5227.  
  5228.   begin
  5229.     PUT ( UNDIMENSION( ITEM )) ;
  5230.     PUT ( " quart (liquid) " ) ;
  5231.   end PUT ;
  5232.  
  5233.   procedure PUT ( ITEM : VOLUME_GALLON ) is
  5234.  
  5235.   begin
  5236.     PUT ( UNDIMENSION( ITEM )) ;
  5237.     PUT ( " gallon " ) ;
  5238.   end PUT ;
  5239.  
  5240.   procedure PUT ( ITEM : VOLUME_KEG ) is
  5241.  
  5242.   begin
  5243.     PUT ( UNDIMENSION( ITEM )) ;
  5244.     PUT ( " keg " ) ;
  5245.   end PUT ;
  5246.  
  5247.   procedure PUT ( ITEM : VOLUME_BARREL ) is
  5248.  
  5249.   begin
  5250.     PUT ( UNDIMENSION( ITEM )) ;
  5251.     PUT ( " barrel " ) ;
  5252.   end PUT ;
  5253.  
  5254.   procedure PUT ( ITEM : VOLUME_PINT_DRY ) is
  5255.  
  5256.   begin
  5257.     PUT ( UNDIMENSION( ITEM )) ;
  5258.     PUT ( " pint (dry) " ) ;
  5259.   end PUT ;
  5260.  
  5261.   procedure PUT ( ITEM : VOLUME_QUART_DRY ) is
  5262.  
  5263.   begin
  5264.     PUT ( UNDIMENSION( ITEM )) ;
  5265.     PUT ( " quart (dry) " ) ;
  5266.   end PUT ;
  5267.  
  5268.   procedure PUT ( ITEM : VOLUME_PECK ) is
  5269.  
  5270.   begin
  5271.     PUT ( UNDIMENSION( ITEM )) ;
  5272.     PUT ( " peck " ) ;
  5273.   end PUT ;
  5274.  
  5275.   procedure PUT ( ITEM : VOLUME_BUSHEL ) is
  5276.  
  5277.   begin
  5278.     PUT ( UNDIMENSION( ITEM )) ;
  5279.     PUT ( " bushel " ) ;
  5280.   end PUT ;
  5281.  
  5282.   procedure PUT ( ITEM : VOLUME_CORD ) is
  5283.  
  5284.   begin
  5285.     PUT ( UNDIMENSION( ITEM )) ;
  5286.     PUT ( " cord " ) ;
  5287.   end PUT ;
  5288.  
  5289.   procedure PUT ( ITEM : VELOCITY_MKS ) is
  5290.  
  5291.   begin
  5292.     PUT ( UNDIMENSION( ITEM )) ;
  5293.     PUT ( " meter per second " ) ;
  5294.   end PUT ;
  5295.  
  5296.   procedure PUT ( ITEM : VELOCITY_ENGLISH ) is
  5297.  
  5298.   begin
  5299.     PUT ( UNDIMENSION( ITEM )) ;
  5300.     PUT ( " foot per second " ) ;
  5301.   end PUT ;
  5302.  
  5303.   procedure PUT ( ITEM : VELOCITY_CENTIMETER_PER_SECOND ) is
  5304.  
  5305.   begin
  5306.     PUT ( UNDIMENSION( ITEM )) ;
  5307.     PUT ( " centimeter per second " ) ;
  5308.   end PUT ;
  5309.  
  5310.   procedure PUT ( ITEM : VELOCITY_KILOMETER_PER_HOUR ) is
  5311.  
  5312.   begin
  5313.     PUT ( UNDIMENSION( ITEM )) ;
  5314.     PUT ( " kilometer per hour " ) ;
  5315.   end PUT ;
  5316.  
  5317.   procedure PUT ( ITEM : VELOCITY_INCHES_PER_SECOND ) is
  5318.  
  5319.   begin
  5320.     PUT ( UNDIMENSION( ITEM )) ;
  5321.     PUT ( " inches per second " ) ;
  5322.   end PUT ;
  5323.  
  5324.   procedure PUT ( ITEM : VELOCITY_MILE_PER_HOUR ) is
  5325.  
  5326.   begin
  5327.     PUT ( UNDIMENSION( ITEM )) ;
  5328.     PUT ( " mile per hour " ) ;
  5329.   end PUT ;
  5330.  
  5331.   procedure PUT ( ITEM : VELOCITY_MILES_PER_SECOND ) is
  5332.  
  5333.   begin
  5334.     PUT ( UNDIMENSION( ITEM )) ;
  5335.     PUT ( " miles per second " ) ;
  5336.   end PUT ;
  5337.  
  5338.   procedure PUT ( ITEM : VELOCITY_INCHES_PER_MINUTE ) is
  5339.  
  5340.   begin
  5341.     PUT ( UNDIMENSION( ITEM )) ;
  5342.     PUT ( " inches per minute " ) ;
  5343.   end PUT ;
  5344.  
  5345.   procedure PUT ( ITEM : VELOCITY_FEET_PER_MINUTE ) is
  5346.  
  5347.   begin
  5348.     PUT ( UNDIMENSION( ITEM )) ;
  5349.     PUT ( " feet per minute " ) ;
  5350.   end PUT ;
  5351.  
  5352.   procedure PUT ( ITEM : VELOCITY_MILES_PER_HOUR ) is
  5353.  
  5354.   begin
  5355.     PUT ( UNDIMENSION( ITEM )) ;
  5356.     PUT ( " miles per hour " ) ;
  5357.   end PUT ;
  5358.  
  5359.   procedure PUT ( ITEM : VELOCITY_KNOTS ) is
  5360.  
  5361.   begin
  5362.     PUT ( UNDIMENSION( ITEM )) ;
  5363.     PUT ( " knots " ) ;
  5364.   end PUT ;
  5365.  
  5366.   procedure PUT ( ITEM : VELOCITY_FURLONG_PER_FORTNIGHT ) is
  5367.  
  5368.   begin
  5369.     PUT ( UNDIMENSION( ITEM )) ;
  5370.     PUT ( " furlong per fortnight " ) ;
  5371.   end PUT ;
  5372.  
  5373.   procedure PUT ( ITEM : ANGULAR_VELOCITY ) is
  5374.  
  5375.   begin
  5376.     PUT ( UNDIMENSION( ITEM )) ;
  5377.     PUT ( " radian per second " ) ;
  5378.   end PUT ;
  5379.  
  5380.   procedure PUT ( ITEM : ANGULAR_VELOCITY_DEGREES_PER_SECOND ) is
  5381.  
  5382.   begin
  5383.     PUT ( UNDIMENSION( ITEM )) ;
  5384.     PUT ( " degrees per second " ) ;
  5385.   end PUT ;
  5386.  
  5387.   procedure PUT ( ITEM : ANGULAR_VELOCITY_REVOLUTIONS_PER_MINUTE ) is
  5388.  
  5389.   begin
  5390.     PUT ( UNDIMENSION( ITEM )) ;
  5391.     PUT ( " revolutions per minute " ) ;
  5392.   end PUT ;
  5393.  
  5394.   procedure PUT ( ITEM : ANGULAR_VELOCITY_REVOLUTIONS_PER_SECOND ) is
  5395.  
  5396.   begin
  5397.     PUT ( UNDIMENSION( ITEM )) ;
  5398.     PUT ( " revolutions per second " ) ;
  5399.   end PUT ;
  5400.  
  5401.   procedure PUT ( ITEM : ACCELERATION_MKS ) is
  5402.  
  5403.   begin
  5404.     PUT ( UNDIMENSION( ITEM )) ;
  5405.     PUT ( " meter per second squared " ) ;
  5406.   end PUT ;
  5407.  
  5408.   procedure PUT ( ITEM : ACCELERATION_ENGLISH ) is
  5409.  
  5410.   begin
  5411.     PUT ( UNDIMENSION( ITEM )) ;
  5412.     PUT ( " foot per second squared " ) ;
  5413.   end PUT ;
  5414.  
  5415.   procedure PUT ( ITEM : ANGULAR_ACCELERATION ) is
  5416.  
  5417.   begin
  5418.     PUT ( UNDIMENSION( ITEM )) ;
  5419.     PUT ( " radians per second squared " ) ;
  5420.   end PUT ;
  5421.  
  5422.   procedure PUT ( ITEM : ANGULAR_ACCELERATION_REVOLUTIONS_PER_MINUTE_SQUARED )
  5423.       is
  5424.  
  5425.   begin
  5426.     PUT ( UNDIMENSION( ITEM )) ;
  5427.     PUT ( " revolutions per minute squared " ) ;
  5428.   end PUT ;
  5429.  
  5430.   procedure PUT ( ITEM : FORCE_MKS ) is
  5431.  
  5432.   begin
  5433.     PUT ( UNDIMENSION( ITEM )) ;
  5434.     PUT ( " newton " ) ;
  5435.   end PUT ;
  5436.  
  5437.   procedure PUT ( ITEM : FORCE_DYNE ) is
  5438.  
  5439.   begin
  5440.     PUT ( UNDIMENSION( ITEM )) ;
  5441.     PUT ( " dyne " ) ;
  5442.   end PUT ;
  5443.  
  5444.   procedure PUT ( ITEM : FORCE_ENGLISH ) is
  5445.  
  5446.   begin
  5447.     PUT ( UNDIMENSION( ITEM )) ;
  5448.     PUT ( " poundal " ) ;
  5449.   end PUT ;
  5450.  
  5451.   procedure PUT ( ITEM : ENERGY_MKS ) is
  5452.  
  5453.   begin
  5454.     PUT ( UNDIMENSION( ITEM )) ;
  5455.     PUT ( " joule " ) ;
  5456.   end PUT ;
  5457.  
  5458.   procedure PUT ( ITEM : ENERGY_ERG ) is
  5459.  
  5460.   begin
  5461.     PUT ( UNDIMENSION( ITEM )) ;
  5462.     PUT ( " erg " ) ;
  5463.   end PUT ;
  5464.  
  5465.   procedure PUT ( ITEM : ENERGY_GRAM_CALORIE ) is
  5466.  
  5467.   begin
  5468.     PUT ( UNDIMENSION( ITEM )) ;
  5469.     PUT ( " gram calorie " ) ;
  5470.   end PUT ;
  5471.  
  5472.   procedure PUT ( ITEM : ENERGY_KILOGRAM_CALORIE ) is
  5473.  
  5474.   begin
  5475.     PUT ( UNDIMENSION( ITEM )) ;
  5476.     PUT ( " kilogram calorie " ) ;
  5477.   end PUT ;
  5478.  
  5479.   procedure PUT ( ITEM : ENERGY_B_T_U ) is
  5480.  
  5481.   begin
  5482.     PUT ( UNDIMENSION( ITEM )) ;
  5483.     PUT ( " B.T.U. " ) ;
  5484.   end PUT ;
  5485.  
  5486.   procedure PUT ( ITEM : ENERGY_FOOT_POUND ) is
  5487.  
  5488.   begin
  5489.     PUT ( UNDIMENSION( ITEM )) ;
  5490.     PUT ( " foot pound " ) ;
  5491.   end PUT ;
  5492.  
  5493.   procedure PUT ( ITEM : ENERGY_KILOWATT_HOUR ) is
  5494.  
  5495.   begin
  5496.     PUT ( UNDIMENSION( ITEM )) ;
  5497.     PUT ( " kilowat hour " ) ;
  5498.   end PUT ;
  5499.  
  5500.   procedure PUT ( ITEM : ENERGY_HORSEPOWER_HOUR ) is
  5501.  
  5502.   begin
  5503.     PUT ( UNDIMENSION( ITEM )) ;
  5504.     PUT ( " horsepower hour " ) ;
  5505.   end PUT ;
  5506.  
  5507.   procedure PUT ( ITEM : POWER_MKS ) is
  5508.  
  5509.   begin
  5510.     PUT ( UNDIMENSION( ITEM )) ;
  5511.     PUT ( " watt " ) ;
  5512.   end PUT ;
  5513.  
  5514.   procedure PUT ( ITEM : POWER_KILOGRAM_CALORIE_PER_SECOND ) is
  5515.  
  5516.   begin
  5517.     PUT ( UNDIMENSION( ITEM )) ;
  5518.     PUT ( " kilogram calorie per second " ) ;
  5519.   end PUT ;
  5520.  
  5521.   procedure PUT ( ITEM : POWER_KILOGRAN_CALORIE_PER_MINUTE ) is
  5522.  
  5523.   begin
  5524.     PUT ( UNDIMENSION( ITEM )) ;
  5525.     PUT ( " kilogram calorie per minute " ) ;
  5526.   end PUT ;
  5527.  
  5528.   procedure PUT ( ITEM : POWER_HORSEPOWER_MECHANICAL ) is
  5529.  
  5530.   begin
  5531.     PUT ( UNDIMENSION( ITEM )) ;
  5532.     PUT ( " horsepower (mechanical) " ) ;
  5533.   end PUT ;
  5534.  
  5535.   procedure PUT ( ITEM : POWER_HORSEPOWER_ELECTRICAL ) is
  5536.  
  5537.   begin
  5538.     PUT ( UNDIMENSION( ITEM )) ;
  5539.     PUT ( " horsepower (electrical) " ) ;
  5540.   end PUT ;
  5541.  
  5542.   procedure PUT ( ITEM : POWER_HORSEPOWER_METRIC ) is
  5543.  
  5544.   begin
  5545.     PUT ( UNDIMENSION( ITEM )) ;
  5546.     PUT ( " horsepower ( metric) " ) ;
  5547.   end PUT ;
  5548.  
  5549.   procedure PUT ( ITEM : POWER_HORSEPOWER_BOILER ) is
  5550.  
  5551.   begin
  5552.     PUT ( UNDIMENSION( ITEM )) ;
  5553.     PUT ( " horsepower (boiler) " ) ;
  5554.   end PUT ;
  5555.  
  5556.   procedure PUT ( ITEM : POWER_B_T_U_PER_MINUTE ) is
  5557.  
  5558.   begin
  5559.     PUT ( UNDIMENSION( ITEM )) ;
  5560.     PUT ( " B.T.U. per minute " ) ;
  5561.   end PUT ;
  5562.  
  5563.   procedure PUT ( ITEM : POWER_B_T_U_PER_HOUR ) is
  5564.  
  5565.   begin
  5566.     PUT ( UNDIMENSION( ITEM )) ;
  5567.     PUT ( " B.T.U. per hour " ) ;
  5568.   end PUT ;
  5569.  
  5570.   procedure PUT ( ITEM : POWER_FOOT_POUND_PER_MINUTE ) is
  5571.  
  5572.   begin
  5573.     PUT ( UNDIMENSION( ITEM )) ;
  5574.     PUT ( " foot pound per minute " ) ;
  5575.   end PUT ;
  5576.  
  5577.   procedure PUT ( ITEM : POWER_FOOT_POUND_PER_SECOND ) is
  5578.  
  5579.   begin
  5580.     PUT ( UNDIMENSION( ITEM )) ;
  5581.     PUT ( " foot pound per second " ) ;
  5582.   end PUT ;
  5583.  
  5584.   procedure PUT ( ITEM : DENSITY_MKS ) is
  5585.  
  5586.   begin
  5587.     PUT ( UNDIMENSION( ITEM )) ;
  5588.     PUT ( " kilogram per cubic meter " ) ;
  5589.   end PUT ;
  5590.  
  5591.   procedure PUT ( ITEM : DENSITY_ENGLISH ) is
  5592.  
  5593.   begin
  5594.     PUT ( UNDIMENSION( ITEM )) ;
  5595.     PUT ( " pound per cubic foot " ) ;
  5596.   end PUT ;
  5597.  
  5598.   procedure PUT ( ITEM : FLOW_RATE_MKS ) is
  5599.  
  5600.   begin
  5601.     PUT ( UNDIMENSION( ITEM )) ;
  5602.     PUT ( " cubic meter per second " ) ;
  5603.   end PUT ;
  5604.  
  5605.   procedure PUT ( ITEM : FLOW_RATE_GALLON_PER_MINUTE ) is
  5606.  
  5607.   begin
  5608.     PUT ( UNDIMENSION( ITEM )) ;
  5609.     PUT ( " gallon per minute " ) ;
  5610.   end PUT ;
  5611.  
  5612.   procedure PUT ( ITEM : FLOW_RATE_ENGLISH ) is
  5613.  
  5614.   begin
  5615.     PUT ( UNDIMENSION( ITEM )) ;
  5616.     PUT ( " cubic feet per second " ) ;
  5617.   end PUT ;
  5618.  
  5619.   procedure PUT ( ITEM : FLOW_RATE_CUBIC_FEET_PER_MINUTE ) is
  5620.  
  5621.   begin
  5622.     PUT ( UNDIMENSION( ITEM )) ;
  5623.     PUT ( " cubic feet per minute " ) ;
  5624.   end PUT ;
  5625.  
  5626.   procedure PUT ( ITEM : PRESSURE_MKS ) is
  5627.  
  5628.   begin
  5629.     PUT ( UNDIMENSION( ITEM )) ;
  5630.     PUT ( " pascal " ) ;
  5631.   end PUT ;
  5632.  
  5633.   procedure PUT ( ITEM : PRESSURE_ENGLISH ) is
  5634.  
  5635.   begin
  5636.     PUT ( UNDIMENSION( ITEM )) ;
  5637.     PUT ( " pound per square foot " ) ;
  5638.   end PUT ;
  5639.  
  5640.   procedure PUT ( ITEM : PRESSURE_TON_PER_SQUARE_FOOT ) is
  5641.  
  5642.   begin
  5643.     PUT ( UNDIMENSION( ITEM )) ;
  5644.     PUT ( " ton per square foot " ) ;
  5645.   end PUT ;
  5646.  
  5647.   procedure PUT ( ITEM : PRESSURE_ATMOSPHERE_STANDARD ) is
  5648.  
  5649.   begin
  5650.     PUT ( UNDIMENSION( ITEM )) ;
  5651.     PUT ( " atmosphere " ) ;
  5652.   end PUT ;
  5653.  
  5654.   procedure PUT ( ITEM : PRESSURE_FEET_OF_WATER ) is
  5655.  
  5656.   begin
  5657.     PUT ( UNDIMENSION( ITEM )) ;
  5658.     PUT ( " feet of water " ) ;
  5659.   end PUT ;
  5660.  
  5661.   procedure PUT ( ITEM : PRESSURE_INCHES_OF_MERCURY ) is
  5662.  
  5663.   begin
  5664.     PUT ( UNDIMENSION( ITEM )) ;
  5665.     PUT ( " inches of mercury " ) ;
  5666.   end PUT ;
  5667.  
  5668.   procedure PUT ( ITEM : PRESSURE_MILLIMETER_OF_MERCURY ) is
  5669.  
  5670.   begin
  5671.     PUT ( UNDIMENSION( ITEM )) ;
  5672.     PUT ( " millimeter of mercury " ) ;
  5673.   end PUT ;
  5674.  
  5675.   procedure PUT ( ITEM : PRESSURE_BAR ) is
  5676.  
  5677.   begin
  5678.     PUT ( UNDIMENSION( ITEM )) ;
  5679.     PUT ( " bar " ) ;
  5680.   end PUT ;
  5681.  
  5682.   procedure PUT ( ITEM : PRESSURE_MILLIBAR ) is
  5683.  
  5684.   begin
  5685.     PUT ( UNDIMENSION( ITEM )) ;
  5686.     PUT ( " millibar " ) ;
  5687.   end PUT ;
  5688.  
  5689.   procedure PUT ( ITEM : PRESSURE_TORR ) is
  5690.  
  5691.   begin
  5692.     PUT ( UNDIMENSION( ITEM )) ;
  5693.     PUT ( " torr " ) ;
  5694.   end PUT ;
  5695.  
  5696.   procedure PUT ( ITEM : MOMENTUM_MKS ) is
  5697.  
  5698.   begin
  5699.     PUT ( UNDIMENSION( ITEM )) ;
  5700.     PUT ( " newton per second " ) ;
  5701.   end PUT ;
  5702.  
  5703.   procedure PUT ( ITEM : INERTIA_MKS ) is
  5704.  
  5705.   begin
  5706.     PUT ( UNDIMENSION( ITEM )) ;
  5707.     PUT ( " joule second " ) ;
  5708.   end PUT ;
  5709.  
  5710.   procedure PUT ( ITEM : MOMENT_OF_INERTIA_MKS ) is
  5711.  
  5712.   begin
  5713.     PUT ( UNDIMENSION( ITEM )) ;
  5714.     PUT ( " kilogram meter squared " ) ;
  5715.   end PUT ;
  5716.  
  5717.   procedure PUT ( ITEM : KINEMATIC_VISCOSITY_MKS ) is
  5718.  
  5719.   begin
  5720.     PUT ( UNDIMENSION( ITEM )) ;
  5721.     PUT ( " meter squared per second " ) ;
  5722.   end PUT ;
  5723.  
  5724.   procedure PUT ( ITEM : DYNAMIC_VISCOSITY_MKS ) is
  5725.  
  5726.   begin
  5727.     PUT ( UNDIMENSION( ITEM )) ;
  5728.     PUT ( " newton second per square meter " ) ;
  5729.   end PUT ;
  5730.  
  5731.   procedure PUT ( ITEM : LUMINOUS_FLUX_LUMEN ) is
  5732.  
  5733.   begin
  5734.     PUT ( UNDIMENSION( ITEM )) ;
  5735.     PUT ( " lumen " ) ;
  5736.   end PUT ;
  5737.  
  5738.   procedure PUT ( ITEM : ILLUMINATION_MKS ) is
  5739.  
  5740.   begin
  5741.     PUT ( UNDIMENSION( ITEM )) ;
  5742.     PUT ( " lumen per square meter " ) ;
  5743.   end PUT ;
  5744.  
  5745.   procedure PUT ( ITEM : LUMINANCE_MKS ) is
  5746.  
  5747.   begin
  5748.     PUT ( UNDIMENSION( ITEM )) ;
  5749.     PUT ( " lux " ) ;
  5750.   end PUT ;
  5751.  
  5752.   procedure PUT ( ITEM : ENTROPY_MKS ) is
  5753.  
  5754.   begin
  5755.     PUT ( UNDIMENSION( ITEM )) ;
  5756.     PUT ( " joule per degree centegrade " ) ;
  5757.   end PUT ;
  5758.  
  5759.   procedure PUT ( ITEM : SPECIFIC_HEAT_B_T_U_PER_POUND_DEGREE_FARENHEIT ) is
  5760.  
  5761.   begin
  5762.     PUT ( UNDIMENSION( ITEM )) ;
  5763.     PUT ( " B.T.U. per pound degree farenheit " ) ;
  5764.   end PUT ;
  5765.  
  5766. end PHYSICAL_UNITS_OUTPUT_MECHANICAL ;
  5767. --------------------------------------------------------------------------------
  5768.  
  5769.  
  5770.  
  5771.  
  5772.  
  5773.  
  5774.  
  5775.  
  5776.  
  5777. --------------------------------------------------------------------------------
  5778. with PHYSICAL_UNITS_BASIC ; use PHYSICAL_UNITS_BASIC ;
  5779. with PHYSICAL_UNITS_MECHANICAL ; use PHYSICAL_UNITS_MECHANICAL ;
  5780. with PHYSICAL_UNITS_OTHER ; use PHYSICAL_UNITS_OTHER ;
  5781.  
  5782. -- This package defines operators needed to evaluate equations of
  5783. -- physics using dimensional and units checking. Only MKS units
  5784. -- are used. A conversion package is available to convert from
  5785. -- other metric units and English units to the MKS units.
  5786. --
  5787. -- This package is not complete. Completeness would imply all
  5788. -- possible operators that combine physical dimensions and yeild
  5789. -- other physical dimensions. Users can provide local definitions
  5790. -- or this package can be augmented.
  5791. --
  5792.  
  5793. package MKS_PHYSICS_MECHANICAL is
  5794.  
  5795.   function "*" ( LEFT , RIGHT : LENGTH_MKS ) return AREA_MKS ;
  5796.  
  5797.   function SQRT ( LEFT : AREA_MKS ) return LENGTH_MKS ;
  5798.  
  5799.   function "**" ( LEFT : LENGTH_MKS ;
  5800.                   RIGHT : INTEGER ) return AREA_MKS ;
  5801.  
  5802.   function "**" ( LEFT : LENGTH_MKS ;
  5803.                   RIGHT : INTEGER ) return VOLUME_MKS ;
  5804.  
  5805.   function "*" ( LEFT : AREA_MKS ;
  5806.                  RIGHT : LENGTH_MKS ) return VOLUME_MKS ;
  5807.  
  5808.   function "*" ( LEFT : LENGTH_MKS ;
  5809.                  RIGHT : AREA_MKS ) return VOLUME_MKS ;
  5810.  
  5811.   function CUBE_ROOT ( LEFT : VOLUME_MKS ) return LENGTH_MKS ;
  5812.  
  5813.   function "/" ( LEFT : VOLUME_MKS ;
  5814.                  RIGHT : LENGTH_MKS ) return AREA_MKS ;
  5815.  
  5816.   function "/" ( LEFT : LENGTH_MKS ;
  5817.                  RIGHT : TIME_SECOND ) return VELOCITY_MKS ;
  5818.  
  5819.   function "/" ( LEFT : LENGTH_MKS ;
  5820.                  RIGHT : TIME_SECOND_SQUARED ) return ACCELERATION_MKS ;
  5821.  
  5822.   function "*" ( LEFT , RIGHT : TIME_SECOND ) return TIME_SECOND_SQUARED ;
  5823.  
  5824.   function "**" ( LEFT : TIME_SECOND ;
  5825.                   RIGHT : INTEGER ) return TIME_SECOND_SQUARED ;
  5826.  
  5827.   function "**" ( LEFT : VELOCITY_MKS ;
  5828.                   RIGHT : INTEGER ) return VELOCITY_SQUARED_MKS ;
  5829.  
  5830.   function SQRT ( LEFT : TIME_SECOND_SQUARED ) return TIME_SECOND ;
  5831.  
  5832.   function "*" ( LEFT , RIGHT : VELOCITY_MKS ) return VELOCITY_SQUARED_MKS ;
  5833.  
  5834.   function SQRT ( LEFT : VELOCITY_SQUARED_MKS ) return VELOCITY_MKS ;
  5835.  
  5836.   function "*" ( LEFT : ACCELERATION_MKS ;
  5837.                  RIGHT : TIME_SECOND_SQUARED ) return LENGTH_MKS ;
  5838.  
  5839.   function "/" ( LEFT : LENGTH_MKS ;
  5840.                  RIGHT : ACCELERATION_MKS ) return TIME_SECOND_SQUARED ;
  5841.  
  5842.   function "*" ( LEFT : ACCELERATION_MKS ;
  5843.                  RIGHT : LENGTH_MKS ) return VELOCITY_SQUARED_MKS ;
  5844.  
  5845.   function "*" ( LEFT : LENGTH_MKS ;
  5846.                  RIGHT : ACCELERATION_MKS ) return VELOCITY_SQUARED_MKS ;
  5847.  
  5848.   function "*" ( LEFT : ACCELERATION_MKS ;
  5849.                  RIGHT : TIME_SECOND ) return VELOCITY_MKS ;
  5850.  
  5851.   function "*" ( LEFT : TIME_SECOND ;
  5852.                  RIGHT : ACCELERATION_MKS ) return VELOCITY_MKS ;
  5853.  
  5854.   function "*" ( LEFT : MASS_MKS ;
  5855.                  RIGHT : ACCELERATION_MKS ) return FORCE_MKS ;
  5856.  
  5857.   function "*" ( LEFT : ACCELERATION_MKS ;
  5858.                  RIGHT : MASS_MKS ) return FORCE_MKS ;
  5859.  
  5860.   function "*" ( LEFT : PRESSURE_MKS ;
  5861.                  RIGHT : AREA_MKS ) return FORCE_MKS ;
  5862.  
  5863.   function "*" ( LEFT : AREA_MKS ;
  5864.                  RIGHT : PRESSURE_MKS ) return FORCE_MKS ;
  5865.  
  5866.   function "/" ( LEFT : POWER_MKS ;
  5867.                  RIGHT : VELOCITY_MKS ) return FORCE_MKS ;
  5868.  
  5869.   function "/" ( LEFT : ENERGY_MKS ;
  5870.                  RIGHT : LENGTH_MKS ) return FORCE_MKS ;
  5871.  
  5872.   function "*" ( LEFT : PRESSURE_MKS ;
  5873.                  RIGHT : VOLUME_MKS ) return ENERGY_MKS ;
  5874.  
  5875.   function "*" ( LEFT : VOLUME_MKS ;
  5876.                  RIGHT : PRESSURE_MKS ) return ENERGY_MKS ;
  5877.  
  5878.   function "*" ( LEFT : FORCE_MKS ;
  5879.                  RIGHT : LENGTH_MKS ) return ENERGY_MKS ;
  5880.  
  5881.   function "*" ( LEFT : LENGTH_MKS ;
  5882.                  RIGHT : FORCE_MKS ) return ENERGY_MKS ;
  5883.  
  5884.   function "*" ( LEFT : MASS_MKS ;
  5885.                  RIGHT : VELOCITY_SQUARED_MKS ) return ENERGY_MKS ;
  5886.  
  5887.   function "*" ( LEFT : VELOCITY_SQUARED_MKS ;
  5888.                  RIGHT : MASS_MKS ) return ENERGY_MKS ;
  5889.  
  5890.   function "*" ( LEFT : POWER_MKS ;
  5891.                  RIGHT : TIME_SECOND ) return ENERGY_MKS ;
  5892.  
  5893.   function "*" ( LEFT : TIME_SECOND ;
  5894.                  RIGHT : POWER_MKS ) return ENERGY_MKS ;
  5895.  
  5896.   function "*" ( LEFT : FORCE_MKS ;
  5897.                  RIGHT : VELOCITY_MKS ) return POWER_MKS ;
  5898.  
  5899.   function "*" ( LEFT : VELOCITY_MKS ;
  5900.                  RIGHT : FORCE_MKS ) return POWER_MKS ;
  5901.  
  5902.   function "/" ( LEFT : ENERGY_MKS ;
  5903.                  RIGHT : TIME_SECOND ) return POWER_MKS ;
  5904.  
  5905.  
  5906.   pragma INLINE ( "*", "/" , "**", SQRT ) ;
  5907.  
  5908. end MKS_PHYSICS_MECHANICAL ;
  5909.  
  5910. --------------------------------------------------------------------------------
  5911.  
  5912.  
  5913.  
  5914.  
  5915.  
  5916.  
  5917.  
  5918.  
  5919.  
  5920. --------------------------------------------------------------------------------
  5921. -- with LONG_REFUNCT; use LONG_REFUNCT;                        --Alstad
  5922. with PHYSICAL_REAL ; use PHYSICAL_REAL ;
  5923.  
  5924. package body MKS_PHYSICS_MECHANICAL is
  5925.  
  5926.   function "*" ( LEFT , RIGHT : LENGTH_MKS ) return AREA_MKS is
  5927.  
  5928.   begin
  5929.     return AREA_MKS'  --
  5930.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  5931.   end "*" ;
  5932.  
  5933.   function SQRT ( LEFT : AREA_MKS ) return LENGTH_MKS is
  5934.  
  5935.   begin
  5936.     return LENGTH_MKS' ( DIMENSION( SQRT( UNDIMENSION( LEFT )))) ;
  5937.   end SQRT ;
  5938.  
  5939.   function "**" ( LEFT : LENGTH_MKS ;
  5940.                   RIGHT : INTEGER ) return AREA_MKS is
  5941.  
  5942.   begin
  5943.     if RIGHT /= 2 then
  5944.       raise NUMERIC_ERROR ;
  5945.     end if ;
  5946.     return AREA_MKS'  --
  5947.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( LEFT ))) ;
  5948.   end "**" ;
  5949.  
  5950.   function "**" ( LEFT : LENGTH_MKS ;
  5951.                   RIGHT : INTEGER ) return VOLUME_MKS is
  5952.  
  5953.   begin
  5954.     if RIGHT /= 3 then
  5955.       raise NUMERIC_ERROR ;
  5956.     end if ;
  5957.     return VOLUME_MKS'  --
  5958.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( LEFT ) * UNDIMENSION
  5959.         ( LEFT ))) ;
  5960.   end "**" ;
  5961.  
  5962.   function "*" ( LEFT : AREA_MKS ;
  5963.                  RIGHT : LENGTH_MKS ) return VOLUME_MKS is
  5964.  
  5965.   begin
  5966.     return VOLUME_MKS'  --
  5967.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  5968.   end "*" ;
  5969.  
  5970.   function "*" ( LEFT : LENGTH_MKS ;
  5971.                  RIGHT : AREA_MKS ) return VOLUME_MKS is
  5972.  
  5973.   begin
  5974.     return VOLUME_MKS'  --
  5975.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  5976.   end "*" ;
  5977.  
  5978.   function CUBE_ROOT ( LEFT : VOLUME_MKS ) return LENGTH_MKS is
  5979.  
  5980.   begin
  5981.     return LENGTH_MKS' ( DIMENSION( CUBE_ROOT( UNDIMENSION( LEFT ))));  --Alstad
  5982.   end CUBE_ROOT ;
  5983.  
  5984.   function "/" ( LEFT : VOLUME_MKS ;
  5985.                  RIGHT : LENGTH_MKS ) return AREA_MKS is
  5986.  
  5987.   begin
  5988.     return AREA_MKS'  --
  5989.         ( DIMENSION( UNDIMENSION( LEFT ) / UNDIMENSION ( RIGHT ))) ;
  5990.   end "/" ;
  5991.  
  5992.   function "/" ( LEFT : LENGTH_MKS ;
  5993.                  RIGHT : TIME_SECOND ) return VELOCITY_MKS is
  5994.  
  5995.   begin
  5996.     return VELOCITY_MKS'  --
  5997.         ( DIMENSION( UNDIMENSION( LEFT ) / UNDIMENSION ( RIGHT ))) ;
  5998.   end "/" ;
  5999.  
  6000.   function "/" ( LEFT : LENGTH_MKS ;
  6001.                  RIGHT : TIME_SECOND_SQUARED ) return ACCELERATION_MKS is
  6002.  
  6003.   begin
  6004.     return ACCELERATION_MKS'  --
  6005.         ( DIMENSION( UNDIMENSION( LEFT ) / UNDIMENSION ( RIGHT ))) ;
  6006.   end "/" ;
  6007.  
  6008.   function "*" ( LEFT , RIGHT : TIME_SECOND ) return TIME_SECOND_SQUARED is
  6009.  
  6010.   begin
  6011.     return TIME_SECOND_SQUARED'  --
  6012.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6013.   end "*" ;
  6014.  
  6015.   function "**" ( LEFT : TIME_SECOND ;
  6016.                   RIGHT : INTEGER ) return TIME_SECOND_SQUARED is
  6017.  
  6018.   begin
  6019.     if RIGHT /= 2 then
  6020.       raise NUMERIC_ERROR ;
  6021.     end if ;
  6022.     return TIME_SECOND_SQUARED'  --
  6023.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( LEFT ))) ;
  6024.   end "**" ;
  6025.  
  6026.   function "**" ( LEFT : VELOCITY_MKS ;
  6027.                   RIGHT : INTEGER ) return VELOCITY_SQUARED_MKS is
  6028.  
  6029.   begin
  6030.     if RIGHT /= 2 then
  6031.       raise NUMERIC_ERROR ;
  6032.     end if ;
  6033.     return VELOCITY_SQUARED_MKS'  --
  6034.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( LEFT ))) ;
  6035.   end "**" ;
  6036.  
  6037.   function SQRT ( LEFT : TIME_SECOND_SQUARED ) return TIME_SECOND is
  6038.  
  6039.   begin
  6040.     return TIME_SECOND' ( DIMENSION( SQRT( UNDIMENSION( LEFT )))) ;
  6041.   end SQRT ;
  6042.  
  6043.   function "*" ( LEFT , RIGHT : VELOCITY_MKS ) return VELOCITY_SQUARED_MKS is
  6044.  
  6045.   begin
  6046.     return VELOCITY_SQUARED_MKS'  --
  6047.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6048.   end "*" ;
  6049.  
  6050.   function SQRT ( LEFT : VELOCITY_SQUARED_MKS ) return VELOCITY_MKS is
  6051.  
  6052.   begin
  6053.     return VELOCITY_MKS' ( DIMENSION( SQRT( UNDIMENSION( LEFT )))) ;
  6054.   end SQRT ;
  6055.  
  6056.   function "*" ( LEFT : ACCELERATION_MKS ;
  6057.                  RIGHT : TIME_SECOND_SQUARED ) return LENGTH_MKS is
  6058.  
  6059.   begin
  6060.     return LENGTH_MKS'  --
  6061.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6062.   end "*" ;
  6063.  
  6064.   function "/" ( LEFT : LENGTH_MKS ;
  6065.                  RIGHT : ACCELERATION_MKS ) return TIME_SECOND_SQUARED is
  6066.  
  6067.   begin
  6068.     return TIME_SECOND_SQUARED'  --
  6069.         ( DIMENSION( UNDIMENSION( LEFT ) / UNDIMENSION ( RIGHT ))) ;
  6070.   end "/" ;
  6071.  
  6072.   function "*" ( LEFT : ACCELERATION_MKS ;
  6073.                  RIGHT : LENGTH_MKS ) return VELOCITY_SQUARED_MKS is
  6074.  
  6075.   begin
  6076.     return VELOCITY_SQUARED_MKS'  --
  6077.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6078.   end "*" ;
  6079.  
  6080.   function "*" ( LEFT : LENGTH_MKS ;
  6081.                  RIGHT : ACCELERATION_MKS ) return VELOCITY_SQUARED_MKS is
  6082.  
  6083.   begin
  6084.     return VELOCITY_SQUARED_MKS'  --
  6085.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6086.   end "*" ;
  6087.  
  6088.   function "*" ( LEFT : ACCELERATION_MKS ;
  6089.                  RIGHT : TIME_SECOND ) return VELOCITY_MKS is
  6090.  
  6091.   begin
  6092.     return VELOCITY_MKS'  --
  6093.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6094.   end "*" ;
  6095.  
  6096.   function "*" ( LEFT : TIME_SECOND ;
  6097.                  RIGHT : ACCELERATION_MKS ) return VELOCITY_MKS is
  6098.  
  6099.   begin
  6100.     return VELOCITY_MKS'  --
  6101.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6102.   end "*" ;
  6103.  
  6104.   function "*" ( LEFT : MASS_MKS ;
  6105.                  RIGHT : ACCELERATION_MKS ) return FORCE_MKS is
  6106.  
  6107.   begin
  6108.     return FORCE_MKS'  --
  6109.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6110.   end "*" ;
  6111.  
  6112.   function "*" ( LEFT : ACCELERATION_MKS ;
  6113.                  RIGHT : MASS_MKS ) return FORCE_MKS is
  6114.  
  6115.   begin
  6116.     return FORCE_MKS'  --
  6117.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6118.   end "*" ;
  6119.  
  6120.   function "*" ( LEFT : PRESSURE_MKS ;
  6121.                  RIGHT : AREA_MKS ) return FORCE_MKS is
  6122.  
  6123.   begin
  6124.     return FORCE_MKS'  --
  6125.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6126.   end "*" ;
  6127.  
  6128.   function "*" ( LEFT : AREA_MKS ;
  6129.                  RIGHT : PRESSURE_MKS ) return FORCE_MKS is
  6130.  
  6131.   begin
  6132.     return FORCE_MKS'  --
  6133.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6134.   end "*" ;
  6135.  
  6136.   function "/" ( LEFT : POWER_MKS ;
  6137.                  RIGHT : VELOCITY_MKS ) return FORCE_MKS is
  6138.  
  6139.   begin
  6140.     return FORCE_MKS'  --
  6141.         ( DIMENSION( UNDIMENSION( LEFT ) / UNDIMENSION ( RIGHT ))) ;
  6142.   end "/" ;
  6143.  
  6144.   function "/" ( LEFT : ENERGY_MKS ;
  6145.                  RIGHT : LENGTH_MKS ) return FORCE_MKS is
  6146.  
  6147.   begin
  6148.     return FORCE_MKS'  --
  6149.         ( DIMENSION( UNDIMENSION( LEFT ) / UNDIMENSION ( RIGHT ))) ;
  6150.   end "/" ;
  6151.  
  6152.   function "*" ( LEFT : PRESSURE_MKS ;
  6153.                  RIGHT : VOLUME_MKS ) return ENERGY_MKS is
  6154.  
  6155.   begin
  6156.     return ENERGY_MKS'  --
  6157.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6158.   end "*" ;
  6159.  
  6160.   function "*" ( LEFT : VOLUME_MKS ;
  6161.                  RIGHT : PRESSURE_MKS ) return ENERGY_MKS is
  6162.  
  6163.   begin
  6164.     return ENERGY_MKS'  --
  6165.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6166.   end "*" ;
  6167.  
  6168.   function "*" ( LEFT : FORCE_MKS ;
  6169.                  RIGHT : LENGTH_MKS ) return ENERGY_MKS is
  6170.  
  6171.   begin
  6172.     return ENERGY_MKS'  --
  6173.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6174.   end "*" ;
  6175.  
  6176.   function "*" ( LEFT : LENGTH_MKS ;
  6177.                  RIGHT : FORCE_MKS ) return ENERGY_MKS is
  6178.  
  6179.   begin
  6180.     return ENERGY_MKS'  --
  6181.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6182.   end "*" ;
  6183.  
  6184.   function "*" ( LEFT : MASS_MKS ;
  6185.                  RIGHT : VELOCITY_SQUARED_MKS ) return ENERGY_MKS is
  6186.  
  6187.   begin
  6188.     return ENERGY_MKS'  --
  6189.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6190.   end "*" ;
  6191.  
  6192.   function "*" ( LEFT : VELOCITY_SQUARED_MKS ;
  6193.                  RIGHT : MASS_MKS ) return ENERGY_MKS is
  6194.  
  6195.   begin
  6196.     return ENERGY_MKS'  --
  6197.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6198.   end "*" ;
  6199.  
  6200.   function "*" ( LEFT : POWER_MKS ;
  6201.                  RIGHT : TIME_SECOND ) return ENERGY_MKS is
  6202.  
  6203.   begin
  6204.     return ENERGY_MKS'  --
  6205.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6206.   end "*" ;
  6207.  
  6208.   function "*" ( LEFT : TIME_SECOND ;
  6209.                  RIGHT : POWER_MKS ) return ENERGY_MKS is
  6210.  
  6211.   begin
  6212.     return ENERGY_MKS'  --
  6213.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6214.   end "*" ;
  6215.  
  6216.   function "*" ( LEFT : FORCE_MKS ;
  6217.                  RIGHT : VELOCITY_MKS ) return POWER_MKS is
  6218.  
  6219.   begin
  6220.     return POWER_MKS'  --
  6221.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6222.   end "*" ;
  6223.  
  6224.   function "*" ( LEFT : VELOCITY_MKS ;
  6225.                  RIGHT : FORCE_MKS ) return POWER_MKS is
  6226.  
  6227.   begin
  6228.     return POWER_MKS'  --
  6229.         ( DIMENSION( UNDIMENSION( LEFT ) * UNDIMENSION ( RIGHT ))) ;
  6230.   end "*" ;
  6231.  
  6232.   function "/" ( LEFT : ENERGY_MKS ;
  6233.                  RIGHT : TIME_SECOND ) return POWER_MKS is
  6234.  
  6235.   begin
  6236.     return POWER_MKS'  --
  6237.         ( DIMENSION( UNDIMENSION( LEFT ) / UNDIMENSION ( RIGHT ))) ;
  6238.   end "/" ;
  6239. end MKS_PHYSICS_MECHANICAL ;
  6240. --------------------------------------------------------------------------------
  6241.  
  6242.  
  6243.  
  6244.  
  6245.  
  6246.  
  6247.  
  6248.  
  6249.  
  6250. --------------------------------------------------------------------------------
  6251.  
  6252. -- This procedure solves a few physics problems involving
  6253. -- time, distance, vecocity and acceleration. All units are 
  6254. -- in the MKS system of units. Note that all "put" calls
  6255. -- on physical quantities are to be printed as the value followed
  6256. -- by the unit.
  6257. --
  6258. -- make available types for physical units
  6259. with PHYSICAL_UNITS_BASIC ; use PHYSICAL_UNITS_BASIC ;
  6260. with PHYSICAL_UNITS_MECHANICAL ; use PHYSICAL_UNITS_MECHANICAL ;
  6261. with PHYSICAL_UNITS_OTHER ; use PHYSICAL_UNITS_OTHER ;
  6262.  
  6263. -- make available operations on MKS types
  6264. with MKS_PHYSICS_MECHANICAL ; use MKS_PHYSICS_MECHANICAL ;
  6265.  
  6266. -- make PUT available for physical units types
  6267. with PHYSICAL_UNITS_OUTPUT_BASIC ; use PHYSICAL_UNITS_OUTPUT_BASIC ;
  6268. with PHYSICAL_UNITS_OUTPUT_MECHANICAL ; use PHYSICAL_UNITS_OUTPUT_MECHANICAL ;
  6269.  
  6270. --
  6271. with TEXT_IO ; use TEXT_IO ;
  6272.  
  6273. procedure PHYSICS_1 is
  6274.  
  6275. --    define acceleration due to gravity
  6276.   G : ACCELERATION_MKS := DIMENSION ( 9.80665 ) ;
  6277.   FALL : DISTANCE_METER ;
  6278.   FALL_TIME : TIME_SECOND ;
  6279.   V_FINAL : VELOCITY_METER_PER_SECOND ;
  6280. begin
  6281.   PUT ( " Test printout and value of acceleration, " ) ;
  6282.   PUT ( G ) ;
  6283.   PUT_LINE ( " = G " ) ;
  6284.  
  6285. -- How far will Ball_1 fall in 1.5 second in earths gravity ?
  6286.   FALL := 0.5 * G * TIME_SECOND' ( DIMENSION( 1.5 )) ** 2 ;
  6287.   PUT ( FALL ) ;
  6288.   NEW_LINE ;
  6289.  
  6290. -- Cross check that the time for the ball to fall is 1.5 seconds.
  6291.   FALL_TIME := SQRT ( 2.0 * FALL / G ) ;
  6292.   PUT ( FALL_TIME ) ;
  6293.   NEW_LINE ;
  6294.  
  6295. -- Now determine the final velocity if the ball falls another 0.2 meter
  6296. -- Method :  square root of initial velocity squared plus twice
  6297. --           the acceleration times the distance
  6298.   V_FINAL := SQRT (( G * FALL_TIME ) ** 2 + 2.0 * G * FALL) ;
  6299.   PUT ( V_FINAL ) ;
  6300.   NEW_LINE ;
  6301. end PHYSICS_1 ;
  6302. ::::::::::
  6303. CONPROD.ADA
  6304. ::::::::::
  6305. -------------------------------------------------------------------
  6306. ---------------------  Next  Program  -----------------------------
  6307. -------------------------------------------------------------------
  6308.  
  6309.  
  6310. ----------------------------------------------------------------------
  6311. --
  6312. --        PRODUCER / CONSUMER TASKING BENCHMARK
  6313. --
  6314. --        Version: @(#)conprod.ada    1.3    Date: 6/20/84
  6315. --
  6316. --                Gerry Fisher
  6317. --            Computer Sciences Corporation
  6318. --                May 27, 1984
  6319. --
  6320. --  This benchmark tests tasking performance using the buffering task
  6321. --  given as an example in chapter 9.12 of the Ada RM.  The consumer
  6322. --  task is the main program itself; the producer and buffer tasks
  6323. --  are declared as tasks within it.  During execution each "write"
  6324. --  entry call produces a "." on the standard output file, while each
  6325. --  "read" call produces a "*".  When all the produced data has been
  6326. --  consumed a check is made to see that the data has arrived in the
  6327. --  correct order and that no data remains buffered within the buffer
  6328. --  task.
  6329. --
  6330. ----------------------------------------------------------------------
  6331.  
  6332. with text_io; use text_io;
  6333. procedure main is
  6334.  
  6335.   all_there : boolean;
  6336.  
  6337. begin
  6338.   set_line_length(50);
  6339.   put_line("*** Producer/Consumer Task Test");
  6340.  
  6341.   declare
  6342.  
  6343.     x         : array(character) of character := (others => ' ');
  6344.     pool_size : constant integer := 5;
  6345.     pool      : array(1 .. pool_size) of character;
  6346.     count     : integer range 0 .. pool_size := 0;
  6347.  
  6348.     task buffer is
  6349.       entry read (c : out character);
  6350.       entry write(c : in  character);
  6351.     end buffer;
  6352.  
  6353.     task producer;
  6354.  
  6355.     task body producer is
  6356.     begin
  6357.       for c in character loop
  6358.         buffer.write(c);
  6359.       end loop;
  6360.     end producer;
  6361.  
  6362.     task body buffer is
  6363.       in_index, out_index : integer range 1 .. pool_size := 1;
  6364.     begin
  6365.       loop
  6366.         select
  6367.           when count < pool_size =>
  6368.         accept write(c : in character) do
  6369.           pool(in_index) := c;
  6370.         end write;
  6371.         put('.');
  6372.         in_index := in_index mod pool_size + 1;
  6373.         count    := count + 1;
  6374.         or when count > 0 =>
  6375.         accept read(c : out character) do
  6376.           c := pool(out_index);
  6377.         end read;
  6378.         put('*');
  6379.         out_index := out_index mod pool_size + 1;
  6380.         count := count - 1;
  6381.         or
  6382.           terminate;
  6383.         end select;
  6384.       end loop;
  6385.     end buffer;
  6386.  
  6387.     function Is_ok return boolean is
  6388.     begin
  6389.       for i in x'range loop
  6390.         if x(i) /= i then return false; end if;
  6391.       end loop;
  6392.       return true;
  6393.     end Is_ok;
  6394.  
  6395.   begin
  6396.     for i in x'range loop
  6397.       buffer.read(x(i));
  6398.     end loop;
  6399.     all_there := Is_ok;
  6400.   end;
  6401.  
  6402.   new_line;
  6403.   if all_there then
  6404.     put_line("*** PASSED Producer/Consumer Task Test");
  6405.   else
  6406.     put_line("*** FAILED Producer/Consumer Task Test");
  6407.   end if;
  6408. end main;
  6409. ::::::::::
  6410. DERIVED.ADA
  6411. ::::::::::
  6412. -------------------------------------------------------------------
  6413. ---------------------  Next  Program  -----------------------------
  6414. -------------------------------------------------------------------
  6415.  
  6416.  
  6417. --
  6418. -- Version: @(#)derived.ada    1.2        Date: 7/2/84
  6419. --
  6420. -- Author:  Bryce Bardin
  6421. --          Ada Projects Section
  6422. --          Software Engineering Division
  6423. --          Ground Systems Group
  6424. --          Hughes Aircraft Company
  6425. --          Fullerton, CA
  6426. --
  6427. -- This program tests the inter-conversion of derived types with 
  6428. -- different representations.  An approriate message is output to 
  6429. -- indicate "pass" or "fail".
  6430. --
  6431. --
  6432. -- Define the original types:
  6433. with Text_IO; use Text_IO;
  6434. package Originals is
  6435.  
  6436.    type Bit is range 0 .. 1;
  6437.  
  6438.    type Bit_String is array (Positive range <>) of Bit;
  6439.  
  6440.    subtype Word is Bit_String (1 .. 16);
  6441.  
  6442.    type Byte is range 0 .. 255;
  6443.  
  6444.    type Block is
  6445.       record
  6446.      First : Byte;
  6447.      Second : Word;
  6448.      Third : Byte;
  6449.       end record;
  6450.  
  6451.    package Byte_IO is new Integer_IO (Byte);
  6452.    use Byte_IO;
  6453.  
  6454.    procedure Put (B : Block);
  6455.  
  6456. end Originals;
  6457.  
  6458.  
  6459. package body Originals is
  6460.  
  6461.    procedure Put (B : Block) is
  6462.       S : String (1 .. Word'Length);
  6463.    begin
  6464.       Put("First = ");
  6465.       Put(B.First);
  6466.       for N in 1 .. Word'Length loop
  6467.      if B.Second(N) = 0 then
  6468.         S(N) := '0';
  6469.      else
  6470.             S(N) := '1';
  6471.      end if;
  6472.       end loop;
  6473.       Put(", Second = ");
  6474.       Put(S);
  6475.       Put(", Third = ");
  6476.       Put(B.Third);
  6477.       Put_Line(".");
  6478.    end Put;
  6479.  
  6480. end Originals;
  6481.  
  6482.  
  6483. -- Define the derived types:
  6484. with Originals; use Originals;
  6485. with System;
  6486. package Deriveds is
  6487.  
  6488.    type New_Block is new Block;
  6489.  
  6490.  for New_Block use
  6491.     record at mod System.Storage_Unit;
  6492.      First  at 0 range  0 ..  7;
  6493.      Second at 0 range  8 .. 23;
  6494.      Third  at 0 range 24 .. 31;
  6495.     end record;
  6496.  
  6497.  for New_Block'Size use 32;
  6498.  
  6499. end Deriveds;
  6500.  
  6501.  
  6502. -- Test conversion from derived to original types and vice versa.
  6503. with Originals; use Originals;
  6504. with Deriveds; use Deriveds;
  6505. with Text_IO; use Text_IO;
  6506. procedure Change_Representation is
  6507.  
  6508.    Original : Block := (First => 85, 
  6509.                Second => (1 .. 8 => 1, 9 .. 16 => 0),
  6510.                Third => 170);
  6511.  
  6512.    Derived  : New_Block := New_Block(Original);
  6513.  
  6514.    Copy : Block := Block(Derived);
  6515.  
  6516.    package Int_IO is new Integer_IO(Integer);
  6517.    use Int_IO;
  6518.  
  6519. begin
  6520.  
  6521.    Put_Line("Original:");
  6522.    Put(Original);
  6523.    New_Line;
  6524.  
  6525.    Put("Size = ");
  6526.    Put(Original'Size);
  6527.    Put_Line(" bits");
  6528.    New_Line;
  6529.  
  6530.    Put_Line("Derived:");
  6531.    Put(Derived);
  6532.    New_Line;
  6533.  
  6534.    Put("Size = ");
  6535.    Put(Derived'Size);
  6536.    Put_Line(" bits");
  6537.    New_Line;
  6538.  
  6539.    Put_Line("Copy:");
  6540.    Put(Copy);
  6541.    New_Line(2);
  6542.  
  6543.    if Copy = Original and Derived'Size = 32 then
  6544.       Put_Line("TEST PASSED!");
  6545.    else
  6546.       Put_Line("** TEST FAILED! **");
  6547.    end if;
  6548.  
  6549. end Change_Representation;
  6550. ::::::::::
  6551. FLOATVEC.ADA
  6552. ::::::::::
  6553. -------------------------------------------------------------------
  6554. ---------------------  Next  Program  -----------------------------
  6555. -------------------------------------------------------------------
  6556.  
  6557. --
  6558. -- Version: @(#)floatvec.ada    1.2        Date: 9/21/84
  6559. --
  6560. -- Author:  Edward Colbert
  6561. --        Ada Technology Group
  6562. --        Information Software Systems Lab
  6563. --        Defense Systems Group
  6564. --        TRW
  6565. --        Redondo Beach, CA
  6566. --
  6567. -- This program measures the time required for the adding of the
  6568. -- elements of a large floating point vector
  6569. --
  6570. -- Note:  In order for the measurement to be meaningful, it must be the 
  6571. -- only program executing while the test is run.  
  6572. --
  6573. -- Please set Vector_Size large enough to provide at least two significant 
  6574. -- digits in the average times, i.e., the difference between 
  6575. -- the elapsed time and the loop time must be at least 100 times 
  6576. -- Duration'Small & at least 100 times System.Tick.
  6577. --
  6578.  
  6579. with Text_IO; use Text_IO;
  6580. with Calendar; use Calendar;
  6581. with System; use System;
  6582. procedure Float_Vector_Add_Test is
  6583.  
  6584.    Vector_Size : constant Positive := 1000;
  6585.  
  6586.    type Real_Time is digits Max_Digits;
  6587.  
  6588.    Start_Time : Time;
  6589.    Loop_Time : Duration;
  6590.    Elapsed_Time : Duration;
  6591.    Average_Time : Real_Time;
  6592.  
  6593.    package Duration_IO is new Fixed_IO (Duration);
  6594.    use Duration_IO;
  6595.  
  6596.    package Real_Time_IO is new Float_IO (Real_Time);
  6597.    use Real_Time_IO;
  6598.  
  6599.    package Int_IO is new Integer_IO (Integer);
  6600.    use Int_IO;
  6601.  
  6602.    type vector is array (1..Vector_Size) of Float;
  6603.    
  6604.    v1, v2, vector_result: vector;
  6605.    count:  integer := integer'first;    -- used in timing loop
  6606.  
  6607. begin
  6608.  
  6609.    -- Initialize Vectors
  6610.    for N in vector'range loop
  6611.       v1(N) := float (N);
  6612.       v2(N) := float (vector'last - N + 1);
  6613.    end loop;
  6614.  
  6615.    -- Measure the timing loop overhead.
  6616.    Start_Time := Clock;
  6617.    for N in vector'range loop
  6618.       count := count + 1;        -- prevent optimization
  6619.    end loop;
  6620.    Loop_Time := Clock - Start_Time;
  6621.  
  6622.  
  6623.    -- Measure the time including the adding of vector elements
  6624.    Start_Time := Clock;
  6625.    for N in vector'range loop
  6626.       count := count + 1;        -- prevent optimization
  6627.       vector_result (n) := v1(n) + v2(n);
  6628.    end loop;
  6629.    Elapsed_Time := Clock - Start_Time;
  6630.  
  6631.  
  6632.    Put("Loop time = ");
  6633.    Put(Loop_Time, Fore => 0);
  6634.    Put(" seconds for ");
  6635.    Put(Vector_Size, Width => 0);
  6636.    Put_Line(" iterations");
  6637.  
  6638.  
  6639.    Put("Elapsed time = ");
  6640.    Put(Elapsed_Time, Fore => 0);
  6641.    Put(" seconds for ");
  6642.    Put(Vector_Size, Width => 0);
  6643.    Put_Line(" iterations (1 iteration/element)");
  6644.  
  6645.    Average_Time := Real_Time(Elapsed_Time - Loop_Time)/Real_Time(Vector_Size);
  6646.    Put("Average time for adding each element = ");
  6647.    Put(Average_Time, Fore => 0);
  6648.    Put_Line(" seconds");
  6649.  
  6650.    New_Line;
  6651.    if (Elapsed_Time - Loop_Time < 100 * Duration'Small    or
  6652.        Elapsed_Time - Loop_Time < 100 * System.Tick)    then
  6653.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  6654.    else
  6655.       Put_Line("** TEST PASSED **");
  6656.    end if;
  6657.  
  6658. end Float_Vector_Add_Test;
  6659. ::::::::::
  6660. FRIEND.ADA
  6661. ::::::::::
  6662. -------------------------------------------------------------------
  6663. ---------------------  Next  Program  -----------------------------
  6664. -------------------------------------------------------------------
  6665.  
  6666. --
  6667. -- Version: @(#)friend.ada    1.1        Date: 5/30/84
  6668. --
  6669. -- Author:  Bryce Bardin
  6670. --          Ada Projects Section
  6671. --          Software Engineering Division
  6672. --          Ground Systems Group
  6673. --          Hughes Aircraft Company
  6674. --          Fullerton, CA
  6675. --
  6676. -- The purpose of this program is to determine how "friendly" the Ada
  6677. -- compiler is with regard to warning about the use of uninitialized 
  6678. -- objects, exceptions which will always be raised, and both warning 
  6679. -- about and removal of code that will never be executed.
  6680. -- Compilers may be graded by the number of instances they catch in each 
  6681. -- of the three categories:  set/use errors, 'hard' exceptions, and 
  6682. -- 'dead' code removal.  A perfect score is: 12, 3, and 4, respectively.
  6683. -- Detection of set/use errors encountered during execution will not be
  6684. -- counted in the score even though it may be a useful feature to have.
  6685. -- Appropriate supporting evidence, such as an assembly listing, must be 
  6686. -- supplied if dead code removal is claimed.
  6687. -- N.B.:  It is not expected that any compiler will get a perfect score!
  6688. --
  6689. package Global is
  6690.    G : Integer; -- uninitialized
  6691. end Global;
  6692.  
  6693. with Global;
  6694. package Renamed is
  6695.    R : Integer renames Global.G; -- "A rose by any other name ..."
  6696. end Renamed;
  6697.  
  6698. with Text_IO; use Text_IO;
  6699. procedure Do_It is
  6700. begin
  6701.    Put_Line("Should do it.");
  6702. end Do_It;
  6703.  
  6704. with Text_IO; use Text_IO;
  6705. procedure Dont_Do_It is
  6706. begin
  6707.    Put_Line("Shouldn't have done it.");
  6708. end Dont_Do_It;
  6709.  
  6710. procedure Raise_It is
  6711. begin
  6712.    raise Program_Error;
  6713. end Raise_It;
  6714.  
  6715. with Global; use Global;
  6716. with Renamed; use Renamed;
  6717. with Do_It;
  6718. with Dont_Do_It;
  6719. with Raise_It;
  6720. procedure Friendly is
  6721.    L : Integer; -- uninitialized
  6722.    Use_1 : Integer := L; -- use before set 1
  6723.    Use_2 : Integer := G; -- use before set 2
  6724.    Use_3 : Integer := R; -- use before set 3
  6725.    Use_4 : Integer;
  6726.    Use_5 : Integer;
  6727.    Use_6 : Integer;
  6728.    Static : constant Integer := 8;
  6729.    Named : constant := 8;
  6730.    procedure Embedded (Data : Integer) is separate;
  6731. begin
  6732.    Use_4 := L; -- use before set 4
  6733.    Use_5 := G; -- use before set 5
  6734.    Use_6 := R; -- use before set 6
  6735.    Embedded(L); -- use before set 7
  6736.    Embedded(G); -- use before set 8
  6737.    Embedded(R); -- use before set 9
  6738.    if Static = 8 then
  6739.       Do_It;
  6740.    else
  6741.       Dont_Do_It; -- never executed 1
  6742.    end if;
  6743.    if Static - 4 /= 2**2 then
  6744.       Dont_Do_It; -- never executed 2
  6745.    else
  6746.       Do_It;
  6747.    end if;
  6748.    if Named mod 4 = 0 then
  6749.       Do_It;
  6750.    else
  6751.       Dont_Do_It; -- never executed 3
  6752.    end if;
  6753.    if Named/2 + 2 /= 6 then
  6754.       Dont_Do_It; -- never executed 4
  6755.    else
  6756.       Do_It;
  6757.    end if;
  6758.    Raise_It; -- always raised 1
  6759. end Friendly;
  6760.  
  6761. separate (Friendly)
  6762. procedure Embedded (Data : Integer) is
  6763.    Use_1 : Integer := L; -- use before set 10
  6764.    Use_2 : Integer := G; -- use before set 11
  6765.    Use_3 : Integer := R; -- use before set 12
  6766. begin
  6767.    Use_4 := Data; -- (if Data is uninitialized, causes a use before set)
  6768.    raise Program_Error; -- always raised 2
  6769.    Raise_It; -- always raised 3
  6770. end Embedded;
  6771. ::::::::::
  6772. INT_DIR.ADA
  6773. ::::::::::
  6774. -------------------------------------------------------------------
  6775. ---------------------  Next  Program  -----------------------------
  6776. -------------------------------------------------------------------
  6777.  
  6778. --
  6779. -- Version: @(#)int_dir.ada    1.2        Date: 9/21/84
  6780. --
  6781. -- Author:  Edward Colbert
  6782. --        Ada Technology Group
  6783. --        Information Software Systems Lab
  6784. --        Defense Systems Group
  6785. --        TRW
  6786. --        Redondo Beach, CA
  6787. --
  6788. -- This program measures the time required for doing various file
  6789. -- operations using the Direct_IO package with Integer.
  6790. --
  6791. -- Note:  In order for the measurement to be meaningful, it must be the 
  6792. -- only program executing while the test is run.  
  6793. --
  6794. -- Please set Times large enough to provide at least two significant 
  6795. -- digits in the average times, i.e., the difference between 
  6796. -- the elapsed time and the loop time must be at least 100 times 
  6797. -- Duration'Small & at least 100 times System.Tick.
  6798. --
  6799.  
  6800. with Text_IO; use Text_IO;
  6801. with Direct_IO;
  6802. with Calendar; use Calendar;
  6803. with System; use System;
  6804. procedure Integer_Direct_IO_Test is
  6805.  
  6806.    Times : constant Positive := 1000;
  6807.  
  6808.    type Real_Time is digits Max_Digits;
  6809.  
  6810.    Start_Time : Time;
  6811.    Loop_Time : Duration;
  6812.    Average_Time : Real_Time;
  6813.    Create_Time : Duration;
  6814.    Close_Time  : Duration;
  6815.    Open_Time   : Duration;
  6816.    Delete_Time : Duration;
  6817.    Read_Time   : Duration;
  6818.    Write_Time  : Duration;
  6819.  
  6820.    package Duration_IO is new Fixed_IO (Duration);
  6821.    use Duration_IO;
  6822.  
  6823.    package Real_Time_IO is new Float_IO (Real_Time);
  6824.    use Real_Time_IO;
  6825.  
  6826.    package Int_IO is new Integer_IO (Integer);
  6827.    use Int_IO;
  6828.  
  6829.    package Int_Direct_IO is new Direct_IO (Integer);
  6830.    use Int_Direct_IO;
  6831.  
  6832.    file:   Int_Direct_IO.file_type;
  6833.    value:  Integer := 5;
  6834.    count:  Integer := Integer'first;    -- used in timing loop
  6835.  
  6836. begin
  6837.  
  6838.    -- Measure the timing loop overhead.
  6839.    Start_Time := Clock;
  6840.    for N in 1 .. Times loop
  6841.       count := count + 1;        -- prevent optimization
  6842.    end loop;
  6843.    Loop_Time := Clock - Start_Time;
  6844.  
  6845.  
  6846.    -- Create a file
  6847.    Start_Time := Clock;
  6848.    Int_Direct_IO.Create (file, mode => out_file, name => "test_file");
  6849.    Create_Time := Clock - Start_Time;
  6850.  
  6851.    -- Measure the time of Writing of value
  6852.    Start_Time := Clock;
  6853.    for N in 1 .. Times loop
  6854.       count := count + 1;
  6855.       Int_Direct_IO.write (file, value);
  6856.    end loop;
  6857.    Write_Time := Clock - Start_Time;
  6858.  
  6859.    -- Close a file
  6860.    Start_Time := Clock;
  6861.    Int_Direct_IO.Close (file);
  6862.    Close_Time := Clock - Start_Time;
  6863.  
  6864.    -- Open a file
  6865.    Start_Time := Clock;
  6866.    Int_Direct_IO.Open (file, mode => in_file, name => "test_file");
  6867.    Open_Time := Clock - Start_Time;
  6868.  
  6869.    -- Measure the time of Reading of value
  6870.    Start_Time := Clock;
  6871.    for N in 1 .. Times loop
  6872.       count := count + 1;
  6873.       Int_Direct_IO.read (file, value);
  6874.    end loop;
  6875.    Read_Time := Clock - Start_Time;
  6876.  
  6877.    -- Delete a file
  6878.    Start_Time := Clock;
  6879.    Int_Direct_IO.Delete (file);
  6880.    Delete_Time := Clock - Start_Time;
  6881.  
  6882.  
  6883.    Put ("Create File Time = ");
  6884.    Put (Create_Time, Fore => 0);
  6885.    put_line (" seconds ");
  6886.  
  6887.    Put ("Close File Time = ");
  6888.    Put (Close_Time, Fore => 0);
  6889.    put_line (" seconds ");
  6890.  
  6891.    Put ("Open File Time = ");
  6892.    Put (Open_Time, Fore => 0);
  6893.    put_line (" seconds ");
  6894.  
  6895.    Put ("Delete File Time = ");
  6896.    Put (Delete_Time, Fore => 0);
  6897.    put_line (" seconds ");
  6898.  
  6899.    Put("Loop time = ");
  6900.    Put(Loop_Time, Fore => 0);
  6901.    Put(" seconds for ");
  6902.    Put(Times, Width => 0);
  6903.    Put_Line(" iterations");
  6904.  
  6905.  
  6906.    Put("Elapsed time = ");
  6907.    Put(Write_Time, Fore => 0);
  6908.    Put(" seconds for ");
  6909.    Put(Times, Width => 0);
  6910.    Put_Line(" Writes");
  6911.  
  6912.    Average_Time := Real_Time(Write_Time - Loop_Time)/Real_Time(Times);
  6913.    Put("Average time for a Write = ");
  6914.    Put(Average_Time, Fore => 0);
  6915.    Put_Line(" seconds");
  6916.  
  6917.    New_Line;
  6918.  
  6919.  
  6920.  
  6921.    Put("Elapsed time = ");
  6922.    Put(Read_Time, Fore => 0);
  6923.    Put(" seconds for ");
  6924.    Put(Times, Width => 0);
  6925.    Put_Line(" Reads");
  6926.  
  6927.    Average_Time := Real_Time(Read_Time - Loop_Time)/Real_Time(Times);
  6928.    Put("Average time for a Read = ");
  6929.    Put(Average_Time, Fore => 0);
  6930.    Put_Line(" seconds");
  6931.  
  6932.    New_Line;
  6933.  
  6934.    if (Read_Time  - Loop_Time < 100 * Duration'Small)    or
  6935.       (Read_Time  - Loop_Time < 100 * System.Tick)    or
  6936.       (Write_Time - Loop_Time < 100 * Duration'Small)    or
  6937.       (Write_Time - Loop_Time < 100 * System.Tick)    then
  6938.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  6939.    else
  6940.       Put_Line("** TEST PASSED **");
  6941.    end if;
  6942.  
  6943. end Integer_Direct_IO_Test;
  6944. ::::::::::
  6945. INT_TEXT.ADA
  6946. ::::::::::
  6947. -------------------------------------------------------------------
  6948. ---------------------  Next  Program  -----------------------------
  6949. -------------------------------------------------------------------
  6950.  
  6951. --
  6952. -- Version: @(#)int_text.ada    1.2        Date: 9/21/84
  6953. --
  6954. -- Author:  Edward Colbert
  6955. --        Ada Technology Group
  6956. --        Information Software Systems Lab
  6957. --        Defense Systems Group
  6958. --        TRW
  6959. --        Redondo Beach, CA
  6960. --
  6961. -- This program measures the time required for doing various file
  6962. -- operations using the Text_IO package with Integers.
  6963. --
  6964. -- Note:  In order for the measurement to be meaningful, it must be the 
  6965. -- only program executing while the test is run.  
  6966. --
  6967. -- Please set Times large enough to provide at least two significant 
  6968. -- digits in the average times, i.e., the difference between 
  6969. -- the elapsed time and the loop time must be at least 100 times 
  6970. -- Duration'Small & at least 100 times System.Tick.
  6971. --
  6972.  
  6973. with Text_IO; use Text_IO;
  6974. with Calendar; use Calendar;
  6975. with System; use System;
  6976. procedure Integer_Text_IO_Test is
  6977.  
  6978.    Times : constant Positive := 1000;
  6979.  
  6980.    type Real_Time is digits Max_Digits;
  6981.  
  6982.    Start_Time : Time;
  6983.    Loop_Time : Duration;
  6984.    Average_Time : Real_Time;
  6985.    Create_Time : Duration;
  6986.    Close_Time  : Duration;
  6987.    Open_Time   : Duration;
  6988.    Delete_Time : Duration;
  6989.    Read_Time   : Duration;
  6990.    Write_Time  : Duration;
  6991.  
  6992.    package Duration_IO is new Fixed_IO (Duration);
  6993.    use Duration_IO;
  6994.  
  6995.    package Real_Time_IO is new Float_IO (Real_Time);
  6996.    use Real_Time_IO;
  6997.  
  6998.    package Int_IO is new Integer_IO (Integer);
  6999.    use Int_IO;
  7000.  
  7001.    file:   Text_IO.file_type;
  7002.    value:  Integer := 5;
  7003.    count:  Integer := Integer'first;    -- used in timing loop
  7004.  
  7005. begin
  7006.  
  7007.    -- Measure the timing loop overhead.
  7008.    Start_Time := Clock;
  7009.    for N in 1 .. Times loop
  7010.       count := count + 1;        -- prevent optimization
  7011.    end loop;
  7012.    Loop_Time := Clock - Start_Time;
  7013.  
  7014.  
  7015.    -- Create a file
  7016.    Start_Time := Clock;
  7017.    Text_IO.Create (file, mode => out_file, name => "test_file");
  7018.    Create_Time := Clock - Start_Time;
  7019.  
  7020.    -- Measure the time of Writing of value
  7021.    Start_Time := Clock;
  7022.    for N in 1 .. Times loop
  7023.       count := count + 1;
  7024.       Int_IO.put (file, value);
  7025.    end loop;
  7026.    Write_Time := Clock - Start_Time;
  7027.  
  7028.    -- Close a file
  7029.    Start_Time := Clock;
  7030.    Text_IO.Close (file);
  7031.    Close_Time := Clock - Start_Time;
  7032.  
  7033.    -- Open a file
  7034.    Start_Time := Clock;
  7035.    Text_IO.Open (file, mode => in_file, name => "test_file");
  7036.    Open_Time := Clock - Start_Time;
  7037.  
  7038.    -- Measure the time of Reading of value
  7039.    Start_Time := Clock;
  7040.    for N in 1 .. Times loop
  7041.       count := count + 1;
  7042.       Int_IO.get (file, value);
  7043.    end loop;
  7044.    Read_Time := Clock - Start_Time;
  7045.  
  7046.    -- Delete a file
  7047.    Start_Time := Clock;
  7048.    Text_IO.Delete (file);
  7049.    Delete_Time := Clock - Start_Time;
  7050.  
  7051.  
  7052.    Put ("Create File Time = ");
  7053.    Put (Create_Time, Fore => 0);
  7054.    put_line (" seconds ");
  7055.  
  7056.    Put ("Close File Time = ");
  7057.    Put (Close_Time, Fore => 0);
  7058.    put_line (" seconds ");
  7059.  
  7060.    Put ("Open File Time = ");
  7061.    Put (Open_Time, Fore => 0);
  7062.    put_line (" seconds ");
  7063.  
  7064.    Put ("Delete File Time = ");
  7065.    Put (Delete_Time, Fore => 0);
  7066.    put_line (" seconds ");
  7067.  
  7068.    Put("Loop time = ");
  7069.    Put(Loop_Time, Fore => 0);
  7070.    Put(" seconds for ");
  7071.    Put(Times, Width => 0);
  7072.    Put_Line(" iterations");
  7073.  
  7074.  
  7075.    Put("Elapsed time = ");
  7076.    Put(Write_Time, Fore => 0);
  7077.    Put(" seconds for ");
  7078.    Put(Times, Width => 0);
  7079.    Put_Line(" Writes");
  7080.  
  7081.    Average_Time := Real_Time(Write_Time - Loop_Time)/Real_Time(Times);
  7082.    Put("Average time for a Write = ");
  7083.    Put(Average_Time, Fore => 0);
  7084.    Put_Line(" seconds");
  7085.  
  7086.    New_Line;
  7087.  
  7088.  
  7089.  
  7090.    Put("Elapsed time = ");
  7091.    Put(Read_Time, Fore => 0);
  7092.    Put(" seconds for ");
  7093.    Put(Times, Width => 0);
  7094.    Put_Line(" Reads");
  7095.  
  7096.    Average_Time := Real_Time(Read_Time - Loop_Time)/Real_Time(Times);
  7097.    Put("Average time for a Read = ");
  7098.    Put(Average_Time, Fore => 0);
  7099.    Put_Line(" seconds");
  7100.  
  7101.    New_Line;
  7102.  
  7103.    if (Read_Time  - Loop_Time < 100 * Duration'Small)    or
  7104.       (Read_Time  - Loop_Time < 100 * System.Tick)    or
  7105.       (Write_Time - Loop_Time < 100 * Duration'Small)    or
  7106.       (Write_Time - Loop_Time < 100 * System.Tick)    then
  7107.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  7108.    else
  7109.       Put_Line("** TEST PASSED **");
  7110.    end if;
  7111.  
  7112. end Integer_Text_IO_Test;
  7113. ::::::::::
  7114. INTVEC.ADA
  7115. ::::::::::
  7116. -------------------------------------------------------------------
  7117. ---------------------  Next  Program  -----------------------------
  7118. -------------------------------------------------------------------
  7119.  
  7120. --
  7121. -- Version: @(#)intvec.ada    1.2        Date: 9/21/84
  7122. --
  7123. -- Author:  Edward Colbert
  7124. --        Ada Technology Group
  7125. --        Information Software Systems Lab
  7126. --        Defense Systems Group
  7127. --        TRW
  7128. --        Redondo Beach, CA
  7129. --
  7130. -- This program measures the time required for the adding of the
  7131. -- elements of a large integer vector
  7132. --
  7133. -- Note:  In order for the measurement to be meaningful, it must be the 
  7134. -- only program executing while the test is run.  
  7135. --
  7136. -- Please set Vector_Size large enough to provide at least two significant 
  7137. -- digits in the average times, i.e., the difference between 
  7138. -- the elapsed time and the loop time must be at least 100 times 
  7139. -- Duration'Small & at least 100 times System.Tick.
  7140. --
  7141.  
  7142. with Text_IO; use Text_IO;
  7143. with Calendar; use Calendar;
  7144. with System; use System;
  7145. procedure Integer_Vector_Add_Test is
  7146.  
  7147.    Vector_Size : constant Positive := 1000;
  7148.  
  7149.    type Real_Time is digits Max_Digits;
  7150.  
  7151.    Start_Time : Time;
  7152.    Loop_Time : Duration;
  7153.    Elapsed_Time : Duration;
  7154.    Average_Time : Real_Time;
  7155.  
  7156.    package Duration_IO is new Fixed_IO (Duration);
  7157.    use Duration_IO;
  7158.  
  7159.    package Real_Time_IO is new Float_IO (Real_Time);
  7160.    use Real_Time_IO;
  7161.  
  7162.    package Int_IO is new Integer_IO (Integer);
  7163.    use Int_IO;
  7164.  
  7165.    type vector is array (1..Vector_Size) of integer;
  7166.    
  7167.    v1, v2, vector_result: vector;
  7168.    count:  integer := integer'first;    -- used in timing loop
  7169.  
  7170. begin
  7171.  
  7172.    -- Initialize Vectors
  7173.    for N in vector'range loop
  7174.       v1(N) := N;
  7175.       v2(N) := vector'last - N + 1;
  7176.    end loop;
  7177.  
  7178.    -- Measure the timing loop overhead.
  7179.    Start_Time := Clock;
  7180.    for N in vector'range loop
  7181.       count := count + 1;        -- prevent optimization
  7182.    end loop;
  7183.    Loop_Time := Clock - Start_Time;
  7184.  
  7185.  
  7186.    -- Measure the time including the adding of vector elements
  7187.    Start_Time := Clock;
  7188.    for N in vector'range loop
  7189.       count := count + 1;        -- prevent optimization
  7190.       vector_result (n) := v1(n) + v2(n);
  7191.    end loop;
  7192.    Elapsed_Time := Clock - Start_Time;
  7193.  
  7194.  
  7195.    Put("Loop time = ");
  7196.    Put(Loop_Time, Fore => 0);
  7197.    Put(" seconds for ");
  7198.    Put(Vector_Size, Width => 0);
  7199.    Put_Line(" iterations");
  7200.  
  7201.  
  7202.    Put("Elapsed time = ");
  7203.    Put(Elapsed_Time, Fore => 0);
  7204.    Put(" seconds for ");
  7205.    Put(Vector_Size, Width => 0);
  7206.    Put_Line(" Elements");
  7207.  
  7208.    Average_Time := Real_Time(Elapsed_Time - Loop_Time)/Real_Time(Vector_Size);
  7209.    Put("Average time for adding each element = ");
  7210.    Put(Average_Time, Fore => 0);
  7211.    Put_Line(" seconds");
  7212.  
  7213.    New_Line;
  7214.    if (Elapsed_Time - Loop_Time < 100 * Duration'Small    or
  7215.        Elapsed_Time - Loop_Time < 100 * System.Tick)    then
  7216.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  7217.    else
  7218.       Put_Line("** TEST PASSED **");
  7219.    end if;
  7220.  
  7221. end Integer_Vector_Add_Test;
  7222. ::::::::::
  7223. LOWLEV.ADA
  7224. ::::::::::
  7225. -------------------------------------------------------------------
  7226. ---------------------  Next  Program  -----------------------------
  7227. -------------------------------------------------------------------
  7228.  
  7229. --
  7230. -- Version: @(#)lowlev.ada    1.1        Date: 5/30/84
  7231. --
  7232. -- Author:  Bryce Bardin
  7233. --          Ada Projects Section
  7234. --          Software Engineering Division
  7235. --          Ground Systems Group
  7236. --          Hughes Aircraft Company
  7237. --          Fullerton, CA
  7238. --
  7239. -- The following program tests length clauses in conjunction with 
  7240. -- unchecked conversion.
  7241. --
  7242. -- Before running the test, No_Of_Bits must be set to the base 2 logarithm 
  7243. -- of the successor of System.Max_Int, i.e., the total number of bits in 
  7244. -- the largest integer type supported.
  7245. -- Note:  The place where this change is to be made is flagged by a 
  7246. -- comment prefixed by "--!".  
  7247. --
  7248. -- For a compiler to pass this test, it must obey the length clauses 
  7249. -- and instantiate and use the unchecked conversions correctly.
  7250. -- The output will consist of Cases sets of three identical values.
  7251. -- If a conversion fails, the line will be flagged as an error.  A summary
  7252. -- error count and a "pass/fail" message will be output.
  7253. -- Ideally, an assembly listing should be provided which demonstrates 
  7254. -- the efficiency of the compiled code.
  7255. --
  7256.  
  7257.  
  7258. with Text_IO; use Text_IO;
  7259. with Unchecked_Conversion;
  7260. with System;
  7261. procedure Change_Types is
  7262.  
  7263. --! Change this to Log2 (System.Max_Int + 1):
  7264.    No_Of_Bits : constant := 32;
  7265.  
  7266.    Cases : constant := 100;
  7267.  
  7268.    type Int is range 0 .. 2**No_Of_Bits - 1;
  7269.    for Int'Size use No_Of_Bits;
  7270.    
  7271. --! Change this to System.Max_Int/(Cases - 1):
  7272.    Increment : constant Int := System.Max_Int/(Cases - 1);
  7273.  
  7274.    type Bit is (Off, On);
  7275.    for Bit use (Off => 0, On => 1);
  7276.    for Bit'Size use 1;
  7277.  
  7278.    subtype Bits is Positive range 1 .. No_Of_Bits;
  7279.  
  7280.    type Bit_String is array (Bits) of Bit;
  7281.    for Bit_String'Size use No_Of_Bits;
  7282.  
  7283.    I : Int;
  7284.    J : Int;
  7285.    B : Bit_String;
  7286.    Errors : Natural := 0;
  7287.    Column : constant := 16;
  7288.  
  7289.    package Int_IO is new Integer_IO(Int);
  7290.    use Int_IO;
  7291.  
  7292.    package Nat_IO is new Integer_IO(Natural);
  7293.    use Nat_IO;
  7294.  
  7295.    procedure Put (B : Bit_String) is
  7296.    begin
  7297.       Put("2#");
  7298.       for N in Bits loop
  7299.      if B(N) = On then
  7300.         Put("1");
  7301.      else
  7302.         Put("0");
  7303.      end if;
  7304.       end loop;
  7305.       Put("#");
  7306.    end Put;
  7307.  
  7308.    function To_Bit_String is new Unchecked_Conversion (Int, Bit_String);
  7309.  
  7310.    function To_Int is new Unchecked_Conversion (Bit_String, Int);
  7311.  
  7312. begin
  7313.  
  7314.    for N in 1 .. Cases loop
  7315.  
  7316.       I := Int(N-1) * Increment;
  7317.       B := To_Bit_String(I);
  7318.       J := To_Int(B);
  7319.  
  7320.       if J /= I then
  7321.      Errors := Errors + 1;
  7322.      Put("*** ERROR ***");
  7323.       end if;
  7324.  
  7325.       Set_Col(To => Column);
  7326.       Put("I = ");
  7327.       Put(I, Base => 2);
  7328.       Put_Line(",");
  7329.  
  7330.       Set_Col(To => Column);
  7331.       Put("B = ");
  7332.       Put(B);
  7333.       Put_Line(",");
  7334.  
  7335.       Set_Col(To => Column);
  7336.       Put("J = ");
  7337.       Put(J, Base => 2);
  7338.       Put(".");
  7339.       New_Line(2);
  7340.  
  7341.    end loop;
  7342.  
  7343.    New_Line(2);
  7344.  
  7345.    if Errors > 0 then
  7346.       Put_Line("*** TEST FAILED! ***");
  7347.       if Errors = 1 then
  7348.      Put_Line("There was 1 error.");
  7349.       else
  7350.      Put("There were ");
  7351.      Put(Errors, Width => 0);
  7352.      Put_Line(" errors.");
  7353.       end if;
  7354.    else
  7355.       Put_Line("TEST PASSED!");
  7356.       Put_Line("There were no errors.");
  7357.    end if;
  7358.  
  7359. end Change_Types;
  7360. ::::::::::
  7361. PROCCAL.ADA
  7362. ::::::::::
  7363. -------------------------------------------------------------------
  7364. ---------------------  Next  Program  -----------------------------
  7365. -------------------------------------------------------------------
  7366.  
  7367. --
  7368. -- Version: @(#)proccal.ada    1.2        Date: 9/21/84
  7369. --
  7370. --
  7371. -- Author:  Bryce Bardin
  7372. --          Ada Projects Section
  7373. --          Software Engineering Division
  7374. --          Ground Systems Group
  7375. --          Hughes Aircraft Company
  7376. --          Fullerton, CA
  7377. --
  7378. -- This program measures the time required for simple procedure calls 
  7379. -- with scalar parameters.
  7380. --
  7381. -- Note:  In order for the measurement to be meaningful, it must be the 
  7382. -- only program executing while the test is run.  
  7383. --
  7384. -- Please set Times large enough to provide at least two significant 
  7385. -- digits in the average calling times, i.e., the differences between 
  7386. -- the elapsed times and the corresponding loop times for each form of
  7387. -- call should be greater than 100 times Duration'Small & greater than
  7388. -- 100 times System.Tick.
  7389.  
  7390. with Text_IO; use Text_IO;
  7391. with Calendar; use Calendar;
  7392. with System; use System;
  7393. procedure Procedure_Call is
  7394.  
  7395.    Times : constant Positive := 1000;
  7396.  
  7397.    type Real_Time is digits Max_Digits;
  7398.  
  7399.    Start_Time : Time;
  7400.    Loop_Time : Duration;
  7401.    Elapsed_Time : Duration;
  7402.    Average_Time : Real_Time;
  7403.  
  7404.    Insufficient_Precision : Boolean := False;
  7405.  
  7406.    package Duration_IO is new Fixed_IO (Duration);
  7407.    use Duration_IO;
  7408.  
  7409.    package Real_Time_IO is new Float_IO (Real_Time);
  7410.    use Real_Time_IO;
  7411.  
  7412.    package Int_IO is new Integer_IO (Integer);
  7413.    use Int_IO;
  7414.  
  7415.    type Cases is range 1 .. 4;
  7416.  
  7417.    Kind : array (Cases) of String (1 .. 22) :=
  7418.       ("No parameter call:    ",
  7419.        "In parameter call:    ",
  7420.        "Out parameter call:   ",
  7421.        "In Out parameter call:");
  7422.  
  7423.    -- This package is used to prevent elimination of a "null" call
  7424.    -- by a smart compiler.
  7425.    package Prevent is
  7426.       Counter : Natural := 0;
  7427.       procedure Prevent_Optimization;
  7428.    end Prevent;
  7429.    use Prevent;
  7430.  
  7431.    procedure Call is
  7432.    begin
  7433.       Prevent_Optimization;
  7434.    end Call;
  7435.  
  7436.    procedure Call_In (N : in Natural) is
  7437.    begin
  7438.       Counter := N;
  7439.    end Call_In;
  7440.  
  7441.    procedure Call_Out (N : out Natural) is
  7442.    begin
  7443.       N := Counter;
  7444.    end Call_Out;
  7445.  
  7446.    procedure Call_In_Out (N : in out Natural) is
  7447.    begin
  7448.       N := Counter;
  7449.    end Call_In_Out;
  7450.  
  7451. -- This procedure determines if Times is large enough to assure adequate 
  7452. -- precision in the timings.
  7453.    procedure Check_Precision is
  7454.    begin
  7455.       if (Elapsed_Time - Loop_Time < 100 * Duration'Small    or
  7456.           Elapsed_Time - Loop_Time < 100 * System.Tick)    then
  7457.      Insufficient_Precision := True;
  7458.       end if;
  7459.    end Check_Precision;
  7460.  
  7461.    package body Prevent is
  7462.       procedure Prevent_Optimization is
  7463.       begin
  7464.      Counter := Counter + 1;
  7465.       end Prevent_Optimization;
  7466.    end Prevent;
  7467.  
  7468. begin
  7469.  
  7470.    for Case_Number in Cases loop
  7471.  
  7472.       -- Measure the timing loop overhead.
  7473.       Start_Time := Clock;
  7474.       for N in 1 .. Times loop
  7475.      case Case_Number is
  7476.         when 1 =>
  7477.            Prevent_Optimization;
  7478.         when 2 =>
  7479.            Counter := N;
  7480.         when 3 =>
  7481.            Counter := N;
  7482.         when 4 =>
  7483.            Counter := N;
  7484.      end case;
  7485.       end loop;
  7486.       Loop_Time := Clock - Start_Time;
  7487.  
  7488.       -- Measure the time including the procedure call.
  7489.       Start_Time := Clock;
  7490.       for N in 1 .. Times loop
  7491.      case Case_Number is
  7492.         when 1 =>
  7493.            Call;
  7494.         when 2 =>
  7495.            Call_In(Counter);
  7496.         when 3 =>
  7497.            Call_Out(Counter);
  7498.         when 4 =>
  7499.            Call_In_Out(Counter);
  7500.      end case;
  7501.       end loop;
  7502.       Elapsed_Time := Clock - Start_Time;
  7503.  
  7504.       Check_Precision;
  7505.  
  7506.       -- Calculate timing and output the result
  7507.  
  7508.       Put(Kind(Case_Number));
  7509.       New_Line(2);
  7510.  
  7511.       Put("Loop time = ");
  7512.       Put(Loop_Time, Fore => 0);
  7513.       Put(" seconds for ");
  7514.       Put(Times, Width => 0);
  7515.       Put_Line(" iterations");
  7516.  
  7517.       Put("Elapsed time = ");
  7518.       Put(Elapsed_Time, Fore => 0);
  7519.       Put(" seconds for ");
  7520.       Put(Times, Width => 0);
  7521.       Put_Line(" iterations");
  7522.  
  7523.       Average_Time := Real_Time(Elapsed_Time - Loop_Time)/Real_Time(Times);
  7524.       New_Line;
  7525.       Put("Average time for a call = ");
  7526.       Put(Average_Time);
  7527.       Put_Line(" seconds");
  7528.       New_Line(3);
  7529.  
  7530.    end loop;
  7531.  
  7532.    if Insufficient_Precision then
  7533.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  7534.    else
  7535.       Put_Line("TEST PASSED");
  7536.    end if;
  7537.  
  7538. end Procedure_Call;
  7539. ::::::::::
  7540. QSORTPAR.ADA
  7541. ::::::::::
  7542. -------------------------------------------------------------------
  7543. ---------------------  Next  Program  -----------------------------
  7544. -------------------------------------------------------------------
  7545.  
  7546.  
  7547. ----------------------------------------------------------------------
  7548. --
  7549. --             QUICK SORT BENCHMARK
  7550. --
  7551. --          Version: @(#)qsortpar.ada    1.1    Date: 6/5/84
  7552. --
  7553. --                Gerry Fisher
  7554. --            Computer Sciences Corporation
  7555. --
  7556. --                May 26, 1984
  7557. --
  7558. --  This benchmark consists of two versions of the familiar quick
  7559. --  sort algorithm: a parallel version and a sequential version.
  7560. --  A relatively small vector (length 100) is sorted into ascending
  7561. --  sequence.  The number of comparisons and exchanges is counted.
  7562. --  In the parallel version separate tasks are created to sort the
  7563. --  two subvectors created by partitioning the vector.  Each task
  7564. --  invokes the quicksort procedure.  The parallel version is
  7565. --  functionally equivalent to the sequential version and should
  7566. --  require the same number of comparisions and exchanges.  A check
  7567. --  is made to verify that this is so.  Also, the sorted vector is
  7568. --  checked to verify that the sort has been performed correctly.
  7569. --  Control is exercised so that no more than fourteen tasks are
  7570. --  created when sorting the vector.
  7571. --
  7572. --  The sorting is repeated a number of times to obtain a measurable
  7573. --  amount of execution time.
  7574. --
  7575. --  The important measure for this benchmark is the ratio of the
  7576. --  execution time of the parallel version to that of the sequential
  7577. --  version.  This will give some indication of task activation and
  7578. --  scheduling overhead.
  7579. --
  7580. --  One file is used for both versions.  The boolean constant "p"
  7581. --  indicates whether the parallel or serial version of the algorithm
  7582. --  is to be used.  Simply set this constant TRUE for the parallel
  7583. --  test and FALSE for the sequential test.  A difference in code
  7584. --  size between the two tests may indicate that conditional
  7585. --  compilation is supported by the compiler.
  7586. --
  7587. ------------------------------------------------------------------------
  7588.  
  7589. with text_io; use text_io;
  7590. procedure main is
  7591.    failed : exception;
  7592.  
  7593.    type vector is array(integer range <>) of integer;
  7594.    type stats  is record c, e : integer := 0; end record;
  7595.  
  7596.    p : constant boolean := true;    -- true for parallel algorithm
  7597.    n : constant integer := 100;        -- size of vector to be sorted
  7598.    m : constant integer := 100;        -- number of times to sort vector
  7599.  
  7600.    x : vector(1 .. n);
  7601.  
  7602.    y : stats;
  7603.  
  7604.    procedure Quick_sort(A : in out vector; w : out stats) is
  7605.      lb : constant integer := A'first;
  7606.      ub : constant integer := A'last;
  7607.      k    : integer;
  7608.  
  7609.      c, e : integer := 0;
  7610.      u, v : stats;
  7611.  
  7612.      function partition(L, U : integer) return integer is
  7613.        q, r, i, j : integer;
  7614.      begin
  7615.  
  7616.        r := A((U + L)/2);
  7617.        i := L;
  7618.        j := U;
  7619.  
  7620.        while i < j loop
  7621.       while A(i) < r loop
  7622.         c := c + 1;
  7623.         i := i + 1;
  7624.       end loop;
  7625.  
  7626.       while A(j) > r loop
  7627.         c := c + 1;
  7628.         j := j - 1;
  7629.       end loop;
  7630.  
  7631.       c := c + 2;
  7632.  
  7633.       if i <= j then
  7634.         e := e + 1;
  7635.         q := A(i);
  7636.         A(i) := A(j);
  7637.         A(j) := q;
  7638.         i := i + 1;
  7639.         j := j - 1;
  7640.       end if;
  7641.        end loop;
  7642.  
  7643.        if j > L then
  7644.      return j;
  7645.        else
  7646.      return L;
  7647.        end if;
  7648.  
  7649.      end partition;
  7650.  
  7651.    begin
  7652.      if lb < ub then
  7653.  
  7654.       k := partition(lb, ub);
  7655.  
  7656.       if ub > lb + 15 then
  7657.        if p then
  7658.     declare
  7659.       task S1;
  7660.       task body S1 is
  7661.       begin
  7662.         Quick_sort(A(lb .. k), u);
  7663.       end S1;
  7664.  
  7665.       task S2;
  7666.       task body S2 is
  7667.       begin
  7668.         Quick_sort(A(k + 1 .. ub), v);
  7669.       end S2;
  7670.     begin
  7671.       null;
  7672.     end;
  7673.  
  7674.        else
  7675.     Quick_sort(A(lb .. k), u);
  7676.     Quick_sort(A(k + 1 .. ub), v);
  7677.        end if;
  7678.  
  7679.       elsif ub > lb + 1 then
  7680.     Quick_sort(A(lb .. k), u);
  7681.     Quick_sort(A(k + 1 .. ub), v);
  7682.       end if;
  7683.  
  7684.       e := e + u.e + v.e;
  7685.       c := c + u.c + v.c;
  7686.  
  7687.      end if;
  7688.  
  7689.      w := (c, e);
  7690.  
  7691.    end Quick_sort;
  7692.  
  7693. begin
  7694.  
  7695.   set_line_length(count(50));
  7696.   if p then
  7697.     put_line("*** Starting Parallel Quick Sort Benchmark");
  7698.   else
  7699.     put_line("*** Starting Sequential Quick Sort Benchmark");
  7700.   end if;
  7701.  
  7702.   for k in 1 .. m loop
  7703.  
  7704.    for i in x'range loop
  7705.      x(i) := x'last - i + 1;
  7706.    end loop;
  7707.  
  7708.    Quick_sort(x, y);
  7709.  
  7710.    for i in x'first .. x'last - 1 loop
  7711.      if x(i) > x(i + 1) then
  7712.        raise failed;
  7713.      end if;
  7714.   end loop;
  7715.  
  7716.   put(".");
  7717.  
  7718.  end loop;
  7719.  
  7720.  new_line;
  7721.  
  7722.  if y.c /= 782 or else y.e /= 148 then
  7723.    put_line("*** FAILED Wrong number of comparisons or exchanges");
  7724.  else
  7725.    put_line("*** PASSED Sorting test");
  7726.  end if;
  7727.  
  7728. exception
  7729.   when failed => put_line("*** FAILED Vector not sorted");
  7730.  
  7731. end main;
  7732. ::::::::::
  7733. QSORTSEQ.ADA
  7734. ::::::::::
  7735. -------------------------------------------------------------------
  7736. ---------------------  Next  Program  -----------------------------
  7737. -------------------------------------------------------------------
  7738.  
  7739.  
  7740. ----------------------------------------------------------------------
  7741. --
  7742. --             QUICK SORT BENCHMARK
  7743. --
  7744. --        Version: @(#)qsortseq.ada    1.1    Date: 6/5/84
  7745. --
  7746. --                Gerry Fisher
  7747. --            Computer Sciences Corporation
  7748. --                May 27, 1984
  7749. --
  7750. --
  7751. --  This benchmark consists of two versions of the familiar quick
  7752. --  sort algorithm: a parallel version and a sequential version.
  7753. --  A relatively small vector (length 100) is sorted into ascending
  7754. --  sequence.  The number of comparisons and exchanges is counted.
  7755. --  In the parallel version separate tasks are created to sort the
  7756. --  two subvectors created by partitioning the vector.  Each task
  7757. --  invokes the quicksort procedure.  The parallel version is
  7758. --  functionally equivalent to the sequential version and should
  7759. --  require the same number of comparisions and exchanges.  A check
  7760. --  is made to verify that this is so.  Also, the sorted vector is
  7761. --  checked to verify that the sort has been performed correctly.
  7762. --  Control is exercised so that no more than fourteen tasks are
  7763. --  created when sorting the vector.
  7764. --
  7765. --  The sorting is repeated a number of times to obtain a measurable
  7766. --  amount of execution time.
  7767. --
  7768. --  The important measure for this benchmark is the ratio of the
  7769. --  execution time of the parallel version to that of the sequential
  7770. --  version.  This will give some indication of task activation and
  7771. --  scheduling overhead.
  7772. --
  7773. --  One file is used for both versions.  The boolean constant "p"
  7774. --  indicates whether the parallel or serial version of the algorithm
  7775. --  is to be used.  Simply set this constant TRUE for the parallel
  7776. --  test and FALSE for the sequential test.  A difference in code
  7777. --  size between the two tests may indicate that conditional
  7778. --  compilation is supported by the compiler.
  7779. --
  7780. --------------------------------------------------------------------
  7781.  
  7782. with text_io; use text_io;
  7783. procedure main is
  7784.    failed : exception;
  7785.  
  7786.    type vector is array(integer range <>) of integer;
  7787.    type stats  is record c, e : integer := 0; end record;
  7788.  
  7789.    p : constant boolean := false;    -- true for parallel algorithm
  7790.    n : constant integer := 100;        -- size of vector to be sorted
  7791.    m : constant integer := 100;        -- number of times to sort vector
  7792.  
  7793.    x : vector(1 .. n);
  7794.  
  7795.    y : stats;
  7796.  
  7797.    procedure Quick_sort(A : in out vector; w : out stats) is
  7798.      lb : constant integer := A'first;
  7799.      ub : constant integer := A'last;
  7800.      k    : integer;
  7801.  
  7802.      c, e : integer := 0;
  7803.      u, v : stats;
  7804.  
  7805.      function partition(L, U : integer) return integer is
  7806.        q, r, i, j : integer;
  7807.      begin
  7808.  
  7809.        r := A((U + L)/2);
  7810.        i := L;
  7811.        j := U;
  7812.  
  7813.        while i < j loop
  7814.       while A(i) < r loop
  7815.         c := c + 1;
  7816.         i := i + 1;
  7817.       end loop;
  7818.  
  7819.       while A(j) > r loop
  7820.         c := c + 1;
  7821.         j := j - 1;
  7822.       end loop;
  7823.  
  7824.       c := c + 2;
  7825.  
  7826.       if i <= j then
  7827.         e := e + 1;
  7828.         q := A(i);
  7829.         A(i) := A(j);
  7830.         A(j) := q;
  7831.         i := i + 1;
  7832.         j := j - 1;
  7833.       end if;
  7834.        end loop;
  7835.  
  7836.        if j > L then
  7837.      return j;
  7838.        else
  7839.      return L;
  7840.        end if;
  7841.  
  7842.      end partition;
  7843.  
  7844.    begin
  7845.      if lb < ub then
  7846.  
  7847.       k := partition(lb, ub);
  7848.  
  7849.       if ub > lb + 15 then
  7850.        if p then
  7851.     declare
  7852.       task S1;
  7853.       task body S1 is
  7854.       begin
  7855.         Quick_sort(A(lb .. k), u);
  7856.       end S1;
  7857.  
  7858.       task S2;
  7859.       task body S2 is
  7860.       begin
  7861.         Quick_sort(A(k + 1 .. ub), v);
  7862.       end S2;
  7863.     begin
  7864.       null;
  7865.     end;
  7866.  
  7867.        else
  7868.     Quick_sort(A(lb .. k), u);
  7869.     Quick_sort(A(k + 1 .. ub), v);
  7870.        end if;
  7871.  
  7872.       elsif ub > lb + 1 then
  7873.     Quick_sort(A(lb .. k), u);
  7874.     Quick_sort(A(k + 1 .. ub), v);
  7875.       end if;
  7876.  
  7877.       e := e + u.e + v.e;
  7878.       c := c + u.c + v.c;
  7879.  
  7880.      end if;
  7881.  
  7882.      w := (c, e);
  7883.  
  7884.    end Quick_sort;
  7885.  
  7886. begin
  7887.  
  7888.   set_line_length(count(50));
  7889.   if p then
  7890.     put_line("*** Starting Parallel Quick Sort Benchmark");
  7891.   else
  7892.     put_line("*** Starting Sequential Quick Sort Benchmark");
  7893.   end if;
  7894.  
  7895.   for k in 1 .. m loop
  7896.  
  7897.    for i in x'range loop
  7898.      x(i) := x'last - i + 1;
  7899.    end loop;
  7900.  
  7901.    Quick_sort(x, y);
  7902.  
  7903.    for i in x'first .. x'last - 1 loop
  7904.      if x(i) > x(i + 1) then
  7905.        raise failed;
  7906.      end if;
  7907.   end loop;
  7908.  
  7909.   put(".");
  7910.  
  7911.  end loop;
  7912.  
  7913.  new_line;
  7914.  
  7915.  if y.c /= 782 or else y.e /= 148 then
  7916.    put_line("*** FAILED Wrong number of comparisons or exchanges");
  7917.  else
  7918.    put_line("*** PASSED Sorting test");
  7919.  end if;
  7920.  
  7921. exception
  7922.   when failed => put_line("*** FAILED Vector not sorted");
  7923.  
  7924. end main;
  7925.  
  7926. ::::::::::
  7927. RENDEZ.ADA
  7928. ::::::::::
  7929. -------------------------------------------------------------------
  7930. ---------------------  Next  Program  -----------------------------
  7931. -------------------------------------------------------------------
  7932.  
  7933.  
  7934. --
  7935. -- Version: @(#)rendez.ada    1.2        Date: 9/21/84
  7936. --
  7937. -- Author:  Bryce Bardin
  7938. --          Ada Projects Section
  7939. --          Software Engineering Division
  7940. --          Ground Systems Group
  7941. --          Hughes Aircraft Company
  7942. --          Fullerton, CA
  7943. --
  7944. -- This program measures the time required for a simple rendezvous.
  7945. --
  7946. -- Note:  In order for the measurement to be meaningful, it must be the 
  7947. -- only program executing while the test is run.  
  7948. --
  7949. -- Please set Times large enough to provide at least two significant 
  7950. -- digits in the average rendezvous times, i.e., the difference between 
  7951. -- the elapsed time and the loop time must be at least 100 times 
  7952. -- Duration'Small & at least 100 times System.Tick.
  7953.  
  7954. with Text_IO; use Text_IO;
  7955. with Calendar; use Calendar;
  7956. with System; use System;
  7957. procedure Rendezvous is
  7958.  
  7959.    Times : constant Positive := 1000;
  7960.  
  7961.    type Real_Time is digits Max_Digits;
  7962.  
  7963.    Start_Time : Time;
  7964.    Loop_Time : Duration;
  7965.    Elapsed_Time : Duration;
  7966.    Average_Time : Real_Time;
  7967.  
  7968.    package Duration_IO is new Fixed_IO (Duration);
  7969.    use Duration_IO;
  7970.  
  7971.    package Real_Time_IO is new Float_IO (Real_Time);
  7972.    use Real_Time_IO;
  7973.  
  7974.    package Int_IO is new Integer_IO (Integer);
  7975.    use Int_IO;
  7976.  
  7977.    task T is
  7978.       entry Call;
  7979.    end T;
  7980.  
  7981.    -- This package is used to prevent elimination of the "null" timing loop 
  7982.    -- by a smart compiler.
  7983.    package Prevent is
  7984.       Count : Natural := 0;
  7985.       procedure Prevent_Optimization;
  7986.    end Prevent;
  7987.    use Prevent;
  7988.  
  7989.    task body T is
  7990.    begin
  7991.       loop
  7992.      select
  7993.         accept Call;
  7994.      or
  7995.         terminate;
  7996.      end select;
  7997.       end loop;
  7998.    end T;
  7999.  
  8000.    package body Prevent is
  8001.       procedure Prevent_Optimization is
  8002.       begin
  8003.      Count := Count + 1;
  8004.       end Prevent_Optimization;
  8005.    end Prevent;
  8006.  
  8007. begin
  8008.  
  8009.    -- Measure the timing loop overhead.
  8010.    Start_Time := Clock;
  8011.    for N in 1 .. Times loop
  8012.       Prevent_Optimization;
  8013.    end loop;
  8014.    Loop_Time := Clock - Start_Time;
  8015.  
  8016.    -- Measure the time including rendezvous.
  8017.    Start_Time := Clock;
  8018.    for N in 1 .. Times loop
  8019.       Prevent_Optimization;
  8020.       T.Call;
  8021.    end loop;
  8022.  
  8023.    Put("Loop time = ");
  8024.    Put(Loop_Time, Fore => 0);
  8025.    Put(" seconds for ");
  8026.    Put(Times, Width => 0);
  8027.    Put_Line(" iterations");
  8028.  
  8029.    Elapsed_Time := Clock - Start_Time;
  8030.    Put("Elapsed time = ");
  8031.    Put(Elapsed_Time, Fore => 0);
  8032.    Put(" seconds for ");
  8033.    Put(Times, Width => 0);
  8034.    Put_Line(" iterations");
  8035.  
  8036.    Average_Time := Real_Time(Elapsed_Time - Loop_Time)/Real_Time(Times);
  8037.    Put("Average time for no-parameter rendezvous = ");
  8038.    Put(Average_Time, Fore => 0);
  8039.    Put_Line(" seconds");
  8040.  
  8041.    New_Line;
  8042.    if (Elapsed_Time - Loop_Time < 100 * Duration'Small    or
  8043.        Elapsed_Time - Loop_Time < 100 * System.Tick)    then
  8044.       Put_Line("** TEST FAILED (due to insufficient precision)! **");
  8045.    else
  8046.       Put_Line("** TEST PASSED **");
  8047.    end if;
  8048.  
  8049. end Rendezvous;
  8050. ::::::::::
  8051. SETS.ADA
  8052. ::::::::::
  8053. -------------------------------------------------------------------
  8054. ---------------------  Next  Program  -----------------------------
  8055. -------------------------------------------------------------------
  8056.  
  8057.  
  8058. --
  8059. -- Version: @(#)sets.ada    1.3        Date: 10/19/84
  8060. --
  8061. --
  8062. -- Author:  Bryce Bardin
  8063. --          Ada Projects Section
  8064. --          Software Engineering Division
  8065. --          Ground Systems Group
  8066. --          Hughes Aircraft Company
  8067. --          Fullerton, CA
  8068. --
  8069. -- This is a highly portable implementation of sets in Ada.
  8070. --
  8071. -- N. B.:  Vendors are invited to supply listings which demonstrate 
  8072. -- the quality of the code generated.
  8073. --
  8074. generic
  8075.    type Element is (<>);
  8076.    with function Image (E : Element) return String is Element'Image;
  8077. package Sets is
  8078.  
  8079.    type Set is private;
  8080.    -- A set of elements.
  8081.  
  8082.    Empty_Set : constant Set;
  8083.    -- The set of no elements.
  8084.  
  8085.    Full_Set : constant Set;
  8086.    -- The set of all elements.
  8087.  
  8088.    function "and" (Left, Right : Set) return Set;
  8089.    -- Returns the conjunction (intersection) of two sets.
  8090.    -- Usage:  S1 and S2
  8091.  
  8092.    function "or" (Left, Right : Set) return Set;
  8093.    -- Returns the inclusive disjunction (union) of two sets.
  8094.    -- Usage:  S1 or S2
  8095.  
  8096.    function "xor" (Left, Right : Set) return Set;
  8097.    -- Returns the exclusive disjunction of two sets.
  8098.    -- Usage:  S1 xor S2
  8099.  
  8100.    function "not" (Right : Set) return Set;
  8101.    -- Returns the negation (complement) of a set, i.e., the set of
  8102.    -- all elements not in Right.
  8103.    -- Usage:  not S
  8104.  
  8105.    function "-" (Left, Right : Set) return Set;
  8106.    -- Returns the difference of two sets, i.e., the set of elements
  8107.    -- in Left which are not in Right.
  8108.    -- Usage:  S1 - S2
  8109.  
  8110.    function "+" (Left : Element; Right : Set) return Set;
  8111.    -- Adds an element to a set.
  8112.    -- Returns the union (or) of an element with a set.
  8113.    -- Usage:  E + S
  8114.  
  8115.    function "+" (Left : Set; Right : Element) return Set;
  8116.    -- Adds an element to a set.
  8117.    -- Returns the union (or) of an element with a set.
  8118.    -- Usage:  S + E
  8119.  
  8120.    function "+" (Right : Element) return Set;
  8121.    -- Makes an element into a Set.
  8122.    -- Returns the union of the element with the Empty_Set.
  8123.    -- Usage:  + E
  8124.  
  8125.    function "+" (Left, Right : Element) return Set;
  8126.    -- Combines two elements into a Set.
  8127.    -- Returns the union (or) of two elements with the Empty_Set.
  8128.    -- Usage:  E1 + E2
  8129.  
  8130.    function "-" (Left : Set; Right : Element) return Set;
  8131.    -- Deletes an element from a set, i.e., removes it from the set
  8132.    -- if it is currently a member of the set, otherwise it returns
  8133.    -- the original set.
  8134.    -- Usage:  S - E
  8135.  
  8136. -- This function is predefined:
  8137. -- function "=" (Left, Right : Set) return Boolean;
  8138.    -- Tests whether Left is identical to Right.
  8139.    -- Usage: S1 = S2
  8140.  
  8141.    function "<=" (Left, Right : Set) return Boolean;
  8142.    -- Tests whether Left is contained in Right, i.e., whether Left 
  8143.    -- is a subset of Right.
  8144.    -- Usage:  S1 <= S2
  8145.  
  8146.    function Is_Member (S : Set; E : Element) return Boolean;
  8147.    -- Tests an element for membership in a set.
  8148.    -- Returns true if an element is in a set.
  8149.    -- Usage:  Is_Member (S, E)
  8150.  
  8151.    procedure Put (S : Set);
  8152.    -- Prints a set.
  8153.    -- Usage:  Put (S)
  8154.  
  8155. private
  8156.  
  8157.    type Set is array (Element) of Boolean;
  8158.    -- A set of elements.
  8159.  
  8160.    Empty_Set : constant Set := (Element => False);
  8161.    -- The set of no elements.
  8162.  
  8163.    Full_Set : constant Set := (Element => True);   
  8164.    -- The set of all elements.
  8165.  
  8166.    pragma Inline ("and");
  8167.    pragma Inline ("or");
  8168.    pragma Inline ("xor");
  8169.    pragma Inline ("not");
  8170.    pragma Inline ("-");
  8171.    pragma Inline ("+");
  8172.    pragma Inline ("<=");
  8173.    pragma Inline (Is_Member);
  8174.  
  8175. end Sets;
  8176.  
  8177. with Text_IO; use Text_IO;
  8178. package body Sets is
  8179.  
  8180.    type Bool is array (Element) of Boolean;
  8181.  
  8182.    function "and" (Left, Right : Set) return Set is
  8183.    begin
  8184.       return Set(Bool(Left) and Bool(Right));
  8185.    end "and";
  8186.  
  8187.    function "or" (Left, Right : Set) return Set is
  8188.    begin
  8189.       return Set(Bool(Left) or Bool(Right));
  8190.    end "or";
  8191.  
  8192.    function "xor" (Left, Right : Set) return Set is
  8193.    begin
  8194.       return Set(Bool(Left) xor Bool(Right));
  8195.    end "xor";
  8196.  
  8197.    function "not" (Right : Set) return Set is
  8198.    begin
  8199.       return Set(not Bool(Right));
  8200.    end "not";
  8201.  
  8202.    function "-" (Left, Right : Set) return Set is
  8203.    begin
  8204.       return (Left and not Right);
  8205.    end "-";
  8206.  
  8207.    function "+" (Left : Element; Right : Set) return Set is
  8208.       Temp : Set := Right;
  8209.    begin
  8210.       Temp(Left) := True;
  8211.       return Temp;
  8212.    end "+";
  8213.  
  8214.    function "+" (Left : Set; Right : Element) return Set is
  8215.       Temp : Set := Left;
  8216.    begin
  8217.       Temp(Right) := True;
  8218.       return Temp;
  8219.    end "+";
  8220.  
  8221.    function "+" (Right : Element) return Set is
  8222.    begin
  8223.       return Empty_Set + Right;
  8224.    end "+";
  8225.  
  8226.    function "+" (Left, Right : Element) return Set is
  8227.    begin
  8228.       return Empty_Set + Left + Right;
  8229.    end "+";
  8230.  
  8231.    function "-" (Left : Set; Right : Element) return Set is
  8232.       Temp : Set := Left;
  8233.    begin
  8234.       Temp(Right) := False;
  8235.       return Temp;
  8236.    end "-";
  8237.  
  8238.    function "<=" (Left, Right : Set) return Boolean is
  8239.    begin
  8240.       return ((Left and not Right) = Empty_Set);
  8241.    end "<=";
  8242.  
  8243.    function Is_Member (S : Set; E : Element) return Boolean is
  8244.    begin
  8245.       return (S(E) = True);
  8246.    end Is_Member;
  8247.  
  8248.    procedure Put (S : Set) is
  8249.       Comma_Needed : Boolean := False;
  8250.    begin
  8251.       Text_IO.Put ("{");
  8252.       for E in Element loop
  8253.          if S(E) then
  8254.             if Comma_Needed then
  8255.                Text_IO.Put (",");
  8256.             end if;
  8257.             Text_IO.Put (Image(E));
  8258.             Comma_Needed := True;
  8259.          end if;
  8260.       end loop;
  8261.       Text_IO.Put ("}");
  8262.       New_Line;
  8263.    end Put;
  8264.  
  8265. end Sets;
  8266.  
  8267.  
  8268. -- This procedure tests the set package.
  8269. -- Its output is self-explanatory.
  8270. with Text_IO; use Text_IO;
  8271. with Sets;
  8272. procedure Main is
  8273.  
  8274.    type Color is (Red, Yellow, Green, Blue);
  8275.  
  8276.    package Color_Set is new Sets(Color);
  8277.    use Color_Set;
  8278.  
  8279.    X, Y, Z : Set;
  8280.  
  8281.    procedure Put_Set (Name : String; S : Set) is
  8282.    begin
  8283.       Put (Name);
  8284.       Put (" = ");
  8285.       Put (S);
  8286.    end Put_Set;
  8287.  
  8288.    procedure Compare_Set (S_String : String; S : Set;
  8289.                           T_String : String; T : Set) is
  8290.    begin
  8291.       if S = T then
  8292.          Put (S_String);
  8293.          Put (" is identical to ");
  8294.          Put (T_String);
  8295.          New_Line;
  8296.       end if;
  8297.       if S /= T then
  8298.          Put (S_String);
  8299.          Put (" is not identical to ");
  8300.          Put (T_String);
  8301.          New_Line;
  8302.       end if;
  8303.       if S <= T then
  8304.          Put (S_String);
  8305.          Put (" is a subset of ");
  8306.          Put (T_String);
  8307.          New_Line;
  8308.       end if;
  8309.       if T <= S then
  8310.          Put (T_String);
  8311.          Put (" is a subset of ");
  8312.          Put (S_String);
  8313.          New_Line;
  8314.       end if;
  8315.    end Compare_Set;
  8316.  
  8317.    procedure Test_Membership (C : Color; S_String : String; S : Set) is
  8318.    begin
  8319.       Put (Color'Image(C));
  8320.       if Is_Member(S,C) then
  8321.          Put (" is a member of ");
  8322.       else
  8323.          Put (" is not a member of ");
  8324.       end if;
  8325.       Put (S_String);
  8326.       New_Line;
  8327.    end Test_Membership;
  8328.  
  8329. begin
  8330.  
  8331.    X := Empty_Set;
  8332.    Put_Line ("X := Empty_Set");
  8333.    Put_Set ("X",X);
  8334.  
  8335.    Y := Empty_Set;
  8336.    Put_Line ("Y := Empty_Set");
  8337.    Put_Set ("Y",Y);
  8338.  
  8339.    Compare_Set ("X",X,"Y",Y);
  8340.  
  8341.    Y := Full_Set;
  8342.    Put_Line ("Y := Full_Set");
  8343.    Put_Set ("Y",Y);
  8344.  
  8345.    Compare_Set ("X",X,"Y",Y);
  8346.  
  8347.    X := not X;
  8348.    Put_Line ("X := not X");
  8349.    Put_Set ("X",X);
  8350.  
  8351.    Compare_Set ("X",X,"Y",Y);
  8352.  
  8353.    Y := Empty_Set + Blue;
  8354.    Put_Line ("Y := Empty_Set + Blue");
  8355.    Put_Set ("Y",Y);
  8356.  
  8357.    Y := + Yellow;
  8358.    Put_Line ("Y := + Yellow");
  8359.    Put_Set ("Y",Y);
  8360.  
  8361.    Y := Blue + Y;
  8362.    Put_Line ("Y := Blue + Y");
  8363.    Put_Set ("Y",Y);
  8364.  
  8365.    X := Full_Set - Red;
  8366.    Put_Line ("X := Full_Set - Red");
  8367.    Put_Set ("X",X);
  8368.  
  8369.    Test_Membership (Red,"X",X);
  8370.    Test_Membership (Yellow,"X",X);
  8371.    
  8372.    Compare_Set ("X",X,"Y",Y);
  8373.  
  8374.    Z := X - Y;
  8375.    Put_Line ("Z := X - Y");
  8376.    Put_Set ("Z",Z);
  8377.  
  8378.    Z := Y - X;
  8379.    Put_Line ("Z := Y - X");
  8380.    Put_Set ("Z",Z);
  8381.  
  8382.    X := Green + Blue + Yellow + Red;
  8383.    Put_Line ("X := Green + Blue + Yellow + Red");
  8384.    Put_Set ("X",X);
  8385.  
  8386.    X := Green + Blue;
  8387.    Put_Line ("X := Green + Blue");
  8388.    Put_Set ("X",X);
  8389.  
  8390.    Z := X or Y;
  8391.    Put_Line ("Z := X or Y");
  8392.    Put_Set ("Z",Z);
  8393.  
  8394.    Z := X and Y;   
  8395.    Put_Line ("Z := X and Y");
  8396.    Put_Set ("Z",Z);
  8397.  
  8398.    Z := X xor Y;   
  8399.    Put_Line ("Z := X xor Y");
  8400.    Put_Set ("Z",Z);
  8401.  
  8402. end Main;
  8403. ::::::::::
  8404. SHARED.ADA
  8405. ::::::::::
  8406. -------------------------------------------------------------------
  8407. ---------------------  Next  Program  -----------------------------
  8408. -------------------------------------------------------------------
  8409.  
  8410.  
  8411. --
  8412. -- Version: @(#)shared.ada    1.1        Date: 5/30/84
  8413. --
  8414. --
  8415. -- Author:  Bryce Bardin
  8416. --          Ada Projects Section
  8417. --          Software Engineering Division
  8418. --          Ground Systems Group
  8419. --          Hughes Aircraft Company
  8420. --          Fullerton, CA
  8421. --
  8422. -- This program illustrates the use of tasking to provide shared access 
  8423. -- to global variables.  N.B.:  The values it outputs may vary from run 
  8424. -- to run depending on how tasking is implemented.
  8425.  
  8426.  
  8427. -- A "FIFO" solution to the READERS/WRITERS problem.
  8428. -- Authors:  Gerald Fisher and Robert Dewar.
  8429. -- (Modified by Bryce Bardin to terminate gracefully.)
  8430. -- May be used to provide shared access to objects by an arbitrary number of 
  8431. -- readers and writers which are serviced in order from a single queue.  
  8432. -- Writers are given uninterrupted access for updates and readers are assured 
  8433. -- that updates are indivisible and therefore complete when read access is 
  8434. -- granted.
  8435. --
  8436. -- If C is a task object of type Control and O is an object which is to be 
  8437. -- shared between readers and writers using C, then:
  8438. --
  8439. --    readers should do:
  8440. --
  8441. --       C.Start(Read);
  8442. --       <read all or part of O>
  8443. --       C.Stop;
  8444. --
  8445. --    and writers should do:
  8446. --
  8447. --       C.Start(Write);
  8448. --       <update all or part of O>
  8449. --       C.Stop;
  8450.  
  8451. package Readers_Writers is
  8452.  
  8453.    type Service is (Read, Write);
  8454.  
  8455.    task type Control is
  8456.       entry Start (Mode : Service);  -- start readers or writers
  8457.       entry Stop;                    -- stop readers or writers
  8458.    end Control;
  8459.  
  8460. end Readers_Writers;
  8461.  
  8462. package body Readers_Writers is
  8463.  
  8464.    task body Control is
  8465.       Read_Count : Natural := 0;
  8466.    begin
  8467.       loop
  8468.          select
  8469.             -- remove the first reader or writer from the queue
  8470.             accept Start (Mode : Service) do
  8471.                if Mode = Read then
  8472.                   Read_Count := Read_Count + 1;
  8473.                else
  8474.                   -- when writer, wait for readers which have already 
  8475.                   -- started to finish before allowing the writer to 
  8476.                   -- perform the update
  8477.                   while Read_Count > 0 loop
  8478.                      -- when a write is pending, readers stop here        
  8479.                      accept Stop;
  8480.                      Read_Count := Read_Count - 1;
  8481.                   end loop;
  8482.                end if;
  8483.             end Start;
  8484.  
  8485.             if Read_Count = 0 then
  8486.                -- when writer, wait for writer to stop before allowing 
  8487.                -- other readers or writers to start
  8488.                accept Stop;
  8489.             end if;
  8490.          or
  8491.             -- when no write is pending, readers stop here
  8492.             accept Stop;
  8493.             Read_Count := Read_Count -1;
  8494.          or
  8495.             -- quit when everyone agrees to do so
  8496.             terminate;
  8497.          end select;
  8498.       end loop;
  8499.    end Control;
  8500.  
  8501. end Readers_Writers;
  8502.  
  8503.  
  8504.  
  8505. -- This package allows any number of concurrent programs to read and/or 
  8506. -- indivisibly write a particular (possibly composite) variable object
  8507. -- without interference and in FIFO order.  Similar packages can be 
  8508. -- constructed to perform partial reads and writes of composite objects.
  8509. -- If service cannot be started before the appropriate time limit expires,
  8510. -- the exception Timed_Out will be raised.  (By default, service must be
  8511. -- started within Duration'Last (24+) hours.  Setting the time limits to 
  8512. -- 0.0 will require immediate service.)
  8513. --
  8514. generic
  8515.  
  8516.    type Object_Type is private;
  8517.    Object : in out Object_Type;
  8518.  
  8519.    Read_Time_Limit : in Duration := Duration'Last;
  8520.    Write_Time_Limit : in Duration := Duration'Last;
  8521.  
  8522.    -- for testing only
  8523.    with procedure Read_Put (Item : in Object_Type) is <>;
  8524.  
  8525.    -- for testing only
  8526.    with procedure Write_Put (Item : in Object_Type) is <>;
  8527.  
  8528.    -- for testing only
  8529.    with procedure Copy (From : in Object_Type; To : in out Object_Type);
  8530.  
  8531. package Shared_Variable is
  8532.  
  8533.    -- for testing only: Item made "in out" instead of "out"
  8534.    procedure Read (Item : in out Object_Type);
  8535.    procedure Write (Item : in Object_Type);
  8536.  
  8537.    Timed_Out : exception;
  8538.  
  8539. end Shared_Variable;
  8540.  
  8541. with Readers_Writers; use Readers_Writers;
  8542. package body Shared_Variable is
  8543.  
  8544.    C : Control;
  8545.  
  8546.    -- for testing only: Item made "in out" instead of "out"
  8547.    procedure Read (Item : in out Object_Type) is
  8548.    begin
  8549.  
  8550.       select
  8551.      C.Start(Read);
  8552.       or
  8553.      delay Read_Time_Limit;
  8554.      raise Timed_Out;
  8555.       end select;
  8556.  
  8557. -- for testing only; this allows the scheduler to screw up!
  8558.       Copy(From => Object, To => Item);
  8559. -- temporarily replaces
  8560. --    Item := Object;
  8561.  
  8562. -- for testing only
  8563.       Read_Put(Item);
  8564.  
  8565.       C.Stop;
  8566.    end Read;
  8567.  
  8568.    procedure Write (Item : in Object_Type) is
  8569.    begin
  8570.  
  8571.       select
  8572.      C.Start(Write);
  8573.       or
  8574.      delay Write_Time_Limit;
  8575.      raise Timed_Out;
  8576.       end select;
  8577.  
  8578. -- for testing only; this allows the scheduler to screw up!
  8579.       Copy(From => Item, To => Object);
  8580. -- temporarily replaces
  8581.       Object := Item;
  8582.  
  8583. -- for testing only
  8584.       Write_Put(Item);
  8585.  
  8586.       C.Stop;
  8587.    end Write;
  8588.  
  8589. end Shared_Variable;
  8590.  
  8591.  
  8592.  
  8593. with Shared_Variable;
  8594. package Encapsulate is
  8595.  
  8596.    Max : constant := 2;
  8597.  
  8598.    subtype Index is Positive range 1 .. Max;
  8599.  
  8600.    type Composite is array (Index) of Integer;
  8601.  
  8602.    procedure Read (C : out Composite);
  8603.  
  8604.    procedure Write (C : in Composite);
  8605.  
  8606. -- This is a help function for testing
  8607.    function Set_To (I : Integer) return Composite;
  8608.  
  8609. -- This is a help function for testing
  8610.    function Value_Of (C : Composite) return Integer;
  8611.  
  8612. -- This entry is used to serialize debug output to Standard_Output
  8613.    task Msg is
  8614.       entry Put (S : String);
  8615.    end Msg;
  8616.  
  8617. end Encapsulate;
  8618.  
  8619.  
  8620. with Text_IO;
  8621. package body Encapsulate is
  8622.  
  8623.    Shared : Composite;
  8624.  
  8625.    function Set_To (I : Integer) return Composite is
  8626.       Temp : Composite;
  8627.    begin
  8628.       for N in Index loop
  8629.      Temp(N) := I;
  8630.       end loop;
  8631.       return Temp;
  8632.    end Set_To;
  8633.  
  8634.    function Value_Of (C : Composite) return Integer is
  8635.    begin
  8636.       return C(Index'First);
  8637.    end Value_Of;
  8638.  
  8639.    -- for testing only; this allows the scheduler to overlap readers and 
  8640.    -- writers and thus screw up if Readers_Writers doesn't do its job.
  8641.    -- it also checks that the copy is consistent.
  8642.    procedure Copy (From : in Composite; To : in out Composite) is
  8643.    begin
  8644.       for I in Index loop
  8645.      To(I) := From(I);
  8646.          -- delay so that another access could be made:
  8647.      delay 0.5;
  8648.       end loop;
  8649.       -- test for consistency:
  8650.       for I in Index range Index'Succ(Index'First) .. Index'Last loop
  8651.      if To(I) /= To(Index'First) then
  8652.         raise Program_Error;
  8653.      end if;
  8654.       end loop;
  8655.    end Copy;
  8656.  
  8657.    procedure Read_Put (Item : Composite) is
  8658.    begin
  8659.       Msg.Put(Integer'Image(Value_Of(Item)) & " read");
  8660.    end Read_Put;
  8661.  
  8662.    procedure Write_Put (Item : Composite) is
  8663.    begin
  8664.       Msg.Put(Integer'Image(Value_Of(Item)) & " written");
  8665.    end Write_Put;
  8666.  
  8667.    task body Msg is
  8668.    begin
  8669.       loop
  8670.      select
  8671.         accept Put (S : String) do
  8672.            Text_IO.Put (S);
  8673.            Text_IO.New_Line;
  8674.         end Put;
  8675.      or
  8676.         terminate;
  8677.      end select;
  8678.       end loop;
  8679.    end Msg;
  8680.  
  8681.    package Share is new Shared_Variable 
  8682.       (Object_Type => Composite, Object => Shared, Read_Put => Read_Put,
  8683.       Write_Put => Write_Put, Copy => Copy);
  8684.    use Share;
  8685.  
  8686.    procedure Read (C : out Composite) is
  8687.       Temp : Composite;
  8688.    begin
  8689.       Share.Read(Temp);
  8690.       C := Temp;
  8691.    end Read;
  8692.  
  8693.    procedure Write (C : in Composite) is
  8694.    begin
  8695.       Share.Write(C);
  8696.    end Write;
  8697.  
  8698. begin
  8699.  
  8700.    Shared := Set_To (0);
  8701.  
  8702. end Encapsulate;
  8703.  
  8704.  
  8705. with Encapsulate; use Encapsulate;
  8706. with Text_IO; use Text_IO;
  8707. procedure Test_Shared is
  8708.  
  8709.    Local : Composite := Set_To (-1);
  8710.  
  8711.    task A;
  8712.    task B;
  8713.    task C;
  8714.  
  8715.    procedure Put(C : Character; I : Integer);
  8716.  
  8717.    task body A is
  8718.    begin
  8719.       Read(Local);
  8720.       Put('A',Value_Of(Local));
  8721.  
  8722.       Write(Set_To(1));
  8723.  
  8724.       Read(Local);
  8725.       Put('A',Value_Of(Local));
  8726.  
  8727.       Write(Set_To(2));
  8728.  
  8729.       Read(Local);
  8730.       Put('A',Value_Of(Local));
  8731.    end A;
  8732.  
  8733.    task body B is
  8734.    begin
  8735.       Read(Local);
  8736.       Put('B',Value_Of(Local));
  8737.  
  8738.       Write(Set_To(3));
  8739.  
  8740.       Read(Local);
  8741.       Put('B',Value_Of(Local));
  8742.    end B;
  8743.  
  8744.    task body C is
  8745.    begin
  8746.       Write(Set_To(4));
  8747.  
  8748.       Read(Local);
  8749.       Put('C',Value_Of(Local));
  8750.  
  8751.       Write(Set_To(5));
  8752.  
  8753.       Read(Local);
  8754.       Put('C',Value_Of(Local));
  8755.    end C;
  8756.  
  8757.    procedure Put(C : Character; I : Integer) is
  8758.    begin
  8759.       Msg.Put("Task " & C & " read the value " & Integer'Image(I));
  8760.    end Put;
  8761.  
  8762. begin
  8763.    null;
  8764. end Test_Shared;
  8765.