' Feeder from EZNEC or 4nec2 FF Table Tot_dB to 1 column text file. ' Sorting : azimuth from 0 to 360 deg., elevation from +90 to -90 deg. (= theta from 0 to 180 deg.). ' Step : 1 deg. ' ' Author: F5FOD Jean-Pierre Waymel, with the DG7YBN Hartmut Klüver's advices and suggestions. ' Date : march 2018. ' ' Program name: azel_V1-02.bas ' Version 1.02 ' 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 1.01 ' 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 ). ' ' Version 1 ' Asking for "comma" or "dot" as Tot_dB decimal mark in the output file. ' ' ' theta = 90 - elevation, in degrees. ' ' Due to the sorting, the range and the step of phi and theta, the value of a pair (phi, theta) ' is "hidden" in an index: ' phi = (index - 1)\181, where the "\" stands for the euclidian division (integer division); ' theta = (index - 1) - phi * 181; ' "- 1" is due to the fact that the index begins at "1" (as the line numbering in Excel) ' when phi and theta begin at "0". ' ' On the other hand, index = 181 * phi + theta + 1. ' ' An index is then a simplified way to give a pair (phi, theta). ' ' ON ERROR GOTO error_handler ' DIM Tot_dB$(65341) ' For FF Table: 181 x 361 lines. DIM index_phi_theta AS LONG ' Integer, up to 65,341. ' quote$ = CHR$(34%) ' _TITLE "Feeder from FFtab Tot_dB to file text" _DELAY 2 CLS ' COLOR 14 PRINT " azel_V1-02.bas" COLOR 7 PRINT " Feeder FF Tot_dB, by F5FOD with DG7YBN, vers. 1.02" PRINT PRINT " From EZNEC or 4nec2 FF Table to 1-column text file" PRINT " Sorting:" PRINT " azimuth, 0 to 360 deg. <=> phi, 0 to 360 deg." PRINT " elevation, +90 to -90 deg. <=> theta, 0 to 180 deg." PRINT " Step: 1 deg." PRINT ' ' ' ===> PART 1 ' 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 it FF Table step = 1 deg. FOR I% = 1% to 12% ' To remove the 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 ' ' Reading the FF Table. CLOSE 1% OPEN FF_Table$ FOR INPUT as #1% FOR I% = 1% to 9% ' To remove the FF Table header. LINE INPUT #1%, header$ NEXT I% ' PRINT PRINT " Extracting the 65,341 Tot_dB values from the FF Table," PRINT " please, wait ..." 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". index_phi_theta = 181% * phi% + theta% + 1% ' Sort: increasing phi increasing theta. Tot_dB$(index_phi_theta) = Tot_dB$ 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 ' CLOSE 1% ' ' ' ===> PART 2 ' Saving Tot_dB values in a file. ' save_data: CLS 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_data 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_data ENDIF NEXT I% PRINT ' result_filename$ = result_filename$ + ".txt" CLOSE 2% 10 OPEN result_filename$ FOR OUTPUT as #2% ' ' alpha_choice: CLS COLOR 7 ' By security ! PRINT " Now choose the Tot_dB decimal mark in the output file:" PRINT SPACE$(2%);"- for a dot : type ";quote$;"1";quote$ PRINT SPACE$(2%);"- for a comma: type ";quote$;"2";quote$ PRINT PRINT " Enter # =>"; INPUT choice% IF choice% <> 1% AND choice% <> 2% THEN BEEP PRINT COLOR 12 PRINT " Enter only 1 or 2 for your choice!" COLOR 7 PRINT COLOR 9 PRINT " Press any key to continue!"; COLOR 7 GOSUB waiting GOTO alpha_choice ENDIF ' EZN$ = MID$(Tot_dB$(1%), 8%, 1%) NEC$ = MID$(Tot_dB$(1%), 5%, 1%) IF EZN$ = "." OR EZN$ = "," THEN EZN% = 1% mark_in$ = EZN$ ENDIF ' IF NEC$ = "." OR NEC$ = "," THEN NEC% = 1% mark_in$ = NEC$ ENDIF ' SELECT CASE choice% CASE 1%: CLS mark_out$ = "." IF mark_in$ = mark_out$ THEN GOSUB save IF mark_in$ <> mark_out$ THEN GOSUB change CASE 2%: CLS mark_out$ = "," IF mark_in$ = mark_out$ THEN GOSUB save IF mark_in$ <> mark_out$ THEN GOSUB change END SELECT ' SYSTEM ' ' ############################## SUBROUTINES ############################## ' waiting: ' Waiting for pressing any key waiting$ = "" WHILE waiting$= "" waiting$ = INKEY$ WEND ' RETURN ' ************************************************************************* ' change: FOR index_phi_theta = 1% to 65341% IF EZN% = 1% THEN before$ = LEFT$(Tot_dB$(index_phi_theta), 7%) after$ = RIGHT$(Tot_dB$(index_phi_theta), 2%) ENDIF ' IF NEC% = 1% THEN before$ = LEFT$(Tot_dB$(index_phi_theta), 4%) after$ = RIGHT$(Tot_dB$(index_phi_theta), 2%) ENDIF ' Tot_dB$(index_phi_theta) = before$ + mark_out$ + after$ NEXT index_phi_theta ' GOSUB save ' RETURN ' ************************************************************************* ' save: PRINT " Saving and closing ..." ' FOR index_phi_theta = 1% to 65341% PRINT #2%, Tot_dB$(index_phi_theta) NEXT index_phi_theta ' CLOSE 2% ' SYSTEM ' 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_data 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_data 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_data 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 ' COLOR 12 PRINT "Error"; ERR; "at line";_ERRORLINE PRINT COLOR 9 PRINT " Press any key to close the windows!"; COLOR 7 GOSUB waiting SYSTEM