Exemple #1
0
        void SetWind()
        {
            if (metar == null || metar.Wind == null)
            {
                return;
            }

            Wind          w   = metar.Wind;
            StringBuilder sb  = new StringBuilder("Wind ");
            WindDirection dir = wind_directions [(int)Math.Round(w.Direction / 22.5)];

            sb.AppendFormat("from {0}", dir.Name);

            double speed = 0.0;
            string unit  = String.Empty;

            switch (windUnits)
            {
            case WindUnits.Knots:
                unit  = "kt";
                speed = w.Knots;
                break;

            case WindUnits.MetersPerSecond:
                unit  = "m/s";
                speed = w.MetersPerSecond;
                break;

            case WindUnits.KilometersPerHour:
                unit  = "km/h";
                speed = w.KilometersPerHour;
                break;

            case WindUnits.MilesPerHour:
                unit  = "mph";
                speed = w.MilesPerHour;
                break;
            }
            sb.AppendFormat(", {0} {1}", speed, unit);
            windConditions.Text = sb.ToString();

            // move wind indicator
            Canvas.SetLeft(windIndicator, dir.X + windIconLeft - (windIndicator.Width / 2));
            Canvas.SetTop(windIndicator, dir.Y + windIconTop - (windIndicator.Height / 2));
        }
Exemple #2
0
		void DoPart (string part)
		{
			Console.WriteLine ("part {0}", part);
			if (part == "CAVOK") {
				AddClouds (new Clouds ());
				return;
			}
			
			Match match;
			match = Regexps.StationId.Match (part);
			if (match.Success) {
				stationCode = part;
				return;
			}

			string[] groups;
			match = Regexps.ReportTime.Match (part);
			if (match.Success) {
				groups = GetGroups (match);

				// format: ddmmhhZ
				DateTime now = DateTime.Now;
				int day, minute, hour;

				try {
					day = Convert.ToInt32 (groups [0]);
				} catch {
					day = now.Day;
				}

				try {
					hour = Convert.ToInt32 (groups [1]);
				} catch {
					hour = now.Hour;
				}

				try {
					minute = Convert.ToInt32 (groups [2]);
				} catch {
					minute = now.Minute;
				}
				
				time = new DateTime (now.Year, now.Month, day, hour, minute, 0);
				return;				
			}

			match = Regexps.Wind.Match (part);
			if (match.Success) {
				groups = GetGroups (match);

				wind = new Wind (groups [0], groups [1], groups [2], groups [3]);
				return;
			}

			match = Regexps.Visibility.Match (part);
			if (match.Success) {
				groups = GetGroups (match);

				visibility = new Visibility (groups [0], groups [1]);
				return;
			}
			
			match = Regexps.Clouds.Match (part);
			if (match.Success) {
				groups = GetGroups (match);

				AddClouds (new Clouds (groups [0], groups [1], groups [2]));
				return;
			}

			match = Regexps.TempAndDew.Match (part);
			if (match.Success) {
				groups = GetGroups (match);
				
				temperature = new Temperature (groups [0].Replace ("M", "-"));
				dewPoint = new Temperature (groups [1].Replace ("M", "-"));
				return;
			}

			match = Regexps.PressureHg.Match (part);
			if (match.Success) {
				groups = GetGroups (match);
				
				try {
					pressureHg = Convert.ToDouble (groups [0]) / 100;
				} catch {
					pressureHg = -1;
				}
				return;
			}

			match = Regexps.PressureMb.Match (part);
			if (match.Success) {
				groups = GetGroups (match);

				try {
					pressureMb = Convert.ToDouble (groups [0]);
				} catch {
					pressureMb = -1;
				}
				return;
			}

			match = Regexps.Weather.Match (part);
			if (match.Success) {
				groups = GetGroups (match);

				weather = new Weather (groups [0], groups [1], groups [2],
						       groups [3], groups [4], groups [5]);
				return;
			}
			
			// We ignore all the other parts
		}
Exemple #3
0
        void DoPart(string part)
        {
            Console.WriteLine("part {0}", part);
            if (part == "CAVOK")
            {
                AddClouds(new Clouds());
                return;
            }

            Match match;

            match = Regexps.StationId.Match(part);
            if (match.Success)
            {
                stationCode = part;
                return;
            }

            string[] groups;
            match = Regexps.ReportTime.Match(part);
            if (match.Success)
            {
                groups = GetGroups(match);

                // format: ddmmhhZ
                DateTime now = DateTime.Now;
                int      day, minute, hour;

                try {
                    day = Convert.ToInt32(groups [0]);
                } catch {
                    day = now.Day;
                }

                try {
                    hour = Convert.ToInt32(groups [1]);
                } catch {
                    hour = now.Hour;
                }

                try {
                    minute = Convert.ToInt32(groups [2]);
                } catch {
                    minute = now.Minute;
                }

                time = new DateTime(now.Year, now.Month, day, hour, minute, 0);
                return;
            }

            match = Regexps.Wind.Match(part);
            if (match.Success)
            {
                groups = GetGroups(match);

                wind = new Wind(groups [0], groups [1], groups [2], groups [3]);
                return;
            }

            match = Regexps.Visibility.Match(part);
            if (match.Success)
            {
                groups = GetGroups(match);

                visibility = new Visibility(groups [0], groups [1]);
                return;
            }

            match = Regexps.Clouds.Match(part);
            if (match.Success)
            {
                groups = GetGroups(match);

                AddClouds(new Clouds(groups [0], groups [1], groups [2]));
                return;
            }

            match = Regexps.TempAndDew.Match(part);
            if (match.Success)
            {
                groups = GetGroups(match);

                temperature = new Temperature(groups [0].Replace("M", "-"));
                dewPoint    = new Temperature(groups [1].Replace("M", "-"));
                return;
            }

            match = Regexps.PressureHg.Match(part);
            if (match.Success)
            {
                groups = GetGroups(match);

                try {
                    pressureHg = Convert.ToDouble(groups [0]) / 100;
                } catch {
                    pressureHg = -1;
                }
                return;
            }

            match = Regexps.PressureMb.Match(part);
            if (match.Success)
            {
                groups = GetGroups(match);

                try {
                    pressureMb = Convert.ToDouble(groups [0]);
                } catch {
                    pressureMb = -1;
                }
                return;
            }

            match = Regexps.Weather.Match(part);
            if (match.Success)
            {
                groups = GetGroups(match);

                weather = new Weather(groups [0], groups [1], groups [2],
                                      groups [3], groups [4], groups [5]);
                return;
            }

            // We ignore all the other parts
        }