move the rb mode to the overloaded open_file function
This commit is contained in:
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
// only proc 0 calls methods of this class, except for constructor/destructor
|
// only proc 0 calls methods of this class, except for constructor/destructor
|
||||||
@ -44,18 +42,7 @@ void Reader::open_file(const std::string &file)
|
|||||||
if (!fp) error->one(FLERR,"Cannot open compressed file for reading");
|
if (!fp) error->one(FLERR,"Cannot open compressed file for reading");
|
||||||
} else {
|
} else {
|
||||||
compressed = 0;
|
compressed = 0;
|
||||||
|
fp = fopen(file.c_str(),"r");
|
||||||
// leleslx: if there is .bin ending
|
|
||||||
std::size_t dot = file.find_last_of('.');
|
|
||||||
char reading_mode[3] = "r";
|
|
||||||
if (dot != std::string::npos) {
|
|
||||||
const std::string ext = file.substr(dot + 1);
|
|
||||||
if ("bin" == ext){
|
|
||||||
sprintf(reading_mode, "rb");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fp = fopen(file.c_str(), reading_mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fp) error->one(FLERR,"Cannot open file {}: {}", file, utils::getsyserror());
|
if (!fp) error->one(FLERR,"Cannot open file {}: {}", file, utils::getsyserror());
|
||||||
|
|||||||
@ -43,6 +43,23 @@ ReaderNativeBin::~ReaderNativeBin()
|
|||||||
memory->destroy(fieldindex);
|
memory->destroy(fieldindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
overload the open_file function to open the binary file
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
void ReaderNativeBin::open_file(const std::string &file)
|
||||||
|
{
|
||||||
|
if (fp != nullptr) close_file();
|
||||||
|
|
||||||
|
if (platform::has_compress_extension(file)) {
|
||||||
|
error->one(FLERR,"Compressed binary files are not supported");
|
||||||
|
} else {
|
||||||
|
compressed = 0;
|
||||||
|
fp = fopen(file.c_str(), "rb");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fp) error->one(FLERR,"Cannot open file {}: {}", file, utils::getsyserror());
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
read and return time stamp from dump file
|
read and return time stamp from dump file
|
||||||
if first read reaches end-of-file, return 1 so caller can open next file
|
if first read reaches end-of-file, return 1 so caller can open next file
|
||||||
|
|||||||
@ -38,14 +38,16 @@ class ReaderNativeBin : public ReaderNative {
|
|||||||
bigint read_header(double[3][3], int &, int &, int, int, int *, char **, int, int, int &, int &,
|
bigint read_header(double[3][3], int &, int &, int, int, int *, char **, int, int, int &, int &,
|
||||||
int &, int &);
|
int &, int &);
|
||||||
void read_atoms(int, int, double **);
|
void read_atoms(int, int, double **);
|
||||||
|
void open_file(const std::string &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int revision;
|
int revision;
|
||||||
char *magic_string;
|
char *magic_string;
|
||||||
char *unit_style;
|
char *unit_style;
|
||||||
int size_one;
|
|
||||||
int maxbuf = 1;
|
int size_one; // number of double for one atom
|
||||||
double *buf;
|
double *buf;
|
||||||
|
int maxbuf = 1; // maximum buffer size
|
||||||
|
|
||||||
void read_buf(void *, size_t, size_t);
|
void read_buf(void *, size_t, size_t);
|
||||||
void read_double_chunk(size_t);
|
void read_double_chunk(size_t);
|
||||||
|
|||||||
Reference in New Issue
Block a user