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

  1.  
  2. -- The combinational problem of converting from every unit to every
  3. -- other units of the same dimension is too large to be practical.
  4. --
  5. -- The compromise solution is to provide:
  6. --   MKS,     conversion of every metric unit to the corresponding MKS unit 
  7. --   MKS,     conversion of primary English unit to corresponding MKS unit
  8. --   ENGLISH, conversion of every English unit to the primary English unit
  9. --   ENGLISH, conversion of every MKS unit to corresponding primary English unit
  10. --   CONVERT, conversion from primary English unit to other English units
  11. --   CONVERT, conversion from MKS unit to other metric units
  12. --
  13. -- The overloaded function MKS returns the MKS value.
  14. --
  15. -- The overloaded function ENGLISH returns the primary English value.
  16. --
  17. -- The overloaded function CONVERT returns all units
  18. --                                         other than MKS or primary English
  19. -- 
  20. -- Note: Any of these functions may need to be called with qualification.
  21. --       Usually, MKS and ENGLISH will not require qualification.
  22. --       Almost always, CONVERT will require qualification.
  23. --
  24. --         PUT ( LENGTH_CENTIMETER' ( CONVERT ( SOME_LENGTH ) ) ) ;
  25. --
  26. --      DO NOT get the concept of units conversion confused with the
  27. --      Ada concept of type conversion. An Ada type conversion CAN NOT
  28. --      change meters to feet.
  29. --
  30.  
  31. with PHYSICAL_UNITS_BASIC ; use PHYSICAL_UNITS_BASIC ;
  32. with PHYSICAL_UNITS_MECHANICAL ; use PHYSICAL_UNITS_MECHANICAL ;
  33. with PHYSICAL_UNITS_ELECTRICAL ; use PHYSICAL_UNITS_ELECTRICAL ;
  34.  
  35. package PHYSICAL_UNITS_CONVERSION is
  36.  
  37.   function CONVERT ( ITEM : LENGTH_ENGLISH ) return LENGTH_INCH ;
  38.  
  39.   function CONVERT ( ITEM : LENGTH_MKS ) return LENGTH_CENTIMETER ;
  40.  
  41. end PHYSICAL_UNITS_CONVERSION ;
  42.  
  43.  
  44. with PHYSICAL_CONVERSION_CONSTANT ; use PHYSICAL_CONVERSION_CONSTANT ;
  45. with PHYSICAL_REAL ; use PHYSICAL_REAL ;
  46.  
  47. package body PHYSICAL_UNITS_CONVERSION is
  48. -- This will be filled in for all CONVERT functions
  49.  
  50.   function CONVERT ( ITEM : LENGTH_ENGLISH ) return LENGTH_INCH is
  51.   begin
  52.     return DIMENSION ( UNDIMENSION( ITEM )) * FOOT_TO_INCH ;
  53.   end CONVERT ;
  54.  
  55.   function CONVERT ( ITEM : LENGTH_MKS ) return LENGTH_CENTIMETER is
  56.   begin
  57.     return DIMENSION ( UNDIMENSION( ITEM )) * METER_TO_CENTIMETER ;
  58.   end CONVERT ;
  59.  
  60. end PHYSICAL_UNITS_CONVERSION ;
  61.