示例#1
0
        /// <summary>
        /// Reads in all initialisation files and copies them to the output directory for future reference
        /// </summary>
        /// <param name="initialisationFile">The name of the initialization file with information on the simulations to be run</param>
        /// <param name="outputPath">The path to folder in which outputs will be stored</param>
        /// <todo>Need to adjust this file to deal with incorrect inputs, extra columns etc by throwing an error</todo>
        /// <todo>Also need to strip leading spaces</todo>
        public void ReadAndCopyInitialisationFiles(string simulationInitialisationFilename, string definitionsFilename, string outputsFilename, string outputPath)
        {
            // Construct file names
            string SimulationFileString  = "msds:csv?file=input/Model setup/" + simulationInitialisationFilename + "&openMode=readOnly";
            string DefinitionsFileString = "msds:csv?file=input/Model setup/" + definitionsFilename + "&openMode=readOnly";
            string OutputsFileString     = "msds:csv?file=input/Model setup/" + outputsFilename + "&openMode=readOnly";

            // Copy the initialisation files to the output directory
            System.IO.File.Copy("input/Model setup/" + simulationInitialisationFilename, outputPath + simulationInitialisationFilename, true);
            System.IO.File.Copy("input/Model setup/" + definitionsFilename, outputPath + definitionsFilename, true);
            System.IO.File.Copy("input/Model setup/" + outputsFilename, outputPath + outputsFilename, true);

            // Read in the definitions data
            InternalData = DataSet.Open(DefinitionsFileString);

            // Get the names of parameters in the initialization file
            VarParameters = InternalData.Variables[1].GetData();

            // Get the values for the parameters
            VarValues = InternalData.Variables[0].GetData();
#endif

            // Loop over the parameters
            for (int row = 0; row < VarParameters.Length; row++)
            {
                // Switch based on the name of the parameter, and write the value to the appropriate field
                switch (VarParameters.GetValue(row).ToString().ToLower())
                {
                case "mass bin filename":
                    // Set up the mass bins as specified in the initialization file
#if true
                    _ModelMassBins.SetUpMassBins(VarValues.GetValue(row).ToString(), outputPath, inputPath);
#else
                    _ModelMassBins.SetUpMassBins(VarValues.GetValue(row).ToString(), outputPath);
#endif
                    break;
                }
            }

            InternalData.Dispose();

            // Read in the outputs data
            InternalData = DataSet.Open(OutputsFileString);

            // Get the names of parameters in the initialization file
            VarParameters = InternalData.Variables[1].GetData();

            // Get the values for the parameters
            VarValues = InternalData.Variables[0].GetData();

            // Loop over the parameters
            for (int row = 0; row < VarParameters.Length; row++)
            {
                // Switch based on the name of the parameter, and write the value to the appropriate field
                switch (VarParameters.GetValue(row).ToString().ToLower())
                {
                case "track processes":
                    switch (VarValues.GetValue(row).ToString().ToLower())
                    {
                    case "yes":
                        _TrackProcesses = true;
                        break;

                    case "no":
                        _TrackProcesses = false;
                        break;
                    }
                    break;

                case "track cross cell processes":
                    switch (VarValues.GetValue(row).ToString().ToLower())
                    {
                    case "yes":
                        _TrackCrossCellProcesses = true;
                        break;

                    case "no":
                        _TrackCrossCellProcesses = false;
                        break;
                    }
                    break;

                case "track global processes":
                    switch (VarValues.GetValue(row).ToString().ToLower())
                    {
                    case "yes":
                        _TrackGlobalProcesses = true;
                        break;

                    case "no":
                        _TrackGlobalProcesses = false;
                        break;
                    }
                    break;

                case "new cohorts filename":
                    _ProcessTrackingOutputs.Add("NewCohortsOutput", VarValues.GetValue(row).ToString());
                    break;

                case "maturity filename":
                    _ProcessTrackingOutputs.Add("MaturityOutput", VarValues.GetValue(row).ToString());
                    break;

                case "biomasses eaten filename":
                    _ProcessTrackingOutputs.Add("BiomassesEatenOutput", VarValues.GetValue(row).ToString());
                    break;

                case "trophic flows filename":
                    _ProcessTrackingOutputs.Add("TrophicFlowsOutput", VarValues.GetValue(row).ToString());
                    break;

                case "growth filename":
                    _ProcessTrackingOutputs.Add("GrowthOutput", VarValues.GetValue(row).ToString());
                    break;

                case "metabolism filename":
                    _ProcessTrackingOutputs.Add("MetabolismOutput", VarValues.GetValue(row).ToString());
                    break;

                case "npp output filename":
                    _ProcessTrackingOutputs.Add("NPPOutput", VarValues.GetValue(row).ToString());
                    break;

                case "predation flows filename":
                    _ProcessTrackingOutputs.Add("PredationFlowsOutput", VarValues.GetValue(row).ToString());
                    break;

                case "herbivory flows filename":
                    _ProcessTrackingOutputs.Add("HerbivoryFlowsOutput", VarValues.GetValue(row).ToString());
                    break;

                case "mortality filename":
                    _ProcessTrackingOutputs.Add("MortalityOutput", VarValues.GetValue(row).ToString());
                    break;

                case "extinction filename":
                    _ProcessTrackingOutputs.Add("ExtinctionOutput", VarValues.GetValue(row).ToString());
                    break;

                case "output detail":
                    _InitialisationFileStrings.Add("OutputDetail", VarValues.GetValue(row).ToString());
                    break;

                case "live outputs":
                    if (VarValues.GetValue(row).ToString() == "yes")
                    {
                        _LiveOutputs = true;
                    }
                    else
                    {
                        _LiveOutputs = false;
                    }
                    break;

                case "track marine specifics":
                    if (VarValues.GetValue(row).ToString() == "yes")
                    {
                        _TrackMarineSpecifics = true;
                    }
                    else
                    {
                        _TrackMarineSpecifics = false;
                    }
                    break;

                case "output metrics":
                    if (VarValues.GetValue(row).ToString() == "yes")
                    {
                        _OutputMetrics = true;
                    }
                    else
                    {
                        _OutputMetrics = false;
                    }
                    break;

                case "output model state timesteps":

                    if (VarValues.GetValue(row).ToString() != "no")
                    {
                        string[] OutputStateTimesSteps = VarValues.GetValue(row).ToString().Split(new char[] { ';' });
                        foreach (string t in OutputStateTimesSteps)
                        {
                            if (t.Split(new char[] { '-' }).Length > 1)
                            {
                                string[] range = t.Split(new char[] { '-' });
                                for (uint i = Convert.ToUInt32(range[0]); i <= Convert.ToUInt32(range[1]); i++)
                                {
                                    _OutputStateTimestep.Add(i);
                                }
                            }
                            else
                            {
                                _OutputStateTimestep.Add(Convert.ToUInt32(Convert.ToInt32(t)));
                            }
                        }
                    }

                    break;
                }
            }

            InternalData.Dispose();
        }
示例#2
0
 /* Method: Dispose
  *
  *  Disposes of the training data.
  */
 public void Dispose()
 {
     InternalData.Dispose();
 }