Text_readNC.cs 13 KB

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