コード例 #1
0
    IEnumerator GetPointVariables()
    {
        List <float> EData = new List <float>();

        for (int i = 1; i < 121; ++i)
        {
            if (i < 10)
            {
                DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_00" + i + ".nc";
            }
            else if (i < 100)
            {
                DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_0" + i + ".nc";
            }
            else
            {
                DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_" + i + ".nc";
            }

            //string DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_d03_3times.nc";
            if (!System.IO.File.Exists(DataPath))
            {
                Debug.Log("File doesn't exist!  " + DataPath);
            }
            else
            {
                Debug.Log(DataPath);
            }

            ty = new Ty_Class(DataPath, WeatherVariableNames);

            List <float> tmp = ty.GetCertainPointWholeTimeValues(WeatherVariableNames, Longitude, Latitude, LayerNumber);

            foreach (float ff in tmp)
            {
                EData.Add(ff);
            }

            //清空变量
            tmp.Clear();
            Array.Clear(ty.stackData, 0, ty.allDataCount);

            Resources.UnloadUnusedAssets();
            System.GC.Collect();

            Debug.Log("读取进度 " + 0.833 * i + "%...");

            yield return(new WaitForEndOfFrame());
        }
        //foreach (string Variable in WeatherVariableNames)
        //{
        //    Debug.Log("Write: " + Variable + "Data...");
        //    Write_File(EData, Variable + "Data", Variable + "Data.txt");
        //}
        yield return(null);

        Debug.Log("GetPointVariables Finish!");
    }
コード例 #2
0
    public void Read_NCFile()
    {
        Ty_Class      ty;
        int           rd = 2; //选择读取的变量,一个nc文件保存有6个变量float值,选择一个读取保存入ty.stackData,rd = 0为"Cloud",rd = 1为"Rain",之后分别为"Ice","Snow","Graupel","All"
        List <string> WeatherVariableNames;

        if (rd % 6 == 0)
        {
            WeatherVariableNames = new List <string>()
            {
                "Cloud"
            };
        }
        else if (rd % 6 == 1)
        {
            WeatherVariableNames = new List <string>()
            {
                "Rain"
            };
        }
        else if (rd % 6 == 2)
        {
            WeatherVariableNames = new List <string>()
            {
                "Ice"
            };
        }
        else if (rd % 6 == 3)
        {
            WeatherVariableNames = new List <string>()
            {
                "Snow"
            };
        }
        else if (rd % 6 == 4)
        {
            WeatherVariableNames = new List <string>()
            {
                "Graupel"
            };
        }
        else
        {
            WeatherVariableNames = new List <string>()
            {
                "All"
            };
        }

        string DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_001" + ".nc"; //选择读取的文件

        ty = new Ty_Class(DataPath, WeatherVariableNames);                                                 //调用Ty_class.ReadNetCDFStackDataOnly 读取nc文件,坐标数据存入ty.VortexPoints,float value数据存入ty.stackData

        Debug.Log(ty.VortexPoints.Length);
        Debug.Log(ty.stackData.Length);
    }
コード例 #3
0
    public void Trans_VortexList()
    {
        StopAllCoroutines();
        ClearMesh();

        DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_001.nc";

        if (!System.IO.File.Exists(DataPath))
        {
            Debug.Log("File doesn't exist!  " + DataPath);
        }
        else
        {
            Debug.Log(DataPath);
        }
        ty = new Ty_Class(DataPath, floor, floorMat, WeatherVariableNames);

        VortexList = new List <Vector3>();

        int random;

        for (int i = 10; i < 11; i += 2)
        {
            for (int j = 0; j < 420; j += 20)
            {
                for (int k = 0; k < 450; k += 20)
                {
                    //random = 450 * UnityEngine.Random.Range(j - 5, j + 5) + UnityEngine.Random.Range(k - 5, k + 5);
                    //random = random < 0 ? 0 : random;
                    //random = random > 420 * 450 - 1 ? 420 * 450 - 1 : random;
                    random = 450 * j + k;

                    GameObject sphereObj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    sphereObj.transform.parent     = GameObject.Find("PointCloud").transform;
                    sphereObj.transform.position   = ty.VortexPoints[i][random];
                    sphereObj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
                    VortexList.Add(ty.VortexPoints[i][random]);
                }
            }
        }
    }
コード例 #4
0
    IEnumerator ShowAllTimeSomeLayerSimulation()
    {
        for (int i = 0; i < target.transform.childCount; ++i)
        {
            GameObject child = target.transform.GetChild(i).gameObject;
            Destroy(child);
        }
        target.GetComponent <MeshFilter>().mesh.Clear();

        for (int i = NowPlayNumber; i < TotalFrameNumber; ++i)
        {
            string DataPath;
            if (i < 10)
            {
                DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_00" + i + ".nc";
            }
            else if (i < 100)
            {
                DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_0" + i + ".nc";
            }
            else
            {
                DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_" + i + ".nc";
            }

            ty = new Ty_Class(DataPath, WeatherVariableNames);  //调用Ty_class.ReadNetCDFStackDataOnly 读取nc文件,坐标数据存入ty.VortexPoints,float value数据存入ty.stackData

            if (WeatherVariableNames.Contains("Cloud"))
            {
                cm_script.colorMode = 1;
            }
            else if (WeatherVariableNames.Contains("Rain"))
            {
                cm_script.colorMode = 2;
            }
            else
            {
                cm_script.colorMode = 0;
            }

            float max = 0,
                  min = 1;
            for (int it = 0; it < ty.stackData.Length; it++)
            {
                if (min > ty.stackData[it])
                {
                    min = ty.stackData[it];
                }
                if (max < ty.stackData[it])
                {
                    max = ty.stackData[it];
                }
            }
            //switch (variables_dropdown.value)
            //{
            //    case 0:
            //        min = min + mask_rate[0, 0] * (max - min);
            //        max = min + mask_rate[1, 0] * (max - min);
            //        break;
            //    case 1:
            //        min = min + mask_rate[0, 1] * (max - min);
            //        max = min + mask_rate[1, 1] * (max - min);
            //        break;
            //    case 2:
            //        min = min + mask_rate[0, 2] * (max - min);
            //        max = min + mask_rate[1, 2] * (max - min);
            //        break;
            //    case 3:
            //        min = min + mask_rate[0, 3] * (max - min);
            //        max = min + mask_rate[1, 3] * (max - min);
            //        break;
            //    case 4:
            //        min = min + mask_rate[0, 4] * (max - min);
            //        max = min + mask_rate[1, 4] * (max - min);
            //        break;
            //    case 5:
            //        min = min + mask_rate[0, 5] * (max - min);
            //        max = min + mask_rate[1, 5] * (max - min);
            //        break;
            //}
            //min = min + 0.2f * (max - min);
            max = min + gramMax_mask_single[variables_dropdown.value] * (max - min);

            //cm_script.Input(ty.VortexPoints, ty.stackData, max, min, target, variables_dropdown.value);
            cm_script.input_single(ty.VortexPoints, ty.stackData, max, min, target, 1, LayerNumber, dataMin_mask[variables_dropdown.value]);

            ty.oriLatData.Clear();
            ty.oriLogData.Clear();
            System.Array.Clear(ty.stackData, 0, ty.stackData.Length);
            Resources.UnloadUnusedAssets();
            System.GC.Collect();

            yield return(new WaitForEndOfFrame());

            cm_script.Clear();
            //记录当前读取帧数
            NowPlayNumber = i;
        }

        //播放帧数复位
        NowPlayNumber = 1;
    }
コード例 #5
0
    IEnumerator ShowAllTimeSimulation()
    {
        for (int i = 0; i < target.transform.childCount; ++i)
        {
            GameObject child = target.transform.GetChild(i).gameObject;
            Destroy(child);
        }
        target.GetComponent <MeshFilter>().mesh.Clear();

        for (int i = NowPlayNumber; i < TotalFrameNumber; ++i)
        {
            string DataPath;
            if (i < 10)
            {
                DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_00" + i + ".nc";
            }
            else if (i < 100)
            {
                DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_0" + i + ".nc";
            }
            else
            {
                DataPath = Application.dataPath + @"/StreamingAssets/1.typhoon/wrfout_typhoon_" + i + ".nc";
            }

            ty = new Ty_Class(DataPath, WeatherVariableNames);  //调用Ty_class.ReadNetCDFStackDataOnly 读取nc文件,坐标数据存入ty.VortexPoints,float value数据存入ty.stackData
            Debug.Log(DataPath);

            if (WeatherVariableNames.Contains("Cloud"))
            {
                //target.GetComponent<Renderer>().material = new Material(Shader.Find("Legacy Shaders/Diffuse"));
                //if (WeatherVariableNames.Contains("Cloud"))
                //{
                //    target.GetComponent<Renderer>().material.color = new Color(0.8f, 0.8f, 0.8f, 0.9f);
                //}
                //else
                //{
                //    target.GetComponent<Renderer>().material.color = new Color(0.65f, 0.65f, 0.65f, 0.75f);
                //}
                cm_script.colorMode = 1;
            }
            else if (WeatherVariableNames.Contains("Rain"))
            {
                cm_script.colorMode = 2;
            }
            else
            {
                //target.GetComponent<Renderer>().material = new Material(Shader.Find("Custom/Transent"));
                cm_script.colorMode = 0;
            }

            float max = 0,
                  min = 1;
            for (int it = 0; it < ty.stackData.Length; it++)
            {
                if (min > ty.stackData[it])
                {
                    min = ty.stackData[it];
                }
                if (max < ty.stackData[it])
                {
                    max = ty.stackData[it];
                }
            }
            //switch (variables_dropdown.value)
            //{
            //    case 0:
            //        max = min + gramMax_mask[0] * (max - min);
            //        break;
            //    case 1:
            //        min = min + mask_rate[0, 1] * (max - min);
            //        max = min + mask_rate[1, 1] * (max - min);
            //        break;
            //    case 2:
            //        min = min + mask_rate[0, 2] * (max - min);
            //        max = min + mask_rate[1, 2] * (max - min);
            //        break;
            //    case 3:
            //        min = min + mask_rate[0, 3] * (max - min);
            //        max = min + mask_rate[1, 3] * (max - min);
            //        break;
            //    case 4:
            //        min = min + mask_rate[0, 4] * (max - min);
            //        max = min + mask_rate[1, 4] * (max - min);
            //        break;
            //    case 5:
            //        min = min + mask_rate[0, 5] * (max - min);
            //        max = min + mask_rate[1, 5] * (max - min);
            //        break;
            //}
            max = min + gramMax_mask[variables_dropdown.value] * (max - min);

            cm_script.Input(ty.VortexPoints, ty.stackData, max, min, target, dataMin_mask[variables_dropdown.value]);
            //cm_script.input_single(ty.VortexPoints, ty.stackData, max, min, target, 1, 12);

            ty.oriLatData.Clear();
            ty.oriLogData.Clear();
            System.Array.Clear(ty.stackData, 0, ty.stackData.Length);
            Resources.UnloadUnusedAssets();
            System.GC.Collect();

            yield return(new WaitForEndOfFrame());

            cm_script.Clear();

            //记录当前读取帧数
            NowPlayNumber = i;

            //int[] count = new int[101];
            //for (int c = 0; c < 101; ++c)
            //    count[c] = 0;
            //float stair = (max - min) / 100;
            //int[] acc = new int[101];
            //foreach (float data in ty.stackData)
            //{
            //    if (Convert.ToInt16((data - min) / stair) > 100)
            //    {
            //        Debug.Log(data + ", " + max + ", " + min + ", " + stair);
            //        Debug.Log(Convert.ToInt16((data - min) / stair));
            //    }
            //    count[Convert.ToInt16((data - min) / stair)] += 1;
            //}
            ////Debug.Log(min);
            //FileStream fs = new FileStream(Application.dataPath + @"/StreamingAssets/ice_statistics.txt", FileMode.Create);
            //StreamWriter sw = new StreamWriter(fs);
            //for (int c = 0; c < 101; ++c)
            //{
            //    if (c == 0)
            //        acc[c] = count[c];
            //    else
            //        acc[c] = acc[c - 1] + count[c];
            //    sw.WriteLine(c + ",    " + count[c] + ",    " + stair * c + " - " + stair * (c + 1) + ",    " + acc[c] / 51030 + "%");
            //}
            //sw.Close();
        }

        //播放帧数复位
        NowPlayNumber = 1;
    }