Branch data Line data Source code
1 : : /*
2 : : * check_dataset.cpp - checker for the Qucs dataset
3 : : *
4 : : * Copyright (C) 2003, 2006 Stefan Jahn <stefan@lkcc.org>
5 : : *
6 : : * This is free software; you can redistribute it and/or modify
7 : : * it under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation; either version 2, or (at your option)
9 : : * any later version.
10 : : *
11 : : * This software is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with this package; see the file COPYING. If not, write to
18 : : * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19 : : * Boston, MA 02110-1301, USA.
20 : : *
21 : : * $Id$
22 : : *
23 : : */
24 : :
25 : : #if HAVE_CONFIG_H
26 : : # include <config.h>
27 : : #endif
28 : :
29 : : #include <stdio.h>
30 : : #include <stdlib.h>
31 : : #include <string.h>
32 : : #include <cmath>
33 : :
34 : : #include "logging.h"
35 : : #include "complex.h"
36 : : #include "object.h"
37 : : #include "vector.h"
38 : : #include "dataset.h"
39 : : #include "strlist.h"
40 : : #include "check_dataset.h"
41 : :
42 : : using namespace qucs;
43 : :
44 : : strlist * dataset_idents = NULL;
45 : : dataset * dataset_result = NULL;
46 : : vector * dataset_vector = NULL;
47 : :
48 : : /* This function is the checker routine for a parsed dataset. It
49 : : returns zero on success or non-zero if the parsed dataset contained
50 : : errors. */
51 : 0 : int dataset_check (dataset * data) {
52 : :
53 : 0 : int errors = 0;
54 : : vector * v, * d;
55 : :
56 : : /* check actual size and requested size of independent vectors */
57 [ # # ]: 0 : for (v = data->getDependencies (); v != NULL; v = (vector *) v->getNext ()) {
58 [ # # ]: 0 : if (v->getSize () != v->getRequested ()) {
59 : : logprint (LOG_ERROR, "checker error, vector `%s' contains %d values, "
60 : : "%d have been stated\n", v->getName (), v->getSize (),
61 : 0 : v->getRequested ());
62 : 0 : errors++;
63 : : }
64 : : }
65 : :
66 : : /* check dependencies of dependent vectors */
67 [ # # ]: 0 : for (v = data->getVariables (); v != NULL; v = (vector *) v->getNext ()) {
68 : 0 : strlist * s = v->getDependencies ();
69 : : /* any dependencies at all ? */
70 [ # # ][ # # ]: 0 : if (s == NULL || s->length () == 0) {
[ # # ]
71 : : logprint (LOG_ERROR, "checker error, vector `%s' contains no "
72 : 0 : "dependencies\n", v->getName ());
73 : 0 : errors++;
74 : : }
75 : : /* yes */
76 : : else {
77 : 0 : int n = 1;
78 : : /* go through each dependency and check it */
79 [ # # ][ # # ]: 0 : for (strlistiterator it (s); *it; ++it) {
[ # # ][ # # ]
80 [ # # ][ # # ]: 0 : if ((d = data->findDependency (*it)) == NULL) {
[ # # ]
81 : : logprint (LOG_ERROR, "checker error, no such dependency `%s' as "
82 [ # # ][ # # ]: 0 : "stated in `%s'\n", *it, v->getName ());
83 : 0 : errors++;
84 : : }
85 : : else {
86 [ # # ]: 0 : n *= d->getSize ();
87 : : }
88 [ # # ]: 0 : }
89 [ # # ]: 0 : if (n != 0) {
90 [ # # ]: 0 : if (v->getSize () % n != 0) {
91 : : logprint (LOG_ERROR, "checker error, size of vector `%s' %d should "
92 : 0 : "be dividable by %d\n", v->getName (), v->getSize (), n);
93 : 0 : errors++;
94 : : }
95 : : }
96 : : }
97 : : }
98 : :
99 [ # # ]: 0 : return errors ? -1 : 0;
100 : : }
|