Changeset d1df9b
- Timestamp:
- Jul 10, 2009, 9:01:40 PM (16 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 205ccd
- Parents:
- 6cb412
- git-author:
- Frederik Heber <heber@…> (07/10/09 20:21:12)
- git-committer:
- Frederik Heber <heber@…> (07/10/09 21:01:40)
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/config.cpp
r6cb412 rd1df9b 6 6 7 7 #include "molecules.hpp" 8 9 /******************************** Functions for class ConfigFileBuffer **********************/ 10 11 /** Structure containing compare function for Ion_Type sorting. 12 */ 13 struct IonTypeCompare { 14 bool operator()(const char* s1, const char *s2) const { 15 char number1[8]; 16 char number2[8]; 17 char *dummy1, *dummy2; 18 //cout << s1 << " " << s2 << endl; 19 dummy1 = strchr(s1, '_')+sizeof(char)*5; // go just after "Ion_Type" 20 dummy2 = strchr(dummy1, '_'); 21 strncpy(number1, dummy1, dummy2-dummy1); // copy the number 22 number1[dummy2-dummy1]='\0'; 23 dummy1 = strchr(s2, '_')+sizeof(char)*5; // go just after "Ion_Type" 24 dummy2 = strchr(dummy1, '_'); 25 strncpy(number2, dummy1, dummy2-dummy1); // copy the number 26 number2[dummy2-dummy1]='\0'; 27 if (atoi(number1) != atoi(number2)) 28 return (atoi(number1) < atoi(number2)); 29 else { 30 dummy1 = strchr(s1, '_')+sizeof(char); 31 dummy1 = strchr(dummy1, '_')+sizeof(char); 32 dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t'); 33 strncpy(number1, dummy1, dummy2-dummy1); // copy the number 34 number1[dummy2-dummy1]='\0'; 35 dummy1 = strchr(s2, '_')+sizeof(char); 36 dummy1 = strchr(dummy1, '_')+sizeof(char); 37 dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t'); 38 strncpy(number2, dummy1, dummy2-dummy1); // copy the number 39 number2[dummy2-dummy1]='\0'; 40 return (atoi(number1) < atoi(number2)); 41 } 42 } 43 }; 44 45 /** Constructor for ConfigFileBuffer class. 46 */ 47 ConfigFileBuffer::ConfigFileBuffer() 48 { 49 NoLines = 0; 50 CurrentLine = 0; 51 buffer = NULL; 52 LineMapping = NULL; 53 } 54 55 /** Constructor for ConfigFileBuffer class with filename to be parsed. 56 * \param *filename file name 57 */ 58 ConfigFileBuffer::ConfigFileBuffer(char *filename) 59 { 60 NoLines = 0; 61 CurrentLine = 0; 62 buffer = NULL; 63 LineMapping = NULL; 64 ifstream *file = NULL; 65 char line[MAXSTRINGSIZE]; 66 67 // prescan number of lines 68 file= new ifstream(filename); 69 if (file == NULL) { 70 cerr << "ERROR: config file " << filename << " missing!" << endl; 71 return; 72 } 73 NoLines = 0; // we're overcounting by one 74 long file_position = file->tellg(); // mark current position 75 do { 76 file->getline(line, 256); 77 NoLines++; 78 } while (!file->eof()); 79 file->clear(); 80 file->seekg(file_position, ios::beg); 81 cout << Verbose(1) << NoLines-1 << " lines were recognized." << endl; 82 83 // allocate buffer's 1st dimension 84 if (buffer != NULL) { 85 cerr << "ERROR: FileBuffer->buffer is not NULL!" << endl; 86 return; 87 } else 88 buffer = (char **) Malloc(sizeof(char *)*NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer"); 89 90 // scan each line and put into buffer 91 int lines=0; 92 int i; 93 do { 94 buffer[lines] = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]"); 95 file->getline(buffer[lines], MAXSTRINGSIZE-1); 96 i = strlen(buffer[lines]); 97 buffer[lines][i] = '\n'; 98 buffer[lines][i+1] = '\0'; 99 lines++; 100 } while((!file->eof()) && (lines < NoLines)); 101 cout << Verbose(1) << lines-1 << " lines were read into the buffer." << endl; 102 103 // close and exit 104 file->close(); 105 file->clear(); 106 delete(file); 107 } 108 109 /** Destructor for ConfigFileBuffer class. 110 */ 111 ConfigFileBuffer::~ConfigFileBuffer() 112 { 113 for(int i=0;i<NoLines;++i) 114 Free((void **)&buffer[i], "ConfigFileBuffer::~ConfigFileBuffer: *buffer[]"); 115 Free((void **)&buffer, "ConfigFileBuffer::~ConfigFileBuffer: **buffer"); 116 Free((void **)&LineMapping, "ConfigFileBuffer::~ConfigFileBuffer: *LineMapping"); 117 } 118 119 120 /** Create trivial mapping. 121 */ 122 void ConfigFileBuffer::InitMapping() 123 { 124 LineMapping = (int *) Malloc(sizeof(int)*NoLines, "ConfigFileBuffer::InitMapping: *LineMapping"); 125 for (int i=0;i<NoLines;i++) 126 LineMapping[i] = i; 127 } 128 129 /** Creates a mapping for the \a *FileBuffer's lines containing the Ion_Type keyword such that they are sorted. 130 * \a *map on return contains a list of NoAtom entries such that going through the list, yields indices to the 131 * lines in \a *FileBuffer in a sorted manner of the Ion_Type?_? keywords. We assume that ConfigFileBuffer::CurrentLine 132 * points to first Ion_Type entry. 133 * \param *FileBuffer pointer to buffer structure 134 * \param NoAtoms of subsequent lines to look at 135 */ 136 void ConfigFileBuffer::MapIonTypesInBuffer(int NoAtoms) 137 { 138 map<const char *, int, IonTypeCompare> LineList; 139 if (LineMapping == NULL) { 140 cerr << "map pointer is NULL: " << LineMapping << endl; 141 return; 142 } 143 144 // put all into hashed map 145 for (int i=0; i<NoAtoms; ++i) { 146 LineList.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i)); 147 } 148 149 // fill map 150 int nr=0; 151 for (map<const char *, int, IonTypeCompare>::iterator runner = LineList.begin(); runner != LineList.end(); ++runner) { 152 if (CurrentLine+nr < NoLines) 153 LineMapping[CurrentLine+(nr++)] = runner->second; 154 else 155 cerr << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl; 156 } 157 } 8 158 9 159 /************************************* Functions for class config ***************************/ … … 447 597 void config::Load(char *filename, periodentafel *periode, molecule *mol) 448 598 { 449 ifstream *file = new ifstream(filename);450 if (file == NULL) {451 cerr << "ERROR: config file " << filename << " missing!" << endl;452 return;453 }454 599 RetrieveConfigPathAndName(filename); 455 // ParseParameters 600 601 // ParseParameterFile 602 struct ConfigFileBuffer *FileBuffer = new ConfigFileBuffer(filename); 603 FileBuffer->InitMapping(); 456 604 457 605 /* Oeffne Hauptparameterdatei */ … … 469 617 /* Namen einlesen */ 470 618 471 ParseForParameter(verbose, file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);472 ParseForParameter(verbose, file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);473 ParseForParameter(verbose, file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);474 ParseForParameter(verbose, file,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);475 ParseForParameter(verbose, file,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);476 477 if (!ParseForParameter(verbose, file,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))619 ParseForParameter(verbose,FileBuffer, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical); 620 ParseForParameter(verbose,FileBuffer, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical); 621 ParseForParameter(verbose,FileBuffer, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical); 622 ParseForParameter(verbose,FileBuffer,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical); 623 ParseForParameter(verbose,FileBuffer,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical); 624 625 if (!ParseForParameter(verbose,FileBuffer,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional)) 478 626 config::Seed = 1; 479 627 480 if(!ParseForParameter(verbose, file,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {628 if(!ParseForParameter(verbose,FileBuffer,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) { 481 629 config::DoOutOrbitals = 0; 482 630 } else { … … 484 632 if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1; 485 633 } 486 ParseForParameter(verbose, file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);634 ParseForParameter(verbose,FileBuffer,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical); 487 635 if (config::DoOutVis < 0) config::DoOutVis = 0; 488 636 if (config::DoOutVis > 1) config::DoOutVis = 1; 489 if (!ParseForParameter(verbose, file,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))637 if (!ParseForParameter(verbose,FileBuffer,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional)) 490 638 config::VectorPlane = -1; 491 if (!ParseForParameter(verbose, file,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))639 if (!ParseForParameter(verbose,FileBuffer,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional)) 492 640 config::VectorCut = 0.; 493 ParseForParameter(verbose, file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);641 ParseForParameter(verbose,FileBuffer,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical); 494 642 if (config::DoOutMes < 0) config::DoOutMes = 0; 495 643 if (config::DoOutMes > 1) config::DoOutMes = 1; 496 if (!ParseForParameter(verbose, file,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))644 if (!ParseForParameter(verbose,FileBuffer,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional)) 497 645 config::DoOutCurrent = 0; 498 646 if (config::DoOutCurrent < 0) config::DoOutCurrent = 0; 499 647 if (config::DoOutCurrent > 1) config::DoOutCurrent = 1; 500 ParseForParameter(verbose, file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);648 ParseForParameter(verbose,FileBuffer,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical); 501 649 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0; 502 650 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2; 503 if(!ParseForParameter(verbose, file,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {651 if(!ParseForParameter(verbose,FileBuffer,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) { 504 652 config::DoWannier = 0; 505 653 } else { … … 507 655 if (config::DoWannier > 1) config::DoWannier = 1; 508 656 } 509 if(!ParseForParameter(verbose, file,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {657 if(!ParseForParameter(verbose,FileBuffer,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) { 510 658 config::CommonWannier = 0; 511 659 } else { … … 513 661 if (config::CommonWannier > 4) config::CommonWannier = 4; 514 662 } 515 if(!ParseForParameter(verbose, file,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {663 if(!ParseForParameter(verbose,FileBuffer,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) { 516 664 config::SawtoothStart = 0.01; 517 665 } else { … … 520 668 } 521 669 522 ParseForParameter(verbose, file,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);523 if (!ParseForParameter(verbose, file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional))670 ParseForParameter(verbose,FileBuffer,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical); 671 if (!ParseForParameter(verbose,FileBuffer,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional)) 524 672 config::Deltat = 1; 525 ParseForParameter(verbose, file,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);526 ParseForParameter(verbose, file,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);527 ParseForParameter(verbose, file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);528 //ParseForParameter(verbose, file,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);529 if (!ParseForParameter(verbose, file,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))673 ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional); 674 ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional); 675 ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional); 676 //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional); 677 if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional)) 530 678 config::EpsWannier = 1e-8; 531 679 532 680 // stop conditions 533 681 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1; 534 ParseForParameter(verbose, file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);682 ParseForParameter(verbose,FileBuffer,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical); 535 683 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3; 536 684 537 ParseForParameter(verbose, file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);538 ParseForParameter(verbose, file,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);539 ParseForParameter(verbose, file,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);540 ParseForParameter(verbose, file,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);541 ParseForParameter(verbose, file,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);685 ParseForParameter(verbose,FileBuffer,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical); 686 ParseForParameter(verbose,FileBuffer,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical); 687 ParseForParameter(verbose,FileBuffer,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical); 688 ParseForParameter(verbose,FileBuffer,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical); 689 ParseForParameter(verbose,FileBuffer,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical); 542 690 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep; 543 691 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1; 544 692 if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1; 545 693 546 ParseForParameter(verbose, file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);547 ParseForParameter(verbose, file,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);548 ParseForParameter(verbose, file,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);549 ParseForParameter(verbose, file,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);550 ParseForParameter(verbose, file,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);694 ParseForParameter(verbose,FileBuffer,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical); 695 ParseForParameter(verbose,FileBuffer,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical); 696 ParseForParameter(verbose,FileBuffer,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical); 697 ParseForParameter(verbose,FileBuffer,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical); 698 ParseForParameter(verbose,FileBuffer,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical); 551 699 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep; 552 700 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1; … … 554 702 555 703 // Unit cell and magnetic field 556 ParseForParameter(verbose, file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */704 ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */ 557 705 mol->cell_size[0] = BoxLength[0]; 558 706 mol->cell_size[1] = BoxLength[3]; … … 561 709 mol->cell_size[4] = BoxLength[7]; 562 710 mol->cell_size[5] = BoxLength[8]; 563 if (1) fprintf(stderr,"\n");564 565 ParseForParameter(verbose, file,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);566 ParseForParameter(verbose, file,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);567 if (!ParseForParameter(verbose, file,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))711 //if (1) fprintf(stderr,"\n"); 712 713 ParseForParameter(verbose,FileBuffer,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional); 714 ParseForParameter(verbose,FileBuffer,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional); 715 if (!ParseForParameter(verbose,FileBuffer,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional)) 568 716 config::DoFullCurrent = 0; 569 717 if (config::DoFullCurrent < 0) config::DoFullCurrent = 0; … … 576 724 } 577 725 578 ParseForParameter(verbose, file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);579 ParseForParameter(verbose, file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);580 ParseForParameter(verbose, file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);726 ParseForParameter(verbose,FileBuffer,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical); 727 ParseForParameter(verbose,FileBuffer,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical); 728 ParseForParameter(verbose,FileBuffer,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical); 581 729 if (config::Lev0Factor < 2) { 582 730 config::Lev0Factor = 2; 583 731 } 584 ParseForParameter(verbose, file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);732 ParseForParameter(verbose,FileBuffer,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical); 585 733 if (di >= 0 && di < 2) { 586 734 config::RiemannTensor = di; … … 601 749 config::MaxLevel = 3; 602 750 } 603 ParseForParameter(verbose, file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);751 ParseForParameter(verbose,FileBuffer,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical); 604 752 if (config::RiemannLevel < 2) { 605 753 config::RiemannLevel = 2; … … 608 756 config::RiemannLevel = config::MaxLevel-1; 609 757 } 610 ParseForParameter(verbose, file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);758 ParseForParameter(verbose,FileBuffer,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical); 611 759 if (config::LevRFactor < 2) { 612 760 config::LevRFactor = 2; … … 616 764 break; 617 765 } 618 ParseForParameter(verbose, file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);766 ParseForParameter(verbose,FileBuffer,"PsiType", 0, 1, 1, int_type, &di, 1, critical); 619 767 if (di >= 0 && di < 2) { 620 768 config::PsiType = di; … … 625 773 switch (config::PsiType) { 626 774 case 0: // SpinDouble 627 ParseForParameter(verbose, file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);628 ParseForParameter(verbose, file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);775 ParseForParameter(verbose,FileBuffer,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical); 776 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional); 629 777 break; 630 778 case 1: // SpinUpDown 631 779 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2; 632 ParseForParameter(verbose, file,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);633 ParseForParameter(verbose, file,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);634 ParseForParameter(verbose, file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);780 ParseForParameter(verbose,FileBuffer,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical); 781 ParseForParameter(verbose,FileBuffer,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical); 782 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional); 635 783 break; 636 784 } … … 638 786 // IonsInitRead 639 787 640 ParseForParameter(verbose, file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);641 ParseForParameter(verbose, file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);642 ParseForParameter(verbose, file,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical);643 if (!ParseForParameter(verbose, file,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))788 ParseForParameter(verbose,FileBuffer,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical); 789 ParseForParameter(verbose,FileBuffer,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical); 790 ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical); 791 if (!ParseForParameter(verbose,FileBuffer,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional)) 644 792 config::RelativeCoord = 0; 645 if (!ParseForParameter(verbose, file,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))793 if (!ParseForParameter(verbose,FileBuffer,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional)) 646 794 config::StructOpt = 0; 647 795 if (MaxTypes == 0) { … … 650 798 // prescan number of ions per type 651 799 cout << Verbose(0) << "Prescanning ions per type: " << endl; 800 int NoAtoms = 0; 652 801 for (int i=0; i < config::MaxTypes; i++) { 653 802 sprintf(name,"Ion_Type%i",i+1); 654 ParseForParameter(verbose, file, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);655 ParseForParameter(verbose, file, name, 0, 2, 1, int_type, &Z, 1, critical);803 ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical); 804 ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical); 656 805 elementhash[i] = periode->FindElement(Z); 657 806 cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl; 807 NoAtoms += No[i]; 658 808 } 659 809 int repetition = 0; // which repeated keyword shall be read 660 810 811 // sort the lines via the LineMapping 812 sprintf(name,"Ion_Type%i",config::MaxTypes); 813 if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) { 814 cerr << "There are no atoms in the config file!" << endl; 815 return; 816 } 817 FileBuffer->CurrentLine++; 818 //cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine]]; 819 FileBuffer->MapIonTypesInBuffer(NoAtoms); 820 //for (int i=0; i<(NoAtoms < 100 ? NoAtoms : 100 < 100 ? NoAtoms : 100);++i) { 821 // cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine+i]]; 822 //} 823 661 824 map<int, atom *> AtomList[config::MaxTypes]; 825 map<int, atom *> LinearList; 662 826 if (!FastParsing) { 663 827 // parse in trajectories … … 673 837 neues = new atom(); 674 838 AtomList[i][j] = neues; 839 LinearList[FileBuffer->CurrentLine] = neues; 675 840 neues->type = elementhash[i]; // find element type 676 mol->AddAtom(neues);677 841 } else 678 842 neues = AtomList[i][j]; 679 680 ParseForParameter(verbose, file, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&681 ParseForParameter(verbose, file, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&682 ParseForParameter(verbose, file, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&683 ParseForParameter(verbose, file, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));843 status = (status && 844 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) && 845 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) && 846 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) && 847 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional)); 684 848 if (!status) break; 685 849 … … 697 861 698 862 // parse velocities if present 699 if(!ParseForParameter(verbose, file, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))863 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional)) 700 864 neues->v.x[0] = 0.; 701 if(!ParseForParameter(verbose, file, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))865 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional)) 702 866 neues->v.x[1] = 0.; 703 if(!ParseForParameter(verbose, file, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))867 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional)) 704 868 neues->v.x[2] = 0.; 705 869 for (int d=0;d<NDIM;d++) … … 707 871 708 872 // parse forces if present 709 if(!ParseForParameter(verbose, file, keyword, 0, 8, 1, double_type, &value[0], 1,optional))873 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 8, 1, double_type, &value[0], 1,optional)) 710 874 value[0] = 0.; 711 if(!ParseForParameter(verbose, file, keyword, 0, 9, 1, double_type, &value[1], 1,optional))875 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 9, 1, double_type, &value[1], 1,optional)) 712 876 value[1] = 0.; 713 if(!ParseForParameter(verbose, file, keyword, 1, 10, 1, double_type, &value[2], 1,optional))877 if(!ParseForParameter(verbose,FileBuffer, keyword, 1, 10, 1, double_type, &value[2], 1,optional)) 714 878 value[2] = 0.; 715 879 for (int d=0;d<NDIM;d++) … … 730 894 repetition++; 731 895 } 896 // put atoms into the molecule in their original order 897 for(map<int, atom*>::iterator runner = LinearList.begin(); runner != LinearList.end(); ++runner) { 898 mol->AddAtom(runner->second); 899 } 732 900 repetition--; 733 901 cout << "Found " << repetition << " trajectory steps." << endl; … … 736 904 // find the maximum number of MD steps so that we may parse last one (Ion_Type1_1 must always be present, because is the first atom) 737 905 repetition = 0; 738 while ( ParseForParameter(verbose, file, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&739 ParseForParameter(verbose, file, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&740 ParseForParameter(verbose, file, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))906 while ( ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) && 907 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) && 908 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional)) 741 909 repetition++; 742 910 cout << "I found " << repetition << " times the keyword Ion_Type1_1." << endl; … … 748 916 atom *neues = new atom(); 749 917 // then parse for each atom the coordinates as often as present 750 ParseForParameter(verbose, file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);751 ParseForParameter(verbose, file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);752 ParseForParameter(verbose, file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);753 ParseForParameter(verbose, file, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);754 if(!ParseForParameter(verbose, file, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))918 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical); 919 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical); 920 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical); 921 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical); 922 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional)) 755 923 neues->v.x[0] = 0.; 756 if(!ParseForParameter(verbose, file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))924 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional)) 757 925 neues->v.x[1] = 0.; 758 if(!ParseForParameter(verbose, file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))926 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional)) 759 927 neues->v.x[2] = 0.; 760 928 // here we don't care if forces are present (last in trajectories is always equal to current position) … … 765 933 } 766 934 } 767 file->close(); 768 delete(file); 935 delete(FileBuffer); 769 936 }; 770 937 … … 1203 1370 * \warning value is modified (both in contents and position)! 1204 1371 * \param verbose 1 - print found value to stderr, 0 - don't 1205 * \param file file to be parsed1372 * \param *file file to be parsed 1206 1373 * \param name Name of value in file (at least 3 chars!) 1207 1374 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning … … 1432 1599 return (found); // true if found, false if not 1433 1600 } 1601 1602 1603 /** Reads parameter from a parsed file. 1604 * The file is either parsed for a certain keyword or if null is given for 1605 * the value in row yth and column xth. If the keyword was necessity#critical, 1606 * then an error is thrown and the programme aborted. 1607 * \warning value is modified (both in contents and position)! 1608 * \param verbose 1 - print found value to stderr, 0 - don't 1609 * \param *FileBuffer pointer to buffer structure 1610 * \param name Name of value in file (at least 3 chars!) 1611 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning 1612 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read - 1613 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now 1614 * counted from this unresetted position!) 1615 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!) 1616 * \param yth In grid case specifying column number, otherwise the yth \a name matching line 1617 * \param type Type of the Parameter to be read 1618 * \param value address of the value to be read (must have been allocated) 1619 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply 1620 * \param critical necessity of this keyword being specified (optional, critical) 1621 * \return 1 - found, 0 - not found 1622 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++ 1623 */ 1624 int config::ParseForParameter(int verbose, struct ConfigFileBuffer *FileBuffer, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) { 1625 int i,j; // loop variables 1626 int length = 0, maxlength = -1; 1627 int OldCurrentLine = FileBuffer->CurrentLine; 1628 char *dummy1, *dummy; // pointers in the line that is read in per step 1629 1630 //fprintf(stderr,"Parsing for %s\n",name); 1631 if (repetition == 0) 1632 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!"); 1633 return 0; 1634 1635 int line = 0; // marks line where parameter was found 1636 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found 1637 while((found != repetition)) { 1638 dummy1 = dummy = NULL; 1639 do { 1640 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ]; 1641 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) { 1642 if ((critical) && (found == 0)) { 1643 //Error(InitReading, name); 1644 fprintf(stderr,"Error:InitReading, critical %s not found\n", name); 1645 exit(255); 1646 } else { 1647 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1648 return 0; 1649 } 1650 } 1651 if (dummy1 == NULL) { 1652 if (verbose) fprintf(stderr,"Error reading line %i\n",line); 1653 } else { 1654 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1); 1655 } 1656 line++; 1657 } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines 1658 1659 // Seek for possible end of keyword on line if given ... 1660 if (name != NULL) { 1661 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer 1662 if (dummy == NULL) { 1663 dummy = strchr(dummy1, ' '); // if not found seek for space 1664 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary 1665 dummy++; 1666 } 1667 if (dummy == NULL) { 1668 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword) 1669 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name); 1670 //Free((void **)&free_dummy); 1671 //Error(FileOpenParams, NULL); 1672 } else { 1673 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1); 1674 } 1675 } else dummy = dummy1; 1676 // ... and check if it is the keyword! 1677 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name)); 1678 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) { 1679 found++; // found the parameter! 1680 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy); 1681 1682 if (found == repetition) { 1683 for (i=0;i<xth;i++) { // i = rows 1684 if (type >= grid) { 1685 // grid structure means that grid starts on the next line, not right after keyword 1686 dummy1 = dummy = NULL; 1687 do { 1688 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ]; 1689 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) { 1690 if ((critical) && (found == 0)) { 1691 //Error(InitReading, name); 1692 fprintf(stderr,"Error:InitReading, critical %s not found\n", name); 1693 exit(255); 1694 } else { 1695 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1696 return 0; 1697 } 1698 } 1699 if (dummy1 == NULL) { 1700 if (verbose) fprintf(stderr,"Error reading line %i\n", line); 1701 } else { 1702 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1); 1703 } 1704 line++; 1705 } while (dummy1 != NULL && (dummy1[0] == '#') || (dummy1[0] == '\n')); 1706 dummy = dummy1; 1707 } else { // simple int, strings or doubles start in the same line 1708 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces 1709 dummy++; 1710 } 1711 1712 for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns 1713 // check for lower triangular area and upper triangular area 1714 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) { 1715 *((double *)value) = 0.0; 1716 fprintf(stderr,"%f\t",*((double *)value)); 1717 value = (void *)((long)value + sizeof(double)); 1718 //value += sizeof(double); 1719 } else { 1720 // otherwise we must skip all interjacent tabs and spaces and find next value 1721 dummy1 = dummy; 1722 dummy = strchr(dummy1, '\t'); // seek for tab or space 1723 if (dummy == NULL) 1724 dummy = strchr(dummy1, ' '); // if not found seek for space 1725 if (dummy == NULL) { // if still zero returned ... 1726 dummy = strchr(dummy1, '\n'); // ... at line end then 1727 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet 1728 if (critical) { 1729 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name); 1730 //return 0; 1731 exit(255); 1732 //Error(FileOpenParams, NULL); 1733 } else { 1734 if (!sequential) { // here we need it! 1735 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1736 } 1737 return 0; 1738 } 1739 } 1740 } else { 1741 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy); 1742 } 1743 if (*dummy1 == '#') { 1744 // found comment, skipping rest of line 1745 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name); 1746 if (!sequential) { // here we need it! 1747 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1748 } 1749 return 0; 1750 } 1751 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy); 1752 switch(type) { 1753 case (row_int): 1754 *((int *)value) = atoi(dummy1); 1755 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name); 1756 if (verbose) fprintf(stderr,"%i\t",*((int *)value)); 1757 value = (void *)((long)value + sizeof(int)); 1758 //value += sizeof(int); 1759 break; 1760 case(row_double): 1761 case(grid): 1762 case(lower_trigrid): 1763 case(upper_trigrid): 1764 *((double *)value) = atof(dummy1); 1765 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name); 1766 if (verbose) fprintf(stderr,"%lg\t",*((double *)value)); 1767 value = (void *)((long)value + sizeof(double)); 1768 //value += sizeof(double); 1769 break; 1770 case(double_type): 1771 *((double *)value) = atof(dummy1); 1772 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value)); 1773 //value += sizeof(double); 1774 break; 1775 case(int_type): 1776 *((int *)value) = atoi(dummy1); 1777 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value)); 1778 //value += sizeof(int); 1779 break; 1780 default: 1781 case(string_type): 1782 if (value != NULL) { 1783 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array 1784 maxlength = MAXSTRINGSIZE; 1785 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum 1786 strncpy((char *)value, dummy1, length); // copy as much 1787 ((char *)value)[length] = '\0'; // and set end marker 1788 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length); 1789 //value += sizeof(char); 1790 } else { 1791 } 1792 break; 1793 } 1794 } 1795 while (*dummy == '\t') 1796 dummy++; 1797 } 1798 } 1799 } 1800 } 1801 } 1802 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n"); 1803 if (!sequential) { 1804 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position 1805 } 1806 //fprintf(stderr, "End of Parsing\n\n"); 1807 1808 return (found); // true if found, false if not 1809 } -
src/molecules.cpp
r6cb412 rd1df9b 1471 1471 atom *walker = NULL; 1472 1472 int ElementNo[MAX_ELEMENTS], AtomNo[MAX_ELEMENTS]; 1473 int CurrentMaxElement = 0;1474 1473 CountElements(); 1475 1474 … … 1485 1484 while (walker->next != end) { // go through every atom of this element 1486 1485 walker = walker->next; 1487 if (ElementNo[walker->type->Z] == 0) // new element 1488 ElementNo[walker->type->Z] = ++CurrentMaxElement; 1486 ElementNo[walker->type->Z] = 1; 1487 } 1488 int current=1; 1489 for (int i=0;i<MAX_ELEMENTS;++i) { 1490 if (ElementNo[i] == 1) 1491 ElementNo[i] = current++; 1492 } 1493 walker = start; 1494 while (walker->next != end) { // go through every atom of this element 1495 walker = walker->next; 1489 1496 AtomNo[walker->type->Z]++; 1490 1497 walker->Output(ElementNo[walker->type->Z], AtomNo[walker->type->Z], out); // removed due to trajectories … … 1501 1508 atom *walker = NULL; 1502 1509 int ElementNo[MAX_ELEMENTS], AtomNo[MAX_ELEMENTS]; 1503 int CurrentMaxElement = 0;1504 1510 CountElements(); 1505 1511 … … 1517 1523 ElementNo[i] = 0; 1518 1524 } 1519 walker = start; 1525 walker = start; 1526 while (walker->next != end) { // go through every atom of this element 1527 walker = walker->next; 1528 ElementNo[walker->type->Z] = 1; 1529 } 1530 int current=1; 1531 for (int i=0;i<MAX_ELEMENTS;++i) { 1532 if (ElementNo[i] == 1) 1533 ElementNo[i] = current++; 1534 } 1535 walker = start; 1520 1536 while (walker->next != end) { // go through every atom of this element 1521 1537 walker = walker->next; 1522 if (ElementNo[walker->type->Z] == 0) // new element1523 ElementNo[walker->type->Z] = ++CurrentMaxElement;1524 1538 AtomNo[walker->type->Z]++; 1525 1539 *out << "Ion_Type" << ElementNo[walker->type->Z] << "_" << AtomNo[walker->type->Z] << "\t" << fixed << setprecision(9) << showpoint; -
src/molecules.hpp
r6cb412 rd1df9b 392 392 }; 393 393 394 class ConfigFileBuffer { 395 public: 396 char **buffer; 397 int *LineMapping; 398 int CurrentLine; 399 int NoLines; 400 401 ConfigFileBuffer(); 402 ConfigFileBuffer(char *filename); 403 ~ConfigFileBuffer(); 404 405 void InitMapping(); 406 void MapIonTypesInBuffer(int NoAtoms); 407 }; 408 409 394 410 /** The config file. 395 411 * The class contains all parameters that control a dft run also functions to load and save. … … 469 485 470 486 int ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical); 487 int ParseForParameter(int verbose, struct ConfigFileBuffer *FileBuffer, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical); 471 488 472 489 public:
Note:
See TracChangeset
for help on using the changeset viewer.