Temperature conversion/REXX: Difference between revisions

m
added whitespace.
m (added the COMMA subroutine to add commas to output.)
m (added whitespace.)
 
(28 intermediate revisions by 2 users not shown)
Line 1:
This is the unabridged version of the REXX program to solve the Rosetta Code task of   ''Temperature conversion''.
=={{header|REXX}}
<lang rexx>/*REXX program converts temperatures for a number of temperature scales.*/
call e /*let's see the precision we have*/
numeric digits length(e) /*big digits for Planck & Daltons*/
parse arg tList /*get specified temperature lists*/
 
 
do until tList='' /*process a list of temperatures.*/
Note that conversion from/to the &nbsp; '''Dalton''' &nbsp; temperature scale requires natural logarithms &nbsp; ('''ln'''), &nbsp; and the &nbsp; '''pow''' &nbsp; function.
parse var tList x ',' tList /*temps are separated by commas. */
 
x=translate(x,'((',"[{") /*support other grouping symbols.*/
 
x=space(x); parse var x z '(' /*handle any comments (if any). */
No commenting/explaining was affixed to the higher math functions because it would detract from the logic of the main program.
parse upper var z z ' TO ' ! . /*separate the TO option from #*/
 
if !=='' then !='ALL'; all=!=='ALL' /*allow specification of "TO" opt*/
 
<span style='font-family: "Linux Libertine",Georgia,Times,serif;font-size:150%;'>[[REXX]]</span><hr>
 
 
<lang rexx>/*REXX program converts temperatures for fifty─eight different temperature scales. */
/*
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
 
tt tt
tt tt
tttttt tttttt
tttttt eeee mmm mm ppppp eeee rr rr aaaa tttttt uu uu rr rr eee
tt eeeeee mmmmmmmm pppppp eeeeee rrrrrr aaaaa tt uu uu rrrrrr eeeeee
tt ee ee mm mm mm pp pp ee ee rrr rr aa tt uu uu rrr rr ee ee
tt eeeeee mm mm mm pp pp eeeeee rr aaaaaa tt uu uu rr eeeeee
tt eeeeee mm mm mm pppppp eeeeee rr aaaaaaa tt uu uu rr eeeeee
tt tt ee mm mm mm ppppp ee rr aa aa tt tt uu uu rr ee
ttttt eeeee mm mm mm pp eeeee rr aaaaaaa ttttt uuuuuu rr eeeee
ttt eee mm mm mm pp eee rr aaaaaaa ttt uuu uu rr eee
pp
pp
 
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
*/
 
 
call e /*let's see the precision we can use. */
numeric digits length(e) - 1 /*big digits for Planck & Dalton scale.*/
/*subtract one for the decimal point.*/
parse arg tList /*get the specified temperature lists. */
tList= space(tList) /*elide any and all superfluous blanks.*/
 
do until tList='' /*process the list of temperatures. */
parse var tList x ',' tList /*temperatures are separated by commas.*/
x= translate(x, '(((', "[{«") /*support other grouping symbols. */
x= space(x) /*elide any and all superfluous blanks.*/
parse var x z '(' /*handle any comments (if there're any)*/
parse upper var z z ' TO ' ! . /*separate the TO option from number.*/
parse upper var z z 'NOT' not . , noS noE /*separate NOT option from number. */
/*for the NOT keyword, see (below).*/
/* *xxx ◄───don't show scales that end in xxx */
/* xxx* ◄─── " " " " begin with xxx */
if not\=='' then do
if left(not, 1) == '*' then noE= substr(not, 2)
if right(not, 1) == '*' then noS= left(not, length(not) - 1)
noL= length(noE || noS)
if noL==0 then call serr ,
"illegal NOT keyword, no leading or trailing * specified."
end
 
if !=='' then != "ALL" /*nothing specific, so choose "ALL". */
 
all= (!=='ALL') /*allows specification of the "TO" opt.*/
 
if z=='' then call serr 'no arguments were specified.'
 
_=verify(z, '+-.0123456789') /*a list of valid number thingys.*/
_= verify(z, '+-.0123456789') /*list of valid decimal digs & thingys.*/
n=z
n= z /*obtain a "backup" copy of Z (number).*/
 
if _\==0 then do
if _==1 then call serr 'illegal temperature:' z
n= left(z, _-1) /*pick offobtain the number (hopefully). */
u= strip( substr(z, _) ) /*pick offobtain the temperature unit. */
end
else u= 'k' /*assume kelvin as per task req.requirement*/
/* ────── */
if \datatype(n, 'N') then call serr "illegal number:" n
 
if \all then do /*there is a TO ααα temp. scale. */
call scaleName ! /*process the TO temp. abbreviation.*/
!= sn /*assign the full temperature name to !*/
end /*! now contains temp scale full name.*/
 
call scaleName u /*allow alternate temp. scale spellings*/
call convert2Fahrenheit /*convert a temperature ──► Fahrenheit.*/
 
say right(' ' x, 79, "─") /*show original value & scale (for sep)*/
 
call convert2specific /*convert Fahrenheit ──► specific temp,*/
end /*until tlist*/ /*this is a biggish DO loop. */
 
 
exit /*stick a fork in it, we're all done. */
 
 
/*──────────────────────────────────────────────────────────────────────────────────────*/
$: procedure; showDig= 8 /*only show 8 significant decimal digs.*/
_= commas( format( arg(1), , showDig ) / 1 ) /*format# 8 digits past . and add comma*/
p= pos(., _) /*find position of the decimal point. */
/* [↓] align integers with FP numbers.*/
if p==0 then _= _ || left('', 5 + showDig + 1) /*no decimal point.*/
else _= _ || left('', 5 + showDig - length(_) + p) /*has " " */
 
return right(_, max(60, length(_) ) ) /*return the re─formatted argument (#).*/
 
 
/*────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
if \datatype(n,'N') then call serr 'illegal number:' n
convert2Fahrenheit: if \all then do /*there is a /*convert TON ααα──► ºF scale temperatures. */
call scaleName ! /*process the TO abbreviation*/
!=sn /*assign the full name to ! */
end /* ! now contains scale full name*/
call scaleName u /*allow alternate scale spellings*/
 
select /*convert ──►[↓] °Ffifty-eight temperature temperaturesscales. */
select
when sn=='ABSOLUTE' then F= n * 9/5 - 459.67
when sn=='AMONTON' then F= n * 8.37209 - 399.163
when sn=='BARNSDORF' then F= n * 6.85714 + 6.85714
when sn=='BEAUMUIR' then F= n * 2.22951 + 32
when sn=='BENART' then F= n * 1.43391 + 31.2831
when sn=='BERGEN' then F=(n + 23.8667) * 15/14
when sn=='BRISSEN' then F= n * 32/15 + 32
when sn=='CELSIUS' then F= n * 9/5 + 32 /*a single C is taken as Celsius.*/
Line 40 ⟶ 119:
when sn=='CRUQUIUS' then F= n * 0.409266 - 405.992
when sn=='DALENCE' then F= n * 2.7 + 59
when sn=='DALTON' then F= 273.15 * pow(273.15 / 273.15, n / 100) * 1.8 - 459.67
when sn=='DANIELL' then F= n * 7.27194 + 55.9994
when sn=='DE LA HIRE' then F=(n - 3) / 0.549057
when sn=='DE LA VILLE' then F=(n + 6.48011) / 0.985568
when sn=='DELISLE' then F=212 - n * 6/5
when sn=='DELISLE oldOLD' then F=212 - n * 1.58590197
when sn=='DE LUC' then F=(n + 14) * 16/7
when sn=='DE LYON' then F=(n + 17.5) * 64/35
when sn=='DE REVILLAS' then F=212 - n * 97/80
when sn=='DERHAM' then F= n / 0.38444386 - 188.578
when sn=='DERHAM oldOLD' then F= n * 3 + 4.5
when sn=='DE SUEDE' then F=(n + 17.6666) * 150/83
when sn=='DE VILLENEUVE' then F=(n + 23.7037) / 0.740741
when sn=='DU CREST' then F=(n + 37.9202) / 0.650656
when sn=='EDINBURGH' then F= n * 4.6546 - 6.40048
when sn=='ELECTRON VOLTS' then F= n * 20888.1 - 459.67
when sn=='FAHRENHEIT' then F= n
when sn=='FAHRENHEIT oldOLD' then F= n * 20/11 - 89.2727
when sn=='FLORENTINE LARGE' then F=(n + 7.42857) / 0.857143
when sn=='FLORENTINE MAGNUM' then F=(n + 73.9736 ) / 1.50659
when sn=='FLORENTINE SMALL' then F=(n - 1.38571) / 0.378571
when sn=='FOWLER' then F= n * 0.640321 + 53.7709
when sn=='FRICK' then F= n * 200/251 + 58.5339
Line 73 ⟶ 152:
when sn=='NEWTON' then F= n * 60/11 + 32
when sn=='OERTEL' then F= n + n - 32
when sn=='PLANCK' then F= n * 1.416833e32 * 9/5 - 459.67
when sn=='RANKINE' then F= n - 459.67 /*a single R is taken as Rankine.*/
when sn=='REAUMUR' then F= n * 9/4 + 32
Line 80 ⟶ 159:
when sn=='ROMER' then F=(n - 7.5) * 27/4 + 32
when sn=='ROSENTHAL' then F= n * 45/86 - 453.581
when sn=='ROYAL SOCIETY' then F=(n -122.82) * -50/69
when sn=='SAGREDO' then F= n * 0.3798 - 5.98
when sn=='SAINT-PATRICE' then F= n * 2.62123 + 115.879
Line 90 ⟶ 169:
end /*select*/
 
return
K = (F + 459.67) * 5/9 /*compute temperature to kelvins.*/
 
a =(1e || (-digits()%2)-digits()%20) /*mininum number for Dalton temp.*/
 
eV=(F + 459.67) / 20888.1 /*compute number electron volts. */
/*─────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
say right(' ' x, 79, "─") /*show original value &scale,sep.*/
convert2specific: if all | !=='AMONTON' then say $( ( F + 399.163 ) / 8.37209 /*convert ºF ──► )xxx 'Amonton'temperatures.*/
 
if all | !=='BARNSDORF' then say $( ( F - 6.85715) / 6.85715 ) 'Barnsdorf'
ifK all= |(F !=='BEAUMUIR'+ 459.67) * 5/9 then say $( ( F - 32 ) /*compute temperature 2.22951in kelvin scale. ) 'Beaumuir'*/
a = (1e || (-digits() % 2) - digits() % 20) /*minimum number for Dalton temperature*/
if all | !=='BENART' then say $( ( F - 31.2831 ) / 1.43391 ) 'Benart'
eV = if(F all+ |459.67) !=='BERGEN' / 20888.1 then say $( ( F * 14/15 /*compute the )number of electron - 23volts.8667 ) 'Bergen'*/
 
if all | !=='BRISSON' then say $( ( F - 32 ) * 15/32 ) 'Brisson'
 
if all | !=='CELSIUS' then say $( ( F - 32 ) * 5/9 ) 'Celsius'
if all | !==?('CIMENTOABSOLUTE') then say $( ( F +k 4.54135) / 2.70677 ) 'Cimento' ) "Absolute"
if all | !==?('CRUQUIUSAMONTON') then say $( ( F + 405399.992163 ) / / 08.40926637209 ) 'Cruquius' ) "Amonton"
if all | !==?('DALENCEBARNSDORF' ) then say $( ( F - 59 6.85715) / 6.85715 ) / 2.7 ) 'Dalence'"Barnsdorf"
if ?('BEAUMUIR') then say $( ( F - 32 ) / 2.22951 ) "Beaumuir"
if all | !=='DALTON' then if k>a then say $(100*ln(k/273.15)/ln(373.15/273.15)) 'Dalton'
if ?('BENART') then say $( ( F - 31.2831 ) / 1.43391 else say right('-infinity ',60) 'Dalton'"Benart"
if all | !==?('DANIELLBERGEN') then say $( ( F * 14/15 ) - 5523.99948667 ) / 7.27194 ) ) 'Daniell' "Bergen"
if all?('BRISSON') | !=='DE LA HIRE' then say $( ( F *- 32 0.549057 + 3) * 15/32 ) 'De la Hire' ) "Brisson"
if all?('CELSIUS') | !=='DE LA VILLE' then say $( ( F - 32 ) * 0.9855685/9 - 6.48011 ) 'De la Ville' ) "Celsius"
if all | !==?('DELISLECIMENTO') then say $( ( 212F - F + 4.54135) / )2.70677 * 5/6 ) 'Delisle'"Cimento"
if all?('CRUQUIUS') | !=='DELISLE old' then say $( ( 212F - F + 405.992 ) / )0.409266 / 1.58590197 ) 'Delisle old') "Cruquius"
if all | !==?('DE LUCDALENCE') then say $( ( F *- 7/1659 ) / - 14 2.7 ) 'De Luc' ) "Dalence"
 
if all | !=='DE LYON' then say $( F * 35/64 - 17.5 ) 'De Lyon'
if all | !==?('DE REVILLASDALTON') then say $( ( 212 - Fthen if K>a then say ) $(100* 80ln(k/273.15)/ln(373.15/97 273.15) ) 'De Revillas'"Dalton"
if all | !=='DERHAM' then say $( F * 0.38444386 + 72.4978 else say right("-infinity ", 60) 'Derham' "Dalton"
 
if all | !=='DERHAM old' then say $( ( F - 4.5 ) / 3 ) 'Derham old'
if ?('DANIELL') if all | !=='DE VILLENEUVE' then say $( ( F *- 0 55.7407419994 ) / - 237.703727194 ) 'De Villeneuve' ) "Daniell"
if all | !==?('DE SUEDELA HIRE' ) then say $( F * 83/150 0.549057 + 3 - 17.6666 ) ' ) "De Suede'la Hire"
if all?('DE |LA !==VILLE'DU CREST' ) then say $( F * 0.650656985568 - 6.48011 - 37.9202 ) 'Du Crest') "De la Ville"
if all | !==?('EDINBURGHDELISLE') then say $( ( 212 - F + 6.40048 ) * 5/6 4.6546 ) 'Edinburgh' ) "Delisle"
if ?('DELISLE ifOLD') all | !=='ELECTRON VOLTS' then say $( ( 212 - eV F ) / 1.58590197 ) "Delisle 'electron volt's(eV)OLD"
if ?('DE LUC') if all | !=='FAHRENHEIT' then say $( F * 7/16 - 14 ) "De 'Fahrenheit'Luc"
if ?('DE LYON') if all | !=='FAHRENHEIT old' then say $( F * 2035/11 64 - 89 17.27275 ) 'Fahrenheit old' ) "De Lyon"
if ?('DE REVILLAS') if all | !=='FLORENTINE LARGE' then say $( ( 212 - F ) * 0.857143 80/97 - 7.42857 ) 'Florentine large') "De Revillas"
if ?('DERHAM') if all | !=='FLORENTINE MAGNUM' then say $( F * 10.5065938444386 + 72.4978 - 73.9736 ) 'Florentine) Magnum' "Derham"
if ?('DERHAM OLD') if all | !=='FLORENTINE SMALL' then say $( ( F *- 04.3785715 + 1.38571) / 3 ) 'Florentine small' ) "Derham OLD"
if all?('DE | !=='FOWLERVILLENEUVE') then say $( F then say $(* ( F0.740741 - 5323.77097037 ) / 0.640321 ) 'Fowler') "De Villeneuve"
if all?('DE | !=='FRICKSUEDE' ) then say $( ( F * 83/150 - 5817.53386666 ) * 251/200 ) ) 'Frick' "De Suede"
if all | !==?('GASDU MARKCREST') then say $( ( F -* 2500.650656 - 37.9202 ) * 0.04 ) "Du 'gas mark'Crest"
if all | !==?('GOUBERTEDINBURGH' ) then say $( ( F + 32 6.40048) / 4.6546 ) * 0.5 ) 'Goubert'"Edinburgh"
if ?('ELECTRON ifVOLTS') all | !=='HALES' then say $( eV then say $( ( F - 32 ) / 1.2 ) 'Hales') "electron volt"s(eV)
if all | !==?('HANOWFAHRENHEIT' ) then say $( ( F + 10.6672 ) / 1.06668 ) 'Hanow' ) "Fahrenheit"
if ?('FAHRENHEIT ifOLD') all | !=='HAUKSBEE' then say $( F then* say20/11 $( ( F - 8889.162727 ) * 25/18 ) "Fahrenheit 'Hauksbee'OLD"
if all?('FLORENTINE | !==LARGE'JACOBS-HOLBORN' ) then say $( ( F +* 0.857143 53 - 7.436642857 ) * 71/18 ) "Florentine 'Jacobs-Holborn'large"
if all?('FLORENTINE | !==MAGNUM'KELVIN' ) then say $( k F * 1.50659 - 73.9736 ) "Florentine 'kelvin's(k)Magnum"
if all?('FLORENTINE | !==SMALL'LEIDEN' ) then say $( F /* 0.378571 + 1.838571 + 235.222 ) "Florentine 'Leiden'small"
if all | !==?('NEWTONFOWLER') then say $( ( F - 3253.7709 ) / 0.640321 ) * 11/60 ) 'Newton'"Fowler"
if all | !==?('OERTELFRICK') then say $( ( F +- 3258.5338 ) * 251/200 ) * 0.5 ) 'Oertel'"Frick"
if all |?('GAS !=='PLANCKMARK' ) then say $( ( F +- 459.67250 ) ) * 5/90.04 / 1.416833e32) 'Planck' "gas mark"
if all | !==?('RANKINEGOUBERT') then say $( ( F + 459.67 32 ) * 0.5 ) 'Rankine' ) "Goubert"
if all | !==?('REAUMURHALES') then say $( ( F - 32 ) / * 1.2 4/9 ) 'Reaumur' ) "Hales"
if all | !==?('RICHTERHANOW') then say $( ( F + 710.452056672 ) / * 1.06668 73/160 ) 'Richter' ) "Hanow"
if all | !==?('RINALDINIHAUKSBEE') then say $( ( F - 3288.16 ) * )25/18 / 15 ) ) 'Rinaldini'"Hauksbee"
if all | !==?('ROMERJACOBS-HOLBORN' ) then say $( ( F -+ 3253.4366 ) * 71/18 ) * 7/24 + 7.5 ) 'Romer' ) "Jacobs-Holborn"
if ?('KELVIN') if all | !=='ROSENTHAL' then say $( ( F +k 453.581 ) * 86/45 ) 'Rosenthal' ) "kelvin"s(k)
if ?('LEIDEN') if all | !=='ROYAL SOCIETY' then say $( F * -69/50 1.8 + 122235.82222 ) 'Royal Society of London' ) "Leiden"
if all | !==?('SEGREDONEWTON') then say $( ( F +- 32 5.98 ) * 11/60 0.3798 ) 'Segredo' ) "Newton"
if ?('OERTEL') if all | !=='SAINT-PATRICE' then say $( ( F -+ 115.879 32 ) / ) * 20.621235 ) 'Saint-Patrice' ) "Oertel"
if all | !==?('STUFEPLANCK') then say $( ( F -+ 257459.67 ) * ) 5/9 / 45 1.416833e32 ) 'Stufe'"Planck"
if all | !==?('SULZERRANKINE') then say $( ( F -+ 33459.233467 ) / 1.14595 ) 'Sulzer' ) "Rankine"
if ?('REAUMUR') if all | !=='THERMOSTAT' then say $( ( F - 32 ) * 4/9 54 ) 'Thermostat' ) "Reaumur"
if all | !==?('WEDGWOODRICHTER') then say $( ( F -+ 516 7.245205) * 73/160 ) / 44.7429295 ) 'Wedgwood' ) "Richter"
if ?('RINALDINI') then say $( ( F - 32 ) / 15 ) "Rinaldini"
end /*until tlist ···*/
if ?('ROMER') then say $( ( F - 32 ) * 4/27 + 7.5 ) "Romer"
if ?('ROSENTHAL') then say $( ( F + 453.581 ) * 86/45 ) "Rosenthal"
if ?('ROYAL SOCIETY') then say $( F * -69/50 + 122.82 ) "Royal Society of London"
if ?('SAGREDO') then say $( ( F + 5.98 ) / 0.3798 ) "Segredo"
if ?('SAINT-PATRICE') then say $( ( F - 115.879 ) / 2.62123 ) "Saint-Patrice"
if ?('STUFE') then say $( ( F - 257 ) / 45 ) "Stufe"
if ?('SULZER') then say $( ( F - 33.2334 ) / 1.14595 ) "Sulzer"
if ?('THERMOSTAT') then say $( ( F - 32 ) / 54 ) "Thermostat"
if ?('WEDGWOOD') then say $( ( F - 516.2 ) / 44.7429295 ) "Wedgwood"
 
return
 
 
/*──────────────────────────────────────────────────────────────────────────────────────────────────*/
exit /*stick a fork in it, we're done.*/
scaleName: parse arg y /*abbreviations ──► temp. short name.*/
/*──────────────────────────────────$ subroutine────────────────────────*/
$:yU= translate(y, '-eE', "_éÉ") procedure; showDig=8 /*onlytranslate showsome 8accented significant digitscharacters. */
upper yU /*uppercase version of temperature unit*/
_=comma(format(arg(1), , showDig)/1) /*format# 8 digs past . and add ,*/
p=pos(.,_) /*find position of decimal point.*/
/* [↓] align integers with FP #s.*/
if p==0 then _=_ || left('',5+showDig+1) /*no decimal point.*/
else _=_ || left('',5+showDig-length(_)+p) /*has " " */
return right(_,60) /*return the re-formatted arg. */
/*──────────────────────────────────COMMA subroutine────────────────────*/
comma: procedure; parse arg _,c,p,t,s /*get number and optional options*/
arg ,cU . /*get an uppercase version of C.*/
c=word(c ',', 1) /*get the commatizing char(s).*/
if cU=='BLANK' then c=' ' /*special case for a "blank" sep.*/
o=word(p 3, 1) /*get the optional period length.*/
p=abs(o) /*get the positive period length.*/
t=word(t 999999999, 1) /*get max# of "commas" to insert.*/
s=word(s 1, 1) /*get optional start position. */
 
if left(yU, 7)=='DEGREES' then yU=substr(yU, 8) /*is this a redundant "degrees" ? */
if \datatype(p,'W') | \datatype(t,"W") | \datatype(s,'W') |,
if left(yU, 6)=='DEGREE' t<1 |then yU=substr(yU, s<17) /* |" p==0 " | " arg()>5 then return" _ /*invalid options "degree" ? */
 
nyU=_'.9'; strip(yU) #=123456789; k=0 /*defineelide someall handy-dandyleading vars.& trailing blanks. */
_= length(yU) /*obtain the length of the yU value. */
 
if right(yU,1)=='S' & _>1 then yU=left(yU, _-1) /*remove any trailing plural(s). */
if o<0 then do /*using a negative period length.*/
b=verify(_,' ', , s) /*position of 1st blank in string*/
e=length(_) - verify(reverse(_), ' ') + 1 - p
end
else do /*using a positive period length.*/
b=verify(n, #, "M", s) /*position of 1st useable digits.*/
z=max(1, verify(n, #"0.", 'M', s))
e=verify(n, #'0', , max(1, verify(n, #"0.", 'M', s))) - p - 1
end
 
if e>0 & b>0 then do j=e to b by -p while k<t /*commatize the digs*/
_=insert(c, _, j) /*comma spray ──� #.*/
k=k+1 /*bump commatizing. */
end /*j*/
return _
/*──────────────────────────────────SCALENAME subroutine────────────────*/
scaleName: parse arg y /*abbreviations ──► shortname. */
yU=translate(y,'-eE',"_éÉ") /*uppercase version of temp unit.*/
upper yU /*uppercase version of temp unit.*/
if left(yU,7)=='DEGREES' then yU=substr(yU,8) /*redundant "degrees"? */
if left(yU,6)=='DEGREE' then yU=substr(yU,7) /* " "degree" ? */
yU=strip(yU) /*elide blanks at ends.*/
_=length(yU) /*obtain the yU length.*/
if right(yU,1)=='S' & _>1 then yU=left(yU,_-1) /*elide trailing plural*/
 
select /*change abbreviations ──► shortname. */
when abbrev('AMONTONABSOLUTE' , yU, yU1) then sn='AMONTON' "ABSOLUTE"
when abbrev('AMONTON' , yU) then sn= "AMONTON"
when abbrev('BARNDORF' , yU,2) |,
abbrev('BARNSDORF' , yU,2) then sn=' "BARNSDORF'"
when abbrev('BEAUMIUR' , yU,3) |,
abbrev('BEAUMUIR' , yU,3) then sn=' "BEAUMUIR'"
when abbrev('BENERT' , yU,3) |,
abbrev('BENART' , yU,3) then sn=' "BENART'"
when abbrev('BRISSEN' , yU,3) |,
abbrev('BRISSON' , yU,3) then sn=' "BRISSEN'"
when abbrev('BURGEN' , yU,3) |,
abbrev('BURGAN' , yU,3) |,
abbrev('BERGAN' , yU,3) |,
abbrev('BERGEN' , yU,3) then sn=' "BERGEN'"
when abbrev('CENTIGRADE' , yU) |,
abbrev('CENTRIGRADE' , yU) |, /* 50% misspelled.*/
Line 230 ⟶ 287:
abbrev('CELISU' , yU) |, /* 1% misspelled.*/
abbrev('CELSU' , yU) |, /* 1% misspelled.*/
abbrev('CELSIUHECTOGRADE' , yU) |, then sn='CELSIUS'
abbrev('CELSIU' , yU) then sn= "CELSIUS"
when abbrev('CIMANTO' , yU,2) |,
abbrev('CIMENTO' , yU,2) then sn=' "CIMENTO'"
when abbrev('CRUQUIOU' , yU,2) |,
abbrev('CRUQUIO' , yU,2) |,
abbrev('CRUQUIU' , yU,2) then sn=' "CRUQUIU'"
when abbrev('DALANCE' , yU,4) |,
abbrev('DALENCE' , yU,4) then sn=' "DALENCE'"
when abbrev('DANELLE' , yU,3) |,
abbrev('DANEAL' , yU,3) |,
Line 245 ⟶ 303:
abbrev('DANYAL' , yU,3) |,
abbrev('DANYEL' , yU,3) |,
abbrev('DANIELL' , yU,3) then sn=' "DANIELL'"
when abbrev('DALTON' , yU,3) then sn=' "DALTON'"
when abbrev('DELAHIRE' , yU,7) |,
abbrev('LAHIRE' , yU,4) |,
abbrev('HIRE' , yU,2) |,
abbrev('DE-LA-HIRE' , yU,7) then sn=' "DE LA HIRE'"
when abbrev('DELAVILLE' , yU,7) |,
abbrev('LAVILLE' , yU,3) |,
abbrev('VILLE' , yU,1) |,
abbrev('VILLA' , yU,1) |,
abbrev('DE-LA-VILLE' , yU,7) then sn=' "DE LA VILLE'"
when abbrev('DELISLE' , yU,3) then sn=' "DELISLE'"
when abbrev('DELISLE-OLD' , yU,8) |,
abbrev('OLDDELISLE' , yU,6) |,
abbrev('DELISLEOLD' , yU,8) then sn=' "DELISLE old'OLD"
when abbrev('DELUC' , yU,4) |,
abbrev('LUC' , yU,2) |,
abbrev('DE-LUC' , yU,5) then sn=' "DE LUC'"
when abbrev('DELYON' , yU,4) |,
abbrev('LYON' , yU,2) |,
abbrev('DE-LYON' , yU,5) then sn=' "DE LYON'"
when abbrev('DEREVILLA' , yU,3) |,
abbrev('DEREVILA' , yU,3) |,
abbrev('REVILLA' , yU,3) |,
abbrev('DE-REVILLA' , yU,4) |,
abbrev('DE-REVILLA' , yU,5) then sn=' "DE REVILLAS'"
when abbrev('DEVILLENEUVE' , yU,3) |,
abbrev('DE-VILLENEUVE' , yU,4) then sn=' "DE VILLENEUVE'"
when abbrev('DURHAM' , yU,3) |,
abbrev('DERHAM' , yU,4) then sn=' "DERHAM'"
when abbrev('OLDDURHAM' , yU,5) |,
abbrev('OLDDERHAM' , yU,6) |,
abbrev('DERHAM-OLD' , yU,4) |,
abbrev('DERHAMOLD' , yU,4) then sn=' "DERHAM old'OLD"
when abbrev('DE-SUEDE' , yU,4) |,
abbrev('DESUEDE' , yU,4) then sn=' "DE SUEDE'"
when abbrev('DU-CREST' , yU,2) |,
abbrev('DUCREST' , yU,2) then sn=' "DU CREST'"
when abbrev('EDENBURGH' , yU,2) |,
abbrev('EDINBURGH' , yU,2) then sn=' "EDINBURGH'"
when abbrev('EVOLT' , yU,2) |,
abbrev('ELECTRONVOLT' , yU,2) then sn=' "ELECTRON VOLTS'"
when abbrev('FARENHEIT' , yU) |, /* 39% misspelled.*/
abbrev('FARENHEIGHT' , yU) |, /* 15% misspelled.*/
Line 302 ⟶ 360:
abbrev('FARINHEIT' , yU) |, /* 1% misspelled.*/
abbrev('FARANHITE' , yU) |, /* 1% misspelled.*/
abbrev('FAHRENHEIT' , yU) then sn=' "FAHRENHEIT'"
when abbrev('OLDFAHRENHEIT' , yU,4) |,
abbrev('FAHRENHEIT-OLD' , yU,13) |,
abbrev('FAHRENHEITOLD' , yU,13) then sn=' "FARHENHEIT old'OLD"
when abbrev('FLORENTINE-LARGE' , yU,12) |,
abbrev('LARGE-FLORENTINE' , yU,7) |,
abbrev('LARGEFLORENTINE' , yU,6) |,
abbrev('FLORENTINELARGE' , yU,12) then sn=' "FLORENTINE LARGE'"
when abbrev('FLORENTINE-MAGNUM' , yU,2) |,
abbrev('MAGNUM-FLORENTINE' , yU,3) |,
abbrev('MAGNUMFLORENTINE' , yU,3) |,
abbrev('FLORENTINEMAGNUM' , yU,2) then sn=' "FLORENTINE MAGNUM'"
when abbrev('FLORENTINE-SMALL' , yU,13) |,
abbrev('SMALL-FLORENTINE' , yU,7) |,
abbrev('SMALLFLORENTINE' , yU,6) |,
abbrev('FLORENTINESMALL' , yU,13) then sn=' "FLORENTINE SMALL'"
when abbrev('FOULER' , yU,2) |,
abbrev('FOWLOR' , yU,2) |,
abbrev('FOWLER' , yU,2) then sn=' "FOWLER'"
when abbrev('FRICK' , yU,2) then sn=' "FRICK'"
when abbrev('GAS-MARK' , yU,2) |,
abbrev('GASMARK' , yU,2) then sn=' "GAS MARK'"
when abbrev('GOUBERT' , yU,2) then sn=' "GOUBERT'"
when abbrev('HAIL' , yU,3) |,
abbrev('HALE' , yU,3) then sn=' "HALES'"
when abbrev('HANOW' , yU,3) then sn=' "HANOW'"
when abbrev('HUCKSBEE' , yU,3) |,
abbrev('HAWKSBEE' , yU,3) |,
abbrev('HAUKSBEE' , yU,3) then sn=' "HAUKSBEE'"
when abbrev('JACOBSHOLBORN' , yU,2) |,
abbrev('JACOBS-HOLBORN' , yU,2) then sn=' "JACOBS-HOLBORN'"
when abbrev('KALVIN' , yU) |, /* 27% misspelled.*/
abbrev('KERLIN' , yU) |, /* 18% misspelled.*/
abbrev('KEVEN' , yU) |, /* 9% misspelled.*/
abbrev('KELVIN' , yU) then sn=' "KELVIN'"
when abbrev('LAYDEN' , yU) |,
abbrev('LEIDEN' , yU) then sn=' "LEIDEN'"
when abbrev('NEUTON' , yU) |, /*100% misspelled.*/
abbrev('NEWTON' , yU) then sn=' "NEWTON'"
when abbrev('ORTEL' , yU) |,
abbrev('OERTEL' , yU) then sn=' "OERTEL'"
when abbrev('PLACK' , yU) |, /*100% misspelled.*/
abbrev('PLANC' , yU) |, /* misspelled.*/
abbrev('PLANK' , yU) |, /* misspelled.*/
abbrev('PLANCK' , yU) then sn=' "PLANCK'"
when abbrev('RANKINE' , yU, 1) then sn=' "RANKINE'"
when abbrev('REAUMUR' , yU, 2) then sn=' "REAUMUR'"
when abbrev('RICKTER' , yU, 3) |,
abbrev('RICHTER' , yU, 3) then sn=' "RICHTER'"
when abbrev('RINALDINI' , yU, 3) then sn=' "RINALDINI'"
when abbrev('ROEMER' , yU, 3) |,
abbrev('ROMER' , yU, 3) then sn=' "ROMER'"
when abbrev('ROSANTHAL' , yU, 3) |,
abbrev('ROSENTHAL' , yU, 3) then sn=' "ROSENTHAL'"
when abbrev('RSOL' , yU, 2) |,
abbrev('RSL' , yU, 2) |,
abbrev('ROYALSOCIETYOFLONDON' , yU, 3) |,
abbrev('ROYAL-SOCIETY-OF-LONDON' , yU, 3) then sn=' "ROYAL SOCIETY'"
when abbrev('SAGREDO' , yU, 3) then sn=' "SAGREDO'"
when abbrev('ST.-PATRICE' , yU, 3) |,
abbrev('ST.PATRICE' , yU, 3) |,
abbrev('SAINTPATRICE' , yU, 3) |,
abbrev('SAINT-PATRICE' , yU, 3) then sn=' "SAINT-PATRICE'"
when abbrev('STUFFE' , yU, 3) |,
abbrev('STUFE' , yU, 3) then sn=' "STUFE'"
when abbrev('SULTZER' , yU, 2) |,
abbrev('SULZER' , yU, 2) then sn=' "SULZER'"
when abbrev('WEDGEWOOD' , yU) |,
abbrev('WEDGWOOD' , yU) then sn=' "WEDGWOOD'"
 
otherwise call serr 'illegal temperature scale:' y
end /*select*/
 
 
return
 
/*──────────────────────────────────one─liner subroutines───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
 
e: e = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932; return e
/*──────────────────────────────────────────────────────────────────────────────────────*/
isInt: return datatype(arg(1), 'W') /*is it a whole number (integer) ? */
?: parse arg y 1 yu
exp: procedure; parse arg x; ix=x%1; if abs(x-ix)>.5 then ix=ix+sign(x); x=x-ix; z=1; _=1; w=z; do j=1; _=_*x/j; z=(z+_)/1; if z==w then leave;w=z;end;if z\==0 then z=z*e()**ix;return z/1
upper yu
ln: procedure; parse arg x; call e; ig=x>1.5; is=1-2*(ig\==1); ii=0; xx=x; return ln..()
if not\=='' then do
ln..: do while ig & xx>1.5 | \ig & xx<.5;_=e;do k=-1;iz=xx*_**-is;if k>=0 & (ig & iz<1 | \ig & iz>.5) then leave;_=_*_;izz=iz;end;xx=izz; ii=ii+is*2**k; end; x=x*e**-ii-1; z=0;_=-1;p=z;do k=1; _=-_*x; z=z+_/k; if z=p then leave;p=z; end; return z+ii
pow: procedure; parse arg x,y; if y=0 then return 1; if x=0 then return 0; if isInt(y) then return x**y; if isInt(1/y)noS\=="" then returnif rootleft(xyu,1/y,f noL);==noS then return pow_()0
pow_: if abs(y//1)noE\=.5='' then returnif sqrtright(xyu, noL)**sign(y)*x**(y%1);==noE then return exp(y*ln(x))0
end
root: procedure; parse arg x,y; if x=0 | y=1 then return x; if isInt(y) then return rooti(x,y); _=sqrt(x); if y<0 then _=1/_; return _
 
rooti: procedure; parse arg x,y; if x=0 | y=1 then return x; n=y<0; y=abs(y); numeric digits digits()+2; z=abs(x); g=(z+1)/y; m=y-1; numeric fuzz 2; do forever; _=(m*g**y+z)/y/g**m; if _=g then leave; g=_; end; _=g*sign(x); if n then _=1/_; return _
s: if arg(1)==1 thenif return arg(3);all | y==! then return word(arg(2) 's',1) /*pluralizer.*/
serr: say; say '***error!***'; say; say arg(1); say; exit 13 return 0
 
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); p=d; m.=9; numeric digits 9; g=sqrt.(); m.0=d; m.1=d; do j=2 while p>9; m.j=p; p=p%2+1; end; do k=j+5 to 0 by -1; numeric digits m.k; g=.5*(g+x/g); end; numeric digits d; return (g/1)i
 
sqrt.: i=; if x<0 then do; x=-x; i='i'; end; numeric form; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; return g*.5'E'_%2</lang>
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: procedure; parse arg _ /*insert commas in a number. */
n= _'.9' /*added suffix for VERIFY BIF.*/
#= 123456789 /*a nifty handy-dandy literal.*/
b= verify(n, #, "M") /*find beginning of a number. */
e= verify(n, #'0', , verify(n, #"0.", 'M') ) - 4 /* " end " " " */
 
do j=e to b by -3 /*insert commas right─to─left.*/
_= insert(",", _, j) /*insert a comma every period.*/
end /*j*/
 
return _
 
 
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x /*obtain the target of SQRT. */
if x=0 then return 0 /*Argument is zero? Return 0.*/
/*This function work for zero.*/
d= digits() /*get # of dec. digs, current.*/
m.= 9 /*set " " " " at start.*/
h= d+6 /*add 6 for rounding concerns.*/
numeric form /*right form of exponentiation*/
numeric digits /*start with nine numeric digs*/
 
/*a way of getting the expon. */
/*No exponent? Then add one. */
parse value format(x, 2, 1, , 0) 'E0' with g "E" _ .
/* [↓] halve the exponent. */
g=g * .5'e'_ % 2 /*a first best guess for sqrt,*/
/*which is 1/2 of the exponent*/
/* [↓] use min number of dec.*/
/* digs for early SQRTs. */
do j=0 while h>9
m.j= h /*calculate # of digits to use*/
h= h % 2 + 1 /*halving the exponent means */
end /*j*/ /* that it'll be doubled as */
/* the M. array will be */
/* processed backwards. [↓] */
do k=j+5 to 0 by -1 /*calculate higher precision. */
numeric digits m.k /*bump the decimal digits. */
g= (g + x / g) * .5 /*calculate SQRT approximation*/
end /*k*/
return g / 1 /*this normalizes the sqrt #. */
 
 
/*──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────*/
?: parse arg y; if not\=='' then do; if noS\=="" then if left(y, noL)==noS then return 0; if noE\=='' then if right(y, noL)==noE then return 0; end; if all | y==! then return 1; return 0
e: e = 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932; return e /*112 useful decimal digits. */
isInt: return datatype(arg(1), 'W') /*is the argument a whole number (integer)? */
exp: procedure; parse arg x; ix=x%1; if abs(x-ix)>.5 then ix=ix+sign(x); x=x-ix; z=1; _=1; w=z; do j=1; _=_*x/j; z=(z+_)/1; if z==w then leave; w=z; end; if z\==0 then z= z * e()**ix; return z/1
ln: procedure; parse arg x; call e; ig=x>1.5; is=1-2*(ig\==1); ii=0; xx=x; return ln..()
ln..: do while ig & xx>1.5 | \ig & xx<.5;_=e;do k=-1;iz=xx*_**-is;if k>=0 & (ig & iz<1 | \ig & iz>.5) then leave;_=_*_;izz=iz;end;xx=izz; ii=ii+is*2**k; end; x=x*e**-ii-1; z=0;_=-1;p=z;do k=1; _=-_*x;z=z+_/k; if z=p then leave;p=z; end; return z+ii
pow: procedure; parse arg x,y; if y=0 then return 1; if x=0 then return 0; if isInt(y) then return x**y; if isInt(1/y) then return root(x,1/y,f); return pow.()
pow.: if abs(y//1)=.5 then return sqrt(x)**sign(y)*x**(y%1); return exp(y*ln(x))
root: procedure; parse arg x 1 ox,y 1 oy; if x=0 | y=1 then return x; if isInt(y) then return rooti(x,y); _=sqrt(x); if y<0 then _=1/_; return _
rooti: x=abs(x); y=abs(y); a= digits() + 5; g=rootIg(); m= y-1; d=5; do until d==a; d=min(d+d, a); numeric digits d; o=0; do until o=g; o=g; g=format( (m*g**y+x) /y/g**m, , d-2); end; end; _= g * sign(ox); if oy<0 then _= 1/_; return _
rootIg: numeric form;parse value format(x,2,1,,0) 'E0' with ? 'E' _ .; return (? / y'E'_ % y) + (x>1)
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizer.*/
serr: say; say '***error***'; say; say arg(1); say; exit 13
</lang>