/// <summary> /// calculate main field and field change at a 'spot' in time and space /// </summary> /// <param name="CalculationOptions">details of the time and space to for which to calculate</param> /// <param name="dateOfCalc">The DateTime object for the calculation date</param> /// <param name="magModels">the models loaded by the Model Reader</param> /// <param name="internalSH">internal coeffiecients for a particular date</param> /// <param name="externalSH">external coeffiecients for a particular date</param> /// <param name="earthRadius">Optional: Radius of the earth used by the model</param> /// <returns>The result of the magnetic calculation</returns> public static MagneticCalculations SpotCalculation(CalculationOptions CalculationOptions, DateTime dateOfCalc, MagneticModelSet magModels, Coefficients internalSH, Coefficients externalSH, double earthRadius = Constants.EarthsRadiusInKm) { /* call procedure GETFIELD - values returned in geomagfield*/ var fieldCalculations = GetField(CalculationOptions, internalSH, externalSH, earthRadius); GeoMagVector svCalculations = null; if (CalculationOptions.SecularVariation) { double date1 = -1; double date2 = -1; CalculateDatesForVariation(CalculationOptions.StartDate.ToDecimal(), magModels.MinDate, magModels.MaxDate, out date1, out date2); /* get coefficients and field for date1 */ var SVintSH = new Coefficients(); var SVextSH = new Coefficients(); magModels.GetIntExt(date1, out SVintSH, out SVextSH); var geomagfield1 = GetField(CalculationOptions, SVintSH, SVextSH, earthRadius); /* get coefficients and field for date2 */ magModels.GetIntExt(date2, out SVintSH, out SVextSH); var geomagfield2 = GetField(CalculationOptions, SVintSH, SVextSH, earthRadius); /* calculate changes - difference between * fields 1 & 2 returned in fielddiffs */ svCalculations = geomagfield2.Subtract(geomagfield1); } /* end of secular variation calc. for SPOT */ return(new MagneticCalculations(dateOfCalc, fieldCalculations, svCalculations)); }
public void MagneticCalculations(CalculationOptions inCalculationOptions) { _CalculationOptions = null; ResultsOfCalculation = null; if (_Models == null || _Models.NumberOfModels.Equals(0)) { throw new GeoMagExceptionModelNotLoaded("Error: No models avaliable for calculation"); } if (!_Models.IsDateInRange(inCalculationOptions.StartDate)) { throw new GeoMagExceptionOutOfRange(string.Format("Error: the date {0} is out of range for this model{1}The valid date range for the is {2} to {3}", inCalculationOptions.StartDate.ToShortDateString(), Environment.NewLine, _Models.MinDate.ToDateTime().ToShortDateString(), _Models.MaxDate.ToDateTime().ToShortDateString())); } if (inCalculationOptions.EndDate.Equals(DateTime.MinValue)) { inCalculationOptions.EndDate = inCalculationOptions.StartDate; } if (!_Models.IsDateInRange(inCalculationOptions.EndDate)) { throw new GeoMagExceptionOutOfRange(string.Format("Error: the date {0} is out of range for this model{1}The valid date range for the is {2} to {3}", inCalculationOptions.EndDate.ToShortDateString(), Environment.NewLine, _Models.MinDate.ToDateTime().ToShortDateString(), _Models.MaxDate.ToDateTime().ToShortDateString())); } TimeSpan timespan = (inCalculationOptions.EndDate.Date - inCalculationOptions.StartDate.Date); double dayInc = inCalculationOptions.StepInterval < 1 ? 1 : inCalculationOptions.StepInterval; double dateIdx = 0; ResultsOfCalculation = new List <MagneticCalculations>(); _CalculationOptions = new CalculationOptions(inCalculationOptions); while (dateIdx <= timespan.Days) { var internalSH = new Coefficients(); var externalSH = new Coefficients(); DateTime intervalDate = _CalculationOptions.StartDate.AddDays(dateIdx); _Models.GetIntExt(intervalDate.ToDecimal(), out internalSH, out externalSH); var magCalcDate = Calculator.SpotCalculation(_CalculationOptions, intervalDate, _Models, internalSH, externalSH, _Models.EarthRadius); if (magCalcDate != null) { ResultsOfCalculation.Add(magCalcDate); } dateIdx = ((dateIdx < timespan.Days) && ((dateIdx + dayInc) > timespan.Days)) ? timespan.Days : dateIdx + dayInc; } }