diff --git a/src/parallel_io.c b/src/parallel_io.c index d82fdc933526179fa9f0a09f026376b3a15219ca..cd9498612e204858af5da7f268d2c17eb7932083 100644 --- a/src/parallel_io.c +++ b/src/parallel_io.c @@ -211,9 +211,25 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile, if (temp == NULL) error("Unable to allocate memory for temporary buffer"); /* Copy particle data to temporary buffer */ - char* temp_c = temp; - for (size_t i = 0; i < N; ++i) - memcpy(&temp_c[i * copySize], props.field + i * props.partSize, copySize); + if (props.convert_part == NULL && + props.convert_gpart == NULL) { /* No conversion */ + + char* temp_c = temp; + for (size_t i = 0; i < N; ++i) + memcpy(&temp_c[i * copySize], props.field + i * props.partSize, copySize); + + } else if (props.convert_part != NULL) { /* conversion (for parts)*/ + + float* temp_f = temp; + for (size_t i = 0; i < N; ++i) + temp_f[i] = props.convert_part(&props.parts[i]); + + } else if (props.convert_gpart != NULL) { /* conversion (for gparts)*/ + + float* temp_f = temp; + for (size_t i = 0; i < N; ++i) + temp_f[i] = props.convert_gpart(&props.gparts[i]); + } /* Unit conversion if necessary */ const double factor = diff --git a/src/serial_io.c b/src/serial_io.c index 9ece59914c5a928d80a918930ee2dc983427b608..6e6a57f49b6daf653dc12486a5af0de035e924e5 100644 --- a/src/serial_io.c +++ b/src/serial_io.c @@ -298,9 +298,25 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile, if (temp == NULL) error("Unable to allocate memory for temporary buffer"); /* Copy particle data to temporary buffer */ - char* temp_c = temp; - for (size_t i = 0; i < N; ++i) - memcpy(&temp_c[i * copySize], props.field + i * props.partSize, copySize); + if (props.convert_part == NULL && + props.convert_gpart == NULL) { /* No conversion */ + + char* temp_c = temp; + for (size_t i = 0; i < N; ++i) + memcpy(&temp_c[i * copySize], props.field + i * props.partSize, copySize); + + } else if (props.convert_part != NULL) { /* conversion (for parts)*/ + + float* temp_f = temp; + for (size_t i = 0; i < N; ++i) + temp_f[i] = props.convert_part(&props.parts[i]); + + } else if (props.convert_gpart != NULL) { /* conversion (for gparts)*/ + + float* temp_f = temp; + for (size_t i = 0; i < N; ++i) + temp_f[i] = props.convert_gpart(&props.gparts[i]); + } /* Unit conversion if necessary */ const double factor = diff --git a/src/single_io.c b/src/single_io.c index bbe5d53f6b5e620dce3945e3f1590192f2edb384..b3478912c9fdf2759995875f0b30a5f3acf8a9b5 100644 --- a/src/single_io.c +++ b/src/single_io.c @@ -183,14 +183,19 @@ void writeArray(hid_t grp, char* fileName, FILE* xmfFile, /* Copy particle data to temporary buffer */ if (props.convert_part == NULL && props.convert_gpart == NULL) { /* No conversion */ + char* temp_c = temp; for (size_t i = 0; i < N; ++i) memcpy(&temp_c[i * copySize], props.field + i * props.partSize, copySize); + } else if (props.convert_part != NULL) { /* conversion (for parts)*/ + float* temp_f = temp; for (size_t i = 0; i < N; ++i) temp_f[i] = props.convert_part(&props.parts[i]); - } else if (props.convert_part != NULL) { /* conversion (for gparts)*/ + + } else if (props.convert_gpart != NULL) { /* conversion (for gparts)*/ + float* temp_f = temp; for (size_t i = 0; i < N; ++i) temp_f[i] = props.convert_gpart(&props.gparts[i]);