Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fix" M2 Mac TDFieldExporter2D problem. #254

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tdms/include/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class TDFieldExporter2D {
public:
mxArray *matlab_array = nullptr;
double **array = nullptr;
const char *folder_name = nullptr;
std::string folder_name = "";

/**
* Allocate the arrays to hold the field
Expand Down
17 changes: 10 additions & 7 deletions tdms/src/fields/td_field_exporter_2d.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include "field.h"

#include <stdexcept>
#include <string>
samcunliffe marked this conversation as resolved.
Show resolved Hide resolved

#include <spdlog/spdlog.h>

#include "matlabio.h"
using std::string;

void TDFieldExporter2D::allocate(int _nI, int _nK) {

Expand Down Expand Up @@ -37,11 +41,10 @@ void TDFieldExporter2D::export_field(SplitField &F, int stride,
i += stride;
}

char toutputfilename[512];
snprintf(toutputfilename, 512, "%s/ex_%06d.mat", folder_name, iteration);
fprintf(stderr, "time domain output: %s\n", toutputfilename);

auto toutfile = matOpen(toutputfilename, "w");
matPutVariable(toutfile, "ex_tdf", (mxArray *) matlab_array);
matClose(toutfile);
// set up and write to MATLAB file
string file_name = folder_name + "ex_" + std::to_string(iteration) + ".mat";
spdlog::debug("Writing time-domain output to: {}", file_name);
auto output_file = matOpen(file_name.c_str(), "w");
matPutVariable(output_file, "ex_tdf", (mxArray *) matlab_array);
matClose(output_file);
}
28 changes: 18 additions & 10 deletions tdms/src/simulation_manager/objects_from_infile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,29 @@ IndependentObjectsFromInfile::IndependentObjectsFromInfile(
params.z_obs = input_grid_labels.z[params.k_det_obs];
}

// Get tdfdir - check what's going on here in a second
// Get 'tdfdir' - this is the directory name to write the time-domain fields
// into. If it's an empty string, then don't write out the TD fields at all.
// Only write out every `skip_tdf` fields.
ex_td_field_exporter = TDFieldExporter2D();
if (mxIsChar(matrices_from_input_file["tdfdir"])) {
ex_td_field_exporter.folder_name =
string_in(matrices_from_input_file["tdfdir"], "tdfdir").c_str();
std::string dir = string_in(matrices_from_input_file["tdfdir"], "tdfdir");

int Ni_tdf = 0, Nk_tdf = 0;
for (int k = 0; k < IJK_tot.k; k++)
if ((k % skip_tdf) == 0) Nk_tdf++;
if (dir == "") {
spdlog::debug("Will not write out the time-domain fields.");

for (int i = 0; i < IJK_tot.i; i++)
if ((i % skip_tdf) == 0) Ni_tdf++;
spdlog::info("Ni_tdf = {0:d}, Nk_tdf = {1:d}", Ni_tdf, Nk_tdf);
} else {
ex_td_field_exporter.folder_name = dir;
spdlog::debug("Will write the time-domain fields to '{}'.",
ex_td_field_exporter.folder_name);

int Ni_tdf = 0, Nk_tdf = 0;
for (int k = 0; k < IJK_tot.k; k++)
if ((k % skip_tdf) == 0) Nk_tdf++;

for (int i = 0; i < IJK_tot.i; i++)
if ((i % skip_tdf) == 0) Ni_tdf++;
spdlog::debug("Ni_tdf = {0:d}, Nk_tdf = {1:d}", Ni_tdf, Nk_tdf);

if (!are_equal(ex_td_field_exporter.folder_name, "")) {
params.has_tdfdir = true;
ex_td_field_exporter.allocate(Ni_tdf, Nk_tdf);
}
Expand Down