Beispiel #1
0
        //============================================================================
        /// <summary>
        ///
        /// </summary>
        /// <param name="compID"></param>
        /// <param name="parentCompID"></param>
        /// <param name="messageCallback"></param>
        //============================================================================
        public TextOutInstance(uint compID, uint parentCompID, MessageFromLogic messageCallback)
            : base(compID, parentCompID, messageCallback, _STYPE, _SVERSION, _SAUTHOR)
        {
            if (isWaterCastSim)
            {
                FReporter = new TStaticReporter();
            }
            else
            {
                FReporter = new TTextReporter();
            }
            FRequests      = new List <string>();
            FTimeStep      = new TTimeStep();
            FFirstTime     = true;
            FSummaryStream = null;
            WriteEventIds  = new List <int>();
            RegExtraEvents = new Dictionary <int, string>();

            TInitValue newProperty;

            //addDriver(sName,  ID,      lMinConn, lMaxConn, sUnit, bIsArray, sType)
            addDriver("time", drvTIME, 1, 1, "-", false, TTimeStep.typeTIMESTEP, "", "", 0);

            //addProperty(              sName,         ID,             bRead,bWrite,bInit, sUnit,bIsArray,sType)
            addProperty("title", prpTITLE, true, true, true, "-", false, TTypedValue.STYPE_STR, "Title of the file", "");
            addProperty("filename", prpFILE, true, true, true, "-", false, TTypedValue.STYPE_STR, "Output file", "Full path of the output file");
            addProperty("interval", prpINTV, true, false, true, "-", false, TTypedValue.STYPE_INT4, "Logging interval", "");
            setPropertyRange(prpINTV, 1, 1, 365);

            newProperty = addProperty("intervalunit", prpUNIT, true, false, true, "-", false, TTypedValue.STYPE_STR, "", "");
            newProperty.setDefault("day");

            newProperty = addProperty("outputs", prpOUTS, true, false, true, "-", false, TGenericReporter.typeOUTPUTS, "", "");
            newProperty.item(0).member("decplaces").setValue(2);

            addProperty("summary_file", prpSUMMARYFILE, true, true, true, "-", false, TTypedValue.STYPE_STR, "Summary file name", "");
            addProperty("apsim_format", prpAPSIMFMT, true, true, true, "-", false, TTypedValue.STYPE_BOOL, "Use an APSIM output format", "");
            addProperty("outputfrequency", prpOUTFREQ, true, true, true, "-", true, TTypedValue.STYPE_STR, "Report when these events are received", "");
            addProperty("dateformat", prpDATEFMT, true, true, true, "-", false, TTypedValue.STYPE_STR, "Date format string", "Use: dd/mm/yyyy etc. Ignored if empty string.");

            addWritingEvent(evtEXEC, "update_outputs");
        }
Beispiel #2
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);
            }
        }