41 #include <sys/types.h> 
   53         for (i = 0; i < bufsiz; i++) {
 
   81                 if (buf[0] == 
'\n' || buf[0] == 
'\0' || (buf[0] != 
',' && !std::isspace(buf[0]))) {
 
   98         size_t vallen = strlen(val);
 
   99         if (buflen < vallen) {
 
  103         if (strncmp(buf, val, vallen) == 0) {
 
  120                 if (buf[0] == 
',' || std::isspace(buf[0])) {
 
  136         std::string& fdataname, 
mbsleep_t SleepTime, std::streamsize Precision)
 
  138 fflagname(fflagname), fdataname(fdataname),
 
  175         return sEDGEcmd2str[cmd];
 
  187         if (!
infile && cnt == -1) {
 
  192         const int max_retries = 10;
 
  200                         silent_cout(
"flag file \"" << 
fflagname.c_str() << 
"\" " 
  201                                 "missing, try #" << cnt << 
"; " 
  202                                 "sleeping " << 
SleepTime << 
" s" << std::endl); 
 
  216                 silent_cerr(
"flag file \"" << 
fflagname.c_str() << 
"\" " 
  217                         "missing" << std::endl); 
 
  229                 char buf[BUFSIZ], *p;
 
  242                 if (strncasecmp(buf, 
"UPDATE", 
STRLENOF(
"UPDATE")) == 0) {
 
  248                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip separator " 
  249                                         "at line=" << lineno << 
", \"" << &buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  250                                 if (retrying < max_retries) {
 
  259                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip field \"N\" " 
  260                                         "at line=" << lineno << 
", \"" << &buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  261                                 if (retrying < max_retries) {
 
  270                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip separator " 
  271                                         "at line=" << lineno << 
", \"" << &buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  272                                 if (retrying < max_retries) {
 
  281                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip field \"0\" " 
  282                                         "at line=" << lineno << 
", \"" << &buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  283                                 if (retrying < max_retries) {
 
  292                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip separator " 
  293                                         "at line=" << lineno << 
", \"" << &buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  294                                 if (retrying < max_retries) {
 
  303                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip field \"0\" " 
  304                                         "at line=" << lineno << 
", \"" << &buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  305                                 if (retrying < max_retries) {
 
  314                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip separator " 
  315                                         "at line=" << lineno << 
", \"" << &buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  316                                 if (retrying < max_retries) {
 
  325                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip field \"1\" " 
  326                                         "at line=" << lineno << 
", \"" << &buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  327                                 if (retrying < max_retries) {
 
  336                                 silent_cerr(
"ExtRigidForceEDGE: unable to skip separator " 
  337                                         "at line=" << lineno << 
", \"" << &buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  338                                 if (retrying < max_retries) {
 
  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) {
 
  356                                 silent_cerr(
"ExtRigidForceEDGE: unable to get \"FLAG\" line " 
  357                                         "at line=" << lineno << 
", \"" << p << 
"\"" << std::endl);
 
  358                                 if (retrying < max_retries) {
 
  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) {
 
  382                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip separator " 
  383                                         "at line=" << lineno << 
", \"" << buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  384                                 if (retrying < max_retries) {
 
  393                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip field \"I\" " 
  394                                         "at line=" << lineno << 
", \"" << buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  395                                 if (retrying < max_retries) {
 
  404                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip separator " 
  405                                         "at line=" << lineno << 
", \"" << buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  406                                 if (retrying < max_retries) {
 
  415                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip field \"1\" " 
  416                                         "at line=" << lineno << 
", \"" << buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  417                                 if (retrying < max_retries) {
 
  426                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip separator " 
  427                                         "at line=" << lineno << 
", \"" << buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  428                                 if (retrying < max_retries) {
 
  437                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip field \"1\" " 
  438                                         "at line=" << lineno << 
", \"" << buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  439                                 if (retrying < max_retries) {
 
  448                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip separator " 
  449                                         "at line=" << lineno << 
", \"" << buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  450                                 if (retrying < max_retries) {
 
  459                                 silent_cerr(
"ExtFileHandlerEDGE: unable to skip field \"0\" " 
  460                                         "at line=" << lineno << 
", \"" << buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  461                                 if (retrying < max_retries) {
 
  470                                 silent_cerr(
"ExtRigidForceEDGE: unable to skip separator " 
  471                                         "at line=" << lineno << 
", \"" << buf[
sizeof(buf) - buflen] << 
"\"" << std::endl);
 
  472                                 if (retrying < max_retries) {
 
  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) {
 
  498         silent_cerr(
"<<< checking flag file \"" << 
fflagname.c_str() << 
"\": " 
  513         char ftmpname[] = 
"mbedgeXXXXXX";
 
  514         int filedes = mkstemp(ftmpname);
 
  515         FILE *fd = fdopen(filedes, 
"w");
 
  516 #else // ! HAVE_MKSTEMP 
  518         const char *ftmpname = ftmpn.c_str();
 
  519         FILE *fd = fopen(ftmpname, 
"w");
 
  520 #endif // ! HAVE_MKSTEMP 
  522         fprintf(fd, 
"UPDATE,N,0,0,1\n");
 
  523         fprintf(fd, 
"FLAG,I,1,1,0\n");
 
  524         fprintf(fd, 
"%d", 
int(cmd));
 
  527         if (rename(ftmpname, 
fflagname.c_str()) == -1) {
 
  544                         int save_errno = errno;
 
  545                         silent_cerr(
"unable to rename flag file " 
  547                                 "(errno=" << save_errno << 
": " 
  548                                 << strerror(save_errno) << 
")" 
  555         silent_cerr(
">>> sending flag file \"" << 
fflagname.c_str() << 
"\": " 
  596                         silent_cout(
"flag file \"" << 
fflagname.c_str() << 
"\": " 
  598                                 " try #" << cnt << 
"; " 
  599                                 "sleeping " << 
SleepTime << 
" s" << std::endl); 
 
  615                         int save_errno = errno;
 
  616                         silent_cerr(
"unable to open data file " 
  618                                 "for output (" << errno << 
": " 
  619                                 << strerror(save_errno) << 
")" 
  624                 outfile.setf(std::ios::scientific);
 
  630                 outfile.setstate(std::ios_base::badbit);
 
  670         for (
int cnt = 0; ;) {
 
  684                         silent_cout(
"EDGE requested end of simulation" 
  702                         silent_cout(
"flag file \"" << 
fflagname.c_str() << 
"\": " 
  704                                 " try #" << cnt << 
"; " 
  705                                 "sleeping " << 
SleepTime << 
" s" << std::endl); 
 
  709                         silent_cout(
"flag file \"" << 
fflagname.c_str() << 
"\": " 
  711                                 " try #" << cnt << std::endl); 
 
  719                         silent_cerr(
"unable to open data file " 
  721                                 "for input" << std::endl);
 
  726                 infile.setstate(std::ios_base::badbit);
 
  765                 silent_cerr(
"ExtForceEDGE(" << uLabel << 
"): " 
  766                         "unable to get flag file name " 
  770         std::string fflagname = s;
 
  774                 silent_cerr(
"ExtForceEDGE(" << uLabel << 
"): " 
  775                         "unable to get data file name " 
  779         std::string fdataname = s;
 
  782         std::streamsize Precision = 0;
 
virtual bool Prepare_pre(void)
 
#define MBDYN_EXCEPT_ARGS
 
const char * EDGEcmd2str(int cmd) const 
 
int mbsleep(const mbsleep_t *t)
 
char * mbedge_eat_sep(char *buf, size_t &buflen)
 
virtual void AfterPredict(void)
 
virtual std::ostream * GetOutStream(void)
 
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
 
ExtFileHandlerEDGE(std::string &fflagname, std::string &fdataname, mbsleep_t SleepTime, std::streamsize Precision)
 
int mbdyn_stop_at_end_of_iteration(void)
 
static const char * sEDGEcmd2str[]
 
virtual void Prepare_post(bool ok)
 
ExtFileHandlerBase * ReadExtFileHandlerEDGE(DataManager *pDM, MBDynParser &HP, unsigned int uLabel)
 
virtual bool Recv_post(void)
 
int mbedge_goto_eol(std::istream &fin, char *buf, size_t bufsiz)
 
virtual void Send_post(SendWhen when)
 
mbsleep_t mbsleep_init(long t)
 
std::streamsize Precision
 
virtual std::istream * GetInStream(void)
 
virtual bool Send_pre(SendWhen when)
 
#define ASSERT(expression)
 
char * mbedge_eat_field(char *buf, size_t &buflen, const char *val)
 
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
 
virtual bool Recv_pre(void)
 
~ExtFileHandlerEDGE(void)
 
void SendFlag(EDGEcmd cmd)
 
EDGEcmd CheckFlag(int &cnt)
 
static doublereal buf[BUFSIZE]
 
virtual HighParser::ErrOut GetLineData(void) const 
 
void mbdyn_set_stop_at_end_of_time_step(void)
 
void ReadExtFileParams(DataManager *pDM, MBDynParser &HP, unsigned int uLabel, mbsleep_t &SleepTime, std::streamsize &Precision)