comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 695:5bf4f526f552

... minor cleanups ...
author JeanDo
date Wed, 13 Feb 2013 10:36:28 +0100
parents 6e456a6398e0
children 53e41fa1e3f0 fdeb01351f23
comparison
equal deleted inserted replaced
693:59e5998931d3 695:5bf4f526f552
163 static float GF_high; 163 static float GF_high;
164 static float GF_delta; 164 static float GF_delta;
165 static float locked_GF_step; // GF_delta / low_depth 165 static float locked_GF_step; // GF_delta / low_depth
166 166
167 static unsigned char temp_depth_limit; 167 static unsigned char temp_depth_limit;
168 static unsigned char low_depth; // Depth of deepest stop 168 float low_depth; // Depth of deepest stop
169 169
170 // Simulation context: used to predict ascent. 170 // Simulation context: used to predict ascent.
171 static unsigned char sim_lead_tissue_no; // Leading compatiment number. 171 unsigned char sim_lead_tissue_no; // Leading compatiment number.
172 static float sim_lead_tissue_limit; // Buhlmann tolerated pressure. 172 float sim_lead_tissue_limit; // Buhlmann tolerated pressure.
173 173
174 // Real context: what we are doing now. 174 // Real context: what we are doing now.
175 static float calc_lead_tissue_limit; // 175 static float calc_lead_tissue_limit; //
176 176
177 static unsigned char internal_deco_time[NUM_STOPS]; 177 static unsigned char internal_deco_time[NUM_STOPS];
549 overlay unsigned char first_stop = 0; 549 overlay unsigned char first_stop = 0;
550 overlay float p; 550 overlay float p;
551 551
552 sim_limit( GF_low ); 552 sim_limit( GF_low );
553 p = sim_lead_tissue_limit - pres_surface; 553 p = sim_lead_tissue_limit - pres_surface;
554 p *= BAR_TO_METER;
554 if( p <= 0.0f ) 555 if( p <= 0.0f )
555 goto no_deco_stop; // We can surface directly... 556 goto no_deco_stop; // We can surface directly...
556
557 p *= BAR_TO_METER;
558 if( p < min_depth )
559 goto no_deco_stop; // First stop is higher than 1' ascent.
560
561 first_stop = 3 * (short)(0.99999 + p*0.333333);
562 assert( first_stop < 128 );
563
564 // Apply correction for the shallowest stop.
565 if( first_stop == 3 ) // new in v104
566 first_stop = char_I_depth_last_deco; // Use last 3m..6m instead.
567 557
568 // Store the deepest point needing a deco stop as the LOW reference for GF. 558 // Store the deepest point needing a deco stop as the LOW reference for GF.
569 // NOTE: following stops will be validated using this LOW-HIGH gf scale, 559 // NOTE: following stops will be validated using this LOW-HIGH gf scale,
570 // so if we want to keep coherency, we should not validate this stop 560 // so if we want to keep coherency, we should not validate this stop
571 // yet, but apply the search to it, as for all the following stops afterward. 561 // yet, but apply the search to it, as for all the following stops afterward.
572 if( first_stop > low_depth ) 562 if( p > low_depth )
573 { 563 {
574 low_depth = first_stop; 564 low_depth = p;
575 locked_GF_step = GF_delta / first_stop; 565 locked_GF_step = GF_delta / low_depth;
576 } 566 }
567
568 if( p < min_depth )
569 goto no_deco_stop; // First stop is higher than 1' ascent.
570
571 // Round to multiple of 3m.
572 first_stop = 3 * (short)(0.9995f + p*0.333333f);
573 assert( first_stop < 128 );
574
575 // Apply correction for the shallowest stop.
576 if( first_stop == 3 ) // new in v104
577 first_stop = char_I_depth_last_deco; // Use last 3m..6m instead.
577 578
578 // We have a stop candidate. 579 // We have a stop candidate.
579 // But maybe ascending to the next stop will diminish the constraint, 580 // But maybe ascending to the next stop will diminish the constraint,
580 // because the GF might decrease more than the preassure gradient... 581 // because the GF might decrease more than the preassure gradient...
581 while(first_stop > 0) 582 while(first_stop > 0)
582 { 583 {
583 overlay unsigned char next_stop; // Next depth (0..90m) 584 overlay unsigned char next_stop; // Next depth (0..90m)
584 overlay float pres_stop; // Next pressure (bar)
585 585
586 // Check max speed, or reaching surface. 586 // Check max speed, or reaching surface.
587 if( first_stop <= min_depth ) 587 if( first_stop <= min_depth )
588 goto no_deco_stop; 588 goto no_deco_stop;
589 589
592 else if( first_stop == 6 ) 592 else if( first_stop == 6 )
593 next_stop = char_I_depth_last_deco; 593 next_stop = char_I_depth_last_deco;
594 else 594 else
595 next_stop = first_stop - 3; // Index of next (upper) stop. 595 next_stop = first_stop - 3; // Index of next (upper) stop.
596 596
597 // Just a check we are indeed above LOW ref.
598 assert( next_stop < low_depth );
599
600 // Total preassure at the new stop candidate: 597 // Total preassure at the new stop candidate:
601 pres_stop = next_stop * METER_TO_BAR 598 p = next_stop * METER_TO_BAR
602 + pres_surface; 599 + pres_surface;
603 600
604 // Keep GF_low until a first stop depth is found: 601 // Recompute limit for this new stop:
605 sim_limit( GF_high - next_stop * locked_GF_step ); 602 if( !low_depth || next_stop > low_depth )
606 603 sim_limit( GF_low );
607 // Check upper limit (lowest pressure tolerated): 604 else
608 if( sim_lead_tissue_limit >= pres_stop ) // check if ascent to next deco stop is ok 605 sim_limit( GF_high - next_stop * locked_GF_step );
609 goto deco_stop_found; 606
607 // Check upper limit (lowest ambiant pressure tolerated):
608 if( sim_lead_tissue_limit >= p )
609 goto deco_stop_found; // Ascent to next_stop forbiden.
610 610
611 // Else, validate that stop and loop... 611 // Else, validate that stop and loop...
612 first_stop = next_stop; 612 first_stop = next_stop;
613 } 613 }
614 assert( first_stop == 0 );
615 614
616 no_deco_stop: 615 no_deco_stop:
617 temp_depth_limit = min_depth; 616 temp_depth_limit = min_depth;
618 goto done; 617 goto done;
619 618
619 deco_stop_found:
620 // next stop is the last validated depth found, aka first_stop 620 // next stop is the last validated depth found, aka first_stop
621 deco_stop_found:
622 need_stop = 1; // Hit. 621 need_stop = 1; // Hit.
623 temp_depth_limit = first_stop; // Stop depth, in meter. 622 temp_depth_limit = first_stop; // Stop depth, in meter.
624 623
625 done: 624 done:
626 ; 625 ;
1067 char_O_deco_status = 0; // Calc bottom-time/nullzeit next iteration. 1066 char_O_deco_status = 0; // Calc bottom-time/nullzeit next iteration.
1068 1067
1069 // Values that should be reset just once for the full real dive. 1068 // Values that should be reset just once for the full real dive.
1070 // This is used to record the lowest stop for the whole dive, 1069 // This is used to record the lowest stop for the whole dive,
1071 // Including ACCROSS all simulated ascent. 1070 // Including ACCROSS all simulated ascent.
1072 low_depth = 0; 1071 low_depth = 0.0;
1073 locked_GF_step = 0.0; 1072 locked_GF_step = 0.0;
1074 1073
1075 // Reset gas switch history. 1074 // Reset gas switch history.
1076 backup_gas_used = sim_gas_last_used = 0; 1075 backup_gas_used = sim_gas_last_used = 0;
1077 backup_gas_depth = sim_gas_last_depth = 0; 1076 backup_gas_depth = sim_gas_last_depth = 0;
1680 if( char_I_deco_model != 0 ) 1679 if( char_I_deco_model != 0 )
1681 p = ( p - var_N2_a * GF_current) 1680 p = ( p - var_N2_a * GF_current)
1682 / (GF_current / var_N2_b + 1.0 - GF_current); 1681 / (GF_current / var_N2_b + 1.0 - GF_current);
1683 else 1682 else
1684 p = (p - var_N2_a) * var_N2_b; 1683 p = (p - var_N2_a) * var_N2_b;
1685 if( p < 0.0 ) p = 0.0;
1686 1684
1687 if( p > sim_lead_tissue_limit ) 1685 if( p > sim_lead_tissue_limit )
1688 { 1686 {
1689 sim_lead_tissue_no = ci; 1687 sim_lead_tissue_no = ci;
1690 sim_lead_tissue_limit = p; 1688 sim_lead_tissue_limit = p;