commit baf96fdc4b7f02c0d34c03e463297008d8491198
parent 02c4f0a3bf97ee978b067e9e2fa9ddd930b9c3e1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sat, 22 Sep 2018 15:15:26 +0200
Add the '-m FP_TO_METER' argument to les2htcp
Diffstat:
4 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -85,7 +85,7 @@ if(NOT NO_TEST)
add_custom_command(
OUTPUT ${_output_base}.htcp
- COMMAND les2htcp -i ${_netcdf} -fo ${_output_base}.htcp
+ COMMAND les2htcp -m 1000 -i ${_netcdf} -fo ${_output_base}.htcp
DEPENDS les2htcp
COMMENT "${_file}.nc: convert to HTCP fileformat"
VERBATIM)
diff --git a/src/htcp.h b/src/htcp.h
@@ -52,11 +52,11 @@ struct htcp_desc {
size_t spatial_definition[3];
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 */
+ double lower[3]; /* Lower position of the grid in meters */
+ double upper[3]; /* Upper position of the grid in meters */
+ double vxsz_x; /* Voxel size in X in meters */
+ double vxsz_y; /* Voxel size in Y in meters */
+ const double* vxsz_z; /* Voxel size along Z in meters */
const double* coord_z; /* Voxel lower bound along Z. NULL if !irregular_z */
const double* RCT;
diff --git a/src/les2htcp.c b/src/les2htcp.c
@@ -36,13 +36,14 @@
struct args {
const char* output;
const char* input;
+ double fp_to_meter;
long pagesize;
int force_overwrite;
int check;
int no_output;
int quit; /* Quit the application */
};
-#define ARGS_DEFAULT__ {NULL,NULL,4096,0,0,0,0}
+#define ARGS_DEFAULT__ {NULL,NULL,1.0,4096,0,0,0,0}
static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
static void
@@ -66,6 +67,10 @@ print_help(const char* cmd)
printf(
" -i INPUT path of the LES file to convert.\n");
printf(
+" -m FLT_TO_METER scale factor to convert from floating point units to\n"
+" meters. By default, it is set to %g.\n",
+ ARGS_DEFAULT.fp_to_meter);
+ printf(
" -o OUTPUT write results to OUTPUT. If not defined, write results to\n"
" standard output.\n");
printf(
@@ -99,7 +104,7 @@ args_init(struct args* args, const int argc, char** argv)
res_T res = RES_OK;
ASSERT(args && argc && argv);
- while((opt = getopt(argc, argv, "cfhi:o:p:qv")) != -1) {
+ while((opt = getopt(argc, argv, "cfhi:m:o:p:qv")) != -1) {
switch(opt) {
case 'c': args->check = 1; break;
case 'f': args->force_overwrite = 1; break;
@@ -109,6 +114,10 @@ args_init(struct args* args, const int argc, char** argv)
args->quit = 1;
goto exit;
case 'i': args->input = optarg; break;
+ case 'm':
+ res = cstr_to_double(optarg, &args->fp_to_meter);
+ if(res == RES_OK && args->fp_to_meter <= 0) res = RES_BAD_ARG;
+ break;
case 'o': args->output = optarg; break;
case 'p':
res = cstr_to_long(optarg, &args->pagesize);
@@ -127,7 +136,7 @@ args_init(struct args* args, const int argc, char** argv)
}
if(res != RES_OK) {
if(optarg) {
- fprintf(stderr, "%s: invalid option argumet '%s' -- '%c'\n",
+ fprintf(stderr, "%s: invalid option argument '%s' -- '%c'\n",
argv[0], optarg, opt);
}
goto error;
@@ -320,7 +329,7 @@ open_output_stream(const char* path, const int force_overwrite, FILE** stream)
int fd = -1;
FILE* fp = NULL;
res_T res = RES_OK;
- ASSERT(path);
+ ASSERT(path && stream);
if(force_overwrite) {
fp = fopen(path, "w");
@@ -801,6 +810,23 @@ main(int argc, char** argv)
CALL(setup_Z_dimension
(nc, &grid.vxsz_z, grid.lower+2, &grid.is_z_irregular, args.check));
+ if(args.fp_to_meter != 1) { /* Convert the grid in meters */
+ grid.lower[0] *= args.fp_to_meter;
+ grid.lower[1] *= args.fp_to_meter;
+ grid.lower[2] *= args.fp_to_meter;
+
+ grid.vxsz_x *= args.fp_to_meter;
+ grid.vxsz_y *= args.fp_to_meter;
+ if(!grid.is_z_irregular) {
+ grid.vxsz_z[0] *= args.fp_to_meter;
+ } else {
+ size_t i;
+ FOR_EACH(i, 0, grid.nz) {
+ grid.vxsz_z[i] *= args.fp_to_meter;
+ }
+ }
+ }
+
#define WRITE(Var, N, Name) { \
if(fwrite((Var), sizeof(*(Var)), (N), stream) != (N)) { \
fprintf(stderr, "Error writing the %s.\n", (Name)); \
diff --git a/src/test_htcp_load_from_file.c b/src/test_htcp_load_from_file.c
@@ -18,6 +18,7 @@
#include "htcp.h"
#include "test_htcp_utils.h"
+#include <rsys/cstr.h>
#include <rsys/double3.h>
#include <rsys/math.h>
#include <string.h>
@@ -153,6 +154,7 @@ main(int argc, char** argv)
{
struct htcp* htcp = NULL;
struct htcp_desc desc = HTCP_DESC_NULL;
+ double fp_to_meter = 1.0;
char* filename = NULL;
char* path = NULL;
char* base = NULL;
@@ -160,9 +162,12 @@ main(int argc, char** argv)
size_t n;
if(argc < 3) {
- fprintf(stderr, "Usage: %s <htcp> <ref-data-path> \n", argv[0]);
+ fprintf(stderr, "Usage: %s <htcp> <ref-data-path> [fp-to-meter]\n", argv[0]);
return -1;
}
+ if(argc > 3) {
+ CHK(cstr_to_double(argv[3], &fp_to_meter) == RES_OK);
+ }
filename = argv[1];
path = argv[2];