I attached 3 files. A QSpice schematic a Cblock .cpp and the compiled CBlock .dll.
It is a example sim and CBlock with two features.
A new feature Mike Engelhardt added on August 20, 2025. It is a library call of a special function that takes a string that contains metric multipliers and expands them and the result is a ‘double’ value. The function is EngAtof().
I provided a ‘simplified’ example of the Trunc() function. Proper use of this function can minimize the number of timesteps used in a simulation reducing sim time. Additionally, it can be used to significantly improve timing accuracy for switching events.
The CBlock is similar to the voltage component with the PULSE argument.
Thanks for getting us started with the new EngAtof() feature. It’s more clever than it may appear and can do some interesting stuff. I’m working on a new C-Block Basics paper to explain it in my typically tedious and tiresome detail. That’s not yet ready…
Looking at your code, I think that it can be simplified. You don’t need to split the passed String Attribute “args” in advance. EngAtof() will do it for you in a fashion similar to strtok().
See the attached revisions to your example. I tried not to change it too much but my IDE reformatted it. Sorry.
There was, I think, an error in the original code (“==” where “=” was intended). I corrected and commented that.
Comparing your code output to my version looks the same:
I documented my study for most of them in device guideline (currently p.351-367). I cannot figure how to use DFFT(), and Robert is working on a paper on EngAtof(), as it usage seems more than just this example explored. 08/20/2025 In a C++ .DLL, added access to user-defined parameters, mathematical expressions, and SPICE metric multipliers via extern "C" __declspec(dllexport) double (*EngAtof)(const char **string) = 0;
I think that Kelvin and I have a handle on most of them.
If I remember correctly, Kelvin determined that *CKTtime and *CKTdelta are the “last committed simulation” timepoint and time increment from the prior time-point. (“Committed” meaning that QSpice directly called the evaluation function and stored the results, i.e., not a hypothetical Trunc() call to the eval func.) You might want to confirm with him in case my memory is imperfect.
*InstallDirectory is the file path to QSpice, “C:\Program Files\QSpice” typically.
Thanks for providing this example and document!
My initial impression is that having the ability to verify the existence and to get the value of parameters could provide better handling for parameters required in DLL blocks when using .step. Currently, I need to supply the parameter either through a parameter input or an input port using a B-source with V=[parameter name]. EngAtof() seems to be a much more effective way to address this.
Reading a function may be less common. Just a quick thought.
I don’t know if you solved it (in which case please ignore this) or not but, in the case that you didn’t, here’s the solution: The struct needs to be struct sComplex { double data[2]; }; with [0] being the real and [1] the imaginary. Fill it up with pointer_to_it[i].data[0] (and [1], respectively). It should be obvious it’s in-place.