Example #1
0
        private void SelectTable()
        {
            hydrometRatingTable = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
            var f = new RatingTableSelector();

            if (f.ShowDialog() == DialogResult.OK)
            {
                cbtt  = f.cbtt;
                yparm = f.pcode;

                this.labelSiteName.Text = "Description: " + HydrometInfoUtility.LookupSiteDescription(cbtt);
                this.labelcbtt.Text     = "cbtt: " + cbtt;
                string altid = HydrometInfoUtility.LookupAltID(cbtt).Trim();
                if (altid.Length > 0)
                {
                    labelcbtt.Text += " altid: " + altid;
                }
                this.labelyparm.Text = "y parameter: " + yparm;

                ReadTableFromInternet(cbtt, yparm, f.RatingName, altid);

                hydrometRatingTable.Name     = f.RatingName + " -- " + HydrometInfoUtility.LookupSiteDescription(cbtt);
                hydrometRatingTable.EditDate = f.DateModified;

                this.labelDate.Text = "Modified " + f.DateModified;
            }
        }
Example #2
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string cbtt, string pcode, string ratingName)
        {
            string url = "";


            if (HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.GreatPlains)
            {
                //url = "http://www.usbr.gov/gp-bin/expandrtf.pl?site=adatunco&pcode=q&form=col";
                url = "http://www.usbr.gov/gp-bin/expandrtf.pl?site=pali&pcode=q&form=col";
                url = url.Replace("site=pali", "site=" + cbtt.Trim());
                url = url.Replace("pcode=q", "pcode=" + pcode.Trim());
            }
            else
            {
                //url = "http://www.usbr.gov/pn-bin/expandrtf.pl?site=pali&pcode=q&form=col";
                url = "http://lrgs1.pn.usbr.gov/rating_tables/" + ratingName + ".csv";
                if (!NetworkUtility.Intranet)
                {
                    url = "http://www.usbr.gov/pn/hydromet/configurationdata/rating_tables/" + ratingName + ".csv";
                }

                var tmp = FileUtility.GetTempFileName(".csv");
                Web.GetFile(url, tmp);

                var rt = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
                rt.ReadFile(tmp);
                return(rt);
            }
            // yakima ?
            //http://www.usbr.gov/pn-bin/yak/expandrtf.pl?site=kee&pcode=af&form=col


            return(ReadFromWeb(cbtt, pcode, url));
        }
Example #3
0
        /// <summary>
        /// This method creates the shift table based on the 'lower'-'mid'-'upper' values specified in the owrd RDB file
        /// </summary>
        /// <param name="rdbFile"></param>
        private TimeSeriesDatabaseDataSet.RatingTableDataTable CreateShiftTable(TextFile rdbFile)
        {
            double gh1    = rdbFile.ReadSingle("SHIFT_LOWER_STAGE");
            var    shift1 = rdbFile.ReadSingle("SHIFT_LOWER_VALUE");
            double gh2    = rdbFile.ReadSingle("SHIFT_MID_STAGE");
            var    shift2 = rdbFile.ReadSingle("SHIFT_MID_VALUE");
            double gh3    = rdbFile.ReadSingle("SHIFT_UPPER_STAGE");
            var    shift3 = rdbFile.ReadSingle("SHIFT_UPPER_VALUE");

            if (gh1 == 0 && gh2 == 0 && gh3 == 0)
            {
                gh2 = 5.0;
                gh3 = 100;
            }

            // Build shift table
            var tbl = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

            tbl.AddRatingTableRow(gh1, shift1);
            tbl.AddRatingTableRow(gh2, shift2);
            tbl.AddRatingTableRow(gh3, shift3);
            tbl.AddRatingTableRow(gh3 * 5, shift3); // extrapolate out

            if (gh1 > gh2 || gh2 > gh3)
            {
                var msg = "Error: Stages values in the shift table are not in increasing order.";
                msg += "\n" + this.ratingNumber;
                msg += "\n" + this.stationNumber;
                msg += "\n" + this.downloadURL;
                Console.WriteLine(msg);
                throw new ArgumentException(msg);
            }
            return(tbl);
        }
Example #4
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string siteNumber)
        {
            //string url = "http://waterdata.usgs.gov/nwisweb/data/exsa_rat/13236500.rdb";
            string url = "http://waterdata.usgs.gov/nwisweb/get_ratings?site_no=13081500&file_type=exsa";

            url = url.Replace("13081500", siteNumber);
            string[] data = Web.GetPage(url);

            TextFile tf = new TextFile(data);

            UsgsRDBFile rdb = new UsgsRDBFile(data);

            TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

            t.XUnits = LookupUnits(tf, "# //RATING_INDEP");
            t.YUnits = LookupUnits(tf, "# //RATING_DEP");

            for (int i = 0; i < rdb.Rows.Count; i++)
            {
                double x = Convert.ToDouble(rdb.Rows[i]["indep"]);
                double y = Convert.ToDouble(rdb.Rows[i]["dep"]);
                var    r = t.FindByx(x);
                if (r == null)
                {
                    t.AddRatingTableRow(x, y);
                }
                else
                {
                    Console.WriteLine("Warning: duplicate x " + x);
                }
            }
            t.Name = "Usgs " + siteNumber;
            return(t);
        }
Example #5
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string siteNumber)
        {
            //string url = "http://waterdata.usgs.gov/nwisweb/data/exsa_rat/13236500.rdb";
              string url = "http://waterdata.usgs.gov/nwisweb/get_ratings?site_no=13081500&file_type=exsa";
              url = url.Replace("13081500", siteNumber);
              string[] data = Web.GetPage(url);

              TextFile tf = new TextFile(data);

              UsgsRDBFile rdb = new UsgsRDBFile(data);

              TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

              t.XUnits = LookupUnits(tf,"# //RATING_INDEP");
              t.YUnits = LookupUnits(tf,"# //RATING_DEP");

              for (int i = 0; i < rdb.Rows.Count; i++)
              {
              double x = Convert.ToDouble(rdb.Rows[i]["indep"]);
              double y = Convert.ToDouble(rdb.Rows[i]["dep"]);
              t.AddRatingTableRow(x, y);
              }
              t.Name = "Usgs " + siteNumber;
              return t;
        }
Example #6
0
        private static void DownloadRatingsFromPnhyd0()
        {
            TextFile tf = new TextFile(@"c:\temp\rtf_list.dat");

            for (int i = 0; i < tf.Length; i++)
            {
                if (tf[i].Length < 14)
                {
                    continue;
                }
                var cbtt  = tf[i].Substring(6, 8).ToLower().Trim();
                var pcode = tf[i].Substring(14, 7).ToLower().Trim();

                if (pcode.Trim() == "")
                {
                    continue;
                }


                string path = @"C:\temp\rating_tables";

                var fn  = Path.Combine(path, cbtt + "_" + pcode + ".csv");
                var fn2 = Path.Combine(path, cbtt + ".csv");

                if (File.Exists(fn) || File.Exists(fn2))
                {
                    System.Console.WriteLine("File exists <skipping> :" + cbtt + " " + pcode);
                    continue;
                }

                //var rt = HydrometInfoUtility.GetRatingTable(cbtt, pcode);
                string url = "http://www.usbr.gov/pn-bin/expandrtf.pl?site=pali&pcode=q&form=csv";
                url = "http://hydromet.pn.usbr.gov/~dataaccess/expandrtf.exe?site=pali&pcode=q&shift&form=csv";

                url = url.Replace("site=pali", "site=" + cbtt.Trim());
                url = url.Replace("pcode=q", "pcode=" + pcode.Trim());

                string[] data = Web.GetPage(url);


                TextFile tf2 = new TextFile(data);

                if (pcode == "q")
                {
                    fn = fn2; // short filename
                }

                System.Console.WriteLine("Saving: " + fn);
                tf2.SaveAs(Path.Combine(path, fn));

                // test

                var rt = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
                rt.ReadFile(fn);
            }
        }
Example #7
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string cbtt, string pcode, string ratingName)
        {
            string url = "";

            var server = HydrometInfoUtility.HydrometServerFromPreferences();

            if (server == HydrometHost.GreatPlains)
            {
                url = "https://www.usbr.gov/gp-bin/expandrtf.pl?site=pali&pcode=q&form=col";
                url = url.Replace("site=pali", "site=" + cbtt.Trim());
                url = url.Replace("pcode=q", "pcode=" + pcode.Trim());
            }
            else if (server == HydrometHost.PN || server == HydrometHost.PNLinux)
            {
                url = ConfigurationManager.AppSettings["RatingTablePath"] + ratingName + ".csv";

                if (!NetworkUtility.Intranet)
                {
                    url = "https://www.usbr.gov/pn/hydromet/configurationdata/rating_tables/" + ratingName + ".csv";
                }

                var tmp = FileUtility.GetTempFileName(".csv");
                Web.GetFile(url, tmp);

                var rt = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
                rt.ReadFile(tmp);
                return(rt);
            }
            else if (server == HydrometHost.Yakima)
            {            // yakima ?
                url = "https://www.usbr.gov/pn-bin/yak/expandrtf.pl?site=kee&pcode=af&form=col";
                url = url.Replace("site=kee", "site=" + cbtt.Trim());
                url = url.Replace("pcode=af", "pcode=" + pcode.Trim());
            }

            string[] data = Web.GetPage(url);
            TextFile tf   = new TextFile(data);

            return(ParseRatingTableData(tf, cbtt, pcode));
        }
Example #8
0
        private void ReadTableFromInternet(string cbtt, string yparm, string ratingName, string altid)
        {
            hydrometRatingTable = HydrometInfoUtility.GetRatingTable(cbtt, yparm, ratingName);
            usgsRatingTable     = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

            if (altid.Trim() != "")
            {
                try
                {
                    usgsRatingTable = Reclamation.TimeSeries.Usgs.Utility.GetRatingTable(altid);
                }
                catch (Exception eek)
                {
                    MessageBox.Show(eek.Message);
                }
            }

            this.ratingTableGraph1.RatingTable = new TimeSeriesDatabaseDataSet.RatingTableDataTable[] { hydrometRatingTable, usgsRatingTable };

            this.ratingTableTableHydromet.RatingTable = hydrometRatingTable;
            this.ratingTableTableUsgs.RatingTable     = usgsRatingTable;
        }
Example #9
0
        /// <summary>
        /// This method creates the shift table based on the 'lower'-'mid'-'upper' values specified in the owrd RDB file
        /// </summary>
        /// <param name="rdbFile"></param>
        private TimeSeriesDatabaseDataSet.RatingTableDataTable CreateShiftTable(TextFile rdbFile)
        {
            double gh1    = rdbFile.ReadSingle("SHIFT_LOWER_STAGE");
            var    shift1 = rdbFile.ReadSingle("SHIFT_LOWER_VALUE");
            double gh2    = rdbFile.ReadSingle("SHIFT_MID_STAGE");
            var    shift2 = rdbFile.ReadSingle("SHIFT_MID_VALUE");
            double gh3    = rdbFile.ReadSingle("SHIFT_UPPER_STAGE");
            var    shift3 = rdbFile.ReadSingle("SHIFT_UPPER_VALUE");

            if (gh1 == 0 && gh2 == 0 && gh3 == 0)
            {
                gh2 = 5.0;
                gh3 = 100;
            }

            // Build shift table
            var tbl = new TimeSeriesDatabaseDataSet.RatingTableDataTable();

            tbl.AddRatingTableRow(gh1, shift1);
            tbl.AddRatingTableRow(gh2, shift2);
            tbl.AddRatingTableRow(gh3, shift3);
            tbl.AddRatingTableRow(gh3 * 5, shift3); // extrapolate out
            return(tbl);
        }
Example #10
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable ParseRatingTableData(TextFile tf,
                                                                                          string cbtt, string pcode)
        {
            /*
             * <table border="1" summary="Expanded Rating Table">	<tr align="center">
             * <th width="80px"><b>ft</b></th>
             * <th width="80px"><b>cfs</b></th>
             * </tr>
             *
             * Table Edit Date: 18-SEP-2014 02:22
             * <tr align="right"><td>2440.01</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.02</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.03</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.04</td><td>-704.00</td></tr>
             */


            TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
            int idx = tf.IndexOfBothRegex("<th.*</th>", "<th.*</th>");

            if (idx >= 0)
            {
                t.XUnits = Regex.Match(tf[idx], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
                t.YUnits = Regex.Match(tf[idx + 1], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
            }
            //<br>Table Edit Date: 18-SEP-2014 02:22<br>Today's Date: 23-SEP-2014 06:54
            var idxDate = tf.IndexOfRegex("Table Edit Date:.*<br>");

            if (idxDate >= 0)
            {
                t.EditDate = Regex.Match(tf[idxDate], "Table Edit Date:(?<date>.*)<br>").Groups[1].Value;
            }


            Regex re = new Regex(@"<tr.*?>(?<x>[\d\.\-\+]{1,12})</td><td>(?<y>[\d\.\-\+]{1,12})</td>");

            for (int i = idx + 2; i < tf.Length; i++)
            {
                var m = re.Match(tf[i]);
                if (m.Success)
                {
                    double x, y;
                    if (double.TryParse(m.Groups["x"].Value, out x)
                        )
                    {
                        if (double.TryParse(m.Groups["y"].Value, out y) &&
                            System.Math.Abs(998877 - y) > 0.01
                            )
                        {
                            t.AddRatingTableRow(x, y);
                        }
                    }
                }
            }
            t.Name = "Hydromet " + cbtt + " " + pcode;
            idx    = tf.IndexOfRegex("<b>Station .+<br />");
            if (idx >= 0)
            {
                t.Name = Regex.Match(tf[idx], "<b>Station (.+)<br />").Groups[1].Value;
            }

            return(t);
        }
Example #11
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable ParseRatingTableData(TextFile tf, 
            string cbtt, string pcode)
        {
            /*
             <table border="1" summary="Expanded Rating Table">	<tr align="center">
            <th width="80px"><b>ft</b></th>
            <th width="80px"><b>cfs</b></th>
            </tr>
             *
             * Table Edit Date: 18-SEP-2014 02:22
            <tr align="right"><td>2440.01</td><td>-704.00</td></tr>
            <tr align="right"><td>2440.02</td><td>-704.00</td></tr>
            <tr align="right"><td>2440.03</td><td>-704.00</td></tr>
            <tr align="right"><td>2440.04</td><td>-704.00</td></tr>
             */

            TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
            int idx = tf.IndexOfBothRegex("<th.*</th>", "<th.*</th>");
            if (idx >= 0)
            {
                t.XUnits = Regex.Match(tf[idx], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
                t.YUnits = Regex.Match(tf[idx + 1], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
            }
            //<br>Table Edit Date: 18-SEP-2014 02:22<br>Today's Date: 23-SEP-2014 06:54
            var idxDate = tf.IndexOfRegex("Table Edit Date:.*<br>");
            if (idxDate >= 0)
            {
                t.EditDate = Regex.Match(tf[idxDate], "Table Edit Date:(?<date>.*)<br>").Groups[1].Value;
            }

            Regex re = new Regex(@"<tr.*?>(?<x>[\d\.\-\+]{1,12})</td><td>(?<y>[\d\.\-\+]{1,12})</td>");
            for (int i = idx + 2; i < tf.Length; i++)
            {
                var m = re.Match(tf[i]);
                if (m.Success)
                {
                    double x, y;
                    if (double.TryParse(m.Groups["x"].Value, out x)
                        )
                    {
                        if (double.TryParse(m.Groups["y"].Value, out y)
                            && System.Math.Abs(998877 - y) > 0.01
                            )
                        {
                            t.AddRatingTableRow(x, y);
                        }
                    }
                }
            }
            t.Name = "Hydromet " + cbtt + " " + pcode;
            idx = tf.IndexOfRegex("<b>Station .+<br />");
            if (idx >= 0)
                t.Name = Regex.Match(tf[idx], "<b>Station (.+)<br />").Groups[1].Value;

            return t;
        }
Example #12
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string cbtt, string pcode,string ratingName)
        {
            string url = "";

            if (HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.GreatPlains)
            {
                url = "https://www.usbr.gov/gp-bin/expandrtf.pl?site=pali&pcode=q&form=col";
                url = url.Replace("site=pali", "site=" + cbtt.Trim());
                url = url.Replace("pcode=q", "pcode=" + pcode.Trim());
            }
            else if( HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.PN)
            {
                url = "http://lrgs1.pn.usbr.gov/rating_tables/"+ratingName+".csv";
                if( !NetworkUtility.Intranet)
                    url = "https://www.usbr.gov/pn/hydromet/configurationdata/rating_tables/" + ratingName + ".csv";

                var tmp = FileUtility.GetTempFileName(".csv");
                Web.GetFile(url, tmp);

                var rt = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
                rt.ReadFile(tmp);
                return rt;
            }
            else if (HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.Yakima)
            {            // yakima ?
                url = "https://www.usbr.gov/pn-bin/yak/expandrtf.pl?site=kee&pcode=af&form=col";
                url = url.Replace("site=kee", "site=" + cbtt.Trim());
                url = url.Replace("pcode=af", "pcode=" + pcode.Trim());
            }

            string[] data = Web.GetPage(url);
            TextFile tf = new TextFile(data);
            return ParseRatingTableData(tf, cbtt, pcode);
        }
Example #13
0
        public static TimeSeriesDatabaseDataSet.RatingTableDataTable GetRatingTable(string cbtt, string pcode)
        {
            // yakima ?
            //http://www.usbr.gov/pn-bin/yak/expandrtf.pl?site=kee&pcode=af&form=col

            string url = "http://www.usbr.gov/pn-bin/expandrtf.pl?site=pali&pcode=q&form=col";

            if (HydrometInfoUtility.HydrometServerFromPreferences() == HydrometHost.GreatPlains)
            {
                //url = "http://www.usbr.gov/gp-bin/expandrtf.pl?site=adatunco&pcode=q&form=col";
                url = "http://www.usbr.gov/gp-bin/expandrtf.pl?site=pali&pcode=q&form=col";
            }


            url = url.Replace("site=pali", "site=" + cbtt.Trim());
            url = url.Replace("pcode=q", "pcode=" + pcode.Trim());

            string[] data = Web.GetPage(url);
            TextFile tf   = new TextFile(data);

            /*
             * <table border="1" summary="Expanded Rating Table">	<tr align="center">
             * <th width="80px"><b>ft</b></th>
             * <th width="80px"><b>cfs</b></th>
             * </tr>
             *
             * Table Edit Date: 18-SEP-2014 02:22
             * <tr align="right"><td>2440.01</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.02</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.03</td><td>-704.00</td></tr>
             * <tr align="right"><td>2440.04</td><td>-704.00</td></tr>
             */


            TimeSeriesDatabaseDataSet.RatingTableDataTable t = new TimeSeriesDatabaseDataSet.RatingTableDataTable();
            int idx = tf.IndexOfBothRegex("<th.*</th>", "<th.*</th>");

            if (idx >= 0)
            {
                t.XUnits = Regex.Match(tf[idx], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
                t.YUnits = Regex.Match(tf[idx + 1], @"<th.*<b>(?<x>\w*)</b>").Groups[1].Value;
            }
            //<br>Table Edit Date: 18-SEP-2014 02:22<br>Today's Date: 23-SEP-2014 06:54
            var idxDate = tf.IndexOfRegex("Table Edit Date:.*<br>");

            if (idxDate >= 0)
            {
                t.EditDate = Regex.Match(tf[idxDate], "Table Edit Date:(?<date>.*)<br>").Groups[1].Value;
            }


            Regex re = new Regex(@"<tr.*?>(?<x>[\d\.\-\+]{1,12})</td><td>(?<y>[\d\.\-\+]{1,12})</td>");

            for (int i = idx + 2; i < tf.Length; i++)
            {
                var m = re.Match(tf[i]);
                if (m.Success)
                {
                    double x, y;
                    if (double.TryParse(m.Groups["x"].Value, out x)
                        )
                    {
                        if (double.TryParse(m.Groups["y"].Value, out y) &&
                            System.Math.Abs(998877 - y) > 0.01
                            )
                        {
                            t.AddRatingTableRow(x, y);
                        }
                    }
                }
            }
            t.Name = "Hydromet " + cbtt + " " + pcode;
            idx    = tf.IndexOfRegex("<b>Station .+<br />");
            if (idx >= 0)
            {
                t.Name = Regex.Match(tf[idx], "<b>Station (.+)<br />").Groups[1].Value;
            }

            return(t);
        }