LCOV - code coverage report
Current view: top level - EnergyPlus/api - EnergyPlusPgm.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 67 124 54.0 %
Date: 2024-08-23 23:50:59 Functions: 7 11 63.6 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2024, The Board of Trustees of the University of Illinois,
       2             : // The Regents of the University of California, through Lawrence Berkeley National Laboratory
       3             : // (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
       4             : // National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
       5             : // contributors. All rights reserved.
       6             : //
       7             : // NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
       8             : // U.S. Government consequently retains certain rights. As such, the U.S. Government has been
       9             : // granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
      10             : // worldwide license in the Software to reproduce, distribute copies to the public, prepare
      11             : // derivative works, and perform publicly and display publicly, and to permit others to do so.
      12             : //
      13             : // Redistribution and use in source and binary forms, with or without modification, are permitted
      14             : // provided that the following conditions are met:
      15             : //
      16             : // (1) Redistributions of source code must retain the above copyright notice, this list of
      17             : //     conditions and the following disclaimer.
      18             : //
      19             : // (2) Redistributions in binary form must reproduce the above copyright notice, this list of
      20             : //     conditions and the following disclaimer in the documentation and/or other materials
      21             : //     provided with the distribution.
      22             : //
      23             : // (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
      24             : //     the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
      25             : //     used to endorse or promote products derived from this software without specific prior
      26             : //     written permission.
      27             : //
      28             : // (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
      29             : //     without changes from the version obtained under this License, or (ii) Licensee makes a
      30             : //     reference solely to the software portion of its product, Licensee must refer to the
      31             : //     software as "EnergyPlus version X" software, where "X" is the version number Licensee
      32             : //     obtained under this License and may not use a different name for the software. Except as
      33             : //     specifically required in this Section (4), Licensee shall not use in a company name, a
      34             : //     product name, in advertising, publicity, or other promotional activities any name, trade
      35             : //     name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
      36             : //     similar designation, without the U.S. Department of Energy's prior written consent.
      37             : //
      38             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
      39             : // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      40             : // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      41             : // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      42             : // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
      43             : // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      44             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      45             : // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      46             : // POSSIBILITY OF SUCH DAMAGE.
      47             : 
      48             : // Portions of the EnergyPlus(tm) software package have been developed and copyrighted by other
      49             : // individuals, companies and institutions.  These portions have been incorporated into the EnergyPlus
      50             : // software package under license.
      51             : 
      52             : // In addition to the primary authorship of the LBNL Simulation Research Group (
      53             : // http://simulationresearch.lbl.gov/) and the UIUC Building Systems Laboratory (
      54             : // http://www.bso.uiuc.edu/), the following have contributed to EnergyPlus V1.0:
      55             : 
      56             : // Portions of the EnergyPlus weather processor were developed by US Department of Energy, Building
      57             : // Technologies Program, www.energyplus.gov
      58             : 
      59             : // Portions of the input processing, output processing, weather processor, BLAST Translator were
      60             : // developed by US Army Corps of Engineers, Construction Engineering Research Laboratories, 2902 Newmark
      61             : // Drive, Champaign IL  61821. www.cecer.army.mil
      62             : 
      63             : // Portions of this software package were developed by Linda Lawrie of DHL Consulting LLC.
      64             : 
      65             : // Portions of this software package were developed by C.O. Pedersen Associates.
      66             : 
      67             : // Portions of the EnergyPlus utility software (EP-Launch, IDFEditor, DOE2Translator, HVAC-Diagram,
      68             : // ExpandObjects, CSVProc, System Templates, and convertESOMTR) were developed by GARD Analytics, Inc.
      69             : // 1028 Busse Highway, Park Ridge, Illinois 60068-1802, USA (847) 698-5690, www.gard.com.  GARD Analytics
      70             : // performed independent verification and validation testing of the software after developing the testing
      71             : // strategy and plan.  GARD Analytics was also responsible for gas absorption chiller, desiccant
      72             : // dehumidifier, ice storage (simple), table reports and economics.
      73             : 
      74             : // Portions of flow resolver, chiller models (absorption, electric, const cop, engine-driven, gas-
      75             : // turbine), generator models (diesel electric, gas turbine), furnace models, heat recovery loop, plant
      76             : // loop, plant condenser loop, air-change dependent inside film coefficients were developed by Oklahoma
      77             : // State University, 110 Engineering North, Stillwater, OK 74078.
      78             : 
      79             : // Portions of EnergyPlus related to the models for EMPD moisture calculations, DX coils, furnace/unitary
      80             : // systems, cooling towers, air-to-air heat pumps, air distribution systems, refrigerated cases, electric
      81             : // EIR chillers, packaged terminal heat pumps, desuperheater air and water heating coils, and heat pump
      82             : // water heaters were developed by University of Central Florida, Florida Solar Energy Center (FSEC),
      83             : // 1679 Clearlake Road, Cocoa, FL  32922, www.fsec.ucf.edu/.
      84             : 
      85             : // Portions of EnergyPlus were developed by the National Renewable Energy Laboratory (NREL), 1617 Cole
      86             : // Blvd, Golden, CO 80401.
      87             : 
      88             : // EnergyPlus v1.0.1, v1.0.2, v1.0.3, v1.1, v1.1.1 (Wintel platform) includes a link to TRNSYS (The Transient
      89             : // Energy System Simulation Tool) for photovoltaic calculations developed by Thermal Energy System Specialists,
      90             : // 2916 Marketplace Drive, Suite 104, Madison, WI 53719; Tel: (608) 274-2577. EnergyPlus v1.2 and later
      91             : // includes Photovoltaic calculations implemented in EnergyPlus by Thermal Energy System Specialists.
      92             : // This model was originally developed by Oystein Ulleberg, Institute for Energy Technology, Norway -- based on
      93             : // the Duffie and Beckman equivalent one-diode model.
      94             : 
      95             : // Portions of this software package that convert certain stand-alone heat transfer models for slab-on-
      96             : // grade and basement foundations were developed by William Bahnfleth, Cynthia Cogil, and Edward
      97             : // Clements, Department of Architectural Engineering, Pennsylvania State University, 224 Engineering Unit
      98             : // A, University Park, Pennsylvania  16802-1416, (814) 863-2076.
      99             : 
     100             : // The concept and initial implementation for the EnergyPlus COM/DLL version (Wintel platform) was made
     101             : // possible through cooperation with DesignBuilder Software, Ltd, Andy Tindale - an EnergyPlus
     102             : // collaborative developer.
     103             : 
     104             : // The thickness, conductivity, density and specific heat values of the material layers for the
     105             : // constructions in the Composite Wall Construction reference data set have been taken from the ASHRAE
     106             : // report "Modeling Two- and Three-Dimensional Heat Transfer through Composite Wall and Roof Assemblies
     107             : // in Hourly  Energy Simulation Programs (1145-TRP)," by Enermodal Engineering Limited, Oak Ridge
     108             : // National Laboratory, and the Polish Academy of Sciences, January 2001.
     109             : 
     110             : // EnergyPlus v1.2 contains DELight2 (wintel platform), a simulation engine for daylighting and electric
     111             : // lighting system analysis developed at Ernest Orlando Lawrence Berkeley National Laboratory.
     112             : 
     113             : // Portions of the EnergyPlus v1.2 air distribution system calculations were written by George Walton of
     114             : // the National Institute for Standards and Technology (NIST), 100 Bureau Drive, Gaithersburg, MD 20899,
     115             : // (301) 975-6478.  The EnergyPlus AirflowNetwork model also includes portions of an early version of COMIS
     116             : // (Conjunction Of Multizone Infiltration Specialists) developed by a multinational, multi-institutional
     117             : // effort under the auspices of the International Energy Agency's Buildings and Community Systems Agreement
     118             : // working group focusing on multizone air flow modeling (Annex 23) and now administered by the Swiss Federal
     119             : // Laboratories for Materials Testing and Research (EMPA), Division 175, Uberlandstrasse 129, CH-8600 Dubendorf,
     120             : // Switzerland.
     121             : 
     122             : // The EnergyPlus v1.2 model for displacement ventilation and cross-ventilation was developed
     123             : // by Guilherme Carrilho da Graca and Paul Linden of the Department of Mechanical and Aerospace
     124             : // Engineering, University of California, San Diego.
     125             : 
     126             : // The EnergyPlus models for UFAD served zones were developed by Anna Liu and Paul Linden at the Department
     127             : // of Mechanical and Aerospace Engineering, University of California, San Diego.
     128             : 
     129             : // ASHRAE research project 1254-RP supported the development of the following features first added in
     130             : // EnergyPlus v1.2.2:
     131             : //    DXSystem:AirLoop enhancements (valid as OA system equipment, new humidity control options);
     132             : //    New set point managers: SET POINT MANAGER:SINGLE ZONE HEATING, SET POINT MANAGER:SINGLE ZONE COOLING,
     133             : //            and SET POINT MANAGER:OUTSIDE AIR PRETREAT;
     134             : //    New 2-stage DX coil with enhanced dehumidification option (COIL:DX:MultiMode:CoolingEmpirical);
     135             : //    Additional DESICCANT DEHUMIDIFIER:SOLID setpoint control option;
     136             : // American Society of Heating Refrigerating and Air-Conditioning Engineers, Inc,,
     137             : // 1791 Tullie Circle, N.E., Atlanta, GA 30329. www.ashrae.org
     138             : // Work performed by GARD Analytics, Inc., 1028 Busse Highway, Park Ridge, Illinois 60068-1802, USA.
     139             : // www.gard.com, November 2004.
     140             : 
     141             : // EnergyPlus v1.2.2 and later versions (wintel platform) contains links to SPARK, a simulation engine for
     142             : // detailed system modeling developed at Ernest Orlando Lawrence Berkeley National Laboratory in
     143             : // conjunction with Ayres Sowell Associates, Inc.  SPARK was removed in V3.1 - April 2009 release.
     144             : 
     145             : // The Ecoroof (Green Roof) model, first introduced in EnergyPlus v2.0, was developed at Portland State University,
     146             : // by David Sailor and his students. It is based on the FASST vegetation models developed by Frankenstein and
     147             : // Koenig for the US Army Corps of Engineers.
     148             : 
     149             : // The HAMT (Heat And Moisture Transfer) model, first introduced in EnergyPlus v3.0.0 was developed by Phillip Biddulph,
     150             : // Complex Built Environment Systems, The Bartlett School of Graduate Studies, University College London, Gower Street,
     151             : // London WC1E 6BT, United Kingdom. http://www.cbes.ucl.ac.uk/.
     152             : 
     153             : // The SQLite output module, first introduced in EnergyPlus v3.0.0, was developed by Gregory B. Stark, P.E.,
     154             : // Building Synergies, LLC, 1860 Washington Street, Suite 208, Denver, Colorado 80203, United States.
     155             : // http://www.buildingsynergies.com/
     156             : 
     157             : // Refrigeration compressor performance data and refrigeration practices were provided by CDH Energy, Cazenovia, NY 12035.
     158             : 
     159             : // Other Acknowledgments
     160             : 
     161             : // This work was supported by the Assistant Secretary for Energy Efficiency and Renewable Energy, Office
     162             : // of Building Technologies Program of the US Department of Energy.
     163             : 
     164             : // Additional support was provided by the Gas Technology Institute and the California Energy Commission.
     165             : 
     166             : // The ice thermal storage module development was supported by the U.S. Department of Energy Office of
     167             : // Electricity Delivery and Energy Reliability.
     168             : 
     169             : // The HAMT (Heat And Moisture Transfer) model was supported by the Engineering and Physical Sciences Research Council (EPSRC),
     170             : // the UK government agency for funding research and training in engineering and the physical sciences.
     171             : 
     172             : // The SQLite output module was funded by Building Synergies, LLC and was made possible by inclusion of software code
     173             : // from the SQLite project (http://www.sqlite.org/).
     174             : 
     175             : #ifdef _WIN32
     176             : #include <Windows.h>
     177             : #endif
     178             : 
     179             : // C++ Headers
     180             : #include <exception>
     181             : #include <iostream>
     182             : #include <string>
     183             : #include <vector>
     184             : 
     185             : #ifdef DEBUG_ARITHM_GCC_OR_CLANG
     186             : #include <EnergyPlus/fenv_missing.h>
     187             : #endif
     188             : 
     189             : #ifdef DEBUG_ARITHM_MSVC
     190             : #include <cfloat>
     191             : #endif
     192             : 
     193             : // ObjexxFCL Headers
     194             : #include <ObjexxFCL/Array1D.hh>
     195             : #include <ObjexxFCL/time.hh>
     196             : 
     197             : // EnergyPlus Headers
     198             : #include <EnergyPlus/CommandLineInterface.hh>
     199             : #include <EnergyPlus/Data/EnergyPlusData.hh>
     200             : #include <EnergyPlus/DataGlobals.hh>
     201             : #include <EnergyPlus/DataStringGlobals.hh>
     202             : #include <EnergyPlus/DataSystemVariables.hh>
     203             : #include <EnergyPlus/DataTimings.hh>
     204             : #include <EnergyPlus/DisplayRoutines.hh>
     205             : #include <EnergyPlus/FileSystem.hh>
     206             : #include <EnergyPlus/FluidProperties.hh>
     207             : #include <EnergyPlus/IOFiles.hh>
     208             : #include <EnergyPlus/InputProcessing/IdfParser.hh>
     209             : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
     210             : #include <EnergyPlus/InputProcessing/InputValidation.hh>
     211             : #include <EnergyPlus/OutputProcessor.hh>
     212             : #include <EnergyPlus/Psychrometrics.hh>
     213             : #include <EnergyPlus/ResultsFramework.hh>
     214             : #include <EnergyPlus/SQLiteProcedures.hh>
     215             : #include <EnergyPlus/ScheduleManager.hh>
     216             : #include <EnergyPlus/SimulationManager.hh>
     217             : #include <EnergyPlus/UtilityRoutines.hh>
     218             : #include <EnergyPlus/api/EnergyPlusPgm.hh>
     219             : 
     220             : #ifdef _WIN32
     221             : #include <direct.h>
     222             : #include <stdlib.h>
     223             : #else // Mac or Linux
     224             : #include <unistd.h>
     225             : #endif
     226             : 
     227         796 : int EnergyPlusPgm(const std::vector<std::string> &args, std::string const &filepath)
     228             : {
     229         796 :     EnergyPlus::EnergyPlusData state;
     230             :     //// these need to be set early to be used in help and version output messaging
     231         796 :     Array1D_int value(8);
     232         796 :     std::string datestring; // supposedly returns blank when no date available.
     233         796 :     date_and_time(datestring, _, _, value);
     234         796 :     if (!datestring.empty()) {
     235        1592 :         state.dataStrGlobals->CurrentDateTime = fmt::format(" YMD={:4}.{:02}.{:02} {:02}:{:02}", value(1), value(2), value(3), value(5), value(6));
     236             :     } else {
     237           0 :         state.dataStrGlobals->CurrentDateTime = " unknown date/time";
     238             :     }
     239         796 :     state.dataStrGlobals->VerStringVar = EnergyPlus::DataStringGlobals::VerString + "," + state.dataStrGlobals->CurrentDateTime;
     240             : 
     241         796 :     EnergyPlus::CommandLineInterface::ProcessArgs(state, args);
     242        1592 :     return RunEnergyPlus(state, filepath);
     243         796 : }
     244             : 
     245         796 : void commonInitialize(EnergyPlus::EnergyPlusData &state)
     246             : {
     247             :     using namespace EnergyPlus;
     248             :     // Disable C++ i/o synching with C methods for speed
     249             :     // std::ios_base::sync_with_stdio(false);
     250             :     // std::cin.tie(nullptr); // Untie cin and cout: Could cause odd behavior for interactive prompts
     251             : 
     252             : // Enable floating point exceptions
     253             : #ifdef DEBUG_ARITHM_GCC_OR_CLANG
     254         796 :     feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); // These exceptions are enabled (FE_INEXACT and FE_UNDERFLOW will not throw)
     255             : #endif
     256             : 
     257             : #ifdef DEBUG_ARITHM_MSVC
     258             :     // the following enables NaN detection in Visual Studio debug builds. See
     259             :     // https://github.com/NREL/EnergyPlus/wiki/Debugging-Tips
     260             : 
     261             :     // Note: what you need to pass to the _controlfp_s is actually the opposite
     262             :     // By default all bits are 1, and the exceptions are turned off, so you need to turn off the bits for the exceptions you want to enable
     263             :     // > For the _MCW_EM mask, clearing it sets the exception, which allows the hardware exception; setting it hides the exception.
     264             :     unsigned int fpcntrl = 0;
     265             :     _controlfp_s(&fpcntrl, 0, 0);
     266             :     unsigned int new_exceptions = _EM_ZERODIVIDE | _EM_INVALID | _EM_OVERFLOW;
     267             :     unsigned int new_control = fpcntrl & ~new_exceptions;
     268             :     _controlfp_s(&fpcntrl, new_control, _MCW_EM);
     269             : #endif
     270             : 
     271             : #ifdef _MSC_VER
     272             : #ifndef _DEBUG
     273             :     // If _MSC_VER and not debug then prevent dialogs on error
     274             :     SetErrorMode(SEM_NOGPFAULTERRORBOX);
     275             :     _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
     276             :     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
     277             : #endif
     278             : #endif
     279             : 
     280         796 :     state.dataSysVars->runtimeTimer.tick();
     281             : 
     282         796 :     state.dataStrGlobals->CurrentDateTime = CreateCurrentDateTimeString();
     283             : 
     284         796 :     state.dataResultsFramework->resultsFramework->SimulationInformation.setProgramVersion(state.dataStrGlobals->VerStringVar);
     285         796 :     state.dataResultsFramework->resultsFramework->SimulationInformation.setStartDateTimeStamp(state.dataStrGlobals->CurrentDateTime.substr(5));
     286             : 
     287         796 :     state.dataStrGlobals->VerStringVar = DataStringGlobals::VerString + "," + state.dataStrGlobals->CurrentDateTime;
     288             : 
     289         796 :     DataSystemVariables::processEnvironmentVariables(state);
     290         796 : }
     291             : 
     292         796 : int commonRun(EnergyPlus::EnergyPlusData &state)
     293             : {
     294             :     using namespace EnergyPlus;
     295             : 
     296         796 :     int errStatus = initErrorFile(state);
     297         796 :     if (errStatus) {
     298           0 :         return errStatus;
     299             :     }
     300             : 
     301         796 :     state.dataSysVars->TestAllPaths = true;
     302             : 
     303         796 :     DisplayString(state, "EnergyPlus Starting");
     304         796 :     DisplayString(state, state.dataStrGlobals->VerStringVar);
     305             : 
     306             :     try {
     307         796 :         if (!state.dataInputProcessing->inputProcessor) {
     308           0 :             state.dataInputProcessing->inputProcessor = InputProcessor::factory();
     309             :         }
     310         796 :         state.dataInputProcessing->inputProcessor->processInput(state);
     311         796 :         if (state.dataGlobal->outputEpJSONConversionOnly) {
     312           0 :             DisplayString(state, "Converted input file format. Exiting.");
     313           0 :             return EndEnergyPlus(state);
     314             :         }
     315           0 :     } catch (const FatalError &e) {
     316           0 :         return AbortEnergyPlus(state);
     317           0 :     } catch (const std::exception &e) {
     318           0 :         ShowSevereError(state, e.what());
     319           0 :         return AbortEnergyPlus(state);
     320           0 :     }
     321         796 :     return 0;
     322             : }
     323             : 
     324         796 : int initializeEnergyPlus(EnergyPlus::EnergyPlusData &state, std::string const &filepath)
     325             : {
     326             :     using namespace EnergyPlus;
     327         796 :     commonInitialize(state);
     328             : 
     329         796 :     if (!filepath.empty()) {
     330             :         // if filepath is not empty, then we are using E+ as a library API call
     331             :         // change the directory to the specified folder, and pass in dummy args to command line parser
     332             :         // this will initialize the paths throughout E+ to the defaults
     333           0 :         DisplayString(state, "EnergyPlus Library: Changing directory to: " + filepath);
     334             : #ifdef _WIN32
     335             :         int status = _chdir(filepath.c_str());
     336             : #else
     337           0 :         int status = chdir(filepath.c_str());
     338             : #endif
     339           0 :         if (status == 0) {
     340           0 :             DisplayString(state, "Directory change successful.");
     341             :         } else {
     342           0 :             DisplayString(state, "Couldn't change directory; aborting EnergyPlus");
     343           0 :             return EXIT_FAILURE;
     344             :         }
     345           0 :         state.dataStrGlobals->ProgramPath = filepath + DataStringGlobals::pathChar;
     346           0 :         CommandLineInterface::ProcessArgs(state, {"energyplus"});
     347             :     }
     348             : 
     349         796 :     return commonRun(state);
     350             : }
     351             : 
     352           0 : int initializeAsLibrary(EnergyPlus::EnergyPlusData &state)
     353             : {
     354           0 :     commonInitialize(state);
     355           0 :     return commonRun(state);
     356             : }
     357             : 
     358         794 : int wrapUpEnergyPlus(EnergyPlus::EnergyPlusData &state)
     359             : {
     360             :     using namespace EnergyPlus;
     361             : 
     362             :     try {
     363         794 :         ShowMessage(state, "Simulation Error Summary *************");
     364             : 
     365         794 :         GenOutputVariablesAuditReport(state);
     366             : 
     367         794 :         Psychrometrics::ShowPsychrometricSummary(state, state.files.audit);
     368             : 
     369         794 :         state.dataInputProcessing->inputProcessor->reportOrphanRecordObjects(state);
     370         794 :         FluidProperties::ReportOrphanFluids(state);
     371         794 :         ScheduleManager::ReportOrphanSchedules(state);
     372         794 :         if (state.dataSQLiteProcedures->sqlite) {
     373         123 :             state.dataSQLiteProcedures->sqlite.reset();
     374             :         }
     375         794 :         if (state.dataInputProcessing->inputProcessor) {
     376         794 :             state.dataInputProcessing->inputProcessor.reset();
     377             :         }
     378             : 
     379         794 :         if (state.dataGlobal->runReadVars) {
     380         794 :             if (state.files.outputControl.csv) {
     381           6 :                 ShowWarningMessage(state, "Native CSV output requested in input file, but running ReadVarsESO due to command line argument.");
     382           6 :                 ShowWarningMessage(state, "This will overwrite the native CSV output.");
     383             :             }
     384         794 :             int status = CommandLineInterface::runReadVarsESO(state);
     385         794 :             if (status) {
     386           0 :                 return status;
     387             :             }
     388             :         }
     389           0 :     } catch (const FatalError &e) {
     390           0 :         return AbortEnergyPlus(state);
     391           0 :     } catch (const std::exception &e) {
     392           0 :         ShowSevereError(state, e.what());
     393           0 :         return AbortEnergyPlus(state);
     394           0 :     }
     395             : 
     396         794 :     return EndEnergyPlus(state);
     397             : }
     398             : 
     399         796 : int RunEnergyPlus(EnergyPlus::EnergyPlusData &state, std::string const &filepath)
     400             : {
     401             : 
     402             :     // PROGRAM INFORMATION:
     403             :     //       AUTHOR         Linda K. Lawrie, et al
     404             :     //       DATE WRITTEN   January 1997.....
     405             :     //       MODIFIED       na
     406             :     //       RE-ENGINEERED  na
     407             : 
     408             :     // PURPOSE OF THIS PROGRAM:
     409             :     // This program implements the calls for EnergyPlus (originally configured
     410             :     // as the merger of BLAST/IBLAST and DOE-2 energy analysis programs).
     411             : 
     412             :     // METHODOLOGY EMPLOYED:
     413             :     // The method used in EnergyPlus is to simplify the main program as much
     414             :     // as possible and contain all "simulation" code in other modules and files.
     415             :     using namespace EnergyPlus;
     416         796 :     int status = initializeEnergyPlus(state, filepath);
     417         796 :     if (status || state.dataGlobal->outputEpJSONConversionOnly) return status;
     418             :     try {
     419         796 :         EnergyPlus::SimulationManager::ManageSimulation(state);
     420           2 :     } catch (const EnergyPlus::FatalError &e) {
     421           2 :         return EnergyPlus::AbortEnergyPlus(state);
     422             : #ifdef NDEBUG
     423             :     } catch (const std::exception &e) {
     424             :         ShowSevereError(state, e.what());
     425             :         return EnergyPlus::AbortEnergyPlus(state);
     426             : #endif
     427           2 :     }
     428             : 
     429         794 :     return wrapUpEnergyPlus(state);
     430             : }
     431             : 
     432           0 : int runEnergyPlusAsLibrary(EnergyPlus::EnergyPlusData &state, const std::vector<std::string> &args)
     433             : {
     434             :     // PROGRAM INFORMATION:
     435             :     //       AUTHOR         Linda K. Lawrie, et al
     436             :     //       DATE WRITTEN   January 1997.....
     437             :     //       MODIFIED       na
     438             :     //       RE-ENGINEERED  na
     439             : 
     440             :     // PURPOSE OF THIS PROGRAM:
     441             :     // This program implements the calls for EnergyPlus (originally configured
     442             :     // as the merger of BLAST/IBLAST and DOE-2 energy analysis programs).
     443             : 
     444             :     // METHODOLOGY EMPLOYED:
     445             :     // The method used in EnergyPlus is to simplify the main program as much
     446             :     // as possible and contain all "simulation" code in other modules and files.
     447             :     using namespace EnergyPlus;
     448           0 :     state.dataGlobal->eplusRunningViaAPI = true;
     449             : 
     450             :     // clean out any stdin, stderr, stdout flags from a prior call
     451           0 :     if (!std::cin.good()) std::cin.clear();
     452           0 :     if (!std::cerr.good()) std::cerr.clear();
     453           0 :     if (!std::cout.good()) std::cout.clear();
     454             : 
     455           0 :     int return_code = EnergyPlus::CommandLineInterface::ProcessArgs(state, args);
     456           0 :     if (return_code == static_cast<int>(EnergyPlus::CommandLineInterface::ReturnCodes::Failure)) {
     457           0 :         return return_code;
     458           0 :     } else if (return_code == static_cast<int>(EnergyPlus::CommandLineInterface::ReturnCodes::SuccessButHelper)) {
     459             :         // If it was "--version" or "--help", you do not want to continue trying to run the simulation, but do not want to indicate failure either
     460           0 :         return static_cast<int>(EnergyPlus::CommandLineInterface::ReturnCodes::Success);
     461             :     }
     462             : 
     463           0 :     int status = initializeAsLibrary(state);
     464           0 :     if (status || state.dataGlobal->outputEpJSONConversionOnly) {
     465           0 :         return status;
     466             :     }
     467             :     try {
     468           0 :         EnergyPlus::SimulationManager::ManageSimulation(state);
     469           0 :     } catch (const EnergyPlus::FatalError &e) {
     470           0 :         return EnergyPlus::AbortEnergyPlus(state);
     471           0 :     } catch (const std::exception &e) {
     472           0 :         ShowSevereError(state, e.what());
     473           0 :         return EnergyPlus::AbortEnergyPlus(state);
     474           0 :     }
     475           0 :     return wrapUpEnergyPlus(state);
     476             : }
     477             : 
     478           0 : void StoreProgressCallback(EnergyPlus::EnergyPlusData &state, void (*f)(int const))
     479             : {
     480           0 :     state.dataGlobal->fProgressPtr = f;
     481           0 : }
     482           0 : void StoreMessageCallback(EnergyPlus::EnergyPlusData &state, void (*f)(std::string const &))
     483             : {
     484           0 :     state.dataGlobal->fMessagePtr = f;
     485           0 : }
     486             : 
     487         796 : std::string CreateCurrentDateTimeString()
     488             : {
     489             : 
     490             :     // SUBROUTINE INFORMATION:
     491             :     //       AUTHOR         Linda Lawrie
     492             :     //       DATE WRITTEN   October 2010
     493             :     //       MODIFIED       na
     494             :     //       RE-ENGINEERED  na
     495             : 
     496             :     // PURPOSE OF THIS SUBROUTINE:
     497             :     // Be able to supply a current date/time string from intrinsic calls so
     498             :     // that one is always available.
     499             : 
     500             :     // SUBROUTINE PARAMETER DEFINITIONS:
     501             : 
     502             :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     503         796 :     Array1D_int value(8);
     504             :     // value(1)   Current year
     505             :     // value(2)   Current month
     506             :     // value(3)   Current day
     507             :     // value(4)   Time difference with respect to UTC in minutes (0-59)
     508             :     // value(5)   Hour of the day (0-23)
     509             :     // value(6)   Minutes (0-59)
     510             :     // value(7)   Seconds (0-59)
     511             :     // value(8)   Milliseconds (0-999)
     512         796 :     std::string datestring; // supposedly returns blank when no date available.
     513             : 
     514         796 :     date_and_time(datestring, _, _, value);
     515         796 :     if (!datestring.empty()) {
     516         796 :         return EnergyPlus::format(" YMD={:4}.{:02}.{:02} {:02}:{:02}", value(1), value(2), value(3), value(5), value(6));
     517             :     } else {
     518           0 :         return " unknown date/time";
     519             :     }
     520         796 : }

Generated by: LCOV version 1.14