1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

made histogram plotter more fancy

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@227 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-09-09 11:11:15 +00:00
parent 310031dc16
commit 764531787a
2 changed files with 18 additions and 10 deletions

View file

@ -29,6 +29,7 @@
#define MAG(str) "\x1B[35m" str "\x1B[0m" /**< Print str in magenta */
#define CYN(str) "\x1B[36m" str "\x1B[0m" /**< Print str in cyan */
#define WHT(str) "\x1B[37m" str "\x1B[0m" /**< Print str in white */
#define BLD(str) "\x1B[1m" str "\x1B[0m" /**< Print str in bold */
/** The log level which is passed as first argument to print() */
enum log_level { DEBUG, INFO, WARN, ERROR };

View file

@ -124,23 +124,30 @@ struct timespec timespec_rate(double rate)
void hist_print(unsigned *hist, int length)
{
char buf[HIST_HEIGHT + 8];
char buf[HIST_HEIGHT + 32];
int bar;
int max = 0;
/* Get max */
/* Get max, first & last */
for (int i = 0; i < length; i++) {
if (hist[i] > hist[max])
max = i;
}
/* Print plot */
for (int i = 0; i < length; i++) {
memset(buf, 0, sizeof(buf));
for (int j = 0; j < HIST_HEIGHT * (float) hist[i] / hist[max]; j++)
strcat(buf, "#");
info("%2u: %s", i, buf);
/* Print header */
info("%2s | %5s | %s", "Id", "Value", "Histogram Plot:");
/* Print plot */
memset(buf, '#', sizeof(buf));
for (int i = 0; i < length; i++) {
bar = HIST_HEIGHT * (float) hist[i] / hist[max];
if (i == max)
info("%2u | " RED("%5u") " | " BLD("%.*s"), i, hist[i], bar, buf);
else if (hist[i] == 0)
info("%2u | " GRN("%5u") " | " "%.*s", i, hist[i], bar, buf);
else
info("%2u | " "%5u" " | " "%.*s", i, hist[i], bar, buf);
}
}
@ -156,5 +163,5 @@ void hist_dump(unsigned *hist, int length)
strncat(buf, tok, sizeof(buf)-strlen(buf));
}
info("hist = [ %s]", buf);
info("Matlab: hist = [ %s]", buf);
}