public RunTrnsys(TrnsysModel trnsys_model) { string deckfilename = Path.Combine(CreateDckFile.get_trnsys_file_path(), trnsys_model.ModelName + ".dck"); string command = CreateDckFile.get_trnsys_exe() + deckfilename + "/n"; int exitCode; ProcessStartInfo processInfo; Process process; processInfo = new ProcessStartInfo("cmd.exe", command); processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; // Redirect the outputs processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; process = Process.Start(processInfo); process.WaitForExit(); // Read the streams string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); exitCode = process.ExitCode; Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output)); Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error)); Console.WriteLine("ExitCode: " + exitCode.ToString(), "ExeciteCommand"); process.Close(); }
public WriteDckFile(TrnsysModel trnsys_model) { string filename = Path.Combine(CreateDckFile.get_trnsys_file_path(), trnsys_model.ModelName + ".dck"); using (StreamWriter file = new StreamWriter(filename, false)) { // Write the begining of the deck file. Intro intro = new Intro(trnsys_model.ProjectCreator, trnsys_model.CreationDate, trnsys_model.ModifiedDate, trnsys_model.Description); file.WriteLine(intro.WriteIntro()); // Write the control cars. ControlCards controlcards = new ControlCards(0, 8760, trnsys_model.HourlyTimestep); file.WriteLine(controlcards.WriteControlCards()); Type15_3 weather2 = new Type15_3(trnsys_model.WeatherFile); file.WriteLine(weather2.WriteType()); Type741 pump = new Type741(0, 0, 0, 0); file.WriteLine(pump.WriteType()); // Write Type31 Type31 pipe = new Type31(new int[, ] { { 0, 0 }, { 0, 0 }, { weather2.Unit_number, 2 } }, 0.5, 525, 3, 998, 4.31, 10); file.WriteLine(pipe.WriteType()); file.WriteLine("END\\n"); file.Close(); } }
static void Main(string[] args) { //double timestep = 0.25; //var a = new List<object>(); //var f1 = new ControlCards(0, 8760, timestep); //a.Add(f1); var trnsys_model = new TrnsysModel(); trnsys_model.PlantSelection = "Plant 1"; trnsys_model.ModelName = "MyModel"; trnsys_model.WeatherFile = "CAN_PQ_Montreal.Intl.AP.716270_CWEC"; trnsys_model.HourlyTimestep = 0.25; //var b = new CreateDckFile(trnsys_model); var b = new WriteDckFile(trnsys_model); var c = new RunTrnsys(trnsys_model); //Console.WriteLine("There are " + a.Count + " items"); //Console.WriteLine("Press enter to close..."); //Console.ReadLine(); }
public CreateDckFile(TrnsysModel trnsys_model) { // "This creates a new deck file (filename) by replacing %TURN% with azimuth_string, // %APPLICATION% with hvac_string, and %HOUSE_FILE% with building_file in the deck template file." string templatefilename = Path.Combine(get_templates_file_path(), "ParametrizedVersion_a.dck"); // Assign Plant where: // Ideal (1), Conventional(2), HeatPump(3), VRF-HP-SingleZone (4), VRF-HP-Multizone(5) char hvac = '1'; //Ideal if (trnsys_model.PlantSelection == "Plant 1") { hvac = '1'; } else if (trnsys_model.PlantSelection == "Plant 2") { hvac = '2'; } else if (trnsys_model.PlantSelection == "Plant 3") { hvac = '3'; } else if (trnsys_model.PlantSelection == "Plant 4") { hvac = '4'; } else { Console.WriteLine("HVAC selection not valid - using Ideal"); } Console.WriteLine("template: " + templatefilename); string deckfilename = Path.Combine(get_trnsys_file_path(), trnsys_model.ModelName + ".dck"); // Open template deck file and read all lines string[] template_deck_file = File.ReadAllLines(templatefilename); // Replacements to include in file string[,] replacements = new string[, ] { { "%DATASTEP%", trnsys_model.HourlyTimestep.ToString() }, { "%WEATHER_FILE%", trnsys_model.WeatherFile + ".epw" }, { "%PLOTTER%", "-1" } }; // Go through the template file searching for placeholders to replace with selected values. string line; using (StreamReader file = new StreamReader(@templatefilename)) using (StreamWriter file2 = new StreamWriter(@deckfilename)) while ((line = file.ReadLine()) != null) { string line2 = line; file2.WriteLine(line2); } var writer = new StreamWriter(deckfilename); for (int i = 0; i < template_deck_file.Length; i++) { for (int j = 0; j < replacements.GetLength(0) - 1; j++) { string line3 = template_deck_file[i]; line3.Replace(replacements[j, 0], replacements[j, 0]); writer.WriteLine(line3); } } }