コード例 #1
0
ファイル: ProjectHLK.cs プロジェクト: HowLeaky/HowLeaky-Core
        public Dictionary <string, List <Simulation> > Open(ConsoleOutputLogger consoleoutput, string filename)
        {
            try
            {
                ConsoleOutput = consoleoutput;
                FileName      = filename;
                var path = Path.GetDirectoryName(filename);
                OutputsDirectory = Path.Combine(path, "Outputs");
                if (RemapDictionary != null)
                {
                    AddConsoleOutput($"Opening {filename}...");
                    if (File.Exists(filename))
                    {
                        var type = Path.GetExtension(filename.ToLower());
                        if (type == ".hlk")
                        {
                            var         datasets    = new Dictionary <string, ParameterDataSet>();
                            var         datafiles   = new Dictionary <string, P51DataFile>();
                            var         alldatasets = new List <ParameterDataSet>();
                            XmlDocument Doc         = new XmlDocument();
                            Doc.Load(filename);
                            var parameterdatasets = ExtractParameterDataSetFileNames(Doc);

                            foreach (var item in parameterdatasets)
                            {
                                if (IsValidateType(item))
                                {
                                    var    itemfilename = Path.GetFileName(item);
                                    string updateditem  = item;
                                    if (!File.Exists(item))
                                    {
                                        var oldpathname1 = Path.GetDirectoryName(item);
                                        var oldpathname  = Path.GetDirectoryName(oldpathname1);
                                        updateditem = item.Replace(oldpathname, path).ToLower();
                                    }

                                    if (updateditem.Contains("p51"))
                                    {
                                        var datafile = new P51DataFile(updateditem);

                                        datafiles.Add(itemfilename, datafile);
                                    }
                                    else
                                    {
                                        var dataset = ExtractParameterDataSet(updateditem);
                                        if (dataset != null)
                                        {
                                            datasets.Add(itemfilename, dataset);
                                            alldatasets.Add(dataset);
                                        }
                                        else
                                        {
                                            AddErrorOutput($"CORRUPTED PARAMETERSET -Couldn't read {item}");
                                        }
                                    }
                                }
                            }
                            DataFiles          = datafiles.Select(x => x.Value).ToList();
                            Datasets           = alldatasets;
                            Simulations        = ExtractSimulations(Doc, datasets, datafiles);
                            GroupedSimulations = GroupSimulations();
                            GenerateInitialConsoleOutput(filename, alldatasets, datafiles);
                            return(GroupedSimulations);
                        }
                    }
                    else
                    {
                        AddErrorOutput($"File note found ({filename})");
                    }
                }
                else
                {
                    AddErrorOutput($"Remap dictionary could not be found");
                    throw new Exception("Fatal Error - Remap dictionary not found");
                }
            }
            catch (Exception ex)
            {
                AddErrorOutput($"Exception Caught: {ex}");
            }
            return(null);
        }
コード例 #2
0
ファイル: Simulation.cs プロジェクト: HowLeaky/HowLeaky-Core
 private HowLeakyInputs_Climate GenerateClimateInputs(HowLeakyInputs_Climate inputs, P51DataFile climateData)
 {
     if (ClimateData != null)
     {
         if (climateData.HasLoaded == false)
         {
             climateData.OpenFull();
         }
         if (climateData.HasLoaded)
         {
             inputs           = new HowLeakyInputs_Climate();
             inputs.MaxT      = climateData.TimeSeries[0].Select(x => (double)x).ToList(); //MaxTempValues
             inputs.MinT      = climateData.TimeSeries[1].Select(x => (double)x).ToList(); //MinTempValues
             inputs.Rain      = climateData.TimeSeries[2].Select(x => (double)x).ToList(); //RainfallValues
             inputs.PanEvap   = climateData.TimeSeries[3].Select(x => (double)x).ToList(); //PanEvapValues
             inputs.Radiation = climateData.TimeSeries[4].Select(x => (double)x).ToList(); //SolarRadValues
             inputs.StartDate = climateData.StartDate;
             inputs.EndDate   = climateData.EndDate;
             return(inputs);
         }
         else
         {
             Errors.Add($"Error reading climate data ({climateData.FileName})");
         }
     }
     return(null);
 }