public static sinter_Variable makeNewVariable(sinter_Sim sim, string path)
        {
            sinter_Variable retVar = null;

            sinter.sinter_Variable.sinter_IOType vartype = sim.guessTypeFromSim(path);
            if (vartype == sinter.sinter_Variable.sinter_IOType.si_DOUBLE ||
                vartype == sinter.sinter_Variable.sinter_IOType.si_INTEGER ||
                vartype == sinter.sinter_Variable.sinter_IOType.si_STRING)
            {
                sinter_Variable previewVar    = new sinter_Variable();
                string[]        addressString = new string[1] {
                    path
                };
                previewVar.init(sim, vartype, addressString);
                previewVar.initializeUnits(sim);
                previewVar.initializeDescription(sim);
                retVar = previewVar;
            }
            else if (vartype == sinter.sinter_Variable.sinter_IOType.si_DOUBLE_VEC ||
                     vartype == sinter.sinter_Variable.sinter_IOType.si_INTEGER_VEC ||
                     vartype == sinter.sinter_Variable.sinter_IOType.si_STRING_VEC)
            {
                sinter_Vector previewVar    = new sinter_Vector();
                string[]      addressString = new string[1] {
                    path
                };
                previewVar.init(sim, vartype, addressString);
                previewVar.initializeUnits(sim);
                previewVar.initializeDescription(sim);
                retVar = previewVar;
            }
            return(retVar);
        }
 private void addIO(sinter_Variable.sinter_IOMode iomode, sinter_Variable.sinter_IOType type, string name, string desc, string[] addStrings, int[] bounds)
 {
     if (type == sinter_Variable.sinter_IOType.si_TABLE)
     {
         sinter_Table thisTable = new sinter_Table();
         if (bounds == null || bounds.Length < 2)
         {
             thisTable.init(name, iomode, desc, addStrings, 0, 0);
         }
         else
         {
             thisTable.init(name, iomode, desc, addStrings, bounds[0], bounds[1]);
         }
         addTable(thisTable);
     }
     else if (type == sinter_Variable.sinter_IOType.si_DOUBLE_VEC ||
              type == sinter_Variable.sinter_IOType.si_INTEGER_VEC ||
              type == sinter_Variable.sinter_IOType.si_STRING_VEC)
     {
         sinter_Vector o = new sinter_Vector();
         if (bounds == null || bounds.Length < 1)
         {
             o.init(name, iomode, type, desc, addStrings, 0);
         }
         else
         {
             o.init(name, iomode, type, desc, addStrings, bounds[0]);
         }
         addVariable(o);
     }
     else
     {
         sinter_Variable o = new sinter_Variable();
         o.init(name, iomode, type, desc, addStrings);
         if (o.isSetting)
         {
             addSetting(o);
         }
         else
         {
             addVariable(o);
         }
     }
 }
Beispiel #3
0
        //Convert from a steady state variable to a dynamic one
        public sinter_DynamicVector(sinter_Vector rhs)
        {
            o_TimeSeriesLength = 1;
            o_TimeSeriesValues = new double[1];
            addressStrings     = rhs.addressStrings;
            name         = rhs.name;
            mode         = rhs.mode;
            description  = rhs.description;
            table        = rhs.table;
            tableName    = rhs.tableName;
            tableCol     = rhs.tableCol;
            tableRow     = rhs.tableRow;
            units        = rhs.units;
            defaultUnits = rhs.defaultUnits;

            Value   = rhs.Value;
            maximum = rhs.maximum;
            minimum = rhs.minimum;
            dfault  = rhs.dfault;

            switch (rhs.type)
            {
            case sinter_Variable.sinter_IOType.si_DOUBLE_VEC:
                type = sinter_Variable.sinter_IOType.si_DY_DOUBLE_VEC;
                break;

            case sinter_Variable.sinter_IOType.si_INTEGER_VEC:
                type = sinter_Variable.sinter_IOType.si_DY_INTEGER_VEC;
                break;

            case sinter_Variable.sinter_IOType.si_STRING_VEC:
                type = sinter_Variable.sinter_IOType.si_DY_STRING_VEC;
                break;
            }
            resetToDefault();
        }
        private void processLabels(string type, string[] fields, sinter_IVariable thisIVar)
        {
            string[] labels   = new string[fields.Length - 2];
            int      labelLen = labels.Length;
            int      ii       = 0;

            for (ii = 0; ii <= labelLen - 1; ii++)
            {
                labels[ii] = fields[ii + 2];
            }

            if (type == "r")
            {
                if (thisIVar.isTable)
                {
                    sinter_Table thisTable = (sinter_Table)thisIVar;
                    thisTable.rowLabelCount = labelLen;
                    for (ii = 0; ii <= labelLen - 1; ii++)
                    {
                        thisTable.setRowLabel(ii, labels[ii]);
                    }
                }
                else
                {
                    sinter_Vector thisVar = (sinter_Vector)thisIVar;
                    thisVar.rowLabelCount = labelLen;
                    for (ii = 0; ii <= labelLen - 1; ii++)
                    {
                        thisVar.setRowLabel(ii, labels[ii]);
                    }
                }
            }
            if ((type == "c"))
            {
                sinter_Table thisTable = (sinter_Table)thisIVar;
                thisTable.colLabelCount = labelLen;
                for (ii = 0; ii <= labelLen - 1; ii++)
                {
                    thisTable.setColLabel(ii, labels[ii]);
                }
            }

            if ((type == "rs"))
            {
                if (thisIVar.isTable)
                {
                    sinter_Table thisTable = (sinter_Table)thisIVar;
                    thisTable.rowStringCount = labelLen;
                    for (ii = 0; ii <= labelLen - 1; ii++)
                    {
                        thisTable.setRowString(ii, labels[ii]);
                    }
                }
                else
                {
                    sinter_Vector thisVar = (sinter_Vector)thisIVar;
                    thisVar.rowStringCount = labelLen;
                    for (ii = 0; ii <= labelLen - 1; ii++)
                    {
                        thisVar.setRowString(ii, labels[ii]);
                    }
                }
            }
            if ((type == "cs"))
            {
                sinter_Table thisTable = (sinter_Table)thisIVar;
                thisTable.colStringCount = labelLen;
                for (ii = 0; ii <= labelLen - 1; ii++)
                {
                    thisTable.setColString(ii, labels[ii]);
                }
            }
        }
        private void processDefault(string[] fields)
        {
            int    i    = 0;
            string line = null;

            string[]         n        = null;
            int              j        = 0;
            sinter_IVariable thisIVar = (sinter_IVariable)getIOByName(fields[1]);

            if (thisIVar == null)
            {
                throw new System.IO.IOException("Cannot apply labels, Object " + fields[1] + " not found");
            }
            if (thisIVar.isScalar)
            {
                sinter_Variable thisVar = (sinter_Variable)thisIVar;
                if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE)
                {
                    thisVar.dfault = Convert.ToDouble(fields[2]);
                }
                else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER)
                {
                    thisVar.dfault = Convert.ToInt32(fields[2]);
                }
                else if (thisVar.type == sinter_Variable.sinter_IOType.si_STRING)
                {
                    thisVar.dfault = Convert.ToString(fields[2]);
                }
            }
            else if (thisIVar.isVec)
            {
                sinter_Vector thisVar = (sinter_Vector)thisIVar;
                if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE_VEC)
                {
                    thisVar.setElementDefault(0, Convert.ToDouble(fields[2]));
                }
                else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER_VEC)
                {
                    thisVar.setElementDefault(0, Convert.ToInt32(fields[2]));
                }
                for (i = 1; i <= thisVar.size - 1; i++)
                {
                    line = inFileStream.ReadLine();
                    n    = line.Split('|');
                    if (n.Length == 0)
                    {
                        return;
                    }
                    for (j = 0; j <= n.Length - 1; j++)
                    {
                        n[j] = n[j].Trim();
                    }
                    if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE_VEC)
                    {
                        thisVar.setElementDefault(i, Convert.ToDouble(n[0]));
                    }
                    else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER_VEC)
                    {
                        thisVar.setElementDefault(i, Convert.ToInt32(n[0]));
                    }
                }
            }
            else if (thisIVar.isTable)
            {
                sinter_Table thisTable = (sinter_Table)thisIVar;
                for (j = 2; j <= fields.Length - 1; j++)
                {
                    sinter_Variable thisVar = (sinter_Variable)thisTable.getElement(0, j - 2);
                    if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE)
                    {
                        thisVar.dfault = Convert.ToDouble(fields[j]);
                    }
                    else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER)
                    {
                        thisVar.dfault = Convert.ToInt32(fields[j]);
                    }
                    else
                    {
                        throw new System.IO.IOException("Cannot apply minimum on " + thisVar.name + ".  Bad type");
                    }
                }
                for (i = 1; i <= thisTable.MNRows; i++)
                {
                    line = inFileStream.ReadLine();
                    n    = line.Split('|');
                    if (n.Length == 0)
                    {
                        return;
                    }
                    for (j = 0; j <= n.Length - 1; j++)
                    {
                        n[j] = n[j].Trim();
                    }
                    for (j = 0; j <= n.Length - 1; j++)
                    {
                        sinter_Variable thisVar = (sinter_Variable)thisTable.getElement(0, j);
                        if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE)
                        {
                            thisVar.dfault = Convert.ToDouble(fields[j]);
                        }
                        else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER)
                        {
                            thisVar.dfault = Convert.ToInt32(fields[j]);
                        }
                        else
                        {
                            throw new System.IO.IOException("Cannot apply maximum on " + thisVar.name + ".  Bad type");
                        }
                    }
                }
            }
            ////////////////////////////////////////////////////////////////
            //Now that we've set all the defaults, make them the basic value
            ////////////////////////////////////////////////////////////////
            thisIVar.resetToDefault();
        }
Beispiel #6
0
        public void sendDefaults(JObject inputDict)
        {
            //If we didn't get any defaults, just return
            if (inputDict == null || inputDict.Count <= 0)
            {
                return;
            }

            checkAllInputs(inputDict);

            foreach (KeyValuePair <String, JToken> entry in inputDict)
            {
                int    row     = -1;
                int    column  = -1;
                string varName = sinter_SetupFile.parseVariable(entry.Key, ref row, ref column);

                sinter_IVariable inputVal = this.getIOByName(varName);
                if (inputVal == null)
                {
                    Console.WriteLine("Ignoring non-var: " + varName);
                }
                else if (inputVal.isOutput)
                {
                    throw new System.IO.IOException(string.Format("Variable {0} is an output varaible.  It should not be in the input list.", varName));
                }
                else
                {
                    if (inputVal.isScalar)
                    {
                        ((sinter_Variable)inputVal).dfault = sinter_HelperFunctions.convertJTokenToNative(entry.Value);
                    }
                    else if (inputVal.isVec)
                    {
                        //Check that the indexes are valid
                        sinter_Vector thisVar = (sinter_Vector)inputVal;
                        if (row >= 0)   //Editing a single entry of a vector
                        {
                            thisVar.setElementDefault(row, sinter_HelperFunctions.convertJTokenToNative(entry.Value));
                        }
                        else
                        { //copying in an entire vector at once
                            Newtonsoft.Json.Linq.JArray jsonArray = (Newtonsoft.Json.Linq.JArray)entry.Value;
                            if (thisVar.size != jsonArray.Count)
                            {
                                throw new System.IO.IOException(string.Format("Variable {0} has an index out of range.  Upper bound: {1}, bad index: {2}", varName, (int)thisVar.size - 1, row));
                            }
                            //Annoyingly, a jsonArray is not a C# Array, so I have to copy element by element, rather than just copying the array
                            for (int ii = 0; ii < thisVar.size; ++ii)
                            {
                                thisVar.setElementDefault(ii, sinter_HelperFunctions.convertJTokenToNative(jsonArray[ii]));
                            }
                        }
                    }

                    else if (inputVal.isTable)
                    {
                        sinter_Table thisTable = (sinter_Table)inputVal;
                        //Check that the indexes are valid
                        if (row >= 0 && row <= (int)thisTable.MNRows &&
                            column >= 0 && column <= (int)thisTable.MNCols)
                        {
                            thisTable.setElementDefault(row, column, sinter_HelperFunctions.convertJTokenToNative(entry.Value));
                        }
                        else
                        {
                            throw new System.IO.IOException(string.Format("Variable {0} has an index out of range. Range: {1},{2} Index: {3},{4}", varName, (int)thisTable.MNRows, (int)thisTable.MNCols, row, column));
                        }
                    }
                }

                //Now, make the default the current real value
                inputVal.resetToDefault();
            }
        }