2 #include <qucs-core/qucs_interface.h>
16 mexPrintf(
"%s\n", warningmsg);
42 mexErrMsgIdAndTxt (
"MATLAB:trsolver:invalidNumInputs",
43 "Three inputs required.");
45 mexErrMsgIdAndTxt (
"MATLAB:trsolver:maxlhs",
46 "Too many output arguments.");
49 if (mxIsChar(prhs[2]) != 1)
50 mexErrMsgIdAndTxt (
"MATLAB:trsolver:inputNotString",
51 "Input must be a string containing the file name.");
54 if (mxGetM(prhs[2]) != 1)
55 mexErrMsgIdAndTxt (
"MATLAB:trsolver:inputNotVector",
56 "Input must be a row vector.");
59 input_buf = mxArrayToString (prhs[2]);
62 result = qtr.prepare_netlist (input_buf);
64 if (result == NETLIST_OK)
69 else if (result == NETLIST_FAILED_CHECK)
71 mexErrMsgIdAndTxt (
"MATLAB:trsolver:netlistcheckfailure",
72 "The netlist file failed the netlist check.");
74 else if (result == NETLIST_FILE_NOT_FOUND)
76 mexErrMsgIdAndTxt (
"MATLAB:trsolver:netlistcheckfailure",
77 "The netlist was not found or could not be opened.");
81 mexErrMsgIdAndTxt (
"MATLAB:trsolver:unknownfailure",
82 "The qucs interface returned an unknown error code.");
85 if (!qtr.getIsInitialised ())
87 mexErrMsgIdAndTxt (
"MATLAB:trsolver:noetr",
88 "The transient solver could not be initialised (Is there an ETR sim in the netlist?).");
108 mexErrMsgIdAndTxt(
"MATLAB:trsolver:invalidNumInputs",
109 "One input required.");
111 mexErrMsgIdAndTxt(
"MATLAB:trsolver:maxlhs",
112 "Too many output arguments.");
115 if ((mxGetM(prhs[2])!=1) | (mxGetN(prhs[2])!=1))
116 mexErrMsgIdAndTxt(
"MATLAB:trsolver:inputNotVector",
117 "Input must be a scalar.");
120 double synctime = mxGetScalar(prhs[2]);
122 qtr.stepsolve_sync(synctime);
132 mexErrMsgIdAndTxt(
"MATLAB:trsolver:invalidNumInputs",
133 "No input required.");
135 mexErrMsgIdAndTxt(
"MATLAB:trsolver:maxlhs",
136 "Too many output arguments.");
139 qtr.acceptstep_sync();
149 mexErrMsgIdAndTxt(
"MATLAB:trsolver:invalidNumInputs",
150 "One input required.");
152 mexErrMsgIdAndTxt(
"MATLAB:trsolver:maxlhs",
153 "Too many output arguments.");
156 if ((mxGetM(prhs[2])!=1) | (mxGetN(prhs[2])!=1))
157 mexErrMsgIdAndTxt(
"MATLAB:trsolver:inputNotVector",
158 "Input must be a scalar.");
161 double synctime = mxGetScalar(prhs[2]);
163 qtr.stepsolve_async(synctime);
173 mexErrMsgIdAndTxt(
"MATLAB:trsolver:invalidNumInputs",
174 "No input required.");
176 mexErrMsgIdAndTxt(
"MATLAB:trsolver:maxlhs",
177 "Too many output arguments.");
180 qtr.acceptstep_async();
187 mexErrMsgIdAndTxt(
"MATLAB:trsolver:invalidNumInputs",
188 "No input required.");
190 mexErrMsgIdAndTxt(
"MATLAB:trsolver:maxlhs",
191 "Too many output arguments.");
194 qtr.rejectstep_async();
201 int xN, xM, status = 0;
205 mexErrMsgIdAndTxt(
"MATLAB:trsolver:invalidNumInputs",
206 "No input required.");
208 mexErrMsgIdAndTxt(
"MATLAB:trsolver:maxlhs",
209 "Too many output arguments.");
219 mexErrMsgIdAndTxt(
"MATLAB:trsolver:nosolution",
220 "There zero nodes in the circuit.");
224 plhs[0] = mxCreateDoubleMatrix( (mwSize)(xN+xM), (mwSize)(1), mxREAL);
227 outpointer = mxGetPr(plhs[0]);
230 qtr.getsolution(outpointer);
233 plhs[1] = mxCreateDoubleMatrix( (mwSize)(1), (mwSize)(2), mxREAL);
236 outpointer = mxGetPr(plhs[1]);
239 outpointer[0] = (double)xN;
240 outpointer[1] = (double)xM;
252 mexErrMsgIdAndTxt(
"MATLAB:trsolver:invalidNumInputs",
253 "One input required.");
255 mexErrMsgIdAndTxt(
"MATLAB:trsolver:maxlhs",
256 "Too many output arguments.");
259 if ((mxGetM(prhs[2])!=1) | (mxGetN(prhs[2])!=1))
260 mexErrMsgIdAndTxt(
"MATLAB:trsolver:inputNotVector",
261 "Input must be a scalar.");
264 start = mxGetScalar(prhs[2]);
266 qtr.init(start, 1e-6, ETR_MODE_SYNC);
271 double start, firstdelta;
275 mexErrMsgIdAndTxt(
"MATLAB:trsolver:invalidNumInputs",
276 "Two inputs required.");
278 mexErrMsgIdAndTxt(
"MATLAB:trsolver:maxlhs",
279 "Too many output arguments.");
282 if ((mxGetM(prhs[2])!=1) | (mxGetN(prhs[2])!=1))
283 mexErrMsgIdAndTxt(
"MATLAB:trsolver:inputNotVector",
284 "Input 1 must be a scalar.");
287 start = mxGetScalar(prhs[2]);
290 if ((mxGetM(prhs[3])!=1) | (mxGetN(prhs[3])!=1))
291 mexErrMsgIdAndTxt(
"MATLAB:trsolver:inputNotVector",
292 "Input 2 must be a scalar.");
295 firstdelta = mxGetScalar(prhs[3]);
297 qtr.init(start, firstdelta, ETR_MODE_ASYNC);
308 mexErrMsgIdAndTxt (
"MATLAB:trsolver:invalidNumInputs",
309 "No input required.");
311 mexErrMsgIdAndTxt (
"MATLAB:trsolver:maxlhs",
312 "Too many output arguments.");
315 int xN = qtr.getN ();
318 plhs[0] = mxCreateDoubleMatrix ( (mwSize)(1), (mwSize)(1), mxREAL);
321 outpointer = mxGetPr (plhs[0]);
324 outpointer[0] = (double)xN;
334 mexErrMsgIdAndTxt (
"MATLAB:trsolver:invalidNumInputs",
335 "No input required.");
337 mexErrMsgIdAndTxt (
"MATLAB:trsolver:maxlhs",
338 "Too many output arguments.");
341 int xM = qtr.getM ();
344 plhs[0] = mxCreateDoubleMatrix ( (mwSize)(1), (mwSize)(1), mxREAL);
347 outpointer = mxGetPr (plhs[0]);
350 outpointer[0] = (double)xM;
361 mexErrMsgIdAndTxt (
"MATLAB:trsolver:invalidNumInputs",
362 "No input required.");
364 mexErrMsgIdAndTxt (
"MATLAB:trsolver:maxlhs",
365 "Too many output arguments.");
367 int jrows = qtr.getJacRows ();
368 int jcols = qtr.getJacCols ();
371 plhs[0] = mxCreateDoubleMatrix ( (mwSize)(jrows), (mwSize)(jcols), mxREAL);
374 outpointer = mxGetPr (plhs[0]);
377 for(
int c = 0;
c < jcols;
c++)
379 for(
int r = 0;
r < jrows;
r++)
381 qtr.getJacData(
r,
c, outpointer[(
c*jrows)+
r]);
391 double newvoltage = 0;
396 mexErrMsgIdAndTxt (
"MATLAB:trsolver:invalidNumInputs",
397 "One input required.");
399 mexErrMsgIdAndTxt (
"MATLAB:trsolver:maxlhs",
400 "Too many output arguments.");
403 if (mxIsChar(prhs[2]) != 1)
404 mexErrMsgIdAndTxt (
"MATLAB:trsolver:inputNotString",
405 "Input must be a string containing the file name.");
408 if (mxIsNumeric (prhs[3]) & ((mxGetM (prhs[3]) != 1) | (mxGetN (prhs[3]) != 1)))
409 mexErrMsgIdAndTxt (
"MATLAB:trsolver:inputNotVector",
410 "Voltage input must be a scalar.");
414 ecvsname = mxArrayToString (prhs[2]);
416 newvoltage = mxGetScalar (prhs[3]);
418 result = qtr.setECVSVoltage (ecvsname, newvoltage);
423 mexErrMsgIdAndTxt (
"MATLAB:trsolver:ecvsnotfound",
424 "The ECVS component with name %s was not found.",
440 mexErrMsgIdAndTxt (
"MATLAB:trsolver:invalidNumInputs",
441 "One input required.");
443 mexErrMsgIdAndTxt (
"MATLAB:trsolver:maxlhs",
444 "Too many output arguments.");
447 if (mxIsChar(prhs[2]) != 1)
448 mexErrMsgIdAndTxt (
"MATLAB:trsolver:inputNotString",
449 "Input must be a string containing the file name.");
453 probename = mxArrayToString (prhs[2]);
455 result = qtr.getIProbeI (probename, current);
460 mexErrMsgIdAndTxt (
"MATLAB:trsolver:vprobenotfound",
461 "The current probe with name %s was not found.",
467 plhs[0] = mxCreateDoubleMatrix ( (mwSize)(1), (mwSize)(1), mxREAL);
470 outpointer = mxGetPr (plhs[0]);
473 outpointer[0] = (double)current;
487 mexErrMsgIdAndTxt (
"MATLAB:trsolver:invalidNumInputs",
488 "One input required.");
490 mexErrMsgIdAndTxt (
"MATLAB:trsolver:maxlhs",
491 "Too many output arguments.");
494 if (mxIsChar(prhs[2]) != 1)
495 mexErrMsgIdAndTxt (
"MATLAB:trsolver:inputNotString",
496 "Input must be a string containing the file name.");
500 probename = mxArrayToString (prhs[2]);
502 result = qtr.getVProbeV (probename, voltage);
507 mexErrMsgIdAndTxt (
"MATLAB:trsolver:vprobenotfound",
508 "The voltage probe with name %s was not found.",
514 plhs[0] = mxCreateDoubleMatrix ( (mwSize)(1), (mwSize)(1), mxREAL);
517 outpointer = mxGetPr (plhs[0]);
520 outpointer[0] = (double)voltage;
535 mexErrMsgIdAndTxt (
"MATLAB:trsolver:invalidNumInputs",
536 "One input required.");
538 mexErrMsgIdAndTxt (
"MATLAB:trsolver:maxlhs",
539 "Too many output arguments.");
542 if (mxIsChar(prhs[2]) != 1)
543 mexErrMsgIdAndTxt (
"MATLAB:trsolver:inputNotString",
544 "Input must be a string containing the file name.");
548 nodename = mxArrayToString (prhs[2]);
550 result = qtr.getNodeV (nodename, voltage);
555 mexErrMsgIdAndTxt (
"MATLAB:trsolver:vprobenotfound",
556 "The voltage probe with name %s was not found.",
562 plhs[0] = mxCreateDoubleMatrix ( (mwSize)(1), (mwSize)(1), mxREAL);
565 outpointer = mxGetPr (plhs[0]);
568 outpointer[0] = (double)voltage;
int stepsolve_async(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void getiprobe(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int stepsolve_sync(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void acceptstep_sync(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int prepare_netlist(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void mextrsolvermessage(int level, const char *warningmsg,...)
void getJac(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void getnodev(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int getsolution(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void init_sync(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void init_async(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void rejectstep_async(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void getvprobe(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void acceptstep_async(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void setecvs(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int getM(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int getN(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])