htcp

Properties of water suspended in clouds
git clone git://git.meso-star.fr/htcp.git
Log | Files | Refs | README | LICENSE

commit 39e191921d315baa6ba287c280f20d249949258a
parent 919404f768af19476a90f673c6ae821d351cf18d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 30 Apr 2018 11:36:13 +0200

Implement and test the htcop_get_desc function

Diffstat:
Msrc/htcop.c | 22++++++++++++++++++++++
Msrc/htcop.h | 55++++++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/test_htcop_load.c | 45+++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 117 insertions(+), 5 deletions(-)

diff --git a/src/htcop.c b/src/htcop.c @@ -311,3 +311,25 @@ htcop_load_stream(struct htcop* htcop, FILE* stream) return load_stream(htcop, stream, "<stream>"); } +res_T +htcop_get_desc(const struct htcop* htcop, struct htcop_desc* desc) +{ + if(!htcop || !desc) return RES_BAD_ARG; + if(!htcop->RVT) return RES_BAD_ARG; + desc->pagesize = (size_t)htcop->pagesize; + desc->irregular_z = htcop->irregular_z != 0; + desc->spatial_definition[0] = (size_t)htcop->definition[X]; + desc->spatial_definition[1] = (size_t)htcop->definition[Y]; + desc->spatial_definition[2] = (size_t)htcop->definition[Z]; + desc->time_definition = (size_t)htcop->definition[TIME]; + desc->lower[0] = htcop->lower[0]; + desc->lower[1] = htcop->lower[1]; + desc->lower[2] = htcop->lower[2]; + desc->vxsz_x = htcop->vxsz[0]; + desc->vxsz_y = htcop->vxsz[1]; + desc->vxsz_z = darray_double_cdata_get(&htcop->vxsz_z); + desc->RCT = htcop->RCT; + desc->RVT = htcop->RVT; + return RES_OK; +} + diff --git a/src/htcop.h b/src/htcop.h @@ -43,12 +43,25 @@ struct mem_allocator; /* Forward declaration of opaque data types */ struct htcop; -struct htcop_layout { +struct htcop_desc { + size_t pagesize; /* In bytes */ + int irregular_z; + /* #coordinates along the X, Y and Z axis. X means for the West-Est axis, Y * is the South-North axis and finally Z is the altitude */ size_t spatial_definition[3]; size_t time_definition; /* Definition of the time */ + + double lower[3]; /* Lower position of the grid */ + double vxsz_x; /* Voxel size in X */ + double vxsz_y; /* Voxel size in Y */ + const double* vxsz_z; /* Voxel size along Z */ + + const double* RCT; + const double* RVT; }; +#define HTCOP_DESC_NULL__ {0,-1,{0,0,0},0,{-1,-1,-1},-1,-1,NULL,NULL,NULL} +static const struct htcop_desc HTCOP_DESC_NULL = HTCOP_DESC_NULL__; BEGIN_DECLS @@ -81,9 +94,45 @@ htcop_ref_put (struct htcop* htcop); HTCOP_API res_T -htcop_get_layout +htcop_get_desc (const struct htcop* htcop, - struct htcop_layout* layout); + struct htcop_desc* desc); + +/* Internal function */ +static FINLINE double +htcop_dblgrid4D_at__ + (const double* grid, + const struct htcop_desc* desc, + size_t x, size_t y, size_t z, size_t t) +{ + size_t row, slice, array; + ASSERT(desc && grid); + ASSERT(x < desc->spatial_definition[0]); + ASSERT(y < desc->spatial_definition[1]); + ASSERT(z < desc->spatial_definition[2]); + ASSERT(t < desc->time_definition); + row = desc->spatial_definition[0]; + slice = desc->spatial_definition[1] * row; + array = desc->spatial_definition[2] * slice; + return grid[t*array + z*slice + y*row + x]; +} + +static FINLINE double +htcop_desc_RCT_at + (const struct htcop_desc* desc, + size_t x, size_t y, size_t z, size_t t) +{ + return htcop_dblgrid4D_at__(desc->RCT, desc, x, y, z, t); +} + + +static FINLINE double +htcop_desc_RVT_at + (const struct htcop_desc* desc, + size_t x, size_t y, size_t z, size_t t) +{ + return htcop_dblgrid4D_at__(desc->RVT, desc, x, y, z, t); +} END_DECLS diff --git a/src/test_htcop_load.c b/src/test_htcop_load.c @@ -23,11 +23,13 @@ main(int argc, char** argv) { int64_t pagesize; struct htcop* htcop = NULL; + struct htcop_desc desc = HTCOP_DESC_NULL; FILE* stream = NULL; int8_t i8; int32_t i32[4]; double dbl[3]; - size_t i; + size_t i, n; + size_t x, y, z, t; (void)argc, (void)argv; stream = tmpfile(); @@ -58,7 +60,7 @@ main(int argc, char** argv) fseek(stream, ALIGN_SIZE(ftell(stream), pagesize), SEEK_SET); /* padding */ FOR_EACH(i, 0, i32[0]*i32[1]*i32[2]*i32[3]) { /* RCT */ - dbl[0] = (double)i; + dbl[0] =-(double)i; CHK(fwrite(dbl, sizeof(dbl[0]), 1, stream) == 1); } fseek(stream, ALIGN_SIZE(ftell(stream), pagesize), SEEK_SET); /* padding */ @@ -67,10 +69,49 @@ main(int argc, char** argv) CHK(htcop_create(NULL, &mem_default_allocator, 1, &htcop) == RES_OK); + CHK(htcop_get_desc(NULL, &desc) == RES_BAD_ARG); + CHK(htcop_get_desc(htcop, NULL) == RES_BAD_ARG); + CHK(htcop_get_desc(htcop, &desc) == RES_BAD_ARG); + CHK(htcop_load_stream(NULL, stream) == RES_BAD_ARG); CHK(htcop_load_stream(htcop, NULL) == RES_BAD_ARG); CHK(htcop_load_stream(htcop, stream) == RES_OK); + fclose(stream); + + CHK(htcop_get_desc(NULL, &desc) == RES_BAD_ARG); + CHK(htcop_get_desc(htcop, NULL) == RES_BAD_ARG); + CHK(htcop_get_desc(htcop, &desc) == RES_OK); + CHK(desc.pagesize == 4096); + CHK(desc.irregular_z == 0); + CHK(desc.spatial_definition[0] == 2); + CHK(desc.spatial_definition[1] == 2); + CHK(desc.spatial_definition[2] == 3); + CHK(desc.time_definition == 1); + CHK(desc.lower[0] == 0); + CHK(desc.lower[1] == 0); + CHK(desc.lower[2] == 0); + CHK(desc.vxsz_x == 1); + CHK(desc.vxsz_y == 2); + CHK(desc.vxsz_z[0] == 3); + + n = desc.spatial_definition[0] + * desc.spatial_definition[1] + * desc.spatial_definition[2] + * desc.time_definition; + FOR_EACH(i, 0,n) { + CHK(desc.RVT[i] == (double)i); + CHK(desc.RCT[i] ==-(double)i); + } + i = 0; + FOR_EACH(t, 0, desc.time_definition) { + FOR_EACH(z, 0, desc.spatial_definition[2]) { + FOR_EACH(y, 0, desc.spatial_definition[1]) { + FOR_EACH(x, 0, desc.spatial_definition[0]) { + CHK(htcop_desc_RVT_at(&desc, x, y, z, t) == (double)i); + CHK(htcop_desc_RCT_at(&desc, x, y, z, t) ==-(double)i); + ++i; + }}}} CHK(htcop_ref_put(htcop) == RES_OK); CHK(mem_allocated_size() == 0);