Calculating mean depth for a dive

Willem Ferguson willemferguson at zoology.up.ac.za
Tue Nov 12 10:05:30 UTC 2013


Dirk and Linus wrote:

Make fake profile average depth come out right

This isn't perfect as it doesn't really cover all cases. If we need to
generate a profile for some fairly insane cases, the stupid thing just
gives up rather than try to search for a solution that satisfies the
constraints.

For example, if you have a maxdepth=10m and an average depth of 9.9m, it
will try two different (roughly sane) dive profiles, fail to get anything
that matches that kind of dive and that average depth, and then just say
"screw it, I'll match an insane profile instead" and basically generate a
rectangular dive.

It does seem to handle the few cases I tried.
==============End of quote ================

I am acutely aware that in this discussion group I am in the company of 
people a thousand times more intelligent than I can ever hope to be and 
a million times more experienced. I strongly suspect there is a 
fundamental aspect here that I have missed in this discussion. In this 
very likely event, please forgive my ignorance.

Can the code below perhaps be useful? It should be absolutely 100% 
accurate for all possible hand recorded dives, including the data for 
solo dives that are often supposed to have written depth-time 
information at fairly regular but not necessarily constant intervals. 
For dive planning, assumptions about the terminal ascent rate need to be 
made because this is determined by subsurface, not by the dive plan 
designer, so an absolutely accurate calculation of mean depth may not 
possible.
Kind regards,
willemf


#include <stdio.h>

double Calc_Mean_Depth(int no_samples, int Depth[], int DTime[]) {
int i;
double area;
if(Depth[0] != 0) {
         printf("\nERROR: Dive did not start at surface!\n");
         return -1;
         }
if(Depth[no_samples-1] != 0) {
         printf("\nERROR: Dive did not end at surface!\n");
         return -2;
         }
area = 0.0;                                        // Initialise the 
area above the dive profile to 0
for(i=1; i<no_samples; i++)             // For each line segment of the 
dive profile:
         area = area + 0.5 * (Depth[i] + Depth[i-1]) * 
(DTime[i]-DTime[i-1]);
return(area/(DTime[i-1]-DTime[0]));
}

int main(void) {
// Define an arbitrary dive profile:   (d=depth, t=time, 14 data points 
this time round)
static int d[] = {0,10,22,23,23,23,26,22,24,22,8,5,5,0};
static int t[] = {0,1,2,3,4,5,6,8,9,11,12,13,17,18};

printf("\nMean depth=%6.3f\n",Calc_Mean_Depth(14,d,t));

return 0;
}



More information about the subsurface mailing list