1 #ifdef HAVE_STDLIB_H
2 #include <stdlib.h>
3 #endif
4 #include <stdio.h>
5 #include <string.h>
6 #include "yagi.h"
7 
read_yagi_data(char * one_line,char * input_filename,double * frequency,double * min_frequency,double * max_frequency,double * step_frequency,int driven,double ** d,int parasitic,double ** p,double * angular_step)8 void read_yagi_data(char *one_line, char *input_filename, double *frequency, double *min_frequency, double *max_frequency, double *step_frequency, int driven , double **d, int parasitic, double **p, double *angular_step)
9 {
10 	FILE *ifp;
11 	char *null, *tmp;
12 	int i;
13 
14 	null=string(0L,MAX_LINE);
15 
16 	tmp=string(0L,MAX_LINE);
17 	ifp=fopen(input_filename, "rt");
18 	if(ifp == NULL)
19 	{
20 		fprintf(stderr,"Sorry, cant find file:  %s\n", input_filename);
21 		exit(2);
22 	}
23 	/* Read one_line by one_line, looking for data on the elements */
24 	while(!feof(ifp))
25 	{
26 		fgets(one_line, MAX_LINE-1, ifp);
27 
28 		if(strncmp(one_line,"STEP_FREQUENCY",14) == 0)
29 		{
30 			sscanf(one_line,"%s %lf", null, step_frequency);
31 			*step_frequency*=1e6;
32 		}
33 		if(strncmp(one_line,"MIN_FREQUENCY",13) == 0)
34 		{
35 			sscanf(one_line,"%s %lf", null, min_frequency);
36 			*min_frequency*=1e6;
37 		}
38 		if(strncmp(one_line,"MAX_FREQUENCY",13) == 0)
39 		{
40 			sscanf(one_line,"%s %lf", null, max_frequency);
41 			*max_frequency*=1e6;
42 		}
43 		if(strncmp(one_line,"ANGULAR_STEP",12) == 0)
44 		{
45 			sscanf(one_line,"%s %lf", null, angular_step);
46 		}
47 		if(strncmp(one_line,"FREQUENCY",9) == 0)
48 		{
49 			sscanf(one_line,"%s %lf", null, frequency);
50 			*frequency*=1e6;
51 		}
52 		if(strncmp(one_line,"DATA_PARASITIC",14) == 0)
53 		{
54 			one_line+=14;
55 			for(i=1;i<=parasitic; ++i)
56 			{
57 				fgets(one_line, MAX_LINE-1, ifp);
58 				sscanf(one_line,"\n%lf %lf %lf %lf",&p[i][X], &p[i][Y], &p[i][LENGTH], &p[i][DIAMETER] );
59 			}
60 		}
61 		if(strncmp(one_line,"DATA_DRIVEN",11) == 0)
62 		{
63 			one_line+=11; /* skip DATA_DRIVEN */
64 			for(i=1;i<=driven; ++i)
65 				sscanf(one_line, "%lf %lf %lf %lf %lf %lf\n", &d[i][X], &d[i][Y], &d[i][LENGTH], &d[i][DIAMETER], &d[i][VOLTAGE_R], &d[i][VOLTAGE_I]);
66 		}
67 	}
68 	fclose(ifp);
69 	if(*min_frequency > *max_frequency || *angular_step <= 0 || *step_frequency <=0.0 || *frequency <=0.0 )
70 	{
71 		fprintf(stderr,"Error in input file %s. Please check:\n", input_filename);
72 		fprintf(stderr,"FREQUENCY, MIN_FREQUENCY, MAX_FREQUENCY, STEP_FREQUENCY and ANGULAR_STEP\n");
73 		exit(1);
74 	}
75 
76 	free_string(null,0L,MAX_LINE);
77 	free_string(tmp,0L,MAX_LINE);
78 }
79 
80