// // parameter.h // // // Created by Christian Reiling on 13.09.18. // #ifndef parameter_h #define parameter_h #include #include using namespace std; using namespace blitz; class Parameter { public: virtual ~Parameter(){}; Parameter() { seed = (int)value("seed"); numTotalParticles = (long int)value("numTotalParticles"); dt = value("dt"); injectionMethod = (int)value("injectionMethod"); deltaKinEnergy = value("deltaKinEnergy"); MBKinEnergy = value("MBKinEnergy"); wgtsMagField = value("wgtsMagField"); wgtsLength = value("wgtsLength"); wgtsDiameter = value("wgtsDiameter"); constPi = value("constPi"); constc = value("constc"); constme = value("constme"); constqe = value("constqe"); } double value(char *str, char* ext = "cat") // Reads Parameter from config file { double temp; char dummy[256]; char fname[256],*pname; FILE *fcat; if (getenv("poub") == NULL) { fprintf(stderr,"Environment variable %s not defined.\n","poub"); exit(1); } strcpy(fname, getenv("poub")); pname = getenv("pname"); if (pname == NULL) { fprintf(stderr,"Environment variable %s not defined.\n","pname"); exit(1); } if (!ext) { ext = "cat"; } sprintf(fname,"%s/%s.%s",getenv("poub"),getenv("pname"), ext); if (!(fcat = fopen(fname, "r"))) { fprintf(stderr,"value: cannot open file %s\n",fname); exit(1); } while (!feof(fcat)) { // fscanf(fcat, "'%s%*[^']'%F%*[^']",dummy,&temp); 1 fscanf(fcat, "%s = %lf", dummy, &temp); // if (strncmp(dummy, str,strlen(str)) == 0) { if (strcmp(dummy, str) == 0) { fclose(fcat); return(temp); } } fclose(fcat); fprintf(stderr,"variable %s not found\n",str); exit(1); return 0; } protected: string configFilePath; //Simulation specs int seed; long int numTotalParticles; double dt; int injectionMethod; double deltaKinEnergy; double MBKinEnergy; //KATRIN Specs double wgtsMagField; double wgtsLength; double wgtsDiameter; // physical constants double constPi; double constc; double constme; double constqe; }; #endif