public void LoadInitialConditions()
        {
            string pressureFile    = string.Format("P{0:d2}.thd", _levelType);
            string temperatureFile = string.Format("T{0:d2}.thd", _levelType);
            string humidityFile    = string.Format("H{0:d2}.thd", _levelType);

            string filePath = Path.Combine(SimulationData.WorkFolder, temperatureFile);

            if (File.Exists(filePath) == false)
            {
                throw new FileNotFoundException();
            }

            DenseMatrix t = FileSupport.LoadMatrixFromFile(filePath);

            filePath = Path.Combine(SimulationData.WorkFolder, pressureFile);
            if (File.Exists(filePath) == false)
            {
                throw new FileNotFoundException();
            }

            DenseMatrix p = FileSupport.LoadMatrixFromFile(filePath);

            filePath = Path.Combine(SimulationData.WorkFolder, humidityFile);
            if (File.Exists(filePath) == false)
            {
                throw new FileNotFoundException();
            }

            DenseMatrix h = FileSupport.LoadMatrixFromFile(filePath);

            H = h.EQ();
            P = p.EQ();
            T = t.EQ();
        }
        private void InitGeographicalParams()
        {
            // ------------
            string filePath = ".\\ElevationMap.thd";

            if (File.Exists(filePath) == false)
            {
                throw new FileNotFoundException();
            }

            Height = FileSupport.LoadMatrixFromFile(filePath);

            // ------------
            filePath = ".\\LandWaterMask.thd";
            if (File.Exists(filePath) == false)
            {
                throw new FileNotFoundException();
            }

            var wlMask = FileSupport.LoadMatrixFromFile(filePath);
            var he     = Height.EQ(8);

            WL.Assign((r, c) =>
            {
                var sgn = 0f;

                sgn = Math.Sign(wlMask[r, c]);
                if (sgn == 1)
                {
                    return(1);
                }

                if (he[r, c] >= 50f)
                {
                    return(0);
                }

                return(1);
            });


            // ------------
            filePath = ".\\ADJ_LR.thd";
            if (File.Exists(filePath) == false)
            {
                throw new FileNotFoundException();
            }

            this.ADJ_LR = FileSupport.LoadMatrixFromFile(filePath);

            // ------------
            filePath = ".\\albedo.thd";
            if (File.Exists(filePath) == false)
            {
                throw new FileNotFoundException();
            }

            this.ALBEDO     = FileSupport.LoadMatrixFromFile(filePath);
            this.DEF_ALBEDO = FileSupport.LoadMatrixFromFile(filePath);
        }
        public SurfaceLevel(EarthModel earth, bool loadFromStateFiles, float defaultValue = 0)
        {
            this.Earth = earth;
            InitGeographicalParams();

            if (loadFromStateFiles == false)
            {
                if (defaultValue == 0)
                {
                    // ------------
                    // Soil temperature where applicable
                    string filePath = Path.Combine(SimulationData.WorkFolder, "SOIL.thd");
                    if (File.Exists(filePath))
                    {
                        var tl = FileSupport.LoadMatrixFromFile(filePath);
                        TL.Assign((r, c) =>
                        {
                            if (WL[r, c] == 0)
                            {
                                return(tl[r, c]);
                            }

                            return(0);
                        });
                    }

                    // ------------
                    // Sea temperature where applicable
                    filePath = Path.Combine(SimulationData.WorkFolder, "SST.thd");
                    if (File.Exists(filePath))
                    {
                        var tw = FileSupport.LoadMatrixFromFile(filePath);
                        TW.Assign((r, c) =>
                        {
                            if (WL[r, c] != 0)
                            {
                                return(tw[r, c]);
                            }

                            return(0);
                        });
                    }

                    // Combined surface temperature
                    TS.Assign((r, c) =>
                    {
                        if (WL[r, c] != 0)
                        {
                            return(TW[r, c]);
                        }

                        return(TL[r, c]);
                    });

                    // ------------
                    // Snow cover
                    filePath = Path.Combine(SimulationData.WorkFolder, "SNOW.thd");
                    if (File.Exists(filePath))
                    {
                        this.SNOW = FileSupport.LoadMatrixFromFile(filePath);
                    }
                }
                else
                {
                    TE       = MatrixFactory.Init(defaultValue);
                    TW       = MatrixFactory.Init(defaultValue);
                    TL       = MatrixFactory.Init(defaultValue);
                    TS       = MatrixFactory.Init(defaultValue);
                    SNOW     = MatrixFactory.Init(defaultValue);
                    RAIN     = MatrixFactory.Init(defaultValue);
                    BLIZZARD = MatrixFactory.Init(defaultValue);
                    ALBEDO   = MatrixFactory.Init(defaultValue);

                    Precip = MatrixFactory.Init(defaultValue);
                    TLow   = MatrixFactory.Init(defaultValue);
                    THigh  = MatrixFactory.Init(defaultValue);
                    LIDX   = MatrixFactory.Init(defaultValue);

                    FOG = MatrixFactory.Init(defaultValue);

                    TNormLow  = MatrixFactory.Init(defaultValue);
                    TNormHigh = MatrixFactory.Init(defaultValue);
                }
            }
            else
            {
                TE = FileSupport.Load(Earth.UTC.Title, "T_TE_MAP");
                TW = FileSupport.Load(Earth.UTC.Title, "T_TW_MAP");
                TL = FileSupport.Load(Earth.UTC.Title, "T_TL_MAP");
                TS = FileSupport.Load(Earth.UTC.Title, "T_TS_MAP");

                SNOW = FileSupport.Load(Earth.UTC.Title, "N_00_MAP");
                RAIN = FileSupport.Load(Earth.UTC.Title, "R_00_MAP");

                BLIZZARD = FileSupport.Load(Earth.UTC.Title, "B_00_MAP");
                ALBEDO   = FileSupport.Load(Earth.UTC.Title, "A_00_MAP");

                Precip = FileSupport.Load(Earth.UTC.Title, "C_00_MAP");
                TLow   = FileSupport.Load(Earth.UTC.Title, "T_SL_MAP");
                THigh  = FileSupport.Load(Earth.UTC.Title, "T_SH_MAP");
                LIDX   = FileSupport.Load(Earth.UTC.Title, "L_00_MAP");

                FOG = FileSupport.Load(Earth.UTC.Title, "F_SI_MAP");

                TNormLow  = FileSupport.Load(Earth.UTC.Title, "T_NL_MAP");
                TNormHigh = FileSupport.Load(Earth.UTC.Title, "T_NH_MAP");
            }
        }