Qucs-core  0.0.19
analysis.cpp
Go to the documentation of this file.
00001 /*
00002  * analysis.cpp - analysis class implementation
00003  *
00004  *
00005  * Copyright (C) 2003-2008 Stefan Jahn <stefan@lkcc.org>
00006  *
00007  * This is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2, or (at your option)
00010  * any later version.
00011  *
00012  * This software is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this package; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021  *
00022  * $Id: analysis.cpp 1869 2013-03-06 12:50:21Z crobarcro $
00023  *
00024  */
00025 
00033 #if HAVE_CONFIG_H
00034 # include <config.h>
00035 #endif
00036 
00037 //#include <stdio.h>
00038 //#include <stdlib.h>
00039 #include <string.h>
00040 
00041 #include "object.h"
00042 #include "complex.h"
00043 #include "sweep.h"
00044 #include "vector.h"
00045 #include "strlist.h"
00046 #include "dataset.h"
00047 #include "ptrlist.h"
00048 #include "analysis.h"
00049 
00050 namespace qucs {
00051 
00052 //Constructor. Creates an unnamed instance of the analysis class.
00053 analysis::analysis () : object () {
00054   data = NULL;
00055   subnet = NULL;
00056   env = NULL;
00057   actions = NULL;
00058   type = ANALYSIS_UNKNOWN;
00059   runs = 0;
00060   progress = true;
00061 }
00062 
00063 // Constructor creates a named instance of the analysis class.
00064 analysis::analysis (const std::string &n) : object (n) {
00065   data = NULL;
00066   subnet = NULL;
00067   env = NULL;
00068   actions = NULL;
00069   type = ANALYSIS_UNKNOWN;
00070   runs = 0;
00071   progress = true;
00072 }
00073 
00074 // Destructor deletes the analysis class object.
00075 analysis::~analysis () {
00076   delete actions;
00077 }
00078 
00079 /* The copy constructor creates a new instance of the analysis class
00080    based on the given analysis object. */
00081 analysis::analysis (analysis & a) : object (a) {
00082   data = a.data;
00083   subnet = a.subnet;
00084   env = a.env;
00085   actions = a.actions ? new ptrlist<analysis> (*a.actions) : NULL;
00086   type = a.type;
00087   runs = a.runs;
00088   progress = a.progress;
00089 }
00090 
00091 /* This function adds the given analysis to the actions being
00092    associated with the current analysis object. */
00093 void analysis::addAnalysis (analysis * a) {
00094   if (!actions) actions = new ptrlist<analysis> ();
00095   actions->push_front (a);
00096 }
00097 
00098 /* This function deletes the given analysis from the actions being
00099    associated with the current analysis object. */
00100 void analysis::delAnalysis (analysis * a) {
00101   if (actions != nullptr) {
00102     actions->remove (a);
00103   }
00104 }
00105 
00106 /* The following function creates a sweep object depending on the
00107    analysis's properties.  Supported sweep types are: linear,
00108    logarithmic, lists and constants. */
00109 sweep * analysis::createSweep (const std::string& n) {
00110   sweep * swp = NULL;
00111   // get type of sweep
00112   const char * const type = getPropertyString ("Type");
00113 
00114   // linearly or logarithmically stepped sweeps
00115   if (!strcmp (type, "lin") || !strcmp (type, "log")) {
00116     nr_double_t start = getPropertyDouble ("Start");
00117     nr_double_t stop = getPropertyDouble ("Stop");
00118     int points = getPropertyInteger ("Points");
00119     if (!strcmp (type, "lin")) {
00120       swp = new linsweep (n);
00121       ((linsweep *) swp)->create (start, stop, points);
00122     }
00123     else if (!strcmp (type, "log")) {
00124       swp = new logsweep (n);
00125       ((logsweep *) swp)->create (start, stop, points);
00126     }
00127   }
00128 
00129   // lists of values
00130   else if (!strcmp (type, "list")) {
00131     vector * values = getPropertyVector ("Values");
00132     int points = values->getSize ();
00133     swp = new lstsweep (n);
00134     ((lstsweep *) swp)->create (points);
00135     for (int i = 0; i < values->getSize (); i++)
00136       swp->set (i, real (values->get (i)));
00137   }
00138 
00139   // constant value
00140   else if (!strcmp (type, "const")) {
00141     nr_double_t val = getPropertyDouble ("Values");
00142     swp = new consweep (n);
00143     ((consweep *) swp)->create (1);
00144     swp->set (0, val);
00145   }
00146 
00147   swp->setParent (this);
00148   return swp;
00149 }
00150 
00151 /* Saves the given variable into the dataset.  Creates the dataset
00152    vector if necessary. */
00153   void analysis::saveVariable (const std::string &n, nr_complex_t z, vector * f) {
00154   vector * d;
00155   if ((d = data->findVariable (n)) == NULL) {
00156     d = new vector (n);
00157     if (f != NULL) {
00158       d->setDependencies (new strlist ());
00159       d->getDependencies()->add (f->getName ());
00160     }
00161     d->setOrigin (getName ());
00162     data->addVariable (d);
00163   }
00164   d->add (z);
00165 }
00166 
00167 } // namespace qucs