aboutsummaryrefslogtreecommitdiff
path: root/src/Write2D.c
diff options
context:
space:
mode:
authortradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350>2004-06-04 12:19:47 +0000
committertradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350>2004-06-04 12:19:47 +0000
commit53d1bd7d1a4fcacc8fc27a7dff7c5aef60b26da7 (patch)
tree6aee439b216c391e1640cc722fd04e3f873f6dc3 /src/Write2D.c
parent3d2b4e80fee7da7264a227741dd24979fd10487f (diff)
Don't hyperslab/output zero-sized grid variables.
Finally closes PR CactusPUGH/1243: "Segmentation fault in PUGHSlab". git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOASCII/trunk@177 94b1c47f-dcfd-45ef-a468-0854c0e9e350
Diffstat (limited to 'src/Write2D.c')
-rw-r--r--src/Write2D.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/Write2D.c b/src/Write2D.c
index 66e25f3..4c7db4d 100644
--- a/src/Write2D.c
+++ b/src/Write2D.c
@@ -219,23 +219,31 @@ int IOASCII_Write2D (const cGH *GH, int vindex, const char *alias)
sprintf (format[2], "\t\t%%%s", out_format);
/* processor 0 opens the files on the first trip through */
+ fileset = NULL;
myproc = CCTK_MyProc (GH);
if (myproc == 0)
{
fileset = OpenFile (GH, fullname, alias, gdata.dim,
have_coords ? coord_lower : NULL, maxdir);
}
- else
- {
- fileset = NULL;
- }
/* get the extents of the variable */
CCTK_GroupgshVI (GH, gdata.dim, extent_int, vindex);
+ /* get the total number of grid points to check for zero-sized variables */
+ for (dir = 0, hsize[0] = 1; dir < gdata.dim; dir++)
+ {
+ hsize[0] *= extent_int[dir];
+ }
+
/* now do the actual I/O looping over all directions */
for (dir = 0; dir < maxdir; dir++)
{
+ if (hsize[0] <= 0)
+ {
+ continue;
+ }
+
/* get the directions to span the hyperslab */
if (dir == 0)
{
@@ -288,6 +296,7 @@ int IOASCII_Write2D (const cGH *GH, int vindex, const char *alias)
continue;
}
+ hdata[0] = hdata[1] = hdata[2];
if (myproc == 0)
{
/* allocate hyperslab buffers */
@@ -309,7 +318,7 @@ int IOASCII_Write2D (const cGH *GH, int vindex, const char *alias)
Hyperslab_FreeMapping (mapping);
/* and dump the data to file */
- if (myproc == 0 && fileset)
+ if (fileset)
{
if (num_returned_hslabs == num_requested_hslabs)
{
@@ -338,10 +347,7 @@ int IOASCII_Write2D (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 */