Old Russian measure of length: Difference between revisions
m (→{{header|REXX}}: changed method of capitalizing a variable. -- ~~~~) |
(→{{header|REXX}}: rewrote the REXX program. -- ~~~~) |
||
Line 23: | Line 23: | ||
* shows all ''other'' units of measurements when any unit is specified. |
* shows all ''other'' units of measurements when any unit is specified. |
||
* accepts abbreviations of the length units |
* accepts abbreviations of the length units |
||
* does rounding for |
* does rounding for so results are more meaningful and recognizable |
||
* does error checking on the user input |
* does error checking on the user input |
||
* added other old Russian units of measurements |
|||
* uses the correct length unit names when not plural |
* uses the correct length unit names when not plural |
||
* columnarized the output (instead of a horizontal stream). |
* columnarized the output (instead of a horizontal stream). |
||
<lang rexx>/*REXX program to read a config file and assign VARs as found within. */ |
<lang rexx>/*REXX program to read a config file and assign VARs as found within. */ |
||
numeric digits |
numeric digits 200 |
||
/*──translation──*/ |
|||
⚫ | |||
/*tip, top*/ vershok = 22.492971 /*1.75 inch.*/ |
|||
/*palm, quarter*/ piad = vershok / 4 /*≡chetvert.*/ |
|||
/*yard*/ arshin = vershok / 16 |
|||
/*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*/ |
parse arg N what _ . /*obtain the user's input from CL*/ |
||
if N =='' then call err 'no arguments specified.' |
if N =='' then call err 'no arguments specified.' |
||
if \datatype(N,'N') then call 'units not numeric: ' N |
if \datatype(N,'N') then call err 'units not numeric: ' N |
||
if _\=='' then call err 'too many arguments specified.' |
if _\=='' then call err 'too many arguments specified.' |
||
n=n/1 /*normalize it (004──►4 7.──►7)*/ |
n=n/1 /*normalize it (004──►4 7.──►7)*/ |
||
if what=='' then what='meters' /*None specified? Assume meters.*/ |
if what=='' then what='meters' /*None specified? Assume meters.*/ |
||
whatU=what; upper whatU |
whatU=what; upper whatU /*an uppercase version for ABBREV*/ |
||
⚫ | |||
select /*convert the length ───► meters.*/ |
|||
when abbrev('METRES' ,whatU ) |, |
|||
abbrev('METERS' ,whatU ) then m=N |
|||
when abbrev('KILOMETRES' ,whatU,2 ) |, |
|||
abbrev('KILOMETERS' ,whatU,2 ) |, |
|||
abbrev('KMS' ,whatU, ) then m=N*KM |
|||
when abbrev('CENTIMETRES',whatU,2 ) |, |
|||
abbrev('CENTIMETERS',whatU,2 ) |, |
|||
say n what ' is:' |
|||
abbrev('CMS' ,whatU,2 ) 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.*/ |
exit /*stick a fork in it, we're done.*/ |
||
/*───────────────────────────────ERR subroutine─────────────────────────*/ |
/*───────────────────────────────ERR subroutine─────────────────────────*/ |
||
err: say; say; say center(' error! ', max(40, linesize()%2), "*"); say |
err: say; say; say center(' error! ', max(40, linesize()%2), "*"); say |
||
do j=1 for arg(); say arg(j); say; end; say; exit 13 |
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 subroutine───────────────────────────*/ |
||
s: if arg(1)=1 then return arg(3); return word(arg(2) 's',1) /*plural*/ |
s: if arg(1)=1 then return arg(3); return word(arg(2) 's',1) /*plural*/ |
||
/*───────────────────────────────SAYM subroutine────────────────────────*/ |
|||
⚫ | |||
saym: parse arg _; numeric digits digits()%25; _=_/1 |
|||
say right(_,40) arg(2)s(_); return</lang> |
|||
⚫ | |||
<pre style="overflow:scroll"> |
<pre style="overflow:scroll"> |
||
────────────────────────────────────metric───────────────────────────────────── |
|||
100 meter is: |
|||
0.1 kilometers |
|||
100 meters |
|||
10000 centimeters |
|||
──────────────────────────────────old Russian────────────────────────────────── |
|||
⚫ | |||
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> |
</pre> |
||
'''output''' when using the input of: <tt> 1.4058107 arshins </tt> |
'''output''' when using the input of: <tt> 1.4058107 arshins </tt> |
||
<pre style="overflow:scroll"> |
<pre style="overflow:scroll"> |
||
────────────────────────────────────metric───────────────────────────────────── |
|||
1.4058107 arshins is: |
|||
⚫ | |||
1 meter |
1 meter |
||
100 centimeters |
|||
──────────────────────────────────old Russian────────────────────────────────── |
|||
0.00062480476 milias |
|||
0.00093720713 versts |
|||
0.46860357 sazhens |
|||
1.4058107 arshins |
1.4058107 arshins |
||
3.280225 futs |
|||
5.6232428 piads |
|||
22.492971 vershoks |
|||
39.3627 diuyms |
|||
393.627 liniyas |
|||
3936.27 tochkas |
|||
</pre> |
</pre> |
||
'''output''' when using the input of: <tt> -46.860366 sazhens </tt> |
'''output''' when using the input of: <tt> -46.860366 sazhens </tt> |
||
<pre style="overflow:scroll"> |
<pre style="overflow:scroll"> |
||
────────────────────────────────────metric───────────────────────────────────── |
|||
-46.860366 sazhens is: |
|||
-0.10000002 kilometers |
|||
- |
-100.00002 meters |
||
- |
-10000.002 centimeters |
||
──────────────────────────────────old Russian────────────────────────────────── |
|||
-0.062480488 milias |
|||
-0.093720732 versts |
|||
-46.860366 sazhens |
-46.860366 sazhens |
||
- |
-140.5811 arshins |
||
-328.02256 futs |
|||
-562.32439 piads |
|||
-2249.2976 vershoks |
|||
-3936.2707 diuyms |
|||
-39362.707 liniyas |
|||
-393627.07 tochkas |
|||
</pre> |
</pre> |
Revision as of 07:02, 12 February 2013
The program should make the conversion of the old Russian measures of length in the metric and vice versa.
Is an example of the transformation of several variables that are linearly. The program accepts a single value in the selected unit, and return it in the rest: vershoks, arshins, sazhens, versts, meters, centimeters and kilometers.
МК-61/52
<lang>П7 1 0 0 * П8 1 ВП 5 / П9 ИП7 1 0 6 7 / П0 5 0 0 * ПC 3 * ПA 1 6 * ПB С/П ПB 1 6 / ПA 3 / ПC 5 0 0 / П0 1 0 6 7 / БП 00</lang>
Instruction: l, meters = РX В/О С/П; l, vershoks = БП 3 1 С/П; l, arshins = РX БП 3 5 С/П; l, sazhens = РX БП 3 8 С/П; l, versts = РX БП 4 3 С/П; РX = РB = l, vershoks; РA = l, arshins; РB = l, versts; РC = l, sazhens; Р7 = l, meters; Р8 = l, centimeters; Р9 = l, kilometers.
Example: 100 m = 2249,2971 vershoks = 140,58107 arshins = 46,860366 sazhens = 0,093790712 versts; 3 vershoks = 13,3375 cm; 2 sazhens = 96 vershoks = 6 arshins = 4,268 m; 1 verst = 1,067 km.
REXX
Program features:
- shows all other units of measurements when any unit is specified.
- accepts abbreviations of the length units
- does rounding for so results are more meaningful 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 200 /*──translation──*/ /*tip, top*/ vershok = 22.492971 /*1.75 inch.*/ /*palm, quarter*/ piad = vershok / 4 /*≡chetvert.*/ /*yard*/ arshin = vershok / 16 /*fathom*/ sazhen = arshin / 3 /*turn (of a plow)*/ verst = sazhen / 500 /*≡versta. */ /*mile*/ milia = verst / 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.*/ when abbrev('METRES' ,whatU ) |, abbrev('METERS' ,whatU ) then m=N when abbrev('KILOMETRES' ,whatU,2 ) |, abbrev('KILOMETERS' ,whatU,2 ) |, abbrev('KMS' ,whatU, ) then m=N*KM when abbrev('CENTIMETRES',whatU,2 ) |, abbrev('CENTIMETERS',whatU,2 ) |, abbrev('CMS' ,whatU,2 ) then m=N/CM 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────────────────────────*/ saym: parse arg _; numeric digits digits()%25; _=_/1
say right(_,40) arg(2)s(_); return</lang>
output when using the input of: 100 metres
────────────────────────────────────metric───────────────────────────────────── 0.1 kilometers 100 meters 10000 centimeters ──────────────────────────────────old Russian────────────────────────────────── 0.062480475 milias 0.093720713 versts 46.860356 sazhens 140.58107 arshins 328.02249 futs 562.32428 piads 2249.2971 vershoks 3936.2699 diuyms 39362.699 liniyas 393626.99 tochkas
output when using the input of: 1.4058107 arshins
────────────────────────────────────metric───────────────────────────────────── 0.001 kilometers 1 meter 100 centimeters ──────────────────────────────────old Russian────────────────────────────────── 0.00062480476 milias 0.00093720713 versts 0.46860357 sazhens 1.4058107 arshins 3.280225 futs 5.6232428 piads 22.492971 vershoks 39.3627 diuyms 393.627 liniyas 3936.27 tochkas
output when using the input of: -46.860366 sazhens
────────────────────────────────────metric───────────────────────────────────── -0.10000002 kilometers -100.00002 meters -10000.002 centimeters ──────────────────────────────────old Russian────────────────────────────────── -0.062480488 milias -0.093720732 versts -46.860366 sazhens -140.5811 arshins -328.02256 futs -562.32439 piads -2249.2976 vershoks -3936.2707 diuyms -39362.707 liniyas -393627.07 tochkas