' Antenna temperature calculation. ' Based on a set of rotation matrixes. ' ' One given temperature for the whole Sky. ' One given temperature for the whole Earth. ' FF Table step : 1 degree. ' ' Author : F5FOD Jean-Pierre Waymel, with the DG7YBN Hartmut Klüver's advices and suggestions. ' Date : march 2018. ' ' Program name : Antenna G/T Calculator, AGTC_V3-06.bas ' Version 3.06 ' A bug has been discovered the 15th of march, 2018 by F5FOD : the program gave wrong results ' and no alert if FFTab was coming from 4nec2 with a comma as decimal mark. ' This is due to the 4nec2 FFTab format which is a little bit different from the EZNEC one, ' especially the position of the decimal mark of the value "Tot dB". ' ' FFTab 4nec2 format : ' Deg V dB H dB Tot dB ' 7 -26.49 -8.27 -8.21 ' 179 -51,95 -16,56 -16,56 ' 12345678901234567890123456789012 ' 1 2 3 ' ' FFTab EZNEC format : ' Deg V dB H dB Tot dB ' 4 -31.72 -8.60 -8.58X ' 136 -19,50 -19,19 -16,33X ' 123456789012345678901234567890123456 ' 1 2 3 ' ' (the "X" is a space character) ' ' Version 3.05 ' FF Table file name added in the window title before extracting the 65,341 Tot_dB values from the FF Table. ' ' Version 3.04 ' Beep when the page computation is ready in alpha range choice 3 (own range). ' Sky and Earth Temperatures in the output file : ####.## format instead of #####.# format. ' ' Version 3.03 ' Management of defaults in the FFtab by 2 means : input # after the EOF and 3 first characters ' of the last data line ("360"). The EZNEC files end with a line which contains only ' followed by a last line which contains only NULL. The 4nec2 files end only with a last line ' which contains only NULL (no line before which would contain only ). ' Beep when the page computation is ready in alpha range choice 2 (91 values from 0 to 90 deg.). ' Error handler for matrix non found and matrix incomplete. ' ' Version 3.02 ' New window title with the program name. ' 0 <= T_sky < 10,000 and 0 <= T_earth < 10,000 K. Zero K to be able to do the Vladimir's UR5EAZ ' tests : T_sky or T_earth = 0 K. ' T_sky and T_earth displayed on top of the result screens. ' Comment for alpha = 0 matrix program. ' Corrupted matrix error routine : 1 degree/n degrees. ' ' Version 3.01 ' Format ####.## instead of ###.## for pattern and total Temperatures as one may enter ' Tsky = 290 K and Tearth = 5000 K at 144 MHz(Vladimir, UR5EAZ) or ' Tsky = 2200 K and Tearth = 3000 K at 50 MHz (Hartmut, DG7YBN). ' For azimuth = 0 deg., the same max gain may be reached at elevation = - 1 deg. ' and elevation = 0 deg. and elevation = + 1 deg. for instance. Therefore it is the elevation ' equal to - 1 deg. which is displayed on screen and saved in the output file. ' This is not a bug but a fact discovered by Vladimir, UR5EAZ. ' A modification is done to display and save elevation = 0 deg. (theta = 90 deg.) for this ' special case. ' For the choice "alpha 0 - 90 degr., step 1 deg.", there were 2 spaces instead of 1 space ' in front of "Alpha (deg.)" in the corresponding title line. One space is removed. ' ' Version 3.0 ' From version 2.6. ' alpha = 90 deg. exception removed because not needed. ' Matrixes : V2. ' Error handler : case matrix file not found added. ' ' The points M, M1 and M2 are situated on a sphere the radius of which is equal to 1. ' (phi , theta ) : point M, before the rotation ; ' (phi1, theta1) : point M1, directly after a rotation of an angle alpha around OY, towards OZ ; ' (phi2, theta2) : point M2, phi2 and theta2 being a couple of integers step 1 deg., ' the arc M1M2 having the smallest possible value. ' ' Matrixes giving the relations between the pairs (phi2, theta2) and the pairs (phi, theta) ' are calculated by step1_matrix_generator_basic_V2-y.bas. ' There is one matrix per alpha value : "FFstep1_phi2_theta2_basic_**.txt" ' or "FFstep1_phi2_theta2_basic_**_Va-b.txt" where "**" is the rotation angle alpha ' in deg. (alpha <> 0, alpha = 0 being calculated by another program). ' ' The pairs (phi2, theta2) are sorted by increasing phi2 by increasing theta2 ; ' phi2 runs from 0 deg. to 360 deg. step 1 deg. ' theta2 runs from 0 deg. to 180 deg. step 1 deg. ' Then the (phi2, theta2) pairs are : ' (0, 0), (0, 1),..., (0, 180), ' (1, 0), (1, 1),..., (1, 180), ' ..., ' ..., (360, 180). ' ' Due to the sorting, the range and the step of phi2's and theta2's, the value of a pair (phi2, theta2) ' is "hidden" in an index : ' phi2 = (index - 1)\181, where the "\" stands for the euclidian division (integer division); ' theta2 = (index - 1) - phi2 * 181 ; ' "- 1" is due to the fact that the index begins at "1" (as the line numbering in Excel) ' when phi2 and theta2 begin at "0". ' ' On the other hand, index = 181 * phi2 + theta2 + 1. ' ' An index is then a simplified way to give a pair (phi2, theta2). ' ' ON ERROR GOTO error_handler ' DIM Tot_dB(65341%) AS DOUBLE ' From FF Table : 181 x 361 lines. DIM element(65341%) AS DOUBLE DIM element2(65341%) AS DOUBLE ' After the rotation. ' DIM index_phi_theta AS LONG ' Integer, up to 65,341. DIM index_phi2_theta2 AS LONG ' Rotation and Trapezoidal sums subroutines. ' DIM sum AS DOUBLE DIM sum(361%) AS DOUBLE ' For the trapezoidal sum on theta2 for a given phi2. DIM sum_sum AS DOUBLE ' For the trapezoidal sum on phi2. DIM sum_Sky(91%) AS DOUBLE ' 91 different alpha values. DIM sum_Earth(91%) AS DOUBLE ' DIM avg_gain_num AS DOUBLE ' The Average Gain computed at alpha = 0 deg. DIM avg_gain_dB AS DOUBLE ' DIM loss_dB AS DOUBLE ' The Loss computed at alpha = 0 deg. DIM loss_temperature AS DOUBLE DIM pattern_temperature(91%) AS DOUBLE ' 91 different alpha values. DIM total_temperature(91%) AS DOUBLE DIM G_on_T_dB(91%) AS DOUBLE ' format_sign1_2$ = "+#.##" format_1_3$ = "#.###" format_sign1_3$ = "+#.###" format_1_5$ = "#.#####" format_2_0$ = "##" format_sign2_2$ = "+##.##" format_sign2_3$ = "+##.###" format_2_5$ = "##.#####" format_3_0$ = "###" format_3_2$ = "###.##" format_3_3$ = "###.###" format_4_0$ = "####" format_4_2$ = "####.##" format_5_1$ = "#####.#" ' Not used. ' quote$ = CHR$(34%) ' ' ' ===> PART 1 ' Asking Sky and Earth temperature. ' CLS _TITLE "AGTC v3.06: G/T computed with pattern rotation and 91 external matrixes" _DELAY 2 ' COLOR 14 PRINT " AGTC_V3-06" COLOR 7 PRINT " Computation of G/T from Far Field Table by F5FOD with DG7YBN, vers. 3.06" PRINT ' Sky_temperature: PRINT " Enter Sky Temperature (K)"; INPUT Sky_temperature IF Sky_temperature = 0 THEN COLOR 9 PRINT " Sky Temperature (K)= 0" COLOR 7 ENDIF IF Sky_temperature < 0 THEN BEEP PRINT COLOR 12 PRINT " Sky temperature must be >= 0 K" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS GOTO Sky_temperature ENDIF ' IF Sky_temperature >= 10000 THEN BEEP PRINT COLOR 12 PRINT " Sky temperature too high ... must be < 10,000 K" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS GOTO Sky_temperature ENDIF ' Earth_temperature: PRINT " Enter Earth Temperature (K)"; INPUT Earth_temperature IF Earth_temperature = 0 THEN COLOR 9 PRINT " Earth Temperature (K)= 0" COLOR 7 ENDIF IF Earth_temperature < 0 THEN BEEP PRINT COLOR 12 PRINT " Earth temperature must be >= 0 K" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS PRINT " Sky Temperature (K):";Sky_temperature GOTO Earth_temperature ENDIF ' IF Earth_temperature >= 10000 THEN BEEP PRINT COLOR 12 PRINT " Earth temperature too high ... must be < 10,000 K" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS PRINT " Sky Temperature (K):";Sky_temperature GOTO Earth_temperature ENDIF ' PRINT ' ' ' ===> PART 2 ' Getting Tot_dB from an EZNEC style FF Table, step 1 deg. ' FF_Table_filename: PRINT " Enter FFTab's file name _ _ _ .txt"; INPUT FF_Table$ filename_length% = LEN(FF_Table$) IF filename_length% = 0% THEN BEEP PRINT COLOR 12 PRINT " You did not set any FFtab file name" 'Length of file name is null ... COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS GOTO FF_Table_filename ENDIF ' ' ' Verifying that the FF Table is really step 1 deg. CLOSE 1% 20 OPEN FF_Table$ FOR INPUT AS #1% ' Verifying if FF Table step = 1 deg. FOR I% = 1% TO 12% ' To remove the EZNEC FF Table top. LINE INPUT #1%, top$ NEXT I% LINE INPUT #1%, A$ ' To get the first phi value azimuth_0$ = LEFT$(A$,3%) azimuth_0 = VAL(azimuth_0$) LINE INPUT #1%, A$ ' To get the second phi value azimuth_1$ = LEFT$(A$,3%) azimuth_1 = VAL(azimuth_1$) IF azimuth_1 - azimuth_0 <> 1% THEN BEEP PRINT COLOR 12 PRINT " The FF Table must be of 1 deg. resolution but is not!" PRINT COLOR 9 PRINT " Please close the program window ..." COLOR 7 END ENDIF CLOSE 1% ' _TITLE "AGTC v3.06" + SPACE$(9%) +"FFTab: " + FF_Table$ _DELAY 2 ' OPEN FF_Table$ FOR INPUT AS #1% FOR I% = 1% TO 9% ' To remove the EZNEC FF Table header. LINE INPUT #1%, header$ NEXT I% ' PRINT PRINT " Extracting the 65,341 Tot_dB values from the FF Table," PRINT " looking at any possible comma and preparing" PRINT " the 65,341 elements for the double integration," PRINT " please, wait ..." Tot_dB_max = -1000 FOR theta% = 180% TO 0% STEP -1% ' The FF Table "Elevation" goes from -90 deg. to +90 deg. ' and theta = 90 - elevation. 100 LINE INPUT #1%, A$ ' To remove the empty line. 110 LINE INPUT #1%, A$ ' To remove "Azimuth ..." line. 120 LINE INPUT #1%, A$ ' To remove " Deg ..." line. FOR phi% = 0% TO 360% 130 LINE INPUT #1%, A$ Tot_dB$ = MID$(A$, 26%, 10%) ' Format: "1234567.90". mark_comma%=INSTR(Tot_dB$,",") ' Where is the possible comma ? ' IF mark_comma%=5% THEN ' 4nec2 case IF theta% = 180% AND phi% = 0% THEN ' To display the following message only once PRINT COLOR 9 PRINT " Replacing commas by dots, please wait a little more!" COLOR 7 PRINT ENDIF before$=LEFT$(Tot_dB$, 4%) ' Data before the comma after$= RIGHT$(Tot_dB$, 2%) ' Data after the comma Tot_dB$=before$+"."+after$ ' Tot_dB$ now with a dot ENDIF ' IF mark_comma%=8% THEN ' EZNEC case IF theta% = 180% AND phi% = 0% THEN PRINT COLOR 9 PRINT " Replacing commas by dots, please wait a little more!" COLOR 7 PRINT ENDIF before$=LEFT$(Tot_dB$, 7%) after$= RIGHT$(Tot_dB$, 2%) Tot_dB$=before$+"."+after$ ENDIF ' index_phi_theta = 181% * phi% + theta% + 1% ' Sort: increasing phi increasing theta. Tot_dB(index_phi_theta) = VAL(Tot_dB$) IF Tot_dB(index_phi_theta) > Tot_dB_max THEN ' Searching for Tot_dB max Tot_dB_max = Tot_dB(index_phi_theta) phi_gain_max% = phi% theta_gain_max% = theta% ENDIF ' element(index_phi_theta) = 10^(Tot_dB(index_phi_theta)/10%) * (_PI/180% * 1%)^2% ' (angles : in radians) Tot_num * d(theta) * d(phi). ' NEXT phi% NEXT theta% ' IF LEFT$(A$,3%) <> "360" THEN ' Test on the beginning of the last data line. BEEP PRINT COLOR 12 PRINT " The FF Table file is not in accordance with the right format" PRINT " (number of lines and/or content of lines)." PRINT COLOR 9 PRINT " Please close the program window ..." COLOR 7 END ENDIF ' IF Tot_dB(91%) = Tot_dB_max THEN theta_gain_max% = 90% ' If the gain at phi = 0 deg. and theta = 90 deg. (=> index = 91) ' is equal to the max gain, then 90 deg. is elected ' as the value for max gain theta to be displayed on screen and ' recorded in the output file. ' CLOSE 1% ' ' ' ===> PART 3 ' Calculating the average gain and T_loss at alpha = 0 deg. ' with Tot_dB's using the no rotation matrix (alpha = 0 deg.). ' alpha% = 0% GOSUB total_calculation sum_Sky_avg_gain = sum_Sky(alpha%) sum_Earth_avg_gain = sum_Earth(alpha%) avg_gain_num = (sum_Sky_avg_gain + sum_Earth_avg_gain)/(4% * _PI) avg_gain_dB = 10% * (LOG(avg_gain_num))/LOG(10) ' loss_dB = - avg_gain_dB loss_temperature = 290% * (1/avg_gain_num - 1%) IF avg_gain_num > 0.999 THEN loss_temperature = 0 ' For a lossless antenna ' ' ' ===> PART 4 ' Alpha choice and Calculating T_pattern, T_total and G/T. ' alpha_choice: CLS COLOR 7 ' By security ! PRINT " Alpha is antenna tilting angle in degrees." PRINT " Now enter range of alpha for computation:" PRINT SPACE$(2%);"- for alpha 0 - 90 degr., step 5 deg.: type ";quote$;"1";quote$;"," PRINT SPACE$(2%);"- for alpha 0 - 90 degr., step 1 deg.: type ";quote$;"2";quote$;"," PRINT SPACE$(2%);"- for your own alpha value range : type ";quote$;"3";quote$;"," PRINT SPACE$(2%);"- for a single alpha value : type ";quote$;"4";quote$ PRINT PRINT " Enter # =>"; INPUT choice% IF choice% <> 1% AND choice% <> 2% AND choice% <> 3% AND choice% <> 4% THEN BEEP PRINT COLOR 12 PRINT " Enter only 1, 2, 3 or 4 for your choice!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting GOTO alpha_choice ENDIF ' SELECT CASE choice% CASE 1%: alpha_save_begin% = 0% ' Will be used to save the data in the output file. alpha_save_end% = 90% alpha_save_step% = 5% CLS GOSUB on_screen_avg_max_gains COLOR 14 PRINT " Alpha (deg.)";SPACE$(2%);"T_pattern (K)";SPACE$(3%);"T_loss (K)";SPACE$(3%);"T_total (K)";SPACE$(5%);"G/T (dB)" FOR alpha% = 0% TO 90% STEP 5% GOSUB total_calculation NEXT alpha% LOCATE 25, 1 COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CASE 2%: alpha_save_begin% = 0% alpha_save_end% = 90% alpha_save_step% = 1% CLS GOSUB on_screen_avg_max_gains first_alpha% = 0% ' 19 alpha value lines max per page last_alpha% = 18% GOSUB total_range LOCATE 25,1 COLOR 9 PRINT " Press any key to continue!"; BEEP COLOR 7 GOSUB waiting ' CLS GOSUB on_screen_avg_max_gains first_alpha% = 19% last_alpha% = 37% GOSUB total_range LOCATE 25,1 COLOR 9 PRINT " Press any key to continue!"; BEEP COLOR 7 GOSUB waiting ' CLS GOSUB on_screen_avg_max_gains first_alpha% = 38% last_alpha% = 56% GOSUB total_range LOCATE 25,1 COLOR 9 PRINT " Press any key to continue!"; BEEP COLOR 7 GOSUB waiting ' CLS GOSUB on_screen_avg_max_gains first_alpha% = 57% last_alpha% = 75% GOSUB total_range LOCATE 25,1 COLOR 9 PRINT " Press any key to continue!"; BEEP COLOR 7 GOSUB waiting ' CLS GOSUB on_screen_avg_max_gains first_alpha% = 76% last_alpha% = 90% GOSUB total_range LOCATE 25, 1 COLOR 9 PRINT " Press any key to continue!"; BEEP COLOR 7 GOSUB waiting CASE 3%: choice3_first: PRINT " Your choice for the first alpha value"; INPUT first_alpha% IF first_alpha% = 0% THEN COLOR 9 PRINT " First alpha value = 0 deg." COLOR 7 PRINT GOTO choice3_last ENDIF IF first_alpha% < 0% OR first_alpha% > 89% THEN BEEP COLOR 12 PRINT " First alpha value must be contained between 0 and 89 deg. inclusively!" COLOR 7 PRINT GOTO choice3_first ENDIF PRINT choice3_last: PRINT " Your choice for the last alpha value"; INPUT last_alpha% IF last_alpha% <= first_alpha% THEN BEEP COLOR 12 PRINT " Last alpha value must be greater than the first alpha value!" COLOR 7 PRINT GOTO choice3_last ENDIF ' IF last_alpha% > 90% THEN BEEP COLOR 12 PRINT " Maximum last alpha value is equal to 90 deg.!" COLOR 7 PRINT GOTO choice3_last ENDIF ' alpha_save_begin% = first_alpha% alpha_save_end% = last_alpha% alpha_save_step% = 1% n% = 0% ' Page number - 1 page_screen: IF last_alpha% - (first_alpha% + 19% * n%) + 1% <= 19% THEN ' Here 19 alpha value lines max per page CLS GOSUB on_screen_avg_max_gains COLOR 14 PRINT " Alpha (deg.)";SPACE$(2%);"T_pattern (K)";SPACE$(3%);"T_loss (K)";SPACE$(3%);"T_total (K)";SPACE$(5%);"G/T (dB)" FOR alpha% = first_alpha% + 19% * n% TO last_alpha% GOSUB total_calculation NEXT alpha% LOCATE 25, 1 COLOR 9 PRINT " Press any key to continue!"; BEEP COLOR 7 GOSUB waiting GOTO end_select ENDIF ' CLS GOSUB on_screen_avg_max_gains COLOR 14 PRINT " Alpha (deg.)";SPACE$(2%);"T_pattern (K)";SPACE$(3%);"T_loss (K)";SPACE$(3%);"T_total (K)";SPACE$(5%);"G/T (dB)" FOR alpha% = first_alpha% + 19% * n% TO first_alpha% + (n% + 1%) * 19% - 1% GOSUB total_calculation NEXT alpha% n%= n% + 1% LOCATE 25, 1 COLOR 9 PRINT " Press any key to continue!"; BEEP COLOR 7 GOSUB waiting GOTO page_screen ' CASE 4%: choice4: PRINT " Your choice for alpha"; INPUT alpha% IF alpha% < 0% OR alpha% > 90% THEN BEEP COLOR 12 PRINT " Alpha must be between 0 to 90 degr. inclusively!" COLOR 7 PRINT GOTO choice4 ENDIF CLS alpha_save_begin% = alpha% alpha_save_end% = alpha% alpha_save_step% = 1% GOSUB on_screen_avg_max_gains COLOR 14 PRINT " Alpha (deg.)";SPACE$(2%);"T_pattern (K)";SPACE$(3%);"T_loss (K)";SPACE$(3%);"T_total (K)";SPACE$(5%);"G/T (dB)" GOSUB total_calculation LOCATE 25, 1 COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting end_select: END SELECT ' GOSUB new_alpha_choice ' SYSTEM ' By security! ' ' ############################## SUBROUTINES ############################## ' total_range: ' Alpha = 0 to 90 deg., step 1 deg. COLOR 14 PRINT " Alpha (deg.)";SPACE$(2%);"T_pattern (K)";SPACE$(3%);"T_loss (K)";SPACE$(3%);"T_total (K)";SPACE$(5%);"G/T (dB)" FOR alpha% = first_alpha% TO last_alpha% ' One page of results per screen GOSUB total_calculation NEXT alpha% ' RETURN ' ' ************************************************************************* ' on_screen_avg_max_gains: ' Average and Max gains on top of results screen. IF avg_gain_num <= 0.999 THEN COLOR 15 PRINT " Average Gain = "; USING format_1_3$; avg_gain_num; PRINT " (/) = "; PRINT USING format_sign1_2$; avg_gain_dB; PRINT " dBi" PRINT " Max Gain = "; PRINT USING format_sign2_2$; Tot_dB_max; PRINT " dBi at azimuth = "; PRINT USING format_3_0$; phi_gain_max%; PRINT " degree(s) and elevation = "; PRINT USING format_3_0$; 90% - theta_gain_max%; PRINT " degree(s)" COLOR 9 PRINT SPACE$(1%); " T_sky = "; USING format_4_2$; Sky_temperature; PRINT " K"; PRINT SPACE$(39%); PRINT " T_earth = "; USING format_4_2$; Earth_temperature; PRINT " K" COLOR 7 END IF ' IF avg_gain_num > 0.999 THEN COLOR 15 PRINT " Average Gain = "; USING format_1_3$; avg_gain_num; PRINT " (/) = "; PRINT USING format_sign1_2$; avg_gain_dB; PRINT " dBi, rounded to 1 (0 dBi)!" PRINT " Max Gain = "; PRINT USING format_sign2_2$; Tot_dB_max; PRINT " dBi at azimuth = "; PRINT USING format_3_0$; phi_gain_max%; PRINT " degree(s) and elevation = "; PRINT USING format_3_0$; 90% - theta_gain_max%; PRINT " degree(s)" COLOR 9 PRINT SPACE$(1%); " T_sky = "; USING format_4_2$; Sky_temperature; PRINT " K"; PRINT SPACE$(39%); PRINT " T_earth = "; USING format_4_2$; Earth_temperature; PRINT " K" COLOR 7 END IF ' RETURN ' ************************************************************************* ' new_alpha_choice: CLS COLOR 7 PRINT " Enter another range of alpha for computation "; COLOR 15 PRINT "(Y/N)"; COLOR 7 PRINT "?" PRINT PRINT " Enter # =>"; INPUT save_choice$ IF save_choice$ <> "Y" AND save_choice$ <> "y" AND save_choice$ <> "N" AND save_choice$ <> "n" THEN BEEP COLOR 12 PRINT " Enter only ";quote$;"Y";quote$;" or ";quote$;"N";quote$;"!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting GOTO new_alpha_choice ENDIF ' IF save_choice$ = "Y" OR save_choice$ = "y" THEN GOTO alpha_choice ' ' No new alpha choice save_or_quit: CLS COLOR 7 PRINT " Save last alpha choice results "; COLOR 15 PRINT "(Y/N)"; COLOR 7 PRINT "?" PRINT " ";quote$;"N";quote$;" will close AGTC without any results saving!" PRINT PRINT " Enter # =>"; INPUT save_choice$ IF save_choice$ <> "Y" AND save_choice$ <> "y" AND save_choice$ <> "N" AND save_choice$ <> "n" THEN BEEP COLOR 12 PRINT " Enter only ";quote$;"Y";quote$;" or ";quote$;"N";quote$;"!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting GOTO save_or_quit ENDIF ' IF save_choice$ = "Y" OR save_choice$ = "y" THEN GOSUB save_results SYSTEM ' RETURN ' ************************************************************************* ' total_calculation: ' Calculating the Tot_dB's of the rotated antenna using the rotation matrixes. IF alpha% < 10% THEN alpha$ = "0" + LTRIM$(STR$(alpha%)) ELSE alpha$ = LTRIM$(STR$(alpha%)) GOSUB rotation ' ' Calculating the double sum (trapezoidal sum on theta2 then trapezoidal sum on phi2). begin_theta2% = 0% ' For Sky zone : theta2 goes from 0 deg. to 90 deg. end_theta2% = 90% GOSUB trapezoidal_sums ' Sky. sum_Sky(alpha%) = sum_sum ' Total Sky double sum. ' begin_theta2% = 90% ' For Earth zone : theta2 goes from 90 deg. to 180 deg. end_theta2% = 180% GOSUB trapezoidal_sums ' Earth. sum_Earth(alpha%) = sum_sum ' Total Earth double sum. ' ' Computing and displaying T_pattern, T_total, G/T. pattern_temperature(alpha%) = (Sky_temperature * sum_Sky(alpha%) + Earth_temperature * sum_Earth(alpha%))/(sum_Sky(alpha%) + sum_Earth(alpha%)) total_temperature(alpha%) = (pattern_temperature(alpha%) - 290) * avg_gain_num + 290 IF avg_gain_num > 0.999 THEN total_temperature(alpha%) = pattern_temperature(alpha%) ' For a lossless antenna G_on_T_dB(alpha%) = Tot_dB_max - 10% * (LOG(total_temperature(alpha%)))/LOG(10%) ' IF ALPHA% = 30% THEN COLOR 12 PRINT SPACE$(6%); PRINT USING format_2_0$; alpha%; PRINT SPACE$(10%); PRINT USING format_4_2$; pattern_temperature(alpha%); PRINT SPACE$(7%); PRINT USING format_3_2$; loss_temperature; PRINT SPACE$(8%); PRINT USING format_4_2$; total_temperature(alpha%); PRINT SPACE$(8%); PRINT USING format_sign2_3$; G_on_T_dB(alpha%) COLOR 14 ' RETURN ' ************************************************************************* ' rotation: ' Using rotation matrixes. 200 OPEN "FFstep1_phi2_theta2_basic_" + alpha$ + "_V2-0.txt" FOR INPUT AS #1% ' The alpha value matrix. FOR index_phi2_theta2 = 1% to 65341% ' index_phi2_theta2 is the 1st column of the matrix. 210 INPUT #1%, A$ index_phi_theta$ = MID$(A$,14%,9%) ' Getting the 2nd column of the matrix. index_phi_theta = VAL(index_phi_theta$) element2(index_phi2_theta2) = element(index_phi_theta) ' The heart of the rotation ! NEXT index_phi2_theta2 CLOSE 1% ' RETURN ' ************************************************************************* ' trapezoidal_sums: FOR phi2% = 0% TO 360% ' Trapezoidal sum on theta2 for each phi2. sum = 0 FOR theta2% = begin_theta2% + 1% TO end_theta2% - 1% index_phi2_theta2 = 181% * phi2% + theta2% + 1% sum = sum + element2(index_phi2_theta2) * sin(_PI/180% * theta2%) NEXT theta2% ' index_phi2_theta2 = 181% * phi2% + begin_theta2% + 1% sum = sum + (element2(index_phi2_theta2) * sin(_PI/180% * begin_theta2%))/2% index_phi2_theta2 = 181% * phi2% + end_theta2% + 1% sum = sum + (element2(index_phi2_theta2) * sin(_PI/180% * end_theta2%))/2% sum(phi2%) = sum NEXT phi2% ' sum_sum = 0 ' Trapezoidal sum on phi2. FOR phi2% = 1% TO 359% sum_sum = sum_sum + sum(phi2%) NEXT phi2% ' sum_sum = sum_sum + (sum(0%) + sum(360%))/2% ' RETURN ' ************************************************************************* ' waiting: ' Waiting for pressing any key waiting$ = "" WHILE waiting$= "" waiting$ = INKEY$ WEND ' RETURN ' ************************************************************************* ' save_results: ' Saving the results corresponding to the last alpha choice. PRINT " Please type name of file name for saving results to" PRINT " Enter name without extension: ";quote$;".txt";quote$;" will be added." PRINT " Be careful if this file name + extension is already in use in your directory" PRINT " as it will be erased !" PRINT PRINT " Enter file name for Output"; INPUT result_filename$ ' filename_length% = LEN(result_filename$) IF filename_length% = 0% THEN BEEP PRINT COLOR 12 PRINT " You did not set any file name" 'Length of file name is null ... COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS GOTO save_results ENDIF ' FOR I% = 1% TO LEN(result_filename$) character$ = MID$(result_filename$,I%,1%) IF character$ = "." OR character$ = ":" OR character$ = "/" THEN BEEP PRINT COLOR 12 PRINT " No special characters like . : / allowed in file name!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS GOTO save_results ENDIF NEXT I% PRINT ' result_filename$ = result_filename$ + ".txt" CLOSE 2% 10 OPEN result_filename$ FOR OUTPUT AS #2% PRINT #2%, "Program name : "; PRINT #2%, "AGTC_V3-06.bas" PRINT #2%, "This output file name : "; PRINT #2%, result_filename$ PRINT #2%, "Date (mm-dd-yyyy) : "; PRINT #2%, DATE$ PRINT #2%, "Time (hh-mm-ss) : "; PRINT #2%, TIME$ PRINT #2%, ' PRINT #2%, "Sky Temperature : "; PRINT #2%, USING format_4_2$; Sky_temperature; PRINT #2%, " K" PRINT #2%, "Earth Temperature : "; PRINT #2%, USING format_4_2$; Earth_temperature; PRINT #2%, " K" PRINT #2%, ' PRINT #2%, "FF Table file name : "; PRINT #2%, FF_Table$ PRINT #2%, ' PRINT #2%, "Max Gain : "; PRINT #2%, USING format_sign2_2$; Tot_dB_max; PRINT #2%, " dBi at phi = "; PRINT #2%, USING format_3_0$; phi_gain_max%; PRINT #2%, " degree(s) and theta = "; PRINT #2%, USING format_3_0$; theta_gain_max%; PRINT #2%, " degree(s)" PRINT #2%, SPACE$(34%);"with phi = EZNEC ";quote$;"azimuth";quote$;" and theta = 90 - EZNEC ";quote$;"elevation";quote$;" (deg.)" PRINT #2%, ' IF avg_gain_num <= 0.999 THEN PRINT #2%, "Average Gain (Avg_Gain): "; USING format_1_5$; avg_gain_num; PRINT #2%, " (/) = "; PRINT #2%, USING format_sign1_3$; avg_gain_dB; PRINT #2%, " dBi" END IF IF avg_gain_num > 0.999 THEN PRINT #2%, "Average Gain (Avg_Gain): "; USING format_1_5$; avg_gain_num; PRINT #2%, " (/) = "; PRINT #2%, USING format_sign1_3$; avg_gain_dB; PRINT #2%, " dBi, rounded to 1 (0 dBi)!" END IF PRINT #2%, ' PRINT #2%, "Sky zone : "; PRINT #2%, USING format_2_5$; sum_Sky_avg_gain PRINT #2%, "Earth zone : "; PRINT #2%, USING format_2_5$; sum_Earth_avg_gain PRINT #2%, "Total zone : "; PRINT #2%, USING format_2_5$; sum_Sky_avg_gain + sum_Earth_avg_gain PRINT #2%, ' PRINT #2%, "alpha T_pattern T_loss T_tot G/T Sky Earth Total Local_Avg_Gain LAG/Avg_Gain alpha" PRINT #2%, " deg. K K K dB zone zone zone (LAG) deg." FOR alpha% = alpha_save_begin% TO alpha_save_end% STEP alpha_save_step% PRINT #2%, SPACE$(3%); PRINT #2%, USING format_2_0$; alpha%; PRINT #2%, SPACE$(4%); PRINT #2%, USING format_4_2$; pattern_temperature(alpha%); PRINT #2%, SPACE$(2%); PRINT #2%, USING format_3_2$; loss_temperature; PRINT #2%, SPACE$(1%); PRINT #2%, USING format_4_2$; total_temperature(alpha%); PRINT #2%, SPACE$(2%); PRINT #2%, USING format_sign2_3$; G_on_T_dB(alpha%); PRINT #2%, SPACE$(2%); PRINT #2%, USING format_2_5$; sum_Sky(alpha%); PRINT #2%, SPACE$(2%); PRINT #2%, USING format_2_5$; sum_Earth(alpha%); PRINT #2%, SPACE$(2%); PRINT #2%, USING format_2_5$; sum_Sky(alpha%) + sum_Earth(alpha%); PRINT #2%, SPACE$(10%); PRINT #2%, USING format_1_5$; (sum_Sky(alpha%) + sum_Earth(alpha%))/(4% * _PI); PRINT #2%, SPACE$(5%); PRINT #2%, USING format_3_3$; (((sum_Sky(alpha%) + sum_Earth(alpha%))/(4% * _PI))/avg_gain_num) * 100%; PRINT #2%, " %"; PRINT #2%, SPACE$(5%); PRINT #2%, USING format_2_0$; alpha% NEXT alpha% ' CLOSE 2% ' RETURN ' ######################################################################### ' error_handler: IF ERR = 53% AND ERL = 10% THEN ' Error when opening the output file due to ' an inappropriate character in its name. BEEP COLOR 12 PRINT " No < > ? * ";quote$;" in the file name!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS RESUME save_results ENDIF ' IF ERR = 70% AND ERL = 10% THEN ' Error when opening the output file as a file ' with the same name is already opened in another application. BEEP COLOR 12 PRINT " A file with the same name is already opened in another application!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS RESUME save_results ENDIF ' IF ERR = 76% AND ERL = 10% THEN ' Error when opening the output file due to ' its too long filename. BEEP COLOR 12 PRINT " Filename exceeds 222 characters!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS RESUME save_results ENDIF ' IF ERR = 53% AND ERL = 20% THEN ' FF Table file not found BEEP PRINT COLOR 12 PRINT " The FF Table file has not been found!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS RESUME FF_Table_filename ENDIF ' IF (ERR = 70% OR ERR = 76%) AND ERL = 20% THEN ' FF Table file not found due to wrong characters BEEP PRINT COLOR 12 PRINT " The FF Table file has not been found!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting CLS RESUME FF_Table_filename ENDIF ' IF ERR = 62% AND (ERL = 100 OR ERL = 110 OR ERL = 120 OR ERL = 130) THEN ' FF Table input past end of file. BEEP PRINT COLOR 12 PRINT " The FF Table file is not in accordance with the right format" PRINT " (number of lines and/or content of lines)." PRINT COLOR 9 PRINT " Please close the program window ..." COLOR 7 END ENDIF ' IF ERR = 53% AND ERL = 200% THEN ' Matrix file not found. BEEP PRINT COLOR 12 IF alpha% = 1% THEN PRINT " The Matrix file for alpha ="; alpha%; "degree has not been found!" IF alpha% <> 1% THEN PRINT " The Matrix file for alpha ="; alpha%; "degrees has not been found!" PRINT COLOR 9 PRINT " Please close the program window ..." COLOR 7 END ENDIF ' IF ERR = 62% AND ERL = 210% THEN ' Matrix input past end of file. BEEP PRINT COLOR 12 IF alpha% = 1% THEN PRINT " The Matrix file for alpha ="; alpha%; "degree is incomplete!" IF alpha% <> 1% THEN PRINT " The Matrix file for alpha ="; alpha%; "degrees is incomplete!" PRINT COLOR 9 PRINT " Please close the program window ..." COLOR 7 END ENDIF ' COLOR 12 PRINT "Error"; ERR; "at line";_ERRORLINE PRINT COLOR 9 PRINT " Press any key to close the windows!"; COLOR 7 GOSUB waiting SYSTEM