/// <summary> /// Check if the time set of a provider fits accoring to what the consumer /// requires. This method can be used to check of the providing component yet needs to do another Update() step. /// </summary> /// <param name="provider">The provider</param> /// <param name="consumer">The consumer</param> /// <returns>True if the time set fits</returns> public static bool OutputAndInputTimeSetsFit(ITimeSpaceExchangeItem provider, ITimeSpaceExchangeItem consumer) { if (provider == null) { throw new ArgumentNullException("provider"); } if (consumer == null) { throw new ArgumentNullException("consumer"); } bool timeFits = true; ITimeSet sourceTimeSet = provider.TimeSet; ITimeSet targetTimeSet = consumer.TimeSet; if (sourceTimeSet == null) { if (targetTimeSet != null) { // NOTE: Source has no timeset specification, source has. // Source fits target if target requires only one time step. timeFits = targetTimeSet.Times.Count == 1; } } else { if (targetTimeSet == null) { // NOTE: Target has no timeset specification, source has. // Source fits target if source has values for only one time step available. timeFits = sourceTimeSet.Times.Count == 1; } else { /* * SH/AM: TODO I Think this code is wrong, IOutput and IAdaptedOutput should be treated the same * (SH: reactivated (if (provider is IAdaptedOutput) code * to make things work for time extrapolators again. */ // Both source and target have time set specification if (provider is ITimeSpaceAdaptedOutput) { // NOTE: Source is an adaptedOutput that has a time set. // Most probably a timeinterpolator, but: // TODO: Check how we can find out that it is a time interpolator. // For now: check if the target's last required time is included in the source's time horizon if (sourceTimeSet.TimeHorizon == null) { throw new Exception("Error when checking if the times of AdaptedOutput \"" + provider.Id + " fits the times required by inputItem \"" + consumer.Id + "\": no time horizon available in the adaptedOutput"); } ITime lastRequiredTime = targetTimeSet.Times[targetTimeSet.Times.Count - 1]; double lastRequiredTimeAsMJD = lastRequiredTime.End().StampAsModifiedJulianDay; double endOfSourceTimeHorizon = sourceTimeSet.TimeHorizon.End().StampAsModifiedJulianDay; timeFits = lastRequiredTimeAsMJD <= (endOfSourceTimeHorizon + Time.EpsilonForTimeCompare); } else { timeFits = false; // regular (output) exchange item, check if all times fit IList <ITime> sourceTimes = sourceTimeSet.Times; IList <ITime> requiredTimes = targetTimeSet.Times; if (sourceTimes.Count == requiredTimes.Count) { timeFits = true; for (int timeIndex = 0; timeIndex < requiredTimes.Count; timeIndex++) { if ((requiredTimes[timeIndex].DurationInDays > 0 && !(sourceTimes[timeIndex].DurationInDays > 0)) || (sourceTimes[timeIndex].DurationInDays > 0 && !(requiredTimes[timeIndex].DurationInDays > 0))) { throw new Exception("Incompatible times (stamp versus span) between outputItem \"" + provider.Id + " and inputItem \"" + consumer.Id + "\""); } if (requiredTimes[timeIndex].Equals(sourceTimes[timeIndex])) { continue; } timeFits = false; break; } } } } } return(timeFits); }