obidmscolumn_float.c 2.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/****************************************************************************
 * OBIDMS_column_float functions                                              *
 ****************************************************************************/

/**
 * @file obidsmcolumn_float.c
 * @author Celine Mercier
 * @date August 10th 2015
 * @brief Functions handling OBIColumns containing data with the OBIType OBI_FLOAT.
 */


#include <stdlib.h>
#include <stdio.h>

#include "obidmscolumn.h"
#include "obitypes.h"
18 19


20 21 22 23 24 25
/**********************************************************************
 *
 * D E F I N I T I O N   O F   T H E   P U B L I C   F U N C T I O N S
 *
 **********************************************************************/

26
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value)
27
{
28
	if (obi_column_prepare_to_set_value(column, line_nb, element_idx) < 0)
29
		return -1;
30 31

	// Set the value
Celine Mercier committed
32
	*(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
33

34 35 36 37
	return 0;
}


Celine Mercier committed
38 39
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
{
40
	if (obi_column_prepare_to_get_value(column, line_nb) < 0)
41
		return OBIFloat_NA;
42

Celine Mercier committed
43 44 45 46
	return *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
}


47
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value)
48
{
49
	index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
50
	if (element_idx == OBIIdx_NA)
51
		return -1;
52

53
	return obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value);
Celine Mercier committed
54 55 56
}


57
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
58
{
59
	index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
60
	if (element_idx == OBIIdx_NA)
61
		return OBIFloat_NA;
62

63
	return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
64
}
65