Commit 599b7076 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Add function to make simpple text graph for char, uchars and floats

parent 9ebb7c0d
......@@ -138,9 +138,6 @@ void blc_mems_fprint_graph_uchars(blc_mem *const *mems, int mems_nb, FILE *file,
*/
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
......
......@@ -155,6 +155,11 @@ void fscan_tsv_floats(FILE *file, float *values, int values_nb);
///Read tab separated uchars in the files and set values with the result.
void fscan_tsv_uchars(FILE *file, uchar *values, int values_nb);
void blc_fprint_char_graph(FILE *file, char *values, int values_nb, char const *title, int width, int height, int max, int min, char const* abscissa_name, char const* ordinate_name);
void blc_fprint_uchar_graph(FILE *file, uchar *values, int values_nb, char const *title, int width, int height, int max, int min, char const* abscissa_name, char const* ordinate_name);
void blc_fprint_float_graph(FILE *file, float *values, int values_nb, char const *title, int width, int height, float max, float min, char const* abscissa_name, char const* ordinate_name);
/**Display a surface graph of a 3D array in text mode ( tipically a image). If step0 and lenght0 = 1 it works with a 2D array.
The parameters are a bit complex, you are advised to use higher level functions like: blc_array::fprint_surface_uchars in C++
@param file where to put the graph usually stderr
......
......@@ -77,8 +77,6 @@ void blc_mem::append_text(char const *new_text)
append(new_text, strlen(new_text));
}
/* C wrapper */
START_EXTERN_C
void blc_mem::reset(int value){
memset(data, value, size);
......@@ -94,6 +92,8 @@ void blc_mem::fprint_graph_floats(FILE *file, char const *title, int height, flo
blc_mems_fprint_graph_floats(&this_mem, 1, file, &title, height, max, min, abscissa_name, ordinate_name);
}
START_EXTERN_C
void blc_mem_allocate(blc_mem *mem, size_t size){
mem->allocate(size);
}
......@@ -180,13 +180,21 @@ void blc_mems_fprint_graph_uchars(blc_mem *const*mems, int mems_nb, FILE *file,
}
static void fprint_graph_float_title(FILE *file, const char*title, float max, int width){
int i;
for (i = fprintf(file, "100%%(%.2f) [%s] ", max, title); i < width-1; ++i){
fputc('-', file);
}
fputc('|', file);
}
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, percent;
int j, graph_id, percent, standard_width;
float threhold, threhold1;
char c;
char vertical_arrow[] = "^|";
......@@ -199,11 +207,16 @@ void blc_mems_fprint_graph_floats(blc_mem *const*mems, int mems_nb, FILE *file,
range = max - min;
fprintf(file, "\n");
//Standard width
standard_width=0;
FOR(graph_id, mems_nb) standard_width+=mems[graph_id]->size/sizeof(float) * 3;
standard_width+=1;
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);
fprint_graph_float_title(file, titles[graph_id], max, mems[graph_id]->size/sizeof(float) * 3);
total_size+=mems[graph_id]->size;
fputc('|', file);
}
fprintf(file, "\n");
......@@ -247,4 +260,5 @@ void blc_mems_fprint_graph_floats(blc_mem *const*mems, int mems_nb, FILE *file,
}
END_EXTERN_C
......@@ -287,6 +287,185 @@ void fscan_tsv_uchars(FILE *file, uchar *values, int values_nb)
if (fscanf(file, "\n")!=0) EXIT_ON_ERROR("fscanf");
}
static void fprint_ordinate(FILE *file, const char* ordinate_name, int line){
}
void blc_fprint_char_graph(FILE *file, char *values, int values_nb, char const *title, int width, int height, int max, int min, char const* abscissa_name, char const* ordinate_name){
float width_ratio;
int range, value;
int percent;
int column, line;
float threhold, threhold1;
int i, display_values_nb;
char vertical_arrow[] = "^|";
//Size for the title
height-=3;
range = max - min;
//If width == -1 we take the size we need
if (width==-1) width = values_nb * 3+1;
display_values_nb=(width-1)/3;
if (display_values_nb > values_nb) display_values_nb=values_nb;
width_ratio=values_nb/(float)display_values_nb;
for (i = fprintf(file, "100%%(%.2d) [%s] ", max, title); i < width-1; ++i){
fputc('-', file);
}
fprintf(file, "\n");
FOR_INV(line, height){
if (line < strlen(vertical_arrow)) fputc(vertical_arrow[line], file);
else if ((ordinate_name) && (line < strlen(ordinate_name)+strlen(vertical_arrow))) fputc(ordinate_name[line-strlen(vertical_arrow)], file);
else fputc('|', file);
threhold = line * range / height;
threhold1 = (line+1) * range / height;
//We draw data
FOR(column, display_values_nb){
value = values[(int) (column * width_ratio)];
if (value - min > threhold1) fprintf(file, " []");
else if (value - min > threhold) {
percent=99 * (value - min) / range;
if (percent >= 100) percent=99;
fprintf(file, " %.2d", percent);
}
else fprintf(file, " ");
}
fprintf(file, "\n");
}
if (abscissa_name==NULL) abscissa_name="";
for (i = fprintf(file, " 0%%(%.3d) %s ", min, abscissa_name); i < width; ++i)
fputc('-', file);
fputc('>', file);
fprintf(file, "\n");
}
void blc_fprint_uchar_graph(FILE *file, uchar *values, int values_nb, char const *title, int width, int height, int max, int min, char const* abscissa_name, char const* ordinate_name){
float width_ratio;
int range, value;
int percent;
int column, line;
float threhold, threhold1;
int i, display_values_nb;
char vertical_arrow[] = "^|";
//Size for the title
height-=3;
range = max - min;
//If width == -1 we take the size we need
if (width==-1) width = values_nb * 3+1;
display_values_nb=(width-1)/3;
if (display_values_nb > values_nb) display_values_nb=values_nb;
width_ratio=values_nb/(float)display_values_nb;
for (i = fprintf(file, "100%%(%.2d) [%s] ", max, title); i < width-1; ++i){
fputc('-', file);
}
fprintf(file, "\n");
FOR_INV(line, height){
if (line < strlen(vertical_arrow)) fputc(vertical_arrow[line], file);
else if ((ordinate_name) && (line < strlen(ordinate_name)+strlen(vertical_arrow))) fputc(ordinate_name[line-strlen(vertical_arrow)], file);
else fputc('|', file);
threhold = line * range / height;
threhold1 = (line+1) * range / height;
//We draw data
FOR(column, display_values_nb){
value = values[(int) (column * width_ratio)];
if (value - min > threhold1) fprintf(file, " []");
else if (value - min > threhold) {
percent=99 * (value - min) / range;
if (percent >= 100) percent=99;
fprintf(file, " %.2d", percent);
}
else fprintf(file, " ");
}
fprintf(file, "\n");
}
if (abscissa_name==NULL) abscissa_name="";
for (i = fprintf(file, " 0%%(%.3d) %s ", min, abscissa_name); i < width; ++i)
fputc('-', file);
fputc('>', file);
fprintf(file, "\n");
}
void blc_fprint_float_graph(FILE *file, float *values, int values_nb, char const *title, int width, int height, float max, float min, char const* abscissa_name, char const* ordinate_name){
float width_ratio;
float range, value;
int percent;
int column, line;
float threhold, threhold1;
int i, display_values_nb;
char vertical_arrow[] = "^|";
//Size for the title
height-=3;
range = max - min;
//If width == -1 we take the size we need
if (width==-1) width=values_nb * 3+1;
display_values_nb=(width-1)/3;
if (display_values_nb > values_nb) display_values_nb=values_nb;
width_ratio=values_nb/(float)display_values_nb;
for (i = fprintf(file, "100%%(%.2f) [%s] ", max, title); i < width-1; ++i){
fputc('-', file);
}
fprintf(file, "\n");
FOR_INV(line, height){
if (line < strlen(vertical_arrow)) fputc(vertical_arrow[line], file);
else if ((ordinate_name) && (line < strlen(ordinate_name)+strlen(vertical_arrow))) fputc(ordinate_name[line-strlen(vertical_arrow)], file);
else fputc('|', file);
threhold = line * range / height;
threhold1 = (line+1) * range / height;
//We draw data
FOR(column, display_values_nb){
value = values[(int) (column * width_ratio)];
if (value - min > threhold1) fprintf(file, " []");
else if (value - min >= threhold) {
percent=99 * (value - min) / range;
if (percent >= 100) percent=99;
fprintf(file, " %.2d", percent);
}
else fprintf(file, " ");
}
fprintf(file, "\n");
}
if (abscissa_name==NULL) abscissa_name="";
for (i = fprintf(file, " 0%%(%.3f) %s ", min, abscissa_name); i < width; ++i)
fputc('-', file);
fputc('>', file);
fprintf(file, "\n");
}
void blc_fprint_3Darray(FILE *file, uchar *data, size_t size, int offset, int step0, int length0, int step1, int width, int step2, int height, int ansi_terminal)
{
char tmp_string[8];
......
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