MCPcopy Create free account
hub / github.com/NatLabRockies/SAM / SaveToCSV

Method SaveToCSV

src/parametric.cpp:1445–1504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1443}
1444
1445void ParametricViewer::SaveToCSV()
1446{
1447 wxFileDialog fdlg(this, "Save as CSV", wxEmptyString, "results.csv", "Comma-separated values (*.csv)|*.csv", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
1448 if (fdlg.ShowModal() != wxID_OK) return;
1449
1450
1451 std::ofstream fp(fdlg.GetPath().ToStdString(), std::ios::out | std::ios::binary);
1452 if (!fp.is_open())
1453 {
1454 wxMessageBox("Could not open file for write:\n\n" + fdlg.GetPath());
1455 return;
1456 }
1457
1458 wxBusyInfo busy("Writing CSV file... please wait");
1459
1460 wxString sep = ",";
1461 wxString header = "run";
1462 // e.g. run,1,2,3,...
1463 for (int run = 1; run < m_grid_data->GetNumberRows()+1; run++) {
1464 header += sep + wxString::Format("%d", run);
1465 }
1466 header += "\n";
1467 fp << header;
1468
1469 for (int col = 0; col < m_grid_data->GetNumberCols(); col++) {
1470 if (VarValue* vv = m_grid_data->GetVarValue(0, col)) {
1471 wxString title = m_grid_data->GetColLabelValue(col) + wxString::Format(" | %d | ", m_grid_data->GetNdxHybrid(0, col)) + m_grid_data->GetVarName(0, col);
1472
1473 wxString dat;
1474 if (vv->Type() == VV_STRING) {
1475// dat = '"' + m_grid_data->GetColLabelValue(col) + '"';
1476 dat = '"' + title + '"';
1477
1478 for (int row = 0; row < m_grid_data->GetNumberRows(); row++)
1479 dat += "," + m_grid_data->GetValue(row, col);
1480 dat += "\n";
1481 }
1482 else {
1483 std::vector<std::vector<double> > values_vec;
1484 wxArrayString labels;
1485 for (int row = 0; row < m_grid_data->GetNumberRows(); row++)
1486 {
1487 std::vector<double> vec = m_grid_data->GetArray(row, col);
1488 if (vec.size() == 0) // single values
1489 vec.push_back(m_grid_data->GetDouble(row, col));
1490 values_vec.push_back(vec);
1491 labels.push_back(wxString::Format("Run %d", row + 1));
1492 }
1493// ArrayPopupDialog apd(this, m_grid_data->GetColLabelValue(col).ToAscii(' '), labels, values_vec);
1494 ArrayPopupDialog apd(this, title.ToAscii(' '), labels, values_vec);
1495
1496 apd.GetParametricTextData(dat, ',');
1497 }
1498 fp << dat;
1499 }
1500 }
1501 fp.close();
1502

Callers

nothing calls this directly

Calls 13

GetNdxHybridMethod · 0.80
TypeMethod · 0.80
sizeMethod · 0.80
GetParametricTextDataMethod · 0.80
ShowModalMethod · 0.45
GetNumberRowsMethod · 0.45
GetNumberColsMethod · 0.45
GetVarValueMethod · 0.45
GetColLabelValueMethod · 0.45
GetVarNameMethod · 0.45
GetValueMethod · 0.45
GetArrayMethod · 0.45

Tested by

no test coverage detected