add simple CLI interface

This commit is contained in:
Florian Stecker 2022-06-14 16:03:40 +02:00
parent 0763056ccb
commit 729d1a10b7

View File

@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define LOOP(i,n) for(int i = 0; i < (n); i++)
#define SWAP(t,x,y) do { t _tmp = (x); (x) = (y); (y) = _tmp; } while (0);
@ -81,15 +82,51 @@ static double gaussian_sqrt5_imag(NUMBER x)
return result;
}
enum mode {
MODE_HELP,
MODE_TRACES,
MODE_SUMMARY,
MODE_TRACE_IDS
};
int main(int argc, char *argv[])
{
char buf[100];
int n = atoi(argv[1]);
int mode;
if(argc < 2 || strcmp(argv[1], "help") == 0)
mode = MODE_HELP;
else if(strcmp(argv[1], "traces") == 0)
mode = MODE_TRACES;
else if(strcmp(argv[1], "summary") == 0)
mode = MODE_SUMMARY;
else if(strcmp(argv[1], "trace_ids") == 0)
mode = MODE_TRACE_IDS;
else
mode = MODE_HELP;
if(mode == MODE_HELP) {
fprintf(stderr, "Usage: %s <help|traces|summary|trace_ids> [arguments]\n", argv[0]);
fprintf(stderr, "%s help display this page\n", argv[0]);
fprintf(stderr, "%s traces <n> <qreal> <qimag> enumerate group and output unique trace/trace inverse pairs\n", argv[0]);
fprintf(stderr, "%s summary <n> <qreal> <qimag> only output max slope etc.\n", argv[0]);
fprintf(stderr, "%s trace_ids <n> <qreal> <qimag> list of ids of unique traces\n", argv[0]);
return 0;
}
if(argc < 5) {
fprintf(stderr, "Not enough arguments!\n");
return 0;
}
int n = atoi(argv[2]);
mpq_t qreal, qimag;
mpq_inits(qreal, qimag, NULL);
mpq_set_si(qreal, 50, 10);
mpq_set_si(qimag, 1, 10);
mpq_set_str(qreal, argv[3], 10);
mpq_set_str(qimag, argv[4], 10);
// mpq_set_si(qreal, 50, 10);
// mpq_set_si(qimag, 1, 10);
mpq_canonicalize(qreal);
mpq_canonicalize(qimag);
@ -170,12 +207,21 @@ int main(int argc, char *argv[])
max_slope_id = traces[i].id;
}
if(mode == MODE_TRACES) {
printf("%d %f %f %f\n",
traces[i].id, log(ev_abs2[0]), log(ev_abs2[1]), log(ev_abs2[2]));
} else if(mode == MODE_TRACE_IDS) {
printf("%d\n", traces[i].id);
}
}
coxeter_snprint(buf, sizeof(buf), &group->elements[max_slope_id]);
gmp_printf("q = %Qd + i*%Qd\tElements: %d\tTraces: %d\tMaximal slope: %f at %s\n", qreal, qimag, n, nuniq, max_slope, buf);
if(mode == MODE_SUMMARY) {
gmp_fprintf(stdout, "%f %f %d %d %f %s\n", mpq_get_d(qreal), mpq_get_d(qimag), n, nuniq, max_slope, buf);
} else {
gmp_fprintf(stderr, "q = %Qd + i*%Qd\tElements: %d\tTraces: %d\tMaximal slope: %f at %s\n", qreal, qimag, n, nuniq, max_slope, buf);
}
mps_monomial_poly_free(solver, MPS_POLYNOMIAL(poly));
mps_context_free(solver);