Federal Communications Commission

AM Directional Antenna Stability Assessment Program Code
MM Docket 93-177

July 12, 1999

This page contains the code for the AM directional antanna array stability assessment program proposed in the Notice of Proposed Rulemaking in MM Docket 93-177 (MS Word 97 version).

The following is the "C" language source code for the stability analysis program. During preparation of the program, the main program was rewritten for the number of towers being studied. These programs, named vary4.c, vary5.c, etc. as well as the source code given below, may be downloaded as a zipped file.


vary.c

#ident "@(#)wgb_vary 1.0 98/02/12 William G. Ball"
/*
* internet
*
* Started, October 14, 1997 by William G. Ball
* modification started on January 16, 1998
* Audio Services Division
* Mass Media Bureau
* Federal Communications Commission
*
* All output goes to stdout.
* Program assumes the RMS of all the varied patterns is the same
* but because of the variations in parameters, the k factor must
* be calculated for each combination of parameters
*/
#define FAILURE 0 /* Return value indicating failure */
#define SUCCESS 1 /* Return value indicating sucess */
#define maxtow 17 /* Maximum number of towers permitted */
#define maxaug 28 /* Maximum number of augmentations permitted */
#define maxaz 72 /* maximum number of azimuths */
#define MaxCityline 24
#define MaxFreqline 12
#define azinc1 5
#define azinc2 1
#define vertical 5
/*
* Declare functions
*/
#define dmstosec(a,b,c) (a*3600.0 + b*60.0 +c)
#include <fcntl.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
/* Declare global variables */
char prefix[4];
char filenr[8];
char callsign[6];
char amindex[12];
char arn_line[15];
char comment[77];
char waste[3];
char domclass[2];
char testclass[2];
char reg2class;

int attempts[21]; /* total time the variation field is calculated */
int hits[21]; /* actual time the value is exceeded */

float az[maxaz];
float e0[maxaz]; /* pattern values for GWAVE */
float et[maxaz]; /* theoretical pattern values */
float es[maxaz]; /* standard pattern values */
float ea[maxaz]; /* augmented pattern values */
float ev[maxaz]; /* varied pattern value */
float vert[13];
float emin[30];
float emax[30];
float emm[3610]; /* for finding the minimum and maximum */
float azmin[30]; /* azimuths for mimiums */
float azmax[30]; /* azimuths for maximums */
float vaz[maxaz];
int rec_count; /* number of records to look up */
int recno;
int lenenv;
int machine; /* MMBS2 (#1) or Internet (#2)
int nfreq;
int iaz; /* loop counter for the azimuth */
int itheta; /* loop counter for theta */
int ih; /* loop variable for horizontal pattern */
int iv; /* loop variable for vertical pattern */
int imax;
int imin;

char header_trash[18]; /* read first 18 characaters of am database */
char AM_volume[5]; /* AM data base volume number */
char Change_list[5]; /* AM database change list number */
char Change_list[5]; /* Next available change list number */
char AM_update_year[2]; /* Last update year */
char AM_update_month[2]; /* Last update month */
char AM_update_day[2]; /* last update day */
static char AM_city[27]; /* AM city of license */
static char Stadt[27];
static char AM_state[3]; /* AM state of license */
static char Staat[2];
static char AM_country[3];/* AM country of license */
static char land[2];
char state[2];
int frequenz;
int frequency;
char freq[4];
int record_type;
char rectyp[2];
float rss;
float rms;
char crms[8];
double kfactor; /* the k-factor of the unmodified pattern */
double kfaktor; /* the k-factor for the varied array */
double qcal; /* q as calculated by he formulae */
double qfac; /* q as specified in database, i.e. specified q */
double qfactor; /* the actual q factor choosen */
double qcal1; /* q factor for the varied arrays */
char cqfactor[13]; /* the characters forming specified the q-factor */
double power;
char cpower[10];
char *kall;
char *env;
char rek[6];
char mrek[7];
char rufzeichen[7];
char ksign;
char *arn;
char *cty;
char *fre;
char *whr;
char *all;
char *pat;
int start_rek;
int stop_rek;
int ref_freq;
int freq_start;
int freq_stop;
int am_record[750];
int reknumber;
long am_point0; /* for reading header */
long am_point1; /* for reading the type 1 line */
long am_point2;
long am_point3;
long am_point4;
long tower_point1;
long lat1;
long lon1;
long lat2;
long lon2;
char type1_line[600];
char type2_line[600];
char type3_line[600];
char type4_line[600];
char domstat;
char mexstat;
char r2stat;
char hours; /* position 40 in the record */
char dstat; /* position 39 in recrod */
char dompat; /* domestic pattern - position 42 */
char cntow[2]; /* number of towers - posistion 72 */
char schedule; /* complete schedule - position 383 */
int ntow;
int tow;
int maxf; /* highest field ratio in the array - used in variation */
int kurz; /* shortest tower in the array -used in g of theta */
char antmode[4]; /* antenna mode - position 380 */
char cnaug[3]; /* number of augmentation - position 385 */
int naug;
/* long alat, alon, blat, blon; */
int lad, lam, las;
int lod, lom, los;
int dlat; /* used in get_dist() */
int dlon; /* used in get_dist() */
int mlat; /* used in get_dist() */
int mlon; /* used in get_dist() */
int slat; /* used in get_dist() */
int slon; /* used in get_dist() */
char clad[3], clam[3], clas[3];
char clod[4], clom[3], clos[3];
char latdir,londir;
int number;
int floh;
/* typedef struct tow */ /* structure for each antenna */
struct tow /* structure for each antenna */
{
double field; /* field ratio of tower */
double phase; /* phase in degrees */
double rphase; /* phase in radians */
double spacing; /* spacing in degrees */
double dd; /* spacing in degrees after towref() */
double dr; /* spacing in radians after towref() */
double azimuth; /* azimuth in degrees true */
double alphad; /* azimuth in degrees after towref() */
double alpha; /* azimuth in radians after towref() */
int tower_ref; /* tower reference switch */
int tlswitch; /* the type of tower */
double hgt; /* tower height in degrees for simple towers */
double a; /* sectionalized tower and /or top-loaded tower */
double b;
double c;
double d;
double rhgt;/* tow.hgt in radians */
double ra; /* tow.a in radians */
double rb; /* tow.b in radians */
double rc; /* tow.c in radians */
double rd; /* tow.d in radians */
} antenna[maxtow];

/* tower parameters */
char cfield[10];
char cheight[6];
char cphase[9];
char cspace[9];
char corientation[8];
char ctowref;
char ctlswitch;
char ca[6];
char cb[7];
char cc[7];
char cd[7];
char filler[10];
int fld[maxtow]; /* tracking array for the field variations */
int pha[maxtow]; /* tracking array for the phase variations */
double field[maxtow];
double phase[maxtow];
double height[maxtow];
double space[maxtow];
double orientation[maxtow];
int nda[maxtow];
int tlswitch[maxtow];
double a[maxtow];
double b[maxtow];
double c[maxtow];
double d[maxtow];
double cu[maxtow];
double psi[maxtow];
double br[maxtow];
double atemp[maxtow];
double dtemp[maxtow];
double dr[maxtow]; /* towref output distance from common
origin in radians */
double dd[maxtow]; /* towref output distance from common
origin in electrical degrees */
double alphad[maxtow]; /* towref output the orientations for
each tower with respect to the common
origin (after adjustments) in degrees */
double alpha[maxtow]; /* towref output the orientations for
each tower with respect to the common
origin (after adjustments) in radians */
/* End of the tower data */
float theta;
float ftheta[maxtow]; /* f of theta for each tower at vertical angle theta */
float Etheo;
double ref_dist;
double pi = 3.14159265358973;
double radian = 0.01745329519943;
double degree = 57.2957795131;
double atof ();
float Estd();
float Eth();
float Evary();
int shortwr();
int getref(); /* determines the reference towerr */
int reftow; /* reference tower - highest power tower held constant */
/* print_eminmax(); */
/* set_vary_param(); */
/* for incrementing the fields */
int i1;
int itow;
/* for incrementing the phases */
int i2;
int ktow;
/* for incrementing the tolerance */
int inc;
int iant;
/* tolerences */
float ftol; /* field tolerence */
float ptol; /* phase tolerence */
float fplus;
float fminus;
long int am_rec_length = 600;
int lt; /* used in the variation routine */
int lp1;
int lp2;
int lp3;
int lp4;
int lp7;
int lp8;
int lp11;
int lp12;
int lp13;
int lp14;
int lnew;
int lmax;
int itwr;
int imaxvary;
int maxtowvary;
int dbtwr[34];
int stepone();
int maxfld(); /* determines tower number of tower with maximum field */
int tested;
char fe[17]; /* stores character constants for the -,0 & + field offsets */
char ph[17]; /* stores character constants for the -,0 & + phase offsets */
char maxfe[maxtow];
char maxph[maxtow];
float results[10];
float ecomp1;
float ecomp2;
int flag_vary;
int pcent;
int maxpcent;
int attempt[5];
long bucket[5][21][100];
FILE *AMDB;
FILE *AMREC;
FILE *AM_CITY;
FILE *AM_COORDS;
FILE *READFREQ;
FILE *FINI;
FILE *SUMMED;
FILE *OUT;
FILE *TRACE;
FILE *RESULTS;
/*
* End of headers etc
*
* ------------------------------------------------------------------
*
* Main Program
*/
main()
{
int i;
int j; /* station found counter */
int j1;
int k; /* main loop counter for the number of stations */
int l1;
int l9;
int key;
int zfreq;
char rnv[12];
char empty[1];
int lengthcall;
int calllength;
int lengtharn;
int lengthcty;
int lengthfre;
int lengthwhr;
int lengthall;
int lengthpat;
int start_rec;
float maxdist;
float horazi; /* horizontal azimuth */
float vang;
long int am_rec_length = 600;
/* =+=+=+=+=+=+=+=+=+=+=+= Declarations finished =+=+=+=+=+=+=+=+=+=+=+= */
printf("Anfang\n");
fflush(stdout);
rec_count = 0;
zfreq = 0;
k=0;
floh = 0;
testclass[0] = 'U';
testclass[1] = 'S';
testclass[2] = '\0';
machine = 1;
/* next calculate the standard azimuths */
for(ih = 0; ih < 72; ih++) az[ih] = 5.0 * (float)ih;
/* then calculate the vertical angles to be used */
for(iv=0; iv < 13; iv++) vert[iv] = 5.0 * (float)iv;
printf("Azimuths and Elevation angles calculated\n");
fflush(stdout);
/* Initialization finished */
/* ==================== MAIN PROGRAM =====================================
======================= MAIN PROGRAM ===================================*/
/* open AM data base */
if(floh == 1) printf("open am.dat\n");
if(floh == 1) fflush(stdout);
AMDB = fopen("/dbs/amdb/am.dat", "r");
/* AMDB = fopen("/home/users/dba/amdb/fccdb/am.dat", "r"); */
/* AMDB = fopen("/home/users/AM/ball/variation/am.dat", "r"); */
if(floh == 1) printf("open trace.fnl\n");
if(floh == 1) fflush(stdout);
TRACE =fopen("wgb0.trace.fnl","w");
/* start_rec = 13140; */
/* start_rec = 3397; */
start_rec = 1;

if(floh == 1) printf("getting header\n");
if(floh == 1) fflush(stdout);
getheader(); /* database header now read and printed */
fflush(stdout);
j = 1;
frequency = 0;
tested = 0;
/* for (k=0;k<=rec_count-1;k++) */ /* alternative means of running */
/* while( (fseek(AMDB,am_point1,0) != EOF ) ) */
while( frequency < 1610 )
{
reknumber = k;
am_point1 = am_rec_length * reknumber;
am_point4 = am_rec_length * (reknumber +1); /*augmentation record */
fseek(AMDB,am_point1,0);
fgets(type1_line,600,AMDB);
/* if(fgets(type1_line,600,AMDB) != NULL) */
/* while(frequency < 1610) */
/* { */
for (i=0; i<2; i++) rectyp[i] = type1_line[i+10]; /* get record type */
rectyp[2] = '\0';
record_type = atoi(rectyp);
if(k >= start_rec)
{
fprintf(TRACE,"%d %d\n",reknumber,record_type);
fflush(TRACE);
}
if(record_type == 1)
{
hours = type1_line[39]; /* position 40 */
for (i=0; i<2; i++) AM_country[i] = type1_line[i+18]; /* station country */
AM_country[2] = '\0';
for (i=0; i<2; i++) cntow[i] = type1_line[i+71]; /* get number of towers */
cntow[2] = '\0';
ntow = atoi(cntow);
for (i=0;i< 4; i++) freq[i] = type1_line[i]; /* recover the freq */
frequency = atoi(freq);
if( (hours == 'U' || hours == 'N') && ((ntow > 1) && (ntow <= 4)) &&
(!strncmp("US",AM_country,2) ) && (k > start_rec) )
{
for (i=0; i<2; i++)
{
AM_state[i] = type1_line[i+349]; /* get state of station */
cnaug[i] = type1_line[i+384]; /* get number of augmentations */
domclass[i] = type1_line[i+42]; /* get domestic class */
} /* end of the for i loop */
clod[2] = type1_line[55];
AM_state[2] = '\0';
cnaug[2] = '\0';
domclass[2] = '\0';
latdir = type1_line[45];
londir = type1_line[52];
dstat = type1_line[38]; /* domestic status */
r2stat = type1_line[40]; /* region 2 class/position 41 */
dompat = type1_line[41]; /* position 42 */
schedule = type1_line[382];
naug = atoi(cnaug);
for (i=0; i<7; i++) crms[i] = type1_line[i+483];
rms = atof(crms)/100.0;
for (i=0; i<7; i++) rufzeichen[i] =type1_line[i+351];
rufzeichen[7] = '\0';
for (i=0; i<9; i++) cpower[i] = type1_line[i+61];
cpower[9] = '\0';
power = atof(cpower)/100000.0;
if(ntow > 1)
{
for (i=0; i<12; i++) cqfactor[i] = type1_line[i+367];
cqfactor[12] = '\0';
qfac = atof(cqfactor)/100000000.0;
} /* end if(ntow > 1) */

for (i=0; i<27; i++) AM_city[i] = type1_line[i+322];
AM_city[27] = '\0';
for (i=0; i<4; i++) prefix[i] = type1_line[i+26];
prefix[4] = '\0';
for (i=0; i<8; i++) filenr[i] = type1_line[i+30];
filenr[8] = '\0';
for (i=0; i<77; i++) comment[i] = type1_line[i+386];
/* ====================================================================== */
/* output the data */
/* ====================================================================== */
j++; /* increment stations found counter */

if( (rufzeichen[0] != '0' || rufzeichen[0] != ' ')
&& (AM_city[0] != '0' || AM_city[0] != ' ')
&& (AM_city[1] != '0' || AM_city[1] != ' ')
&& (AM_state[0] != '0' || AM_state[0] != ' ')
&& (AM_state[1] != '0' || AM_state[1] != ' ')
&& (dstat != 'M' || dstat != 'S' || dstat != 'D'
|| dstat != 'P' || dstat != 'T')
&& ( (ntow > 1) && (ntow <= 4) )
&& ( record_type == 1) )
{
attempt[ntow]++; /* advance station counter by number of towers*/
printf("\n"); /* line feed */
printf("Station Call : %7s Frequency : %5d kHz record %7d\n",
rufzeichen, frequency, k);
printf("no. towers: %d attempt no. %d \n",ntow,attempt[ntow]);
/* if(ntow > 1) */
/* { */
if (comment[0] != ' ') printf("Comment: %75s\n",comment);
if(floh == 1) printf("c_get_param\n");
c_getparam();
/* floh = 1; */
if(floh == 1) printf("conq\n");
conq();
if (qfac > 0.0)
{
qfactor = qfac;
}
else
qfactor = qcal;
/* printf("Qfactor : %7.4\n",qfactor); */
if(floh == 1) printf("kurz\n");
kurz = shortwr();
if(floh == 1) printf("maxf\n");
maxf = maxfld(); /* get maximum field */
if(floh == 1) printf("getref\n");
reftow = getref();
if(floh == 1) printf("End of directional data\n");
/* } */ /* end of directional antenna data */
} /* end of regular print statement */
/* f of theta = 1 ; all calculations on the ground */
for(j1=0;j1<ntow;j1++) ftheta[j1] = 1;
/* now we find the minimums and maximums */
if(floh == 1) printf("Eminmax\n");
Eminmax();
if(floh ==1) printf("set_vary_param\n");
set_vary_param();
/* now calculate the standard pattern at the min/max azimuths */
if(floh ==1) printf("min max fields\n");
/* floh = 0; */
for(ih = 0; ih <imaxvary; ih++)
{
vang = 0.0; /* vertical angle */
/* printf("%d Eth in\n", imaxvary); */
/* fflush(stdout); */
et[ih] = Eth(vang,vaz[ih]);
/* printf("%d Eth out\n",ih); */
/* fflush(stdout); */
/* es[ih] = Estd(kurz,et[ih],0.0); */
es[ih] = 1.05*sqrt(et[ih]*et[ih] + qfactor*qfactor);
/* printf("%d Estd out\n",ih); */
/* fflush(stdout); */
}
if(k>= start_rec) printf(" Rec: %d %s computed\n", k,rufzeichen);
/* =+=+=+=+=+=+=+ VARATION OF THE ARRAY PARAMETERS =+=+=+=+=+=+=+= */
maxtowvary = 2*ntow+1; /* maximum number of parametrs that vary */
if(floh == 1) printf("maxtowvary %d\n",maxtowvary);
for(inc=0; inc <21; inc++) /* set tolerances */
{
if(floh == 1) printf(" inc = %d\n",inc);
flag_vary = 0; /* set flag */
ecomp2 = 0; /* initialize the comparison value */
if(inc == 0) /* standard variation */
{
ftol = 0.05; /* 5% under */
ptol = 3.0; /* 3 degrees */
}
if(inc == 1) /* standard variation */
{
ftol = 0.04; /* 4% under */
ptol = 2.40; /* 2.4 degrees */
}
if(inc == 2) /* standard variation */
{
ftol = 0.03; /* 3% under */
ptol = 1.80; /* 1.8 degrees */
}
if(inc == 3) /* standard variation */
{
ftol = 0.02; /* 2% under */
ptol = 1.20; /* 1.2 degrees */
}
if(inc == 4) /* standard variation */
{
ftol = 0.01; /* 1% under */
ptol = 0.6; /* 0.6 degrees */
}
if(inc == 5) /* critical ? */
{
ftol = 0.0175; /* 1.75% under */
ptol = 1.75; /* 1.75 degrees */
}
if(inc == 6) /* critical ? */
{
ftol = 0.015; /* 1.5% under */
ptol = 1.5; /* 1.5 degrees */
}
if(inc == 7) /* critical ? */
{
ftol = 0.0125; /* 1.25% under */
ptol = 1.25; /* 1.25 degrees */
}
if(inc == 8) /* critical ? */
{
ftol = 0.01; /* 1% under */
ptol = 1.0; /* 1.0 degrees */
}
if(inc == 9) /* more critical */
{
ftol = 0.0095; /* 0.95% under */
ptol = 0.95; /* 0.95 degrees */
}
if(inc == 10) /* more critical */
{
ftol = 0.0090; /* 0.90% under */
ptol = 0.90; /* 0.90 degrees */
}
if(inc == 11) /* more critical */
{
ftol = 0.0085; /* 0.85% under */
ptol = 0.85; /* 0.85 degrees */
}
if(inc == 12) /* more critical */
{
ftol = 0.0080; /* 0.80% under */
ptol = 0.80; /* 0.80 degrees */
}
if(inc == 13) /* more critical */
{
ftol = 0.0075; /* 0.75% under */
ptol = 0.75; /* 0.75 degrees */
}
if(inc == 14) /* more critical */
{
ftol = 0.0075; /* 0.5% under */
ptol = 0.75; /* 0.5 degrees */
}
if(inc == 15) /* more critical */
{
ftol = 0.0065; /* 0.65% under */
ptol = 0.65; /* 0.65 degrees */
}
if(inc == 16) /* more critical */
{
ftol = 0.0060; /* 0.6% under */
ptol = 0.60; /* 0.6 degrees */
}
if(inc == 17) /* more critical */
{
ftol = 0.0055; /* 0.55% under */
ptol = 0.55; /* 0.55 degrees */
}
if(inc == 18) /* more critical */
{
ftol = 0.005; /* 0.5% under */
ptol = 0.5; /* 0.5 degrees */
}
if(inc == 19) /* more critical */
{
ftol = 0.0045; /* 0.45% under */
ptol = 0.45; /* 0.45 degrees */
}
if(inc == 20) /* not grantable */
{
ftol = 0.004; /* 0.4% under */
ptol = 0.4; /* 0.4 degrees */
} /* tolerances set */
if(floh == 1) printf("\nTol Field: %f",ftol);
if(floh == 1) printf("Phase: %f degrees\n", ptol);
/* rezero the variation array */
for(itwr=0;itwr <34; itwr++) dbtwr[itwr] = 0; /* initialized */
for(lp1=0; lp1<ntow;lp1++) fe[lp1] = '0';
for(lp1=0; lp1<ntow;lp1++) ph[lp1] = '0';
for(lp1 = 0; lp1<6; lp1++) attempts[lp1] = 0;
for(lp1 = 0; lp1<6; lp1++) hits[lp1] = 0;
/* initialization finished */
if(floh == 1) printf("Initialization complete\n");
/* now set up the new varied arrays */
lnew= 0;
lmax = 2*ntow - 1;
while( lnew < lmax)
{
for(lp7=0;lp7<lmax;lp7++)
if(dbtwr[lp7] >=3)
{
lnew = stepone(lp7);
}
if(lnew != 2*maxf || lnew != (2*maxf-1) )
{
for(lp1=0; lp1<lmax; lp1++)
{
lp2 = lp1/2; /* convert back to tower numbers */
if(lp2 != maxf)
{
if(dbtwr[lp1] == 0 && 2*lp2 == lp1) fe[lp2] = '0';
if(dbtwr[lp1] == 0 && 2*lp2 != lp1) ph[lp2] = '0';
if(dbtwr[lp1] == 1 && 2*lp2 == lp1) fe[lp2] = 'P';
if(dbtwr[lp1] == 1 && 2*lp2 != lp1) ph[lp2] = 'P';
if(dbtwr[lp1] == 2 && 2*lp2 == lp1) fe[lp2] = 'M';
if(dbtwr[lp1] == 2 && 2*lp2 != lp1) ph[lp2] = 'M';
}
} /* end of for lp1 loop */
if(floh == 1) printf("End of lp1 loop\n");
if(floh == 1) fflush(stdout);
/* parameters varies at this point - reset the reference tower */
fe[maxf] = 'K';
ph[maxf] = 'K';
/* new varied parameters established at this point - now set up new array */
for(lp1 = 0; lp1< ntow; lp1++)
{
if(fe[lp1] == '0' || fe[lp1] == 'K')
field[lp1] = antenna[lp1].field;
if(ph[lp1] == '0' || ph[lp1] == 'K')
phase[lp1] = antenna[lp1].phase;
if(fe[lp1] == 'P')
field[lp1] = (float)(1+ftol)*antenna[lp1].field;
if(ph[lp1] == 'P')
phase[lp1] = antenna[lp1].phase + ptol;
if(fe[lp1] == 'M')
field[lp1] = (float)(1-ftol)*antenna[lp1].field;
if(ph[lp1] == 'M')
phase[lp1] = antenna[lp1].phase - ptol;
}
for(j1=0;j1<ntow;j1++) ftheta[j1] = 1;
/* next calculate the k-factor and q-factor for this set of parameers */
if(floh == 1) printf("modified k-factor - start\n");
conq1();
if(floh == 1) printf("modified k-factor - stop\n");
/* now calculate the varied pattern at the desired azimuths */
for(ih = 0; ih <imaxvary; ih++)
{
attempts[inc]++; /* increment attempts counter */
vang = 0.0; /* vertical angle */
/* calculate the varied theoretical horizontal pattern */
ev[ih] = Evary(vang,vaz[ih]);
/* comparison routine */
if(ev[ih] > es[ih]) hits[inc]++;
if(ev[ih] > es[ih]) flag_vary++;
/* comparison routine goes here */
ecomp1 = ((ev[ih]-es[ih])/es[ih]);
if((ev[ih] > es[ih]) && (ecomp1 > ecomp2))
{
flag_vary++;
results[0] = vaz[ih];
results[1] = es[ih];
results[2] = ev[ih];
results[3] = ecomp1;
results[4] = kfaktor;
strcpy(maxfe,fe);
strcpy(maxph,ph);
ecomp2 = ecomp1; /* set comparison to higher value */
}
} /* end of for ih loop - comparison finished. */
} /* end of if lnew loop */
if(floh == 1) printf("vary next pattern\n");
dbtwr[0] = dbtwr[0] +1; /* increment counter */
/* get next varied pattern */
} /*end of while lnew loop */
if(flag_vary != 0)
{
/* increment the number of stations having problems */
printf(" Az: %5.1f", results[0]);
printf(" Estd : %7.1f ", results[1]);
printf(" Ev : %7.1f ", results[2]);
printf(" Magnitude: %8.5f", results[3]);
printf(" Code : ");
for(l1 = 0; l1 < ntow; l1++)
{
printf("%c%c",maxfe[l1],maxph[l1]);
}
printf(" KF: %8.4f %ld\n", results[4],flag_vary);
maxpcent = (int)(100*hits[inc]/attempts[inc]);
printf("\n Before %d %d %d ", ntow,inc,maxpcent);
printf(" %d \n", bucket[ntow-2][inc][maxpcent] );
bucket[ntow-2][inc][maxpcent]++;
printf(" After %d %d %d ", ntow,inc,maxpcent);
printf(" %d \n", bucket[ntow-2][inc][maxpcent] );
fflush(stdout);
} /* end of if flag_vary */
} /* the end of the for inc variation section */
tested++; /* increment the station number counter */
OUT = fopen("wgb0vary.output.fnl.lis","a+"); /* File for outputting solutions*/
printf(" %d stations investigated.\n",k);
fprintf(OUT,"\n%d stations investigated.\n",k);
fprintf(OUT,"\n%d stations tested.\n",tested);
fprintf(OUT,"\nStation Call : %7s Frequency : %5d kHz\n",
rufzeichen, frequency);
fprintf(OUT,"City %s, State: %2s Country : %2s\n",
AM_city, AM_state, AM_country);
/* fprintf(OUT,"%c %2d %2d %2d %c %3d %2d %2d \n", latdir,lad, */
/* lam, las, londir, lod, lom, los); */
fclose(OUT);
system("date >> vary.output.fnl.lis");
SUMMED = fopen("wgb0sum.txt.fnl","w"); /* File for outputting summations */
if(floh == 1) printf(" Printing Summary\n");
fprintf(SUMMED,"\n Summary\n");
for(lp11=0;lp11<21; lp11++)
{
if(lp11 == 0)
fprintf(SUMMED," 5.00% - 3.00 degree\n");
if(lp11 == 1)
fprintf(SUMMED," 4.00% - 2.40 degree\n");
if(lp11 == 2)
fprintf(SUMMED," 3.00% - 1.80 degree\n");
if(lp11 == 3)
fprintf(SUMMED," 2.00% - 1.20 degree\n");
if(lp11 == 4)
fprintf(SUMMED," 1.00% - 0.60 degree\n");
if(lp11 == 5)
fprintf(SUMMED," 1.75% - 1.75 degree\n");
if(lp11 == 6)
fprintf(SUMMED," 1.50% - 1.50 degree\n");
if(lp11 == 7)
fprintf(SUMMED," 1.25% - 1.25 degree\n");
if(lp11 == 8)
fprintf(SUMMED," 1.00% - 1.00 degree\n");
if(lp11 == 9)
fprintf(SUMMED," 0.95% - 0.95 degree\n");
if(lp11 == 10)
fprintf(SUMMED," 0.90% - 0.90 degree\n");
if(lp11 == 11)
fprintf(SUMMED," 0.85% - 0.85 degree\n");
if(lp11 == 12)
fprintf(SUMMED," 0.80% - 0.80 degree\n");
if(lp11 == 13)
fprintf(SUMMED," 0.75% - 0.75 degree\n");
if(lp11 == 14)
fprintf(SUMMED," 0.70% - 0.70 degree\n");
if(lp11 == 15)
fprintf(SUMMED," 0.65% - 0.65 degree\n");
if(lp11 == 16)
fprintf(SUMMED," 0.60% - 0.60 degree\n");
if(lp11 == 17)
fprintf(SUMMED," 0.55% - 0.55 degree\n");
if(lp11 == 18)
fprintf(SUMMED," 0.50% - 0.50 degree\n");
if(lp11 == 19)
fprintf(SUMMED," 0.45% - 0.45 degree\n");
if(lp11 == 20)
fprintf(SUMMED," 0.40% - 0.40 degree\n");
fprintf(SUMMED," percent 2twr 3twr 4twr\n");
for(lp12 =0;lp12<101; lp12++)
{
fprintf(SUMMED," %3d",lp12);
fprintf(SUMMED," %4d", bucket[0][lp11][lp12]);
fprintf(SUMMED," %4d", bucket[1][lp11][lp12]);
fprintf(SUMMED," %4d", bucket[2][lp11][lp12]);
fprintf(SUMMED," %4d\n",bucket[3][lp11][lp12]);
} /* end of if lp12 print loop */
} /* end of for lp11 */
fclose(SUMMED);
system("date >> sum.txt.fnl");
} /* end of the if((hours == 'U' usw. */
} /*end of (if record_type == 1 */
/* }*/ /* end of if fgets( ) usw */
/* if(k >= start_rec) printf("k before: %d ",k); */
k++; /* increment k */
/* if(k > start_rec) printf("k after: %d \n",k); */
fflush(stdout);
/* if(k >= start_rec && floh == 1) printf(" k incremented %d\n",k); */
/* am_point1 = am_rec_length * reknumber; */
} /* end of while (frequency < 1610) loop */
/* Now we print out the summary */
FINI = fopen("wgb0vary.final.fnl.lis","w"); /* File for outputting solutions*/
for (lp13 =0; lp13<5; lp13++)
{
fprintf(FINI,"\n Summary\n");
if(lp13 == 0) fprintf(FINI," 5.00% - 3.00 degree\n");
if(lp13 == 1) fprintf(FINI," 4.00% - 2.40 degree\n");
if(lp13 == 2) fprintf(FINI," 3.00% - 1.80 degree\n");
if(lp13 == 3) fprintf(FINI," 2.00% - 1.20 degree\n");
if(lp13 == 4) fprintf(FINI," 1.00% - 0.60 degree\n");
if(lp13 == 5) fprintf(FINI," 1.75% - 1.00 degree\n");
if(lp13 == 6) fprintf(FINI," 1.50% - 1.00 degree\n");
if(lp13 == 7) fprintf(FINI," 1.25% - 1.25 degree\n");
if(lp13 == 8) fprintf(FINI," 1.00% - 1.00 degree\n");
if(lp13 == 9) fprintf(FINI," 0.95% - 0.95 degree\n");
if(lp13 == 10) fprintf(FINI," 0.90% - 0.90 degree\n");
if(lp13 == 11) fprintf(FINI," 0.85% - 0.85 degree\n");
if(lp13 == 12) fprintf(FINI," 0.80% - 0.80 degree\n");
if(lp13 == 13) fprintf(FINI," 0.75% - 0.75 degree\n");
if(lp13 == 14) fprintf(FINI," 0.70% - 0.70 degree\n");
if(lp13 == 15) fprintf(FINI," 0.65% - 0.65 degree\n");
if(lp13 == 16) fprintf(FINI," 0.60% - 0.60 degree\n");
if(lp13 == 17) fprintf(FINI," 0.55% - 0.55 degree\n");
if(lp13 == 18) fprintf(FINI," 0.50% - 0.50 degree\n");
if(lp13 == 19) fprintf(FINI," 0.45% - 0.45 degree\n");
if(lp13 == 20) fprintf(FINI," 0.40% - 0.40 degree\n");
fprintf(FINI," percent 2twr 3twr 4twr 5twr\n");
for(lp14 =0; lp14<101; lp14++)
{
fprintf(FINI," %3d",lp14+1);
fprintf(FINI," %4d", bucket[0][lp13][lp14]);
fprintf(FINI," %4d", bucket[1][lp13][lp14]);
fprintf(FINI," %4d", bucket[2][lp13][lp14]);
fprintf(FINI," %4d\n", bucket[3][lp13][lp14]);
} /* end of if lp14 print loop */
} /* end of if lp13 print loop */
/* summary printed - end program */
fclose(FINI);
fclose (AMDB); /* close the am database */
printf("\n End of run. Number of stations found : %d\n\n", j);
fflush(stdout);
exit(0); /* Exit program */
} /* end of main program */
/* ==================== END OF MAIN PROGRAM =============================*/
/* ==================== END OF MAIN PROGRAM =============================*/
/* ================================================================== */
getheader() /* read the database header */
{
/* am_point0 = 19; */
/* fseek(AMDB, am_point0, 0); */
/* fgets(AM_volume,5, AMDB); */
/* fgets(Change_list,5,AMDB); */
am_point0 = 28;
fseek(AMDB,am_point0,0);
fgets(AM_update_year,3,AMDB);
am_point0 = 30;
fseek(AMDB,am_point0,0);
fgets(AM_update_month,3,AMDB);
am_point0 = 32;
fseek(AMDB,am_point0,0);
fgets(AM_update_day,3,AMDB);
/* printf("<H4><Center>"); */
printf("\n AM Data Base\n");
printf(" Last Update : %2s/%2s/%2s\n\n", AM_update_month,
AM_update_day,AM_update_year);
/* printf("</center></h4>"); */
}
/*-----------------------------------------------------------------*/
c_getparam()
{
int mtow;
int i1;
int i2;
int i3;
int j1;
int j2;
int j3;
int k1;
int k2;
int k3;
int l1;
int l2;
long int am_rec_length =600;
am_point1 = am_rec_length * reknumber;
fseek(AMDB,am_point1,0);
if(fgets(type1_line,600,AMDB) != NULL)
{
mtow = ntow-1;
if(ntow >= 3 ) mtow = 2;
/* printf("towers 1-3\n"); */
/* fflush(stdout); */
for (i1 = 0; i1<= mtow; i1++)
{
ctowref = type1_line[155 + i1*68];
j1 = 156 + i1*68;
ctlswitch = type1_line[156 + i1*68];
if(ctowref == '0') nda[i1] = 0;
if(ctowref == '1') nda[i1] = 1;
if(ctowref == '0') antenna[i1].tower_ref = 0;
if(ctowref == '1') antenna[i1].tower_ref = 1;
if(ctlswitch == '0') tlswitch[i1] = 0;
if(ctlswitch == '1') tlswitch[i1] = 1;
if(ctlswitch == '2') tlswitch[i1] = 2;
if(ctlswitch == '3') tlswitch[i1] = 3;
if(ctlswitch == '4') tlswitch[i1] = 4;
if(ctlswitch == '5') tlswitch[i1] = 5;
if(ctlswitch == '6') tlswitch[i1] = 6;
if(ctlswitch == '7') tlswitch[i1] = 7;
if(ctlswitch == '8') tlswitch[i1] = 8;
if(ctlswitch == '9') tlswitch[i1] = 9;
if(ctlswitch == 'A') tlswitch[i1] = 10;
if(ctlswitch == 'B') tlswitch[i1] = 11;
if(ctlswitch == 'C') tlswitch[i1] = 12;
antenna[i1].tlswitch = tlswitch[i1];
/* read field ratio */
for (k1 =0; k1 < 9; k1++)
{
cfield[k1] = type1_line[118 + i1*68 + k1];
}
cfield[9] = '\0'; /* end of field read */
/* read tower phase */
for (k1 =0; k1 < 8; k1++)
{
cphase[k1] = type1_line[132 + i1*68 + k1];
}
cphase[8] = '\0'; /* end of phase read */
/* read tower spacing */
for (k1 =0; k1 < 8; k1++)
{
cspace[k1] = type1_line[140 + i1*68 + k1];
}
cspace[8] = '\0'; /* end of spacing read */
/* read tower orientation */
for (k1 =0; k1 < 7; k1++)
{
corientation[k1] = type1_line[148 + i1*68 +k1];
}
corientation[7] = '\0'; /* end of orientation read */
/* tower parameters height, b, c, & d read */
for (k1 =0; k1 <5; k1++)
{
cheight[k1] = type1_line[127 + i1*68 +k1];
cb[k1] = type1_line[161 + i1*68 + k1];
cc[k1] = type1_line[166 + i1*68 + k1];
cd[k1] = type1_line[171 + i1*68 + k1];
}
cheight[5] = '\0';
cb[5] = '\0';
cc[5] = '\0';
cd[5] = '\0';
for (k1=0; k1 < 4; k1++)
{
ca[k1] = type1_line[157 + i1*68 + k1];
}
ca[4] = '\0'; /* end of tower parameter read */
/* data is read, so now convert and store */
field[i1] = atoi(cfield)/10000000.0;
phase[i1] = atoi(cphase)/10000.0 - 360.0;
height[i1] = atoi(cheight)/100.0;
space[i1] = atoi(cspace)/10000.0;
orientation[i1] = atoi(corientation)/10000.0;
a[i1] = atoi(ca)/10.0;
b[i1] = atoi(cb)/100.0;
c[i1] = atoi(cc)/100.0;
d[i1] = atoi(cc)/100.0;
antenna[i1].field =atoi(cfield)/10000000.0;
antenna[i1].phase = atoi(cphase)/10000.0 - 360.0;
antenna[i1].rphase = radian*antenna[i1].phase;
antenna[i1].hgt = atoi(cheight)/100.0;
antenna[i1].rhgt = radian*height[i1];
antenna[i1].spacing = atoi(cspace)/10000.0;
antenna[i1].dr = radian*antenna[i1].spacing;
antenna[i1].dd = antenna[i1].spacing;
antenna[i1].azimuth = atoi(corientation)/10000.0;
antenna[i1].alpha = radian*antenna[i1].azimuth;
antenna[i1].alphad = antenna[i1].azimuth;
antenna[i1].a = atoi(ca)/10.0;
antenna[i1].ra = radian*antenna[i1].a;
antenna[i1].b = atoi(cb)/100.0;
antenna[i1].rb = radian*antenna[i1].b;
antenna[i1].c = atoi(cc)/100.0;
antenna[i1].rc = radian*antenna[i1].c;
antenna[i1].d = atoi(cd)/100.0;
antenna[i1].rd = radian*antenna[i1].d;
} /* end of towers 1-3 i.e. 0-2 */
if(ntow > 3)
{
am_point2 = am_point1 + 600;
fseek(AMDB,am_point2,0);
fgets(type2_line,600,AMDB);
am_point4 = am_point2 + 600;
}
mtow = ntow-1;
if(ntow >= 10 ) mtow = 9;
/* printf("towers 4-10\n"); */
/* fflush(stdout); */
for (i2 = 3; i2 <= mtow; i2++)
{
ctowref = type2_line[67 + (i2 - 3)*68];
ctlswitch = type2_line[68 + (i2 - 3)*68];
if(ctowref == '0') nda[i2] = 0;
if(ctowref == '1') nda[i2] = 1;
if(ctowref == '0') antenna[i2].tower_ref = 0;
if(ctowref == '1') antenna[i2].tower_ref = 1;
if(ctlswitch == '0') tlswitch[i2] = 0;
if(ctlswitch == '1') tlswitch[i2] = 1;
if(ctlswitch == '2') tlswitch[i2] = 2;
if(ctlswitch == '3') tlswitch[i2] = 3;
if(ctlswitch == '4') tlswitch[i2] = 4;
if(ctlswitch == '5') tlswitch[i2] = 5;
if(ctlswitch == '6') tlswitch[i2] = 6;
if(ctlswitch == '7') tlswitch[i2] = 7;
if(ctlswitch == '8') tlswitch[i2] = 8;
if(ctlswitch == '9') tlswitch[i2] = 9;
if(ctlswitch == 'A') tlswitch[i2] = 10;
if(ctlswitch == 'B') tlswitch[i2] = 11;
if(ctlswitch == 'C') tlswitch[i2] = 12;
antenna[i2].tlswitch = tlswitch[i2];
for (k2 = 0; k2 < 9; k2++)
{
cfield[k2] = type2_line[30 + (i2 - 3)*68 + k2];
}
cfield[9] = '\0'; /* field read */

for (k2 =0; k2 < 8; k2++)
{
cphase[k2] = type2_line[44 + (i2 - 3)*68 + k2];
}
cphase[8] = '\0';
for (k2 =0; k2 < 8; k2++)
{
cspace[k2] = type2_line[52 + (i2 - 3)*68 + k2];
}
cspace[8] = '\0';
for (k2 =0; k2 < 7; k2++)
{
corientation[k2] = type2_line[60 + (i2 - 3)*68 + k2];
}
corientation[7] = '\0'; /* orientation read */
for (k2 =0; k2 <5; k2++)
{
cheight[k2] = type2_line[39 + (i2 - 3)*68 + k2];
cb[k2] = type2_line[73 + (i2 - 3)*68 + k2];
cc[k2] = type2_line[78 + (i2 - 3)*68 + k2];
cd[k2] = type2_line[83 + (i2 - 3)*68 + k2];
}
cheight[5] = '\0';
cb[5] = '\0';
cc[5] = '\0';
cd[5] = '\0';
for (k2=0; k2 < 4; k2++)
{
ca[k2] = type2_line[69 + (i2 - 3)*68 + k2];
}
ca[4] = '\0';
/* data is read, so now convert and store */
field[i2] = atoi(cfield)/10000000.0;
phase[i2] = atoi(cphase)/10000.0 - 360.0;
height[i2] = atoi(cheight)/100.0;
space[i2] = atoi(cspace)/10000.0;
orientation[i2] = atoi(corientation)/10000.0;
a[i2] = atoi(ca)/10.0;
b[i2] = atoi(cb)/100.0;
c[i2] = atoi(cc)/100.0;
d[i2] = atoi(cc)/100.0;
antenna[i2].field =atoi(cfield)/10000000.0;
antenna[i2].phase = atoi(cphase)/10000.0 - 360.0;
antenna[i2].rphase = radian*phase[i2];
antenna[i2].hgt = atoi(cheight)/100.0;
antenna[i2].rhgt = radian*height[i2];
antenna[i2].spacing = atoi(cspace)/10000.0;
antenna[i2].dr = radian*antenna[i2].spacing;
antenna[i2].azimuth = atoi(corientation)/10000.0;
antenna[i2].dd = antenna[i2].azimuth;
antenna[i2].alphad = antenna[i2].azimuth;
antenna[i2].alpha = radian*antenna[i2].azimuth;
antenna[i2].a = atoi(ca)/10.0;
antenna[i2].ra = radian*antenna[i2].a;
antenna[i2].b = atoi(cb)/100.0;
antenna[i2].rb = radian*antenna[i2].b;
antenna[i2].c = atoi(cc)/100.0;
antenna[i2].rc = radian*antenna[i2].c;
antenna[i2].d = atoi(cd)/100.0;
antenna[i2].rd = radian*antenna[i2].d;
} /* end of towers 4-10 i.e. 3-9 */
 
if(ntow > 10)
{
am_point3 = am_point2 + 600;
fseek(AMDB,am_point3,0);
fgets(type3_line,600,AMDB);
am_point4 = am_point3 + 600;
}
mtow = ntow-1;
/* printf("towers 11-17\n"); */
/* fflush(stdout); */
for (i3 = 10; i3 <= mtow; i3++)
{
/* j3 = 67 + (i3-3)*68; */
ctowref = type3_line[67 + (i3 - 10)*68];
/* j3 = 68 + (i3-3)*68; */
ctlswitch = type3_line[68 + (i3 - 10)*68];
if(ctowref == '0') nda[i3] = 0;
if(ctowref == '1') nda[i3] = 1;
if(ctowref == '0') antenna[i3].tower_ref = 0;
if(ctowref == '1') antenna[i3].tower_ref = 1;
if(ctlswitch == '0') tlswitch[i3] = 0;
if(ctlswitch == '1') tlswitch[i3] = 1;
if(ctlswitch == '2') tlswitch[i3] = 2;
if(ctlswitch == '3') tlswitch[i3] = 3;
if(ctlswitch == '4') tlswitch[i3] = 4;
if(ctlswitch == '5') tlswitch[i3] = 5;
if(ctlswitch == '6') tlswitch[i3] = 6;
if(ctlswitch == '7') tlswitch[i3] = 7;
if(ctlswitch == '8') tlswitch[i3] = 8;
if(ctlswitch == '9') tlswitch[i3] = 9;
if(ctlswitch == 'A') tlswitch[i3] = 10;
if(ctlswitch == 'B') tlswitch[i3] = 11;
if(ctlswitch == 'C') tlswitch[i3] = 12;
antenna[i3].tlswitch = tlswitch[i3];
for (k3 =0; k3 < 9; k3++)
{
cfield[k3] = type3_line[30 + (i3 - 10)*68 +k3];
}
cfield[9] = '\0'; /* field read */

for (k3 =0; k3 < 8; k3++)
{
cphase[k3] = type3_line[44 + (i3 - 10)*68 + k3];
}
cphase[8] = '\0';
for (k3 =0; k3 < 8; k3++)
{
cspace[k3] = type3_line[52 + (i3 - 10)*68 + k3];
}
cspace[8] = '\0';
for (k3 =0; k3 < 7; k3++)
{
corientation[31] = type3_line[60 + (i3-10)*68 + k3];
}
corientation[7] = '\0'; /* orientation read */
for (k3 =0; k3 <5; k3++)
{
cheight[k3] = type3_line[39 + (i3 - 10)*68 + k3];
cb[k3] = type3_line[73 + (i3 - 10)*68 + k3];
cc[k3] = type3_line[78 + (i3 - 10)*68 + k3];
cd[k3] = type3_line[83 + (i3 - 10)*68 + k3];
}
cheight[5] = '\0';
cb[5] = '\0';
cc[5] = '\0';
cd[5] = '\0';
for (k3=0; k3 < 4; k3++)
{
ca[k3] = type3_line[69 + (i3 -10)*68 + k3];
}
ca[4] = '\0';
/* data is read, so now convert and store */
field[i3] = atoi(cfield)/10000000.0;
phase[i3] = atoi(cphase)/10000.0 - 360.0;
height[i3] = atoi(cheight)/100.0;
space[i3] = atoi(cspace)/10000.0;
orientation[i3] = atoi(corientation)/10000.0;
a[i3] = atoi(ca)/10.0;
b[i3] = atoi(cb)/100.0;
c[i3] = atoi(cc)/100.0;
d[i3] = atoi(cc)/100.0;
antenna[i3].field =atoi(cfield)/10000000.0;
antenna[i3].phase = atoi(cphase)/10000.0 - 360.0;
antenna[i3].rphase = radian*phase[i3];
antenna[i3].hgt = atoi(cheight)/100.0;
antenna[i3].rhgt = radian*height[i3];
antenna[i3].spacing = atoi(cspace)/10000.0;
antenna[i3].dr = radian*antenna[i3].spacing;
antenna[i3].dd = antenna[i3].spacing;
antenna[i3].azimuth = atoi(corientation)/10000.0;
antenna[i3].alpha = radian*antenna[i3].azimuth;
antenna[i3].alphad = antenna[i3].azimuth;
antenna[i3].a = atoi(ca)/10.0;
antenna[i3].ra = radian*antenna[i3].a;
antenna[i3].b = atoi(cb)/100.0;
antenna[i3].rb = radian*antenna[i3].b;
antenna[i3].c = atoi(cc)/100.0;
antenna[i3].rc = radian*antenna[i3].c;
antenna[i3].d = atoi(cd)/100.0;
antenna[i3].rd = radian*antenna[i3].d;
} /* end of towers 10-17 read */
towref(); /* now get the tower references set to the origin */
/* now fill in the antenna array parameters */
} /*end of if fgets */
} /* end of c_getparam */
/* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= */
towref()
{
int klm;
int loop;
int loop1;
double atemp[maxtow];
double dtemp[maxtow];
double temp1;
double temp2;
klm=0;
for(loop=0; loop < ntow; loop++)
{
dtemp[loop] = space[loop];
dr[loop] = dtemp[loop] * radian; /* antenna[loop].dr */
atemp[loop] = orientation[loop];
alpha[loop] = atemp[loop] * radian; /* antenna[loop].alpha */
/* if(loop > 0 && nda[loop] == 1) */
if(loop > 0 && antenna[loop].tower_ref == 1)
{
klm = 1;
loop1 = loop -1;
/* temp1 = dr[loop]* cos(alpha[loop]) + dr[loop1] * cos(alpha[loop1]); */
temp1 = antenna[loop].dr*cos(antenna[loop].alpha) +
antenna[loop1].dr*cos(antenna[loop1].alpha);
/* temp2 = dr[loop]* sin(alpha[loop]) + dr[loop1] * sin(alpha[loop1]); */
temp2 = antenna[loop].dr*sin(antenna[loop].alpha) +
antenna[loop1].dr*sin(antenna[loop1].alpha);
dr[loop] = sqrt(temp1 * temp1 + temp2 * temp2);
if(temp1 == 0.0 & temp2 == 0.0)
{
/* alpha[loop] = 0.0; */
antenna[loop].alpha = 0.0;
}
else if(temp1 ==0.0 && temp2 !=0)
antenna[loop].alpha = pi/2;
else
/* alpha[loop] = atan2(temp2,temp1); */
antenna[loop].alpha = atan2(temp2,temp1);
antenna[loop].dr = (float)dr[loop];
/* antenna[loop].alpha = (float)alpha[loop]; */
/* alphad[loop] = alpha[loop] * degree; */
alphad[loop] = antenna[loop].alpha * degree;
if(alphad[loop] < 0.0 ) alphad[loop] = alphad[loop] + 360.0;
antenna[loop].alphad = (float)alphad[loop];
dd[loop] = dr[loop] * degree;
antenna[loop].dd = (float)dd[loop];
/* if(klm == 1) printf("\nklm equals one.\n"); */
} /* end if */
} /* end for */
} /* end of towref */
/* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= */
conq() /* uses the antenna[*].*** */
{
double cusq;
double dph;
double erss;
double s1;
double s2;
double s3;
double s4;
double s5;
double q1;
double q2;
float azr;
float increment;
int j;
int k;
int loop;
cusq = 0.0;
s3 = 0.0;
s4 = 0.0;
increment = 360.0 / maxaz;
for(loop = 0; loop < ntow; loop++)
{
/* cu[loop] = antenna[loop].field; */
cusq = cusq + (antenna[loop].field * antenna[loop].field);
/* psi[loop] = phase[loop] * radian; */
psi[loop] = antenna[loop].rphase;
}
s4 = 0.0;
for(loop = 0; loop < maxaz; loop++)
{
az[loop] = loop * increment;
azr = az[loop] * radian;
s1 = 0.0;
s2 = 0.0;
for(k = 0; k < ntow; k++)
{
dph = antenna[k].dr * cos(azr - antenna[k].alpha) +
antenna[k].rphase;
s1 = s1 + antenna[k].field * sin(dph);
s2 = s2 + antenna[k].field * cos(dph);
} /* end of k loop */
s4 = s4 + (s1 * s1) + (s2 * s2);
} /* end of loop loop */
s5 = sqrt(s4/maxaz);
kfactor = rms/s5;

erss = kfactor * sqrt(cusq);
/* printf("Erss : %8.3f\n", erss); */
q1 = 0.025 * erss;
if(power >= 0.25 || rms >=141)
{
q2 = 10.0 * sqrt(power);
if(q2 < 10.0) q2 = 10.0;
}
else
q2 = 10.0 * sqrt(power);
if( q2 >= q1) qcal = q2;
if( q2 < q1) qcal = q1;
/* printf(" q1 : %8.4f q2 : %8.4f qcal : %8.4f\n", q1, q2, qcal); */
}
/* ------------------------------------------------------------ */
conq1() /* for calculating the k factors of the varied arrays */
{
double cusq;
double dph;
double erss;
double s1;
double s2;
double s3;
double s4;
double s5;
double q1;
double q2;
float azr;
float increment;
int j;
int k;
int loop;
cusq = 0.0;
s3 = 0.0;
s4 = 0.0;
increment = 360.0 / maxaz;
for(loop = 0; loop < ntow; loop++)
{
cu[loop] = field[loop];
cusq = cusq + (field[loop] * field[loop]);
psi[loop] = phase[loop] * radian;
}
s4 = 0.0;
for(loop = 0; loop < maxaz; loop++)
{
az[loop] = loop * increment;
azr = az[loop] * radian;
s1 = 0.0;
s2 = 0.0;
for(k = 0; k < ntow; k++)
{
dph = antenna[k].dr * cos(azr - antenna[k].alpha)
+ psi[k]; /* all in radians */
s1 = s1 + field[k] * sin(dph);
s2 = s2 + field[k] * cos(dph);
} /* end of k loop */
s4 = s4 + (s1 * s1) + (s2 * s2);
} /* end of loop loop */
s5 = sqrt(s4/maxaz);
kfaktor = rms/s5;
}
/* ------------------------------------------------------------ */
float Eth(vang,hang)
float vang;
float hang;
{
int nt;
float aphase;
/* float rphase; tower phase in radians */
float rtheta; /* vertical angle in radians */
float razi; /* horizontal azimuth in radians */
float r1;
float x1;
r1 = 0.0;
x1 = 0.0;
rtheta = (float)(radian * vang); /* vertical angle - degrees to radians*/
razi = (float)(radian * hang);
for(nt = 0; nt < ntow; nt++)
{
if(vang == 0.0) ftheta[nt] = 1.0;
aphase = antenna[nt].rphase +
(float)antenna[nt].dr * cos(rtheta) * cos(antenna[nt].alpha
- (razi));
r1 = r1 + antenna[nt].field*ftheta[nt]*cos(aphase);
x1 = x1 + antenna[nt].field*ftheta[nt]*sin(aphase);
}
return (kfactor*sqrt(r1*r1 + x1*x1));
} /* end of Eth() */
/* ------------------------------------------------------------ */
float Estd(ish,eth,vang)
int ish; /* index to the shortest tower */
float eth; /* theoretical pattern value */
float vang; /* vertical angle */
{
/* float Etheo; */
float qc;
float gtheta;
if(vang == 0.0) ftheta[ish] = 1.0;
qc = (float)qfactor * ftheta[ish];
return (1.05 * sqrt(eth * eth + qc*qc));
}
/* ------------------------------------------------------------ */
float Evary(vang,hang)
float vang;
float hang;
{
int nt;
float aphase;
float rphase; /* tower phase in radians */
float rtheta; /* vertical angle in radians */
float razi; /* horizontal azimuth in radians */
float r1;
float x1;
r1 = 0.0;
x1 = 0.0;
rtheta = (float)radian * vang; /* vertical angle - degrees to radians*/
razi = (float)radian * hang;
for(nt = 0; nt < ntow; nt++)
{
if(vang == 0.0) ftheta[nt] = 1.0;
rphase = (float)radian * phase[nt];
aphase = rphase + (float)antenna[nt].dr * cos(rtheta) *
cos(antenna[nt].alpha - (razi));
r1 = r1 + field[nt]*ftheta[nt]*cos(aphase);
x1 = x1 + field[nt]*ftheta[nt]*sin(aphase);
}
return (kfaktor*sqrt(r1*r1 + x1*x1));
}
/* ------------------------------------------------------------ */
int shortwr()
{
float gtemp;
float gshort;
int lp1;
int ishrt;
gshort = 1000.0;
ishrt = 0;
if(ntow > 1)
{
for(lp1 = 0; lp1 < ntow; lp1++)
{
if (tlswitch[lp1] == 0) gtemp = antenna[lp1].hgt;
if (tlswitch[lp1] == 1) gtemp = antenna[lp1].a+antenna[lp1].b;
if (tlswitch[lp1] == 2) gtemp = antenna[lp1].a+antenna[lp1].b;
if (tlswitch[lp1] == 3) gtemp = antenna[lp1].c;
if (tlswitch[lp1] == 4) gtemp = antenna[lp1].b;
if (tlswitch[lp1] == 5) gtemp = antenna[lp1].a;
if (tlswitch[lp1] == 6) gtemp = antenna[lp1].a+antenna[lp1].b;
if (tlswitch[lp1] == 7) gtemp = antenna[lp1].a;
if (tlswitch[lp1] == 8) gtemp = antenna[lp1].b;
if (tlswitch[lp1] == 9) gtemp = antenna[lp1].a+antenna[lp1].b;
if (gtemp < gshort)
{
gshort = gtemp;
ishrt = lp1;
}
} /* end of for lp1 */
} /* end of if (ntow > 1) */
return(ishrt);
}
/* ------------------------------------------------------------ */
int getref()
{
int iref;
int lp0;
int lp1;
iref = 0;
if(ntow > 1)
{
for(lp1 = 1; lp1 < ntow; lp1++)
{
lp0 = lp1 - 1;
if(antenna[lp1].field > antenna[lp0].field) iref = lp1;
} /* end of for lp1 */
} /* end of if (ntow > 1) */
return(iref);
}
/* ------------------------------------------------------------ */
int stepone(kt)
int kt;
{
int mt;
int lp5;
mt = kt;
if(dbtwr[kt]>= 3)
{
mt++; /* increment mt for return */
dbtwr[mt] = dbtwr[mt] + 1; /* increment next box */
for(lp5=0;lp5<mt;lp5++)
dbtwr[lp5]=0; /* rezero lower numbered boxes */
}
/* printf("mt before : %d after: %d\n",kt,mt); */
return(mt);
}
/* ------------------------------------------------------------ */
int maxfld()
{
int loop1;
int ifld;
ifld = 0;
for(loop1 = 0; loop1 < ntow; loop1++)
{
if(antenna[loop1].field > antenna[ifld].field)
ifld = loop1;
} /* end of for loop1 */
return(ifld);
}
/* ------------------------------------------------------------ */
Eminmax()
{
int iq;
int iq1;
float az0;
float az1;
float az2;
float Est0;
float Est1;
float Est2;
float eth0;
float eth1;
float eth2;
/* start of actual calculation */
imax = 0;
imin = 0;
for(iq=0; iq <30; iq++)
{
emax[iq] = 0.0;
emin[iq] = 0.0;
}
for(iq=1; iq < 3602; iq++)
{
az0 = ((float)iq)/10.0;
az1 = ((float)(iq - 1))/10.0;
az2 = ((float)(iq + 1))/10.0;
eth0 = Eth(0.0, az0);
eth1 = Eth(0.0, az1);
eth2 = Eth(0.0, az2);
Est0 = Estd(kurz,eth0,0.0);
Est1 = Estd(kurz,eth1,0.0);
Est2 = Estd(kurz,eth2,0.0);
if((Est0 > Est1) && (Est0 > Est2) )
{
azmax[imax] = az0;
emax[imax] = Est0;
imax++;
} /* maximums stored */
if((Est0 < Est1) && (Est0 < Est2) )
{
azmin[imin] = az0;
emin[imin] = Est0;
imin++;
} /* minimums stored */
}
}
/* ------------------------------------------------------------ */
print_eminmax()
{
int ilp;
printf(" Azimuth Emin Azimuth Emax\n");
for(ilp=0; ilp<30; ilp++)
{
if(ilp <= (imax-1) & ilp <= (imin-1))
{
printf(" %5.1f %6.1f",azmin[ilp],emin[ilp]);
printf(" %5.1f %8.1f\n",azmax[ilp],emax[ilp]);
}
if(ilp <= (imax-1) & ilp > (imin-1))
printf(" %5.1f %8.1f",azmin[ilp],emin[ilp]);
if(ilp > (imax-1) & ilp <= (imin-1))
printf(" %5.1f %6.1f\n",azmax[ilp],emax[ilp]);
}
printf("\n");
}
/* ------------------------------------------------------------ */
set_vary_param()
{
int lpf;
int ih1;
int ih2;
int ih3;
float aztemp;
float estemp;
for(ih1 = 0; ih1<72; ih1++) az[ih1] = 0.0;
for(ih1 = 0; ih1<72; ih1++) es[ih1] = 0.0;
imaxvary = 0;
for(ih1 = 0;ih1<imin; ih1++)
{
vaz[ih1] = azmin[ih1];
es[ih1] = emin[ih1];
imaxvary++;
}
for(ih1 = 0;ih1<imax; ih1++)
{
vaz[ih1+(imin-1)] = azmax[ih1];
es[ih1+(imin-1)] = emax[ih1];
imaxvary++;
}
imaxvary--;
/* sort by azimuths */
for (ih2 = 0; ih2 < imaxvary-1; ih2++)
{
for (ih3 = ih2+1; ih3< imaxvary; ih3++)
{
if(vaz[ih2] > vaz[ih3])
{
estemp = es[ih2];
aztemp = vaz[ih2];
es[ih2] = es[ih3];
vaz[ih2] = vaz[ih3];
es[ih3] = estemp;
vaz[ih3] = aztemp;
}
}
}
/* sort is ended. Now print */
}
/* ------------------------------------------------------------ */