-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_print_var_names.c
89 lines (63 loc) · 1.77 KB
/
test_print_var_names.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <stdlib.h>
#include <heat.h>
#include <bmi.h>
#include <bmi_heat.h>
void print_var_names (Bmi *model);
int
main (void)
{
Bmi * model = (Bmi*)malloc (sizeof(Bmi));
register_bmi_heat(model);
if (model->initialize(model, NULL) != BMI_SUCCESS || !model)
return BMI_FAILURE;
{
char name[BMI_MAX_COMPONENT_NAME];
model->get_component_name(model, name);
fprintf(stdout, "%s\n\n", name);
}
print_var_names (model);
if (model->finalize(model) != BMI_SUCCESS)
return BMI_FAILURE;
free (model);
return BMI_SUCCESS;
}
void
print_var_names (Bmi *model)
{
{ /* Print the input var names */
int n_names;
char **names = NULL;
int i;
model->get_input_item_count(model, &n_names);
names = (char**) malloc (sizeof(char *) * n_names);
for (i=0; i<n_names; i++)
names[i] = (char*) malloc (sizeof(char) * BMI_MAX_VAR_NAME);
model->get_input_var_names(model, names);
fprintf (stdout, "Input var names\n");
fprintf (stdout, "===============\n");
for (i = 0; i<n_names; i++)
fprintf (stdout, "%s\n", names[i]);
for (i=0; i<n_names; i++)
free (names[i]);
free (names);
}
fprintf (stdout, "\n");
{ /* Print the output var names */
int n_names;
char **names = NULL;
int i;
model->get_output_item_count(model, &n_names);
names = (char**) malloc (sizeof(char *) * n_names);
for (i=0; i<n_names; i++)
names[i] = (char*) malloc (sizeof(char) * BMI_MAX_VAR_NAME);
model->get_output_var_names(model, names);
fprintf (stdout, "Output var names\n");
fprintf (stdout, "================\n");
for (i = 0; i<n_names; i++)
fprintf (stdout, "%s\n", names[i]);
for (i=0; i<n_names; i++)
free (names[i]);
free (names);
}
}