1 /*
2  * sim-settings.c
3  *
4  *
5  * Authors:
6  *  Richard Hult <rhult@hem.passagen.se>
7  *  Ricardo Markiewicz <rmarkie@fi.uba.ar>
8  *  Andres de Barbara <adebarbara@fi.uba.ar>
9  *  Marc Lorber <lorber.marc@wanadoo.fr>
10  *  Bernhard Schuster <bernhard@ahoi.io>
11  *  Guido Trentalancia <guido@trentalancia.com>
12  *
13  * Web page: https://ahoi.io/project/oregano
14  *
15  * Copyright (C) 1999-2001  Richard Hult
16  * Copyright (C) 2003,2006  Ricardo Markiewicz
17  * Copyright (C) 2009-2012  Marc Lorber
18  * Copyright (C) 2013-2014  Bernhard Schuster
19  * Copyright (C) 2017       Guido Trentalancia
20  *
21  * This program is free software; you can redistribute it and/or
22  * modify it under the terms of the GNU General Public License as
23  * published by the Free Software Foundation; either version 2 of the
24  * License, or (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29  * General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public
32  * License along with this program; if not, write to the
33  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
34  * Boston, MA 02110-1301, USA.
35  */
36 
37 #include <stdlib.h>
38 #include <string.h>
39 #include <glib.h>
40 
41 #include "oregano-utils.h"
42 #include "sim-settings.h"
43 
sim_settings_new()44 SimSettings *sim_settings_new ()
45 {
46 	SimSettings *sim_settings;
47 
48 	sim_settings = g_new0 (SimSettings, 1);
49 
50 	sim_settings->configured = FALSE;
51 	sim_settings->simulation_requested = FALSE;
52 
53 	// Set some default settings.
54 	// transient
55 	sim_settings->trans_enable = TRUE;
56 	sim_settings->trans_start = g_strdup ("0 s");
57 	sim_settings->trans_stop = g_strdup ("5 ms");
58 	sim_settings->trans_step = g_strdup ("0.1 ms");
59 	sim_settings->trans_step_enable = FALSE;
60 
61 	//  AC
62 	sim_settings->ac_enable = FALSE;
63 	sim_settings->ac_vout = g_strdup ("");
64 	sim_settings->ac_type = g_strdup ("DEC");
65 	sim_settings->ac_npoints = g_strdup ("50");
66 	sim_settings->ac_start = g_strdup ("1 Hz");
67 	sim_settings->ac_stop = g_strdup ("1 MHz");
68 
69 	// DC
70 	sim_settings->dc_enable = FALSE;
71 	sim_settings->dc_vin = g_strdup ("");
72 	sim_settings->dc_vout = g_strdup ("");
73 	sim_settings->dc_start = g_strdup ("");
74 	sim_settings->dc_stop = g_strdup ("");
75 	sim_settings->dc_step = g_strdup ("");
76 
77 	// Fourier
78 	sim_settings->fourier_enable = FALSE;
79 	sim_settings->fourier_frequency = g_strdup ("1 MHz");
80 	sim_settings->fourier_vout = NULL;
81 
82 	//  Noise
83 	sim_settings->noise_enable = FALSE;
84 	sim_settings->noise_vin = g_strdup ("");
85 	sim_settings->noise_vout = g_strdup ("");
86 	sim_settings->noise_type = g_strdup ("DEC");
87 	sim_settings->noise_npoints = g_strdup ("50");
88 	sim_settings->noise_start = g_strdup ("1 Hz");
89 	sim_settings->noise_stop = g_strdup ("1 MHz");
90 
91 	sim_settings->options = NULL;
92 
93 	return sim_settings;
94 }
95 
sim_option_finalize(SimOption * option)96 static void sim_option_finalize(SimOption *option) {
97 	g_free(option->name);
98 	g_free(option->value);
99 	g_free(option);
100 }
101 
sim_settings_finalize(SimSettings * sim_settings)102 void sim_settings_finalize(SimSettings *sim_settings) {
103 
104 	// Set some default settings.
105 	// transient
106 	g_free(sim_settings->trans_start);
107 	g_free(sim_settings->trans_stop);
108 	g_free(sim_settings->trans_step);
109 
110 	//  AC
111 	g_free(sim_settings->ac_vout);
112 	g_free(sim_settings->ac_type);
113 	g_free(sim_settings->ac_npoints);
114 	g_free(sim_settings->ac_start);
115 	g_free(sim_settings->ac_stop);
116 
117 	// DC
118 	g_free(sim_settings->dc_vin);
119 	g_free(sim_settings->dc_vout);
120 	g_free(sim_settings->dc_start);
121 	g_free(sim_settings->dc_stop);
122 	g_free(sim_settings->dc_step);
123 
124 	// Fourier
125 	sim_settings->fourier_enable = FALSE;
126 	g_free(sim_settings->fourier_frequency);
127 	if (sim_settings->fourier_vout != NULL)
128 		g_slist_free_full(sim_settings->fourier_vout, g_free);
129 
130 	// Noise
131 	g_free(sim_settings->noise_vin);
132 	g_free(sim_settings->noise_vout);
133 	g_free(sim_settings->noise_type);
134 	g_free(sim_settings->noise_npoints);
135 	g_free(sim_settings->noise_start);
136 	g_free(sim_settings->noise_stop);
137 
138 	if (sim_settings->options != NULL)
139 		g_list_free_full(sim_settings->options, (GDestroyNotify)sim_option_finalize);
140 
141 	g_free(sim_settings);
142 }
143 
fourier_add_vout(SimSettings * sim_settings,guint node_index)144 gchar *fourier_add_vout(SimSettings *sim_settings, guint node_index) {
145 	gboolean result;
146 	guint i;
147 	gchar *ret_val = NULL;
148 	gchar *text;
149 	gchar **node_ids;
150 	GSList *node_slist;
151 
152 	// Is the node identifier for the output vector already
153 	// stored in the fourier_vout list ?
154 	node_slist = g_slist_copy (sim_settings->fourier_vout);
155 	result = FALSE;
156 	while (node_slist) {
157 		if ((node_index - 1) == atoi (node_slist->data)) {
158 			result = TRUE;
159 		}
160 		node_slist = node_slist->next;
161 	}
162 
163 	g_slist_free_full (node_slist, g_free);
164 
165 	// If the output vector is not already in the fourier_vout list
166 	// then add it to the list and return the updated list.
167 	// Otherwise, simply return the existing list of output vectors.
168 	if (!result) {
169 		// Add Node (node_index-1) at the end of fourier_vout
170 		text = g_strdup_printf ("%d", node_index - 1);
171 		sim_settings->fourier_vout =
172 			g_slist_append (sim_settings->fourier_vout, text);
173 
174 		// Update the fourier_vout widget
175 		node_slist = g_slist_copy (sim_settings->fourier_vout);
176 		if (node_slist) {
177 			if (node_slist->data && atoi (node_slist->data) > 0)
178 				ret_val = g_strdup_printf ("V(%d)", atoi (node_slist->data));
179 			node_slist = node_slist->next;
180 		}
181 		while (node_slist) {
182 			if (node_slist->data && atoi (node_slist->data) > 0) {
183 				if (ret_val) {
184 					text = ret_val;
185 					ret_val = g_strdup_printf ("%s V(%d)", ret_val, atoi (node_slist->data));
186 					g_free (text);
187 				} else {
188 					ret_val = g_strdup_printf ("V(%d)", atoi (node_slist->data));
189 				}
190 			}
191 			node_slist = node_slist->next;
192 		}
193 
194 		g_slist_free_full (node_slist, g_free);
195 	} else {
196 		text = sim_settings_get_fourier_vout (sim_settings);
197 		node_ids = g_strsplit (text, " ", 0);
198 
199 		for (i = 0; node_ids[i] != NULL; i++) {
200 			if (node_ids[i] && atoi (node_ids[i]) > 0) {
201 				if (ret_val) {
202 					text = ret_val;
203 					ret_val = g_strdup_printf ("%s V(%d)", ret_val, atoi (node_ids[i]));
204 					g_free (text);
205 				} else {
206 					ret_val = g_strdup_printf ("V(%d)", atoi (node_ids[i]));
207 				}
208 			}
209 		}
210 
211 		g_strfreev (node_ids);
212 	}
213 
214 	if (!ret_val)
215 		ret_val = g_strdup ("");
216 
217 	return ret_val;
218 }
219 
sim_settings_get_trans(const SimSettings * sim_settings)220 gboolean sim_settings_get_trans (const SimSettings *sim_settings)
221 {
222 	return sim_settings->trans_enable;
223 }
224 
sim_settings_get_trans_init_cond(const SimSettings * sim_settings)225 gboolean sim_settings_get_trans_init_cond (const SimSettings *sim_settings)
226 {
227 	return sim_settings->trans_init_cond;
228 }
229 
sim_settings_get_trans_analyze_all(const SimSettings * sim_settings)230 gboolean sim_settings_get_trans_analyze_all (const SimSettings *sim_settings)
231 {
232 	return sim_settings->trans_analyze_all;
233 }
234 
sim_settings_get_trans_start(const SimSettings * sim_settings)235 gdouble sim_settings_get_trans_start (const SimSettings *sim_settings)
236 {
237 	gchar *text = sim_settings->trans_start;
238 	return oregano_strtod (text, "s");
239 }
240 
sim_settings_get_trans_stop(const SimSettings * sim_settings)241 gdouble sim_settings_get_trans_stop (const SimSettings *sim_settings)
242 {
243 	gchar *text = sim_settings->trans_stop;
244 	return oregano_strtod (text, "s");
245 }
246 
sim_settings_get_trans_step(const SimSettings * sim_settings)247 gdouble sim_settings_get_trans_step (const SimSettings *sim_settings)
248 {
249 	gchar *text = sim_settings->trans_step;
250 	return oregano_strtod (text, "s");
251 }
252 
sim_settings_get_trans_step_enable(const SimSettings * sim_settings)253 gdouble sim_settings_get_trans_step_enable (const SimSettings *sim_settings)
254 {
255 	return sim_settings->trans_step_enable;
256 }
257 
sim_settings_set_trans(SimSettings * sim_settings,gboolean enable)258 void sim_settings_set_trans (SimSettings *sim_settings, gboolean enable)
259 {
260 	sim_settings->trans_enable = enable;
261 }
262 
sim_settings_set_trans_start(SimSettings * sim_settings,gchar * str)263 void sim_settings_set_trans_start (SimSettings *sim_settings, gchar *str)
264 {
265 	if (sim_settings->trans_start)
266 		g_strdup (sim_settings->trans_start);
267 	sim_settings->trans_start = g_strdup (str);
268 }
269 
sim_settings_set_trans_init_cond(SimSettings * sim_settings,gboolean enable)270 void sim_settings_set_trans_init_cond (SimSettings *sim_settings, gboolean enable)
271 {
272 	sim_settings->trans_init_cond = enable;
273 }
274 
sim_settings_set_trans_analyze_all(SimSettings * sim_settings,gboolean enable)275 void sim_settings_set_trans_analyze_all (SimSettings *sim_settings, gboolean enable)
276 {
277 	sim_settings->trans_analyze_all = enable;
278 }
279 
sim_settings_set_trans_stop(SimSettings * sim_settings,gchar * str)280 void sim_settings_set_trans_stop (SimSettings *sim_settings, gchar *str)
281 {
282 	if (sim_settings->trans_stop)
283 		g_strdup (sim_settings->trans_stop);
284 	sim_settings->trans_stop = g_strdup (str);
285 }
286 
sim_settings_set_trans_step(SimSettings * sim_settings,gchar * str)287 void sim_settings_set_trans_step (SimSettings *sim_settings, gchar *str)
288 {
289 	if (sim_settings->trans_step)
290 		g_strdup (sim_settings->trans_step);
291 	sim_settings->trans_step = g_strdup (str);
292 }
293 
sim_settings_set_trans_step_enable(SimSettings * sim_settings,gboolean enable)294 void sim_settings_set_trans_step_enable (SimSettings *sim_settings, gboolean enable)
295 {
296 	sim_settings->trans_step_enable = enable;
297 }
298 
sim_settings_get_ac(const SimSettings * sim_settings)299 gboolean sim_settings_get_ac (const SimSettings *sim_settings) { return sim_settings->ac_enable; }
300 
sim_settings_get_ac_vout(const SimSettings * sim_settings)301 gchar *sim_settings_get_ac_vout (const SimSettings *sim_settings) { return sim_settings->ac_vout; }
302 
sim_settings_get_ac_type(const SimSettings * sim_settings)303 gchar *sim_settings_get_ac_type (const SimSettings *sim_settings) { return sim_settings->ac_type; }
304 
sim_settings_get_ac_npoints(const SimSettings * sim_settings)305 gint sim_settings_get_ac_npoints (const SimSettings *sim_settings)
306 {
307 	return atoi (sim_settings->ac_npoints);
308 }
309 
sim_settings_get_ac_start(const SimSettings * sim_settings)310 gdouble sim_settings_get_ac_start (const SimSettings *sim_settings)
311 {
312 	return oregano_strtod (sim_settings->ac_start, "Hz");
313 }
314 
sim_settings_get_ac_stop(const SimSettings * sim_settings)315 gdouble sim_settings_get_ac_stop (const SimSettings *sim_settings)
316 {
317 	return oregano_strtod (sim_settings->ac_stop, "Hz");
318 }
319 
sim_settings_set_ac(SimSettings * sim_settings,gboolean enable)320 void sim_settings_set_ac (SimSettings *sim_settings, gboolean enable)
321 {
322 	sim_settings->ac_enable = enable;
323 }
324 
sim_settings_set_ac_vout(SimSettings * sim_settings,gchar * str)325 void sim_settings_set_ac_vout (SimSettings *sim_settings, gchar *str)
326 {
327 	g_free (sim_settings->ac_vout);
328 	sim_settings->ac_vout = g_strdup (str);
329 }
330 
sim_settings_set_ac_type(SimSettings * sim_settings,gchar * str)331 void sim_settings_set_ac_type (SimSettings *sim_settings, gchar *str)
332 {
333 	g_free (sim_settings->ac_type);
334 	sim_settings->ac_type = g_strdup (str);
335 }
336 
sim_settings_set_ac_npoints(SimSettings * sim_settings,gchar * str)337 void sim_settings_set_ac_npoints (SimSettings *sim_settings, gchar *str)
338 {
339 	g_free (sim_settings->ac_npoints);
340 	sim_settings->ac_npoints = g_strdup (str);
341 }
342 
sim_settings_set_ac_start(SimSettings * sim_settings,gchar * str)343 void sim_settings_set_ac_start (SimSettings *sim_settings, gchar *str)
344 {
345 	g_free (sim_settings->ac_start);
346 	sim_settings->ac_start = g_strdup (str);
347 }
348 
sim_settings_set_ac_stop(SimSettings * sim_settings,gchar * str)349 void sim_settings_set_ac_stop (SimSettings *sim_settings, gchar *str)
350 {
351 	g_free (sim_settings->ac_stop);
352 	sim_settings->ac_stop = g_strdup (str);
353 }
354 
sim_settings_get_dc(const SimSettings * sim_settings)355 gboolean sim_settings_get_dc (const SimSettings *sim_settings) { return sim_settings->dc_enable; }
356 
sim_settings_get_dc_vsrc(const SimSettings * sim_settings)357 gchar *sim_settings_get_dc_vsrc (const SimSettings *sim_settings) { return sim_settings->dc_vin; }
358 
sim_settings_get_dc_vout(const SimSettings * sim_settings)359 gchar *sim_settings_get_dc_vout (const SimSettings *sim_settings) { return sim_settings->dc_vout; }
360 
sim_settings_get_dc_start(const SimSettings * sim_settings)361 gdouble sim_settings_get_dc_start (const SimSettings *sim_settings)
362 {
363 	return oregano_strtod (sim_settings->dc_start, "V");
364 }
365 
sim_settings_get_dc_stop(const SimSettings * sim_settings)366 gdouble sim_settings_get_dc_stop (const SimSettings *sim_settings)
367 {
368 	return oregano_strtod (sim_settings->dc_stop, "V");
369 }
370 
sim_settings_get_dc_step(const SimSettings * sim_settings)371 gdouble sim_settings_get_dc_step (const SimSettings *sim_settings)
372 {
373 	return oregano_strtod (sim_settings->dc_step, "V");
374 }
375 
sim_settings_set_dc(SimSettings * sim_settings,gboolean enable)376 void sim_settings_set_dc (SimSettings *sim_settings, gboolean enable)
377 {
378 	sim_settings->dc_enable = enable;
379 }
380 
sim_settings_set_dc_vsrc(SimSettings * sim_settings,gchar * str)381 void sim_settings_set_dc_vsrc (SimSettings *sim_settings, gchar *str)
382 {
383 	g_free (sim_settings->dc_vin);
384 	sim_settings->dc_vin = g_strdup (str);
385 }
386 
sim_settings_set_dc_vout(SimSettings * sim_settings,gchar * str)387 void sim_settings_set_dc_vout (SimSettings *sim_settings, gchar *str)
388 {
389 	g_free (sim_settings->dc_vout);
390 	sim_settings->dc_vout = g_strdup (str);
391 }
392 
sim_settings_set_dc_start(SimSettings * sim_settings,gchar * str)393 void sim_settings_set_dc_start (SimSettings *sim_settings, gchar *str)
394 {
395 	g_free (sim_settings->dc_start);
396 	sim_settings->dc_start = g_strdup (str);
397 }
398 
sim_settings_set_dc_stop(SimSettings * sim_settings,gchar * str)399 void sim_settings_set_dc_stop (SimSettings *sim_settings, gchar *str)
400 {
401 	g_free (sim_settings->dc_stop);
402 	sim_settings->dc_stop = g_strdup (str);
403 }
404 
sim_settings_set_dc_step(SimSettings * sim_settings,gchar * str)405 void sim_settings_set_dc_step (SimSettings *sim_settings, gchar *str)
406 {
407 	g_free (sim_settings->dc_step);
408 	sim_settings->dc_step = g_strdup (str);
409 }
410 
sim_settings_set_fourier(SimSettings * sim_settings,gboolean enable)411 void sim_settings_set_fourier (SimSettings *sim_settings, gboolean enable)
412 {
413 	sim_settings->fourier_enable = enable;
414 }
415 
sim_settings_set_fourier_frequency(SimSettings * sim_settings,gchar * str)416 void sim_settings_set_fourier_frequency (SimSettings *sim_settings, gchar *str)
417 {
418 	g_free (sim_settings->fourier_frequency);
419 	sim_settings->fourier_frequency = g_strdup (str);
420 }
421 
sim_settings_set_fourier_vout(SimSettings * sim_settings,gchar * str)422 void sim_settings_set_fourier_vout (SimSettings *sim_settings, gchar *str)
423 {
424 	gchar **node_ids = NULL;
425 	gint i;
426 
427 	if (!str)
428 		return;
429 
430 	g_slist_free_full (sim_settings->fourier_vout, g_free);
431 	sim_settings->fourier_vout = NULL;
432 
433 	node_ids = g_strsplit (str, " ", 0);
434 	for (i = 0; node_ids[i] != NULL; i++) {
435 		if (node_ids[i])
436 			sim_settings->fourier_vout =
437 			    g_slist_append (sim_settings->fourier_vout, g_strdup (node_ids[i]));
438 	}
439 
440 	g_strfreev (node_ids);
441 }
442 
sim_settings_get_fourier(const SimSettings * sim_settings)443 gboolean sim_settings_get_fourier (const SimSettings *sim_settings)
444 {
445 	return sim_settings->fourier_enable;
446 }
447 
sim_settings_get_fourier_frequency(const SimSettings * sim_settings)448 gdouble sim_settings_get_fourier_frequency (const SimSettings *sim_settings)
449 {
450 	return oregano_strtod (sim_settings->fourier_frequency, "Hz");
451 }
452 
sim_settings_get_fourier_vout(const SimSettings * sim_settings)453 gchar *sim_settings_get_fourier_vout (const SimSettings *sim_settings)
454 {
455 	GSList *node_slist;
456 	gchar *text, *text2;
457 	gchar *ret_val = NULL;
458 
459 	text = NULL;
460 	node_slist = g_slist_copy (sim_settings->fourier_vout);
461 	if (node_slist) {
462 		if (node_slist->data && atoi (node_slist->data) > 0)
463 			text = g_strdup_printf ("%d", atoi (node_slist->data));
464 		node_slist = node_slist->next;
465 	}
466 	while (node_slist) {
467 		if (node_slist->data && atoi (node_slist->data) > 0) {
468 			if (text) {
469 				text2 = text;
470 				text = g_strdup_printf ("%s %d", text, atoi (node_slist->data));
471 				g_free (text2);
472 			} else {
473 				text = g_strdup_printf ("%d", atoi (node_slist->data));
474 			}
475 		}
476 		node_slist = node_slist->next;
477 	}
478 
479 	g_slist_free_full (node_slist, g_free);
480 
481 	if (text)
482 		ret_val = text;
483 	else
484 		ret_val = g_strdup ("");
485 
486 	return ret_val;
487 }
488 
sim_settings_get_fourier_nodes(const SimSettings * sim_settings)489 gchar *sim_settings_get_fourier_nodes (const SimSettings *sim_settings)
490 {
491 	GSList *node_slist;
492 	gchar *ret_val = NULL;
493 	gchar *text, *text2;
494 
495 	text = NULL;
496 	node_slist = g_slist_copy (sim_settings->fourier_vout);
497 	if (node_slist) {
498 		if (node_slist->data && atoi (node_slist->data) > 0)
499 			text = g_strdup_printf ("V(%d)", atoi (node_slist->data));
500 		node_slist = node_slist->next;
501 	}
502 	while (node_slist) {
503 		if (node_slist->data && atoi (node_slist->data) > 0) {
504 			if (text) {
505 				text2 = text;
506 				text = g_strdup_printf ("%s V(%d)", text, atoi (node_slist->data));
507 				g_free (text2);
508 			} else {
509 				text = g_strdup_printf ("V(%d)", atoi (node_slist->data));
510 			}
511 		}
512 		node_slist = node_slist->next;
513 	}
514 
515 	if (text)
516 		ret_val = text;
517 	else
518 		ret_val = g_strdup ("");
519 
520 	g_slist_free_full (node_slist, g_free);
521 
522 	return ret_val;
523 }
524 
sim_settings_get_noise(const SimSettings * sim_settings)525 gboolean sim_settings_get_noise (const SimSettings *sim_settings) { return sim_settings->noise_enable; }
526 
sim_settings_get_noise_vsrc(const SimSettings * sim_settings)527 gchar *sim_settings_get_noise_vsrc (const SimSettings *sim_settings) { return sim_settings->noise_vin; }
528 
sim_settings_get_noise_vout(const SimSettings * sim_settings)529 gchar *sim_settings_get_noise_vout (const SimSettings *sim_settings) { return sim_settings->noise_vout; }
530 
sim_settings_get_noise_type(const SimSettings * sim_settings)531 gchar *sim_settings_get_noise_type (const SimSettings *sim_settings) { return sim_settings->noise_type; }
532 
sim_settings_get_noise_npoints(const SimSettings * sim_settings)533 gint sim_settings_get_noise_npoints (const SimSettings *sim_settings)
534 {
535 	return atoi (sim_settings->noise_npoints);
536 }
537 
sim_settings_get_noise_start(const SimSettings * sim_settings)538 gdouble sim_settings_get_noise_start (const SimSettings *sim_settings)
539 {
540 	return oregano_strtod (sim_settings->noise_start, "Hz");
541 }
542 
sim_settings_get_noise_stop(const SimSettings * sim_settings)543 gdouble sim_settings_get_noise_stop (const SimSettings *sim_settings)
544 {
545 	return oregano_strtod (sim_settings->noise_stop, "Hz");
546 }
547 
sim_settings_set_noise(SimSettings * sim_settings,gboolean enable)548 void sim_settings_set_noise (SimSettings *sim_settings, gboolean enable)
549 {
550 	sim_settings->noise_enable = enable;
551 }
552 
sim_settings_set_noise_vsrc(SimSettings * sim_settings,gchar * str)553 void sim_settings_set_noise_vsrc (SimSettings *sim_settings, gchar *str)
554 {
555 	g_free (sim_settings->noise_vin);
556 	sim_settings->noise_vin = g_strdup (str);
557 }
558 
sim_settings_set_noise_vout(SimSettings * sim_settings,gchar * str)559 void sim_settings_set_noise_vout (SimSettings *sim_settings, gchar *str)
560 {
561 	g_free (sim_settings->noise_vout);
562 	sim_settings->noise_vout = g_strdup (str);
563 }
564 
sim_settings_set_noise_type(SimSettings * sim_settings,gchar * str)565 void sim_settings_set_noise_type (SimSettings *sim_settings, gchar *str)
566 {
567 	g_free (sim_settings->noise_type);
568 	sim_settings->noise_type = g_strdup (str);
569 }
570 
sim_settings_set_noise_npoints(SimSettings * sim_settings,gchar * str)571 void sim_settings_set_noise_npoints (SimSettings *sim_settings, gchar *str)
572 {
573 	g_free (sim_settings->noise_npoints);
574 	sim_settings->noise_npoints = g_strdup (str);
575 }
576 
sim_settings_set_noise_start(SimSettings * sim_settings,gchar * str)577 void sim_settings_set_noise_start (SimSettings *sim_settings, gchar *str)
578 {
579 	g_free (sim_settings->noise_start);
580 	sim_settings->noise_start = g_strdup (str);
581 }
582 
sim_settings_set_noise_stop(SimSettings * sim_settings,gchar * str)583 void sim_settings_set_noise_stop (SimSettings *sim_settings, gchar *str)
584 {
585 	g_free (sim_settings->noise_stop);
586 	sim_settings->noise_stop = g_strdup (str);
587 }
588 
sim_settings_get_options(const SimSettings * sim_settings)589 GList *sim_settings_get_options (const SimSettings *sim_settings)
590 {
591 	g_return_val_if_fail (sim_settings != NULL, NULL);
592 	return sim_settings->options;
593 }
594 
sim_settings_add_option(SimSettings * sim_settings,SimOption * opt)595 void sim_settings_add_option (SimSettings *sim_settings, SimOption *opt)
596 {
597 	GList *iter;
598 	// Remove the option if already in the list.
599 	for (iter = sim_settings->options; iter; iter = iter->next) {
600 		SimOption *so = iter->data;
601 		if (so && !strcmp (opt->name, so->name)) {
602 			g_free (so->name);
603 			g_free (so->value);
604 			sim_settings->options = g_list_remove (sim_settings->options, so);
605 			sim_option_finalize(so);
606 		}
607 	}
608 	sim_settings->options = g_list_append (sim_settings->options, opt);
609 }
610