Salmo
Mar-24-2014, 05:25
Wolverine asked for it, here it is. Returns wind direction as specified in mission file.
public double GetWindAngleDegrees(string missionfile)
{
// --------------------------------------------------------------------
// Get the wind angle (in degrees) from the mission file
// --------------------------------------------------------------------
// example mis file line - Power -0.70 -0.25 0 .... Power x y z
// missionfile is the full path to the mission file
// Ref: https://www.eol.ucar.edu/content/wind-direction-quick-reference
// --------------------------------------------------------------------
System.IO.StreamReader file = new System.IO.StreamReader(missionfile); // open the mission file for processing
string line;
string key = "Power"; // we want to look for the "Power" line in the mission file
while ((line = file.ReadLine()) != null) // read mission file one line at a time
{
if (line.TrimStart().StartsWith(key)) // we found the 'Power' line in the mis file
{
string[] parts = line.Split(' '); // break the line up into parts
for (int i = 0; i < parts.GetLength(0); i++)
{
if (parts[i] != null && parts[i] != "" && parts[i] != key) // we've got the line parameters y & x
{
double DperR = 180 / Math.PI; // radians to degrees
// get meteorological wind coordinates, right handed with respect to an upward +Wmet.
double uMET = Convert.ToDouble(parts[i]); // 1st parameter is uMET; positive uMET is wind blowing to the East.
double vMET = Convert.ToDouble(parts[i + 1]); // 2nd parameter is vMET; positive vMET is wind blowing to the North.
double DirMET = Math.Atan2(-uMET, -vMET) * DperR; // get direction wind blowing FROM -180 to +180 as in game GUI
// the actual wind angle in degrees
Double WindAngleDegrees = DirMET;
if (DirMET < 0) WindAngleDegrees = 180 - Math.Abs(DirMET) + 180;
file.Close(); // close the mission file to processing
// troubleshoot negative values
if (WindAngleDegrees < 0 || WindAngleDegrees > 360)
{
Console.WriteLine("Windangledegrees invalid value " + WindAngleDegrees.ToString("##0.00") + "[GetWindAngleDegrees]");
}
return WindAngleDegrees; // return the wind angle in degrees
}
}
}
}
file.Close(); // close the mission file to processing
return -1; // default to minus 1 if we can't find the 'Power' line in the mis file
}
public double GetWindAngleDegrees(string missionfile)
{
// --------------------------------------------------------------------
// Get the wind angle (in degrees) from the mission file
// --------------------------------------------------------------------
// example mis file line - Power -0.70 -0.25 0 .... Power x y z
// missionfile is the full path to the mission file
// Ref: https://www.eol.ucar.edu/content/wind-direction-quick-reference
// --------------------------------------------------------------------
System.IO.StreamReader file = new System.IO.StreamReader(missionfile); // open the mission file for processing
string line;
string key = "Power"; // we want to look for the "Power" line in the mission file
while ((line = file.ReadLine()) != null) // read mission file one line at a time
{
if (line.TrimStart().StartsWith(key)) // we found the 'Power' line in the mis file
{
string[] parts = line.Split(' '); // break the line up into parts
for (int i = 0; i < parts.GetLength(0); i++)
{
if (parts[i] != null && parts[i] != "" && parts[i] != key) // we've got the line parameters y & x
{
double DperR = 180 / Math.PI; // radians to degrees
// get meteorological wind coordinates, right handed with respect to an upward +Wmet.
double uMET = Convert.ToDouble(parts[i]); // 1st parameter is uMET; positive uMET is wind blowing to the East.
double vMET = Convert.ToDouble(parts[i + 1]); // 2nd parameter is vMET; positive vMET is wind blowing to the North.
double DirMET = Math.Atan2(-uMET, -vMET) * DperR; // get direction wind blowing FROM -180 to +180 as in game GUI
// the actual wind angle in degrees
Double WindAngleDegrees = DirMET;
if (DirMET < 0) WindAngleDegrees = 180 - Math.Abs(DirMET) + 180;
file.Close(); // close the mission file to processing
// troubleshoot negative values
if (WindAngleDegrees < 0 || WindAngleDegrees > 360)
{
Console.WriteLine("Windangledegrees invalid value " + WindAngleDegrees.ToString("##0.00") + "[GetWindAngleDegrees]");
}
return WindAngleDegrees; // return the wind angle in degrees
}
}
}
}
file.Close(); // close the mission file to processing
return -1; // default to minus 1 if we can't find the 'Power' line in the mis file
}