Minor Changes
This commit is contained in:
@@ -6,4 +6,90 @@
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "parameter.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Parameter::Parameter() {
|
||||
// Simulation Specs
|
||||
seed = (int)getValue("seed");
|
||||
numTotalElectrons = (long int)getValue("numTotalElectrons");
|
||||
dt_s = getValue("dt_s");
|
||||
injectionMethod = (int)getValue("injectionMethod");
|
||||
deltaKinEnergy_eV = getValue("deltaKinEnergy_eV");
|
||||
MBTemp_K = getValue("MBTemp_K");
|
||||
elaOn = (int)getValue("elaOn");
|
||||
ionOn = (int)getValue("ionOn");
|
||||
propagationMethod = (int)getValue("propagationMethod");
|
||||
|
||||
// Cutoff
|
||||
cutoffMode = (int)getValue("cutoffMode");
|
||||
cutoffEnergySet_eV = getValue("cutoffEnergySet_eV");
|
||||
cutoffFactor = getValue("cutoffFactor");
|
||||
|
||||
// Katrin Specs
|
||||
wgtsMagField_T = getValue("wgtsMagField_T");
|
||||
wgtsLength_m = getValue("wgtsLength_m");
|
||||
wgtsRadius_m = getValue("wgtsRadius_m");
|
||||
wgtsT2Density_m3 = getValue("wgtsT2Density_m3");
|
||||
wgtsTemp_K = getValue("wgtsTemp_K");
|
||||
wgtsT2FlowSpeed_ms = getValue("wgtsT2FlowSpeed_ms");
|
||||
|
||||
// Output
|
||||
numberZBins = getValue ("numberZBins");
|
||||
}
|
||||
|
||||
|
||||
double Parameter::getValue(std::string varName) {
|
||||
char* ext = (char*)("cat");
|
||||
char* str = strdup(varName.c_str());
|
||||
double temp;
|
||||
char dummy[256];
|
||||
char fname[256],*parfile;
|
||||
FILE *fcat;
|
||||
|
||||
if (getenv("parpath") == NULL)
|
||||
{
|
||||
throw ("Parameter::value: Environment variable parpath not defined.");
|
||||
}
|
||||
strcpy(fname, getenv("parpath"));
|
||||
parfile = getenv("parfile");
|
||||
if (parfile == NULL)
|
||||
{
|
||||
throw ("Parameter::value: Environment variable parfile not defined.");
|
||||
}
|
||||
if (!ext)
|
||||
{
|
||||
ext = (char*)("cat");
|
||||
}
|
||||
sprintf(fname,"%s/%s.%s",getenv("parpath"),getenv("parfile"), ext);
|
||||
if (!(fcat = fopen(fname, "r")))
|
||||
{
|
||||
stringstream ss;
|
||||
ss<<"Parameter::value: Can not open file " <<fname<<".";
|
||||
throw (ss.str());
|
||||
}
|
||||
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);
|
||||
|
||||
stringstream ss;
|
||||
ss<<"Parameter::value: Variable "<<str<<" not found.";
|
||||
throw (ss.str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user