Text_readNC.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 int times;
  8. public int latitudes;
  9. public int longitudes;
  10. //public int timeSteps2;
  11. //public int latitudes2;
  12. //public int longitudes2;
  13. //public int timeSteps3;
  14. //public int latitudes3;
  15. //public int longitudes3;
  16. //public int timeSteps4;
  17. //public int latitudes4;
  18. //public int longitudes4;
  19. //public int timeSteps1;
  20. //public int latitudes1;
  21. //public int longitudes1;
  22. public double initlatitudes;
  23. public double initlongitudes;
  24. public void GetNCData()
  25. {
  26. //"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"
  27. //string url1 = "http://10.130.100.5:7785//rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_u10_v10_temp.nc&varName=v10";
  28. string url1 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_u10_v10_temp.nc&varName=v10&centerLon=" + initlongitudes.ToString() + "&centerLat=" + initlatitudes.ToString();
  29. // Create a GET request to the specified URL
  30. HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
  31. request1.Method = "GET";
  32. // Send request and get response
  33. using (HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse())
  34. {
  35. using (StreamReader reader1 = new StreamReader(response1.GetResponseStream()))
  36. {
  37. string result1 = reader1.ReadToEnd();
  38. // Parse the JSON string into a JObject
  39. JObject resultObject1 = JObject.Parse(result1);
  40. // Extract the 'data' field from the parsed JObject
  41. JArray dataArray1 = (JArray)resultObject1["data"];
  42. // Determine the dimensions of the data array
  43. times = dataArray1.Count;
  44. latitudes = ((JArray)dataArray1[0]).Count;
  45. longitudes = ((JArray)dataArray1[0][0]).Count;
  46. // Initialize float[][][] array
  47. float[][][] v10Array = new float[times][][];
  48. // Convert each element to float and populate v10Array
  49. for (int t = 0; t < times; t++)
  50. {
  51. v10Array[t] = new float[latitudes][];
  52. for (int lat = 0; lat < latitudes; lat++)
  53. {
  54. v10Array[t][lat] = new float[longitudes];
  55. for (int lon = 0; lon < longitudes; lon++)
  56. {
  57. v10Array[t][lat][lon] = (float)dataArray1[t][lat][lon];
  58. }
  59. }
  60. }
  61. JArray lonArray = (JArray)resultObject1["data_lon"];
  62. JArray lanArray = (JArray)resultObject1["data_lat"];
  63. //JArray tArray = (JArray)resultObject["data_time"];
  64. int lons = lonArray.Count;
  65. int lans = lanArray.Count;
  66. //int times = tArray.Count;
  67. float[] longitudeArray = new float[lons];
  68. float[] latitudeArray = new float[lans];
  69. //float[] timeArray = new float[times];
  70. for (int i = 0; i < lons; i++)
  71. {
  72. longitudeArray[i] = (float)lonArray[i];
  73. }
  74. for (int j = 0; j < lans; j++)
  75. {
  76. latitudeArray[j] = (float)lanArray[j];
  77. }
  78. /* for (int k = 0; k < lons; k++)
  79. {
  80. timeArray[k] = (float)tArray[k];
  81. }*/
  82. windNCread.latitudeArray = latitudeArray;
  83. windNCread.longitudeArray = longitudeArray;
  84. windNCread.v10Array = v10Array;
  85. // Example: Print the first value of the array
  86. //Console.WriteLine("a value of timeArray: " + timeArray[0]);
  87. }
  88. }
  89. string url2 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_u10_v10_temp.nc&varName=u10&centerLon=" + initlongitudes + "&centerLat=" + initlatitudes;
  90. // Create a GET request to the specified URL
  91. HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(url2);
  92. request1.Method = "GET";
  93. // Send request and get response
  94. using (HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse())
  95. {
  96. using (StreamReader reader2 = new StreamReader(response2.GetResponseStream()))
  97. {
  98. string result2 = reader2.ReadToEnd();
  99. // Parse the JSON string into a JObject
  100. JObject resultObject2 = JObject.Parse(result2);
  101. // Extract the 'data' field from the parsed JObject
  102. JArray dataArray2 = (JArray)resultObject2["data"];
  103. // Determine the dimensions of the data array
  104. times = dataArray2.Count;
  105. latitudes = ((JArray)dataArray2[0]).Count;
  106. longitudes = ((JArray)dataArray2[0][0]).Count;
  107. // Initialize float[][][] array
  108. float[][][] u10Array = new float[times][][];
  109. // Convert each element to float and populate v10Array
  110. for (int t = 0; t < times; t++)
  111. {
  112. u10Array[t] = new float[latitudes][];
  113. for (int lat = 0; lat < latitudes; lat++)
  114. {
  115. u10Array[t][lat] = new float[longitudes];
  116. for (int lon = 0; lon < longitudes; lon++)
  117. {
  118. u10Array[t][lat][lon] = (float)dataArray2[t][lat][lon];
  119. }
  120. }
  121. }
  122. windNCread.u10Array = u10Array;
  123. }
  124. }
  125. string url3 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_mwd_currentV_waveHeight.nc&varName=p140208&centerLon=" + initlongitudes + "&centerLat=" + initlatitudes;
  126. // Create a GET request to the specified URL
  127. HttpWebRequest request3 = (HttpWebRequest)WebRequest.Create(url3);
  128. request1.Method = "GET";
  129. // Send request and get response
  130. using (HttpWebResponse response3 = (HttpWebResponse)request3.GetResponse())
  131. {
  132. using (StreamReader reader3 = new StreamReader(response3.GetResponseStream()))
  133. {
  134. string result3 = reader3.ReadToEnd();
  135. // Parse the JSON string into a JObject
  136. JObject resultObject3 = JObject.Parse(result3);
  137. // Extract the 'data' field from the parsed JObject
  138. JArray dataArray3 = (JArray)resultObject3["data"];
  139. // Determine the dimensions of the data array
  140. times = dataArray3.Count;
  141. latitudes = ((JArray)dataArray3[0]).Count;
  142. longitudes = ((JArray)dataArray3[0][0]).Count;
  143. // Initialize float[][][] array
  144. float[][][] p140208Array = new float[times][][];
  145. // Convert each element to float and populate v10Array
  146. for (int t = 0; t < times; t++)
  147. {
  148. p140208Array[t] = new float[latitudes][];
  149. for (int lat = 0; lat < latitudes; lat++)
  150. {
  151. p140208Array[t][lat] = new float[longitudes];
  152. for (int lon = 0; lon < longitudes; lon++)
  153. {
  154. p140208Array[t][lat][lon] = (float)dataArray3[t][lat][lon];
  155. }
  156. }
  157. }
  158. windNCread.p140208Array = p140208Array;
  159. }
  160. }
  161. string url4 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_mwd_currentV_waveHeight.nc&varName=mwd&centerLon=" + initlongitudes + "&centerLat=" + initlatitudes;
  162. // Create a GET request to the specified URL
  163. HttpWebRequest request4 = (HttpWebRequest)WebRequest.Create(url4);
  164. request1.Method = "GET";
  165. // Send request and get response
  166. using (HttpWebResponse response4 = (HttpWebResponse)request4.GetResponse())
  167. {
  168. using (StreamReader reader4 = new StreamReader(response4.GetResponseStream()))
  169. {
  170. string result4 = reader4.ReadToEnd();
  171. // Parse the JSON string into a JObject
  172. JObject resultObject4 = JObject.Parse(result4);
  173. // Extract the 'data' field from the parsed JObject
  174. JArray dataArray4 = (JArray)resultObject4["data"];
  175. // Determine the dimensions of the data array
  176. times = dataArray4.Count;
  177. latitudes = ((JArray)dataArray4[0]).Count;
  178. longitudes = ((JArray)dataArray4[0][0]).Count;
  179. // Initialize float[][][] array
  180. float[][][] mwdArray = new float[times][][];
  181. // Convert each element to float and populate v10Array
  182. for (int t = 0; t < times; t++)
  183. {
  184. mwdArray[t] = new float[latitudes][];
  185. for (int lat = 0; lat < latitudes; lat++)
  186. {
  187. mwdArray[t][lat] = new float[longitudes];
  188. for (int lon = 0; lon < longitudes; lon++)
  189. {
  190. mwdArray[t][lat][lon] = (float)dataArray4[t][lat][lon];
  191. }
  192. }
  193. }
  194. windNCread.mwdArray = mwdArray;
  195. }
  196. }
  197. }
  198. public void GetWaveHighData()
  199. {
  200. //中心点坐标应该选取伤员初始位置坐标
  201. string url1 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_mwd_currentV_waveHeight.nc&varName=hmax&centerLon=" + initlongitudes + "&centerLat=" + initlatitudes;
  202. // Create a GET request to the specified URL
  203. HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
  204. request1.Method = "GET";
  205. // Send request and get response
  206. using (HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse())
  207. {
  208. using (StreamReader reader1 = new StreamReader(response1.GetResponseStream()))
  209. {
  210. string result1 = reader1.ReadToEnd();
  211. // Parse the JSON string into a JObject
  212. JObject resultObject1 = JObject.Parse(result1);
  213. // Extract the 'data' field from the parsed JObject
  214. JArray dataArray1 = (JArray)resultObject1["data"];
  215. // Determine the dimensions of the data array
  216. times = dataArray1.Count;
  217. latitudes = ((JArray)dataArray1[0]).Count;
  218. longitudes = ((JArray)dataArray1[0][0]).Count;
  219. // Initialize float[][][] array
  220. float[][][] hmaxArray = new float[times][][];
  221. for (int t = 0; t < times; t++)
  222. {
  223. hmaxArray[t] = new float[latitudes][];
  224. for (int lat = 0; lat < latitudes; lat++)
  225. {
  226. hmaxArray[t][lat] = new float[longitudes];
  227. for (int lon = 0; lon < longitudes; lon++)
  228. {
  229. hmaxArray[t][lat][lon] = (float)dataArray1[t][lat][lon];
  230. }
  231. }
  232. }
  233. JArray lonArray = (JArray)resultObject1["data_lon"];
  234. JArray lanArray = (JArray)resultObject1["data_lat"];
  235. //JArray tArray = (JArray)resultObject["data_time"];
  236. int lons = lonArray.Count;
  237. int lans = lanArray.Count;
  238. //int times = tArray.Count;
  239. float[] longitudeArray = new float[lons];
  240. float[] latitudeArray = new float[lans];
  241. //float[] timeArray = new float[times];
  242. for (int i = 0; i < lons; i++)
  243. {
  244. longitudeArray[i] = (float)lonArray[i];
  245. }
  246. for (int j = 0; j < lans; j++)
  247. {
  248. latitudeArray[j] = (float)lanArray[j];
  249. }
  250. windNCread.hmaxArray = hmaxArray;
  251. //Console.WriteLine("a value of timeArray: " + timeArray[0]);
  252. }
  253. }
  254. }
  255. }