aboutsummaryrefslogtreecommitdiff
path: root/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc
diff options
context:
space:
mode:
authorcott <>2004-01-12 08:50:00 +0000
committercott <>2004-01-12 08:50:00 +0000
commit42aba9fa4095963646be9770e879ffd62c4691d6 (patch)
treec1ba31adf0a6572799e55aea22509ebdd5c428af /CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc
parent29c34c256c04683b6958a6ab7d10fbb6df1a1b5a (diff)
Mostly code beautification. Incorporated Erik's new WriteAttribute
Mostly code beautification. Incorporated Erik's new WriteAttribute functions and changed the way CarpetIOFlexIO writes dataset attributes. All the functionality provided in CarpetIOFlexIO is now provided. darcs-hash:20040112085031-19929-ce03ec0298a148bc14855d0db33cfa50ce59e681.gz
Diffstat (limited to 'CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc')
-rw-r--r--CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc191
1 files changed, 91 insertions, 100 deletions
diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc
index 17d2c699a..1342cbfa5 100644
--- a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc
+++ b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc
@@ -30,10 +30,6 @@
#undef BYTE
#undef CHAR
-//#include "CactusBase/IOUtil/src/ioGH.h"
-//#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h"
-//#include "CactusBase/IOUtil/src/ioutil_Utils.h"
-
#include "bbox.hh"
#include "data.hh"
#include "gdata.hh"
@@ -50,9 +46,9 @@ namespace CarpetIOFlexIOUtil {
using namespace Carpet;
using namespace CarpetIOFlexIO;
-IObase::DataType FlexIODataType (int cctk_type){
- //we need this to have the FlexIO data types on hand
- //for WriteGFAs
+ IObase::DataType FlexIODataType (int cctk_type){
+ //we need this to have the FlexIO data types on hand
+ //for WriteGFAs
int retval;
@@ -90,107 +86,102 @@ IObase::DataType FlexIODataType (int cctk_type){
}
-void DumpCommonAttributes (const cGH *cgh, IObase* writer, ioRequest* request)
-{
- int dim, vdim, tl;
- CCTK_INT attr_int,dimscalar;
- CCTK_REAL *attr_real;
- char coord_system_name[20];
- DECLARE_CCTK_PARAMETERS
-
- /* attributes describing the variable */
- char* groupname = CCTK_GroupNameFromVarI (request->vindex);
-
-
-//
- char *name = CCTK_FullName (request->vindex);
- writer->writeAttribute("name",IObase::Char,strlen(name)+1,name);
- free(name);
+ void DumpCommonAttributes (const cGH *cgh, IObase* writer, ioRequest* request)
+ {
+ int tl;
+ CCTK_INT attr_int,dimscalar;
+ DECLARE_CCTK_PARAMETERS;
+
+ /* attributes describing the variable */
+
+ char *name = CCTK_FullName (request->vindex);
+ WriteAttribute(writer,"name",name);
+ free(name);
+
+ char* groupname = CCTK_GroupNameFromVarI (request->vindex);
+ WriteAttribute(writer,"groupname",groupname);
+ free (groupname);
-
- //fprintf(stderr,"\nattrib %s\n",groupname);
- writer->writeAttribute("groupname",IObase::String,strlen(groupname)+1,groupname);
- free (groupname);
-
- CCTK_INT attr_int = CCTK_GroupTypeFromVarI (request->vindex);
- writer->writeAttribute("grouptype",FlexIODataType(CCTK_VARIABLE_INT),1,&attr_int);
-
- writer->writeAttribute("reflevel",FlexIODataType(CCTK_VARIABLE_INT),1,&reflevel);
- writer->writeAttribute("component",FlexIODataType(CCTK_VARIABLE_INT),1,&component);
- writer->writeAttribute("mglevel",FlexIODataType(CCTK_VARIABLE_INT),1,&mglevel);
-
-
- attr_int = CCTK_MaxTimeLevelsVI (request->vindex);
- writer->writeAttribute("ntimelevels",FlexIODataType(CCTK_VARIABLE_INT),1,&attr_int);
-
- // lets get the correct Carpet time level (which is the (-1) * timelevel):
- if (request->timelevel==0)
- tl = 0;
- else
+ WriteAttribute(writer,"grouptype",CCTK_GroupTypeFromVarI (request->vindex));
+ WriteAttribute(writer,"reflevel",reflevel);
+ WriteAttribute(writer,"component",component);
+ WriteAttribute(writer,"mglevel",mglevel);
+
+
+ WriteAttribute (writer,"ntimelevels",CCTK_MaxTimeLevelsVI (request->vindex));
+
+ // lets get the correct Carpet time level (which is the (-1) * timelevel):
+ if (request->timelevel==0)
+ tl = 0;
+ else
tl = - request->timelevel;
-
- writer->writeAttribute("timelevel",FlexIODataType(CCTK_VARIABLE_INT),1,&tl);
-
- /* we have to do below since cactus believes scalars have dimension 0, but
- flexio likes them to be of dimension 1
- */
-
- if(CCTK_GroupTypeFromVarI(request->vindex) == CCTK_SCALAR) {
- dimscalar=1;
- writer->writeAttribute("global_size",FlexIODataType(CCTK_VARIABLE_INT),1,&dimscalar);
+ WriteAttribute (writer, "timelevel", tl);
+
+ WriteAttribute (writer, "carpet_flexio_version", 1);
+ WriteAttribute (writer, "cctk_dim", cgh->cctk_dim);
+ WriteAttribute (writer, "cctk_iteration", cgh->cctk_iteration);
+ WriteAttribute (writer, "cctk_gsh", cgh->cctk_gsh, dim);
+ WriteAttribute (writer, "cctk_lsh", cgh->cctk_lsh, dim);
+ WriteAttribute (writer, "cctk_lbnd", cgh->cctk_lbnd, dim);
+ WriteAttribute (writer, "cctk_delta_time", cgh->cctk_delta_time);
+ WriteAttribute (writer, "cctk_delta_space", cgh->cctk_delta_space, dim);
+ WriteAttribute (writer, "cctk_origin_space", cgh->cctk_origin_space, dim);
+ WriteAttribute (writer, "cctk_bbox", cgh->cctk_bbox, 2*dim);
+ WriteAttribute (writer, "cctk_levfac", cgh->cctk_levfac, dim);
+ WriteAttribute (writer, "cctk_levoff", cgh->cctk_levoff, dim);
+ WriteAttribute (writer, "cctk_levoffdenom", cgh->cctk_levoffdenom, dim);
+ WriteAttribute (writer, "cctk_timefac", cgh->cctk_timefac);
+ WriteAttribute (writer, "cctk_convlevel", cgh->cctk_convlevel);
+ WriteAttribute (writer, "cctk_nghostzones", cgh->cctk_nghostzones, dim);
+ WriteAttribute (writer, "cctk_time", cgh->cctk_time);
}
- else
- writer->writeAttribute("global_size",FlexIODataType(CCTK_VARIABLE_INT),request->hdim,request->hsize);
-
-
-
-
-
- // already dumped by amrwriter (obsolete!)
- writer->writeAttribute("cctk_time",FlexIODataType(CCTK_VARIABLE_REAL),1,&cgh->cctk_time);
-
- /* attributes describing the underlying grid
- These are only stored for CCTK_GF variables if they are associated
- with coordinates. */
- /* FIXME: This is hardcoded for cartesian coordinate systems.
- A better solution would be to be able to query the coordinate
- system which is associated with the variable. */
- vdim = CCTK_GroupDimFromVarI (request->vindex);
- sprintf (coord_system_name, "cart%dd", vdim);
-
- /* this is already dumped by amrwriter or */
-#if 0
- /*
- if (CCTK_GroupTypeFromVarI (request->vindex) == CCTK_GF &&
- CCTK_CoordSystemHandle (coord_system_name) >= 0)
+
+ void WriteAttribute (IObase* writer, const char* name, int value)
+ {
+ WriteAttribute (writer, name, &value, 1);
+ }
+
+ void WriteAttribute (IObase* writer, const char* name,
+ const int* values, int nvalues)
{
- attr_real = (CCTK_REAL*) malloc (3 * vdim * sizeof (CCTK_REAL));
- for (dim = 0; dim < vdim; dim++)
- {
- CCTK_CoordRange (cgh, &attr_real[dim], &attr_real[dim + vdim], dim + 1,
- NULL, coord_system_name);
-
- attr_real[dim + 0*vdim] +=
- request->origin[dim] * cgh->cctk_delta_space[dim];
- attr_real[dim + 2*vdim] =
- cgh->cctk_delta_space[dim] * request->downsample[dim];
- attr_real[dim + 1*vdim] = attr_real[dim + 0*vdim] +
- ((request->extent[dim] + request->downsample[dim]-1) /
- request->downsample[dim] - 1) * attr_real[dim + 2*vdim];
+ assert (writer);
+ assert (name);
+ assert (values);
+ vector<CCTK_INT4> values1(nvalues);
+ for (int i=0; i<nvalues; ++i) {
+ values1[i] = values[i];
}
-
- writer->writeAttribute ("origin", FlexIODataType(CCTK_VARIABLE_REAL), vdim, attr_real);
- writer->writeAttribute ("min_ext", FlexIODataType(CCTK_VARIABLE_REAL), vdim, attr_real);
- writer->writeAttribute ("max_ext", FlexIODataType(CCTK_VARIABLE_REAL), vdim, attr_real+vdim);
- writer->writeAttribute ("delta", FlexIODataType(CCTK_VARIABLE_REAL), vdim, attr_real+2*vdim);
- free (attr_real);
- }
- */
-#endif
-
+ writer->writeAttribute (name, IObase::Int32, nvalues, &values1[0]);
+ }
+
+ void WriteAttribute (IObase* writer, const char* name, CCTK_REAL value)
+ {
+ WriteAttribute (writer, name, &value, 1);
+ }
+
+ void WriteAttribute (IObase* writer, const char* name,
+ const CCTK_REAL* values, int nvalues)
+ {
+ assert (writer);
+ assert (name);
+ assert (values);
+ vector<CCTK_REAL8> values1(nvalues);
+ for (int i=0; i<nvalues; ++i) {
+ values1[i] = values[i];
+ }
+ writer->writeAttribute (name, IObase::Float64, nvalues, &values1[0]);
}
+ void WriteAttribute (IObase* writer, const char* name,
+ const char* valuestring)
+ {
+ assert (writer);
+ assert (name);
+ assert (valuestring);
+ writer->writeAttribute (name, IObase::String, strlen(valuestring)+1, valuestring);
+ }
+
} // namespace CarpetIOFlexIOUtil