diff options
Diffstat (limited to 'src/Write2D.c')
-rw-r--r-- | src/Write2D.c | 98 |
1 files changed, 37 insertions, 61 deletions
diff --git a/src/Write2D.c b/src/Write2D.c index 551e0c8..2906c79 100644 --- a/src/Write2D.c +++ b/src/Write2D.c @@ -43,7 +43,7 @@ static char **OpenFile (const cGH *GH, @enddesc @calls Hyperslab_GlobalMappingByIndex Hyperslab_FreeMapping - Hyperslab_GetList + Hyperslab_Get OpenFile WriteData @@ -75,21 +75,19 @@ static char **OpenFile (const cGH *GH, int IOSDF_Write2D (const cGH *GH, int vindex, const char *alias) { ioSDFGH *myGH; - int i, total_hsize, num_requested_hslabs, num_returned_hslabs; + int i, total_hsize; int dir, dir_i, dir_j, maxdir, myproc, gindex, have_coords; int mapping; cGroup gdata; - int coord_index[3]; CCTK_INT coord_system_handle, coord_handles[3]; char *fullname, *groupname; - int extent_int[3]; - double offset[2]; - CCTK_INT vindices[3], origin[3], extent[2], direction[6], downsample[2], - hsize[2]; - double *hdata[3]; + int full_extent[3], slice_extent[2]; + double bbox[2*2]; + CCTK_INT origin[3], extent[2], direction[6], downsample[2], hsize[2]; + CCTK_REAL minext[2], delta[2]; + double *hdata; char **filenames; const double dtime = GH->cctk_time; - const char *coordnames[] = {"x|y", "x|z", "y|z"}; DECLARE_CCTK_PARAMETERS @@ -124,17 +122,6 @@ int IOSDF_Write2D (const cGH *GH, int vindex, const char *alias) have_coords = coord_system_handle >= 0 && Util_TableGetIntArray (coord_system_handle, dir, coord_handles, "COORDINATES") >= 0; - if (have_coords) - { - /* get the coordinate functions and coordinate physical minimum */ - for (i = 0; i < dir; i++) - { - coord_index[i] = -1; - Util_TableGetInt (coord_handles[i], &coord_index[i], "GAINDEX"); - have_coords &= coord_index[i] >= 0; - } - } - num_requested_hslabs = have_coords ? 3 : 1; /* processor 0 opens the files on the first trip through */ filenames = NULL; @@ -145,12 +132,12 @@ int IOSDF_Write2D (const cGH *GH, int vindex, const char *alias) } /* get the extents of the variable */ - CCTK_GroupgshVI (GH, gdata.dim, extent_int, vindex); + CCTK_GroupgshVI (GH, gdata.dim, full_extent, 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]; + hsize[0] *= full_extent[dir]; } /* now do the actual I/O looping over all directions */ @@ -179,8 +166,8 @@ int IOSDF_Write2D (const cGH *GH, int vindex, const char *alias) } /* set the extent vector */ - extent[0] = extent_int[dir_i]; - extent[1] = extent_int[dir_j]; + extent[0] = full_extent[dir_i]; + extent[1] = full_extent[dir_j]; /* set the origin using the slice center from IOUtil */ memset (origin, 0, sizeof (origin)); @@ -216,22 +203,30 @@ int IOSDF_Write2D (const cGH *GH, int vindex, const char *alias) continue; } - hdata[0] = hdata[1] = hdata[2]; - if (myproc == 0) + /* get the bounding box information */ + bbox[0] = bbox[2] = -1; + bbox[1] = bbox[3] = +1; + if (have_coords) { - /* allocate hyperslab buffers */ - hdata[0] = malloc (total_hsize * sizeof (double)); - hdata[1] = have_coords ? malloc (2 * total_hsize * sizeof(double)) : NULL; - hdata[2] = hdata[1] + total_hsize; + Util_TableGetReal (coord_handles[dir_i], &minext[0], "COMPMIN"); + Util_TableGetReal (coord_handles[dir_i], &delta[0], "DELTA"); + Util_TableGetReal (coord_handles[dir_j], &minext[1], "COMPMIN"); + Util_TableGetReal (coord_handles[dir_j], &delta[1], "DELTA"); + + delta[0] *= downsample[0]; + delta[1] *= downsample[1]; + bbox[0] = minext[0]; + bbox[1] = bbox[0] + delta[0]*(hsize[0]-1); + bbox[2] = minext[1]; + bbox[3] = bbox[2] + delta[1]*(hsize[1]-1); } + gft_out_set_bbox (bbox, 2); - /* get the hyperslabs */ - vindices[0] = vindex; - vindices[1] = coord_index[dir_i]; - vindices[2] = coord_index[dir_j]; - num_returned_hslabs = Hyperslab_GetList (GH, mapping, num_requested_hslabs, - NULL, vindices, NULL, NULL, - (void **) hdata, NULL); + /* allocate hyperslab buffer */ + hdata = myproc == 0 ? malloc (total_hsize * sizeof (double)) : NULL; + + /* get the hyperslab */ + i = Hyperslab_Get (GH, mapping, 0, vindex, 0, gdata.vartype, hdata); /* release the mapping structure */ Hyperslab_FreeMapping (mapping); @@ -239,30 +234,12 @@ int IOSDF_Write2D (const cGH *GH, int vindex, const char *alias) /* and dump the data to file */ if (filenames) { - if (num_returned_hslabs == num_requested_hslabs) + if (i == 0) { - if (have_coords) - { - /* get the staggering offset for the coordinates */ - offset[0] = 0.5 * GH->cctk_delta_space[dir_i] * - CCTK_StaggerDirIndex (dir_i, gdata.stagtype); - offset[1] = 0.5 * GH->cctk_delta_space[dir_j] * - CCTK_StaggerDirIndex (dir_j, gdata.stagtype); - for (i = 0; i < total_hsize; i++) - { - hdata[1][i] += offset[0]; - hdata[2][i] += offset[1]; - } - } - - extent[0] = hsize[0]; - extent[1] = hsize[1]; + slice_extent[0] = hsize[0]; + slice_extent[1] = hsize[1]; - i = have_coords ? gft_out_full (filenames[dir], dtime, extent_int, - coordnames[dir], 2, hdata[1], hdata[0]): - gft_out_brief (filenames[dir], dtime, extent_int, - 2, hdata[0]); - if (i <= 0) + if (gft_out_brief (filenames[dir], dtime, slice_extent, 2, hdata) <= 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Error writing to 2D IOSDF output file '%s'", @@ -277,8 +254,7 @@ int IOSDF_Write2D (const cGH *GH, int vindex, const char *alias) } /* clean up */ - free (hdata[0]); - free (hdata[1]); + free (hdata); } /* end of outputting the data by processor 0 */ |