LCOV - code coverage report
Current view: top level - EnergyPlus/api - EnergyPlusPgm.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 64 122 52.5 %
Date: 2023-01-17 19:17:23 Functions: 9 13 69.2 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2023, 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             : #ifndef NDEBUG
     183             : #ifdef __unix__
     184             : #include <cfenv>
     185             : #endif
     186             : #endif
     187             : 
     188             : // ObjexxFCL Headers
     189             : #include <ObjexxFCL/Array1D.hh>
     190             : #include <ObjexxFCL/time.hh>
     191             : 
     192             : // EnergyPlus Headers
     193             : #include <EnergyPlus/CommandLineInterface.hh>
     194             : #include <EnergyPlus/Data/EnergyPlusData.hh>
     195             : #include <EnergyPlus/DataGlobals.hh>
     196             : #include <EnergyPlus/DataStringGlobals.hh>
     197             : #include <EnergyPlus/DataSystemVariables.hh>
     198             : #include <EnergyPlus/DataTimings.hh>
     199             : #include <EnergyPlus/DisplayRoutines.hh>
     200             : #include <EnergyPlus/FileSystem.hh>
     201             : #include <EnergyPlus/FluidProperties.hh>
     202             : #include <EnergyPlus/IOFiles.hh>
     203             : #include <EnergyPlus/InputProcessing/IdfParser.hh>
     204             : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
     205             : #include <EnergyPlus/InputProcessing/InputValidation.hh>
     206             : #include <EnergyPlus/OutputProcessor.hh>
     207             : #include <EnergyPlus/Psychrometrics.hh>
     208             : #include <EnergyPlus/ResultsFramework.hh>
     209             : #include <EnergyPlus/SQLiteProcedures.hh>
     210             : #include <EnergyPlus/ScheduleManager.hh>
     211             : #include <EnergyPlus/SimulationManager.hh>
     212             : #include <EnergyPlus/UtilityRoutines.hh>
     213             : #include <EnergyPlus/api/EnergyPlusPgm.hh>
     214             : 
     215             : #ifdef _WIN32
     216             : #include <direct.h>
     217             : #include <stdlib.h>
     218             : #else // Mac or Linux
     219             : #include <unistd.h>
     220             : #endif
     221             : 
     222         771 : int EnergyPlusPgm(int argc, const char *argv[], std::string const &filepath)
     223             : {
     224        1542 :     EnergyPlus::EnergyPlusData state;
     225             :     //// these need to be set early to be used in help and version output messaging
     226        1542 :     Array1D_int value(8);
     227        1542 :     std::string datestring; // supposedly returns blank when no date available.
     228         771 :     date_and_time(datestring, _, _, value);
     229         771 :     if (!datestring.empty()) {
     230        1542 :         state.dataStrGlobals->CurrentDateTime = fmt::format(" YMD={:4}.{:02}.{:02} {:02}:{:02}", value(1), value(2), value(3), value(5), value(6));
     231             :     } else {
     232           0 :         state.dataStrGlobals->CurrentDateTime = " unknown date/time";
     233             :     }
     234         771 :     state.dataStrGlobals->VerStringVar = EnergyPlus::DataStringGlobals::VerString + "," + state.dataStrGlobals->CurrentDateTime;
     235             : 
     236         771 :     EnergyPlus::CommandLineInterface::ProcessArgs(state, argc, argv);
     237        1542 :     return RunEnergyPlus(state, filepath);
     238             : }
     239             : 
     240         771 : void commonInitialize(EnergyPlus::EnergyPlusData &state)
     241             : {
     242             :     using namespace EnergyPlus;
     243             :     // Disable C++ i/o synching with C methods for speed
     244             :     // std::ios_base::sync_with_stdio(false);
     245             :     // std::cin.tie(nullptr); // Untie cin and cout: Could cause odd behavior for interactive prompts
     246             : 
     247             : // Enable floating point exceptions
     248             : #ifndef NDEBUG
     249             : #ifdef __unix__
     250         771 :     feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); // These exceptions are enabled (FE_INEXACT and FE_UNDERFLOW will not throw)
     251             : #endif
     252             : #endif
     253             : 
     254             : #ifdef MSVC_DEBUG
     255             :     // the following line enables NaN detection in Visual Studio debug builds. See
     256             :     // https://github.com/NREL/EnergyPlus/wiki/Debugging-Tips
     257             :     int fp_control_state =
     258             :         _controlfp(_EM_INEXACT | _EM_UNDERFLOW, _MCW_EM); // These exceptions are disabled (_EM_INEXACT and _EM_UNDERFLOW will not throw)
     259             : #endif
     260             : 
     261             : #ifdef _MSC_VER
     262             : #ifndef _DEBUG
     263             :     // If _MSC_VER and not debug then prevent dialogs on error
     264             :     SetErrorMode(SEM_NOGPFAULTERRORBOX);
     265             :     _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
     266             :     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
     267             : #endif
     268             : #endif
     269             : 
     270         771 :     state.dataSysVars->Time_Start = UtilityRoutines::epElapsedTime();
     271             : 
     272         771 :     state.dataStrGlobals->CurrentDateTime = CreateCurrentDateTimeString();
     273             : 
     274         771 :     state.dataResultsFramework->resultsFramework->SimulationInformation.setProgramVersion(state.dataStrGlobals->VerStringVar);
     275         771 :     state.dataResultsFramework->resultsFramework->SimulationInformation.setStartDateTimeStamp(state.dataStrGlobals->CurrentDateTime.substr(5));
     276             : 
     277         771 :     state.dataStrGlobals->VerStringVar = DataStringGlobals::VerString + "," + state.dataStrGlobals->CurrentDateTime;
     278             : 
     279         771 :     DataSystemVariables::processEnvironmentVariables(state);
     280         771 : }
     281             : 
     282         771 : int commonRun(EnergyPlus::EnergyPlusData &state)
     283             : {
     284             :     using namespace EnergyPlus;
     285             : 
     286         771 :     int errStatus = initErrorFile(state);
     287         771 :     if (errStatus) {
     288           0 :         return errStatus;
     289             :     }
     290             : 
     291         771 :     state.dataSysVars->TestAllPaths = true;
     292             : 
     293         771 :     DisplayString(state, "EnergyPlus Starting");
     294         771 :     DisplayString(state, state.dataStrGlobals->VerStringVar);
     295             : 
     296             :     try {
     297         771 :         if (!state.dataInputProcessing->inputProcessor) {
     298           0 :             state.dataInputProcessing->inputProcessor = InputProcessor::factory();
     299             :         }
     300         771 :         state.dataInputProcessing->inputProcessor->processInput(state);
     301         771 :         if (state.dataGlobal->outputEpJSONConversionOnly) {
     302           0 :             DisplayString(state, "Converted input file format. Exiting.");
     303           0 :             return EndEnergyPlus(state);
     304             :         }
     305           0 :     } catch (const FatalError &e) {
     306           0 :         return AbortEnergyPlus(state);
     307           0 :     } catch (const std::exception &e) {
     308           0 :         ShowSevereError(state, e.what());
     309           0 :         return AbortEnergyPlus(state);
     310             :     }
     311         771 :     return 0;
     312             : }
     313             : 
     314         771 : int initializeEnergyPlus(EnergyPlus::EnergyPlusData &state, std::string const &filepath)
     315             : {
     316             :     using namespace EnergyPlus;
     317         771 :     commonInitialize(state);
     318             : 
     319         771 :     if (!filepath.empty()) {
     320             :         // if filepath is not empty, then we are using E+ as a library API call
     321             :         // change the directory to the specified folder, and pass in dummy args to command line parser
     322             :         // this will initialize the paths throughout E+ to the defaults
     323           0 :         DisplayString(state, "EnergyPlus Library: Changing directory to: " + filepath);
     324             : #ifdef _WIN32
     325             :         int status = _chdir(filepath.c_str());
     326             : #else
     327           0 :         int status = chdir(filepath.c_str());
     328             : #endif
     329           0 :         if (status == 0) {
     330           0 :             DisplayString(state, "Directory change successful.");
     331             :         } else {
     332           0 :             DisplayString(state, "Couldn't change directory; aborting EnergyPlus");
     333           0 :             return EXIT_FAILURE;
     334             :         }
     335           0 :         state.dataStrGlobals->ProgramPath = filepath + DataStringGlobals::pathChar;
     336           0 :         int dummy_argc = 1;
     337           0 :         const char *dummy_argv[1] = {"energyplus"};
     338           0 :         CommandLineInterface::ProcessArgs(state, dummy_argc, dummy_argv);
     339             :     }
     340             : 
     341         771 :     return commonRun(state);
     342             : }
     343             : 
     344           0 : int initializeAsLibrary(EnergyPlus::EnergyPlusData &state)
     345             : {
     346           0 :     commonInitialize(state);
     347           0 :     return commonRun(state);
     348             : }
     349             : 
     350         769 : int wrapUpEnergyPlus(EnergyPlus::EnergyPlusData &state)
     351             : {
     352             :     using namespace EnergyPlus;
     353             : 
     354             :     try {
     355         769 :         ShowMessage(state, "Simulation Error Summary *************");
     356             : 
     357         769 :         GenOutputVariablesAuditReport(state);
     358             : 
     359         769 :         Psychrometrics::ShowPsychrometricSummary(state, state.files.audit);
     360             : 
     361         769 :         state.dataInputProcessing->inputProcessor->reportOrphanRecordObjects(state);
     362         769 :         FluidProperties::ReportOrphanFluids(state);
     363         769 :         ScheduleManager::ReportOrphanSchedules(state);
     364         769 :         if (state.dataSQLiteProcedures->sqlite) {
     365         116 :             state.dataSQLiteProcedures->sqlite.reset();
     366             :         }
     367         769 :         if (state.dataInputProcessing->inputProcessor) {
     368         769 :             state.dataInputProcessing->inputProcessor.reset();
     369             :         }
     370             : 
     371         769 :         if (state.dataGlobal->runReadVars) {
     372             :             //            state.files.outputControl.csv = true;
     373         769 :             if (state.files.outputControl.csv) {
     374           4 :                 ShowWarningMessage(state, "Native CSV output requested in input file, but running ReadVarsESO due to command line argument.");
     375             :             }
     376         769 :             int status = CommandLineInterface::runReadVarsESO(state);
     377         769 :             if (status) {
     378           0 :                 return status;
     379             :             }
     380             :         }
     381           0 :     } catch (const FatalError &e) {
     382           0 :         return AbortEnergyPlus(state);
     383           0 :     } catch (const std::exception &e) {
     384           0 :         ShowSevereError(state, e.what());
     385           0 :         return AbortEnergyPlus(state);
     386             :     }
     387             : 
     388         769 :     return EndEnergyPlus(state);
     389             : }
     390             : 
     391         771 : int RunEnergyPlus(EnergyPlus::EnergyPlusData &state, std::string const &filepath)
     392             : {
     393             : 
     394             :     // PROGRAM INFORMATION:
     395             :     //       AUTHOR         Linda K. Lawrie, et al
     396             :     //       DATE WRITTEN   January 1997.....
     397             :     //       MODIFIED       na
     398             :     //       RE-ENGINEERED  na
     399             : 
     400             :     // PURPOSE OF THIS PROGRAM:
     401             :     // This program implements the calls for EnergyPlus (originally configured
     402             :     // as the merger of BLAST/IBLAST and DOE-2 energy analysis programs).
     403             : 
     404             :     // METHODOLOGY EMPLOYED:
     405             :     // The method used in EnergyPlus is to simplify the main program as much
     406             :     // as possible and contain all "simulation" code in other modules and files.
     407             : 
     408         771 :     int status = initializeEnergyPlus(state, filepath);
     409         771 :     if (status || state.dataGlobal->outputEpJSONConversionOnly) return status;
     410             :     try {
     411         771 :         EnergyPlus::SimulationManager::ManageSimulation(state);
     412           4 :     } catch (const EnergyPlus::FatalError &e) {
     413           2 :         return EnergyPlus::AbortEnergyPlus(state);
     414           0 :     } catch (const std::exception &e) {
     415           0 :         EnergyPlus::ShowSevereError(state, e.what());
     416           0 :         return EnergyPlus::AbortEnergyPlus(state);
     417             :     }
     418         769 :     return wrapUpEnergyPlus(state);
     419             : }
     420             : 
     421           0 : int runEnergyPlusAsLibrary(EnergyPlus::EnergyPlusData &state, int argc, const char *argv[])
     422             : {
     423             :     // PROGRAM INFORMATION:
     424             :     //       AUTHOR         Linda K. Lawrie, et al
     425             :     //       DATE WRITTEN   January 1997.....
     426             :     //       MODIFIED       na
     427             :     //       RE-ENGINEERED  na
     428             : 
     429             :     // PURPOSE OF THIS PROGRAM:
     430             :     // This program implements the calls for EnergyPlus (originally configured
     431             :     // as the merger of BLAST/IBLAST and DOE-2 energy analysis programs).
     432             : 
     433             :     // METHODOLOGY EMPLOYED:
     434             :     // The method used in EnergyPlus is to simplify the main program as much
     435             :     // as possible and contain all "simulation" code in other modules and files.
     436             : 
     437           0 :     state.dataGlobal->eplusRunningViaAPI = true;
     438             : 
     439             :     // clean out any stdin, stderr, stdout flags from a prior call
     440           0 :     if (!std::cin.good()) std::cin.clear();
     441           0 :     if (!std::cerr.good()) std::cerr.clear();
     442           0 :     if (!std::cout.good()) std::cout.clear();
     443             : 
     444           0 :     int return_code = EnergyPlus::CommandLineInterface::ProcessArgs(state, argc, argv);
     445           0 :     if (return_code == static_cast<int>(EnergyPlus::CommandLineInterface::ReturnCodes::Failure)) {
     446           0 :         return return_code;
     447           0 :     } else if (return_code == static_cast<int>(EnergyPlus::CommandLineInterface::ReturnCodes::SuccessButHelper)) {
     448             :         // 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
     449           0 :         return static_cast<int>(EnergyPlus::CommandLineInterface::ReturnCodes::Success);
     450             :     }
     451             : 
     452           0 :     int status = initializeAsLibrary(state);
     453           0 :     if (status || state.dataGlobal->outputEpJSONConversionOnly) return status;
     454             :     try {
     455           0 :         EnergyPlus::SimulationManager::ManageSimulation(state);
     456           0 :     } catch (const EnergyPlus::FatalError &e) {
     457           0 :         return EnergyPlus::AbortEnergyPlus(state);
     458           0 :     } catch (const std::exception &e) {
     459           0 :         EnergyPlus::ShowSevereError(state, e.what());
     460           0 :         return EnergyPlus::AbortEnergyPlus(state);
     461             :     }
     462           0 :     return wrapUpEnergyPlus(state);
     463             : }
     464             : 
     465           0 : void StoreProgressCallback(EnergyPlus::EnergyPlusData &state, void (*f)(int const))
     466             : {
     467           0 :     state.dataGlobal->fProgressPtr = f;
     468           0 : }
     469           0 : void StoreMessageCallback(EnergyPlus::EnergyPlusData &state, void (*f)(std::string const &))
     470             : {
     471           0 :     state.dataGlobal->fMessagePtr = f;
     472           0 : }
     473             : 
     474         771 : std::string CreateCurrentDateTimeString()
     475             : {
     476             : 
     477             :     // SUBROUTINE INFORMATION:
     478             :     //       AUTHOR         Linda Lawrie
     479             :     //       DATE WRITTEN   October 2010
     480             :     //       MODIFIED       na
     481             :     //       RE-ENGINEERED  na
     482             : 
     483             :     // PURPOSE OF THIS SUBROUTINE:
     484             :     // Be able to supply a current date/time string from intrinsic calls so
     485             :     // that one is always available.
     486             : 
     487             :     // SUBROUTINE PARAMETER DEFINITIONS:
     488             : 
     489             :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     490        1542 :     Array1D_int value(8);
     491             :     // value(1)   Current year
     492             :     // value(2)   Current month
     493             :     // value(3)   Current day
     494             :     // value(4)   Time difference with respect to UTC in minutes (0-59)
     495             :     // value(5)   Hour of the day (0-23)
     496             :     // value(6)   Minutes (0-59)
     497             :     // value(7)   Seconds (0-59)
     498             :     // value(8)   Milliseconds (0-999)
     499        1542 :     std::string datestring; // supposedly returns blank when no date available.
     500             : 
     501         771 :     date_and_time(datestring, _, _, value);
     502         771 :     if (!datestring.empty()) {
     503         771 :         return EnergyPlus::format(" YMD={:4}.{:02}.{:02} {:02}:{:02}", value(1), value(2), value(3), value(5), value(6));
     504             :     } else {
     505           0 :         return " unknown date/time";
     506             :     }
     507        2313 : }

Generated by: LCOV version 1.13