public static void Main(string[] args)
        {
            System.Console.WriteLine("Initializing LANDIS-II core...");
            RasterFactory rasterFactory = new RasterFactory();
            LandscapeFactory landscapeFactory = new LandscapeFactory();
            Core modelCore = new Core(rasterFactory, landscapeFactory);

            // Run a scenario using the model's core.
            modelCore.RunScenario("path/to/scenario.txt");
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            System.Console.WriteLine("Initializing LANDIS-II core...");
            RasterFactory    rasterFactory    = new RasterFactory();
            LandscapeFactory landscapeFactory = new LandscapeFactory();
            Core             modelCore        = new Core(rasterFactory, landscapeFactory);

            // Run a scenario using the model's core.
            modelCore.RunScenario("path/to/scenario.txt");
        }
        public void Init()
        {
            List<IEcoregionParameters> ecoregionParms = new List<IEcoregionParameters>();
            ecoregionParms.Add(new Parameters("eco0", "Ecoregion A", 0, true));
            ecoregionParms.Add(new Parameters("eco11", "Ecoregion B", 11, false));
            ecoregionParms.Add(new Parameters("eco222", "Ecoregion C", 222, true));
            ecoregionParms.Add(new Parameters("eco3333", "Ecoregion D", 3333, false));
            ecoregionParms.Add(new Parameters("eco-65535", "Ecoregion E", 65535, true));

            dataset = new Dataset(ecoregionParms);
            rasterFactory = new RasterFactory();

            //  Initialize 8-bit ecoregion data
            ecoregions8Bit = new byte[,] {
                {   0,   0,  11, 222,  11 },
                {   0,  11,  11, 222,  11 },
                {   0,  11,  11, 222, 222 },
                {  11,  11,  11, 222, 222 },
                {  11,  11, 222, 222, 222 },
                {  11,  11, 222, 222, 222 }
            };
            dims8Bit = new Dimensions(ecoregions8Bit.GetLength(0),
                                      ecoregions8Bit.GetLength(1));
            rasterFactory.SetData(path8Bit, ecoregions8Bit);

            //  Initialize 16-bit ecoregion data
            ecoregions16Bit = new ushort[,] {
                {   0,   0,  11, 222,  11,  3333,     0 },
                {   0,  11,  11, 222,  11,  3333, 65535 },
                {   0,  11,  11, 222, 222,  3333, 65535 },
                {  11,  11,  11, 222, 222,  3333, 65535 },
                {  11,  11, 222, 222, 222,  3333, 65535 },
                {  11,  11, 222, 222, 222, 65535, 65535 },
                {   0,   0, 222, 222, 222, 65535, 65535 }
            };
            dims16Bit = new Dimensions(ecoregions16Bit.GetLength(0),
                                       ecoregions16Bit.GetLength(1));
            rasterFactory.SetData(path16Bit, ecoregions16Bit);
        }
Exemple #4
0
        public static int Main(string[] args)
        {
            try {
                // The log4net section in the application's configuration file
                // requires the environment variable WORKING_DIR be set to the
                // current working directory.
                Environment.SetEnvironmentVariable("WORKING_DIR", Environment.CurrentDirectory);
                log4net.Config.XmlConfigurator.Configure();

                ConsoleInterface ci = new ConsoleInterface();

                ci.TextWriter = Console.Out;

                string version = GetAppSetting("version");
                if (version == "")
                {
                    throw new Exception("The application setting \"version\" is empty or blank");
                }
                string release = GetAppSetting("release");
                if (release != "")
                {
                    release = string.Format(" ({0})", release);
                }
                ci.WriteLine("LANDIS-II {0}{1}", version, release);

                Assembly assembly = Assembly.GetExecutingAssembly();
                foreach (object attribute in assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false))
                {
                    ci.WriteLine(((AssemblyCopyrightAttribute)attribute).Copyright);
                }
                ci.WriteLine();

                if (args.Length == 0)
                {
                    ci.WriteLine("Error: No scenario file specified.");
                    return(1);
                }
                if (args.Length > 1)
                {
                    ci.WriteLine("Error: Extra argument(s) on command line:");
                    StringBuilder argsList = new StringBuilder();
                    argsList.Append(" ");
                    for (int i = 1; i < args.Length; ++i)
                    {
                        argsList.AppendFormat(" {0}", args[i]);
                    }
                    ci.WriteLine(argsList.ToString());
                    return(1);
                }

                //Warn if user's computer is not using United States number format
                string decimal_separator = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
                string period            = ".";
                if (decimal_separator != period)
                {
                    ci.WriteLine("Warning: The decimal separator of your system is '" + decimal_separator + "'. Most LANDIS-II");
                    ci.WriteLine("Warning: scenario files use '" + period + "' for the decimal separator. The scenario");
                    ci.WriteLine("Warning: files may not run or your results could be inaccurate.");
                    ci.WriteLine();
                }

                IExtensionDataset extensions = Landis.Extensions.Dataset.LoadOrCreate();
                //Pre-pending the GDAL directory is required to run the Console project in debug mode
                //string path = Environment.GetEnvironmentVariable("PATH");
                //string newPath = "C:\\Program Files\\LANDIS-II\\GDAL\\1.9;" + path;
                //Environment.SetEnvironmentVariable("PATH", newPath);
                RasterFactory    rasterFactory    = new RasterFactory();
                LandscapeFactory landscapeFactory = new LandscapeFactory();
                Model            model            = new Model(extensions, rasterFactory, landscapeFactory);
                model.Run(args[0], ci);
                return(0);
            }
            catch (ApplicationException exc) {
                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine(exc.Message);
                return(1);
            }
            catch (Exception exc) {
                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine("Internal error occurred within the program:");
                ci.WriteLine("  {0}", exc.Message);
                if (exc.InnerException != null)
                {
                    ci.WriteLine("  {0}", exc.InnerException.Message);
                }
                ci.WriteLine();
                ci.WriteLine("Stack trace:");
                ci.WriteLine(exc.StackTrace);
                return(1);
            }
        }
 private Validator InitializeValidator(Model _model, IUserInterface _ui)
 {
     Validator _validator;
     string extFolder = Constants.EXTENSIONS_FOLDER + Constants.EXTENSIONS_XML;
     IExtensionDataset extensions = Landis.Extensions.Dataset.LoadOrCreate(extFolder);
     RasterFactory rasterFactory = new RasterFactory();
     Landis.Landscapes.LandscapeFactory landscapeFactory = new Landis.Landscapes.LandscapeFactory();
     _validator = new Validator(extensions, rasterFactory, landscapeFactory, _model, _ui);
     return _validator;
 }
 private Model InitializeModel()
 {
     Model model;
     //@ToDo: Is it okay to hard-code this path? If the widget runs from the LANDIS-II bin, shouldn't be needed
     //Landis.Core.IExtensionDataset extensions = Landis.Extensions.Dataset.LoadOrCreate();
     string extFolder = Constants.EXTENSIONS_FOLDER + Constants.EXTENSIONS_XML;
     IExtensionDataset extensions = Landis.Extensions.Dataset.LoadOrCreate(extFolder);
     //IExtensionDataset extensions = Landis.Extensions.Dataset.LoadOrCreate();
     RasterFactory rasterFactory = new RasterFactory();
     Landis.Landscapes.LandscapeFactory landscapeFactory = new Landis.Landscapes.LandscapeFactory();
     model = new Landis.Model(extensions, rasterFactory, landscapeFactory);
     return model;
 }
        public static int Main(string[] args)
        {
            try {
                // The log4net section in the application's configuration file
                // requires the environment variable WORKING_DIR be set to the
                // current working directory.
                Environment.SetEnvironmentVariable("WORKING_DIR", Environment.CurrentDirectory);
                log4net.Config.XmlConfigurator.Configure();

                ConsoleInterface ci = new ConsoleInterface();

                ci.TextWriter = Console.Out;

                string version = GetAppSetting("version");
                if (version == "")
                    throw new Exception("The application setting \"version\" is empty or blank");
                string release = GetAppSetting("release");
                if (release != "")
                    release = string.Format(" ({0})", release);
                ci.WriteLine("LANDIS-II {0}{1}", version, release);

                Assembly assembly = Assembly.GetExecutingAssembly();
                foreach (object attribute in assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false))
                    ci.WriteLine(((AssemblyCopyrightAttribute) attribute).Copyright);
                ci.WriteLine();

                if (args.Length == 0) {
                    ci.WriteLine("Error: No scenario file specified.");
                    return 1;
                }
                if (args.Length > 1) {
                    ci.WriteLine("Error: Extra argument(s) on command line:");
                    StringBuilder argsList = new StringBuilder();
                    argsList.Append(" ");
                    for (int i = 1; i < args.Length; ++i)
                        argsList.AppendFormat(" {0}", args[i]);
                    ci.WriteLine(argsList.ToString());
                    return 1;
                }

                IExtensionDataset extensions = Landis.Extensions.Dataset.LoadOrCreate();
                RasterFactory rasterFactory = new RasterFactory();
                LandscapeFactory landscapeFactory = new LandscapeFactory();
                Model model = new Model(extensions, rasterFactory, landscapeFactory);
                model.Run(args[0], ci);
                return 0;
            }
            catch (ApplicationException exc) {
                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine(exc.Message);
                return 1;
            }
            catch (Exception exc) {

                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine("Internal error occurred within the program:");
                ci.WriteLine("  {0}", exc.Message);
                if (exc.InnerException != null) {
                    ci.WriteLine("  {0}", exc.InnerException.Message);
                }
                ci.WriteLine();
                ci.WriteLine("Stack trace:");
                ci.WriteLine(exc.StackTrace);
                return 1;
            }
        }
Exemple #8
0
        public static int Main(string[] args)
        {
            try {
                // The log4net section in the application's configuration file
                // requires the environment variable WORKING_DIR be set to the
                // current working directory.
                Environment.SetEnvironmentVariable("WORKING_DIR", Environment.CurrentDirectory);
                log4net.Config.XmlConfigurator.Configure();

                ConsoleInterface ci = new ConsoleInterface();

                ci.TextWriter = Console.Out;

                string version = GetAppSetting("version");
                if (version == "")
                {
                    throw new Exception("The application setting \"version\" is empty or blank");
                }
                string release = GetAppSetting("release");
                if (release != "")
                {
                    release = string.Format(" ({0})", release);
                }
                ci.WriteLine("LANDIS-II {0}{1}", version, release);

                Assembly assembly = Assembly.GetExecutingAssembly();
                foreach (object attribute in assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false))
                {
                    ci.WriteLine(((AssemblyCopyrightAttribute)attribute).Copyright);
                }
                ci.WriteLine();

                if (args.Length == 0)
                {
                    ci.WriteLine("Error: No scenario file specified.");
                    return(1);
                }
                if (args.Length > 1)
                {
                    ci.WriteLine("Error: Extra argument(s) on command line:");
                    StringBuilder argsList = new StringBuilder();
                    argsList.Append(" ");
                    for (int i = 1; i < args.Length; ++i)
                    {
                        argsList.AppendFormat(" {0}", args[i]);
                    }
                    ci.WriteLine(argsList.ToString());
                    return(1);
                }

                IExtensionDataset extensions       = Landis.Extensions.Dataset.LoadOrCreate();
                RasterFactory     rasterFactory    = new RasterFactory();
                LandscapeFactory  landscapeFactory = new LandscapeFactory();
                Model             model            = new Model(extensions, rasterFactory, landscapeFactory);
                model.Run(args[0], ci);
                return(0);
            }
            catch (ApplicationException exc) {
                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine(exc.Message);
                return(1);
            }
            catch (Exception exc) {
                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine("Internal error occurred within the program:");
                ci.WriteLine("  {0}", exc.Message);
                if (exc.InnerException != null)
                {
                    ci.WriteLine("  {0}", exc.InnerException.Message);
                }
                ci.WriteLine();
                ci.WriteLine("Stack trace:");
                ci.WriteLine(exc.StackTrace);
                return(1);
            }
        }
        public static int Main(string[] args)
        {
            try {
                // The log4net section in the application's configuration file
                // requires the environment variable WORKING_DIR be set to the
                // current working directory.
                Environment.SetEnvironmentVariable("WORKING_DIR", Environment.CurrentDirectory);
                log4net.Config.XmlConfigurator.Configure();

                ConsoleInterface ci = new ConsoleInterface();

                ci.TextWriter = Console.Out;

                string version = GetAppSetting("version");
                if (version == "")
                    throw new Exception("The application setting \"version\" is empty or blank");
                string release = GetAppSetting("release");
                if (release != "")
                    release = string.Format(" ({0})", release);
                ci.WriteLine("LANDIS-II {0}{1}", version, release);

                Assembly assembly = Assembly.GetExecutingAssembly();
                foreach (object attribute in assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false))
                    ci.WriteLine(((AssemblyCopyrightAttribute) attribute).Copyright);
                ci.WriteLine();

                if (args.Length == 0) {
                    ci.WriteLine("Error: No scenario file specified.");
                    return 1;
                }
                if (args.Length > 1) {
                    ci.WriteLine("Error: Extra argument(s) on command line:");
                    StringBuilder argsList = new StringBuilder();
                    argsList.Append(" ");
                    for (int i = 1; i < args.Length; ++i)
                        argsList.AppendFormat(" {0}", args[i]);
                    ci.WriteLine(argsList.ToString());
                    return 1;
                }

                //Warn if user's computer is not using United States number format
                string decimal_separator = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
                string period = ".";
                if (decimal_separator != period)
                {
                    ci.WriteLine("Warning: The decimal separator of your system is '" + decimal_separator + "'. Most LANDIS-II");
                    ci.WriteLine("Warning: scenario files use '" + period + "' for the decimal separator. The scenario");
                    ci.WriteLine("Warning: files may not run or your results could be inaccurate.");
                    ci.WriteLine();
                }

                IExtensionDataset extensions = Landis.Extensions.Dataset.LoadOrCreate();
                //Pre-pending the GDAL directory is required to run the Console in debug mode
                //string path = Environment.GetEnvironmentVariable("PATH");
                //string newPath = "C:\\Program Files\\LANDIS-II\\GDAL\\1.9;" + path;
                //Environment.SetEnvironmentVariable("PATH", newPath);
                RasterFactory rasterFactory = new RasterFactory();
                LandscapeFactory landscapeFactory = new LandscapeFactory();
                Model model = new Model(extensions, rasterFactory, landscapeFactory);
                model.Run(args[0], ci);
                return 0;
            }
            catch (ApplicationException exc) {
                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine(exc.Message);
                return 1;
            }
            catch (Exception exc) {

                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine("Internal error occurred within the program:");
                ci.WriteLine("  {0}", exc.Message);
                if (exc.InnerException != null) {
                    ci.WriteLine("  {0}", exc.InnerException.Message);
                }
                ci.WriteLine();
                ci.WriteLine("Stack trace:");
                ci.WriteLine(exc.StackTrace);
                return 1;
            }
        }