Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: LRAFUNC5

LRAFUNC5.m

Go to the documentation of this file.
  1. LRAFUNC5 ; IHS/DIR/FJE - FUNCTION CALLS CONVERSION IN MEASURMENTS A5AFUNC5 ;
  1. ;;5.2;LR;**1013**;JUL 15, 2002
  1. ;
  1. ;;5.2;LAB SERVICE;;Sep 27, 1994
  1. ;
  1. N I,X
  1. W !!,"Routine: "_$T(+0),! F I=8:1 S X=$T(LRAFUNC5+I) Q:'$L(X) I X[";;" W !,X
  1. W !!
  1. Q
  1. ;;
  1. WEIGHT(X,Y,Z) ;; convert metric mass to approx. U.S. weights and visa versa
  1. ;; Call by value
  1. ;; returns equivilent value with out units
  1. ;; X must contain a positive numeric value
  1. ;; Y must contain the units of measure of X
  1. ;; Z must contain the units of measure to convert X to
  1. ;; eg. S X=$$WEIGHT(12,"LB","GM") will return a value of X (12)
  1. ;; pounds in grams
  1. ;; Valid units in either lowercase or uppercase
  1. ;; are t = metric tons
  1. ;; kg = kilograms
  1. ;; g = grams
  1. ;; mg = milligram
  1. ;; tn = tons
  1. ;; lb = pounds
  1. ;; oz = ounces
  1. ;; gr = grain
  1. N CKY,CKZ
  1. I '$G(X) Q 0
  1. I X[".",$L(X)>19 Q 0_" ILLEGAL NUMBER"
  1. I $L(X)>18 Q 0_" ILLEGAL NUMBER"
  1. S Y=$$UPCASE(Y),Z=$$UPCASE(Z)
  1. Q:'$L(Y)!('$L(Z)) 0
  1. S CKY=U_Y_U
  1. I "^T^KG^G^MG^TN^LB^OZ^GR^"'[CKY Q "ERROR"
  1. S CKZ=U_Z_U
  1. I "^T^KG^G^MG^TN^LB^OZ^GR^"'[CKZ Q "ERROR"
  1. ; quit with no conversion
  1. I Y=Z Q X_" "_Z
  1. ; common metric unit is kilograms KG
  1. I $P("^T^1^KG^1^G^1^MG^1",CKY,2) S X=X*$P("^T^1000^KG^1^G^.001^MG^.000001",CKY,2) S X=X_"M"
  1. ; common english unit is pound LB
  1. I $P("^TN^1^LB^1^OZ^1^GR^1",CKY,2) S X=X*$P("^TN^2000^LB^1^OZ^.0625^GR^.0001302083",CKY,2) S X=X_"U"
  1. ; the result of the above 2 IF statments will result in X being
  1. ; converted to kilograms or pounds depending on the value of Y
  1. ;
  1. ; X in metric and will convert to metric X in KG
  1. I X["M",$P("^T^1^KG^1^G^1^MG^1",CKZ,2) S X=X*$P("^T^.00001^KG^1^G^1000^MG^10000",CKZ,2) Q $$FORMAT(X)_" "_Z
  1. ;
  1. ; X in U.S. and will convert to U.S. X in LB
  1. I X["U",$P("^TN^1^LB^1^OZ^1^GR^1",CKZ,2) S X=X*$P("^TN^.0005^LB^1^OZ^16^GR^7680",CKZ,2) Q $$FORMAT(X)_" "_Z
  1. ;
  1. ; X in U.S. and will convert to metric X in LB
  1. I X["U",$P("^T^1^KG^1^G^1^MG^1",CKZ,2) S X=X*$P("^T^.000454^KG^.454^G^454^MG^454000",CKZ,2) Q $$FORMAT(X)_" "_Z
  1. ;
  1. ; X in metric and will convert to U.S. X in KG
  1. I X["M",$P("^TN^1^LB^1^OZ^1^GR^1",CKZ,2) S X=X*$P("^TN^.00062^LB^2.2046^OZ^35.2736^GR^154300",CKZ,2) Q $$FORMAT(X)_" "_Z
  1. ;
  1. ;;
  1. FORMAT(X) ;
  1. S X=$S(X>.9:$FN(X,"",3),1:$FN(X,"",4))
  1. Q $S($P(X,".",2):X,1:$FN(X,"",0))
  1. ;
  1. UPCASE(X) ;
  1. Q $TR(X,"zxcvbnmlkjhgfdsaqwertyuiop","ZXCVBNMLKJHGFDSAQWERTYUIOP")