My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check_dataset.cpp
Go to the documentation of this file.
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: check_dataset.cpp 1825 2011-03-11 20:42:14Z ela $
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 <math.h>
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 
45 
46 /* This function is the checker routine for a parsed dataset. It
47  returns zero on success or non-zero if the parsed dataset contained
48  errors. */
50 
51  int errors = 0;
52  vector * v, * d;
53 
54  /* check actual size and requested size of independent vectors */
55  for (v = data->getDependencies (); v != NULL; v = (vector *) v->getNext ()) {
56  if (v->getSize () != v->getRequested ()) {
57  logprint (LOG_ERROR, "checker error, vector `%s' contains %d values, "
58  "%d have been stated\n", v->getName (), v->getSize (),
59  v->getRequested ());
60  errors++;
61  }
62  }
63 
64  /* check dependencies of dependent vectors */
65  for (v = data->getVariables (); v != NULL; v = (vector *) v->getNext ()) {
66  strlist * s = v->getDependencies ();
67  /* any dependencies at all ? */
68  if (s == NULL || s->length () == 0) {
69  logprint (LOG_ERROR, "checker error, vector `%s' contains no "
70  "dependencies\n", v->getName ());
71  errors++;
72  }
73  /* yes */
74  else {
75  int n = 1;
76  /* go through each dependency and check it */
77  for (strlistiterator it (s); *it; ++it) {
78  if ((d = data->findDependency (*it)) == NULL) {
79  logprint (LOG_ERROR, "checker error, no such dependency `%s' as "
80  "stated in `%s'\n", *it, v->getName ());
81  errors++;
82  }
83  else {
84  n *= d->getSize ();
85  }
86  }
87  if (n != 0) {
88  if (v->getSize () % n != 0) {
89  logprint (LOG_ERROR, "checker error, size of vector `%s' %d should "
90  "be dividable by %d\n", v->getName (), v->getSize (), n);
91  errors++;
92  }
93  }
94  }
95  }
96 
97  return errors ? -1 : 0;
98 }