;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udftemperatureconvert",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udftemperatureconvert
#DefineFunction udfTemperatureConvert (fDegrees, sDimFrom, sDimTo)
sDimList = "c/f/k/r"
sDimFrom = StrLower(sDimFrom)
iFrom = ItemLocate(sDimFrom,sDimList,"/")
Terminate(iFrom==0,'udfTemperatureConvert',StrCat('Allowed dimensions = ',sDimList,@LF,'Failure at: DimFrom="',sDimFrom,'"'))
sDimTo = StrLower(sDimTo)
iTo = ItemLocate(sDimTo,sDimList,"/")
Terminate(iTo==0,'udfTemperatureConvert',StrCat('Allowed dimensions = ',sDimList,@LF,'Failure at: DimTo="',sDimTo,'"'))
Goto %sDimFrom%_%sDimTo%
:c_f
Return ((1.80*fDegrees)+32.0)
:c_k
Return (fDegrees+273.15)
:c_r
Return (1.80*(fDegrees+273.15))
:f_c
Return ((fDegrees-32.0)*(5.0/9.0))
:f_k
Return (((fDegrees-32.0)*(5.0/9.0))+273.15)
:f_r
Return (fDegrees+459.67)
:k_c
Return (fDegrees-273.15)
:k_f
Return (((9.0/5.0)*(fDegrees-273.15))+32)
:k_r
Return ((9.0/5.0)*fDegrees)
:r_c
Return (((5.0/9.0)*fDegrees)-273.15)
:r_f
Return (fDegrees-459.67)
:r_k
Return ((5.0/9.0)*fDegrees)
:c_c
:f_f
:k_k
:r_r
Return (fDegrees)
;..........................................................................................................................................
; fDegrees = any numeric value, makes no allowance for absolute zero
; sDimFrom and sDimTo are keywords from sDimList="c/f/k/r", e.g."c" or "r"
; with C = Celsius, K = Kelvin, F = Fahrenheit, R = Rankine.
;
; Adapted from database Wilson WinWare Tech BBS
; Published by Craig Storey."2001:03:23:17:14:00" cstorey@canada.com
; Modified by Detlev Dalitz."2001:03:24:14:45:00" dd@dalitz-im-netz.de
; Modified by Detlev Dalitz."2002:02:03:19:29:00" dd@dalitz-im-netz.de
;..........................................................................................................................................
; Temperature Conversion References
; CRC Handbook: www.hbcpnetbase.com/
; NRC Measurement Standards: www.thermometry.inms.nrc.ca/thermometry/ITS-90.htm
;
; Celsius=(Fahrenheit-32)*(5/9), Defined by Water bp=100C, fp=0C
; Fahrenheit=(9/5)*Celsius +32, Defined by Water bp=212F, fp=32F
; Kelvin=Celsius+273.15 Define Zero entropy at 0K (-273.15C), tp=273.16K, 1K=1C
; Rankine=Fahrenheit+459.67 Define Zero entropy at 0R, 1R=1F
;
; Fahrenheit Celsius Kelvin Rankine
; Absolute Zero -459.67 -273.15 0 0
; Liquid Helium (boiling) -452.1 -268.9 4.2 7.6
; Liquid nitrogen (boiling -321.07 -196.0 77.2 138.6
; Water (freezing) 32 0 273.15 491.67
; Water (boiling) 212 100 373.15 671.67
;..........................................................................................................................................
#EndFunction
:skip_udftemperatureconvert
;------------------------------------------------------------------------------------------------------------------------------------------
; --- test ---
iLastDecimals = Decimals(2)
sStringOut = ""
sDimList = "C/F/K/R"
sDegreeList = "0.00/32.00/77.20/671.67"
For i=1 To 4
For k=1 To 4
sDimFrom = ItemExtract(i,sDimList,"/")
sDimTo = ItemExtract(k,sDimList,"/")
sDegree = ItemExtract(i,sDegreeList,"/")
fResult = udfTemperatureConvert(sDegree,sDimFrom,sDimTo)
sStringOut = StrCat(sStringOut,sDegree,@TAB,sDimFrom,@TAB,"= ",fResult,@TAB,sDimTo,@LF)
Next
sStringOut = StrCat(sStringOut,@LF)
Next
IntControl (63,300,100,650,700) ; Screen coordinates for AskItemList.
AskItemlist("Temperature Conversion",sStringOut,@LF,@UNSORTED,@SINGLE)
:CANCEL
Decimals(iLastDecimals)
Exit
;------------------------------------------------------------------------------------------------------------------------------------------
*EOF*
|