Ver código fonte

更新代码以实现可读取全年NC文件

liyang 7 meses atrás
pai
commit
f67095405b

+ 37 - 0
Models/SimulationCommon/DataCalculate.cs

@@ -0,0 +1,37 @@
+using System;
+
+static class DataCalculate
+{
+    static void Main()
+    {
+        Console.Write("请输入年份:");
+        int year = int.Parse(Console.ReadLine());
+        Console.Write("请输入月份:");
+        int month = int.Parse(Console.ReadLine());
+        Console.Write("请输入日期:");
+        int day = int.Parse(Console.ReadLine());
+
+        int daysInYear = GetDaysInYear(year, month, day);
+        Console.WriteLine($"{year}年{month}月{day}日是该年的第{daysInYear}天。");
+    }
+
+    public static int GetDaysInYear(int year, int month, int day)
+    {
+        int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+        if (IsLeapYear(year))
+        {
+            daysInMonths[1] = 29;
+        }
+        int days = day;
+        for (int i = 0; i < month - 1; i++)
+        {
+            days += daysInMonths[i];
+        }
+        return days;
+    }
+
+    public static bool IsLeapYear(int year)
+    {
+        return (year % 4 == 0 && year % 100!= 0) || (year % 400 == 0);
+    }
+}

+ 34 - 31
Models/SimulationCommon/SeaSJ.cs

@@ -26,12 +26,12 @@ public class Current
 
 public class NCread
 {
-        
+
     //各数组来源文件'Text_readNC.cs';时间范围:2024-06-04T00:00:00 ... 2024-06-04T23:00:00;
     //地点范围:落水点为中心100公里
     public float[] longitudeArray = new float[10];//经度一维数组来源自文件'Text_readNC.cs'
     public float[] latitudeArray = new float[7];//纬度一维数组来源自文件'Text_readNC.cs'
-    public float[][][] u10Array ;//风的10米U(向东)分量三维数组来源自文件'Text_readNC.cs'
+    public float[][][] u10Array;//风的10米U(向东)分量三维数组来源自文件'Text_readNC.cs'
     public float[][][] v10Array;//风的10米V(向北)分量三维数组来源自文件'Text_readNC.cs'
     public float[][][] p140208Array;//海洋上空的自由对流速度三维数组来源自文件'Text_readNC.cs'
     public float[][][] mwdArray;//平均波向(单位:度;0度表示北方,90度表示东方)三维数组来源自文件'Text_readNC.cs'       
@@ -52,15 +52,15 @@ public class SeaSJ
     }
 
     // 交付类方法
-    public static List<double[]> GetDrift(NCread nCread,double[] initialPosition, double dt, double totalTime)
+    public static List<double[]> GetDrift(NCread nCread, double[] initialPosition, double dt, double totalTime, int times, int latitudes, int longitudes, int days, int hour, double initlatitudes, double initlongitudes)
     {
         // run 获取轨迹的函数
         // initialPosition --> 初始位置; dt --> 时间步长; totalTime --> 总时长
-        List<double[]> trajectory = CalculateDriftTrajectory(nCread,initialPosition, dt, totalTime);
+        List<double[]> trajectory = CalculateDriftTrajectory(nCread, initialPosition, dt, totalTime, times, latitudes, longitudes, days, hour, initlatitudes, initlongitudes);
         return trajectory;
     }
 
-    public static List<double[]> CalculateDriftTrajectory(NCread nCread,double[] initialPosition, double dt, double totalTime)
+    public static List<double[]> CalculateDriftTrajectory(NCread nCread, double[] initialPosition, double dt, double totalTime, int times, int latitudes, int longitudes, int days, int hour, double initlatitudes, double initlongitudes)
     {
         int timeSteps = (int)(totalTime / dt);
         List<double[]> trajectory = new List<double[]>();
@@ -72,8 +72,8 @@ public class SeaSJ
 
             int outputTime = 3600 * t;
             // 动态获取当前位置的风力和洋流数据
-            double[] windVelocity = GetWindVelocityFromAPI(nCread,currentPos[0], currentPos[1], outputTime);
-            double[] currentVelocity = GetCurrentVelocityFromAPI(nCread,currentPos[0], currentPos[1], outputTime);
+            double[] windVelocity = GetWindVelocityFromAPI(nCread, currentPos[0], currentPos[1], outputTime, times, latitudes, longitudes, days, hour);
+            double[] currentVelocity = GetCurrentVelocityFromAPI(nCread, currentPos[0], currentPos[1], outputTime, times, latitudes, longitudes, days, hour);
 
             // 计算漂移速度(m/s)
             double[] driftVelocity = {
@@ -93,7 +93,7 @@ public class SeaSJ
         return trajectory;//(纬度,经度)
     }
 
-    public static double[] GetWindVelocityFromAPI(NCread windNCread,double latitude, double longitude, double temptime)
+    public static double[] GetWindVelocityFromAPI(NCread windNCread, double latitude, double longitude, double temptime, int times, int latitudes, int longitudes, int days, int hour)
     {
         float[] longitudeArray = windNCread.longitudeArray;//经度一维数组来源自文件'Text_readNC.cs'
         float[] latitudeArray = windNCread.latitudeArray;//纬度一维数组来源自文件'Text_readNC.cs'
@@ -105,7 +105,7 @@ public class SeaSJ
         int temptimeNum = 0;
         //定义NC文件中读取不到的坐标点海洋数据信息(后续可采用插值法等)
         //经度连续化
-        for (int i = 0; i < 9; i++)
+        for (int i = 0; i < longitudes - 1; i++)
         {
             if (longitude >= longitudeArray[i] && longitude < longitudeArray[i + 1])
             {
@@ -115,7 +115,7 @@ public class SeaSJ
         }
 
         //纬度连续化
-        for (int i = 0; i < 6; i++)
+        for (int i = 0; i < latitudes - 1; i++)
         {
             if (latitude >= latitudeArray[i] && latitude < latitudeArray[i + 1])
             {
@@ -123,9 +123,9 @@ public class SeaSJ
                 latitudeNum = i;
             }
         }
-        
+
         //时间连续化
-        for (int i = 0; i < 23 ; i ++)
+        for (int i = 0; i < times - 1; i++)
         {
             if (temptime >= 3600 * i && temptime < (3600 * (i + 1)))
             {
@@ -133,13 +133,15 @@ public class SeaSJ
             }
         }
 
+        temptimeNum += (days - 1) * 24 + hour;
+
         double windX = (double)u10Array[temptimeNum][latitudeNum][longitudeNum];
-        double windY = (double)v10Array[temptimeNum][latitudeNum][ longitudeNum];
+        double windY = (double)v10Array[temptimeNum][latitudeNum][longitudeNum];
 
         return new double[] { windX, windY };
     }
 
-    public static double[] GetCurrentVelocityFromAPI(NCread CurrentNCread,double latitude, double longitude, double temptime)
+    public static double[] GetCurrentVelocityFromAPI(NCread CurrentNCread, double latitude, double longitude, double temptime, int times, int latitudes, int longitudes, int days, int hour)
     {
         float[] longitudeArray = CurrentNCread.longitudeArray;//经度一维数组来源自文件'Text_readNC.cs'
         float[] latitudeArray = CurrentNCread.latitudeArray;//纬度一维数组来源自文件'Text_readNC.cs'
@@ -153,7 +155,7 @@ public class SeaSJ
         int temptimeNum = 0;
         //定义NC文件中读取不到的坐标点海洋数据信息(后续可采用插值法等)
         //经度连续化
-        for (int i = 0; i < 9; i++)
+        for (int i = 0; i < longitudes - 1; i++)
         {
             if (longitude >= longitudeArray[i] && longitude < longitudeArray[i + 1])
             {
@@ -163,7 +165,7 @@ public class SeaSJ
         }
 
         //纬度连续化
-        for (int i = 0; i < 6; i++)
+        for (int i = 0; i < latitudes - 1; i++)
         {
             if (latitude >= latitudeArray[i] && latitude < latitudeArray[i + 1])
             {
@@ -171,27 +173,28 @@ public class SeaSJ
                 latitudeNum = i;
             }
         }
-        
+
         //时间连续化
-        for (int i = 0; i < 23; i++)
+        for (int i = 0; i < times - 1; i++)
         {
             if (temptime >= 3600 * 1 && temptime < 3600 * (i + 1))
             {
                 temptimeNum = i;
             }
         }
-        double currentSpeed = (double)p140208Array[temptimeNum][latitudeNum][ longitudeNum];
-        double currentDirection = (double)mwdArray[temptimeNum][latitudeNum][ longitudeNum];
+        temptimeNum += (days - 1) * 24 + hour;
+        double currentSpeed = (double)p140208Array[temptimeNum][latitudeNum][longitudeNum];
+        double currentDirection = (double)mwdArray[temptimeNum][latitudeNum][longitudeNum];
 
         double currentDirectionInRadians = currentDirection * (Math.PI / 180);
         double currentX = currentSpeed * Math.Cos(currentDirectionInRadians);
         double currentY = currentSpeed * Math.Sin(currentDirectionInRadians);
 
         return new double[] { currentX, currentY };
-    } 
-    
+    }
+
     //海浪高度获取
-   public static double GetWaveHeightFromAPI(NCread WaveNCread,double latitude, double longitude, double temptime)//temptime:仿真时间(秒)
+    public static double GetWaveHeightFromAPI(NCread WaveNCread, double latitude, double longitude, double temptime, int times, int latitudes, int longitudes, int days, int hour)//temptime:仿真时间(秒)
     {
         float[] longitudeArray = WaveNCread.longitudeArray;//经度一维数组来源自文件'Text_readNC.cs'
         float[] latitudeArray = WaveNCread.latitudeArray;//纬度一维数组来源自文件'Text_readNC.cs'
@@ -203,7 +206,7 @@ public class SeaSJ
 
         //定义NC文件中读取不到的坐标点海洋数据信息(后续可采用插值法等)
         //经度连续化
-        for (int i = 0; i < 9; i++)
+        for (int i = 0; i < longitudes - 1; i++)
         {
             if (longitude >= longitudeArray[i] && longitude < longitudeArray[i + 1])
             {
@@ -213,7 +216,7 @@ public class SeaSJ
         }
 
         //纬度连续化
-        for (int i = 0; i < 6; i++)
+        for (int i = 0; i < latitudes - 1; i++)
         {
             if (latitude >= latitudeArray[i] && latitude < latitudeArray[i + 1])
             {
@@ -223,19 +226,19 @@ public class SeaSJ
         }
 
         //时间连续化
-        for (int i = 0; i < 23 ; i ++)
+        for (int i = 0; i < times - 1; i++)
         {
             if (temptime >= 3600 * i && temptime < (3600 * (i + 1)))
             {
                 temptimeNum = i;
             }
         }
-
-        double WaveHeight = (double)hmaxArray[temptimeNum][ latitudeNum][ longitudeNum];
+        temptimeNum += (days - 1) * 24 + hour;
+        double WaveHeight = (double)hmaxArray[temptimeNum][latitudeNum][longitudeNum];
 
         return WaveHeight;
     }
-    
+
     // 交付部分方法代码
     public static List<double[]> getminEnclosingRect(List<double[]> latLonList)
     {
@@ -250,7 +253,7 @@ public class SeaSJ
 
         // 获取凸包
         Point2f[] convexHull = Rectangular_Area_Search_Function.GetConvexHull(pointList);
-        
+
         //获取凸包各点经纬度坐标
         List<double[]> hullPoint = new List<double[]>();
         for (int num = 0; num < convexHull.Length - 1; num++)
@@ -265,7 +268,7 @@ public class SeaSJ
             double pointLon = Rectangular_Area_Search_Function.RMokatuoLon(point[0]);
             hullPointLatLon.Add(new double[] { pointLat, pointLon });
         }
-        
+
         // 计算最小包围矩形
         List<double[]> minEnclosingRect = Rectangular_Area_Search_Function.MinEnclosingRectangle(convexHull);
 

+ 5 - 5
Models/SimulationCommon/SurvivalTimeModel.cs

@@ -11,7 +11,7 @@ public class tempNCread
 public class SurvivalTimeModel
 {
     //得到在某经纬度、任务运行时间下的落水人员幸存时间
-    public static double SurvivalTime(tempNCread tempNCread, double latitude, double longitude, double time)
+    public static double SurvivalTime(tempNCread tempNCread, double latitude, double longitude, double time, int times, int latitudes, int longitudes, int days, int hour)
         //time表示任务执行时间,单位:秒,后续可以转换单位
     {
         int latitudeNum = 0;
@@ -24,7 +24,7 @@ public class SurvivalTimeModel
 
         //定义NC文件中读取不到的坐标点海洋数据信息(后续可采用插值法等)
         //经度连续化
-        for (int i = 0; i < 9; i++)
+        for (int i = 0; i < longitudes - 1; i++)
         {
             if (longitude >= longitudeArray[i] && longitude < longitudeArray[i + 1])
             {
@@ -34,7 +34,7 @@ public class SurvivalTimeModel
         }
 
         //纬度连续化
-        for (int i = 0; i < 6; i++)
+        for (int i = 0; i < latitudes - 1; i++)
         {
             if (latitude >= latitudeArray[i] && latitude < latitudeArray[i + 1])
             {
@@ -44,14 +44,14 @@ public class SurvivalTimeModel
         }
 
         //时间连续化
-        for (int i = 0; i < 23; i++)
+        for (int i = 0; i < times - 1; i++)
         {
             if (time >= (i * 3600) && time < ((i + 1) * 3600))
             {
                 timeNum = i;
             }
         }
-
+        timeNum += (days - 1) * 24 + hour;
         double temp = (double)tempArray[timeNum][ latitudeNum][ longitudeNum]; //得到该坐标和时间下的温度
 
         double time1 = 1.2860 * Math.Exp(0.1604 * temp);

+ 67 - 48
Models/SimulationCommon/Text_readNC.cs

@@ -6,10 +6,29 @@ namespace SimulationCommon;
 public class Text_readNC
 {
     public NCread windNCread = new NCread();
+    public int times;
+    public int latitudes;
+    public int longitudes;
+    //public int timeSteps2;
+    //public int latitudes2;
+    //public int longitudes2;
+    //public int timeSteps3;
+    //public int latitudes3;
+    //public int longitudes3;
+    //public int timeSteps4;
+    //public int latitudes4;
+    //public int longitudes4;
+    //public int timeSteps1;
+    //public int latitudes1;
+    //public int longitudes1;
+    public double initlatitudes;
+    public double initlongitudes;
+
     public void GetNCData()
     {
-        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";
-
+        //"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"
+        //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&centerLon=" + initlongitudes.ToString() + "&centerLat=" + initlatitudes.ToString();
         // Create a GET request to the specified URL
         HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
         request1.Method = "GET";
@@ -28,15 +47,15 @@ public class Text_readNC
                 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;
+                times = dataArray1.Count;
+                latitudes = ((JArray)dataArray1[0]).Count;
+                longitudes = ((JArray)dataArray1[0][0]).Count;
 
                 // Initialize float[][][] array
-                float[][][] v10Array = new float[timeSteps][][];
+                float[][][] v10Array = new float[times][][];
 
                 // Convert each element to float and populate v10Array
-                for (int t = 0; t < timeSteps; t++)
+                for (int t = 0; t < times; t++)
                 {
                     v10Array[t] = new float[latitudes][];
 
@@ -86,7 +105,7 @@ public class Text_readNC
             }
         }
 
-        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";
+        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;
 
         // Create a GET request to the specified URL
         HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(url2);
@@ -106,36 +125,36 @@ public class Text_readNC
                 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;
+                times = dataArray2.Count;
+                latitudes = ((JArray)dataArray2[0]).Count;
+                longitudes = ((JArray)dataArray2[0][0]).Count;
 
                 // Initialize float[][][] array
-                float[][][] u10Array = new float[timeSteps2][][];
+                float[][][] u10Array = new float[times][][];
 
                 // Convert each element to float and populate v10Array
-                for (int t = 0; t < timeSteps2; t++)
+                for (int t = 0; t < times; t++)
                 {
-                    u10Array[t] = new float[latitudes2][];
+                    u10Array[t] = new float[latitudes][];
 
-                    for (int lat = 0; lat < latitudes2; lat++)
+                    for (int lat = 0; lat < latitudes; lat++)
                     {
-                        u10Array[t][lat] = new float[longitudes2];
+                        u10Array[t][lat] = new float[longitudes];
 
-                        for (int lon = 0; lon < longitudes2; lon++)
+                        for (int lon = 0; lon < longitudes; 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/DATA.nc&varName=p140208&centerLon=116.41992593821296&centerLat=40.18801994965735";
+        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;
 
         // Create a GET request to the specified URL
         HttpWebRequest request3 = (HttpWebRequest)WebRequest.Create(url3);
@@ -155,34 +174,34 @@ public class Text_readNC
                 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;
+                times = dataArray3.Count;
+                latitudes = ((JArray)dataArray3[0]).Count;
+                longitudes = ((JArray)dataArray3[0][0]).Count;
 
                 // Initialize float[][][] array
-                float[][][] p140208Array = new float[timeSteps3][][];
+                float[][][] p140208Array = new float[times][][];
 
                 // Convert each element to float and populate v10Array
-                for (int t = 0; t < timeSteps3; t++)
+                for (int t = 0; t < times; t++)
                 {
-                    p140208Array[t] = new float[latitudes3][];
+                    p140208Array[t] = new float[latitudes][];
 
-                    for (int lat = 0; lat < latitudes3; lat++)
+                    for (int lat = 0; lat < latitudes; lat++)
                     {
-                        p140208Array[t][lat] = new float[longitudes3];
+                        p140208Array[t][lat] = new float[longitudes];
 
-                        for (int lon = 0; lon < longitudes3; lon++)
+                        for (int lon = 0; lon < longitudes; 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/DATA.nc&varName=mwd&centerLon=116.41992593821296&centerLat=40.18801994965735";
+        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;
 
         // Create a GET request to the specified URL
         HttpWebRequest request4 = (HttpWebRequest)WebRequest.Create(url4);
@@ -202,29 +221,29 @@ public class Text_readNC
                 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;
+                times = dataArray4.Count;
+                latitudes = ((JArray)dataArray4[0]).Count;
+                longitudes = ((JArray)dataArray4[0][0]).Count;
 
                 // Initialize float[][][] array
-                float[][][] mwdArray = new float[timeSteps4][][];
+                float[][][] mwdArray = new float[times][][];
 
                 // Convert each element to float and populate v10Array
-                for (int t = 0; t < timeSteps4; t++)
+                for (int t = 0; t < times; t++)
                 {
-                    mwdArray[t] = new float[latitudes4][];
+                    mwdArray[t] = new float[latitudes][];
 
-                    for (int lat = 0; lat < latitudes4; lat++)
+                    for (int lat = 0; lat < latitudes; lat++)
                     {
-                        mwdArray[t][lat] = new float[longitudes4];
+                        mwdArray[t][lat] = new float[longitudes];
 
-                        for (int lon = 0; lon < longitudes4; lon++)
+                        for (int lon = 0; lon < longitudes; lon++)
                         {
                             mwdArray[t][lat][lon] = (float)dataArray4[t][lat][lon];
                         }
                     }
                 }
-                
+
                 windNCread.mwdArray = mwdArray;
             }
         }
@@ -232,8 +251,8 @@ public class Text_readNC
 
     public void GetWaveHighData()
     {
-         //中心点坐标应该选取伤员初始位置坐标
-        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";
+        //中心点坐标应该选取伤员初始位置坐标
+        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;
 
         // Create a GET request to the specified URL
         HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
@@ -253,14 +272,14 @@ public class Text_readNC
                 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;
+                times = dataArray1.Count;
+                latitudes = ((JArray)dataArray1[0]).Count;
+                longitudes = ((JArray)dataArray1[0][0]).Count;
 
                 // Initialize float[][][] array
-                float[][][] hmaxArray = new float[timeSteps][][];
+                float[][][] hmaxArray = new float[times][][];
 
-                for (int t = 0; t < timeSteps; t++)
+                for (int t = 0; t < times; t++)
                 {
                     hmaxArray[t] = new float[latitudes][];
 

+ 4 - 1
Models/SimulationCommon/temp_readNC.cs

@@ -8,13 +8,16 @@ using SimulationCommon;
 public class GetNCData
 {
     public tempNCread tempreadNC = new tempNCread();
+
+    public double initlatitudes;
+    public double initlongitudes;
     //longitudeArray:经度一维数组;
     //latitudeArray:纬度一维数组;
     //tempArray:海面温度_24(时间)*7(纬度)*10(经度);
     public void GetData()
     {
         //中心点坐标应该选取伤员初始位置坐标
-        string url1 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/temp.nc&varName=d2m&centerLon=116.41992593821296&centerLat=40.18801994965735";
+        string url1 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_u10_v10_temp.nc&varName=sst&centerLon=" + initlongitudes + "&centerLat=" + initlatitudes;
 
         // Create a GET request to the specified URL
         HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);

+ 37 - 4
SimulationServer/Entity/AircraftSJ.cs

@@ -31,6 +31,8 @@ public class AircraftSJ : AircraftEntity
     //Text_readNC text_ReadNC;
 
     public SearchMissionMode SearchMode;
+    int Days;
+    int Hour;
 
     public override void Reset()
     {
@@ -44,6 +46,13 @@ public class AircraftSJ : AircraftEntity
 
     public override void Start()
     {
+        int Year = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[0]);
+        int Month = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[0]);
+        int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]);
+        Hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
+        Days = GetDaysInYear(Year, Month, Day);
+        //Console.WriteLine("Day:" + Days);
+
         Velocitys = new double[5] { 220, 220, 60, 110, 0 }; // 速度
 
         //TODO 计算 AirRoute[]
@@ -57,6 +66,8 @@ public class AircraftSJ : AircraftEntity
         //if (!isbool2)
         //{
         Text_readNC text_ReadNC = new Text_readNC();
+        text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
+        text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
         //text_ReadNC = new Text_readNC();
         text_ReadNC.GetNCData();
         text_ReadNC.GetWaveHighData();
@@ -65,7 +76,7 @@ public class AircraftSJ : AircraftEntity
         var nCread = text_ReadNC.windNCread;
 
         //漂移轨迹
-        List<double[]> trajectory = SeaSJ.CalculateDriftTrajectory(nCread, initialPosition, dt, totalTime);
+        List<double[]> trajectory = SeaSJ.CalculateDriftTrajectory(nCread, initialPosition, dt, totalTime, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, Days, Hour, text_ReadNC.initlatitudes, text_ReadNC.initlongitudes);
 
         // 生成任务终点
         MissionEndPoint = new MissionEndPoint
@@ -199,6 +210,8 @@ public class AircraftSJ : AircraftEntity
         //if (!isbool)
         //{
         getNCData = new GetNCData();
+        getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
+        getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
         getNCData.GetData();
         //isbool = true;
         //}
@@ -240,13 +253,13 @@ public class AircraftSJ : AircraftEntity
 
 
                 var wind = SeaSJ.GetWindVelocityFromAPI(nCread, currentLocation.CurrentLat, currentLocation.CurrentLon,
-                    temptime);
+                    temptime, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, Days, Hour);
 
 
                 var windSpeed = Math.Sqrt(wind[0] * wind[0] + wind[1] * wind[1]);
 
                 var waveHigh = SeaSJ.GetWaveHeightFromAPI(nCread, currentLocation.CurrentLon,
-                    currentLocation.CurrentLat, temptime);
+                    currentLocation.CurrentLat, temptime, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, Days, Hour);
 
                 var distance = Utils.Util.GetDistance(currentLocation.CurrentLon, targetPoint.x,
                     currentLocation.CurrentLat,
@@ -297,7 +310,7 @@ public class AircraftSJ : AircraftEntity
                 double latitude = FlightPlanEditor.targetpoint[0].TargetPointLatitude; //落水人员纬度;数据测试用
                 double longitude = FlightPlanEditor.targetpoint[0].TargetPointLongitude; //落水人员经度,数据测试用
 
-                double survivalTime = SurvivalTimeModel.SurvivalTime(getNCData.tempreadNC, latitude, longitude, time); //幸存时间
+                double survivalTime = SurvivalTimeModel.SurvivalTime(getNCData.tempreadNC, latitude, longitude, time, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, Days, Hour); //幸存时间
 
                 if (survivalTime * 3600 > time)
                 {
@@ -343,6 +356,26 @@ public class AircraftSJ : AircraftEntity
         });
     }
 
+    public static int GetDaysInYear(int year, int month, int day)
+    {
+        int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+        if (IsLeapYear(year))
+        {
+            daysInMonths[1] = 29;
+        }
+        int days = day;
+        for (int i = 0; i < month - 1; i++)
+        {
+            days += daysInMonths[i];
+        }
+        return days;
+    }
+
+    public static bool IsLeapYear(int year)
+    {
+        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
+    }
+
 
     public override void End()
     {

+ 7 - 7
SimulationServer/EventHandler/ServerStartEventHandler.cs

@@ -107,15 +107,15 @@ public class ServerStartEventHandler : AEvent<ServerStart>
             //Console.WriteLine("仿真次数:" + editorConfig.runCounts);
             Game.EventSystem.Publish(new CreateSeaSJTask
             { EditorConfig = editorConfig, SeaSJTask = seaSJTask });
-            //break;
+            break;
         }
 
-        foreach (var landSXTask in taskConfig.LandSouXunTasks)
-        {
-            Game.EventSystem.Publish(new CreateLandSXTask
-            { EditorConfig = editorConfig, LandSXTask = landSXTask });
-            //break;
-        }
+        //foreach (var landSXTask in taskConfig.LandSouXunTasks)
+        //{
+        //    Game.EventSystem.Publish(new CreateLandSXTask
+        //    { EditorConfig = editorConfig, LandSXTask = landSXTask });
+        //    //break;
+        //}
 
         taskSys.ExecutionContext = editorConfig.runCounts;
         taskSys.Start();

+ 1 - 1
SimulationServer/bin/Debug/net7.0/Missions/editor_config.json

@@ -1,5 +1,5 @@
 {
-    "仿真次数": 100,
+    "仿真次数": 1,
     "想定信息": {
         "想定日期": "2024年4月10日",
         "想定时间": "00时00分00秒"

BIN
SimulationServer/bin/Debug/net7.0/SimulationCommon.dll


BIN
SimulationServer/bin/Debug/net7.0/SimulationCommon.pdb


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.dll


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.exe


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.pdb