From 2d3bafd961cb671c275c99b5e2d884fe7e910480 Mon Sep 17 00:00:00 2001 From: tradke Date: Thu, 27 Mar 2003 10:47:12 +0000 Subject: Transposed order of grid points for 2D gnuplot output (CactusBase/1444), mark restart points in output files with a blank line between the last output before the abort and the first output after the restart (CactusBase/1446), removed superfluous blank line in gnuplot output files (CactusBase/1447) and fixed broken output of complex variables (PR CactusBase/1456). git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOASCII/trunk@144 94b1c47f-dcfd-45ef-a468-0854c0e9e350 --- src/Write1D.c | 46 ++++++++++++++++++++++++++++------------------ src/Write2D.c | 9 ++++----- 2 files changed, 32 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/Write1D.c b/src/Write1D.c index ddc2dbd..e65de2b 100644 --- a/src/Write1D.c +++ b/src/Write1D.c @@ -41,25 +41,27 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write1D_c) #define WRITE_DATA(hstart, cctk_type, c_type, is_complex, fmt, file) \ { \ int _h; \ - const cctk_type *_hdata = (const cctk_type *) hdata[0]; \ - const CCTK_REAL *_coord = (const CCTK_REAL *) hdata[1]; \ + int _offset = is_complex ? 2 : 1; \ + const cctk_type *_hdata = hdata[0]; \ + const CCTK_REAL *_coord = hdata[1]; \ \ \ - for (_h = hstart; _h < hsize; _h++) \ + _hdata += hstart; \ + for (_h = 0; _h < hsize; _h++) \ { \ if (_coord) \ { \ fprintf (file, fmt, (double) _coord[_h], \ - (c_type) _hdata[_h * hstride]); \ + (c_type) _hdata[_h * _offset]); \ } \ else \ { \ - fprintf (file, fmt, _h, (c_type) _hdata[_h * hstride]); \ + fprintf (file, fmt, _h, (c_type) _hdata[_h * _offset]); \ } \ \ if (is_complex && hstride == 1) \ { \ - fprintf (file, format[2], (c_type) _hdata[_h + 1]); \ + fprintf (file, format[2], (c_type) _hdata[_h * _offset + 1]); \ } \ fputc ('\n', file); \ } \ @@ -163,7 +165,7 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias) } /* get the handle for IOASCII extensions */ - myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII"); + myGH = CCTK_GHExtension (GH, "IOASCII"); /* get the variable's group information */ CCTK_GroupData (groupindex, &gdata); @@ -256,9 +258,9 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias) have_coords ? coord_lower : NULL, num_files, file); } - origin = (CCTK_INT *) calloc (2*gdata.dim, sizeof (CCTK_INT)); + origin = calloc (2*gdata.dim, sizeof (CCTK_INT)); direction = origin + gdata.dim; - extent_int = (int *) malloc ((gdata.dim + 1) * sizeof (int)); + extent_int = malloc ((gdata.dim + 1) * sizeof (int)); /* get the variable's extents, compute the extent for 3D-diagonals as the minimum of grid points in each direction */ @@ -473,8 +475,8 @@ static void OpenFile (const cGH *GH, /* get handles for IOUtil and IOASCII extensions */ - myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII"); - ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO"); + myGH = CCTK_GHExtension (GH, "IOASCII"); + ioUtilGH = CCTK_GHExtension (GH, "IO"); /* set comment character and file extension */ if (CCTK_Equals (out1D_style, "xgraph")) @@ -493,8 +495,8 @@ static void OpenFile (const cGH *GH, /* 20 extra characters should be enough for '/', the type extension, the file extension, and the trailing '\0' */ - filename = (char *) malloc (strlen (myGH->out1D_dir) + strlen (alias) + - sizeof (slicename) + 20); + filename = malloc (strlen (myGH->out1D_dir) + strlen (alias) + + sizeof (slicename) + 20); for (i = 0; i < num_files; i++) { @@ -552,9 +554,9 @@ static void OpenFile (const cGH *GH, { /* give the slice origin as range [1 .. n] */ sprintf (slicename, "%s%c_[%d][%d]", type_extension, 'x' + dir, - gdata->grouptype == CCTK_GF ? + gdata->grouptype == CCTK_GF ? myGH->spxyz[gdata->dim-1][dir][lower] : 0, - gdata->grouptype == CCTK_GF ? + gdata->grouptype == CCTK_GF ? myGH->spxyz[gdata->dim-1][dir][upper] : 0); } } @@ -595,6 +597,14 @@ static void OpenFile (const cGH *GH, IOUtil_AdvertiseFile (GH, filename, &advertised_file); + /* mark a restart point with an empty line in the output file, + so that gnuplot/xgraph don't try to connect the last output + before the abort and the first output after the restart */ + if (ioUtilGH->recovered) + { + fputc ('\n', file[i]); + } + /* add some file information to the output file */ if (CCTK_Equals (out_fileinfo, "parameter filename") || CCTK_Equals (out_fileinfo, "all")) @@ -642,15 +652,15 @@ static void OpenFile (const cGH *GH, } /* output the index coordinates of the 1D line */ fprintf (file[i], " (%ci = %d", 'x' + lower, - gdata->grouptype == CCTK_GF ? + gdata->grouptype == CCTK_GF ? myGH->spxyz[gdata->dim-1][dir][lower] : 0); if (gdata->dim > 2) { fprintf (file[i], ", %ci = %d", 'x' + upper, - gdata->grouptype == CCTK_GF ? + gdata->grouptype == CCTK_GF ? myGH->spxyz[gdata->dim-1][dir][upper] : 0); } - fputs (") \n", file[i]); + fputs (")", file[i]); } fputc ('\n', file[i]); } diff --git a/src/Write2D.c b/src/Write2D.c index 7197231..0dd3099 100644 --- a/src/Write2D.c +++ b/src/Write2D.c @@ -33,7 +33,7 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write2D_c) #define WRITE_DATA(cctk_type, c_type, fmt) \ { \ int _i, _j; \ - const cctk_type *_hdata = (const cctk_type *) hdata[0]; \ + const cctk_type *_hdata = hdata[0]; \ const CCTK_REAL *_coord[2]; \ \ \ @@ -46,12 +46,12 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write2D_c) { \ if (_coord[0]) \ { \ - fprintf (file, fmt, (double) *_coord[0]++, \ - (double) *_coord[1]++, (c_type) *_hdata++); \ + fprintf (file, fmt, (double) *_coord[1]++, \ + (double) *_coord[0]++, (c_type) *_hdata++); \ } \ else \ { \ - fprintf (file, fmt, _i, _j, (c_type) *_hdata++); \ + fprintf (file, fmt, _j, _i, (c_type) *_hdata++); \ } \ \ if (is_complex) \ @@ -483,7 +483,6 @@ static FILE **OpenFile (const cGH *GH, fprintf (fileset[dir], " (%ci = %d)", 'x' + (maxdir-dir-1), myGH->sp2xyz[dim-1][dir]); } - fputc ('\n', fileset[dir]); } } -- cgit v1.2.3