diff --git a/src/include/ngspice/sharedspice.h b/src/include/ngspice/sharedspice.h index d0f471168..6f7333b6f 100644 --- a/src/include/ngspice/sharedspice.h +++ b/src/include/ngspice/sharedspice.h @@ -44,6 +44,18 @@ receives the name of a vector (may be in the form 'vectorname' or The caller may then directly assess the vector data (but probably should not modify them). +***************** If XSPICE is enabled ************************************* +** +ngGet_Evt_NodeInfo(char*) +receives the name of a event node vector (may be in the form 'vectorname' or +.vectorname) and returns a pointer to a evt_node_info struct. +The caller may then directly assess the vector data. + +** +char** ngSpice_AllEvtNodes(void); +returns to the caller a pointer to an array of all event node names. +**************************************************************************** + ** ngSpice_Circ(char**) sends an array of null-terminated char* to ngspice.dll. Each char* contains a @@ -163,6 +175,24 @@ typedef struct vecinfoall } vecinfoall, *pvecinfoall; +/* to be used by ngGet_Evt_NodeInfo, returns all data of a specific node after simulation */ +#ifdef XSPICE +/* a single data point */ +typedef struct evt_data +{ + int dcop; /* t.b.d. */ + double step; /* simulation time */ + char *node_value; /* one of 0s, 1s, Us, 0r, 1r, Ur, 0z, 1z, Uz, 0u, 1u, Uu */ +} evt_data, *pevt_data; + +/* a list of all data points of the node selected by the char* argument to ngGet_Evt_NodeInfo */ +typedef struct evt_shared_data +{ + pevt_data evt_dect; /* array of data */ + int num_steps; /* length of the array */ +} evt_shared_data, *pevt_shared_data; +#endif + /* callback functions addresses received from caller with ngSpice_Init() function @@ -287,6 +317,16 @@ int ngSpice_Command(char* command); IMPEXP pvector_info ngGet_Vec_Info(char* vecname); +#ifdef XSPICE +/* get info about the event node vector */ +IMPEXP +pevt_shared_data ngGet_Evt_NodeInfo(char* nodename); + +/* get a list of all event nodes */ +IMPEXP +char** ngSpice_AllEvtNodes(void); +#endif + /* send a circuit to ngspice.dll The circuit description is a dynamic array diff --git a/src/sharedspice.c b/src/sharedspice.c index b9fe13cf4..21a05f4ea 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -172,6 +172,11 @@ extern int SIMinit(IFfrontEnd *frontEnd, IFsimulator **simulator); extern wordlist *cp_varwl(struct variable *var); extern void create_circbyline(char *line); +#ifdef XSPICE +extern struct evt_shared_data *EVTshareddata(char *node_name); +extern char** EVTallnodes(void); +#endif + /*The current run (to get variable names, etc)*/ static runDesc *cur_run; @@ -958,6 +963,22 @@ bool ngSpice_SetBkpt(double time) return(TRUE); } +#ifdef XSPICE +/* get info about the event node vector */ +IMPEXP +pevt_shared_data ngGet_Evt_NodeInfo(char* node_name) +{ + return EVTshareddata(node_name); +} + +/* get a list of all event nodes */ +IMPEXP +char** ngSpice_AllEvtNodes(void) +{ + return EVTallnodes(); +} +#endif + /* add the preliminary breakpoints to the list. called from dctran.c */ diff --git a/src/xspice/evt/evtshared.c b/src/xspice/evt/evtshared.c index 22e396ce2..46f660ebe 100644 --- a/src/xspice/evt/evtshared.c +++ b/src/xspice/evt/evtshared.c @@ -3,7 +3,7 @@ FILE EVTshared.c MEMBER OF process XSPICE -This code is in the public domain +This code is in the public domain. AUTHORS @@ -16,7 +16,7 @@ MODIFICATIONS SUMMARY This file function to prepare event node data for transfer over the - shared ngspice interface. + shared ngspice interface. INTERFACES @@ -33,7 +33,7 @@ NON-STANDARD FEATURES ============================================================================*/ #include "ngspice/ngspice.h" - +#include "ngspice/sharedspice.h" #include "ngspice/cpstd.h" #include "ngspice/cpextern.h" #include "ngspice/fteext.h" @@ -48,29 +48,30 @@ NON-STANDARD FEATURES static int get_index(char *node_name); +/* -struct evt_data { - Mif_Boolean_t dcop; - double step; - char *node_value; -}; +// typedefs are done in sharedspice.h -struct evt_shared_data { - struct evt_data *evt_dect; - int num_steps; -}; +typedef struct evt_data { + Mif_Boolean_t dcop; + double step; + char *node_value; +} evt_data, *pevt_data; -struct evt_data *return_node; -struct evt_shared_data *return_all; +typedef struct evt_shared_data { + pevt_data evt_dect; + int num_steps; +} evt_shared_data, *pevt_shared_data; +*/ -struct evt_shared_data -*EVTshareddata( - char *node_name) /* The command line called by ngGet_EVT_Info(char* nodename) */ +pevt_shared_data +EVTshareddata( + char *node_name) /* The command called by ngGet_EVT_Info(char* nodename) */ { int i; - int nodes; + int num_points; int node_index; int udn_index; @@ -90,6 +91,9 @@ struct evt_shared_data char *value; + pevt_data return_node; + pevt_shared_data return_all; + /* Get needed pointers */ ckt = g_mif_info.ckt; if (!ckt) { @@ -136,23 +140,23 @@ struct evt_shared_data next_step = node_data->step; } - /* Count the neumber of node data */ - count_data = node_data; - nodes = 0; - while (count_data) { - nodes++; - count_data = count_data->next; - } + /* Count the number of data points of this node */ + count_data = node_data; + num_points = 0; + while (count_data) { + num_points++; + count_data = count_data->next; + } - /* Store the data */ - return_node = TMALLOC(struct evt_data, nodes); - return_node[0].dcop = dcop; - return_node[0].node_value = copy(value); - return_node[0].step = step; + /* Store the data */ + return_node = TMALLOC(evt_data, num_points); + return_node[0].dcop = dcop; + return_node[0].node_value = copy(value); + return_node[0].step = step; /* While there is more data, get the next values and print */ - i = 1; - while(more) { + i = 1; + while(more) { more = MIF_FALSE; this_step = next_step; @@ -173,15 +177,16 @@ struct evt_shared_data } /* end if node_data not NULL */ - return_node[i].dcop = dcop; - return_node[i].node_value = copy(value); - return_node[i].step = this_step; - i++; + return_node[i].dcop = dcop; + return_node[i].node_value = copy(value); + return_node[i].step = this_step; + i++; } /* end while there is more data */ - return_all = TMALLOC(struct evt_shared_data, 1); - return_all->evt_dect = return_node; - return_all->num_steps = i; - return return_all; + return_all = TMALLOC(evt_shared_data, 1); + return_all->evt_dect = return_node; + return_all->num_steps = i; + + return return_all; } @@ -239,3 +244,34 @@ static int get_index( } +char** EVTallnodes(void) +{ + static char** allnodes; + int len = 0, i = 0; + Evt_Node_Info_t *node; + CKTcircuit *ckt = g_mif_info.ckt; + if (!ckt) { + fprintf(cp_err, "Error: no circuit loaded.\n"); + return NULL; + } + if (allnodes) + tfree(allnodes); + node = ckt->evt->info.node_list; + /* count the event nodes */ + while (node) { + len++; + node = node->next; + } + if (len == 0) { + fprintf(cp_err, "Error: no event nodes found.\n"); + return NULL; + } + allnodes = TMALLOC(char*, len + 1); + node = ckt->evt->info.node_list; + for (i = 0; i < len; i++) { + allnodes[i] = node->name; + node = node->next; + } + allnodes[len] = '\0'; + return allnodes; +}