Text_readNC.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 = $"{Util.baseURl}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 timeArray: " + timeArray[0]);
  68. }
  69. }
  70. string url2 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=u10&centerLon=116.41992593821296&centerLat=40.18801994965735";
  71. // Create a GET request to the specified URL
  72. HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(url2);
  73. request1.Method = "GET";
  74. // Send request and get response
  75. using (HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse())
  76. {
  77. using (StreamReader reader2 = new StreamReader(response2.GetResponseStream()))
  78. {
  79. string result2 = reader2.ReadToEnd();
  80. // Parse the JSON string into a JObject
  81. JObject resultObject2 = JObject.Parse(result2);
  82. // Extract the 'data' field from the parsed JObject
  83. JArray dataArray2 = (JArray)resultObject2["data"];
  84. // Determine the dimensions of the data array
  85. int timeSteps2 = dataArray2.Count;
  86. int latitudes2 = ((JArray)dataArray2[0]).Count;
  87. int longitudes2 = ((JArray)dataArray2[0][0]).Count;
  88. // Initialize float[][][] array
  89. float[][][] u10Array = new float[timeSteps2][][];
  90. // Convert each element to float and populate v10Array
  91. for (int t = 0; t < timeSteps2; t++)
  92. {
  93. u10Array[t] = new float[latitudes2][];
  94. for (int lat = 0; lat < latitudes2; lat++)
  95. {
  96. u10Array[t][lat] = new float[longitudes2];
  97. for (int lon = 0; lon < longitudes2; lon++)
  98. {
  99. u10Array[t][lat][lon] = (float)dataArray2[t][lat][lon];
  100. }
  101. }
  102. }
  103. windNCread.u10Array = u10Array;
  104. }
  105. }
  106. string url3 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=p140208&centerLon=116.41992593821296&centerLat=40.18801994965735";
  107. // Create a GET request to the specified URL
  108. HttpWebRequest request3 = (HttpWebRequest)WebRequest.Create(url3);
  109. request1.Method = "GET";
  110. // Send request and get response
  111. using (HttpWebResponse response3 = (HttpWebResponse)request3.GetResponse())
  112. {
  113. using (StreamReader reader3 = new StreamReader(response3.GetResponseStream()))
  114. {
  115. string result3 = reader3.ReadToEnd();
  116. // Parse the JSON string into a JObject
  117. JObject resultObject3 = JObject.Parse(result3);
  118. // Extract the 'data' field from the parsed JObject
  119. JArray dataArray3 = (JArray)resultObject3["data"];
  120. // Determine the dimensions of the data array
  121. int timeSteps3 = dataArray3.Count;
  122. int latitudes3 = ((JArray)dataArray3[0]).Count;
  123. int longitudes3 = ((JArray)dataArray3[0][0]).Count;
  124. // Initialize float[][][] array
  125. float[][][] p140208Array = new float[timeSteps3][][];
  126. // Convert each element to float and populate v10Array
  127. for (int t = 0; t < timeSteps3; t++)
  128. {
  129. p140208Array[t] = new float[latitudes3][];
  130. for (int lat = 0; lat < latitudes3; lat++)
  131. {
  132. p140208Array[t][lat] = new float[longitudes3];
  133. for (int lon = 0; lon < longitudes3; lon++)
  134. {
  135. p140208Array[t][lat][lon] = (float)dataArray3[t][lat][lon];
  136. }
  137. }
  138. }
  139. windNCread.p140208Array = p140208Array;
  140. }
  141. }
  142. string url4 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=mwd&centerLon=116.41992593821296&centerLat=40.18801994965735";
  143. // Create a GET request to the specified URL
  144. HttpWebRequest request4 = (HttpWebRequest)WebRequest.Create(url4);
  145. request1.Method = "GET";
  146. // Send request and get response
  147. using (HttpWebResponse response4 = (HttpWebResponse)request4.GetResponse())
  148. {
  149. using (StreamReader reader4 = new StreamReader(response4.GetResponseStream()))
  150. {
  151. string result4 = reader4.ReadToEnd();
  152. // Parse the JSON string into a JObject
  153. JObject resultObject4 = JObject.Parse(result4);
  154. // Extract the 'data' field from the parsed JObject
  155. JArray dataArray4 = (JArray)resultObject4["data"];
  156. // Determine the dimensions of the data array
  157. int timeSteps4 = dataArray4.Count;
  158. int latitudes4 = ((JArray)dataArray4[0]).Count;
  159. int longitudes4 = ((JArray)dataArray4[0][0]).Count;
  160. // Initialize float[][][] array
  161. float[][][] mwdArray = new float[timeSteps4][][];
  162. // Convert each element to float and populate v10Array
  163. for (int t = 0; t < timeSteps4; t++)
  164. {
  165. mwdArray[t] = new float[latitudes4][];
  166. for (int lat = 0; lat < latitudes4; lat++)
  167. {
  168. mwdArray[t][lat] = new float[longitudes4];
  169. for (int lon = 0; lon < longitudes4; lon++)
  170. {
  171. mwdArray[t][lat][lon] = (float)dataArray4[t][lat][lon];
  172. }
  173. }
  174. }
  175. windNCread.mwdArray = mwdArray;
  176. }
  177. }
  178. }
  179. public void GetWaveHighData()
  180. {
  181. //中心点坐标应该选取伤员初始位置坐标
  182. string url1 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/WaveHeight.nc&varName=hmax&centerLon=116.41992593821296&centerLat=40.18801994965735";
  183. // Create a GET request to the specified URL
  184. HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
  185. request1.Method = "GET";
  186. // Send request and get response
  187. using (HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse())
  188. {
  189. using (StreamReader reader1 = new StreamReader(response1.GetResponseStream()))
  190. {
  191. string result1 = reader1.ReadToEnd();
  192. // Parse the JSON string into a JObject
  193. JObject resultObject1 = JObject.Parse(result1);
  194. // Extract the 'data' field from the parsed JObject
  195. JArray dataArray1 = (JArray)resultObject1["data"];
  196. // Determine the dimensions of the data array
  197. int timeSteps = dataArray1.Count;
  198. int latitudes = ((JArray)dataArray1[0]).Count;
  199. int longitudes = ((JArray)dataArray1[0][0]).Count;
  200. // Initialize float[][][] array
  201. float[][][] hmaxArray = new float[timeSteps][][];
  202. for (int t = 0; t < timeSteps; t++)
  203. {
  204. hmaxArray[t] = new float[latitudes][];
  205. for (int lat = 0; lat < latitudes; lat++)
  206. {
  207. hmaxArray[t][lat] = new float[longitudes];
  208. for (int lon = 0; lon < longitudes; lon++)
  209. {
  210. hmaxArray[t][lat][lon] = (float)dataArray1[t][lat][lon];
  211. }
  212. }
  213. }
  214. JArray lonArray = (JArray)resultObject1["data_lon"];
  215. JArray lanArray = (JArray)resultObject1["data_lat"];
  216. //JArray tArray = (JArray)resultObject["data_time"];
  217. int lons = lonArray.Count;
  218. int lans = lanArray.Count;
  219. //int times = tArray.Count;
  220. float[] longitudeArray = new float[lons];
  221. float[] latitudeArray = new float[lans];
  222. //float[] timeArray = new float[times];
  223. for (int i = 0; i < lons; i++)
  224. {
  225. longitudeArray[i] = (float)lonArray[i];
  226. }
  227. for (int j = 0; j < lans; j++)
  228. {
  229. latitudeArray[j] = (float)lanArray[j];
  230. }
  231. windNCread.hmaxArray = hmaxArray;
  232. //Console.WriteLine("a value of timeArray: " + timeArray[0]);
  233. }
  234. }
  235. }
  236. }