示例#1
0
        /// <summary>
        /// Sets the value at the specified position to the specified value. </summary>
        /// <param name="value"> the value to set the cell to. </param>
        /// <param name="row"> the row of the cell for which to set the value. </param>
        /// <param name="col"> the col of the cell for which to set the value. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            StateMod_StreamGage sg = (StateMod_StreamGage)_data.get(row);

            switch (col)
            {
            case COL_ID:
                sg.setID((string)value);
                break;

            case COL_NAME:
                sg.setName((string)value);
                break;

            case COL_NODE_ID:
                sg.setCgoto((string)value);
                break;

            case COL_DAILY_ID:
                sg.setCrunidy((string)value);
                break;
            }

            base.setValueAt(value, row, col);
        }
        /// <summary>
        /// Read the stream gage station file and store return a Vector of StateMod_StreamGage. </summary>
        /// <returns> a list of StateMod_StreamGage. </returns>
        /// <param name="filename"> Name of file to read. </param>
        /// <exception cref="Exception"> if there is an error reading the file. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static java.util.List<StateMod_StreamGage> readStateModFile(String filename) throws Exception
        public static IList <StateMod_StreamGage> readStateModFile(string filename)
        {
            string rtn = "StateMod_StreamGage.readStateModFile";
            IList <StateMod_StreamGage> theRivs = new List <StateMod_StreamGage>();
            string         iline;
            IList <object> v = new List <object>(5);

            int[] format_0;
            int[] format_0w;
            format_0     = new int[5];
            format_0[0]  = StringUtil.TYPE_STRING;
            format_0[1]  = StringUtil.TYPE_STRING;
            format_0[2]  = StringUtil.TYPE_STRING;
            format_0[3]  = StringUtil.TYPE_STRING;
            format_0[4]  = StringUtil.TYPE_STRING;
            format_0w    = new int [5];
            format_0w[0] = 12;
            format_0w[1] = 24;
            format_0w[2] = 12;
            format_0w[3] = 1;
            format_0w[4] = 12;
            int linecount = 0;

            if (Message.isDebugOn)
            {
                Message.printDebug(10, rtn, "in " + rtn + " reading file: " + filename);
            }
            StreamReader @in = null;

            try
            {
                @in = new StreamReader(filename);
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    ++linecount;
                    // check for comments
                    if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0)
                    {
                        continue;
                    }

                    // allocate new StateMod_StreamGage node
                    StateMod_StreamGage aRiverNode = new StateMod_StreamGage();

                    // line 1
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, rtn, "line 1: " + iline);
                    }
                    StringUtil.fixedRead(iline, format_0, format_0w, v);
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, rtn, "Fixed read returned " + v.Count + " elements");
                    }
                    aRiverNode.setID(((string)v[0]).Trim());
                    aRiverNode.setName(((string)v[1]).Trim());
                    aRiverNode.setCgoto(((string)v[2]).Trim());
                    // Space
                    aRiverNode.setCrunidy(((string)v[4]).Trim());

                    // add the node to the vector of river nodes
                    theRivs.Add(aRiverNode);
                }
            }
            catch (Exception e)
            {
                // Clean up...
                Message.printWarning(3, rtn, "Error reading \"" + filename + "\" at line " + linecount);
                throw e;
            }
            finally
            {
                // Clean up...
                if (@in != null)
                {
                    @in.Close();
                }
            }
            return(theRivs);
        }