MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
ExtFileHandlerEDGE Class Reference

#include <extedge.h>

Inheritance diagram for ExtFileHandlerEDGE:
Collaboration diagram for ExtFileHandlerEDGE:

Public Member Functions

 ExtFileHandlerEDGE (std::string &fflagname, std::string &fdataname, mbsleep_t SleepTime, std::streamsize Precision)
 
 ~ExtFileHandlerEDGE (void)
 
virtual bool Prepare_pre (void)
 
virtual void Prepare_post (bool ok)
 
virtual void AfterPredict (void)
 
virtual bool Send_pre (SendWhen when)
 
virtual void Send_post (SendWhen when)
 
virtual bool Recv_pre (void)
 
virtual bool Recv_post (void)
 
virtual std::ostream * GetOutStream (void)
 
virtual std::istream * GetInStream (void)
 
- Public Member Functions inherited from ExtFileHandlerBase
 ExtFileHandlerBase (mbsleep_t SleepTime, std::streamsize Precision)
 
virtual ~ExtFileHandlerBase (void)
 
virtual Negotiate NegotiateRequest (void) const
 
virtual int GetOutFileDes (void)
 
virtual int GetSendFlags (void) const
 
virtual int GetInFileDes (void)
 
virtual int GetRecvFlags (void) const
 

Protected Types

enum  EDGEcmd {
  EDGE_UNKNOWN = -1, EDGE_INITIALIZING = 0, EDGE_BUSY = 1, EDGE_READ_READY = 2,
  EDGE_MBDYN_WRITE_DONE = 3, EDGE_GOTO_NEXT_STEP = 4, EDGE_QUIT = 5, EDGE_LAST
}
 

Protected Member Functions

const char * EDGEcmd2str (int cmd) const
 
EDGEcmd CheckFlag (int &cnt)
 
void SendFlag (EDGEcmd cmd)
 

Protected Attributes

std::string fflagname
 
std::string fdataname
 
bool bReadForces
 
std::ifstream infile
 
std::ofstream outfile
 
- Protected Attributes inherited from ExtFileHandlerBase
std::streamsize Precision
 
mbsleep_t SleepTime
 
bool bOK
 

Additional Inherited Members

- Public Types inherited from ExtFileHandlerBase
enum  SendWhen { SEND_FIRST_TIME, SEND_REGULAR, SEND_AFTER_CONVERGENCE }
 
enum  Negotiate { NEGOTIATE_NO, NEGOTIATE_CLIENT, NEGOTIATE_SERVER }
 
enum  OutputFlags {
  OUTPUT_KIN = 0x1000, OUTPUT_DYN = 0x2000, OUTPUT_REF = 0x4000, OUTPUT_REF_KIN = (OUTPUT_REF | OUTPUT_KIN),
  OUTPUT_REF_DYN = (OUTPUT_REF | OUTPUT_DYN)
}
 

Detailed Description

Definition at line 41 of file extedge.h.

Member Enumeration Documentation

Enumerator
EDGE_UNKNOWN 
EDGE_INITIALIZING 
EDGE_BUSY 
EDGE_READ_READY 
EDGE_MBDYN_WRITE_DONE 
EDGE_GOTO_NEXT_STEP 
EDGE_QUIT 
EDGE_LAST 

Definition at line 49 of file extedge.h.

49  {
50  // ?
51  EDGE_UNKNOWN = -1,
52 
53  // EDGE is initializing; MBDyn waits
55 
56  // EDGE is busy; MBDyn waits
57  EDGE_BUSY = 1,
58 
59  // EDGE waits (is ready to read kinematics); MBDyn iterates
60  EDGE_READ_READY = 2,
61 
62  // EDGE is computing; MBDyn waits before reading forces
64 
65  // EDGE converged; MBDyn advances one step
67 
68  // EDGE wants to end simulation
69  EDGE_QUIT = 5,
70 
71  // must be the last one
72  EDGE_LAST
73  };

Constructor & Destructor Documentation

ExtFileHandlerEDGE::ExtFileHandlerEDGE ( std::string &  fflagname,
std::string &  fdataname,
mbsleep_t  SleepTime,
std::streamsize  Precision 
)

Definition at line 135 of file extedge.cc.

References NO_OP.

139 bReadForces(true)
140 {
141  NO_OP;
142 }
std::string fdataname
Definition: extedge.h:43
ExtFileHandlerBase(mbsleep_t SleepTime, std::streamsize Precision)
Definition: extforce.cc:50
#define NO_OP
Definition: myassert.h:74
std::string fflagname
Definition: extedge.h:43
std::streamsize Precision
Definition: extforce.h:75
mbsleep_t SleepTime
Definition: extforce.h:76
ExtFileHandlerEDGE::~ExtFileHandlerEDGE ( void  )

Definition at line 144 of file extedge.cc.

References CheckFlag(), EDGE_GOTO_NEXT_STEP, EDGE_QUIT, EDGE_READ_READY, and SendFlag().

145 {
146  int cnt = -1;
147  switch (CheckFlag(cnt)) {
148  case EDGE_READ_READY:
149  case EDGE_GOTO_NEXT_STEP:
151  break;
152 
153  default:
154  break;
155  }
156 }
void SendFlag(EDGEcmd cmd)
Definition: extedge.cc:509
EDGEcmd CheckFlag(int &cnt)
Definition: extedge.cc:179

Here is the call graph for this function:

Member Function Documentation

void ExtFileHandlerEDGE::AfterPredict ( void  )
virtual

Implements ExtFileHandlerBase.

Definition at line 574 of file extedge.cc.

References bReadForces.

575 {
576  bReadForces = true;
577 }
ExtFileHandlerEDGE::EDGEcmd ExtFileHandlerEDGE::CheckFlag ( int cnt)
protected

Definition at line 179 of file extedge.cc.

References buf, done, EDGE_QUIT, EDGEcmd2str(), fflagname, infile, MBDYN_EXCEPT_ARGS, mbdyn_stop_at_end_of_iteration(), mbedge_eat_field(), mbedge_eat_sep(), mbedge_goto_eol(), mbsleep(), ExtFileHandlerBase::SleepTime, and STRLENOF.

Referenced by Recv_pre(), Send_pre(), and ~ExtFileHandlerEDGE().

180 {
181  int cmd;
182  unsigned lineno = 0;
183 
184  cnt++;
185 
186  infile.open(fflagname.c_str());
187  if (!infile && cnt == -1) {
188  return EDGE_QUIT;
189  }
190 
191  // Needs tuning?
192  const int max_retries = 10;
193  int retrying = 0;
194 retry:;
195 
196  if (SleepTime > 0) {
197  // WARNING: loops forever
198  // add optional, configurable limit?
199  for (; !infile; cnt++) {
200  silent_cout("flag file \"" << fflagname.c_str() << "\" "
201  "missing, try #" << cnt << "; "
202  "sleeping " << SleepTime << " s" << std::endl);
204  cmd = EDGE_QUIT;
205  goto done;
206  }
207 
208  mbsleep(&SleepTime);
209 
210  infile.clear();
211  infile.open(fflagname.c_str());
212  }
213 
214  } else if (!infile) {
215  // error
216  silent_cerr("flag file \"" << fflagname.c_str() << "\" "
217  "missing" << std::endl);
219  }
220 
221  /*
222  UPDATE,N,0,0,1
223  FLAG,I,1,1,0
224  <flag value>
225  */
226 
227  // old syntax without this block
228  while (true) {
229  char buf[BUFSIZ], *p;
230  if (mbedge_goto_eol(infile, buf, sizeof(buf))) {
231  if (!infile) {
232  break;
233  }
234  }
235 
236  lineno++;
237 
238  if (buf[0] == '*') {
239  continue;
240  }
241 
242  if (strncasecmp(buf, "UPDATE", STRLENOF("UPDATE")) == 0) {
243  size_t buflen = sizeof(buf) - STRLENOF("UPDATE");
244  p = &buf[0] + STRLENOF("UPDATE");
245 
246  p = mbedge_eat_sep(p, buflen);
247  if (p == 0) {
248  silent_cerr("ExtFileHandlerEDGE: unable to skip separator "
249  "at line=" << lineno << ", \"" << &buf[sizeof(buf) - buflen] << "\"" << std::endl);
250  if (retrying < max_retries) {
251  retrying++;
252  goto retry;
253  }
255  }
256 
257  p = mbedge_eat_field(p, buflen, "N");
258  if (p == 0) {
259  silent_cerr("ExtFileHandlerEDGE: unable to skip field \"N\" "
260  "at line=" << lineno << ", \"" << &buf[sizeof(buf) - buflen] << "\"" << std::endl);
261  if (retrying < max_retries) {
262  retrying++;
263  goto retry;
264  }
266  }
267 
268  p = mbedge_eat_sep(p, buflen);
269  if (p == 0) {
270  silent_cerr("ExtFileHandlerEDGE: unable to skip separator "
271  "at line=" << lineno << ", \"" << &buf[sizeof(buf) - buflen] << "\"" << std::endl);
272  if (retrying < max_retries) {
273  retrying++;
274  goto retry;
275  }
277  }
278 
279  p = mbedge_eat_field(p, buflen, "0");
280  if (p == 0) {
281  silent_cerr("ExtFileHandlerEDGE: unable to skip field \"0\" "
282  "at line=" << lineno << ", \"" << &buf[sizeof(buf) - buflen] << "\"" << std::endl);
283  if (retrying < max_retries) {
284  retrying++;
285  goto retry;
286  }
288  }
289 
290  p = mbedge_eat_sep(p, buflen);
291  if (p == 0) {
292  silent_cerr("ExtFileHandlerEDGE: unable to skip separator "
293  "at line=" << lineno << ", \"" << &buf[sizeof(buf) - buflen] << "\"" << std::endl);
294  if (retrying < max_retries) {
295  retrying++;
296  goto retry;
297  }
299  }
300 
301  p = mbedge_eat_field(p, buflen, "0");
302  if (p == 0) {
303  silent_cerr("ExtFileHandlerEDGE: unable to skip field \"0\" "
304  "at line=" << lineno << ", \"" << &buf[sizeof(buf) - buflen] << "\"" << std::endl);
305  if (retrying < max_retries) {
306  retrying++;
307  goto retry;
308  }
310  }
311 
312  p = mbedge_eat_sep(p, buflen);
313  if (p == 0) {
314  silent_cerr("ExtFileHandlerEDGE: unable to skip separator "
315  "at line=" << lineno << ", \"" << &buf[sizeof(buf) - buflen] << "\"" << std::endl);
316  if (retrying < max_retries) {
317  retrying++;
318  goto retry;
319  }
321  }
322 
323  p = mbedge_eat_field(p, buflen, "1");
324  if (p == 0) {
325  silent_cerr("ExtFileHandlerEDGE: unable to skip field \"1\" "
326  "at line=" << lineno << ", \"" << &buf[sizeof(buf) - buflen] << "\"" << std::endl);
327  if (retrying < max_retries) {
328  retrying++;
329  goto retry;
330  }
332  }
333 
334  p = mbedge_eat_sep(p, buflen);
335  if (p == 0) {
336  silent_cerr("ExtRigidForceEDGE: unable to skip separator "
337  "at line=" << lineno << ", \"" << &buf[sizeof(buf) - buflen] << "\"" << std::endl);
338  if (retrying < max_retries) {
339  retrying++;
340  goto retry;
341  }
343  }
344 
345  if (p[0] != '\0' && p[0] != '\n') {
346  silent_cerr("ExtRigidForceEDGE: no line terminator "
347  "at line=" << lineno << ", \"" << p << "\"" << std::endl);
348  if (retrying < max_retries) {
349  retrying++;
350  goto retry;
351  }
353  }
354 
355  if (mbedge_goto_eol(infile, buf, sizeof(buf))) {
356  silent_cerr("ExtRigidForceEDGE: unable to get \"FLAG\" line "
357  "at line=" << lineno << ", \"" << p << "\"" << std::endl);
358  if (retrying < max_retries) {
359  retrying++;
360  goto retry;
361  }
363  }
364 
365  lineno++;
366 
367  if (strncasecmp(buf, "FLAG", STRLENOF("FLAG")) != 0) {
368  silent_cerr("ExtRigidForceEDGE: \"FLAG\" line expected "
369  "at line=" << lineno << ", \"" << p << "\"" << std::endl);
370  if (retrying < max_retries) {
371  retrying++;
372  goto retry;
373  }
375  }
376 
377  buflen = sizeof(buf) - STRLENOF("FLAG");
378  p = &buf[0] + STRLENOF("FLAG");
379 
380  p = mbedge_eat_sep(p, buflen);
381  if (p == 0) {
382  silent_cerr("ExtFileHandlerEDGE: unable to skip separator "
383  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
384  if (retrying < max_retries) {
385  retrying++;
386  goto retry;
387  }
389  }
390 
391  p = mbedge_eat_field(p, buflen, "I");
392  if (p == 0) {
393  silent_cerr("ExtFileHandlerEDGE: unable to skip field \"I\" "
394  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
395  if (retrying < max_retries) {
396  retrying++;
397  goto retry;
398  }
400  }
401 
402  p = mbedge_eat_sep(p, buflen);
403  if (p == 0) {
404  silent_cerr("ExtFileHandlerEDGE: unable to skip separator "
405  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
406  if (retrying < max_retries) {
407  retrying++;
408  goto retry;
409  }
411  }
412 
413  p = mbedge_eat_field(p, buflen, "1");
414  if (p == 0) {
415  silent_cerr("ExtFileHandlerEDGE: unable to skip field \"1\" "
416  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
417  if (retrying < max_retries) {
418  retrying++;
419  goto retry;
420  }
422  }
423 
424  p = mbedge_eat_sep(p, buflen);
425  if (p == 0) {
426  silent_cerr("ExtFileHandlerEDGE: unable to skip separator "
427  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
428  if (retrying < max_retries) {
429  retrying++;
430  goto retry;
431  }
433  }
434 
435  p = mbedge_eat_field(p, buflen, "1");
436  if (p == 0) {
437  silent_cerr("ExtFileHandlerEDGE: unable to skip field \"1\" "
438  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
439  if (retrying < max_retries) {
440  retrying++;
441  goto retry;
442  }
444  }
445 
446  p = mbedge_eat_sep(p, buflen);
447  if (p == 0) {
448  silent_cerr("ExtFileHandlerEDGE: unable to skip separator "
449  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
450  if (retrying < max_retries) {
451  retrying++;
452  goto retry;
453  }
455  }
456 
457  p = mbedge_eat_field(p, buflen, "0");
458  if (p == 0) {
459  silent_cerr("ExtFileHandlerEDGE: unable to skip field \"0\" "
460  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
461  if (retrying < max_retries) {
462  retrying++;
463  goto retry;
464  }
466  }
467 
468  p = mbedge_eat_sep(p, buflen);
469  if (p == 0) {
470  silent_cerr("ExtRigidForceEDGE: unable to skip separator "
471  "at line=" << lineno << ", \"" << buf[sizeof(buf) - buflen] << "\"" << std::endl);
472  if (retrying < max_retries) {
473  retrying++;
474  goto retry;
475  }
477  }
478 
479  if (p[0] != '\0' && p[0] != '\n') {
480  silent_cerr("ExtRigidForceEDGE: no line terminator "
481  "at line=" << lineno << ", \"" << p << "\"" << std::endl);
482  if (retrying < max_retries) {
483  retrying++;
484  goto retry;
485  }
487  }
488 
489  lineno++;
490 
491  break;
492  }
493  }
494 
495  infile >> cmd;
496 
497 done:;
498  silent_cerr("<<< checking flag file \"" << fflagname.c_str() << "\": "
499  "cmd=" << cmd << " (" << EDGEcmd2str(cmd) << ")"
500  << std::endl);
501 
502  infile.close();
503  infile.clear();
504 
505  return EDGEcmd(cmd);
506 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const char * EDGEcmd2str(int cmd) const
Definition: extedge.cc:169
int mbsleep(const mbsleep_t *t)
Definition: mbsleep.c:90
char * mbedge_eat_sep(char *buf, size_t &buflen)
Definition: extedge.cc:74
int mbdyn_stop_at_end_of_iteration(void)
Definition: solver.cc:172
std::string fflagname
Definition: extedge.h:43
int mbedge_goto_eol(std::istream &fin, char *buf, size_t bufsiz)
Definition: extedge.cc:49
std::ifstream infile
Definition: extedge.h:46
char * mbedge_eat_field(char *buf, size_t &buflen, const char *val)
Definition: extedge.cc:94
#define STRLENOF(s)
Definition: mbdyn.h:166
static unsigned done
Definition: gust.cc:209
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
mbsleep_t SleepTime
Definition: extforce.h:76

Here is the call graph for this function:

const char * ExtFileHandlerEDGE::EDGEcmd2str ( int  cmd) const
protected

Definition at line 169 of file extedge.cc.

References EDGE_LAST.

Referenced by CheckFlag(), Recv_pre(), Send_pre(), and SendFlag().

170 {
171  if (cmd < 0 || cmd >= EDGE_LAST) {
172  return "UNKNOWN";
173  }
174 
175  return sEDGEcmd2str[cmd];
176 }
static const char * sEDGEcmd2str[]
Definition: extedge.cc:158
std::istream * ExtFileHandlerEDGE::GetInStream ( void  )
virtual

Reimplemented from ExtFileHandlerBase.

Definition at line 749 of file extedge.cc.

References infile.

750 {
751  return &infile;
752 }
std::ifstream infile
Definition: extedge.h:46
std::ostream * ExtFileHandlerEDGE::GetOutStream ( void  )
virtual

Reimplemented from ExtFileHandlerBase.

Definition at line 743 of file extedge.cc.

References outfile.

744 {
745  return &outfile;
746 }
std::ofstream outfile
Definition: extedge.h:47
void ExtFileHandlerEDGE::Prepare_post ( bool  ok)
virtual

Implements ExtFileHandlerBase.

Definition at line 568 of file extedge.cc.

References NO_OP.

569 {
570  NO_OP;
571 }
#define NO_OP
Definition: myassert.h:74
bool ExtFileHandlerEDGE::Prepare_pre ( void  )
virtual

Implements ExtFileHandlerBase.

Definition at line 562 of file extedge.cc.

563 {
564  return true;
565 }
bool ExtFileHandlerEDGE::Recv_post ( void  )
virtual

Implements ExtFileHandlerBase.

Definition at line 733 of file extedge.cc.

References bReadForces, and infile.

734 {
735  if (infile.is_open()) {
736  infile.close();
737  }
738 
739  return !bReadForces;
740 }
std::ifstream infile
Definition: extedge.h:46
bool ExtFileHandlerEDGE::Recv_pre ( void  )
virtual

Implements ExtFileHandlerBase.

Definition at line 668 of file extedge.cc.

References bReadForces, CheckFlag(), done, EDGE_GOTO_NEXT_STEP, EDGE_QUIT, EDGE_READ_READY, EDGEcmd2str(), fdataname, fflagname, infile, MBDYN_EXCEPT_ARGS, mbdyn_set_stop_at_end_of_time_step(), mbdyn_stop_at_end_of_iteration(), mbsleep(), and ExtFileHandlerBase::SleepTime.

669 {
670  for (int cnt = 0; ;) {
671 
672  EDGEcmd cmd = CheckFlag(cnt);
673  switch (cmd) {
674  case EDGE_READ_READY:
675  goto done;
676 
677  case EDGE_GOTO_NEXT_STEP:
678  // FIXME: EDGE is done; do not read forces,
679  // keep using old
680  bReadForces = false;
681  goto done;
682 
683  case EDGE_QUIT:
684  silent_cout("EDGE requested end of simulation"
685  << std::endl);
687  bReadForces = false;
688  goto done;
689 
690  default:
691  break;
692  }
693 
695  bReadForces = false;
696  goto done;
697  }
698 
699  // WARNING: loops forever
700  // add optional, configurable limit?
701  if (SleepTime > 0) {
702  silent_cout("flag file \"" << fflagname.c_str() << "\": "
703  "cmd=" << cmd << " (" << EDGEcmd2str(cmd) << ")"
704  " try #" << cnt << "; "
705  "sleeping " << SleepTime << " s" << std::endl);
706 
707  mbsleep(&SleepTime);
708  } else {
709  silent_cout("flag file \"" << fflagname.c_str() << "\": "
710  "cmd=" << cmd << " (" << EDGEcmd2str(cmd) << ")"
711  " try #" << cnt << std::endl);
712  }
713  }
714 
715 done:;
716  if (bReadForces) {
717  infile.open(fdataname.c_str());
718  if (!infile) {
719  silent_cerr("unable to open data file "
720  "\"" << fdataname.c_str() << "\" "
721  "for input" << std::endl);
723  }
724 
725  } else {
726  infile.setstate(std::ios_base::badbit);
727  }
728 
729  return infile.good();
730 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const char * EDGEcmd2str(int cmd) const
Definition: extedge.cc:169
std::string fdataname
Definition: extedge.h:43
int mbsleep(const mbsleep_t *t)
Definition: mbsleep.c:90
int mbdyn_stop_at_end_of_iteration(void)
Definition: solver.cc:172
std::string fflagname
Definition: extedge.h:43
std::ifstream infile
Definition: extedge.h:46
static unsigned done
Definition: gust.cc:209
EDGEcmd CheckFlag(int &cnt)
Definition: extedge.cc:179
mbsleep_t SleepTime
Definition: extforce.h:76
void mbdyn_set_stop_at_end_of_time_step(void)
Definition: solver.cc:200

Here is the call graph for this function:

void ExtFileHandlerEDGE::Send_post ( SendWhen  when)
virtual

Implements ExtFileHandlerBase.

Definition at line 638 of file extedge.cc.

References bReadForces, EDGE_MBDYN_WRITE_DONE, outfile, ExtFileHandlerBase::SEND_AFTER_CONVERGENCE, and SendFlag().

639 {
640  if (!bReadForces) {
641  return;
642  }
643 
644  // close data file after writing
645  if (outfile.is_open()) {
646  outfile.close();
647  }
648 
649  if (when == SEND_AFTER_CONVERGENCE) {
650 #if 0
651  // This stops EDGE's subiterations
652  // and advances to next step
653  outfile.open("update.ainp");
654  outfile <<
655  "UPDATE,N,0,0,1\n"
656  "IBREAK,I,1,1,0\n"
657  "5\n";
658  outfile.close();
659 #endif
660 
661  bReadForces = true;
662  }
663 
665 }
void SendFlag(EDGEcmd cmd)
Definition: extedge.cc:509
std::ofstream outfile
Definition: extedge.h:47

Here is the call graph for this function:

bool ExtFileHandlerEDGE::Send_pre ( SendWhen  when)
virtual

Implements ExtFileHandlerBase.

Definition at line 580 of file extedge.cc.

References bReadForces, CheckFlag(), EDGE_BUSY, EDGE_GOTO_NEXT_STEP, EDGE_INITIALIZING, EDGE_READ_READY, EDGE_UNKNOWN, EDGEcmd2str(), fdataname, fflagname, MBDYN_EXCEPT_ARGS, mbdyn_stop_at_end_of_iteration(), mbsleep(), outfile, ExtFileHandlerBase::Precision, and ExtFileHandlerBase::SleepTime.

581 {
582  int cnt = 0;
583  EDGEcmd cmd = EDGE_UNKNOWN;
584 
585  if (!bReadForces) {
586  goto bad;
587  }
588 
589  // open data file for writing
590 retry:;
591  cmd = CheckFlag(cnt);
592  switch (cmd) {
593  case EDGE_INITIALIZING:
594  case EDGE_BUSY:
595  if (SleepTime > 0) {
596  silent_cout("flag file \"" << fflagname.c_str() << "\": "
597  "cmd=" << cmd << " (" << EDGEcmd2str(cmd) << ")"
598  " try #" << cnt << "; "
599  "sleeping " << SleepTime << " s" << std::endl);
600 
601  mbsleep(&SleepTime);
602  }
603 
605  bReadForces = false;
606  goto bad;
607  }
608 
609  goto retry;
610 
611  case EDGE_READ_READY:
612  case EDGE_GOTO_NEXT_STEP:
613  outfile.open(fdataname.c_str());
614  if (!outfile) {
615  int save_errno = errno;
616  silent_cerr("unable to open data file "
617  "\"" << fdataname.c_str() << "\" "
618  "for output (" << errno << ": "
619  << strerror(save_errno) << ")"
620  << std::endl);
622  }
623 
624  outfile.setf(std::ios::scientific);
625  outfile.precision(Precision);
626  break;
627 
628  default:
629 bad:;
630  outfile.setstate(std::ios_base::badbit);
631  break;
632  }
633 
634  return outfile.good();
635 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const char * EDGEcmd2str(int cmd) const
Definition: extedge.cc:169
std::string fdataname
Definition: extedge.h:43
int mbsleep(const mbsleep_t *t)
Definition: mbsleep.c:90
int mbdyn_stop_at_end_of_iteration(void)
Definition: solver.cc:172
std::string fflagname
Definition: extedge.h:43
std::streamsize Precision
Definition: extforce.h:75
std::ofstream outfile
Definition: extedge.h:47
EDGEcmd CheckFlag(int &cnt)
Definition: extedge.cc:179
mbsleep_t SleepTime
Definition: extforce.h:76

Here is the call graph for this function:

void ExtFileHandlerEDGE::SendFlag ( EDGEcmd  cmd)
protected

Definition at line 509 of file extedge.cc.

References EDGEcmd2str(), fdataname, fflagname, MBDYN_EXCEPT_ARGS, mbdyn_stop_at_end_of_iteration(), mbsleep(), mbsleep_init(), and timeout.

Referenced by Send_post(), and ~ExtFileHandlerEDGE().

510 {
511  // write to a temporary, unique file and then rename to fflagname
512 #ifdef HAVE_MKSTEMP
513  char ftmpname[] = "mbedgeXXXXXX";
514  int filedes = mkstemp(ftmpname);
515  FILE *fd = fdopen(filedes, "w");
516 #else // ! HAVE_MKSTEMP
517  std::string ftmpn(fflagname + ".tmp");
518  const char *ftmpname = ftmpn.c_str();
519  FILE *fd = fopen(ftmpname, "w");
520 #endif // ! HAVE_MKSTEMP
521 
522  fprintf(fd, "UPDATE,N,0,0,1\n");
523  fprintf(fd, "FLAG,I,1,1,0\n");
524  fprintf(fd, "%d", int(cmd));
525  fclose(fd);
526 retry:;
527  if (rename(ftmpname, fflagname.c_str()) == -1) {
528  switch (errno) {
529  case EBUSY: {
531  // TODO: configurable?
532  mbsleep(&timeout);
533 
535  // ultimately give up
536  unlink(ftmpname);
537  return;
538  }
539 
540  goto retry;
541  }
542 
543  default: {
544  int save_errno = errno;
545  silent_cerr("unable to rename flag file "
546  "\"" << fdataname.c_str() << "\" "
547  "(errno=" << save_errno << ": "
548  << strerror(save_errno) << ")"
549  << std::endl);
551  }
552  }
553  }
554 
555  silent_cerr(">>> sending flag file \"" << fflagname.c_str() << "\": "
556  "cmd=" << cmd << " (" << EDGEcmd2str(cmd) << ")"
557  << std::endl);
558 
559 }
static int timeout
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
const char * EDGEcmd2str(int cmd) const
Definition: extedge.cc:169
std::string fdataname
Definition: extedge.h:43
int mbsleep(const mbsleep_t *t)
Definition: mbsleep.c:90
unsigned long mbsleep_t
Definition: mbsleep.h:51
int mbdyn_stop_at_end_of_iteration(void)
Definition: solver.cc:172
std::string fflagname
Definition: extedge.h:43
mbsleep_t mbsleep_init(long t)
Definition: mbsleep.c:38

Here is the call graph for this function:

Member Data Documentation

bool ExtFileHandlerEDGE::bReadForces
protected

Definition at line 44 of file extedge.h.

Referenced by AfterPredict(), Recv_post(), Recv_pre(), Send_post(), and Send_pre().

std::string ExtFileHandlerEDGE::fdataname
protected

Definition at line 43 of file extedge.h.

Referenced by Recv_pre(), Send_pre(), and SendFlag().

std::string ExtFileHandlerEDGE::fflagname
protected

Definition at line 43 of file extedge.h.

Referenced by CheckFlag(), Recv_pre(), Send_pre(), and SendFlag().

std::ifstream ExtFileHandlerEDGE::infile
protected

Definition at line 46 of file extedge.h.

Referenced by CheckFlag(), GetInStream(), Recv_post(), and Recv_pre().

std::ofstream ExtFileHandlerEDGE::outfile
protected

Definition at line 47 of file extedge.h.

Referenced by GetOutStream(), Send_post(), and Send_pre().


The documentation for this class was generated from the following files: