source: src/config.cpp@ ccd9f5

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 ccd9f5 was f66195, checked in by Frederik Heber <heber@…>, 16 years ago

forward declarations used to untangle interdependet classes.

  • basically, everywhere in header files we removed '#include' lines were only pointer to the respective classes were used and the include line was moved to the implementation file.
  • as a sidenote, lots of funny errors happened because headers were included via a nesting over three other includes. Now, all should be declared directly as needed, as only very little include lines remain in header files.
  • Property mode set to 100755
File size: 89.6 KB
Line 
1/** \file config.cpp
2 *
3 * Function implementations for the class config.
4 *
5 */
6
7#include "atom.hpp"
8#include "config.hpp"
9#include "element.hpp"
10#include "memoryallocator.hpp"
11#include "molecule.hpp"
12#include "periodentafel.hpp"
13
14/******************************** Functions for class ConfigFileBuffer **********************/
15
16/** Structure containing compare function for Ion_Type sorting.
17 */
18struct IonTypeCompare {
19 bool operator()(const char* s1, const char *s2) const {
20 char number1[8];
21 char number2[8];
22 char *dummy1, *dummy2;
23 //cout << s1 << " " << s2 << endl;
24 dummy1 = strchr(s1, '_')+sizeof(char)*5; // go just after "Ion_Type"
25 dummy2 = strchr(dummy1, '_');
26 strncpy(number1, dummy1, dummy2-dummy1); // copy the number
27 number1[dummy2-dummy1]='\0';
28 dummy1 = strchr(s2, '_')+sizeof(char)*5; // go just after "Ion_Type"
29 dummy2 = strchr(dummy1, '_');
30 strncpy(number2, dummy1, dummy2-dummy1); // copy the number
31 number2[dummy2-dummy1]='\0';
32 if (atoi(number1) != atoi(number2))
33 return (atoi(number1) < atoi(number2));
34 else {
35 dummy1 = strchr(s1, '_')+sizeof(char);
36 dummy1 = strchr(dummy1, '_')+sizeof(char);
37 dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
38 strncpy(number1, dummy1, dummy2-dummy1); // copy the number
39 number1[dummy2-dummy1]='\0';
40 dummy1 = strchr(s2, '_')+sizeof(char);
41 dummy1 = strchr(dummy1, '_')+sizeof(char);
42 dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
43 strncpy(number2, dummy1, dummy2-dummy1); // copy the number
44 number2[dummy2-dummy1]='\0';
45 return (atoi(number1) < atoi(number2));
46 }
47 }
48};
49
50/** Constructor for ConfigFileBuffer class.
51 */
52ConfigFileBuffer::ConfigFileBuffer()
53{
54 NoLines = 0;
55 CurrentLine = 0;
56 buffer = NULL;
57 LineMapping = NULL;
58}
59
60/** Constructor for ConfigFileBuffer class with filename to be parsed.
61 * \param *filename file name
62 */
63ConfigFileBuffer::ConfigFileBuffer(char *filename)
64{
65 NoLines = 0;
66 CurrentLine = 0;
67 buffer = NULL;
68 LineMapping = NULL;
69 ifstream *file = NULL;
70 char line[MAXSTRINGSIZE];
71
72 // prescan number of lines
73 file= new ifstream(filename);
74 if (file == NULL) {
75 cerr << "ERROR: config file " << filename << " missing!" << endl;
76 return;
77 }
78 NoLines = 0; // we're overcounting by one
79 long file_position = file->tellg(); // mark current position
80 do {
81 file->getline(line, 256);
82 NoLines++;
83 } while (!file->eof());
84 file->clear();
85 file->seekg(file_position, ios::beg);
86 cout << Verbose(1) << NoLines-1 << " lines were recognized." << endl;
87
88 // allocate buffer's 1st dimension
89 if (buffer != NULL) {
90 cerr << "ERROR: FileBuffer->buffer is not NULL!" << endl;
91 return;
92 } else
93 buffer = Malloc<char*>(NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
94
95 // scan each line and put into buffer
96 int lines=0;
97 int i;
98 do {
99 buffer[lines] = Malloc<char>(MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
100 file->getline(buffer[lines], MAXSTRINGSIZE-1);
101 i = strlen(buffer[lines]);
102 buffer[lines][i] = '\n';
103 buffer[lines][i+1] = '\0';
104 lines++;
105 } while((!file->eof()) && (lines < NoLines));
106 cout << Verbose(1) << lines-1 << " lines were read into the buffer." << endl;
107
108 // close and exit
109 file->close();
110 file->clear();
111 delete(file);
112}
113
114/** Destructor for ConfigFileBuffer class.
115 */
116ConfigFileBuffer::~ConfigFileBuffer()
117{
118 for(int i=0;i<NoLines;++i)
119 Free(&buffer[i]);
120 Free(&buffer);
121 Free(&LineMapping);
122}
123
124
125/** Create trivial mapping.
126 */
127void ConfigFileBuffer::InitMapping()
128{
129 LineMapping = Malloc<int>(NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
130 for (int i=0;i<NoLines;i++)
131 LineMapping[i] = i;
132}
133
134/** Creates a mapping for the \a *FileBuffer's lines containing the Ion_Type keyword such that they are sorted.
135 * \a *map on return contains a list of NoAtom entries such that going through the list, yields indices to the
136 * lines in \a *FileBuffer in a sorted manner of the Ion_Type?_? keywords. We assume that ConfigFileBuffer::CurrentLine
137 * points to first Ion_Type entry.
138 * \param *FileBuffer pointer to buffer structure
139 * \param NoAtoms of subsequent lines to look at
140 */
141void ConfigFileBuffer::MapIonTypesInBuffer(int NoAtoms)
142{
143 map<const char *, int, IonTypeCompare> LineList;
144 if (LineMapping == NULL) {
145 cerr << "map pointer is NULL: " << LineMapping << endl;
146 return;
147 }
148
149 // put all into hashed map
150 for (int i=0; i<NoAtoms; ++i) {
151 LineList.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
152 }
153
154 // fill map
155 int nr=0;
156 for (map<const char *, int, IonTypeCompare>::iterator runner = LineList.begin(); runner != LineList.end(); ++runner) {
157 if (CurrentLine+nr < NoLines)
158 LineMapping[CurrentLine+(nr++)] = runner->second;
159 else
160 cerr << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl;
161 }
162}
163
164/************************************* Functions for class config ***************************/
165
166/** Constructor for config file class.
167 */
168config::config()
169{
170 mainname = Malloc<char>(MAXSTRINGSIZE,"config constructor: mainname");
171 defaultpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: defaultpath");
172 pseudopotpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: pseudopotpath");
173 databasepath = Malloc<char>(MAXSTRINGSIZE,"config constructor: databasepath");
174 configpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: configpath");
175 configname = Malloc<char>(MAXSTRINGSIZE,"config constructor: configname");
176 ThermostatImplemented = Malloc<int>(MaxThermostats, "config constructor: *ThermostatImplemented");
177 ThermostatNames = Malloc<char*>(MaxThermostats, "config constructor: *ThermostatNames");
178 for (int j=0;j<MaxThermostats;j++)
179 ThermostatNames[j] = Malloc<char>(12, "config constructor: ThermostatNames[]");
180 Thermostat = 4;
181 alpha = 0.;
182 ScaleTempStep = 25;
183 TempFrequency = 2.5;
184 strcpy(mainname,"pcp");
185 strcpy(defaultpath,"not specified");
186 strcpy(pseudopotpath,"not specified");
187 configpath[0]='\0';
188 configname[0]='\0';
189 basis = "3-21G";
190
191 strcpy(ThermostatNames[0],"None");
192 ThermostatImplemented[0] = 1;
193 strcpy(ThermostatNames[1],"Woodcock");
194 ThermostatImplemented[1] = 1;
195 strcpy(ThermostatNames[2],"Gaussian");
196 ThermostatImplemented[2] = 1;
197 strcpy(ThermostatNames[3],"Langevin");
198 ThermostatImplemented[3] = 1;
199 strcpy(ThermostatNames[4],"Berendsen");
200 ThermostatImplemented[4] = 1;
201 strcpy(ThermostatNames[5],"NoseHoover");
202 ThermostatImplemented[5] = 1;
203
204 FastParsing = false;
205 ProcPEGamma=8;
206 ProcPEPsi=1;
207 DoOutVis=0;
208 DoOutMes=1;
209 DoOutNICS=0;
210 DoOutOrbitals=0;
211 DoOutCurrent=0;
212 DoPerturbation=0;
213 DoFullCurrent=0;
214 DoWannier=0;
215 DoConstrainedMD=0;
216 CommonWannier=0;
217 SawtoothStart=0.01;
218 VectorPlane=0;
219 VectorCut=0;
220 UseAddGramSch=1;
221 Seed=1;
222
223 MaxOuterStep=0;
224 Deltat=0.01;
225 OutVisStep=10;
226 OutSrcStep=5;
227 TargetTemp=0.00095004455;
228 ScaleTempStep=25;
229 MaxPsiStep=0;
230 EpsWannier=1e-7;
231
232 MaxMinStep=100;
233 RelEpsTotalEnergy=1e-7;
234 RelEpsKineticEnergy=1e-5;
235 MaxMinStopStep=1;
236 MaxMinGapStopStep=0;
237 MaxInitMinStep=100;
238 InitRelEpsTotalEnergy=1e-5;
239 InitRelEpsKineticEnergy=1e-4;
240 InitMaxMinStopStep=1;
241 InitMaxMinGapStopStep=0;
242
243 //BoxLength[NDIM*NDIM];
244
245 ECut=128.;
246 MaxLevel=5;
247 RiemannTensor=0;
248 LevRFactor=0;
249 RiemannLevel=0;
250 Lev0Factor=2;
251 RTActualUse=0;
252 PsiType=0;
253 MaxPsiDouble=0;
254 PsiMaxNoUp=0;
255 PsiMaxNoDown=0;
256 AddPsis=0;
257
258 RCut=20.;
259 StructOpt=0;
260 IsAngstroem=1;
261 RelativeCoord=0;
262 MaxTypes=0;
263};
264
265
266/** Destructor for config file class.
267 */
268config::~config()
269{
270 Free(&mainname);
271 Free(&defaultpath);
272 Free(&pseudopotpath);
273 Free(&databasepath);
274 Free(&configpath);
275 Free(&configname);
276 Free(&ThermostatImplemented);
277 for (int j=0;j<MaxThermostats;j++)
278 Free(&ThermostatNames[j]);
279 Free(&ThermostatNames);
280};
281
282/** Readin of Thermostat related values from parameter file.
283 * \param *fb file buffer containing the config file
284 */
285void config::InitThermostats(class ConfigFileBuffer *fb)
286{
287 char *thermo = Malloc<char>(12, "IonsInitRead: thermo");
288 int verbose = 0;
289
290 // read desired Thermostat from file along with needed additional parameters
291 if (ParseForParameter(verbose,fb,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
292 if (strcmp(thermo, ThermostatNames[0]) == 0) { // None
293 if (ThermostatImplemented[0] == 1) {
294 Thermostat = None;
295 } else {
296 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
297 Thermostat = None;
298 }
299 } else if (strcmp(thermo, ThermostatNames[1]) == 0) { // Woodcock
300 if (ThermostatImplemented[1] == 1) {
301 Thermostat = Woodcock;
302 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read scaling frequency
303 } else {
304 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
305 Thermostat = None;
306 }
307 } else if (strcmp(thermo, ThermostatNames[2]) == 0) { // Gaussian
308 if (ThermostatImplemented[2] == 1) {
309 Thermostat = Gaussian;
310 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read collision rate
311 } else {
312 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
313 Thermostat = None;
314 }
315 } else if (strcmp(thermo, ThermostatNames[3]) == 0) { // Langevin
316 if (ThermostatImplemented[3] == 1) {
317 Thermostat = Langevin;
318 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read gamma
319 if (ParseForParameter(verbose,fb,"Thermostat", 0, 3, 1, double_type, &alpha, 1, optional)) {
320 cout << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << "." << endl;
321 } else {
322 alpha = 1.;
323 }
324 } else {
325 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
326 Thermostat = None;
327 }
328 } else if (strcmp(thermo, ThermostatNames[4]) == 0) { // Berendsen
329 if (ThermostatImplemented[4] == 1) {
330 Thermostat = Berendsen;
331 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T
332 } else {
333 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
334 Thermostat = None;
335 }
336 } else if (strcmp(thermo, ThermostatNames[5]) == 0) { // Nose-Hoover
337 if (ThermostatImplemented[5] == 1) {
338 Thermostat = NoseHoover;
339 ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &HooverMass, 1, critical); // read Hoovermass
340 alpha = 0.;
341 } else {
342 cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
343 Thermostat = None;
344 }
345 } else {
346 cout << Verbose(1) << " Warning: thermostat name was not understood!" << endl;
347 Thermostat = None;
348 }
349 } else {
350 if ((MaxOuterStep > 0) && (TargetTemp != 0))
351 cout << Verbose(2) << "No thermostat chosen despite finite temperature MD, falling back to None." << endl;
352 Thermostat = None;
353 }
354 Free(&thermo);
355};
356
357
358/** Displays menu for editing each entry of the config file.
359 * Nothing fancy here, just lots of cout << Verbose(0)s for the menu and a switch/case
360 * for each entry of the config file structure.
361 */
362void config::Edit()
363{
364 char choice;
365
366 do {
367 cout << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl;
368 cout << Verbose(0) << " A - mainname (prefix for all runtime files)" << endl;
369 cout << Verbose(0) << " B - Default path (for runtime files)" << endl;
370 cout << Verbose(0) << " C - Path of pseudopotential files" << endl;
371 cout << Verbose(0) << " D - Number of coefficient sharing processes" << endl;
372 cout << Verbose(0) << " E - Number of wave function sharing processes" << endl;
373 cout << Verbose(0) << " F - 0: Don't output density for OpenDX, 1: do" << endl;
374 cout << Verbose(0) << " G - 0: Don't output physical data, 1: do" << endl;
375 cout << Verbose(0) << " H - 0: Don't output densities of each unperturbed orbital for OpenDX, 1: do" << endl;
376 cout << Verbose(0) << " I - 0: Don't output current density for OpenDX, 1: do" << endl;
377 cout << Verbose(0) << " J - 0: Don't do the full current calculation, 1: do" << endl;
378 cout << Verbose(0) << " K - 0: Don't do perturbation calculation to obtain susceptibility and shielding, 1: do" << endl;
379 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;
380 cout << Verbose(0) << " M - Absolute begin of unphysical sawtooth transfer for position operator within cell" << endl;
381 cout << Verbose(0) << " N - (0,1,2) x,y,z-plane to do two-dimensional current vector cut" << endl;
382 cout << Verbose(0) << " O - Absolute position along vector cut axis for cut plane" << endl;
383 cout << Verbose(0) << " P - Additional Gram-Schmidt-Orthonormalization to stabilize numerics" << endl;
384 cout << Verbose(0) << " Q - Initial integer value of random number generator" << endl;
385 cout << Verbose(0) << " R - for perturbation 0, for structure optimization defines upper limit of iterations" << endl;
386 cout << Verbose(0) << " T - Output visual after ...th step" << endl;
387 cout << Verbose(0) << " U - Output source densities of wave functions after ...th step" << endl;
388 cout << Verbose(0) << " X - minimization iterations per wave function, if unsure leave at default value 0" << endl;
389 cout << Verbose(0) << " Y - tolerance value for total spread in iterative Jacobi diagonalization" << endl;
390 cout << Verbose(0) << " Z - Maximum number of minimization iterations" << endl;
391 cout << Verbose(0) << " a - Relative change in total energy to stop min. iteration" << endl;
392 cout << Verbose(0) << " b - Relative change in kinetic energy to stop min. iteration" << endl;
393 cout << Verbose(0) << " c - Check stop conditions every ..th step during min. iteration" << endl;
394 cout << Verbose(0) << " e - Maximum number of minimization iterations during initial level" << endl;
395 cout << Verbose(0) << " f - Relative change in total energy to stop min. iteration during initial level" << endl;
396 cout << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl;
397 cout << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl;
398// cout << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
399 cout << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl;
400 cout << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl;
401 cout << Verbose(0) << " m - Factor by which grid nodes increase between standard and upper level" << endl;
402 cout << Verbose(0) << " n - 0: Don't use RiemannTensor, 1: Do" << endl;
403 cout << Verbose(0) << " o - Factor by which grid nodes increase between Riemann and standard(?) level" << endl;
404 cout << Verbose(0) << " p - Number of Riemann levels" << endl;
405 cout << Verbose(0) << " r - 0: Don't Use RiemannTensor, 1: Do" << endl;
406 cout << Verbose(0) << " s - 0: Doubly occupied orbitals, 1: Up-/Down-Orbitals" << endl;
407 cout << Verbose(0) << " t - Number of orbitals (depends pn SpinType)" << endl;
408 cout << Verbose(0) << " u - Number of SpinUp orbitals (depends on SpinType)" << endl;
409 cout << Verbose(0) << " v - Number of SpinDown orbitals (depends on SpinType)" << endl;
410 cout << Verbose(0) << " w - Number of additional, unoccupied orbitals" << endl;
411 cout << Verbose(0) << " x - radial cutoff for ewald summation in Bohrradii" << endl;
412 cout << Verbose(0) << " y - 0: Don't do structure optimization beforehand, 1: Do" << endl;
413 cout << Verbose(0) << " z - 0: Units are in Bohr radii, 1: units are in Aengstrom" << endl;
414 cout << Verbose(0) << " i - 0: Coordinates given in file are absolute, 1: ... are relative to unit cell" << endl;
415 cout << Verbose(0) << "=========================================================" << endl;
416 cout << Verbose(0) << "INPUT: ";
417 cin >> choice;
418
419 switch (choice) {
420 case 'A': // mainname
421 cout << Verbose(0) << "Old: " << config::mainname << "\t new: ";
422 cin >> config::mainname;
423 break;
424 case 'B': // defaultpath
425 cout << Verbose(0) << "Old: " << config::defaultpath << "\t new: ";
426 cin >> config::defaultpath;
427 break;
428 case 'C': // pseudopotpath
429 cout << Verbose(0) << "Old: " << config::pseudopotpath << "\t new: ";
430 cin >> config::pseudopotpath;
431 break;
432
433 case 'D': // ProcPEGamma
434 cout << Verbose(0) << "Old: " << config::ProcPEGamma << "\t new: ";
435 cin >> config::ProcPEGamma;
436 break;
437 case 'E': // ProcPEPsi
438 cout << Verbose(0) << "Old: " << config::ProcPEPsi << "\t new: ";
439 cin >> config::ProcPEPsi;
440 break;
441 case 'F': // DoOutVis
442 cout << Verbose(0) << "Old: " << config::DoOutVis << "\t new: ";
443 cin >> config::DoOutVis;
444 break;
445 case 'G': // DoOutMes
446 cout << Verbose(0) << "Old: " << config::DoOutMes << "\t new: ";
447 cin >> config::DoOutMes;
448 break;
449 case 'H': // DoOutOrbitals
450 cout << Verbose(0) << "Old: " << config::DoOutOrbitals << "\t new: ";
451 cin >> config::DoOutOrbitals;
452 break;
453 case 'I': // DoOutCurrent
454 cout << Verbose(0) << "Old: " << config::DoOutCurrent << "\t new: ";
455 cin >> config::DoOutCurrent;
456 break;
457 case 'J': // DoFullCurrent
458 cout << Verbose(0) << "Old: " << config::DoFullCurrent << "\t new: ";
459 cin >> config::DoFullCurrent;
460 break;
461 case 'K': // DoPerturbation
462 cout << Verbose(0) << "Old: " << config::DoPerturbation << "\t new: ";
463 cin >> config::DoPerturbation;
464 break;
465 case 'L': // CommonWannier
466 cout << Verbose(0) << "Old: " << config::CommonWannier << "\t new: ";
467 cin >> config::CommonWannier;
468 break;
469 case 'M': // SawtoothStart
470 cout << Verbose(0) << "Old: " << config::SawtoothStart << "\t new: ";
471 cin >> config::SawtoothStart;
472 break;
473 case 'N': // VectorPlane
474 cout << Verbose(0) << "Old: " << config::VectorPlane << "\t new: ";
475 cin >> config::VectorPlane;
476 break;
477 case 'O': // VectorCut
478 cout << Verbose(0) << "Old: " << config::VectorCut << "\t new: ";
479 cin >> config::VectorCut;
480 break;
481 case 'P': // UseAddGramSch
482 cout << Verbose(0) << "Old: " << config::UseAddGramSch << "\t new: ";
483 cin >> config::UseAddGramSch;
484 break;
485 case 'Q': // Seed
486 cout << Verbose(0) << "Old: " << config::Seed << "\t new: ";
487 cin >> config::Seed;
488 break;
489
490 case 'R': // MaxOuterStep
491 cout << Verbose(0) << "Old: " << config::MaxOuterStep << "\t new: ";
492 cin >> config::MaxOuterStep;
493 break;
494 case 'T': // OutVisStep
495 cout << Verbose(0) << "Old: " << config::OutVisStep << "\t new: ";
496 cin >> config::OutVisStep;
497 break;
498 case 'U': // OutSrcStep
499 cout << Verbose(0) << "Old: " << config::OutSrcStep << "\t new: ";
500 cin >> config::OutSrcStep;
501 break;
502 case 'X': // MaxPsiStep
503 cout << Verbose(0) << "Old: " << config::MaxPsiStep << "\t new: ";
504 cin >> config::MaxPsiStep;
505 break;
506 case 'Y': // EpsWannier
507 cout << Verbose(0) << "Old: " << config::EpsWannier << "\t new: ";
508 cin >> config::EpsWannier;
509 break;
510
511 case 'Z': // MaxMinStep
512 cout << Verbose(0) << "Old: " << config::MaxMinStep << "\t new: ";
513 cin >> config::MaxMinStep;
514 break;
515 case 'a': // RelEpsTotalEnergy
516 cout << Verbose(0) << "Old: " << config::RelEpsTotalEnergy << "\t new: ";
517 cin >> config::RelEpsTotalEnergy;
518 break;
519 case 'b': // RelEpsKineticEnergy
520 cout << Verbose(0) << "Old: " << config::RelEpsKineticEnergy << "\t new: ";
521 cin >> config::RelEpsKineticEnergy;
522 break;
523 case 'c': // MaxMinStopStep
524 cout << Verbose(0) << "Old: " << config::MaxMinStopStep << "\t new: ";
525 cin >> config::MaxMinStopStep;
526 break;
527 case 'e': // MaxInitMinStep
528 cout << Verbose(0) << "Old: " << config::MaxInitMinStep << "\t new: ";
529 cin >> config::MaxInitMinStep;
530 break;
531 case 'f': // InitRelEpsTotalEnergy
532 cout << Verbose(0) << "Old: " << config::InitRelEpsTotalEnergy << "\t new: ";
533 cin >> config::InitRelEpsTotalEnergy;
534 break;
535 case 'g': // InitRelEpsKineticEnergy
536 cout << Verbose(0) << "Old: " << config::InitRelEpsKineticEnergy << "\t new: ";
537 cin >> config::InitRelEpsKineticEnergy;
538 break;
539 case 'h': // InitMaxMinStopStep
540 cout << Verbose(0) << "Old: " << config::InitMaxMinStopStep << "\t new: ";
541 cin >> config::InitMaxMinStopStep;
542 break;
543
544// case 'j': // BoxLength
545// cout << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
546// for (int i=0;i<6;i++) {
547// cout << Verbose(0) << "Cell size" << i << ": ";
548// cin >> mol->cell_size[i];
549// }
550// break;
551
552 case 'k': // ECut
553 cout << Verbose(0) << "Old: " << config::ECut << "\t new: ";
554 cin >> config::ECut;
555 break;
556 case 'l': // MaxLevel
557 cout << Verbose(0) << "Old: " << config::MaxLevel << "\t new: ";
558 cin >> config::MaxLevel;
559 break;
560 case 'm': // RiemannTensor
561 cout << Verbose(0) << "Old: " << config::RiemannTensor << "\t new: ";
562 cin >> config::RiemannTensor;
563 break;
564 case 'n': // LevRFactor
565 cout << Verbose(0) << "Old: " << config::LevRFactor << "\t new: ";
566 cin >> config::LevRFactor;
567 break;
568 case 'o': // RiemannLevel
569 cout << Verbose(0) << "Old: " << config::RiemannLevel << "\t new: ";
570 cin >> config::RiemannLevel;
571 break;
572 case 'p': // Lev0Factor
573 cout << Verbose(0) << "Old: " << config::Lev0Factor << "\t new: ";
574 cin >> config::Lev0Factor;
575 break;
576 case 'r': // RTActualUse
577 cout << Verbose(0) << "Old: " << config::RTActualUse << "\t new: ";
578 cin >> config::RTActualUse;
579 break;
580 case 's': // PsiType
581 cout << Verbose(0) << "Old: " << config::PsiType << "\t new: ";
582 cin >> config::PsiType;
583 break;
584 case 't': // MaxPsiDouble
585 cout << Verbose(0) << "Old: " << config::MaxPsiDouble << "\t new: ";
586 cin >> config::MaxPsiDouble;
587 break;
588 case 'u': // PsiMaxNoUp
589 cout << Verbose(0) << "Old: " << config::PsiMaxNoUp << "\t new: ";
590 cin >> config::PsiMaxNoUp;
591 break;
592 case 'v': // PsiMaxNoDown
593 cout << Verbose(0) << "Old: " << config::PsiMaxNoDown << "\t new: ";
594 cin >> config::PsiMaxNoDown;
595 break;
596 case 'w': // AddPsis
597 cout << Verbose(0) << "Old: " << config::AddPsis << "\t new: ";
598 cin >> config::AddPsis;
599 break;
600
601 case 'x': // RCut
602 cout << Verbose(0) << "Old: " << config::RCut << "\t new: ";
603 cin >> config::RCut;
604 break;
605 case 'y': // StructOpt
606 cout << Verbose(0) << "Old: " << config::StructOpt << "\t new: ";
607 cin >> config::StructOpt;
608 break;
609 case 'z': // IsAngstroem
610 cout << Verbose(0) << "Old: " << config::IsAngstroem << "\t new: ";
611 cin >> config::IsAngstroem;
612 break;
613 case 'i': // RelativeCoord
614 cout << Verbose(0) << "Old: " << config::RelativeCoord << "\t new: ";
615 cin >> config::RelativeCoord;
616 break;
617 };
618 } while (choice != 'q');
619};
620
621/** Tests whether a given configuration file adhears to old or new syntax.
622 * \param *filename filename of config file to be tested
623 * \param *periode pointer to a periodentafel class with all elements
624 * \param *mol pointer to molecule containing all atoms of the molecule
625 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
626 */
627int config::TestSyntax(char *filename, periodentafel *periode, molecule *mol)
628{
629 int test;
630 ifstream file(filename);
631
632 // search file for keyword: ProcPEGamma (new syntax)
633 if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) {
634 file.close();
635 return 1;
636 }
637 // search file for keyword: ProcsGammaPsi (old syntax)
638 if (ParseForParameter(1,&file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional)) {
639 file.close();
640 return 0;
641 }
642 file.close();
643 return -1;
644}
645
646/** Returns private config::IsAngstroem.
647 * \return IsAngstroem
648 */
649bool config::GetIsAngstroem() const
650{
651 return (IsAngstroem == 1);
652};
653
654/** Returns private config::*defaultpath.
655 * \return *defaultpath
656 */
657char * config::GetDefaultPath() const
658{
659 return defaultpath;
660};
661
662
663/** Returns private config::*defaultpath.
664 * \return *defaultpath
665 */
666void config::SetDefaultPath(const char *path)
667{
668 strcpy(defaultpath, path);
669};
670
671/** Retrieves the path in the given config file name.
672 * \param filename config file string
673 */
674void config::RetrieveConfigPathAndName(string filename)
675{
676 char *ptr = NULL;
677 char *buffer = new char[MAXSTRINGSIZE];
678 strncpy(buffer, filename.c_str(), MAXSTRINGSIZE);
679 int last = -1;
680 for(last=MAXSTRINGSIZE;last--;) {
681 if (buffer[last] == '/')
682 break;
683 }
684 if (last == -1) { // no path in front, set to local directory.
685 strcpy(configpath, "./");
686 ptr = buffer;
687 } else {
688 strncpy(configpath, buffer, last+1);
689 ptr = &buffer[last+1];
690 if (last < 254)
691 configpath[last+1]='\0';
692 }
693 strcpy(configname, ptr);
694 cout << "Found configpath: " << configpath << ", dir slash was found at " << last << ", config name is " << configname << "." << endl;
695 delete[](buffer);
696};
697
698
699/** Initializes config file structure by loading elements from a give file.
700 * \param *file input file stream being the opened config file
701 * \param *periode pointer to a periodentafel class with all elements
702 * \param *mol pointer to molecule containing all atoms of the molecule
703 */
704void config::Load(char *filename, periodentafel *periode, molecule *mol)
705{
706 ifstream *file = new ifstream(filename);
707 if (file == NULL) {
708 cerr << "ERROR: config file " << filename << " missing!" << endl;
709 return;
710 }
711 file->close();
712 delete(file);
713 RetrieveConfigPathAndName(filename);
714
715 // ParseParameterFile
716 struct ConfigFileBuffer *FileBuffer = new ConfigFileBuffer(filename);
717 FileBuffer->InitMapping();
718
719 /* Oeffne Hauptparameterdatei */
720 int di;
721 double BoxLength[9];
722 string zeile;
723 string dummy;
724 element *elementhash[MAX_ELEMENTS];
725 char name[MAX_ELEMENTS];
726 char keyword[MAX_ELEMENTS];
727 int Z, No[MAX_ELEMENTS];
728 int verbose = 0;
729 double value[3];
730
731 InitThermostats(FileBuffer);
732
733 /* Namen einlesen */
734
735 ParseForParameter(verbose,FileBuffer, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
736 ParseForParameter(verbose,FileBuffer, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
737 ParseForParameter(verbose,FileBuffer, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
738 ParseForParameter(verbose,FileBuffer,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
739 ParseForParameter(verbose,FileBuffer,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
740
741 if (!ParseForParameter(verbose,FileBuffer,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
742 config::Seed = 1;
743
744 if(!ParseForParameter(verbose,FileBuffer,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
745 config::DoOutOrbitals = 0;
746 } else {
747 if (config::DoOutOrbitals < 0) config::DoOutOrbitals = 0;
748 if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1;
749 }
750 ParseForParameter(verbose,FileBuffer,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
751 if (config::DoOutVis < 0) config::DoOutVis = 0;
752 if (config::DoOutVis > 1) config::DoOutVis = 1;
753 if (!ParseForParameter(verbose,FileBuffer,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
754 config::VectorPlane = -1;
755 if (!ParseForParameter(verbose,FileBuffer,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
756 config::VectorCut = 0.;
757 ParseForParameter(verbose,FileBuffer,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
758 if (config::DoOutMes < 0) config::DoOutMes = 0;
759 if (config::DoOutMes > 1) config::DoOutMes = 1;
760 if (!ParseForParameter(verbose,FileBuffer,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
761 config::DoOutCurrent = 0;
762 if (config::DoOutCurrent < 0) config::DoOutCurrent = 0;
763 if (config::DoOutCurrent > 1) config::DoOutCurrent = 1;
764 ParseForParameter(verbose,FileBuffer,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
765 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
766 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
767 if(!ParseForParameter(verbose,FileBuffer,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {
768 config::DoWannier = 0;
769 } else {
770 if (config::DoWannier < 0) config::DoWannier = 0;
771 if (config::DoWannier > 1) config::DoWannier = 1;
772 }
773 if(!ParseForParameter(verbose,FileBuffer,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
774 config::CommonWannier = 0;
775 } else {
776 if (config::CommonWannier < 0) config::CommonWannier = 0;
777 if (config::CommonWannier > 4) config::CommonWannier = 4;
778 }
779 if(!ParseForParameter(verbose,FileBuffer,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
780 config::SawtoothStart = 0.01;
781 } else {
782 if (config::SawtoothStart < 0.) config::SawtoothStart = 0.;
783 if (config::SawtoothStart > 1.) config::SawtoothStart = 1.;
784 }
785
786 if (ParseForParameter(verbose,FileBuffer,"DoConstrainedMD", 0, 1, 1, int_type, &(config::DoConstrainedMD), 1, optional))
787 if (config::DoConstrainedMD < 0)
788 config::DoConstrainedMD = 0;
789 ParseForParameter(verbose,FileBuffer,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
790 if (!ParseForParameter(verbose,FileBuffer,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional))
791 config::Deltat = 1;
792 ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
793 ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
794 ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
795 //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
796 if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
797 config::EpsWannier = 1e-8;
798
799 // stop conditions
800 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
801 ParseForParameter(verbose,FileBuffer,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
802 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
803
804 ParseForParameter(verbose,FileBuffer,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
805 ParseForParameter(verbose,FileBuffer,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
806 ParseForParameter(verbose,FileBuffer,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
807 ParseForParameter(verbose,FileBuffer,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
808 ParseForParameter(verbose,FileBuffer,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
809 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
810 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
811 if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1;
812
813 ParseForParameter(verbose,FileBuffer,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
814 ParseForParameter(verbose,FileBuffer,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
815 ParseForParameter(verbose,FileBuffer,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
816 ParseForParameter(verbose,FileBuffer,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
817 ParseForParameter(verbose,FileBuffer,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
818 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
819 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
820 if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1;
821
822 // Unit cell and magnetic field
823 ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
824 mol->cell_size[0] = BoxLength[0];
825 mol->cell_size[1] = BoxLength[3];
826 mol->cell_size[2] = BoxLength[4];
827 mol->cell_size[3] = BoxLength[6];
828 mol->cell_size[4] = BoxLength[7];
829 mol->cell_size[5] = BoxLength[8];
830 //if (1) fprintf(stderr,"\n");
831
832 ParseForParameter(verbose,FileBuffer,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
833 ParseForParameter(verbose,FileBuffer,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
834 if (!ParseForParameter(verbose,FileBuffer,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
835 config::DoFullCurrent = 0;
836 if (config::DoFullCurrent < 0) config::DoFullCurrent = 0;
837 if (config::DoFullCurrent > 2) config::DoFullCurrent = 2;
838 if (config::DoOutNICS < 0) config::DoOutNICS = 0;
839 if (config::DoOutNICS > 2) config::DoOutNICS = 2;
840 if (config::DoPerturbation == 0) {
841 config::DoFullCurrent = 0;
842 config::DoOutNICS = 0;
843 }
844
845 ParseForParameter(verbose,FileBuffer,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
846 ParseForParameter(verbose,FileBuffer,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
847 ParseForParameter(verbose,FileBuffer,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
848 if (config::Lev0Factor < 2) {
849 config::Lev0Factor = 2;
850 }
851 ParseForParameter(verbose,FileBuffer,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
852 if (di >= 0 && di < 2) {
853 config::RiemannTensor = di;
854 } else {
855 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
856 exit(1);
857 }
858 switch (config::RiemannTensor) {
859 case 0: //UseNoRT
860 if (config::MaxLevel < 2) {
861 config::MaxLevel = 2;
862 }
863 config::LevRFactor = 2;
864 config::RTActualUse = 0;
865 break;
866 case 1: // UseRT
867 if (config::MaxLevel < 3) {
868 config::MaxLevel = 3;
869 }
870 ParseForParameter(verbose,FileBuffer,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
871 if (config::RiemannLevel < 2) {
872 config::RiemannLevel = 2;
873 }
874 if (config::RiemannLevel > config::MaxLevel-1) {
875 config::RiemannLevel = config::MaxLevel-1;
876 }
877 ParseForParameter(verbose,FileBuffer,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
878 if (config::LevRFactor < 2) {
879 config::LevRFactor = 2;
880 }
881 config::Lev0Factor = 2;
882 config::RTActualUse = 2;
883 break;
884 }
885 ParseForParameter(verbose,FileBuffer,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
886 if (di >= 0 && di < 2) {
887 config::PsiType = di;
888 } else {
889 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
890 exit(1);
891 }
892 switch (config::PsiType) {
893 case 0: // SpinDouble
894 ParseForParameter(verbose,FileBuffer,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
895 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
896 break;
897 case 1: // SpinUpDown
898 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
899 ParseForParameter(verbose,FileBuffer,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
900 ParseForParameter(verbose,FileBuffer,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
901 ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
902 break;
903 }
904
905 // IonsInitRead
906
907 ParseForParameter(verbose,FileBuffer,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
908 ParseForParameter(verbose,FileBuffer,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
909 ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical);
910 if (!ParseForParameter(verbose,FileBuffer,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
911 config::RelativeCoord = 0;
912 if (!ParseForParameter(verbose,FileBuffer,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
913 config::StructOpt = 0;
914 if (MaxTypes == 0) {
915 cerr << "There are no atoms according to MaxTypes in this config file." << endl;
916 } else {
917 // prescan number of ions per type
918 cout << Verbose(0) << "Prescanning ions per type: " << endl;
919 int NoAtoms = 0;
920 for (int i=0; i < config::MaxTypes; i++) {
921 sprintf(name,"Ion_Type%i",i+1);
922 ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
923 ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical);
924 elementhash[i] = periode->FindElement(Z);
925 cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl;
926 NoAtoms += No[i];
927 }
928 int repetition = 0; // which repeated keyword shall be read
929
930 // sort the lines via the LineMapping
931 sprintf(name,"Ion_Type%i",config::MaxTypes);
932 if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) {
933 cerr << "There are no atoms in the config file!" << endl;
934 return;
935 }
936 FileBuffer->CurrentLine++;
937 //cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine]];
938 FileBuffer->MapIonTypesInBuffer(NoAtoms);
939 //for (int i=0; i<(NoAtoms < 100 ? NoAtoms : 100 < 100 ? NoAtoms : 100);++i) {
940 // cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine+i]];
941 //}
942
943 map<int, atom *> AtomList[config::MaxTypes];
944 map<int, atom *> LinearList;
945 atom *neues = NULL;
946 if (!FastParsing) {
947 // parse in trajectories
948 bool status = true;
949 while (status) {
950 cout << "Currently parsing MD step " << repetition << "." << endl;
951 for (int i=0; i < config::MaxTypes; i++) {
952 sprintf(name,"Ion_Type%i",i+1);
953 for(int j=0;j<No[i];j++) {
954 sprintf(keyword,"%s_%i",name, j+1);
955 if (repetition == 0) {
956 neues = new atom();
957 AtomList[i][j] = neues;
958 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
959 neues->type = elementhash[i]; // find element type
960 } else
961 neues = AtomList[i][j];
962 status = (status &&
963 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&
964 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&
965 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&
966 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));
967 if (!status) break;
968
969 // check size of vectors
970 if (neues->Trajectory.R.size() <= (unsigned int)(repetition)) {
971 //cout << "Increasing size for trajectory array of " << keyword << " to " << (repetition+10) << "." << endl;
972 neues->Trajectory.R.resize(repetition+10);
973 neues->Trajectory.U.resize(repetition+10);
974 neues->Trajectory.F.resize(repetition+10);
975 }
976
977 // put into trajectories list
978 for (int d=0;d<NDIM;d++)
979 neues->Trajectory.R.at(repetition).x[d] = neues->x.x[d];
980
981 // parse velocities if present
982 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))
983 neues->v.x[0] = 0.;
984 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))
985 neues->v.x[1] = 0.;
986 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))
987 neues->v.x[2] = 0.;
988 for (int d=0;d<NDIM;d++)
989 neues->Trajectory.U.at(repetition).x[d] = neues->v.x[d];
990
991 // parse forces if present
992 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 8, 1, double_type, &value[0], 1,optional))
993 value[0] = 0.;
994 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 9, 1, double_type, &value[1], 1,optional))
995 value[1] = 0.;
996 if(!ParseForParameter(verbose,FileBuffer, keyword, 1, 10, 1, double_type, &value[2], 1,optional))
997 value[2] = 0.;
998 for (int d=0;d<NDIM;d++)
999 neues->Trajectory.F.at(repetition).x[d] = value[d];
1000
1001 // cout << "Parsed position of step " << (repetition) << ": (";
1002 // for (int d=0;d<NDIM;d++)
1003 // cout << neues->Trajectory.R.at(repetition).x[d] << " "; // next step
1004 // cout << ")\t(";
1005 // for (int d=0;d<NDIM;d++)
1006 // cout << neues->Trajectory.U.at(repetition).x[d] << " "; // next step
1007 // cout << ")\t(";
1008 // for (int d=0;d<NDIM;d++)
1009 // cout << neues->Trajectory.F.at(repetition).x[d] << " "; // next step
1010 // cout << ")" << endl;
1011 }
1012 }
1013 repetition++;
1014 }
1015 repetition--;
1016 cout << "Found " << repetition << " trajectory steps." << endl;
1017 if (repetition <= 1) // if onyl one step, desactivate use of trajectories
1018 mol->MDSteps = 0;
1019 else
1020 mol->MDSteps = repetition;
1021 } else {
1022 // 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)
1023 repetition = 0;
1024 while ( ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&
1025 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&
1026 ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
1027 repetition++;
1028 cout << "I found " << repetition << " times the keyword Ion_Type1_1." << endl;
1029 // parse in molecule coordinates
1030 for (int i=0; i < config::MaxTypes; i++) {
1031 sprintf(name,"Ion_Type%i",i+1);
1032 for(int j=0;j<No[i];j++) {
1033 sprintf(keyword,"%s_%i",name, j+1);
1034 if (repetition == 0) {
1035 neues = new atom();
1036 AtomList[i][j] = neues;
1037 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
1038 neues->type = elementhash[i]; // find element type
1039 } else
1040 neues = AtomList[i][j];
1041 // then parse for each atom the coordinates as often as present
1042 ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
1043 ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
1044 ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
1045 ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
1046 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
1047 neues->v.x[0] = 0.;
1048 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
1049 neues->v.x[1] = 0.;
1050 if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
1051 neues->v.x[2] = 0.;
1052 // here we don't care if forces are present (last in trajectories is always equal to current position)
1053 neues->type = elementhash[i]; // find element type
1054 mol->AddAtom(neues);
1055 }
1056 }
1057 }
1058 // put atoms into the molecule in their original order
1059 for(map<int, atom*>::iterator runner = LinearList.begin(); runner != LinearList.end(); ++runner) {
1060 mol->AddAtom(runner->second);
1061 }
1062 }
1063 delete(FileBuffer);
1064};
1065
1066/** Initializes config file structure by loading elements from a give file with old pcp syntax.
1067 * \param *file input file stream being the opened config file with old pcp syntax
1068 * \param *periode pointer to a periodentafel class with all elements
1069 * \param *mol pointer to molecule containing all atoms of the molecule
1070 */
1071void config::LoadOld(char *filename, periodentafel *periode, molecule *mol)
1072{
1073 ifstream *file = new ifstream(filename);
1074 if (file == NULL) {
1075 cerr << "ERROR: config file " << filename << " missing!" << endl;
1076 return;
1077 }
1078 RetrieveConfigPathAndName(filename);
1079 // ParseParameters
1080
1081 /* Oeffne Hauptparameterdatei */
1082 int l, i, di;
1083 double a,b;
1084 double BoxLength[9];
1085 string zeile;
1086 string dummy;
1087 element *elementhash[128];
1088 int Z, No, AtomNo, found;
1089 int verbose = 0;
1090
1091 /* Namen einlesen */
1092
1093 ParseForParameter(verbose,file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
1094 ParseForParameter(verbose,file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
1095 ParseForParameter(verbose,file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
1096 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
1097 ParseForParameter(verbose,file, "ProcsGammaPsi", 0, 2, 1, int_type, &(config::ProcPEPsi), 1, critical);
1098 config::Seed = 1;
1099 config::DoOutOrbitals = 0;
1100 ParseForParameter(verbose,file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
1101 if (config::DoOutVis < 0) config::DoOutVis = 0;
1102 if (config::DoOutVis > 1) config::DoOutVis = 1;
1103 config::VectorPlane = -1;
1104 config::VectorCut = 0.;
1105 ParseForParameter(verbose,file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
1106 if (config::DoOutMes < 0) config::DoOutMes = 0;
1107 if (config::DoOutMes > 1) config::DoOutMes = 1;
1108 config::DoOutCurrent = 0;
1109 ParseForParameter(verbose,file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
1110 if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
1111 if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
1112 config::CommonWannier = 0;
1113 config::SawtoothStart = 0.01;
1114
1115 ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, double_type, &(config::MaxOuterStep), 1, critical);
1116 ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional);
1117 ParseForParameter(verbose,file,"VisOuterStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
1118 ParseForParameter(verbose,file,"VisSrcOuterStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
1119 ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
1120 ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
1121 config::EpsWannier = 1e-8;
1122
1123 // stop conditions
1124 //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
1125 ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
1126 if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
1127
1128 ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
1129 ParseForParameter(verbose,file,"MaxMinStep", 0, 2, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
1130 ParseForParameter(verbose,file,"MaxMinStep", 0, 3, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
1131 ParseForParameter(verbose,file,"MaxMinStep", 0, 4, 1, int_type, &(config::MaxMinStopStep), 1, critical);
1132 if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
1133 if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
1134 config::MaxMinGapStopStep = 1;
1135
1136 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
1137 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 2, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
1138 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 3, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
1139 ParseForParameter(verbose,file,"MaxInitMinStep", 0, 4, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
1140 if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
1141 if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
1142 config::InitMaxMinGapStopStep = 1;
1143
1144 ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
1145 mol->cell_size[0] = BoxLength[0];
1146 mol->cell_size[1] = BoxLength[3];
1147 mol->cell_size[2] = BoxLength[4];
1148 mol->cell_size[3] = BoxLength[6];
1149 mol->cell_size[4] = BoxLength[7];
1150 mol->cell_size[5] = BoxLength[8];
1151 if (1) fprintf(stderr,"\n");
1152 config::DoPerturbation = 0;
1153 config::DoFullCurrent = 0;
1154
1155 ParseForParameter(verbose,file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
1156 ParseForParameter(verbose,file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
1157 ParseForParameter(verbose,file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
1158 if (config::Lev0Factor < 2) {
1159 config::Lev0Factor = 2;
1160 }
1161 ParseForParameter(verbose,file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
1162 if (di >= 0 && di < 2) {
1163 config::RiemannTensor = di;
1164 } else {
1165 fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
1166 exit(1);
1167 }
1168 switch (config::RiemannTensor) {
1169 case 0: //UseNoRT
1170 if (config::MaxLevel < 2) {
1171 config::MaxLevel = 2;
1172 }
1173 config::LevRFactor = 2;
1174 config::RTActualUse = 0;
1175 break;
1176 case 1: // UseRT
1177 if (config::MaxLevel < 3) {
1178 config::MaxLevel = 3;
1179 }
1180 ParseForParameter(verbose,file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
1181 if (config::RiemannLevel < 2) {
1182 config::RiemannLevel = 2;
1183 }
1184 if (config::RiemannLevel > config::MaxLevel-1) {
1185 config::RiemannLevel = config::MaxLevel-1;
1186 }
1187 ParseForParameter(verbose,file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
1188 if (config::LevRFactor < 2) {
1189 config::LevRFactor = 2;
1190 }
1191 config::Lev0Factor = 2;
1192 config::RTActualUse = 2;
1193 break;
1194 }
1195 ParseForParameter(verbose,file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
1196 if (di >= 0 && di < 2) {
1197 config::PsiType = di;
1198 } else {
1199 fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
1200 exit(1);
1201 }
1202 switch (config::PsiType) {
1203 case 0: // SpinDouble
1204 ParseForParameter(verbose,file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
1205 config::AddPsis = 0;
1206 break;
1207 case 1: // SpinUpDown
1208 if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
1209 ParseForParameter(verbose,file,"MaxPsiUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
1210 ParseForParameter(verbose,file,"MaxPsiDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
1211 config::AddPsis = 0;
1212 break;
1213 }
1214
1215 // IonsInitRead
1216
1217 ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
1218 ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
1219 config::RelativeCoord = 0;
1220 config::StructOpt = 0;
1221
1222 // Routine from builder.cpp
1223
1224
1225 for (i=MAX_ELEMENTS;i--;)
1226 elementhash[i] = NULL;
1227 cout << Verbose(0) << "Parsing Ions ..." << endl;
1228 No=0;
1229 found = 0;
1230 while (getline(*file,zeile,'\n')) {
1231 if (zeile.find("Ions_Data") == 0) {
1232 cout << Verbose(1) << "found Ions_Data...begin parsing" << endl;
1233 found ++;
1234 }
1235 if (found > 0) {
1236 if (zeile.find("Ions_Data") == 0)
1237 getline(*file,zeile,'\n'); // read next line and parse this one
1238 istringstream input(zeile);
1239 input >> AtomNo; // number of atoms
1240 input >> Z; // atomic number
1241 input >> a;
1242 input >> l;
1243 input >> l;
1244 input >> b; // element mass
1245 elementhash[No] = periode->FindElement(Z);
1246 cout << Verbose(1) << "AtomNo: " << AtomNo << "\tZ: " << Z << "\ta:" << a << "\tl:" << l << "\b:" << b << "\tElement:" << elementhash[No] << "\t:" << endl;
1247 for(i=0;i<AtomNo;i++) {
1248 if (!getline(*file,zeile,'\n')) {// parse on and on
1249 cout << Verbose(2) << "Error: Too few items in ionic list of element" << elementhash[No] << "." << endl << "Exiting." << endl;
1250 // return 1;
1251 } else {
1252 //cout << Verbose(2) << "Reading line: " << zeile << endl;
1253 }
1254 istringstream input2(zeile);
1255 atom *neues = new atom();
1256 input2 >> neues->x.x[0]; // x
1257 input2 >> neues->x.x[1]; // y
1258 input2 >> neues->x.x[2]; // z
1259 input2 >> l;
1260 neues->type = elementhash[No]; // find element type
1261 mol->AddAtom(neues);
1262 }
1263 No++;
1264 }
1265 }
1266 file->close();
1267 delete(file);
1268};
1269
1270/** Stores all elements of config structure from which they can be re-read.
1271 * \param *filename name of file
1272 * \param *periode pointer to a periodentafel class with all elements
1273 * \param *mol pointer to molecule containing all atoms of the molecule
1274 */
1275bool config::Save(const char *filename, periodentafel *periode, molecule *mol) const
1276{
1277 bool result = true;
1278 // bring MaxTypes up to date
1279 mol->CountElements();
1280 ofstream *output = NULL;
1281 output = new ofstream(filename, ios::out);
1282 if (output != NULL) {
1283 *output << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
1284 *output << endl;
1285 *output << "mainname\t" << config::mainname << "\t# programm name (for runtime files)" << endl;
1286 *output << "defaultpath\t" << config::defaultpath << "\t# where to put files during runtime" << endl;
1287 *output << "pseudopotpath\t" << config::pseudopotpath << "\t# where to find pseudopotentials" << endl;
1288 *output << endl;
1289 *output << "ProcPEGamma\t" << config::ProcPEGamma << "\t# for parallel computing: share constants" << endl;
1290 *output << "ProcPEPsi\t" << config::ProcPEPsi << "\t# for parallel computing: share wave functions" << endl;
1291 *output << "DoOutVis\t" << config::DoOutVis << "\t# Output data for OpenDX" << endl;
1292 *output << "DoOutMes\t" << config::DoOutMes << "\t# Output data for measurements" << endl;
1293 *output << "DoOutOrbitals\t" << config::DoOutOrbitals << "\t# Output all Orbitals" << endl;
1294 *output << "DoOutCurr\t" << config::DoOutCurrent << "\t# Ouput current density for OpenDx" << endl;
1295 *output << "DoOutNICS\t" << config::DoOutNICS << "\t# Output Nucleus independent current shieldings" << endl;
1296 *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
1297 *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
1298 *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
1299 *output << "Thermostat\t" << ThermostatNames[Thermostat] << "\t";
1300 switch(Thermostat) {
1301 default:
1302 case None:
1303 break;
1304 case Woodcock:
1305 *output << ScaleTempStep;
1306 break;
1307 case Gaussian:
1308 *output << ScaleTempStep;
1309 break;
1310 case Langevin:
1311 *output << TempFrequency << "\t" << alpha;
1312 break;
1313 case Berendsen:
1314 *output << TempFrequency;
1315 break;
1316 case NoseHoover:
1317 *output << HooverMass;
1318 break;
1319 };
1320 *output << "\t# Which Thermostat and its parameters to use in MD case." << endl;
1321 *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
1322 *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
1323 *output << "VectorPlane\t" << config::VectorPlane << "\t# Cut plane axis (x, y or z: 0,1,2) for two-dim current vector plot" << endl;
1324 *output << "VectorCut\t" << config::VectorCut << "\t# Cut plane axis value" << endl;
1325 *output << "AddGramSch\t" << config::UseAddGramSch << "\t# Additional GramSchmidtOrtogonalization to be safe" << endl;
1326 *output << "Seed\t\t" << config::Seed << "\t# initial value for random seed for Psi coefficients" << endl;
1327 *output << endl;
1328 *output << "MaxOuterStep\t" << config::MaxOuterStep << "\t# number of MolecularDynamics/Structure optimization steps" << endl;
1329 *output << "Deltat\t" << config::Deltat << "\t# time per MD step" << endl;
1330 *output << "OutVisStep\t" << config::OutVisStep << "\t# Output visual data every ...th step" << endl;
1331 *output << "OutSrcStep\t" << config::OutSrcStep << "\t# Output \"restart\" data every ..th step" << endl;
1332 *output << "TargetTemp\t" << config::TargetTemp << "\t# Target temperature" << endl;
1333 *output << "MaxPsiStep\t" << config::MaxPsiStep << "\t# number of Minimisation steps per state (0 - default)" << endl;
1334 *output << "EpsWannier\t" << config::EpsWannier << "\t# tolerance value for spread minimisation of orbitals" << endl;
1335 *output << endl;
1336 *output << "# Values specifying when to stop" << endl;
1337 *output << "MaxMinStep\t" << config::MaxMinStep << "\t# Maximum number of steps" << endl;
1338 *output << "RelEpsTotalE\t" << config::RelEpsTotalEnergy << "\t# relative change in total energy" << endl;
1339 *output << "RelEpsKineticE\t" << config::RelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
1340 *output << "MaxMinStopStep\t" << config::MaxMinStopStep << "\t# check every ..th steps" << endl;
1341 *output << "MaxMinGapStopStep\t" << config::MaxMinGapStopStep << "\t# check every ..th steps" << endl;
1342 *output << endl;
1343 *output << "# Values specifying when to stop for INIT, otherwise same as above" << endl;
1344 *output << "MaxInitMinStep\t" << config::MaxInitMinStep << "\t# Maximum number of steps" << endl;
1345 *output << "InitRelEpsTotalE\t" << config::InitRelEpsTotalEnergy << "\t# relative change in total energy" << endl;
1346 *output << "InitRelEpsKineticE\t" << config::InitRelEpsKineticEnergy << "\t# relative change in kinetic energy" << endl;
1347 *output << "InitMaxMinStopStep\t" << config::InitMaxMinStopStep << "\t# check every ..th steps" << endl;
1348 *output << "InitMaxMinGapStopStep\t" << config::InitMaxMinGapStopStep << "\t# check every ..th steps" << endl;
1349 *output << endl;
1350 *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
1351 *output << mol->cell_size[0] << "\t" << endl;
1352 *output << mol->cell_size[1] << "\t" << mol->cell_size[2] << "\t" << endl;
1353 *output << mol->cell_size[3] << "\t" << mol->cell_size[4] << "\t" << mol->cell_size[5] << "\t" << endl;
1354 // FIXME
1355 *output << endl;
1356 *output << "ECut\t\t" << config::ECut << "\t# energy cutoff for discretization in Hartrees" << endl;
1357 *output << "MaxLevel\t" << config::MaxLevel << "\t# number of different levels in the code, >=2" << endl;
1358 *output << "Level0Factor\t" << config::Lev0Factor << "\t# factor by which node number increases from S to 0 level" << endl;
1359 *output << "RiemannTensor\t" << config::RiemannTensor << "\t# (Use metric)" << endl;
1360 switch (config::RiemannTensor) {
1361 case 0: //UseNoRT
1362 break;
1363 case 1: // UseRT
1364 *output << "RiemannLevel\t" << config::RiemannLevel << "\t# Number of Riemann Levels" << endl;
1365 *output << "LevRFactor\t" << config::LevRFactor << "\t# factor by which node number increases from 0 to R level from" << endl;
1366 break;
1367 }
1368 *output << "PsiType\t\t" << config::PsiType << "\t# 0 - doubly occupied, 1 - SpinUp,SpinDown" << endl;
1369 // write out both types for easier changing afterwards
1370 // switch (PsiType) {
1371 // case 0:
1372 *output << "MaxPsiDouble\t" << config::MaxPsiDouble << "\t# here: specifying both maximum number of SpinUp- and -Down-states" << endl;
1373 // break;
1374 // case 1:
1375 *output << "PsiMaxNoUp\t" << config::PsiMaxNoUp << "\t# here: specifying maximum number of SpinUp-states" << endl;
1376 *output << "PsiMaxNoDown\t" << config::PsiMaxNoDown << "\t# here: specifying maximum number of SpinDown-states" << endl;
1377 // break;
1378 // }
1379 *output << "AddPsis\t\t" << config::AddPsis << "\t# Additional unoccupied Psis for bandgap determination" << endl;
1380 *output << endl;
1381 *output << "RCut\t\t" << config::RCut << "\t# R-cut for the ewald summation" << endl;
1382 *output << "StructOpt\t" << config::StructOpt << "\t# Do structure optimization beforehand" << endl;
1383 *output << "IsAngstroem\t" << config::IsAngstroem << "\t# 0 - Bohr, 1 - Angstroem" << endl;
1384 *output << "RelativeCoord\t" << config::RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
1385 *output << "MaxTypes\t" << mol->ElementCount << "\t# maximum number of different ion types" << endl;
1386 *output << endl;
1387 result = result && mol->Checkout(output);
1388 if (mol->MDSteps <=1 )
1389 result = result && mol->Output(output);
1390 else
1391 result = result && mol->OutputTrajectories(output);
1392 output->close();
1393 output->clear();
1394 delete(output);
1395 return result;
1396 } else
1397 return false;
1398};
1399
1400/** Stores all elements in a MPQC input file.
1401 * Note that this format cannot be parsed again.
1402 * \param *filename name of file (without ".in" suffix!)
1403 * \param *mol pointer to molecule containing all atoms of the molecule
1404 */
1405bool config::SaveMPQC(const char *filename, molecule *mol) const
1406{
1407 int ElementNo = 0;
1408 int AtomNo;
1409 atom *Walker = NULL;
1410 element *runner = NULL;
1411 Vector *center = NULL;
1412 ofstream *output = NULL;
1413 stringstream *fname = NULL;
1414
1415 // first without hessian
1416 fname = new stringstream;
1417 *fname << filename << ".in";
1418 output = new ofstream(fname->str().c_str(), ios::out);
1419 *output << "% Created by MoleCuilder" << endl;
1420 *output << "mpqc: (" << endl;
1421 *output << "\tsavestate = no" << endl;
1422 *output << "\tdo_gradient = yes" << endl;
1423 *output << "\tmole<MBPT2>: (" << endl;
1424 *output << "\t\tmaxiter = 200" << endl;
1425 *output << "\t\tbasis = $:basis" << endl;
1426 *output << "\t\tmolecule = $:molecule" << endl;
1427 *output << "\t\treference<CLHF>: (" << endl;
1428 *output << "\t\t\tbasis = $:basis" << endl;
1429 *output << "\t\t\tmolecule = $:molecule" << endl;
1430 *output << "\t\t)" << endl;
1431 *output << "\t)" << endl;
1432 *output << ")" << endl;
1433 *output << "molecule<Molecule>: (" << endl;
1434 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
1435 *output << "\t{ atoms geometry } = {" << endl;
1436 center = mol->DetermineCenterOfAll(output);
1437 // output of atoms
1438 runner = mol->elemente->start;
1439 while (runner->next != mol->elemente->end) { // go through every element
1440 runner = runner->next;
1441 if (mol->ElementsInMolecule[runner->Z]) { // if this element got atoms
1442 ElementNo++;
1443 AtomNo = 0;
1444 Walker = mol->start;
1445 while (Walker->next != mol->end) { // go through every atom of this element
1446 Walker = Walker->next;
1447 if (Walker->type == runner) { // if this atom fits to element
1448 AtomNo++;
1449 *output << "\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;
1450 }
1451 }
1452 }
1453 }
1454 delete(center);
1455 *output << "\t}" << endl;
1456 *output << ")" << endl;
1457 *output << "basis<GaussianBasisSet>: (" << endl;
1458 *output << "\tname = \"" << basis << "\"" << endl;
1459 *output << "\tmolecule = $:molecule" << endl;
1460 *output << ")" << endl;
1461 output->close();
1462 delete(output);
1463 delete(fname);
1464
1465 // second with hessian
1466 fname = new stringstream;
1467 *fname << filename << ".hess.in";
1468 output = new ofstream(fname->str().c_str(), ios::out);
1469 *output << "% Created by MoleCuilder" << endl;
1470 *output << "mpqc: (" << endl;
1471 *output << "\tsavestate = no" << endl;
1472 *output << "\tdo_gradient = yes" << endl;
1473 *output << "\tmole<CLHF>: (" << endl;
1474 *output << "\t\tmaxiter = 200" << endl;
1475 *output << "\t\tbasis = $:basis" << endl;
1476 *output << "\t\tmolecule = $:molecule" << endl;
1477 *output << "\t)" << endl;
1478 *output << "\tfreq<MolecularFrequencies>: (" << endl;
1479 *output << "\t\tmolecule=$:molecule" << endl;
1480 *output << "\t)" << endl;
1481 *output << ")" << endl;
1482 *output << "molecule<Molecule>: (" << endl;
1483 *output << "\tunit = " << (IsAngstroem ? "angstrom" : "bohr" ) << endl;
1484 *output << "\t{ atoms geometry } = {" << endl;
1485 center = mol->DetermineCenterOfAll(output);
1486 // output of atoms
1487 runner = mol->elemente->start;
1488 while (runner->next != mol->elemente->end) { // go through every element
1489 runner = runner->next;
1490 if (mol->ElementsInMolecule[runner->Z]) { // if this element got atoms
1491 ElementNo++;
1492 AtomNo = 0;
1493 Walker = mol->start;
1494 while (Walker->next != mol->end) { // go through every atom of this element
1495 Walker = Walker->next;
1496 if (Walker->type == runner) { // if this atom fits to element
1497 AtomNo++;
1498 *output << "\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;
1499 }
1500 }
1501 }
1502 }
1503 delete(center);
1504 *output << "\t}" << endl;
1505 *output << ")" << endl;
1506 *output << "basis<GaussianBasisSet>: (" << endl;
1507 *output << "\tname = \"3-21G\"" << endl;
1508 *output << "\tmolecule = $:molecule" << endl;
1509 *output << ")" << endl;
1510 output->close();
1511 delete(output);
1512 delete(fname);
1513
1514 return true;
1515};
1516
1517/** Reads parameter from a parsed file.
1518 * The file is either parsed for a certain keyword or if null is given for
1519 * the value in row yth and column xth. If the keyword was necessity#critical,
1520 * then an error is thrown and the programme aborted.
1521 * \warning value is modified (both in contents and position)!
1522 * \param verbose 1 - print found value to stderr, 0 - don't
1523 * \param *file file to be parsed
1524 * \param name Name of value in file (at least 3 chars!)
1525 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1526 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1527 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1528 * counted from this unresetted position!)
1529 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1530 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1531 * \param type Type of the Parameter to be read
1532 * \param value address of the value to be read (must have been allocated)
1533 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1534 * \param critical necessity of this keyword being specified (optional, critical)
1535 * \return 1 - found, 0 - not found
1536 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1537 */
1538int 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) {
1539 int i,j; // loop variables
1540 int length = 0, maxlength = -1;
1541 long file_position = file->tellg(); // mark current position
1542 char *dummy1, *dummy, *free_dummy; // pointers in the line that is read in per step
1543 dummy1 = free_dummy = Malloc<char>(256, "config::ParseForParameter: *free_dummy");
1544
1545 //fprintf(stderr,"Parsing for %s\n",name);
1546 if (repetition == 0)
1547 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1548 return 0;
1549
1550 int line = 0; // marks line where parameter was found
1551 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1552 while((found != repetition)) {
1553 dummy1 = dummy = free_dummy;
1554 do {
1555 file->getline(dummy1, 256); // Read the whole line
1556 if (file->eof()) {
1557 if ((critical) && (found == 0)) {
1558 Free(&free_dummy);
1559 //Error(InitReading, name);
1560 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1561 exit(255);
1562 } else {
1563 //if (!sequential)
1564 file->clear();
1565 file->seekg(file_position, ios::beg); // rewind to start position
1566 Free(&free_dummy);
1567 return 0;
1568 }
1569 }
1570 line++;
1571 } while (dummy != NULL && dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1572
1573 // C++ getline removes newline at end, thus re-add
1574 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1575 i = strlen(dummy1);
1576 dummy1[i] = '\n';
1577 dummy1[i+1] = '\0';
1578 }
1579 //fprintf(stderr,"line %i ends at %i, newline at %i\n", line, strlen(dummy1), strchr(dummy1,'\n')-free_dummy);
1580
1581 if (dummy1 == NULL) {
1582 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1583 } else {
1584 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1585 }
1586 // Seek for possible end of keyword on line if given ...
1587 if (name != NULL) {
1588 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1589 if (dummy == NULL) {
1590 dummy = strchr(dummy1, ' '); // if not found seek for space
1591 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1592 dummy++;
1593 }
1594 if (dummy == NULL) {
1595 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1596 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1597 //Free((void **)&free_dummy);
1598 //Error(FileOpenParams, NULL);
1599 } else {
1600 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1601 }
1602 } else dummy = dummy1;
1603 // ... and check if it is the keyword!
1604 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1605 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1606 found++; // found the parameter!
1607 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1608
1609 if (found == repetition) {
1610 for (i=0;i<xth;i++) { // i = rows
1611 if (type >= grid) {
1612 // grid structure means that grid starts on the next line, not right after keyword
1613 dummy1 = dummy = free_dummy;
1614 do {
1615 file->getline(dummy1, 256); // Read the whole line, skip commentary and empty ones
1616 if (file->eof()) {
1617 if ((critical) && (found == 0)) {
1618 Free(&free_dummy);
1619 //Error(InitReading, name);
1620 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1621 exit(255);
1622 } else {
1623 //if (!sequential)
1624 file->clear();
1625 file->seekg(file_position, ios::beg); // rewind to start position
1626 Free(&free_dummy);
1627 return 0;
1628 }
1629 }
1630 line++;
1631 } while ((dummy1[0] == '#') || (dummy1[0] == '\n'));
1632 if (dummy1 == NULL){
1633 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1634 } else {
1635 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1636 }
1637 } else { // simple int, strings or doubles start in the same line
1638 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1639 dummy++;
1640 }
1641 // C++ getline removes newline at end, thus re-add
1642 if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
1643 j = strlen(dummy1);
1644 dummy1[j] = '\n';
1645 dummy1[j+1] = '\0';
1646 }
1647
1648 int start = (type >= grid) ? 0 : yth-1 ;
1649 for (j=start;j<yth;j++) { // j = columns
1650 // check for lower triangular area and upper triangular area
1651 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1652 *((double *)value) = 0.0;
1653 fprintf(stderr,"%f\t",*((double *)value));
1654 value = (void *)((long)value + sizeof(double));
1655 //value += sizeof(double);
1656 } else {
1657 // otherwise we must skip all interjacent tabs and spaces and find next value
1658 dummy1 = dummy;
1659 dummy = strchr(dummy1, '\t'); // seek for tab or space
1660 if (dummy == NULL)
1661 dummy = strchr(dummy1, ' '); // if not found seek for space
1662 if (dummy == NULL) { // if still zero returned ...
1663 dummy = strchr(dummy1, '\n'); // ... at line end then
1664 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1665 if (critical) {
1666 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1667 Free(&free_dummy);
1668 //return 0;
1669 exit(255);
1670 //Error(FileOpenParams, NULL);
1671 } else {
1672 //if (!sequential)
1673 file->clear();
1674 file->seekg(file_position, ios::beg); // rewind to start position
1675 Free(&free_dummy);
1676 return 0;
1677 }
1678 }
1679 } else {
1680 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1681 }
1682 if (*dummy1 == '#') {
1683 // found comment, skipping rest of line
1684 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1685 if (!sequential) { // here we need it!
1686 file->seekg(file_position, ios::beg); // rewind to start position
1687 }
1688 Free(&free_dummy);
1689 return 0;
1690 }
1691 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1692 switch(type) {
1693 case (row_int):
1694 *((int *)value) = atoi(dummy1);
1695 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1696 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1697 value = (void *)((long)value + sizeof(int));
1698 //value += sizeof(int);
1699 break;
1700 case(row_double):
1701 case(grid):
1702 case(lower_trigrid):
1703 case(upper_trigrid):
1704 *((double *)value) = atof(dummy1);
1705 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1706 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1707 value = (void *)((long)value + sizeof(double));
1708 //value += sizeof(double);
1709 break;
1710 case(double_type):
1711 *((double *)value) = atof(dummy1);
1712 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1713 //value += sizeof(double);
1714 break;
1715 case(int_type):
1716 *((int *)value) = atoi(dummy1);
1717 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1718 //value += sizeof(int);
1719 break;
1720 default:
1721 case(string_type):
1722 if (value != NULL) {
1723 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1724 maxlength = MAXSTRINGSIZE;
1725 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1726 strncpy((char *)value, dummy1, length); // copy as much
1727 ((char *)value)[length] = '\0'; // and set end marker
1728 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1729 //value += sizeof(char);
1730 } else {
1731 }
1732 break;
1733 }
1734 }
1735 while (*dummy == '\t')
1736 dummy++;
1737 }
1738 }
1739 }
1740 }
1741 }
1742 if ((type >= row_int) && (verbose))
1743 fprintf(stderr,"\n");
1744 Free(&free_dummy);
1745 if (!sequential) {
1746 file->clear();
1747 file->seekg(file_position, ios::beg); // rewind to start position
1748 }
1749 //fprintf(stderr, "End of Parsing\n\n");
1750
1751 return (found); // true if found, false if not
1752}
1753
1754
1755/** Reads parameter from a parsed file.
1756 * The file is either parsed for a certain keyword or if null is given for
1757 * the value in row yth and column xth. If the keyword was necessity#critical,
1758 * then an error is thrown and the programme aborted.
1759 * \warning value is modified (both in contents and position)!
1760 * \param verbose 1 - print found value to stderr, 0 - don't
1761 * \param *FileBuffer pointer to buffer structure
1762 * \param name Name of value in file (at least 3 chars!)
1763 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
1764 * (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
1765 * best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
1766 * counted from this unresetted position!)
1767 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
1768 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
1769 * \param type Type of the Parameter to be read
1770 * \param value address of the value to be read (must have been allocated)
1771 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
1772 * \param critical necessity of this keyword being specified (optional, critical)
1773 * \return 1 - found, 0 - not found
1774 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
1775 */
1776int config::ParseForParameter(int verbose, struct ConfigFileBuffer *FileBuffer, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) {
1777 int i,j; // loop variables
1778 int length = 0, maxlength = -1;
1779 int OldCurrentLine = FileBuffer->CurrentLine;
1780 char *dummy1, *dummy; // pointers in the line that is read in per step
1781
1782 //fprintf(stderr,"Parsing for %s\n",name);
1783 if (repetition == 0)
1784 //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
1785 return 0;
1786
1787 int line = 0; // marks line where parameter was found
1788 int found = (type >= grid) ? 0 : (-yth + 1); // marks if yth parameter name was found
1789 while((found != repetition)) {
1790 dummy1 = dummy = NULL;
1791 do {
1792 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ];
1793 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1794 if ((critical) && (found == 0)) {
1795 //Error(InitReading, name);
1796 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1797 exit(255);
1798 } else {
1799 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1800 return 0;
1801 }
1802 }
1803 if (dummy1 == NULL) {
1804 if (verbose) fprintf(stderr,"Error reading line %i\n",line);
1805 } else {
1806 //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
1807 }
1808 line++;
1809 } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
1810
1811 // Seek for possible end of keyword on line if given ...
1812 if (name != NULL) {
1813 dummy = strchr(dummy1,'\t'); // set dummy on first tab or space which ever's nearer
1814 if (dummy == NULL) {
1815 dummy = strchr(dummy1, ' '); // if not found seek for space
1816 while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' '))) // skip some more tabs and spaces if necessary
1817 dummy++;
1818 }
1819 if (dummy == NULL) {
1820 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
1821 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
1822 //Free(&free_dummy);
1823 //Error(FileOpenParams, NULL);
1824 } else {
1825 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
1826 }
1827 } else dummy = dummy1;
1828 // ... and check if it is the keyword!
1829 //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
1830 if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
1831 found++; // found the parameter!
1832 //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
1833
1834 if (found == repetition) {
1835 for (i=0;i<xth;i++) { // i = rows
1836 if (type >= grid) {
1837 // grid structure means that grid starts on the next line, not right after keyword
1838 dummy1 = dummy = NULL;
1839 do {
1840 dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ];
1841 if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
1842 if ((critical) && (found == 0)) {
1843 //Error(InitReading, name);
1844 fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
1845 exit(255);
1846 } else {
1847 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1848 return 0;
1849 }
1850 }
1851 if (dummy1 == NULL) {
1852 if (verbose) fprintf(stderr,"Error reading line %i\n", line);
1853 } else {
1854 //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
1855 }
1856 line++;
1857 } while (dummy1 != NULL && (dummy1[0] == '#') || (dummy1[0] == '\n'));
1858 dummy = dummy1;
1859 } else { // simple int, strings or doubles start in the same line
1860 while ((*dummy == '\t') || (*dummy == ' ')) // skip interjacent tabs and spaces
1861 dummy++;
1862 }
1863
1864 for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns
1865 // check for lower triangular area and upper triangular area
1866 if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
1867 *((double *)value) = 0.0;
1868 fprintf(stderr,"%f\t",*((double *)value));
1869 value = (void *)((long)value + sizeof(double));
1870 //value += sizeof(double);
1871 } else {
1872 // otherwise we must skip all interjacent tabs and spaces and find next value
1873 dummy1 = dummy;
1874 dummy = strchr(dummy1, '\t'); // seek for tab or space
1875 if (dummy == NULL)
1876 dummy = strchr(dummy1, ' '); // if not found seek for space
1877 if (dummy == NULL) { // if still zero returned ...
1878 dummy = strchr(dummy1, '\n'); // ... at line end then
1879 if ((j < yth-1) && (type < 4)) { // check if xth value or not yet
1880 if (critical) {
1881 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1882 //return 0;
1883 exit(255);
1884 //Error(FileOpenParams, NULL);
1885 } else {
1886 if (!sequential) { // here we need it!
1887 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1888 }
1889 return 0;
1890 }
1891 }
1892 } else {
1893 //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
1894 }
1895 if (*dummy1 == '#') {
1896 // found comment, skipping rest of line
1897 //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
1898 if (!sequential) { // here we need it!
1899 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1900 }
1901 return 0;
1902 }
1903 //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
1904 switch(type) {
1905 case (row_int):
1906 *((int *)value) = atoi(dummy1);
1907 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1908 if (verbose) fprintf(stderr,"%i\t",*((int *)value));
1909 value = (void *)((long)value + sizeof(int));
1910 //value += sizeof(int);
1911 break;
1912 case(row_double):
1913 case(grid):
1914 case(lower_trigrid):
1915 case(upper_trigrid):
1916 *((double *)value) = atof(dummy1);
1917 if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
1918 if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
1919 value = (void *)((long)value + sizeof(double));
1920 //value += sizeof(double);
1921 break;
1922 case(double_type):
1923 *((double *)value) = atof(dummy1);
1924 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
1925 //value += sizeof(double);
1926 break;
1927 case(int_type):
1928 *((int *)value) = atoi(dummy1);
1929 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
1930 //value += sizeof(int);
1931 break;
1932 default:
1933 case(string_type):
1934 if (value != NULL) {
1935 //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
1936 maxlength = MAXSTRINGSIZE;
1937 length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
1938 strncpy((char *)value, dummy1, length); // copy as much
1939 ((char *)value)[length] = '\0'; // and set end marker
1940 if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
1941 //value += sizeof(char);
1942 } else {
1943 }
1944 break;
1945 }
1946 }
1947 while (*dummy == '\t')
1948 dummy++;
1949 }
1950 }
1951 }
1952 }
1953 }
1954 if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
1955 if (!sequential) {
1956 FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
1957 }
1958 //fprintf(stderr, "End of Parsing\n\n");
1959
1960 return (found); // true if found, false if not
1961}
Note: See TracBrowser for help on using the repository browser.