Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
744548bb
Commit
744548bb
authored
9 years ago
by
James Willis
Browse files
Options
Downloads
Patches
Plain Diff
Renamed functions according to SWIFT coding standards.
parent
f4c2e5e5
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!129
Parameter file
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/parser.c
+11
-11
11 additions, 11 deletions
src/parser.c
src/parser.h
+8
-7
8 additions, 7 deletions
src/parser.h
src/testParser.c
+6
-6
6 additions, 6 deletions
src/testParser.c
with
25 additions
and
24 deletions
src/parser.c
+
11
−
11
View file @
744548bb
...
...
@@ -24,7 +24,7 @@
#include
<stdlib.h>
#include
"error.h"
void
parse
F
ile
(
const
char
*
file_name
,
struct
swift_params
*
params
)
{
void
parse
r_read_f
ile
(
const
char
*
file_name
,
struct
swift_params
*
params
)
{
FILE
*
fp
;
...
...
@@ -39,13 +39,13 @@ void parseFile(const char *file_name, struct swift_params *params) {
/* Read until the end of the file is reached.*/
while
(
!
feof
(
fp
))
{
read
P
aram
eter
(
fp
,
params
);
read
_p
aram
(
fp
,
params
);
}
fclose
(
fp
);
}
static
int
count
C
har
(
char
*
str
,
char
val
)
{
static
int
count
_c
har
(
char
*
str
,
char
val
)
{
int
i
,
count
=
0
;
...
...
@@ -59,7 +59,7 @@ static int countChar(char *str, char val) {
return
count
;
}
static
void
read
P
aram
eter
(
FILE
*
fp
,
struct
swift_params
*
params
)
{
static
void
read
_p
aram
(
FILE
*
fp
,
struct
swift_params
*
params
)
{
char
line
[
MAX_LINE_SIZE
];
char
trim_line
[
MAX_LINE_SIZE
];
...
...
@@ -73,14 +73,14 @@ static void readParameter(FILE *fp, struct swift_params *params) {
strcpy
(
trim_line
,
token
);
/* 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. */
if
(
count
C
har
(
trim_line
,
VALUE
)
>
1
)
{
if
(
count
_c
har
(
trim_line
,
':'
)
>
1
)
{
error
(
"Found more than one parameter in '%s', only one allowed."
,
line
);
}
else
{
/*Take first token as the parameter name. */
token
=
strtok
(
trim_line
,
VALUE
);
token
=
strtok
(
trim_line
,
":"
);
strcpy
(
params
->
data
[
params
->
count
].
name
,
token
);
/*Take second token as the parameter value. */
...
...
@@ -91,7 +91,7 @@ static void readParameter(FILE *fp, struct swift_params *params) {
}
}
void
get
P
aram
I
nt
(
struct
swift_params
*
params
,
char
*
name
,
int
*
retParam
)
{
void
parser_
get
_p
aram
_i
nt
(
struct
swift_params
*
params
,
char
*
name
,
int
*
retParam
)
{
int
i
;
...
...
@@ -122,7 +122,7 @@ void getParamInt(struct swift_params *params, char * name, int * retParam) {
}
}
void
get
P
aram
F
loat
(
struct
swift_params
*
params
,
char
*
name
,
float
*
retParam
)
{
void
parser_
get
_p
aram
_f
loat
(
struct
swift_params
*
params
,
char
*
name
,
float
*
retParam
)
{
int
i
;
...
...
@@ -136,7 +136,7 @@ void getParamFloat(struct swift_params *params, char * name, float * retParam) {
}
}
void
get
P
aram
S
tring
(
struct
swift_params
*
params
,
char
*
name
,
char
*
retParam
)
{
void
parser_
get
_p
aram
_s
tring
(
struct
swift_params
*
params
,
char
*
name
,
char
*
retParam
)
{
int
i
;
...
...
@@ -150,7 +150,7 @@ void getParamString(struct swift_params *params, char * name, char * retParam) {
}
}
void
print
P
aram
eter
s
(
struct
swift_params
*
params
)
{
void
parser_
print
_p
arams
(
struct
swift_params
*
params
)
{
int
i
;
...
...
This diff is collapsed.
Click to expand it.
src/parser.h
+
8
−
7
View file @
744548bb
...
...
@@ -26,7 +26,7 @@
#define MAX_NO_OF_PARAMS 512
#define COMMENT "#"
#define VALUE
char ":"
#define VALUE
':'
#define END_OF_FILE "..."
struct
parameter
{
...
...
@@ -40,13 +40,14 @@ struct swift_params {
};
/* Public API. */
void
parse
F
ile
(
const
char
*
file_name
,
struct
swift_params
*
params
);
void
print
P
aram
eter
s
(
struct
swift_params
*
params
);
void
get
P
aram
I
nt
(
struct
swift_params
*
params
,
char
*
name
,
int
*
retParam
);
void
get
P
aram
F
loat
(
struct
swift_params
*
params
,
char
*
name
,
float
*
retParam
);
void
get
P
aram
S
tring
(
struct
swift_params
*
params
,
char
*
name
,
char
*
retParam
);
void
parse
r_read_f
ile
(
const
char
*
file_name
,
struct
swift_params
*
params
);
void
parser_
print
_p
arams
(
struct
swift_params
*
params
);
void
parser_
get
_p
aram
_i
nt
(
struct
swift_params
*
params
,
char
*
name
,
int
*
retParam
);
void
parser_
get
_p
aram
_f
loat
(
struct
swift_params
*
params
,
char
*
name
,
float
*
retParam
);
void
parser_
get
_p
aram
_s
tring
(
struct
swift_params
*
params
,
char
*
name
,
char
*
retParam
);
/* 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 */
This diff is collapsed.
Click to expand it.
src/testParser.c
+
6
−
6
View file @
744548bb
...
...
@@ -9,14 +9,14 @@ int main(int argc, char *argv[]) {
float
max_h
=
0
.
0
f
;
char
ic_file
[
MAX_LINE_SIZE
];
parse
F
ile
(
input_file
,
&
param_file
);
parse
r_read_f
ile
(
input_file
,
&
param_file
);
print
P
aram
eter
s
(
&
param_file
);
parser_
print
_p
arams
(
&
param_file
);
get
P
aram
I
nt
(
&
param_file
,
"no_of_threads"
,
&
no_of_threads
);
get
P
aram
I
nt
(
&
param_file
,
"no_of_time_steps"
,
&
no_of_time_steps
);
get
P
aram
F
loat
(
&
param_file
,
"max_h"
,
&
max_h
);
get
P
aram
S
tring
(
&
param_file
,
"ic_file"
,
ic_file
);
parser_
get
_p
aram
_i
nt
(
&
param_file
,
"no_of_threads"
,
&
no_of_threads
);
parser_
get
_p
aram
_i
nt
(
&
param_file
,
"no_of_time_steps"
,
&
no_of_time_steps
);
parser_
get
_p
aram
_f
loat
(
&
param_file
,
"max_h"
,
&
max_h
);
parser_
get
_p
aram
_s
tring
(
&
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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment