2015-08-10 16:04:53 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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"
|
2016-02-18 10:38:51 +01:00
|
|
|
#include "obiview.h"
|
2015-08-10 16:04:53 +02:00
|
|
|
#include "obitypes.h"
|
|
|
|
#include "obierrno.h"
|
|
|
|
#include "obidebug.h"
|
|
|
|
|
|
|
|
|
2015-09-30 12:03:46 +02:00
|
|
|
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
2015-08-26 15:05:23 +02:00
|
|
|
|
|
|
|
|
2015-08-10 16:04:53 +02:00
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
2015-11-06 17:55:15 +01:00
|
|
|
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value)
|
2015-08-10 16:04:53 +02:00
|
|
|
{
|
2015-09-01 17:38:08 +02:00
|
|
|
// Check that the line number is not greater than the maximum allowed
|
|
|
|
if (line_nb >= MAXIMUM_LINE_COUNT)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the file needs to be enlarged
|
|
|
|
while ((line_nb+1) > (column->header)->line_count)
|
|
|
|
{
|
|
|
|
// Enlarge the file
|
|
|
|
if (obi_enlarge_column(column) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-08-26 17:25:15 +02:00
|
|
|
// Update lines used
|
|
|
|
if ((line_nb+1) > (column->header)->lines_used)
|
|
|
|
(column->header)->lines_used = line_nb+1;
|
2015-09-01 17:38:08 +02:00
|
|
|
|
|
|
|
// Set the value
|
2016-02-18 10:38:51 +01:00
|
|
|
*(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
2015-09-01 17:38:08 +02:00
|
|
|
|
2015-08-10 16:04:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-18 10:38:51 +01:00
|
|
|
int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value)
|
2015-08-10 16:04:53 +02:00
|
|
|
{
|
2016-02-18 10:38:51 +01:00
|
|
|
// Check that the view is not read-only
|
|
|
|
if (view->read_only)
|
|
|
|
{
|
|
|
|
obi_set_errno(OBIVIEW_ERROR);
|
|
|
|
obidebug(1, "\nError trying to set a value in a column in a read-only view");
|
|
|
|
return -1;
|
|
|
|
}
|
2015-11-29 11:57:07 +01:00
|
|
|
|
2016-02-18 10:38:51 +01:00
|
|
|
if ((view->line_selection != NULL) || (!(column->writable)))
|
|
|
|
{
|
|
|
|
// Get the right line number
|
|
|
|
if (column->writable)
|
|
|
|
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
|
|
|
|
|
|
|
column = obi_view_clone_column(view, (column->header)->name);
|
|
|
|
if (column == NULL)
|
|
|
|
{
|
|
|
|
obidebug(1, "\nError trying to clone a column to modify it");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((line_nb+1) > view->line_count)
|
|
|
|
{
|
|
|
|
if (obi_view_update_lines(view, (line_nb+1)) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
|
|
|
{
|
|
|
|
if ((line_nb+1) > ((column->header)->line_count))
|
2015-09-01 17:38:08 +02:00
|
|
|
{
|
2015-09-14 17:04:29 +02:00
|
|
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
2016-02-18 10:38:51 +01:00
|
|
|
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
2015-09-14 17:04:29 +02:00
|
|
|
return OBIFloat_NA;
|
2015-09-01 17:38:08 +02:00
|
|
|
}
|
2015-11-29 11:57:07 +01:00
|
|
|
|
2016-02-18 10:38:51 +01:00
|
|
|
return *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
|
|
|
{
|
|
|
|
if ((line_nb+1) > (view->line_count))
|
2015-11-29 11:57:07 +01:00
|
|
|
{
|
2016-02-18 10:38:51 +01:00
|
|
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
|
|
|
obidebug(1, "\nError trying to get a value that is beyond the current line count of the view");
|
|
|
|
return OBIFloat_NA;
|
2015-11-29 11:57:07 +01:00
|
|
|
}
|
2016-02-18 10:38:51 +01:00
|
|
|
|
|
|
|
if (view->line_selection)
|
|
|
|
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
|
|
|
|
|
|
|
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
|
2015-08-10 16:04:53 +02:00
|
|
|
}
|
|
|
|
|
2015-08-26 15:05:23 +02:00
|
|
|
|
2015-11-06 17:55:15 +01:00
|
|
|
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value)
|
2015-08-26 15:05:23 +02:00
|
|
|
{
|
2015-11-06 17:55:15 +01:00
|
|
|
index_t element_idx;
|
2015-10-14 18:05:34 +02:00
|
|
|
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
2015-11-06 17:55:15 +01:00
|
|
|
if (element_idx == OBIIdx_NA)
|
2015-10-14 18:05:34 +02:00
|
|
|
return -1;
|
2015-09-01 17:38:08 +02:00
|
|
|
obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value);
|
2015-08-26 15:05:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-18 10:38:51 +01:00
|
|
|
int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value)
|
|
|
|
{
|
|
|
|
index_t element_idx;
|
|
|
|
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
|
|
|
if (element_idx == OBIIdx_NA)
|
|
|
|
return -1;
|
|
|
|
obi_column_set_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-06 17:55:15 +01:00
|
|
|
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
2015-08-26 15:05:23 +02:00
|
|
|
{
|
2015-11-06 17:55:15 +01:00
|
|
|
index_t element_idx;
|
2015-08-26 15:05:23 +02:00
|
|
|
|
2015-10-14 18:05:34 +02:00
|
|
|
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
2015-11-06 17:55:15 +01:00
|
|
|
if (element_idx == OBIIdx_NA)
|
2015-10-14 18:05:34 +02:00
|
|
|
return OBIFloat_NA;
|
2015-09-01 17:38:08 +02:00
|
|
|
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
|
2015-08-26 15:05:23 +02:00
|
|
|
}
|
2015-09-01 17:38:08 +02:00
|
|
|
|
2016-02-18 10:38:51 +01:00
|
|
|
|
|
|
|
obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
|
|
|
{
|
|
|
|
index_t element_idx;
|
|
|
|
|
|
|
|
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
|
|
|
if (element_idx == OBIIdx_NA)
|
|
|
|
return OBIFloat_NA;
|
|
|
|
return obi_column_get_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx);
|
|
|
|
}
|