LRAFUNC7 ;SLC/MRH/FHS - FUNCTION CALL CONVERSION IN MEASUREMENT A5AFUNC7
;;5.2;LAB SERVICE;;Sep 27, 1994
N I,X
W !!,"Routine: "_$T(+0),! F I=8:1 S X=$T(LRAFUNC7+I) Q:'$L(X) I X[";;" W !,X
W !!
Q
;
CAP(X,Y,Z) ;; convert metric capacity to U.S. capacity and visa versa
;; Call by value
;; Mililiters to cubic inches or quarts or ounces
;; returns equivilent value with units
;; X must contain a positive numeric value
;; Y must contain the units of measure of X
;; Z must contain the units of measure to convert X to
;; eg. S X=$$CAP(12,"CF","ML") will return a value of X (12)
;; in mililiters
;; Valid units in either uppercase or lowercase are:
;; kl = kiloliter
;; hl = hectoliter
;; dal = dekaliter
;; l = liters
;; dl = deciliter
;; cl = centiliter
;; ml = mililiter
;;
;; cf = feet
;; ci = inch
;; gal = gallon
;; qt = quart
;; pt = pint
;; c = cup
;; oz = ounce
;
N CKY,CKZ
I '$G(X) Q 0
I X[".",$L(X)>19 Q 0_" ILLEGAL NUMBER"
I $L(X)>18 Q 0_" ILLEGAL NUMBER"
S Y=$$UPCASE(Y),Z=$$UPCASE(Z)
Q:'$L(Y)!('$L(Z)) 0
S CKY=U_Y_U
I "^KL^HL^DAL^L^DL^CL^ML^CF^CI^GAL^QT^PT^C^OZ^"'[CKY Q "ERROR"
S CKZ=U_Z_U
I "^KL^HL^DAL^L^DL^CL^ML^CF^CI^GAL^QT^PT^C^OZ^"'[CKZ Q "ERROR"
; quit with no conversion
I Y=Z Q X_" "_Z
;
; common metric unit = mililiter ML
I $P("^KL^1^HL^1^DAL^1^L^1^DL^1^CL^1^ML^1^",CKY,2) S X=X*+$P("^KL^1000000^HL^100000^DAL^10000^L^1000^DL^100^CL^10^ML^1",CKY,2)_"M"
; common U.S. unit = cubic inches CI
I $P("^CF^1^CI^1^GAL^1^QT^1^PT^1^C^1^OZ^1",CKY,2) S X=X*+$P("^CF^1728^CI^1^GAL^231^QT^57.75^PT^28.875^C^14.4375^OZ^1.805",CKY,2)_"U"
;
; X in U.S. (cubic inches) and will convert to metric
I X["U",$P("^KL^1^HL^1^DAL^1^L^1^DL^1^CL^1^ML^1^",CKZ,2) S X=X*+$P("^KL^.000016387^HL^.00016387^DAL^.0016387^L^.016387^DL^.16387^CL^1.6387^ML^16.387^",CKZ,2) Q $$FORMAT(X)_" "_Z
;
; X in metric (mililiter) and will convert to U.S.
I X["M",$P("^CF^1^CI^1^GAL^1^QT^1^PT^1^C^1^OZ^1",CKZ,2) S X=X*+$P("^CF^.00003531^CI^.0610^GAL^.0002642^QT^.0010568^PT^.0021136^C^.0042272^OZ^.033818^",CKZ,2) Q $$FORMAT(X)_" "_Z
;
; X in metric (mililiter) and will convert to metric
I X["M",$P("^KL^1^HL^1^DAL^1^L^1^CL^1^DL^1^ML^1",CKZ,2) S X=X*+$P("^KL^1000000^HL^100000^DAL^10000^L^1000^CL^100^CL^10^ML^1",CKZ,2) Q $$FORMAT(X)_" "_Z
;
; X in U.S. (cubic inches) and will convert to U.S.
I X["U",$P("^CF^1^CI^1^GAL^1^QT^1^PT^1^C^1^OZ^1",CKZ,2) S X=X*+$P("^CF^.0005787^CI^1^GAL^.004329^QT^.017316^PT^.034632^C^.069264^OZ^.554017",CKZ,2) Q $$FORMAT(X)_" "_Z
Q "ERROR"
;
FORMAT(X) ;
S X=$S(X>.9:$FN(X,"",3),1:$FN(X,"",4))
Q $S($P(X,".",2):X,1:$FN(X,"",0))
;
UPCASE(X) ;
Q $TR(X,"zxcvbnmlkjhgfdsaqwertyuiop","ZXCVBNMLKJHGFDSAQWERTYUIOP")
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HLRAFUNC7 3076 printed Nov 22, 2024@17:16:51 Page 2
LRAFUNC7 ;SLC/MRH/FHS - FUNCTION CALL CONVERSION IN MEASUREMENT A5AFUNC7
+1 ;;5.2;LAB SERVICE;;Sep 27, 1994
+2 NEW I,X
+3 WRITE !!,"Routine: "_$TEXT(+0),!
FOR I=8:1
SET X=$TEXT(LRAFUNC7+I)
if '$LENGTH(X)
QUIT
IF X[";;"
WRITE !,X
+4 WRITE !!
+5 QUIT
+6 ;
CAP(X,Y,Z) ;; convert metric capacity to U.S. capacity and visa versa
+1 ;; Call by value
+2 ;; Mililiters to cubic inches or quarts or ounces
+3 ;; returns equivilent value with units
+4 ;; X must contain a positive numeric value
+5 ;; Y must contain the units of measure of X
+6 ;; Z must contain the units of measure to convert X to
+7 ;; eg. S X=$$CAP(12,"CF","ML") will return a value of X (12)
+8 ;; in mililiters
+9 ;; Valid units in either uppercase or lowercase are:
+10 ;; kl = kiloliter
+11 ;; hl = hectoliter
+12 ;; dal = dekaliter
+13 ;; l = liters
+14 ;; dl = deciliter
+15 ;; cl = centiliter
+16 ;; ml = mililiter
+17 ;;
+18 ;; cf = feet
+19 ;; ci = inch
+20 ;; gal = gallon
+21 ;; qt = quart
+22 ;; pt = pint
+23 ;; c = cup
+24 ;; oz = ounce
+25 ;
+26 NEW CKY,CKZ
+27 IF '$GET(X)
QUIT 0
+28 IF X["."
IF $LENGTH(X)>19
QUIT 0_" ILLEGAL NUMBER"
+29 IF $LENGTH(X)>18
QUIT 0_" ILLEGAL NUMBER"
+30 SET Y=$$UPCASE(Y)
SET Z=$$UPCASE(Z)
+31 if '$LENGTH(Y)!('$LENGTH(Z))
QUIT 0
+32 SET CKY=U_Y_U
+33 IF "^KL^HL^DAL^L^DL^CL^ML^CF^CI^GAL^QT^PT^C^OZ^"'[CKY
QUIT "ERROR"
+34 SET CKZ=U_Z_U
+35 IF "^KL^HL^DAL^L^DL^CL^ML^CF^CI^GAL^QT^PT^C^OZ^"'[CKZ
QUIT "ERROR"
+36 ; quit with no conversion
+37 IF Y=Z
QUIT X_" "_Z
+38 ;
+39 ; common metric unit = mililiter ML
+40 IF $PIECE("^KL^1^HL^1^DAL^1^L^1^DL^1^CL^1^ML^1^",CKY,2)
SET X=X*+$PIECE("^KL^1000000^HL^100000^DAL^10000^L^1000^DL^100^CL^10^ML^1",CKY,2)_"M"
+41 ; common U.S. unit = cubic inches CI
+42 IF $PIECE("^CF^1^CI^1^GAL^1^QT^1^PT^1^C^1^OZ^1",CKY,2)
SET X=X*+$PIECE("^CF^1728^CI^1^GAL^231^QT^57.75^PT^28.875^C^14.4375^OZ^1.805",CKY,2)_"U"
+43 ;
+44 ; X in U.S. (cubic inches) and will convert to metric
+45 IF X["U"
IF $PIECE("^KL^1^HL^1^DAL^1^L^1^DL^1^CL^1^ML^1^",CKZ,2)
SET X=X*+$PIECE("^KL^.000016387^HL^.00016387^DAL^.0016387^L^.016387^DL^.16387^CL^1.6387^ML^16.387^",CKZ,2)
QUIT $$FORMAT(X)_" "_Z
+46 ;
+47 ; X in metric (mililiter) and will convert to U.S.
+48 IF X["M"
IF $PIECE("^CF^1^CI^1^GAL^1^QT^1^PT^1^C^1^OZ^1",CKZ,2)
SET X=X*+$PIECE("^CF^.00003531^CI^.0610^GAL^.0002642^QT^.0010568^PT^.0021136^C^.0042272^OZ^.033818^",CKZ,2)
QUIT $$FORMAT(X)_" "_Z
+49 ;
+50 ; X in metric (mililiter) and will convert to metric
+51 IF X["M"
IF $PIECE("^KL^1^HL^1^DAL^1^L^1^CL^1^DL^1^ML^1",CKZ,2)
SET X=X*+$PIECE("^KL^1000000^HL^100000^DAL^10000^L^1000^CL^100^CL^10^ML^1",CKZ,2)
QUIT $$FORMAT(X)_" "_Z
+52 ;
+53 ; X in U.S. (cubic inches) and will convert to U.S.
+54 IF X["U"
IF $PIECE("^CF^1^CI^1^GAL^1^QT^1^PT^1^C^1^OZ^1",CKZ,2)
SET X=X*+$PIECE("^CF^.0005787^CI^1^GAL^.004329^QT^.017316^PT^.034632^C^.069264^OZ^.554017",CKZ,2)
QUIT $$FORMAT(X)_" "_Z
+55 QUIT "ERROR"
+56 ;
FORMAT(X) ;
+1 SET X=$SELECT(X>.9:$FNUMBER(X,"",3),1:$FNUMBER(X,"",4))
+2 QUIT $SELECT($PIECE(X,".",2):X,1:$FNUMBER(X,"",0))
+3 ;
UPCASE(X) ;
+1 QUIT $TRANSLATE(X,"zxcvbnmlkjhgfdsaqwertyuiop","ZXCVBNMLKJHGFDSAQWERTYUIOP")