comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 261:9d4ab7c96885

Fix first stop rounding in GF model.
author JeanDo
date Mon, 11 Apr 2011 09:00:49 +0200
parents bde83cac971f
children d9593e0f1eea
comparison
equal deleted inserted replaced
260:bde83cac971f 261:9d4ab7c96885
533 ////////////////////////////////////////////////////////////////////////////// 533 //////////////////////////////////////////////////////////////////////////////
534 // Fast subroutine to read RTC timer 3. 534 // Fast subroutine to read RTC timer 3.
535 // Note: result is in 1/32 of msecs. 535 // Note: result is in 1/32 of msecs.
536 static unsigned short tmr3(void) 536 static unsigned short tmr3(void)
537 { 537 {
538 #ifndef CROSS_COMPILE
538 _asm 539 _asm
539 movff 0xfb2,PRODL // TMR3L 540 movff 0xfb2,PRODL // TMR3L
540 movff 0xfb3,PRODH // TMR3H 541 movff 0xfb3,PRODH // TMR3H
541 _endasm // result in PRODH:PRODL. 542 _endasm // result in PRODH:PRODL.
543 #else
544 return 0;
545 #endif
542 } 546 }
543 547
544 ////////////////////////////////////////////////////////////////////////////// 548 //////////////////////////////////////////////////////////////////////////////
545 // read buhlmann tables A and B for compatriment ci 549 // read buhlmann tables A and B for compatriment ci
546 // 550 //
693 697
694 // Stops are needed ? 698 // Stops are needed ?
695 if( sim_lead_tissue_limit > pres_surface ) 699 if( sim_lead_tissue_limit > pres_surface )
696 { 700 {
697 // Deepest stop, in meter (rounded up with a margin of 0.5m) 701 // Deepest stop, in meter (rounded up with a margin of 0.5m)
698 overlay unsigned char first_stop = 3 * (short)(0.83 + (sim_lead_tissue_limit - pres_surface) / 0.29955); 702 overlay unsigned char first_stop = 3 * (short)(0.99 + (sim_lead_tissue_limit - pres_surface) / 0.29955);
699 assert( first_stop < 128 ); 703 assert( first_stop < 128 );
704
705 #ifdef __DEBUG || defined(CROSS_COMPILE)
706 {
707 // Extra testing code to make sure the first_stop formula
708 // and rounding provides correct depth:
709 overlay float pres_stop = first_stop * 0.09985 // Meters to bar
710 + pres_surface;
711
712 // Keep GF_low until a first stop depth is found:
713 if( first_stop >= low_depth )
714 sim_limit( GF_low );
715 else
716 // current GF is GF_high - alpha (GF_high - GF_low)
717 // With alpha = currentDepth / maxDepth, hence in [0..1]
718 sim_limit( GF_high - first_stop * locked_GF_step );
719
720 // upper limit (lowest pressure tolerated):
721 assert( sim_lead_tissue_limit < pres_stop );
722 }
723 #endif
700 724
701 // Apply correction for the shallowest stop. 725 // Apply correction for the shallowest stop.
702 if( first_stop == 3 ) // new in v104 726 if( first_stop == 3 ) // new in v104
703 first_stop = char_I_depth_last_deco; // Use last 3m..6m instead. 727 first_stop = char_I_depth_last_deco; // Use last 3m..6m instead.
704 728
705 // Check all stops until one is higher than tolerated presure 729 // Because gradient factor at fist_stop might be less than at
706 while(first_stop > 0) 730 // current depth, we might ascent a bit more.
731 // Hence, check all stops until one is indeed higher than tolerated presure:
732 while(first_stop > 0)
707 { 733 {
708 overlay unsigned char next_stop; // Next index (0..30) 734 overlay unsigned char next_stop; // Next index (0..30)
709 overlay float pres_stop; // Next depth (0m..90m) 735 overlay float pres_stop; // Next depth (0m..90m)
710 736
711 // Check max speed, or reaching surface. 737 // Check max speed, or reaching surface.
1953 else 1979 else
1954 temp3 = - temp3 / (pres_tissue+16)[ci]; 1980 temp3 = - temp3 / (pres_tissue+16)[ci];
1955 if( 0.0 < temp3 && temp3 < 1.0 ) 1981 if( 0.0 < temp3 && temp3 < 1.0 )
1956 { 1982 {
1957 overlay float var_He_halftime = (buhlmann_ht+16)[ci]; 1983 overlay float var_He_halftime = (buhlmann_ht+16)[ci];
1958 assert( 1.51 <= var_N2_halftime && var_N2_halftime <= 240.03 ); 1984 assert( 1.51 <= var_He_halftime && var_He_halftime <= 240.03 );
1959 1985
1960 temp3 = log(1.0 - temp3) / -0.6931; // temp1 is the multiples of half times necessary. 1986 temp3 = log(1.0 - temp3) / -0.6931; // temp1 is the multiples of half times necessary.
1961 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. 1987 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
1962 // minus because log is negative 1988 // minus because log is negative
1963 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier 1989 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier