source: src/config.cpp@ a1fe77

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
Last change on this file since a1fe77 was a1fe77, checked in by Frederik Heber <heber@…>, 16 years ago

Basic implementation of Constrained MD is done, missing testing.

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