//get start times from event or interval list public static List <double> GetStartTimes(Section item) { List <IAgCrdn> events = new List <IAgCrdn>(); List <double> startTimes = new List <double>(); if (item.isLinked && !item.linkedToList) { events = GetAllEventInstances(); int eventCount = events.Count; for (int i = 0; i < eventCount; i++) { IAgCrdnEvent currentEvent = (IAgCrdnEvent)events[i]; if (events[i].Name == item.linkTimeInstanceName) { IAgCrdnEventFindOccurrenceResult epochResult = (IAgCrdnEventFindOccurrenceResult)currentEvent.FindOccurrence(); double epoch = epochResult.Epoch; string epochStr = epoch.ToString(); try { string epochInEpSec = CommonData.StkRoot.ExecuteCommand("Units_Convert * Date GregorianUTC EpSec \"" + epochStr + "\"").ToString(); if (startTimes.Contains(Convert.ToDouble(epochInEpSec))) { } else { startTimes.Add(Convert.ToDouble(epochInEpSec)); } } catch (Exception) { if (startTimes.Contains(epoch)) { } else { startTimes.Add(epoch); } } } } } else if (item.linkedToList) { events = GetAllEventInstances(); int eventCount = events.Count; for (int i = 0; i < item.linkedToListInstantNames.Count; i++) { for (int j = 0; j < eventCount; j++) { IAgCrdnEvent currentEvent = (IAgCrdnEvent)events[j]; if (events[j].Name == item.linkedToListInstantNames[i]) { IAgCrdnEventFindOccurrenceResult epochResult = (IAgCrdnEventFindOccurrenceResult)currentEvent.FindOccurrence(); double epoch = epochResult.Epoch; string epochStr = epoch.ToString(); try { string epochStrTry = CommonData.StkRoot.ExecuteCommand("Units_Convert * Date GregorianUTC EpSec \"" + epochStr + "\"").ToString(); if (startTimes.Contains(Convert.ToDouble(epochStrTry))) { } else { startTimes.Add(Convert.ToDouble(epochStrTry)); } } catch (Exception) { if (startTimes.Contains(epoch)) { } else { startTimes.Add(epoch); } } } } } } else { startTimes.Add(Convert.ToDouble(item.startTimeValue)); } //sort start times in ascending order double temp1 = 0.0; double temp2 = 0.0; for (int i = 0; i < startTimes.Count; i++) { temp1 = startTimes[i]; for (int j = 0; j < startTimes.Count; j++) { temp2 = startTimes[j]; if (temp1 == temp2) { } else if (temp2 < temp1 && j > i) { startTimes[i] = temp2; startTimes[j] = temp1; temp1 = startTimes[i]; } else { } } } return(startTimes); }
//get start time and timestep to pull attitude data public static Tuple <int, double, double> GetStartTimeAndMinimumTimeStep() { int count = 0; double timeStep1 = 1.0; double timeStepCurrent = 1.0; double startTime = 10000000000; double currentStartTime = 0.0; string startTimeStr = null; List <IAgCrdn> events = new List <IAgCrdn>(); IAgCrdn accessEvents; foreach (Section item in CommonData.sectionList) { count++; if (item.linkedToAttitude && item.objectName == CommonData.MainBody) { if (item.isLinked && !item.linkedToList) { events = GetAllEventInstances(); int eventCount = events.Count; for (int i = 0; i < eventCount; i++) { IAgCrdnEvent currentEvent = (IAgCrdnEvent)events[i]; if (events[i].Name == item.linkTimeInstanceName) { IAgCrdnEventFindOccurrenceResult epochResult = (IAgCrdnEventFindOccurrenceResult)currentEvent.FindOccurrence(); double epoch = epochResult.Epoch; string epochStr = epoch.ToString(); try { string cmd = "Units_Convert * Date GregorianUTC EpSec \"" + epochStr + "\""; string epochInEpSec = CommonData.StkRoot.ExecuteCommand(cmd).ToString(); currentStartTime = Convert.ToDouble(epochInEpSec); timeStepCurrent = GetTimestep(epochInEpSec); } catch (Exception) { currentStartTime = Convert.ToDouble(epoch); timeStepCurrent = GetTimestep(epochStr); } } } } else if (item.linkedToList) { double listCurrentStart = startTime; double listCurrentTimestep = timeStepCurrent; events = GetAllEventInstances(); int eventCount = events.Count; for (int i = 0; i < item.linkedToListInstantNames.Count; i++) { for (int j = 0; j < eventCount; j++) { IAgCrdnEvent currentEvent = (IAgCrdnEvent)events[j]; if (events[j].Name == item.linkedToListInstantNames[i]) { IAgCrdnEventFindOccurrenceResult epochResult = (IAgCrdnEventFindOccurrenceResult)currentEvent.FindOccurrence(); double epoch = epochResult.Epoch; string epochStr = epoch.ToString(); try { string cmd = "Units_Convert * Date GregorianUTC EpSec \"" + epochStr + "\""; epochStr = CommonData.StkRoot.ExecuteCommand(cmd).ToString(); listCurrentStart = Convert.ToDouble(epochStr); timeStepCurrent = GetTimestep(epochStr); } catch (Exception) { listCurrentStart = Convert.ToDouble(epoch); timeStepCurrent = GetTimestep(epochStr); } if (count == 1) { currentStartTime = listCurrentStart; } else if (listCurrentStart < currentStartTime) { currentStartTime = listCurrentStart; } count++; //check decimals to get timestep if (listCurrentTimestep < timeStepCurrent) { timeStepCurrent = listCurrentTimestep; } } } } } else { startTimeStr = item.startTimeValue; timeStepCurrent = GetTimestep(startTimeStr); currentStartTime = Convert.ToDouble(item.startTimeValue); } //Check timestep from this articulation to the previous ones to get the smallest one if (timeStepCurrent < timeStep1) { timeStep1 = timeStepCurrent; } //Check current startime to previous ones to get the first one if (count == 1) { startTime = currentStartTime; } else if (currentStartTime < startTime) { startTime = currentStartTime; } } } Tuple <int, double, double> timestepValues = new Tuple <int, double, double>(count, timeStep1, startTime); return(timestepValues); }