55 static void mdl_create_depdataset (
sweep *
data,
char *
name) {
62 static void mdl_create_condataset (
double val,
char *
name) {
69 static void mdl_create_vardataset (
struct mdl_point_t * point,
71 const char * name,
const char * type,
75 if (!strcmp (type,
"MEAS"))
77 else if (!strcmp (type,
"SIMU"))
79 else if (!strcmp (type,
"COMMON"))
83 int n = (p->y - 1) * 2 + p->x - 1;
87 for (
int x = 1;
x < dsize->
x + 1;
x++) {
88 for (
int y = 1; y < dsize->
y + 1; y++) {
90 int n = (y - 1) * 2 +
x - 1;
91 char * txt = (
char *) malloc (strlen (name) + strlen (type) + 4 + 2 * 3);
92 if (dsize->
x > 1 || dsize->
y > 1)
93 sprintf (txt,
"%s%s[%d,%d]", name, type,
x, y);
95 sprintf (txt,
"%s%s", name, type);
99 if (v[n].getSize () > 1) {
112 static char * mdl_find_helement (
struct mdl_element_t * root,
114 for (; root != NULL; root = root->
next) {
115 if (!strcmp (root->
name, name))
return root->
value;
121 static char * mdl_find_telement (
struct mdl_element_t * root,
123 for (; root != NULL; root = root->
next) {
124 if (!strcmp (root->
name,
"Name") && !strcmp (root->
value, name)) {
125 if (root->
next && !strcmp (root->
next->
name,
"Value")) {
134 static double mdl_convert_factor (
char * end) {
138 case 'K': f = 1
e+03;
break;
139 case 'M': f = 1
e+06;
break;
140 case 'G': f = 1
e+09;
break;
141 case 'T': f = 1
e+12;
break;
142 case 'm': f = 1
e-03;
break;
143 case 'u': f = 1
e-06;
break;
144 case 'n': f = 1
e-09;
break;
145 case 'p': f = 1
e-12;
break;
146 case 'f': f = 1
e-15;
break;
147 case 'a': f = 1
e-18;
break;
158 static int mdl_resolve_variable (
struct mdl_link_t * link,
char * name,
164 for (root = link->
content; !done && root != NULL; root = root->
next) {
167 if (mdl_find_telement (eroot, name)) {
168 val = mdl_telement_dvalue (link, eroot, name);
174 if (!done && link->
parent) {
175 done = mdl_resolve_variable (link->
parent, name, val);
181 static double mdl_variable_value (
struct mdl_link_t * link,
char * txt) {
190 while (*t) { *t = *(t + 1); t++; }
196 val = strtod (txt, &end);
200 if (*txt ==
'-') { f = -1.0; txt++; }
201 else if (*txt ==
'+') { f = +1.0; txt++; }
202 if (!mdl_resolve_variable (link, txt, val)) {
204 if (!strcmp (txt,
"PI")) {
210 "checker error, unable to resolve `%s' variable in '%s'\n",
219 val *= mdl_convert_factor (end);
226 static double mdl_helement_dvalue (
struct mdl_link_t * link,
229 char * txt = mdl_find_helement (eroot, name);
230 return mdl_variable_value (link, txt);
234 static double mdl_telement_dvalue (
struct mdl_link_t * link,
237 char * txt = mdl_find_telement (eroot, name);
238 return mdl_variable_value (link, txt);
242 static int mdl_helement_ivalue (
struct mdl_link_t * link,
245 return (
int) mdl_helement_dvalue (link, eroot, name);
249 static void mdl_find_vardataset (
struct mdl_dcontent_t * droot,
char * name,
253 for (root = droot; root != NULL; root = root->
next) {
272 double val, start, stop,
step;
273 int nof = 0, order = 0;
278 for (root = droot; root != NULL; root = root->
next) {
282 if (!strcmp (hyptab->
name,
"Edit Sweep Def")) {
283 if (!strcmp (stype,
"LIN")) {
285 order = mdl_helement_ivalue (link, hyptab->
data,
"Sweep Order");
286 start = mdl_helement_dvalue (link, hyptab->
data,
"Start");
287 stop = mdl_helement_dvalue (link, hyptab->
data,
"Stop");
288 nof = mdl_helement_ivalue (link, hyptab->
data,
"# of Points");
289 step = mdl_helement_dvalue (link, hyptab->
data,
"Step Size");
290 if (nof <= 0) nof = (int) fabs ((stop - start) /
step) + 1;
291 deps->
append (name,
new int (order));
293 sw->
create (start, stop, nof);
294 mdl_create_depdataset (sw, name);
297 else if (!strcmp (stype,
"CON")) {
299 val = mdl_helement_dvalue (link, hyptab->
data,
"Value");
300 mdl_create_condataset (val, name);
302 else if (!strcmp (stype,
"LOG")) {
304 order = mdl_helement_ivalue (link, hyptab->
data,
"Sweep Order");
305 start = mdl_helement_dvalue (link, hyptab->
data,
"Start");
306 stop = mdl_helement_dvalue (link, hyptab->
data,
"Stop");
307 nof = mdl_helement_ivalue (link, hyptab->
data,
"Total Pts");
309 nof = mdl_helement_ivalue (link, hyptab->
data,
"# of Points");
310 if (start * stop == 0.0) {
311 if (start == 0.0) start = 1.0;
312 if (stop == 0.0) stop = 1.0;
314 deps->
append (name,
new int (order));
316 sw->
create (start, stop, nof);
317 mdl_create_depdataset (sw, name);
320 else if (!strcmp (stype,
"LIST")) {
322 order = mdl_helement_ivalue (link, hyptab->
data,
"Sweep Order");
323 nof = mdl_helement_ivalue (link, hyptab->
data,
"# of Values");
324 deps->
append (name,
new int (order));
326 else if (!strcmp (stype,
"SYNC")) {
330 sync->
ratio = mdl_helement_dvalue (link, hyptab->
data,
"Ratio");
331 sync->
offset = mdl_helement_dvalue (link, hyptab->
data,
"Offset");
332 sync->
master = mdl_find_helement (hyptab->
data,
"Master Sweep");
334 sync->
name = strdup (name);
336 mdl_sync_root = sync;
340 else if (!strcmp (hyptab->
name,
"Edit Sweep Info")) {
341 stype = mdl_find_helement (hyptab->
data,
"Sweep Type");
344 else if (!strcmp (hyptab->
name,
"List Table")) {
348 for (
int i = 0;
i < nof;
i++) {
349 sprintf (txt,
"Value %d",
i + 1);
350 val = mdl_helement_dvalue (link, hyptab->
data, txt);
353 mdl_create_depdataset (sw, name);
362 static char * mdl_create_linkname (
char * base,
char * name) {
363 char * txt = (
char *) malloc (strlen (base) + 2 + strlen (name));
364 sprintf (txt,
"%s.%s", base, name);
369 static void mdl_find_deplink (
struct mdl_link_t * link,
char * name,
374 for (root = link->
content; root != NULL; root = root->
next) {
385 char * txt = mdl_create_linkname (name, root->
link->
name);
387 mdl_find_deplink (root->
link, txt, deps);
394 static void mdl_find_varlink (
struct mdl_link_t * link,
char * name,
398 for (root = link->
content; root != NULL; root = root->
next) {
401 mdl_find_vardataset (root->
data->
content, name, deps);
405 !strcmp (root->
link->
type,
"XFORM"))) {
406 char * txt = mdl_create_linkname (name, root->
link->
name);
408 mdl_find_varlink (root->
link, txt, deps);
419 if (*(it.currentVal ()) ==
i + 1) {
420 deps->
append (it.currentKey ());
428 static void mdl_find_link (
struct mdl_link_t * link,
char * name) {
433 mdl_find_deplink (link, name, vdeps);
434 strlist * deps = mdl_sort_deps (vdeps);
438 mdl_find_varlink (link, name, deps);
442 for (root = link->
content; root != NULL; root = root->
next) {
445 strcmp (root->
link->
type,
"SWEEP") &&
446 strcmp (root->
link->
type,
"XFORM")) {
447 char * txt = mdl_create_linkname (name, root->
link->
name);
449 mdl_find_link (root->
link, txt);
456 static void mdl_create_syndataset (
vector * v,
char * name) {
464 for (sync = root; sync != NULL; sync = sync->
next) {
466 char * link = sync->
name;
467 int i = strlen (link) - 1;
468 while (i > 0 && link[i] !=
'.') i--;
469 if (link[i] ==
'.') {
471 char * txt = (
char *) malloc (i + 2 + strlen (sync->
master));
472 sprintf (txt,
"%s.%s", link, sync->
master);
481 mdl_create_syndataset (s, sync->
name);
504 for (e = h->
data; e != NULL; e = next) {
506 mdl_free_element (e);
512 static void mdl_free_table (
struct mdl_table_t * t) {
515 for (e = t->
data; e != NULL; e = next) {
517 mdl_free_element (e);
526 for (p = d->
data1; p != NULL; p = next) {
531 for (p = d->
data2; p != NULL; p = next) {
547 static void mdl_free_data (
struct mdl_data_t * d) {
549 for (c = d->
content; c != NULL; c = next) {
551 mdl_free_dcontent (c);
556 static void mdl_free_link (
struct mdl_link_t *);
569 static void mdl_free_link (
struct mdl_link_t * l) {
573 for (c = l->
content; c != NULL; c = next) {
575 mdl_free_lcontent (c);
580 static void mdl_free_sync (
struct mdl_sync_t *
s) {
582 for (; s != NULL; s =
next) {
591 static int mdl_get_depsize (
strlist * deps) {
595 for (
int i = 0;
i < deps->
length ();
i++) {
596 if ((n = deps->
get (
i)) != NULL)
605 static void mdl_check_xform_deplen (
void) {
610 if (deps->
length () <= 0) {
619 static void mdl_check_xform_dep (
void) {
624 int s = mdl_get_depsize (deps);
628 for (
int i = 0;
i < deps->
length ();
i++) {
630 char * n = deps->
get (
i);
649 static void mdl_check_xforms (
void) {
650 mdl_check_xform_dep ();
651 mdl_check_xform_deplen ();
660 for (root = mdl_root; root; root = root->
next) {
661 char * name = root->
name;
662 mdl_find_link (root, name);
666 return errors ? -1 : 0;
671 if (mdl_result != NULL) {
676 if (mdl_root != NULL) {
679 for (root = mdl_root; root; root =
next) {
681 mdl_free_link (root);
685 if (mdl_sync_root != NULL) {
687 mdl_free_sync (mdl_sync_root);
688 mdl_sync_root = NULL;
696 mdl_sync_root = NULL;