source: FOIAVistA/trunk/r/LAB_SERVICE-LR-LS/LRAFUNC6.m@ 632

Last change on this file since 632 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 2.3 KB
Line 
1LRAFUNC6 ;SLC/MRH/FHS - FUNCTION CALLS CONVERSION IN MEASUREMENT A5AFUNC6
2 ;;5.2;LAB SERVICE;;Sep 27, 1994
3 ;
4 N I,X
5 W !!,"Routine: "_$T(+0),! F I=8:1 S X=$T(LRAFUNC6+I) Q:'$L(X) I X[";;" W !,X
6 W !!
7 Q
8 ;
9LENGTH(X,Y,Z) ;; convert metric length to U.S. length and visa versa
10 ;; Call by value
11 ;; returns equivilent value with out units
12 ;; X must contain a positive numeric value
13 ;; Y must contain the units of measure of X
14 ;; Z must contain the units of measure to convert X to
15 ;; eg. S X=$$LENGTH(12,"IN","CM") will return a value of X (12)
16 ;; in centimeters
17 ;; Valid units are in either uppercase or lowercase are:
18 ;; km = kilometers
19 ;; m = meters
20 ;; cm = centimeters
21 ;; mm = millimeters
22 ;; mi = miles
23 ;; yd = yards
24 ;; ft = feet
25 ;; in = inches
26 N CKY,CKZ
27 I '$G(X) Q 0
28 I X[".",$L(X)>19 Q 0_" ILLEGAL NUMBER"
29 I $L(X)>18 Q 0_" ILLEGAL NUMBER"
30 S Y=$$UPCASE(Y),Z=$$UPCASE(Z)
31 Q:'$L(Y)!('$L(Z)) 0
32 S CKY=U_Y_U
33 I "^KM^M^CM^MM^MI^YD^FT^IN^"'[CKY Q "ERROR"
34 S CKZ=U_Z_U
35 I "^KM^M^CM^MM^MI^YD^FT^IN^"'[CKZ Q "ERROR"
36 ; quit with no conversion
37 I Y=Z Q X_" "_Z
38 ;
39 ; -***- common metric unit is centimeters CM -***-
40 I $P("^KM^1^M^1^CM^1^MM^1",CKY,2) S X=X*+$P("^KM^100000^M^100^CM^1^MM^.1",CKY,2)_"M"
41 ;
42 ; -***- common U.S. unit is inches IN -***-
43 I $P("^MI^1^YD^1^FT^1^IN^1",CKY,2) S X=X*$P("^MI^63360^YD^36^FT^12^IN^1",CKY,2)_"U"
44 ;
45 ; X in metric (cm) and will convert to metric
46 I X["M",$P("^KM^1^M^1^CM^1^MM^1",CKZ,2) S X=X*$P("^KM^.001^M^.01^CM^1^MM^10^",CKZ,2) Q $$FORMAT(X)_" "_Z
47 ;
48 ; X in U.S. and will convert to U.S.
49 I X["U",$P("^MI^1^YD^1^FT^1^IN^1",CKZ,2) S X=X*$P("^MI^.0000158^YD^.027778^FT^.083338^IN^1",CKZ,2) Q $$FORMAT(X)_" "_Z
50 ;
51 ; X in U.S. and will convert to metric
52 I X["U",$P("^KM^1^M^1^CM^1^MM^1",CKZ,2) S X=X*$P("^KM^.0000254^M^.0254^CM^2.540^MM^25.4",CKZ,2) Q $$FORMAT(X)_" "_Z
53 ;
54 ; X in metric (cm) and will convert to U.S.
55 I X["M",$P("^MI^1^YD^1^FT^1^IN^1",CKZ,2) S X=X*$P("^MI^.0000062^YD^.010936^FT^.032808^IN^.393696",CKZ,2) Q $$FORMAT(X)_" "_Z
56 ;
57 ;;
58FORMAT(X) ;
59 S X=$S(X>.9:$FN(X,"",3),1:$FN(X,"",4))
60 Q $S($P(X,".",2):X,1:$FN(X,"",0))
61 ;
62UPCASE(X) ;
63 Q $TR(X,"zxcvbnmlkjhgfdsaqwertyuiop","ZXCVBNMLKJHGFDSAQWERTYUIOP")
Note: See TracBrowser for help on using the repository browser.