comparison src/p2_deco.c @ 608:d866684249bd

work on 2.99 stable
author heinrichsweikamp
date Mon, 07 Jan 2019 21:13:43 +0100
parents ca4556fb60b9
children 7b3903536213
comparison
equal deleted inserted replaced
607:c5151a490d88 608:d866684249bd
1 // *************************************************************************** 1 // ***************************************************************************
2 // p2_deco.c REFACTORED VERSION V2.99e 2 // p2_deco.c REFACTORED VERSION V2.99f
3 // 3 //
4 // Created on: 12.05.2009 4 // Created on: 12.05.2009
5 // Author: heinrichs weikamp, contributions by Ralph Lembcke and others 5 // Author: heinrichs weikamp, contributions by Ralph Lembcke and others
6 // 6 //
7 // *************************************************************************** 7 // ***************************************************************************
312 static float sim_CNS_fraction; // CNS after predicted ascent, 0.01 = 1%, as float 312 static float sim_CNS_fraction; // CNS after predicted ascent, 0.01 = 1%, as float
313 313
314 static unsigned int int_sim_CNS_fraction; // CNS after predicted ascent, 1 = 1%, as integer 314 static unsigned int int_sim_CNS_fraction; // CNS after predicted ascent, 1 = 1%, as integer
315 315
316 static unsigned char sim_depth_limit; // depth of next stop in meters, used in deco calculations 316 static unsigned char sim_depth_limit; // depth of next stop in meters, used in deco calculations
317 static unsigned char NDL_lead_tissue; // used to cache the tissue to start with when calculating the NDL 317 static unsigned char NDL_lead_tissue_norm; // used to cache the tissue to start with when calculating the NDL
318 static unsigned char NDL_lead_tissue_alt; // used to cache the tissue to start with when calculating the NDL
318 319
319 320
320 // result values from calculation functions 321 // result values from calculation functions
321 322
322 static float ceiling; // minimum tolerated relative pressure (i.e. without surface pressure) 323 static float ceiling; // minimum tolerated relative pressure (i.e. without surface pressure)
357 static float float_pSCR_factor; // pre-computed factor for pSCR ppO2 drop calculation 358 static float float_pSCR_factor; // pre-computed factor for pSCR ppO2 drop calculation
358 static float calc_pres_tissue_N2; // auxiliary variable to buffer tissue N2 pressure 359 static float calc_pres_tissue_N2; // auxiliary variable to buffer tissue N2 pressure
359 static float calc_pres_tissue_He; // auxiliary variable to buffer tissue He pressure 360 static float calc_pres_tissue_He; // auxiliary variable to buffer tissue He pressure
360 static float pres_tissue; // auxiliary variable to buffer total tissue pressure 361 static float pres_tissue; // auxiliary variable to buffer total tissue pressure
361 362
362 // 11 byte free space left in this bank (4 bytes per float, 2 bytes per int/short, 1 byte per char) 363 // 10 byte free space left in this bank (4 bytes per float, 2 bytes per int/short, 1 byte per char)
363 364
364 365
365 //---- Bank 6 parameters ----------------------------------------------------- 366 //---- Bank 6 parameters -----------------------------------------------------
366 #ifndef UNIX 367 #ifndef UNIX
367 # pragma udata bank6=0x600 368 # pragma udata bank6=0x600
1104 } 1105 }
1105 else 1106 else
1106 { 1107 {
1107 // yes - set flag for stop needed to 'no' 1108 // yes - set flag for stop needed to 'no'
1108 need_stop = 0; 1109 need_stop = 0;
1109 1110
1110 // set depth we can ascent to as 0 = surface 1111 // set depth we can ascent to as 0 = surface
1111 sim_depth_limit = 0; 1112 sim_depth_limit = 0;
1112 } 1113 }
1113 } 1114 }
1114 1115
2012 int_O_alternate_ascenttime = 0; // reset ascent time for the alternative plan 2013 int_O_alternate_ascenttime = 0; // reset ascent time for the alternative plan
2013 char_O_deco_warnings = 0; // reset all deco warnings 2014 char_O_deco_warnings = 0; // reset all deco warnings
2014 char_O_deco_info = 0; // reset all deco infos 2015 char_O_deco_info = 0; // reset all deco infos
2015 deco_tissue_vector = 0; // reset tissue deco vector 2016 deco_tissue_vector = 0; // reset tissue deco vector
2016 IBCD_tissue_vector = 0; // reset tissue IBCD vector 2017 IBCD_tissue_vector = 0; // reset tissue IBCD vector
2017 NDL_lead_tissue = 0; // reset first tissue to look at during NDL calculation 2018 NDL_lead_tissue_norm = 0; // reset first tissue to look at during NDL calculation
2019 NDL_lead_tissue_alt = 0; // reset first tissue to look at during NDL calculation
2018 2020
2019 // tag desaturation time as invalid (it will not be computed during a dive) 2021 // tag desaturation time as invalid (it will not be computed during a dive)
2020 int_O_desaturation_time = 65535; 2022 int_O_desaturation_time = 65535;
2021 2023
2022 // initialize values for first stop depth and GF slope 2024 // initialize values for first stop depth and GF slope
2728 // Modified: 2730 // Modified:
2729 // char_O_deco_warnings : for IBCD, microbubbles and outside warning (only in real tissues context) 2731 // char_O_deco_warnings : for IBCD, microbubbles and outside warning (only in real tissues context)
2730 // 2732 //
2731 static void calc_limit(PARAMETER float GF_parameter) 2733 static void calc_limit(PARAMETER float GF_parameter)
2732 { 2734 {
2733 overlay float lead_tissue_limit = 0.0; 2735 overlay float lead_tissue_limit = 0.0;
2734 2736
2735 2737
2736 // set leading tissue number to not yet computed 2738 // set leading tissue number to not yet computed
2737 lead_number = 0; 2739 lead_number = 0;
2738 2740
2779 2781
2780 // next calculations are only relevant when invoked on the real tissues 2782 // next calculations are only relevant when invoked on the real tissues
2781 if( tissue_increment & TISSUE_FLAG ) 2783 if( tissue_increment & TISSUE_FLAG )
2782 { 2784 {
2783 overlay float supersat; 2785 overlay float supersat;
2784 overlay float limit_warning; 2786 overlay float baseline_threshold;
2785 2787
2786 // calculate current supersaturation value (1.0 = 100%) of this tissue according to straight Buhlmann 2788 // calculate current supersaturation value (1.0 = 100%) of this tissue according to straight Buhlmann
2787 supersat = (pres_tissue - real_pres_respiration) / (pres_tissue - pres_min); 2789 supersat = (pres_tissue - real_pres_respiration) / (pres_tissue - pres_min);
2788 2790
2789 // check if tissue is in supersaturation 2791 // check if tissue is in supersaturation
2790 if( supersat > 0.0 ) 2792 if( supersat > 0.0 )
2791 { 2793 {
2792 // memorize highest supersaturation found 2794 // memorize highest supersaturation found
2793 if( supersat > lead_supersat ) lead_supersat = supersat; 2795 if( supersat > lead_supersat ) lead_supersat = supersat;
2794 2796
2795 // limit value for micro bubbles and outside warnings 2797 // tissue-dependent baseline threshold for micro bubbles and outside warnings
2796 limit_warning = 0.02 * ci + 0.9; 2798 baseline_threshold = 0.02 * ci + 1.0;
2797 2799
2798 // micro bubbles warning: supersaturation >= limit_warning OR >= 1.0 2800 // micro bubbles warning: supersaturation > baseline threshold
2799 if( (supersat >= limit_warning) || (supersat >= 1.0) ) 2801 if( supersat > baseline_threshold )
2800 char_O_deco_warnings |= (DECO_WARNING_MBUBBLES + DECO_WARNING_MBUBBLES_lock); 2802 char_O_deco_warnings |= (DECO_WARNING_MBUBBLES + DECO_WARNING_MBUBBLES_lock);
2801 2803
2802 // outside warning: supersaturation >= limit_warning AND >= 1.0 2804 // outside warning: supersaturation > baseline threshold + additional 5% margin
2803 if( (supersat >= limit_warning) && (supersat >= 1.0) ) 2805 if( supersat > baseline_threshold + 0.05 )
2804 char_O_deco_warnings |= (DECO_WARNING_OUTSIDE + DECO_WARNING_OUTSIDE_lock ); 2806 char_O_deco_warnings |= (DECO_WARNING_OUTSIDE + DECO_WARNING_OUTSIDE_lock );
2805 } 2807 }
2806 } 2808 }
2807 2809
2808 // Apply the Eric Baker's varying gradient factor correction if the GF-Model is selected. 2810 // Apply the Eric Baker's varying gradient factor correction if the GF-Model is selected.
2871 // select gradient factor to use 2873 // select gradient factor to use
2872 GF_factor = (char_I_deco_model != 0) ? GF_high : 1.0; 2874 GF_factor = (char_I_deco_model != 0) ? GF_high : 1.0;
2873 2875
2874 // the fastest way to find out if already being beyond NDL is to start with 2876 // the fastest way to find out if already being beyond NDL is to start with
2875 // the tissue that was the leading one during the last NDL computation... 2877 // the tissue that was the leading one during the last NDL computation...
2876 ci = i + NDL_lead_tissue; 2878 ci = (char_O_deco_status & DECO_PLAN_ALTERNATE) ? (NDL_lead_tissue_alt + i) : (NDL_lead_tissue_norm + i);
2877 2879
2878 // wrap around after the 16th tissue 2880 // wrap around after the 16th tissue
2879 if( ci >= NUM_COMP ) ci -= NUM_COMP; 2881 if( ci >= NUM_COMP ) ci -= NUM_COMP;
2880 2882
2881 // read the loading factors for 10 minute iterations 2883 // read the loading factors for 10 minute iterations
2986 // If NDL found to be overrun, outer loop will be terminated by means of the i = NUM_COMP statement. 2988 // If NDL found to be overrun, outer loop will be terminated by means of the i = NUM_COMP statement.
2987 2989
2988 } // outer for-loop iterating over all tissues 2990 } // outer for-loop iterating over all tissues
2989 2991
2990 // store the NDL dominating tissue for to start with in the next NDL calculation 2992 // store the NDL dominating tissue for to start with in the next NDL calculation
2991 NDL_lead_tissue = new_NDL_lead_tissue; 2993 if( char_O_deco_status & DECO_PLAN_ALTERNATE ) NDL_lead_tissue_alt = new_NDL_lead_tissue;
2994 else NDL_lead_tissue_norm = new_NDL_lead_tissue;
2992 } 2995 }
2993 2996
2994 2997
2995 ////////////////////////////////////////////////////////////////////////////// 2998 //////////////////////////////////////////////////////////////////////////////
2996 // calc_ascenttime 2999 // calc_ascenttime
3705 3708
3706 // volumes are only calculated for gases 1-5, but not the manually configured one 3709 // volumes are only calculated for gases 1-5, but not the manually configured one
3707 if( stop_gas ) 3710 if( stop_gas )
3708 { 3711 {
3709 // compute distance between bottom and first stop 3712 // compute distance between bottom and first stop
3710 float_depth = (float)(char_bottom_depth - stop_depth); 3713 float_depth = (float)char_bottom_depth - (float)stop_depth;
3711 3714
3712 // initial ascent exists only if ascent distance is > 0 3715 // initial ascent exists only if ascent distance is > 0
3713 if( float_depth > 0.0 ) 3716 if( float_depth > 0.0 )
3714 { 3717 {
3715 // compute ascent time 3718 // compute ascent time
3984 int_O_gradient_factor = (unsigned int)(100 * lead_supersat + 0.5); 3987 int_O_gradient_factor = (unsigned int)(100 * lead_supersat + 0.5);
3985 3988
3986 if( char_I_deco_model != 0 ) 3989 if( char_I_deco_model != 0 )
3987 { 3990 {
3988 // GF factors enabled 3991 // GF factors enabled
3989 if( int_O_gradient_factor >= char_I_GF_High_percentage ) 3992 if ( int_O_gradient_factor > 99 )
3993 {
3994 int_O_gradient_factor |= INT_FLAG_WARNING; // make GF factor shown in red
3995 }
3996 else if( int_O_gradient_factor > char_I_GF_High_percentage )
3990 { 3997 {
3991 int_O_gradient_factor |= INT_FLAG_ATTENTION; // make GF factor shown in yellow 3998 int_O_gradient_factor |= INT_FLAG_ATTENTION; // make GF factor shown in yellow
3992 char_O_deco_warnings |= DECO_ATTENTION_OUTSIDE; // make depth blink in yellow 3999 char_O_deco_warnings |= DECO_ATTENTION_OUTSIDE; // make depth blink in yellow
3993 } 4000 }
3994 4001 }
3995 if( int_O_gradient_factor >= 100 ) 4002 else
4003 {
4004 // straight Buhlmann
4005 if ( int_O_gradient_factor > 100 )
3996 int_O_gradient_factor |= INT_FLAG_WARNING; // make GF factor shown in red 4006 int_O_gradient_factor |= INT_FLAG_WARNING; // make GF factor shown in red
3997 } 4007
3998 else 4008 else if ( int_O_gradient_factor > 99 )
3999 {
4000 // straight Buhlmann
4001 if ( int_O_gradient_factor >= 100 )
4002 int_O_gradient_factor |= INT_FLAG_WARNING; // make GF factor shown in red
4003
4004 else if ( int_O_gradient_factor >= 90 )
4005 { 4009 {
4006 int_O_gradient_factor |= INT_FLAG_ATTENTION; // make GF factor shown in yellow 4010 int_O_gradient_factor |= INT_FLAG_ATTENTION; // make GF factor shown in yellow
4007 char_O_deco_warnings |= DECO_ATTENTION_OUTSIDE; // make depth blink in yellow 4011 char_O_deco_warnings |= DECO_ATTENTION_OUTSIDE; // make depth blink in yellow
4008 } 4012 }
4009 } 4013 }