330 {
331 TRACE();
332 MBool readNew =
true;
333 MInt noVariables = 0;
338
339 if(readNew) {
340
342
343 const char MPropertySeperator = '.';
344
345
347
348
350 if(!parallelIo.hasDataset("noSolvers", 0)) {
351 dsolvers = 1;
352
353
354 } else {
355 parallelIo.readScalar(&dsolvers, "noSolvers");
356 }
358
359
361
363
365
367 vector<MString> varNames = parallelIo.getDatasetNames();
368 noVariables = varNames.size();
369
370 for(
MInt id = 0;
id < noVariables;
id++) {
371 varName = varNames[
id];
372
373 if(!strstr(varName.c_str(), ".")) {
374
375
376
377
378 DEBUG("IONetcdf::readNCPropertyFile: default property : " << varName, MAIA_DEBUG_IO);
381 p->name.append(varName);
382
383 if("standardTextLength" == varName) {
384 continue;
385 }
387 }
388
389 else {
390 if(strstr(varName.c_str(), "_zones.")) {
391 DEBUG("IONetcdf::readPropertyFile: regular property: " << varName, MAIA_DEBUG_IO);
394 noDims = parallelIo.getDatasetNoDims(varName);
397 DEBUG("IONetcdf::readPropertyFile: no. of dimensions = " << noDims, MAIA_DEBUG_IO);
398 switch(noDims) {
399 case 0: {
400
402 parallelIo.readScalar(&buf, varName);
404 break;
405 }
406 case 1: {
407
408 length = parallelIo.getArraySize(varName);
410 parallelIo.setOffset(length, 0);
411 parallelIo.readArray(&buf, varName);
413 break;
414 }
415 case 2: {
416
418 dzones = parallelIo.getArraySize(varName, 0);
419 noZones = (
MInt)dzones;
421
422 length = parallelIo.getArraySize(varName, 1);
424
425 for(
MInt i = 0; i < noZones; i++) {
426 start = i;
427 parallelIo.setOffset(1, start, 2);
429 parallelIo.readArray(&buf, varName);
430 (zones[i]).append(buf);
431 DEBUG("IONetcdf::readPropertyFile: " << zones[i], MAIA_DEBUG_IO);
432 }
433 break;
434 }
435 default: {
436 stringstream errorMessage;
437 errorMessage << "IONetcdf::readPropertyFile Error: only one dimensional zone lists allowed!" << endl;
438 mTerm(1, AT_, errorMessage.str());
439 }
440 }
441
442
443 list<MInt> solverList;
444 for(
MInt i = 0; i != noZones; i++) {
445 DEBUG("IONetcdf::readPropertyFile: definition for zone " << zones[i], MAIA_DEBUG_IO);
447
449
450 for(
MInt j = 0; j < zI->second->noSolvers; j++) {
451 solverList.push_back(zI->second->solvers[j]);
452 }
453 }
454
455
456 const char* du;
457 du = strrchr(varName.c_str(), MPropertySeperator);
459
460 dummy.replace(dummy.find("_zones."), dummy.size(), du);
461 DEBUG("IONetcdf::readPropertyFile: found property: " << dummy, MAIA_DEBUG_IO);
463
464 list<MInt>::const_iterator it = solverList.begin();
465 dummy.erase(dummy.find("."));
466
467 for(; it != solverList.end(); it++) {
470 p->name.append(dummy);
472 DEBUG("IONetcdf::readPropertyFile: created property for solver " << *it, MAIA_DEBUG_IO);
473 }
474 }
475 else {
476
477 const char* du;
478 du = strrchr(varName.c_str(), MPropertySeperator) + 1;
479 MInt singleSolverId = atoi(du);
480
482
483 if(singleSolverId || *du == '0') {
484 DEBUG("IONetcdf::readPropertyFile: Found single solver property definition for solver "
485 << singleSolverId,
486 MAIA_DEBUG_IO);
488 p->solverId = singleSolverId;
489
491
492 dummyName.erase(dummyName.find("."));
493 p->name.append(dummyName);
494 if("standardTextLength" != varName) {
496 }
497 }
498 }
499 }
500 }
501
503 DEBUG("IONetcdf::readPropertyFile: property consistency check succeeded", MAIA_DEBUG_IO);
504 } else {
505 stringstream errorMessage;
506 errorMessage << "IONetcdf::readPropertyFile Error: some properties are not defined for all solvers!" << endl;
507 mTerm(1, AT_, errorMessage.str());
508 }
509 } else {
510 stringstream errorMessage;
511 errorMessage << "IONetcdf::readPropertyFile Error: Inconsistent solver List!\n Make sure that solvers start "
512 "with index 0 and are consecutive!"
513 << endl;
514 mTerm(1, AT_, errorMessage.str());
515 }
516
517
518
520
523 totalCount += prop->second->count();
524 }
525 MInt sizeofallProp = noProperties * (256 + 4 *
sizeof(
MInt)) + totalCount * (256 +
sizeof(
MInt));
526
528 propMapArray.fill(0);
529
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);
548 break;
549 }
551 memcpy((
void*)&propMapArray(pCounter), (
void*)&(prop->second->floatField[0]), count *
sizeof(
MFloat));
552 pCounter += count *
sizeof(
MFloat);
553 break;
554 }
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);
563 }
564 break;
565 }
566 default: {
567 mTerm(1, AT_,
"no such variable type!!!!");
568 break;
569 }
570 }
571 }
572
573
575
578 zoneCount += zone->second->noSolvers;
579 }
580 MInt sizeofZones = noProperties * (2 * (256 +
sizeof(
MInt)) +
sizeof(
MInt) * 2) + zoneCount *
sizeof(
MInt);
582 zoneMapArray.fill(0);
583
584 pCounter = 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;
597 }
598
599 MInt dummyInt[5] = {noProperties, totalCount, zoneCount, noZones,
m_noSolvers};
600 MPI_Bcast(&dummyInt, 5, MPI_INT, 0, MPI_COMM_WORLD, AT_,
"dummyInt");
601 MPI_Bcast(propMapArray.getPointer(), sizeofallProp, MPI_CHAR, 0, MPI_COMM_WORLD, AT_,
602 "propMapArray.getPointer()");
603 MPI_Bcast(zoneMapArray.getPointer(), sizeofZones, MPI_CHAR, 0, MPI_COMM_WORLD, AT_,
"zoneMapArray.getPointer()");
604
605 } else {
606
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);
620
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()");
624
627 for(
MInt i = 0; i < noProperties; i++) {
628
630
632
633 memcpy(&asize, &propMapArray[pCounter],
sizeof(
MInt));
634 pCounter +=
sizeof(
MInt);
635 char*
a =
new char[asize + 1];
636
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) {
650 case 0: {
651 p->propertyType =
MINT;
652 break;
653 }
654 case 1: {
656 break;
657 }
658 case 2: {
660 break;
661 }
662 default: {
663 mTerm(1, AT_,
"no such variable type");
664 break;
665 }
666 }
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;
674 break;
675 }
677 p->floatField =
new MFloat[
p->elements];
678 memcpy(&(
p->floatField[0]), &propMapArray[pCounter],
p->elements *
sizeof(
MFloat));
679 pCounter +=
sizeof(
MFloat) *
p->elements;
680 break;
681 }
683 p->stringField =
new MString[
p->elements];
684 for(
MInt j = 0; j <
p->elements; j++) {
685 asize = 0;
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);
691 c[asize] = '\0';
692 const char* d = c;
694 p->stringField[j] = st;
695 }
696 break;
697 }
698 default: {
699 mTerm(1, AT_,
"no such variable type");
700 break;
701 }
702 }
703
704 const pair<const MString, MProperty*> mp(
p->name, p);
705
706
708 std::transform(nameL.begin(), nameL.end(), nameL.begin(), [](unsigned char c) { return std::tolower(c); });
709
710 const pair<const MString, MProperty*> mpL(nameL, p);
711
712
716 "There are multiple occurrences of the property " +
p->name
717 + " with different cases. This should not happen!");
718 }
721 }
722
725
726 for(
MInt zo = 0; zo < noZones; zo++) {
727
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);
735 c[asize] = '\0';
736 const char* d = c;
738 z->name = st;
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));
747 }
748 }
749 } else {
750
751 const char MPropertySeperator = '.';
752
754
756 if(!parallelIo.hasDataset("noSolvers", 0)) {
757 dsolvers = 1;
758 } else {
759 parallelIo.readScalar(&dsolvers, "noSolvers");
760 }
762
766
768 vector<MString> varNames = parallelIo.getDatasetNames();
769 noVariables = varNames.size();
770 for(
MInt id = 0;
id < noVariables;
id++) {
771 varName = varNames[
id];
772
773 if(!strstr(varName.c_str(), ".")) {
774
775
776
777 DEBUG("IONetcdf::readNCPropertyFile: default property : " << varName, MAIA_DEBUG_IO);
780 p->name.append(varName);
781
782 if("standardTextLength" == varName) {
783 continue;
784 }
786 }
787
788 else {
789 if(strstr(varName.c_str(), "_zones.")) {
790 DEBUG("IONetcdf::readPropertyFile: regular property: " << varName, MAIA_DEBUG_IO);
793 noDims = parallelIo.getDatasetNoDims(varName);
796 DEBUG("IONetcdf::readPropertyFile: no. of dimensions = " << noDims, MAIA_DEBUG_IO);
797 switch(noDims) {
798 case 0: {
799
801 parallelIo.readScalar(&buf, varName);
803 break;
804 }
805 case 1: {
806
807 length = parallelIo.getArraySize(varName);
809 parallelIo.setOffset(length, 0);
810 parallelIo.readArray(&buf, varName);
812 break;
813 }
814 case 2: {
815
817 dzones = parallelIo.getArraySize(varName, 0);
818 noZones = (
MInt)dzones;
820
821 length = parallelIo.getArraySize(varName, 1);
823
824 for(
MInt i = 0; i < noZones; i++) {
825 start = i;
826 parallelIo.setOffset(1, start, 2);
828 parallelIo.readArray(&buf, varName);
829 (zones[i]).append(buf);
830 DEBUG("IONetcdf::readPropertyFile: " << zones[i], MAIA_DEBUG_IO);
831 }
832 break;
833 }
834 default: {
835 stringstream errorMessage;
836 errorMessage << "IONetcdf::readPropertyFile Error: only one dimensional zone lists allowed!" << endl;
837 mTerm(1, AT_, errorMessage.str());
838 }
839 }
840
841
842 list<MInt> solverList;
843 for(
MInt i = 0; i != noZones; i++) {
844 DEBUG("IONetcdf::readPropertyFile: definition for zone " << zones[i], MAIA_DEBUG_IO);
846
848
849 for(
MInt j = 0; j < zI->second->noSolvers; j++) {
850 solverList.push_back(zI->second->solvers[j]);
851 }
852 }
853 const char* du;
854 du = strrchr(varName.c_str(), MPropertySeperator);
856
857 dummy.replace(dummy.find("_zones."), dummy.size(), du);
858 DEBUG("IONetcdf::readPropertyFile: found property: " << dummy, MAIA_DEBUG_IO);
860
861 list<MInt>::const_iterator it = solverList.begin();
862 dummy.erase(dummy.find("."));
863
864 for(; it != solverList.end(); it++) {
867 p->name.append(dummy);
869 DEBUG("IONetcdf::readPropertyFile: created property for solver " << *it, MAIA_DEBUG_IO);
870 }
871 }
872 else {
873
874 const char* du;
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,
880 MAIA_DEBUG_IO);
882 p->solverId = singleSolverId;
884 dummyName.erase(dummyName.find("."));
885 p->name.append(dummyName);
886 if("standardTextLength" != varName) {
888 }
889 }
890 }
891 }
892 }
893
895 DEBUG("IONetcdf::readPropertyFile: property consistency check succeeded", MAIA_DEBUG_IO);
896 } else {
897 stringstream errorMessage;
898 errorMessage << "IONetcdf::readPropertyFile Error: some properties are not defined for all solvers!" << endl;
899 mTerm(1, AT_, errorMessage.str());
900 }
901 } else {
902 stringstream errorMessage;
903 errorMessage << "IONetcdf::readPropertyFile Error: Inconsistent solver List!\n Make sure that solvers start "
904 "with index 0 and are consecutive!"
905 << endl;
906 mTerm(1, AT_, errorMessage.str());
907 }
908 }
909
914
916}
void readZones(ParallelIo *bdFile)
MBool checkZoneConsistency()
MBool checkPropertyConsistency()
void makeProperty(MProperty *, const MString &, ParallelIo *bdFile)
This class is a ScratchSpace.
std::map< MString, MZone * > zoneMap
zoneMap::const_iterator zoneIterator
std::multimap< MString, MProperty * > propertyMap
MInt globalDomainId()
Return global domain id.
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
PARALLELIO_DEFAULT_BACKEND ParallelIo
propertyMap * propertiesLowercase