-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_n.c
222 lines (193 loc) · 5.02 KB
/
main_n.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*************************************************************************
*
* JSIM Release 2.0 10/24/92
*
* JSIM is a simulator for circuits containing Josephson Junctions.
*
* Author: Emerson Fang, 1991
* University of California, Berkeley
* Dept. of Electrical Engineering and Computer Sciences
* Cryoelectronics Group, Professor Ted Van Duzer
*
*
* Cleanup Crew: Jay Fleischman (jef@swordfish.berkeley.edu)
* Steve Whiteley (stevew@landau.conductus.com)
*
*************************************************************************/
/** noise hack by J Satchell, DRA Malvern **/
/*************************************************************************
*
* jsim [-options] [filenames] [-options] [filenames] ...
*
* Options can be d, r, or nothing, following a '-'.
* d toggle debugging, which dumps a file jsim.dbg (initially off).
* r toggle use of a rawfile jsim.raw for output (initially off).
* - read the standard input.
*
* Otherwise, tokens on the command line are assumed to be file names
* to read for input. If no such tokens are found, the standard input
* is read.
*
* The options operate on files listed to the right of the option
* list, and are active until changed with another invocation. If
* no files are listed, the options are read before the standard
* input is read.
*
* examples:
*
* jsim file1 -d file2 -d file3
* will dump debug information while simulating file2.
*
* jsim file1 -rd - file3 <anotherfile
* will simulate file1, turn on debugging and rawfile creation,
* then simulate anotherfile, then file3.
*
* jsim -r <inputfile
* will simulate inputfile and create a rawfile.
*
*************************************************************************/
#include "jsim_n.h"
#include "global.h"
#include <sys/types.h>
#include <sys/timeb.h>
#if __STDC__
static void run_jsim(void);
static void do_opts(char*);
#else
static void run_jsim();
static void do_opts();
#endif
FILE *fp;
int
main(argc,argv)
int argc;
char **argv;
{
int i;
int tried = FALSE;
struct timeb now;
int seed;
#if (__TURBOC__)
_control87(0xffff,0x003f);
#endif
/* use real time to set random number generator to non repeatable state */
ftime(&now);
seed = now.time*1000+now.millitm;
#ifdef WIN32
srand(seed);
#else
srandom(seed);
#endif
jsim_dbg = FALSE;
jsim_raw = FALSE;
jsim_mout = FALSE;
for (i = 1; i < argc; i++) {
if (*argv[i] == '-') {
if (*(argv[i]+1) == '\0') {
fp = stdin;
if (jsim_raw)
printf("\nReading stdin\n");
run_jsim();
tried = TRUE;
}
else
if (*(argv[i]+1) == 'm') {
jsim_mout ^= 1;
jsim_raw = FALSE;
mfilename = argv[i+1]; /* argv should not vanish during program execution */
printf("Filename for exported variables: %s\n", mfilename);
i++;
} else {
do_opts(argv[i]+1);
}
}
else {
fp = fopen(argv[i],"r");
if (fp == NULL)
printf("\nCan't open %s\n",argv[i]);
else {
if (jsim_raw)
printf("\nReading %s\n",argv[i]);
run_jsim();
}
tried = TRUE;
}
}
if (tried == FALSE) {
fp = stdin;
if (jsim_raw)
printf("\nReading stdin\n");
run_jsim();
}
} /* main */
static void
run_jsim()
{
FILE *fopen();
struct timeb now;
long t;
init_global();
read_deck();
process_deck();
deckerror_check();
topology_check();
free_space();
if (jsim_mout) {
mfile = fopen(mfilename, "w");
if (!mfile) {
printf("## Error -- cannot open output file: %s\n", mfilename);
no_go = TRUE;
} else {
print_header(mfile);
}
} else {
print_header(stdout);
}
if (stop_time < 0.0)
{
printf("## Error -- no transient analysis specified\n");
no_go = TRUE;
}
if ((no_go == FALSE) &&
((warned == FALSE) || (igwarn_no_go == TRUE)))
{
setup_device();
setup_matrix();
get_breakpoint();
ftime(&now);
t = now.time*1000 + now.millitm;
time_loop(hptr);
ftime(&now);
t -= now.time*1000 + now.millitm;
print_stat_LU(my_matrix);
printf("\nSimulation ran %.2f seconds.\n",-t/1000.0);
printf("This Stochastic extension to JSIM bought to you by\n");
printf("Julian Satchell, DRA(Malvern), UK. \n");
printf("satchell@dra.hmg.gb\nOur WWW page is at: www.dera.hmg.gb\n");
/*
printf("lu op count %d\n", lu_opcount);
*/
}
else if (no_go == TRUE)
printf("\n\n#### JOB ABORTED due to error in input deck\n");
else if (warned == TRUE)
printf("\n\n#### JOB ABORTED due to warning in input deck\n");
} /* run_jsim */
static void
do_opts(s)
char *s;
{
char *c;
for (c = s; *c; c++) {
if (*c == 'd') {
jsim_dbg ^= 1;
break;
}
}
for (c = s; *c; c++) {
if (*c == 'r') {
if (!jsim_mout) jsim_raw ^= 1;
break;
}
}
} /* do_opts */