//------------------------------------------------------------------------------
//
//
// function uv2deg($u, $v)
//
// Converts winds in u and v to degrees
//
//
//
//
//
//------------------------------------------------------------------------------
function uv2deg($u, $v){
//convert u, v components to direction and speed
// (Remember u and v are wind *vectors* ... *not* conventional winds
// in which direction is the direction *from* which winds are coming!)
// Quadrant I (positive u and v...this would be a wind *from* the SW quadrant
If ($u >= 0 and $v > 0){
$wind_dir = @sprintf("%03.0f", @round((180 /M_PI) * @atan($u/$v))+180,-1);
}
// Quadrant II (negative u, positive v... wind *from* SE)
If ($u <>= 0){
$wind_dir = @sprintf("%03.0f", @round((180 /M_PI) * @atan($v/abs($u))+90),-1);
}
// Quadrant III (negative u and v...wind from NE quadrant)
if ($u <= 0 And $v < 0){
$wind_dir = @sprintf("%03.0f", @round((180 /M_PI) * @atan(abs($u)/abs($v))),-1);
}
// Quadrant IV (positive u, negative v...wind *from* the NW)
If ($u > 0 and $v <= 0 ){
$wind_dir = @sprintf("%03.0f", @round((180 /M_PI) * @atan(abs($v)/$u)+270),-1);
}
if ($u==0 and $v==0){
$wind_dir="Ca";
}
if ($wind_dir=="000"){
$wind_dir = "360";
}
return $wind_dir;
}
Tuesday, July 21, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment