source: src/config.cpp@ 87e2e39

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 87e2e39 was 29812d, checked in by Saskia Metzler <metzler@…>, 15 years ago

Ticket 11: use templates and/or traits to fix Malloc/ReAlloc-Free warnings in a clean manner

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