Skip to content
Snippets Groups Projects
Commit 34a1526c authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

add functions that allow the user to convert rlx_spectras to flat arrays

parent 530bddb5
No related branches found
No related tags found
No related merge requests found
...@@ -323,6 +323,54 @@ int* rlx_get_spectra_ids(struct rlxfile* file, const struct rlx_project* project ...@@ -323,6 +323,54 @@ int* rlx_get_spectra_ids(struct rlxfile* file, const struct rlx_project* project
return ids; return ids;
} }
int rlx_get_float_arrays(const struct rlx_spectra *spectra, float **re, float **im, float **omega)
{
*re = malloc(sizeof(float)*spectra->length);
if(!*re)
return -103;
*im = malloc(sizeof(float)*spectra->length);
if(!*im)
return -103;
*omega = malloc(sizeof(float)*spectra->length);
if(!*omega)
return -103;
for(size_t i = 0; i <spectra->length; ++i)
{
(*re)[i] = spectra->datapoints[i].re;
(*im)[i] = spectra->datapoints[i].im;
(*omega)[i] = spectra->datapoints[i].omega;
}
return 0;
}
int rlx_get_double_arrays(const struct rlx_spectra *spectra, double **re, double **im, double **omega)
{
*re = malloc(sizeof(double)*spectra->length);
if(!*re)
return -103;
*im = malloc(sizeof(double)*spectra->length);
if(!*im)
return -103;
*omega = malloc(sizeof(double)*spectra->length);
if(!*omega)
return -103;
for(size_t i = 0; i <spectra->length; ++i)
{
(*re)[i] = spectra->datapoints[i].re;
(*im)[i] = spectra->datapoints[i].im;
(*omega)[i] = spectra->datapoints[i].omega;
}
return 0;
}
struct rlx_fitparam** rlx_get_fit_parameters(struct rlxfile* file, const struct rlx_project* project, int id, size_t *length) struct rlx_fitparam** rlx_get_fit_parameters(struct rlxfile* file, const struct rlx_project* project, int id, size_t *length)
{ {
(void)project; (void)project;
...@@ -394,6 +442,8 @@ const char* rlx_get_errnum_str(int errnum) ...@@ -394,6 +442,8 @@ const char* rlx_get_errnum_str(int errnum)
return "Project contains no spectra"; return "Project contains no spectra";
if(errnum == -102) if(errnum == -102)
return "Tried to load non existing spectra"; return "Tried to load non existing spectra";
if(errnum == -103)
return "Out of memory";
return "Unkown error"; return "Unkown error";
} }
...@@ -190,6 +190,32 @@ int* rlx_get_spectra_ids(struct rlxfile* file, const struct rlx_project* project ...@@ -190,6 +190,32 @@ int* rlx_get_spectra_ids(struct rlxfile* file, const struct rlx_project* project
*/ */
struct rlx_spectra* rlx_get_spectra(struct rlxfile* file, const struct rlx_project* project, int id); struct rlx_spectra* rlx_get_spectra(struct rlxfile* file, const struct rlx_project* project, int id);
/**
* @brief transforms a rlx_spectra struct into a set of newly allocated arrays, float version.
*
* If this function encounters an error it will return NULL and set an error at rlx_get_errnum.
*
* @param spectra the spectra to convert
* @param re an array with the real part of the spectra will be allocated here. To be freed by free().
* @param im an array with the imaginary part of the spectra will be allocated here. To be freed by free().
* @param omega an array with the omega values of the spectra will be allocated here. To be freed by free().
* @return 0 if successful or an error number < 0 interpertable by rlx_get_errnum_str otherwise, no allocations will be performed on error.
*/
int rlx_get_float_arrays(const struct rlx_spectra *spectra, float **re, float **im, float **omega);
/**
* @brief transforms a rlx_spectra struct into a set of newly allocated arrays, double version.
*
* If this function encounters an error it will return NULL and set an error at rlx_get_errnum.
*
* @param spectra the spectra to convert
* @param re an array with the real part of the spectra will be allocated here. To be freed by free().
* @param im an array with the imaginary part of the spectra will be allocated here. To be freed by free().
* @param omega an array with the omega values of the spectra will be allocated here. To be freed by free().
* @return 0 if successful or an error number < 0 interpertable by rlx_get_errnum_str otherwise, no allocations will be performed on error.
*/
int rlx_get_double_arrays(const struct rlx_spectra *spectra, double **re, double **im, double **omega);
/** /**
* @brief Loads the parameters for a given spectra id from file * @brief Loads the parameters for a given spectra id from file
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment