Commit d004d058 authored by Sebastien Timmermans's avatar Sebastien Timmermans 🎹

[New] add error mngmnt in dirdyn, save files part, to be tested

parent ba27989b
Pipeline #4339 failed with stage
in 8 minutes and 44 seconds
......@@ -136,18 +136,34 @@ void mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data)
void mbs_dirdyn_save(MbsDirdyn* dd, MbsData *mbs_data, double t){
int i;
int i, err =0;
#ifdef VISU_3D
Simu_realtime *realtime;
Realtime_visu *visu;
#endif
for (i=0 ; i < dd->bufferNb ; i++){
mbs_buffer_save(dd->buffers[i], t, dd->savedArrays[i]);
err = mbs_buffer_save(dd->buffers[i], t, dd->savedArrays[i]);
}
if (err < 0)
{
mbs_msg(">>DIRDYN>> ***** mbs_dirdyn_save : impossible to save the files *****\n");
mbs_msg(">>DIRDYN>> ***** during buffer save *****\n");
mbs_msg(">>DIRDYN>>\n");
mbs_error_msg("[%d] in mbs_fct_dirdyn !! \n", -400 + err);
}
mbs_growing_buffer_save(dd->user_buffer, t);
if (err < 0)
{
mbs_msg(">>DIRDYN>> ***** mbs_dirdyn_save : impossible to save the files *****\n");
mbs_msg(">>DIRDYN>> ***** during growing buffer save *****\n");
mbs_msg(">>DIRDYN>>\n");
mbs_error_msg("[%d] in mbs_fct_dirdyn !! \n", -400 + err);
}
if (dd->options->save_visu)
{
#ifdef VISU_3D
......@@ -581,11 +597,12 @@ void mbs_dirdyn_finish(MbsDirdyn* dd, MbsData* mbs_data){
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void mbs_dirdyn_write_buffers(MbsDirdyn* dd){
int mbs_dirdyn_write_buffers(MbsDirdyn* dd){
int i;
for (i=0 ; i < dd->bufferNb ; i++){
mbs_buffer_write(dd->buffers[i]);
}
return mbs_buffer_write(dd->buffers[i]);
}
return 0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
......
......@@ -124,8 +124,9 @@ void mbs_delete_dirdyn(MbsDirdyn* dirdyn, MbsData* mbs_data);
* python.
*
* \p dd the MbsDirdyn struct for which the buffers must be written
* \return error (0 if no error)
*/
void mbs_dirdyn_write_buffers(MbsDirdyn* dd);
int mbs_dirdyn_write_buffers(MbsDirdyn* dd);
/*! \brief direct dynamics derivative computation
*
......
......@@ -178,9 +178,9 @@ void mbs_delete_growing_buffer(MbsGrowingBuffer *b)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void mbs_buffer_save(MbsBuffer* b, double t, double *x){
int mbs_buffer_save(MbsBuffer* b, double t, double *x){
int i;
int i, err =0;
// save time
b->tx[TIME_ID(b->index)] = t;
......@@ -197,8 +197,13 @@ void mbs_buffer_save(MbsBuffer* b, double t, double *x){
if(b->index == b->size){
// write the buffer to file
mbs_buffer_write(b);
err = mbs_buffer_write(b);
if (err < 0)
{
return err;
}
// save last values added
b->last_t = t;
......@@ -209,12 +214,13 @@ void mbs_buffer_save(MbsBuffer* b, double t, double *x){
// reset the buffer index to start of the buffer (next save will overide old values)
b->index = 0;
}
return 0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void mbs_growing_buffer_save(MbsGrowingBuffer* b, double t)
int mbs_growing_buffer_save(MbsGrowingBuffer* b, double t)
{
int i, j;
int index, nb_new, cur_nx;
......@@ -246,8 +252,8 @@ void mbs_growing_buffer_save(MbsGrowingBuffer* b, double t)
if(fid == NULL)
{
mbs_error_msg("in mbs_buffer_save: cannot open file '%s'\n", b->names[i]);
exit(EXIT_FAILURE);
mbs_msg("\t >BUFFER SAVE> Error: in mbs_buffer_save: cannot open file '%s'\n", b->names[i]);
return -8;
}
else
{
......@@ -268,9 +274,9 @@ void mbs_growing_buffer_save(MbsGrowingBuffer* b, double t)
if (b->nx != get_output_nb())
{
printf("%d, %d\n", b->nx, get_output_nb());
printf("Error: number of user inputs not the same as in the auto-output structure! \n");
exit(EXIT_FAILURE);
mbs_msg("\t >BUFFER SAVE> %d, %d\n", b->nx, get_output_nb());
mbs_msg("\t >BUFFER SAVE> Error: number of user inputs not the same as in the auto-output structure! \n");
return -8;
}
}
......@@ -297,21 +303,22 @@ void mbs_growing_buffer_save(MbsGrowingBuffer* b, double t)
// reset the buffer index to start of the buffer (next save will overide old values)
b->index = 0;
}
return 0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void mbs_buffer_write(MbsBuffer* b){
int mbs_buffer_write(MbsBuffer* b){
int i, j;
int i, j, err =0;
FILE* fid;
// Open the file associated to the buffer
fid = fopen(b->filename, "a");
if(fid == NULL)
{
mbs_error_msg("in mbs_buffer_save: cannot open file '%s'\n", b->filename);
return;
mbs_msg("\t >BUFFER WRITE> in mbs_buffer_save: cannot open file '%s'\n", b->filename);
return -9;
}
for (i=0; i<b->index; i++){
......@@ -330,16 +337,17 @@ void mbs_buffer_write(MbsBuffer* b){
// special case for .anim file
if ( (b->anim->save_anim && (b->id == BUFFER_Q)) || (b->anim->save_visu && (b->id == BUFFER_VISU)) )
{
mbs_anim_write(b);
err = mbs_anim_write(b);
}
// first print done
b->flag_no_print = 0;
return err;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void mbs_anim_write(MbsBuffer* b)
int mbs_anim_write(MbsBuffer* b)
{
int i;
int next_index;
......@@ -353,15 +361,15 @@ void mbs_anim_write(MbsBuffer* b)
if(fid == NULL)
{
mbs_error_msg("in mbs_buffer_save: cannot open file '%s'\n", b->anim->filename);
return;
mbs_error_msg("\t >ANIM WRITE>in mbs_anim_write: cannot open file '%s'\n", b->anim->filename);
return -9;
}
// safety
if (b->index < 1)
{
fclose(fid);
return;
return 0;
}
// period
......@@ -382,7 +390,7 @@ void mbs_anim_write(MbsBuffer* b)
if (b->index < 2)
{
fclose(fid);
return;
return 0;
}
cur_t = b->tx[TIME_ID(0)] + anim_period;
......@@ -463,7 +471,7 @@ void mbs_anim_write(MbsBuffer* b)
{
b->anim->last_print_t = print_t;
fclose(fid);
return;
return 0;
}
prev_t = next_t;
......@@ -476,6 +484,7 @@ void mbs_anim_write(MbsBuffer* b)
// close file
fclose(fid);
return 0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
......
......@@ -146,8 +146,9 @@ void mbs_delete_growing_buffer(MbsGrowingBuffer *b);
* @param t the corresponding time [s]
* @param x the array to save (value are copied)
*
* \return error (0 if no error)
*/
void mbs_buffer_save(MbsBuffer* b, double t, double *x);
int mbs_buffer_save(MbsBuffer* b, double t, double *x);
/**
* Save the given values of auto_output to the specified buffer with the specified time.
......@@ -157,8 +158,10 @@ void mbs_buffer_save(MbsBuffer* b, double t, double *x);
*
* 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.
*
* \return error (0 if no error)
*/
void mbs_growing_buffer_save(MbsGrowingBuffer* b, double t);
int mbs_growing_buffer_save(MbsGrowingBuffer* b, double t);
/**
......@@ -166,13 +169,15 @@ void mbs_growing_buffer_save(MbsGrowingBuffer* b, double t);
* buffer for line 0 to line index-1 are appended to the file
* associated with this buffer.
*
* \return error (0 if no error)
*/
void mbs_buffer_write(MbsBuffer* b);
int mbs_buffer_write(MbsBuffer* b);
/**
* Write the content of the q buffer as anim file to the disk.
* \return error (0 if no error)
*/
void mbs_anim_write(MbsBuffer* b);
int mbs_anim_write(MbsBuffer* b);
/*! \brief write the content of the growing buffer to disk
*
......
Markdown is supported
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