README.md 3.09 KB
Newer Older
1
BLC core : Core of Basic Libraries for C/C++ 
Arnaud Blanchard's avatar
Arnaud Blanchard committed
2
============================================
Arnaud Blanchard's avatar
Arnaud Blanchard committed
3

Arnaud Blanchard's avatar
Arnaud Blanchard committed
4
Core functions used by almost all the projects of BLAAR
Arnaud Blanchard's avatar
Arnaud Blanchard committed
5

Arnaud Blanchard's avatar
Arnaud Blanchard committed
6
It is composed of five main files for Linux and Mac OSX.
Arnaud Blanchard's avatar
Arnaud Blanchard committed
7

Arnaud Blanchard's avatar
Arnaud Blanchard committed
8
9
10
11
12
- **[blc_text](include/blc_text.h)** manage ASCII terminals (colors, cursor, sizes)
- **[blc_tools](include/blc_tools.h)** macros and functions to simplify coding and memory management
- **[blc_mem](include/blc_mem.h)** a memory structure (data pointer and size) essentially to manage dynamic memory buffers
- **[blc_array](include/blc_array.h)** a structure to manage n-dimensional arrays. It also manage type and format of the data
- **[blc_realtime](include/blc_realtime.h)** few helpers to use time, POSIX semaphore and pthreads
Arnaud Blanchard's avatar
Arnaud Blanchard committed
13

Arnaud Blanchard's avatar
Arnaud Blanchard committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

Install
=======

This library is installed with any configuration of blaar. However, independently of blaar, you can [manually build the library](INSTALL.md)

Tutorials
=========

Exemple of simple text functions
===============================

```c
 #include "blc_core.h"

 int main(int argc, char **argv){
    int rows_nb, columns_nb;
    float values[3]={1.3, 4.2, 5.5};
 
    color_printf(BLC_BLUE, "\nWriting in blue\n\n");
    underline_printf('=', "Writing with inlining with '='");
//printing 3 floats of the array values
    fprint_tsv_floats(stderr, values, 3);
//Getting the size in characters of the current terminal
    blc_terminal_get_size(&columns_nb, &rows_nb);
    printf("\nSize of the terminal  %dx%d\n", columns_nb, rows_nb);
//Writing size in human readable format
    fprint_human_size(stdout, 1000456670); //1Kb = 1024b
    printf("\n");
    return EXIT_SUCCESS;
 }
```

Exemple of text graphs
======================

Arnaud Blanchard's avatar
Arnaud Blanchard committed
50
This is the output of **blc_core/t_array** see the [code](blob/master/t_array/main.cpp) and the [cmake config file](blob/master/t_array/CMakeLists.txt)
Arnaud Blanchard's avatar
Arnaud Blanchard committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

### Manipulating **blc_array** vector

You can modify the code to dynamically refresh the graph with something like:

```c++
...
//We display 100 times the graph with the sinusoid shifted each time
for(shift =0;  shift <100; shift ++){
   // We set a sinusoid in the vector (converting [-1f, 1f] -> [0, 255]) and we  shift it
   for(i=0; i!=vector.size; i++) vector.uchars[i]=128+127*sinf(i/2.f+ shift);
   //If it is not the first time we erase the previous graph by putting back (ANSI escape code) the cursor 16 lines (height of the graph) up. 'sprint' stand for fprint on stderr
   if (shift != 0) blc_eprint_cursor_up(16); //blc_text.h function
   /*We graph the vector, with title "vector test", the height of 16 chars, the limit max 256 and limit min 0.
   Text on abscissa "position" and text on ordinate "intensity"*/
   vector.fprint_graph_uchars(stderr, "Vector test", 16, 256, 0, "position", "intensity");
   //We stop 100ms to let time to the user to see the graph.
   usleep(100000);
}
...
```
Which produces :
![blc_core sinusoid video](http://www.etis.ensea.fr/neurocyber/blaar/videos/blc_core_sinusoid.mp4)

Manipulating **blc_array** 2D matrix
==============================

Arnaud Blanchard's avatar
Arnaud Blanchard committed
78
![image not yet accessible](/uploads/fbdcda2237070183dcdc6ef813b1fb1c/t_array_2.png)
Arnaud Blanchard's avatar
Arnaud Blanchard committed
79
80
81
82

These displays could be dynamical as well