From 624b24e647d15c86a064a9045d7ac275e439d74b Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 2 Feb 2022 11:17:02 +0100 Subject: [PATCH] New CoPilot function to load from .spt file. --- solarpilot/CoPilot_API.cpp | 30 ++++++++++++++++++++++++++++++ solarpilot/CoPilot_API.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/solarpilot/CoPilot_API.cpp b/solarpilot/CoPilot_API.cpp index 46c29141b3..1544f23bf8 100644 --- a/solarpilot/CoPilot_API.cpp +++ b/solarpilot/CoPilot_API.cpp @@ -2193,6 +2193,36 @@ SPEXPORT bool sp_save_from_script(sp_data_t p_data, const char* sp_fname) return false; } +SPEXPORT bool sp_load_from_script(sp_data_t p_data, const char* sp_fname) +{ + /* + Load a SolarPILOT .spt file. Returns true if successful. + Returns: (string:path):boolean + */ + + api_helper *mc = static_cast(p_data); + var_map* V = &mc->variables; + + if (!ioutil::file_exists(sp_fname)) + { + return false; + } + + try + { + parametric p; + optimization o; + + ioutil::parseXMLInputFile(sp_fname, *V, p, o); + return true; + } + catch (...) + { + + } + return false; +} + SPEXPORT bool sp_dump_varmap(sp_data_t p_data, const char* sp_fname) { /* diff --git a/solarpilot/CoPilot_API.h b/solarpilot/CoPilot_API.h index 425b780c7e..09f95ced93 100644 --- a/solarpilot/CoPilot_API.h +++ b/solarpilot/CoPilot_API.h @@ -105,6 +105,8 @@ extern "C" { SPEXPORT bool sp_save_from_script(sp_data_t p_data, const char* sp_fname); + SPEXPORT bool sp_load_from_script(sp_data_t p_data, const char* sp_fname); + SPEXPORT bool sp_dump_varmap(sp_data_t p_data, const char* sp_fname); #ifdef __cplusplus