Source: https://meteosat.pessac.free.fr/Cd_elect/Doc_pdf/LangageC/algo.pdf