public static SimDateTime SelectNextSnapshot(SimDateTime sdt) { List <SimDateTime> snapshots = AvailableSnapshots; if (snapshots != null && snapshots.Count > 0) { if (snapshots.Contains(sdt) == false) { sdt = SelectNearestSnapshot(sdt); } int idx = snapshots.IndexOf(sdt); if (idx < 0) { return(snapshots[0]); } if (idx >= snapshots.Count) { return(snapshots[snapshots.Count - 1]); } return(snapshots[idx + 1]); } return(null); }
public int GetHoursOffset(SimDateTime sdt) { DateTime dt1 = new DateTime(Year, Month, Day, Hour, 0, 0); DateTime dt2 = new DateTime(sdt.Year, sdt.Month, sdt.Day, sdt.Hour, 0, 0); float h = (float)dt1.Subtract(dt2).TotalHours; if (h - Math.Floor(h) >= 0.5f) { return((int)(h) + 1); } return((int)h); }
public SimDateTime AddHours(int hours) { DateTime dt = new DateTime(Year, Month, Day, Hour, 0, 0); DateTime dt2 = dt.AddHours(hours); SimDateTime sdt = new SimDateTime(); sdt.Year = dt2.Year; sdt.Month = dt2.Month; sdt.Day = dt2.Day; sdt.Hour = dt2.Hour; return(sdt); }
public int CompareTo(object obj) { SimDateTime sdt = obj as SimDateTime; if (sdt == null) { return(1); } string s1 = this.ToString(); string s2 = sdt.ToString(); return(string.Compare(s1, s2, true)); }
public static SimDateTime FromFileName(string fileName) { SimDateTime sdt = null; try { int idx = fileName.IndexOf("MAP_"); if (idx > 0) { string dateTimePart = fileName.Substring(idx + 4); sdt = new SimDateTime(dateTimePart); } } catch { } return(sdt); }
public static SimDateTimeRange BuildRange(SimDateTime dtStart, int rangeSize) { EarthModel earth = new EarthModel(dtStart, true, (int)AbsoluteConstants.HoursPerDay); if (SimulationData.AvailableSnapshots.Contains(dtStart)) { SimDateTime sdt = dtStart.AddHours((rangeSize - 1) * earth.SnapshotLength); SimDateTime dtEnd = SimulationData.SelectNearestSnapshot(sdt); if (dtEnd != null) { return(new SimDateTimeRange(earth, dtStart, dtEnd)); } } return(null); }
public static void LookupDataFiles(string category) { lock (_availableSnapshotsLock) { try { _availableSnapshots.Clear(); List <string> files = GetDataFiles(category); foreach (string file in files) { string fileName = Path.GetFileNameWithoutExtension(file); SimDateTime sdt = SimDateTime.FromFileName(fileName); string dataType = fileName.Substring(0, 4).ToUpperInvariant(); if (_availableSnapshots.Contains(sdt) == false) { _availableSnapshots.Add(sdt); } if (_availableDataTypes.Contains(dataType) == false) { _availableDataTypes.Add(dataType); } } _availableSnapshots.Sort(); if (SnapshotListChanged != null) { SnapshotListChanged(null, EventArgs.Empty); } } catch (Exception ex) { string s = ex.Message; } } }
public static SimDateTime SelectNearestSnapshot(SimDateTime sdt) { List <SimDateTime> snapshots = AvailableSnapshots; if (snapshots != null && snapshots.Count > 0) { if (snapshots.Contains(sdt)) { return(sdt); } int minOffset = 32768; foreach (SimDateTime val in snapshots) { int offset = Math.Abs(val.GetHoursOffset(sdt)); if (offset < minOffset) { minOffset = offset; } } foreach (SimDateTime val in snapshots) { int offset = Math.Abs(val.GetHoursOffset(sdt)); if (offset == minOffset) { return(val); } } return(snapshots[0]); } return(null); }
public SimDateTimeRange(EarthModel earth, SimDateTime dtStart, SimDateTime dtEnd) { this.Start = dtStart; this.End = dtEnd; this.Earth = earth; AtmList = new List <Atmosphere>(); SfcList = new List <SurfaceLevel>(); for (SimDateTime sdt = dtStart; sdt.CompareTo(dtEnd) <= 0; sdt = sdt.AddHours(earth.SnapshotLength)) { Atmosphere atm = null; SurfaceLevel sfc = null; try { earth.SetUTC(sdt); atm = new Atmosphere(earth, true); sfc = new SurfaceLevel(earth, true); } catch { atm = null; sfc = null; } if (atm != null) { AtmList.Add(atm); } if (sfc != null) { SfcList.Add(sfc); } } }