diff options
Diffstat (limited to 'src/Write3D.c')
-rw-r--r-- | src/Write3D.c | 670 |
1 files changed, 350 insertions, 320 deletions
diff --git a/src/Write3D.c b/src/Write3D.c index e5c477b..0aee309 100644 --- a/src/Write3D.c +++ b/src/Write3D.c @@ -15,81 +15,77 @@ #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$"; +static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusBase_IOASCII_Write3D_c) -/* enable debug output */ -/*#define IOASCII_DEBUG 1*/ - -/* macro to output a time volume as typed data */ -#define OUTPUT_TYPED_DATA(hsize, coord, stagger_offset, cctk_type, c_type, \ - data, have_coords, is_cmplx_type, fmt_string, file) \ - { \ - int _i, _j, _k; \ - const cctk_type *_typed_data = (const cctk_type *) (data); \ +/******************************************************************** + ******************** Macro Definitions ************************ + ********************************************************************/ +/* uncomment this to enable debugging output */ +/* #define DEBUG_IOASCII 1 */ + +/* Macro to output a 3D array (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, _k; \ + const cctk_type *_hdata = (const cctk_type *) hdata[0]; \ + const CCTK_REAL *_coord[3]; \ + \ \ \ - /* 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]; \ + _coord[2] = (const CCTK_REAL *) hdata[3]; \ + for (_k = 0; _k < hsize[2]; _k++) \ + { \ + for (_j = 0; _j < hsize[1]; _j++) \ { \ - for (_k = 0; _k < hsize[2]; _k++) \ + 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[0]++ + stagger_offset[0]), \ - (double) (*coord[1]++ + stagger_offset[1]), \ - (double) (*coord[2]++ + stagger_offset[2]), \ - (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]++, \ + (double) *_coord[2]++, (c_type) *_hdata++); \ } \ - } \ - coord[0] -= hsize[0] * hsize[1] * hsize[2]; \ - coord[1] -= hsize[0] * hsize[1] * hsize[2]; \ - coord[2] -= hsize[0] * hsize[1] * hsize[2]; \ - } \ - else \ - { \ - for (_k = 0; _k < hsize[2]; _k++) \ - { \ - for (_j = 0; _j < hsize[1]; _j++) \ + else \ + { \ + fprintf (file, fmt, (double) _i, (double) _j, (double) _k, \ + (c_type) *_hdata++); \ + } \ + \ + if (is_complex) \ { \ - for (_i = 0; _i < hsize[0]; _i++) \ - { \ - fprintf (file, fmt_string, \ - (double) _i, \ - (double) _j, \ - (double) _k, \ - (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); +static void WriteData (int vtype, + const char *header, + char format[3][30], + const CCTK_INT hsize[3], + void *const *const hdata, + FILE *file); + /*@@ @routine IOASCII_Write3D @date Wed 12 Dec 2001 @@ -97,8 +93,11 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write3D_c) @desc Writes the 3D volume of a variable into a gnuplot ASCII file. @enddesc - @calls IOUtil_RestartFromRecovery - IOUtil_AdvertiseFile + @calls Hyperslab_DefineGlobalMappingByIndex + Hyperslab_FreeMapping + Hyperslab_GetList + OpenFile + WriteData @var GH @vdesc Pointer to CCTK GH @@ -127,344 +126,375 @@ CCTK_FILEVERSION(CactusBase_IOASCII_Write3D_c) @@*/ int IOASCII_Write3D (const cGH *GH, int vindex, const char *alias) { - DECLARE_CCTK_PARAMETERS - int myproc, groupindex, dir, have_coords; - asciiioGH *myGH; - char header_fmt_string[30]; /* header 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 */ - FILE **file; - int coord_index[3]; /* variable indices for xyz coordinates */ - CCTK_REAL coord_lower[3]; /* coordinates' minima */ - CCTK_REAL dummy; - char *filename; + int i, total_hsize; + int myproc, groupindex, have_coords; + int num_requested_hslabs, num_returned_hslabs; + char header[30], buffer[30]; + char format[3][30]; + FILE *file; + cGroup gdata; char *fullname; - cGroup groupinfo; - ioAdvertisedFileDesc advertised_file; - char buffer[128]; - const int directions[3] = {1, 1, 1}; - const int origin[3] = {0, 0, 0}; - const int lengths[3] = {-1, -1, -1}; - const int downsamples[3] = {1, 1, 1}; - int hsize[3]; - CCTK_REAL *coord_data[3], stagger_offset[3]; - void *data; - + void *hdata[4]; + int extent_int[3]; + CCTK_REAL offset[3]; + CCTK_INT mapping; + CCTK_INT vindices[4]; + CCTK_INT extent[3], hsize[3]; + const CCTK_INT origin[] = {0, 0, 0}, + direction[] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; + DECLARE_CCTK_PARAMETERS - /* to make the compiler happy */ - file = NULL; - filename = fullname = NULL; /* get the variable 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 3D output for '%s' (no storage)", fullname); free (fullname); return (-1); } - /* Get the handle for IOASCII extensions */ - myGH = (asciiioGH *) CCTK_GHExtension (GH, "IOASCII"); - - /* set header and data format strings */ - sprintf (header_fmt_string, "\n\n#Time = %%%s\n", out_format); - sprintf (out_real_format, "%%%s", out_format); - dir = 0; - if (CCTK_Equals (out3D_style, "gnuplot f(t,x,y,z)")) - { - 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\t\t%%d", - out_format, out_format); - sprintf (data_fmt_string_real + dir, "%%%s\t\t%%%s\t\t%%%s\t\t%%%s", - out_format, out_format, out_format, out_format); - - /* 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) */ + vindices[0] = vindex; + have_coords = gdata.grouptype == CCTK_GF; + if (have_coords) { - have_coords = 1; - for (dir = 0; dir < 3; dir++) + for (i = 1; i <= 3; i++) { - CCTK_CoordRange (GH, &coord_lower[dir], &dummy, dir+1, NULL, "cart3d"); - coord_index[dir] = CCTK_CoordIndex (dir + 1, NULL, "cart3d"); - have_coords &= coord_index[dir] >= 0; + vindices[i] = CCTK_CoordIndex (i, NULL, "cart3d"); + have_coords &= vindices[i] >= 0; } if (! have_coords) { - CCTK_VWarn (8, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOASCII_Write3D: No coordinate ranges found for '%s'", - "cart3d"); + CCTK_WARN (8, "IOASCII_Write3D: No coordinate ranges found for 'card3d'"); } } + num_requested_hslabs = have_coords ? 4 : 1; + + /* set header and data format strings */ + sprintf (buffer, "\n\n#Time = %%%s\n", out_format); + sprintf (header, buffer, (double) GH->cctk_time); + i = 0; + if (CCTK_Equals (out3D_style, "gnuplot f(t,x,y,z)")) + { + sprintf (buffer, "%%%s\t\t", out_format); + sprintf (format[0], buffer, (double) GH->cctk_time); + sprintf (format[1], buffer, (double) GH->cctk_time); + i = strlen (format[0]); + } + if (have_coords) + { + sprintf (format[0] + i, "%%%s\t\t%%%s\t\t%%d\t\t%%d", + out_format, out_format); + sprintf (format[1] + i, "%%%s\t\t%%%s\t\t%%%s\t\t%%%s", + out_format, out_format, out_format, out_format); + } else { - /* CCTK_ARRAY variables never have coordinates associated */ - have_coords = 0; + sprintf (format[0] + i, "%%d\t\t%%d\t\t%%d\t\t%%d"); + sprintf (format[1] + i, "%%d\t\t%%d\t\t%%%s\t\t%%%s", + out_format, out_format); } + sprintf (format[2], "\t\t%%%s", out_format); /* What processor are we on? */ myproc = CCTK_MyProc (GH); - /* Open the files on the first trip through if we are proc. 0 */ + /* Open the file on processor 0 */ + file = myproc == 0 ? OpenFile (GH, fullname, alias) : NULL; + + /* set the extent vector (copy from 'int' to 'CCTK_INT' */ + CCTK_GroupgshVI (GH, 3, extent_int, vindex); + for (i = 0; i < 3; i++) + { + extent[i] = extent_int[i]; + } + + /* get the hyperslab mapping */ + mapping = Hyperslab_DefineGlobalMappingByIndex (GH, vindex, 3, + direction, + origin, + extent, + NULL, /* downsample */ + -1, /* table handle */ + NULL /* conversion fn */, + hsize); + if (mapping < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOASCII_Write3D: Failed to define hyperslab mapping for " + "variable '%s'", fullname); + free (fullname); + return (-1); + } + total_hsize = hsize[0] * hsize[1] * hsize[2]; + if (total_hsize <= 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOASCII_Write3D: selected hyperslab has zero size for " + "variable '%s'", fullname); + Hyperslab_FreeMapping (mapping); + free (fullname); + return (-1); + } + + if (myproc == 0) + { + /* allocate hyperslab buffers */ + hdata[0] = malloc (total_hsize * CCTK_VarTypeSize (gdata.vartype)); + hdata[1] = have_coords ? malloc (3 * total_hsize * sizeof (CCTK_REAL)) : + NULL; + hdata[2] = (CCTK_REAL *) hdata[1] + 1*total_hsize; + hdata[3] = (CCTK_REAL *) hdata[1] + 2*total_hsize; + } + + /* get the hyperslabs */ + num_returned_hslabs = Hyperslab_GetList (GH, mapping, num_requested_hslabs, + NULL, vindices, NULL, NULL, hdata, + NULL); + + /* And dump the data to file */ if (myproc == 0) { - /* see if output file for this alias name was already created */ - file = (FILE **) GetNamedData (myGH->fileList_3D, alias); - if (file == NULL) + if (num_returned_hslabs == num_requested_hslabs) { - file = (FILE **) malloc (sizeof (FILE *)); - filename = (char *) malloc (strlen (myGH->outdir3D) + strlen (alias) + 9); - - /* get the variable's full name */ - fullname = CCTK_FullName (vindex); - - /* Open/Create the file */ - /* skip pathname if output goes into current directory */ - if (strcmp (myGH->outdir3D, ".")) + if (have_coords) { - sprintf (filename, "%s/%s_3D.asc", myGH->outdir3D, alias); - } - else - { - sprintf (filename, "%s_3D.asc", alias); + /* 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++) + { + ((CCTK_REAL *) hdata[1])[i] += offset[0]; + ((CCTK_REAL *) hdata[2])[i] += offset[1]; + ((CCTK_REAL *) hdata[3])[i] += offset[2]; + } } - /* if restart from recovery, try to open an existing file ... */ - *file = NULL; - if (IOUtil_RestartFromRecovery (GH)) - { - *file = fopen (filename, "a"); - } + WriteData (gdata.vartype, header, format, hsize, hdata, file); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOASCII_Write3D: Failed to extract hyperslab for " + "variable '%s'", fullname); + } - /* otherwise or if that failed, create a new one */ - if (! *file) - { - *file = fopen (filename, "w"); - } - if (! *file) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Cannot open 3D IOASCII output file '%s'", filename); - return (-2); - } + /* clean up */ + free (hdata[0]); + if (hdata[1]) + { + free (hdata[1]); + } + } /* end of outputting the data by processor 0 */ - /* 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 = ""; - advertised_file.thorn = CCTK_THORNSTRING; - advertised_file.varname = fullname; - advertised_file.description = "Full-dimensional variable contents"; - advertised_file.mimetype = "application/gnuplot"; + free (fullname); - IOUtil_AdvertiseFile (GH, filename, &advertised_file); + return (0); +} - if (CCTK_Equals (out_fileinfo, "parameter filename") || - CCTK_Equals (out_fileinfo, "all")) - { - buffer[0] = 0; - CCTK_ParameterFilename (sizeof (buffer), buffer); - fprintf (*file, "#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 (*file, "#Created %s ", buffer); - Util_CurrentTime (sizeof (buffer), buffer); - fprintf (*file, "%s\n", buffer); - } - if (CCTK_Equals (out_fileinfo, "axis labels") || - CCTK_Equals (out_fileinfo, "all")) - { - fprintf (*file, "#z-label %s\n", advertised_file.varname); - } - } - /* store file desriptors in database */ - StoreNamedData (&myGH->fileList_3D, alias, file); +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +/*@@ + @routine OpenFile + @date Wed 12 Dec 2001 + @author Thomas Radke + @desc + Opens an ASCII file for a given alias name. + If this is the first time through, it will create the file, + write some header information, and advertise it to IOUtil. + @enddesc - free (filename); - free (fullname); - } + @returntype FILE * + @returndesc + the file descriptor, or NULL if the file couldn't be created + @endreturndesc + @@*/ +static FILE *OpenFile (const cGH *GH, const char *fullname, const char *alias) +{ + FILE **file; + char *filename; + char buffer[128]; + asciiioGH *myGH; + const ioGH *ioUtilGH; + ioAdvertisedFileDesc advertised_file; + DECLARE_CCTK_PARAMETERS - /* get the coordinates for grid function output */ - if (have_coords) + + /* 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 */ + file = (FILE **) GetNamedData (myGH->fileList_3D, alias); + if (file) { - /* get the i-coordinate volume */ - if (Hyperslab_GetHyperslab (GH, 0, coord_index[0], 0, 3, - origin, directions, lengths, downsamples, - (void **) &coord_data[0], hsize) < 0) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Failed to extract 3D hyperslab for x-coordinate"); - return (-3); - } + return (*file); + } - /* get the j-coordinate volume */ - if (Hyperslab_GetHyperslab (GH, 0, coord_index[1], 0, 3, - origin, directions, lengths, downsamples, - (void **) &coord_data[1], hsize) < 0) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Failed to extract 3D hyperslab for y-coordinate"); - free (coord_data[0]); - return (-3); - } + file = (FILE **) malloc (sizeof (FILE *)); + filename = (char *) malloc (strlen (myGH->outdir3D) + strlen (alias) + 9); - /* get the k-coordinate volume */ - if (Hyperslab_GetHyperslab (GH, 0, coord_index[2], 0, 3, - origin, directions, lengths, downsamples, - (void **) &coord_data[2], hsize) < 0) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Failed to extract 3D hyperslab for z-coordinate"); - free (coord_data[1]); - free (coord_data[0]); - return (-3); - } + /* Open/Create the file */ + /* skip pathname if output goes into current directory */ + if (strcmp (myGH->outdir3D, ".")) + { + sprintf (filename, "%s/%s_3D.asc", myGH->outdir3D, alias); } else { - /* grid arrays don't have coordinates assigned */ - coord_data[0] = coord_data[1] = coord_data[2] = NULL; + sprintf (filename, "%s_3D.asc", alias); } - /* get the variable volume */ - if (Hyperslab_GetHyperslab (GH, 0, vindex, 0, 3, origin, directions, - lengths, downsamples, &data, hsize) < 0) + /* if restart from recovery, try to open an existing file ... */ + *file = fopen (filename, ioUtilGH->recovered ? "a" : "w"); + if (! *file) { - fullname = CCTK_FullName (vindex); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Failed to extract 3D hyperslab for variable '%s'", fullname); - free (fullname); - for (dir = 0; dir < 3; dir++) - { - if (coord_data[dir]) - { - free (coord_data[dir]); - } - } - return (-3); + "Cannot open 3D IOASCII output file '%s'", filename); + return (NULL); } - /* proc 0 writes */ - if (myproc == 0) + /* advertise the file for downloading and write file info */ + advertised_file.slice = ""; + advertised_file.thorn = CCTK_THORNSTRING; + advertised_file.varname = fullname; + advertised_file.description = "Full-dimensional variable contents"; + advertised_file.mimetype = "application/gnuplot"; + + IOUtil_AdvertiseFile (GH, filename, &advertised_file); + + if (CCTK_Equals (out_fileinfo, "parameter filename") || + CCTK_Equals (out_fileinfo, "all")) { - /* get the staggering offset for the coordinates */ - for (dir = 0; dir < 3; dir++) - { - stagger_offset[dir] = CCTK_StaggerDirIndex (dir, groupinfo.stagtype) * - 0.5 * GH->cctk_delta_space[dir]; - } + buffer[0] = 0; + CCTK_ParameterFilename (sizeof (buffer), buffer); + fprintf (*file, "#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 (*file, "#Created %s ", buffer); + Util_CurrentTime (sizeof (buffer), buffer); + fprintf (*file, "%s\n", buffer); + } + if (CCTK_Equals (out_fileinfo, "axis labels") || + CCTK_Equals (out_fileinfo, "all")) + { + fprintf (*file, "#z-label %s\n", advertised_file.varname); + } - /* print out header */ - fprintf (*file, header_fmt_string, GH->cctk_time); + /* store file desriptors in database */ + StoreNamedData (&myGH->fileList_3D, alias, file); + + free (filename); + + return (*file); +} - switch (groupinfo.vartype) - { - case CCTK_VARIABLE_CHAR: - OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_BYTE, int, - data, have_coords, 0, data_fmt_string_int, *file); - break; - - case CCTK_VARIABLE_INT: - OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_INT, int, - data, have_coords, 0, data_fmt_string_int, *file); - break; - - case CCTK_VARIABLE_REAL: - case CCTK_VARIABLE_COMPLEX: - OUTPUT_TYPED_DATA (hsize, coord_data, stagger_offset, CCTK_REAL, double, - data, have_coords, - groupinfo.vartype == CCTK_VARIABLE_COMPLEX, - data_fmt_string_real, *file); - break; + +/*@@ + @routine WriteData + @date Wed 12 Dec 2001 + @author Thomas Radke + @desc + Writes the given hyperslab data into a file. + @enddesc + @@*/ +static void WriteData (int vtype, + const char *header, + char format[3][30], + const CCTK_INT hsize[3], + void *const *const hdata, + FILE *file) +{ + int is_complex; + + + if (file == NULL) + { + return; + } + + is_complex = strncmp (CCTK_VarTypeName (vtype), "CCTK_COMPLEX", 12) == 0; + + /* 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 (hsize, coord_data, stagger_offset, CCTK_INT2, int, - data, have_coords, 0, data_fmt_string_int, *file); - 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 (hsize, coord_data, stagger_offset, CCTK_INT4, int, - data, have_coords, 0, data_fmt_string_int, *file); - 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 (hsize, coord_data, stagger_offset, CCTK_INT8, int, - data, have_coords, 0, data_fmt_string_int, *file); - 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 (hsize, coord_data, stagger_offset, CCTK_REAL4, - double, data, have_coords, - groupinfo.vartype == CCTK_VARIABLE_COMPLEX8, - data_fmt_string_real, *file); - 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 (hsize, coord_data, stagger_offset, CCTK_REAL8, - double, data, have_coords, - groupinfo.vartype == CCTK_VARIABLE_COMPLEX16, - data_fmt_string_real, *file); - 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 (hsize, coord_data, stagger_offset, CCTK_REAL16, - double, data, have_coords, - groupinfo.vartype == CCTK_VARIABLE_COMPLEX32, - data_fmt_string_real, *file); - 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 (*file); - - /* free the hyperslabs */ - free (data); - for (dir = 0; dir < 3; dir++) - { - if (coord_data[dir]) - { - free (coord_data[dir]); - } - } - - } /* end of outputting the data by processor 0 */ - + else + { + CCTK_WARN (1, "Unsupported variable type"); + } - return (0); + /* keep the file open but flush it */ + fflush (file); } |