Arrays of doubles parsing progress

Former-commit-id: df30b965006ff7cde4fef8465175a9332da24a76
This commit is contained in:
Marek Nečada 2019-06-19 02:44:26 +03:00
parent 51fe6a0b52
commit f05d164585
3 changed files with 36 additions and 17 deletions

View File

@ -18,7 +18,7 @@ option "base-vector" b "Base vector"
details="Single base vector (two numbers separated by comma)" details="Single base vector (two numbers separated by comma)"
string string
typestr="X,Y" 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" option "error-estimate-output" E "Path to the output with error estimates"
string string

View File

@ -56,9 +56,8 @@ size_t qpms_parse_ndoubles(
if (endptr > beg) { if (endptr > beg) {
if (i >= n) { if (i >= n) {
errno = EOVERFLOW; 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); " (expected only %zd numbers): %s\n", n, beg);
goto qpms_parse_ndoubles_cleanup;
} }
else else
target[i] = parsed; target[i] = parsed;
@ -165,20 +164,40 @@ int main (int argc, char **argv) {
int retval = cmdline_parser(argc, argv, *args_info); int retval = cmdline_parser(argc, argv, *args_info);
if (retval) return retval; if (retval) return retval;
cart2_t b1 = {strtod(argv[2], NULL), strtod(argv[3], NULL)}, const int latdim = args_info.base_vector_given;
b2 = {strtod(argv[4], NULL), strtod(argv[5], NULL)}; QPMS_ENSURE(latdim == 2,
const qpms_l_t lMax = strtol(argv[6], NULL, 10); assert(lMax>0); "Sorry, only 2d lattices supported, but %d basis vectors were given\n",
const double scuffomega = strtod(argv[7], NULL); latdim);
const double refindex = strtod(argv[8], NULL); cart2_t b[latdim];
const int npart = strtol(argv[9], NULL, 10); assert(npart>0); for (int i = 0; i < latdim; ++i) {
assert(argc >= 2*npart + 10); const int gotnumbers = qpms_parse_ndoubles(
assert(npart > 0); (*double) &(b[i].x), latdim,
cart2_t part_positions[npart]; args_info.base_vector_arg[i]);
for(int p = 0; p < npart; ++p) { QPMS_ENSURE(latdim == gotnumbers,
part_positions[p].x = strtod(argv[10+2*p], NULL); "%d. base vector contained %d numbers, expected %d\n",
part_positions[p].y = strtod(argv[10+2*p+1], NULL); 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 //#ifdef KSTDIN
size_t kcount = 0; size_t kcount = 0;
size_t klist_capacity = MAXKCOUNT; size_t klist_capacity = MAXKCOUNT;

View File

@ -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->version_help = gengetopt_args_info_detailed_help[2] ;
args_info->output_help = gengetopt_args_info_detailed_help[3] ; 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_help = gengetopt_args_info_detailed_help[5] ;
args_info->base_vector_min = 0; args_info->base_vector_min = 2;
args_info->base_vector_max = 0; args_info->base_vector_max = 2;
args_info->error_estimate_output_help = gengetopt_args_info_detailed_help[7] ; args_info->error_estimate_output_help = gengetopt_args_info_detailed_help[7] ;
args_info->normalisation_help = gengetopt_args_info_detailed_help[8] ; args_info->normalisation_help = gengetopt_args_info_detailed_help[8] ;
args_info->csphase_help = gengetopt_args_info_detailed_help[9] ; args_info->csphase_help = gengetopt_args_info_detailed_help[9] ;