From boyer@rd.eng.bbc.co.uk Mon Nov 15 06:29:00 1993 From: john.boyer@rd.eng.bbc.co.uk (John Boyer) Subject: Homebrew NEC post pro To: nec-list@ee.ubc.ca Date: Mon, 15 Nov 1993 14:11:49 +0000 (GMT) X-Mailer: ELM [version 2.4 PL21] Content-Type: text Content-Length: 10826 Status: RO X-Lines: 466 Here is the post pro I wrote in Quick Basic for the PC, it requires a configuration file called config.dat, which must reside in the same directory is the prog, and looks like this:- polar both HRP c:\needs\nec .out The prog should just load into quick basic and run. The config.dat file just sets where things are. I know it's not pretty, but when you have a prog that works why bother doing anything else to it. I also know that it only does polar plots, but again that's all I use. The only redeeming feature of this prog is that it is dead easy and quick to use. Hope someone finds it useful. PS Spot the hidden feature! J.B. this is the prog ' Plots patterns from NEC output files ' Ver 2.92 6/9/93 John Boyer ' boyer@rd.eng.bbc.co.uk DECLARE SUB dsplay (d, scale.f, sc.f, graph.type$, what$, cut$, ang.offset) DECLARE SUB drawsit (graph.type$, what$, cut$, path$, extn$) DECLARE SUB plotter (f$, path$, sc.f, scale.f, ang.offset, what$) DECLARE SUB freader.bas (graph.type$, what$, cut$, path$, extn$, f$) DECLARE SUB sort (lne$, graph.type$, what$, cut$) DECLARE SUB config (option$, graph.type$, what$, cuts$, path$, extn$) DECLARE SUB fmax (scale.f, graph.type$, what$, cut$, path$, extn$) DECLARE SUB dur (path$, extn$, f$) 'array for pattern data DIM SHARED values(3, 400) WHILE 2 > 1 CLS option$ = "" PRINT , "'D'isplay pattern from nec output file" PRINT , "'C'hange program defaults" PRINT , "'Quit" WHILE option$ = "" option$ = UCASE$(INKEY$) WEND SELECT CASE option$ <> "" CASE option$ = "D" drawsit graph.type$, what$, cut$, path$, extn$ CASE option$ = "C" config option$, graph.type$, what$, cut$, path$, extn$ CASE option$ = "Q" END END SELECT WEND SUB config (option$, graph.type$, what$, cut$, path$, extn$) ' FIle that holds configuration conf$ = "c:\needs\jgraps\config.dat" menu$ = "" CLS 'some options 'graph.type :- polar-lin lin-lin 'what :- vp hp both 'cut :- HRP VRP 'this bit gets existing config OPEN conf$ FOR INPUT AS #8 INPUT #8, graph.type$ INPUT #8, what$ INPUT #8, cut$ INPUT #8, path$ INPUT #8, extn$ CLOSE #8 'options menu IF option$ <> "C" THEN GOTO fin CLS PRINT , "The existing configuation is...." PRINT PRINT , "'T'race to be plotted is "; what$ PRINT , "'C'ut is "; cut$ PRINT , "'P'ath for files "; path$ PRINT , "'F'ile extension "; extn$ PRINT PRINT , "Hit key for option" WHILE menu$ = "" menu$ = UCASE$(INKEY$) WEND option$ = "" IF menu$ = "F" THEN option$ = "@" menu$ = "" INPUT "Enter new default file extension"; extn$ END IF IF menu$ = "P" THEN option$ = "@" menu$ = "" INPUT "Enter new default path"; path$ END IF CLS PRINT SELECT CASE menu$ <> "" CASE menu$ = "T" PRINT , , "'H'orizontal" PRINT , , "'V'ertical" PRINT , , "'B'oth" PRINT PRINT "Hit key for option " CASE menu$ = "C" PRINT , , "H'o'rizontal radiation pattern" PRINT , , "Ver't'ical radiation pattern" PRINT PRINT "Hit key for option " END SELECT WHILE option$ = "" option$ = UCASE$(INKEY$) WEND SELECT CASE option$ <> "" CASE option$ = "P" graph.type$ = "polar" CASE option$ = "a" graph.type$ = "lpolar" CASE option$ = "L" graph.type$ = "linear" CASE option$ = "H" what$ = "hp" CASE option$ = "V" what$ = "vp" CASE option$ = "B" what$ = "both" CASE option$ = "O" cut$ = "HRP" CASE option$ = "T" cut$ = "VRP" END SELECT 'This saves new config OPEN conf$ FOR OUTPUT AS #8 PRINT #8, graph.type$ PRINT #8, what$ PRINT #8, cut$ PRINT #8, path$ PRINT #8, extn$ CLOSE #8 fin: END SUB SUB drawsit (graph.type$, what$, cut$, path$, extn$) SHARED max, sumh, sumv 'max used for auto scaling sumh and sumv used for mean gain calculation config "", graph.type$, what$, cut$, path$, extn$ 'routine to draw pattern on screen 'go and get data from file freader.bas graph.type$, what$, cut$, path$, extn$, f$ sc.f = 1 ang.offset = 0 olx = 0 oly = 0 fmax scale.f, graph.type$, what$, cut$, path$, extn$ here: 'graphics screen mode SCREEN 12 WHILE k$ <> " " 'This bit does graticule FOR g = 1 TO 10 CIRCLE (320, 240), 200 * g / 10, 5 NEXT g FOR ang = 0 TO 350 STEP 10 a = ang * .01745 LINE (320 - SIN(a) * 20, 240 - COS(a) * 20)-(320 - SIN(a) * 200, 240 - COS(a) * 200), 5 NEXT ang 'Now to plot patterns IF what$ = "vp" THEN d = 2 ELSE d = 0 IF what$ = "hp" THEN d = 3 IF what$ = "both" THEN FOR d = 2 TO 3 dsplay d, scale.f, sc.f, graph.type$, what$, cut$, ang.offset NEXT d ELSE dsplay d, scale.f, sc.f, graph.type$, what$, cut$, ang.offset END IF 'PRINT "Any key" VIEW PRINT 29 TO 30 PRINT "Use < > keys to rotate trace. Space when done. Offset="; PRINT USING "###.#"; (ang.offset / .0174533); PRINT " degrees"; k$ = "" WHILE k$ = "" k$ = INKEY$ WEND '.08727 is 10 degrees could be made smaller IF k$ = "." OR k$ = ">" THEN ang.offset = (ang.offset + .08727) IF k$ = "<" OR k$ = "," THEN ang.offset = (ang.offset - .08727) IF k$ <> " " AND k$ <> "." AND k$ <> "," AND k$ <> "<" AND k$ <> ">" THEN k$ = " " IF k$ <> " " THEN CLS WEND PRINT "Press S to scale trace or space for next option" k$ = "" WHILE k$ = "" k$ = UCASE$(INKEY$) WEND mgv = (sumv * sc.f * sc.f / (max * max * 3.14159)) mgh = (sumh * sc.f * sc.f / (max * max * 3.14159)) IF k$ = "M" THEN PRINT "vp "; mgv, "hp "; mgh IF k$ = "M" THEN k$ = "" WHILE k$ = "" k$ = UCASE$(INKEY$) WEND IF k$ = "S" THEN s$ = "0" DO UNTIL VAL(s$) > 0 INPUT "Enter new scale factor of trace"; s$ LOOP sc.f = sc.f * VAL(s$) PRINT sc.f CLS GOTO here END IF PRINT "Press P for HPGL plot or space to end" k$ = "" WHILE k$ = "" k$ = UCASE$(INKEY$) WEND IF k$ = "P" THEN plotter f$, path$, sc.f, scale.f, ang.offset, what$ SCREEN 0 END SUB SUB dsplay (d, scale.f, sc.f, graph.type$, what$, cut$, ang.offset) SHARED ang.end, ang.step, ang.start olx = values(1, 1) * .017453 + ang.offset oly = values(d, 1) FOR a = 2 TO (ang.end - ang.start) / ang.step + 1 x = values(1, a) * .017453 + ang.offset y = values(d, a) LINE (320 + (SIN(olx) * oly * scale.f * sc.f), 240 - (COS(olx) * oly * scale.f * sc.f))-(320 + (SIN(x) * y * scale.f * sc.f), 240 - (COS(x) * y * scale.f * sc.f)), d + 12 olx = x oly = y NEXT a IF (360 - (ang.end - ang.start)) MOD 360 <= 10 THEN x = values(1, 1) * .017453 + ang.offset y = values(d, 1) LINE (320 + (SIN(olx) * oly * scale.f * sc.f), 240 - (COS(olx) * oly * scale.f * sc.f))-(320 + (SIN(x) * y * scale.f * sc.f), 240 - (COS(x) * y * scale.f * sc.f)), d + 12 END IF END SUB SUB dur (path$, ext$, f$) 'get list of files with right extn CLS it$ = path$ + "\*" + ext$ PRINT it$ FILES it$ INPUT "Enter filename "; f$ END SUB SUB fmax (scale.f, graph.type$, what$, cut$, path$, extn$) SHARED max, sumh, sumv, ang.step, ang.end PI = ATN(1) * 4 max = 0 sumh = 0 sumv = 0 ang.end = 0 ang.step = values(1, 2) - values(1, 1) FOR a = 1 TO 360 'sum areas sumv = sumv + (values(2, a) * values(2, a) * PI * ang.step / 360) sumh = sumh + (values(3, a) * values(3, a) * PI * ang.step / 360) 'look for max of either pattern IF and.end < values(1, a) THEN ang.end = values(1, a) IF max < values(2, a) THEN max = values(2, a) IF max < values(3, a) THEN max = values(3, a) NEXT a scale.f = 200 / max END SUB SUB freader.bas (graph.type$, what$, cut$, path$, extn$, f$) SHARED pointer 'read nec output file flnum = 1 pointer = 1 INPUT "Enter filename"; f$ IF f$ = "" THEN CALL dur(path$, extn$, f$) filename$ = path$ + "\" + f$ + extn$ PRINT filename$ OPEN filename$ FOR INPUT AS #flnum 'look for start of pattern data DO WHILE INSTR(LEFT$(line$, 9), "DEGREES") = 0 LINE INPUT #flnum, line$ LOOP 'get pttern data and put in array WHILE NOT EOF(flnum) LINE INPUT #flnum, line$ CALL sort(line$, graph.type$, what$, cut$) pointer = pointer + 1 ' PRINT line$ WEND CLOSE #flnum END SUB SUB plotter (f$, path$, sc.f, scale.f, ang.offset, what$) SHARED ang.start, ang.step, ang.end 'routine to plot pattern to plotter or file SCREEN 0 INPUT "Enter plot filename or Enter to plot"; ff$ filename$ = path$ + "\" + ff$ a = 1 CONST PI = 3.141592654# CONST dtor = PI / 180 CONST ninety = 90 * dtor CONST xx = 5300 CONST yy = 3800 CONST radius = 3198 'This bit plots to the file IF ff$ = "" THEN OPEN "COM1:9600, S, 7, 1, RS, CS65535, DS, CD" FOR RANDOM AS #2 IF ff$ <> "" THEN OPEN filename$ FOR OUTPUT AS #2 PRINT "Graticule y/n?" WHILE g$ = "" g$ = UCASE$(INKEY$) WEND 'Plotter initialisation" PRINT #2, "IN;SP1;PU"; xx; ","; yy; ";" PRINT "Plotting to "; filename$ 'This does graticule IF g$ = "Y" THEN FOR g = 10 TO 1 STEP -1 PRINT #2, "CI"; INT(radius * g / 10); ";" NEXT g FOR ang = 10 TO 350 STEP 20 a = ang * dtor PRINT #2, "PU;PA"; xx - (SIN(a) * radius / 10); ","; yy - (COS(a) * radius / 10); ";" PRINT #2, "PD;PA"; xx - (SIN(a) * radius); ","; yy - (COS(a) * radius); ";" a = a + 10 * dtor PRINT #2, "PU;PA"; xx - (SIN(a) * radius); ","; yy - (COS(a) * radius); ";" PRINT #2, "PD;PA"; xx - (SIN(a) * radius / 10); ","; yy - (COS(a) * radius / 10); ";" NEXT ang END IF 'plot actual radiation pattern IF what$ = "vp" THEN u = 2 ELSE u = 3 IF what$ = "hp" THEN t = 3 ELSE t = 2 FOR d = t TO u olx = values(1, 1) * dtor + ang.offset + ninety oly = values(d, 1) IF d = 3 THEN PRINT #2, "LT5;" PRINT #2, "SP2;PU"; xx + (SIN(olx) * oly * scale.f * sc.f * radius / 200); ","; yy + (COS(olx) * oly * scale.f * sc.f * radius / 200); ";" PRINT #2, "PD" FOR a = 2 TO ((ang.end - ang.start) / ang.step) + 1 x = values(1, a) * dtor + ang.offset + ninety y = values(d, a) PRINT #2, xx + (SIN(x) * y * scale.f * sc.f * radius / 200); ","; yy + (COS(x) * y * scale.f * sc.f * radius / 200); "," olx = x oly = y NEXT a IF (360 - (ang.end - ang.start)) MOD 360 <= 10 THEN x = values(1, 1) * dtor + ang.offset + ninety y = values(d, 1) PRINT #2, xx + (SIN(x) * oly * scale.f * sc.f * radius / 200); ","; yy + (COS(x) * oly * scale.f * sc.f * radius / 200); "," END IF PRINT #2, ";PU;" NEXT d CLOSE #2 PRINT "Any key." WHILE a$ = "" a$ = INKEY$ WEND 'FOR j = 1 TO 40 ' PRINT values(1, j), values(2, j), values(3, j) ' INPUT y$ 'NEXT j END SUB SUB sort (lne$, graph.type$, what$, cut$) SHARED pointer, ang.start IF lne$ = "" THEN GOTO bye IF what$ <> "log" THEN mag$ = MID$(lne$, 75, 15) mag2$ = MID$(lne$, 100, 14) END IF SELECT CASE cut$ <> "" CASE cut$ = "HRP" ang$ = MID$(lne$, 10, 8) CASE cut$ = "VRP" ang$ = MID$(lne$, 1, 9) END SELECT 'store values in array values(1, pointer) = VAL(ang$) values(2, pointer) = VAL(mag$) values(3, pointer) = VAL(mag2$) 'PRINT ang$, mag$, mag2$ 'INPUT f$ ang.start = values(1, 1) bye: END SUB