From f05d1645852a8c090d1d8232e02d321a4a6a212e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Wed, 19 Jun 2019 02:44:26 +0300 Subject: [PATCH] Arrays of doubles parsing progress Former-commit-id: df30b965006ff7cde4fef8465175a9332da24a76 --- apps/transop-ewald/translations_ewald.ggo | 2 +- apps/transop-ewald/transop_ewald.c | 47 +++++++++++++++------- apps/transop-ewald/transop_ewald_cmdline.c | 4 +- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/apps/transop-ewald/translations_ewald.ggo b/apps/transop-ewald/translations_ewald.ggo index d7c9a00..06d7b34 100644 --- a/apps/transop-ewald/translations_ewald.ggo +++ b/apps/transop-ewald/translations_ewald.ggo @@ -18,7 +18,7 @@ option "base-vector" b "Base vector" details="Single base vector (two numbers separated by comma)" string typestr="X,Y" - multiple required + multiple(2) required # will be multiple(-3) when implemented 1d, 3d option "error-estimate-output" E "Path to the output with error estimates" string diff --git a/apps/transop-ewald/transop_ewald.c b/apps/transop-ewald/transop_ewald.c index 3cece51..b3ae859 100644 --- a/apps/transop-ewald/transop_ewald.c +++ b/apps/transop-ewald/transop_ewald.c @@ -56,9 +56,8 @@ size_t qpms_parse_ndoubles( if (endptr > beg) { if (i >= n) { errno = EOVERFLOW; - QPMS_WARN("Supplied string contains additional numbers" + if (i == n) QPMS_WARN("Supplied string contains additional numbers" " (expected only %zd numbers): %s\n", n, beg); - goto qpms_parse_ndoubles_cleanup; } else target[i] = parsed; @@ -165,20 +164,40 @@ int main (int argc, char **argv) { int retval = cmdline_parser(argc, argv, *args_info); if (retval) return retval; - cart2_t b1 = {strtod(argv[2], NULL), strtod(argv[3], NULL)}, - b2 = {strtod(argv[4], NULL), strtod(argv[5], NULL)}; - const qpms_l_t lMax = strtol(argv[6], NULL, 10); assert(lMax>0); - const double scuffomega = strtod(argv[7], NULL); - const double refindex = strtod(argv[8], NULL); - const int npart = strtol(argv[9], NULL, 10); assert(npart>0); - assert(argc >= 2*npart + 10); - assert(npart > 0); - cart2_t part_positions[npart]; - for(int p = 0; p < npart; ++p) { - part_positions[p].x = strtod(argv[10+2*p], NULL); - part_positions[p].y = strtod(argv[10+2*p+1], NULL); + const int latdim = args_info.base_vector_given; + QPMS_ENSURE(latdim == 2, + "Sorry, only 2d lattices supported, but %d basis vectors were given\n", + latdim); + cart2_t b[latdim]; + for (int i = 0; i < latdim; ++i) { + const int gotnumbers = qpms_parse_ndoubles( + (*double) &(b[i].x), latdim, + args_info.base_vector_arg[i]); + QPMS_ENSURE(latdim == gotnumbers, + "%d. base vector contained %d numbers, expected %d\n", + i, gotnumbers, latdim); } + const qpms_l_t lMax = args_info.lMax_arg; + QPMS_ENSURE(lMax > 0, "invalid value of lMax: %d", (int)lMax); + + const double refindex = args_info.refractive_index_arg; + + const int npart = args_info.particle_given; + if(!npart) ++npart; + cart2_t part_positions[npart]; + if(!args_info.particle_given) + part_positions[0].x = part_positions[0].y = 0; + else for (int i = 0; i < npart; ++i) { + const int gotnumbers = qpms_parse_ndoubles( + (*double) &(part_positions[i].x), latdim, + args_info.particle_arg[i]); + QPMS_ENSURE(latdim == gotnumbers, + "%d. particle position contained %d coordinates, expected %d\n", + i, gotnumbers, latdim); + } + + const double scuffomega = strtod(argv[7], NULL); //#ifdef KSTDIN size_t kcount = 0; size_t klist_capacity = MAXKCOUNT; diff --git a/apps/transop-ewald/transop_ewald_cmdline.c b/apps/transop-ewald/transop_ewald_cmdline.c index dca379a..e4e162f 100644 --- a/apps/transop-ewald/transop_ewald_cmdline.c +++ b/apps/transop-ewald/transop_ewald_cmdline.c @@ -188,8 +188,8 @@ void init_args_info(struct gengetopt_args_info *args_info) args_info->version_help = gengetopt_args_info_detailed_help[2] ; args_info->output_help = gengetopt_args_info_detailed_help[3] ; args_info->base_vector_help = gengetopt_args_info_detailed_help[5] ; - args_info->base_vector_min = 0; - args_info->base_vector_max = 0; + args_info->base_vector_min = 2; + args_info->base_vector_max = 2; args_info->error_estimate_output_help = gengetopt_args_info_detailed_help[7] ; args_info->normalisation_help = gengetopt_args_info_detailed_help[8] ; args_info->csphase_help = gengetopt_args_info_detailed_help[9] ;