ecl_type.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Equinor ASA, Norway.
3
4 The file 'ecl_type.h' is part of ERT - Ensemble based Reservoir Tool.
5
6 ERT is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 ERT is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
16 for more details.
17*/
18
19#ifndef ERT_ECL_TYPE_H
20#define ERT_ECL_TYPE_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#include <stdlib.h>
27#include <stdbool.h>
28
29/*
30 The type of an eclipse keyword is carried by a struct
31 ecl_type_struct which contains a type enum, and the size in bytes of
32 one such element. These structs are for the most part handled with
33 value semantics, and created with macros ECL_INT, ECL_FLOAT and so
34 on.
35
36 The macros in C use designated initializers, whereas the C++ macros
37 use a constructor, for this reason this file has two slightly
38 different code paths for C and C++.
39*/
40
41#define ECL_STRING8_LENGTH 8
42#define ECL_TYPE_LENGTH 4
43
44typedef enum {
53
54#define ECL_TYPE_ENUM_DEFS {.value = 0 , .name = "ECL_CHAR_TYPE"}, \
55{.value = 1 , .name = "ECL_FLOAT_TYPE"} , \
56{.value = 2 , .name = "ECL_DOUBLE_TYPE"}, \
57{.value = 3 , .name = "ECL_INT_TYPE"}, \
58{.value = 4 , .name = "ECL_BOOL_TYPE"}, \
59{.value = 5 , .name = "ECL_MESS_TYPE"}, \
60{.value = 7 , .name = "ECL_STRING_TYPE"}
61
62
63/*
64 Character data in ECLIPSE files comes as an array of fixed-length
65 string. Each of these strings is 8 characters long. The type name,
66 i.e. 'REAL', 'INTE', ... , come as 4 character strings.
67*/
68
69#define ECL_STRING8_LENGTH 8 // 'Normal' 8 characters 'CHAR' type.
70#define ECL_TYPE_LENGTH 4
71
74 const size_t element_size;
75};
76
77#ifdef __cplusplus
78
79#define ECL_INT ecl_data_type{ ECL_INT_TYPE, sizeof(int)}
80#define ECL_FLOAT ecl_data_type{ ECL_FLOAT_TYPE, sizeof(float)}
81#define ECL_DOUBLE ecl_data_type{ ECL_DOUBLE_TYPE, sizeof(double)}
82#define ECL_BOOL ecl_data_type{ ECL_BOOL_TYPE, sizeof(bool)}
83#define ECL_CHAR ecl_data_type{ ECL_CHAR_TYPE, ECL_STRING8_LENGTH + 1}
84#define ECL_MESS ecl_data_type{ ECL_MESS_TYPE, 0}
85#define ECL_STRING(size) ecl_data_type{ECL_STRING_TYPE, (size) + 1}
86
87}
88
89#else
90
91#define ECL_CHAR (ecl_data_type) {.type = ECL_CHAR_TYPE, .element_size = ECL_STRING8_LENGTH + 1}
92#define ECL_INT (ecl_data_type) {.type = ECL_INT_TYPE, .element_size = sizeof(int)}
93#define ECL_FLOAT (ecl_data_type) {.type = ECL_FLOAT_TYPE, .element_size = sizeof(float)}
94#define ECL_DOUBLE (ecl_data_type) {.type = ECL_DOUBLE_TYPE, .element_size = sizeof(double)}
95#define ECL_BOOL (ecl_data_type) {.type = ECL_BOOL_TYPE, .element_size = sizeof(bool)}
96#define ECL_MESS (ecl_data_type) {.type = ECL_MESS_TYPE, .element_size = 0}
97#define ECL_STRING(size) (ecl_data_type) {.type = ECL_STRING_TYPE, .element_size = (size) + 1}
98
99#endif
100
101#ifdef __cplusplus
102extern "C" {
103#endif
104
106
110
113
116
118
128
129// Temporary fixup for OPM.
131
132#ifdef __cplusplus
133}
134#endif
135
136
137#endif
bool ecl_type_is_equal(const ecl_data_type, const ecl_data_type)
bool ecl_type_is_char(const ecl_data_type)
char * ecl_type_alloc_name(const ecl_data_type)
bool ecl_type_is_mess(const ecl_data_type)
ecl_data_type ecl_type_create_from_name(const char *)
bool ecl_type_is_int(const ecl_data_type)
bool ecl_type_is_bool(const ecl_data_type)
bool ecl_type_is_string(const ecl_data_type)
ecl_data_type ecl_type_create(const ecl_type_enum, const size_t)
bool ecl_type_is_alpha(const ecl_data_type)
bool ecl_type_is_double(const ecl_data_type)
ecl_type_enum ecl_type_get_type(const ecl_data_type)
bool ecl_type_is_numeric(const ecl_data_type)
int ecl_type_get_sizeof_ctype(const ecl_data_type)
int ecl_type_get_sizeof_iotype(const ecl_data_type)
ecl_type_enum
Definition: ecl_type.hpp:44
@ ECL_FLOAT_TYPE
Definition: ecl_type.hpp:46
@ ECL_INT_TYPE
Definition: ecl_type.hpp:48
@ ECL_STRING_TYPE
Definition: ecl_type.hpp:51
@ ECL_MESS_TYPE
Definition: ecl_type.hpp:50
@ ECL_CHAR_TYPE
Definition: ecl_type.hpp:45
@ ECL_BOOL_TYPE
Definition: ecl_type.hpp:49
@ ECL_DOUBLE_TYPE
Definition: ecl_type.hpp:47
bool ecl_type_is_float(const ecl_data_type)
char * ecl_type_get_name(const ecl_data_type)
ecl_data_type ecl_type_create_from_type(const ecl_type_enum)
Definition: ecl_type.hpp:72
const size_t element_size
Definition: ecl_type.hpp:74
const ecl_type_enum type
Definition: ecl_type.hpp:73