| 628 | |
| 629 | |
| 630 | bool Case::SaveAsSSCJSON(wxString filename) |
| 631 | { |
| 632 | // similar to CodeGen_json but uses RapidJSON instead of fprintf (prototype for rewriting codegenerator) |
| 633 | // run equations to update calculated values |
| 634 | // write out all inputs for all compute modules |
| 635 | ConfigInfo* cfg = GetConfiguration(); |
| 636 | if (!cfg) return false; |
| 637 | |
| 638 | char json_string[32256]; |
| 639 | // TODO - finish and concatenate based on hybrid compute modules - see test input json for cmod_hybrid |
| 640 | for (size_t i = 0; i < cfg->Technology.size(); i++) { |
| 641 | |
| 642 | VarTable inputs = Values(i); // SAM VarTable for the case |
| 643 | CaseEvaluator eval(this, inputs, Equations(i)); |
| 644 | int n = eval.CalculateAll(i); |
| 645 | if (n < 0) return false; |
| 646 | |
| 647 | // get list of compute modules from case configuration |
| 648 | wxArrayString simlist = cfg->Simulations; |
| 649 | if (simlist.size() == 0) return false; |
| 650 | // go through and translate all SAM UI variables to SSC variables |
| 651 | ssc_data_t p_data = ssc_data_create(); |
| 652 | |
| 653 | for (size_t kk = 0; kk < simlist.size(); kk++) |
| 654 | { |
| 655 | ssc_module_t p_mod = ssc_module_create(simlist[kk].c_str()); |
| 656 | if (!p_mod) continue; |
| 657 | |
| 658 | int pidx = 0; |
| 659 | while (const ssc_info_t p_inf = ssc_module_var_info(p_mod, pidx++)) { |
| 660 | int var_type = ssc_info_var_type(p_inf); // SSC_INPUT, SSC_OUTPUT, SSC_INOUT |
| 661 | int ssc_data_type = ssc_info_data_type(p_inf); // SSC_STRING, SSC_NUMBER, SSC_ARRAY, SSC_MATRIX |
| 662 | const char* var_name = ssc_info_name(p_inf); |
| 663 | wxString name(var_name); // assumed to be non-null |
| 664 | wxString reqd(ssc_info_required(p_inf)); |
| 665 | |
| 666 | if (var_type == SSC_INPUT || var_type == SSC_INOUT) { |
| 667 | int existing_type = ssc_data_query(p_data, ssc_info_name(p_inf)); |
| 668 | if (existing_type != ssc_data_type) { |
| 669 | if (VarValue* vv = Values(i).Get(name)) { |
| 670 | if (!VarValueToSSC(vv, p_data, name, true)) |
| 671 | wxLogStatus("Error translating data from SAM UI to SSC for " + name); |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | strcpy(json_string,ssc_data_to_json(p_data)); |
| 678 | |
| 679 | } |
| 680 | |
| 681 | rapidjson::Document doc; |
| 682 | doc.Parse(json_string); |
| 683 | |
| 684 | rapidjson::StringBuffer os; |
| 685 | rapidjson::PrettyWriter<rapidjson::StringBuffer, rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator, rapidjson::kWriteNanAndInfFlag> writer(os); |
| 686 | doc.Accept(writer); |
| 687 | wxFFileOutputStream out(filename); |
no test coverage detected