VAPOR3 3.9.4
converter.h
Go to the documentation of this file.
1/*
2 * Copyright 2008, 2009 University Corporation for Atmospheric Research
3 *
4 * This file is part of the UDUNITS-2 package. See the file LICENSE
5 * in the top-level source-directory of the package for copying and
6 * redistribution conditions.
7 */
8/*
9 * Public header-file for the Unidata units(3) library.
10 */
11
12#ifndef CV_CONVERTER_H_INCLUDED
13#define CV_CONVERTER_H_INCLUDED
14
15#include <stddef.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#include "udunits2.h"
23
24/*
25 * Returns the trivial converter (i.e., y = x).
26 * When finished with the converter, the client should pass the converter to
27 * cv_free().
28 * RETURNS:
29 * The trivial converter.
30 */
31UDUNITS2_API cv_converter *cv_get_trivial(void);
32
33/*
34 * Returns the reciprocal converter (i.e., y = 1/x).
35 * When finished with the converter, the client should pass the converter to
36 * cv_free().
37 * RETURNS:
38 * The reciprocal converter.
39 */
40UDUNITS2_API cv_converter *cv_get_inverse(void);
41
42/*
43 * Returns a scaling converter (i.e., y = ax).
44 * When finished with the converter, the client should pass the converter to
45 * cv_free().
46 * RETURNS:
47 * The scaling converter.
48 */
49UDUNITS2_API cv_converter *cv_get_scale(const double slope);
50
51/*
52 * Returns a converter that adds a number to values (i.e., y = x + b).
53 * When finished with the converter, the client should pass the converter to
54 * cv_free().
55 * ARGUMENTS:
56 * intercept The number to be added.
57 * RETURNS:
58 * NULL Necessary memory couldn't be allocated.
59 * else A converter that adds the given number to values.
60 */
61UDUNITS2_API cv_converter *cv_get_offset(const double intercept);
62
63/*
64 * Returns a Galilean converter (i.e., y = ax + b).
65 * When finished with the converter, the client should pass the converter to
66 * cv_free().
67 * ARGUMENTS:
68 * slope The number by which to multiply values.
69 * intercept The number to be added.
70 * RETURNS:
71 * NULL Necessary memory couldn't be allocated.
72 * else A Galilean converter corresponding to the inputs.
73 */
74UDUNITS2_API cv_converter *cv_get_galilean(const double slope, const double intercept);
75
76/*
77 * Returns a logarithmic converter (i.e., y = log(x) in some base).
78 * When finished with the converter, the client should pass the converter to
79 * cv_free().
80 * ARGUMENTS:
81 * base The logarithmic base (e.g., 2, M_E, 10). Must be
82 * greater than one.
83 * RETURNS:
84 * NULL "base" is not greater than one or necessary
85 * memory couldn't be allocated.
86 * else A logarithmic converter corresponding to the inputs.
87 */
88UDUNITS2_API cv_converter *cv_get_log(const double base);
89
90/*
91 * Returns an exponential converter (i.e., y = pow(b, x) in some base "b").
92 * When finished with the converter, the client should pass the converter to
93 * cv_free().
94 *
95 * Arguments:
96 * base The desired base. Must be positive.
97 * Returns:
98 * NULL "base" is invalid or necessary memory couldn't be
99 * allocated.
100 * else An exponential converter corresponding to the inputs.
101 */
102UDUNITS2_API cv_converter *cv_get_pow(const double base);
103
104/*
105 * Returns a converter corresponding to the sequential application of two
106 * other converters.
107 * ARGUMENTS:
108 * first The converter to be applied first.
109 * second The converter to be applied second.
110 * RETURNS:
111 * NULL Either "first" or "second" is NULL or necessary memory couldn't
112 * be allocated.
113 * else A converter corresponding to the sequential application of the
114 * given converters. If one of the input converters is the trivial
115 * converter, then the returned converter will be the other input
116 * converter.
117 */
118UDUNITS2_API cv_converter *cv_combine(cv_converter *const first, cv_converter *const second);
119
120/*
121 * Frees resources associated with a converter.
122 * ARGUMENTS:
123 * conv The converter to have its resources freed or NULL.
124 */
125UDUNITS2_API void cv_free(cv_converter *const conv);
126
127/*
128 * Converts a float.
129 * ARGUMENTS:
130 * converter The converter.
131 * value The value to be converted.
132 * RETURNS:
133 * The converted value.
134 */
135UDUNITS2_API float cv_convert_float(const cv_converter *converter, const float value);
136
137/*
138 * Converts a double.
139 * ARGUMENTS:
140 * converter The converter.
141 * value The value to be converted.
142 * RETURNS:
143 * The converted value.
144 */
145UDUNITS2_API double cv_convert_double(const cv_converter *converter, const double value);
146
147/*
148 * Converts an array of floats.
149 * ARGUMENTS:
150 * converter The converter.
151 * in The values to be converted.
152 * count The number of values to be converted.
153 * out The output array for the converted values. May
154 * be the same array as "in" or overlap it.
155 * RETURNS:
156 * NULL "out" is NULL.
157 * else A pointer to the output array.
158 */
159UDUNITS2_API float *cv_convert_floats(const cv_converter *converter, const float *const in, const size_t count, float *out);
160
161/*
162 * Converts an array of doubles.
163 * ARGUMENTS:
164 * converter The converter.
165 * in The values to be converted.
166 * count The number of values to be converted.
167 * out The output array for the converted values. May
168 * be the same array as "in" or overlap it.
169 * RETURNS:
170 * NULL "out" is NULL.
171 * else A pointer to the output array.
172 */
173UDUNITS2_API double *cv_convert_doubles(const cv_converter *converter, const double *const in, const size_t count, double *out);
174
175/*
176 * Returns a string representation of a converter.
177 * ARGUMENTS:
178 * conv The converter.
179 * buf The buffer into which to write the expression.
180 * max The size of the buffer.
181 * variable The string to be used as the input value for the
182 * converter.
183 * RETURNS
184 * <0 An error was encountered.
185 * else The number of bytes formatted excluding the terminating null.
186 */
187UDUNITS2_API int cv_get_expression(const cv_converter *const conv, char *const buf, size_t max, const char *const variable);
188
189#ifdef __cplusplus
190}
191#endif
192
193#endif
UDUNITS2_API int cv_get_expression(const cv_converter *const conv, char *const buf, size_t max, const char *const variable)
UDUNITS2_API float cv_convert_float(const cv_converter *converter, const float value)
UDUNITS2_API cv_converter * cv_get_log(const double base)
UDUNITS2_API float * cv_convert_floats(const cv_converter *converter, const float *const in, const size_t count, float *out)
union cv_converter cv_converter
Definition: converter.h:22
UDUNITS2_API cv_converter * cv_get_scale(const double slope)
UDUNITS2_API cv_converter * cv_get_offset(const double intercept)
UDUNITS2_API cv_converter * cv_get_galilean(const double slope, const double intercept)
UDUNITS2_API cv_converter * cv_get_trivial(void)
UDUNITS2_API cv_converter * cv_get_pow(const double base)
UDUNITS2_API void cv_free(cv_converter *const conv)
UDUNITS2_API double cv_convert_double(const cv_converter *converter, const double value)
UDUNITS2_API cv_converter * cv_get_inverse(void)
UDUNITS2_API cv_converter * cv_combine(cv_converter *const first, cv_converter *const second)
UDUNITS2_API double * cv_convert_doubles(const cv_converter *converter, const double *const in, const size_t count, double *out)