Commit 7ff821fd authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Add text graph for floats

parent f10f565b
......@@ -82,7 +82,17 @@ typedef struct blc_mem {
@param ordinate_name text displayed in ordonate
*/
void fprint_graph_uchars(FILE *file, char const *title, int height, int max=255, int min=0, char const* abscissa_name=NULL, char const* ordinate_name = NULL);
/** Draw text only the graph usually on a terminal based on the float data.
@param file ouptut where to graph (usually stderr)
@param title title of the graph
@param height height of the text graph in lines of text
@param max top value drawn. It is in this order (max first) to avoid to set min when it is 0
@param min is the bottom value drawn
@param abscissa_name text displayed in the abscissa. It as to be the same for all graphs
@param ordinate_name text displayed in ordonate
*/
void fprint_graph_floats(FILE *file, char const *title, int height, float max=1.0f, float min=0.f, char const* abscissa_name=NULL, char const* ordinate_name = NULL);
#endif
}blc_mem;
......@@ -114,6 +124,23 @@ void blc_mem_append(blc_mem *mem, char const* data, size_t size);
*/
void blc_mems_fprint_graph_uchars(blc_mem *const *mems, int mems_nb, FILE *file, char const *const* titles, int height, int max, int min, char const* abscissa_name, char const* ordinate_name );
/// Draw text graphs usually on the terminal based and blc_mems uchars.
/**
@param mems pointer to an array of blc_mem to graph
@param mems_nb number of blc_mems to graph
@param file ouptut where to graph (usually stderr)
@param titles array of graph titles
@param height height of the text graph in lines of text
@param max top value drawn. It is in this order (max first) to be consistent with c++ version
@param min is the bottom value drawn
@param abscissa_name text displayed in the abscissa. It as to be the same for all graphs
@param ordinate_name text displayed in ordonate
*/
void blc_mems_fprint_graph_floats(blc_mem *const *mems, int mems_nb, FILE *file, char const *const* titles, int height, float max, float min, char const* abscissa_name, char const* ordinate_name );
END_EXTERN_C
//@}
#endif
......
......@@ -26,8 +26,6 @@ Blc core is composed of these five modules (one file each):
*/
#ifndef BLC_TEXT_H
#define BLC_TEXT_H
......@@ -36,7 +34,6 @@ Blc core is composed of these five modules (one file each):
#include "blc_tools.h"
#include "blc_mem.h"
/**
@defgroup blc_text blc_text
@{
......
......@@ -89,6 +89,11 @@ void blc_mem::fprint_graph_uchars(FILE *file, char const *title, int height, int
blc_mems_fprint_graph_uchars(&this_mem, 1, file, &title, height, max, min, abscissa_name, ordinate_name);
}
void blc_mem::fprint_graph_floats(FILE *file, char const *title, int height, float max, float min, char const* abscissa_name, char const* ordinate_name ){
blc_mem *this_mem=this; //This does not support &
blc_mems_fprint_graph_floats(&this_mem, 1, file, &title, height, max, min, abscissa_name, ordinate_name);
}
void blc_mem_allocate(blc_mem *mem, size_t size){
mem->allocate(size);
}
......@@ -173,4 +178,71 @@ void blc_mems_fprint_graph_uchars(blc_mem *const*mems, int mems_nb, FILE *file,
fprintf(file, "\n");
}
void blc_mems_fprint_graph_floats(blc_mem *const*mems, int mems_nb, FILE *file, char const * const *titles, int height, float max, float min, char const* abscissa_name, char const* ordinate_name ){
float value;
size_t i, total_size = 0;
float range;
int ordinate_name_length, ordinate_name_position;
int j, graph_id;
float threhold, threhold1;
char c;
char vertical_arrow[] = "^|";
ordinate_name_position = - strlen(vertical_arrow);
if (ordinate_name != NULL) ordinate_name_length = strlen(ordinate_name);
else ordinate_name_length = 0;
height-=3;
range = max - min;
fprintf(file, "\n");
FOR(graph_id, mems_nb){
for (i = fprintf(file, "100%%(%.2f) [%s] ", max, titles[graph_id]); i < mems[graph_id]->size/sizeof(float) * 3; ++i) fputc('-', file);
total_size+=mems[graph_id]->size;
fputc('|', file);
}
fprintf(file, "\n");
FOR_INV(j, height){
threhold = j * range / height;
threhold1 = (j+1) * range / height;
if (ordinate_name_position < 0){
c = vertical_arrow[strlen(vertical_arrow) + ordinate_name_position];
ordinate_name_position++;
}
else if (ordinate_name_position != ordinate_name_length){
c = ordinate_name[ordinate_name_position];
ordinate_name_position++;
}
else c = '|';
FOR(graph_id, mems_nb){
fputc(c, file);
FOR(i, mems[graph_id]->size/sizeof(float)){
value = mems[graph_id]->floats[i];
if (value - min > threhold1) fprintf(file, " []");
else if (value - min >= threhold) {
fprintf(file, " %.2d", (int)(99 * (value - min) / range));
}
else fprintf(file, " ");
}
}
fprintf(file, "\n");
}
FOR(graph_id, mems_nb){
if (abscissa_name==NULL) abscissa_name="";
for (i = fprintf(file, " 0%%(%.3f) %s ", min, abscissa_name); i < mems[graph_id]->size/sizeof(float) * 3; ++i)
fputc('-', file);
fputc('>', file);
}
fprintf(file, "\n");
}
END_EXTERN_C
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment