aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2002-11-06 19:35:26 +0000
committertradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2002-11-06 19:35:26 +0000
commite6c537f1f59d2af6e1c5ee32cddaf1ae195af3cd (patch)
tree9e346bbdcd9d1f65abc7e4940d385bee1dd3f8f6 /src
parent91c7d0746bc28d7d3ea99eb0ef34378197ba53fd (diff)
2D IOFlexIO output routines were still using the old hyperslab API.
Now they are using the "Hyperslab_*" function aliases. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOFlexIO/trunk@266 ebee0441-1374-4afa-a3b5-247f3ba15b9a
Diffstat (limited to 'src')
-rw-r--r--src/Write2D.c144
1 files changed, 93 insertions, 51 deletions
diff --git a/src/Write2D.c b/src/Write2D.c
index 51416b7..8c393d1 100644
--- a/src/Write2D.c
+++ b/src/Write2D.c
@@ -27,7 +27,6 @@
#include "cctk.h"
#include "cctk_Parameters.h"
-#include "Hyperslab.h"
#include "CactusBase/IOUtil/src/ioGH.h"
#include "ioFlexGH.h"
@@ -78,6 +77,11 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias)
CCTK_REAL min_ext[3], max_ext[3]; /* bounding box information */
CCTK_REAL min_ext_attr[2], max_ext_attr[2], delta_attr[2];
IOFile *IEEEfile_2D; /* file descriptors */
+ int total_hsize, mapping, dir_i, dir_j, retval;
+ int extent_int[3], extent_flexio[2];
+ CCTK_INT origin[3], extent[2], direction[6], hsize[2];
+ void *data;
+ char *fullname;
/* to make the compiler happy */
@@ -86,13 +90,11 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias)
/* get the variable group indormation */
groupindex = CCTK_GroupIndexFromVarI (vindex);
CCTK_GroupData (groupindex, &groupinfo);
+ fullname = CCTK_FullName (vindex);
/* check if variable has storage assigned */
if (! CCTK_QueryGroupStorageI (GH, groupindex))
{
- char *fullname = CCTK_FullName (vindex);
-
-
CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
"No IOFlexIO 2D output for '%s' (no storage)", fullname);
free (fullname);
@@ -145,7 +147,7 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias)
{
int len;
char buffer[128];
- const char *extensions[3] = {"yz", "xz", "xy"};
+ const char *extensions[3] = {"xy", "xz", "yz"};
sprintf (fname, "%s/%s_2d_%s%s.ieee", myGH->out2D_dir, alias,
@@ -225,21 +227,16 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias)
CCTK_CoordRange (GH, &min_ext[1], &max_ext[1], -1, "y", "cart3d");
CCTK_CoordRange (GH, &min_ext[2], &max_ext[2], -1, "z", "cart3d");
+ /* get the extents of the variable */
+ CCTK_GroupgshVI (GH, 3, extent_int, vindex);
+
/* loop over all 3 planes */
for (dir = 0; dir < 3; dir++)
{
- int dir_i, dir_j;
- int directions[3], origin[3];
- const int lengths[2] = {-1, -1};
- const int downsamples[2] = {1, 1};
- int data_hsizes[2];
- void *data;
-
-
/* get the directions to span the hyperslab */
if (dir == 0)
{
- dir_i = 1; dir_j = 2; /* yz */
+ dir_i = 0; dir_j = 1; /* xy */
}
else if (dir == 1)
{
@@ -247,59 +244,104 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias)
}
else
{
- dir_i = 0; dir_j = 1; /* xy */
+ dir_i = 1; dir_j = 2; /* yz */
}
- /* set the origin using the slice center from IOUtil */
- memset (origin, 0, GH->cctk_dim * sizeof (int));
- origin[dir] = myGH->sp2xyz[groupinfo.dim-1][dir];
+ /* set the extent vector */
+ extent[0] = extent_int[dir_i];
+ extent[1] = extent_int[dir_j];
+ extent_flexio[0] = extent_int[dir_i];
+ extent_flexio[1] = extent_int[dir_j];
- /* set the directions vector */
- memset (directions, 0, sizeof (directions));
- directions[dir] = 1;
+ /* set the origin using the slice center from IOUtil */
+ memset (origin, 0, sizeof (origin));
+ origin[3-dir-1] = myGH->sp2xyz[2][dir];
+
+ /* set the direction vector */
+ memset (direction, 0, sizeof (direction));
+ direction[dir_i] = direction[3 + dir_j] = 1;
+
+ mapping = Hyperslab_DefineGlobalMappingByIndex (GH, vindex, 2,
+ direction,
+ origin,
+ extent,
+ NULL, /* downsample */
+ -1, /* table handle */
+ NULL /* conversion fn */,
+ hsize);
+ if (mapping < 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOFlexIO_Write2D: Failed to define hyperslab mapping for "
+ "variable '%s'", fullname);
+ continue;
+ }
+ total_hsize = hsize[0] * hsize[1];
+ if (total_hsize <= 0)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOFlexIO_Write2D: selected hyperslab has zero size for "
+ "variable '%s' direction %d", fullname, dir);
+ Hyperslab_FreeMapping (mapping);
+ continue;
+ }
- /* get the variable slice */
- if (Hyperslab_GetHyperslab (GH, 0, vindex, 0, 2, origin, directions,
- lengths, downsamples, &data, data_hsizes) < 0)
+ /* allocate hyperslab buffers */
+ if (myproc == 0)
+ {
+ data = malloc (total_hsize * CCTK_VarTypeSize (groupinfo.vartype));
+ }
+ else
{
- char *fullname = CCTK_FullName (vindex);
+ data = NULL;
+ }
+ /* get the variable slice */
+ retval = Hyperslab_Get (GH, mapping, 0, vindex, 0, -1, data);
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Failed to extract 2D hyperslab for variable '%s'", fullname);
- free (fullname);
- return (-4);
- }
+ /* release the mapping structure */
+ Hyperslab_FreeMapping (mapping);
/* processor 0 write the hyperslab data */
if (myproc == 0)
{
- /* the data itself */
- FLEXIO_ERROR (IOwrite (IEEEfile_2D[dir],
- ioflex_type, 2, data_hsizes, data));
- free (data);
+ if (retval >= 0)
+ {
+ /* the data itself */
+ FLEXIO_ERROR (IOwrite (IEEEfile_2D[dir],
+ ioflex_type, 2, extent_flexio, data));
+
+ /* Time, space, and coordinate attributes */
+ min_ext_attr[0] = min_ext[dir_i];
+ min_ext_attr[1] = min_ext[dir_j];
+ max_ext_attr[0] = max_ext[dir_i];
+ max_ext_attr[1] = max_ext[dir_j];
+ delta_attr[0] = GH->cctk_delta_space[dir_i];
+ delta_attr[1] = GH->cctk_delta_space[dir_j];
+ FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "time",
+ FLEXIO_REAL, 1, &GH->cctk_time));
+ FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "origin",
+ FLEXIO_REAL, 2, min_ext_attr));
+ FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "min_ext",
+ FLEXIO_REAL, 2, min_ext_attr));
+ FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "max_ext",
+ FLEXIO_REAL, 2, max_ext_attr));
+ FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "delta",
+ FLEXIO_REAL, 2, delta_attr));
+ }
+ else
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Failed to extract 2D hyperslab for variable '%s'", fullname);
+ }
- /* Time, space, and coordinate attributes */
- min_ext_attr[0] = min_ext[dir_i];
- min_ext_attr[1] = min_ext[dir_j];
- max_ext_attr[0] = max_ext[dir_i];
- max_ext_attr[1] = max_ext[dir_j];
- delta_attr[0] = GH->cctk_delta_space[dir_i];
- delta_attr[1] = GH->cctk_delta_space[dir_j];
- FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "time",
- FLEXIO_REAL, 1, &GH->cctk_time));
- FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "origin",
- FLEXIO_REAL, 2, min_ext_attr));
- FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "min_ext",
- FLEXIO_REAL, 2, min_ext_attr));
- FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "max_ext",
- FLEXIO_REAL, 2, max_ext_attr));
- FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "delta",
- FLEXIO_REAL, 2, delta_attr));
+ free (data);
}
} /* end of loop over all 3 planes */
+ free (fullname);
+
if (reuse_filehandles && myproc == 0)
{
/* pause the files (close system descriptors) */