1 #ifdef HAVE_STDLIB_H
2 #include <stdlib.h>
3 #endif
4 #include <stdio.h>
5 #include <string.h>
6 #include <errno.h>
7 #include "yagi.h"
8
9 #include <errno.h>
10
get_number_of_elements(char * input_filename,int * driven,int * parasitic)11 int get_number_of_elements(char *input_filename, int *driven , int *parasitic)
12 {
13 FILE *ifp;
14 char *null, *line;
15 int num_elements;
16
17 null=string(0L,12L);
18 line=string(0L,81L);
19 ifp=fopen(input_filename, "rt");
20 *driven=-1;
21 *parasitic=-1;
22 if(ifp == NULL)
23 {
24 fprintf(stderr,"Sorry, cant find file: %s\n", input_filename);
25 exit(2);
26 }
27 /* Read line by line, looking for data on number of elements */
28 while(!feof(ifp))
29 {
30 fgets(line, 80, ifp);
31 if(strncmp(line,"ELEMENTS",8) == 0)
32 {
33 sscanf(line,"%s %d\n", null, &num_elements);
34 }
35 if(strncmp(line,"DRIVEN",6) == 0)
36 {
37 sscanf(line,"%s %d\n", null, driven);
38 }
39 if(strncmp(line,"PARASITIC",8) == 0)
40 {
41 sscanf(line,"%s %d\n", null, parasitic);
42 }
43 }
44 #ifdef DEBUG
45 errno=0;
46 #endif
47 fclose(ifp);
48 if(num_elements == -1)
49 fprintf(stderr,"Error in data file %s: ELEMENTS undefined\n",input_filename);
50 if(*driven == -1)
51 fprintf(stderr,"Error in data file %s : DRIVEN undefined\n", input_filename);
52 if(*parasitic == -1)
53 fprintf(stderr,"Error in data file %s: PARASITIC undefined\n", input_filename);
54 if(num_elements != *driven + *parasitic)
55 {
56 fprintf(stderr,"Check ELEMENTS, DRIVEN & PARASITIC in data file %s\n", input_filename);
57 fprintf(stderr,"ELEMENTS = %d DRIVEN = %d PARASITIC = %d\n", num_elements, *driven, *parasitic);
58 exit(3);
59 }
60 free_string(line,0L,81L);
61 free_string(null,0L,12L);
62
63 #ifdef DEBUG
64 if(errno)
65 {
66 fprintf(stderr,"Errno =%d in mum_elem.c\n", errno);
67 exit(1);
68 }
69 #endif
70 return(num_elements);
71 }
72
73