Using NEC-4 with cocoaNEC

Kok Chen, W7AY [w7ay (at) arrl (dot) net]
Last updated: May 25, 2012

Primary differences between NEC Engines

cocoaNEC 2.0 comes with an embedded NEC-2 engine. NEC-2 is sufficiently accurate for many antenna modeling purposes, but does not work for buried wires or models with wires that are close to ground. The embedded NEC-2 engine is significantly faster than NEC-4.

NEC-3, and the current NEC-4 program which superseeds NEC-3, allows buried wires and wires close to ground to be modeled correctly. NEC-4 further allows electrically small antennas to be modeled with better accuracy.

NEC 4.2 improves upon NEC 4.1 by providing a better Sommerfeld ground model. NEC-4.2 is also no longer limited by the size of memory that is allocated at compile time; memory is expanded as the antenna model grows in size. In addition to voltage sources, NEC-4.2 now allows current sources to be specified (this function has already been provided by cocoaNEC).


The NEC-4 program is licensed by the Lawrence Livermore National Laboratory (LLNL) and is under United States export control. Please refer to the LLNL web page here for information on how to obtain NEC-4.

Because of the export control, there is no other way for an individual to obtain NEC-4 other than going through the process described in the aforementioned web page. To use NEC-4 with cocoaNEC, you will have to be personally licensed by the Lawrence Livermore Lab.

The current NEC-4 version is NEC-4.2.

As of May 2012, the documentation still mentions that NEC-4.2 should be considered as beta software. If you have a license for NEC-4 on record at the LLNL, you can contact Jerry Burke for a copy of NEC-4.2. Both NEC-4.1 and NEC-4.2 are present in the current distribution CD-ROM.

NEC-4 is not available as a prebuilt program for Unix based operating systems. You have to build your own Unix executable binary from the sources that are in the CD-ROMs. Please refer to the NEC-4.1 and NEC-4.2 pages for instructions on how to build the executables which run on Mac OS X.

cocoaNEC assumes that the Unix executable for NEC-4.1 is saved in the /Applications folder as a file named nec4d and the executable for NEC-4.2 is saved in the /Applications folder as a file named nec4d42.

Selecting a NEC Engine

To select NEC-4.1 or NEC-4.2 as the compute engine, open the Preferences panel (Preferences menu item in the cocoaNEC menu in the main menu bar) and choose "NEC-4.1 (external)" or "NEC-4.2 (external)" as shown below:


Once selected, the NEC Engine setting will be saved to your cocoaNEC plist (preference list) file when you exit cocoaNEC. The next time you launch cocoaNEC, you will be using the same engine that you had previously selected.

As with the case of the built-in NEC-2 engine (nec2c), cocoaNEC first generates a card deck file from either an NC program or a spreadsheet.

When NEC-4.1 (or NEC-4.2) is selected as the compute engine, cocoaNEC runs nec4d (or nec4d42) as a MacOS X task. cocoaNEC sends NEC-4 the names of the card deck file and the name of the file that NEC-4 writes its output to. cocoaNEC waits for the task to finish execution, it then proceeds to parse the NEC-4 output into the familiar graphical views in the cocoaNEC output window.

The Use GN2 checkbox lets you choose the old Sommerfeld ground model instead of the newer GN3 in NEC-4.2 when you ask for the Sommerfeld ground approximation.

One difference that you will notice when using NEC-4 is that the MacOS X Activity Monitor will show an extra process which runs for the duration that NEC engine is running (e.g., while the circular progress indicator that is next to the NC window's Run button is active).

You can dynamically select between using the nec2c engine and a NEC-4 engine. The same model that is run under nec2c and under NEC-4 will appear as separate contexts in the output window. This allows you to compare the outputs from NEC-2 and NEC-4.

The output of the model that is produced using the NEC-4 engine will appear as a context whose name has "(NEC-4.1)" or "(NEC-4.1)" appended to it, as shown below:


The summary view of the output window will also indicate the engine you have selected for the run:


Building the NEC-4 Unix Executable

Please continue to the following sections for instructions on how to build the Mac OS X Unix executables for NEC-4.1 and NEC-4.2 . If you don't already have the gfortran compiler installed on your computer, please follow the instructions in the following gfortran page. gfortran does not come with Mac OS X.