star-ck

Describe the radiative properties of gas mixtures
git clone git://git.meso-star.fr/star-ck.git
Log | Files | Refs | README | LICENSE

commit d20041c579fca392de2484fc147caec513410441
parent 36e6495a6ce4a902804fd304167ea5e925ba0d5b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  2 Nov 2020 12:52:32 +0100

Implement accessors to the loaded data

Diffstat:
Msrc/atrck.c | 91++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/atrck.h | 39+++++++++++++++++++++++++++++++++++++++
Msrc/atrck_c.h | 4++--
3 files changed, 129 insertions(+), 5 deletions(-)

diff --git a/src/atrck.c b/src/atrck.c @@ -60,7 +60,7 @@ read_quad_pt goto error; \ } \ } (void)0 - READ(&quad_pt->absissa, "quadrature point absissa"); + READ(&quad_pt->abscissa, "quadrature point abscissa"); READ(&quad_pt->weight, "quadrature point weight"); #undef READ @@ -162,6 +162,7 @@ load_stream(struct atrck* atrck, FILE* stream, const char* stream_name) size_t map_len; size_t iband; uint64_t nbands; + off_t offset = 0; res_T res = RES_OK; ASSERT(atrck && stream && stream_name); @@ -218,16 +219,17 @@ load_stream(struct atrck* atrck, FILE* stream, const char* stream_name) /* Compute the length in bytes of the ka to map for each quadrature point */ map_len = ALIGN_SIZE(atrck->nnodes * sizeof(double), atrck->pagesize); + /* Compute the offset toward the 1st list of ka */ + offset = (off_t)ALIGN_SIZE((uint64_t)ftell(stream), atrck->pagesize); + /* Load the per band, per quadrature point and per node correlated K */ FOR_EACH(iband, 0, nbands) { struct band* band = darray_band_data_get(&atrck->bands) + iband; size_t iquad_pt; FOR_EACH(iquad_pt, 0, darray_quad_pt_size_get(&band->quad_pts)) { struct quad_pt* quad_pt = NULL; - off_t offset = 0; quad_pt = darray_quad_pt_data_get(&band->quad_pts)+iquad_pt; - offset = (off_t)ALIGN_SIZE((uint64_t)ftell(stream), atrck->pagesize); quad_pt->map_len = map_len; quad_pt->ka_list = mmap(NULL, quad_pt->map_len, PROT_READ, MAP_PRIVATE|MAP_POPULATE, fileno(stream), offset); @@ -242,6 +244,7 @@ load_stream(struct atrck* atrck, FILE* stream, const char* stream_name) res = RES_IO_ERR; goto error; } + offset = (off_t)((size_t)offset + map_len); } } @@ -373,6 +376,88 @@ atrck_load_stream return load_stream(atrck, stream, stream_name ? stream_name : "<stream>"); } +size_t +atrck_get_bands_count(const struct atrck* atrck) +{ + ASSERT(atrck); + return darray_band_size_get(&atrck->bands); +} + +size_t +atrck_get_nodes_count(const struct atrck* atrck) +{ + ASSERT(atrck); + return atrck->nnodes; +} + +res_T +atrck_get_band + (const struct atrck* atrck, + const size_t iband, + struct atrck_band* atrck_band) +{ + const struct band* band = NULL; + res_T res = RES_OK; + + if(!atrck || !atrck_band) { + res = RES_BAD_ARG; + goto error; + } + + if(iband >= atrck_get_bands_count(atrck)) { + log_err(atrck, "%s: invalid band index %lu.\n", + FUNC_NAME, (unsigned long)iband); + res = RES_BAD_ARG; + goto error; + } + + band = darray_band_cdata_get(&atrck->bands) + iband; + atrck_band->lower = band->low; + atrck_band->upper = band->upp; + atrck_band->quad_pts_count = darray_quad_pt_size_get(&band->quad_pts); + atrck_band->id = (size_t)band->id; + atrck_band->band__ = band; + +exit: + return res; +error: + goto exit; +} + +res_T +atrck_band_get_quad_pt + (const struct atrck* atrck, + const struct atrck_band* atrck_band, + const size_t iquad_pt, + struct atrck_quad_pt* atrck_quad_pt) +{ + const struct band* band = NULL; + const struct quad_pt* quad_pt = NULL; + res_T res = RES_OK; + + if(!atrck || !atrck_band || !atrck_quad_pt) { + res = RES_BAD_ARG; + goto error; + } + + band = atrck_band->band__; + if(iquad_pt >= atrck_band->quad_pts_count) { + log_err(atrck, "%s: band %lu: invalid quadrature point index %lu.\n", + FUNC_NAME, (unsigned long)atrck_band->id, (unsigned long)iquad_pt); + res = RES_BAD_ARG; + goto error; + } + + quad_pt = darray_quad_pt_cdata_get(&band->quad_pts) + iquad_pt; + atrck_quad_pt->ka_list = quad_pt->ka_list; + atrck_quad_pt->abscissa = quad_pt->abscissa; + atrck_quad_pt->weight = quad_pt->weight; + +exit: + return res; +error: + goto exit; +} /******************************************************************************* * Local functions diff --git a/src/atrck.h b/src/atrck.h @@ -36,6 +36,24 @@ #define ATRCK(Func) atrck_ ## Func #endif +struct atrck_band { + double lower; /* Lower band wavenumber in cm^-1 */ + double upper; /* Upper band wavenumber in cm^-1 */ + size_t quad_pts_count; /* #quadrature points */ + size_t id; + + /* Internal data */ + const void* band__; +}; +static const struct atrck_band ATRCK_BAND_NULL; + +struct atrck_quad_pt { + double* ka_list; /* Per node ka */ + double abscissa; /* m^-1 */ + double weight; +}; +static const struct atrck_quad_pt ATRCK_QUAD_PT_NULL; + /* Forward declaration of external data types */ struct logger; struct mem_allocator; @@ -74,6 +92,27 @@ atrck_load_stream FILE* stream, const char* stream_name); /* Can be NULL */ +ATRCK_API size_t +atrck_get_bands_count + (const struct atrck* atrck); + +ATRCK_API size_t +atrck_get_nodes_count + (const struct atrck* atrck); + +ATRCK_API res_T +atrck_get_band + (const struct atrck* atrck, + const size_t iband, + struct atrck_band* band); + +ATRCK_API res_T +atrck_band_get_quad_pt + (const struct atrck* atrck, + const struct atrck_band* band, + const size_t iquad_pt, + struct atrck_quad_pt* quad_pt); + END_DECLS #endif /* ATRCK_H */ diff --git a/src/atrck_c.h b/src/atrck_c.h @@ -25,7 +25,7 @@ struct mem_allocator; struct quad_pt { double* ka_list; /* Per node ka */ size_t map_len; - double absissa; + double abscissa; double weight; }; @@ -36,7 +36,7 @@ quad_pt_init(struct mem_allocator* allocator, struct quad_pt* quad) (void)allocator; quad->ka_list = NULL; quad->map_len = 0;; - quad->absissa = 0; + quad->abscissa = 0; quad->weight = 0; }