atrri

Refractive indices varying with wavelength
git clone git://git.meso-star.fr/atrri.git
Log | Files | Refs | README | LICENSE

commit df65eb1cb032efe96b3568c4391ccb012f214855
parent 8248d8cd48cb8022075f88e845f84660e95f2165
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 13 Jan 2021 10:30:33 +0100

Add and implement the atrri_get_desc function

Diffstat:
Msrc/atrri.c | 25+++++++++++++++++++++----
Msrc/atrri.h | 22++++++++++++++++++++++
Msrc/atrri_c.h | 13+++----------
3 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/src/atrri.c b/src/atrri.c @@ -28,10 +28,17 @@ /******************************************************************************* * Local functions ******************************************************************************/ +static INLINE void +reset_atrri(struct atrri* atrri) +{ + ASSERT(atrri); + darray_refractive_id_clear(&atrri->refract_ids); +} + static res_T parse_line(struct atrri* atrri, struct txtrdr* txtrdr) { - struct refractive_index refract_id = REFRACTIVE_INDEX_NULL; + struct atrri_refractive_index refract_id = ATRRI_REFRACTIVE_INDEX_NULL; char* tk = NULL; char* tk_ctx = NULL; size_t nrefract_ids = 0; @@ -53,10 +60,10 @@ parse_line(struct atrri* atrri, struct txtrdr* txtrdr) nrefract_ids = darray_refractive_id_size_get(&atrri->refract_ids); if(nrefract_ids != 0) { /* Check that the indices are sorted in ascending order wrt wavelength */ - const struct refractive_index* prev_refract_id = + const struct atrri_refractive_index* prev_refract_id = darray_refractive_id_cdata_get(&atrri->refract_ids) + nrefract_ids - 1; - if(prev_refract_id->wavelength <= refract_id.wavelength) { - log_err(atrri, + if(prev_refract_id->wavelength >= refract_id.wavelength) { + log_err(atrri, "%s:%lu: refractive indices must be sorted in ascending order.\n,", txtrdr_get_name(txtrdr), (unsigned long)txtrdr_get_line_num(txtrdr)); res = RES_BAD_ARG; @@ -130,6 +137,8 @@ load_stream(struct atrri* atrri, FILE* stream, const char* stream_name) res_T res = RES_OK; ASSERT(atrri && stream && stream_name); + reset_atrri(atrri); + res = txtrdr_stream(atrri->allocator, stream, stream_name, '#', &txtrdr); if(res != RES_OK) { log_err(atrri, "%s: could not create the text reader -- %s.\n", @@ -289,3 +298,11 @@ error: goto exit; } +res_T +atrri_get_desc(const struct atrri* atrri, struct atrri_desc* desc) +{ + if(!atrri || !desc) return RES_BAD_ARG; + desc->indices = darray_refractive_id_cdata_get(&atrri->refract_ids); + desc->nindices = darray_refractive_id_size_get(&atrri->refract_ids); + return RES_OK; +} diff --git a/src/atrri.h b/src/atrri.h @@ -36,6 +36,23 @@ #define ATRRI(Func) atrri_ ## Func #endif +struct atrri_refractive_index { + double wavelength; /* In nanometer */ + double n; /* Real part */ + double kappa; /* Imaginary part */ +}; +#define ATRRI_REFRACTIVE_INDEX_NULL__ {0,0,0} +static const struct atrri_refractive_index ATRRI_REFRACTIVE_INDEX_NULL = + ATRRI_REFRACTIVE_INDEX_NULL__; + +struct atrri_desc { + /* List of indices sorted in ascending order wrt the wavelength */ + const struct atrri_refractive_index* indices; + size_t nindices; +}; +#define ATRRI_DESC_NULL__ {NULL, 0} +static const struct atrri_desc ATRRI_DESC_NULL = ATRRI_DESC_NULL__; + /* Forward declaration of external data types */ struct logger; struct mem_allocator; @@ -74,6 +91,11 @@ atrri_load_stream FILE* stream, const char* stream_name); /* Can be NULL */ +ATRRI_API res_T +atrri_get_desc + (const struct atrri* atrri, + struct atrri_desc* desc); + END_DECLS #endif /* ATRRI_H */ diff --git a/src/atrri_c.h b/src/atrri_c.h @@ -16,21 +16,14 @@ #ifndef ATRRI_C_H #define ATRRI_C_H +#include "atrri.h" + #include <rsys/dynamic_array.h> #include <rsys/logger.h> #include <rsys/ref_count.h> -struct refractive_index { - double wavelength; /* In nanometers */ - double n; /* Real part */ - double kappa; /* Imaginary part */ -}; -#define REFRACTIVE_INDEX_NULL__ {0,0,0} -static const struct refractive_index REFRACTIVE_INDEX_NULL = - REFRACTIVE_INDEX_NULL__; - #define DARRAY_NAME refractive_id -#define DARRAY_DATA struct refractive_index +#define DARRAY_DATA struct atrri_refractive_index #include <rsys/dynamic_array.h> struct mem_allocator;