elpa_index.h 5.44 KB
Newer Older
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <search.h>
#include <elpa/elpa.h>

#define nelements(x) (sizeof(x)/sizeof(x[0]))

/* A simple structure for storing values to a pre-set
 * number of keys */

/* Forward declaration of configuration structure */
typedef struct elpa_index_struct* elpa_index_t;

16
17
/* Function type for the cardinality */
typedef int (*elpa_index_cardinality_t)(elpa_index_t index, int n);
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
18

19
20
21
22
23
24
25
26
/* Function type to enumerate all possible values (if possible) */
typedef int (*elpa_index_enumerate_int_option_t)(elpa_index_t index, int n, unsigned int i);

/* Function type to check the validity of a value */
typedef int (*elpa_index_valid_int_t)(elpa_index_t index, int n, int new_value);

/* Function type to give a string representation of a value */
typedef const char* (*elpa_index_repr_int_t)(elpa_index_t index, int n);
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
27
28
29
30
31


typedef struct {
        const char *name;
        int default_value;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
        elpa_index_cardinality_t cardinality;
        elpa_index_enumerate_int_option_t enumerate_option;
        elpa_index_valid_int_t valid;
        elpa_index_repr_int_t repr;

        /* For simple, fixed range options: */
        int fixed_range;
        const char **fixed_range_reprs;

} elpa_index_int_entry_t;

typedef struct {
        const char *name;
        double value;
} elpa_index_double_entry_t;
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
47
48
49
50

struct elpa_index_struct {
        int n_int_entries;
        int *int_values;
51
52
53
54
55
56
57
        int *int_value_is_set;
        elpa_index_int_entry_t *int_entries;

        int n_double_entries;
        double *double_values;
        int *double_value_is_set;
        elpa_index_double_entry_t *double_entries;
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
58
59
};

60
61
62
elpa_index_t elpa_index_allocate(
                int n_int_entries, elpa_index_int_entry_t int_entries[n_int_entries],
                int n_double_entries, elpa_index_double_entry_t double_entries[n_double_entries]);
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
63
64
65

/*
 !f> interface
66
 !f>   subroutine elpa_index_free(index) bind(C, name="elpa_index_free")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
67
68
69
70
71
 !f>     import c_ptr
 !f>     type(c_ptr), value :: index
 !f>   end subroutine
 !f> end interface
 */
72
73
void elpa_index_free(elpa_index_t index);

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
74
75
76

/*
 !f> interface
77
 !f>   function elpa_index_get_int_value(index, name, success) result(value) bind(C, name="elpa_index_get_int_value")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
78
79
80
81
82
83
84
85
 !f>     import c_ptr, c_int, c_char
 !f>     type(c_ptr), value                 :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     integer(kind=c_int)                :: value
 !f>     integer(kind=c_int), optional      :: success
 !f>   end function
 !f> end interface
 */
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
int elpa_index_get_int_value(elpa_index_t index, const char *name, int *success);


/*
 !f> interface
 !f>   function elpa_index_get_int_loc(index, name) result(loc) bind(C, name="elpa_index_get_int_loc")
 !f>     import c_ptr, c_char
 !f>     type(c_ptr), value                 :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     type(c_ptr)                        :: loc
 !f>   end function
 !f> end interface
 */
int* elpa_index_get_int_loc(elpa_index_t index, const char *name);

Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
101
102
103

/*
 !f> interface
104
 !f>   function elpa_index_set_int_value(index, name, value) result(success) bind(C, name="elpa_index_set_int_value")
Lorenz Huedepohl's avatar
Lorenz Huedepohl committed
105
106
107
108
109
110
111
112
 !f>     import c_ptr, c_int, c_char
 !f>     type(c_ptr), value                    :: index
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     integer(kind=c_int),intent(in), value :: value
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
int elpa_index_set_int_value(elpa_index_t index, const char *name, int value);


/*
 !f> interface
 !f>   function elpa_index_int_value_is_set(index, name) result(success) bind(C, name="elpa_index_int_value_is_set")
 !f>     import c_ptr, c_int, c_char
 !f>     type(c_ptr), value                    :: index
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
int elpa_index_int_value_is_set(elpa_index_t index, const char *name);


/*
 !f> interface
 !f>   function elpa_index_get_double_value(index, name, success) result(value) bind(C, name="elpa_index_get_double_value")
 !f>     import c_ptr, c_int, c_double, c_char
 !f>     type(c_ptr), value                 :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     real(kind=c_double)                :: value
 !f>     integer(kind=c_int), optional      :: success
 !f>   end function
 !f> end interface
 */
double elpa_index_get_double_value(elpa_index_t index, const char *name, int *success);


/*
 !f> interface
 !f>   function elpa_index_get_double_loc(index, name) result(loc) bind(C, name="elpa_index_get_double_loc")
 !f>     import c_ptr, c_char
 !f>     type(c_ptr), value                 :: index
 !f>     character(kind=c_char), intent(in) :: name(*)
 !f>     type(c_ptr)                        :: loc
 !f>   end function
 !f> end interface
 */
double* elpa_index_get_double_loc(elpa_index_t index, const char *name);


/*
 !f> interface
 !f>   function elpa_index_set_double_value(index, name, value) result(success) bind(C, name="elpa_index_set_double_value")
 !f>     import c_ptr, c_int, c_double, c_char
 !f>     type(c_ptr), value                    :: index
 !f>     character(kind=c_char), intent(in)    :: name(*)
 !f>     real(kind=c_double),intent(in), value :: value
 !f>     integer(kind=c_int)                   :: success
 !f>   end function
 !f> end interface
 */
int elpa_index_set_double_value(elpa_index_t index, const char *name, double value);