Skip to content
Snippets Groups Projects
Commit 744548bb authored by James Willis's avatar James Willis
Browse files

Renamed functions according to SWIFT coding standards.

parent f4c2e5e5
No related branches found
No related tags found
1 merge request!129Parameter file
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "error.h" #include "error.h"
void parseFile(const char *file_name, struct swift_params *params) { void parser_read_file(const char *file_name, struct swift_params *params) {
FILE *fp; FILE *fp;
...@@ -39,13 +39,13 @@ void parseFile(const char *file_name, struct swift_params *params) { ...@@ -39,13 +39,13 @@ void parseFile(const char *file_name, struct swift_params *params) {
/* Read until the end of the file is reached.*/ /* Read until the end of the file is reached.*/
while(!feof(fp)) { while(!feof(fp)) {
readParameter(fp,params); read_param(fp,params);
} }
fclose(fp); fclose(fp);
} }
static int countChar(char *str, char val) { static int count_char(char *str, char val) {
int i, count = 0; int i, count = 0;
...@@ -59,7 +59,7 @@ static int countChar(char *str, char val) { ...@@ -59,7 +59,7 @@ static int countChar(char *str, char val) {
return count; return count;
} }
static void readParameter(FILE *fp, struct swift_params *params) { static void read_param(FILE *fp, struct swift_params *params) {
char line [MAX_LINE_SIZE]; char line [MAX_LINE_SIZE];
char trim_line [MAX_LINE_SIZE]; char trim_line [MAX_LINE_SIZE];
...@@ -73,14 +73,14 @@ static void readParameter(FILE *fp, struct swift_params *params) { ...@@ -73,14 +73,14 @@ static void readParameter(FILE *fp, struct swift_params *params) {
strcpy(trim_line,token); strcpy(trim_line,token);
/* Check if the line contains a value */ /* Check if the line contains a value */
if(strchr(trim_line,VALUE)) { if(strchr(trim_line,':')) {
/* Check for more than one parameter on the same line. */ /* Check for more than one parameter on the same line. */
if(countChar(trim_line,VALUE) > 1) { if(count_char(trim_line,':') > 1) {
error("Found more than one parameter in '%s', only one allowed.",line); error("Found more than one parameter in '%s', only one allowed.",line);
} }
else { else {
/*Take first token as the parameter name. */ /*Take first token as the parameter name. */
token = strtok(trim_line,VALUE); token = strtok(trim_line,":");
strcpy(params->data[params->count].name,token); strcpy(params->data[params->count].name,token);
/*Take second token as the parameter value. */ /*Take second token as the parameter value. */
...@@ -91,7 +91,7 @@ static void readParameter(FILE *fp, struct swift_params *params) { ...@@ -91,7 +91,7 @@ static void readParameter(FILE *fp, struct swift_params *params) {
} }
} }
void getParamInt(struct swift_params *params, char * name, int * retParam) { void parser_get_param_int(struct swift_params *params, char * name, int * retParam) {
int i; int i;
...@@ -122,7 +122,7 @@ void getParamInt(struct swift_params *params, char * name, int * retParam) { ...@@ -122,7 +122,7 @@ void getParamInt(struct swift_params *params, char * name, int * retParam) {
} }
} }
void getParamFloat(struct swift_params *params, char * name, float * retParam) { void parser_get_param_float(struct swift_params *params, char * name, float * retParam) {
int i; int i;
...@@ -136,7 +136,7 @@ void getParamFloat(struct swift_params *params, char * name, float * retParam) { ...@@ -136,7 +136,7 @@ void getParamFloat(struct swift_params *params, char * name, float * retParam) {
} }
} }
void getParamString(struct swift_params *params, char * name, char * retParam) { void parser_get_param_string(struct swift_params *params, char * name, char * retParam) {
int i; int i;
...@@ -150,7 +150,7 @@ void getParamString(struct swift_params *params, char * name, char * retParam) { ...@@ -150,7 +150,7 @@ void getParamString(struct swift_params *params, char * name, char * retParam) {
} }
} }
void printParameters(struct swift_params *params) { void parser_print_params(struct swift_params *params) {
int i; int i;
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#define MAX_NO_OF_PARAMS 512 #define MAX_NO_OF_PARAMS 512
#define COMMENT "#" #define COMMENT "#"
#define VALUE char ":" #define VALUE ':'
#define END_OF_FILE "..." #define END_OF_FILE "..."
struct parameter { struct parameter {
...@@ -40,13 +40,14 @@ struct swift_params { ...@@ -40,13 +40,14 @@ struct swift_params {
}; };
/* Public API. */ /* Public API. */
void parseFile(const char *file_name, struct swift_params *params); void parser_read_file(const char *file_name, struct swift_params *params);
void printParameters(struct swift_params *params); void parser_print_params(struct swift_params *params);
void getParamInt(struct swift_params *params, char *name, int *retParam); void parser_get_param_int(struct swift_params *params, char *name, int *retParam);
void getParamFloat(struct swift_params *params, char *name, float *retParam); void parser_get_param_float(struct swift_params *params, char *name, float *retParam);
void getParamString(struct swift_params *params, char *name, char *retParam); void parser_get_param_string(struct swift_params *params, char *name, char *retParam);
/* Private functions. */ /* Private functions. */
static void readParameter(FILE *fp, struct swift_params *params); static void read_param(FILE *fp, struct swift_params *params);
static int count_char(char *str, char val);
#endif /* SWIFT_PARSER_H */ #endif /* SWIFT_PARSER_H */
...@@ -9,14 +9,14 @@ int main(int argc, char *argv[]) { ...@@ -9,14 +9,14 @@ int main(int argc, char *argv[]) {
float max_h = 0.0f; float max_h = 0.0f;
char ic_file [MAX_LINE_SIZE]; char ic_file [MAX_LINE_SIZE];
parseFile(input_file,&param_file); parser_read_file(input_file,&param_file);
printParameters(&param_file); parser_print_params(&param_file);
getParamInt(&param_file,"no_of_threads",&no_of_threads); parser_get_param_int(&param_file,"no_of_threads",&no_of_threads);
getParamInt(&param_file,"no_of_time_steps",&no_of_time_steps); parser_get_param_int(&param_file,"no_of_time_steps",&no_of_time_steps);
getParamFloat(&param_file,"max_h",&max_h); parser_get_param_float(&param_file,"max_h",&max_h);
getParamString(&param_file,"ic_file",ic_file); parser_get_param_string(&param_file,"ic_file",ic_file);
printf("no_of_threads: %d, no_of_time_steps: %d, max_h: %f, ic_file: %s\n",no_of_threads, no_of_time_steps, max_h, ic_file); printf("no_of_threads: %d, no_of_time_steps: %d, max_h: %f, ic_file: %s\n",no_of_threads, no_of_time_steps, max_h, ic_file);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment