Added sequential version
This commit is contained in:
58
config/config.c
Normal file
58
config/config.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct configuration {
|
||||
int n;
|
||||
double north;
|
||||
double east;
|
||||
double south;
|
||||
double west;
|
||||
double init_value;
|
||||
double threshold;
|
||||
} configuration;
|
||||
|
||||
int load_config(configuration *config) {
|
||||
char property[100];
|
||||
char *value;
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen("jacobi.conf", "r");
|
||||
if (fp == NULL) {
|
||||
perror("Error opening file jacobi.conf");
|
||||
return 1;
|
||||
}
|
||||
while (fgets(property, 100, fp) != NULL) {
|
||||
if (property[0] == '\n' || property[0] == '#') {
|
||||
/* Skip empty lines and comments */
|
||||
continue;
|
||||
}
|
||||
value = strchr(property, ' ');
|
||||
if (value == NULL) {
|
||||
fclose(fp);
|
||||
perror("Error reading file jacobi.conf");
|
||||
return 1;
|
||||
}
|
||||
value[0] = '\0';
|
||||
value += sizeof(char);
|
||||
value[strlen(value) - 1] = '\0';
|
||||
if (strcmp(property, "N") == 0) {
|
||||
sscanf(value, "%d", &(config->n));
|
||||
} else if (strcmp(property, "NORTH") == 0) {
|
||||
sscanf(value, "%lf", &(config->north));
|
||||
} else if (strcmp(property, "EAST") == 0) {
|
||||
sscanf(value, "%lf", &(config->east));
|
||||
} else if (strcmp(property, "SOUTH") == 0) {
|
||||
sscanf(value, "%lf", &(config->south));
|
||||
} else if (strcmp(property, "WEST") == 0) {
|
||||
sscanf(value, "%lf", &(config->west));
|
||||
} else if (strcmp(property, "INIT_VALUE") == 0) {
|
||||
sscanf(value, "%lf", &(config->init_value));
|
||||
} else if (strcmp(property, "THRESHOLD") == 0) {
|
||||
sscanf(value, "%lf", &(config->threshold));
|
||||
} else {
|
||||
printf("Unknown property %s\n", property);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
11
config/config.h
Normal file
11
config/config.h
Normal file
@@ -0,0 +1,11 @@
|
||||
typedef struct configuration {
|
||||
int n;
|
||||
double north;
|
||||
double east;
|
||||
double south;
|
||||
double west;
|
||||
double init_value;
|
||||
double threshold;
|
||||
} configuration;
|
||||
|
||||
int load_config(configuration *config);
|
||||
Reference in New Issue
Block a user