/// <summary>
        /// Sets up the data to be displayed in the table. </summary>
        /// <param name="data"> a Vector of StateMod_StreamEstimate_Coefficients objects from
        /// which the data to be be displayed in the table will be gathered. </param>
        private void setupData(System.Collections.IList data)
        {
            int num  = 0;
            int size = data.Count;
            StateMod_StreamEstimate_Coefficients coeff = null;

            __data = new System.Collections.IList[__COLUMNS];
            for (int i = 0; i < __COLUMNS; i++)
            {
                __data[i] = new List <object>();
            }

            string id       = null;
            int    rowCount = 0;
            int    M        = 0;
            int    N        = 0;

            for (int i = 0; i < size; i++)
            {
                coeff = (StateMod_StreamEstimate_Coefficients)data[i];
                id    = coeff.getID();
                M     = coeff.getM();
                N     = coeff.getN();
                num   = M < N ? N : M;
                for (int j = 0; j < num; j++)
                {
                    __data[COL_ID].Add(id);

                    if (j < N)
                    {
                        __data[COL_STREAM_NAME].Add(new double?(coeff.getCoefn(j)));
                        __data[COL_UPSTREAM_GAGE].Add(coeff.getUpper(j));
                    }
                    else
                    {
                        __data[COL_STREAM_NAME].Add(new double?(-999));
                        __data[COL_UPSTREAM_GAGE].Add("");
                    }

                    if (j < M)
                    {
                        __data[COL_GAIN_TERM_PRO].Add(new double?(coeff.getProratnf()));
                        __data[COL_GAIN_TERM_WT].Add(new double?(coeff.getCoefm(j)));
                        __data[COL_GAIN_TERM_GAGE_ID].Add(coeff.getFlowm(j));
                    }
                    else
                    {
                        __data[COL_GAIN_TERM_PRO].Add(new double?(-999));
                        __data[COL_GAIN_TERM_WT].Add(new double?(-999));
                        __data[COL_GAIN_TERM_GAGE_ID].Add("");
                    }
                    rowCount++;
                }
            }
            _rows = rowCount;
        }
        /// <summary>
        /// Returns the data that should be placed in the JTable
        /// at the given row and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            if (__coeff == null)
            {
                return("");
            }

            switch (col)
            {
            case COL_STREAM_NAME:
            case COL_UPSTREAM_GAGE:
            case COL_GAIN_TERM_WT:
            case COL_GAIN_TERM_GAGE_ID:
                int M = __coeff.getM();
                int N = __coeff.getN();
                switch (col)
                {
                case COL_STREAM_NAME:
                    if (row < N)
                    {
                        return(new double?(__coeff.getCoefn(row)));
                    }
                    return("");

                case COL_UPSTREAM_GAGE:
                    if (row < N)
                    {
                        return(__coeff.getUpper(row));
                    }
                    return("");

                case COL_GAIN_TERM_WT:
                    if (row < M)
                    {
                        return(new double?(__coeff.getCoefm(row)));
                    }
                    return("");

                case COL_GAIN_TERM_GAGE_ID:
                    if (row < M)
                    {
                        return(__coeff.getFlowm(row));
                    }
                    return("");
                }

            default:
                return("");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Read stream estimate coefficients and store in a list. </summary>
        /// <param name="filename"> Name of file to read. </param>
        /// <returns> list of streamflow estimate coefficients data </returns>
        /// <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_StreamEstimate_Coefficients> readStateModFile(String filename) throws Exception
        public static IList <StateMod_StreamEstimate_Coefficients> readStateModFile(string filename)
        {
            string routine = "StateMod_StreamEstimate_Coefficients.readStateModFile";
            IList <StateMod_StreamEstimate_Coefficients> theBaseflows = new List <StateMod_StreamEstimate_Coefficients>();

            string         iline = null;
            IList <object> v     = new List <object>(2); // used to retrieve from fixedRead
            string         adnl  = null;

            int[]        format_0  = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_SPACE, StringUtil.TYPE_INTEGER };
            int[]        format_0w = new int[] { 12, 8, 8 };
            int[]        format_1  = new int[] { StringUtil.TYPE_DOUBLE, StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING };
            int[]        format_1w = new int[] { 8, 1, 12 };
            int[]        format_2  = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER };
            int[]        format_2w = new int[] { 12, 8, 8 };
            int[]        format_3  = new int[] { StringUtil.TYPE_DOUBLE, StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING };
            int[]        format_3w = new int[] { 8, 1, 12 };
            StreamReader @in       = null;
            StateMod_StreamEstimate_Coefficients aBaseflow = null;
            int i = 0;
            int num_adnl;
            int begin_pos;
            int end_pos;
            int linecount = 0;

            if (Message.isDebugOn)
            {
                Message.printDebug(30, routine, "Reading file :" + filename);
            }

            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 a new baseflow
                    aBaseflow = new StateMod_StreamEstimate_Coefficients();

                    // read in first of two lines for each baseflow
                    StringUtil.fixedRead(iline, format_0, format_0w, v);
                    aBaseflow.setFlowX(((string)v[0]).Trim());
                    aBaseflow.setN((int?)v[1]);

                    num_adnl = aBaseflow.getN();
                    for (i = 0; i < num_adnl; i++)
                    {
                        // calculate begin_pos and end_pos
                        //	 8(factor to weight the gaged flow)
                        // +	 1(space)
                        // +	12(station id upstream X)
                        // --------
                        //	21(for each set of num_adnl
                        // +	28(array index after initial info)
                        // +	 1(we should start on next position)
                        // -	 1(our string starts with index 0)
                        //
                        begin_pos = 28 + (i * 21);
                        end_pos   = begin_pos + 21;
                        adnl      = iline.Substring(begin_pos, end_pos - begin_pos);
                        StringUtil.fixedRead(adnl, format_1, format_1w, v);
                        aBaseflow.addCoefn((double?)v[0]);
                        aBaseflow.addUpper((string)v[1]);
                    }

                    // read in second of two lines for each baseflow
                    iline = @in.ReadLine();
                    StringUtil.fixedRead(iline, format_2, format_2w, v);
                    aBaseflow.setProratnf((double?)v[0]);
                    aBaseflow.setM((int?)v[1]);

                    num_adnl = aBaseflow.getM();
                    for (i = 0; i < num_adnl; i++)
                    {
                        begin_pos = 28 + (i * 21);
                        end_pos   = begin_pos + 21;
                        adnl      = iline.Substring(begin_pos, end_pos - begin_pos);
                        StringUtil.fixedRead(adnl, format_3, format_3w, v);
                        aBaseflow.addCoefm((double?)v[0]);
                        aBaseflow.addFlowm((string)v[1]);
                    }

                    // add the baseflow to the vector of baseflows
                    theBaseflows.Add(aBaseflow);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, "Error reading near line " + linecount);
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
                @in = null;
            }
            return(theBaseflows);
        }