/// <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];
            }
            double dval;
            int    ival;
            int    index;
            string s;

            StateMod_ReturnFlow rf = (StateMod_ReturnFlow)_data.get(row);

            switch (col)
            {
            case COL_RIVER_NODE:
                rf.setCrtnid((string)value);
                break;

            case COL_RETURN_PCT:
                dval = ((double?)value).Value;
                rf.setPcttot(dval);
                break;

            case COL_RETURN_ID:
                if (value is string)
                {
                    index = ((string)value).IndexOf(" -", StringComparison.Ordinal);
                    s     = null;
                    if (index > -1)
                    {
                        s = ((string)value).Substring(0, index);
                    }
                    else
                    {
                        s = (string)value;
                    }
                    rf.setIrtndl(s);
                }
                else
                {
                    if (value == null)
                    {
                        // user input a blank value -- just keep what was originally in the table
                        return;
                    }
                    ival = ((int?)value).Value;
                    rf.setIrtndl(ival);
                }
                break;
            }

            base.setValueAt(value, row, col);
        }
        /// <summary>
        /// Sets up the data to be displayed in the table. </summary>
        /// <param name="data"> a Vector of StateMod_DelayTable objects from which the data to b
        /// be displayed in the table will be gathered. </param>

        /*
         * private void setupData(List data) {
         *      int num = 0;
         *      int size = data.size();
         *      StateMod_DelayTable dt = null;
         *      String id = null;
         *      __data = new List[__COLUMNS];
         *      for (int i = 0; i < __COLUMNS; i++) {
         *              __data[i] = new Vector();
         *      }
         *
         *      __rowMap = new Vector();
         *
         *      double total = 0;
         *      int rowCount = 0;
         *      for (int i = 0; i < size; i++) {
         *              total = 0;
         *              dt = (StateMod_DelayTable)data.get(i);
         *              id = dt.getID();
         *              num = dt.getNdly();
         *              for (int j = 0; j < num; j++) {
         *                      __data[COL_PLAN_ID].add(id);
         *                      __data[COL_RIVER_NODE_ID].add(new Integer(j + 1));
         *                      __data[COL_PERCENT_RETURN].add( new Double(dt.getRet_val(j)));
         *                      total += dt.getRet_val(j);
         *                      __rowMap.add(new Integer(rowCount));
         *                      rowCount++;
         *              }
         *
         *              __data[COL_PLAN_ID].add("TOTAL " + id);
         *              __data[COL_RIVER_NODE_ID].add(new Integer(-999));
         *              __data[COL_PERCENT_RETURN].add(new Double(total));
         *
         *              rowCount++;
         *      }
         *      _rows = rowCount;
         * }
         */

        /// <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_ReturnFlow rf = (StateMod_ReturnFlow)_data.get(row);

            switch (col)
            {
            case COL_PLAN_ID:
                rf.setID((string)value);
                break;

            case COL_RIVER_NODE_ID:
                rf.setCrtnid((string)value);
                break;

            case COL_PERCENT_RETURN:
                rf.setPcttot((double?)value);
                break;

            case COL_DELAY_TABLE_ID:
                rf.setIrtndl((string)value);
                break;

            case COL_COMMENT:
                rf.setComment((string)value);
                break;
            }
            base.setValueAt(value, row, col);
        }
        /// <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);
        }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// Read return information in and store in a list. </summary>
        /// <param name="filename"> filename containing return flow information </param>
        /// <param name="smdataCompType"> the StateMod_DataSet component type, passed to the constructor of StateMod_ReturnFlow
        /// objects. </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_ReturnFlow> readStateModFile(String filename, int smdataCompType) throws Exception
        public static IList <StateMod_ReturnFlow> readStateModFile(string filename, int smdataCompType)
        {
            string         routine = "StateMod_ReturnFlow.readStateModFile";
            string         iline   = null;
            IList <string> v;
            IList <StateMod_ReturnFlow> theReturns = new List <StateMod_ReturnFlow>();
            int linecount = 0;

            StateMod_ReturnFlow aReturn = null;
            StreamReader        @in     = null;

            Message.printStatus(2, routine, "Reading return file: " + filename);
            int size       = 0;
            int errorCount = 0;

            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))
                    {
                        // Special dynamic header comments written by software and blank lines - no need to keep
                        continue;
                    }
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line: " + iline);
                    }
                    // Break the line using whitespace, while allowing for quoted strings...
                    v    = StringUtil.breakStringList(iline, " \t", StringUtil.DELIM_ALLOW_STRINGS | StringUtil.DELIM_SKIP_BLANKS);
                    size = 0;
                    if (v != null)
                    {
                        size = v.Count;
                    }
                    if (size < 4)
                    {
                        Message.printStatus(2, routine, "Ignoring line " + linecount + " not enough data values.  Have " + size + " expecting 4+");
                        ++errorCount;
                        continue;
                    }
                    // Uncomment if testing...
                    //Message.printStatus ( 2, routine, "" + v );

                    // Allocate new plan node and set the values
                    aReturn = new StateMod_ReturnFlow(smdataCompType);
                    aReturn.setID(v[0].Trim());
                    aReturn.setName(v[0].Trim());             // Same as ID
                    aReturn.setCrtnid(v[1].Trim());
                    aReturn.setCgoto(v[1].Trim());            // Redundant
                    aReturn.setPcttot(v[2].Trim());
                    aReturn.setIrtndl(v[3].Trim());
                    if (v.Count > 4)
                    {
                        aReturn.setComment(v[4].Trim());
                    }

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

                    aReturn.setDirty(false);

                    // Add the return to the list of returns
                    theReturns.Add(aReturn);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, "Error reading line " + linecount + " \"" + iline + "\" uniquetempvar.");
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            if (errorCount > 0)
            {
                throw new Exception("There were " + errorCount + " errors processing the data - refer to log file.");
            }
            return(theReturns);
        }