00001 #include "configuration.h"
00002
00003 Configuration::Configuration()
00004 {
00005 homePath = gSystem->HomeDirectory();
00006 fileName = gSystem->ConcatFileName(homePath, CONFIG_FILE);
00007
00008 params = 0;
00009 functions = 0;
00010 xmlDoc = 0;
00011
00012 LoadConfigFromFile();
00013 }
00014
00015 Configuration::~Configuration()
00016 {
00017 delete [] params;
00018 delete [] functions;
00019 delete imgPath; delete imgPrefix;
00020 xmlFreeDoc(xmlDoc);
00021 }
00022
00023 void Configuration::LoadConfigFromFile()
00024 {
00025 UInt_t count;
00026 Int_t* iid;
00027 const char** expr;
00028 const char** latex;
00029 const char** id;
00030 const char** name;
00031 const char** descr;
00032 const char **x, **y, **z;
00033 Double_t* value;
00034 xmlChar* xmlStr;
00035 xmlNodePtr node;
00036
00037 xmlFreeDoc(xmlDoc);
00038
00039 xmlDoc = xmlParseFile(fileName);
00040 if (!xmlDoc)
00041 xmlDoc = CreateConfigFile();
00042 if (!xmlDoc) {
00043 cerr << "Error opening xml configuration file, aborting." << endl;
00044 exit(0);
00045 }
00046
00047
00048
00049 node = GetConfigNode("Algorithm");
00050 if (node) {
00051 xmlStr = xmlGetProp(node, (const xmlChar*)"k");
00052 k = atof((const char*)xmlStr);
00053 delete xmlStr;
00054 xmlStr = xmlGetProp(node, (const xmlChar*)"T");
00055 T = atof((const char*)xmlStr);
00056 delete xmlStr;
00057 xmlStr = xmlGetProp(node, (const xmlChar*)"Tmin");
00058 Tmin = atof((const char*)xmlStr);
00059 delete xmlStr;
00060 xmlStr = xmlGetProp(node, (const xmlChar*)"Tmax");
00061 Tmax = atof((const char*)xmlStr);
00062 delete xmlStr;
00063 xmlStr = xmlGetProp(node, (const xmlChar*)"IntLimit");
00064 intLimit = atof((const char*)xmlStr);
00065 delete xmlStr;
00066 }
00067 else {
00068 cerr << "Could not read Algorithm info from configuration file." << endl;
00069 k = 1.0;
00070 T = 0.5;
00071 Tmin = 0.0;
00072 Tmax = 1.0;
00073 intLimit = 10.0;
00074 }
00075
00076 node = GetConfigNode("Visualization");
00077 if (node) {
00078 xmlStr = xmlGetProp(node, (const xmlChar*)"UpdateCanvas");
00079 if (strncmp((const char*)xmlStr, "1", 1) == 0)
00080 bUpdateCanvas = 1;
00081 else bUpdateCanvas = 0;
00082 delete xmlStr;
00083 xmlStr = xmlGetProp(node, (const xmlChar*)"UpdateInt");
00084 updateInt = atoi((const char*)xmlStr),
00085 delete xmlStr;
00086 xmlStr = xmlGetProp(node, (const xmlChar*)"AutoSave");
00087 if (strncmp((const char*)xmlStr, "1", 1) == 0)
00088 bAutoSave = 1;
00089 else bAutoSave = 0;
00090 delete xmlStr;
00091 imgPath = (char*)xmlGetProp(node, (const xmlChar*)"ImgPath");
00092 imgPrefix = (char*)xmlGetProp(node, (const xmlChar*)"ImgPrefix");
00093 xmlStr = xmlGetProp(node, (const xmlChar*)"ImgFormat");
00094 imgFormat = atoi((const char*)xmlStr);
00095 delete xmlStr;
00096 xmlStr = xmlGetProp(node, (const xmlChar*)"SaveInt");
00097 saveInt = atoi((const char*)xmlStr);
00098 delete xmlStr;
00099 }
00100 else {
00101 cerr << "Could not read Visualization info from configuration file." << endl;
00102 bUpdateCanvas = 1;
00103 updateInt = 20;
00104 bAutoSave = 0;
00105 imgPath = new char[strlen(homePath)+1];
00106 strncpy(imgPath, homePath, strlen(homePath)+1);
00107 imgPrefix = "canv";
00108 imgFormat = 3;
00109 saveInt = 40;
00110 }
00111
00112 node = GetConfigNode("Atom");
00113 if (node) {
00114 xmlStr = xmlGetProp(node, (const xmlChar*)"shape");
00115 atomShape = atoi((const char*)xmlStr);
00116 delete xmlStr;
00117 xmlStr = xmlGetProp(node, (const xmlChar*)"size");
00118 atomSize = atof((const char*)xmlStr);
00119 delete xmlStr;
00120 xmlStr = xmlGetProp(node, (const xmlChar*)"color");
00121 atomColor = (Color_t)atoi((const char*)xmlStr);
00122 delete xmlStr;
00123 }
00124 else {
00125 cerr << "Could not read Atom style from configuration file." << endl;
00126 atomShape = 1;
00127 atomSize = 1.0;
00128 atomColor = 1;
00129 }
00130
00131 node = GetConfigNode("Defect");
00132 if (node) {
00133 xmlStr = xmlGetProp(node, (const xmlChar*)"shape");
00134 defectShape = atoi((const char*)xmlStr);
00135 delete xmlStr;
00136 xmlStr = xmlGetProp(node, (const xmlChar*)"size");
00137 defectSize = atof((const char*)xmlStr);
00138 delete xmlStr;
00139 xmlStr = xmlGetProp(node, (const xmlChar*)"color");
00140 defectColor = (Color_t)atoi((const char*)xmlStr);
00141 delete xmlStr;
00142 xmlStr = xmlGetProp(node, (const xmlChar*)"insert");
00143 insNum = atoi((const char*)xmlStr);
00144 delete xmlStr;
00145 xmlStr = xmlGetProp(node, (const xmlChar*)"remove");
00146 remNum = atoi((const char*)xmlStr);
00147 delete xmlStr;
00148 }
00149 else {
00150 cerr << "Could not read Defect style from configuration file." << endl;
00151 defectShape = 1;
00152 defectSize = 1.0;
00153 defectColor = 4;
00154 insNum = 5;
00155 remNum = 5;
00156 }
00157
00158
00159 node = GetConfigNode("Parameter");
00160 if (node) {
00161 xmlStr = xmlGetProp(node, (const xmlChar*)"count");
00162 count = atoi((const char*)xmlStr);
00163 delete xmlStr;
00164
00165 id = new (const char*)[count];
00166 name = new (const char*)[count];
00167 value = new Double_t[count];
00168 descr = new (const char*)[count];
00169
00170 node = node->xmlChildrenNode;
00171 for (UInt_t i = 0; i < count; i++) {
00172 if (!node) {
00173 count = i;
00174 break;
00175 }
00176 id[i] = (const char*)xmlGetProp(node, (const xmlChar*)"id");
00177 name[i] = (const char*)node->name;
00178 descr[i] = (const char*)xmlGetProp(node, (const xmlChar*)"descr");
00179 value[i] = atof((const char*)node->xmlChildrenNode->content);
00180 node = node->next;
00181 }
00182
00183 SetParam(id, name, value, descr, count);
00184 for (UInt_t i = 0; i < count; i++) {
00185 delete id[i];
00186 delete descr[i];
00187 }
00188 delete [] id;
00189 delete [] name;
00190 delete [] value;
00191 delete [] descr;
00192 }
00193 else
00194 cerr << "Could not read Parameter from configuration file." << endl;
00195
00196
00197 node = GetConfigNode("Functions");
00198 if (node) {
00199 xmlStr = xmlGetProp(node, (const xmlChar*)"count");
00200 count = atoi((const char*)xmlStr);
00201 delete xmlStr;
00202
00203 iid = new Int_t[count];
00204 name = new (const char*)[count];
00205 expr = new (const char*)[count];
00206 latex = new (const char*)[count];
00207 x = new (const char*)[count];
00208 y = new (const char*)[count];
00209 z = new (const char*)[count];
00210
00211 node = node->xmlChildrenNode;
00212 for (UInt_t i = 0; i < count; i++) {
00213 if (!node) {
00214 count = i;
00215 break;
00216 }
00217 iid[i] = atoi((const char*)(xmlStr = xmlGetProp(node, (const xmlChar*)"id")));
00218 delete xmlStr;
00219 name[i] = (const char*)node->name;
00220 expr[i] = (const char*)node->xmlChildrenNode->content;
00221 x[i] = (const char*)xmlGetProp(node, (const xmlChar*)"x");
00222 y[i] = (const char*)xmlGetProp(node, (const xmlChar*)"y");
00223 z[i] = (const char*)xmlGetProp(node, (const xmlChar*)"z");
00224 latex[i] = (const char*)xmlGetProp(node, (const xmlChar*)"latex");
00225 node = node->next;
00226 }
00227
00228 SetFunction(iid, name, expr, latex, x, y, z, count);
00229 for (UInt_t i = 0; i < count; i++) {
00230 delete latex[i];
00231 delete x[i];
00232 delete y[i];
00233 delete z[i];
00234 }
00235
00236 delete [] iid;
00237 delete [] name;
00238 delete [] expr;
00239 delete [] latex;
00240 delete [] x; delete [] y; delete [] z;
00241 }
00242 else
00243 cerr << "Could not read Functions from configuration file." << endl;
00244
00245 }
00246
00247 void Configuration::SaveFormulaToFile()
00248 {
00249
00250 xmlNodePtr xmlNPtr;
00251
00252 if ((xmlNPtr = GetConfigNode("Parameter")))
00253 WriteParam(xmlNPtr);
00254 else
00255 cerr << "Error writing Configuration->Parameter" << endl;
00256
00257 if ((xmlNPtr = GetConfigNode("Functions")))
00258 WriteFunction(xmlNPtr);
00259 else
00260 cerr << "Error writing Configuration->Functions" << endl;
00261
00262
00263
00264 if (xmlSaveFile(fileName, xmlDoc) == -1)
00265 cerr << "Error writing file " << fileName << ". Check your permissions." << endl;
00266 }
00267
00268 void Configuration::SaveSimulationToFile()
00269 {
00270
00271 xmlNodePtr xmlNPtr;
00272
00273 if ((xmlNPtr = GetConfigNode("MonteCarlo")))
00274 WriteMonteCarlo(xmlNPtr);
00275 else
00276 cerr << "Error writing Configuration->MonteCarlo" << endl;
00277
00278 if ((xmlNPtr = GetConfigNode("Lattice")))
00279 WriteLattice(xmlNPtr);
00280 else
00281 cerr << "Error writing Configuration->Lattice" << endl;
00282
00283
00284 if (xmlSaveFile(fileName, xmlDoc) == -1)
00285 cerr << "Error writing file " << fileName << ". Check your permissions." << endl;
00286 }
00287
00288 void Configuration::SaveTempToFile()
00289 {
00290 char str[32];
00291 xmlNodePtr algNode;
00292
00293 if ((algNode = GetConfigNode("Algorithm"))) {
00294 snprintf(str, 32, "%f", T);
00295 xmlSetProp(algNode, (const xmlChar*)"T", (const xmlChar*)str);
00296 snprintf(str, 32, "%f", Tmin);
00297 xmlSetProp(algNode, (const xmlChar*)"Tmin", (const xmlChar*)str);
00298 snprintf(str, 32, "%f", Tmax);
00299 xmlSetProp(algNode, (const xmlChar*)"Tmax", (const xmlChar*)str);
00300 }
00301 else
00302 cerr << "Error writing Configuration->Algorithm" << endl;
00303
00304 if (xmlSaveFile(fileName, xmlDoc) == -1)
00305 cerr << "Error writing file " << fileName << ". Check your permissions." << endl;
00306
00307 }
00308
00309
00310 void Configuration::SetImagePath(const char* str)
00311 {
00312 Int_t size;
00313
00314 TThread::Lock();
00315 if (imgPath) delete imgPath;
00316 size = strlen(str)+1;
00317 imgPath = new char[size];
00318 strncpy(imgPath, str, size);
00319 TThread::UnLock();
00320 }
00321
00322 void Configuration::SetImagePrefix(const char* str)
00323 {
00324 Int_t size;
00325
00326 TThread::Lock();
00327 if (imgPrefix) delete imgPrefix;
00328 size = strlen(str)+1;
00329 imgPrefix = new char[size];
00330 strncpy(imgPrefix, str, size);
00331 TThread::UnLock();
00332 }
00333
00334 void Configuration::SetAtomStyle(Style_t style, Size_t size, Color_t color)
00335 {
00336 atomShape = style;
00337 atomSize = size;
00338 atomColor = color;
00339 }
00340
00341 void Configuration::SetDefectStyle(Style_t style, Size_t size, Color_t color)
00342 {
00343 defectShape = style;
00344 defectSize = size;
00345 defectColor = color;
00346 }
00347
00348 void Configuration::SetParam(const char** id, const char** name, Double_t* value, const char** descr, UInt_t count)
00349 {
00350 UInt_t i;
00351 Param** newParams;
00352
00353 newParams = new (Param*)[count];
00354 for (i = 0; i < count; i++)
00355 newParams[i] = new Param(id[i], name[i], value[i], descr[i]);
00356
00357 for (i = 0; i < paramCount; i++)
00358 delete params[i];
00359 delete [] params;
00360
00361 params = newParams;
00362 paramCount = count;
00363 }
00364
00365 void Configuration::SetFunction(Int_t* id, const char** name, const char** expr, const char** latex, const char** x, const char** y, const char **z, UInt_t count)
00366 {
00367 UInt_t i;
00368 Function** newFunctions;
00369
00370 newFunctions = new (Function*)[count];
00371 for (i = 0; i < count; i++)
00372 newFunctions[i] = new Function(id[i], name[i], expr[i], latex[i], x[i], y[i], z[i]);
00373
00374 for (i = 0; i < funcCount; i++)
00375 delete functions[i];
00376 delete [] functions;
00377
00378 functions = newFunctions;
00379 funcCount = count;
00380 }
00381
00382 Function** Configuration::AddFunction(Int_t id, const char* name, const char* expr, const char* latex, const char* x, const char* y, const char* z)
00383 {
00384 UInt_t i;
00385 Function** newFunctions;
00386
00387 newFunctions = new (Function*)[funcCount+1];
00388 for (i = 0; i < funcCount; i++)
00389 newFunctions[i] = new Function(functions[i]);
00390
00391 newFunctions[i] = new Function(id, name, expr, latex, x, y, z);
00392 newFunctions[i]->bAdded = kTRUE;
00393
00394 for (i = 0; i < funcCount; i++)
00395 delete functions[i];
00396 delete [] functions;
00397
00398 functions = newFunctions;
00399 funcCount++;
00400
00401 return functions;
00402 }
00403
00404 void Configuration::RevertFunction()
00405 {
00406 UInt_t i, j, count;
00407 Int_t* id;
00408 const char** name;
00409 const char** expr;
00410 const char** latex;
00411 const char **x, **y, **z;
00412
00413 count = 0;
00414 for (i = 0; i < funcCount; i++)
00415 if (!functions[i]->bAdded) count++;
00416
00417 id = new Int_t[count];
00418 name = new (const char*)[count];
00419 expr = new (const char*)[count];
00420 latex = new (const char*)[count];
00421 x = new (const char*)[count];
00422 y = new (const char*)[count];
00423 z = new (const char*)[count];
00424
00425 j = 0;
00426 for (i = 0; i < funcCount; i++)
00427 if (!functions[i]->bAdded) {
00428 id[j] = j;
00429 name[j] = functions[i]->oldName;
00430 expr[j] = functions[i]->oldExpr;
00431 latex[j] = functions[i]->oldLatex;
00432 x[j] = functions[i]->oldX;
00433 y[j] = functions[i]->oldY;
00434 z[j] = functions[i]->oldZ;
00435 j++;
00436 }
00437
00438 SetFunction(id, name, expr, latex, x, y, z, count);
00439
00440 delete [] id;
00441 delete [] name;
00442 delete [] expr;
00443 delete [] latex;
00444 delete [] x; delete [] y; delete [] z;
00445 }
00446
00447 void Configuration::CleanFunction()
00448 {
00449 UInt_t i, j, count;
00450 Int_t* id;
00451 const char** name;
00452 const char** expr;
00453 const char** latex;
00454 const char **x, **y, **z;
00455
00456 count = 0;
00457 for (i = 0; i < funcCount; i++)
00458 if (!functions[i]->bDeleted) count++;
00459
00460 id = new Int_t[count];
00461 name = new (const char*)[count];
00462 expr = new (const char*)[count];
00463 latex = new (const char*)[count];
00464 x = new (const char*)[count];
00465 y = new (const char*)[count];
00466 z = new (const char*)[count];
00467
00468 j = 0;
00469 for (i = 0; i < funcCount; i++)
00470 if (!functions[i]->bDeleted) {
00471 id[j] = j;
00472 name[j] = functions[i]->curName;
00473 expr[j] = functions[i]->curExpr;
00474 latex[j] = functions[i]->curLatex;
00475 x[j] = functions[i]->curX;
00476 y[j] = functions[i]->curY;
00477 z[j] = functions[i]->curZ;
00478 j++;
00479 }
00480
00481 SetFunction(id, name, expr, latex, x, y, z, count);
00482
00483 delete [] id;
00484 delete [] name;
00485 delete [] expr;
00486 delete [] latex;
00487 delete [] x; delete [] y; delete [] z;
00488 }
00489
00490 UInt_t Configuration::GetParam(Param**& p)
00491 {
00492 p = params;
00493 return paramCount;
00494 }
00495
00496 UInt_t Configuration::GetFunction(Function**& f)
00497 {
00498 f = functions;
00499 return funcCount;
00500 }
00501
00502 xmlDocPtr Configuration::CreateConfigFile()
00503 {
00504 xmlDocPtr doc;
00505 xmlNodePtr formulaTree, paramTree;
00506 xmlNodePtr simTree, latticeTree, mcTree;
00507 xmlNodePtr algChild, visChild;
00508 xmlNodePtr sigmaChild, fChild, aChild, EChild, hChild;
00509 xmlNodePtr atomChild, defectChild;
00510 xmlNodePtr funcTree;
00511 xmlNodePtr f1Child, f2Child;
00512
00513 cout << "Creating configuration file " << fileName << "..." << endl;
00514
00515 doc = xmlNewDoc((const xmlChar*)"1.0");
00516 doc->children = xmlNewDocNode(doc, NULL, (const xmlChar*)"XEIS", NULL);
00517 xmlSetProp(doc->children, (const xmlChar*)"version", (const xmlChar*)"1.1c");
00518 simTree = xmlNewChild(doc->children, NULL, (const xmlChar*)"Simulation", NULL);
00519 latticeTree = xmlNewChild(simTree, NULL, (const xmlChar*)"Lattice", NULL);
00520 atomChild = xmlNewChild(latticeTree, NULL, (const xmlChar*)"Atom", NULL);
00521 xmlSetProp(atomChild, (const xmlChar*)"shape", (const xmlChar*)"21");
00522 xmlSetProp(atomChild, (const xmlChar*)"size", (const xmlChar*)"0.2");
00523 xmlSetProp(atomChild, (const xmlChar*)"color", (const xmlChar*)"1");
00524 defectChild = xmlNewChild(latticeTree, NULL, (const xmlChar*)"Defect", NULL);
00525 xmlSetProp(defectChild, (const xmlChar*)"shape", (const xmlChar*)"4");
00526 xmlSetProp(defectChild, (const xmlChar*)"size", (const xmlChar*)"1.0");
00527 xmlSetProp(defectChild, (const xmlChar*)"color", (const xmlChar*)"2");
00528 xmlSetProp(defectChild, (const xmlChar*)"insert", (const xmlChar*)"5");
00529 xmlSetProp(defectChild, (const xmlChar*)"remove", (const xmlChar*)"5");
00530 mcTree = xmlNewChild(simTree, NULL, (const xmlChar*)"MonteCarlo", NULL);
00531 algChild = xmlNewChild(mcTree, NULL, (const xmlChar*)"Algorithm", NULL);
00532 xmlSetProp(algChild, (const xmlChar*)"k", (const xmlChar*)"1.0");
00533 xmlSetProp(algChild, (const xmlChar*)"T", (const xmlChar*)"0.5");
00534 xmlSetProp(algChild, (const xmlChar*)"Tmin", (const xmlChar*)"0.0");
00535 xmlSetProp(algChild, (const xmlChar*)"Tmax", (const xmlChar*)"1.0");
00536 xmlSetProp(algChild, (const xmlChar*)"IntLimit", (const xmlChar*)"10.0");
00537 visChild = xmlNewChild(mcTree, NULL, (const xmlChar*)"Visualization", NULL);
00538 xmlSetProp(visChild, (const xmlChar*)"UpdateCanvas", (const xmlChar*)"1");
00539 xmlSetProp(visChild, (const xmlChar*)"UpdateInt", (const xmlChar*)"20");
00540 xmlSetProp(visChild, (const xmlChar*)"AutoSave", (const xmlChar*)"0");
00541 xmlSetProp(visChild, (const xmlChar*)"ImgPath", (const xmlChar*)homePath);
00542 xmlSetProp(visChild, (const xmlChar*)"ImgPrefix", (const xmlChar*)"canv");
00543 xmlSetProp(visChild, (const xmlChar*)"ImgFormat", (const xmlChar*)"3");
00544 xmlSetProp(visChild, (const xmlChar*)"SaveInt", (const xmlChar*)"40");
00545 formulaTree = xmlNewChild(doc->children, NULL, (const xmlChar*)"Formula", NULL);
00546 paramTree = xmlNewChild(formulaTree, NULL, (const xmlChar*)"Parameter", NULL);
00547 xmlSetProp(paramTree, (const xmlChar*)"count", (const xmlChar*)"5");
00548 sigmaChild = xmlNewChild(paramTree, NULL, (const xmlChar*)"sigma", (const xmlChar*)"0.3");
00549 xmlSetProp(sigmaChild, (const xmlChar*)"id", (const xmlChar*)"[0]");
00550 xmlSetProp(sigmaChild, (const xmlChar*)"descr", (const xmlChar*)"Poisson ratio");
00551 fChild = xmlNewChild(paramTree, NULL, (const xmlChar*)"f", (const xmlChar*)"1.0");
00552 xmlSetProp(fChild, (const xmlChar*)"id", (const xmlChar*)"[1]");
00553 xmlSetProp(fChild, (const xmlChar*)"descr", (const xmlChar*)"force");
00554 aChild = xmlNewChild(paramTree, NULL, (const xmlChar*)"a", (const xmlChar*)"1.0");
00555 xmlSetProp(aChild, (const xmlChar*)"id", (const xmlChar*)"[2]");
00556 xmlSetProp(aChild, (const xmlChar*)"descr", (const xmlChar*)"size of defect");
00557 EChild = xmlNewChild(paramTree, NULL, (const xmlChar*)"E", (const xmlChar*)"1.0");
00558 xmlSetProp(EChild, (const xmlChar*)"id", (const xmlChar*)"[3]");
00559 xmlSetProp(EChild, (const xmlChar*)"descr", (const xmlChar*)"Young's modulus");
00560 hChild = xmlNewChild(paramTree, NULL, (const xmlChar*)"h", (const xmlChar*)"1.0");
00561 xmlSetProp(hChild, (const xmlChar*)"id", (const xmlChar*)"[4]");
00562 xmlSetProp(hChild, (const xmlChar*)"descr", (const xmlChar*)"layer thickness");
00563 funcTree = xmlNewChild(formulaTree, NULL, (const xmlChar*)"Functions", NULL);
00564 xmlSetProp(funcTree, (const xmlChar*)"count", (const xmlChar*)"2");
00565 f1Child = xmlNewChild(funcTree, NULL, (const xmlChar*)"Threefold", (const xmlChar*)"(1+sigma)*f*f/(pi*E*h)*pow(a/r, 4)*(-27*(1+sigma)/2*cos(6*theta))");
00566 xmlSetProp(f1Child, (const xmlChar*)"id", (const xmlChar*)"0");
00567 xmlSetProp(f1Child, (const xmlChar*)"x", (const xmlChar*)"r");
00568 xmlSetProp(f1Child, (const xmlChar*)"y", (const xmlChar*)"theta");
00569 xmlSetProp(f1Child, (const xmlChar*)"z", (const xmlChar*)"");
00570 xmlSetProp(f1Child, (const xmlChar*)"latex", (const xmlChar*)"#frac{(1 + #sigma) f^{2} a^{4}}{#pi E h r^{4}} (-27 #frac{(1 + #sigma)}{2} cos(6 #theta))");
00571 f2Child = xmlNewChild(funcTree, NULL, (const xmlChar*)"Fourfold", (const xmlChar*)"(1+sigma)*f*f/(pi*E*h)*pow(a/r, 4)*(25-5*sigma)*cos(4*theta)");
00572 xmlSetProp(f2Child, (const xmlChar*)"id", (const xmlChar*)"1");
00573 xmlSetProp(f2Child, (const xmlChar*)"x", (const xmlChar*)"r");
00574 xmlSetProp(f2Child, (const xmlChar*)"y", (const xmlChar*)"theta");
00575 xmlSetProp(f2Child, (const xmlChar*)"z", (const xmlChar*)"");
00576 xmlSetProp(f2Child, (const xmlChar*)"latex", (const xmlChar*)"#frac{(1 + #sigma) f^{2} a^{4}}{#pi E h r^{4}} (25 - 5 #sigma) cos(4 #theta)");
00577
00578 if (xmlSaveFile(fileName, doc) == -1) {
00579 cerr << "Error writing file " << fileName << ". Check your permissions." << endl;
00580 return NULL;
00581 }
00582 else
00583 return doc;
00584 }
00585
00586 void Configuration::WriteParam(xmlNodePtr oldParamTree)
00587 {
00588 xmlNodePtr newParamTree, paramChild;
00589 char strVal[30];
00590
00591 newParamTree = xmlNewNode(NULL, (const xmlChar*)"Parameter");
00592 snprintf(strVal, 30, "%d", paramCount);
00593 xmlSetProp(newParamTree, (const xmlChar*)"count", (const xmlChar*)strVal);
00594
00595 for (UInt_t i = 0; i < paramCount; i++) {
00596 snprintf(strVal, 30, "%f", params[i]->value);
00597 paramChild = xmlNewChild(newParamTree, NULL, (const xmlChar*)params[i]->name, (const xmlChar*)strVal);
00598 xmlSetProp(paramChild, (const xmlChar*)"id", (const xmlChar*)params[i]->id);
00599 xmlSetProp(paramChild, (const xmlChar*)"descr", (const xmlChar*)params[i]->descr);
00600 }
00601
00602 xmlReplaceNode(oldParamTree, newParamTree);
00603 xmlFreeNode(oldParamTree);
00604 }
00605
00606 void Configuration::WriteFunction(xmlNodePtr oldFuncTree)
00607 {
00608 xmlNodePtr newFuncTree, funcChild;
00609 char strVal[30];
00610
00611 newFuncTree = xmlNewNode(NULL, (const xmlChar*)"Functions");
00612
00613 for (UInt_t i = 0; i < funcCount; i++) {
00614 snprintf(strVal, 30, "%d", i);
00615 funcChild = xmlNewChild(newFuncTree, NULL, (const xmlChar*)functions[i]->curName, (const xmlChar*)functions[i]->curExpr);
00616 xmlSetProp(funcChild, (const xmlChar*)"id", (const xmlChar*)strVal);
00617 xmlSetProp(funcChild, (const xmlChar*)"x", (const xmlChar*)functions[i]->curX);
00618 xmlSetProp(funcChild, (const xmlChar*)"y", (const xmlChar*)functions[i]->curY);
00619 xmlSetProp(funcChild, (const xmlChar*)"z", (const xmlChar*)functions[i]->curZ);
00620 xmlSetProp(funcChild, (const xmlChar*)"latex", (const xmlChar*)functions[i]->curLatex);
00621 }
00622
00623 snprintf(strVal, 30, "%d", funcCount);
00624 xmlSetProp(newFuncTree, (const xmlChar*)"count", (const xmlChar*)strVal);
00625
00626 xmlReplaceNode(oldFuncTree, newFuncTree);
00627 xmlFreeNode(oldFuncTree);
00628 }
00629
00630 void Configuration::WriteLattice(xmlNodePtr oldLatticeTree)
00631 {
00632 xmlNodePtr newLatticeTree;
00633 xmlNodePtr atomChild, defectChild;
00634 char str[10];
00635
00636 newLatticeTree = xmlNewNode(NULL, (const xmlChar*)"Lattice");
00637 atomChild = xmlNewChild(newLatticeTree, NULL, (const xmlChar*)"Atom", NULL);
00638 snprintf(str, 10, "%d", atomShape);
00639 xmlSetProp(atomChild, (const xmlChar*)"shape", (const xmlChar*)str);
00640 snprintf(str, 10, "%f", atomSize);
00641 xmlSetProp(atomChild, (const xmlChar*)"size", (const xmlChar*)str);
00642 snprintf(str, 10, "%d", atomColor);
00643 xmlSetProp(atomChild, (const xmlChar*)"color", (const xmlChar*)str);
00644 defectChild = xmlNewChild(newLatticeTree, NULL, (const xmlChar*)"Defect", NULL);
00645 snprintf(str, 10, "%d", defectShape);
00646 xmlSetProp(defectChild, (const xmlChar*)"shape", (const xmlChar*)str);
00647 snprintf(str, 10, "%f", defectSize);
00648 xmlSetProp(defectChild, (const xmlChar*)"size", (const xmlChar*)str);
00649 snprintf(str, 10, "%d", defectColor);
00650 xmlSetProp(defectChild, (const xmlChar*)"color", (const xmlChar*)str);
00651 snprintf(str, 10, "%d", insNum);
00652 xmlSetProp(defectChild, (const xmlChar*)"insert", (const xmlChar*)str);
00653 snprintf(str, 10, "%d", remNum);
00654 xmlSetProp(defectChild, (const xmlChar*)"remove", (const xmlChar*)str);
00655
00656 xmlReplaceNode(oldLatticeTree, newLatticeTree);
00657 xmlFreeNode(oldLatticeTree);
00658 }
00659
00660 void Configuration::WriteMonteCarlo(xmlNodePtr oldMCTree)
00661 {
00662 xmlNodePtr newMCTree, algChild, visChild;
00663 char str[32];
00664
00665 newMCTree = xmlNewNode(NULL, (const xmlChar*)"MonteCarlo");
00666 algChild = xmlNewChild(newMCTree, NULL, (const xmlChar*)"Algorithm", NULL);
00667 snprintf(str, 32, "%f", k);
00668 xmlSetProp(algChild, (const xmlChar*)"k", (const xmlChar*)str);
00669 snprintf(str, 32, "%f", T);
00670 xmlSetProp(algChild, (const xmlChar*)"T", (const xmlChar*)str);
00671 snprintf(str, 32, "%f", Tmin);
00672 xmlSetProp(algChild, (const xmlChar*)"Tmin", (const xmlChar*)str);
00673 snprintf(str, 32, "%f", Tmax),
00674 xmlSetProp(algChild, (const xmlChar*)"Tmax", (const xmlChar*)str);
00675 snprintf(str, 32, "%f", intLimit);
00676 xmlSetProp(algChild, (const xmlChar*)"IntLimit", (const xmlChar*)str);
00677 visChild = xmlNewChild(newMCTree, NULL, (const xmlChar*)"Visualization", NULL);
00678 if (bUpdateCanvas)
00679 xmlSetProp(visChild, (const xmlChar*)"UpdateCanvas", (const xmlChar*)"1");
00680 else
00681 xmlSetProp(visChild, (const xmlChar*)"UpdateCanvas", (const xmlChar*)"0");
00682 snprintf(str, 32, "%d", updateInt);
00683 xmlSetProp(visChild, (const xmlChar*)"UpdateInt", (const xmlChar*)str);
00684 if (bAutoSave)
00685 xmlSetProp(visChild, (const xmlChar*)"AutoSave", (const xmlChar*)"1");
00686 else
00687 xmlSetProp(visChild, (const xmlChar*)"AutoSave", (const xmlChar*)"0");
00688 xmlSetProp(visChild, (const xmlChar*)"ImgPath", (const xmlChar*)imgPath);
00689 xmlSetProp(visChild, (const xmlChar*)"ImgPrefix", (const xmlChar*)imgPrefix);
00690 snprintf(str, 32, "%d", imgFormat);
00691 xmlSetProp(visChild, (const xmlChar*)"ImgFormat", (const xmlChar*)str);
00692 snprintf(str, 32, "%d", saveInt);
00693 xmlSetProp(visChild, (const xmlChar*)"SaveInt", (const xmlChar*)str);
00694
00695 xmlReplaceNode(oldMCTree, newMCTree);
00696 xmlFreeNode(oldMCTree);
00697 }
00698
00699 xmlNodePtr Configuration::GetConfigNode(char* name)
00700 {
00701 xmlNodePtr cur;
00702
00703 cur = xmlDocGetRootElement(xmlDoc);
00704 if (cur == NULL) {
00705 cerr << "Empty configuration file!" << endl;
00706 return NULL;
00707 }
00708
00709 if (xmlStrcmp(cur->name, (const xmlChar *) "XEIS")) {
00710 fprintf(stderr,"document of the wrong type, root node != XEIS");
00711 return NULL;
00712 }
00713
00714 cur = cur->xmlChildrenNode;
00715
00716 while (xmlStrcmp (cur->name, (const xmlChar*)name) && cur != NULL) {
00717
00718 if (cur->xmlChildrenNode != NULL)
00719 cur = cur->xmlChildrenNode;
00720 else if (cur->next != NULL)
00721 cur = cur->next;
00722 else {
00723 cur = cur->parent;
00724 while (cur != NULL && cur->next == NULL)
00725 cur = cur->parent;
00726 cur = cur->next;
00727 }
00728 }
00729
00730 return cur;
00731 }