Text_readNC.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using System.Net;
  2. using Newtonsoft.Json.Linq;
  3. namespace SimulationCommon;
  4. public class Text_readNC
  5. {
  6. public NCread windNCread = new NCread();
  7. public void GetNCData()
  8. {
  9. string url1 = "http://10.130.100.5:7785//rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=v10&centerLon=116.41992593821296&centerLat=40.18801994965735";
  10. // Create a GET request to the specified URL
  11. HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
  12. request1.Method = "GET";
  13. // Send request and get response
  14. using (HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse())
  15. {
  16. using (StreamReader reader1 = new StreamReader(response1.GetResponseStream()))
  17. {
  18. string result1 = reader1.ReadToEnd();
  19. // Parse the JSON string into a JObject
  20. JObject resultObject1 = JObject.Parse(result1);
  21. // Extract the 'data' field from the parsed JObject
  22. JArray dataArray1 = (JArray)resultObject1["data"];
  23. // Determine the dimensions of the data array
  24. int timeSteps = dataArray1.Count;
  25. int latitudes = ((JArray)dataArray1[0]).Count;
  26. int longitudes = ((JArray)dataArray1[0][0]).Count;
  27. // Initialize float[][][] array
  28. float[][][] v10Array = new float[timeSteps][][];
  29. // Convert each element to float and populate v10Array
  30. for (int t = 0; t < timeSteps; t++)
  31. {
  32. v10Array[t] = new float[latitudes][];
  33. for (int lat = 0; lat < latitudes; lat++)
  34. {
  35. v10Array[t][lat] = new float[longitudes];
  36. for (int lon = 0; lon < longitudes; lon++)
  37. {
  38. v10Array[t][lat][lon] = (float)dataArray1[t][lat][lon];
  39. }
  40. }
  41. }
  42. JArray lonArray = (JArray)resultObject1["data_lon"];
  43. JArray lanArray = (JArray)resultObject1["data_lat"];
  44. //JArray tArray = (JArray)resultObject["data_time"];
  45. int lons = lonArray.Count;
  46. int lans = lanArray.Count;
  47. //int times = tArray.Count;
  48. float[] longitudeArray = new float[lons];
  49. float[] latitudeArray = new float[lans];
  50. //float[] timeArray = new float[times];
  51. for (int i = 0; i < lons; i++)
  52. {
  53. longitudeArray[i] = (float)lonArray[i];
  54. }
  55. for (int j = 0; j < lans; j++)
  56. {
  57. latitudeArray[j] = (float)lanArray[j];
  58. }
  59. /* for (int k = 0; k < lons; k++)
  60. {
  61. timeArray[k] = (float)tArray[k];
  62. }*/
  63. windNCread.latitudeArray = latitudeArray;
  64. windNCread.longitudeArray = longitudeArray;
  65. windNCread.v10Array = v10Array;
  66. // Example: Print the first value of the array
  67. Console.WriteLine("a value of v10Array: " + v10Array[0][6][9]);
  68. Console.WriteLine("a value of longitudeArray: " + longitudeArray[0]);
  69. Console.WriteLine("a value of latitudeArray: " + latitudeArray[0]);
  70. //Console.WriteLine("a value of timeArray: " + timeArray[0]);
  71. }
  72. }
  73. string url2 = "http://10.130.100.5:7785//rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=u10&centerLon=116.41992593821296&centerLat=40.18801994965735";
  74. // Create a GET request to the specified URL
  75. HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(url2);
  76. request1.Method = "GET";
  77. // Send request and get response
  78. using (HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse())
  79. {
  80. using (StreamReader reader2 = new StreamReader(response2.GetResponseStream()))
  81. {
  82. string result2 = reader2.ReadToEnd();
  83. // Parse the JSON string into a JObject
  84. JObject resultObject2 = JObject.Parse(result2);
  85. // Extract the 'data' field from the parsed JObject
  86. JArray dataArray2 = (JArray)resultObject2["data"];
  87. // Determine the dimensions of the data array
  88. int timeSteps2 = dataArray2.Count;
  89. int latitudes2 = ((JArray)dataArray2[0]).Count;
  90. int longitudes2 = ((JArray)dataArray2[0][0]).Count;
  91. // Initialize float[][][] array
  92. float[][][] u10Array = new float[timeSteps2][][];
  93. // Convert each element to float and populate v10Array
  94. for (int t = 0; t < timeSteps2; t++)
  95. {
  96. u10Array[t] = new float[latitudes2][];
  97. for (int lat = 0; lat < latitudes2; lat++)
  98. {
  99. u10Array[t][lat] = new float[longitudes2];
  100. for (int lon = 0; lon < longitudes2; lon++)
  101. {
  102. u10Array[t][lat][lon] = (float)dataArray2[t][lat][lon];
  103. }
  104. }
  105. }
  106. windNCread.u10Array = u10Array;
  107. Console.WriteLine("a value of u10Array: " + u10Array[0][6][9]);
  108. }
  109. }
  110. string url3 = "http://10.130.100.5:7785//rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=p140208&centerLon=116.41992593821296&centerLat=40.18801994965735";
  111. // Create a GET request to the specified URL
  112. HttpWebRequest request3 = (HttpWebRequest)WebRequest.Create(url3);
  113. request1.Method = "GET";
  114. // Send request and get response
  115. using (HttpWebResponse response3 = (HttpWebResponse)request3.GetResponse())
  116. {
  117. using (StreamReader reader3 = new StreamReader(response3.GetResponseStream()))
  118. {
  119. string result3 = reader3.ReadToEnd();
  120. // Parse the JSON string into a JObject
  121. JObject resultObject3 = JObject.Parse(result3);
  122. // Extract the 'data' field from the parsed JObject
  123. JArray dataArray3 = (JArray)resultObject3["data"];
  124. // Determine the dimensions of the data array
  125. int timeSteps3 = dataArray3.Count;
  126. int latitudes3 = ((JArray)dataArray3[0]).Count;
  127. int longitudes3 = ((JArray)dataArray3[0][0]).Count;
  128. // Initialize float[][][] array
  129. float[][][] p140208Array = new float[timeSteps3][][];
  130. // Convert each element to float and populate v10Array
  131. for (int t = 0; t < timeSteps3; t++)
  132. {
  133. p140208Array[t] = new float[latitudes3][];
  134. for (int lat = 0; lat < latitudes3; lat++)
  135. {
  136. p140208Array[t][lat] = new float[longitudes3];
  137. for (int lon = 0; lon < longitudes3; lon++)
  138. {
  139. p140208Array[t][lat][lon] = (float)dataArray3[t][lat][lon];
  140. }
  141. }
  142. }
  143. windNCread.p140208Array = p140208Array;
  144. Console.WriteLine("a value of p140208Array: " + p140208Array[2][3][9]);
  145. }
  146. }
  147. string url4 = "http://10.130.100.5:7785//rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=mwd&centerLon=116.41992593821296&centerLat=40.18801994965735";
  148. // Create a GET request to the specified URL
  149. HttpWebRequest request4 = (HttpWebRequest)WebRequest.Create(url4);
  150. request1.Method = "GET";
  151. // Send request and get response
  152. using (HttpWebResponse response4 = (HttpWebResponse)request4.GetResponse())
  153. {
  154. using (StreamReader reader4 = new StreamReader(response4.GetResponseStream()))
  155. {
  156. string result4 = reader4.ReadToEnd();
  157. // Parse the JSON string into a JObject
  158. JObject resultObject4 = JObject.Parse(result4);
  159. // Extract the 'data' field from the parsed JObject
  160. JArray dataArray4 = (JArray)resultObject4["data"];
  161. // Determine the dimensions of the data array
  162. int timeSteps4 = dataArray4.Count;
  163. int latitudes4 = ((JArray)dataArray4[0]).Count;
  164. int longitudes4 = ((JArray)dataArray4[0][0]).Count;
  165. // Initialize float[][][] array
  166. float[][][] mwdArray = new float[timeSteps4][][];
  167. // Convert each element to float and populate v10Array
  168. for (int t = 0; t < timeSteps4; t++)
  169. {
  170. mwdArray[t] = new float[latitudes4][];
  171. for (int lat = 0; lat < latitudes4; lat++)
  172. {
  173. mwdArray[t][lat] = new float[longitudes4];
  174. for (int lon = 0; lon < longitudes4; lon++)
  175. {
  176. mwdArray[t][lat][lon] = (float)dataArray4[t][lat][lon];
  177. }
  178. }
  179. }
  180. windNCread.mwdArray = mwdArray;
  181. Console.WriteLine("a value of mwdArray: " + mwdArray[2][3][9]);
  182. Console.ReadKey();
  183. }
  184. }
  185. }
  186. }