Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 int dataset_check (dataset * data) {
52 
53  int errors = 0;
54  vector * v, * d;
55 
56  /* check actual size and requested size of independent vectors */
57  for (v = data->getDependencies (); v != NULL; v = (vector *) v->getNext ()) {
58  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  v->getRequested ());
62  errors++;
63  }
64  }
65 
66  /* check dependencies of dependent vectors */
67  for (v = data->getVariables (); v != NULL; v = (vector *) v->getNext ()) {
68  strlist * s = v->getDependencies ();
69  /* any dependencies at all ? */
70  if (s == NULL || s->length () == 0) {
71  logprint (LOG_ERROR, "checker error, vector `%s' contains no "
72  "dependencies\n", v->getName ());
73  errors++;
74  }
75  /* yes */
76  else {
77  int n = 1;
78  /* go through each dependency and check it */
79  for (strlistiterator it (s); *it; ++it) {
80  if ((d = data->findDependency (*it)) == NULL) {
81  logprint (LOG_ERROR, "checker error, no such dependency `%s' as "
82  "stated in `%s'\n", *it, v->getName ());
83  errors++;
84  }
85  else {
86  n *= d->getSize ();
87  }
88  }
89  if (n != 0) {
90  if (v->getSize () % n != 0) {
91  logprint (LOG_ERROR, "checker error, size of vector `%s' %d should "
92  "be dividable by %d\n", v->getName (), v->getSize (), n);
93  errors++;
94  }
95  }
96  }
97  }
98 
99  return errors ? -1 : 0;
100 }
int dataset_check(dataset *data)
n
Definition: parse_citi.y:147
dataset * dataset_result
strlist * dataset_idents
v
Definition: parse_zvr.y:141
#define LOG_ERROR
Definition: logging.h:28
vector * dataset_vector
void logprint(int level, const char *format,...)
Definition: logging.c:37
data
Definition: parse_citi.y:117