20 #ifndef JDFTX_CORE_SCALARFIELDIO_H 21 #define JDFTX_CORE_SCALARFIELDIO_H 34 #define Tptr std::shared_ptr<T> 38 {
int nWrote =
fwriteLE(X->data(),
sizeof(
typename T::DataType), X->nElem, fp);
39 if(nWrote < X->nElem)
die(
"Write failed after %d of %d records.\n", nWrote, X->nElem)
42 template<
typename T>
void saveRawBinary(
const Tptr& X,
const char* filename)
43 { FILE* fp = fopen(filename,
"wb");
44 if(!fp)
die(
"Could not open '%s' for writing.\n", filename)
51 {
int nRead =
freadLE(X->data(),
sizeof(
typename T::DataType), X->nElem, fp);
52 if(nRead < X->nElem)
die(
"Read failed after %d of %d records.\n", nRead, X->nElem)
56 { FILE* fp = fopen(filename,
"rb");
57 if(!fp)
die(
"Could not open '%s' for reading.\n", filename)
60 off_t expectedLen =
sizeof(
typename T::DataType) * X->nElem;
61 if(fLen != expectedLen)
62 {
die(
"\nLength of '%s' was %ld instead of the expected %ld bytes.\n" 63 "Hint: Are you really reading the correct file?\n\n",
64 filename, (
unsigned long)fLen, (
unsigned long)expectedLen);
106 #endif // JDFTX_CORE_SCALARFIELDIO_H
void loadRawBinary(Tptr &X, FILE *fp)
Load the data in raw binary format from stream.
Definition: ScalarFieldIO.h:50
std::shared_ptr< ScalarFieldTildeData > ScalarFieldTilde
A smart reference-counting pointer to ScalarFieldTildeData.
Definition: ScalarField.h:45
off_t fileSize(const char *filename)
Get the size of a file.
size_t freadLE(void *ptr, size_t size, size_t nmemb, FILE *fp)
Read from a little-endian binary file, regardless of operating endianness.
Real and complex scalar fields in real and reciprocal space.
void saveSphericalized(const ScalarField *dataR, int nColumns, const char *filename, double drFac=1.0, vector3<> *center=0)
size_t fwriteLE(const void *ptr, size_t size, size_t nmemb, FILE *fp)
Write to a little-endian binary file, regardless of operating endianness.
void saveDX(const ScalarField &, const char *filenamePrefix)
void saveRawBinary(const Tptr &X, FILE *fp)
Save the data in raw binary format to stream.
Definition: ScalarFieldIO.h:37
#define die(...)
Quit with an error message (formatted using printf()). Must be called from all processes.
Definition: Util.h:114
std::shared_ptr< ScalarFieldData > ScalarField
A smart reference-counting pointer to ScalarFieldData.
Definition: ScalarField.h:41
std::vector< std::vector< double > > sphericalize(const ScalarField *dataR, int nColumns, double drFac=1.0, vector3<> *center=0)