using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Diagnostics; public class station_data { private int year_; private int month_; private double tmax_; private double tmin_; private int af_days_; private double rainfall_; private double sunshine_; public station_data(int year,int month,double tmax,double tmin,int af_days,double rainfall,double sunshine) { year_ = year; month_ = month; tmax_ = tmax; tmin_ = tmin; af_days_ = af_days; rainfall_ = rainfall; sunshine_ = sunshine; } public int year { get { return year_; } set { } } public int month { get { return month_; } set { } } public double tmax { get { return tmax_; } set { } } public double tmin { get { return tmin_; } set { } } public int af_days { get { return af_days_; } set { } } public double rainfall { get { return rainfall_; } set { } } public double sunshine { get { return sunshine_; } set { } } public override string ToString() { return string.Format(" {0,4} {1,2} {2,5:##0.0} {3,5:##0.0} {4,3:##0} {5,5:##0.0} {6,5:##0.0}", year_, month_, tmax_, tmin_, af_days_, rainfall_, sunshine_); } } public class weather { public static int Main() { double t1,t2,t3; Console.WriteLine(DateTime.Now); Console.Write("Program starts"); var sw = Stopwatch.StartNew(); t1=sw.ElapsedMilliseconds / 1000.0; Console.WriteLine(" {0,5:0.000}",t1); // The program works with the Cwmystwyth site. // There are 618 records const int n_records = 618; const int n_months = 13; double [] rainfall_sum = new double[n_months] ; double [] rainfall_average = new double[n_months] ; string [] months = new string[n_months] { "", "January","February","March" ,"April" ,"May" ,"June", "July" ,"August" ,"September","October","November","December" }; for (int i=0;i -98.0 ) && (t.month==i) ) select t.rainfall; rainfall_sum[i] = select_rainfall.Sum(); rainfall_average[i] = select_rainfall.Average(); Console.Write("{0,10}",months[i]); Console.Write(" {0,8:##,###.0}", rainfall_sum[i] ) ; Console.WriteLine(" {0,8:####.00}", rainfall_average[i] ) ; } Console.Write("\nSequential"); t2=sw.ElapsedMilliseconds / 1000.0; t3=t2-t1; Console.WriteLine(" {0,5:0.000}",t3); t1=t2; t3=t2; Console.WriteLine("\n Imperial \n"); Console.WriteLine(" Sum Average"); for (int i=1;i -98.0 ) && (t.month==i) ) select t.rainfall; rainfall_sum[i] = select_parallel_rainfall.Sum()/25.4; rainfall_average[i] = select_parallel_rainfall.Average()/25.4; Console.Write("{0,10}",months[i]); Console.Write(" {0,8:##,###.0}", rainfall_sum[i] ) ; Console.WriteLine(" {0,8:####.00}", rainfall_average[i] ) ; } Console.Write("\nParallel "); t2=sw.ElapsedMilliseconds / 1000.0; t3=t2-t1; Console.WriteLine(" {0,5:0.000}\n",t3); Console.WriteLine("Program ends"); Console.WriteLine(DateTime.Now); return (0); } public static void read_station_data(station_data [] x,int n_records) { int year; int month; double tmax; double tmin; int af_days; double rainfall; double sunshine; const int h=7; int i; string line; string filename ="cwmystwythdata.txt"; if (!File.Exists(filename)) { Console.WriteLine("{0} not found.", filename); Environment.Exit(1); } StreamReader input_file=File.OpenText(filename); // skip 7 header lines // print out the header lines for (i=0;i(IEnumerable x, string heading) { Console.WriteLine(" {0} ", heading); foreach (T i in x) Console.WriteLine(i); } }