Anonymous user
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
* 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
/*──translation──*/
vershoks = 2249.2971 / 100▼
/*tip, top*/ vershok = 22.492971 /*1.75
/*palm, quarter*/ piad = vershok / 4
/*yard*/
/*fathom*/ sazhen = arshin / 3
/*turn (of a plow)*/ verst = sazhen / 500 /*≡versta. */
/*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
select /*convert the length ───► meters.*/▼
select
when abbrev('CENTIMETRES',whatU,2 )
abbrev('CENTIMETERS',whatU,2 ) |,
when abbrev('ARSHINS' ,whatU ) then m=N/arshin
when abbrev('DIUYM' ,whatU ) then m=N/diuym
when abbrev('FUT' ,whatU ) then m=N/fut
when abbrev('LINIYA' ,whatU ) then m=N/liniya
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
/*───────────────────────────────S subroutine───────────────────────────*/
s: if arg(1)=1 then return arg(3); return word(arg(2) 's',1) /*plural*/
/*───────────────────────────────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>
<pre style="overflow:scroll">
────────────────────────────────────metric─────────────────────────────────────
──────────────────────────────────old Russian──────────────────────────────────
▲ 0.09379071200 versts
0.062480475 milias
0.093720713 versts
46.860356 sazhens
140.58107 arshins
328.02249 futs
562.32428 piads
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 meter
──────────────────────────────────old Russian──────────────────────────────────
0.00062480476 milias
0.00093720713 versts
0.46860357 sazhens
1.4058107 arshins
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─────────────────────────────────────
-
-
──────────────────────────────────old Russian──────────────────────────────────
-0.062480488 milias
-0.093720732 versts
-46.860366 sazhens
-
-328.02256 futs
-562.32439 piads
-2249.2976 vershoks
-3936.2707 diuyms
-39362.707 liniyas
-393627.07 tochkas
</pre>
|