Ejemplo n.º 1
0
        /// <summary>
        /// Read a well input file. </summary>
        /// <param name="filename"> name of file containing well information </param>
        /// <returns> status(always 0 since exception handling is now used) </returns>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public static java.util.List<StateMod_Well> readStateModFile(String filename) throws Exception
        public static IList <StateMod_Well> readStateModFile(string filename)
        {
            string routine = "StateMod_Well.readStateModFile";
            IList <StateMod_Well> theWellStations = new List <StateMod_Well>();

            int[]               format_1 = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_SPACE, StringUtil.TYPE_DOUBLE };
            int[]               format_1w = new int[] { 12, 24, 12, 8, 8, 1, 12, 1, 12 };
            int[]               format_2 = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER };
            int[]               format_2w = new int[] { 36, 12, 8, 8, 8, 8, 8, 8, 8 };
            int[]               format_4 = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER };
            int[]               format_4w = new int[] { 36, 12, 8, 8 };
            string              iline = null;
            string              s = null;
            IList <object>      v = new List <object>(9);
            StreamReader        @in = null;
            StateMod_Well       aWell = null;
            StateMod_ReturnFlow aReturnNode = null;
            IList <string>      effv = null;
            int nrtn, ndepl;

            Message.printStatus(1, routine, "Reading well file: " + filename);

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

                    aWell = new StateMod_Well();

                    StringUtil.fixedRead(iline, format_1, format_1w, v);
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "iline: " + iline);
                    }
                    aWell.setID(((string)v[0]).Trim());
                    aWell.setName(((string)v[1]).Trim());
                    aWell.setCgoto(((string)v[2]).Trim());
                    aWell.setSwitch((int?)v[3]);
                    aWell.setDivcapw((double?)v[4]);
                    aWell.setCdividyw(((string)v[5]).Trim());
                    aWell.setPrimary((double?)v[6]);

                    // user data

                    iline = @in.ReadLine();
                    StringUtil.fixedRead(iline, format_2, format_2w, v);
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "iline: " + iline);
                    }
                    aWell.setIdvcow2(((string)v[0]).Trim());
                    aWell.setIdvcomw((int?)v[1]);
                    // Don't set the number of return flow data get(2) or depletion data get(3) because
                    // those will be calculated
                    nrtn  = ((int?)v[2]).Value;
                    ndepl = ((int?)v[3]).Value;
                    aWell.setDivefcw((double?)v[4]);
                    aWell.setAreaw((double?)v[5]);
                    aWell.setIrturnw((int?)v[6]);
                    aWell.setDemsrcw((int?)v[7]);
                    if (aWell.getDivefcw() >= 0)
                    {
                        // Efficiency line won't be included - set each value to the average
                        for (int i = 0; i < 12; i++)
                        {
                            aWell.setDiveff(i, aWell.getDivefcw());
                        }
                    }
                    else
                    {
                        // 12 efficiency values
                        iline = @in.ReadLine();
                        effv  = StringUtil.breakStringList(iline, " ", StringUtil.DELIM_SKIP_BLANKS);
                        for (int i = 0; i < 12; i++)
                        {
                            aWell.setDiveff(i, (string)effv[i]);
                        }
                    }

                    // return flow data

                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "Number of return flows: " + nrtn);
                    }
                    for (int i = 0; i < nrtn; i++)
                    {
                        iline = @in.ReadLine();
                        StringUtil.fixedRead(iline, format_4, format_4w, v);
                        if (Message.isDebugOn)
                        {
                            Message.printDebug(50, routine, "Fixed read returned " + v.Count + " elements");
                        }

                        aReturnNode = new StateMod_ReturnFlow(StateMod_DataSet.COMP_WELL_STATIONS);
                        s           = ((string)v[0]).Trim();
                        if (s.Length <= 0)
                        {
                            aReturnNode.setCrtnid(s);
                            Message.printWarning(2, routine, "Return node for structure \"" + aWell.getID() + "\" is blank. ");
                        }
                        else
                        {
                            aReturnNode.setCrtnid(s);
                        }

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

                    // depletion data

                    for (int i = 0; i < ndepl; i++)
                    {
                        iline = @in.ReadLine();
                        StringUtil.fixedRead(iline, format_4, format_4w, v);

                        aReturnNode = new StateMod_ReturnFlow(StateMod_DataSet.COMP_WELL_STATIONS);
                        s           = ((string)v[0]).Trim();
                        if (s.Length <= 0)
                        {
                            aReturnNode.setCrtnid(s);
                            Message.printWarning(2, routine, "Return node for structure \"" + aWell.getID() + "\" is blank. ");
                        }
                        else
                        {
                            aReturnNode.setCrtnid(s);
                        }

                        aReturnNode.setPcttot(((double?)v[1]));
                        aReturnNode.setIrtndl(((int?)v[2]));
                        aWell.addDepletion(aReturnNode);
                    }

                    theWellStations.Add(aWell);
                }
            }
            catch (Exception e)
            {
                routine   = null;
                format_1  = null;
                format_1w = null;
                format_2  = null;
                format_2w = null;
                format_4  = null;
                format_4w = null;
                s         = null;
                v         = null;
                if (@in != null)
                {
                    @in.Close();
                }
                @in         = null;
                aWell       = null;
                aReturnNode = null;
                effv        = null;
                Message.printWarning(2, routine, e);
                throw e;
            }
            routine   = null;
            format_1  = null;
            format_1w = null;
            format_2  = null;
            format_2w = null;
            format_4  = null;
            format_4w = null;
            iline     = null;
            s         = null;
            v         = null;
            if (@in != null)
            {
                @in.Close();
            }
            @in         = null;
            aWell       = null;
            aReturnNode = null;
            effv        = null;
            return(theWellStations);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Inserts the specified value into the table at the given position. </summary>
        /// <param name="value"> the object to store in the table cell. </param>
        /// <param name="row"> the row of the cell in which to place the object. </param>
        /// <param name="col"> the column of the cell in which to place the object. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            StateMod_Well smw = (StateMod_Well)_data.get(row);

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

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

            case COL_RIVER_NODE_ID:
                smw.setCgoto((string)value);
                break;

            case COL_SWITCH:
                smw.setSwitch(((int?)value).Value);
                break;

            case COL_DAILY_ID:
                smw.setCdividyw((string)value);
                break;

            case COL_CAPACITY:
                smw.setDivcapw(((double?)value).Value);
                break;

            case COL_DIVERSION_ID:
                smw.setIdvcow2((string)value);
                break;

            case COL_DEMAND_TYPE:
                smw.setIdvcomw(((int?)value).Value);
                break;

            case COL_EFF_ANNUAL:
                smw.setDivefcw(((double?)value).Value);
                break;

            case COL_AREA:
                smw.setAreaw(((double?)value).Value);
                break;

            case COL_USE_TYPE:
                smw.setIrturnw(((int?)value).Value);
                break;

            case COL_DEMAND_SOURCE:
                smw.setDemsrcw(((int?)value).Value);
                break;

            case COL_PRIMARY:
                smw.setPrimary(((double?)value).Value);
                break;

            case COL_EFF_01:
                smw.setDiveff(0, (double?)value);
                break;

            case COL_EFF_02:
                smw.setDiveff(1, (double?)value);
                break;

            case COL_EFF_03:
                smw.setDiveff(2, (double?)value);
                break;

            case COL_EFF_04:
                smw.setDiveff(3, (double?)value);
                break;

            case COL_EFF_05:
                smw.setDiveff(4, (double?)value);
                break;

            case COL_EFF_06:
                smw.setDiveff(5, (double?)value);
                break;

            case COL_EFF_07:
                smw.setDiveff(6, (double?)value);
                break;

            case COL_EFF_08:
                smw.setDiveff(7, (double?)value);
                break;

            case COL_EFF_09:
                smw.setDiveff(8, (double?)value);
                break;

            case COL_EFF_10:
                smw.setDiveff(9, (double?)value);
                break;

            case COL_EFF_11:
                smw.setDiveff(10, (double?)value);
                break;

            case COL_EFF_12:
                smw.setDiveff(11, (double?)value);
                break;
            }

            base.setValueAt(value, row, col);
        }