Well... I converted the JavaScript version into a C function. I left the wind component in, even if I don't have a gauge for that yet. I was able to get rid of his long if/then logic tree and the results agree. I still have one problem. The JS page lets the user enter the trend (Falling, Steady, Rising). I am having trouble getting a consensus on the range that is considered "Steady". Somewhere, I recall seeing -1.6 mbar to 1.6 mbar, but can't find the reference again. All other pages seem to gloss over the subject. Any suggestions?
Thanks.
VBR
Inq
u8 zambretti(float P, float d3P, float minP, float maxP, bool north,
float dirWind = NO_WIND)
{
float dLP = maxP - minP;
if (!dLP)
return 0;
if (dirWind < 1000) // NO_WIND = 1E6
{
if (!north)
dirWind += 180;
// This mess, just converts angle in degrees to 16 windrose cardinal
// 0 = N to 15 = NNW
u8 w = (u8)((dirWind + 11.25) / 22.5) % 16;
const float wind_dir[]
{6,5,5,2,-0.5,-2,-5,-8.5,-12,-10,-6,-4.5,-3,-0.5,1.5,3};
P += dLP * wind_dir[w] / 100.0;
}
d3P = d3P > STEADY ? 1.0 : (d3P < -STEADY ? -1.0 : 0);
if (month49 == north) // Summer in each hemisphere
P += d3P * 7.0 / 100.0 * dLP;
u8 index = (u8)((P - minP) / dLP * 21.99F);
// equivalents of Zambretti 'dial window' letters A - Z
const u8 rise_options[]
{25,25,25,24,24,19,16,12,11,9,8,6,5,2,1,1,0,0,0,0,0,0};
const u8 steady_options[]
{25,25,25,25,25,25,23,23,22,18,15,13,10,4,1,1,0,0,0,0,0,0};
const u8 fall_options[]
{25,25,25,25,25,25,25,25,23,23,21,20,17,14,7,3,1,1,1,0,0,0};
if (d3P > 0)
return rise_options[index];
else if (d3P < 0)
return fall_options[index];
return steady_options[index];
}