public IVariable Subtract(IVariable x, GekkoTime t) { switch (x.Type()) { case EVariableType.Val: { return(Operators.DateVal.Subtract(this, (ScalarVal)x)); } break; case EVariableType.Date: { int obs = GekkoTime.Observations(((ScalarDate)x).date, this.date) - 1; if (obs < 0) { G.Writeln(); G.Writeln("*** ERROR: Subtraction of two dates gave negative number of observations: " + obs); throw new GekkoException(); } return(new ScalarVal(obs)); } break; default: { G.Writeln2("*** ERROR: Type error regarding subtract"); throw new GekkoException(); } break; } }
/// <summary> /// Gets a pointer to the data array of the timeseries corresponding to the given time period. /// </summary> /// <param name="index1">The array index corresponding to the start of the period</param> /// <param name="index2">The array index corresponding to the end of the period</param> /// <param name="gt1">The start of the period.</param> /// <param name="gt2">The end of the period.</param> /// <param name="setStartEndPeriods">Normally false.</param> /// <returns>A pointer to the data array that contains the data. This is a pointer to the REAL data, so /// DO NOT change the array values unless you know what you are doing!</returns> /// <exception cref="GekkoException">Exception if frequency of timeseries and periods differ.</exception> public double[] GetDataSequence(out int index1, out int index2, GekkoTime gt1, GekkoTime gt2, bool setStartEndPeriods) { //NB NB NB NB NB //NB NB NB NB NB //NB NB NB NB NB BEWARE: the array returned is a pointer to the REAL datacontainer for the timeseries. So do not alter the array unless you are ACTUALLY altering the timeseries (for instance UPD, GENR etc.) //NB NB NB NB NB //NB NB NB NB NB // It might be called half overlapped like this: // +++++++++++++++++++++++ // --------------- // if so, the array is resized before it is returned. // if the array is null, it will be created when calling this method. // //Also beware that if the array returned is touched afterwards, the timeseries will be dirty. This only happens in the //simulation code, though. See #98726527! //DimensionCheck(); if (this.isTimeless) { int n = GekkoTime.Observations(gt1, gt2); double[] numbers = new double[n]; for (int i = 0; i < n; i++) { numbers[i] = this.dataArray[0]; } index1 = 0; index2 = n - 1; return(numbers); } if (this.freqEnum != gt1.freq || gt1.freq != gt2.freq) { //This check: better safe than sorry! //See comment to GetData() G.Writeln2("*** ERROR: Freq mismatch"); throw new GekkoException(); } if (this.dataArray == null) { InitDataArray(gt1); } ; index1 = GetArrayIndex(gt1); index2 = GetArrayIndex(gt2); if (index1 < 0 || index1 >= this.dataArray.Length || index2 < 0 || index2 >= this.dataArray.Length) { index1 = ResizeDataArray(gt1); index2 = ResizeDataArray(gt2); //this would never change index1 } if (setStartEndPeriods) //only relevant if the returned arrays is actually tampered with, which is normally NOT the case (only for a[,] and b[] array stuff in simulation) { if (index2 > this.lastPeriodPositionInArray) { this.lastPeriodPositionInArray = index2; } if (index1 < this.firstPeriodPositionInArray) { this.firstPeriodPositionInArray = index1; } } return(this.dataArray); }