Port VPM Decompression Algorithm to PHP and then to Dive Computer


 
Thread Tools Search this Thread
The Lounge What is on Your Mind? Port VPM Decompression Algorithm to PHP and then to Dive Computer
# 1  
Old 05-04-2012
Lightbulb Port VPM Decompression Algorithm to PHP and then to Dive Computer

Hello!

I'm about to embark on a new project to port the VPM (Variable Permability Model) for decompression diving from some old BASIC code (attached, "VPM.txt") to PHP.

Then, I plan to create a plugin for this site where folks can run VPM on the web.

Then, I plan to improve VPM based on some scientific papers (like the one attached, "sdeco.pdf").

And then, if all goes well, port to an "open source" dive computer.

Anyone interested to help in this fun project!?

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!
# 2  
Old 05-05-2012
Folders full of decompression-related technical articles and computer code are at the site:

ftp://decompression.org/

To access the site, you'll need login credentials (anonymous ftp will not work):

Code:
username: downloadfiles

password: decompression1

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!
# 3  
Old 05-05-2012
From the archives above, VPM-B was ported to both FORTRAN and C.

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!
# 4  
Old 05-06-2012
Guess I'll start first by porting these functions, one-at-a-time, from C to PHP:

Blue means "First Cut Done" in this thread/project (update each time a function is ported to PHP)

Code:
extern /* Subroutine */ int calc_barometric_pressure();
extern /* Subroutine */ int calc_deco_ceiling();
extern /* Subroutine */ int onset_of_impermeability();
extern /* Subroutine */ int radius_root_finder();
extern /* Subroutine */ int nuclear_regeneration(), clock_();
extern /* Subroutine */ int vpm_repetitive_algorithm();
extern /* Subroutine */ int gas_loadings_surface_interval();
extern /* Subroutine */ int critical_volume();	    ;
extern /* Subroutine */ int calc_crushing_pressure(), 
                            calc_surface_phase_volume_time(), 
                            decompression_stop();
extern /* Subroutine */ int calc_start_of_deco_zone();
extern /* Subroutine */ int calc_initial_allowable_gradient(), 
                            gas_loadings_ascent_descen();
extern /* Subroutine */ int gas_loadings_constant_depth();
extern /* Subroutine */ int vpm_altitude_dive_algorithm();
extern /* Subroutine */ int calc_max_actual_gradient(), 
                            projected_ascent();

extern /* Subroutine */ doublereal schreiner_equation__();
extern /* Subroutine */ doublereal haldane_equation__();

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!
# 5  
Old 05-06-2012
SUBROUTINE CALC_BAROMETRIC_PRESSURE

First one, in C:

Code:
/* =============================================================================== */
/*     SUBROUTINE CALC_BAROMETRIC_PRESSURE */
/*     Purpose: This sub calculates barometric pressure at altitude based on the */
/*     publication "U.S. Standard Atmosphere, 1976", U.S. Government Printing */
/*     Office, Washington, D.C. The source for this code is a Fortran 90 program */
/*     written by Ralph L. Carmichael (retired NASA researcher) and endorsed by */
/*     the National Geophysical Data Center of the National Oceanic and */
/*     Atmospheric Administration.  It is available for download free from */
/*     Public Domain Aeronautical Software at:  http://www.pdas.com/atmos.htm */
/* =============================================================================== */

int calc_barometric_pressure(real *altitude)
{
    /* Local variables */
    static real altitude_meters, 
                molecular_weight_of_air, 
	            acceleration_of_operation, 
                altitude_kilometers, 
                altitude_feet,
	            temp_gradient, 
                temp_at_sea_level, 
                pressure_at_sea_level, 
	            geopotential_altitude, 
                gmr_factor, 
	            pressure_at_sea_level_fsw, 
                pressure_at_sea_level_msw, 
	            temp_at_geopotential_altitude, 
                gas_constant_r, 
	            radius_of_earth;

/* =============================================================================== */
/*     CALCULATIONS */
/* =============================================================================== */

    radius_of_earth = 6369.;                 /* ki */
    acceleration_of_operation = 9.80665;     /* meters/ */
    molecular_weight_of_air = 28.9644;
    gas_constant_r = 8.31432;                /* Joules/mol*de */
    temp_at_sea_level = 288.15;              /* degree */
    pressure_at_sea_level_fsw = 33.;         /* at sea level (Standard Atm */
                                             /* feet of seawater based on 1 */
    pressure_at_sea_level_msw = 10.;         /* at sea level (European */
                                             /* meters of seawater based on 1 */
    temp_gradient = -6.5;                    /* change in geopotential a */
                                             /* valid for first layer of at */
                                             /* up to 11 kilometers or 36, */
                                             /* Change in Temp deg Kel */
    gmr_factor = 
        acceleration_of_operation * molecular_weight_of_air / gas_constant_r;
    if (units_equal_fsw) {
	    altitude_feet = *altitude;
	    altitude_kilometers = altitude_feet / 3280.839895;
	    pressure_at_sea_level = pressure_at_sea_level_fsw;
    }
    if (units_equal_msw) {
	    altitude_meters = *altitude;
	    altitude_kilometers = altitude_meters / 1e3;
	    pressure_at_sea_level = pressure_at_sea_level_msw;
    }
    geopotential_altitude = 
        altitude_kilometers * radius_of_earth / (altitude_kilometers + radius_of_earth);
    temp_at_geopotential_altitude = 
        temp_at_sea_level + temp_gradient * geopotential_altitude;
    barometric_pressure = 
        pressure_at_sea_level * 
        exp(log(temp_at_sea_level / temp_at_geopotential_altitude) * gmr_factor / temp_gradient);

    return 0;
} /* calc_barometric_pressure */

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!
# 6  
Old 05-07-2012
FUNCTION CALC_BAROMETRIC_PRESSURE

Porting to alc_barometric_pressure() PHP was easy:

PHP Code:
<?php

/* =============================================================================== */
/*     SUBROUTINE CALC_BAROMETRIC_PRESSURE */
/*     Purpose: This sub calculates barometric pressure at altitude based on the */
/*     publication "U.S. Standard Atmosphere, 1976", U.S. Government Printing */
/*     Office, Washington, D.C. The source for this code is a Fortran 90 program */
/*     written by Ralph L. Carmichael (retired NASA researcher) and endorsed by */
/*     the National Geophysical Data Center of the National Oceanic and */
/*     Atmospheric Administration.  It is available for download free from */
/*     Public Domain Aeronautical Software at:  http://www.pdas.com/atmos.htm */
/* =============================================================================== */
/*     INITIAL PORT TO PHP  VERSION 0.1 */
/*     https://www.unix.com/whats-your-mind/185211-port-vpm-decompression-algorithm-php-then-dive-computer.html */
/* =============================================================================== */


function calc_barometric_pressure($altitude$options)
{
    

    
$radius_of_earth 6369.0;                /* ki */
    
$acceleration_of_operation 9.80665;     /* meters/ */
    
$molecular_weight_of_air 28.9644;
    
$gas_constant_r 8.31432;                /* Joules/mol*de */
    
$temp_at_sea_level 288.15;              /* degree */
    
$pressure_at_sea_level_fsw 33.0;        /* at sea level (Standard Atm */
                                              /* feet of seawater based on 1 */
    
$pressure_at_sea_level_msw 10.0;        /* at sea level (European */
                                              /* meters of seawater based on 1 */
    
$temp_gradient = -6.5;                    /* change in geopotential a */
                                              /* valid for first layer of at */
                                              /* up to 11 kilometers or 36, */
                                              /* Change in Temp deg Kel */
    
$gmr_factor 
        
$acceleration_of_operation $molecular_weight_of_air $gas_constant_r;
    if (
$options['units_equal_fsw']) {
        
$altitude_feet $altitude;
        
$altitude_kilometers $altitude_feet 3280.839895;
        
$pressure_at_sea_level $pressure_at_sea_level_fsw;
    }
    else  {     
/* Default to meters */
        
$altitude_meters $altitude;
        
$altitude_kilometers $altitude_meters 1000;
        
$pressure_at_sea_level $pressure_at_sea_level_msw;
    }
    
$geopotential_altitude 
        
$altitude_kilometers $radius_of_earth / ($altitude_kilometers $radius_of_earth);
    
$temp_at_geopotential_altitude 
        
$temp_at_sea_level $temp_gradient $geopotential_altitude;
    
$barometric_pressure 
        
$pressure_at_sea_level 
        
exp(log($temp_at_sea_level $temp_at_geopotential_altitude) * $gmr_factor $temp_gradient);

    return 
$barometric_pressure;
/* calc_barometric_pressure */

?>
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!
# 7  
Old 05-07-2012
SUBROUTINE CALC_DECO_CEILING

Next one in C:

Code:
/* =============================================================================== */
/*     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. */
/* =============================================================================== */

int calc_deco_ceiling(real *deco_ceiling_depth)
{
    /* System generated locals */
    real r1, r2;

    /* Local variables */
    static real weighted_allowable_gradient;
    static integer i;
    static real compartment_deco_ceiling[16], 
                gas_loading, 
	            tolerated_ambient_pressure;

/* 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 + 
		        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 = 
		        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.;
	    }
	    compartment_deco_ceiling[i - 1] = 
            tolerated_ambient_pressure - 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 0;
} /* 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!
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

VPM decompression algorithm +++for NEO+++

Hi Neo, i have followed your porting of the VPM algorithm to C+. Did you ever finish this exercise? I am playing around with some ARM chips and would love to run the algorithm on them... would you care to share the final results? Thanks for your help. Greetings Carsten (0 Replies)
Discussion started by: carsten
0 Replies

2. What is on Your Mind?

Port VPM Decompression Algorithm to PHP (Main Loop) - Part 2

Continued from here. Port the main loop C code to PHP. Here is the C code for the main loop: /* =============================================================================== */ /* Begin MAIN proc (see endofpgm for alternate entry) */ /*... (2 Replies)
Discussion started by: Neo
2 Replies

3. Ubuntu

SSH and VPM Doubt

hI MY Nerd folks...i have ubuntu 10.4 in my machine...i want to use open shh in my latop for the sake of being complete anonymous...but am just a noob anyont got any tips for me for the complete steps or for How to LInks ...watever..thanks in advance (4 Replies)
Discussion started by: surensach
4 Replies

4. UNIX for Dummies Questions & Answers

Compression and decompression in the same script

Hi Guys, I'm just wondering how to compress and decompress a file in the same script using multiple programs, and can it be done in one line? e.g gzip file && gunzip file bzip2 file && bunzip file I tried this and a few other combinations but it doesn't seem to work. Any... (6 Replies)
Discussion started by: Spaulds
6 Replies

5. Windows & DOS: Issues & Discussions

Decompression with Cygwin

I am having some trouble decompressing a tar.bz2 with Cygwin. Is it even possible to do this? I am new to Unix so I have no idea. I downloaded GCC on my Windows machine (gcc-3.4.4.tar.bz2) and I've been trying to decompress and install it. Is cygwin this best way to decompress on a windows... (3 Replies)
Discussion started by: noob1021
3 Replies

6. UNIX for Dummies Questions & Answers

Decompression utility

I am looking for an unzip application that can handle Unix .z files, but from a Windows environment AND has a command-line prompt. Anybody know of anything? TIA, H2M3 (2 Replies)
Discussion started by: H2M3
2 Replies
Login or Register to Ask a Question