Writers.h¶
Classes for writing time-dependent text output files.
These classes produce the files in the data
directory
For a description of the output files, see Output Files.
-
class
WriterBase
¶ - #include <Writers.h>
Common functions for scalar and array writers.
This class is not instantiated directly, only it’s children are.
- See
- ScalarWriter
- See
- ArrayWriter.
Subclassed by ArrayWriter, ScalarWriter
Protected Functions
-
void
storeType
(double *x)¶ Store a char (d) representing the type of
*x
intypeArray
.
-
void
storeType
(int *x)¶ Store a char (i) representing the type of
*x
intypeArray
.
-
void
setOutputDir
(const char *path)¶
-
void
createDataDir
()¶ Create data directory if it doesn’t already exist.
-
void
getFmtStr
(char *fmt, double *dataPtr)¶ Get format string, e.g. ‘%15.6f’.
-
void
getFmtStr
(char *fmt, int *dataPtr)¶ Get format string, e.g. ‘%15d’.
-
void
getFmtStr
(char *fmt, const char *dataPtr)¶ Get format string, e.g. ‘%15s’.
-
void
deleteFmtStrs
()¶
Protected Attributes
-
char
outputDir
[256]¶ - See
- Options::outLoc
-
char
path
[256]¶
-
bool
leftJustify
¶ Whether to left-justify output data.
-
int
numQuantities
¶ Number of quantities to be written.
-
vector<void *>
dataPtrArray
¶ Pointers to actual output quantity data.
-
vector<char>
typeArray
¶ char
s representing output quantity types
-
vector<const char *>
quantityNameArray
¶ Labels for output quantities.
-
vector<const char *>
fmtArray
¶ Format strings (e.g. ‘%15.6f’) for output quantities.
-
char
line
[2048]¶ Maximum line length is 2047 characters (last element is null).
-
class
ScalarWriter
: public WriterBase¶ - #include <Writers.h>
Write single column scalar data.
See Data Directory.
Public Functions
-
ScalarWriter
(DumpfileReader &dumpfileReader, Droplet &droplet)¶ Save appropriate pointers, left justify scalar data, set output quantities, and write appropriate headers.
-
~ScalarWriter
()¶
-
FILE *
openFileBase
(const char *filename)¶ Open a file at Options::outLoc/data/
filename
.
-
void
openFile
(const char *quantityName)¶ Call openFileBase and store the
FILE*
in files.
-
void
setOutputQuantities
()¶ Call addQuantity for each quantity of interest.
If you’d like to add a new output file or modify file names, this is the place to do so.
A quantity name and pointer to the quantity are given for each.
- See
- addQuantity
-
void
getQuantityStr
(char *quantityStr, int i)¶ Get the formatted data for this quantity.
Since dataPtrArray is a vector of void pointers, this function checks typeArray in order to know how to appropriately dereference the pointer.
Also, values larger than
1e20
are replaced with “INF” (formatted as the quantity would have been).- Parameters
quantityStr
: Final formatted quantity string.i
: Index of the quantity.
-
void
writeHeaders
()¶ Write the quantity name to the first line of each file, with ‘#’ prepended.
-
void
writeFrame
()¶ Write the values of all scalar quantities to the appropriate files.
FILE*
s are flushed after each write.
-
template <typename T>
voidaddQuantity
(const char *quantityName, T *dataPtr)¶ Register a scalar quantity to be written to an output file.
A pointer to the data must be given since the value will presumably change over time.
- Note
- For some reason, this template function must be fully defined in header file.
- See
- http://www.cplusplus.com/forum/general/114299/
- See
- https://stackoverflow.com/questions/10632251/undefined-reference-to-template-function
- Parameters
quantityName
: Name of the quantitydataPtr
: Pointer to the data
Private Members
-
vector<FILE *>
files
¶ All of the files being written to each timestep.
-
DumpfileReader *
dumpfileReaderPtr
¶
-
-
class
ArrayWriter
: public WriterBase¶ - #include <Writers.h>
Write multi-column array data.
See Data Directory.
Public Functions
-
ArrayWriter
(DumpfileReader &dumpfileReader, Droplet &droplet)¶ Save appropriate pointers, left justify scalar data, and set output quantities.
-
~ArrayWriter
()¶
-
void
writeHeaders
()¶
-
void
writeFrame
()¶
-
template <typename T>
voidaddQuantity
(const char *quantityName, T **dataPtr, int *lengthPtr, char **headers, int numColumns)¶ Register an array quantity to be written to a new output file each timestep.
Pointers to the data and number of rows must be given since their values will presumably change over time.
- Note
- For some reason, this template function must be fully defined in header file.
- See
- http://www.cplusplus.com/forum/general/114299/
- See
- https://stackoverflow.com/questions/10632251/undefined-reference-to-template-function
- Parameters
quantityName
: Name of the quantity.dataPtr
: Pointer to the data (may vary over time).lengthPtr
: Pointer to the number of rows in the array (may vary over time).headers
: Pointer to array of column headers (e.g. {“x”, “y”}).numColumns
: Number of columns in the array (assumed constant over time).
Private Functions
-
void
setOutputQuantities
()¶ Call addQuantity for each quantity of interest.
If you’d like to add a new output file or modify file names, this is the place to do so.
Each quantity requires:
- A quantity name, a pointer to the data array,
- a pointer to the number of rows,
- a pointer to the array of header strings,
- the number of columns.
Currently, only
boundaryPoints
(CircularBulk::boundaryPointsArray) is written in this manner.- See
- addQuantity
-
void
getQuantityStr
(char *quantityStr, int quantityNum, int i, int j)¶ Get the formatted data for one element in the array quantity.
Since dataPtrArray is a vector of void pointers, this function checks typeArray in order to know how to appropriately dereference the pointer.
Also, values larger than
1e20
are replaced with “INF” (formatted as the quantity would have been).- Parameters
quantityStr
: Final formatted string for this element.quantityNum
: Index of the quantity.i
: Row number of this element.j
: Column number of this element.
-
void
concatenateQuantityStrs
(int quantityNum, int i)¶ Join individual quantity strings to form a row.
Final formatted quantity string is appended to line.
- Parameters
quantityNum
: Index of the quantity.i
: Row number of the quantity
-
void
createQuantityDir
(const char *quantityName)¶ Create Options::outLoc/data/
quantityName
if it doesn’t alread exist.
-
void
getFilePath
(char *filePath, const char *quantityName)¶ Get the path to the quantity file for the current timestep.
- Parameters
filePath
: Final path to quantity file for this timestep.quantityName
: Name of this quantity
-
void
writeHeader
(FILE *file, int quantityNum)¶ Write column headers to the first line of the file.
-
void
writeQuantityFile
(int i)¶ Write the array data for quantity
i
to the appropriate file for this timestep.
Private Members
-
DumpfileReader *
dumpfileReaderPtr
¶
-
vector<int>
numColumnsArray
¶ The number of columns in each quantity.
-
vector<int *>
lengthPtrArray
¶ A pointer to the number of rows of data, which may change from one step to the next.
-
vector<char **>
headersArray
¶ A pointer to an array of headers whose length is defined by the corresponding element of numColumnsArray.
-