Qucs-core
0.0.19
|
00001 /* 00002 * check_dataset.cpp - checker for the Qucs dataset 00003 * 00004 * Copyright (C) 2003, 2006 Stefan Jahn <stefan@lkcc.org> 00005 * 00006 * This is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2, or (at your option) 00009 * any later version. 00010 * 00011 * This software is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this package; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 * $Id$ 00022 * 00023 */ 00024 00025 #if HAVE_CONFIG_H 00026 # include <config.h> 00027 #endif 00028 00029 #include <stdio.h> 00030 #include <stdlib.h> 00031 #include <string.h> 00032 #include <cmath> 00033 00034 #include "logging.h" 00035 #include "complex.h" 00036 #include "object.h" 00037 #include "vector.h" 00038 #include "dataset.h" 00039 #include "strlist.h" 00040 #include "check_dataset.h" 00041 00042 using namespace qucs; 00043 00044 strlist * dataset_idents = NULL; 00045 dataset * dataset_result = NULL; 00046 vector * dataset_vector = NULL; 00047 00048 /* This function is the checker routine for a parsed dataset. It 00049 returns zero on success or non-zero if the parsed dataset contained 00050 errors. */ 00051 int dataset_check (dataset * data) { 00052 00053 int errors = 0; 00054 vector * v, * d; 00055 00056 /* check actual size and requested size of independent vectors */ 00057 for (v = data->getDependencies (); v != NULL; v = (vector *) v->getNext ()) { 00058 if (v->getSize () != v->getRequested ()) { 00059 logprint (LOG_ERROR, "checker error, vector `%s' contains %d values, " 00060 "%d have been stated\n", v->getName (), v->getSize (), 00061 v->getRequested ()); 00062 errors++; 00063 } 00064 } 00065 00066 /* check dependencies of dependent vectors */ 00067 for (v = data->getVariables (); v != NULL; v = (vector *) v->getNext ()) { 00068 strlist * s = v->getDependencies (); 00069 /* any dependencies at all ? */ 00070 if (s == NULL || s->length () == 0) { 00071 logprint (LOG_ERROR, "checker error, vector `%s' contains no " 00072 "dependencies\n", v->getName ()); 00073 errors++; 00074 } 00075 /* yes */ 00076 else { 00077 int n = 1; 00078 /* go through each dependency and check it */ 00079 for (strlistiterator it (s); *it; ++it) { 00080 if ((d = data->findDependency (*it)) == NULL) { 00081 logprint (LOG_ERROR, "checker error, no such dependency `%s' as " 00082 "stated in `%s'\n", *it, v->getName ()); 00083 errors++; 00084 } 00085 else { 00086 n *= d->getSize (); 00087 } 00088 } 00089 if (n != 0) { 00090 if (v->getSize () % n != 0) { 00091 logprint (LOG_ERROR, "checker error, size of vector `%s' %d should " 00092 "be dividable by %d\n", v->getName (), v->getSize (), n); 00093 errors++; 00094 } 00095 } 00096 } 00097 } 00098 00099 return errors ? -1 : 0; 00100 }