Temperature conversion: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added whitespace. -- ~~~~) |
m (→{{header|REXX}}: simplified uppercasing of some none-Latin characters, added whitespace. -- ~~~~) |
||
Line 257: | Line 257: | ||
x=space(x); parse var x z '(' /*handle any comments (if any). */ |
x=space(x); parse var x z '(' /*handle any comments (if any). */ |
||
if z=='' then call serr 'no arguments were specified.' |
if z=='' then call serr 'no arguments were specified.' |
||
_ |
_=verify(z, '+-.0123456789') /*a list of valid number thingys.*/ |
||
if _\==0 then do |
if _\==0 then do |
||
if _==1 then call serr 'illegal temperature:' # |
if _==1 then call serr 'illegal temperature:' # |
||
n= |
n=left(z,_-1) /*pick off the number (hopefully)*/ |
||
u= |
u=strip(substr(z,_)) /*pick off the temperature unit. */ |
||
end |
end |
||
else u= |
else u='k' /*assume Kelvin as per task req.*/ |
||
uU=u; upper uU |
uU=translate(u,'EE',"éÉ"); upper uU /*uppercase version of temp unit.*/ |
||
if left(uU,7)=='DEGREES' then uU=substr(uU,8) /*redundant "degrees"? */ |
if left(uU,7)=='DEGREES' then uU=substr(uU,8) /*redundant "degrees"? */ |
||
if left(uU,5)=='DEGREE' then uU=substr(uU,7) /* |
if left(uU,5)=='DEGREE' then uU=substr(uU,7) /* " "degree" ? */ |
||
uU=strip(uU) |
uU=strip(uU) |
||
if \datatype(n,'N') then call serr 'illegal number:' n |
if \datatype(n,'N') then call serr 'illegal number:' n |
||
/*accept alternate spellings. */ |
/*accept alternate spellings. */ |
||
select /*convert ──► ºF temperatures. */ |
select /*convert ──► ºF temperatures. */ |
||
when abbrev('CENTIGRADE', uU) |, |
when abbrev('CENTIGRADE', uU) |, |
||
abbrev('CENTESIMAL', uU) |, |
abbrev('CENTESIMAL', uU) |, |
||
abbrev('CELSIUS' , uU) |, |
abbrev('CELSIUS' , uU) |, |
||
abbrev('CELCIUS' , uU) then F=n * 9/5 + 32 |
abbrev('CELCIUS' , uU) then F=n * 9/5 + 32 |
||
when abbrev('DELISLE' , uU) then F=212 -(n * 6/5) |
when abbrev('DELISLE' , uU) then F=212 -(n * 6/5) |
||
Line 283: | Line 283: | ||
when abbrev('RANKINE' , uU) then F=n - 459.67 |
when abbrev('RANKINE' , uU) then F=n - 459.67 |
||
when abbrev('REAUMUR' , uU, 2) then F=n * 9/4 + 32 |
when abbrev('REAUMUR' , uU, 2) then F=n * 9/4 + 32 |
||
when abbrev('RéAUMUR' , uU, 2) |, |
|||
abbrev('RÉAUMUR' , uU, 2) |, |
|||
abbrev('REAUMUR' , uU, 2) then F=n * 9/4 + 32 |
|||
when abbrev('ROEMER' , uU, 2) |, |
when abbrev('ROEMER' , uU, 2) |, |
||
abbrev('ROMER' , uU, 2) then F=(n-7.5) * 27/4 + 32 |
abbrev('ROMER' , uU, 2) then F=(n-7.5) * 27/4 + 32 |
||
Line 291: | Line 288: | ||
end /*select*/ |
end /*select*/ |
||
say right(' ' x,55,"─") |
say right(' ' x,55,"─") |
||
say Tform((F - 32 |
say Tform( ( F - 32 ) * 5/9 ) 'Celcius' |
||
say Tform((212-F |
say Tform( ( 212 - F ) * 5/6 ) 'Delisle' |
||
say Tform( F ) 'Fahrenheit' |
say Tform( F ) 'Fahrenheit' |
||
say Tform((F + 459.67) * 5/9 ) 'Kelvin' |
say Tform( ( F + 459.67 ) * 5/9 ) 'Kelvin' |
||
say Tform((F - 32 ) * 11/60 ) 'Newton' |
say Tform( ( F - 32 ) * 11/60 ) 'Newton' |
||
say Tform( F + 459.67 ) 'Rankine' |
say Tform( F + 459.67 ) 'Rankine' |
||
say Tform((F - 32 ) * 4/9 ) 'Reaumur' |
say Tform( ( F - 32 ) * 4/9 ) 'Reaumur' |
||
say Tform((F - 32 ) * 7/24 + 7.5) 'Romer' |
say Tform( ( F - 32 ) * 7/24 + 7.5 ) 'Romer' |
||
end /*until tlist=''*/ |
end /*until tlist=''*/ |
||