Kaynağa Gözat

取消部分错误提示,修改读取NC文件方法,读取错误时循环读取

liyang 2 hafta önce
ebeveyn
işleme
5b64fb9ef5

+ 15 - 6
Models/SimulationCommon/Text_readNC.cs

@@ -25,7 +25,7 @@ public class Text_readNC
     public double initlatitudes;
     public double initlongitudes;
 
-    public void GetNCData()
+    public bool GetNCData()
     {
         //"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";
@@ -47,6 +47,9 @@ public class Text_readNC
                 // 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;
@@ -124,7 +127,8 @@ public class Text_readNC
 
                 // 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;
@@ -173,7 +177,8 @@ public class Text_readNC
 
                 // 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;
@@ -220,7 +225,8 @@ public class Text_readNC
 
                 // 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;
@@ -248,9 +254,10 @@ public class Text_readNC
                 windNCread.mwdArray = mwdArray;
             }
         }
+        return true;
     }
 
-    public void GetWaveHighData()
+    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&centerLon=" + initlongitudes + "&centerLat=" + initlatitudes;
@@ -271,7 +278,8 @@ public class Text_readNC
 
                 // 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;
@@ -320,5 +328,6 @@ public class Text_readNC
                 //Console.WriteLine("a value of timeArray: " + timeArray[0]);
             }
         }
+        return true;
     }
 }

+ 2 - 2
Models/SimulationCommon/Util.cs

@@ -33,12 +33,12 @@ public class Util
                 fuel = fuelDb.data[0];
             else
             {
-                Console.WriteLine($"没有找到【{json}】对应的油耗信息");
+                //Console.WriteLine($"没有找到【{json}】对应的油耗信息");
             }
         }
         catch (Exception e)
         {
-            Console.WriteLine($"没有找到【{json}】对应的油耗信息");
+            //Console.WriteLine($"没有找到【{json}】对应的油耗信息");
         }
 
         return fuel;

+ 4 - 3
Models/SimulationCommon/temp_readNC.cs

@@ -14,7 +14,7 @@ public class GetNCData
     //longitudeArray:经度一维数组;
     //latitudeArray:纬度一维数组;
     //tempArray:海面温度_24(时间)*7(纬度)*10(经度);
-    public void GetData()
+    public bool GetData()
     {
         //中心点坐标应该选取伤员初始位置坐标
         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;
@@ -36,7 +36,8 @@ public class GetNCData
 
                 // 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
                 int times5 = dataArray1.Count;
                 int latitudes5 = ((JArray)dataArray1[0]).Count;
@@ -91,7 +92,7 @@ public class GetNCData
                 tempreadNC.tempArray = tempArray;
             }
         }
-
+        return true;
     }
     
 

+ 10 - 2
SimulationServer/Entity/AircraftDY.cs

@@ -44,12 +44,20 @@ public class AircraftDY : AircraftEntity
             getNCData = new GetNCData();
             getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
             getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
-            getNCData.GetData();
+            bool isSuccess3 = false;
+            while (!isSuccess3)
+            {
+                isSuccess3 = getNCData.GetData();
+            }
             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();
+            bool isSuccess = false;
+            while (!isSuccess)
+            {
+                isSuccess = text_ReadNC.GetNCData();
+            }
             isReadNC = true;
         }
 

+ 5 - 1
SimulationServer/Entity/AircraftKTKS.cs

@@ -82,7 +82,11 @@ public class AircraftKTKS : AircraftEntity
             text_ReadNC = new Text_readNC();
             text_ReadNC.initlatitudes = rescueDemandInfo.TargetPointLatitude;
             text_ReadNC.initlongitudes = rescueDemandInfo.TargetPointLongitude;
-            text_ReadNC.GetNCData();
+            bool isSuccess = false;
+            while (!isSuccess)
+            {
+                isSuccess = text_ReadNC.GetNCData();
+            }
             isReadNC = true;
         }
         var nCread = text_ReadNC.windNCread;

+ 5 - 1
SimulationServer/Entity/AircraftLandSJ.cs

@@ -307,7 +307,11 @@ public class AircraftLandSJ : AircraftEntity
                         text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
                         text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
                         //text_ReadNC = new Text_readNC();
-                        text_ReadNC.GetNCData();
+                        bool isSuccess = false;
+                        while (!isSuccess)
+                        {
+                            isSuccess = text_ReadNC.GetNCData();
+                        }
                         isReadNC = true;
                     }
                     var nCread = text_ReadNC.windNCread;

+ 18 - 3
SimulationServer/Entity/AircraftSJ.cs

@@ -101,15 +101,30 @@ public class AircraftSJ : AircraftEntity
             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();
+
+            bool isSuccess = false;
+            while(!isSuccess)
+            {
+                isSuccess = text_ReadNC.GetNCData();
+            }
+
+            bool isSuccess2 = false;
+            while (!isSuccess2)
+            {
+                isSuccess2 = text_ReadNC.GetWaveHighData();
+            }
+
             //isbool2 = true;
             //}
 
             getNCData = new GetNCData();
             getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
             getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
-            getNCData.GetData();
+            bool isSuccess3 = false;
+            while(!isSuccess3)
+            {
+                isSuccess3 = getNCData.GetData();
+            }
 
             isReadNC = true;
         }

+ 1 - 1
SimulationServer/Utils/Util.cs

@@ -57,7 +57,7 @@ public class Util
 
         if (define.zs.Count == 0)
         {
-            Log.Debug($"没有找到对应 [{aircraftID}] 的飞机信息");
+            //Log.Debug($"没有找到对应 [{aircraftID}] 的飞机信息");
             return new AircraftDB();
         }
             

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