Ejemplo n.º 1
1
        /// <summary>Get a rainfall forecast for the specified station number.</summary>
        /// <param name="stationNumber">The SILO station number.</param>
        /// <returns>Stream of data.</returns>
        public Stream Get(int stationNumber, DateTime nowDate, bool rainOnly)
        {
            // Get SILO data and write to a temporary file.
            DateTime startDate = new DateTime(1981, 1, 1);
            MemoryStream dataStream = WeatherFile.ExtractMetStreamFromSILO(stationNumber, startDate, DateTime.Now);
            string siloFileName = GetTemporaryFileName();
            string forecastFileName = null;

            try
            {
                File.WriteAllBytes(siloFileName, dataStream.ToArray());

                ChangeToWorkingDirectory();

                // Run the MatLab script over the temporary SILO file.
                POAMAforecast.Class1 forecast = new POAMAforecast.Class1();

                MWArray metFile = new MWCharArray(siloFileName);
                MWArray rainfallOnly = new MWNumericArray((double)1);
                if (!rainOnly)
                    rainfallOnly = new MWNumericArray((double)0);
                MWArray writeFiles = new MWNumericArray((double)1.0);
                MWArray startDay = new MWNumericArray(Convert.ToDouble(nowDate.Day));
                MWArray startMonth = new MWNumericArray(Convert.ToDouble(nowDate.Month));
                MWArray startYear = new MWNumericArray(Convert.ToDouble(nowDate.Year));
                forecast.calsite(metFile, rainfallOnly, writeFiles, startDay, startMonth, startYear);

                forecastFileName = siloFileName.Replace(".sim", "") + "_" + nowDate.Year + ".sim";

                // Get rid of temporary file.
                File.Delete(siloFileName);

                if (WebOperationContext.Current != null && WebOperationContext.Current.OutgoingRequest != null)
                    WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";
                if (File.Exists(forecastFileName))
                {
                    // Read in the forecast data.
                    byte[] bytes = File.ReadAllBytes(forecastFileName);
                    return new MemoryStream(bytes);
                }
                else
                    return null;
            }
            finally
            {
                if (File.Exists(siloFileName))
                    File.Delete(siloFileName);
                if (forecastFileName != null && File.Exists(forecastFileName))
                    File.Delete(forecastFileName);
            }
        }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     Directory.SetCurrentDirectory(@"G:\");
     POAMAforecast.Class1 d = new POAMAforecast.Class1();
     MWArray metFile = new MWCharArray(@"Burnie.sim");
     MWArray startMonth = new MWNumericArray((double) 6.0);
     MWArray startDay = new MWNumericArray((double) 1.0);
     MWArray rainOnly = new MWNumericArray((double)1.0);
     MWArray writeFiles = new MWNumericArray((double)1.0);
     MWArray lastYearOnly = new MWNumericArray((double)1.0);
     d.calsite(metFile, startMonth, startDay, rainOnly, writeFiles, lastYearOnly);
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(@"G:\");
            POAMAforecast.Class1 d = new POAMAforecast.Class1();
            MWArray metFile        = new MWCharArray(@"Burnie.sim");
            MWArray startMonth     = new MWNumericArray((double)6.0);
            MWArray startDay       = new MWNumericArray((double)1.0);
            MWArray rainOnly       = new MWNumericArray((double)1.0);
            MWArray writeFiles     = new MWNumericArray((double)1.0);
            MWArray lastYearOnly   = new MWNumericArray((double)1.0);

            d.calsite(metFile, startMonth, startDay, rainOnly, writeFiles, lastYearOnly);
        }
Ejemplo n.º 4
0
 /// <summary>Update the NetCDF files behind the forecast system.</summary>
 public void Update()
 {
     ChangeToWorkingDirectory();
     POAMAforecast.Class1 forecast = new POAMAforecast.Class1();
     forecast.update_e24_2014on();
 }
Ejemplo n.º 5
0
        /// <summary>Get a rainfall forecast for the specified station number.</summary>
        /// <param name="stationNumber">The SILO station number.</param>
        /// <returns>Stream of data.</returns>
        private Stream Get(int stationNumber, DateTime nowDate, bool rainOnly, bool asPlainText)
        {
            // Get SILO data and write to a temporary file.
            DateTime     startDate        = new DateTime(1981, 1, 1);
            MemoryStream dataStream       = Weather.ExtractMetStreamFromSILO(stationNumber, startDate, DateTime.Now);
            string       siloFileName     = GetTemporaryFileName();
            string       forecastFileName = null;

            try
            {
                File.WriteAllBytes(siloFileName, dataStream.ToArray());

                ChangeToWorkingDirectory();

                // Run the MatLab script over the temporary SILO file.
                POAMAforecast.Class1 forecast = new POAMAforecast.Class1();

                MWArray metFile      = new MWCharArray(siloFileName);
                MWArray rainfallOnly = new MWNumericArray((double)1);
                if (!rainOnly)
                {
                    rainfallOnly = new MWNumericArray((double)0);
                }
                MWArray writeFiles = new MWNumericArray((double)1.0);
                MWArray startDay   = new MWNumericArray(Convert.ToDouble(nowDate.Day));
                MWArray startMonth = new MWNumericArray(Convert.ToDouble(nowDate.Month));
                MWArray startYear  = new MWNumericArray(Convert.ToDouble(nowDate.Year));
                forecast.calsite(metFile, rainfallOnly, writeFiles, startDay, startMonth, startYear);

                forecastFileName = siloFileName.Replace(".sim", "") + "_" + nowDate.Year + ".sim";

                // Get rid of temporary file.
                File.Delete(siloFileName);

                if (asPlainText && WebOperationContext.Current != null && WebOperationContext.Current.OutgoingRequest != null)
                {
                    WebOperationContext.Current.OutgoingResponse.ContentType = "text/plain";
                }
                if (File.Exists(forecastFileName))
                {
                    // Read in the forecast data.
                    byte[] bytes = File.ReadAllBytes(forecastFileName);
                    return(new MemoryStream(bytes));
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                if (File.Exists(siloFileName))
                {
                    File.Delete(siloFileName);
                }
                if (forecastFileName != null && File.Exists(forecastFileName))
                {
                    File.Delete(forecastFileName);
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>Update the NetCDF files behind the forecast system.</summary>
 public void Update()
 {
     ChangeToWorkingDirectory();
     POAMAforecast.Class1 forecast = new POAMAforecast.Class1();
     forecast.update_e24_2014on();
 }