diff options
Diffstat (limited to 'src/Write2D.c')
-rw-r--r-- | src/Write2D.c | 830 |
1 files changed, 440 insertions, 390 deletions
diff --git a/src/Write2D.c b/src/Write2D.c index 65fdebb..6442060 100644 --- a/src/Write2D.c +++ b/src/Write2D.c @@ -15,71 +15,76 @@ #include "cctk.h" #include "cctk_Parameters.h" #include "Hyperslab.h" +#include "CactusBase/IOUtil/src/ioGH.h" #include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h" -#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h" #include "ioASCIIGH.h" /* the rcs ID and its dummy function to use it */ static const char *rcsid = "$Id$"; CCTK_FILEVERSION(CactusBase_IOASCII_Write2D_c) -/* enable debug output */ -/*#define IOASCII_DEBUG 1*/ +/******************************************************************** + ******************** Macro Definitions ************************ + ********************************************************************/ +/* uncomment this to enable debugging output */ +/* #define DEBUG_IOASCII 1 */ /* macro to output a time slice as typed data */ -#define OUTPUT_TYPED_DATA(coord_i, coord_j, stagger_offset_i,stagger_offset_j,\ - cctk_type, c_type, data, hsize, is_cmplx_type, \ - have_coords, fmt_string, file) \ - { \ - int i, j; \ - const cctk_type *typed_data = (const cctk_type *) (data); \ +/* Macro to output a 2D slice (with coordinates if available) as typed data + For readability, the macro definition implicitely uses the following + variables (which are defined in the calling routine): + hdata, hsize, is_complex, format[2], file */ +#define WRITE_DATA(cctk_type, c_type, fmt) \ + { \ + int _i, _j; \ + const cctk_type *_hdata = (const cctk_type *) hdata[0]; \ + const CCTK_REAL *_coord[2]; \ + \ \ \ - /* output coordinates if available otherwise just the indices */ \ - if (have_coords) \ + _coord[0] = (const CCTK_REAL *) hdata[1]; \ + _coord[1] = (const CCTK_REAL *) hdata[2]; \ + for (_j = 0; _j < hsize[1]; _j++) \ + { \ + for (_i = 0; _i < hsize[0]; _i++) \ { \ - for (j = 0; j < hsize[1]; j++) \ + if (_coord[0]) \ { \ - for (i = 0; i < hsize[0]; i++) \ - { \ - fprintf (file, fmt_string, \ - (double) (*coord_i++ + stagger_offset_i), \ - (double) (*coord_j++ + stagger_offset_j), \ - (c_type) *typed_data++); \ - if (is_cmplx_type) \ - { \ - fprintf (file, "\t\t"); \ - fprintf (file, out_real_format, (double) *typed_data++); \ - } \ - fprintf (file, "\n"); \ - } \ - fprintf (file, "\n"); \ + fprintf (file, fmt, (double) *_coord[0]++, \ + (double) *_coord[1]++, (c_type) *_hdata++); \ } \ - coord_i -= hsize[0] * hsize[1]; \ - coord_j -= hsize[0] * hsize[1]; \ - } \ - else \ - { \ - for (j = 0; j < hsize[1]; j++) \ + else \ + { \ + fprintf (file, fmt, _i, _j, (c_type) *_hdata++); \ + } \ + \ + if (is_complex) \ { \ - for (i = 0; i < hsize[0]; i++) \ - { \ - fprintf (file, fmt_string, \ - (double) i, \ - (double) j, \ - (c_type) *typed_data++); \ - if (is_cmplx_type) \ - { \ - fprintf (file, "\t\t"); \ - fprintf (file, out_real_format, (double) *typed_data++); \ - } \ - fprintf (file, "\n"); \ - } \ - fprintf (file, "\n"); \ + fprintf (file, format[2], (c_type) *_hdata++); \ } \ + fputc ('\n', file); \ } \ - } + fputc ('\n', file); \ + } \ + } + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static FILE **OpenFile (const cGH *GH, + const char *fullname, + const char *alias, + int dim, + const CCTK_REAL *coord_lower, + int maxdir); +static void WriteData (int vtype, + const char *header, + char format[3][30], + const CCTK_INT hsize[2], + void *const *const hdata, + FILE *file); /*@@ @@ -89,9 +94,11 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write2D_c) @desc Writes the 2D slices of a variable into separate ASCII files. @enddesc - @calls IOUtil_RestartFromRecovery - IOUtil_AdvertiseFile - Hyperslab_GetHyperslab + @calls Hyperslab_DefineGlobalMappingByIndex + Hyperslab_FreeMapping + Hyperslab_GetList + OpenFile + WriteData @var GH @vdesc Pointer to CCTK GH @@ -120,44 +127,34 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write2D_c) @@*/ int IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) { - DECLARE_CCTK_PARAMETERS - int myproc; asciiioGH *myGH; - char header_fmt_string[30]; /* header format string */ - char zlabel_fmt_string[30]; /* z-label format string */ - char out_real_format[30]; /* data format string for a real type */ - char time_fmt_string[30]; /* time format string */ - char data_fmt_string_int[30]; /* data format string for int types */ - char data_fmt_string_real[30]; /* data format string for real types */ - int dir, maxdir; - int groupindex; - int have_coords; - cGroup groupinfo; - FILE **fdset_2D; /* array of output file pointers */ - int coord_index[3]; /* variable indices for xyz coordinates */ - CCTK_REAL coord_lower[3]; /* coordinates' minima */ - char coord_system[20]; /* name of the coordinate system */ - int origin[3]; /* the slice origin */ - CCTK_REAL dummy; - char *filename; + int i, total_hsize, num_requested_hslabs, num_returned_hslabs; + int dir, dir_i, dir_j, maxdir, myproc, groupindex, have_coords; + cGroup gdata; + int coord_index[3]; + CCTK_REAL coord_lower[3]; + char coord_system[20]; + char format[3][30]; + char header[30], buffer[30]; char *fullname; - char slicename[20]; - ioAdvertisedFileDesc advertised_file; - char buffer[128]; - static char *extensions[] = {"xy", "xz", "yz"}; - + int extent_int[3]; + CCTK_INT mapping; + CCTK_REAL offset[2]; + CCTK_INT vindices[3]; + CCTK_INT origin[3], extent[3], direction[6], hsize[2]; + void *hdata[3]; + FILE **fileset; + DECLARE_CCTK_PARAMETERS - /* to make the compiler happy */ - fdset_2D = NULL; - /* get the variable group information */ + /* get the variable name and group information */ + fullname = CCTK_FullName (vindex); groupindex = CCTK_GroupIndexFromVarI (vindex); - CCTK_GroupData (groupindex, &groupinfo); + CCTK_GroupData (groupindex, &gdata); /* check if variable has storage assigned */ if (! CCTK_QueryGroupStorageI (GH, groupindex)) { - fullname = CCTK_FullName (vindex); CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "No IOASCII 2D output for '%s' (no storage)", fullname); free (fullname); @@ -168,34 +165,18 @@ int IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII"); /* get the number of slices to output */ - /* in general: maxdir = groupinfo.dim * (groupinfo.dim - 1) / 2; */ - maxdir = groupinfo.dim == 2 ? 1 : 3; - - /* set header and data format strings */ - sprintf (header_fmt_string, "\n\n#Time = %%%s\n", out_format); - sprintf (zlabel_fmt_string, " (%%c = %%%s),", out_format); - sprintf (out_real_format, "%%%s", out_format); - dir = 0; - if (CCTK_Equals (out2D_style, "gnuplot f(t,x,y)")) - { - sprintf (time_fmt_string, "%%%s\t\t", out_format); - sprintf (data_fmt_string_int, time_fmt_string, (double) GH->cctk_time); - sprintf (data_fmt_string_real, time_fmt_string, (double) GH->cctk_time); - dir = strlen (data_fmt_string_int); - } - sprintf (data_fmt_string_int + dir, "%%%s\t\t%%%s\t\t%%d", - out_format, out_format); - sprintf (data_fmt_string_real + dir, "%%%s\t\t%%%s\t\t%%%s", - out_format, out_format, out_format); + /* in general: maxdir = gdata.dim * (gdata.dim - 1) / 2; */ + maxdir = gdata.dim == 2 ? 1 : 3; - /* get the coordinate indices if we output a grid function */ - if (groupinfo.grouptype == CCTK_GF) + /* get the coordinate indices for CCTK_GF variables + (CCTK_ARRAY variables never have coordinates associated) */ + have_coords = gdata.grouptype == CCTK_GF; + if (have_coords) { - sprintf (coord_system, "cart%dd", groupinfo.dim); - have_coords = 1; - for (dir = 0; dir < groupinfo.dim && dir < 3; dir++) + sprintf (coord_system, "cart%dd", gdata.dim); + for (dir = 0; dir < gdata.dim && dir < 3; dir++) { - CCTK_CoordRange (GH, &coord_lower[dir], &dummy, dir+1, NULL,coord_system); + CCTK_CoordRange (GH, &coord_lower[dir], offset, dir+1, NULL,coord_system); coord_index[dir] = CCTK_CoordIndex (dir + 1, NULL, coord_system); have_coords &= coord_index[dir] >= 0; } @@ -207,173 +188,49 @@ int IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) coord_system); } } + num_requested_hslabs = have_coords ? 3 : 1; + + /* set header and data format strings */ + sprintf (buffer, "\n\n#Time = %%%s\n", out_format); + sprintf (header, buffer, GH->cctk_time); + dir = 0; + if (CCTK_Equals (out2D_style, "gnuplot f(t,x,y)")) + { + sprintf (buffer, "%%%s\t\t", out_format); + sprintf (format[0], buffer, (double) GH->cctk_time); + sprintf (format[1], buffer, (double) GH->cctk_time); + dir = strlen (format[0]); + } + if (have_coords) + { + sprintf (format[0] + dir, "%%%s\t\t%%%s\t\t%%d", + out_format, out_format); + sprintf (format[1] + dir, "%%%s\t\t%%%s\t\t%%%s", + out_format, out_format, out_format); + } else { - /* CCTK_ARRAY variables never have coordinates associated */ - have_coords = 0; + sprintf (format[0] + dir, "%%d\t\t%%d\t\t%%d"); + sprintf (format[1] + dir, "%%d\t\t%%d\t\t%%%s", out_format); } - /* What processor are we on? */ + /* processor 0 opens the files on the first trip through */ myproc = CCTK_MyProc (GH); - - /* Open the files on the first trip through if we are proc. 0 */ if (myproc == 0) { - - /* see if output file for this alias name was already created */ - fdset_2D = (FILE **) GetNamedData (myGH->fileList_2D, alias); - if (fdset_2D == NULL) - { - fdset_2D = (FILE **) malloc (3 * sizeof (FILE *)); - filename = (char *) malloc (strlen (myGH->outdir2D) + strlen (alias) + - sizeof (slicename) + 20); - - /* get the variable's full name */ - fullname = CCTK_FullName (vindex); - - /* Open/Create files */ - for (dir = 0; dir < maxdir; dir++) - { - /* FIXME: this can go when we permanently switch the the - new filename scheme */ - if (new_filename_scheme) - { - if (groupinfo.dim == 2) - { - strcpy (slicename, "2D"); - } - else - { - /* give the slice origin as range [1 .. n] */ - sprintf (slicename, "%s_[%d]", extensions[dir], - myGH->sp2xyz[groupinfo.dim - 1][dir]); - } - - /* skip pathname if output goes into current directory */ - if (strcmp (myGH->outdir2D, ".")) - { - sprintf (filename, "%s/%s_%s.asc", myGH->outdir2D, alias,slicename); - } - else - { - sprintf (filename, "%s_%s.asc", alias, slicename); - } - } - else - { - /* skip pathname if output goes into current directory */ - if (strcmp (myGH->outdir2D, ".")) - { - if (groupinfo.dim == 2) - { - sprintf (filename, "%s/%s_2D.gnuplot", myGH->outdir2D, alias); - } - else - { - sprintf (filename, "%s/%s_2d_%s.gnuplot", myGH->outdir2D, alias, - extensions[dir]); - } - } - else - { - if (groupinfo.dim == 2) - { - sprintf (filename, "%s_2D.gnuplot", alias); - } - else - { - sprintf (filename, "%s_2d_%s.gnuplot", alias, extensions[dir]); - } - } - } - - /* if restart from recovery, try to open an existing file ... */ - fdset_2D[dir] = NULL; - if (IOUtil_RestartFromRecovery (GH)) - { - fdset_2D[dir] = fopen (filename, "a"); - } - - /* otherwise or if that failed, create a new one */ - if (! fdset_2D[dir]) - { - fdset_2D[dir] = fopen (filename, "w"); - } - if (! fdset_2D[dir]) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Cannot open 2D output file '%s'", filename); - return (-2); - } - - /* advertise the file for downloading and write file info */ - /* FIXME: this can go when we permanently switch the the - new filename scheme */ - advertised_file.slice = new_filename_scheme ? - slicename : extensions[dir]; - advertised_file.thorn = CCTK_THORNSTRING; - advertised_file.varname = fullname; - advertised_file.description = "Two-dimensional slice plots"; - advertised_file.mimetype = "application/gnuplot"; - - IOUtil_AdvertiseFile (GH, filename, &advertised_file); - - if (CCTK_Equals (out_fileinfo, "parameter filename") || - CCTK_Equals (out_fileinfo, "all")) - { - buffer[0] = 0; - CCTK_ParameterFilename (sizeof (buffer), buffer); - fprintf (fdset_2D[dir], "#Parameter file %s\n", buffer); - } - if (CCTK_Equals (out_fileinfo, "creation date") || - CCTK_Equals (out_fileinfo, "all")) - { - buffer[0] = 0; - Util_CurrentDate (sizeof (buffer), buffer); - fprintf (fdset_2D[dir], "#Created %s ", buffer); - Util_CurrentTime (sizeof (buffer), buffer); - fprintf (fdset_2D[dir], "%s\n", buffer); - } - if (CCTK_Equals (out_fileinfo, "axis labels") || - CCTK_Equals (out_fileinfo, "all")) - { - fprintf (fdset_2D[dir], "#x-label %c\n", extensions[dir][0]); - fprintf (fdset_2D[dir], "#y-label %c\n", extensions[dir][1]); - fprintf (fdset_2D[dir], "#z-label %s", advertised_file.varname); - if (groupinfo.dim != 2) - { - if (have_coords) - { - fprintf (fdset_2D[dir], zlabel_fmt_string, 'x' + (maxdir-dir-1), - coord_lower[maxdir-dir-1] + - GH->cctk_delta_space[maxdir-dir-1] * - myGH->sp2xyz[groupinfo.dim-1][dir]); - } - fprintf (fdset_2D[dir], " (%ci = %d)", - 'x' + (maxdir-dir-1), myGH->sp2xyz[groupinfo.dim-1][dir]); - } - fputc ('\n', fdset_2D[dir]); - } - } - - /* store file desriptors in database */ - StoreNamedData (&myGH->fileList_2D, alias, fdset_2D); - - free (filename); - free (fullname); - } + fileset = OpenFile (GH, fullname, alias, gdata.dim, + have_coords ? coord_lower : NULL, maxdir); } + else + { + fileset = NULL; + } + + CCTK_GroupgshVI (GH, 3, extent_int, vindex); + /* now do the actual I/O looping over all directions */ for (dir = 0; dir < maxdir; dir++) { - int dir_i, dir_j; - int directions[3]; - const int lengths[2] = {-1, -1}; - const int downsamples[2] = {1, 1}; - int hsize[2]; - CCTK_REAL *coord_data_i, *coord_data_j; - void *data; - /* get the directions to span the hyperslab */ if (dir == 0) { @@ -388,179 +245,372 @@ int IOASCII_Write2D (const cGH *GH, int vindex, const char *alias) dir_i = 1; dir_j = 2; /* yz */ } + /* set the extent vector */ + for (i = 0; i < 3; i++) + { + extent[i] = extent_int[i]; + } + /* set the origin using the slice center from IOUtil */ - memset (origin, 0, GH->cctk_dim * sizeof (int)); - origin[maxdir-dir-1] = myGH->sp2xyz[groupinfo.dim - 1][dir]; + memset (origin, 0, sizeof (origin)); + if (have_coords) + { + origin[maxdir-dir-1] = myGH->sp2xyz[gdata.dim - 1][dir]; + } - /* set the directions vector */ - memset (directions, 0, sizeof (directions)); - directions[maxdir-dir-1] = 1; + /* set the direction vector */ + memset (direction, 0, sizeof (direction)); + direction[dir_i] = direction[gdata.dim + 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, + "IOASCII_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, + "IOASCII_Write2D: selected hyperslab has zero size for " + "variable '%s' direction %d", fullname, dir); + Hyperslab_FreeMapping (mapping); + continue; + } - /* get the coordinates for grid function output */ - if (have_coords) + if (myproc == 0) { - /* get the i-coordinate slice */ - if (Hyperslab_GetHyperslab (GH, 0, coord_index[dir_i], 0, 2, - origin, directions, lengths, downsamples, - (void **) &coord_data_i, hsize) < 0) + /* allocate hyperslab buffers */ + hdata[0] = malloc (total_hsize * CCTK_VarTypeSize (gdata.vartype)); + hdata[1] = have_coords ? malloc (2 * total_hsize * sizeof (CCTK_REAL)) : + NULL; + hdata[2] = (CCTK_REAL *) hdata[1] + total_hsize; + } + + /* 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, hdata, + NULL); + + /* release the mapping structure */ + Hyperslab_FreeMapping (mapping); + + /* And dump the data to file */ + if (myproc == 0 && fileset) + { + if (num_returned_hslabs == num_requested_hslabs) + { + 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++) + { + ((CCTK_REAL *) hdata[1])[i] += offset[0]; + ((CCTK_REAL *) hdata[2])[i] += offset[1]; + } + } + + WriteData (gdata.vartype, header, format, hsize, hdata, fileset[dir]); + } + else { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Failed to extract 2D hyperslab for %c-coordinate", - 'x' + dir_i); - return (-3); + "IOASCII_Write2D: Failed to extract hyperslab for " + "variable '%s'", fullname); } - /* get the j-coordinate slice */ - if (Hyperslab_GetHyperslab (GH, 0, coord_index[dir_j], 0, 2, - origin, directions, lengths, downsamples, - (void **) &coord_data_j, hsize) < 0) + /* clean up */ + free (hdata[0]); + if (hdata[1]) { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Failed to extract 2D hyperslab for %c-coordinate", - 'x' + dir_j); - free (coord_data_i); - return (-3); + free (hdata[1]); + } + + } /* end of outputting the data by processor 0 */ + + } /* end of looping through xyz directions */ + + free (fullname); + + return (0); +} + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +/*@@ + @routine OpenFile + @date Wed 12 Dec 2001 + @author Thomas Radke + @desc + Opens a set of ASCII files for a given alias name. + If this is the first time through, it will create the files, + write some header information, and advertise them to IOUtil. + @enddesc + + @returntype FILE ** + @returndesc + the set of open file descriptors,<BR> + or NULL if a file couldn't be created + @endreturndesc + @@*/ +static FILE **OpenFile (const cGH *GH, + const char *fullname, + const char *alias, + int dim, + const CCTK_REAL *coord_lower, + int maxdir) +{ + int dir; + FILE **fileset; + char *filename; + asciiioGH *myGH; + const ioGH *ioUtilGH; + ioAdvertisedFileDesc advertised_file; + char slicename[30], zlabel_fmt_string[30], buffer[128]; + const char *extensions[] = {"xy", "xz", "yz"}; + DECLARE_CCTK_PARAMETERS + + + /* get handles for IOUtil and IOASCII extensions */ + myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII"); + ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO"); + + /* see if we are the first time through */ + fileset = (FILE **) GetNamedData (myGH->fileList_2D, alias); + if (fileset) + { + return (fileset); + } + + sprintf (zlabel_fmt_string, " (%%c = %%%s),", out_format); + fileset = (FILE **) malloc (3 * sizeof (FILE *)); + filename = (char *) malloc (strlen (myGH->outdir2D) + strlen (alias) + + sizeof (slicename) + 20); + + /* open/create files for each slice */ + for (dir = 0; dir < maxdir; dir++) + { + if (new_filename_scheme) + { + if (dim == 2) + { + strcpy (slicename, "2D"); + } + else + { + /* give the slice origin as range [1 .. n] */ + sprintf (slicename, "%s_[%d]", extensions[dir], + myGH->sp2xyz[dim - 1][dir]); + } + + /* skip pathname if output goes into current directory */ + if (strcmp (myGH->outdir2D, ".")) + { + sprintf (filename, "%s/%s_%s.asc", myGH->outdir2D, alias, slicename); + } + else + { + sprintf (filename, "%s_%s.asc", alias, slicename); } } else { - /* grid arrays don't have coordinates assigned */ - coord_data_i = NULL; - coord_data_j = NULL; + /* skip pathname if output goes into current directory */ + if (strcmp (myGH->outdir2D, ".")) + { + if (dim == 2) + { + sprintf (filename, "%s/%s_2D.gnuplot", myGH->outdir2D, alias); + } + else + { + sprintf (filename, "%s/%s_2d_%s.gnuplot", myGH->outdir2D, alias, + extensions[dir]); + } + } + else + { + if (dim == 2) + { + sprintf (filename, "%s_2D.gnuplot", alias); + } + else + { + sprintf (filename, "%s_2d_%s.gnuplot", alias, extensions[dir]); + } + } } - /* get the variable slice */ - if (Hyperslab_GetHyperslab (GH, 0, vindex, 0, 2, origin, directions, - lengths, downsamples, &data, hsize) < 0) + /* if restart from recovery, try to open an existing file ... */ + fileset[dir] = fopen (filename, ioUtilGH->recovered ? "a" : "w"); + if (! fileset[dir]) { - fullname = CCTK_FullName (vindex); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Failed to extract 2D hyperslab for variable '%s'", fullname); - free (fullname); - if (coord_data_i) - { - free (coord_data_i); - } - if (coord_data_j) + "Cannot open 2D output file '%s'", filename); + free (fileset); + free (filename); + return (NULL); + } + + /* advertise the file for downloading and write file info */ + advertised_file.slice = new_filename_scheme ? slicename : extensions[dir]; + advertised_file.thorn = CCTK_THORNSTRING; + advertised_file.varname = fullname; + advertised_file.description = "Two-dimensional slice plots"; + advertised_file.mimetype = "application/gnuplot"; + + IOUtil_AdvertiseFile (GH, filename, &advertised_file); + + if (CCTK_Equals (out_fileinfo, "parameter filename") || + CCTK_Equals (out_fileinfo, "all")) + { + buffer[0] = 0; + CCTK_ParameterFilename (sizeof (buffer), buffer); + fprintf (fileset[dir], "#Parameter file %s\n", buffer); + } + if (CCTK_Equals (out_fileinfo, "creation date") || + CCTK_Equals (out_fileinfo, "all")) + { + buffer[0] = 0; + Util_CurrentDate (sizeof (buffer), buffer); + fprintf (fileset[dir], "#Created %s ", buffer); + Util_CurrentTime (sizeof (buffer), buffer); + fprintf (fileset[dir], "%s\n", buffer); + } + if (CCTK_Equals (out_fileinfo, "axis labels") || + CCTK_Equals (out_fileinfo, "all")) + { + fprintf (fileset[dir], "#x-label %c\n", extensions[dir][0]); + fprintf (fileset[dir], "#y-label %c\n", extensions[dir][1]); + fprintf (fileset[dir], "#z-label %s", advertised_file.varname); + if (dim != 2) { - free (coord_data_j); + if (coord_lower) + { + fprintf (fileset[dir], zlabel_fmt_string, 'x' + (maxdir-dir-1), + coord_lower[maxdir-dir-1] + + GH->cctk_delta_space[maxdir-dir-1] * + myGH->sp2xyz[dim-1][dir]); + } + fprintf (fileset[dir], " (%ci = %d)", + 'x' + (maxdir-dir-1), myGH->sp2xyz[dim-1][dir]); } - return (-3); + fputc ('\n', fileset[dir]); } + } - /* proc 0 writes */ - if (myproc == 0) - { - CCTK_REAL stagger_offset_i, stagger_offset_j; + /* store file desriptors in database */ + StoreNamedData (&myGH->fileList_2D, alias, fileset); + free (filename); - /* get the staggering offset for the coordinates */ - stagger_offset_i = CCTK_StaggerDirIndex (dir_i, groupinfo.stagtype) * - 0.5 * GH->cctk_delta_space[dir_i]; - stagger_offset_j = CCTK_StaggerDirIndex (dir_j, groupinfo.stagtype) * - 0.5 * GH->cctk_delta_space[dir_j]; + return (fileset); +} - /* print out header */ - fprintf (fdset_2D[dir], header_fmt_string, GH->cctk_time); - switch (groupinfo.vartype) - { - case CCTK_VARIABLE_CHAR: - OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, - stagger_offset_j, CCTK_BYTE, int, data, hsize, - 0, have_coords, data_fmt_string_int,fdset_2D[dir]); - break; - - case CCTK_VARIABLE_INT: - OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, - stagger_offset_j, CCTK_INT, int, data, hsize, - 0, have_coords, data_fmt_string_int,fdset_2D[dir]); - break; - - case CCTK_VARIABLE_REAL: - case CCTK_VARIABLE_COMPLEX: - OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, - stagger_offset_j, CCTK_REAL, double, data, hsize, - groupinfo.vartype == CCTK_VARIABLE_COMPLEX, - have_coords, data_fmt_string_real, fdset_2D[dir]); - break; +/*@@ + @routine WriteData + @date Wed 12 Dec 2001 + @author Thomas Radke + @desc + Writes the given hyperslabs into the appropriate output files. + @enddesc + @@*/ +static void WriteData (int vtype, + const char *header, + char format[3][30], + const CCTK_INT hsize[2], + void *const *const hdata, + FILE *file) +{ + int is_complex; + char complex_fmt_string[30]; + DECLARE_CCTK_PARAMETERS + + is_complex = strncmp (CCTK_VarTypeName (vtype), "CCTK_COMPLEX", 12) == 0; + sprintf (complex_fmt_string, "\t\t%%%s", out_format); + + /* print out header */ + fputs (header, file); + + if (vtype == CCTK_VARIABLE_CHAR) + { + WRITE_DATA (CCTK_BYTE, int, format[0]); + } + else if (vtype == CCTK_VARIABLE_INT) + { + WRITE_DATA (CCTK_INT, int, format[0]); + } + else if (vtype == CCTK_VARIABLE_REAL || vtype == CCTK_VARIABLE_COMPLEX) + { + WRITE_DATA (CCTK_REAL, double, format[1]); + } #ifdef CCTK_INT2 - case CCTK_VARIABLE_INT2: - OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, - stagger_offset_j, CCTK_INT2, int, data, hsize, - 0, have_coords, data_fmt_string_int,fdset_2D[dir]); - break; + else if (vtype == CCTK_VARIABLE_INT2) + { + WRITE_DATA (CCTK_INT2, int, format[0]); + } #endif #ifdef CCTK_INT4 - case CCTK_VARIABLE_INT4: - OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, - stagger_offset_j, CCTK_INT4, int, data, hsize, - 0, have_coords, data_fmt_string_int,fdset_2D[dir]); - break; + else if (vtype == CCTK_VARIABLE_INT4) + { + WRITE_DATA (CCTK_INT4, int, format[0]); + } #endif #ifdef CCTK_INT8 - case CCTK_VARIABLE_INT8: - OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, - stagger_offset_j, CCTK_INT8, int, data, hsize, - 0, have_coords, data_fmt_string_int,fdset_2D[dir]); - break; + else if (vtype == CCTK_VARIABLE_INT8) + { + WRITE_DATA (CCTK_INT8, int, format[0]); + } #endif #ifdef CCTK_REAL4 - case CCTK_VARIABLE_REAL4: - case CCTK_VARIABLE_COMPLEX8: - OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, - stagger_offset_j, CCTK_REAL4, double, data, hsize, - groupinfo.vartype == CCTK_VARIABLE_COMPLEX8, - have_coords, data_fmt_string_real, fdset_2D[dir]); - break; + else if (vtype == CCTK_VARIABLE_REAL4 || vtype == CCTK_VARIABLE_COMPLEX8) + { + WRITE_DATA (CCTK_REAL4, double, format[1]); + } #endif #ifdef CCTK_REAL8 - case CCTK_VARIABLE_REAL8: - case CCTK_VARIABLE_COMPLEX16: - OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, - stagger_offset_j, CCTK_REAL8, double, data, hsize, - groupinfo.vartype == CCTK_VARIABLE_COMPLEX16, - have_coords, data_fmt_string_real, fdset_2D[dir]); - break; + else if (vtype == CCTK_VARIABLE_REAL8 || vtype == CCTK_VARIABLE_COMPLEX16) + { + WRITE_DATA (CCTK_REAL8, double, format[1]); + } #endif #ifdef CCTK_REAL16 - case CCTK_VARIABLE_REAL16: - case CCTK_VARIABLE_COMPLEX32: - OUTPUT_TYPED_DATA (coord_data_i, coord_data_j, stagger_offset_i, - stagger_offset_j, CCTK_REAL16, double, data, hsize, - groupinfo.vartype == CCTK_VARIABLE_COMPLEX32, - have_coords, data_fmt_string_real, fdset_2D[dir]); - break; + else if (vtype == CCTK_VARIABLE_REAL16 || vtype == CCTK_VARIABLE_COMPLEX32) + { + WRITE_DATA (CCTK_REAL16, double, format[1]); + } #endif - default: - CCTK_WARN (1, "Unsupported variable type"); - break; - } - - /* keep the file open but flush it */ - fflush (fdset_2D[dir]); - - /* free the hyperslabs */ - free (data); - if (coord_data_i) - { - free (coord_data_i); - } - if (coord_data_j) - { - free (coord_data_j); - } - - } /* end of outputting the data by processor 0 */ - - } /* end of looping through xyz directions */ + else + { + CCTK_WARN (1, "Unsupported variable type"); + } - return (0); + /* keep the file open but flush it */ + fflush (file); } |