Пример #1
0
Файл: Metar.cs Проект: dfr0/moon
		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
		}