commit 02c4f0a3bf97ee978b067e9e2fa9ddd930b9c3e1
parent 5ea6630f034ca357ff5a76c2fc6adc2269f53b40
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 10 Aug 2018 15:52:58 +0200
Add the upper bound of the grid to the htcp desc
Diffstat:
5 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/src/htcp.c b/src/htcp.c
@@ -35,6 +35,7 @@ struct htcp {
int8_t irregular_z;
int32_t definition[4];
double lower[3];
+ double upper[3];
double vxsz[2]; /* Size of the voxels in X and Y */
struct darray_double vxsz_z; /* Size of the voxels along the Z dimension */
struct darray_double coord_z; /* Lower coordinate of the voxel along Z */
@@ -113,7 +114,7 @@ load_stream(struct htcp* htcp, FILE* stream, const char* stream_name)
{
size_t nz = 0;
size_t map_len = 0;
- size_t filesz;
+ size_t filesz;
off_t offset = 0;
res_T res = RES_OK;
ASSERT(htcp && stream && stream_name);
@@ -172,7 +173,13 @@ load_stream(struct htcp* htcp, FILE* stream, const char* stream_name)
READ(darray_double_data_get(&htcp->vxsz_z), nz, "Z voxel size(s)");
#undef READ
- if(htcp->irregular_z) {
+ htcp->upper[0] = htcp->lower[0] + htcp->vxsz[0] * htcp->definition[0];
+ htcp->upper[1] = htcp->lower[1] + htcp->vxsz[1] * htcp->definition[1];
+ if(!htcp->irregular_z) {
+ htcp->upper[2] = htcp->lower[2]
+ + darray_double_cdata_get(&htcp->vxsz_z)[0] * htcp->definition[2];
+ } else {
+ /* Compute the Z lower bound in Z of each Z slice */
const double* size = NULL;
double* coord = NULL;
size_t i;
@@ -185,6 +192,7 @@ load_stream(struct htcp* htcp, FILE* stream, const char* stream_name)
size = darray_double_cdata_get(&htcp->vxsz_z);
coord = darray_double_data_get(&htcp->coord_z);
FOR_EACH(i, 0, nz) coord[i] = i ? coord[i-1] + size[i-1] : htcp->lower[2];
+ htcp->upper[2] = coord[nz-1] + size[nz-1];
}
map_len =
@@ -360,6 +368,9 @@ htcp_get_desc(const struct htcp* htcp, struct htcp_desc* desc)
desc->lower[0] = htcp->lower[0];
desc->lower[1] = htcp->lower[1];
desc->lower[2] = htcp->lower[2];
+ desc->upper[0] = htcp->upper[0];
+ desc->upper[1] = htcp->upper[1];
+ desc->upper[2] = htcp->upper[2];
desc->vxsz_x = htcp->vxsz[0];
desc->vxsz_y = htcp->vxsz[1];
desc->vxsz_z = darray_double_cdata_get(&htcp->vxsz_z);
diff --git a/src/htcp.h b/src/htcp.h
@@ -53,6 +53,7 @@ struct htcp_desc {
size_t time_definition; /* Definition of the time */
double lower[3]; /* Lower position of the grid */
+ double upper[3]; /* Upper 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 */
@@ -64,7 +65,7 @@ struct htcp_desc {
const double* T; /* Temperature */
};
#define HTCP_DESC_NULL__ \
- {0,-1,{0,0,0},0,{-1,-1,-1},-1,-1,NULL,NULL,NULL,NULL,NULL,NULL}
+ {0,-1,{0,0,0},0,{-1,-1,-1},{0,0,0},-1,-1,NULL,NULL,NULL,NULL,NULL,NULL}
static const struct htcp_desc HTCP_DESC_NULL = HTCP_DESC_NULL__;
BEGIN_DECLS
diff --git a/src/les2htcp.c b/src/les2htcp.c
@@ -834,7 +834,7 @@ main(int argc, char** argv)
CALL(write_data(nc, "THT", stream, THT_to_T, &THT_to_T_ctx));
if(!IS_ALIGNED(ftell(stream), (size_t)pagesz)) {
/* Padding to ensure that the size is aligned on the page size. Note that
- * one char is written to positioned the EOF indicator */
+ * one char is written to position the EOF indicator */
const char byte = 0;
fseek(stream, ALIGN_SIZE(ftell(stream),(off_t)pagesz)-1, SEEK_SET);
WRITE(&byte, 1, "Dummy Byte");
diff --git a/src/test_htcp_load.c b/src/test_htcp_load.c
@@ -112,6 +112,9 @@ main(int argc, char** argv)
CHK(desc.lower[0] == 0);
CHK(desc.lower[1] == 0);
CHK(desc.lower[2] == 0);
+ CHK(desc.upper[0] == desc.vxsz_x * (double)desc.spatial_definition[0]);
+ CHK(desc.upper[1] == desc.vxsz_y * (double)desc.spatial_definition[1]);
+ CHK(desc.upper[2] == desc.vxsz_z[0] * (double)desc.spatial_definition[2]);
CHK(desc.vxsz_x == 1);
CHK(desc.vxsz_y == 2);
CHK(desc.vxsz_z[0] == 3);
diff --git a/src/test_htcp_load_from_file.c b/src/test_htcp_load_from_file.c
@@ -134,6 +134,18 @@ check_misc(const struct htcp* htcp)
}
}
}
+
+ upp[0] = desc.lower[0] + desc.vxsz_x * (double)desc.spatial_definition[0];
+ upp[1] = desc.lower[1] + desc.vxsz_y * (double)desc.spatial_definition[1];
+ if(!desc.irregular_z) {
+ upp[2] = desc.lower[2] + desc.vxsz_z[0] * (double)desc.spatial_definition[2];
+ } else {
+ upp[2] = desc.lower[2];
+ FOR_EACH(z, 0, desc.spatial_definition[2]) {
+ upp[2] += desc.vxsz_z[z];
+ }
+ }
+ CHK(d3_eq_eps(upp, desc.upper, 1.e-6));
}
int