MC Electron Programmgerüst

This commit is contained in:
2018-09-13 11:10:13 +02:00
parent 7497e67537
commit bd62f5c66f
2 changed files with 118 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
#ifndef PARAMETER_H
#define PARAMETER_H
#include <vector>
using namespace blitz;
using namespace std;
class Parameter
{
public:
virtual ~Parameter(){};
Parameter()
{
beschissenegrosseganzzahl = (int)value("beschissenegrosseganzzahl");
totalparticles = value("totalparticles");
dt = value("dt");
}
double value(char *str, char* ext = "cat")
{
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:
long int totalparticles;
double dt;
};
#endif