コード例 #1
0
        /// <summary>
        /// Read diversion information in and store in a java vector.
        /// The new diversions are added to the end of the previously stored diversions. </summary>
        /// <param name="filename"> filename containing diversion information </param>
        /// <exception cref="Exception"> if an error occurs </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public static java.util.List<StateMod_Diversion> readStateModFile(String filename) throws Exception
        public static IList <StateMod_Diversion> readStateModFile(string filename)
        {
            string                     routine       = "StateMod_Diversion.readStateModFile";
            string                     iline         = null;
            IList <object>             v             = new List <object>(9);
            IList <StateMod_Diversion> theDiversions = new List <StateMod_Diversion>();
            int    i;
            int    linecount = 0;
            string s         = null;

            int[] format_0  = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING };
            int[] format_0w = new int[] { 12, 24, 12, 8, 8, 8, 8, 1, 12 };
            int[] format_1  = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER };
            int[] format_1w = new int[] { 12, 24, 12, 8, 8, 8, 8, 8, 8 };
            int[] format_2  = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER };
            int[] format_2w = new int[] { 36, 12, 8, 8 };

            StateMod_Diversion  aDiversion  = null;
            StateMod_ReturnFlow aReturnNode = null;
            StreamReader        @in         = null;

            Message.printStatus(1, routine, "Reading diversion file: " + filename);
            try
            {
                @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename));
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    ++linecount;
                    // check for comments
                    if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0)
                    {
                        continue;
                    }

                    // allocate new diversion node
                    aDiversion = new StateMod_Diversion();

                    // line 1
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line 1: " + iline);
                    }
                    StringUtil.fixedRead(iline, format_0, format_0w, v);
                    aDiversion.setID(((string)v[0]).Trim());
                    aDiversion.setName(((string)v[1]).Trim());
                    aDiversion.setCgoto(((string)v[2]).Trim());
                    aDiversion.setSwitch((int?)v[3]);
                    aDiversion.setDivcap((double?)v[4]);
                    aDiversion.setIreptype(((int?)v[6]));
                    aDiversion.setCdividy(((string)v[8]).Trim());

                    // line 2
                    iline = @in.ReadLine();
                    ++linecount;
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line 2: " + iline);
                    }
                    StringUtil.fixedRead(iline, format_1, format_1w, v);
                    aDiversion.setUsername(((string)v[1]).Trim());
                    aDiversion.setIdvcom(((int?)v[3]));
                    int nrtn = ((int?)v[4]).Value;
                    aDiversion.setDivefc(((double?)v[5]));
                    aDiversion.setArea(((double?)v[6]));
                    aDiversion.setIrturn(((int?)v[7]));
                    aDiversion.setDemsrc(((int?)v[8]));

                    // get the efficiency information
                    if (aDiversion.getDivefc() < 0)
                    {
                        // Negative value indicates monthly efficiencies will follow...
                        iline = @in.ReadLine();
                        ++linecount;
                        // Free format...
                        char[]   seps  = { ' ', '\t', '\n', '\r', '\f' };
                        string[] split = iline.Split(seps);
                        if (split != null && split.Length == 12)
                        {
                            for (i = 0; i < 12; i++)
                            {
                                aDiversion.setDiveff(i, split[0]);
                            }
                        }
                    }
                    else
                    {
                        // Annual efficiency so set monthly efficiencies to the annual...
                        aDiversion.setDiveff(0, aDiversion.getDivefc());
                        aDiversion.setDiveff(1, aDiversion.getDivefc());
                        aDiversion.setDiveff(2, aDiversion.getDivefc());
                        aDiversion.setDiveff(3, aDiversion.getDivefc());
                        aDiversion.setDiveff(4, aDiversion.getDivefc());
                        aDiversion.setDiveff(5, aDiversion.getDivefc());
                        aDiversion.setDiveff(6, aDiversion.getDivefc());
                        aDiversion.setDiveff(7, aDiversion.getDivefc());
                        aDiversion.setDiveff(8, aDiversion.getDivefc());
                        aDiversion.setDiveff(9, aDiversion.getDivefc());
                        aDiversion.setDiveff(10, aDiversion.getDivefc());
                        aDiversion.setDiveff(11, aDiversion.getDivefc());
                    }

                    // get the return information
                    for (i = 0; i < nrtn; i++)
                    {
                        iline = @in.ReadLine();
                        ++linecount;
                        StringUtil.fixedRead(iline, format_2, format_2w, v);
                        aReturnNode = new StateMod_ReturnFlow(StateMod_DataSet.COMP_DIVERSION_STATIONS);
                        s           = ((string)v[1]).Trim();
                        if (s.Length <= 0)
                        {
                            aReturnNode.setCrtnid(((string)v[0]).Trim());
                            Message.printWarning(3, routine, "Return node for structure \"" + aDiversion.getID() + "\" is blank. ");
                        }
                        else
                        {
                            aReturnNode.setCrtnid(s);
                        }

                        aReturnNode.setPcttot(((double?)v[2]));
                        aReturnNode.setIrtndl(((int?)v[3]));
                        aDiversion.addReturnFlow(aReturnNode);
                    }

                    // Set the diversion to not dirty because it was just initialized...

                    aDiversion.setDirty(false);

                    // add the diversion to the vector of diversions
                    theDiversions.Add(aDiversion);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, "Error reading line " + linecount + " \"" + iline + "\"");
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            return(theDiversions);
        }
コード例 #2
0
        /// <summary>
        /// Perform the query.  Currently only diversion stations are supported.
        /// </summary>
        private void doQuery()
        {
            string             routine = "StateMod_QueryTool_JFrame.doQuery", message;
            InputFilter_JPanel ifp    = __input_filter_diversion_JPanel;
            InputFilter        filter = null;
            int size;  // Size of data Vector
            int i;     // Loop for data items.
            DataSetComponent comp = null;

            string where, @operator, input;
            int    where_length = 0; // Length of "where", to optimize code.
            bool   do_int, do_double, do_string;
            string input_string;     // Data parameters to check, as
            int    input_int;        // transferred from the data objects.
            double input_double;
            bool   do_ID, do_Name, do_RiverNodeID, do_OnOff, do_Capacity, do_ReplaceResOption, do_DailyID, do_UserName, do_DemandType, do_EffAnnual, do_Area, do_UseType, do_DemandSource;

            bool[] matches = null; // Indicates if a data item matches all
            // the filter criteria.
            bool item_matches;     // Indicates whether the itme matches a

            // single filter criteria.
            bool[] @checked = null;     // Indicates whether a data item has
            // already been checked for a criteria.
            // If checked and false, then a "true"
            // should not reset the false.
            int nfg = 0;       // Number of filter groups.

            do_int    = false; // Whether the data item is an integer.
            do_double = false; // Whether the data item is a double.
            do_string = false; // Whether the data item is a string.
            StateMod_Diversion dds = null;

            __status_JTextField.setText(__Wait);
            JGUIUtil.setWaitCursor(this, true);
            if (ifp is StateMod_Diversion_InputFilter_JPanel)
            {
                input_int    = StateMod_Util.MISSING_INT;
                input_double = StateMod_Util.MISSING_DOUBLE;
                input_string = StateMod_Util.MISSING_STRING;
                comp         = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DIVERSION_STATIONS);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Diversion> dds_Vector = (java.util.List<StateMod_Diversion>)comp.getData();
                IList <StateMod_Diversion> dds_Vector = (IList <StateMod_Diversion>)comp.getData();
                size = 0;
                if (dds_Vector != null)
                {
                    size = dds_Vector.Count;
                }
                // REVISIT SAM 2004-10-27 Remove when debugging is complete
                //Message.printStatus ( 2, routine,
                //"Searching " + size + " diversion stations." );
                // Initialize the arrays indicating if data objects have been
                // checked and whether they matched the filter(s)...
                if (size > 0)
                {
                    matches  = new bool[size];
                    @checked = new bool[size];
                }
                for (i = 0; i < size; i++)
                {
                    matches[i]  = false;
                    @checked[i] = false;
                }
                // Loop through the where clauses...
                nfg = ifp.getNumFilterGroups();
                for (int ifg = 0; ifg < nfg; ifg++)
                {
                    // Get the filter information...
                    filter       = ifp.getInputFilter(ifg);
                    where        = filter.getWhereInternal();
                    where_length = where.Length;
                    @operator    = ifp.getOperator(ifg);
                    input        = filter.getInput(false);
                    // REVISIT SAM 2004-10-27 Remove when debugging is
                    // complete
                    //Message.printStatus ( 2, routine,
                    //"where=" + where + " operator=" + operator +
                    //" input=" + input );
                    // Initialize flags to indicate what data will be
                    // checked...
                    do_int              = false;
                    do_double           = false;
                    do_string           = false;
                    do_ID               = false;
                    do_Name             = false;
                    do_RiverNodeID      = false;
                    do_OnOff            = false;
                    do_Capacity         = false;
                    do_ReplaceResOption = false;
                    do_DailyID          = false;
                    do_UserName         = false;
                    do_DemandType       = false;
                    do_EffAnnual        = false;
                    do_Area             = false;
                    do_UseType          = false;
                    do_DemandSource     = false;
                    // The following checks on "where" need to match the
                    // input filter internal where labels assigned in
                    // StateMod_Diversion_InputFilter_JPanel.
                    // List in the order of the StateMod documentation...
                    if (where.Equals("ID", StringComparison.OrdinalIgnoreCase))
                    {
                        do_string = true;
                        do_ID     = true;
                    }
                    else if (where.Equals("Name", StringComparison.OrdinalIgnoreCase))
                    {
                        do_string = true;
                        do_Name   = true;
                    }
                    else if (where.Equals("RiverNodeID", StringComparison.OrdinalIgnoreCase))
                    {
                        do_string      = true;
                        do_RiverNodeID = true;
                    }
                    else if (where.Equals("OnOff", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input))
                    {
                        do_int   = true;
                        do_OnOff = true;
                    }
                    else if (where.Equals("Capacity", StringComparison.OrdinalIgnoreCase) && StringUtil.isDouble(input))
                    {
                        do_double   = true;
                        do_Capacity = true;
                    }
                    else if (where.Equals("ReplaceResOption", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input))
                    {
                        do_int = true;
                        do_ReplaceResOption = true;
                    }
                    else if (where.Equals("DailyID", StringComparison.OrdinalIgnoreCase))
                    {
                        do_string  = true;
                        do_DailyID = true;
                    }
                    else if (where.Equals("UserName", StringComparison.OrdinalIgnoreCase))
                    {
                        do_string   = true;
                        do_UserName = true;
                    }
                    else if (where.Equals("DemandType", StringComparison.OrdinalIgnoreCase))
                    {
                        do_int        = true;
                        do_DemandType = true;
                    }
                    else if (where.Equals("EffAnnual", StringComparison.OrdinalIgnoreCase) && StringUtil.isDouble(input))
                    {
                        do_double    = true;
                        do_EffAnnual = true;
                    }
                    else if (where.Equals("Area", StringComparison.OrdinalIgnoreCase) && StringUtil.isDouble(input))
                    {
                        do_double = true;
                        do_Area   = true;
                    }
                    else if (where.Equals("UseType", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input))
                    {
                        do_int     = true;
                        do_UseType = true;
                    }
                    else if (where.Equals("DemandSource", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input))
                    {
                        do_int          = true;
                        do_DemandSource = true;
                    }
                    else if (where_length == 0)
                    {
                        // WIll match anything.
                    }
                    else
                    {             // Unrecognized where...
                        continue;
                    }
                    // REVISIT SAM 2004-10-27 Remove when debugging is
                    // complete

                    /*
                     * Message.printStatus ( 2, routine,
                     * "do_string=" + do_string + " do_int=" + do_int +
                     * "do_double=" + do_double +
                     * " " + do_ID +
                     * " " + do_Name +
                     * " " + do_RiverNodeID +
                     * " " + do_OnOff +
                     * " " + do_Capacity +
                     * " " + do_ReplaceResOption +
                     * " " + do_DailyID +
                     * " " + do_UserName +
                     * " " + do_DemandType +
                     * " " + do_EffAnnual +
                     * " " + do_Area +
                     * " " + do_UseType +
                     * " " + do_DemandSource );
                     */
                    for (i = 0; i < size; i++)
                    {
                        dds = (StateMod_Diversion)dds_Vector[i];
                        // Get the specific data to compare...
                        if (do_ID)
                        {
                            input_string = dds.getID();
                        }
                        else if (do_Name)
                        {
                            input_string = dds.getName();
                        }
                        else if (do_RiverNodeID)
                        {
                            input_string = dds.getCgoto();
                        }
                        else if (do_OnOff)
                        {
                            input_int = dds.getSwitch();
                        }
                        else if (do_Capacity)
                        {
                            input_double = dds.getDivcap();
                        }
                        else if (do_ReplaceResOption)
                        {
                            input_int = dds.getIreptype();
                        }
                        else if (do_DailyID)
                        {
                            input_string = dds.getCdividy();
                        }
                        else if (do_UserName)
                        {
                            input_string = dds.getUsername();
                        }
                        else if (do_DemandType)
                        {
                            input_int = dds.getIdvcom();
                        }
                        else if (do_EffAnnual)
                        {
                            input_double = dds.getDivefc();
                        }
                        else if (do_Area)
                        {
                            input_double = dds.getArea();
                        }
                        else if (do_UseType)
                        {
                            input_int = dds.getIrturn();
                        }
                        else if (do_DemandSource)
                        {
                            input_int = dds.getDemsrc();
                        }
                        else
                        {                 // Unrecognized...
                            continue;
                        }
                        // Compare the data with the input filter...
                        item_matches = false;
                        if (do_string)
                        {
                            item_matches = filter.matches(input_string, @operator, true);
                        }
                        else if (do_int)
                        {
                            item_matches = filter.matches(input_int, @operator);
                        }
                        else if (do_double)
                        {
                            item_matches = filter.matches(input_double, @operator);
                        }
                        if (where_length == 0)
                        {
                            // Always consider a match...
                            item_matches = true;
                        }
                        if (item_matches && (!@checked[i] || (@checked[i] && matches[i])))
                        {
                            // So far the item matches all
                            // filters...
                            matches[i] = true;
                        }
                        else if (@checked[i] && !item_matches)
                        {
                            // Does not match this filter to reset
                            // result to false...
                            matches[i] = false;
                        }
                        // Indicate that we have checked the item
                        // against at least one filter...
                        @checked[i] = true;
                    }
                }
                // Get a count so the Vector can be sized appropriately (this
                // should be fast)...
                int match_count = 0;
                for (i = 0; i < size; i++)
                {
                    if (matches[i])
                    {
                        ++match_count;
                    }
                }
                // Loop through and set up the matches_Vector...
                __matches_Vector = null;
                if (match_count > 0)
                {
                    __matches_Vector = new List <StateMod_Diversion> (match_count);
                    for (i = 0; i < size; i++)
                    {
                        if (matches[i])
                        {
                            // The diversion station matches so add
                            // to the list...
                            __matches_Vector.Add(dds_Vector[i]);
                        }
                    }
                }
                message = "Matched " + match_count +
                          " diversion stations (from original " + size + ").";
                Message.printStatus(2, routine, message);
                __message_JTextField.setText(message);
                __status_JTextField.setText(__Ready);
                JGUIUtil.setWaitCursor(this, false);
            }
            if (__matches_Vector == null)
            {
                __display_JButton.setEnabled(false);
            }
            else
            {
                __display_JButton.setEnabled(true);
            }
        }
コード例 #3
0
        /// <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];
            }

            StateMod_Diversion smd = (StateMod_Diversion)_data.get(row);

            switch (col)
            {
            case COL_ID:
                return(smd.getID());

            case COL_NAME:
                return(smd.getName());

            case COL_RIVER_NODE_ID:
                return(smd.getCgoto());

            case COL_ON_OFF:
                return(new int?(smd.getSwitch()));

            case COL_CAPACITY:
                return(new double?(smd.getDivcap()));

            case COL_REPLACE_RES_OPTION:
                return(new int?(smd.getIreptype()));

            case COL_DAILY_ID:
                return(smd.getCdividy());

            case COL_USER_NAME:
                return(smd.getUsername());

            case COL_DEMAND_TYPE:
                return(new int?(smd.getIdvcom()));

            case COL_AREA:
                return(new double?(smd.getArea()));

            case COL_USE_TYPE:
                return(new int?(smd.getIrturn()));

            case COL_DEMAND_SOURCE:
                return(new int?(smd.getDemsrc()));

            case COL_EFF_ANNUAL:
                return(new double?(smd.getDivefc()));

            case COL_EFF_01:
                return(new double?(smd.getDiveff(0)));

            case COL_EFF_02:
                return(new double?(smd.getDiveff(1)));

            case COL_EFF_03:
                return(new double?(smd.getDiveff(2)));

            case COL_EFF_04:
                return(new double?(smd.getDiveff(3)));

            case COL_EFF_05:
                return(new double?(smd.getDiveff(4)));

            case COL_EFF_06:
                return(new double?(smd.getDiveff(5)));

            case COL_EFF_07:
                return(new double?(smd.getDiveff(6)));

            case COL_EFF_08:
                return(new double?(smd.getDiveff(7)));

            case COL_EFF_09:
                return(new double?(smd.getDiveff(8)));

            case COL_EFF_10:
                return(new double?(smd.getDiveff(9)));

            case COL_EFF_11:
                return(new double?(smd.getDiveff(10)));

            case COL_EFF_12:
                return(new double?(smd.getDiveff(11)));

            default:
                return("");
            }
        }