18 DEBUG(
"IONetcdf::IONetcdf: entry", MAIA_DEBUG_ALLOCATION);
19 DEBUG(
"IONetcdf::IONetcdf: return", MAIA_DEBUG_ALLOCATION);
24 DEBUG(
"IONetcdf::~IONetcdf: entry", MAIA_DEBUG_ALLOCATION);
25 DEBUG(
"IONetcdf::~IONetcdf: return", MAIA_DEBUG_ALLOCATION);
42 DEBUG(
"IONetcdf::makeProperty: found integer property :", MAIA_DEBUG_IO);
43 p->propertyType =
MINT;
46 p->intField =
new MInt[1];
48 if(p->intField[0] == NC_FILL_INT) {
49 stringstream errorMessage;
50 errorMessage <<
"IONetcdf::makeProperty: Error" << endl
51 <<
"Property int " << p->name <<
" is filled by value " << NC_FILL_INT
52 <<
". This happens, because the property was declared in the property file but was never "
53 "initialized there. Go and fix it!";
54 mTerm(1, AT_, errorMessage.str());
56 DEBUG(
"IONetcdf::makeProperty: " << p->intField[0], MAIA_DEBUG_IO);
62 p->intField =
new MInt[length];
65 for(
MInt i = 0; i < (
MInt)length; i++) {
66 if(p->intField[i] == NC_FILL_INT) {
67 stringstream errorMessage;
68 errorMessage <<
"Property int " << p->name <<
" array is filled by the fill value " << NC_FILL_INT
69 <<
" at the position " << i
70 <<
". This happens, because the property was declared in the property file but never "
71 "initialized there. Go and fix it!";
72 mTerm(1, AT_, errorMessage.str());
84 DEBUG(
"IONetcdf::makeProperty: found float property :", MAIA_DEBUG_IO);
88 p->floatField =
new MFloat[1];
90 DEBUG(
"IONetcdf::makeProperty: " << p->floatField[0], MAIA_DEBUG_IO);
91 if(
approx(p->floatField[0], NC_FILL_DOUBLE, MFloatEps)) {
92 stringstream errorMessage;
93 errorMessage <<
"Property double " << p->name <<
" is filled by the fill value " << NC_FILL_DOUBLE
94 <<
". This happens, because the property was declared in the property file but never "
95 "initialized there. Go and fix it!";
96 mTerm(1, AT_, errorMessage.str());
102 p->elements = length;
103 p->floatField =
new MFloat[length];
106 for(
MInt i = 0; i < (
MInt)length; i++) {
107 if(
approx(p->floatField[i], NC_FILL_DOUBLE, MFloatEps)) {
108 stringstream errorMessage;
109 errorMessage <<
"Property double " << p->name <<
" array is filled by the fill value " << NC_FILL_DOUBLE
110 <<
" at the position " << i
111 <<
". This happens, because the property was declared in the property file but never "
112 "initialized there. Go and fix it!";
113 mTerm(1, AT_, errorMessage.str());
125 DEBUG(
"IONetcdf::makeProperty: found char property :", MAIA_DEBUG_IO);
129 p->stringField =
new MString[1];
132 if(buf[0] == NC_FILL_CHAR) {
133 stringstream errorMessage;
134 errorMessage <<
"Property char " << p->name <<
" is filled by the fill value \"" << NC_FILL_CHAR
135 <<
"\". This happens, because the property was declared in the property file but never "
136 "initialized there. Go and fix it!";
137 mTerm(1, AT_, errorMessage.str());
139 p->stringField->append(buf);
143 p->stringField =
new MString[1];
149 if(buf[0] == NC_FILL_CHAR) {
150 stringstream errorMessage;
151 errorMessage <<
"Property array of char " << p->name <<
" is filled by the fill value \"" << NC_FILL_CHAR
152 <<
"\". This happens, because the property was declared in the property file but never "
153 "initialized there. Go and fix it!";
154 mTerm(1, AT_, errorMessage.str());
156 p->stringField->append(buf);
157 DEBUG(
"IONetcdf::makeProperty: " << p->stringField[0], MAIA_DEBUG_IO);
162 p->elements = length;
163 p->stringField =
new MString[length];
165 for(
MInt i = 0; i < p->elements; i++) {
170 if(buf[0] == NC_FILL_CHAR) {
171 stringstream errorMessage;
172 errorMessage <<
"Property array of array of char " << p->name <<
" element " << i <<
" of " << p->elements
173 <<
" is filled by the fill value \"" << NC_FILL_CHAR
174 <<
"\". This happens, because the property was declared in the property file but never "
175 "initialized there. Go and fix it!";
176 mTerm(1, AT_, errorMessage.str());
178 p->stringField[i] = buf;
179 DEBUG(
"IONetcdf::makeProperty: " << p->stringField[i], MAIA_DEBUG_IO);
185 stringstream errorMessage;
186 errorMessage <<
"IONetcdf::makeProperty Error: Unsupported variable input type encountered!" << endl;
187 mTerm(1, AT_, errorMessage.str());
190 const pair<const MString, MProperty*> mp(p->name, p);
194 std::transform(nameL.begin(), nameL.end(), nameL.begin(), [](
unsigned char c) { return std::tolower(c); });
196 const pair<const MString, MProperty*> mpL(nameL, p);
202 "There are multiple occurrences of the property " + p->name
203 +
" with different cases. This should not happen!");
213 DEBUG(
"IONetcdf::makeProperty: created default property ", MAIA_DEBUG_IO);
214 DEBUG(
"IONetcdf::makeProperty: elements = " << p->elements, MAIA_DEBUG_IO);
215 DEBUG(
"IONetcdf::makeProperty: m_noProperties = " <<
m_propertyMap->size(), MAIA_DEBUG_IO);
225 MInt noVariables = 0;
226 const char MPropertySeperator =
'.';
235 noVariables = varNames.size();
236 for(
MInt n = 0; n < noVariables; n++) {
237 varName = varNames[n];
238 if(strstr(varName.c_str(),
"zone_solvers.")) {
239 du = strrchr(varName.c_str(), MPropertySeperator);
244 zone->name.append(++du);
245 if(zone->name ==
"default") {
246 mTerm(1, AT_,
"IONetcdf::readZones Error: The zone name \"default\" is reserved and cannot be used!");
248 DEBUG(
"IONetcdf::readZones: zone found (name: " << zone->name <<
")", MAIA_DEBUG_USER2);
252 DEBUG(
"IONetcdf::readZones: the Zone has " << length <<
" solvers.", MAIA_DEBUG_USER2);
253 zone->noSolvers = length;
254 zone->solvers =
new MInt[length];
261 zone->solvers[i] = dsolvers;
265 m_zoneMap->insert(make_pair(zone->name, zone));
268 stringstream errorMessage;
269 errorMessage <<
" Error : Double occurence of zone id! " << endl;
270 mTerm(1, AT_, errorMessage.str());
287 zone->name.append(
"default");
290 list<MInt> solverList;
292 for(
MInt i = 0; i < it->second->noSolvers; i++) {
293 solverList.push_back(it->second->solvers[i]);
300 zone->noSolvers = (
m_noSolvers - solverList.size());
301 zone->solvers =
new MInt[zone->noSolvers];
305 MInt simpleIterator = 0;
306 list<MInt>::const_iterator solverIt = solverList.begin();
309 if((!solverList.empty()) && (*solverIt == i)) {
313 zone->solvers[simpleIterator] = i;
314 DEBUG(
"IONetcdf::buildDefaultZone: added solver " << i <<
" to the default zone. ", MAIA_DEBUG_IO);
321 m_zoneMap->insert(make_pair(zone->name, zone));
322 DEBUG(
"IONetcdf::buildDefaultZone: default zone has " << zone->noSolvers <<
" solvers.", MAIA_DEBUG_IO);
332 MBool readNew =
true;
333 MInt noVariables = 0;
343 const char MPropertySeperator =
'.';
355 parallelIo.
readScalar(&dsolvers,
"noSolvers");
368 noVariables = varNames.size();
370 for(
MInt id = 0;
id < noVariables;
id++) {
371 varName = varNames[
id];
373 if(!strstr(varName.c_str(),
".")) {
378 DEBUG(
"IONetcdf::readNCPropertyFile: default property : " << varName, MAIA_DEBUG_IO);
381 p->name.append(varName);
383 if(
"standardTextLength" == varName) {
390 if(strstr(varName.c_str(),
"_zones.")) {
391 DEBUG(
"IONetcdf::readPropertyFile: regular property: " << varName, MAIA_DEBUG_IO);
397 DEBUG(
"IONetcdf::readPropertyFile: no. of dimensions = " << noDims, MAIA_DEBUG_IO);
419 noZones = (
MInt)dzones;
425 for(
MInt i = 0; i < noZones; i++) {
430 (zones[i]).append(buf);
431 DEBUG(
"IONetcdf::readPropertyFile: " << zones[i], MAIA_DEBUG_IO);
436 stringstream errorMessage;
437 errorMessage <<
"IONetcdf::readPropertyFile Error: only one dimensional zone lists allowed!" << endl;
438 mTerm(1, AT_, errorMessage.str());
443 list<MInt> solverList;
444 for(
MInt i = 0; i != noZones; i++) {
445 DEBUG(
"IONetcdf::readPropertyFile: definition for zone " << zones[i], MAIA_DEBUG_IO);
450 for(
MInt j = 0; j < zI->second->noSolvers; j++) {
451 solverList.push_back(zI->second->solvers[j]);
457 du = strrchr(varName.c_str(), MPropertySeperator);
460 dummy.replace(dummy.find(
"_zones."), dummy.size(), du);
461 DEBUG(
"IONetcdf::readPropertyFile: found property: " << dummy, MAIA_DEBUG_IO);
464 list<MInt>::const_iterator it = solverList.begin();
465 dummy.erase(dummy.find(
"."));
467 for(; it != solverList.end(); it++) {
470 p->name.append(dummy);
472 DEBUG(
"IONetcdf::readPropertyFile: created property for solver " << *it, MAIA_DEBUG_IO);
478 du = strrchr(varName.c_str(), MPropertySeperator) + 1;
479 MInt singleSolverId = atoi(du);
483 if(singleSolverId || *du ==
'0') {
484 DEBUG(
"IONetcdf::readPropertyFile: Found single solver property definition for solver "
488 p->solverId = singleSolverId;
492 dummyName.erase(dummyName.find(
"."));
493 p->name.append(dummyName);
494 if(
"standardTextLength" != varName) {
503 DEBUG(
"IONetcdf::readPropertyFile: property consistency check succeeded", MAIA_DEBUG_IO);
505 stringstream errorMessage;
506 errorMessage <<
"IONetcdf::readPropertyFile Error: some properties are not defined for all solvers!" << endl;
507 mTerm(1, AT_, errorMessage.str());
510 stringstream errorMessage;
511 errorMessage <<
"IONetcdf::readPropertyFile Error: Inconsistent solver List!\n Make sure that solvers start "
512 "with index 0 and are consecutive!"
514 mTerm(1, AT_, errorMessage.str());
523 totalCount += prop->second->count();
525 MInt sizeofallProp = noProperties * (256 + 4 *
sizeof(
MInt)) + totalCount * (256 +
sizeof(
MInt));
528 propMapArray.
fill(0);
532 MInt asize = prop->first.size();
533 memcpy(&propMapArray(pCounter), &asize,
sizeof(
MInt));
534 pCounter +=
sizeof(
MInt);
535 memcpy(&propMapArray(pCounter), prop->first.c_str(), asize *
sizeof(
MChar));
536 pCounter += asize *
sizeof(
MChar);
537 memcpy(&propMapArray(pCounter), (
void*)&(prop->second->solverId),
sizeof(
MInt));
538 pCounter +=
sizeof(
MInt);
539 memcpy(&propMapArray(pCounter), (
void*)&(prop->second->propertyType),
sizeof(
MInt));
540 pCounter +=
sizeof(
MInt);
541 MInt count = prop->second->count();
542 memcpy(&propMapArray(pCounter), &count,
sizeof(
MInt));
543 pCounter +=
sizeof(
MInt);
544 switch(prop->second->propertyType) {
546 memcpy((
void*)&propMapArray(pCounter), (
void*)&(prop->second->intField[0]), count *
sizeof(
MInt));
547 pCounter += count *
sizeof(
MInt);
551 memcpy((
void*)&propMapArray(pCounter), (
void*)&(prop->second->floatField[0]), count *
sizeof(
MFloat));
552 pCounter += count *
sizeof(
MFloat);
556 for(
MInt i = 0; i < count; i++) {
557 asize = prop->second->stringField[i].size();
558 memcpy(&propMapArray(pCounter), &asize,
sizeof(
MInt));
559 pCounter +=
sizeof(
MInt);
560 memcpy(&propMapArray(pCounter), prop->second->stringField[i].c_str(),
561 prop->second->stringField[i].
size() *
sizeof(
MChar));
562 pCounter += asize *
sizeof(
MChar);
567 mTerm(1, AT_,
"no such variable type!!!!");
578 zoneCount += zone->second->noSolvers;
580 MInt sizeofZones = noProperties * (2 * (256 +
sizeof(
MInt)) +
sizeof(
MInt) * 2) + zoneCount *
sizeof(
MInt);
582 zoneMapArray.fill(0);
586 MInt asize = zone->first.size();
587 memcpy(&zoneMapArray(pCounter), &asize,
sizeof(
MInt));
588 pCounter +=
sizeof(
MInt);
589 memcpy(&zoneMapArray(pCounter), zone->first.c_str(), asize *
sizeof(
MChar));
590 pCounter += asize *
sizeof(
MChar);
591 memcpy(&zoneMapArray(pCounter), &(zone->second->id),
sizeof(
MInt));
592 pCounter +=
sizeof(
MInt);
593 memcpy(&zoneMapArray(pCounter), &(zone->second->noSolvers),
sizeof(
MInt));
594 pCounter +=
sizeof(
MInt);
595 memcpy(&zoneMapArray(pCounter), &(zone->second->solvers[0]),
sizeof(
MInt) * zone->second->noSolvers);
596 pCounter +=
sizeof(
MInt) * zone->second->noSolvers;
599 MInt dummyInt[5] = {noProperties, totalCount, zoneCount, noZones,
m_noSolvers};
600 MPI_Bcast(&dummyInt, 5, MPI_INT, 0, MPI_COMM_WORLD, AT_,
"dummyInt");
602 "propMapArray.getPointer()");
603 MPI_Bcast(zoneMapArray.getPointer(), sizeofZones, MPI_CHAR, 0, MPI_COMM_WORLD, AT_,
"zoneMapArray.getPointer()");
607 MInt dummyInt[5] = {0, 0, 0, 0, 0};
608 MPI_Bcast(&dummyInt, 5, MPI_INT, 0, MPI_COMM_WORLD, AT_,
"dummyInt");
609 MInt noProperties = dummyInt[0];
610 MInt totalCount = dummyInt[1];
611 MInt zoneCount = dummyInt[2];
612 MInt noZones = dummyInt[3];
614 MInt sizeofallProp = noProperties * (256 + 4 *
sizeof(
MInt)) + totalCount * (256 +
sizeof(
MInt));
615 MInt sizeofZones = noProperties * (2 * (256 +
sizeof(
MInt)) +
sizeof(
MInt) * 2) + zoneCount *
sizeof(
MInt);
617 propMapArray.fill(0);
619 zoneMapArray.
fill(0);
621 MPI_Bcast(propMapArray.getPointer(), sizeofallProp, MPI_CHAR, 0, MPI_COMM_WORLD, AT_,
622 "propMapArray.getPointer()");
623 MPI_Bcast(zoneMapArray.
getPointer(), sizeofZones, MPI_CHAR, 0, MPI_COMM_WORLD, AT_,
"zoneMapArray.getPointer()");
627 for(
MInt i = 0; i < noProperties; i++) {
633 memcpy(&asize, &propMapArray[pCounter],
sizeof(
MInt));
634 pCounter +=
sizeof(
MInt);
635 char*
a =
new char[asize + 1];
637 memcpy(
a, &propMapArray[pCounter], asize);
639 pCounter += asize *
sizeof(
MChar);
644 memcpy(&(p->solverId), &propMapArray[pCounter],
sizeof(
MInt));
645 pCounter +=
sizeof(
MInt);
646 MInt propertyType = -1;
647 memcpy(&propertyType, &propMapArray[pCounter],
sizeof(
MInt));
648 pCounter +=
sizeof(
MInt);
649 switch(propertyType) {
651 p->propertyType =
MINT;
663 mTerm(1, AT_,
"no such variable type");
667 memcpy(&(p->elements), &propMapArray[pCounter],
sizeof(
MInt));
668 pCounter +=
sizeof(
MInt);
669 switch(p->propertyType) {
671 p->intField =
new MInt[p->elements];
672 memcpy(&(p->intField[0]), &propMapArray[pCounter], p->elements *
sizeof(
MInt));
673 pCounter +=
sizeof(
MInt) * p->elements;
677 p->floatField =
new MFloat[p->elements];
678 memcpy(&(p->floatField[0]), &propMapArray[pCounter], p->elements *
sizeof(
MFloat));
679 pCounter +=
sizeof(
MFloat) * p->elements;
683 p->stringField =
new MString[p->elements];
684 for(
MInt j = 0; j < p->elements; j++) {
686 memcpy(&asize, &propMapArray(pCounter),
sizeof(
MINT));
687 pCounter +=
sizeof(
MInt);
688 char* c =
new char[asize + 1];
689 memcpy(c, &propMapArray[pCounter], asize *
sizeof(
MChar));
690 pCounter += asize *
sizeof(
MChar);
694 p->stringField[j] = st;
699 mTerm(1, AT_,
"no such variable type");
704 const pair<const MString, MProperty*> mp(p->name, p);
708 std::transform(nameL.begin(), nameL.end(), nameL.begin(), [](
unsigned char c) { return std::tolower(c); });
710 const pair<const MString, MProperty*> mpL(nameL, p);
716 "There are multiple occurrences of the property " + p->name
717 +
" with different cases. This should not happen!");
726 for(
MInt zo = 0; zo < noZones; zo++) {
730 memcpy(&asize, &zoneMapArray[pCounterZ],
sizeof(
MInt));
731 pCounterZ +=
sizeof(
MInt);
732 char* c =
new char[asize + 1];
733 memcpy(c, &zoneMapArray[pCounterZ], asize *
sizeof(
MChar));
734 pCounterZ += asize *
sizeof(
MChar);
739 memcpy(&(z->id), &zoneMapArray[pCounterZ],
sizeof(
MInt));
740 pCounterZ +=
sizeof(
MInt);
741 memcpy(&(z->noSolvers), &zoneMapArray[pCounterZ],
sizeof(
MInt));
742 pCounterZ +=
sizeof(
MInt);
743 z->solvers =
new MInt[z->noSolvers];
744 memcpy(&(z->solvers[0]), &zoneMapArray[pCounterZ], z->noSolvers *
sizeof(
MInt));
745 pCounterZ += z->noSolvers *
sizeof(
MInt);
746 m_zoneMap->insert(make_pair(z->name, z));
751 const char MPropertySeperator =
'.';
759 parallelIo.
readScalar(&dsolvers,
"noSolvers");
769 noVariables = varNames.size();
770 for(
MInt id = 0;
id < noVariables;
id++) {
771 varName = varNames[
id];
773 if(!strstr(varName.c_str(),
".")) {
777 DEBUG(
"IONetcdf::readNCPropertyFile: default property : " << varName, MAIA_DEBUG_IO);
780 p->name.append(varName);
782 if(
"standardTextLength" == varName) {
789 if(strstr(varName.c_str(),
"_zones.")) {
790 DEBUG(
"IONetcdf::readPropertyFile: regular property: " << varName, MAIA_DEBUG_IO);
796 DEBUG(
"IONetcdf::readPropertyFile: no. of dimensions = " << noDims, MAIA_DEBUG_IO);
818 noZones = (
MInt)dzones;
824 for(
MInt i = 0; i < noZones; i++) {
829 (zones[i]).append(buf);
830 DEBUG(
"IONetcdf::readPropertyFile: " << zones[i], MAIA_DEBUG_IO);
835 stringstream errorMessage;
836 errorMessage <<
"IONetcdf::readPropertyFile Error: only one dimensional zone lists allowed!" << endl;
837 mTerm(1, AT_, errorMessage.str());
842 list<MInt> solverList;
843 for(
MInt i = 0; i != noZones; i++) {
844 DEBUG(
"IONetcdf::readPropertyFile: definition for zone " << zones[i], MAIA_DEBUG_IO);
849 for(
MInt j = 0; j < zI->second->noSolvers; j++) {
850 solverList.push_back(zI->second->solvers[j]);
854 du = strrchr(varName.c_str(), MPropertySeperator);
857 dummy.replace(dummy.find(
"_zones."), dummy.size(), du);
858 DEBUG(
"IONetcdf::readPropertyFile: found property: " << dummy, MAIA_DEBUG_IO);
861 list<MInt>::const_iterator it = solverList.begin();
862 dummy.erase(dummy.find(
"."));
864 for(; it != solverList.end(); it++) {
867 p->name.append(dummy);
869 DEBUG(
"IONetcdf::readPropertyFile: created property for solver " << *it, MAIA_DEBUG_IO);
875 du = strrchr(varName.c_str(), MPropertySeperator) + 1;
876 MInt singleSolverId = atoi(du);
878 if(singleSolverId || *du ==
'0') {
879 DEBUG(
"IONetcdf::readPropertyFile: Found single solver property definition for solver " << singleSolverId,
882 p->solverId = singleSolverId;
884 dummyName.erase(dummyName.find(
"."));
885 p->name.append(dummyName);
886 if(
"standardTextLength" != varName) {
895 DEBUG(
"IONetcdf::readPropertyFile: property consistency check succeeded", MAIA_DEBUG_IO);
897 stringstream errorMessage;
898 errorMessage <<
"IONetcdf::readPropertyFile Error: some properties are not defined for all solvers!" << endl;
899 mTerm(1, AT_, errorMessage.str());
902 stringstream errorMessage;
903 errorMessage <<
"IONetcdf::readPropertyFile Error: Inconsistent solver List!\n Make sure that solvers start "
904 "with index 0 and are consecutive!"
906 mTerm(1, AT_, errorMessage.str());
930 DEBUG(
"IONetcdf::checkPropertyConsistency: default property exists for :" << i->second->name, MAIA_DEBUG_IO);
947 list<MInt> solverList;
948 list<MInt> compareList;
951 for(
MInt i = 0; i < it->second->noSolvers; i++) {
952 solverList.push_back(it->second->solvers[i]);
953 compareList.push_back(index++);
957 if(solverList == compareList) {
void readZones(ParallelIo *bdFile)
MBool checkZoneConsistency()
propertyMap * m_propertyMapLowercase
assembly * readPropertyFile(const MString &fileName)
propertyMap * m_propertyMap
MBool checkPropertyConsistency()
void makeProperty(MProperty *, const MString &, ParallelIo *bdFile)
MInt getDatasetType(const MString &name)
Returns the data type of an array.
void readScalar(T *scalar, const MString &name)
Read scalar data from file. [MPI]
void setOffset(const size_type localCount, const size_type offset, const size_type noDims, const size_type noChunks)
Set the local and global counts, as well the local offset for array operations.
MBool hasDataset(const MString &name, MInt dimension)
Check if the file contains an dataset with the given name and dimension.
std::vector< MString > getDatasetNames(const size_type dimensions=-1)
Returns a vector with the names of all existing datasets with given dimensionality in the file.
MLong size_type
Type used for all size- and offset-related values.
size_type getArraySize(const MString &name, const size_type dimensionId=0)
Get the length of an array in the file.
size_type getDatasetNoDims(const MString &name)
Get the number of dimensions of a dataset with given name.
void readArray(T *array, const MString &name, size_type memoryStride=-1, size_type diskStride=-1)
Read array data from file. [MPI]
This class is a ScratchSpace.
T * getPointer() const
Deprecated: use begin() instead!
void fill(T val)
fill the scratch with a given value
std::map< MString, MZone * > zoneMap
zoneMap::const_iterator zoneIterator
std::multimap< MString, MProperty * > propertyMap
propertyMap::const_iterator propertyIterator
void mTerm(const MInt errorCode, const MString &location, const MString &message)
MBool approx(const T &, const U &, const T)
MInt globalDomainId()
Return global domain id.
z { MString name MZone
define array structures
std::basic_string< char > MString
int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm, const MString &name, const MString &varname)
same as MPI_Bcast
propertyMap * propertiesLowercase