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

XLFMSMT.m

Go to the documentation of this file.
  1. XLFMSMT ;SLC,SF/MH,RWF - Callable functions for conversions in measurement ;04/09/2002 09:02
  1. ;;8.0;KERNEL;**228**;Jul 10, 1995
  1. N I,VAL
  1. W !!,"Routine: "_$T(+0),! F I=8:1 S VAL=$T(+I) Q:'$L(VAL) I VAL[";;" W !,VAL
  1. W !!
  1. Q
  1. ;;
  1. WEIGHT(VAL,FROM,TO) ;;Convert weight between metric and U.S. weights
  1. ;; returns equivilent value with units
  1. ;; VAL must contain a positive numeric value
  1. ;; FROM must contain the units of measure of VAL
  1. ;; TO must contain the units of measure to convert VAL to
  1. ;; eg. W $$WEIGHT(12,"LB","G") ===> 5448 G
  1. ;; Valid units in either lowercase or uppercase are
  1. ;; t = metric tons tn = tons
  1. ;; kg = kilograms lb = pounds
  1. ;; g = grams oz = ounces
  1. ;; mg = milligram gr = grain
  1. N CKY,CKZ
  1. I '$G(VAL) Q 0
  1. I '$$VAL(VAL) Q 0_" ILLEGAL NUMBER"
  1. S FROM=$$UPCASE(FROM),CKY="^"_FROM_"^",TO=$$UPCASE(TO),CKZ="^"_TO_"^"
  1. Q:'$L(FROM)!('$L(TO)) 0
  1. I "^T^KG^G^MG^TN^LB^OZ^GR^"'[CKY Q "ERROR"
  1. I "^T^KG^G^MG^TN^LB^OZ^GR^"'[CKZ Q "ERROR"
  1. ; quit with no conversion
  1. G WT^XLFMSMT2
  1. LENGTH(VAL,FROM,TO) ;;Convert length between metric and U.S. length
  1. ;; returns equivilent value with units
  1. ;; VAL must contain a positive numeric value
  1. ;; FROM must contain the units of measure of VAL
  1. ;; TO must contain the units of measure to convert VAL to
  1. ;; eg. W $$LENGTH(12,"IN","CM") ===> 30.480 CM
  1. ;; Valid units are in either uppercase or lowercase are:
  1. ;; km = kilometers mi = miles
  1. ;; m = meters yd = yards
  1. ;; cm = centimeters ft = feet
  1. ;; mm = millimeters in = inches
  1. N CKY,CKZ
  1. I '$G(VAL) Q 0
  1. I '$$VAL(VAL) Q 0_" ILLEGAL NUMBER"
  1. S FROM=$$UPCASE(FROM),CKY="^"_FROM_"^",TO=$$UPCASE(TO),CKZ="^"_TO_"^"
  1. Q:'$L(FROM)!('$L(TO)) 0
  1. I "^KM^M^CM^MM^MI^YD^FT^IN^"'[CKY Q "ERROR"
  1. I "^KM^M^CM^MM^MI^YD^FT^IN^"'[CKZ Q "ERROR"
  1. ; quit with no conversion
  1. I FROM=TO Q VAL_" "_TO
  1. G LN^XLFMSMT2
  1. ;;
  1. VOLUME(VAL,FROM,TO) ;;Convert volume between metric and U.S. volume
  1. ;; Mililiters to cubic inches or quarts or ounces
  1. ;; returns equivilent value with units
  1. ;; VAL must contain a positive numeric value
  1. ;; FROM must contain the units of measure of VAL
  1. ;; TO must contain the units of measure to convert VAL to
  1. ;; eg. W $$VOLUME(12,"CF","ML") ===> 339800.832 ML
  1. ;; Valid units in either uppercase or lowercase are:
  1. ;; kl = kiloliter cf = feet
  1. ;; hl = hectoliter ci = inch
  1. ;; dal = dekaliter gal = gallon
  1. ;; l = liters qt = quart
  1. ;; dl = deciliter pt = pint
  1. ;; cl = centiliter c = cup
  1. ;; ml = mililiter oz = ounce
  1. ;
  1. N CKY,CKZ
  1. I '$G(VAL) Q 0
  1. I '$$VAL(VAL) Q 0_" ILLEGAL NUMBER"
  1. S FROM=$$UPCASE(FROM),CKY="^"_FROM_"^",TO=$$UPCASE(TO),CKZ="^"_TO_"^"
  1. Q:'$L(FROM)!('$L(TO)) 0
  1. I "^KL^HL^DAL^L^DL^CL^ML^CF^CI^GAL^QT^PT^C^OZ^"'[CKY Q "ERROR"
  1. I "^KL^HL^DAL^L^DL^CL^ML^CF^CI^GAL^QT^PT^C^OZ^"'[CKZ Q "ERROR"
  1. ; quit with no conversion
  1. I FROM=TO Q VAL_" "_TO
  1. G VOL^XLFMSMT2
  1. ;;
  1. BSA(%HT,%WT) ;;Return Body Surface Area using Dubois formula
  1. ;; Dubois formula BSA=.007184*(ht**.725)*(wt**.425)
  1. ;; %HT is height in centimeters
  1. ;; %WT is weight in Kilograms
  1. ;; eg. $$BSA(175,86)=2.02
  1. ;; or $$BSA(100,43)=1.00
  1. I '$$VAL(%HT) Q 0_"ILLEGAL NUMBER"
  1. I '$$VAL(%WT) Q 0_" ILLEGAL NUMBER"
  1. ;Q $FN(($$PWR^XLFMTH(%HT,.425)*$$PWR^XLFMTH(%WT,.725)*71.84)/10000,"",2)
  1. Q $FN(((%HT**.725)*(%WT**.425)*71.84)/10000,"",2)
  1. ;
  1. TEMP(VAL,FROM,TO) ;;Convert metric temperature to U.S. temperature
  1. ;; F = fahrenheit C = celsius
  1. N CKY,CKZ
  1. I '$D(VAL) Q 0
  1. I '$$VAL(VAL) Q 0_" ILLEGAL NUMBER"
  1. S FROM=$$UPCASE(FROM),CKY="^"_FROM_"^",TO=$$UPCASE(TO),CKZ="^"_TO_"^"
  1. Q:'$L(FROM)!('$L(TO)) 0
  1. I "^F^C^"'[CKY Q "ERROR"
  1. I "^F^C^"'[CKZ Q "ERROR"
  1. I FROM=TO Q VAL_" "_TO
  1. I TO="C" Q $$FORMAT^XLFMSMT2((VAL-32)/1.8)_" "_TO
  1. I TO="F" Q $$FORMAT^XLFMSMT2(1.8*VAL+32)_" "_TO
  1. Q "ERROR"
  1. VAL(X) ;
  1. I X[".",$L(X)>19 Q 0
  1. I $L(X)>18 Q 0
  1. Q 1
  1. UPCASE(X) ;
  1. Q $TR(X,"zxcvbnmlkjhgfdsaqwertyuiop","ZXCVBNMLKJHGFDSAQWERTYUIOP")
  1. ;