aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350>2002-03-19 22:27:04 +0000
committertradke <tradke@94b1c47f-dcfd-45ef-a468-0854c0e9e350>2002-03-19 22:27:04 +0000
commit88a045f23bf33bbe1e309f046b81508260ea723a (patch)
tree967c7ed1d2552101b57c7faf2e3e63f720412247
parentc66c440d5abdcf8e5865dec3551f6495eae97f7e (diff)
Some code cleanup before attemting to switch to the new hyperslabbing API.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOASCII/trunk@104 94b1c47f-dcfd-45ef-a468-0854c0e9e350
-rw-r--r--src/Write1D.c939
1 files changed, 476 insertions, 463 deletions
diff --git a/src/Write1D.c b/src/Write1D.c
index 0cc13fa..f8ad0f3 100644
--- a/src/Write1D.c
+++ b/src/Write1D.c
@@ -33,49 +33,64 @@
static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusBase_IOASCII_Write1D_c)
-/*#define DEBUG_IOASCII 1*/
-/* macro to output a 1D line (with coordinates for GFs) as typed data */
-#define OUTPUT_TYPED_DATA(grouptype, hstart, hsize, hstride, coord_data, \
- stagger_offset, cctk_type, c_type, is_complex, \
- data, format, file) \
- { \
- int h; \
- cctk_type *typed_data = (cctk_type *) data; \
+/********************************************************************
+ ******************** Macro Definitions ************************
+ ********************************************************************/
+/* uncomment this to enable debugging output */
+/* #define DEBUG_IOASCII 1 */
+
+/* Macro to output a 1D line (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, hstride, hsize, complex_fmt_string */
+#define WRITE_DATA(hstart, cctk_type, c_type, is_complex, format, file) \
+ { \
+ int _h; \
+ const cctk_type *_typed_data = (const cctk_type *) hdata[0]; \
+ const CCTK_REAL *_coord_data = (const CCTK_REAL *) hdata[1]; \
\
\
- if (grouptype == CCTK_GF) \
+ for (_h = hstart; _h < hstride * hsize; _h += hstride) \
+ { \
+ if (_coord_data) \
{ \
- for (h = hstart; h < hstride * hsize; h += hstride) \
- { \
- fprintf (file, format, \
- (double) (coord_data[h] + stagger_offset), \
- (c_type) typed_data[h]); \
- if (is_complex && hstride == 1) \
- { \
- fprintf (file, out_real_format, (c_type) typed_data[h + 1]);\
- } \
- fputc ('\n', file); \
- } \
+ fprintf (file, format, \
+ (double) _coord_data[_h], (c_type) _typed_data[_h]); \
} \
else \
{ \
- for (h = hstart; h < hstride * hsize; h += hstride) \
- { \
- fprintf (file, format, (double) h, (c_type) typed_data[h]); \
- if (is_complex && hstride == 1) \
- { \
- fprintf (file, out_real_format, (c_type) typed_data[h + 1]);\
- } \
- fputc ('\n', file); \
- } \
+ fprintf (file, format, _h, (c_type) _typed_data[_h]); \
} \
- }
+ \
+ if (is_complex && hstride == 1) \
+ { \
+ fprintf (file, complex_fmt_string, (c_type) _typed_data[_h+1]); \
+ } \
+ fputc ('\n', file); \
+ } \
+ }
-/* this is needed by some preprocessors to pass into OUTPUT_TYPED_DATA
- as a dummy macro */
-#define NOTHING
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
+static void OpenFile (const cGH *GH,
+ const char *fullname,
+ const char *alias,
+ const cGroup *gdata,
+ const int *Do_it,
+ const CCTK_REAL *coord_lower,
+ int num_files,
+ FILE *file[]);
+static void WriteData (int vtype,
+ const char *header,
+ const char *data_fmt_int,
+ const char *data_fmt_real,
+ int hsize,
+ int hstride,
+ void *const *const hdata,
+ FILE *const file[]);
/*@@
@@ -125,31 +140,26 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
int groupindex; /* variable's group index */
int have_coords; /* boolean for existance of coordinates */
char coord_system[20]; /* name of the coordinate system */
- char slicename[20]; /* name of current output slice */
cGroup group_static_data; /* variable's group static data */
cGroupDynamicData group_dynamic_data;/* variable's group dynamic data */
char *fullname; /* variable's full name */
- char header_fmt_string[18]; /* header format string */
- char ylabel1_fmt_string[13]; /* y-label format string */
- char ylabel2_fmt_string[13]; /* y-label format string */
+ char header[30]; /* header string preceding a dataset */
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 float types */
- char out_real_format[30]; /* data format string for a real type */
- const char *file_extension; /* filename extension */
- char comment_char; /* character starting a comment */
FILE *file[8]; /* fds for x,y,z,d output (also COMPLEX)*/
CCTK_REAL coord_lower[3], offset;
- int stride, num_files;
- int upper, lower;
- struct stat fileinfo;
- const char *openmode;
- static char *extensions[] = {"xl", "yl", "zl", "dl"};
- char *filename, *type_extension, buffer[128];
- ioAdvertisedFileDesc advertised_file;
+ int hstride, hsize, num_files;
DECLARE_CCTK_PARAMETERS
+#ifdef DEBUG_IOASCII
+ printf ("\nIn IOASCII Write1D\n------------------\n");
+ printf (" Variable index is %d\n", vindex);
+ printf (" Alias is -%s-\n", alias);
+ fflush (stdout);
+#endif
+
/* get the variable's group index and its full name */
groupindex = CCTK_GroupIndexFromVarI (vindex);
fullname = CCTK_FullName (vindex);
@@ -194,6 +204,28 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
return (0);
}
+ /* get the coordinate indices for CCTK_GF variables
+ (CCTK_ARRAY variables never have coordinates associated) */
+ have_coords = group_static_data.grouptype == CCTK_GF;
+ if (have_coords)
+ {
+ /* FIXME: this assumes a cartesian coordinate system */
+ sprintf (coord_system, "cart%dd", group_static_data.dim);
+ for (i = 0; i < group_static_data.dim && i < 3; i++)
+ {
+ CCTK_CoordRange (GH, &coord_lower[i], &offset, i + 1, NULL, coord_system);
+ coord_index[i] = CCTK_CoordIndex (i + 1, NULL, coord_system);
+ have_coords &= coord_index[i] >= 0;
+ }
+
+ if (! have_coords)
+ {
+ CCTK_VWarn (8, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOASCII_Write1D: No coordinate ranges found for '%s'",
+ coord_system);
+ }
+ }
+
/* DEPRICATED IN BETA12 */
if (CCTK_ParameterQueryTimesSet ("out_style", CCTK_THORNSTRING) > 0)
{
@@ -207,32 +239,21 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
"instead");
user_was_warned = 1;
}
- if (CCTK_Equals (out_style, "gnuplot"))
- {
- out1D_style = "gnuplot f(x)";
- }
- else
- {
- out1D_style = "xgraph";
- }
+
+ out1D_style = CCTK_Equals (out_style, "gnuplot") ?
+ "gnuplot f(x)" : "xgraph";
}
- /* set header and data format strings */
+ /* set header format string */
if (CCTK_Equals (out1D_style, "xgraph"))
{
- comment_char = '"';
- file_extension = ".xg";
- sprintf (header_fmt_string, "\n\n%cTime = %%%s\n", comment_char,out_format);
+ sprintf (time_fmt_string, "\n\n\"Time = %%%s\n", out_format);
}
else
{
- comment_char = '#';
- file_extension = ".asc";
- sprintf (header_fmt_string, "\n%cTime = %%%s\n", comment_char, out_format);
+ sprintf (time_fmt_string, "\n#Time = %%%s\n", out_format);
}
- sprintf (ylabel1_fmt_string, " (%%c = %%%s", out_format);
- sprintf (ylabel2_fmt_string, ", %%c = %%%s", out_format);
- sprintf (out_real_format, "\t\t%%%s", out_format);
+ sprintf (header, time_fmt_string, GH->cctk_time);
/* check whether to include physical time as separate column in the output */
i = 0;
@@ -243,250 +264,28 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
sprintf (data_fmt_string_real, time_fmt_string, (double) GH->cctk_time);
i = strlen (data_fmt_string_int);
}
- sprintf (data_fmt_string_int + i, "%%%s\t\t%%d", out_format);
- sprintf (data_fmt_string_real + i, "%%%s\t\t%%%s", out_format, out_format);
-
-#ifdef DEBUG_IOASCII
- printf ("\nIn IOASCII Write1D\n------------------\n");
- printf (" Variable index is %d\n",vindex);
- printf (" Alias is -%s-\n",alias);
- fflush (stdout);
-#endif
-
- /* get the coordinate indices for CCTK_GF variables */
- if (group_static_data.grouptype == CCTK_GF)
+ if (have_coords)
{
- sprintf (coord_system, "cart%dd", group_static_data.dim);
- have_coords = 1;
- for (i = 0; i < group_static_data.dim && i < 3; i++)
- {
- CCTK_CoordRange (GH, &coord_lower[i], &offset, i + 1, NULL, coord_system);
- coord_index[i] = CCTK_CoordIndex (i + 1, NULL, coord_system);
- have_coords &= coord_index[i] >= 0;
- }
-
- if (! have_coords)
- {
- CCTK_VWarn (8, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOASCII_Write1D: No coordinate ranges found for '%s'",
- coord_system);
- }
+ sprintf (data_fmt_string_int + i, "%%%s\t\t%%d", out_format);
+ sprintf (data_fmt_string_real + i, "%%%s\t\t%%%s", out_format, out_format);
}
else
{
- /* CCTK_ARRAY variables never have coordinates associated */
- have_coords = 0;
+ sprintf (data_fmt_string_int + i, "%%d\t\t%%d");
+ sprintf (data_fmt_string_real + i, "%%d\t\t%%%s", out_format);
}
- /* What processor are we on? */
- myproc = CCTK_MyProc (GH);
-
/* get the stride into the data and the (maximum) number of files to write */
- stride = group_static_data.vartype == CCTK_VARIABLE_COMPLEX &&
- CCTK_Equals (out1D_style, "xgraph") ? 2 : 1;
- num_files = stride * 4;
+ hstride = group_static_data.vartype == CCTK_VARIABLE_COMPLEX &&
+ CCTK_Equals (out1D_style, "xgraph") ? 2 : 1;
+ num_files = hstride * 4;
/* Processor 0 opens the files with the appropriate name */
+ myproc = CCTK_MyProc (GH);
if (myproc == 0)
{
- /* 20 extra characters should be enough for '/',
- the type extension, the file extension, and the trailing '\0' */
- filename = (char *) malloc (strlen (myGH->outdir1D) + strlen (alias) +
- sizeof (slicename) + 20);
-
- for (i = 0; i < num_files; i++)
- {
- dir = i % 4;
-
- /* skip empty slices */
- if (! Do_it[dir])
- {
- continue;
- }
-
- /* add suffix for complex type variables in xgraph output */
- if (group_static_data.vartype == CCTK_VARIABLE_COMPLEX && num_files == 8)
- {
- if (new_filename_scheme)
- {
- type_extension = i < 4 ? "re_" : "im_";
- }
- else
- {
- type_extension = i < 4 ? "_re" : "_im";
- }
- }
- else
- {
- type_extension = "";
- }
-
- /* get the indices into spxyz[] */
- lower = (dir + 1) % 3;
- upper = (dir + 2) % 3;
- if (upper < lower)
- {
- upper = lower;
- lower = 0;
- }
-
- /* FIXME: this can go after the old filename scheme has gone */
- if (new_filename_scheme)
- {
- if ((i + 1) % 4)
- {
- if (group_static_data.dim == 1)
- {
- sprintf (slicename, "%s1D", type_extension);
- }
- else if (group_static_data.dim == 2)
- {
- /* give the slice origin as range [1 .. n] */
- sprintf (slicename, "%s%c_[%d]", type_extension, 'x' + dir,
- myGH->spxyz[group_static_data.dim-1][dir][lower]);
- }
- else
- {
- /* give the slice origin as range [1 .. n] */
- sprintf (slicename, "%s%c_[%d][%d]", type_extension, 'x' + dir,
- myGH->spxyz[group_static_data.dim-1][dir][lower],
- myGH->spxyz[group_static_data.dim-1][dir][upper]);
- }
- }
- else
- {
- sprintf (slicename, "%s%dD_diagonal", type_extension,
- group_static_data.dim);
- }
-
- /* skip the pathname if output goes into current directory */
- if (strcmp (myGH->outdir1D, "."))
- {
- sprintf (filename, "%s/%s_%s%s", myGH->outdir1D, alias,
- slicename, file_extension);
- }
- else
- {
- sprintf (filename, "%s_%s%s", alias, slicename, file_extension);
- }
- }
- else
- {
- /* skip the pathname if output goes into current directory */
- if (strcmp (myGH->outdir1D, "."))
- {
- sprintf (filename, "%s/%s%s.%s", myGH->outdir1D, alias,
- type_extension, extensions[dir]);
- }
- else
- {
- sprintf (filename, "%s%s.%s", alias, type_extension, extensions[dir]);
- }
- }
-
- /* see if output file was already created */
- if (GetNamedData (myGH->filenameList1D, filename) == NULL)
- {
- /* if restart from recovery, all existing files are opened
- in append mode */
- if (IOUtil_RestartFromRecovery (GH))
- {
- openmode = stat (filename, &fileinfo) == 0 ? "a" : "w";
- }
- else
- {
- openmode = "w";
- }
-
- /* just store a non-NULL pointer in database */
- StoreNamedData (&myGH->filenameList1D, filename, (void *) 1);
- }
- else
- {
- openmode = "a";
- }
-
- if (! (file[i] = fopen (filename, openmode)))
- {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "IOASCII_Write1D: Cannot open 1D output file '%s'",
- filename);
- }
- else if (*openmode == 'w')
- {
- /* advertise new files for downloading and add file info */
- /* FIXME: this can go after the old filename scheme has gone */
- advertised_file.slice = new_filename_scheme ? slicename:extensions[dir];
- advertised_file.thorn = CCTK_THORNSTRING;
- advertised_file.varname = fullname;
- advertised_file.description = "One-dimensional line plots";
- advertised_file.mimetype = comment_char == '#' ?
- "application/gnuplot" : "application/x-graph";
-
- IOUtil_AdvertiseFile (GH, filename, &advertised_file);
-
- /* add some file information to the output file */
- if (CCTK_Equals (out_fileinfo, "parameter filename") ||
- CCTK_Equals (out_fileinfo, "all"))
- {
- buffer[0] = 0;
- CCTK_ParameterFilename (sizeof (buffer), buffer);
- fprintf (file[i], "%cParameter file %s\n", comment_char, buffer);
- }
- if (CCTK_Equals (out_fileinfo, "creation date") ||
- CCTK_Equals (out_fileinfo, "all"))
- {
- buffer[0] = 0;
- Util_CurrentDate (sizeof (buffer), buffer);
- fprintf (file[i], "%cCreated %s ", comment_char, buffer);
- Util_CurrentTime (sizeof (buffer), buffer);
- fprintf (file[i], "%s\n", buffer);
- }
- if (CCTK_Equals (out_fileinfo, "axis labels") ||
- CCTK_Equals (out_fileinfo, "all"))
- {
- if (dir < 3)
- {
- fprintf (file[i], "%cx-label %c\n", comment_char, 'x' + dir);
- }
- else
- {
- fprintf (file[i], "%cx-label diagonal\n", comment_char);
- }
- fprintf (file[i], "%cy-label %s", comment_char, fullname);
- if (dir < 3)
- {
- if (group_static_data.dim > 1)
- {
- /* output the physical coordinates of the 1D line */
- if (have_coords)
- {
- fprintf (file[i], ylabel1_fmt_string, 'x' + lower,
- coord_lower[lower] + GH->cctk_delta_space[lower] *
- myGH->spxyz[group_static_data.dim-1][dir][lower]);
- if (group_static_data.dim > 2)
- {
- fprintf (file[i], ylabel2_fmt_string, 'x' + upper,
- coord_lower[upper] + GH->cctk_delta_space[upper] *
- myGH->spxyz[group_static_data.dim-1][dir][upper]);
- }
- fprintf (file[i], "),");
- }
- /* output the index coordinates of the 1D line */
- fprintf (file[i], " (%ci = %d", 'x' + lower,
- myGH->spxyz[group_static_data.dim-1][dir][lower]);
- if (group_static_data.dim > 2)
- {
- fprintf (file[i], ", %ci = %d", 'x' + upper,
- myGH->spxyz[group_static_data.dim-1][dir][upper]);
- }
- fprintf (file[i], ") \n");
- }
- }
- }
- }
- }
- free (filename);
+ OpenFile (GH, fullname, alias, &group_static_data, Do_it,
+ have_coords ? coord_lower : NULL, num_files, file);
}
/* OK so actually do the I/O in each direction */
@@ -498,9 +297,7 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
const int *origin;
const int zero_point[3] = {0, 0, 0};
int directions[3];
- int hsize;
- void *data;
- CCTK_REAL *coord_data;
+ void *hdata[2];
/* skip empty slices */
@@ -544,7 +341,7 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
{
if (Hyperslab_GetHyperslab (GH, 0, coord_index[dir], 0, 1,
origin, directions, &length, &downsample,
- (void **) &coord_data, &hsize) < 0)
+ &hdata[1], &hsize) < 0)
{
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"IOASCII_Write1D: Failed to extract hyperslab for"
@@ -553,7 +350,7 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
}
else
{
- coord_data = NULL;
+ hdata[1] = NULL;
}
}
else
@@ -568,7 +365,7 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
}
/* coordinates are calculated by output processor */
- coord_data = NULL;
+ hdata[1] = NULL;
}
}
else
@@ -584,20 +381,20 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
}
/* no coordinates are needed for arrays */
- coord_data = NULL;
+ hdata[1] = NULL;
}
/* get the variable's 1D data */
if (Hyperslab_GetHyperslab (GH, 0, vindex, 0, 1, origin,
directions, &length, &downsample,
- &data, &hsize) < 0)
+ &hdata[0], &hsize) < 0)
{
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"IOASCII_Write1D: Failed to extract hyperslab for "
"variable '%s'", fullname);
- if (coord_data)
+ if (hdata[1])
{
- free (coord_data);
+ free (hdata[1]);
}
continue;
}
@@ -605,197 +402,413 @@ int IOASCII_Write1D (const cGH *GH, int vindex, const char *alias)
/* And write it out on processor 0 */
if (myproc == 0 && file[dir] != NULL)
{
- if (group_static_data.grouptype == CCTK_GF)
+ if (have_coords)
{
if (dir < 3)
{
/* get the staggering offset for the xyz coordinates */
- offset = 0.5 * CCTK_StaggerDirIndex (dir, group_static_data.stagtype);
- if (have_coords)
- {
- offset *= GH->cctk_delta_space[dir];
- }
- else
+ offset = 0.5 * GH->cctk_delta_space[dir] *
+ CCTK_StaggerDirIndex (dir, group_static_data.stagtype);
+ for (i = 0; i < hsize; i++)
{
- coord_data = (CCTK_REAL *) malloc (hsize * sizeof (CCTK_REAL));
- for (i = 0; i < hsize; i++)
- {
- coord_data[i] = i;
- }
+ ((CCTK_REAL *) hdata[1])[i] += offset;
}
}
else
{
- /* get the diagonal coordinates */
- offset = have_coords ? GH->cctk_delta_space[0] * sqrt (3) : sqrt(3);
- coord_data = (CCTK_REAL *) malloc (hsize * sizeof (CCTK_REAL));
+ /* calculate the diagonal coordinates */
+ offset = GH->cctk_delta_space[0] * sqrt (3);
+ hdata[1] = malloc (hsize * sizeof (CCTK_REAL));
for (i = 0; i < hsize; i++)
{
- coord_data[i] = i * offset;
- }
- if (have_coords)
- {
- offset = coord_lower[0] * sqrt (3);
- }
- else
- {
- offset = 0.0;
+ ((CCTK_REAL *) hdata[1])[i] = coord_lower[0]*sqrt (3) + i*offset;
}
}
}
- /* print out header */
- fprintf (file[dir], header_fmt_string, GH->cctk_time);
+ WriteData (group_static_data.vartype, header, data_fmt_string_int,
+ data_fmt_string_real, hsize, hstride, hdata, file + dir);
+
+ /* close the output file(s) */
+ fclose (file[dir]);
+ if (num_files == 8)
+ {
+ fclose (file[dir + 4]);
+ }
+
+ /* clean up */
+ free (hdata[0]);
+ if (hdata[1])
+ {
+ free (hdata[1]);
+ }
+ }
+
+ } /* end of loop through all directions */
+
+ /* free allocated resources */
+ free (fullname);
+
+ return (0);
+}
+
+
+static void OpenFile (const cGH *GH,
+ const char *fullname,
+ const char *alias,
+ const cGroup *gdata,
+ const int *Do_it,
+ const CCTK_REAL *coord_lower,
+ int num_files,
+ FILE *file[])
+{
+ int i, dir;
+ asciiioGH *myGH;
+ struct stat fileinfo;
+ const char *openmode;
+ static char *extensions[] = {"xl", "yl", "zl", "dl"};
+ char *filename, *type_extension, buffer[128];
+ ioAdvertisedFileDesc advertised_file;
+ char slicename[20]; /* name of current output slice */
+ int upper, lower;
+ char comment_char; /* character starting a comment */
+ const char *file_extension; /* filename extension */
+ char ylabel1_fmt_string[13]; /* y-label format string */
+ char ylabel2_fmt_string[13]; /* y-label format string */
+ DECLARE_CCTK_PARAMETERS
+
+
+ /* get the handle for IOASCII extensions */
+ myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII");
- /* and then loop through the line points */
- switch (group_static_data.vartype)
+ /* set comment character and file extension */
+ if (CCTK_Equals (out1D_style, "xgraph"))
+ {
+ comment_char = '"';
+ file_extension = ".xg";
+ }
+ else
+ {
+ comment_char = '#';
+ file_extension = ".asc";
+ }
+
+ sprintf (ylabel1_fmt_string, " (%%c = %%%s", out_format);
+ sprintf (ylabel2_fmt_string, ", %%c = %%%s", out_format);
+
+ /* 20 extra characters should be enough for '/',
+ the type extension, the file extension, and the trailing '\0' */
+ filename = (char *) malloc (strlen (myGH->outdir1D) + strlen (alias) +
+ sizeof (slicename) + 20);
+
+ for (i = 0; i < num_files; i++)
+ {
+ dir = i % 4;
+
+ /* skip empty slices */
+ if (! Do_it[dir])
+ {
+ continue;
+ }
+
+ /* add suffix for complex type variables in xgraph output */
+ if (gdata->vartype == CCTK_VARIABLE_COMPLEX && num_files == 8)
+ {
+ if (new_filename_scheme)
{
- case CCTK_VARIABLE_CHAR:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, 1,
- coord_data, offset, CCTK_BYTE, int, 0, data,
- data_fmt_string_int, file[dir]);
- break;
-
- case CCTK_VARIABLE_INT:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, 1,
- coord_data, offset, CCTK_INT, int, 0, data,
- data_fmt_string_int, file[dir]);
- break;
-
- case CCTK_VARIABLE_REAL:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, 1,
- coord_data, offset, CCTK_REAL, double, 0, data,
- data_fmt_string_real, file[dir]);
- break;
-
- case CCTK_VARIABLE_COMPLEX:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, stride,
- coord_data, offset, CCTK_REAL, double, 1, data,
- data_fmt_string_real, file[dir]);
- if (stride == 2)
+ type_extension = i < 4 ? "re_" : "im_";
+ }
+ else
+ {
+ type_extension = i < 4 ? "_re" : "_im";
+ }
+ }
+ else
+ {
+ type_extension = "";
+ }
+
+ /* get the indices into spxyz[] */
+ lower = (dir + 1) % 3;
+ upper = (dir + 2) % 3;
+ if (upper < lower)
+ {
+ upper = lower;
+ lower = 0;
+ }
+
+ /* FIXME: this can go after the old filename scheme has gone */
+ if (new_filename_scheme)
+ {
+ if ((i + 1) % 4)
+ {
+ if (gdata->dim == 1)
+ {
+ sprintf (slicename, "%s1D", type_extension);
+ }
+ else if (gdata->dim == 2)
+ {
+ /* give the slice origin as range [1 .. n] */
+ sprintf (slicename, "%s%c_[%d]", type_extension, 'x' + dir,
+ myGH->spxyz[gdata->dim-1][dir][lower]);
+ }
+ else
+ {
+ /* give the slice origin as range [1 .. n] */
+ sprintf (slicename, "%s%c_[%d][%d]", type_extension, 'x' + dir,
+ myGH->spxyz[gdata->dim-1][dir][lower],
+ myGH->spxyz[gdata->dim-1][dir][upper]);
+ }
+ }
+ else
+ {
+ sprintf (slicename, "%s%dD_diagonal", type_extension, gdata->dim);
+ }
+
+ /* skip the pathname if output goes into current directory */
+ if (strcmp (myGH->outdir1D, "."))
+ {
+ sprintf (filename, "%s/%s_%s%s", myGH->outdir1D, alias,
+ slicename, file_extension);
+ }
+ else
+ {
+ sprintf (filename, "%s_%s%s", alias, slicename, file_extension);
+ }
+ }
+ else
+ {
+ /* skip the pathname if output goes into current directory */
+ if (strcmp (myGH->outdir1D, "."))
+ {
+ sprintf (filename, "%s/%s%s.%s", myGH->outdir1D, alias,
+ type_extension, extensions[dir]);
+ }
+ else
+ {
+ sprintf (filename, "%s%s.%s", alias, type_extension, extensions[dir]);
+ }
+ }
+
+ /* see if output file was already created */
+ if (GetNamedData (myGH->filenameList1D, filename) == NULL)
+ {
+ /* if restart from recovery, existing files are opened in append mode */
+ if (IOUtil_RestartFromRecovery (GH))
+ {
+ openmode = stat (filename, &fileinfo) == 0 ? "a" : "w";
+ }
+ else
+ {
+ openmode = "w";
+ }
+
+ /* just store a non-NULL pointer in database */
+ StoreNamedData (&myGH->filenameList1D, filename, (void *) 1);
+ }
+ else
+ {
+ openmode = "a";
+ }
+
+ if (! (file[i] = fopen (filename, openmode)))
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "IOASCII_Write1D: Cannot open 1D output file '%s'",
+ filename);
+ }
+ else if (*openmode == 'w')
+ {
+ /* advertise new files for downloading and add file info */
+ /* FIXME: this can go after the old filename scheme has gone */
+ advertised_file.slice = new_filename_scheme ? slicename:extensions[dir];
+ advertised_file.thorn = CCTK_THORNSTRING;
+ advertised_file.varname = fullname;
+ advertised_file.description = "One-dimensional line plots";
+ advertised_file.mimetype = comment_char == '#' ?
+ "application/gnuplot" : "application/x-graph";
+
+ IOUtil_AdvertiseFile (GH, filename, &advertised_file);
+
+ /* add some file information to the output file */
+ if (CCTK_Equals (out_fileinfo, "parameter filename") ||
+ CCTK_Equals (out_fileinfo, "all"))
+ {
+ buffer[0] = 0;
+ CCTK_ParameterFilename (sizeof (buffer), buffer);
+ fprintf (file[i], "%cParameter file %s\n", comment_char, buffer);
+ }
+ if (CCTK_Equals (out_fileinfo, "creation date") ||
+ CCTK_Equals (out_fileinfo, "all"))
+ {
+ buffer[0] = 0;
+ Util_CurrentDate (sizeof (buffer), buffer);
+ fprintf (file[i], "%cCreated %s ", comment_char, buffer);
+ Util_CurrentTime (sizeof (buffer), buffer);
+ fprintf (file[i], "%s\n", buffer);
+ }
+ if (CCTK_Equals (out_fileinfo, "axis labels") ||
+ CCTK_Equals (out_fileinfo, "all"))
+ {
+ if (dir < 3)
+ {
+ fprintf (file[i], "%cx-label %c\n", comment_char, 'x' + dir);
+ }
+ else
+ {
+ fprintf (file[i], "%cx-label diagonal\n", comment_char);
+ }
+ fprintf (file[i], "%cy-label %s", comment_char, fullname);
+ if (dir < 3)
+ {
+ if (gdata->dim > 1)
{
- /* print out header */
- fprintf (file[dir + 4], header_fmt_string, GH->cctk_time);
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 1, hsize, stride,
- coord_data, offset, CCTK_REAL, double, 1, data,
- data_fmt_string_real, file[dir + 4]);
+ /* output the physical coordinates of the 1D line */
+ if (coord_lower)
+ {
+ fprintf (file[i], ylabel1_fmt_string, 'x' + lower,
+ coord_lower[lower] + GH->cctk_delta_space[lower] *
+ myGH->spxyz[gdata->dim-1][dir][lower]);
+ if (gdata->dim > 2)
+ {
+ fprintf (file[i], ylabel2_fmt_string, 'x' + upper,
+ coord_lower[upper] + GH->cctk_delta_space[upper] *
+ myGH->spxyz[gdata->dim-1][dir][upper]);
+ }
+ fprintf (file[i], "),");
+ }
+ /* output the index coordinates of the 1D line */
+ fprintf (file[i], " (%ci = %d", 'x' + lower,
+ myGH->spxyz[gdata->dim-1][dir][lower]);
+ if (gdata->dim > 2)
+ {
+ fprintf (file[i], ", %ci = %d", 'x' + upper,
+ myGH->spxyz[gdata->dim-1][dir][upper]);
+ }
+ fprintf (file[i], ") \n");
}
- break;
+ }
+ }
+ }
+ }
+ free (filename);
+}
+
+
+static void WriteData (int vtype,
+ const char *header,
+ const char *data_fmt_string_int,
+ const char *data_fmt_string_real,
+ int hsize,
+ int hstride,
+ void *const *const hdata,
+ FILE *const file[])
+{
+ char complex_fmt_string[30];
+ DECLARE_CCTK_PARAMETERS
+
+ sprintf (complex_fmt_string, "\t\t%%%s", out_format);
+
+ /* print out header */
+ fputs (header, file[0]);
+
+ if (vtype == CCTK_VARIABLE_CHAR)
+ {
+ WRITE_DATA (0, CCTK_BYTE, int, 0, data_fmt_string_int, file[0]);
+ }
+ else if (vtype == CCTK_VARIABLE_INT)
+ {
+ WRITE_DATA (0, CCTK_INT, int, 0, data_fmt_string_int, file[0]);
+ }
+ else if (vtype == CCTK_VARIABLE_REAL)
+ {
+ WRITE_DATA (0, CCTK_REAL, double, 0, data_fmt_string_real, file[0]);
+ }
+ else if (vtype == CCTK_VARIABLE_COMPLEX)
+ {
+ WRITE_DATA (0, CCTK_REAL, double, 1, data_fmt_string_real, file[0]);
+ if (hstride == 2)
+ {
+ /* print out header */
+ fputs (header, file[0 + 4]);
+ WRITE_DATA (1, CCTK_REAL, double, 1, data_fmt_string_real, file[4]);
+ }
+ }
#ifdef CCTK_INT2
- case CCTK_VARIABLE_INT2:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, 1,
- coord_data, offset, CCTK_INT2, int, 0, data,
- data_fmt_string_int, file[dir]);
- break;
+ else if (vtype == CCTK_VARIABLE_INT2)
+ {
+ WRITE_DATA (0, CCTK_INT2, int, 0, data_fmt_string_int, file[0]);
+ }
#endif
#ifdef CCTK_INT4
- case CCTK_VARIABLE_INT4:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, 1,
- coord_data, offset, CCTK_INT4, int, 0, data,
- data_fmt_string_int, file[dir]);
- break;
+ else if (vtype == CCTK_VARIABLE_INT4)
+ {
+ WRITE_DATA (0, CCTK_INT4, int, 0, data_fmt_string_int, file[0]);
+ }
#endif
#ifdef CCTK_INT8
- case CCTK_VARIABLE_INT8:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, 1,
- coord_data, offset, CCTK_INT8, int, 0, data,
- data_fmt_string_int, file[dir]);
- break;
+ else if (vtype == CCTK_VARIABLE_INT8)
+ {
+ WRITE_DATA (0, CCTK_INT8, int, 0, data_fmt_string_int, file[0]);
+ }
#endif
#ifdef CCTK_REAL4
- case CCTK_VARIABLE_REAL4:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, 1,
- coord_data, offset, CCTK_REAL4, double, 0, data,
- data_fmt_string_real, file[dir]);
- break;
-
- case CCTK_VARIABLE_COMPLEX8:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, stride,
- coord_data, offset, CCTK_REAL4, double, 1, data,
- data_fmt_string_real, file[dir]);
- if (stride == 2)
- {
- /* print out header */
- fprintf (file[dir + 4], header_fmt_string, GH->cctk_time);
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 1, hsize, stride,
- coord_data, offset, CCTK_REAL4, double, 1, data,
- data_fmt_string_real, file[dir + 4]);
- }
- break;
+ else if (vtype == CCTK_VARIABLE_REAL4)
+ {
+ WRITE_DATA (0, CCTK_REAL4, double, 0, data_fmt_string_real, file[0]);
+ }
+ else if (vtype == CCTK_VARIABLE_COMPLEX8)
+ {
+ WRITE_DATA (0, CCTK_REAL4, double, 1, data_fmt_string_real, file[0]);
+ if (hstride == 2)
+ {
+ /* print out header */
+ fputs (header, file[0 + 4]);
+ WRITE_DATA (1, CCTK_REAL4, double, 1, data_fmt_string_real, file[0 + 4]);
+ }
+ }
#endif
#ifdef CCTK_REAL8
- case CCTK_VARIABLE_REAL8:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, 1,
- coord_data, offset, CCTK_REAL8, double, 0, data,
- data_fmt_string_real, file[dir]);
- break;
-
- case CCTK_VARIABLE_COMPLEX16:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, stride,
- coord_data, offset, CCTK_REAL8, double, 1, data,
- data_fmt_string_real, file[dir]);
- if (stride == 2)
- {
- /* print out header */
- fprintf (file[dir + 4], header_fmt_string, GH->cctk_time);
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 1, hsize, stride,
- coord_data, offset, CCTK_REAL8, double, 1, data,
- data_fmt_string_real, file[dir + 4]);
- }
- break;
+ else if (vtype == CCTK_VARIABLE_REAL8)
+ {
+ WRITE_DATA (0, CCTK_REAL8, double, 0, data_fmt_string_real, file[0]);
+ }
+ else if (vtype == CCTK_VARIABLE_COMPLEX16)
+ {
+ WRITE_DATA (0, CCTK_REAL8, double, 1, data_fmt_string_real, file[0]);
+ if (hstride == 2)
+ {
+ /* print out header */
+ fputs (header, file[0 + 4]);
+ WRITE_DATA (1, CCTK_REAL8, double, 1, data_fmt_string_real, file[0 + 4]);
+ }
+ }
#endif
#ifdef CCTK_REAL16
- case CCTK_VARIABLE_REAL16:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, 1,
- coord_data, offset, CCTK_REAL16, double, 0, data,
- data_fmt_string_real, file[dir]);
- break;
-
- case CCTK_VARIABLE_COMPLEX32:
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 0, hsize, stride,
- coord_data, offset, CCTK_REAL16, double, 1, data,
- data_fmt_string_real, file[dir]);
- if (stride == 2)
- {
- /* print out header */
- fprintf (file[dir + 4], header_fmt_string, GH->cctk_time);
- OUTPUT_TYPED_DATA (group_static_data.grouptype, 1, hsize, stride,
- coord_data, offset, CCTK_REAL16, double, 1, data,
- data_fmt_string_real, file[dir + 4]);
- }
- break;
-#endif
-
- default:
- CCTK_WARN (1, "Unsupported variable type");
- break;
- }
-
- /* close the output file(s) */
- fclose (file[dir]);
- if (num_files == 8)
- {
- fclose (file[dir + 4]);
- }
-
- /* clean up */
- free (data);
- if (coord_data)
- {
- free (coord_data);
- }
+ else if (vtype == CCTK_VARIABLE_REAL16)
+ {
+ WRITE_DATA (0, CCTK_REAL16, double, 0, data_fmt_string_real, file[0]);
+ }
+ else if (vtype == CCTK_VARIABLE_COMPLEX32)
+ {
+ WRITE_DATA (0, CCTK_REAL16, double, 1, data_fmt_string_real, file[0]);
+ if (hstride == 2)
+ {
+ /* print out header */
+ fputs (header, file[0 + 4]);
+ WRITE_DATA (1, CCTK_REAL16, double, 1, data_fmt_string_real, file[0 + 4]);
}
+ }
+#endif
- } /* end of loop through all directions */
-
- /* free allocated resources */
- free (fullname);
-
- return (0);
+ else
+ {
+ CCTK_WARN (1, "Unsupported variable type");
+ }
}