46 int iomode,
const char *typestr) {
57 int iomode,
const char *typestr) {
66 const char *typestr,
int iomode) {
71 Ippl::abort(
"IO mode for DiscParticle must be INPUT, OUTPUT, or APPEND.");
120 unsigned int attrib)
const {
123 attrib <
RecordList[record]->disctypes.size())
124 return (
RecordList[record]->disctypes[attrib].c_str());
134 unsigned int retval = 0;
135 for (
unsigned int i=0; i <
RecordList[record]->localparticles.size(); ++i)
136 retval +=
RecordList[record]->localparticles[i];
148 FILE *f = fopen(fnm.c_str(), mode.c_str());
151 if (f == 0 && reporterr) {
152 ERRORMSG(
"DiscParticle: Could not open file '" << fnm.c_str());
179 ERRORMSG(
"Bad config file in DiscParticle::write_meta." <<
endl);
182 ERRORMSG(
"Trying to write a DiscParticle .meta file for a DiscParticle");
186 ERRORMSG(
"Only one fileset/SMP max allowed when writing" <<
endl);
196 FILE *outputMeta =
open_file(filename, std::string(
"w"));
202 fprintf(outputMeta,
"Type = %s\n",
TypeString.c_str());
204 fprintf(outputMeta,
"Records = %ld\n", rnum);
208 for (
unsigned int r=0; r <
RecordList.size(); ++r) {
210 fprintf(outputMeta,
"RecordAttribs = %u %d\n", r,
212 fprintf(outputMeta,
"RecordLocPtcl = %u %d\n", r,
214 fprintf(outputMeta,
"RecordGlobPtcl = %u %d\n", r,
218 fprintf(outputMeta,
"RecordElemByte = %u ", r);
221 for (b=0; b<bmax; ++b)
222 fprintf(outputMeta,
" %d",
RecordList[r]->bytesize[b]);
223 fprintf(outputMeta,
"\n");
224 fprintf(outputMeta,
"RecordDiscType = %u ", r);
225 for (b=0; b<bmax; ++b)
226 fprintf(outputMeta,
" %s",
RecordList[r]->disctypes[b].c_str());
227 fprintf(outputMeta,
"\n");
228 fprintf(outputMeta,
"RecordOffset = %u ", r);
230 for (b=0; b<bmax; ++b)
231 fprintf(outputMeta,
" %ld",
RecordList[r]->offset[0][b]);
232 fprintf(outputMeta,
"\n");
249 ERRORMSG(
"Bad config file in DiscParticle::read_meta." <<
endl);
253 bool iserror =
false;
272 DiscMeta outputMeta(filename.c_str());
273 if (outputMeta.
size() == 0)
278 for ( ; metaline != outputMeta.
end(); ++metaline) {
280 int linesread = (*metaline).first;
281 int numtokens = (*metaline).second.first;
282 std::string *tokens = (*metaline).second.second;
285 if (tokens[0] ==
"Type") {
286 if (numtokens > 1 && sf == 0)
288 }
else if (tokens[0] ==
"SMPs" && numtokens == 2) {
289 unsigned int checkfileSMPs = atoi(tokens[1].c_str());
291 ERRORMSG(
"SMP number mismatch in file " << filename);
296 }
else if (tokens[0] ==
"NextOffset" && numtokens == 2) {
298 }
else if (tokens[0] ==
"Records" && numtokens == 2) {
299 unsigned int numrec = atoi(tokens[1].c_str());
301 ERRORMSG(
"Illegal Records value in file '" << filename <<
"' ");
307 for (
int r=0; r < atoi(tokens[1].c_str()); ++r)
310 }
else if (tokens[0] ==
"RecordAttribs" && numtokens == 3) {
311 unsigned int recnum = atoi(tokens[1].c_str());
312 int attribs = atoi(tokens[2].c_str());
314 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
316 }
else if (sf > 0 && attribs !=
RecordList[recnum]->attributes) {
317 ERRORMSG(
"Illegal number of attributes in file " << filename);
318 ERRORMSG(
" (" << attribs <<
" != ");
324 }
else if (tokens[0] ==
"RecordLocPtcl" && numtokens == 3) {
325 unsigned int recnum = atoi(tokens[1].c_str());
326 int nump = atoi(tokens[2].c_str());
328 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
331 RecordList[recnum]->localparticles.push_back(nump);
333 }
else if (tokens[0] ==
"RecordGlobPtcl" && numtokens == 3) {
334 unsigned int recnum = atoi(tokens[1].c_str());
335 int nump = atoi(tokens[2].c_str());
337 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
339 }
else if (sf > 0 && nump !=
RecordList[recnum]->globalparticles) {
340 ERRORMSG(
"Illegal number of global particles in file "<<filename);
347 }
else if (tokens[0] ==
"RecordElemByte" && numtokens >= 2) {
348 unsigned int recnum = atoi(tokens[1].c_str());
350 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
353 for (
int b=2; b < numtokens; ++b) {
354 int bytesize = atoi(tokens[b].c_str());
355 if (sf > 0 && bytesize !=
RecordList[recnum]->bytesize[b-2]) {
356 ERRORMSG(
"Illegal byte size for attribute " << b-2);
357 ERRORMSG(
" in file " << filename <<
"(" << bytesize);
361 }
else if (sf == 0) {
362 RecordList[recnum]->bytesize.push_back(bytesize);
367 static_cast<unsigned int>(
RecordList[recnum]->attributes))) {
368 ERRORMSG(
"Incorrect number of byte size values in file ");
373 }
else if (tokens[0] ==
"RecordDiscType" && numtokens >= 2) {
374 unsigned int recnum = atoi(tokens[1].c_str());
376 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
379 for (
int b=2; b < numtokens; ++b) {
380 if (sf > 0 && tokens[b] !=
RecordList[recnum]->disctypes[b-2]) {
381 ERRORMSG(
"Inconsistent DiscType for attribute " << b-2);
382 ERRORMSG(
" in file " << filename <<
"(" << tokens[b]);
386 }
else if (sf == 0) {
387 RecordList[recnum]->disctypes.push_back(tokens[b]);
392 static_cast<unsigned int>(
RecordList[recnum]->attributes))) {
393 ERRORMSG(
"Incorrect number of DiscType values in file ");
398 }
else if (tokens[0] ==
"RecordOffset" && numtokens >= 2) {
399 unsigned int recnum = atoi(tokens[1].c_str());
401 ERRORMSG(
"Illegal record number '" << recnum <<
"'" <<
endl);
404 std::vector<Offset_t> offsetvec;
405 for (
int b=2; b < numtokens; ++b) {
406 Offset_t offset = atol(tokens[b].c_str());
407 if (sf > 0 && offset !=
RecordList[recnum]->offset[sf][b-2]) {
408 ERRORMSG(
"Illegal offset for attribute " << b-2);
409 ERRORMSG(
" in file " << filename <<
"(");
410 ERRORMSG(
static_cast<long>(offset) <<
" != ");
414 }
else if (sf == 0) {
415 offsetvec.push_back(offset);
419 if (offsetvec.size() != (
RecordList[recnum]->attributes==0 ? 1u :
420 static_cast<unsigned int>(
RecordList[recnum]->attributes))) {
421 ERRORMSG(
"Incorrect number of offset values in file ");
425 RecordList[recnum]->offset.push_back(offsetvec);
436 ERRORMSG(
"Format error on line " << linesread <<
" in file ");
449 for (
int s=0; s <= numinform; ++s) {
459 int errint = iserror;
466 for (
unsigned int r=0; r <
RecordList.size(); ++r) {
467 int filesnum =
RecordList[r]->localparticles.size();
471 for (
unsigned int p=0; p <
RecordList[r]->localparticles.size(); ++p)
473 for (
unsigned int b=0; b <
RecordList[r]->bytesize.size(); ++b)
477 std::string unknowndtype =
"u";
478 for (
unsigned int dr =
RecordList[r]->disctypes.size();
480 RecordList[r]->disctypes.push_back(unknowndtype);
482 for (
unsigned int t=0; t <
RecordList[r]->bytesize.size(); ++t)
484 for (
unsigned int z=0; z <
RecordList[r]->offset.size(); ++z) {
485 for (
unsigned int o=0; o <
RecordList[r]->offset[z].size(); ++o) {
508 int errint = 0, numrec = 0, val = 0;
510 iserror = (errint != 0);
516 for (
int r=0; r < numrec; ++r) {
518 int filesnum =
RecordList[r]->localparticles.size();
525 for (
int p=0; p < filesnum; ++p) {
529 for (
int b=0; b < numattr; ++b) {
533 for (
int t=0; t < numattr; ++t) {
538 for (
int z=0; z < filesnum; ++z) {
539 std::vector<Offset_t> offsetvec;
542 for (
int o=0; o < numattr; ++o) {
545 offsetvec.push_back(offset);
575 std::vector<int> numvec;
576 std::vector<Offset_t> offsetvec;
582 ERRORMSG(
" in .data file for DiscParticle::write_data." <<
endl);
588 int numattr =
info->attributes;
591 for (
int a=0;
a < numattr; ++
a) {
595 for (
unsigned int n=0;
n < msgvec.size(); ++
n) {
600 msgvec[
n]->get(nump);
601 numvec.push_back(nump);
609 void *msgdata = msgvec[
n]->remove();
612 unsigned int totalbytes = nump *
info->bytesize[
a];
613 if (fwrite(msgdata, 1, totalbytes, outputData) != totalbytes) {
614 ERRORMSG(
"Write error in DiscParticle::write_data" <<
endl);
628 if ((
a+1) == numattr)
634 info->offset.push_back(offsetvec);
635 info->localparticles.push_back(totalnum);
646 unsigned int record,
unsigned int fileset) {
650 int nump =
RecordList[record]->localparticles[fileset];
651 int bytesize =
RecordList[record]->bytesize[attrib];
654 if (nump < 1 || bytesize < 1)
660 if (fseek(outputData, seekpos, SEEK_SET) != 0) {
661 ERRORMSG(
"Error seeking to position " <<
static_cast<long>(seekpos));
662 ERRORMSG(
" in .data file for DiscParticle::read_data." <<
endl);
669 unsigned int totalbytes = nump * bytesize;
670 void *buffer = malloc(totalbytes);
673 if (fread(buffer, 1, totalbytes, outputData) != totalbytes) {
674 ERRORMSG(
"Read error in DiscParticle::read_data" <<
endl);
697 msg <<
"For record " << r <<
":" <<
endl;
700 msg <<
" Byte size of attributes =";
704 msg <<
" DiscTypes of attributes =";
711 msg <<
" Local number of particles in fileset " << f <<
" = ";
714 msg <<
" Offset of attribute " <<
a <<
" in fileset " << f <<
" = ";
720 msg <<
"Configuration file information:" <<
endl;
void putMessage(Message &m, const T &t)
void getMessage(Message &m, T &t)
Inform & endl(Inform &inf)
std::string::iterator iterator
bool send(Message *, int node, int tag, bool delmsg=true)
Message * receive_block(int &node, int &tag)
Message & put(const T &val)
Message & get(const T &cval)
int next_tag(int t, int s=1000)
const std::string & getFilename(unsigned int fn) const
unsigned int getOtherSMP(unsigned int sn) const
unsigned int getSMPBox0() const
unsigned int fileSMPs() const
unsigned int getNumOtherSMP() const
unsigned int getSMPNode(unsigned int n) const
unsigned int getNumSMPNodes() const
unsigned int mySMP() const
void printDebug(Inform &)
unsigned int getNumFiles() const
unsigned int size() const
container_t::iterator iterator
std::vector< RecordInfo * > RecordList
unsigned int get_NumLocalParticles(unsigned int record=0) const
DiscParticle(const char *fname, const char *config, int iomode, const char *typestr=0)
unsigned int get_NumRecords() const
bool write_data(FILE *outputData, std::vector< Message * > &, RecordInfo *)
unsigned int get_ElemByteSize(unsigned int record=0, unsigned int attrib=0) const
unsigned int get_NumAttributes(unsigned int record=0) const
FILE * open_file(const std::string &fnm, const std::string &mode, bool reporterr=true)
unsigned int get_NumGlobalParticles(unsigned int record=0) const
void * read_data(FILE *outputData, unsigned int attrib, unsigned int record, unsigned int fileset)
const char * get_DiscType(unsigned int record=0, unsigned int attrib=0) const
void initialize(const char *base, const char *config, const char *typestr, int iomode)
static void abort(const char *=0)
static Communicate * Comm