{ Filename:  Cconv.pas
  Unit for Convert that contains all working code.}

Unit Cconv;

Interface

  const
    blank = ' ';

  type
    str80 = string[80];
    str20 = string[20];

  var
    pstr,ustr    : str80;
    quantity     : real;

  procedure ParseArguments(var pstr,ustr: str80);
  procedure Choose(st: str80; quant: real; bl: integer);

Implementation

  const
    first = true;
    nfirst = false;
    equal = '=';
    period = '.';
{*** Lengths }
    inpercm = 0.393700787;     { inches per centimeter }
    cmperin = 2.54;            { centimeters per inch }
    ftperm = 3.2808399;        { feet per meter }
    mperft = 0.3048;           { meters per foot }
    kmpermi = 1.609344;        { kilometers per mile }
    miperkm = 0.6213712;       { miles per kilometer }
    inperft = 12.0;            { inches per foot }
    ftperyd = 3.0;             { feet per yard }
    ftpermi = 5280.0;          { feet per mile }
    mperkm = 1000.0;           { meters per kilometer }
    mmperm = 1000.0;           { millimeters per meter }
    cmperm = 100.0;            { centimeters per meter }
    nmpermi = 0.86897624;      { nautical miles per mile }
    kmperau = 149.6e6;         { kilometers per astronomical unit }
    mperly = 9.4607e15;        { meters per light year }
    lyperpar = 3.2616;         { light years per parsec }
{*** Areas }
    sqftperac = 43560.0;       { square feet per acre }
    acpersqmi = 640.0;         { acres per square mile }
{*** Volumes }
    lpergal = 3.785411784;     { liters per gallon }
    ozpergal = 128.0;          { ounces per gallon }
    ozperqt = 32.0;            { ounces per quart }
    ozperpt = 16.0;            { ounces per pint }
    ozperl = 33.8140227;       { ounces per liter }
    cinpergal = 231.0;         { cubic inches per gallon }
    ccperl = 1000.0;           { cubic centimeters per liter }
{*** Time }
    secpermin = 60.0;          { seconds per minute }
    minperhr = 60.0;           { minutes per hour }
    hrperday = 24.0;           { hours per day }
    dayperwk = 7.0;            { days per week }
    dayperyr = 365.0;          { days per calendar year }
    secperhr = 3600.0;         { seconds per hour }
    secperday = 86400.0;       { seconds per day }
    dypersld = 1.002737268;    { days per solar day }
    dypersdd = 0.997269572;    { days per sidereal day }
    dypermo = 30.0;            { days per month }
    moperyr = 12.0;            { months per year }
    dypersdm = 27.32166;       { days per sidereal month }
    dypersly = 365.24219;      { days per solar year }
    dypersdy = 365.25636;      { days per sidereal year }
{*** Mass and force }
    ntperlb = 4.4481989;       { newtons per pound }
    dypernt = 1.0e5;           { dynes per newton }
    ozperlb = 16.0;            { ounces per pound }
    lbperton = 2000.0;         { pounds per ton }
    lbperkg = 2.204622622;     { pounds per kilogram-force }
    grperkg = 1000.0;          { grams per kilogram }
    ntpergr = 9.8066e-3;       { newtons per gram-force }
    kgpermt = 1000.0;          { kilograms per metric ton }
{*** Energy and power }
    jperfp = 1.35582;          { joules per foot-pound }
    jpercal = 4.186;           { joules per calorie }
    ergperj = 1.0e7;           { ergs per joule }
    jperbtu = 1054.8;          { joules per British Thermal Unit }
    jperkh = 3.6e6;            { joules per kilowatt-hour }
    jperev = 1.602e-19;        { joules per electron volt }
    wperfp = 0.737561;         { watts per foot-pound/second }
    wperhp = 745.712;          { watts per horsepower }
    wpercal = 4.186;           { watts per calorie/sec }
    wperkw = 1000.0;           { watts per kilowatt }
    fpperhp = 550.0;           { foot-pounds/second per horsepower }
{*** String constants }
    ic = 'inches';
    ft = 'feet';
    yd = 'yards';
    mi = 'miles';
    mm = 'millimeters';
    cm = 'centimeters';
    mt = 'meters';
    km = 'kilometers';
    nm = 'nautical miles';
    au = 'astronomical units';
    ly = 'light years';
    pr = 'parsecs';
    sq = 'square';
    ac = 'acres';
    cb = 'cubic';
    gl = 'gallons';
    lt = 'liters';
    qt = 'quarts';
    pt = 'pints';
    oz = 'ounces';
    sc = 'seconds';
    mn = 'minutes';
    hr = 'hours';
    ds = 'days';
    wk = 'weeks';
    yr = 'years';
    sl = 'solar days';
    sd = 'sidereal days';
    mo = 'months';
    sdm = 'sidereal months';
    sly = 'solar years';
    sdy = 'sidereal years';
    lb = 'pounds';
    nt = 'newtons';
    dy = 'dynes';
    kg = 'kilograms';
    gr = 'grams';
    tn = 'tons';
    mts = 'metric tons';
    fp = 'foot-pounds';
    jl = 'joules';
    er = 'ergs';
    cal = 'calories';
    bt = 'BTU''s';
    kh = 'kilowatt-hours';
    ev = 'electron volts';
    wt = 'watts';
    kw = 'kilowatts';
    fps = 'foot-pounds/sec';
    hp = 'horsepower';
    cs = 'calories/sec';
    mph = 'miles per hour';
    fs = 'feet/sec';
    kph = 'kilometers per hour';
    ms = 'meters/sec';
    err = 'Usage: C> convert quantity unit';

procedure Error(ecode: byte);
  begin
    if ecode = 2 then
      writeln('Too many arguments in command list.');
    writeln(err);
    Halt
  end;

procedure ParseArguments(var pstr,ustr: str80);
{************************************************************************
Function:
    ParseArguments uses the Turbo Pascal functions ParamCount and ParamStr
    to parse the arguments on the command line.  Since many of the arguments
    allowed by Convert have more than one word - e.g., square inches and
    miles per hour - ParseArguments must be able to deal with anywhere from
    two to four arguments.
**************************************************************************}
  var
    code: integer;
  begin
    if ParamCount < 2 then Error(1);
    Val(ParamStr(1),quantity,code);
    if code <> 0 then Error(1);
    if ParamCount = 2
      then begin
        pstr := ParamStr(2);
        ustr := ParamStr(1) + blank + ParamStr(2)
      end
    else if ParamCount = 3
      then begin
        pstr := ParamStr(2) + blank + ParamStr(3);
        ustr := ParamStr(1) + blank + ParamStr(2) + blank + ParamStr(3)
      end
    else if ParamCount = 4
      then begin
        pstr := ParamStr(2) + blank + ParamStr(3) + blank + ParamStr(4);
        ustr := ParamStr(1) + blank + ParamStr(2) + blank + ParamStr(3)
                + blank + ParamStr(4)
      end
    else Error(2)
  end;

function Cube(x: real): real;
  begin
    Cube := x*x*x
  end;

procedure Conversion(value,factor: real; unittype: str20;
                         bl: integer; flag: boolean);
{********************************************************************
Function:
   Conversion performs a conversion by multiplying the input value
   by the conversion factor and writes properly formatted output.
   The first time that Conversion is called the output is written at the
   cursor line; every other time enough blanks are written to align the
   outputs.  The absolute values of all numeric values are checked against
   the constants large and small.  If any of them fall outside the range
   defined by these constants, then all values are written with their full
   Turbo Pascal precision.  If all fall inside this range, then they are
   truncated to five decimal places before being written.
 Argument list:
    value............value input by user.
    factor...........conversion factor.
    unittype.........unit string for output.
    bl...............number of blanks for output.
    flag.............true if first time Conversion has been called,
                     false otherwise.
************************************************************************** }
  const
    large = 1.0e4;  small = 1.0e-4;
  var
    line: string[80];
    num1,num2: str20;
    i: integer;
  begin
    if not flag then
      for i := 1 to bl do
        write(blank);
    if (abs(value) >= large) or (abs(value*factor) >= large)
      or (abs(value) <= small) or (abs(value*factor) <= small)
        then writeln(equal,blank,value*factor,blank,unittype)
        else begin
          str(value*factor:1:5,num2);
          line := equal + blank + blank + num2 + blank + unittype;
          writeln(line)
       end
  end;

procedure CInches(value: real; bl: integer);
{*** Convert inches to feet, yards, millimeters, centimeters, meters. ***}
  begin
    Conversion(value,1/inperft,ft,bl,first);
    Conversion(value,1/(inperft*ftperyd),yd,bl,nfirst);
    Conversion(value,10*cmperin,mm,bl,nfirst);
    Conversion(value,cmperin,cm,bl,nfirst);
    Conversion(value,cmperin/cmperm,mt,bl,nfirst)
  end;

procedure CFeet(value: real; bl:integer);
{*** Convert feet to inches, yards, miles, centimeters, meters,
     kilometers. ***}
  begin
    Conversion(value,inperft,ic,bl,first);
    Conversion(value,1/ftperyd,yd,bl,nfirst);
    Conversion(value,1/ftpermi,mi,bl,nfirst);
    Conversion(value,mperft*cmperm,cm,bl,nfirst);
    Conversion(value,mperft,mt,bl,nfirst);
    Conversion(value,mperft/mperkm,km,bl,nfirst)
  end;

procedure CYards(value: real; bl: integer);
{*** Convert yards to inches, feet, miles, meters, kilometers. ***}
  begin
    Conversion(value,ftperyd*inperft,ic,bl,first);
    Conversion(value,ftperyd,ft,bl,nfirst);
    Conversion(value,ftperyd/ftpermi,mi,bl,nfirst);
    Conversion(value,ftperyd*mperft,mt,bl,nfirst);
    Conversion(value,ftperyd*mperft/mperkm,km,bl,nfirst)
  end;

procedure CMeters(value: real; bl: integer);
{*** Convert meters to millimeters, centimeters, kilometers, inches, feet,
     yards, miles. ***}
  begin
    Conversion(value,mmperm,mm,bl,first);
    Conversion(value,cmperm,cm,bl,nfirst);
    Conversion(value,1/mperkm,km,bl,nfirst);
    Conversion(value,ftperm*inperft,ic,bl,nfirst);
    Conversion(value,ftperm,ft,bl,nfirst);
    Conversion(value,ftperm/ftperyd,yd,bl,nfirst);
    Conversion(value,ftperm/ftpermi,mi,bl,nfirst)
  end;

procedure CCentimeters(value: real; bl: integer);
{*** Convert centimeters to millimeters, meters, inches, feet. ***}
  begin
    Conversion(value,mmperm/cmperm,mm,bl,first);
    Conversion(value,1/cmperm,mt,bl,nfirst);
    Conversion(value,inpercm,ic,bl,nfirst);
    Conversion(value,inpercm/inperft,ft,bl,nfirst)
  end;

procedure CMillimeters(value: real; bl: integer);
{*** Convert millimeters to centimeters, meters, inches, feet. ***}
  begin
    Conversion(value,cmperm/mmperm,cm,bl,first);
    Conversion(value,1/mmperm,mt,bl,nfirst);
    Conversion(value,cmperm*inpercm/mmperm,ic,bl,nfirst);
    Conversion(value,ftperm/mmperm,ft,bl,nfirst)
  end;

procedure CKilometers(value: real; bl: integer);
{*** Convert kilometers to meters, feet, yards, miles, nautical miles. ***}
  begin
    Conversion(value,mperkm,mt,bl,first);
    Conversion(value,mperkm*ftperm,ft,bl,nfirst);
    Conversion(value,mperkm*ftperm/ftperyd,yd,bl,nfirst);
    Conversion(value,miperkm,mi,bl,nfirst);
    Conversion(value,miperkm*nmpermi,nm,bl,nfirst)
  end;

procedure CMiles(value: real; bl: integer);
{*** Convert miles to feet, yards, nautical miles, meters, kilometers. ***}
  begin
    Conversion(value,ftpermi,ft,bl,first);
    Conversion(value,ftpermi/ftperyd,yd,bl,nfirst);
    Conversion(value,nmpermi,nm,bl,nfirst);
    Conversion(value,ftpermi*mperft,mt,bl,nfirst);
    Conversion(value,kmpermi,km,bl,nfirst)
  end;

procedure CNauticalMiles(value: real; bl: integer);
{*** Convert nautical miles to feet, yards, miles, meters, kilometers. ***}
  begin
    Conversion(value,ftpermi/nmpermi,ft,bl,first);
    Conversion(value,ftpermi/(nmpermi*ftperyd),yd,bl,nfirst);
    Conversion(value,1/nmpermi,mi,bl,nfirst);
    Conversion(value,ftpermi*mperft/nmpermi,mt,bl,nfirst);
    Conversion(value,kmpermi/nmpermi,km,bl,nfirst)
  end;

procedure CAstronomicalUnits(value: real; bl: integer);
{*** Convert astronomical units to meters, kilometers, miles, light years,
     parsecs. ***}
  begin
    Conversion(value,kmperau*mperkm,mt,bl,first);
    Conversion(value,kmperau,km,bl,nfirst);
    Conversion(value,kmperau/kmpermi,mi,bl,nfirst);
    Conversion(value,kmperau*mperkm/mperly,ly,bl,nfirst);
    Conversion(value,kmperau*mperkm/(mperly*lyperpar),pr,bl,nfirst)
  end;

procedure CLightYears(value: real; bl: integer);
{*** Convert light years to meters, kilometers, miles, astronomical units,
     parsecs. ***}
  begin
    Conversion(value,mperly,mt,bl,first);
    Conversion(value,mperly/mperkm,km,bl,nfirst);
    Conversion(value,mperly/(mperkm*kmpermi),mi,bl,nfirst);
    Conversion(value,mperly/(mperkm*kmperau),au,bl,nfirst);
    Conversion(value,1/lyperpar,pr,bl,nfirst)
  end;

procedure CParsecs(value: real; bl: integer);
{*** Convert parsecs to meters, kilometers, miles, astronomical units,
     light years. ***}
  begin
    Conversion(value,lyperpar*mperly,mt,bl,first);
    Conversion(value,lyperpar*mperly/mperkm,km,bl,nfirst);
    Conversion(value,lyperpar*mperly/(mperkm*kmpermi),mi,bl,nfirst);
    Conversion(value,lyperpar*mperly/(mperkm*kmperau),au,bl,nfirst);
    Conversion(value,lyperpar,ly,bl,nfirst)
  end;

procedure CSqInches(value: real; bl: integer);
{*** Convert square inches to square feet, square yards, square millimeters,
     square centimeters, square meters. ***}
  begin
    Conversion(value,sqr(1/inperft),sq+blank+ft,bl,first);
    Conversion(value,sqr(1/(inperft*ftperyd)),sq+blank+yd,bl,nfirst);
    Conversion(value,sqr(10*cmperin),sq+blank+mm,bl,nfirst);
    Conversion(value,sqr(cmperin),sq+blank+cm,bl,nfirst);
    Conversion(value,sqr(mperft/inperft),sq+blank+mt,bl,nfirst)
  end;

procedure CSqFeet(value: real; bl: integer);
{*** Convert square feet to square inches, square yards, acres, square miles,
     square centimeters, square meters, square kilometers. ***}
  begin
    Conversion(value,sqr(inperft),sq+blank+ic,bl,first);
    Conversion(value,sqr(1/ftperyd),sq+blank+yd,bl,nfirst);
    Conversion(value,1/sqftperac,ac,bl,nfirst);
    Conversion(value,sqr(1/ftpermi),sq+blank+mi,bl,nfirst);
    Conversion(value,sqr(mperft*cmperm),sq+blank+cm,bl,nfirst);
    Conversion(value,sqr(mperft),sq+blank+mt,bl,nfirst);
    Conversion(value,sqr(mperft/mperkm),sq+blank+km,bl,nfirst)
  end;

procedure CSqYards(value: real; bl: integer);
{*** Convert square yards to square inches, square feet, acres, square miles,
     square centimeters, square meters, square kilometers. ***}
  begin
    Conversion(value,sqr(ftperyd*inperft),sq+blank+ic,bl,first);
    Conversion(value,sqr(ftperyd),sq+blank+ft,bl,nfirst);
    Conversion(value,sqr(ftperyd)/sqftperac,ac,bl,nfirst);
    Conversion(value,sqr(ftperyd/ftpermi),sq+blank+mi,bl,nfirst);
    Conversion(value,sqr(ftperyd*mperft*cmperm),sq+blank+cm,bl,nfirst);
    Conversion(value,sqr(ftperyd*mperft),sq+blank+mt,bl,nfirst);
    Conversion(value,sqr(ftperyd*mperft/mperkm),sq+blank+km,bl,nfirst)
  end;

procedure CSqCentimeters(value: real; bl: integer);
{*** Convert square centimeters to square meters, square inches, square feet,
     square yards. ***}
  begin
    Conversion(value,sqr(1/cmperm),sq+blank+mt,bl,first);
    Conversion(value,sqr(inpercm),sq+blank+ic,bl,nfirst);
    Conversion(value,sqr(inpercm/inperft),sq+blank+ft,bl,nfirst);
    Conversion(value,sqr(inpercm/(inperft*ftperyd)),sq+blank+yd,bl,nfirst)
  end;

procedure CSqMeters(value: real; bl: integer);
{*** Convert square meters to square centimeters, square kilometers, square
     inches, square feet, square yards, acres, square miles. ***}
  begin
    Conversion(value,sqr(cmperm),sq+blank+cm,bl,first);
    Conversion(value,sqr(1/mperkm),sq+blank+km,bl,nfirst);
    Conversion(value,sqr(ftperm*inperft),sq+blank+ic,bl,nfirst);
    Conversion(value,sqr(ftperm),sq+blank+ft,bl,nfirst);
    Conversion(value,sqr(ftperm/ftperyd),sq+blank+yd,bl,nfirst);
    Conversion(value,sqr(ftperm)/sqftperac,ac,bl,nfirst);
    Conversion(value,sqr(ftperm/ftpermi),sq+blank+mi,bl,nfirst)
  end;

procedure CSqKilometers(value: real; bl: integer);
{*** Convert square kilometers to square meters, square feet, square yards,
     acres, square miles. ***}
  begin
    Conversion(value,sqr(mperkm),sq+blank+mt,bl,first);
    Conversion(value,sqr(mperkm*ftperm),sq+blank+ft,bl,nfirst);
    Conversion(value,sqr(mperkm*ftperm/ftperyd),sq+blank+yd,bl,nfirst);
    Conversion(value,sqr(mperkm*ftperm)/sqftperac,ac,bl,nfirst);
    Conversion(value,sqr(miperkm),sq+blank+mi,bl,nfirst)
  end;

procedure CSqMiles(value: real; bl: integer);
{*** Convert square miles to square feet, square yards, acres, square meters,
     square kilometers. ***}
  begin
    Conversion(value,sqr(ftpermi),sq+blank+ft,bl,first);
    Conversion(value,sqr(ftpermi/ftperyd),sq+blank+yd,bl,nfirst);
    Conversion(value,acpersqmi,ac,bl,nfirst);
    Conversion(value,sqr(ftpermi*mperft),sq+blank+mt,bl,nfirst);
    Conversion(value,sqr(kmpermi),sq+blank+km,bl,nfirst)
  end;

procedure CAcres(value: real; bl: integer);
{*** Convert acres to square feet, square yards, square miles, square meters,
     square kilometers. ***}
  begin
    Conversion(value,sqftperac,sq+blank+ft,bl,first);
    Conversion(value,sqftperac/sqr(ftperyd),sq+blank+yd,bl,nfirst);
    Conversion(value,1/acpersqmi,sq+blank+mi,bl,nfirst);
    Conversion(value,sqftperac*sqr(mperft),sq+blank+mt,bl,nfirst);
    Conversion(value,sqr(kmpermi)/acpersqmi,sq+blank+km,bl,nfirst)
  end;

procedure CCubicInches(value: real; bl: integer);
{*** Convert cubic inches to cubic feet, cubic yards, cubic millimeters,
     cubic centimeters, cubic meters, gallons, liters. ***}
  begin
    Conversion(value,cube(1/inperft),cb+blank+ft,bl,first);
    Conversion(value,1/cube(inperft*ftperyd),cb+blank+yd,bl,nfirst);
    Conversion(value,cube(cmperin*10),cb+blank+mm,bl,nfirst);
    Conversion(value,cube(cmperin),cb+blank+cm,bl,nfirst);
    Conversion(value,cube(cmperin/cmperm),cb+blank+mt,bl,nfirst);
    Conversion(value,1/cinpergal,gl,bl,nfirst);
    Conversion(value,lpergal/cinpergal,lt,bl,nfirst)
  end;

procedure CCubicFeet(value: real; bl: integer);
{*** Convert cubic feet to cubic inches, cubic yards, cubic centimeters,
     cubic meters, gallons, liters. ***}
  begin
    Conversion(value,cube(inperft),cb+blank+ic,bl,first);
    Conversion(value,cube(1/ftperyd),cb+blank+yd,bl,nfirst);
    Conversion(value,cube(cmperin*inperft),cb+blank+cm,bl,nfirst);
    Conversion(value,cube(mperft),cb+blank+mt,bl,nfirst);
    Conversion(value,cube(inperft)/cinpergal,gl,bl,nfirst);
    Conversion(value,cube(inperft)*lpergal/cinpergal,lt,bl,nfirst)
  end;

procedure CCubicYards(value: real; bl: integer);
{*** Convert cubic yards to cubic inches, cubic feet, cubic centimeters,
     cubic meters, gallons, liters. ***}
  begin
    Conversion(value,cube(inperft*ftperyd),cb+blank+ic,bl,first);
    Conversion(value,cube(ftperyd),cb+blank+ft,bl,nfirst);
    Conversion(value,cube(inperft*ftperyd*cmperin),cb+blank+cm,bl,nfirst);
    Conversion(value,cube(ftperyd/ftperm),cb+blank+mt,bl,nfirst);
    Conversion(value,cube(inperft*ftperyd)/cinpergal,gl,bl,nfirst);
    Conversion(value,cube(inperft*ftperyd)*lpergal/cinpergal,lt,bl,nfirst)
  end;

procedure CCubicCentimeters(value: real; bl: integer);
{*** Convert cubic centimeters to cubic millimeters, cubic meters, cubic
     inches, cubic feet, cubic yards, liters, gallons, quarts, pints,
     ounces. ***}
  begin
    Conversion(value,cube(10),cb+blank+mm,bl,first);
    Conversion(value,cube(1/cmperm),cb+blank+mt,bl,nfirst);
    Conversion(value,cube(inpercm),cb+blank+ic,bl,nfirst);
    Conversion(value,cube(inpercm/inperft),cb+blank+ft,bl,nfirst);
    Conversion(value,cube(inpercm/(inperft*ftperyd)),cb+blank+yd,bl,nfirst);
    Conversion(value,1/ccperl,lt,bl,nfirst);
    Conversion(value,1/(ccperl*lpergal),gl,bl,nfirst);
    Conversion(value,ozpergal/(ccperl*lpergal*ozperqt),qt,bl,nfirst);
    Conversion(value,ozpergal/(ccperl*lpergal*ozperpt),pt,bl,nfirst);
    Conversion(value,ozpergal/(ccperl*lpergal),oz,bl,nfirst)
  end;

procedure CCubicMeters(value: real; bl: integer);
{*** Convert cubic meters to cubic centimeters, cubic kilometers, cubic
     inches, cubic feet, cubic yards, cubic miles, liters, gallons. ***}
  begin
    Conversion(value,cube(cmperm),cb+blank+cm,bl,first);
    Conversion(value,cube(1/mperkm),cb+blank+km,bl,nfirst);
    Conversion(value,cube(ftperm*inperft),cb+blank+ic,bl,nfirst);
    Conversion(value,cube(ftperm),cb+blank+ft,bl,nfirst);
    Conversion(value,cube(ftperm/ftperyd),cb+blank+yd,bl,nfirst);
    Conversion(value,cube(ftperm/ftpermi),cb+blank+mi,bl,nfirst);
    Conversion(value,cube(cmperm)/ccperl,lt,bl,nfirst);
    Conversion(value,cube(cmperm)/(ccperl*lpergal),gl,bl,nfirst)
  end;

procedure CCubicKilometers(value: real; bl: integer);
{*** Convert cubic kilometers to cubic meters, cubic feet, cubic yards,
     cubic miles. ***}
  begin
    Conversion(value,cube(mperkm),cb+blank+mt,bl,first);
    Conversion(value,cube(mperkm*ftperm),cb+blank+ft,bl,nfirst);
    Conversion(value,cube(mperkm*ftperm/ftperyd),cb+blank+yd,bl,nfirst);
    Conversion(value,cube(miperkm),cb+blank+mi,bl,nfirst)
  end;

procedure CCubicMiles(value: real; bl: integer);
{*** Convert cubic miles to cubic feet, cubic yards, cubic meters,
     cubic kilometers. ***}
  begin
    Conversion(value,cube(ftpermi),cb+blank+ft,bl,first);
    Conversion(value,cube(ftpermi/ftperyd),cb+blank+yd,bl,nfirst);
    Conversion(value,cube(ftpermi*mperft),cb+blank+mt,bl,nfirst);
    Conversion(value,cube(kmpermi),cb+blank+km,bl,nfirst)
  end;

procedure CGallons(value: real; bl: integer);
{*** Convert gallons to cubic inches, cubic feet, cubic yards, cubic
     centimeters, cubic meters, liters, quarts, pints, ounces. ***}
  begin
    Conversion(value,cinpergal,cb+blank+ic,bl,first);
    Conversion(value,cinpergal/cube(inperft),cb+blank+ft,bl,nfirst);
    Conversion(value,cinpergal/cube(inperft*ftperyd),cb+blank+yd,bl,nfirst);
    Conversion(value,cinpergal*cube(cmperin),cb+blank+cm,bl,nfirst);
    Conversion(value,cinpergal*cube(cmperin/cmperm),cb+blank+mt,bl,nfirst);
    Conversion(value,lpergal,lt,bl,nfirst);
    Conversion(value,ozpergal/ozperqt,qt,bl,nfirst);
    Conversion(value,ozpergal/ozperpt,pt,bl,nfirst);
    Conversion(value,ozpergal,oz,bl,nfirst)
  end;

procedure CLiters(value: real; bl: integer);
{*** Convert liters to cubic centimeters, cubic meters, cubic inches,
     cubic feet, cubic yards, gallons, quarts, pints. ***}
  begin
    Conversion(value,ccperl,cb+blank+cm,bl,first);
    Conversion(value,ccperl/cube(cmperm),cb+blank+mt,bl,nfirst);
    Conversion(value,ccperl*cube(inpercm),cb+blank+ic,bl,nfirst);
    Conversion(value,ccperl*cube(inpercm/inperft),cb+blank+ft,bl,nfirst);
    Conversion(value,ccperl*cube(inpercm/(inperft*ftperyd)),cb+blank+yd,
               bl,nfirst);
    Conversion(value,1/lpergal,gl,bl,nfirst);
    Conversion(value,ozpergal/(lpergal*ozperqt),qt,bl,nfirst);
    Conversion(value,ozpergal/(lpergal*ozperpt),pt,bl,nfirst)
  end;

procedure CQuarts(value: real; bl: integer);
{*** Convert quarts to gallons, pints, liters, cubic centimeters,
     cubic inches. ***}
  begin
    Conversion(value,ozperqt/ozpergal,gl,bl,first);
    Conversion(value,ozperqt/ozperpt,pt,bl,nfirst);
    Conversion(value,ozperqt*lpergal/ozpergal,lt,bl,nfirst);
    Conversion(value,ozperqt*lpergal*ccperl/ozpergal,cb+blank+cm,bl,nfirst);
    Conversion(value,ozperqt*cinpergal/ozpergal,cb+blank+ic,bl,nfirst)
  end;

procedure CPints(value: real; bl: integer);
{*** Convert pints to gallons, quarts, ounces, liters, cubic centimeters,
     cubic inches. ***}
  begin
    Conversion(value,ozperpt/ozpergal,gl,bl,first);
    Conversion(value,ozperpt/ozperqt,qt,bl,nfirst);
    Conversion(value,ozperpt,oz,bl,nfirst);
    Conversion(value,ozperpt*lpergal/ozpergal,lt,bl,nfirst);
    Conversion(value,ozperpt*lpergal*ccperl/ozpergal,cb+blank+cm,bl,nfirst);
    Conversion(value,ozperpt*cinpergal/ozpergal,cb+blank+ic,bl,nfirst)
  end;

procedure COunces(value: real; bl: integer);
{*** Convert ounces to gallons, quarts, pints, liters, cubic millimeters,
     cubic centimeters, cubic inches. ***}
  begin
    Conversion(value,1/ozpergal,gl,bl,first);
    Conversion(value,1/ozperqt,qt,bl,nfirst);
    Conversion(value,1/ozperpt,pt,bl,nfirst);
    Conversion(value,lpergal/ozpergal,lt,bl,nfirst);
    Conversion(value,lpergal*ccperl*cube(10)/ozpergal,cb+blank+mm,bl,nfirst);
    Conversion(value,lpergal*ccperl/ozpergal,cb+blank+cm,bl,nfirst);
    Conversion(value,cinpergal/ozpergal,cb+blank+ic,bl,nfirst)
  end;

procedure CDegrees(value: real; bl: integer);
{*** Convert degrees to radians. ***}
  begin
    Conversion(value,pi/180.0,'radians',bl,first)
  end;

procedure CRadians(value: real; bl: integer);
{*** Convert radians to degrees. ***}
  begin
    Conversion(value,180.0/pi,'degrees',bl,first)
  end;

procedure CSeconds(value: real; bl: integer);
{*** Convert seconds to minutes, hours, days, solar days, sidereal days. ***}
  begin
    Conversion(value,1/secpermin,mn,bl,first);
    Conversion(value,1/secperhr,hr,bl,nfirst);
    Conversion(value,1/secperday,ds,bl,nfirst);
    Conversion(value,1/(secperday*dypersld),sl,bl,nfirst);
    Conversion(value,1/(secperday*dypersdd),sd,bl,nfirst)
  end;

procedure CMinutes(value: real; bl: integer);
{*** Convert minutes to seconds, hours, days, solar days, sidereal days. ***}
  begin
    Conversion(value,secpermin,sc,bl,first);
    Conversion(value,1/minperhr,hr,bl,nfirst);
    Conversion(value,1/(minperhr*hrperday),ds,bl,nfirst);
    Conversion(value,1/(minperhr*hrperday*dypersld),sl,bl,nfirst);
    Conversion(value,1/(minperhr*hrperday*dypersdd),sd,bl,nfirst)
  end;

procedure CHours(value: real; bl: integer);
{*** Convert hours to seconds, minutes, days, solar days, sidereal days,
     weeks. ***}
  begin
    Conversion(value,secperhr,sc,bl,first);
    Conversion(value,minperhr,mn,bl,nfirst);
    Conversion(value,1/hrperday,ds,bl,nfirst);
    Conversion(value,1/(hrperday*dypersld),sl,bl,nfirst);
    Conversion(value,1/(hrperday*dypersdd),sd,bl,nfirst);
    Conversion(value,1/(hrperday*dayperwk),wk,bl,nfirst)
  end;

procedure CDays(value: real; bl: integer);
{*** Convert days to seconds, minutes, hours, weeks, months, years, solar
     days, sidereal days, sidereal months, solar years, sidereal years. ***}
  begin
    Conversion(value,secperday,sc,bl,first);
    Conversion(value,hrperday*minperhr,mn,bl,nfirst);
    Conversion(value,hrperday,hr,bl,nfirst);
    Conversion(value,1/dayperwk,wk,bl,nfirst);
    Conversion(value,1/dypermo,mo,bl,nfirst);
    Conversion(value,1/dayperyr,yr,bl,nfirst);
    Conversion(value,1/dypersld,sl,bl,nfirst);
    Conversion(value,1/dypersdd,sd,bl,nfirst);
    Conversion(value,1/dypersdm,sdm,bl,nfirst);
    Conversion(value,1/dypersly,sly,bl,nfirst);
    Conversion(value,1/dypersdy,sdy,bl,nfirst)
  end;

procedure CSolarDays(value: real; bl: integer);
{*** Convert solar days to seconds, minutes, hours, days, sidereal days,
     sidereal months, years, sidereal years, solar years. ***}
  begin
    Conversion(value,dypersld*secperday,sc,bl,first);
    Conversion(value,dypersld*hrperday*minperhr,mn,bl,nfirst);
    Conversion(value,dypersld*hrperday,hr,bl,nfirst);
    Conversion(value,dypersld,ds,bl,nfirst);
    Conversion(value,dypersld/dypersdd,sd,bl,nfirst);
    Conversion(value,dypersld/dypersdm,sdm,bl,nfirst);
    Conversion(value,dypersld/dayperyr,yr,bl,nfirst);
    Conversion(value,dypersld/dypersdy,sdy,bl,nfirst);
    Conversion(value,dypersld/dypersly,sly,bl,nfirst)
  end;

procedure CSiderealDays(value: real; bl: integer);
{*** Convert sidereal days to seconds, minutes, hours, days, years,
     solar days, solar years, sidereal months, sidereal years. ***}
  begin
    Conversion(value,dypersdd*secperday,sc,bl,first);
    Conversion(value,dypersdd*hrperday*minperhr,mn,bl,nfirst);
    Conversion(value,dypersdd*hrperday,hr,bl,nfirst);
    Conversion(value,dypersdd,ds,bl,nfirst);
    Conversion(value,dypersdd/dayperyr,yr,bl,nfirst);
    Conversion(value,dypersdd/dypersld,sl,bl,nfirst);
    Conversion(value,dypersdd/dypersly,sly,bl,nfirst);
    Conversion(value,dypersdd/dypersdm,sdm,bl,nfirst);
    Conversion(value,dypersdd/dypersdy,sdy,bl,nfirst)
  end;


procedure CWeeks(value: real; bl: integer);
{*** Convert weeks to days, solar days, sidereal days, months, sidereal
     months, years, solar years, sidereal years. ***}
  begin
    Conversion(value,dayperwk,ds,bl,first);
    Conversion(value,dayperwk/dypersld,sl,bl,nfirst);
    Conversion(value,dayperwk/dypersdd,sd,bl,nfirst);
    Conversion(value,dayperwk/dypermo,mo,bl,nfirst);
    Conversion(value,dayperwk/dypersdm,sdm,bl,nfirst);
    Conversion(value,dayperwk/dayperyr,yr,bl,nfirst);
    Conversion(value,dayperwk/dypersly,sly,bl,nfirst);
    Conversion(value,dayperwk/dypersdy,sdy,bl,nfirst)
  end;

procedure CMonths(value: real; bl: integer);
{*** Convert months to days, weeks, sidereal months, years, solar years,
     sidereal years. ***}
  begin
    Conversion(value,dypermo,ds,bl,first);
    Conversion(value,dypermo/dayperwk,wk,bl,nfirst);
    Conversion(value,dypermo/dypersdm,sdm,bl,nfirst);
    Conversion(value,1/moperyr,yr,bl,nfirst);
    Conversion(value,dypermo/dypersly,sly,bl,nfirst);
    Conversion(value,dypermo/dypersdy,sdy,bl,nfirst)
  end;

procedure CSiderealMonths(value: real; bl: integer);
{*** Convert sidereal months to days, months, years, solar years,
     sidereal years. ***}
  begin
    Conversion(value,dypersdm,ds,bl,first);
    Conversion(value,dypersdm/dypermo,mo,bl,nfirst);
    Conversion(value,dypersdm/dayperyr,yr,bl,nfirst);
    Conversion(value,dypersdm/dypersly,sly,bl,nfirst);
    Conversion(value,dypersdm/dypersdy,sdy,bl,nfirst)
  end;

procedure CYears(value: real; bl: integer);
{*** Convert years to seconds, minutes, hours, days, weeks, months, solar
     days, sidereal days, sidereal months, solar years, sidereal years. ***}
  begin
    Conversion(value,dayperyr*secperday,sc,bl,first);
    Conversion(value,dayperyr*hrperday*minperhr,mn,bl,nfirst);
    Conversion(value,dayperyr*hrperday,hr,bl,nfirst);
    Conversion(value,dayperyr,ds,bl,nfirst);
    Conversion(value,dayperyr/dayperwk,wk,bl,nfirst);
    Conversion(value,moperyr,mo,bl,nfirst);
    Conversion(value,dayperyr/dypersld,sl,bl,nfirst);
    Conversion(value,dayperyr/dypersdd,sd,bl,nfirst);
    Conversion(value,dayperyr/dypersdm,sdm,bl,nfirst);
    Conversion(value,dayperyr/dypersly,sly,bl,nfirst);
    Conversion(value,dayperyr/dypersdy,sdy,bl,nfirst)
  end;

procedure CSolarYears(value: real; bl: integer);
{*** Convert solar years to days, solar days, sidereal days, years,
     sidereal years. ***}
  begin
    Conversion(value,dypersly,ds,bl,first);
    Conversion(value,dypersly/dypersld,sl,bl,nfirst);
    Conversion(value,dypersly/dypersdd,sd,bl,nfirst);
    Conversion(value,dypersly/dayperyr,yr,bl,nfirst);
    Conversion(value,dypersly/dypersdy,sdy,bl,nfirst)
  end;

procedure CSiderealYears(value: real; bl: integer);
{*** Convert sidereal years to days, solar days, sidereal days, years,
     solar years, sidereal months. ***}
  begin
    Conversion(value,dypersdy,ds,bl,first);
    Conversion(value,dypersdy/dypersld,sl,bl,nfirst);
    Conversion(value,dypersdy/dypersdd,sd,bl,nfirst);
    Conversion(value,dypersdy/dayperyr,yr,bl,nfirst);
    Conversion(value,dypersdy/dypersly,sly,bl,nfirst);
    Conversion(value,dypersdy/dypersdm,sdm,bl,nfirst)
  end;

procedure CPounds(value: real; bl: integer);
{*** Convert pounds to ounces, dynes, newtons, grams-force, kilograms-force,
     tons, metric tons. ***}
  begin
    Conversion(value,ozperlb,oz,bl,first);
    Conversion(value,ntperlb*dypernt,dy,bl,nfirst);
    Conversion(value,ntperlb,nt,bl,nfirst);
    Conversion(value,grperkg/lbperkg,gr,bl,nfirst);
    Conversion(value,1/lbperkg,kg,bl,nfirst);
    Conversion(value,1/lbperton,tn,bl,nfirst);
    Conversion(value,1/(lbperkg*kgpermt),mts,bl,nfirst)
  end;

procedure CNewtons(value: real; bl: integer);
{*** Convert newtons to dynes, pounds, tons. ***}
  begin
    Conversion(value,dypernt,dy,bl,first);
    Conversion(value,1/ntperlb,lb,bl,nfirst);
    Conversion(value,1/(ntperlb*lbperton),tn,bl,nfirst)
  end;

procedure CDynes(value: real; bl: integer);
{*** Convert dynes to newtons, pounds, ounces. ***}
  begin
    Conversion(value,1/dypernt,nt,bl,first);
    Conversion(value,1/(dypernt*ntperlb),lb,bl,nfirst);
    Conversion(value,ozperlb/(dypernt*ntperlb),oz,bl,nfirst)
  end;

procedure CGrams(value: real; bl: integer);
{*** Convert grams to kilograms; convert grams-force to ounces, pounds. ***}
  begin
    Conversion(value,1/grperkg,kg,bl,first);
    Conversion(value,lbperkg*ozperlb/grperkg,oz,bl,nfirst);
    Conversion(value,lbperkg/grperkg,lb,bl,nfirst)
  end;

procedure CKilograms(value: real; bl: integer);
{*** Convert kilograms to grams, metric tons; convert kilograms-force to
     pounds, tons. ***}
  begin
    Conversion(value,grperkg,gr,bl,first);
    Conversion(value,lbperkg,lb,bl,nfirst);
    Conversion(value,lbperkg/lbperton,tn,bl,nfirst);
    Conversion(value,1/kgpermt,mts,bl,nfirst)
  end;

procedure CTons(value: real; bl: integer);
{*** Convert tons to pounds, newtons, kilograms-force, metric tons. ***}
  begin
    Conversion(value,lbperton,lb,bl,first);
    Conversion(value,lbperton*ntperlb,nt,bl,nfirst);
    Conversion(value,lbperton/lbperkg,kg,bl,nfirst);
    Conversion(value,lbperton/(lbperkg*kgpermt),mts,bl,nfirst)
  end;

procedure CMetricTons(value: real; bl: integer);
{*** Convert metric tons to newtons, kilograms, pounds, tons. ***}
  begin
    Conversion(value,kgpermt*lbperkg*ntperlb,nt,bl,first);
    Conversion(value,kgpermt,kg,bl,nfirst);
    Conversion(value,kgpermt*lbperkg,lb,bl,nfirst);
    Conversion(value,kgpermt*lbperkg/lbperton,tn,bl,nfirst)
  end;

procedure CFootPounds(value: real; bl: integer);
{*** Convert foot-pounds to joules, ergs, calories, BTU's, kilowatt-hours,
     electron volts. ***}
  begin
    Conversion(value,jperfp,jl,bl,first);
    Conversion(value,jperfp*ergperj,er,bl,nfirst);
    Conversion(value,jperfp/jpercal,cal,bl,nfirst);
    Conversion(value,jperfp/jperbtu,bt,bl,nfirst);
    Conversion(value,jperfp/jperkh,kh,bl,nfirst);
    Conversion(value,jperfp/jperev,ev,bl,nfirst)
  end;

procedure CJoules(value: real; bl: integer);
{*** Convert joules to foot-pounds, ergs, calories, BTU's, kilowatt-hours,
     electron volts. ***}
  begin
    Conversion(value,1/jperfp,fp,bl,first);
    Conversion(value,ergperj,er,bl,nfirst);
    Conversion(value,1/jpercal,cal,bl,nfirst);
    Conversion(value,1/jperbtu,bt,bl,nfirst);
    Conversion(value,1/jperkh,kh,bl,nfirst);
    Conversion(value,1/jperev,ev,bl,nfirst)
  end;

procedure CErgs(value: real; bl: integer);
{*** Convert ergs to joules, foot-pounds, calories, electron volts. ***}
  begin
    Conversion(value,1/ergperj,jl,bl,first);
    Conversion(value,1/(ergperj*jperfp),fp,bl,nfirst);
    Conversion(value,1/(ergperj*jpercal),cal,bl,nfirst);
    Conversion(value,1/(ergperj*jperev),ev,bl,nfirst)
  end;

procedure CCalories(value: real; bl: integer);
{*** Convert calories to joules, foot-pounds, ergs, BTU's, kilowatt-hours,
     electron volts. ***}
  begin
    Conversion(value,jpercal,jl,bl,first);
    Conversion(value,jpercal/jperfp,fp,bl,nfirst);
    Conversion(value,jpercal*ergperj,er,bl,nfirst);
    Conversion(value,jpercal/jperbtu,bt,bl,nfirst);
    Conversion(value,jpercal/jperkh,kh,bl,nfirst);
    Conversion(value,jpercal/jperev,ev,bl,nfirst)
  end;

procedure CBTU(value: real; bl: integer);
{*** Convert British Thermal Units to joules, foot-pounds, calories,
     kilowatt-hours. ***}
  begin
    Conversion(value,jperbtu,jl,bl,first);
    Conversion(value,jperbtu/jperfp,fp,bl,nfirst);
    Conversion(value,jperbtu/jpercal,cal,bl,nfirst);
    Conversion(value,jperbtu/jperkh,kh,bl,nfirst)
  end;

procedure CKilowattHours(value: real; bl: integer);
{*** Convert kilowatt-hours to joules, foot-pounds, calories, BTU's. ***}
  begin
    Conversion(value,jperkh,jl,bl,first);
    Conversion(value,jperkh/jperfp,fp,bl,nfirst);
    Conversion(value,jperkh/jpercal,cal,bl,nfirst);
    Conversion(value,jperkh/jperbtu,bt,bl,nfirst)
  end;

procedure CElectronVolts(value: real; bl: integer);
{*** Convert electron volts to joules, ergs, foot-pounds, calories. ***}
  begin
    Conversion(value,jperev,jl,bl,first);
    Conversion(value,jperev*ergperj,er,bl,nfirst);
    Conversion(value,jperev/jperfp,fp,bl,nfirst);
    Conversion(value,jperev/jpercal,cal,bl,nfirst)
  end;

procedure CWatts(value: real; bl: integer);
{*** Convert watts to foot-pounds per second, kilowatts, horsepower,
     calories per second. ***}
  begin
    Conversion(value,1/wperfp,fps,bl,first);
    Conversion(value,1/wperkw,kw,bl,nfirst);
    Conversion(value,1/wperhp,hp,bl,nfirst);
    Conversion(value,1/wpercal,cs,bl,nfirst)
  end;

procedure CKilowatts(value: real; bl: integer);
{*** Convert kilowatts to watts, foot-pounds per second, calories per
     second, horsepower. ***}
  begin
    Conversion(value,wperkw,wt,bl,first);
    Conversion(value,wperkw/wperfp,fps,bl,nfirst);
    Conversion(value,wperkw/wpercal,cs,bl,nfirst);
    Conversion(value,wperkw/wperhp,hp,bl,nfirst)
  end;

procedure CFootPoundsSec(value: real; bl: integer);
{*** Convert foot-pounds per second to watts, kilowatts, calories per
     second, horsepower. ***}
  begin
    Conversion(value,wperfp,wt,bl,first);
    Conversion(value,wperfp/wperkw,kw,bl,nfirst);
    Conversion(value,wperfp/wpercal,cs,bl,nfirst);
    Conversion(value,1/fpperhp,hp,bl,nfirst)
  end;

procedure CHorsepower(value: real; bl: integer);
{*** Convert horsepower to foot-pounds per second, watts, kilowatts,
     calories per second. ***}
  begin
    Conversion(value,fpperhp,fps,bl,first);
    Conversion(value,wperhp,wt,bl,nfirst);
    Conversion(value,wperhp/wperkw,kw,bl,nfirst);
    Conversion(value,wperhp/wpercal,cs,bl,nfirst)
  end;

procedure CCaloriesSec(value: real; bl: integer);
{*** Convert calories per second to watts, kilowatts, foot-pounds per
     second, horsepower. ***}
  begin
    Conversion(value,wpercal,wt,bl,first);
    Conversion(value,wpercal/wperkw,kw,bl,nfirst);
    Conversion(value,wpercal/wperfp,fps,bl,nfirst);
    Conversion(value,wpercal/wperhp,hp,bl,nfirst)
  end;

procedure CMPH(value: real; bl: integer);
{*** Convert miles per hour to feet per second, meters per second,
     kilometers per hour. ***}
  begin
    Conversion(value,ftpermi/secperhr,fs,bl,first);
    Conversion(value,ftpermi*mperft/secperhr,ms,bl,nfirst);
    Conversion(value,kmpermi,kph,bl,nfirst)
  end;

procedure CFeetSec(value: real; bl: integer);
{*** Convert feet per second to miles per hour, meters per second,
     kilometers per hour. ***}
  begin
    Conversion(value,secperhr/ftpermi,mph,bl,first);
    Conversion(value,mperft,ms,bl,nfirst);
    Conversion(value,secperhr*kmpermi/ftpermi,kph,bl,nfirst)
  end;

procedure CKPH(value: real; bl: integer);
{*** Convert kilometers per hour to miles per hour, feet per second,
     meters per second. ***}
  begin
    Conversion(value,miperkm,mph,bl,first);
    Conversion(value,miperkm*ftpermi/secperhr,fs,bl,nfirst);
    Conversion(value,mperkm/secperhr,ms,bl,nfirst)
  end;

procedure CMPerSec(value: real; bl: integer);
{*** Convert meters per second to kilometers per hour, miles per hour,
     feet per second. ***}
  begin
    Conversion(value,secperhr/mperkm,kph,bl,first);
    Conversion(value,secperhr*miperkm/mperkm,mph,bl,nfirst);
    Conversion(value,ftperm,fs,bl,nfirst)
  end;


procedure RemoveBlanks(var rstr: str80);
{*** Utility procedure to remove leading blanks from the string rstr. ***}
  begin
    repeat
      if rstr[1] = blank then Delete(rstr,1,1)
    until rstr[1] <> blank
  end;  { RemoveBlanks }

function Inches(tstr: str80): boolean;
  begin
    if (tstr = 'in') or (tstr = 'inch') or (tstr = 'inches')
      then Inches := true
      else Inches := false
  end;

function Feet(tstr: str80): boolean;
  begin
    if (tstr = 'ft') or (tstr = 'foot') or (tstr = 'feet')
      then Feet := true
      else Feet := false
  end;

function Meters(tstr: str80): boolean;
  begin
    if (tstr = 'm') or (tstr = 'meter') or (tstr = 'meters')
      then Meters := true
      else Meters := false
 end;

function Centimeters(tstr: str80): boolean;
  begin
    if (tstr = 'cm') or (tstr = 'centimeter') or (tstr = 'centimeters')
      then Centimeters := true
      else Centimeters := false
  end;

function Millimeters(tstr: str80): boolean;
  begin
    if (tstr = 'mm') or (tstr = 'millimeter') or (tstr = 'millimeters')
      then Millimeters := true
      else Millimeters := false
  end;

function Kilometers(tstr: str80): boolean;
  begin
    if (tstr = 'km') or (tstr = 'kilometer') or (tstr = 'kilometers')
      then Kilometers := true
      else Kilometers := false
  end;

function Yards(tstr: str80): boolean;
  begin
    if (tstr = 'yd') or (tstr = 'yds') or (tstr = 'yard') or (tstr = 'yards')
      then Yards := true
      else Yards := false
  end;

function Miles(tstr: str80): boolean;
  begin
    if (tstr = 'mi') or (tstr = 'mile') or (tstr = 'miles')
      then Miles := true
      else Miles := false
  end;

function NauticalMiles(tstr: str80): boolean;
  begin
    if (tstr = 'nm') or (tstr = 'nautical mile') or (tstr = 'nautical miles')
      then NauticalMiles := true
      else NauticalMiles := false
  end;

function AstronomicalUnits(tstr: str80): boolean;
  begin
    if (tstr = 'au') or (tstr = 'astronomical unit')
      or (tstr = 'astronomical units')
      then AstronomicalUnits := true
      else AstronomicalUnits := false
  end;

function LightYears(tstr: str80): boolean;
  begin
    if (tstr = 'light year') or (tstr = 'light years') or (tstr = 'ly')
      or (tstr = 'lightyear') or (tstr = 'lightyears')
      then LightYears := true
      else LightYears := false
  end;

function Parsecs(tstr: str80): boolean;
  begin
    if (tstr = 'parsec') or (tstr = 'parsecs')
      then Parsecs := true
      else Parsecs := false
  end;

function SquareInches(tstr: str80): boolean;
  begin
    if (tstr = 'sq in') or (tstr = 'square inches')
      then SquareInches := true
      else SquareInches := false
  end;

function SquareCentimeters(tstr: str80): boolean;
  begin
    if (tstr = 'sq cm') or (tstr = 'square centimeters')
      then SquareCentimeters := true
      else SquareCentimeters := false
  end;

function SquareMeters(tstr: str80): boolean;
  begin
    if (tstr = 'sq m') or (tstr = 'square meters')
      then SquareMeters := true
      else SquareMeters := false
  end;

function SquareFeet(tstr: str80): boolean;
  begin
    if (tstr = 'sq ft') or (tstr = 'square foot') or (tstr = 'square feet')
      then SquareFeet := true
      else SquareFeet := false
  end;

function SquareYards(tstr: str80): boolean;
  begin
    if (tstr = 'sq yd') or (tstr = 'sq yds') or (tstr = 'square yard')
      or (tstr = 'square yards')
      then SquareYards := true
      else SquareYards := false
  end;

function SquareMiles(tstr: str80): boolean;
  begin
    if (tstr = 'sq mi') or (tstr = 'square mile') or (tstr = 'square miles')
      then SquareMiles := true
      else SquareMiles := false
  end;

function SquareKilometers(tstr: str80): boolean;
  begin
    if (tstr = 'sq km') or (tstr = 'square kilometer')
      or (tstr = 'square kilometers')
      then SquareKilometers := true
      else SquareKilometers := false
  end;

function Acres(tstr: str80): boolean;
  begin
    if (tstr = 'acre') or (tstr = 'acres')
      then Acres := true
      else Acres := false
  end;

function CubicInches(tstr: str80): boolean;
  begin
    if (tstr = 'cubic inch') or (tstr = 'cubic in')
       or (tstr = 'cubic inches') or (tstr = 'cu in')
      then CubicInches := true
      else CubicInches := false
  end;

function CubicFeet(tstr: str80): boolean;
  begin
    if (tstr = 'cubic ft') or (tstr = 'cubic foot')
      or (tstr = 'cubic feet') or (tstr = 'cu ft')
      then CubicFeet := true
      else CubicFeet := false
  end;

function CubicYards(tstr: str80): boolean;
  begin
    if (tstr = 'cu yd') or (tstr = 'cubic yard') or (tstr = 'cubic yards')
      then CubicYards := true
      else CubicYards := false
  end;

function CubicMeters(tstr: str80): boolean;
  begin
    if (tstr = 'cubic m') or (tstr = 'cubic meter')
      or (tstr = 'cubic meters') or (tstr = 'cu m')
      then CubicMeters := true
      else CubicMeters := false
  end;

function CubicCentimeters(tstr: str80): boolean;
  begin
    if (tstr = 'cc') or (tstr = 'cubic cm')
      or (tstr = 'cubic centimeter') or (tstr = 'cu cm')
      or (tstr = 'cubic centimeters')
      then CubicCentimeters := true
      else CubicCentimeters := false
  end;

function CubicKilometers(tstr: str80): boolean;
  begin
    if (tstr = 'cubic km') or (tstr = 'cubic kilometer')
      or (tstr = 'cubic kilometers') or (tstr = 'cu km')
      then CubicKilometers := true
      else CubicKilometers := false
  end;

function CubicMiles(tstr: str80): boolean;
  begin
    if (tstr = 'cubic mi') or (tstr = 'cubic mile')
      or (tstr = 'cubic miles') or (tstr = 'cu mi')
      then CubicMiles := true
      else CubicMiles := false
  end;

function Gallons(tstr: str80): boolean;
  begin
    if (tstr = 'gal') or (tstr = 'gallon') or (tstr = 'gallons')
      then Gallons := true
      else Gallons := false
  end;

function Liters(tstr: str80): boolean;
  begin
    if (tstr = 'l') or (tstr = 'liter') or (tstr = 'liters')
      then Liters := true
      else Liters := false
  end;

function MilliLiters(tstr: str80): boolean;
  begin
    if (tstr = 'ml') or (tstr = 'milliliter') or (tstr = 'milliliters')
      then MilliLiters := true
      else MilliLiters := false
  end;

function Ounces(tstr: str80): boolean;
  begin
    if (tstr = 'oz') or (tstr = 'ounce') or (tstr = 'ounces')
      then Ounces := true
      else Ounces := false
  end;

function Quarts(tstr: str80): boolean;
  begin
    if (tstr = 'qt') or (tstr = 'quart') or (tstr = 'quarts')
      then Quarts := true
      else Quarts := false
  end;

function Pints(tstr: str80): boolean;
  begin
    if (tstr = 'pt') or (tstr = 'pint') or (tstr = 'pints')
      then Pints := true
      else Pints := false
  end;

function Degrees(tstr: str80): boolean;
  begin
    if (tstr = 'deg') or (tstr = 'degree') or (tstr = 'degrees')
      then Degrees := true
      else Degrees := false
  end;

function Radians(tstr: str80): boolean;
  begin
    if (tstr = 'rad') or (tstr = 'radian') or (tstr = 'radians')
      then Radians := true
      else Radians := false
  end;

function Seconds(tstr: str80): boolean;
  begin
    if (tstr = 's') or (tstr = 'sec') or (tstr = 'second')
      or (tstr = 'seconds')
      then Seconds := true
      else Seconds := false
  end;

function Minutes(tstr: str80): boolean;
  begin
    if (tstr = 'min') or (tstr = 'minute') or (tstr = 'minutes')
      then Minutes := true
      else Minutes := false
  end;

function Hours(tstr: str80): boolean;
  begin
    if (tstr = 'hr') or (tstr = 'hour') or (tstr = 'hours')
      then Hours := true
      else Hours := false
  end;

function Days(tstr: str80): boolean;
  begin
    if (tstr = 'day') or (tstr = 'days')
      then Days := true
      else Days := false
  end;

function SolarDays(tstr: str80): boolean;
  begin
    if (tstr = 'solar day') or (tstr = 'solar days')
      then SolarDays := true
      else SolarDays := false
  end;

function SiderealDays(tstr: str80): boolean;
  begin
    if (tstr = 'sidereal day') or (tstr = 'sidereal days')
      then SiderealDays := true
      else SiderealDays := false
  end;

function Weeks(tstr: str80): boolean;
  begin
    if (tstr = 'wk') or (tstr = 'week') or (tstr = 'weeks')
      then Weeks := true
      else Weeks := false
  end;

function Months(tstr: str80): boolean;
  begin
    if (tstr = 'mo') or (tstr = 'month') or (tstr = 'months')
      then Months := true
      else Months := false
  end;

function SiderealMonths(tstr: str80): boolean;
  begin
    if (tstr = 'sidereal month') or (tstr = 'sidereal months')
      then SiderealMonths := true
      else SiderealMonths := false
  end;

function Years(tstr: str80): boolean;
  begin
    if (tstr = 'yr') or (tstr = 'year') or (tstr = 'years')
      then Years := true
      else Years := false
  end;

function SolarYears(tstr: str80): boolean;
  begin
    if (tstr = 'solar year') or (tstr = 'solar years')
      then SolarYears := true
      else SolarYears := false
  end;

function SiderealYears(tstr: str80): boolean;
  begin
    if (tstr = 'sidereal year') or (tstr = 'sidereal years')
      then SiderealYears := true
      else SiderealYears := false
  end;

function Pounds(tstr: str80): boolean;
  begin
    if (tstr = 'lb') or (tstr = 'pound') or (tstr = 'pounds')
      then Pounds := true
      else Pounds := false
  end;

function Newtons(tstr: str80): boolean;
  begin
    if (tstr = 'nt') or (tstr = 'newton') or (tstr = 'newtons')
      then Newtons := true
      else Newtons := false
  end;

function Dynes(tstr: str80): boolean;
  begin
    if (tstr = 'dy') or (tstr = 'dyne') or (tstr = 'dynes')
      then Dynes := true
      else Dynes := false
  end;

function Grams(tstr: str80): boolean;
  begin
    if (tstr = 'gm') or (tstr = 'gram') or (tstr = 'grams')
      or (tstr = 'gmf') or (tstr = 'gram-force') or (tstr = 'grams-force')
      then Grams := true
      else Grams := false
  end;

function Kilograms(tstr: str80): boolean;
  begin
    if (tstr = 'kg') or (tstr = 'kilogram') or (tstr = 'kilograms') or
     (tstr = 'kgf') or (tstr = 'kilogram-force') or (tstr = 'kilograms-force')
      then Kilograms := true
      else Kilograms := false
  end;

function Tons(tstr: str80): boolean;
  begin
    if (tstr = 'ton') or (tstr = 'tons')
      then Tons := true
      else Tons := false
  end;

function MetricTons(tstr: str80): boolean;
  begin
    if (tstr = 'metric ton') or (tstr = 'metric tons')
      then MetricTons := true
      else MetricTons := false
  end;

function FootPounds(tstr: str80): boolean;
  begin
    if (tstr = 'ft-lb') or (tstr = 'foot-pound') or (tstr = 'foot-pounds')
      then FootPounds := true
      else FootPounds := false
  end;

function Joules(tstr: str80): boolean;
  begin
    if (tstr = 'j') or (tstr = 'joule') or (tstr = 'joules')
      then Joules := true
      else Joules := false
  end;

function Calories(tstr: str80): boolean;
  begin
    if (tstr = 'cal') or (tstr = 'calorie') or (tstr = 'calories')
      then Calories := true
      else Calories := false
  end;

function Ergs(tstr: str80): boolean;
  begin
    if (tstr = 'erg') or (tstr = 'ergs')
      then Ergs := true
      else Ergs := false
  end;

function BTU(tstr: str80): boolean;
  begin
    if (tstr = 'btu') or (tstr = 'btus') or (tstr = 'BTU') or (tstr = 'BTUs')
      then BTU := true
      else BTU := false
  end;

function KilowattHours(tstr: str80): boolean;
  begin
    if (tstr = 'kw-hr') or (tstr = 'kilowatt-hour')
      or (tstr = 'kilowatt-hours')
      then KilowattHours := true
      else KilowattHours := false
  end;

function ElectronVolts(tstr: str80): boolean;
  begin
    if (tstr = 'ev') or (tstr = 'electron volt') or (tstr = 'electron volts')
      then ElectronVolts := true
      else ElectronVolts := false
  end;

function Watts(tstr: str80): boolean;
  begin
    if (tstr = 'w') or (tstr = 'watt') or (tstr = 'watts')
      then Watts := true
      else Watts := false
  end;

function Kilowatts(tstr: str80): boolean;
  begin
    if (tstr = 'kw') or (tstr = 'kilowatt') or (tstr = 'kilowatts')
      then Kilowatts := true
      else Kilowatts := false
  end;

function FootPoundsSec(tstr: str80): boolean;
  begin
    if (tstr = 'ft-lb/s') or (tstr = 'ft-lb/sec')
      or (tstr = 'foot-pound/second') or (tstr = 'foot-pounds/second')
      then FootPoundsSec := true
      else FootPoundsSec := false
  end;

function Horsepower(tstr: str80): boolean;
  begin
    if (tstr = 'hp') or (tstr = 'horsepower')
      then Horsepower := true
      else Horsepower := false
  end;

function CaloriesSec(tstr: str80): boolean;
  begin
    if (tstr = 'cal/s') or (tstr = 'cal/sec')
      or (tstr = 'calories/second')
      then CaloriesSec := true
      else CaloriesSec := false
  end;

function MilesPerHr(tstr: str80): boolean;
  begin
    if (tstr = 'mph') or (tstr = 'miles per hour')
      or (tstr = 'mi/hr')
      then MilesPerHr := true
      else MilesPerHr := false
  end;

function FeetSec(tstr: str80): boolean;
  begin
    if (tstr = 'ft/s') or (tstr = 'feet per sec')
      or (tstr = 'feet per second') or (tstr = 'ft/sec')
      then FeetSec := true
      else FeetSec := false
  end;

function KmPerHr(tstr: str80): boolean;
  begin
    if (tstr = 'kph') or (tstr = 'kilometers per hour')
      or (tstr = 'km/hr')
      then KmPerHr := true
      else KmPerHr := false
  end;

function MPerSec(tstr: str80): boolean;
  begin
    if (tstr = 'm/s') or (tstr = 'meters per sec')
      or (tstr = 'meters per second') or (tstr = 'm/sec')
      then MPerSec := true
      else MPerSec := false
  end;

procedure Choose(st: str80; quant: real; bl: integer);
{*************************************************************************
Function:
   Choose tests the input string until it finds a match, then calls
   the appropriate conversion procedure.  If no match is found, it issues
   a message.  The conversion procedures can all be found in the file
   CConvert.inc.
Argument list:
   st - string to be tested.
   quant - quantity to be converted.
   bl - length of input string plus equal sign, so the number of blanks to
        issue so that all outputs align.
*************************************************************************** }
  begin
    if Inches(st) then CInches(quant,bl)
    else if Feet(st) then CFeet(quant,bl)
    else if Meters(st) then CMeters(quant,bl)
    else if Centimeters(st) then CCentimeters(quant,bl)
    else if Millimeters(st) then CMillimeters(quant,bl)
    else if Kilometers(st) then CKilometers(quant,bl)
    else if Yards(st) then CYards(quant,bl)
    else if Miles(st) then CMiles(quant,bl)
    else if NauticalMiles(st) then CNauticalMiles(quant,bl)
    else if AstronomicalUnits(st) then CAstronomicalUnits(quant,bl)
    else if LightYears(st) then CLightYears(quant,bl)
    else if Parsecs(st) then CParsecs(quant,bl)
    else if SquareInches(st) then CSqInches(quant,bl)
    else if SquareCentimeters(st) then CSqCentimeters(quant,bl)
    else if SquareMeters(st) then CSqMeters(quant,bl)
    else if SquareFeet(st) then CSqFeet(quant,bl)
    else if SquareYards(st) then CSqYards(quant,bl)
    else if SquareMiles(st) then CSqMiles(quant,bl)
    else if SquareKilometers(st) then CSqKilometers(quant,bl)
    else if Acres(st) then CAcres(quant,bl)
    else if CubicInches(st) then CCubicInches(quant,bl)
    else if CubicFeet(st) then CCubicFeet(quant,bl)
    else if CubicYards(st) then CCubicYards(quant,bl)
    else if CubicMeters(st) then CCubicMeters(quant,bl)
    else if CubicCentimeters(st) then CCubicCentimeters(quant,bl)
    else if CubicKilometers(st) then CCubicKilometers(quant,bl)
    else if CubicMiles(st) then CCubicMiles(quant,bl)
    else if Gallons(st) then CGallons(quant,bl)
    else if Liters(st) then CLiters(quant,bl)
    else if Ounces(st) then COunces(quant,bl)
    else if Quarts(st) then CQuarts(quant,bl)
    else if Pints(st) then CPints(quant,bl)
    else if Degrees(st) then CDegrees(quant,bl)
    else if Radians(st) then CRadians(quant,bl)
    else if Seconds(st) then CSeconds(quant,bl)
    else if Minutes(st) then CMinutes(quant,bl)
    else if Hours(st) then CHours(quant,bl)
    else if Days(st) then CDays(quant,bl)
    else if SolarDays(st) then CSolarDays(quant,bl)
    else if SiderealDays(st) then CSiderealDays(quant,bl)
    else if Weeks(st) then CWeeks(quant,bl)
    else if Months(st) then CMonths(quant,bl)
    else if SiderealMonths(st) then CSiderealMonths(quant,bl)
    else if Years(st) then CYears(quant,bl)
    else if SolarYears(st) then CSolarYears(quant,bl)
    else if SiderealYears(st) then CSiderealYears(quant,bl)
    else if Pounds(st) then CPounds(quant,bl)
    else if Newtons(st) then CNewtons(quant,bl)
    else if Dynes(st) then CDynes(quant,bl)
    else if Grams(st) then CGrams(quant,bl)
    else if Kilograms(st) then CKilograms(quant,bl)
    else if Tons(st) then CTons(quant,bl)
    else if MetricTons(st) then CMetricTons(quant,bl)
    else if FootPounds(st) then CFootPounds(quant,bl)
    else if Joules(st) then CJoules(quant,bl)
    else if Calories(st) then CCalories(quant,bl)
    else if Ergs(st) then CErgs(quant,bl)
    else if BTU(st) then CBTU(quant,bl)
    else if KilowattHours(st) then CKilowattHours(quant,bl)
    else if ElectronVolts(st) then CElectronVolts(quant,bl)
    else if Watts(st) then CWatts(quant,bl)
    else if Kilowatts(st) then CKilowatts(quant,bl)
    else if FootPoundsSec(st) then CFootPoundsSec(quant,bl)
    else if Horsepower(st) then CHorsepower(quant,bl)
    else if CaloriesSec(st) then CCaloriesSec(quant,bl)
    else if MilesPerHr(st) then CMPH(quant,bl)
    else if FeetSec(st) then CFeetSec(quant,bl)
    else if KmPerHr(st) then CKPH(quant,bl)
    else if MPerSec(st) then CMPerSec(quant,bl)
    else writeln('-- unknown unit.')
  end;  { Choose }

end. { Implementation }