File: sim2simp.c

package info (click to toggle)
magic 8.3.105%2Bds.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 17,128 kB
  • sloc: ansic: 175,615; sh: 7,634; tcl: 4,536; lisp: 2,554; makefile: 946; cpp: 587; python: 389; csh: 148; awk: 140
file content (156 lines) | stat: -rw-r--r-- 3,523 bytes parent folder | download | duplicates (2)
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
/* no comments are provided - the code is self explanatory :-) */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define STRLEN  1024
#define NSIZE  100000



typedef	struct {
	char		typ;
	char 		*g, *s, *d ;
	float		l, w;
	char 		*ga ;
	int		x, y, as, ps, ad, pd;
}	MOS ;

MOS	mosFets[NSIZE];
int	par = 0, ndx = 0;


char *strsave(s)
char *s;
{
	char *p ;

	p = (char *) malloc(strlen(s)+1);
	strcpy(p,s);
	return p;
}

int parseAttr(str, a, p)
char *str;
int *a, *p;
{
	int l;
	char *s;

	if ( (l=strlen(str)) <= 2 ) {
		*a = 0 ; *p = 0;
		return;
	}

	for ( s = str+l*sizeof(char) ; *s != 'A' && *s != 'a' && s != str ; s-- ) ;
	if ( sscanf(s,"A_%d,P_%d", a, p ) != 2)
	        if ( sscanf(s,"a_%d,p_%d", a, p ) != 2 )
	          if ( sscanf(s,"A_%d,p_%d", a, p ) != 2 )
	            if ( sscanf(s,"a_%d,P_%d", a, p ) != 2 )
			fprintf(stderr,"Weird attributes output will be incorect\n");
}

void addMos( typ, g, s, d, l, w, x, y, ga, sa, da)
char *typ, *g, *s, *d, *l, *w, *x, *y, *ga, *sa, *da;
{
	int i ;
	MOS *iptr;
	float ln, wn ;
	int as, ps, ad, pd;

	ln = (float) atof(l); wn = (float) atof(w);
	if ( ga == NULL )
		as = ps = ad = pd = 0 ;
	else {
		parseAttr(sa, &as, &ps);
		parseAttr(da, &ad, &pd);
	}
	for ( i = 0 ; i < ndx ; i ++ ) {
		iptr = mosFets + i ;
		if ( iptr->typ == *typ  && iptr->l == ln
			&& ! strcmp(iptr->g, g)
			&&  ( ! strcmp(iptr->s, s) && ! strcmp(iptr->d, d) )
			 ) {
				iptr->w += wn;
				iptr->as += as ; iptr->ps += ps ;
				iptr->ad += ad ; iptr->pd += pd ;
				par ++;
				return;
			}
		if ( iptr->typ == *typ  && iptr->l == ln
			&& ! strcmp(iptr->g, g)
			&& ( ! strcmp(iptr->s, d) && ! strcmp(iptr->d, s) )) {
				iptr->w += wn;
				iptr->as += ad ; iptr->ps += pd ;
				iptr->ad += as ; iptr->pd += ps ;
				par ++;
				return;
			}
	}

	iptr = mosFets + ndx ;
	iptr->typ = *typ;
	iptr->g = strsave(g); iptr->s = strsave(s); iptr->d = strsave(d);
	iptr->l = ln ; iptr->w = wn;
	if ( x != NULL ) {
		iptr->x = (int) atoi(x);
		iptr->y = (int) atoi(y);
		iptr->as = as ; iptr->ps = ps ;
		iptr->ad = ad ; iptr->pd = pd ;
		if (ga ) iptr->ga = strsave(ga); else iptr->ga = NULL;
	}
	if ( ++ ndx >= NSIZE ) {
			fprintf(stderr, "Mos max cound %d exceeded\n", NSIZE);
			exit(1);
	}
}


main ()
{
	int i;
	char str[STRLEN];
	char *typ, *g, *s, *d, *l, *w, *x, *y, *ga, *sa, *da;


        while (fgets (str, STRLEN - 1, stdin)) {
		if ( *str == 'p' || *str == 'n' ||
		     *str == 'e' || *str == 'd' ) {
				typ = strtok(str, " ");
				g = strtok(NULL, " ");
				s = strtok(NULL, " ");
				d = strtok(NULL, " ");
				l = strtok(NULL, " ");
				w = strtok(NULL, " ");
				x = strtok(NULL, " ");
				y = strtok(NULL, " ");
				if ( y == NULL ) {
					ga = sa = da = NULL ;
				} else  {
					ga = strtok(NULL, " ");
					sa = strtok(NULL, " ");
					da = strtok(NULL, " ");
				}
				addMos(typ, g, s, d, l, w, x, y, ga, sa, da);
          	}
		else	puts(str);
        }
	fprintf(stderr,"| %d parallel devices\n", par);
	for ( i = 0 ; i < ndx ; i ++ )
	  /*if ( mosFets[i].ga )*/
	if (1)
		printf("%c %s %s %s %g %g %d %d %s s=A_%d,P_%d d=A_%d,P_%d\n",
			mosFets[i].typ, mosFets[i].g, mosFets[i].s,
			mosFets[i].d, mosFets[i].l, mosFets[i].w,
			mosFets[i].x, mosFets[i].y,mosFets[i].ga,
			mosFets[i].as,mosFets[i].ps,
			mosFets[i].ad,mosFets[i].pd);
	   else
		printf("%c %s %s %s %g %g %d %d\n",
			mosFets[i].typ, mosFets[i].g, mosFets[i].s,
			mosFets[i].d, mosFets[i].l, mosFets[i].w,
			mosFets[i].x, mosFets[i].y);
        exit (0);
}