diff options
Diffstat (limited to 'src/Write3D.c')
-rw-r--r-- | src/Write3D.c | 101 |
1 files changed, 39 insertions, 62 deletions
diff --git a/src/Write3D.c b/src/Write3D.c index f07ef55..314146b 100644 --- a/src/Write3D.c +++ b/src/Write3D.c @@ -38,7 +38,7 @@ static char *OpenFile (const cGH *GH, const char *fullname, const char *alias); @enddesc @calls Hyperslab_GlobalMappingByIndex Hyperslab_FreeMapping - Hyperslab_GetList + Hyperslab_Get OpenFile @var GH @@ -69,16 +69,16 @@ static char *OpenFile (const cGH *GH, const char *fullname, const char *alias); int IOSDF_Write3D (const cGH *GH, int vindex, const char *alias) { int i, total_hsize; - int myproc, gindex, have_coords; - int num_requested_hslabs, num_returned_hslabs; + int myproc, gindex; cGroup gdata; CCTK_INT coord_system_handle, coord_handles[3]; char *fullname, *groupname, *filename; - double *hdata[4]; + double *hdata; int extent_int[3]; - double offset[3]; int mapping; - CCTK_INT vindices[4], extent[3], downsample[3], hsize[3]; + CCTK_INT extent[3], downsample[3], hsize[3]; + double bbox_dbl[2*3]; + CCTK_REAL bbox[2*3], delta[3]; const double dtime = GH->cctk_time; const CCTK_INT origin[] = {0, 0, 0}, direction[] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; @@ -100,32 +100,10 @@ int IOSDF_Write3D (const cGH *GH, int vindex, const char *alias) } /* get the coordinate system associated with this grid variable */ - vindices[0] = vindex; groupname = CCTK_GroupName (gindex); coord_system_handle = Coord_GroupSystem (GH, groupname); free (groupname); - have_coords = coord_system_handle >= 0 && - Util_TableGetIntArray (coord_system_handle, 3, - coord_handles, "COORDINATES") >= 0; - if (have_coords) - { - /* get the coordinate functions and coordinate physical minimum */ - for (i = 1; i <= 3; i++) - { - vindices[i] = -1; - Util_TableGetInt (coord_handles[i-1], &vindices[i], "GAINDEX"); - have_coords &= vindices[i] >= 0; - } - } - num_requested_hslabs = have_coords ? 4 : 1; - - /* What processor are we on? */ - myproc = CCTK_MyProc (GH); - - /* Open the file on processor 0 */ - filename = myproc == 0 ? OpenFile (GH, fullname, alias) : NULL; - /* get the total number of grid points to check for zero-sized variables */ /* set the extent vector (copy from 'int' to 'CCTK_INT') */ CCTK_GroupgshVI (GH, 3, extent_int, vindex); @@ -144,6 +122,12 @@ int IOSDF_Write3D (const cGH *GH, int vindex, const char *alias) downsample[1] = out_downsample_y; downsample[2] = out_downsample_z; + /* What processor are we on? */ + myproc = CCTK_MyProc (GH); + + /* Open the file on processor 0 */ + filename = myproc == 0 ? OpenFile (GH, fullname, alias) : NULL; + /* get the hyperslab mapping */ mapping = Hyperslab_GlobalMappingByIndex (GH, vindex, 3, direction, origin, extent, @@ -174,46 +158,40 @@ int IOSDF_Write3D (const cGH *GH, int vindex, const char *alias) return (-1); } - hdata[0] = hdata[1] = hdata[2] = hdata[3]; - if (myproc == 0) + /* get the bounding box information */ + for (i = 0; i < 3; i++) { - /* allocate hyperslab buffers */ - hdata[0] = malloc (total_hsize * sizeof (double)); - hdata[1] = have_coords ? malloc (3 * total_hsize * sizeof (double)) : NULL; - hdata[2] = hdata[1] + 1*total_hsize; - hdata[3] = hdata[1] + 2*total_hsize; + bbox_dbl[2*i + 0] = -1; + bbox_dbl[2*i + 1] = +1; } + if (coord_system_handle >= 0 && + Util_TableGetIntArray (coord_system_handle, 3, coord_handles, + "COORDINATES") >= 0) + { + for (i = 0; i < 3; i++) + { + Util_TableGetReal (coord_handles[i], &bbox[2*i + 0], "COMPMIN"); + Util_TableGetReal (coord_handles[i], &delta[i], "DELTA"); + + delta[i] *= downsample[i]; + bbox_dbl[2*i + 0] = bbox[2*i + 0]; + bbox_dbl[2*i + 1] = bbox_dbl[2*i + 0] + delta[i]*(hsize[i]-1); + } + } + gft_out_set_bbox (bbox_dbl, 3); + + /* allocate hyperslab buffer */ + hdata = myproc == 0 ? malloc (total_hsize * sizeof (double)) : NULL; - /* get the hyperslabs */ - num_returned_hslabs = Hyperslab_GetList (GH, mapping, num_requested_hslabs, - NULL, vindices, NULL, NULL, - (void **) hdata, NULL); + /* get the hyperslab */ + i = Hyperslab_Get (GH, mapping, 0, vindex, 0, gdata.vartype, hdata); /* And dump the data to file */ if (myproc == 0) { - if (num_returned_hslabs == num_requested_hslabs) + if (i == 0) { - if (have_coords) - { - /* get the staggering offset for the coordinates */ - for (i = 0; i < 3; i++) - { - offset[i] = 0.5 * GH->cctk_delta_space[i] * - CCTK_StaggerDirIndex (i, gdata.stagtype); - } - for (i = 0; i < total_hsize; i++) - { - hdata[1][i] += offset[0]; - hdata[2][i] += offset[1]; - hdata[3][i] += offset[2]; - } - } - - i = have_coords ? gft_out_full (filename, dtime, extent_int, "x|y|z", 3, - hdata[1], hdata[0]) : - gft_out_brief (filename, dtime, extent_int, 3,hdata[0]); - if (i <= 0) + if (gft_out_brief (filename, dtime, extent_int, 3, hdata) <= 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Error writing to 3D IOSDF output file '%s'", filename); @@ -227,8 +205,7 @@ int IOSDF_Write3D (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 */ free (fullname); |