SDDSlib
Loading...
Searching...
No Matches
SDDS_rpn.c File Reference

Implements Reverse Polish Notation (RPN) operations for SDDS datasets. More...

#include "mdb.h"
#include "match_string.h"
#include "SDDS.h"
#include "SDDS_internal.h"
#include "rpn.h"

Go to the source code of this file.

Functions

double SDDS_ConvertLongDoubleToDouble (void *data, int64_t index)
 Converts a long double value to double.
 
double SDDS_ConvertDoubleToDouble (void *data, int64_t index)
 Converts a double value to double (identity function).
 
double SDDS_ConvertFloatToDouble (void *data, int64_t index)
 Converts a float value to double.
 
double SDDS_ConvertLong64ToDouble (void *data, int64_t index)
 Converts a 64-bit integer to double.
 
double SDDS_ConvertULong64ToDouble (void *data, int64_t index)
 Converts an unsigned 64-bit integer to double.
 
double SDDS_ConvertLongToDouble (void *data, int64_t index)
 Converts a 32-bit integer to double.
 
double SDDS_ConvertULongToDouble (void *data, int64_t index)
 Converts an unsigned 32-bit integer to double.
 
double SDDS_ConvertShortToDouble (void *data, int64_t index)
 Converts a short integer to double.
 
double SDDS_ConvertUShortToDouble (void *data, int64_t index)
 Converts an unsigned short integer to double.
 
double SDDS_ConvertStringToDouble (void *data, int64_t index)
 Converts a string to double using atof.
 
double SDDS_ConvertCharToDouble (void *data, int64_t index)
 Converts a character to double.
 
long double SDDS_ConvertToLongDouble (int32_t type, void *data, int64_t index)
 Converts a value to long double based on its type.
 
double SDDS_ConvertToDouble (int32_t type, void *data, int64_t index)
 Converts a value to double based on its type.
 
int64_t SDDS_ConvertToLong64 (int32_t type, void *data, int64_t index)
 Converts a value to a 64-bit integer based on its type.
 
int32_t SDDS_ConvertToLong (int32_t type, void *data, int64_t index)
 Converts a value to a 32-bit integer based on its type.
 
int64_t SDDS_CreateRpnMemory (const char *name, short is_string)
 Stub function for creating RPN memory when RPN_SUPPORT is not enabled.
 
int64_t SDDS_CreateRpnArray (char *name)
 Stub function for creating RPN arrays when RPN_SUPPORT is not enabled.
 

Detailed Description

Implements Reverse Polish Notation (RPN) operations for SDDS datasets.

This file provides functions to convert various data types to double and long double, as well as functions to compute parameters and columns using RPN expressions within SDDS datasets. It also includes functionality to filter rows based on RPN tests.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Authors
M. Borland, C. Saunders, R. Soliday H. Shang

Definition in file SDDS_rpn.c.

Function Documentation

◆ SDDS_ConvertCharToDouble()

double SDDS_ConvertCharToDouble ( void * data,
int64_t index )

Converts a character to double.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 147 of file SDDS_rpn.c.

147 {
148 return *((char *)data + index);
149}

◆ SDDS_ConvertDoubleToDouble()

double SDDS_ConvertDoubleToDouble ( void * data,
int64_t index )

Converts a double value to double (identity function).

Parameters
dataPointer to the data array.
indexIndex of the element.
Returns
The double value.

Definition at line 48 of file SDDS_rpn.c.

48 {
49 return *((double *)data + index);
50}

◆ SDDS_ConvertFloatToDouble()

double SDDS_ConvertFloatToDouble ( void * data,
int64_t index )

Converts a float value to double.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 59 of file SDDS_rpn.c.

59 {
60 return *((float *)data + index);
61}

◆ SDDS_ConvertLong64ToDouble()

double SDDS_ConvertLong64ToDouble ( void * data,
int64_t index )

Converts a 64-bit integer to double.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 70 of file SDDS_rpn.c.

70 {
71 return *((int64_t *)data + index);
72}

◆ SDDS_ConvertLongDoubleToDouble()

double SDDS_ConvertLongDoubleToDouble ( void * data,
int64_t index )

Converts a long double value to double.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 37 of file SDDS_rpn.c.

37 {
38 return *((long double *)data + index);
39}

◆ SDDS_ConvertLongToDouble()

double SDDS_ConvertLongToDouble ( void * data,
int64_t index )

Converts a 32-bit integer to double.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 92 of file SDDS_rpn.c.

92 {
93 return *((int32_t *)data + index);
94}

◆ SDDS_ConvertShortToDouble()

double SDDS_ConvertShortToDouble ( void * data,
int64_t index )

Converts a short integer to double.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 114 of file SDDS_rpn.c.

114 {
115 return *((short *)data + index);
116}

◆ SDDS_ConvertStringToDouble()

double SDDS_ConvertStringToDouble ( void * data,
int64_t index )

Converts a string to double using atof.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 136 of file SDDS_rpn.c.

136 {
137 return atof(*((char **)data + index));
138}

◆ SDDS_ConvertToDouble()

double SDDS_ConvertToDouble ( int32_t type,
void * data,
int64_t index )

Converts a value to double based on its type.

Parameters
typeThe SDDS data type of the value.
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value, or 0.0 on error.

Definition at line 199 of file SDDS_rpn.c.

199 {
200 if (!data) {
201 SDDS_SetError("NULL data pointer passed (SDDS_ConvertToDouble)");
202 return (0.0);
203 }
204 switch (type) {
205 case SDDS_SHORT:
206 return ((double)*((short *)data + index));
207 case SDDS_USHORT:
208 return ((double)*((unsigned short *)data + index));
209 case SDDS_LONG:
210 return ((double)*((int32_t *)data + index));
211 case SDDS_ULONG:
212 return ((double)*((uint32_t *)data + index));
213 case SDDS_LONG64:
214 return ((double)*((int64_t *)data + index));
215 case SDDS_ULONG64:
216 return ((double)*((uint64_t *)data + index));
217 case SDDS_FLOAT:
218 return ((double)*((float *)data + index));
219 case SDDS_DOUBLE:
220 return (*((double *)data + index));
221 case SDDS_LONGDOUBLE:
222 return ((double)*((long double *)data + index));
223 case SDDS_CHARACTER:
224 return ((double)*((unsigned char *)data + index));
225 default:
226 SDDS_SetError("Invalid data type seen (SDDS_ConvertToDouble)");
227 return (0.0);
228 }
229}
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
Definition SDDS_utils.c:379
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
Definition SDDStypes.h:67
#define SDDS_FLOAT
Identifier for the float data type.
Definition SDDStypes.h:43
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
Definition SDDStypes.h:55
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
Definition SDDStypes.h:61
#define SDDS_SHORT
Identifier for the signed short integer data type.
Definition SDDStypes.h:73
#define SDDS_CHARACTER
Identifier for the character data type.
Definition SDDStypes.h:91
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
Definition SDDStypes.h:79
#define SDDS_DOUBLE
Identifier for the double data type.
Definition SDDStypes.h:37
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
Definition SDDStypes.h:31
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
Definition SDDStypes.h:49

◆ SDDS_ConvertToLong()

int32_t SDDS_ConvertToLong ( int32_t type,
void * data,
int64_t index )

Converts a value to a 32-bit integer based on its type.

Parameters
typeThe SDDS data type of the value.
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted 32-bit integer, or 0 on error.

Definition at line 279 of file SDDS_rpn.c.

279 {
280 if (!data) {
281 SDDS_SetError("NULL data pointer passed (SDDS_ConvertToLong)");
282 return (0.0);
283 }
284 switch (type) {
285 case SDDS_LONGDOUBLE:
286 return ((int32_t) * ((long double *)data + index));
287 case SDDS_DOUBLE:
288 return ((int32_t) * ((double *)data + index));
289 case SDDS_FLOAT:
290 return ((int32_t) * ((float *)data + index));
291 case SDDS_SHORT:
292 return ((int32_t) * ((short *)data + index));
293 case SDDS_USHORT:
294 return ((int32_t) * ((unsigned short *)data + index));
295 case SDDS_LONG:
296 return (*((int32_t *)data + index));
297 case SDDS_ULONG:
298 return ((int32_t) * ((uint32_t *)data + index));
299 case SDDS_LONG64:
300 return ((int32_t) * ((int64_t *)data + index));
301 case SDDS_ULONG64:
302 return ((int32_t) * ((uint64_t *)data + index));
303 case SDDS_CHARACTER:
304 return ((int32_t) * ((unsigned char *)data + index));
305 default:
306 SDDS_SetError("Invalid data type seen (SDDS_ConvertToLong)");
307 return (0.0);
308 }
309}

◆ SDDS_ConvertToLong64()

int64_t SDDS_ConvertToLong64 ( int32_t type,
void * data,
int64_t index )

Converts a value to a 64-bit integer based on its type.

Parameters
typeThe SDDS data type of the value.
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted 64-bit integer, or 0 on error.

Definition at line 239 of file SDDS_rpn.c.

239 {
240 if (!data) {
241 SDDS_SetError("NULL data pointer passed (SDDS_ConvertToLong64)");
242 return (0.0);
243 }
244 switch (type) {
245 case SDDS_LONGDOUBLE:
246 return ((int64_t) * ((long double *)data + index));
247 case SDDS_DOUBLE:
248 return ((int64_t) * ((double *)data + index));
249 case SDDS_FLOAT:
250 return ((int64_t) * ((float *)data + index));
251 case SDDS_SHORT:
252 return ((int64_t) * ((short *)data + index));
253 case SDDS_USHORT:
254 return ((int64_t) * ((unsigned short *)data + index));
255 case SDDS_LONG:
256 return ((int64_t) * ((int32_t *)data + index));
257 case SDDS_ULONG:
258 return ((int64_t) * ((uint32_t *)data + index));
259 case SDDS_LONG64:
260 return (*((int64_t *)data + index));
261 case SDDS_ULONG64:
262 return ((int64_t) * ((uint64_t *)data + index));
263 case SDDS_CHARACTER:
264 return ((int64_t) * ((unsigned char *)data + index));
265 default:
266 SDDS_SetError("Invalid data type seen (SDDS_ConvertToLong64)");
267 return (0.0);
268 }
269}

◆ SDDS_ConvertToLongDouble()

long double SDDS_ConvertToLongDouble ( int32_t type,
void * data,
int64_t index )

Converts a value to long double based on its type.

Parameters
typeThe SDDS data type of the value.
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted long double value, or 0.0 on error.

Definition at line 159 of file SDDS_rpn.c.

159 {
160 if (!data) {
161 SDDS_SetError("NULL data pointer passed (SDDS_ConvertToLongDouble)");
162 return (0.0);
163 }
164 switch (type) {
165 case SDDS_SHORT:
166 return ((long double)*((short *)data + index));
167 case SDDS_USHORT:
168 return ((long double)*((unsigned short *)data + index));
169 case SDDS_LONG:
170 return ((long double)*((int32_t *)data + index));
171 case SDDS_ULONG:
172 return ((long double)*((uint32_t *)data + index));
173 case SDDS_LONG64:
174 return ((long double)*((int64_t *)data + index));
175 case SDDS_ULONG64:
176 return ((long double)*((uint64_t *)data + index));
177 case SDDS_FLOAT:
178 return ((long double)*((float *)data + index));
179 case SDDS_DOUBLE:
180 return ((long double)*((double *)data + index));
181 case SDDS_LONGDOUBLE:
182 return (*((long double *)data + index));
183 case SDDS_CHARACTER:
184 return ((long double)*((unsigned char *)data + index));
185 default:
186 SDDS_SetError("Invalid data type seen (SDDS_ConvertToLongDouble)");
187 return (0.0);
188 }
189}

◆ SDDS_ConvertULong64ToDouble()

double SDDS_ConvertULong64ToDouble ( void * data,
int64_t index )

Converts an unsigned 64-bit integer to double.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 81 of file SDDS_rpn.c.

81 {
82 return *((uint64_t *)data + index);
83}

◆ SDDS_ConvertULongToDouble()

double SDDS_ConvertULongToDouble ( void * data,
int64_t index )

Converts an unsigned 32-bit integer to double.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 103 of file SDDS_rpn.c.

103 {
104 return *((uint32_t *)data + index);
105}

◆ SDDS_ConvertUShortToDouble()

double SDDS_ConvertUShortToDouble ( void * data,
int64_t index )

Converts an unsigned short integer to double.

Parameters
dataPointer to the data array.
indexIndex of the element to convert.
Returns
The converted double value.

Definition at line 125 of file SDDS_rpn.c.

125 {
126 return *((unsigned short *)data + index);
127}

◆ SDDS_CreateRpnArray()

int64_t SDDS_CreateRpnArray ( char * name)

Stub function for creating RPN arrays when RPN_SUPPORT is not enabled.

Parameters
nameName of the RPN array.
Returns
Always returns 1.

Definition at line 795 of file SDDS_rpn.c.

795 {
796 return (1);
797}

◆ SDDS_CreateRpnMemory()

int64_t SDDS_CreateRpnMemory ( const char * name,
short is_string )

Stub function for creating RPN memory when RPN_SUPPORT is not enabled.

Parameters
nameName of the RPN memory.
is_stringFlag indicating if the memory is for string data.
Returns
Always returns 1.

Definition at line 785 of file SDDS_rpn.c.

785 {
786 return (1);
787}