Here's a little include I've coded in the last days, since I'm very interested in health. It implements all common functions on calculating size/weight relations, which are used for diets, sports, ... (BMI, Broca Index, ....)
Maybe someone can find it useful?
It's licensed under the Z-Lib-License (the most liberal license for the programmer, I think!)
Code: Select all
; HEALTH-LIB
; A PureBasic Library/Include with
; several health/body based
; functions and informations.
;
; Copyright (c) 2009 Peter Kastberger
;
; This software is provided 'as-is', without any express Or
; implied warranty. In no event will the authors be held
; liable For any damages arising from the use of this software.
;
; Permission is granted To anyone To use this software
; For any purpose, including commercial applications,
; And To alter it And redistribute it freely,
; subject To the following restrictions:
;
; 1. The origin of this software must Not be misrepresented;
; you must Not claim that you wrote the original software.
; If you use this software in a product, an acknowledgment
; in the product documentation would be appreciated but is Not required.
;
; 2. Altered source versions must be plainly marked As such,
; And must Not be misrepresented As being the original software.
;
; 3. This notice may Not be removed Or altered from any source distribution.
;
; ================================================================================
;
; GERMAN VERSION:
;
; Copyright (c) 2009 Peter Kastberger
;
; Diese Software wird ohne ausdrückliche oder implizierte Garantie
; bereitgestellt. In keinem Fall können die Autoren für
; irgendwelche Schäden, die durch die Benutzung dieser
; Software entstanden sind, haftbar gemacht werden.
;
; Es ist jedem gestattet, diese Software für jeden Zweck,
; inklusive kommerzieller Anwendungen, zu benutzen,
; zu verändern und sie frei weiterzuverbreiten,
; sofern folgende Bedingungen erfüllt sind:
;
; 1. Die Herkunft dieser Software darf nicht falsch dargestellt werden;
; Sie dürfen nicht angeben, dass Sie die ursprüngliche Software
; geschrieben haben. Wenn Sie diese Software in einem Produkt benutzten,
; würde eine Erwähnung geschätzt werden, sie ist aber nicht erforderlich.
;
; 2. Veränderte Quelltextversionen müssen deutlich als solche
; gekennzeichnet werden und dürfen nicht als die
; Originalsoftware dargestellt werden.
;
; 3. Diese Notiz darf in den Quelltexten nicht verändert
; oder gelöscht werden.
; ENUMS on GENDER ...
Enumeration
#HL_GENDER_MALE
#HL_GENDER_FEMALE
EndEnumeration
; ENUMS on BMI
Enumeration
#HL_BMI_HEAVY_UNDERWEIGHT
#HL_BMI_MID_UNDERWEIGHT
#HL_BMI_LIGHT_UNDERWEIGHT
#HL_BMI_NORMAL_WEIGHT
#HL_BMI_PRAE_ADIPOSITAS
#HL_BMI_ADIPOSITAS_1
#HL_BMI_ADIPOSITAS_2
#HL_BMI_ADIPOSITAS_3
EndEnumeration
; ENUMS on Ponderal
Enumeration
#HL_PONDERAL_LOW
#HL_PONDERAL_NORMAL
#HL_PONDERAL_HIGH
EndEnumeration
; ENUMS on WAIST-HIP-RATIO
Enumeration
#HL_WHR_NORMAL
#HL_WHR_OVERWEIGHT
#HL_WHR_ADIPOSITAS
EndEnumeration
; ENUMS on BROCA INDEX
Enumeration
#HL_BROCA_NORMALWEIGHT
#HL_BROCA_OVERWEIGHT
EndEnumeration
Procedure.f HL_GetBMI(weightKG.f, sizeM.f)
Protected BodyMassIndex.f
BodyMassIndex =(weightKG /(Pow(sizeM, 2)))
ProcedureReturn BodyMassIndex
EndProcedure
Procedure.i HL_RateBMI(bmi.f)
Protected BMI_Rate
If bmi < 16.0
BMI_Rate = #HL_BMI_HEAVY_UNDERWEIGHT
ElseIf bmi => 16.0 And bmi < 17.0
BMI_Rate = #HL_BMI_MID_UNDERWEIGHT
ElseIf bmi => 17.0 And bmi < 18.5
BMI_Rate = #HL_BMI_LIGHT_UNDERWEIGHT
ElseIf bmi => 18.5 And bmi < 25.0
BMI_Rate = #HL_BMI_NORMAL_WEIGHT
ElseIf bmi => 25.0 And bmi < 30.0
BMI_Rate = #HL_BMI_PRAE_ADIPOSITAS
ElseIf bmi => 30.0 And bmi < 35.0
BMI_Rate = #HL_BMI_ADIPOSITAS_1
ElseIf bmi => 35.0 And bmi < 40.0
BMI_Rate = #HL_BMI_ADIPOSITAS_2
ElseIf bmi => 40.0
BMI_Rate = #HL_BMI_ADIPOSITAS_3
EndIf
ProcedureReturn BMI_Rate
EndProcedure
Procedure.f HL_GetPonderal(weightKG.f, sizeM.f)
Protected PonderalIndex.f
PonderalIndex = (weightKG / (Pow(sizeM, 3)))
ProcedureReturn PonderalIndex
EndProcedure
Procedure.i HL_RatePonderal(ponderal.f)
Protected PonderalRate
If ponderal < 11
PonderalRate = #HL_PONDERAL_LOW
ElseIf ponderal => 11 And ponderal <= 14
PonderalRate = #HL_PONDERAL_NORMAL
ElseIf ponderal > 14
PonderalRate = #HL_PONDERAL_HIGH
EndIf
ProcedureReturn PonderalRate
EndProcedure
Procedure.f HL_GetWHR(waistCM.f, hipCM.f)
Protected WaistHipRatio.f
WaistHipRatio = waistCM / hipCM
ProcedureReturn WaistHipRatio
EndProcedure
Procedure.i HL_RateWHR(whratio.f, gender)
Protected WHRate
Select gender
Case #HL_GENDER_FEMALE
If (whratio < 0.8)
WHRate = #HL_WHR_NORMAL
ElseIf (whratio => 0.8 And whratio <= 0.84)
WHRate = #HL_WHR_OVERWEIGHT
ElseIf (whratio > 0.85)
WHRate = #HL_WHR_ADIPOSITAS
EndIf
Case #HL_GENDER_MALE
If (whratio < 0.9)
WHRate = #HL_WHR_NORMAL
ElseIf (whratio => 0.9 And whratio <= 0.99)
WHRate = #HL_WHR_OVERWEIGHT
ElseIf (whratio > 1.0)
WHRate = #HL_WHR_ADIPOSITAS
EndIf
EndSelect
ProcedureReturn WHRate
EndProcedure
Procedure.f HL_GetMostellerSurface(weightKG.f, sizeM.f)
Protected MostellerSurface.f
MostellerSurface = Sqr(sizeM * weightKG / 3600)
ProcedureReturn MostellerSurface
EndProcedure
Procedure.f HL_GetBrocaIndex(weightKG.f, sizeM.f, gender)
Protected BrocaIndex.f
Select gender
Case #HL_GENDER_MALE
BrocaIndex = (weightKG / ((sizeM) - 100))
Case #HL_GENDER_FEMALE
BrocaIndex = (weightKG / ((sizeM) - 100)) * 0.95
EndSelect
ProcedureReturn BrocaIndex
EndProcedure
Code: Select all
; ======================================================================
; TESTING the HEALTH-LIB (HL)
; ======================================================================
; ======================================================================
; TESTING BodyMassIndex related stuff:
; ======================================================================
mybmi.f = HL_GetBMI(80.0, 1.76)
mybmirate = HL_RateBMI(mybmi)
Debug "Bodymass Index: " + StrF(mybmi, 3)
Select mybmirate
;{
Case #HL_BMI_ADIPOSITAS_1
Debug "BMI Rate: Adipositas 1"
Case #HL_BMI_ADIPOSITAS_2
Debug "BMI Rate: Adipositas 2"
Case #HL_BMI_ADIPOSITAS_3
Debug "BMI Rate: Adipositas 3"
Case #HL_BMI_HEAVY_UNDERWEIGHT
Debug "BMI Rate: heavy underweight"
Case #HL_BMI_LIGHT_UNDERWEIGHT
Debug "BMI Rate: light underweight"
Case #HL_BMI_MID_UNDERWEIGHT
Debug "BMI Rate: mid underweight"
Case #HL_BMI_NORMAL_WEIGHT
Debug "BMI Rate: normal weight"
Case #HL_BMI_PRAE_ADIPOSITAS
Debug "BMI Rate: prae adipositas (little overweight)"
;}
EndSelect
; ======================================================================
; TESTING PonderalIndex related stuff:
; ======================================================================
myPonderal.f = HL_GetPonderal(80.0, 1.76)
Debug "Ponderal Index: " + StrF(myPonderal, 3)
myPonderalRate = HL_RatePonderal(myPonderal)
Select myPonderalRate
;{
Case #HL_PONDERAL_HIGH
Debug "Ponderal Rate: HIGH"
Case #HL_PONDERAL_NORMAL
Debug "Ponderal Rate: NORMAL"
Case #HL_PONDERAL_LOW
Debug "Ponderal Rate: LOW"
;}
EndSelect
; ======================================================================
; TESTING WaistToHipRatio related stuff:
; ======================================================================
myWHR.f = HL_GetWHR(90, 95)
Debug "Waist Hip Ratio: " + StrF(myWHR, 3)
myWHRRate = HL_RateWHR(myWHR, #HL_GENDER_MALE)
Select myWHRRate
;{
Case #HL_WHR_NORMAL
Debug "Waist Hip Ratio Rate: NORMAL"
Case #HL_WHR_OVERWEIGHT
Debug "Waist Hip Ratio Rate: OVERWEIGHT"
Case #HL_WHR_ADIPOSITAS
Debug "Waist Hip Ratio Rate: ADIPOSITAS!"
;}
EndSelect
; ======================================================================
; TESTING Mosteller Surface realted stuff:
; ======================================================================
myMosteller.f = HL_GetMostellerSurface(80.0, 176.0)
Debug "Surface in m²: " + StrF(myMosteller, 3)
; ======================================================================
; TESTING Broca Index realted stuff:
; ======================================================================
myBroca.f = HL_GetBrocaIndex(80.0, 176.0, #HL_GENDER_MALE)
Debug "Broca Index: " + StrF(myBroca, 2)