using System.Net; using Newtonsoft.Json.Linq; namespace SimulationCommon; public class Text_readNC { public NCread windNCread = new NCread(); public int times; public int latitudes; public int longitudes; public int times1; public int latitudes1; public int longitudes1; public int times2; public int latitudes2; public int longitudes2; public int times3; public int latitudes3; public int longitudes3; public int times4; public int latitudes4; public int longitudes4; public double initlatitudes; public double initlongitudes; public bool GetNCData() { //"http://10.130.100.5:7785//rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=v10¢erLon=116.41992593821296¢erLat=40.18801994965735" //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"; string url1 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_u10_v10_temp.nc&varName=v10¢erLon=" + initlongitudes.ToString() + "¢erLat=" + initlatitudes.ToString(); // Create a GET request to the specified URL HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1); request1.Method = "GET"; // Send request and get response using (HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse()) { using (StreamReader reader1 = new StreamReader(response1.GetResponseStream())) { string result1 = reader1.ReadToEnd(); //Console.WriteLine("result1:" + result1); // Parse the JSON string into a JObject JObject resultObject1 = JObject.Parse(result1); // Extract the 'data' field from the parsed JObject JArray dataArray1 = (JArray)resultObject1["data"]; if (dataArray1 == null) return false; // Determine the dimensions of the data array times = dataArray1.Count; latitudes = ((JArray)dataArray1[0]).Count; longitudes = ((JArray)dataArray1[0][0]).Count; // Initialize float[][][] array float[][][] v10Array = new float[times][][]; // Convert each element to float and populate v10Array for (int t = 0; t < times; t++) { v10Array[t] = new float[latitudes][]; for (int lat = 0; lat < latitudes; lat++) { v10Array[t][lat] = new float[longitudes]; for (int lon = 0; lon < longitudes; lon++) { v10Array[t][lat][lon] = (float)dataArray1[t][lat][lon]; } } } JArray lonArray = (JArray)resultObject1["data_lon"]; JArray lanArray = (JArray)resultObject1["data_lat"]; //JArray tArray = (JArray)resultObject["data_time"]; int lons = lonArray.Count; int lans = lanArray.Count; //int times = tArray.Count; float[] longitudeArray = new float[lons]; float[] latitudeArray = new float[lans]; //float[] timeArray = new float[times]; for (int i = 0; i < lons; i++) { longitudeArray[i] = (float)lonArray[i]; } for (int j = 0; j < lans; j++) { latitudeArray[j] = (float)lanArray[j]; } /* for (int k = 0; k < lons; k++) { timeArray[k] = (float)tArray[k]; }*/ windNCread.latitudeArray = latitudeArray; windNCread.longitudeArray = longitudeArray; windNCread.v10Array = v10Array; // Example: Print the first value of the array //Console.WriteLine("a value of timeArray: " + timeArray[0]); } } string url2 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_u10_v10_temp.nc&varName=u10¢erLon=" + initlongitudes + "¢erLat=" + initlatitudes; // Create a GET request to the specified URL HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(url2); request1.Method = "GET"; // Send request and get response using (HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse()) { using (StreamReader reader2 = new StreamReader(response2.GetResponseStream())) { string result2 = reader2.ReadToEnd(); //Console.WriteLine("result2:" + result2); // Parse the JSON string into a JObject JObject resultObject2 = JObject.Parse(result2); // Extract the 'data' field from the parsed JObject JArray dataArray2 = (JArray)resultObject2["data"]; if (dataArray2 == null) return false; // Determine the dimensions of the data array times1 = dataArray2.Count; latitudes1 = ((JArray)dataArray2[0]).Count; longitudes1 = ((JArray)dataArray2[0][0]).Count; // Initialize float[][][] array float[][][] u10Array = new float[times1][][]; // Convert each element to float and populate v10Array for (int t = 0; t < times1; t++) { u10Array[t] = new float[latitudes1][]; for (int lat = 0; lat < latitudes1; lat++) { u10Array[t][lat] = new float[longitudes1]; for (int lon = 0; lon < longitudes1; lon++) { u10Array[t][lat][lon] = (float)dataArray2[t][lat][lon]; } } } windNCread.u10Array = u10Array; } } string url3 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_mwd_currentV_waveHeight.nc&varName=p140208¢erLon=" + initlongitudes + "¢erLat=" + initlatitudes; // Create a GET request to the specified URL HttpWebRequest request3 = (HttpWebRequest)WebRequest.Create(url3); request1.Method = "GET"; // Send request and get response using (HttpWebResponse response3 = (HttpWebResponse)request3.GetResponse()) { using (StreamReader reader3 = new StreamReader(response3.GetResponseStream())) { string result3 = reader3.ReadToEnd(); //Console.WriteLine("result3:" + result3); // Parse the JSON string into a JObject JObject resultObject3 = JObject.Parse(result3); // Extract the 'data' field from the parsed JObject JArray dataArray3 = (JArray)resultObject3["data"]; if (dataArray3 == null) return false; // Determine the dimensions of the data array times2 = dataArray3.Count; latitudes2 = ((JArray)dataArray3[0]).Count; longitudes2 = ((JArray)dataArray3[0][0]).Count; // Initialize float[][][] array float[][][] p140208Array = new float[times2][][]; // Convert each element to float and populate v10Array for (int t = 0; t < times2; t++) { p140208Array[t] = new float[latitudes2][]; for (int lat = 0; lat < latitudes2; lat++) { p140208Array[t][lat] = new float[longitudes2]; for (int lon = 0; lon < longitudes2; lon++) { p140208Array[t][lat][lon] = (float)dataArray3[t][lat][lon]; } } } windNCread.p140208Array = p140208Array; } } string url4 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_mwd_currentV_waveHeight.nc&varName=mwd¢erLon=" + initlongitudes + "¢erLat=" + initlatitudes; // Create a GET request to the specified URL HttpWebRequest request4 = (HttpWebRequest)WebRequest.Create(url4); request1.Method = "GET"; // Send request and get response using (HttpWebResponse response4 = (HttpWebResponse)request4.GetResponse()) { using (StreamReader reader4 = new StreamReader(response4.GetResponseStream())) { string result4 = reader4.ReadToEnd(); //Console.WriteLine("result4:" + result4); // Parse the JSON string into a JObject JObject resultObject4 = JObject.Parse(result4); // Extract the 'data' field from the parsed JObject JArray dataArray4 = (JArray)resultObject4["data"]; if (dataArray4 == null) return false; // Determine the dimensions of the data array times3 = dataArray4.Count; latitudes3 = ((JArray)dataArray4[0]).Count; longitudes3 = ((JArray)dataArray4[0][0]).Count; // Initialize float[][][] array float[][][] mwdArray = new float[times3][][]; // Convert each element to float and populate v10Array for (int t = 0; t < times3; t++) { mwdArray[t] = new float[latitudes3][]; for (int lat = 0; lat < latitudes3; lat++) { mwdArray[t][lat] = new float[longitudes3]; for (int lon = 0; lon < longitudes3; lon++) { mwdArray[t][lat][lon] = (float)dataArray4[t][lat][lon]; } } } windNCread.mwdArray = mwdArray; } } return true; } public bool GetWaveHighData() { //中心点坐标应该选取伤员初始位置坐标 string url1 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_mwd_currentV_waveHeight.nc&varName=hmax¢erLon=" + initlongitudes + "¢erLat=" + initlatitudes; // Create a GET request to the specified URL HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1); request1.Method = "GET"; // Send request and get response using (HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse()) { using (StreamReader reader1 = new StreamReader(response1.GetResponseStream())) { string result1 = reader1.ReadToEnd(); //Console.WriteLine("result1:" + result1); // Parse the JSON string into a JObject JObject resultObject1 = JObject.Parse(result1); // Extract the 'data' field from the parsed JObject JArray dataArray1 = (JArray)resultObject1["data"]; if (dataArray1 == null) return false; // Determine the dimensions of the data array times4 = dataArray1.Count; latitudes4 = ((JArray)dataArray1[0]).Count; longitudes4 = ((JArray)dataArray1[0][0]).Count; // Initialize float[][][] array float[][][] hmaxArray = new float[times4][][]; for (int t = 0; t < times4; t++) { hmaxArray[t] = new float[latitudes4][]; for (int lat = 0; lat < latitudes4; lat++) { hmaxArray[t][lat] = new float[longitudes4]; for (int lon = 0; lon < longitudes4; lon++) { hmaxArray[t][lat][lon] = (float)dataArray1[t][lat][lon]; } } } JArray lonArray = (JArray)resultObject1["data_lon"]; JArray lanArray = (JArray)resultObject1["data_lat"]; //JArray tArray = (JArray)resultObject["data_time"]; int lons = lonArray.Count; int lans = lanArray.Count; //int times = tArray.Count; float[] longitudeArray = new float[lons]; float[] latitudeArray = new float[lans]; //float[] timeArray = new float[times]; for (int i = 0; i < lons; i++) { longitudeArray[i] = (float)lonArray[i]; } for (int j = 0; j < lans; j++) { latitudeArray[j] = (float)lanArray[j]; } windNCread.hmaxArray = hmaxArray; //Console.WriteLine("a value of timeArray: " + timeArray[0]); } } return true; } }