/* * Program: Global Communicator II - scanner signals converter * Programmer: Robert John Morton UK-YE572246C * Date: Tue 22 Sep 2020 From the directory in which broadcast.c resides: to compile: gcc broadcast.c -o broadcast -lm NOTE: It is necessary to bear in mind that different shortwave stations transmit on the same frequency at different times and places. In this program, on any given frequency, the more powerful station prevails. Con- sequently, although a station may be registered as transmitting on a par- ticular frequency, it may not be heard because a more powerful station is obliterating it at the receiver's location. To help alleviate this, at least in part, I decided to limit shortwave broadcasts to occupy only 5 x 1 kHz frequency slots. */ #include // input output to/from the console and keyboard #include // standard functions for the 'C' language #include // for log() function FILE *FI, *HS; char FN[28] = "../freqs/freqs000.txt"; char S1[10]; char S2[10]; // to hold the string version of the number char S3[10]; // to hold the string version of the number char S4[10]; // to hold the string version of the number int /* LONG WAVE TRANSMISSIONS kHz Sig CH LANGUAGE LOCATION kW COORDINATES */ T0LW[15][2] = { {153, 10}, // 01 Romanian Brașov 200 45°45′22.27″N 25°36′26.77″E {162,115}, // 02 French Allouis 2000 47°10′10.45″N 2°12′16.75″E // 164* -- Mongolian Ulaanbaatar 500 47°47′54.67″N 107°11′14.7″E {171, 50}, // 03 Arabic Nador 1600 35°02′50.65″N 2°55′22.81″W // French {180, 0}, // 04 {189, 5}, // 05 Icelandic Gufuskalar 300 64°54′26.00″N 23°55′19.50″W {198,100}, // 06 English Droitwich 500 52°17′46.90″N 2°06′24.32″W {207, 3}, // 07 Icelandic Eiðar 100 65°22′22.93″N 14°20′27.29″W // 209* -- Mongolian Choibalsan 75 48°00′17.27″N 114°27′17.6″E {216, 0}, // 08 {225, 45}, // 09 Polish Solec Kuja. 1000 53°01′21.01″N 18°15′32.63″E // 227* -- Mongolian Altai 75 46°19′25.52″N 96°15′31.20″E {234,110}, // 10 French Beidweiler 2000 49°43′42.57″N 6°19′04.29″E {243, 8}, // 11 Danish Kalundborg 50 55°40′39.27″N 11°04′08.60″E {252, 68}, /* 12 Arabic Tipaza 1500 36°33′58.14″N 2°28′50.30″E 12 English Clarkstown 300 53°27′46.00″N 6°40′39.00″W // Irish [two interferring signals]*/ {261, 0}, // 13 {270, 4}, // 14 Czech Topolná257 50 49°07′32.88″N 17°30′45.97″E {279, 0}, // 15 }, // * the 3 Mongolian stations are out of sequence in the 9kHz spacing. T0MW[] = { // MEDIUM WAVE TRANSMISSIONS: SIGNAL STRENGTHS 000,000,000,003,000,000,000,000,001,000,000,002,000,001,003,001,000,000, 175,000,000,000,000,000,000,000,001,001,000,000,000,200,000,000,000,000, 000,000,000,100,000,000,350,000,000,000,000,000,000,001,000,000,000,000, 000,000,002,000,500,000,001,880,000,000,000,000,000,000,024,000,000,000, 000,000,000,630,000,000,000,000,000,000,000,000,200,000,000,000,000,100, 000,000,000,000,000,000,000,000,000,000,000,000,125,000,000,125,000,000, 000,000,000,000,100,000,000,000,000,000,000,000,000 }, // signal level per broadcaster on short wave SI[15] = {60, 80, 40, 30, 23, 87, 92, 77, 34, 66, 26, 100, 34, 52, 65}; /* CONVERT AN 'int x' TO AN l-DIGIT NUMERIC STRING WITH LEADING SPACES OR ZEROS IN ARRAY S2[]: Called from 1 place each in editSI() and openDoc() and from 2 places each in editDT() and ixtotxt(). */ void showInt(int x, int l, int y) { char s = ' '; // for leading spaces if(y) s = '0'; // for leading zeros if(l > 11) l = 11; // safety precaution for(int i = 0; i < l; i++) S2[i] = s; // fill the whole field with spaces or zeros S2[l - 1] = '0'; S2[l] = (char)0; // terminating NULL character if(x > 0) { // if the number is non-zero: int i = l; // total of 'l' possible digits in the number /* While there're still more digits to process, work backwards from [8] to [0], storing the remainder after dividing the number by 10 as a numeric character in array S2[]. Then divide the number by 10 [unrounded] and loop back. */ while(x > 0 && i > 0) { S2[--i] = (char)(x % 10 + 48); x /= 10; } } } void storeSignal(int c) { int x = c; for(int j = 0; j < 4; j++) { // compute sideband amplitudes x *= 0.707; if(x < 2) x = 2; S1[j] = x; } fputc(S1[3],HS); fputc(S1[2],HS); fputc(S1[1],HS); fputc(S1[0],HS); fputc(c,HS); fputc(S1[0],HS); fputc(S1[1],HS); fputc(S1[2],HS); fputc(S1[3],HS); } int getNum() { int x = 0, c; while(!feof(FI) && (c = fgetc(FI)) != '\n') S1[x++] = c; S1[x] = '\0'; return atoi(S1); // number of frequencies in this file } void main() { int Q = 0; HS = fopen("scope.dat","wb"); // open the output file for writing for(int i = 0; i < 30000; i++) // zero the signal strengths fputc('\0',HS); // for the whole spectrum fclose(HS); // close the output file for create/write HS = fopen("scope.dat","rb+"); // open the output file for updating // LONG WAVE BROADCAST BANDS fseek(HS,149,SEEK_SET); // 1st channel frequency - 4KHz for(int i = 0; i < 144; i++) // for byte of the input file fputc('\2',HS); fseek(HS,149,SEEK_SET); // first channel frequency - 4kHz for(int i = 0; i < 15; i++) { // for each of the 15 channels storeSignal(T0LW[i][1]); // supply centre carrier amplitude } // MEDIUM WAVE BROADCAST BANDS int f = 526; // 1st channel frequency, less 4KHz fseek(HS,f,SEEK_SET); for(int i = 0; i < 1090; i++) // for each byte of the band span fputc('\2',HS); fseek(HS,f,SEEK_SET); // first channel's start byte for(int i = 0; i < 121; i++) { // for each of the 121 channels int d = T0MW[i]; // centre carrier amplitude double SIG = d; int c = (int)(log10(SIG) * 40); storeSignal(c); } // SHORTWAVE BROADCAST BANDS for(int K = 0; K < 176; K++) { // for each broadcaster: showInt(K,3,1); // Insert sequence number [000 to 175] of for(int k = 0; k < 3; k++) // current freqs file as a 3-digit string FN[k + 14] = S2[k]; // with leading zeros into file name string FI = fopen(FN,"rb"); // and open the input file for reading. int I = getNum(); // number of freqs for this broadcaster if(I > 150) { // max number of freqs is in fact 125 printf("Input File error: I=%i\n",I); break; } for(int i = 0; i < I; i++) { // for each freq for this broadcaster int f = getNum() - 2; // get the 1st/next frequency and subtract // 2 kHz to get frequency of lowest sideband /* See if there are signals already occupying this piece of the frequency spectrum, which could possibly swamp this transmission. */ fseek(HS,f,SEEK_SET); // seek start byte of lowest sideband S3[0] = fgetc(HS); // get lower far sideband S3[1] = fgetc(HS); // get lower near sideband S3[2] = fgetc(HS); // centre frequency S3[3] = fgetc(HS); // get higher near sideband S3[4] = fgetc(HS); // get higher far sideband int c = SI[Q++]; // signal level for this transmitter if(Q > 15) Q = 0; // cycle round the signal strengths /* Compute amplitudes for the 1 kHz centre frequency slot and the upper & lower pairs of 1 kHz sideband slots. */ S1[2] = c; // centre frequency is unattenuated c *= 0.707; // reduce signal strength for near sidebands S1[1] = c; // first lower sideband S1[3] = c; // first upper sideband c *= 0.707; // reduce signal strength again for far sidebands S1[0] = c; // second lower sideband S1[4] = c; // second upper sideband fseek(HS,f,SEEK_SET); // re-seek start byte of lowest sideband for(int k = 0; k < 5; k++) // for each 1kHz slot if(S1[k] > S3[k]) // If the new signal is greater than what is fputc(S1[k],HS); // already there, the new signal prevails. } fclose(FI); // close the input file } fclose(HS); // close the output file }