aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668>2000-11-20 22:36:59 +0000
committertradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668>2000-11-20 22:36:59 +0000
commit15aa30b0defde6a7a28807759d399446abcbf581 (patch)
tree3351cb00683f8bb299f851a653c3a45113f5e6fc
parentb9830ecc1055b7ea9ac6e7301432a26a1d550541 (diff)
Some cleanup before moving the type conversion code into thorn Hyperslab.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5Util/trunk@8 7842ec3a-9562-4be5-9c5b-06ba18f2b668
-rw-r--r--src/DumpVar.c160
1 files changed, 84 insertions, 76 deletions
diff --git a/src/DumpVar.c b/src/DumpVar.c
index 126232f..b12b5d4 100644
--- a/src/DumpVar.c
+++ b/src/DumpVar.c
@@ -537,7 +537,7 @@ static int IOHDF5Util_getDumpData (cGH *GH,
pGExtras *extras=NULL;
CCTK_REAL4 *single_ptr;
int myproc, do_downsample;
- int idim, sdim, vdim; /*iteration, slab dim, variable dim */
+ int i, sdim, vdim; /*iteration, slab dim, variable dim */
int *hsizes,*hsizes_global,*hsizes_offset; /* geometry information */
int sdir[3]; /* slab direction FIXME */
int locdowns[3]; /* Holds the downsampling in the order
@@ -545,6 +545,7 @@ static int IOHDF5Util_getDumpData (cGH *GH,
int slabstart[3]; /* global start index for slab to extract */
int ip;
void *data;
+ char *fullname;
myproc = CCTK_MyProc (GH);
@@ -560,19 +561,20 @@ static int IOHDF5Util_getDumpData (cGH *GH,
vdim = slab->vdim;
sdim = slab->sdim;
+ /* FIXME */
if (vdim>3)
{
CCTK_WARN(1,"Cannot treat GFs with dim>3, check with cactus support\n");
- return(-1);
+ return (-1);
}
- for (idim=0;idim<sdim;idim++)
- locdowns[idim]=slab->downsample[slab->direction[idim]];
+ for (i=0;i<sdim;i++)
+ locdowns[i]=slab->downsample[slab->direction[i]];
/* Set downsample flag */
do_downsample = 0;
- for (idim = 0; idim < sdim; idim++)
- do_downsample |= locdowns[idim] > 1;
+ for (i = 0; i < sdim; i++)
+ do_downsample |= locdowns[i] > 1;
/* Simple case if no downsampling and sdim==vdim */
if (! do_downsample && sdim==vdim)
@@ -591,117 +593,119 @@ static int IOHDF5Util_getDumpData (cGH *GH,
*free_outme = 0;
}
- for (idim = 0; idim < sdim; idim++) {
- geom[idim + 0*sdim] = extras->lb[myproc][idim];
- geom[idim + 1*sdim] = extras->lnsize[idim];
- geom[idim + 2*sdim] = extras->nsize[idim];
+ for (i = 0; i < sdim; i++) {
+ geom[i + 0*sdim] = extras->lb[myproc][i];
+ geom[i + 1*sdim] = extras->lnsize[i];
+ geom[i + 2*sdim] = extras->nsize[i];
}
}
else /* Call Hyperslab else */
{
/* allocate array to hold size information of slab */
- hsizes = (int*)malloc(sdim*sizeof(int));
- hsizes_global= (int*)malloc(sdim*sizeof(int));
- hsizes_offset= (int*)malloc(sdim*sizeof(int));
-
- for (idim=0;idim<sdim;idim++)
- {
- hsizes[idim]=0;
- hsizes_global[idim]=0;
- hsizes_offset[idim]=0;
- }
+ hsizes = (int *) malloc (3 * sdim * sizeof (int));
+ hsizes_global = hsizes + 1*sdim;
+ hsizes_offset = hsizes + 2*sdim;
/* TEMPORARY FIX DUE TO INCONSISTENT DIR SPECIFICATION */
/* direction vector of 1d line in 3d volume */
- if (sdim==1) {
- sdir[0] = (slab->direction[0]==0) ? 1:0;
- sdir[1] = (slab->direction[0]==1) ? 1:0;
- sdir[2] = (slab->direction[0]==2) ? 1:0;
+ if (sdim == 1)
+ {
+ sdir[0] = slab->direction[0] == 0;
+ sdir[1] = slab->direction[0] == 1;
+ sdir[2] = slab->direction[0] == 2;
}
/* norm vector of 2d surface in 3d volume */
else if (sdim==2)
- {
- sdir[0] = ((slab->direction[0]==1)&&(slab->direction[1]==2)) ? 1:0;
- sdir[1] = ((slab->direction[0]==0)&&(slab->direction[1]==2)) ? 1:0;
- sdir[2] = ((slab->direction[0]==0)&&(slab->direction[1]==1)) ? 1:0;
- }
+ {
+ sdir[0] = slab->direction[0] == 1 && slab->direction[1] == 2;
+ sdir[1] = slab->direction[0] == 0 && slab->direction[1] == 2;
+ sdir[2] = slab->direction[0] == 0 && slab->direction[1] == 1;
+ }
/* spanning directions for 3d */
else if (sdim==3)
- {
- sdir[0] = slab->direction[0];
- sdir[1] = slab->direction[1];
- sdir[2] = slab->direction[2];
- }
+ {
+ sdir[0] = slab->direction[0];
+ sdir[1] = slab->direction[1];
+ sdir[2] = slab->direction[2];
+ }
/* Get the start indeces for the slab from origin. */
- /* Slab_start from the geo structure is not a true start index, it is currently
- used as the intersection point of three surfaces , that's why two entries
- have to be set to zero in the case of a surface (one entry for line) FIXME */
- for (idim=0;idim<vdim;idim++)
- slabstart[idim] = slab->origin[idim];
- for (idim=0;idim<sdim;idim++)
- slabstart[slab->direction[idim]]=0;
-
+ /* Slab_start from the geo structure is not a true start index,
+ it is currently used as the intersection point of three surfaces,
+ that's why two entries have to be set to zero in the case of a
+ surface (one entry for line)
+ FIXME */
+ for (i = 0; i < vdim; i++)
+ {
+ slabstart[i] = slab->origin[i];
+ }
+ for (i = 0; i < sdim; i++)
+ {
+ slabstart[slab->direction[i]] = 0;
+ }
if (Hyperslab_GetLocalHyperslab (GH, index, timelevel, sdim, slab->origin,
sdir, slab->length, locdowns, outme,
- hsizes, hsizes_global, hsizes_offset)< 0) {
- char *fullname = CCTK_FullName (index);
+ hsizes, hsizes_global, hsizes_offset) < 0)
+ {
+ fullname = CCTK_FullName (index);
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Failed to extract hyperslab for variable '%s'", fullname);
- free (fullname);
+ free (fullname);
*free_outme = 0;
- return(-1);
-
+ return (-1);
}
-
+
*free_outme = 1;
- for (idim = 0; idim < sdim; idim++) {
- geom[idim + 0*sdim] = hsizes_offset[idim];
- geom[idim + 1*sdim] = hsizes[idim];
- geom[idim + 2*sdim] = hsizes_global[idim];
- slab->actlen[idim]= hsizes_global[idim];
+ for (i = 0; i < sdim; i++)
+ {
+ geom[i + 0*sdim] = hsizes_offset[i];
+ geom[i + 1*sdim] = hsizes[i];
+ geom[i + 2*sdim] = hsizes_global[i];
+ slab->actlen[i] = hsizes_global[i];
}
+
+ free (hsizes);
}
#ifdef DEBUG_ME
printf ("***** %dD \n",sdim);
printf ("Lower bound: %d", (int) geom[0]);
- for (idim = 1; idim < sdim; idim++)
- printf (" %d", (int) geom[idim]);
+ for (i = 1; i < sdim; i++)
+ printf (" %d", (int) geom[i]);
printf ("\n");
printf ("Chunk size : %d", (int) geom[1*sdim + 0]);
- for (idim = 1; idim < sdim; idim++)
- printf (" %d", (int) geom[1*sdim + idim]);
+ for (i = 1; i < sdim; i++)
+ printf (" %d", (int) geom[1*sdim + i]);
printf ("\n");
printf ("Global size: %d", (int) geom[2*sdim + 0]);
- for (idim = 1; idim < sdim; idim++)
- printf (" %d", (int) geom[2*sdim + idim]);
+ for (i = 1; i < sdim; i++)
+ printf (" %d", (int) geom[2*sdim + i]);
printf ("\n");
printf ("Downsampling: ");
- for (idim = 0; idim < sdim; idim++)
- printf (" %d", locdowns[idim]);
+ for (i = 0; i < sdim; i++)
+ printf (" %d", locdowns[i]);
printf ("\n");
printf ("Direction: ");
- for (idim = 0; idim < sdim; idim++)
- printf (" %d",slab->direction[idim]);
+ for (i = 0; i < sdim; i++)
+ printf (" %d",slab->direction[i]);
printf ("\n");
printf ("Slab Start: %d", (int) slabstart[0]);
- for (idim = 1; idim < vdim; idim++)
- printf (" %d", (int) slabstart[idim]);
+ for (i = 1; i < vdim; i++)
+ printf (" %d", (int) slabstart[i]);
printf ("\n");
printf ("Slab intersect cntr: %d", (int) slab->origin[0]);
- for (idim = 1; idim < vdim; idim++)
- printf (" %d", (int) slab->origin[idim]);
+ for (i = 1; i < vdim; i++)
+ printf (" %d", (int) slab->origin[i]);
printf ("\n");
printf ("SlabDelta: ");
- for (idim = 0; idim < sdim; idim++)
- printf (" %f",GH->cctk_delta_space[slab->direction[idim]]*locdowns[idim]);
+ for (i = 0; i < sdim; i++)
+ printf (" %f",GH->cctk_delta_space[slab->direction[i]]*locdowns[i]);
printf ("\n");
#endif
- return(1);
+ return (0);
}
@@ -973,7 +977,7 @@ static void IOHDF5Util_collectiveDump (cGH *GH,
int i, dim;
ioHDF5GH *myGH;
hid_t dataset, memspace, filespace, xfer_plist;
- char *name, datasetname[128];
+ char *fullname, *datasetname;
hssize_t *chunk_origin;
hsize_t *chunk_dims, *file_dims;
hsize_t buffersize;
@@ -997,9 +1001,10 @@ static void IOHDF5Util_collectiveDump (cGH *GH,
}
/* build the unique dataset name */
- name = CCTK_FullName (index);
- sprintf (datasetname, "%s@%d@%d", name, GH->cctk_iteration, timelevel);
- free (name);
+ fullname = CCTK_FullName (index);
+ datasetname = (char *) malloc (strlen (fullname) + 80);
+ sprintf (datasetname, "%s timelevel %d at iteration %d",
+ fullname, timelevel, GH->cctk_iteration);
/* create the memspace according to chunk dims */
IOHDF5_ERROR (memspace = H5Screate_simple (sdim, chunk_dims, NULL));
@@ -1019,8 +1024,8 @@ static void IOHDF5Util_collectiveDump (cGH *GH,
H5Gunlink (file, datasetname);
IOHDF5_ERROR (H5Eset_auto (myGH->print_error_fn, myGH->print_error_fn_arg));
}
- IOHDF5_ERROR (dataset = H5Dcreate (file, datasetname,
- hdf5io_type, filespace, H5P_DEFAULT));
+ IOHDF5_ERROR (dataset = H5Dcreate (file, datasetname, hdf5io_type, filespace,
+ H5P_DEFAULT));
if (CCTK_MyProc (GH) == 0)
{
IOHDF5Util_DumpCommonAttributes (GH, index, timelevel, &geom[2*sdim],
@@ -1045,6 +1050,9 @@ static void IOHDF5Util_collectiveDump (cGH *GH,
IOHDF5_ERROR (H5Dclose (dataset));
IOHDF5_ERROR (H5Sclose (memspace));
+ /* free allocated resources */
+ free (datasetname);
+ free (fullname);
free (chunk_origin);
free (chunk_dims);
}