Old Russian measure of length: Difference between revisions

→‎{{header|REXX}}: rewrote the REXX program. -- ~~~~
m (→‎{{header|REXX}}: changed method of capitalizing a variable. -- ~~~~)
(→‎{{header|REXX}}: rewrote the REXX program. -- ~~~~)
Line 23:
* shows all ''other'' units of measurements when any unit is specified.
* accepts abbreviations of the length units
* does rounding for theso tworesults arithmeticare operationsmore performedmeaningful and recognizable
* does error checking on the user input
* added other old Russian units of measurements
* uses the correct length unit names when not plural
* columnarized the output   (instead of a horizontal stream).
<lang rexx>/*REXX program to read a config file and assign VARs as found within. */
numeric digits 25200
/*──translation──*/
vershoks = 2249.2971 / 100
/*tip, top*/ vershok = 22.492971 /*1.75 arshins = 140inch.58107 */ 100
/*palm, quarter*/ piad = vershok / 4 sazhens = 46/*≡chetvert.860366 */ 100
/*yard*/ verstsarshin = vershok 0.093790712 / 10016
/*fathom*/ sazhen = arshin / 3
/*turn (of a plow)*/ verst = sazhen / 500 /*≡versta. */
/*mile*/ milia = 0.09379071200verst versts / 1.5
/*inch*/ diuym = arshin * 28
/*foot*/ fut = diuym / 12
/*line*/ liniya = diuym * 10
/*point*/ tochka = diuym * 100
 
KM=1000; CM=100 /*define a couple of multipliers.*/
parse arg N what _ . /*obtain the user's input from CL*/
if N =='' then call err 'no arguments specified.'
if \datatype(N,'N') then call err 'units not numeric: ' N
if _\=='' then call err 'too many arguments specified.'
n=n/1 /*normalize it (004──►4 7.──►7)*/
if what=='' then what='meters' /*None specified? Assume meters.*/
whatU=what; upper whatU /*an uppercase version for ABBREV*/
 
select /*convert the length ───► meters.*/
select when abbrev('METERS' ,whatU ) then m=N /*convert the length ───► meters.*/
when abbrev('VERSHOKSMETRES' ,whatU,2) then m=N/vershoks) |,
when abbrev('ARSHINSMETERS' ,whatU ) then m=N/arshins
when abbrev('SAZHENSKILOMETRES' ,whatU ,2 ) then m=N/sazhens|,
when abbrev('VERSTSKILOMETERS' ,whatU,2 ) then m=N/versts|,
otherwiseabbrev('KMS' call err 'invalid measure name: ',whatU, ) then whatm=N*KM
when abbrev('CENTIMETRES',whatU,2 ) end /*select*/|,
abbrev('CENTIMETERS',whatU,2 ) |,
say n what ' is:'
; if abbrev('CMS' m\=N then say right(m,40whatU,2 ) 'meter's( then m)=N/CM
when abbrev('ARSHINS' ,whatU ) then m=N/arshin
x = m * vershoks ; if rounder(x)\=N then say right(x,40) 'vershok's(x)
when abbrev('DIUYM' ,whatU ) then m=N/diuym
x = m * arshins ; if rounder(x)\=N then say right(x,40) 'arshin's(x)
when abbrev('FUT' ,whatU ) then m=N/fut
x = m * sazhens ; if rounder(x)\=N then say right(x,40) 'sazhen's(x)
when abbrev('LINIYA' ,whatU ) then m=N/liniya
x = m * versts ; if rounder(x)\=N then say right(x,40) 'verst's(x)
when abbrev('PIADS' ,whatU ) |,
abbrev('CHETVERTS' ,whatU,2 ) then m=N/piad
when abbrev('SAZHENS' ,whatU ) then m=N/sazhen
when abbrev('TOCHKA' ,whatU ) then m=N/tochka
when abbrev('VERSHOKS' ,whatU,5 ) then m=N/vershok
when abbrev('VERSTAS' ,whatU,5 ) |,
abbrev('VERSTS' ,whatU,2 ) then m=N/verst
when abbrev('MILIA' ,whatU,2 ) then m=N/milia
otherwise call err 'invalid measure name: ' what
end /*select*/
say centre('metric',79,"─")
call saym m/KM , 'kilometer'
call saym m , 'meter'
call saym m*CM , 'centimeter'
say centre('old Russian',79,"─")
call saym m*milia , 'milia'
call saym m*verst , 'verst'
call saym m*sazhen , 'sazhen'
call saym m*arshin , 'arshin'
call saym m*fut , 'fut'
call saym m*piad , 'piad'
call saym m*vershok , 'vershok'
call saym m*diuym , 'diuym'
call saym m*liniya , 'liniya'
call saym m*tochka , 'tochka'
exit /*stick a fork in it, we're done.*/
/*───────────────────────────────ERR subroutine─────────────────────────*/
err: say; say; say center(' error! ', max(40, linesize()%2), "*"); say
do j=1 for arg(); say arg(j); say; end; say; exit 13
/*───────────────────────────────ROUNDER subroutine─────────────────────*/
rounder: procedure; parse arg x; _=pos('.',x); if _==0 then return x
parse arg '.' f; return format(x,,length(f)-2) /*handle rounding.*/
/*───────────────────────────────S subroutine───────────────────────────*/
s: if arg(1)=1 then return arg(3); return word(arg(2) 's',1) /*plural*/</lang>
/*───────────────────────────────SAYM subroutine────────────────────────*/
'''output''' when using the input of: <tt> 100 meter </tt>
saym: parse arg _; numeric digits digits()%25; _=_/1
say right(_,40) arg(2)s(_); return</lang>
'''output''' when using the input of: <tt> 100 metermetres </tt>
<pre style="overflow:scroll">
────────────────────────────────────metric─────────────────────────────────────
100 meter is:
2249 0.2971001 vershokskilometers
140.5810700 arshins 100 meters
46.86036600 sazhens 10000 centimeters
──────────────────────────────────old Russian──────────────────────────────────
0.09379071200 versts
0.062480475 milias
0.093720713 versts
46.860356 sazhens
140.58107 arshins
328.02249 futs
562.32428 piads
vershoks = 2249.2971 / 100vershoks
3936.2699 diuyms
39362.699 liniyas
393626.99 tochkas
</pre>
'''output''' when using the input of: <tt> 1.4058107 arshins </tt>
<pre style="overflow:scroll">
────────────────────────────────────metric─────────────────────────────────────
1.4058107 arshins is:
select /*convert the length0.001 ───► meters.*/kilometers
1 meter
22.492971 vershoks 100 centimeters
──────────────────────────────────old Russian──────────────────────────────────
0.00062480476 milias
0.00093720713 versts
0.46860357 sazhens
1.4058107 arshins
0 3.46860366280225 sazhensfuts
0 5.000937907126232428 verstspiads
22.492971 vershoks
39.3627 diuyms
393.627 liniyas
3936.27 tochkas
</pre>
'''output''' when using the input of: <tt> -46.860366 sazhens </tt>
<pre style="overflow:scroll">
────────────────────────────────────metric─────────────────────────────────────
-46.860366 sazhens is:
-1000.10000002 meterskilometers
-2249100.297100002 vershoksmeters
-14010000.58107002 arshinscentimeters
──────────────────────────────────old Russian──────────────────────────────────
-0.062480488 milias
-0.093720732 versts
-46.860366 sazhens
-0140.0937907125811 verstsarshins
-328.02256 futs
-562.32439 piads
-2249.2976 vershoks
-3936.2707 diuyms
-39362.707 liniyas
-393627.07 tochkas
</pre>