/// <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];
            }

            switch (col)
            {
            case COL_ID:
                StateMod_DelayTable dt = (StateMod_DelayTable)_data.get(row);
                return(dt.getTableID());

            case COL_DATE:
                return(new int?(row + 1));

            case COL_RETURN_AMT:
                if (__subDelays != null)
                {
                    return(__subDelays[row]);
                }
                else
                {
                    return(new double?(0.0));
                }

            default:
                return("");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Write the new (updated) delay table file.  This routine writes the new delay table file.
        /// If an original file is specified, then the original header is carried into the new file.
        /// The writing of data is done by the dumpDelayFile routine which now does not mess with headers. </summary>
        /// <param name="inputFile"> old file (used as input) </param>
        /// <param name="outputFile"> new file to create </param>
        /// <param name="dly"> list of delays </param>
        /// <param name="newcomments"> new comments to save with the header of the file </param>
        /// <param name="interv"> interv variable specified in control file (if negative, include the number
        /// of entries at the start of each record). </param>
        /// <param name="precision"> number of digits after the decimal to write.  If negative, 2 is assumed. </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 void writeStateModFile(String inputFile, String outputFile, java.util.List<StateMod_DelayTable> dly, java.util.List<String> newcomments, int interv, int precision) throws Exception
        public static void writeStateModFile(string inputFile, string outputFile, IList <StateMod_DelayTable> dly, IList <string> newcomments, int interv, int precision)
        {
            PrintWriter    @out = null;
            IList <string> commentIndicators = new List <string>(1);

            commentIndicators.Add("#");
            IList <string> ignoredCommentIndicators = new List <string>(1);

            ignoredCommentIndicators.Add("#>");
            string routine = "StateMod_DelayTable.writeStateModFile";

            if (precision < 0)
            {
                precision = 2;
            }

            Message.printStatus(2, routine, "Writing delay tables to file \"" + outputFile + "\" using \"" + inputFile + "\" header...");

            try
            {
                // Process the header from the old file...
                @out = IOUtil.processFileHeaders(inputFile, outputFile, newcomments, commentIndicators, ignoredCommentIndicators, 0);

                // Now write the new data...
                string delayVal          = null;
                string cmnt              = "#>";
                string idFormat          = "%8.8s"; // Right justify because StateMod actually uses integers
                string delayValueFormat0 = "%8.";   // no precision
                string delayValueFormat  = "%8." + precision + "f";
                string countFormat       = "%4d";

                @out.println(cmnt);
                @out.println(cmnt + " *******************************************************");
                @out.println(cmnt + " StateMod Delay (Return flow) Table");
                @out.println(cmnt);
                @out.println(cmnt + "     Format (a8, i4, (12f8.2)");
                @out.println(cmnt);
                @out.println(cmnt + "   ID       idly: Delay table id");
                @out.println(cmnt + "   Ndly     ndly: Number of entries in delay table idly.");
                @out.println(cmnt + "                  Include only if \"interv\" in the");
                @out.println(cmnt + "                  control file is equal to -1.");
                @out.println(cmnt + "                  interv = -1 = Variable number of entries");
                @out.println(cmnt + "                                as percent (0-100)");
                @out.println(cmnt + "                  interv = -100 = Variable number of entries");
                @out.println(cmnt + "                                as fraction (0-1)");
                @out.println(cmnt + "   Ret  dlyrat(1-n,idl): Return for month n, station idl");
                @out.println(cmnt);
                @out.println(cmnt + " ID   Ndly  Ret1    Ret2    Ret3    Ret4    Ret5    Ret6    Ret7    Ret8    Ret9    Ret10   Ret11   Ret12");
                @out.println(cmnt + "-----eb--eb------eb------eb------eb------eb------eb------eb------eb------eb------eb------eb------eb------e...next line");
                @out.println(cmnt + "EndHeader");
                @out.println(cmnt);

                int ndly = 0;
                if (dly != null)
                {
                    ndly = dly.Count;
                }
                int numWritten, numToWrite;
                if (Message.isDebugOn)
                {
                    Message.printDebug(3, routine, "Writing " + ndly + " delay table entries.");
                }
                StringBuilder       iline = new StringBuilder();
                StateMod_DelayTable delay = null;
                for (int i = 0; i < ndly; i++)
                {
                    delay = dly[i];
                    // Clear out the string buffer for the new delay table
                    iline.Length = 0;
                    // Create one delay table entry with ID, Nvals, and 12 return values per line.
                    if (interv < 0)
                    {
                        iline.Append(StringUtil.formatString(delay.getTableID(), idFormat));
                        iline.Append(StringUtil.formatString(delay.getNdly(), countFormat));
                    }
                    else
                    {
                        iline.Append(StringUtil.formatString(delay.getTableID(), idFormat));
                    }

                    numWritten = 0;             // Number of values written for this delay table
                    int numDelayVals = delay.getNdly();
                    while (true)
                    {
                        if (numWritten > 0)
                        {
                            // Clear lines 2+ before adding values
                            iline.Length = 0;
                            // Add spaces as per the record header info
                            if (interv < 0)
                            {
                                iline.Append("            ");
                            }
                            else
                            {
                                iline.Append("        ");
                            }
                        }
                        // Number of values remaining to write
                        numToWrite = numDelayVals - numWritten;

                        if (numToWrite > 12)
                        {
                            // Have more than 12 so only write 12 on this line
                            numToWrite = 12;
                        }

                        for (int j = 0; j < numToWrite; j++)
                        {
                            delayVal = StringUtil.formatString(delay.getRet_val(numWritten + j), delayValueFormat);
                            if (delayVal.IndexOf(' ') < 0)
                            {
                                // There are no spaces - this will be a problem because the file is free format.
                                // Do a little more work here to reduce the precision until there is a leading
                                // space.
                                for (int iprecision = precision - 1; iprecision >= 0; iprecision--)
                                {
                                    delayVal = StringUtil.formatString(delay.getRet_val(numWritten + j), delayValueFormat0 + iprecision + ".f");
                                    if (delayVal.IndexOf(' ') >= 0)
                                    {
                                        // Done
                                        break;
                                    }
                                }
                            }
                            iline.Append(delayVal);
                        }
                        // Now output the line:

                        @out.println(iline);
                        numWritten += numToWrite;
                        if (numWritten == numDelayVals)
                        {
                            // Done writing so break out
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (@out != null)
                {
                    @out.close();
                }
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }