aboutsummaryrefslogtreecommitdiff
path: root/src/Write3D.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Write3D.c')
-rw-r--r--src/Write3D.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/Write3D.c b/src/Write3D.c
index b904a39..56fb233 100644
--- a/src/Write3D.c
+++ b/src/Write3D.c
@@ -209,6 +209,17 @@ int IOASCII_Write3D (const cGH *GH, int vindex, const char *alias)
/* Open the file on processor 0 */
file = myproc == 0 ? OpenFile (GH, fullname, alias) : NULL;
+ /* get the total number of grid points to check for zero-sized variables */
+ for (i = 0, total_hsize = 1; i < gdata.dim; i++)
+ {
+ total_hsize *= extent_int[i];
+ }
+ if (total_hsize <= 0)
+ {
+ free (fullname);
+ return (0);
+ }
+
/* set the extent vector (copy from 'int' to 'CCTK_INT' */
CCTK_GroupgshVI (GH, 3, extent_int, vindex);
for (i = 0; i < 3; i++)
@@ -227,10 +238,10 @@ int IOASCII_Write3D (const cGH *GH, int vindex, const char *alias)
{
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"IOASCII_Write3D: Failed to define hyperslab mapping for "
- "variable '%s'", fullname);
+ "variable '%s'", fullname);
free (fullname);
- return (-1);
- }
+ return (-1);
+ }
total_hsize = hsize[0] * hsize[1] * hsize[2];
if (total_hsize <= 0)
{
@@ -240,8 +251,9 @@ int IOASCII_Write3D (const cGH *GH, int vindex, const char *alias)
Hyperslab_FreeMapping (mapping);
free (fullname);
return (-1);
- }
-
+ }
+
+ hdata[0] = hdata[1] = hdata[2] = hdata[3];
if (myproc == 0)
{
/* allocate hyperslab buffers */
@@ -250,8 +262,8 @@ int IOASCII_Write3D (const cGH *GH, int vindex, const char *alias)
NULL;
hdata[2] = (CCTK_REAL *) hdata[1] + 1*total_hsize;
hdata[3] = (CCTK_REAL *) hdata[1] + 2*total_hsize;
- }
-
+ }
+
/* get the hyperslabs */
num_returned_hslabs = Hyperslab_GetList (GH, mapping, num_requested_hslabs,
NULL, vindices, NULL, NULL, hdata,
@@ -289,10 +301,7 @@ int IOASCII_Write3D (const cGH *GH, int vindex, const char *alias)
/* clean up */
free (hdata[0]);
- if (hdata[1])
- {
- free (hdata[1]);
- }
+ free (hdata[1]);
} /* end of outputting the data by processor 0 */
free (fullname);