summaryrefslogtreecommitdiff
path: root/src/engines/gnucap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/engines/gnucap.c')
-rw-r--r--src/engines/gnucap.c555
1 files changed, 252 insertions, 303 deletions
diff --git a/src/engines/gnucap.c b/src/engines/gnucap.c
index e6297d0..f712153 100644
--- a/src/engines/gnucap.c
+++ b/src/engines/gnucap.c
@@ -5,7 +5,7 @@
* Ricardo Markiewicz <rmarkie@fi.uba.ar>
* Marc Lorber <lorber.marc@wanadoo.fr>
*
- * Web page: https://github.com/marc-lorber/oregano
+ * Web page: https://ahoi.io/project/oregano
*
* Copyright (C) 1999-2001 Richard Hult
* Copyright (C) 2003,2006 Ricardo Markiewicz
@@ -23,8 +23,8 @@
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
#include <glib.h>
@@ -42,14 +42,8 @@
// TODO Move analysis data and result to another file
#include "simulation.h"
-typedef enum {
- STATE_IDLE,
- IN_VARIABLES,
- IN_VALUES,
- STATE_ABORT
-} ParseDataState;
-
-struct analysis_tag {
+struct analysis_tag
+{
gchar *name;
guint len;
};
@@ -61,12 +55,13 @@ static struct analysis_tag analysis_tags[] = {
{"#Freq", 5}, /* AC */
};
-#define IS_THIS_ITEM(str,item) (!strncmp(str,item.name,item.len))
+#define IS_THIS_ITEM(str, item) (!strncmp (str, item.name, item.len))
#define GNUCAP_TITLE '#'
-#define TAGS_COUNT (sizeof (analysis_tags) / sizeof (struct analysis_tag))
+#define TAGS_COUNT (sizeof(analysis_tags) / sizeof(struct analysis_tag))
// Parser STATUS
-struct _OreganoGnuCapPriv {
+struct _OreganoGnuCapPriv
+{
GPid child_pid;
gint child_stdout;
GIOChannel *child_iochannel;
@@ -84,41 +79,39 @@ struct _OreganoGnuCapPriv {
guint buf_count;
};
-#define NG_DEBUG(s) if (0) g_print ("%s\n", s)
+#include "debug.h"
static void gnucap_class_init (OreganoGnuCapClass *klass);
static void gnucap_finalize (GObject *object);
static void gnucap_dispose (GObject *object);
static void gnucap_instance_init (GTypeInstance *instance, gpointer g_class);
static void gnucap_interface_init (gpointer g_iface, gpointer iface_data);
-static gboolean gnucap_child_stdout_cb (GIOChannel *source, GIOCondition condition, OreganoGnuCap *gnucap);
+static gboolean gnucap_child_stdout_cb (GIOChannel *source, GIOCondition condition,
+ OreganoGnuCap *gnucap);
static void gnucap_parse (gchar *raw, gint len, OreganoGnuCap *gnucap);
static gdouble strtofloat (char *s);
static GObjectClass *parent_class = NULL;
-GType
-oregano_gnucap_get_type (void)
+GType oregano_gnucap_get_type (void)
{
static GType type = 0;
if (type == 0) {
- static const GTypeInfo info = {
- sizeof (OreganoGnuCapClass),
- NULL, // base_init
- NULL, // base_finalize
- (GClassInitFunc) gnucap_class_init, // class_init
- NULL, // class_finalize
- NULL, // class_data
- sizeof (OreganoGnuCap),
- 0, // n_preallocs
- (GInstanceInitFunc) gnucap_instance_init, // instance_init
- NULL
- };
+ static const GTypeInfo info = {sizeof(OreganoGnuCapClass),
+ NULL, // base_init
+ NULL, // base_finalize
+ (GClassInitFunc)gnucap_class_init, // class_init
+ NULL, // class_finalize
+ NULL, // class_data
+ sizeof(OreganoGnuCap),
+ 0, // n_preallocs
+ (GInstanceInitFunc)gnucap_instance_init, // instance_init
+ NULL};
static const GInterfaceInfo gnucap_info = {
- (GInterfaceInitFunc) gnucap_interface_init, // interface_init
- NULL, // interface_finalize
- NULL // interface_data
+ (GInterfaceInitFunc)gnucap_interface_init, // interface_init
+ NULL, // interface_finalize
+ NULL // interface_data
};
type = g_type_register_static (G_TYPE_OBJECT, "OreganoGnuCap", &info, 0);
@@ -127,8 +120,7 @@ oregano_gnucap_get_type (void)
return type;
}
-static void
-gnucap_class_init (OreganoGnuCapClass *klass)
+static void gnucap_class_init (OreganoGnuCapClass *klass)
{
GObjectClass *object_class;
@@ -140,72 +132,60 @@ gnucap_class_init (OreganoGnuCapClass *klass)
object_class->finalize = gnucap_finalize;
}
-static void
-gnucap_finalize (GObject *object)
+static void gnucap_finalize (GObject *object)
{
SimulationData *data;
OreganoGnuCap *gnucap;
- GList *list;
+ GList *iter;
int i;
gnucap = OREGANO_GNUCAP (object);
- list = gnucap->priv->analysis;
- while (list) {
- data = SIM_DATA (list->data);
- for (i=0; i<data->n_variables; i++) {
+ iter = gnucap->priv->analysis;
+ for (; iter; iter = iter->next) {
+ data = SIM_DATA (iter->data);
+ for (i = 0; i < data->n_variables; i++) {
g_free (data->var_names[i]);
g_free (data->var_units[i]);
}
g_free (data->var_names);
g_free (data->var_units);
- for (i=0; i<data->n_variables; i++)
+ for (i = 0; i < data->n_variables; i++)
g_array_free (data->data[i], TRUE);
g_free (data->min_data);
g_free (data->max_data);
- g_free (list->data);
- list = list->next;
+ g_free (iter->data);
}
g_list_free (gnucap->priv->analysis);
gnucap->priv->analysis = NULL;
- g_list_free_full (list, g_object_unref);
parent_class->finalize (object);
}
-static void
-gnucap_dispose (GObject *object)
-{
- parent_class->dispose (object);
-}
+static void gnucap_dispose (GObject *object) { parent_class->dispose (object); }
-static gboolean
-gnucap_has_warnings (OreganoEngine *self)
-{
- return FALSE;
-}
+static gboolean gnucap_has_warnings (OreganoEngine *self) { return FALSE; }
-static gboolean
-gnucap_is_available (OreganoEngine *self)
+static gboolean gnucap_is_available (OreganoEngine *self)
{
gchar *exe;
exe = g_find_program_in_path ("gnucap");
- if (!exe) return FALSE; // gnucap not found
+ if (!exe)
+ return FALSE; // gnucap not found
g_free (exe);
return TRUE;
}
-static void
-gnucap_generate_netlist (OreganoEngine *engine, const gchar *filename,
- GError **error)
+static gboolean gnucap_generate_netlist (OreganoEngine *engine, const gchar *filename,
+ GError **error)
{
OreganoGnuCap *gnucap;
Netlist output;
SimOption *so;
- GList *list;
+ GList *iter;
FILE *file;
GError *local_error = NULL;
@@ -214,53 +194,50 @@ gnucap_generate_netlist (OreganoEngine *engine, const gchar *filename,
netlist_helper_create (gnucap->priv->schematic, &output, &local_error);
if (local_error != NULL) {
g_propagate_error (error, local_error);
- return;
+ return FALSE;
}
file = fopen (filename, "w");
if (!file) {
- oregano_error (g_strdup_printf ("Creation of %s not possible\n", filename));
- return;
+ oregano_error (g_strdup_printf ("Creation of file %s not possible\n", filename));
+ return FALSE;
}
- list = sim_settings_get_options (output.settings);
-
// Prints title
fputs (output.title ? output.title : "Title: <unset>", file);
fputs ("\n"
- "*----------------------------------------------"
- "\n"
- "*\tGNUCAP - NETLIST"
- "\n", file);
+ "*----------------------------------------------"
+ "\n"
+ "*\tGNUCAP - NETLIST"
+ "\n",
+ file);
// Prints Options
- fputs (".options OUT=120 ",file);
+ fputs (".options OUT=120 ", file);
- while (list) {
- so = list->data;
+ iter = sim_settings_get_options (output.settings);
+ for (; iter; iter = iter->next) {
+ so = iter->data;
// Prevent send NULL text
if (so->value) {
- if (strlen(so->value) > 0) {
- g_fprintf (file,"%s=%s ",so->name,so->value);
+ if (strlen (so->value) > 0) {
+ g_fprintf (file, "%s=%s ", so->name, so->value);
}
}
- list = list->next;
}
- fputc ('\n',file);
+ fputc ('\n', file);
// Include of subckt models
- fputs ("*------------- Models -------------------------\n",file);
- list = output.models;
- while (list) {
+ fputs ("*------------- Models -------------------------\n", file);
+ for (iter = output.models; iter; iter = iter->next) {
gchar *model;
- model = (gchar *)list->data;
- g_fprintf (file,".include %s/%s.model\n", OREGANO_MODELDIR, model);
- list = list->next;
+ model = (gchar *)iter->data;
+ g_fprintf (file, ".include %s/%s.model\n", OREGANO_MODELDIR, model);
}
- // Prints template parts
- fputs ("*------------- Circuit Description-------------\n",file);
+ // Prints template parts
+ fputs ("*------------- Circuit Description-------------\n", file);
fputs (output.template->str, file);
- fputs ("\n*----------------------------------------------\n",file);
+ fputs ("\n*----------------------------------------------\n", file);
// Prints Transient Analysis
if (sim_settings_get_trans (output.settings)) {
@@ -268,71 +245,70 @@ gnucap_generate_netlist (OreganoEngine *engine, const gchar *filename,
g_fprintf (file, ".print tran %s\n", tmp_str);
g_free (tmp_str);
- g_fprintf (file, ".tran %g %g ",
- sim_settings_get_trans_start (output.settings),
- sim_settings_get_trans_stop (output.settings));
+ g_fprintf (file, ".tran %g %g ", sim_settings_get_trans_start (output.settings),
+ sim_settings_get_trans_stop (output.settings));
if (!sim_settings_get_trans_step_enable (output.settings))
- g_fprintf (file,"%g",
- (sim_settings_get_trans_stop (output.settings)-
- sim_settings_get_trans_start (output.settings))/100);
+ g_fprintf (file, "%g", (sim_settings_get_trans_stop (output.settings) -
+ sim_settings_get_trans_start (output.settings)) /
+ 100);
else
- g_fprintf (file,"%g", sim_settings_get_trans_step (output.settings));
+ g_fprintf (file, "%g", sim_settings_get_trans_step (output.settings));
if (sim_settings_get_trans_init_cond (output.settings)) {
- fputs(" UIC\n", file);
- }
- else {
- fputs("\n", file);
+ fputs (" UIC\n", file);
+ } else {
+ fputs ("\n", file);
}
}
- // Print DC Analysis
+ // Print DC Analysis
if (sim_settings_get_dc (output.settings)) {
- g_fprintf (file, ".print dc %s\n", netlist_helper_create_analysis_string (output.store, FALSE));
- fputs (".dc ",file);
+ g_fprintf (file, ".print dc %s\n",
+ netlist_helper_create_analysis_string (output.store, FALSE));
+ fputs (".dc ", file);
// GNUCAP don't support nesting so the first or the second
// Maybe an error message must be show if both are on
- g_fprintf (file, "%s %g %g %g",
- sim_settings_get_dc_vsrc(output.settings),
- sim_settings_get_dc_start (output.settings),
- sim_settings_get_dc_stop (output.settings),
- sim_settings_get_dc_step (output.settings));
- fputc ('\n',file);
+ g_fprintf (file, "%s %g %g %g", sim_settings_get_dc_vsrc (output.settings),
+ sim_settings_get_dc_start (output.settings),
+ sim_settings_get_dc_stop (output.settings),
+ sim_settings_get_dc_step (output.settings));
+ fputc ('\n', file);
}
// Prints AC Analysis
if (sim_settings_get_ac (output.settings)) {
double ac_start, ac_stop, ac_step;
// GNUCAP dont support OCT or DEC: Maybe an error message
- // must be shown if the netlist is set in that way.
- ac_start = sim_settings_get_ac_start (output.settings) ;
+ // must be shown if the netlist is set in that way.
+ ac_start = sim_settings_get_ac_start (output.settings);
ac_stop = sim_settings_get_ac_stop (output.settings);
ac_step = (ac_stop - ac_start) / sim_settings_get_ac_npoints (output.settings);
- g_fprintf(file, ".print ac %s\n", netlist_helper_create_analysis_string (output.store, TRUE));
+ g_fprintf (file, ".print ac %s\n",
+ netlist_helper_create_analysis_string (output.store, TRUE));
// AC format : ac start stop step_size
g_fprintf (file, ".ac %g %g %g\n", ac_start, ac_stop, ac_step);
}
-
+
// Prints analysis using a Fourier transform
/* if (sim_settings_get_fourier (output.settings)) {
- gchar *tmp_str = netlist_helper_create_analysis_string (output.store, FALSE);
- g_fprintf (file, ".four %d %s\n",
- sim_settings_get_fourier_frequency (output.settings), tmp_str);
- g_free (tmp_str);
+ gchar *tmp_str = netlist_helper_create_analysis_string (output.store,
+ FALSE);
+ g_fprintf (file, ".four %d %s\n",
+ sim_settings_get_fourier_frequency (output.settings),
+ tmp_str);
+ g_free (tmp_str);
}*/
- g_list_free_full (list, g_object_unref);
-
// Debug op analysis.
fputs (".print op v(nodes)\n", file);
fputs (".op\n", file);
fputs (".end\n", file);
fclose (file);
+ return TRUE;
}
-static void
-gnucap_progress (OreganoEngine *self, double *d)
+static void gnucap_progress (OreganoEngine *self, double *d)
{
OreganoGnuCap *gnucap = OREGANO_GNUCAP (self);
@@ -340,8 +316,7 @@ gnucap_progress (OreganoEngine *self, double *d)
(*d) = gnucap->priv->progress;
}
-static void
-gnucap_stop (OreganoEngine *self)
+static void gnucap_stop (OreganoEngine *self)
{
OreganoGnuCap *gnucap = OREGANO_GNUCAP (self);
g_io_channel_shutdown (gnucap->priv->child_iochannel, TRUE, NULL);
@@ -350,8 +325,7 @@ gnucap_stop (OreganoEngine *self)
g_spawn_close_pid (gnucap->priv->child_stdout);
}
-static void
-gnucap_watch_cb (GPid pid, gint status, OreganoGnuCap *gnucap)
+static void gnucap_watch_cb (GPid pid, gint status, OreganoGnuCap *gnucap)
{
// check for status, see man waitpid(2)
if (WIFEXITED (status)) {
@@ -371,18 +345,17 @@ gnucap_watch_cb (GPid pid, gint status, OreganoGnuCap *gnucap)
gnucap->priv->current = NULL;
if (gnucap->priv->num_analysis == 0) {
- schematic_log_append_error (gnucap->priv->schematic,
- _("### Too few or none analysis found ###\n"));
+ schematic_log_append_error (gnucap->priv->schematic,
+ _ ("### Too few or none analysis found ###\n"));
gnucap->priv->aborted = TRUE;
g_signal_emit_by_name (G_OBJECT (gnucap), "aborted");
- }
- else
+ } else
g_signal_emit_by_name (G_OBJECT (gnucap), "done");
}
}
-static gboolean
-gnucap_child_stdout_cb (GIOChannel *source, GIOCondition condition, OreganoGnuCap *gnucap)
+static gboolean gnucap_child_stdout_cb (GIOChannel *source, GIOCondition condition,
+ OreganoGnuCap *gnucap)
{
gchar *line;
gsize len, terminator;
@@ -400,8 +373,7 @@ gnucap_child_stdout_cb (GIOChannel *source, GIOCondition condition, OreganoGnuCa
return TRUE;
}
-static void
-gnucap_start (OreganoEngine *self)
+static void gnucap_start (OreganoEngine *self)
{
OreganoGnuCap *gnucap;
GError *error = NULL;
@@ -418,67 +390,57 @@ gnucap_start (OreganoEngine *self)
}
error = NULL;
- if (g_spawn_async_with_pipes (
- NULL, // Working directory
- argv,
- NULL,
- G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
- NULL,
- NULL,
- &gnucap->priv->child_pid,
- NULL, // STDIN
- &gnucap->priv->child_stdout, // STDOUT
- NULL, // STDERR
- &error
- )) {
+ if (g_spawn_async_with_pipes (NULL, // Working directory
+ argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL,
+ NULL, &gnucap->priv->child_pid,
+ NULL, // STDIN
+ &gnucap->priv->child_stdout, // STDOUT
+ NULL, // STDERR
+ &error)) {
// Add a watch for process status
g_child_watch_add (gnucap->priv->child_pid, (GChildWatchFunc)gnucap_watch_cb, gnucap);
// Add a GIOChannel to read from process stdout
gnucap->priv->child_iochannel = g_io_channel_unix_new (gnucap->priv->child_stdout);
// Watch the I/O Channel to read child strout
- gnucap->priv->child_iochannel_watch = g_io_add_watch (gnucap->priv->child_iochannel,
- G_IO_IN|G_IO_PRI|G_IO_HUP|G_IO_NVAL, (GIOFunc)gnucap_child_stdout_cb, gnucap);
- }
- else {
+ gnucap->priv->child_iochannel_watch = g_io_add_watch (
+ gnucap->priv->child_iochannel, G_IO_IN | G_IO_PRI | G_IO_HUP | G_IO_NVAL,
+ (GIOFunc)gnucap_child_stdout_cb, gnucap);
+ } else {
gnucap->priv->aborted = TRUE;
- schematic_log_append_error (gnucap->priv->schematic, _("Unable to execute GnuCap."));
+ schematic_log_append_error (gnucap->priv->schematic, _ ("Unable to execute GnuCap."));
g_signal_emit_by_name (G_OBJECT (gnucap), "aborted");
}
}
-static GList*
-gnucap_get_results (OreganoEngine *self)
+static GList *gnucap_get_results (OreganoEngine *self)
{
return OREGANO_GNUCAP (self)->priv->analysis;
}
-static gchar *
-gnucap_get_operation (OreganoEngine *self)
+static gchar *gnucap_get_operation (OreganoEngine *self)
{
OreganoGnuCapPriv *priv = OREGANO_GNUCAP (self)->priv;
if (priv->current == NULL)
- return _("None");
+ return g_strdup(_("None"));
return oregano_engine_get_analysis_name (priv->current);
}
-static void
-gnucap_interface_init (gpointer g_iface, gpointer iface_data)
+static void gnucap_interface_init (gpointer g_iface, gpointer iface_data)
{
OreganoEngineClass *klass = (OreganoEngineClass *)g_iface;
klass->start = gnucap_start;
klass->stop = gnucap_stop;
- klass->progress = gnucap_progress;
+ klass->progress_solver = gnucap_progress;
klass->get_netlist = gnucap_generate_netlist;
klass->has_warnings = gnucap_has_warnings;
klass->get_results = gnucap_get_results;
- klass->get_operation = gnucap_get_operation;
+ klass->get_operation_solver = gnucap_get_operation;
klass->is_available = gnucap_is_available;
}
-static void
-gnucap_instance_init (GTypeInstance *instance, gpointer g_class)
+static void gnucap_instance_init (GTypeInstance *instance, gpointer g_class)
{
OreganoGnuCap *self = OREGANO_GNUCAP (instance);
@@ -493,8 +455,7 @@ gnucap_instance_init (GTypeInstance *instance, gpointer g_class)
self->priv->aborted = FALSE;
}
-OreganoEngine*
-oregano_gnucap_new (Schematic *sc)
+OreganoEngine *oregano_gnucap_new (Schematic *sc)
{
OreganoGnuCap *gnucap;
@@ -504,12 +465,12 @@ oregano_gnucap_new (Schematic *sc)
return OREGANO_ENGINE (gnucap);
}
-typedef struct {
+typedef struct
+{
gchar *name;
} GCap_Variable;
-static GCap_Variable *
-_get_variables (gchar *str, gint *count)
+static GCap_Variable *_get_variables (gchar *str, gint *count)
{
GCap_Variable *out;
gchar *tmp[100];
@@ -519,7 +480,8 @@ _get_variables (gchar *str, gint *count)
i = 0;
ini = str;
// Put blank in advance
- while (isspace (*ini)) ini++;
+ while (isspace (*ini))
+ ini++;
fin = ini;
while (*fin != '\0') {
if (isspace (*fin)) {
@@ -528,10 +490,11 @@ _get_variables (gchar *str, gint *count)
*fin = ' ';
i++;
ini = fin;
- while (isspace (*ini)) ini++;
+ while (isspace (*ini))
+ ini++;
fin = ini;
- }
- else fin++;
+ } else
+ fin++;
}
if (i == 0) {
@@ -541,23 +504,22 @@ _get_variables (gchar *str, gint *count)
out = g_new0 (GCap_Variable, i);
(*count) = i;
- for ( i=0; i< (*count); i++ ) {
+ for (i = 0; i < (*count); i++) {
out[i].name = tmp[i];
}
return out;
}
-static void
-_free_variables (GCap_Variable *v, gint count)
+static void _free_variables (GCap_Variable *v, gint count)
{
int i;
- for (i=0; i<count; i++)
+ for (i = 0; i < count; i++)
g_free (v[i].name);
g_free (v);
}
-gdouble
-strtofloat (gchar *s) {
+gdouble strtofloat (gchar *s)
+{
gdouble val;
gchar *error;
@@ -565,25 +527,26 @@ strtofloat (gchar *s) {
// If the value looks like : 100.u, adjust it
// We need this because GNU Cap's or ngSpice float notation
switch (error[0]) {
- case 'u':
- val /= 1000000;
+ case 'u':
+ val /= 1000000;
break;
- case 'n':
- val /= 1000000;
- val /= 1000;
+ case 'n':
+ val /= 1000000;
+ val /= 1000;
break;
- case 'p':
- val /= 1000000;
- val /= 1000000;
+ case 'p':
+ val /= 1000000;
+ val /= 1000000;
break;
- case 'f':
- val /= 100;
+ case 'f':
+ val /= 100;
break;
- case 'K':
- val *= 1000;
+ case 'K':
+ val *= 1000;
break;
- default:
- if (strcmp (error, "Meg") == 0) val *= 1000000;
+ default:
+ if (strcmp (error, "Meg") == 0)
+ val *= 1000000;
}
return val;
@@ -591,8 +554,7 @@ strtofloat (gchar *s) {
// Main method. Here we'll transform GnuCap output
// into SimulationResults!
-static void
-gnucap_parse (gchar *raw, gint len, OreganoGnuCap *gnucap)
+static void gnucap_parse (gchar *raw, gint len, OreganoGnuCap *gnucap)
{
static SimulationData *sdata;
static Analysis *data;
@@ -603,28 +565,27 @@ gnucap_parse (gchar *raw, gint len, OreganoGnuCap *gnucap)
gdouble val;
gchar *s;
- for (j=0; j < len; j++) {
+ for (j = 0; j < len; j++) {
if (raw[j] != '\n') {
buf[priv->buf_count++] = raw[j];
continue;
}
buf[priv->buf_count] = '\0';
- //Got a complete line
+ // Got a complete line
s = buf;
- NG_DEBUG (g_strdup_printf ("%s", s));
+ NG_DEBUG ("%s", s);
if (s[0] == GNUCAP_TITLE) {
SimSettings *sim_settings;
gdouble np1;
- sim_settings = (SimSettings *)schematic_get_sim_settings (priv->schematic);
+ sim_settings = schematic_get_sim_settings (priv->schematic);
data = g_new0 (Analysis, 1);
priv->current = sdata = SIM_DATA (data);
priv->analysis = g_list_append (priv->analysis, sdata);
priv->num_analysis++;
- sdata->state = STATE_IDLE;
- sdata->type = ANALYSIS_UNKNOWN;
+ sdata->type = ANALYSIS_TYPE_UNKNOWN;
sdata->functions = NULL;
// Calculates the quantity of variables
@@ -632,92 +593,90 @@ gnucap_parse (gchar *raw, gint len, OreganoGnuCap *gnucap)
for (i = 0; i < TAGS_COUNT; i++)
if (IS_THIS_ITEM (variables[0].name, analysis_tags[i]))
- sdata->type = i;
+ sdata->type = i + 1;
- sdata->state = IN_VALUES;
sdata->n_variables = n;
- sdata->got_points = 0;
- sdata->got_var = 0;
- sdata->var_names = (char**) g_new0 (gpointer, n);
- sdata->var_units = (char**) g_new0 (gpointer, n);
- sdata->data = (GArray**) g_new0 (gpointer, n);
+ sdata->got_points = 0;
+ sdata->got_var = 0;
+ sdata->var_names = (char **)g_new0 (gpointer, n);
+ sdata->var_units = (char **)g_new0 (gpointer, n);
+ sdata->data = (GArray **)g_new0 (gpointer, n);
for (i = 0; i < n; i++)
- sdata->data[i] = g_array_new (TRUE, TRUE, sizeof (double));
+ sdata->data[i] = g_array_new (TRUE, TRUE, sizeof(double));
sdata->min_data = g_new (double, n);
sdata->max_data = g_new (double, n);
for (i = 0; i < n; i++) {
- sdata->min_data[i] = G_MAXDOUBLE;
+ sdata->min_data[i] = G_MAXDOUBLE;
sdata->max_data[i] = -G_MAXDOUBLE;
}
for (i = 0; i < n; i++) {
sdata->var_names[i] = g_strdup (variables[i].name);
switch (sdata->type) {
- case TRANSIENT:
- if (i==0)
- sdata->var_units[i] = g_strdup (_("time"));
- else {
- if (strstr (sdata->var_names[i], "db") != NULL) {
- sdata->var_units[i] = g_strdup ("db");
- }
- else
- sdata->var_units[i] = g_strdup (_("voltage"));
- }
+ case ANALYSIS_TYPE_TRANSIENT:
+ if (i == 0)
+ sdata->var_units[i] = g_strdup (_ ("time"));
+ else {
+ if (strstr (sdata->var_names[i], "db") != NULL) {
+ sdata->var_units[i] = g_strdup ("db");
+ } else
+ sdata->var_units[i] = g_strdup (_ ("voltage"));
+ }
break;
- case AC:
- if (i == 0)
- sdata->var_units[i] = g_strdup (_("frequency"));
- else {
- if (strstr (sdata->var_names[i], "db") != NULL) {
- sdata->var_units[i] = g_strdup ("db");
- }
- else
- sdata->var_units[i] = g_strdup (_("voltage"));
- }
+ case ANALYSIS_TYPE_AC:
+ if (i == 0)
+ sdata->var_units[i] = g_strdup (_ ("frequency"));
+ else {
+ if (strstr (sdata->var_names[i], "db") != NULL) {
+ sdata->var_units[i] = g_strdup ("db");
+ } else
+ sdata->var_units[i] = g_strdup (_ ("voltage"));
+ }
break;
- default:
- sdata->var_units[i] = g_strdup ("");
+ default:
+ sdata->var_units[i] = g_strdup ("");
}
}
sdata->n_variables = n;
switch (sdata->type) {
- case TRANSIENT:
- data->transient.sim_length =
- sim_settings_get_trans_stop (sim_settings) -
- sim_settings_get_trans_start (sim_settings);
- data->transient.step_size =
- sim_settings_get_trans_step (sim_settings);
- break;
- case AC:
- data->ac.start = sim_settings_get_ac_start (sim_settings);
- data->ac.stop = sim_settings_get_ac_stop (sim_settings);
- data->ac.sim_length = sim_settings_get_ac_npoints (sim_settings);
- break;
- case OP_POINT:
- case DC_TRANSFER:
- np1 = 1.;
- data->dc.start = sim_settings_get_dc_start (sim_settings);
- data->dc.stop = sim_settings_get_dc_stop (sim_settings);
- data->dc.step = sim_settings_get_dc_step (sim_settings);
- np1 = (data->dc.stop - data->dc.start) / data->dc.step;
-
- data->dc.sim_length = np1;
- break;
- case TRANSFER:
- case DISTORTION:
- case NOISE:
- case POLE_ZERO:
- case SENSITIVITY:
- case FOURIER:
- break;
- case ANALYSIS_UNKNOWN:
- g_error (_("Unknown analysis"));
- break;
+ case ANALYSIS_TYPE_TRANSIENT:
+ data->transient.sim_length = sim_settings_get_trans_stop (sim_settings) -
+ sim_settings_get_trans_start (sim_settings);
+ data->transient.step_size = sim_settings_get_trans_step (sim_settings);
+ break;
+ case ANALYSIS_TYPE_AC:
+ data->ac.start = sim_settings_get_ac_start (sim_settings);
+ data->ac.stop = sim_settings_get_ac_stop (sim_settings);
+ data->ac.sim_length = sim_settings_get_ac_npoints (sim_settings);
+ break;
+ case ANALYSIS_TYPE_OP_POINT:
+ break;
+ case ANALYSIS_TYPE_DC_TRANSFER:
+ np1 = 1.;
+ data->dc.start = sim_settings_get_dc_start (sim_settings);
+ data->dc.stop = sim_settings_get_dc_stop (sim_settings);
+ data->dc.step = sim_settings_get_dc_step (sim_settings);
+ np1 = (data->dc.stop - data->dc.start) / data->dc.step;
+
+ data->dc.sim_length = np1;
+ break;
+ case ANALYSIS_TYPE_TRANSFER:
+ case ANALYSIS_TYPE_DISTORTION:
+ case ANALYSIS_TYPE_NOISE:
+ case ANALYSIS_TYPE_POLE_ZERO:
+ case ANALYSIS_TYPE_SENSITIVITY:
+ case ANALYSIS_TYPE_FOURIER:
+ break;
+ case ANALYSIS_TYPE_NONE:
+ g_error (_ ("No analysis"));
+ break;
+ case ANALYSIS_TYPE_UNKNOWN:
+ g_error (_ ("Unknown analysis"));
+ break;
}
- }
- else {
+ } else {
if ((priv->analysis == NULL) || (isalpha (s[0]))) {
if (priv->buf_count > 1) {
schematic_log_append (priv->schematic, s);
@@ -727,49 +686,39 @@ gnucap_parse (gchar *raw, gint len, OreganoGnuCap *gnucap)
continue;
}
- switch (sdata->state) {
- case IN_VALUES:
- val = strtofloat (s);
- switch (sdata->type) {
- case TRANSIENT:
- priv->progress = val / data->transient.sim_length;
- break;
- case AC:
- priv->progress = (val - data->ac.start) / data->ac.sim_length;
- break;
- case DC_TRANSFER:
- priv->progress = val / data->ac.sim_length;
- default:
- break;
- }
- if (priv->progress > 1.0)
- priv->progress = 1.0;
-
- variables = _get_variables (s, &n);
- for (i = 0; i < n; i++) {
- val = strtofloat (variables[i].name);
- sdata->data[i] = g_array_append_val (sdata->data[i], val);
-
- // Update the minimal and maximal values so far.
- if (val < sdata->min_data[i])
- sdata->min_data[i] = val;
- if (val > sdata->max_data[i])
- sdata->max_data[i] = val;
- }
+ val = strtofloat (s);
+ switch (sdata->type) {
+ case ANALYSIS_TYPE_TRANSIENT:
+ priv->progress = val / data->transient.sim_length;
+ break;
+ case ANALYSIS_TYPE_AC:
+ priv->progress = (val - data->ac.start) / data->ac.sim_length;
+ break;
+ case ANALYSIS_TYPE_DC_TRANSFER:
+ priv->progress = val / data->ac.sim_length;
+ break;
+ default:
+ break;
+ }
+ if (priv->progress > 1.0)
+ priv->progress = 1.0;
- _free_variables (variables, n);
- sdata->got_points++;
- sdata->got_var = n;
- break;
- default:
- if (priv->buf_count > 1) {
- if (strstr (s, _("abort")))
- sdata->state = STATE_ABORT;
- schematic_log_append_error (priv->schematic, s);
- }
+ variables = _get_variables (s, &n);
+ for (i = 0; i < n; i++) {
+ val = strtofloat (variables[i].name);
+ sdata->data[i] = g_array_append_val (sdata->data[i], val);
+
+ // Update the minimum and maximum values so far.
+ if (val < sdata->min_data[i])
+ sdata->min_data[i] = val;
+ if (val > sdata->max_data[i])
+ sdata->max_data[i] = val;
}
+
+ _free_variables (variables, n);
+ sdata->got_points++;
+ sdata->got_var = n;
}
priv->buf_count = 0;
}
}
-