1 /*============================================================================
2 FILE    int/udnfunc.c
3 
4 MEMBER OF process XSPICE
5 
6 Public Domain
7 
8 Georgia Tech Research Corporation
9 Atlanta, Georgia 30332
10 PROJECT A-8503
11 
12 AUTHORS
13 
14     9/12/91  Bill Kuhn
15 
16 MODIFICATIONS
17 
18     <date> <person name> <nature of modifications>
19 
20 SUMMARY
21 
22     This file contains the definition of the 'int' node type
23     used by event-driven models that simulate with integer type data.
24     These functions are called exclusively through function
25     pointers in an Evt_Udn_Info_t data structure.
26 
27 INTERFACES
28 
29     Evt_Udn_Info_t udn_int_info
30 
31 REFERENCED FILES
32 
33     None.
34 
35 NON-STANDARD FEATURES
36 
37     None.
38 
39 ============================================================================*/
40 
41 #include <stdio.h>
42 
43 
44 #include "ngspice/cm.h"
45 #include "ngspice/evtudn.h"
46 #include "ngspice/memory.h"
47 
48 
49 /* macro to ignore unused variables and parameters */
50 #define NG_IGNORE(x)  (void)x
51 
52 /* ************************************************************************ */
53 
udn_int_create(CREATE_ARGS)54 static void udn_int_create(CREATE_ARGS)
55 {
56     /* Malloc space for an int */
57     MALLOCED_PTR = TMALLOC(int, 1);
58 }
59 
60 
61 /* ************************************************************************ */
62 
udn_int_dismantle(DISMANTLE_ARGS)63 static void udn_int_dismantle(DISMANTLE_ARGS)
64 {
65     NG_IGNORE(STRUCT_PTR);
66 
67     /* Do nothing.  There are no internally malloc'ed things to dismantle */
68 }
69 
70 
71 /* ************************************************************************ */
72 
udn_int_initialize(INITIALIZE_ARGS)73 static void udn_int_initialize(INITIALIZE_ARGS)
74 {
75     int  *int_struct = (int *) STRUCT_PTR;
76 
77 
78     /* Initialize to zero */
79     *int_struct = 0;
80 }
81 
82 
83 /* ************************************************************************ */
84 
udn_int_invert(INVERT_ARGS)85 static void udn_int_invert(INVERT_ARGS)
86 {
87     int      *int_struct = (int *) STRUCT_PTR;
88 
89 
90     /* Invert the state */
91     *int_struct = -(*int_struct);
92 }
93 
94 
95 /* ************************************************************************ */
96 
udn_int_copy(COPY_ARGS)97 static void udn_int_copy(COPY_ARGS)
98 {
99     int  *int_from_struct = (int *) INPUT_STRUCT_PTR;
100     int  *int_to_struct   = (int *) OUTPUT_STRUCT_PTR;
101 
102     /* Copy the structure */
103     *int_to_struct = *int_from_struct;
104 }
105 
106 /* ************************************************************************ */
107 
udn_int_resolve(RESOLVE_ARGS)108 static void udn_int_resolve(RESOLVE_ARGS)
109 {
110     int **array    = (int**)INPUT_STRUCT_PTR_ARRAY;
111     int *out       = (int *) OUTPUT_STRUCT_PTR;
112     int num_struct = INPUT_STRUCT_PTR_ARRAY_SIZE;
113 
114     int         sum;
115     int         i;
116 
117     /* Sum the values */
118     for(i = 0, sum = 0; i < num_struct; i++)
119         sum += *(array[i]);
120 
121     /* Assign the result */
122     *out = sum;
123 }
124 
125 /* ************************************************************************ */
126 
udn_int_compare(COMPARE_ARGS)127 static void udn_int_compare(COMPARE_ARGS)
128 {
129     int  *int_struct1 = (int *) STRUCT_PTR_1;
130     int  *int_struct2 = (int *) STRUCT_PTR_2;
131 
132     /* Compare the structures */
133     if((*int_struct1) == (*int_struct2))
134         EQUAL = TRUE;
135     else
136         EQUAL = FALSE;
137 }
138 
139 
140 /* ************************************************************************ */
141 
udn_int_plot_val(PLOT_VAL_ARGS)142 static void udn_int_plot_val(PLOT_VAL_ARGS)
143 {
144     int   *int_struct = (int *) STRUCT_PTR;
145 
146     NG_IGNORE(STRUCT_MEMBER_ID);
147 
148     /* Output a value for the int struct */
149     PLOT_VAL = *int_struct;
150 }
151 
152 
153 /* ************************************************************************ */
154 
udn_int_print_val(PRINT_VAL_ARGS)155 static void udn_int_print_val(PRINT_VAL_ARGS)
156 {
157     int   *int_struct = (int *) STRUCT_PTR;
158 
159     NG_IGNORE(STRUCT_MEMBER_ID);
160 
161     /* Allocate space for the printed value */
162     PRINT_VAL = TMALLOC(char, 30);
163 
164     /* Print the value into the string */
165     sprintf(PRINT_VAL, "%8d", *int_struct);
166 }
167 
168 
169 
170 /* ************************************************************************ */
171 
udn_int_ipc_val(IPC_VAL_ARGS)172 static void udn_int_ipc_val(IPC_VAL_ARGS)
173 {
174     /* Simply return the structure and its size */
175     IPC_VAL = STRUCT_PTR;
176     IPC_VAL_SIZE = sizeof(int);
177 }
178 
179 
180 
181 Evt_Udn_Info_t udn_int_info = {
182 
183     "int",
184     "integer valued data",
185 
186     udn_int_create,
187     udn_int_dismantle,
188     udn_int_initialize,
189     udn_int_invert,
190     udn_int_copy,
191     udn_int_resolve,
192     udn_int_compare,
193     udn_int_plot_val,
194     udn_int_print_val,
195     udn_int_ipc_val
196 
197 };
198