Skip to content
Open
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 example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ t8_forest_construct_from_vtk (const char *prefix, sc_MPI_Comm comm, const int va
vtk_data[ivalues].data = cell_values[ivalues];
/*TODO: Arbitrary type of data */
vtk_data[ivalues].type = T8_VTK_SCALAR;
snprintf (vtk_data[ivalues].description, BUFSIZ, "cell_data_%i", ivalues);
snprintf (vtk_data[ivalues].description, T8_VTK_MAX_STRING_LENGTH, "cell_data_%i", ivalues);
}

for (t8_locidx_t itree = 0; itree < num_trees; itree++) {
Expand Down
8 changes: 4 additions & 4 deletions example/advect/t8_advection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1112,16 +1112,16 @@ t8_advect_write_vtk (t8_advect_problem_t *problem)
}

/* Write meta data for vtk */
snprintf (vtk_data[0].description, BUFSIZ, "Num. Solution");
snprintf (vtk_data[0].description, T8_VTK_MAX_STRING_LENGTH, "Num. Solution");
vtk_data[0].type = T8_VTK_SCALAR;
vtk_data[0].data = u_and_phi_array[0];
snprintf (vtk_data[1].description, BUFSIZ, "Ana. Solution");
snprintf (vtk_data[1].description, T8_VTK_MAX_STRING_LENGTH, "Ana. Solution");
vtk_data[1].type = T8_VTK_SCALAR;
vtk_data[1].data = u_and_phi_array[1];
snprintf (vtk_data[2].description, BUFSIZ, "Error");
snprintf (vtk_data[2].description, T8_VTK_MAX_STRING_LENGTH, "Error");
vtk_data[2].type = T8_VTK_SCALAR;
vtk_data[2].data = u_and_phi_array[2];
snprintf (vtk_data[3].description, BUFSIZ, "Flow");
snprintf (vtk_data[3].description, T8_VTK_MAX_STRING_LENGTH, "Flow");
vtk_data[3].type = T8_VTK_VECTOR;
vtk_data[3].data = u_and_phi_array[3];
/* Write filename */
Expand Down
2 changes: 1 addition & 1 deletion example/remove/t8_example_gauss_blob.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ t8_output_data_to_vtu (t8_forest_t forest, double *data, const char *prefix)
{
t8_vtk_data_field_t vtk_data;
vtk_data.type = T8_VTK_SCALAR;
snprintf (vtk_data.description, BUFSIZ, "Gauss");
snprintf (vtk_data.description, T8_VTK_MAX_STRING_LENGTH, "Gauss");
vtk_data.data = data;

int num_data = 1;
Expand Down
52 changes: 28 additions & 24 deletions src/t8_vtk/t8_vtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,22 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra

if (num_data > 0) {
/* Print point data for data fields */
char vtkPointDataString[BUFSIZ] = "";
char vtkPointVectorString[BUFSIZ] = "";
char description[BUFSIZ];
char vtkPointDataString[T8_VTK_MAX_STRING_LENGTH] = "";
char vtkPointVectorString[T8_VTK_MAX_STRING_LENGTH] = "";
char description[T8_VTK_MAX_STRING_LENGTH];

for (idata = 0; idata < num_data && data[idata].type == T8_VTK_SCALAR; idata++) {
sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points");
sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points");

if (sreturn >= BUFSIZ) {
if (sreturn >= T8_VTK_MAX_STRING_LENGTH) {
/* The output was truncated */
/* Note: gcc >= 7.1 prints a warning if we
* do not check the return value of snprintf. */
t8_debugf ("Warning: Truncated vtk point data description to '%s'\n", description);
}

printed += snprintf (vtkPointDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", description);
printed += snprintf (vtkPointDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s",
printed > 0 ? "," : "", description);
}
num_scalars = idata;
/* Write Vector fields in data */
Expand All @@ -94,16 +95,16 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra
for (idata = num_scalars; idata < num_data; idata++) {
SC_CHECK_ABORT (data[idata].type == T8_VTK_VECTOR, "vtk data mismatch. After scalar fields only vector"
" fields are allowed.");
sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points");
sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points");

if (sreturn >= BUFSIZ) {
if (sreturn >= T8_VTK_MAX_STRING_LENGTH) {
/* The output was truncated */
/* Note: gcc >= 7.1 prints a warning if we
* do not check the return value of snprintf. */
t8_debugf ("Warning: Truncated vtk point data description to '%s'\n", description);
}
printed
+= snprintf (vtkPointVectorString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", description);
printed += snprintf (vtkPointVectorString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s",
printed > 0 ? "," : "", description);
}
}

Expand All @@ -118,9 +119,9 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra
}
/* Write data fields */
for (idata = 0; idata < num_scalars; idata++) {
sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points");
sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points");

if (sreturn >= BUFSIZ) {
if (sreturn >= T8_VTK_MAX_STRING_LENGTH) {
/* The output was truncated */
/* Note: gcc >= 7.1 prints a warning if we
* do not check the return value of snprintf. */
Expand All @@ -136,9 +137,9 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra
/* Write vector data fields */
for (idata = num_scalars; idata < num_data; idata++) {
T8_ASSERT (data[idata].type == T8_VTK_VECTOR);
sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points");
sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points");

if (sreturn >= BUFSIZ) {
if (sreturn >= T8_VTK_MAX_STRING_LENGTH) {
/* The output was truncated */
/* Note: gcc >= 7.1 prints a warning if we
* do not check the return value of snprintf. */
Expand All @@ -157,24 +158,27 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra
/* reset counter */
printed = 0;
if (write_cell_data) {
char vtkCellDataString[BUFSIZ] = "";
char vtkCellVectorString[BUFSIZ] = "";
char vtkCellDataString[T8_VTK_MAX_STRING_LENGTH] = "";
char vtkCellVectorString[T8_VTK_MAX_STRING_LENGTH] = "";

if (write_tree) {
printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "treeid");
printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "treeid");
}
if (write_rank) {
printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", "mpirank");
printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s",
printed > 0 ? "," : "", "mpirank");
}
if (write_level) {
printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", "level");
printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s",
printed > 0 ? "," : "", "level");
}
if (write_id) {
printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", "element_id");
printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s",
printed > 0 ? "," : "", "element_id");
}
for (idata = 0; idata < num_data && data[idata].type == T8_VTK_SCALAR; idata++) {
printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "",
data[idata].description);
printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s",
printed > 0 ? "," : "", data[idata].description);
}
num_scalars = idata;
/* Write Vector fields in data */
Expand All @@ -183,8 +187,8 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra
for (idata = num_scalars; idata < num_data; idata++) {
SC_CHECK_ABORT (data[idata].type == T8_VTK_VECTOR, "vtk data mismatch. After scalar fields only vector"
" fields are allowed.");
printed += snprintf (vtkCellVectorString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "",
data[idata].description);
printed += snprintf (vtkCellVectorString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s",
printed > 0 ? "," : "", data[idata].description);
}
}
if (strcmp (vtkCellDataString, "")) {
Expand Down
7 changes: 4 additions & 3 deletions src/t8_vtk/t8_vtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
#define T8_VTK_FLOAT_TYPE double
#endif

#define T8_VTK_FORMAT_STRING "ascii" /**< Format string for vtk */
#define T8_VTK_FORMAT_STRING "ascii" /**< Format string for vtk */
#define T8_VTK_MAX_STRING_LENGTH 1023 /**< Maximal string length for the description in t8_vtk_data_field_t */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a comment in the code why we choose 1023 - since its a magic number, we should have an explanation for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Embarrassing...

It had been 1024. 1K, just because I like the number, and I thought 8K (as seen on Linux) is a bit too much.

I then did a quick check to make sure I could actually retrieve the number from an external application, changed the number, and forgot to revert the change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are at it, naming is hard. Do you have other suggestions for the macro name?


#if T8_ENABLE_VTK
#define t8_vtk_locidx_array_type_t vtkTypeInt32Array /**< VTK array type for local indices */
Expand All @@ -65,8 +66,8 @@ typedef enum {
*/
typedef struct
{
t8_vtk_data_type_t type; /**< Describes of which type the data array is */
char description[BUFSIZ]; /**< String that describes the data. */
t8_vtk_data_type_t type; /**< Describes of which type the data array is */
char description[T8_VTK_MAX_STRING_LENGTH]; /**< String that describes the data. */
double *data;
/**< An array of length n*num_local_elements doubles with
n = 1 if type = T8_VTK_SCALAR, n = 3 if type = T8_VTK_VECTOR */
Expand Down
14 changes: 7 additions & 7 deletions src/t8_vtk/t8_vtk_write_ASCII.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ t8_forest_vtk_write_points (t8_forest_t forest, FILE *vtufile, const int write_g
int freturn;
int sreturn;
int idata;
char description[BUFSIZ];
char description[T8_VTK_MAX_STRING_LENGTH];

T8_ASSERT (t8_forest_is_committed (forest));
T8_ASSERT (vtufile != NULL);
Expand Down Expand Up @@ -748,23 +748,23 @@ t8_forest_vtk_write_points (t8_forest_t forest, FILE *vtufile, const int write_g
for (idata = 0; idata < num_data; idata++) {
if (data[idata].type == T8_VTK_SCALAR) {
/* Write the description string. */
sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points");
sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points");

if (sreturn >= BUFSIZ) {
if (sreturn >= T8_VTK_MAX_STRING_LENGTH) {
/* The output was truncated */
t8_debugf ("Warning: Truncated vtk point data description to '%s'\n", description);
}
freturn = t8_forest_vtk_write_cell_data (forest, vtufile, description, T8_VTK_FLOAT_NAME, "", 8,
t8_forest_vtk_vertices_scalar_kernel, write_ghosts, data[idata].data);
}
else {
char component_string[BUFSIZ];
char component_string[T8_VTK_MAX_STRING_LENGTH];
T8_ASSERT (data[idata].type == T8_VTK_VECTOR);
snprintf (component_string, BUFSIZ, "NumberOfComponents=\"3\"");
snprintf (component_string, T8_VTK_MAX_STRING_LENGTH, "NumberOfComponents=\"3\"");
/* Write the description string. */
sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points");
sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points");

if (sreturn >= BUFSIZ) {
if (sreturn >= T8_VTK_MAX_STRING_LENGTH) {
/* The output was truncated */
/* Note: gcc >= 7.1 prints a warning if we
* do not check the return value of snprintf. */
Expand Down
4 changes: 2 additions & 2 deletions test/t8_IO/t8_gtest_vtk_writer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ struct vtk_writer_test: public testing::Test

// Fill the vtk_data descriptors
vtk_data[0].type = T8_VTK_SCALAR;
strncpy (vtk_data[0].description, "Testdata scalar i/10.", BUFSIZ);
strncpy (vtk_data[0].description, "Testdata scalar i/10.", T8_VTK_MAX_STRING_LENGTH);
vtk_data[0].data = scalar_data.data ();
vtk_data[1].type = T8_VTK_VECTOR;
strncpy (vtk_data[1].description, "Testdata vector (i/10.,-i/10.,42)", BUFSIZ);
strncpy (vtk_data[1].description, "Testdata vector (i/10.,-i/10.,42)", T8_VTK_MAX_STRING_LENGTH);
vtk_data[1].data = vector_data.data ();

writer = new vtk_writer<grid_t> (true, true, true, true, true, true, std::string ("test_vtk_writer"), num_vtk_data,
Expand Down
Loading