[14de469] | 1 | /** \file config.cpp
|
---|
| 2 | *
|
---|
| 3 | * Function implementations for the class config.
|
---|
| 4 | *
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | #include "molecules.hpp"
|
---|
| 8 |
|
---|
| 9 | /************************************* Functions for class config ***************************/
|
---|
| 10 |
|
---|
| 11 | /** Constructor for config file class.
|
---|
| 12 | */
|
---|
| 13 | config::config()
|
---|
| 14 | {
|
---|
| 15 | mainname = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
|
---|
| 16 | defaultpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
|
---|
| 17 | pseudopotpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
|
---|
| 18 | strcpy(mainname,"pcp");
|
---|
| 19 | strcpy(defaultpath,"not specified ");
|
---|
| 20 | strcpy(pseudopotpath,"not specified ");
|
---|
| 21 |
|
---|
| 22 | ProcPEGamma=8;
|
---|
| 23 | ProcPEPsi=1;
|
---|
| 24 | DoOutVis=0;
|
---|
| 25 | DoOutMes=1;
|
---|
| 26 | DoOutNICS=0;
|
---|
| 27 | DoOutOrbitals=0;
|
---|
| 28 | DoOutCurrent=0;
|
---|
| 29 | DoPerturbation=0;
|
---|
| 30 | DoFullCurrent=0;
|
---|
| 31 | CommonWannier=0;
|
---|
| 32 | SawtoothStart=0.01;
|
---|
| 33 | VectorPlane=0;
|
---|
| 34 | VectorCut=0;
|
---|
| 35 | UseAddGramSch=1;
|
---|
| 36 | Seed=1;
|
---|
| 37 |
|
---|
| 38 | MaxOuterStep=0;
|
---|
| 39 | Deltat=0;
|
---|
| 40 | OutVisStep=10;
|
---|
| 41 | OutSrcStep=5;
|
---|
| 42 | TargetTemp=0.00095004455;
|
---|
| 43 | ScaleTempStep=25;
|
---|
| 44 | MaxPsiStep=0;
|
---|
| 45 | EpsWannier=1e-7;
|
---|
| 46 |
|
---|
| 47 | MaxMinStep=100;
|
---|
| 48 | RelEpsTotalEnergy=1e-7;
|
---|
| 49 | RelEpsKineticEnergy=1e-5;
|
---|
| 50 | MaxMinStopStep=1;
|
---|
| 51 | MaxMinGapStopStep=0;
|
---|
| 52 | MaxInitMinStep=100;
|
---|
| 53 | InitRelEpsTotalEnergy=1e-5;
|
---|
| 54 | InitRelEpsKineticEnergy=1e-4;
|
---|
| 55 | InitMaxMinStopStep=1;
|
---|
| 56 | InitMaxMinGapStopStep=0;
|
---|
| 57 |
|
---|
| 58 | //BoxLength[NDIM*NDIM];
|
---|
| 59 |
|
---|
| 60 | ECut=128.;
|
---|
| 61 | MaxLevel=5;
|
---|
| 62 | RiemannTensor=0;
|
---|
| 63 | LevRFactor=0;
|
---|
| 64 | RiemannLevel=0;
|
---|
| 65 | Lev0Factor=2;
|
---|
| 66 | RTActualUse=0;
|
---|
| 67 | PsiType=0;
|
---|
| 68 | MaxPsiDouble=0;
|
---|
| 69 | PsiMaxNoUp=0;
|
---|
| 70 | PsiMaxNoDown=0;
|
---|
| 71 | AddPsis=0;
|
---|
| 72 |
|
---|
| 73 | RCut=20.;
|
---|
| 74 | StructOpt=0;
|
---|
| 75 | IsAngstroem=1;
|
---|
| 76 | RelativeCoord=0;
|
---|
| 77 | MaxTypes=0;
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | /** Destructor for config file class.
|
---|
| 82 | */
|
---|
| 83 | config::~config()
|
---|
| 84 | {
|
---|
| 85 | Free((void **)&mainname, "config::~config: *mainname");
|
---|
| 86 | Free((void **)&defaultpath, "config::~config: *defaultpath");
|
---|
| 87 | Free((void **)&pseudopotpath, "config::~config: *pseudopotpath");
|
---|
| 88 | };
|
---|
| 89 |
|
---|
| 90 | /** Displays menu for editing each entry of the config file.
|
---|
| 91 | * Nothing fancy here, just lots of cout << Verbose(0)s for the menu and a switch/case
|
---|
| 92 | * for each entry of the config file structure.
|
---|
| 93 | */
|
---|
| 94 | void config::Edit(molecule *mol)
|
---|
| 95 | {
|
---|
| 96 | char choice;
|
---|
| 97 |
|
---|
| 98 | do {
|
---|
| 99 | cout << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl;
|
---|
| 100 | cout << Verbose(0) << " A - mainname (prefix for all runtime files)" << endl;
|
---|
| 101 | cout << Verbose(0) << " B - Default path (for runtime files)" << endl;
|
---|
| 102 | cout << Verbose(0) << " C - Path of pseudopotential files" << endl;
|
---|
| 103 | cout << Verbose(0) << " D - Number of coefficient sharing processes" << endl;
|
---|
| 104 | cout << Verbose(0) << " E - Number of wave function sharing processes" << endl;
|
---|
| 105 | cout << Verbose(0) << " F - 0: Don't output density for OpenDX, 1: do" << endl;
|
---|
| 106 | cout << Verbose(0) << " G - 0: Don't output physical data, 1: do" << endl;
|
---|
| 107 | cout << Verbose(0) << " H - 0: Don't output densities of each unperturbed orbital for OpenDX, 1: do" << endl;
|
---|
| 108 | cout << Verbose(0) << " I - 0: Don't output current density for OpenDX, 1: do" << endl;
|
---|
| 109 | cout << Verbose(0) << " J - 0: Don't do the full current calculation, 1: do" << endl;
|
---|
| 110 | cout << Verbose(0) << " K - 0: Don't do perturbation calculation to obtain susceptibility and shielding, 1: do" << endl;
|
---|
| 111 | cout << Verbose(0) << " L - 0: Wannier centres as calculated, 1: common centre for all, 2: unite centres according to spread, 3: cell centre, 4: shifted to nearest grid point" << endl;
|
---|
| 112 | cout << Verbose(0) << " M - Absolute begin of unphysical sawtooth transfer for position operator within cell" << endl;
|
---|
| 113 | cout << Verbose(0) << " N - (0,1,2) x,y,z-plane to do two-dimensional current vector cut" << endl;
|
---|
| 114 | cout << Verbose(0) << " O - Absolute position along vector cut axis for cut plane" << endl;
|
---|
| 115 | cout << Verbose(0) << " P - Additional Gram-Schmidt-Orthonormalization to stabilize numerics" << endl;
|
---|
| 116 | cout << Verbose(0) << " Q - Initial integer value of random number generator" << endl;
|
---|
| 117 | cout << Verbose(0) << " R - for perturbation 0, for structure optimization defines upper limit of iterations" << endl;
|
---|
| 118 | cout << Verbose(0) << " T - Output visual after ...th step" << endl;
|
---|
| 119 | cout << Verbose(0) << " U - Output source densities of wave functions after ...th step" << endl;
|
---|
| 120 | cout << Verbose(0) << " X - minimization iterations per wave function, if unsure leave at default value 0" << endl;
|
---|
| 121 | cout << Verbose(0) << " Y - tolerance value for total spread in iterative Jacobi diagonalization" << endl;
|
---|
| 122 | cout << Verbose(0) << " Z - Maximum number of minimization iterations" << endl;
|
---|
| 123 | cout << Verbose(0) << " a - Relative change in total energy to stop min. iteration" << endl;
|
---|
| 124 | cout << Verbose(0) << " b - Relative change in kinetic energy to stop min. iteration" << endl;
|
---|
| 125 | cout << Verbose(0) << " c - Check stop conditions every ..th step during min. iteration" << endl;
|
---|
| 126 | cout << Verbose(0) << " e - Maximum number of minimization iterations during initial level" << endl;
|
---|
| 127 | cout << Verbose(0) << " f - Relative change in total energy to stop min. iteration during initial level" << endl;
|
---|
| 128 | cout << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl;
|
---|
| 129 | cout << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl;
|
---|
| 130 | cout << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
|
---|
| 131 | cout << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl;
|
---|
| 132 | cout << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl;
|
---|
| 133 | cout << Verbose(0) << " m - Factor by which grid nodes increase between standard and upper level" << endl;
|
---|
| 134 | cout << Verbose(0) << " n - 0: Don't use RiemannTensor, 1: Do" << endl;
|
---|
| 135 | cout << Verbose(0) << " o - Factor by which grid nodes increase between Riemann and standard(?) level" << endl;
|
---|
| 136 | cout << Verbose(0) << " p - Number of Riemann levels" << endl;
|
---|
| 137 | cout << Verbose(0) << " r - 0: Don't Use RiemannTensor, 1: Do" << endl;
|
---|
| 138 | cout << Verbose(0) << " s - 0: Doubly occupied orbitals, 1: Up-/Down-Orbitals" << endl;
|
---|
| 139 | cout << Verbose(0) << " t - Number of orbitals (depends pn SpinType)" << endl;
|
---|
| 140 | cout << Verbose(0) << " u - Number of SpinUp orbitals (depends on SpinType)" << endl;
|
---|
| 141 | cout << Verbose(0) << " v - Number of SpinDown orbitals (depends on SpinType)" << endl;
|
---|
| 142 | cout << Verbose(0) << " w - Number of additional, unoccupied orbitals" << endl;
|
---|
| 143 | cout << Verbose(0) << " x - radial cutoff for ewald summation in Bohrradii" << endl;
|
---|
| 144 | cout << Verbose(0) << " y - 0: Don't do structure optimization beforehand, 1: Do" << endl;
|
---|
| 145 | cout << Verbose(0) << " z - 0: Units are in Bohr radii, 1: units are in Aengstrom" << endl;
|
---|
| 146 | cout << Verbose(0) << " i - 0: Coordinates given in file are absolute, 1: ... are relative to unit cell" << endl;
|
---|
| 147 | cout << Verbose(0) << "=========================================================" << endl;
|
---|
| 148 | cout << Verbose(0) << "INPUT: ";
|
---|
| 149 | cin >> choice;
|
---|
| 150 |
|
---|
| 151 | switch (choice) {
|
---|
| 152 | case 'A': // mainname
|
---|
| 153 | cout << Verbose(0) << "Old: " << config::mainname << "\t new: ";
|
---|
| 154 | cin >> config::mainname;
|
---|
| 155 | break;
|
---|
| 156 | case 'B': // defaultpath
|
---|
| 157 | cout << Verbose(0) << "Old: " << config::defaultpath << "\t new: ";
|
---|
| 158 | cin >> config::defaultpath;
|
---|
| 159 | break;
|
---|
| 160 | case 'C': // pseudopotpath
|
---|
| 161 | cout << Verbose(0) << "Old: " << config::pseudopotpath << "\t new: ";
|
---|
| 162 | cin >> config::pseudopotpath;
|
---|
| 163 | break;
|
---|
| 164 |
|
---|
| 165 | case 'D': // ProcPEGamma
|
---|
| 166 | cout << Verbose(0) << "Old: " << config::ProcPEGamma << "\t new: ";
|
---|
| 167 | cin >> config::ProcPEGamma;
|
---|
| 168 | break;
|
---|
| 169 | case 'E': // ProcPEPsi
|
---|
| 170 | cout << Verbose(0) << "Old: " << config::ProcPEPsi << "\t new: ";
|
---|
| 171 | cin >> config::ProcPEPsi;
|
---|
| 172 | break;
|
---|
| 173 | case 'F': // DoOutVis
|
---|
| 174 | cout << Verbose(0) << "Old: " << config::DoOutVis << "\t new: ";
|
---|
| 175 | cin >> config::DoOutVis;
|
---|
| 176 | break;
|
---|
| 177 | case 'G': // DoOutMes
|
---|
| 178 | cout << Verbose(0) << "Old: " << config::DoOutMes << "\t new: ";
|
---|
| 179 | cin >> config::DoOutMes;
|
---|
| 180 | break;
|
---|
| 181 | case 'H': // DoOutOrbitals
|
---|
| 182 | cout << Verbose(0) << "Old: " << config::DoOutOrbitals << "\t new: ";
|
---|
| 183 | cin >> config::DoOutOrbitals;
|
---|
| 184 | break;
|
---|
| 185 | case 'I': // DoOutCurrent
|
---|
| 186 | cout << Verbose(0) << "Old: " << config::DoOutCurrent << "\t new: ";
|
---|
| 187 | cin >> config::DoOutCurrent;
|
---|
| 188 | break;
|
---|
| 189 | case 'J': // DoFullCurrent
|
---|
| 190 | cout << Verbose(0) << "Old: " << config::DoFullCurrent << "\t new: ";
|
---|
| 191 | cin >> config::DoFullCurrent;
|
---|
| 192 | break;
|
---|
| 193 | case 'K': // DoPerturbation
|
---|
| 194 | cout << Verbose(0) << "Old: " << config::DoPerturbation << "\t new: ";
|
---|
| 195 | cin >> config::DoPerturbation;
|
---|
| 196 | break;
|
---|
| 197 | case 'L': // CommonWannier
|
---|
| 198 | cout << Verbose(0) << "Old: " << config::CommonWannier << "\t new: ";
|
---|
| 199 | cin >> config::CommonWannier;
|
---|
| 200 | break;
|
---|
| 201 | case 'M': // SawtoothStart
|
---|
| 202 | cout << Verbose(0) << "Old: " << config::SawtoothStart << "\t new: ";
|
---|
| 203 | cin >> config::SawtoothStart;
|
---|
| 204 | break;
|
---|
| 205 | case 'N': // VectorPlane
|
---|
| 206 | cout << Verbose(0) << "Old: " << config::VectorPlane << "\t new: ";
|
---|
| 207 | cin >> config::VectorPlane;
|
---|
| 208 | break;
|
---|
| 209 | case 'O': // VectorCut
|
---|
| 210 | cout << Verbose(0) << "Old: " << config::VectorCut << "\t new: ";
|
---|
| 211 | cin >> config::VectorCut;
|
---|
| 212 | break;
|
---|
| 213 | case 'P': // UseAddGramSch
|
---|
| 214 | cout << Verbose(0) << "Old: " << config::UseAddGramSch << "\t new: ";
|
---|
| 215 | cin >> config::UseAddGramSch;
|
---|
| 216 | break;
|
---|
| 217 | case 'Q': // Seed
|
---|
| 218 | cout << Verbose(0) << "Old: " << config::Seed << "\t new: ";
|
---|
| 219 | cin >> config::Seed;
|
---|
| 220 | break;
|
---|
| 221 |
|
---|
| 222 | case 'R': // MaxOuterStep
|
---|
| 223 | cout << Verbose(0) << "Old: " << config::MaxOuterStep << "\t new: ";
|
---|
| 224 | cin >> config::MaxOuterStep;
|
---|
| 225 | break;
|
---|
| 226 | case 'T': // OutVisStep
|
---|
| 227 | cout << Verbose(0) << "Old: " << config::OutVisStep << "\t new: ";
|
---|
| 228 | cin >> config::OutVisStep;
|
---|
| 229 | break;
|
---|
| 230 | case 'U': // OutSrcStep
|
---|
| 231 | cout << Verbose(0) << "Old: " << config::OutSrcStep << "\t new: ";
|
---|
| 232 | cin >> config::OutSrcStep;
|
---|
| 233 | break;
|
---|
| 234 | case 'X': // MaxPsiStep
|
---|
| 235 | cout << Verbose(0) << "Old: " << config::MaxPsiStep << "\t new: ";
|
---|
| 236 | cin >> config::MaxPsiStep;
|
---|
| 237 | break;
|
---|
| 238 | case 'Y': // EpsWannier
|
---|
| 239 | cout << Verbose(0) << "Old: " << config::EpsWannier << "\t new: ";
|
---|
| 240 | cin >> config::EpsWannier;
|
---|
| 241 | break;
|
---|
| 242 |
|
---|
| 243 | case 'Z': // MaxMinStep
|
---|
| 244 | cout << Verbose(0) << "Old: " << config::MaxMinStep << "\t new: ";
|
---|
| 245 | cin >> config::MaxMinStep;
|
---|
| 246 | break;
|
---|
| 247 | case 'a': // RelEpsTotalEnergy
|
---|
| 248 | cout << Verbose(0) << "Old: " << config::RelEpsTotalEnergy << "\t new: ";
|
---|
| 249 | cin >> config::RelEpsTotalEnergy;
|
---|
| 250 | break;
|
---|
| 251 | case 'b': // RelEpsKineticEnergy
|
---|
| 252 | cout << Verbose(0) << "Old: " << config::RelEpsKineticEnergy << "\t new: ";
|
---|
| 253 | cin >> config::RelEpsKineticEnergy;
|
---|
| 254 | break;
|
---|
| 255 | case 'c': // MaxMinStopStep
|
---|
| 256 | cout << Verbose(0) << "Old: " << config::MaxMinStopStep << "\t new: ";
|
---|
| 257 | cin >> config::MaxMinStopStep;
|
---|
| 258 | break;
|
---|
| 259 | case 'e': // MaxInitMinStep
|
---|
| 260 | cout << Verbose(0) << "Old: " << config::MaxInitMinStep << "\t new: ";
|
---|
| 261 | cin >> config::MaxInitMinStep;
|
---|
| 262 | break;
|
---|
| 263 | case 'f': // InitRelEpsTotalEnergy
|
---|
| 264 | cout << Verbose(0) << "Old: " << config::InitRelEpsTotalEnergy << "\t new: ";
|
---|
| 265 | cin >> config::InitRelEpsTotalEnergy;
|
---|
| 266 | break;
|
---|
| 267 | case 'g': // InitRelEpsKineticEnergy
|
---|
| 268 | cout << Verbose(0) << "Old: " << config::InitRelEpsKineticEnergy << "\t new: ";
|
---|
| 269 | cin >> config::InitRelEpsKineticEnergy;
|
---|
| 270 | break;
|
---|
| 271 | case 'h': // InitMaxMinStopStep
|
---|
| 272 | cout << Verbose(0) << "Old: " << config::InitMaxMinStopStep << "\t new: ";
|
---|
| 273 | cin >> config::InitMaxMinStopStep;
|
---|
| 274 | break;
|
---|
| 275 |
|
---|
| 276 | case 'j': // BoxLength
|
---|
| 277 | cout << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
|
---|
| 278 | for (int i=0;i<6;i++) {
|
---|
| 279 | cout << Verbose(0) << "Cell size" << i << ": ";
|
---|
| 280 | cin >> mol->cell_size[i];
|
---|
| 281 | }
|
---|
| 282 | break;
|
---|
| 283 |
|
---|
| 284 | case 'k': // ECut
|
---|
| 285 | cout << Verbose(0) << "Old: " << config::ECut << "\t new: ";
|
---|
| 286 | cin >> config::ECut;
|
---|
| 287 | break;
|
---|
| 288 | case 'l': // MaxLevel
|
---|
| 289 | cout << Verbose(0) << "Old: " << config::MaxLevel << "\t new: ";
|
---|
| 290 | cin >> config::MaxLevel;
|
---|
| 291 | break;
|
---|
| 292 | case 'm': // RiemannTensor
|
---|
| 293 | cout << Verbose(0) << "Old: " << config::RiemannTensor << "\t new: ";
|
---|
| 294 | cin >> config::RiemannTensor;
|
---|
| 295 | break;
|
---|
| 296 | case 'n': // LevRFactor
|
---|
| 297 | cout << Verbose(0) << "Old: " << config::LevRFactor << "\t new: ";
|
---|
| 298 | cin >> config::LevRFactor;
|
---|
| 299 | break;
|
---|
| 300 | case 'o': // RiemannLevel
|
---|
| 301 | cout << Verbose(0) << "Old: " << config::RiemannLevel << "\t new: ";
|
---|
| 302 | cin >> config::RiemannLevel;
|
---|
| 303 | break;
|
---|
| 304 | case 'p': // Lev0Factor
|
---|
| 305 | cout << Verbose(0) << "Old: " << config::Lev0Factor << "\t new: ";
|
---|
| 306 | cin >> config::Lev0Factor;
|
---|
| 307 | break;
|
---|
| 308 | case 'r': // RTActualUse
|
---|
| 309 | cout << Verbose(0) << "Old: " << config::RTActualUse << "\t new: ";
|
---|
| 310 | cin >> config::RTActualUse;
|
---|
| 311 | break;
|
---|
| 312 | case 's': // PsiType
|
---|
| 313 | cout << Verbose(0) << "Old: " << config::PsiType << "\t new: ";
|
---|
| 314 | cin >> config::PsiType;
|
---|
| 315 | break;
|
---|
| 316 | case 't': // MaxPsiDouble
|
---|
| 317 | cout << Verbose(0) << "Old: " << config::MaxPsiDouble << "\t new: ";
|
---|
| 318 | cin >> config::MaxPsiDouble;
|
---|
| 319 | break;
|
---|
| 320 | case 'u': // PsiMaxNoUp
|
---|
| 321 | cout << Verbose(0) << "Old: " << config::PsiMaxNoUp << "\t new: ";
|
---|
| 322 | cin >> config::PsiMaxNoUp;
|
---|
| 323 | break;
|
---|
| 324 | case 'v': // PsiMaxNoDown
|
---|
| 325 | cout << Verbose(0) << "Old: " << config::PsiMaxNoDown << "\t new: ";
|
---|
| 326 | cin >> config::PsiMaxNoDown;
|
---|
| 327 | break;
|
---|
| 328 | case 'w': // AddPsis
|
---|
| 329 | cout << Verbose(0) << "Old: " << config::AddPsis << "\t new: ";
|
---|
| 330 | cin >> config::AddPsis;
|
---|
| 331 | break;
|
---|
| 332 |
|
---|
| 333 | case 'x': // RCut
|
---|
| 334 | cout << Verbose(0) << "Old: " << config::RCut << "\t new: ";
|
---|
| 335 | cin >> config::RCut;
|
---|
| 336 | break;
|
---|
| 337 | case 'y': // StructOpt
|
---|
| 338 | cout << Verbose(0) << "Old: " << config::StructOpt << "\t new: ";
|
---|
| 339 | cin >> config::StructOpt;
|
---|
| 340 | break;
|
---|
| 341 | case 'z': // IsAngstroem
|
---|
| 342 | cout << Verbose(0) << "Old: " << config::IsAngstroem << "\t new: ";
|
---|
| 343 | cin >> config::IsAngstroem;
|
---|
| 344 | break;
|
---|
| 345 | case 'i': // RelativeCoord
|
---|
| 346 | cout << Verbose(0) << "Old: " << config::RelativeCoord << "\t new: ";
|
---|
| 347 | cin >> config::RelativeCoord;
|
---|
| 348 | break;
|
---|
| 349 | };
|
---|
| 350 | } while (choice != 'q');
|
---|
| 351 | };
|
---|
| 352 |
|
---|
| 353 | /** Tests whether a given configuration file adhears to old or new syntax.
|
---|
| 354 | * \param *file input file stream being the opened config file
|
---|
| 355 | * \param *periode pointer to a periodentafel class with all elements
|
---|
| 356 | * \param *mol pointer to molecule containing all atoms of the molecule
|
---|
| 357 | * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
|
---|
| 358 | */
|
---|
| 359 | int config::TestSyntax(ifstream *file, periodentafel *periode, molecule *mol)
|
---|
| 360 | {
|
---|
| 361 | int test;
|
---|
| 362 | // search file for keyword: ProcPEGamma (new syntax)
|
---|
| 363 | if (ParseForParameter(1,file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional))
|
---|
| 364 | return 1;
|
---|
| 365 | // search file for keyword: ProcsGammaPsi (old syntax)
|
---|
| 366 | if (ParseForParameter(1,file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional))
|
---|
| 367 | return 0;
|
---|
| 368 | return -1;
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | /** Returns private config::IsAngstroem.
|
---|
| 372 | * \return IsAngstroem
|
---|
| 373 | */
|
---|
| 374 | bool config::GetIsAngstroem() const
|
---|
| 375 | {
|
---|
| 376 | return (IsAngstroem == 1);
|
---|
| 377 | };
|
---|
| 378 |
|
---|
| 379 | /** Returns private config::*defaultpath.
|
---|
| 380 | * \return *defaultpath
|
---|
| 381 | */
|
---|
| 382 | char * config::GetDefaultPath() const
|
---|
| 383 | {
|
---|
| 384 | return defaultpath;
|
---|
| 385 | };
|
---|
| 386 |
|
---|
| 387 |
|
---|
| 388 | /** Returns private config::*defaultpath.
|
---|
| 389 | * \return *defaultpath
|
---|
| 390 | */
|
---|
| 391 | void config::SetDefaultPath(const char *path)
|
---|
| 392 | {
|
---|
| 393 | strcpy(defaultpath, path);
|
---|
| 394 | };
|
---|
| 395 |
|
---|
| 396 | /** Initializes config file structure by loading elements from a give file.
|
---|
| 397 | * \param *file input file stream being the opened config file
|
---|
| 398 | * \param *periode pointer to a periodentafel class with all elements
|
---|
| 399 | * \param *mol pointer to molecule containing all atoms of the molecule
|
---|
| 400 | */
|
---|
| 401 | void config::Load(ifstream *file, periodentafel *periode, molecule *mol)
|
---|
| 402 | {
|
---|
| 403 | // ParseParameters
|
---|
| 404 |
|
---|
| 405 | /* Oeffne Hauptparameterdatei */
|
---|
| 406 | int di;
|
---|
| 407 | double BoxLength[9];
|
---|
| 408 | string zeile;
|
---|
| 409 | string dummy;
|
---|
| 410 | element *elementhash[128];
|
---|
| 411 | char name[128];
|
---|
| 412 | char keyword[128];
|
---|
| 413 | int Z, No;
|
---|
| 414 | int verbose = 0;
|
---|
| 415 |
|
---|
| 416 | /* Namen einlesen */
|
---|
| 417 |
|
---|
| 418 | ParseForParameter(verbose,file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
|
---|
| 419 | ParseForParameter(verbose,file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
|
---|
| 420 | ParseForParameter(verbose,file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
|
---|
| 421 | ParseForParameter(verbose,file,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
|
---|
| 422 | ParseForParameter(verbose,file,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
|
---|
| 423 |
|
---|
| 424 | if (!ParseForParameter(verbose,file,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
|
---|
| 425 | config::Seed = 1;
|
---|
| 426 |
|
---|
| 427 | if(!ParseForParameter(verbose,file,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
|
---|
| 428 | config::DoOutOrbitals = 0;
|
---|
| 429 | } else {
|
---|
| 430 | if (config::DoOutOrbitals < 0) config::DoOutOrbitals = 0;
|
---|
| 431 | if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1;
|
---|
| 432 | }
|
---|
| 433 | ParseForParameter(verbose,file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
|
---|
| 434 | if (config::DoOutVis < 0) config::DoOutVis = 0;
|
---|
| 435 | if (config::DoOutVis > 1) config::DoOutVis = 1;
|
---|
| 436 | if (!ParseForParameter(verbose,file,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
|
---|
| 437 | config::VectorPlane = -1;
|
---|
| 438 | if (!ParseForParameter(verbose,file,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
|
---|
| 439 | config::VectorCut = 0.;
|
---|
| 440 | ParseForParameter(verbose,file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
|
---|
| 441 | if (config::DoOutMes < 0) config::DoOutMes = 0;
|
---|
| 442 | if (config::DoOutMes > 1) config::DoOutMes = 1;
|
---|
| 443 | if (!ParseForParameter(verbose,file,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
|
---|
| 444 | config::DoOutCurrent = 0;
|
---|
| 445 | if (config::DoOutCurrent < 0) config::DoOutCurrent = 0;
|
---|
| 446 | if (config::DoOutCurrent > 1) config::DoOutCurrent = 1;
|
---|
| 447 | ParseForParameter(verbose,file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
|
---|
| 448 | if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
|
---|
| 449 | if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
|
---|
| 450 | if(!ParseForParameter(verbose,file,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
|
---|
| 451 | config::CommonWannier = 0;
|
---|
| 452 | } else {
|
---|
| 453 | if (config::CommonWannier < 0) config::CommonWannier = 0;
|
---|
| 454 | if (config::CommonWannier > 4) config::CommonWannier = 4;
|
---|
| 455 | }
|
---|
| 456 | if(!ParseForParameter(verbose,file,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
|
---|
| 457 | config::SawtoothStart = 0.01;
|
---|
| 458 | } else {
|
---|
| 459 | if (config::SawtoothStart < 0.) config::SawtoothStart = 0.;
|
---|
| 460 | if (config::SawtoothStart > 1.) config::SawtoothStart = 1.;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
|
---|
| 464 | ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional);
|
---|
| 465 | ParseForParameter(verbose,file,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
|
---|
| 466 | ParseForParameter(verbose,file,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
|
---|
| 467 | ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
|
---|
| 468 | //ParseForParameter(verbose,file,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
|
---|
| 469 | if (!ParseForParameter(verbose,file,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
|
---|
| 470 | config::EpsWannier = 1e-8;
|
---|
| 471 |
|
---|
| 472 | // stop conditions
|
---|
| 473 | //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
|
---|
| 474 | ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
|
---|
| 475 | if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
|
---|
| 476 |
|
---|
| 477 | ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
|
---|
| 478 | ParseForParameter(verbose,file,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
|
---|
| 479 | ParseForParameter(verbose,file,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
|
---|
| 480 | ParseForParameter(verbose,file,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
|
---|
| 481 | ParseForParameter(verbose,file,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
|
---|
| 482 | if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
|
---|
| 483 | if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
|
---|
| 484 | if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1;
|
---|
| 485 |
|
---|
| 486 | ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
|
---|
| 487 | ParseForParameter(verbose,file,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
|
---|
| 488 | ParseForParameter(verbose,file,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
|
---|
| 489 | ParseForParameter(verbose,file,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
|
---|
| 490 | ParseForParameter(verbose,file,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
|
---|
| 491 | if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
|
---|
| 492 | if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
|
---|
| 493 | if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1;
|
---|
| 494 |
|
---|
| 495 | // Unit cell and magnetic field
|
---|
| 496 | ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
|
---|
| 497 | mol->cell_size[0] = BoxLength[0];
|
---|
| 498 | mol->cell_size[1] = BoxLength[3];
|
---|
| 499 | mol->cell_size[2] = BoxLength[4];
|
---|
| 500 | mol->cell_size[3] = BoxLength[6];
|
---|
| 501 | mol->cell_size[4] = BoxLength[7];
|
---|
| 502 | mol->cell_size[5] = BoxLength[8];
|
---|
| 503 | if (1) fprintf(stderr,"\n");
|
---|
| 504 |
|
---|
| 505 | ParseForParameter(verbose,file,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
|
---|
| 506 | ParseForParameter(verbose,file,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
|
---|
| 507 | if (!ParseForParameter(verbose,file,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
|
---|
| 508 | config::DoFullCurrent = 0;
|
---|
| 509 | if (config::DoFullCurrent < 0) config::DoFullCurrent = 0;
|
---|
| 510 | if (config::DoFullCurrent > 2) config::DoFullCurrent = 2;
|
---|
| 511 | if (config::DoOutNICS < 0) config::DoOutNICS = 0;
|
---|
| 512 | if (config::DoOutNICS > 2) config::DoOutNICS = 2;
|
---|
| 513 | if (config::DoPerturbation == 0) {
|
---|
| 514 | config::DoFullCurrent = 0;
|
---|
| 515 | config::DoOutNICS = 0;
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 | ParseForParameter(verbose,file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
|
---|
| 519 | ParseForParameter(verbose,file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
|
---|
| 520 | ParseForParameter(verbose,file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
|
---|
| 521 | if (config::Lev0Factor < 2) {
|
---|
| 522 | config::Lev0Factor = 2;
|
---|
| 523 | }
|
---|
| 524 | ParseForParameter(verbose,file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
|
---|
| 525 | if (di >= 0 && di < 2) {
|
---|
| 526 | config::RiemannTensor = di;
|
---|
| 527 | } else {
|
---|
| 528 | fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
|
---|
| 529 | exit(1);
|
---|
| 530 | }
|
---|
| 531 | switch (config::RiemannTensor) {
|
---|
| 532 | case 0: //UseNoRT
|
---|
| 533 | if (config::MaxLevel < 2) {
|
---|
| 534 | config::MaxLevel = 2;
|
---|
| 535 | }
|
---|
| 536 | config::LevRFactor = 2;
|
---|
| 537 | config::RTActualUse = 0;
|
---|
| 538 | break;
|
---|
| 539 | case 1: // UseRT
|
---|
| 540 | if (config::MaxLevel < 3) {
|
---|
| 541 | config::MaxLevel = 3;
|
---|
| 542 | }
|
---|
| 543 | ParseForParameter(verbose,file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
|
---|
| 544 | if (config::RiemannLevel < 2) {
|
---|
| 545 | config::RiemannLevel = 2;
|
---|
| 546 | }
|
---|
| 547 | if (config::RiemannLevel > config::MaxLevel-1) {
|
---|
| 548 | config::RiemannLevel = config::MaxLevel-1;
|
---|
| 549 | }
|
---|
| 550 | ParseForParameter(verbose,file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
|
---|
| 551 | if (config::LevRFactor < 2) {
|
---|
| 552 | config::LevRFactor = 2;
|
---|
| 553 | }
|
---|
| 554 | config::Lev0Factor = 2;
|
---|
| 555 | config::RTActualUse = 2;
|
---|
| 556 | break;
|
---|
| 557 | }
|
---|
| 558 | ParseForParameter(verbose,file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
|
---|
| 559 | if (di >= 0 && di < 2) {
|
---|
| 560 | config::PsiType = di;
|
---|
| 561 | } else {
|
---|
| 562 | fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
|
---|
| 563 | exit(1);
|
---|
| 564 | }
|
---|
| 565 | switch (config::PsiType) {
|
---|
| 566 | case 0: // SpinDouble
|
---|
| 567 | ParseForParameter(verbose,file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
|
---|
| 568 | ParseForParameter(verbose,file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
|
---|
| 569 | break;
|
---|
| 570 | case 1: // SpinUpDown
|
---|
| 571 | if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
|
---|
| 572 | ParseForParameter(verbose,file,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
|
---|
| 573 | ParseForParameter(verbose,file,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
|
---|
| 574 | ParseForParameter(verbose,file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
|
---|
| 575 | break;
|
---|
| 576 | }
|
---|
| 577 |
|
---|
| 578 | // IonsInitRead
|
---|
| 579 |
|
---|
| 580 | ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
|
---|
| 581 | ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
|
---|
| 582 | ParseForParameter(verbose,file,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical);
|
---|
| 583 | if (!ParseForParameter(verbose,file,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
|
---|
| 584 | config::RelativeCoord = 0;
|
---|
| 585 | if (!ParseForParameter(verbose,file,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
|
---|
| 586 | config::StructOpt = 0;
|
---|
| 587 | for (int i=0; i < config::MaxTypes; i++) {
|
---|
| 588 | sprintf(name,"Ion_Type%i",i+1);
|
---|
| 589 | ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No, 1, critical);
|
---|
| 590 | ParseForParameter(verbose,file, name, 0, 2, 1, int_type, &Z, 1, critical);
|
---|
| 591 | elementhash[i] = periode->FindElement(Z);
|
---|
| 592 | for(int j=0;j<No;j++) {
|
---|
| 593 | int repetition = 1; // which repeated keyword shall be read
|
---|
| 594 | sprintf(keyword,"%s_%i",name, j+1);
|
---|
| 595 | atom *neues = new atom();
|
---|
| 596 | // then parse for each atom the coordinates as often as present
|
---|
| 597 | while (ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition, (repetition == 1) ? critical : optional) &&
|
---|
| 598 | ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition, (repetition == 1) ? critical : optional) &&
|
---|
| 599 | ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition, (repetition == 1) ? critical : optional))
|
---|
| 600 | repetition++;
|
---|
| 601 | repetition--;
|
---|
| 602 | cout << "Found " << repetition << " times of the keyword " << keyword << "." << endl;
|
---|
| 603 | ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
|
---|
| 604 | ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
|
---|
| 605 | ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
|
---|
[943d02] | 606 | ParseForParameter(verbose,file, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
|
---|
| 607 | if(!ParseForParameter(verbose,file, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
|
---|
| 608 | neues->v.x[0] = 0.;
|
---|
| 609 | if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
|
---|
| 610 | neues->v.x[1] = 0.;
|
---|
| 611 | if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
|
---|
| 612 | neues->v.x[2] = 0.;
|
---|
[14de469] | 613 | neues->type = elementhash[i]; // find element type
|
---|
| 614 | mol->AddAtom(neues);
|
---|
| 615 | }
|
---|
| 616 | }
|
---|
| 617 | };
|
---|
| 618 |
|
---|
| 619 | /** Initializes config file structure by loading elements from a give file with old pcp syntax.
|
---|
| 620 | * \param *file input file stream being the opened config file with old pcp syntax
|
---|
| 621 | * \param *periode pointer to a periodentafel class with all elements
|
---|
| 622 | * \param *mol pointer to molecule containing all atoms of the molecule
|
---|
| 623 | */
|
---|
| 624 | void config::LoadOld(ifstream *file, periodentafel *periode, molecule *mol)
|
---|
| 625 | {
|
---|
| 626 | // ParseParameters
|
---|
| 627 |
|
---|
| 628 | /* Oeffne Hauptparameterdatei */
|
---|
| 629 | int l, i, di;
|
---|
| 630 | double a,b;
|
---|
| 631 | double BoxLength[9];
|
---|
| 632 | string zeile;
|
---|
| 633 | string dummy;
|
---|
| 634 | element *elementhash[128];
|
---|
| 635 | int Z, No, AtomNo, found;
|
---|
| 636 | int verbose = 0;
|
---|
| 637 |
|
---|
| 638 | /* Namen einlesen */
|
---|
| 639 |
|
---|
| 640 | ParseForParameter(verbose,file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
|
---|
| 641 | ParseForParameter(verbose,file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
|
---|
| 642 | ParseForParameter(verbose,file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
|
---|
| 643 | ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
|
---|
| 644 | ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 2, 1, int_type, &(config::ProcPEPsi), 1, critical);
|
---|
| 645 | config::Seed = 1;
|
---|
| 646 | config::DoOutOrbitals = 0;
|
---|
| 647 | ParseForParameter(verbose,file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
|
---|
| 648 | if (config::DoOutVis < 0) config::DoOutVis = 0;
|
---|
| 649 | if (config::DoOutVis > 1) config::DoOutVis = 1;
|
---|
| 650 | config::VectorPlane = -1;
|
---|
| 651 | config::VectorCut = 0.;
|
---|
| 652 | ParseForParameter(verbose,file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
|
---|
| 653 | if (config::DoOutMes < 0) config::DoOutMes = 0;
|
---|
| 654 | if (config::DoOutMes > 1) config::DoOutMes = 1;
|
---|
| 655 | config::DoOutCurrent = 0;
|
---|
| 656 | ParseForParameter(verbose,file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
|
---|
| 657 | if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
|
---|
| 658 | if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
|
---|
| 659 | config::CommonWannier = 0;
|
---|
| 660 | config::SawtoothStart = 0.01;
|
---|
| 661 |
|
---|
| 662 | ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, double_type, &(config::MaxOuterStep), 1, critical);
|
---|
| 663 | ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional);
|
---|
| 664 | ParseForParameter(verbose,file,"VisOuterStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
|
---|
| 665 | ParseForParameter(verbose,file,"VisSrcOuterStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
|
---|
| 666 | ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
|
---|
| 667 | ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
|
---|
| 668 | config::EpsWannier = 1e-8;
|
---|
| 669 |
|
---|
| 670 | // stop conditions
|
---|
| 671 | //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
|
---|
| 672 | ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
|
---|
| 673 | if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
|
---|
| 674 |
|
---|
| 675 | ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
|
---|
| 676 | ParseForParameter(verbose,file,"MaxMinStep", 0, 2, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
|
---|
| 677 | ParseForParameter(verbose,file,"MaxMinStep", 0, 3, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
|
---|
| 678 | ParseForParameter(verbose,file,"MaxMinStep", 0, 4, 1, int_type, &(config::MaxMinStopStep), 1, critical);
|
---|
| 679 | if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
|
---|
| 680 | if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
|
---|
| 681 | config::MaxMinGapStopStep = 1;
|
---|
| 682 |
|
---|
| 683 | ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
|
---|
| 684 | ParseForParameter(verbose,file,"MaxInitMinStep", 0, 2, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
|
---|
| 685 | ParseForParameter(verbose,file,"MaxInitMinStep", 0, 3, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
|
---|
| 686 | ParseForParameter(verbose,file,"MaxInitMinStep", 0, 4, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
|
---|
| 687 | if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
|
---|
| 688 | if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
|
---|
| 689 | config::InitMaxMinGapStopStep = 1;
|
---|
| 690 |
|
---|
| 691 | ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
|
---|
| 692 | mol->cell_size[0] = BoxLength[0];
|
---|
| 693 | mol->cell_size[1] = BoxLength[3];
|
---|
| 694 | mol->cell_size[2] = BoxLength[4];
|
---|
| 695 | mol->cell_size[3] = BoxLength[6];
|
---|
| 696 | mol->cell_size[4] = BoxLength[7];
|
---|
| 697 | mol->cell_size[5] = BoxLength[8];
|
---|
| 698 | if (1) fprintf(stderr,"\n");
|
---|
| 699 | config::DoPerturbation = 0;
|
---|
| 700 | config::DoFullCurrent = 0;
|
---|
| 701 |
|
---|
| 702 | ParseForParameter(verbose,file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
|
---|
| 703 | ParseForParameter(verbose,file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
|
---|
| 704 | ParseForParameter(verbose,file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
|
---|
| 705 | if (config::Lev0Factor < 2) {
|
---|
| 706 | config::Lev0Factor = 2;
|
---|
| 707 | }
|
---|
| 708 | ParseForParameter(verbose,file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
|
---|
| 709 | if (di >= 0 && di < 2) {
|
---|
| 710 | config::RiemannTensor = di;
|
---|
| 711 | } else {
|
---|
| 712 | fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
|
---|
| 713 | exit(1);
|
---|
| 714 | }
|
---|
| 715 | switch (config::RiemannTensor) {
|
---|
| 716 | case 0: //UseNoRT
|
---|
| 717 | if (config::MaxLevel < 2) {
|
---|
| 718 | config::MaxLevel = 2;
|
---|
| 719 | }
|
---|
| 720 | config::LevRFactor = 2;
|
---|
| 721 | config::RTActualUse = 0;
|
---|
| 722 | break;
|
---|
| 723 | case 1: // UseRT
|
---|
| 724 | if (config::MaxLevel < 3) {
|
---|
| 725 | config::MaxLevel = 3;
|
---|
| 726 | }
|
---|
| 727 | ParseForParameter(verbose,file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
|
---|
| 728 | if (config::RiemannLevel < 2) {
|
---|
| 729 | config::RiemannLevel = 2;
|
---|
| 730 | }
|
---|
| 731 | if (config::RiemannLevel > config::MaxLevel-1) {
|
---|
| 732 | config::RiemannLevel = config::MaxLevel-1;
|
---|
| 733 | }
|
---|
| 734 | ParseForParameter(verbose,file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
|
---|
| 735 | if (config::LevRFactor < 2) {
|
---|
| 736 | config::LevRFactor = 2;
|
---|
| 737 | }
|
---|
| 738 | config::Lev0Factor = 2;
|
---|
| 739 | config::RTActualUse = 2;
|
---|
| 740 | break;
|
---|
| 741 | }
|
---|
| 742 | ParseForParameter(verbose,file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
|
---|
| 743 | if (di >= 0 && di < 2) {
|
---|
| 744 | config::PsiType = di;
|
---|
| 745 | } else {
|
---|
| 746 | fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
|
---|
| 747 | exit(1);
|
---|
| 748 | }
|
---|
| 749 | switch (config::PsiType) {
|
---|
| 750 | case 0: // SpinDouble
|
---|
| 751 | ParseForParameter(verbose,file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
|
---|
| 752 | config::AddPsis = 0;
|
---|
| 753 | break;
|
---|
| 754 | case 1: // SpinUpDown
|
---|
| 755 | if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
|
---|
| 756 | ParseForParameter(verbose,file,"MaxPsiUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
|
---|
| 757 | ParseForParameter(verbose,file,"MaxPsiDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
|
---|
| 758 | config::AddPsis = 0;
|
---|
| 759 | break;
|
---|
| 760 | }
|
---|
| 761 |
|
---|
| 762 | // IonsInitRead
|
---|
| 763 |
|
---|
| 764 | ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
|
---|
| 765 | ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
|
---|
| 766 | config::RelativeCoord = 0;
|
---|
| 767 | config::StructOpt = 0;
|
---|
| 768 |
|
---|
| 769 | // Routine from builder.cpp
|
---|
| 770 |
|
---|
| 771 |
|
---|
| 772 | for (i=0;i<128;i++) elementhash[i] = NULL;
|
---|
| 773 | cout << Verbose(0) << "Parsing Ions ..." << endl;
|
---|
| 774 | No=0;
|
---|
| 775 | found = 0;
|
---|
| 776 | while (getline(*file,zeile,'\n')) {
|
---|
| 777 | if (zeile.find("Ions_Data") == 0) {
|
---|
| 778 | cout << Verbose(1) << "found Ions_Data...begin parsing" << endl;
|
---|
| 779 | found ++;
|
---|
| 780 | }
|
---|
| 781 | if (found > 0) {
|
---|
| 782 | if (zeile.find("Ions_Data") == 0)
|
---|
| 783 | getline(*file,zeile,'\n'); // read next line and parse this one
|
---|
| 784 | istringstream input(zeile);
|
---|
| 785 | input >> AtomNo; // number of atoms
|
---|
| 786 | input >> Z; // atomic number
|
---|
| 787 | input >> a;
|
---|
| 788 | input >> l;
|
---|
| 789 | input >> l;
|
---|
| 790 | input >> b; // element mass
|
---|
| 791 | elementhash[No] = periode->FindElement(Z);
|
---|
| 792 | cout << Verbose(1) << "AtomNo: " << AtomNo << "\tZ: " << Z << "\ta:" << a << "\tl:" << l << "\b:" << b << "\tElement:" << elementhash[No] << "\t:" << endl;
|
---|
| 793 | for(i=0;i<AtomNo;i++) {
|
---|
| 794 | if (!getline(*file,zeile,'\n')) {// parse on and on
|
---|
| 795 | cout << Verbose(2) << "Error: Too few items in ionic list of element" << elementhash[No] << "." << endl << "Exiting." << endl;
|
---|
| 796 | // return 1;
|
---|
| 797 | } else {
|
---|
| 798 | //cout << Verbose(2) << "Reading line: " << zeile << endl;
|
---|
| 799 | }
|
---|
| 800 | istringstream input2(zeile);
|
---|
| 801 | atom *neues = new atom();
|
---|
| 802 | input2 >> neues->x.x[0]; // x
|
---|
| 803 | input2 >> neues->x.x[1]; // y
|
---|
| 804 | input2 >> neues->x.x[2]; // z
|
---|
| 805 | input2 >> l;
|
---|
| 806 | neues->type = elementhash[No]; // find element type
|
---|
| 807 | mol->AddAtom(neues);
|
---|
| 808 | }
|
---|
| 809 | No++;
|
---|
| 810 | }
|
---|
| 811 | }
|
---|
| 812 | };
|
---|
| 813 |
|
---|
| 814 | /** Stores all elements of config structure from which they can be re-read.
|
---|
| 815 | * \param output open output *file stream to write to
|
---|
| 816 | * \param *periode pointer to a periodentafel class with all elements
|
---|
| 817 | * \param *mol pointer to molecule containing all atoms of the molecule
|
---|
| 818 | */
|
---|
| 819 | bool config::Save(ofstream *output, periodentafel *periode, molecule *mol) const
|
---|
| 820 | {
|
---|
| 821 | bool result = true;
|
---|
| 822 | // bring MaxTypes up to date
|
---|
| 823 | mol->CountElements();
|
---|
| 824 | if (output != NULL) {
|
---|
| 825 | *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
|
---|
| 826 | *output << endl;
|
---|
| 827 | *output << "mainname\t" << config::mainname << "\t# programm name (for runtime files)" << endl;
|
---|
| 828 | *output << "defaultpath\t" << config::defaultpath << "\t# where to put files during runtime" << endl;
|
---|
| 829 | *output << "pseudopotpath\t" << config::pseudopotpath << "\t# where to find pseudopotentials" << endl;
|
---|
| 830 | *output << endl;
|
---|
| 831 | *output << "ProcPEGamma\t" << config::ProcPEGamma << "\t# for parallel computing: share constants" << endl;
|
---|
| 832 | *output << "ProcPEPsi\t" << config::ProcPEPsi << "\t# for parallel computing: share wave functions" << endl;
|
---|
| 833 | *output << "DoOutVis\t" << config::DoOutVis << "\t# Output data for OpenDX" << endl;
|
---|
| 834 | *output << "DoOutMes\t" << config::DoOutMes << "\t# Output data for measurements" << endl;
|
---|
| 835 | *output << "DoOutOrbitals\t" << config::DoOutOrbitals << "\t# Output all Orbitals" << endl;
|
---|
| 836 | *output << "DoOutCurr\t" << config::DoOutCurrent << "\t# Ouput current density for OpenDx" << endl;
|
---|
| 837 | *output << "DoOutNICS\t" << config::DoOutNICS << "\t# Output Nucleus independent current shieldings" << endl;
|
---|
| 838 | *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
|
---|
| 839 | *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
|
---|
| 840 | *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
|
---|
| 841 | *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
|
---|
| 842 | *output << "VectorPlane\t" << config::VectorPlane << "\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot" << endl;
|
---|
| 843 | *output << "VectorCut\t" << config::VectorCut << "\t# Cut plane axis value" << endl;
|
---|
| 844 | *output << "AddGramSch\t" << config::UseAddGramSch << "\t# Additional GramSchmidtOrtogonalization to be safe" << endl;
|
---|
| 845 | *output << "Seed\t\t" << config::Seed << "\t# initial value for random seed for Psi coefficients" << endl;
|
---|
| 846 | *output << endl;
|
---|
| 847 | *output << "MaxOuterStep\t" << config::MaxOuterStep << "\t# number of MolecularDynamics/Structure optimization steps" << endl;
|
---|
| 848 | *output << "Deltat\t" << config::Deltat << "\t# time per MD step" << endl;
|
---|
| 849 | *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
|
---|
| 850 | *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
|
---|
| 851 | *output << "TargetTemp\t" << config::TargetTemp << "\t# Target temperature" << endl;
|
---|
| 852 | *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
|
---|
| 853 | *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
|
---|
| 854 | *output << endl;
|
---|
| 855 | *output << "# Values specifying when to stop" << endl;
|
---|
| 856 | *output << "MaxMinStep\t" << config::MaxMinStep << "\t# Maximum number of steps" << endl;
|
---|
| 857 | *output << "RelEpsTotalE\t" << config::RelEpsTotalEnergy << "\t# relative change in total energy" << endl;
|
---|
| 858 | *output << "RelEpsKineticE\t" << config::RelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
|
---|
| 859 | *output << "MaxMinStopStep\t" << config::MaxMinStopStep << "\t# check every ..th steps" << endl;
|
---|
| 860 | *output << "MaxMinGapStopStep\t" << config::MaxMinGapStopStep << "\t# check every ..th steps" << endl;
|
---|
| 861 | *output << endl;
|
---|
| 862 | *output << "# Values specifying when to stop for INIT, otherwise same as above" << endl;
|
---|
| 863 | *output << "MaxInitMinStep\t" << config::MaxInitMinStep << "\t# Maximum number of steps" << endl;
|
---|
| 864 | *output << "InitRelEpsTotalE\t" << config::InitRelEpsTotalEnergy << "\t# relative change in total energy" << endl;
|
---|
| 865 | *output << "InitRelEpsKineticE\t" << config::InitRelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
|
---|
| 866 | *output << "InitMaxMinStopStep\t" << config::InitMaxMinStopStep << "\t# check every ..th steps" << endl;
|
---|
| 867 | *output << "InitMaxMinGapStopStep\t" << config::InitMaxMinGapStopStep << "\t# check every ..th steps" << endl;
|
---|
| 868 | *output << endl;
|
---|
| 869 | *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
|
---|
| 870 | *output << mol->cell_size[0] << "\t" << endl;
|
---|
| 871 | *output << mol->cell_size[1] << "\t" << mol->cell_size[2] << "\t" << endl;
|
---|
| 872 | *output << mol->cell_size[3] << "\t" << mol->cell_size[4] << "\t" << mol->cell_size[5] << "\t" << endl;
|
---|
| 873 | // FIXME
|
---|
| 874 | *output << endl;
|
---|
| 875 | *output << "ECut\t\t" << config::ECut << "\t# energy cutoff for discretization in Hartrees" << endl;
|
---|
| 876 | *output << "MaxLevel\t" << config::MaxLevel << "\t# number of different levels in the code, >=2" << endl;
|
---|
| 877 | *output << "Level0Factor\t" << config::Lev0Factor << "\t# factor by which node number increases from S to 0 level" << endl;
|
---|
| 878 | *output << "RiemannTensor\t" << config::RiemannTensor << "\t# (Use metric)" << endl;
|
---|
| 879 | switch (config::RiemannTensor) {
|
---|
| 880 | case 0: //UseNoRT
|
---|
| 881 | break;
|
---|
| 882 | case 1: // UseRT
|
---|
| 883 | *output << "RiemannLevel\t" << config::RiemannLevel << "\t# Number of Riemann Levels" << endl;
|
---|
| 884 | *output << "LevRFactor\t" << config::LevRFactor << "\t# factor by which node number increases from 0 to R level from" << endl;
|
---|
| 885 | break;
|
---|
| 886 | }
|
---|
| 887 | *output << "PsiType\t\t" << config::PsiType << "\t# 0 - doubly occupied, 1 - SpinUp,SpinDown" << endl;
|
---|
| 888 | // write out both types for easier changing afterwards
|
---|
| 889 | // switch (PsiType) {
|
---|
| 890 | // case 0:
|
---|
| 891 | *output << "MaxPsiDouble\t" << config::MaxPsiDouble << "\t# here: specifying both maximum number of SpinUp- and -Down-states" << endl;
|
---|
| 892 | // break;
|
---|
| 893 | // case 1:
|
---|
| 894 | *output << "PsiMaxNoUp\t" << config::PsiMaxNoUp << "\t# here: specifying maximum number of SpinUp-states" << endl;
|
---|
| 895 | *output << "PsiMaxNoDown\t" << config::PsiMaxNoDown << "\t# here: specifying maximum number of SpinDown-states" << endl;
|
---|
| 896 | // break;
|
---|
| 897 | // }
|
---|
| 898 | *output << "AddPsis\t\t" << config::AddPsis << "\t# Additional unoccupied Psis for bandgap determination" << endl;
|
---|
| 899 | *output << endl;
|
---|
| 900 | *output << "RCut\t\t" << config::RCut << "\t# R-cut for the ewald summation" << endl;
|
---|
| 901 | *output << "StructOpt\t" << config::StructOpt << "\t# Do structure optimization beforehand" << endl;
|
---|
| 902 | *output << "IsAngstroem\t" << config::IsAngstroem << "\t# 0 - Bohr, 1 - Angstroem" << endl;
|
---|
| 903 | *output << "RelativeCoord\t" << config::RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
|
---|
| 904 | *output << "MaxTypes\t" << mol->ElementCount << "\t# maximum number of different ion types" << endl;
|
---|
| 905 | *output << endl;
|
---|
| 906 | result = result && mol->Checkout(output);
|
---|
| 907 | result = result && mol->Output(output);
|
---|
| 908 | return result;
|
---|
| 909 | } else
|
---|
| 910 | return false;
|
---|
| 911 | };
|
---|
| 912 |
|
---|
| 913 | /** Reads parameter from a parsed file.
|
---|
| 914 | * The file is either parsed for a certain keyword or if null is given for
|
---|
| 915 | * the value in row yth and column xth. If the keyword was necessity#critical,
|
---|
| 916 | * then an error is thrown and the programme aborted.
|
---|
| 917 | * \warning value is modified (both in contents and position)!
|
---|
| 918 | * \param verbose 1 - print found value to stderr, 0 - don't
|
---|
| 919 | * \param file file to be parsed
|
---|
| 920 | * \param name Name of value in file (at least 3 chars!)
|
---|
| 921 | * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
|
---|
| 922 | * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
|
---|
| 923 | * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
|
---|
| 924 | * counted from this unresetted position!)
|
---|
| 925 | * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
|
---|
| 926 | * \param yth In grid case specifying column number, otherwise the yth \a name matching line
|
---|
| 927 | * \param type Type of the Parameter to be read
|
---|
| 928 | * \param value address of the value to be read (must have been allocated)
|
---|
| 929 | * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
|
---|
| 930 | * \param critical necessity of this keyword being specified (optional, critical)
|
---|
| 931 | * \return 1 - found, 0 - not found
|
---|
| 932 | * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
|
---|
| 933 | */
|
---|
| 934 | int config::ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) {
|
---|
| 935 | int i,j; // loop variables
|
---|
| 936 | int length = 0, maxlength = -1;
|
---|
| 937 | long file_position = file->tellg(); // mark current position
|
---|
| 938 | char *dummy1, *dummy, *free_dummy; // pointers in the line that is read in per step
|
---|
| 939 | dummy1 = free_dummy = (char *) Malloc(256 * sizeof(char), "config::ParseForParameter: *free_dummy");
|
---|
| 940 |
|
---|
| 941 | //fprintf(stderr,"Parsing for %s\n",name);
|
---|
| 942 | if (repetition == 0)
|
---|
| 943 | //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
|
---|
| 944 | return 0;
|
---|
| 945 |
|
---|
| 946 | int line = 0; // marks line where parameter was found
|
---|
| 947 | int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
|
---|
| 948 | while((found != repetition)) {
|
---|
| 949 | dummy1 = dummy = free_dummy;
|
---|
| 950 | do {
|
---|
| 951 | file->getline(dummy1, 256); // Read the whole line
|
---|
| 952 | if (file->eof()) {
|
---|
| 953 | if ((critical) && (found == 0)) {
|
---|
| 954 | Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
|
---|
| 955 | //Error(InitReading, name);
|
---|
| 956 | fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
|
---|
| 957 | exit(255);
|
---|
| 958 | } else {
|
---|
| 959 | //if (!sequential)
|
---|
| 960 | file->clear();
|
---|
| 961 | file->seekg(file_position, ios::beg); // rewind to start position
|
---|
| 962 | Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
|
---|
| 963 | return 0;
|
---|
| 964 | }
|
---|
| 965 | }
|
---|
| 966 | line++;
|
---|
| 967 | } while (((dummy1[0] == '#') || (dummy1[0] == '\n')) && dummy != NULL); // skip commentary and empty lines
|
---|
| 968 |
|
---|
| 969 | // C++ getline removes newline at end, thus re-add
|
---|
| 970 | if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
|
---|
| 971 | i = strlen(dummy1);
|
---|
| 972 | dummy1[i] = '\n';
|
---|
| 973 | dummy1[i+1] = '\0';
|
---|
| 974 | }
|
---|
| 975 | //fprintf(stderr,"line ends at %i, newline at %i\n", strlen(dummy1), strchr(dummy1,'\n')-free_dummy);
|
---|
| 976 | if (dummy1 == NULL) {
|
---|
| 977 | if (verbose) fprintf(stderr,"Error reading line %i\n",line);
|
---|
| 978 | } else {
|
---|
| 979 | //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
|
---|
| 980 | }
|
---|
| 981 | // Seek for possible end of keyword on line if given ...
|
---|
| 982 | if (name != NULL) {
|
---|
| 983 | dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
|
---|
| 984 | if (dummy == NULL) {
|
---|
| 985 | dummy = strchr(dummy1, ' '); // if not found seek for space
|
---|
| 986 | while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
|
---|
| 987 | dummy++;
|
---|
| 988 | }
|
---|
| 989 | if (dummy == NULL) {
|
---|
| 990 | dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
|
---|
| 991 | //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
|
---|
| 992 | //Free((void **)&free_dummy);
|
---|
| 993 | //Error(FileOpenParams, NULL);
|
---|
| 994 | } else {
|
---|
| 995 | //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
|
---|
| 996 | }
|
---|
| 997 | } else dummy = dummy1;
|
---|
| 998 | // ... and check if it is the keyword!
|
---|
| 999 | //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
|
---|
| 1000 | if ((name == NULL) || ((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name))) {
|
---|
| 1001 | found++; // found the parameter!
|
---|
| 1002 | //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
|
---|
| 1003 |
|
---|
| 1004 | if (found == repetition) {
|
---|
| 1005 | for (i=0;i<xth;i++) { // i = rows
|
---|
| 1006 | if (type >= grid) {
|
---|
| 1007 | // grid structure means that grid starts on the next line, not right after keyword
|
---|
| 1008 | dummy1 = dummy = free_dummy;
|
---|
| 1009 | do {
|
---|
| 1010 | file->getline(dummy1, 256); // Read the whole line, skip commentary and empty ones
|
---|
| 1011 | if (file->eof()) {
|
---|
| 1012 | if ((critical) && (found == 0)) {
|
---|
| 1013 | Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
|
---|
| 1014 | //Error(InitReading, name);
|
---|
| 1015 | fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
|
---|
| 1016 | exit(255);
|
---|
| 1017 | } else {
|
---|
| 1018 | //if (!sequential)
|
---|
| 1019 | file->clear();
|
---|
| 1020 | file->seekg(file_position, ios::beg); // rewind to start position
|
---|
| 1021 | Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
|
---|
| 1022 | return 0;
|
---|
| 1023 | }
|
---|
| 1024 | }
|
---|
| 1025 | line++;
|
---|
| 1026 | } while ((dummy1[0] == '#') || (dummy1[0] == '\n'));
|
---|
| 1027 | if (dummy1 == NULL){
|
---|
| 1028 | if (verbose) fprintf(stderr,"Error reading line %i\n", line);
|
---|
| 1029 | } else {
|
---|
| 1030 | //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
|
---|
| 1031 | }
|
---|
| 1032 | } else { // simple int, strings or doubles start in the same line
|
---|
| 1033 | while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
|
---|
| 1034 | dummy++;
|
---|
| 1035 | }
|
---|
| 1036 | // C++ getline removes newline at end, thus re-add
|
---|
| 1037 | if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
|
---|
| 1038 | j = strlen(dummy1);
|
---|
| 1039 | dummy1[j] = '\n';
|
---|
| 1040 | dummy1[j+1] = '\0';
|
---|
| 1041 | }
|
---|
| 1042 |
|
---|
| 1043 | int start = (type >= grid) ? 0 : yth-1 ;
|
---|
| 1044 | for (j=start;j<yth;j++) { // j = columns
|
---|
| 1045 | // check for lower triangular area and upper triangular area
|
---|
| 1046 | if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
|
---|
| 1047 | *((double *)value) = 0.0;
|
---|
| 1048 | fprintf(stderr,"%f\t",*((double *)value));
|
---|
| 1049 | value = (void *)((long)value + sizeof(double));
|
---|
| 1050 | //value += sizeof(double);
|
---|
| 1051 | } else {
|
---|
| 1052 | // otherwise we must skip all interjacent tabs and spaces and find next value
|
---|
| 1053 | dummy1 = dummy;
|
---|
| 1054 | dummy = strchr(dummy1, '\t'); // seek for tab or space
|
---|
| 1055 | if (dummy == NULL) {
|
---|
| 1056 | dummy = strchr(dummy1, ' '); // if not found seek for space
|
---|
| 1057 | while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
|
---|
| 1058 | dummy++;
|
---|
| 1059 | }
|
---|
| 1060 | /* while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
|
---|
| 1061 | dummy++;*/
|
---|
| 1062 | if (dummy == NULL) { // if still zero returned ...
|
---|
| 1063 | dummy = strchr(dummy1, '\n'); // ... at line end then
|
---|
| 1064 | if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
|
---|
| 1065 | if (critical) {
|
---|
| 1066 | if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
|
---|
| 1067 | Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
|
---|
| 1068 | //return 0;
|
---|
| 1069 | exit(255);
|
---|
| 1070 | //Error(FileOpenParams, NULL);
|
---|
| 1071 | } else {
|
---|
| 1072 | //if (!sequential)
|
---|
| 1073 | file->clear();
|
---|
| 1074 | file->seekg(file_position, ios::beg); // rewind to start position
|
---|
| 1075 | Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
|
---|
| 1076 | return 0;
|
---|
| 1077 | }
|
---|
| 1078 | }
|
---|
| 1079 | } else {
|
---|
| 1080 | //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
|
---|
| 1081 | }
|
---|
| 1082 | //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
|
---|
| 1083 | switch(type) {
|
---|
| 1084 | case (row_int):
|
---|
| 1085 | *((int *)value) = atoi(dummy1);
|
---|
| 1086 | if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
|
---|
| 1087 | if (verbose) fprintf(stderr,"%i\t",*((int *)value));
|
---|
| 1088 | value = (void *)((long)value + sizeof(int));
|
---|
| 1089 | //value += sizeof(int);
|
---|
| 1090 | break;
|
---|
| 1091 | case(row_double):
|
---|
| 1092 | case(grid):
|
---|
| 1093 | case(lower_trigrid):
|
---|
| 1094 | case(upper_trigrid):
|
---|
| 1095 | *((double *)value) = atof(dummy1);
|
---|
| 1096 | if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
|
---|
| 1097 | if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
|
---|
| 1098 | value = (void *)((long)value + sizeof(double));
|
---|
| 1099 | //value += sizeof(double);
|
---|
| 1100 | break;
|
---|
| 1101 | case(double_type):
|
---|
| 1102 | *((double *)value) = atof(dummy1);
|
---|
| 1103 | if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
|
---|
| 1104 | //value += sizeof(double);
|
---|
| 1105 | break;
|
---|
| 1106 | case(int_type):
|
---|
| 1107 | *((int *)value) = atoi(dummy1);
|
---|
| 1108 | if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
|
---|
| 1109 | //value += sizeof(int);
|
---|
| 1110 | break;
|
---|
| 1111 | default:
|
---|
| 1112 | case(string_type):
|
---|
| 1113 | if (value != NULL) {
|
---|
| 1114 | if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
|
---|
| 1115 | length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
|
---|
| 1116 | strncpy((char *)value, dummy1, length); // copy as much
|
---|
| 1117 | ((char *)value)[length] = '\0'; // and set end marker
|
---|
| 1118 | if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
|
---|
| 1119 | //value += sizeof(char);
|
---|
| 1120 | } else {
|
---|
| 1121 | }
|
---|
| 1122 | break;
|
---|
| 1123 | }
|
---|
| 1124 | }
|
---|
| 1125 | while (*dummy == '\t')
|
---|
| 1126 | dummy++;
|
---|
| 1127 | }
|
---|
| 1128 | }
|
---|
| 1129 | }
|
---|
| 1130 | }
|
---|
| 1131 | }
|
---|
| 1132 | if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
|
---|
| 1133 | Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
|
---|
| 1134 | if (!sequential) {
|
---|
| 1135 | file->clear();
|
---|
| 1136 | file->seekg(file_position, ios::beg); // rewind to start position
|
---|
| 1137 | }
|
---|
| 1138 | //fprintf(stderr, "End of Parsing\n\n");
|
---|
| 1139 |
|
---|
| 1140 | return (found); // true if found, false if not
|
---|
| 1141 | }
|
---|