33 int nin_field = v->
nin();
34 int nex_field = v->
nex();
39 if ((nin_file == 0) || (nex_file == 0)) {
46 int size = nin_file * Lvol * nex_file;
53 vtmp.
reset(nin_field, Lvol, nex_field);
56 infile.open(filename.c_str(), std::ios::in | std::ios::binary);
58 vout.
crucial(
m_vl,
"file open failure: %s may not exist.\n", filename.c_str());
62 bool do_byteswap =
false;
70 infile.read((
char *)&flen,
sizeof(uint32_t) * 1);
77 if (flen ==
sizeof(
double) * size) {
81 uint32_t flen_s = flen;
84 if (flen_s ==
sizeof(
double) * size) {
95 const int block_size = nin_file;
96 char buf[
sizeof(double) * block_size];
98 for (
int j = 0; j < nex_file; ++j) {
99 for (
int isite = 0; isite < Lvol; ++isite) {
101 infile.read(buf,
sizeof(
double) * block_size);
114 byte_swap(buf,
sizeof(
double), block_size);
117 double *ptr = (
double *)buf;
119 for (
int i = 0; i < nin_file; ++i) {
123 vtmp.
set(s, isite, t, ptr[i]);
130 infile.read((
char *)&ftail,
sizeof(uint32_t) * 1);
153 int nin_field = v->
nin();
154 int nex_field = v->
nex();
159 if ((nin_file == 0) || (nex_file == 0)) {
160 nin_file = nin_field;
161 nex_file = nex_field;
168 vtmp.
reset(nin_field, Lvol, nex_field);
171 size_t count = nin_file * Lvol * nex_file;
178 std::ofstream outfile(filename.c_str(), std::ios::out | std::ios::binary);
184 uint32_t flen =
sizeof(double) * count;
187 outfile.write((
char *)&flen,
sizeof(uint32_t) * 1);
190 vout.
crucial(
m_vl,
"%s: io error. write record header failed.\n", __func__);
195 const int block_size = nin_file;
196 char buf[
sizeof(double) * block_size];
199 for (
int j = 0; j < nex_file; ++j) {
200 for (
int isite = 0; isite < Lvol; ++isite) {
201 double *ptr = (
double *)buf;
203 for (
int i = 0; i < nin_file; ++i) {
207 ptr[i] = vtmp.
cmp(s, isite, t);
210 outfile.write(buf,
sizeof(
double) * block_size);
220 outfile.write((
char *)&flen,
sizeof(uint32_t) * 1);
223 vout.
crucial(
m_vl,
"%s: io error. write record footer failed.\n", __func__);
239 if ((vv.size() == 0) || (filename ==
""))
return;
241 int nin_field = vv[0]->nin();
242 int nex_field = vv[0]->nex();
247 if ((nin_file == 0) || (nex_file == 0)) {
248 nin_file = nin_field;
249 nex_file = nex_field;
254 int size = nin_file * Lvol * nex_file;
261 vtmp.
reset(nin_field, Lvol, nex_field);
264 infile.open(filename.c_str(), std::ios::in | std::ios::binary);
266 vout.
crucial(
m_vl,
"file open failure: %s may not exist.\n", filename.c_str());
270 bool do_byteswap =
false;
272 for (
size_t i = 0, nrec = vv.size(); i < nrec; ++i) {
279 infile.read((
char *)&flen,
sizeof(uint32_t) * 1);
286 if (flen ==
sizeof(
double) * size) {
290 uint32_t flen_s = flen;
293 if (flen_s ==
sizeof(
double) * size) {
304 const int block_size = nin_file;
305 char buf[
sizeof(double) * block_size];
307 for (
int j = 0; j < nex_file; ++j) {
308 for (
int isite = 0; isite < Lvol; ++isite) {
310 infile.read(buf,
sizeof(
double) * block_size);
323 byte_swap(buf,
sizeof(
double), block_size);
326 double *ptr = (
double *)buf;
328 for (
int i = 0; i < nin_file; ++i) {
332 vtmp.
set(s, isite, t, ptr[i]);
339 infile.read((
char *)&ftail,
sizeof(uint32_t) * 1);
355 for (
size_t i = 0, nrec = vv.size(); i < nrec; ++i) {
367 if ((vv.size() == 0) || (filename ==
""))
return;
369 int nin_field = vv[0]->nin();
370 int nex_field = vv[0]->nex();
375 if ((nin_file == 0) || (nex_file == 0)) {
376 nin_file = nin_field;
377 nex_file = nex_field;
381 size_t count = nin_file * Lvol * nex_file;
386 vtmp.
reset(nin_field, Lvol, nex_field);
392 std::ofstream outfile(filename.c_str(), std::ios::out | std::ios::binary);
398 for (
size_t i = 0, nrec = vv.size(); i < nrec; ++i) {
401 uint32_t flen =
sizeof(double) * count;
404 outfile.write((
char *)&flen,
sizeof(uint32_t) * 1);
407 vout.
crucial(
m_vl,
"%s: io error. write record header failed.\n", __func__);
412 const int block_size = nin_file;
413 char buf[
sizeof(double) * block_size];
415 for (
int j = 0; j < nex_file; ++j) {
416 for (
int isite = 0; isite < Lvol; ++isite) {
417 double *ptr = (
double *)buf;
419 for (
int i = 0; i < nin_file; ++i) {
423 ptr[i] = vtmp.
cmp(s, isite, t);
426 outfile.write(buf,
sizeof(
double) * block_size);
436 outfile.write((
char *)&flen,
sizeof(uint32_t) * 1);
439 vout.
crucial(
m_vl,
"%s: io error. write record footer failed.\n", __func__);
446 for (
size_t i = 0, nrec = vv.size(); i < nrec; ++i) {
static void byte_swap(void *buf, size_t size, size_t nmemb)
< convert byte order. alternative interface.
void detailed(const char *format,...)
static void abort()
terminate communicator
void set(const int jin, const int site, const int jex, double v)
void deliver(Field *vlocal, Field *vglobal)
distribute data on primary node over parallel nodes.
Container of Field-type object.
double cmp(const int jin, const int site, const int jex) const
void read_file(Field *v, std::string filename)
read data from file.
static const std::string class_name
void reset(const int Nin, const int Nvol, const int Nex, const element_type cmpl=COMPLEX)
const IO_Format::Format * m_format
void crucial(const char *format,...)
void write_file(Field *v, std::string filename)
write data to file.
static bool is_primary()
check if the present node is primary in small communicator.
void gather(Field *vglobal, Field *vlocal)
gather data on parallel nodes to primary node.
Bridge::VerboseLevel m_vl