First cut, Porting to calc_deco_celining() to PHP:
PHP Code:
<?php
/* =============================================================================== */
/* SUBROUTINE CALC_DECO_CEILING */
/* Purpose: This subprogram calculates the deco ceiling (the safe ascent */
/* depth) in each compartment, based on the allowable gradients, and then */
/* finds the deepest deco ceiling across all compartments. This deepest */
/* value (Deco Ceiling Depth) is then used by the Decompression Stop */
/* subroutine to determine the actual deco schedule. */
/* =============================================================================== */
/* INITIAL PORT TO PHP VERSION 0.11 */
/* https://www.unix.com/whats-your-mind/185211-port-vpm-decompression-algorithm-php-then-dive-computer.html */
/* =============================================================================== */
function calc_deco_ceiling($deco_ceiling_depth, $helium_pressure,$nitrogen_pressure,$allowable_gradient_he, $allowable_gradient_n2,$dive)
{
/* loop */
/* =============================================================================== */
/* CALCULATIONS */
/* Since there are two sets of allowable gradients being tracked, one for */
/* helium and one for nitrogen, a "weighted allowable gradient" must be */
/* computed each time based on the proportions of helium and nitrogen in */
/* each compartment. This proportioning follows the methodology of */
/* Buhlmann/Keller. If there is no helium and nitrogen in the compartment, */
/* such as after extended periods of oxygen breathing, then the minimum value */
/* across both gases will be used. It is important to note that if a */
/* compartment is empty of helium and nitrogen, then the weighted allowable */
/* gradient formula cannot be used since it will result in division by zero. */
/* =============================================================================== */
for ($i = 1; $i <= 16; ++$i) {
$gas_loading =
$helium_pressure[$i - 1] + $nitrogen_pressure[$i - 1];
if ($gas_loading > 0) {
$weighted_allowable_gradient =
($allowable_gradient_he[$i - 1] * $helium_pressure[$i - 1] +
$allowable_gradient_n2[$i - 1] * $nitrogen_pressure[$i - 1]) /
($helium_pressure[$i - 1] + $nitrogen_pressure[$i - 1]);
$tolerated_ambient_pressure =
$gas_loading +
$dive['constant_pressure_other_gases'] -
$weighted_allowable_gradient;
} else {
/* Computing MIN */
$r1 = $allowable_gradient_he[$i - 1];
$r2 = $allowable_gradient_n2[$i - 1];
$weighted_allowable_gradient = min($r1,$r2);
$tolerated_ambient_pressure =
$dive['constant_pressure_other_gases'] - $weighted_allowable_gradient;
}
/* =============================================================================== */
/* The tolerated ambient pressure cannot be less than zero absolute, i.e., */
/* the vacuum of outer space! */
/* =============================================================================== */
if ($tolerated_ambient_pressure < 0) {
$tolerated_ambient_pressure = 0.0;
}
$compartment_deco_ceiling[$i - 1] =
$tolerated_ambient_pressure - $dive['barometric_pressure'];
}
/* =============================================================================== */
/* The Deco Ceiling Depth is computed in a loop after all of the individual */
/* compartment deco ceilings have been calculated. It is important that the */
/* Deco Ceiling Depth (max deco ceiling across all compartments) only be */
/* extracted from the compartment values and not be compared against some */
/* initialization value. For example, if MAX(Deco_Ceiling_Depth . .) was */
/* compared against zero, this could cause a program lockup because sometimes */
/* the Deco Ceiling Depth needs to be negative (but not less than zero */
/* absolute ambient pressure) in order to decompress to the last stop at zero */
/* depth. */
/* =============================================================================== */
$deco_ceiling_depth = $compartment_deco_ceiling[0];
for ($i = 2; $i <= 16; ++$i) {
/* Computing MAX */
$r1 = $deco_ceiling_depth;
$r2 = $compartment_deco_ceiling[$i - 1];
$deco_ceiling_depth = max($r1,$r2);
}
return $deco_ceiling_depth;
} /* calc_deco_ceiling */
?>
Quote:
WARNING: Breathing compressed gas underwater, whether with conventional open-circuit scuba or closed-circuit rebreathers, is a potentially dangerous activity that requires specialized training. Breathing gas mixtures other than air underwater and especially using rebreather technology underwater, are activities which require considerable specialized training and certification. No one should ever attempt these activities without professional training. The information and software related to scuba diving, decompression theory and software code in this forum is provided for informational purposes only; and this information does not constitute adequate or proper training!