NEC-LIST:NEC2-Cocoa for MacOS X

From: Kok Chen <chen_at_email.domain.hidden>
Date: Fri, 26 Apr 2002 11:11:59 -0700

Darryl Holder wrote:

> For anyone who may be interested, I have successfully compiled NEC-4.1
> double-precision version (as a test case) on a Macintosh running Mac OS X.
> The process was (suprisingly to me) a very straightfoward use of the OS X
> Terminal command-line and the g77 compiler.
>
Hi folks,

For some time now, I have had a C version of NEC-2 (converted by F2C) in a
"work-in-progress" project written for CodeWarrior on MacOS 9.

Recently, I have converted it to use Project Builder on Mac OS X and the
Graphical User Interface has been adapted to use Cocoa (Objective-C
frameworks) and the Interface Builder.

(Project Builder and Interface Builder are completely free tools. They come
in the "Developer" CD-ROM which comes with every copy of Mac OS X that is
sold. They include the GUI constructor, called Interface Builder, the
Objetive-C and Java compilers, and C and C++ compilers, debugger, linkers,
profilers, etc.)

NEC2-Cocoa URLs
---------------

The entire NEC2-Cocoa project (7.2MB) can be downloaded from:

http://homepage.mac.com/chen/.Public/NEC2/NEC2Download.dmg

Sample screenshots:

http://homepage.mac.com/chen/.Public/NEC2/NEC2Cocoa.jpg
http://homepage.mac.com/chen/.Public/NEC2/Azimuth.jpg

NEC2-Cocoa Project
------------------

The NEC2-Cocoa project above includes the F2C generated NEC-2 code and the
F2C library routines. Those parts can be used stand-alone, and can be
included in other applications that are written in C. This version of NEC-2
was generated with double precision and NM=1800.

You will need at least Mac OS X 10.1 to build the project because it was
only at that version when C++ and Cocoa an be intermingled. NEC2-Cocoa
contains Objective-C, C++ and C code.

In addition to NEC-2 and F2C related code, the NEC2-Cocoa project includes

1) a C-like (for lack of a better name, I have been calling it the NC, or
NEC-C) interpreter, with which a model can be described in algebraic form.
The interpreter implements the common trig functions, and (this is the
work-in-progress part) built-in functions such as

   feed, line, ground, azimuthAngle, frequency, etc.

These built-in functions generate the corresponding NEC-2 Hollerith card
images.

The interpreter also include the "if-else", "while" and "for" statements,
thus allowing loops to be written.

I have so far only implemented the interpretation for some simple NEC-2
cards. Enough for my own use in experimenting with long wire and Yagi
antennas for Amateur Radio.

Adding more built-in functions is relatively easy, actually, it is just that
I don't have the need for for more complexity yet. Read further down for
how to use the "traditional Card-image mode" in the NEC2-Cocoa program,
bypassing the interpreter.

An example of an NC program is:

    model( "2 Element Yagi" )
    {
        real x, y, f, h, d, l, sep, freq ;
        
        freq = 14.1 ;
        
        frequency( freq ) ;
        goodground() ; // or freespace(), or ground( conductivity, dconst )
        elevationAngle( 22.0 ) ;
        azimuthAngle( 90.0 ) ;
        
        l = 20. ;
        
        f = 0.2 ;
        x = l * 0.257 ;
        h = 12.0 ;
        d = 0.003*sqrt(2.0) ;
        
        // driven element
        feed( -f, 0, h, f, 0, h, d ) ;
        line( -f, 0, h, -x, 0, h, d ) ;
        line( f, 0, h, x, 0, h, d ) ;
        
        // reflector
        y = x*1.022 ;
        sep = l*.14 ;
        line( -y, -sep, h, y, -sep, h, d ) ;
    }

This source is interpreted into data structures which are passed on to the
preprocessor,

2) the preprocessor applies some simple tapering rules for feedpoints and
wire junctions, and it can generate one or more NEC-2 Card images for each
built-in function that is called.

3) a postprocessor parses the NEC-2 output to extract certain parameters.

4) the postprocessed parameters are fed to methods which produce graphical
outputs, includes simple far field azimuth and elevation plots, and antenna
projective geometry diagrams.

You can basically edit the NC source, click the "Run" button and look at the
azimuth plot in the azimuth pane. Then go back to the NC source pane,
change some code or add some antenna elements, and click "Run" again. All in
rapid succession, not having to exit the application. It took a couple of
nights to write the interpreter, but in using the program, I have since
saved lots of time.

One of the panes that is the generated consists of the NEC card images. By
cutting and pasting from that pane, you can even use NEC2-Cocoa to generate
NEC-2 cards for other purposes :-).

5) in case you don't want to use the NC interpreter, the program has a mode
where straight Hollerith card images can be entered into an edit pane and
sent to NEC-2 and the postprocessor.

The choie of mode (NC or Hollerith card input) is determined by looking at
files extensions. Files with ".nec" extensions open up as NC, and files
with ".hol" extensions open as NEC-2 Hollerith cards. Note: files with
other extensions are ignored.

When starting from an empty file, the mode is selected by choosing either
the File Menu item "New NC Source" or the File Menu item "New Cards".

Screen Shots
------------

As mentioned earlier, a screen shot of the NEC2-Cocoa application window can
be seen at:

http://homepage.mac.com/chen/.Public/NEC2/NEC2Cocoa.jpg

This JPEG image above shows the "NC source" pane, displaying the NC Code for
a 4-element Yagi-Uda.

A screen shot of the "Azimuth" pane showing a far field plot for this model
can be seen at:

http://homepage.mac.com/chen/.Public/NEC2/Azimuth.jpg

Running NEC2-Cocoa
------------------

If you want to try the NEC-Cocoa application, you will need a Macintosh
running Mac OS X 10.1. This is a Cocoa application and it will not run in
MacOS 9.n or earlier systems.

Download the project from the URL mentioned earlier. It is a 8 MB disk
image that contains 7.2 MB of sources, etc.

Once NEC2Download.dmg has finished downloading, double click on it, and the
NEC2Download disk volume should show up on your desktop.

Launch the application that is in the "build" directory of this volume. You
should see an empty NEC2-Cocoa window.

Select File>Open from the Menu Bar, and navigate over to the "Models"
directory and click open the file "20m yagi.nec".

The NC Source pane should now be automatically selected and displaying the
NC source code in an editable text view (NC Source pane).

Click the Run button at the top left of the application window. The program
should now proceed to interpret the source, generate the NEC-2 cards, and
send the cards to NEC-2.

When execution is completed, the program automatically postprocess the NEC2
output. It selects the "Results" pane to show information such as Gain,
front-to-rear ratio, feedpoint impedance, NEC-2 runtime, etc.

The interpreter should generate the NEC2 cards in a blink of the eye. This
4-element Yagi-Uda example takes about 0.7 seconds to run in NEC-2 on a 400
MHz Titanium PowerBook.

The posted project is not compiled in an especially optimized fashion. This
is to facilitate debugging. It should run faster if a higher level of
optimization is requested when building the project.

Click on the different Tabs in the NEC2-Cocoa to inspect the other output
panes. The Geometry view has fields to select the viewing angle of the
antenna. Either click on the stepper arraws, or type in a viewing angle and
hit return on the keyboard.

The "NEC2 cards" pane displays the card images generated by the interpreter.

The "NEC-2 Output" pane shows the equally familiar output that NEC-2
generates (including the Fortran page-eject code :-).

The "Azimuth" pane shows the far-field azimuth plot for the elevation angle
defined in the NC source code, and the "Elevation" pane shows the elevation
gain plot at the azimuth angle defined in the NC source code.

If there is any syntax error in the NC source code, the error is displayed
in the "Listing" window when the Run button is clicked.

Go back to the "NC Source" window and change some parameter (height of the
antenna, center frequency, etc) and click "Run." You should see the output
panes change.

Using Card Images
-----------------

If you want to try NEC2-Cocoa in a more tradional way,

Select File>Open in the Menu Bar and navigate to the file "test.hol" in the
"Models" directory.

After opening the file, you should see the card images appear in the "NEC2
Cards" pane.

Click the "Run" button, and you should see results appear in the
corresponding output panes.

If you have some other NEC2 card images you wish to run, just rename the
file using a ".hol" extension and use File>Open to navigate to the file to
open it.

For the Brave
-------------

The Cocoa project itself is in "NEC2 Cocoa.pbproj". I have stripped the
objects away, otherwise the disk image would have been over 30 MB. The
first time you build it, go for a coffee or pizza. It will take a while,
since it has to compile NEC2 and the F2C library in addition to the GUI of
NEC2-Cocoa.

Play with it, and if you any questions, write to me at either chen_at_mac.com
or at aa6ty_at_arrl.net.

Final words
-----------

Anyway, the code is Freeware (in my day job, I develop imaging algorithms at
Apple, but this is not work related).

The usual disclaimers apply. Don't use this for any life critical/support
work, back up things you cannot afford to lose, #include OtherDisclaimers.h.

Regards,

Kok Chen, AA6TY

-- 
The NEC-List mailing list <nec-list_at_gweep.ca>
http://www.gweep.ca/mailman/listinfo.cgi/nec-list
Received on Sat Apr 27 2002 - 03:12:29 EDT

This archive was generated by hypermail 2.2.0 : Sat Oct 02 2010 - 00:10:42 EDT