Exemple #1
0
        //=========================================================================
        /// <summary>
        /// Read the scalar value in the array at the specified index.
        /// </summary>
        /// <param name="initName">Name of the array init property.</param>
        /// <param name="idx">Item index in the array.</param>
        /// <param name="value">The value found at the index. Returns false if not found.</param>
        //=========================================================================
        public void readElement(string initName, int idx, ref bool value)
        {
            TTypedValue aValue = null;

            aValue = findElementRead(initName, idx);
            if (aValue != null)
            {
                value = aValue.asBool();
            }
            else
            {
                value = false;
            }
        }
        //============================================================================
        /// <summary>
        /// Updates the current value of the variable in the output column. Handles
        /// aggregation within reporting intervals
        /// Assumes:
        ///  * aValue is a scalar of the correct type
        /// </summary>
        /// <param name="aValue"></param>
        //============================================================================
        public void Update(TTypedValue aValue)
        {
            switch (baseType)
            {
            case TTypedValue.TBaseType.ITYPE_INT1:
            case TTypedValue.TBaseType.ITYPE_INT2:
            case TTypedValue.TBaseType.ITYPE_INT4:
            case TTypedValue.TBaseType.ITYPE_INT8:
            {
                if (AggregCount == 0)
                {
                    dVal = aValue.asInt();
                }
                else
                {
                    switch (Aggreg)
                    {
                    case TGenericReporter.AggregType.aggSum: dVal = dVal + aValue.asInt();
                        break;

                    case TGenericReporter.AggregType.aggMax: dVal = Math.Max(dVal, aValue.asInt());
                        break;

                    case TGenericReporter.AggregType.aggMin: dVal = Math.Min(dVal, aValue.asInt());
                        break;
                    }
                }
            }
            break;

            case TTypedValue.TBaseType.ITYPE_SINGLE:
            {
                if (AggregCount == 0)
                {
                    dVal = aValue.asSingle();
                }
                else
                {
                    switch (Aggreg)
                    {
                    case TGenericReporter.AggregType.aggSum: dVal = dVal + aValue.asSingle();
                        break;

                    case TGenericReporter.AggregType.aggAve: dVal = (dVal * AggregCount + aValue.asSingle()) / (AggregCount + 1);
                        break;

                    case TGenericReporter.AggregType.aggMax: dVal = Math.Max(dVal, aValue.asSingle());
                        break;

                    case TGenericReporter.AggregType.aggMin: dVal = Math.Min(dVal, aValue.asSingle());
                        break;
                    }
                }
            }
            break;

            case TTypedValue.TBaseType.ITYPE_DOUBLE:
            {
                if (AggregCount == 0)
                {
                    dVal = aValue.asDouble();
                }
                else
                {
                    switch (Aggreg)
                    {
                    case TGenericReporter.AggregType.aggSum: dVal = dVal + aValue.asDouble();
                        break;

                    case TGenericReporter.AggregType.aggAve: dVal = (dVal * AggregCount + aValue.asDouble()) / (AggregCount + 1);
                        break;

                    case TGenericReporter.AggregType.aggMax: dVal = Math.Max(dVal, aValue.asDouble());
                        break;

                    case TGenericReporter.AggregType.aggMin: dVal = Math.Min(dVal, aValue.asDouble());
                        break;
                    }
                }
            }
            break;

            case TTypedValue.TBaseType.ITYPE_BOOL:
            {
                if (AggregCount == 0)
                {
                    sVal = aValue.asBool().ToString();
                }
                else
                {
                    switch (Aggreg)
                    {
                    case TGenericReporter.AggregType.aggMax:
                    {
                        bool bVal = Convert.ToBoolean(sVal) || aValue.asBool();
                        sVal = bVal.ToString();
                    }
                    break;

                    case TGenericReporter.AggregType.aggMin:
                    {
                        bool bVal = Convert.ToBoolean(sVal) && aValue.asBool();
                        sVal = bVal.ToString();
                    }
                    break;
                    }
                }
            }
            break;

            case TTypedValue.TBaseType.ITYPE_CHAR:
            case TTypedValue.TBaseType.ITYPE_STR:
            {
                if (AggregCount == 0)
                {
                    sVal = aValue.asStr();
                }
            }
            break;
            }
            AggregCount++;
        }
Exemple #3
0
        //==========================================================================
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyID"></param>
        /// <param name="aValue"></param>
        //==========================================================================
        public override void initProperty(int propertyID, TTypedValue aValue)
        {
            String      sText;
            uint        Idx;
            TTypedValue varItem;

            if (!(FReporter is TStaticReporter) && (isWaterCastSim))
            {
                FReporter = null;

                FReporter = new TStaticReporter();
            }

            switch (propertyID)
            {
            case prpFILE:
            {
                FReporter.FileName = aValue.asString();
            } break;

            case prpINTV:
            {
                FReporter.ReportInterval = aValue.asInteger();
            } break;

            case prpUNIT:
            {
                sText = aValue.asString().ToLower().Trim();
                for (int i = TTimeValue.SEC; i <= TTimeValue.YR; i++)
                {
                    if (sText == TTimeValue.TIMETEXTS[i - 1])
                    {
                        FReporter.IntervalUnit = i;
                    }
                }
            } break;

            case prpOUTS:
            {
                for (Idx = 1; Idx <= aValue.count(); Idx++)
                {
                    varItem = aValue.item(Idx);
                    FReporter.addVariable(varItem.member("varname").asString(),
                                          varItem.member("alias").asString(),
                                          varItem.member("decplaces").asInteger(),
                                          FReporter.parseAggreg(varItem.member("aggreg").asString()));
                }
            } break;

            case prpSUMMARYFILE:
            {
                if (aValue.asString().Length == 0)
                {
                    FSummaryStream = null;
                }
                else
                {
                    FSummaryStream = new StreamWriter(aValue.asString());
                    addEvent("summaryFileWrite", evtSUMMARYWRITE, TypeSpec.KIND_SUBSCRIBEDEVENT, typeSUMMARYWRITE, "", "", 0);
                    defineEventState(evtSUMMARYWRITE, stateDOWRITE, TStateMachine.NONLOGIC);
                    defineEventTransition(evtSUMMARYWRITE, stateDOWRITE, 0, TStateMachine.DONE, false);
                }
            } break;

            case prpAPSIMFMT:
            {
                FReporter.ApsimFMT = aValue.asBool();
            } break;

            case prpTITLE:
            {
                FReporter.Title = aValue.asStr();
            } break;

            case prpOUTFREQ:
            {
                uint count = aValue.count();
                for (uint i = 1; i <= count; i++)
                {
                    //for each new event; add it to the list and also register it
                    String eventName = aValue.item(i).asStr().ToLower();
                    if (!RegExtraEvents.ContainsValue(eventName))
                    {
                        int eventId = evtEXTRAWRITE + RegExtraEvents.Count;
                        addWritingEvent(eventId, eventName);
                        RegExtraEvents.Add(eventId, eventName);
                    }
                }
            } break;

            case prpDATEFMT:
            {
                FReporter.DateFMT = aValue.asStr();
            }
            break;

            default: throw (new ApplicationException("Invalid ID code in initProperty()"));
            }

            if ((propertyID == prpFILE) || (propertyID == prpINTV) || //Store the initial value for later reading
                (propertyID == prpUNIT) || (propertyID == prpOUTS) ||
                (propertyID == prpSUMMARYFILE))
            {
                propertyList[propertyID].setValue(aValue);
            }
        }