Robotran C Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Functions
mbs_buffer.c File Reference
#include "mbs_buffer.h"
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "set_output.h"
#include "mbs_message.h"
#include "useful_functions.h"
#include "mbs_errors_names.h"

Macros

#define TIME_ID(i)   ((i)*(b->nx+1))
 Macro to get the id in tx array corresponding to index (assuming b->nx exist) More...
 

Functions

MbsBuffermbs_new_buffer (char *filename, char *anim_name, int nx, int size, int id, char *buf_format, int save_anim, int save_visu, double anim_period, int saving_mode, int *indices_to_print, char **labels, int flag_custom_labels)
 Allocate and initialize a MbsBuffer structure. More...
 
MbsGrowingBuffermbs_new_growing_buffer (int max_nx, int size, const char *respath, int saving_mode)
 create a new growing buffer for the user inputs to save More...
 
void mbs_delete_buffer (MbsBuffer *b)
 Free memory of the specified MbsBuffer. More...
 
void mbs_delete_growing_buffer (MbsGrowingBuffer *b)
 release memory for growing buffer More...
 
int mbs_buffer_save (MbsBuffer *b, double t, double *x)
 Save the given array to the specified buffer with the specified time. More...
 
int mbs_growing_buffer_save (MbsGrowingBuffer *b, double t)
 Save the given values of auto_output to the specified buffer with the specified time. More...
 
int mbs_buffer_write (MbsBuffer *b)
 Write the content of the buffer to disk. More...
 
int mbs_anim_write (MbsBuffer *b)
 Write the content of the q buffer as anim file to the disk. More...
 
int mbs_growing_buffer_write (MbsGrowingBuffer *b)
 write the content of the growing buffer to disk More...
 

Detailed Description

Implements function defined in mbs_buffer.h

Author
Nicolas Docquier

(c) Universite catholique de Louvain

Macro Definition Documentation

◆ TIME_ID

#define TIME_ID (   i)    ((i)*(b->nx+1))

Macro to get the id in tx array corresponding to index (assuming b->nx exist)

Function Documentation

◆ mbs_anim_write()

int mbs_anim_write ( MbsBuffer b)

Write the content of the q buffer as anim file to the disk.

Returns
error (0 if no error)

◆ mbs_buffer_save()

int mbs_buffer_save ( MbsBuffer b,
double  t,
double *  x 
)

Save the given array to the specified buffer with the specified time.

The content of the buffer is automatically written to the associated file when the buffer is full. The buffer index is then reset to 0.

Parameters
bthe buffer in which to store
tthe corresponding time [s]
xthe array to save (value are copied)
Returns
error (0 if no error)

◆ mbs_buffer_write()

int mbs_buffer_write ( MbsBuffer b)

Write the content of the buffer to disk.

Values contained in the buffer for line 0 to line index-1 are appended to the file associated with this buffer.

Returns
error (0 if no error)

◆ mbs_delete_buffer()

void mbs_delete_buffer ( MbsBuffer b)

Free memory of the specified MbsBuffer.

◆ mbs_delete_growing_buffer()

void mbs_delete_growing_buffer ( MbsGrowingBuffer b)

release memory for growing buffer

Parameters
[out]bgrowing buffer to release

◆ mbs_growing_buffer_save()

int mbs_growing_buffer_save ( MbsGrowingBuffer b,
double  t 
)

Save the given values of auto_output to the specified buffer with the specified time.

Parameters
[in,out]bthe growing buffer in which to store
[in]tthe corresponding time [s]

The content of the buffer is automatically written to the associated file when the buffer is full. The buffer index is then reset to 0.

Returns
error (0 if no error)

◆ mbs_growing_buffer_write()

int mbs_growing_buffer_write ( MbsGrowingBuffer b)

write the content of the growing buffer to disk

Parameters
[in]bgrowing buffer
Returns
error (0 if no error)

◆ mbs_new_buffer()

MbsBuffer* mbs_new_buffer ( char *  filename,
char *  anim_name,
int  nx,
int  size,
int  id,
char *  buf_format,
int  save_anim,
int  save_visu,
double  anim_period,
int  saving_mode,
int *  indices_to_print,
char **  labels,
int  flag_custom_label 
)

Allocate and initialize a MbsBuffer structure.

The associated text file defined by filename is (re-)initialized

Parameters
[in]filenamethe name of the file associated to this buffer
[in]anim_namethe name of the file associated to the animation file (only used for BUFFER_Q)
[in]nxthe size of the array to be tracked by this buffer
[in]sizethe size of the buffer
[in]idthe buffer ID, see BUFFER_Q, BUFFER_QD ...
[in]formatof the buffer (if NULL, "%e" is used)
[in]save_anim1 to save the anim file, 0 otherwise
[in]save_visu1 to save the visualization file (as it appears in 'user_realtime_visu.c'), 0 otherwise (for real-time simulation)
[in]anim_periodtime interval between two recorded values in the animation file
[in]saving_modemode of saving res file. 1 is the old (blank space), 2 is the new (semi columns with header line). Default is 1 @params[in] indices_to_print containing the indices to print. NULL if every indice must be printed. start with 0 means nothing is printed (but file is created on the disk) @params[in] labels containing the names of the labels to print. Only used if indices_to_print is NON NULL. In this case, first line of the file contain the label and the indexes. if label is NULL, nothing is printed. @params[in] flag_custom_label flag to indicate to use custom labels. Only used if indices_to_print is NON NULL. In this case, first line of the file contain the label and the indexes. if label is NULL, default prefix is used (q, qd, ...).

◆ mbs_new_growing_buffer()

MbsGrowingBuffer* mbs_new_growing_buffer ( int  max_nx,
int  size,
const char *  respath,
int  saving_mode 
)

create a new growing buffer for the user inputs to save

Parameters
[in]max_nxmaximum number of user inputs to save
[in]sizesize of the buffer
[in]respathpath to the file for the results
[in]saving_modemode of saving res file. 1 is the old (blank space), 2 is the new (semi columns with header line). Default is 1
Returns
new growing buffer initialized, NULL in case of error