예제 #1
0
        public virtual void init(string thisName, sinter_IOMode iomode, sinter_IOType thisType, string desc, string[] addStrings)
        {
            o_name           = thisName;
            o_mode           = iomode;
            o_type           = thisType;
            o_description    = desc;
            o_addressStrings = addStrings;
            o_table          = null;
            o_tableName      = null;
            o_tableCol       = 0;
            o_tableRow       = 0;

            makeValue();
            determineIsSetting();
        }
예제 #2
0
        /**
         * This version of init attempts to discover as much as possible about the variable automatically.
         * This is useful for the GUI, when the user selects a variable off the tree we need to try to figure out all about it.
         **/
        public virtual void init(sinter_Sim sim, sinter.sinter_Variable.sinter_IOType type, string[] addStrings)
        {
            o_addressStrings = addStrings;
            IList <string> splitPath = sim.parsePath(o_addressStrings[0]);

            o_name        = getVariableName(sim, addStrings[0]);
            o_mode        = sinter_IOMode.si_IN; //Default to input
            o_type        = type;
            o_description = null;
            o_table       = null;
            o_tableName   = null;
            o_tableCol    = 0;
            o_tableRow    = 0;

            makeValue();
            recvFromSim(sim);
            setDefaultToValue();
        }
예제 #3
0
 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);
         }
     }
 }
예제 #4
0
        /**
         * bool checkAllInputs(JObject inputDict)
         *
         *  Checks to make sure every input in the sinter configuration is represented in the input dictionary
         *  Mostly useful with sinter config file format 0.1, where there were seperate defaults and input files,
         *  neither of which was guarnateed to have all the variables.
         **/
        public bool checkAllInputs(JObject inputDict)
        {
            //If we didn't get any defaults, just return
            if (inputDict == null)
            {
                return(false);
            }

            for (int ii = 1; ii <= this.countIO; ++ii)
            {
                sinter_IVariable inputVal = this.getIOByIndex(ii);
                if (inputVal.isInput)
                {
                    if (inputVal.isTable)
                    {
                        sinter_Table thisInput = (sinter_Table)inputVal;
                        string       varName   = inputVal.name;
                        int          rowMax    = (int)thisInput.MNRows;
                        int          colMax    = (int)thisInput.MNCols;
                        for (int row = 0; row <= rowMax; ++row)
                        {
                            for (int col = 0; col <= colMax; ++col)
                            {
                                string indexedVarName = string.Format("{0}[{1},{2}]", varName, row, col);
                                if (inputDict[indexedVarName] == null)
                                {
                                    throw new System.IO.IOException(string.Format("Required Input varaible {0} is not represented in the input dictionary!", indexedVarName));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (inputDict[inputVal.name] == null)
                        {
                            throw new System.IO.IOException(string.Format("Required Input varaible {0} is not represented in the input dictionary!", inputVal.name));
                        }
                    }
                }
            }
            return(true);
        }
예제 #5
0
        //old fashioned output, deprecated.
        public JObject getOutputsToJSON_1()
        {
            JObject outputDict = new JObject();

            for (int ii = 1; ii <= this.countIO; ++ii)
            {
                sinter_IVariable outputVal = this.getIOByIndex(ii);
                string           varname   = outputVal.name;
                if (outputVal.isTable)
                {
                    sinter_Table outputTable = (sinter_Table)outputVal;
                    int          nrows       = (int)outputTable.MNRows;
                    int          ncols       = (int)outputTable.MNCols;
                    for (int irow = 0; irow <= nrows; ++irow)
                    {
                        for (int icol = 0; icol <= ncols; ++icol)
                        {
                            outputDict.Add(varname + "[" + irow + "," + icol + "]", sinter_HelperFunctions.convertSinterValueToJToken(outputTable.getVariable(irow, icol)));
                        }
                    }
                }
                else if (outputVal.isVec)
                {
                    sinter_Variable             outputVar = (sinter_Variable)outputVal;
                    Newtonsoft.Json.Linq.JArray jsonArray = new Newtonsoft.Json.Linq.JArray(outputVar.Value);
                    outputDict.Add(varname, jsonArray);
                }
                else
                {
                    sinter_Variable outputVar = (sinter_Variable)outputVal;
                    outputDict.Add(varname, sinter_HelperFunctions.convertSinterValueToJToken(outputVar));
                }
            }

            //Special case, Always put the run Status put the status in the outputs as "status".
            outputDict.Add("status", (int)runStatus);

            return(outputDict);
        }
예제 #6
0
        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]);
                }
            }
        }
예제 #7
0
        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();
        }
예제 #8
0
 public void addTable(sinter_Table var)
 {
     o_AllIVariable.Add(var, var.name);
     o_Tables.Add(var, var.name);
 }
예제 #9
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();
            }
        }