Robotran C Documentation
Functions
useful_functions.c File Reference
#include <limits.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "useful_functions.h"
#include "mbs_message.h"
#include "mbs_errors_names.h"

Functions

void * mbs_free (void *__ptr)
 Free the pointor ptr and set it to NULL. More...
 
void mbs_log (char *msg,...)
 Function for logging messages in a file called "log" where the program is executed. More...
 
double pow_int (double basis, int expo)
 compute efficiently pow with an integer exponent More...
 
int expo_ten_inf (double nb)
 get log with base 10 More...
 
double sign (double a)
 sign function More...
 
char * get_time_machine ()
 returns the current time as a String More...
 
char * get_char_vec (int size)
 create (with memory allocation) a vector (length l_v) of char More...
 
char ** get_char_tab (int nb_r, int nb_c)
 create (with memory allocation) a [nb_r times nb_c] matrix of chars WARNING: only the first dimension (nb_r) is allocated, pointing to NULL ! More...
 
void free_char_vec (char *vec)
 release memory for a vector of char More...
 
char * get_char_cpy (const char *fmt,...)
 Copy the provided formatted string into a newly allocated memory. More...
 
void free_char_tab (char **mat)
 release memory for a matrix of chars More...
 
double *** get_d3Darray_0 (int x, int y, int z)
 create (with memory allocation) a [x times y times z] 3D array of doubles, starting at index 0 More...
 
void free_d3Darray_0 (double ***array3D)
 release memory for a 3D array of doubles, starting at index 0 More...
 
int mbs_strcmp (const char *__s1, const char *__s2)
 Compare two char with strcmp. More...
 

Function Documentation

◆ expo_ten_inf()

int expo_ten_inf ( double  nb)

get log with base 10

Parameters
[in]nbnumber to compute the log
Returns
the exponent (base 10) -> log_10 (this is the inferior exponent)

◆ free_char_tab()

void free_char_tab ( char **  mat)

release memory for a matrix of chars

Parameters
[in]matmatrix of chars

◆ free_char_vec()

void free_char_vec ( char *  vec)

release memory for a vector of char

Parameters
[in]vecvector of chars

◆ free_d3Darray_0()

void free_d3Darray_0 ( double ***  array3D)

release memory for a 3D array of doubles, starting at index 0

Parameters
[in,out]array3D3D array of doubles

◆ get_char_cpy()

char* get_char_cpy ( const char *  fmt,
  ... 
)

Copy the provided formatted string into a newly allocated memory.

The caller is responsible to release the memory.

Parameters
fmtThe string to be formated and stored.
Returns
A pointer to the memory storing the formatted string.

◆ get_char_tab()

char** get_char_tab ( int  nb_r,
int  nb_c 
)

create (with memory allocation) a [nb_r times nb_c] matrix of chars WARNING: only the first dimension (nb_r) is allocated, pointing to NULL !

Parameters
[in]nb_r= nb of rows
[in]nb_c= nb of columns
Returns
requested matrix of chars

◆ get_char_vec()

char* get_char_vec ( int  l_v)

create (with memory allocation) a vector (length l_v) of char

Parameters
[in]l_v= size of the vector
Returns
requested vector of char

◆ get_d3Darray_0()

double*** get_d3Darray_0 ( int  nb_r,
int  nb_c,
int  z 
)

create (with memory allocation) a [x times y times z] 3D array of doubles, starting at index 0

Parameters
[in]xnb of first dimension
[in]nb_cnb of second dimension
[in]znb of third dimension
Returns
requested 3D array of doubles

◆ get_time_machine()

char* get_time_machine ( )

returns the current time as a String

source: http://en.wikipedia.org/wiki/C_date_and_time_functions

◆ mbs_free()

void* mbs_free ( void *  __ptr)

Free the pointor ptr and set it to NULL.

◆ mbs_log()

void mbs_log ( char *  msg,
  ... 
)

Function for logging messages in a file called "log" where the program is executed.

It is useful for debugging when the printf messages do not appear in the console (for instance in Simulink).

◆ mbs_strcmp()

int mbs_strcmp ( const char *  __s1,
const char *  __s2 
)

Compare two char with strcmp.

Parameters
[in]__s1The first char to compare.
[in]__s2The second char to compare.
Returns
Negative number in case of error, 0 otherwhise.

◆ pow_int()

double pow_int ( double  basis,
int  expo 
)

compute efficiently pow with an integer exponent

Parameters
[in]a= basis (double)
[in]b= exponent (integer)
Returns
a^b (same result as pow(a,b), except that b is a integer -> more efficient)

◆ sign()

double sign ( double  a)

sign function

Parameters
[in]ainput
Returns
1 if positive (or 0), -1 if negative