Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. string fileName = "lake1.txt";
  2.  
  3. //===================================================
  4.  
  5. // This line of code has to be in the submission -
  6.  
  7. // Remove comment before submission
  8.  
  9. //fileName = args[0];
  10.  
  11. //===================================================
  12.  
  13. int noData;
  14.  
  15. double[,] myData01 = ReadData_2Darray(fileName, out noData);
  16.  
  17. double[] Depth = new double[noData];
  18.  
  19. double[] Temperature = new double[noData];
  20.  
  21. double[] Oxygen = new double[noData];
  22.  
  23. for (int i = 0; i < noData; i++)
  24.  
  25. {
  26.  
  27. Depth[i] = myData01[i, 0];
  28.  
  29. Temperature[i] = myData01[i, 1];
  30.  
  31. Oxygen[i] = myData01[i, 2];
  32.  
  33. }
  34.  
  35. double max = Temperature.Max();
  36.  
  37. double min = Temperature.Min();
  38.  
  39. Console.WriteLine("Max Temperature is : {0} ", max);
  40.  
  41. Console.WriteLine("Min Temperature is : {0} ", min);
  42.  
  43. //Slope of Depth vs Temperature
  44.  
  45. //Getting depth and position of thermocline
  46.  
  47. double maxslope = (Temperature[1] - Temperature[0]) / (Depth[1] - Depth[0]);
  48.  
  49. int thermocline = 0;
  50.  
  51. for (int i = 1; i < Temperature.Length - 1; i++)
  52.  
  53. {
  54.  
  55. double slope = (Temperature[i + 1] - Temperature[i]) / (Depth[i + 1] - Depth[i]);
  56.  
  57. if (Math.Abs(slope) > Math.Abs(maxslope))
  58.  
  59. {
  60.  
  61. maxslope = slope;
  62.  
  63. thermocline = i;
  64.  
  65. }
  66.  
  67. }
  68.  
  69. Console.WriteLine("Thermo slope : {0} ", maxslope);
  70.  
  71. Console.WriteLine("Position : {0}", thermocline);
  72.  
  73. Console.WriteLine("Starting depth : {0}", Depth[thermocline]);
  74.  
  75. Console.WriteLine("Finishing depth : {0}",Depth[thermocline + 1]);
  76.  
  77. //Calculating Epilimnion
  78.  
  79. double sum = 0;
  80.  
  81. for (int i = 0; i < thermocline - 1; i++)
  82.  
  83. {
  84.  
  85. sum += Oxygen[i];
  86.  
  87. }
  88.  
  89. double Epilimnion = sum/thermocline;
  90.  
  91. Console.WriteLine("The average Oxygen level in the Epilimnion is : {0} ",Epilimnion);
  92.  
  93. //Calculating Hypolimnion
  94.  
  95. double sum1 = 0;
  96.  
  97. for (int j = thermocline +2; j < Temperature.Length - 1; j++)
  98.  
  99. {
  100.  
  101. sum1 += Oxygen[j];
  102.  
  103. }
  104.  
  105. double Hypolimnion = sum1 / (Temperature.Length - (thermocline + 2));
  106.  
  107. Console.WriteLine("The average Oxygen level in the Hypolinmion is : {0} ",Hypolimnion);
  108.  
  109. if (Hypolimnion > 5)
  110.  
  111. {
  112.  
  113. Console.WriteLine("The average Oxygen levels are above the minimum allowable of 5mg/L : {0}", Hypolimnion);
  114.  
  115. }
  116.  
  117. else if (Hypolimnion<=5)
  118.  
  119. {
  120.  
  121. Console.WriteLine("The average Oxygen levels are below the minimum allowable of 5mg/L in the Hypolimnion");
  122.  
  123. }
  124.  
  125. Console.ReadLine();
  126.  
  127. }
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. static double[,] ReadData_2Darray(string DataFile, out int noDataLines)
  140.  
  141. {
  142.  
  143. string s;
  144.  
  145. System.IO.StreamReader inputFile = new System.IO.StreamReader(DataFile);
  146.  
  147. s = inputFile.ReadLine();
  148.  
  149. noDataLines = int.Parse(s);
  150.  
  151. double[,] data = new double[noDataLines, 3];
  152.  
  153. string[] ss;
  154.  
  155. for (int i = 0; i < data.GetLength(0); i++)
  156.  
  157. {
  158.  
  159. s = inputFile.ReadLine();
  160.  
  161. ss = s.Split(',');
  162.  
  163. for (int j = 0; j < data.GetLength(1); j++)
  164.  
  165. data[i, j] = double.Parse(ss[j]);
  166.  
  167. }
  168.  
  169. inputFile.Close();
  170.  
  171. return data;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement