45 static const std::vector<doublereal>
v0;
50 const char*
const sFileName,
55 dT0(t0), dDT(dt), iNumSteps(ins),
56 bLinear(bl), bPadZeroes(pz), boWhen(bo), pd(0), pvd(0)
62 std::ifstream in(sFileName);
64 silent_cerr(
"FixedStepFileDrive(" << uL <<
"): "
65 "can't open file \"" << sFileName <<
"\""
75 while (in.get(cTmp), cTmp ==
'#') {
77 #define FIXED_BUFSIZE (8192)
81 in.getline(tmpbuf,
sizeof(tmpbuf));
84 silent_cerr(
"FixedStepFileDrive(" << uL <<
"): "
85 "can't get line " << uLineNo <<
" "
86 "from file \"" << sFileName <<
"\"" << std::endl);
90 while (isspace(tmpbuf[idx])) {
94 if (
dT0 ==
dFromFile && strncasecmp(&tmpbuf[idx],
"initial time:",
STRLENOF(
"initial time:")) == 0) {
96 if (sscanf(&tmpbuf[idx +
STRLENOF(
"initial time:")],
"%le", &d) != 1) {
97 silent_cerr(
"FixedStepFileDrive(" << uL <<
"): "
98 "can't parse \"initial time\" line \"" << &tmpbuf[idx] <<
"\" "
99 "from file \"" << sFileName <<
"\"" << std::endl);
104 }
else if (
dDT ==
dFromFile && strncasecmp(&tmpbuf[idx],
"time step:",
STRLENOF(
"time step:")) == 0) {
106 if (sscanf(&tmpbuf[idx +
STRLENOF(
"time step:")],
"%le", &d) != 1) {
107 silent_cerr(
"FixedStepFileDrive(" << uL <<
"): "
108 "can't parse \"time step\" line \"" << &tmpbuf[idx] <<
"\" "
109 "from file \"" << sFileName <<
"\"" << std::endl);
113 silent_cerr(
"FixedStepFileDrive(" << uL <<
"): "
114 "invalid time step value " << d <<
" "
115 "in file \"" << sFileName <<
"\"" << std::endl);
121 }
while (strlen(tmpbuf) ==
STRLENOF(tmpbuf) && tmpbuf[
STRLENOF(tmpbuf)] !=
'\n');
125 silent_cerr(
"FixedStepFileDrive(" << uL <<
"): "
126 "expecting \"initial time\" line in file \"" << sFileName <<
"\""
132 silent_cerr(
"FixedStepFileDrive(" << uL <<
"): "
133 "expecting \"time step\" line in file \"" << sFileName <<
"\""
143 std::streampos pos = in.tellg();
145 for (ins = 0; !in.eof(); ins++) {
149 in.getline(tmpbuf,
sizeof(tmpbuf));
156 silent_cerr(
"FixedStepFileDrive(" << uL <<
"): "
157 "can't get line " << uLineNo <<
" "
158 "from file \"" << sFileName <<
"\"" << std::endl);
161 }
while (strlen(tmpbuf) ==
STRLENOF(tmpbuf) && tmpbuf[
STRLENOF(tmpbuf)] !=
'\n');
168 silent_cout(
"FixedStepFileDrive(" << uL <<
"): "
169 "counted " << ins <<
" steps" << std::endl);
186 silent_cerr(
"unexpected end of file '"
187 << sFileName <<
'\'' << std::endl);
192 for (c = in.get(); isspace(c); c = in.get()) {
195 silent_cerr(
"unexpected end of line #" << j + 1 <<
" (" << uLineNo <<
") after channel #" << i <<
", column #" << i <<
" of file '"
196 << sFileName <<
'\'' << std::endl);
206 silent_cerr(
"missing end-of-line at line #" << j + 1 <<
" (" << uLineNo <<
") of file '"
207 << sFileName <<
'\'' << std::endl);
231 return out <<
"0. /* FixedStepFileDrive: not implemented yet! */"
244 "A fixed step file drive lower bound is halting the simulation");
262 "A fixed step file drive upper bound is halting the simulation");
316 silent_cerr(
"FixedStepFileDrive(" << uLabel <<
"): "
317 "invalid steps number " << isteps
326 silent_cerr(
"FixedStepFileDrive(" << uLabel <<
"): "
327 "invalid channels number " << idrives
334 silent_cerr(
"FixedStepFileDrive(" << uLabel <<
"): "
335 "warning, keyword \"initial time\" expected at line "
344 silent_cerr(
"FixedStepFileDrive(" << uLabel <<
"): "
345 "warning, keyword \"time step\" expected at line "
352 silent_cerr(
"FixedStepFileDrive(" << uLabel <<
"): "
353 "invalid time step " << dt
366 silent_cerr(
"FixedStepFileDrive(" << uLabel <<
"): "
367 "unknown value for \"interpolation\" "
378 silent_cerr(
"FixedStepFileDrive(" << uLabel <<
"): "
379 "unknown value for \"pad zeros\" "
398 silent_cerr(
"FixedStepFileDrive(" << uLabel <<
"): "
399 "invalid bailout parameter "
413 t0, dt, bl, pz, bo));
#define MBDYN_EXCEPT_ARGS
virtual integer GetInt(integer iDefval=0)
FixedStepFileDrive(unsigned int uL, const DriveHandler *pDH, const char *const sFileName, integer is, integer id, doublereal t0, doublereal dt, bool bl, bool pz, Drive::Bailout bo)
#define SAFEDELETEARR(pnt)
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
virtual void ServePending(const doublereal &t)
const DriveHandler * pGetDrvHdl(void) const
virtual std::ostream & Restart(std::ostream &out) const
static const doublereal dFromFile
virtual ~FixedStepFileDrive(void)
virtual bool IsKeyWord(const char *sKeyWord)
#define ASSERT(expression)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
virtual Drive * Read(unsigned uLabel, const DataManager *pDM, MBDynParser &HP)
static std::stack< cleanup * > c
virtual bool GetYesNo(bool &bRet)
doublereal dGetTime(void) const
#define SAFENEWARR(pnt, item, sz)
static const std::vector< doublereal > v0
virtual HighParser::ErrOut GetLineData(void) const
virtual doublereal GetReal(const doublereal &dDefval=0.0)