123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- using System.Net;
- using Newtonsoft.Json.Linq;
- namespace SimulationCommon;
- public class Text_readNC
- {
- public NCread windNCread = new NCread();
- public void GetNCData()
- {
- string url1 = "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";
- // 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();
- // 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"];
- // Determine the dimensions of the data array
- int timeSteps = dataArray1.Count;
- int latitudes = ((JArray)dataArray1[0]).Count;
- int longitudes = ((JArray)dataArray1[0][0]).Count;
- // Initialize float[][][] array
- float[][][] v10Array = new float[timeSteps][][];
- // Convert each element to float and populate v10Array
- for (int t = 0; t < timeSteps; 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 = "http://10.130.100.5:7785//rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=u10¢erLon=116.41992593821296¢erLat=40.18801994965735";
- // 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();
- // 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"];
- // Determine the dimensions of the data array
- int timeSteps2 = dataArray2.Count;
- int latitudes2 = ((JArray)dataArray2[0]).Count;
- int longitudes2 = ((JArray)dataArray2[0][0]).Count;
- // Initialize float[][][] array
- float[][][] u10Array = new float[timeSteps2][][];
- // Convert each element to float and populate v10Array
- for (int t = 0; t < timeSteps2; t++)
- {
- u10Array[t] = new float[latitudes2][];
- for (int lat = 0; lat < latitudes2; lat++)
- {
- u10Array[t][lat] = new float[longitudes2];
- for (int lon = 0; lon < longitudes2; lon++)
- {
- u10Array[t][lat][lon] = (float)dataArray2[t][lat][lon];
- }
- }
- }
-
-
- windNCread.u10Array = u10Array;
- }
- }
- string url3 = "http://10.130.100.5:7785//rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=p140208¢erLon=116.41992593821296¢erLat=40.18801994965735";
- // 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();
- // 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"];
- // Determine the dimensions of the data array
- int timeSteps3 = dataArray3.Count;
- int latitudes3 = ((JArray)dataArray3[0]).Count;
- int longitudes3 = ((JArray)dataArray3[0][0]).Count;
- // Initialize float[][][] array
- float[][][] p140208Array = new float[timeSteps3][][];
- // Convert each element to float and populate v10Array
- for (int t = 0; t < timeSteps3; t++)
- {
- p140208Array[t] = new float[latitudes3][];
- for (int lat = 0; lat < latitudes3; lat++)
- {
- p140208Array[t][lat] = new float[longitudes3];
- for (int lon = 0; lon < longitudes3; lon++)
- {
- p140208Array[t][lat][lon] = (float)dataArray3[t][lat][lon];
- }
- }
- }
-
- windNCread.p140208Array = p140208Array;
- }
- }
- string url4 = "http://10.130.100.5:7785//rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/DATA.nc&varName=mwd¢erLon=116.41992593821296¢erLat=40.18801994965735";
- // 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();
- // 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"];
- // Determine the dimensions of the data array
- int timeSteps4 = dataArray4.Count;
- int latitudes4 = ((JArray)dataArray4[0]).Count;
- int longitudes4 = ((JArray)dataArray4[0][0]).Count;
- // Initialize float[][][] array
- float[][][] mwdArray = new float[timeSteps4][][];
- // Convert each element to float and populate v10Array
- for (int t = 0; t < timeSteps4; t++)
- {
- mwdArray[t] = new float[latitudes4][];
- for (int lat = 0; lat < latitudes4; lat++)
- {
- mwdArray[t][lat] = new float[longitudes4];
- for (int lon = 0; lon < longitudes4; lon++)
- {
- mwdArray[t][lat][lon] = (float)dataArray4[t][lat][lon];
- }
- }
- }
-
- windNCread.mwdArray = mwdArray;
- }
- }
- }
- }
|