Example #1
0
        /// <summary>
        /// Returns the value for nrtn to be compared against the interv in the control file.  Either a value
        /// is returned (if every nrtn is the same) or a -1 is returned (variable values for nrtn).
        /// </summary>

        /* TODO SAM 2007-03-01 Evaluate use
         * private int checkDelayInterv(Vector delaysVector) {
         *      int ndly = -999;
         *      if (delaysVector == null) {
         *              return ndly;
         *      }
         *
         *      int ndelay = delaysVector.size();
         *      StateMod_DelayTable delayTable;
         *
         *      for (int i = 0; i < ndelay; i++) {
         *              delayTable =(StateMod_DelayTable)delaysVector.elementAt(i);
         *              if (ndly == -999) {
         *                      ndly = delayTable.getNdly();
         *              }
         *              if (ndly != delayTable.getNdly()) {
         *                      delayTable = null;
         *                      return(-1);
         *              }
         *      }
         *      delayTable = null;
         *      return ndly;
         * }
         */

        /// <summary>
        /// Read delay information in and store in a java vector.  The new delay entries are
        /// added to the end of the previously stored delays.  Returns the delay table information. </summary>
        /// <param name="filename"> the filename to read from. </param>
        /// <param name="isMonthly"> Set to true if the delay table contains monthly data, false if it contains daily data. </param>
        /// <param name="interv"> The control file interv parameter.  +n indicates the number of
        /// values in each delay pattern.  -1 indicates variable number of values with
        /// values as percent (0-100).  -100 indicates variable number of values with values as fraction (0-1). </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static java.util.List<StateMod_DelayTable> readStateModFile(String filename, boolean isMonthly, int interv) throws Exception
        public static IList <StateMod_DelayTable> readStateModFile(string filename, bool isMonthly, int interv)
        {
            string routine = "StateMod_DelayTable.readStateModFile";
            string iline;
            IList <StateMod_DelayTable> theDelays = new List <StateMod_DelayTable>(1);
            StateMod_DelayTable         aDelay = new StateMod_DelayTable(isMonthly);
            int             numRead = 0, totalNumToRead = 0;
            bool            reading = false;
            StreamReader    @in = null;
            StringTokenizer split = null;

            if (Message.isDebugOn)
            {
                Message.printDebug(10, routine, "in readStateModFile reading file: " + filename);
            }
            try
            {
                @in = new StreamReader(filename);
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    // check for comments
                    iline = iline.Trim();
                    if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Length == 0)
                    {
                        continue;
                    }

                    split = new StringTokenizer(iline);
                    if ((split == null) || (split.countTokens() == 0))
                    {
                        continue;
                    }

                    if (!reading)
                    {
                        // allocate new delay node
                        aDelay  = new StateMod_DelayTable(isMonthly);
                        numRead = 0;
                        reading = true;
                        theDelays.Add(aDelay);
                        aDelay.setTableID(split.nextToken());

                        if (interv < 0)
                        {
                            aDelay.setNdly(split.nextToken());
                        }
                        else
                        {
                            aDelay.setNdly(interv);
                        }
                        totalNumToRead = aDelay.getNdly();
                        // Set the delay table units(default is percent)...
                        aDelay.setUnits("PCT");
                        if (interv == -100)
                        {
                            aDelay.setUnits("FRACTION");
                        }
                    }

                    while (split.hasMoreTokens())
                    {
                        aDelay.addRet_val(split.nextToken());
                        numRead++;
                    }
                    if (numRead >= totalNumToRead)
                    {
                        reading = false;
                    }
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
                @in = null;
            }
            return(theDelays);
        }