// Automatically generated C++ file on Sun Aug 27 09:49:23 2023 // // To build with Digital Mars C++ Compiler: // // dmc -mn -WD testcmp.cpp kernel32.lib #include #include #include #include union uData { bool b; char c; unsigned char uc; short s; unsigned short us; int i; unsigned int ui; float f; double d; long long int i64; unsigned long long int ui64; char *str; unsigned char *bytes; }; // int DllMain() must exist and return 1 for a process to load the .DLL // See https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain for more // information. int __stdcall DllMain(void *module, unsigned int reason, void *reserved) { return 1; } #if 0 // for suppressing output void display(const char *fmt, ...) { // for diagnostic print statements msleep(30); fflush(stdout); va_list args = {0}; va_start(args, fmt); vprintf(fmt, args); va_end(args); fflush(stdout); msleep(30); } #else void display(const char *fmt, ...) {} #endif void bzero(void *ptr, unsigned int count) { unsigned char *first = (unsigned char *)ptr; unsigned char *last = first + count; while (first < last) *first++ = '\0'; } // #undef pin names lest they collide with names in any header file(s) you might // include. #undef Out struct sTESTCMP { // declare the structure here int nbrTestcmpCalls; int nbrMaxStepCalls; int nbrTruncCalls; }; extern "C" __declspec(dllexport) void testcmp( struct sTESTCMP **opaque, double t, union uData *data) { /*add*/ static int enterCnt = 0; /*add*/ static int exitCnt = 0; /*add*/ display("(t=%e) testcmp entered %d times\n", t, ++enterCnt); double &Out = data[0].d; // output if (!*opaque) { *opaque = (struct sTESTCMP *)malloc(sizeof(struct sTESTCMP)); bzero(*opaque, sizeof(struct sTESTCMP)); } struct sTESTCMP *inst = *opaque; // Implement module evaluation code here: /*add*/ Out = 1.0 + (t * 10.0); /*add*/ display("(t=%e) testcmp exiting %d times\n", t, ++exitCnt); } extern "C" __declspec(dllexport) double MaxExtStepSize(struct sTESTCMP *inst) { /*add*/ display("MaxExtStepSize called\n"); return 1e308; // implement a good choice of max timestep size that depends // on struct sTESTCMP } extern "C" __declspec(dllexport) void Trunc(struct sTESTCMP *inst, double t, union uData *data, double *timestep) { // limit the timestep to a tolerance if the circuit // causes a change in struct sTESTCMP /*add*/ static int enterCnt = 0; /*add*/ static int exitCnt = 0; /*add*/ display("(t=%e) Trunc entered %d times, *timestep=%e\n", t, ++enterCnt, *timestep); #if 0 // disabling template code for now const double ttol = 1e-9; if (*timestep > ttol) { double &Out = data[0].d; // output // Save output vector const double _Out = Out; struct sTESTCMP tmp = *inst; testcmp(&(&tmp), t, data); // if(tmp != *inst) // implement a meaningful way to detect if the state has // changed // *timestep = ttol; // Restore output vector Out = _Out; } #endif /*add*/ display("(t=%e) Trunc entering %d times\n", t, ++exitCnt); } extern "C" __declspec(dllexport) void Destroy(struct sTESTCMP *inst) { free(inst); }