//============================================================================ /// <summary> /// Output one line of the results file /// </summary> //============================================================================ public override void writeValues() { int Idx; TOutputScalar scalarItem; DateTime dtCurrent = FCurrOutputTime.asDateTime(); TStaticData objStaticData = new TStaticData("dd/mm/yyyy", "Time", 0, "", dtCurrent); if (_currentValues.ContainsKey(getCurrentKey(objStaticData.Name))) { _currentValues[getCurrentKey(objStaticData.Name)] = objStaticData; } else { _currentValues.Add(getCurrentKey(objStaticData.Name), objStaticData); } //addTimeSeries(dtCurrent, objStaticData); for (Idx = 0; Idx <= FColumns.Count - 1; Idx++) { scalarItem = FColumns[Idx]; objStaticData = new TStaticData(scalarItem.Units, scalarItem.Name, scalarItem.dVal, scalarItem.sVal, DateTime.Now); if (_currentValues.ContainsKey(getCurrentKey(objStaticData.Name))) { _currentValues[getCurrentKey(objStaticData.Name)] = objStaticData; } else { _currentValues.Add(getCurrentKey(objStaticData.Name), objStaticData); } //addTimeSeries(dtCurrent, objStaticData); ////_currentValues.Add(FColumns[Idx].Name.ToLower(), new TStaticData(scalarItem.Units, scalarItem.Name, scalarItem.dVal, scalarItem.sVal, DateTime.Now)); FColumns[Idx].Clear(); //Clear the current column values } }
////============================================================================ /// <summary> /// Output one line of the results file /// </summary> ////============================================================================ public override void writeValues() { String sDateStr = ""; String strVal; int Idx; TOutputScalar scalarItem; String[] colArray = new String[FColumns.Count + 1]; if (FFirstTime) { WriteHeaders(); FInitColumns = FColumns.Count; FLastColumnCount = FInitColumns; //avoid recalc apsim format string FFirstTime = false; } //Write the line of output values if (IntervalUnit <= TTimeValue.SEC) // Dates formatted according to ISO 8601 { sDateStr = FCurrOutputTime.asISODateTimeStr(); } else { if (IntervalUnit <= TTimeValue.HR) { sDateStr = FCurrOutputTime.asISODateTimeStr(); } else { if (ApsimFMT) { if (DateFMT.Length > 0) { sDateStr = FCurrOutputTime.asDateStrFMT(DateFMT); } else { sDateStr = FCurrOutputTime.asDateStr(); } } else { if (DateFMT.Length > 0) { sDateStr = FCurrOutputTime.asDateStrFMT(DateFMT); } else { sDateStr = FCurrOutputTime.asISODateStr(); } } } } if (ApsimFMT) { colArray[0] = sDateStr; } else { FOutFile.Write(sDateStr); } for (Idx = 0; Idx <= FColumns.Count - 1; Idx++) { scalarItem = FColumns[Idx]; if (scalarItem.AggregCount == 0) // It is possible that no value has been { // recorded for this column (an array may have shrunk) if (ApsimFMT) { colArray[Idx + 1] = MissingText; } else { FOutFile.Write("\t", MissingText); } } else { strVal = ""; // format the output value switch (scalarItem.baseType) { case TTypedValue.TBaseType.ITYPE_INT1: case TTypedValue.TBaseType.ITYPE_INT2: case TTypedValue.TBaseType.ITYPE_INT4: case TTypedValue.TBaseType.ITYPE_INT8: strVal = Convert.ToInt32(scalarItem.dVal).ToString(); break; case TTypedValue.TBaseType.ITYPE_SINGLE: case TTypedValue.TBaseType.ITYPE_DOUBLE: { if (Math.Log10(Math.Abs(scalarItem.dVal)) > 10) { strVal = String.Format(CultureInfo.InvariantCulture, "{0:e" + scalarItem.decPl + "}", scalarItem.dVal); } else { strVal = String.Format(CultureInfo.InvariantCulture, "{0:f" + scalarItem.decPl + "}", scalarItem.dVal); } } break; case TTypedValue.TBaseType.ITYPE_CHAR: strVal = scalarItem.sVal; break; case TTypedValue.TBaseType.ITYPE_STR: strVal = scalarItem.sVal; break; case TTypedValue.TBaseType.ITYPE_BOOL: strVal = scalarItem.dVal.ToString(); break; } if (ApsimFMT) { colArray[Idx + 1] = strVal; } else { FOutFile.Write("\t" + strVal); // Write the current value of the column } } } FColumns[Idx].Clear(); // Clear the current column values } if (ApsimFMT) { if (FLastColumnCount != FColumns.Count) { RecalcApsimHdrFmt(); //update the header format based on the FColumns FLastColumnCount = FColumns.Count; } FOutFile.Write(FHeaderfmt.ToString(), colArray); } FOutFile.WriteLine(); }