mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Move sac-calculation to profile.c
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									0bdf11b094
								
							
						
					
					
						commit
						437246d3ed
					
				
					 3 changed files with 32 additions and 23 deletions
				
			
		
							
								
								
									
										30
									
								
								profile.c
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								profile.c
									
										
									
									
									
								
							| 
						 | 
					@ -203,7 +203,7 @@ int get_cylinder_pressure_range(struct graphics_context *gc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Get local sac-rate (in ml/min) between entry1 and entry2 */
 | 
					/* Get local sac-rate (in ml/min) between entry1 and entry2 */
 | 
				
			||||||
int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, struct dive *dive)
 | 
					static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, struct dive *dive)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int index = entry1->cylinderindex;
 | 
						int index = entry1->cylinderindex;
 | 
				
			||||||
	cylinder_t *cyl;
 | 
						cylinder_t *cyl;
 | 
				
			||||||
| 
						 | 
					@ -821,6 +821,31 @@ static void populate_cylinder_pressure_data(int idx, int start, int end, struct
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void calculate_sac(struct dive *dive, struct plot_info *pi)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int i = 0, last = 0;
 | 
				
			||||||
 | 
						struct plot_data *last_entry = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < pi->nr; i++) {
 | 
				
			||||||
 | 
							struct plot_data *entry = pi->entry+i;
 | 
				
			||||||
 | 
							if (!last_entry || last_entry->cylinderindex != entry->cylinderindex) {
 | 
				
			||||||
 | 
								last = i;
 | 
				
			||||||
 | 
								last_entry = entry;
 | 
				
			||||||
 | 
								entry->sac = get_local_sac(entry, pi->entry + i + 1, dive);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								int j;
 | 
				
			||||||
 | 
								entry->sac = 0;
 | 
				
			||||||
 | 
								for (j = last; j < i; j++)
 | 
				
			||||||
 | 
									entry->sac += get_local_sac(pi->entry + j, pi->entry + j + 1, dive);
 | 
				
			||||||
 | 
								entry->sac /= (i - last);
 | 
				
			||||||
 | 
								if (entry->sec - last_entry->sec >= SAC_WINDOW) {
 | 
				
			||||||
 | 
									last++;
 | 
				
			||||||
 | 
									last_entry = pi->entry + last;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void populate_secondary_sensor_data(struct divecomputer *dc, struct plot_info *pi)
 | 
					static void populate_secondary_sensor_data(struct divecomputer *dc, struct plot_info *pi)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* We should try to see if it has interesting pressure data here */
 | 
						/* We should try to see if it has interesting pressure data here */
 | 
				
			||||||
| 
						 | 
					@ -1103,6 +1128,9 @@ struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, s
 | 
				
			||||||
	/* .. calculate missing pressure entries */
 | 
						/* .. calculate missing pressure entries */
 | 
				
			||||||
	populate_pressure_information(dive, dc, pi);
 | 
						populate_pressure_information(dive, dc, pi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Calculate sac */
 | 
				
			||||||
 | 
						calculate_sac(dive, pi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Then, calculate partial pressures and deco information */
 | 
						/* Then, calculate partial pressures and deco information */
 | 
				
			||||||
	if (prefs.profile_calc_ceiling)
 | 
						if (prefs.profile_calc_ceiling)
 | 
				
			||||||
		calculate_deco_information(dive, dc, pi);
 | 
							calculate_deco_information(dive, dc, pi);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,7 @@ struct plot_data {
 | 
				
			||||||
	int stopdepth;
 | 
						int stopdepth;
 | 
				
			||||||
	int cns;
 | 
						int cns;
 | 
				
			||||||
	int smoothed;
 | 
						int smoothed;
 | 
				
			||||||
 | 
						int sac;
 | 
				
			||||||
	double po2, pn2, phe;
 | 
						double po2, pn2, phe;
 | 
				
			||||||
	double mod, ead, end, eadd;
 | 
						double mod, ead, end, eadd;
 | 
				
			||||||
	velocity_t velocity;
 | 
						velocity_t velocity;
 | 
				
			||||||
| 
						 | 
					@ -63,8 +64,6 @@ int get_maxtime(struct plot_info *pi);
 | 
				
			||||||
 * partial pressure graphs */
 | 
					 * partial pressure graphs */
 | 
				
			||||||
int get_maxdepth(struct plot_info *pi);
 | 
					int get_maxdepth(struct plot_info *pi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, struct dive *dive);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void setup_pp_limits(struct graphics_context *gc);
 | 
					void setup_pp_limits(struct graphics_context *gc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -694,11 +694,9 @@ void ProfileGraphicsView::plot_single_temp_text(int sec, int mkelvin)
 | 
				
			||||||
void ProfileGraphicsView::plot_cylinder_pressure()
 | 
					void ProfileGraphicsView::plot_cylinder_pressure()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	int last = -1, last_index = -1;
 | 
						int last_index = -1;
 | 
				
			||||||
	int lift_pen = FALSE;
 | 
						int lift_pen = FALSE;
 | 
				
			||||||
	int first_plot = TRUE;
 | 
						int first_plot = TRUE;
 | 
				
			||||||
	int sac = 0;
 | 
					 | 
				
			||||||
	struct plot_data *last_entry = NULL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!get_cylinder_pressure_range(&gc))
 | 
						if (!get_cylinder_pressure_range(&gc))
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -711,29 +709,13 @@ void ProfileGraphicsView::plot_cylinder_pressure()
 | 
				
			||||||
		mbar = GET_PRESSURE(entry);
 | 
							mbar = GET_PRESSURE(entry);
 | 
				
			||||||
		if (entry->cylinderindex != last_index) {
 | 
							if (entry->cylinderindex != last_index) {
 | 
				
			||||||
			lift_pen = TRUE;
 | 
								lift_pen = TRUE;
 | 
				
			||||||
			last_entry = NULL;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!mbar) {
 | 
							if (!mbar) {
 | 
				
			||||||
			lift_pen = TRUE;
 | 
								lift_pen = TRUE;
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!last_entry) {
 | 
					 | 
				
			||||||
			last = i;
 | 
					 | 
				
			||||||
			last_entry = entry;
 | 
					 | 
				
			||||||
			sac = get_local_sac(entry, gc.pi.entry + i + 1, dive);
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			int j;
 | 
					 | 
				
			||||||
			sac = 0;
 | 
					 | 
				
			||||||
			for (j = last; j < i; j++)
 | 
					 | 
				
			||||||
				sac += get_local_sac(gc.pi.entry + j, gc.pi.entry + j + 1, dive);
 | 
					 | 
				
			||||||
			sac /= (i - last);
 | 
					 | 
				
			||||||
			if (entry->sec - last_entry->sec >= SAC_WINDOW) {
 | 
					 | 
				
			||||||
				last++;
 | 
					 | 
				
			||||||
				last_entry = gc.pi.entry + last;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		QColor c = get_sac_color(sac, dive->sac);
 | 
							QColor c = get_sac_color(entry->sac, dive->sac);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (lift_pen) {
 | 
							if (lift_pen) {
 | 
				
			||||||
			if (!first_plot && entry->cylinderindex == last_index) {
 | 
								if (!first_plot && entry->cylinderindex == last_index) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue