cocoaNEC 2.0
Kok Chen, W7AY
[w7ay (at) arrl (dot) net]
Last updated: Sept 25, 2009
What has changed in v0.62 ?
(September 25, 2009)
- v0.62 of cocoaNEC 2.0 turns on the Average Power Gain computation
whenever a 3D Radiation Pattern is generated.
The Average Power Gain is the gain of the modeled antenna relative to an isotropic antenna, averaged over the 4π steradian sphere. For an ideal lossless antenna, this value is 1.0, and the gain number is often used as one of the criteria to check for convergence (usually called the Average Gain Test, or AGT in the literature) of the model (e.g., whether wires are cut into sufficient segments, corners of loops are well formed, etc). Any model whose average gain is within about 0.2 dB of unity gain can be considered a reasonable model. Please note that the inclusion of any lossy elements in the model will render the average gain number meaningless for converence testing purpose.
When the 3D radiation plot is not disabled (see the notes for v0.61 below), the Average Gain is reported in the Summary tab of the Output Window, as shown in the figure below:
- Additionally, averageGain is now available
as a model variable (similar to the maxGain
model variable) that can be referenced from inside of an
NC control function. This allows you to change the number
of wire segments, etc under programmed control instead of
manually adjusting them for convergence.
- The bundle name for cocoaNEC 2.0 has been changed
from w7ay.cocoaNEC 2.0 to
w7ay.cocoaNEC-2.0. This will change the name of
the preference (plist) file for cocoaNEC. The only
preference currently is the choice between using NEC-2 or
NEC-4, so this is the only thing that you would need to
change if you are defaulting cocoaNEC to using NEC-4.
The change is made so that cocoaNEC files (NC or spreadsheet models) can comply with the Snow Leopard sole scheme to connect a file with an application. Mac OS X 10.6 no longer uses the Resource Signature to distinguish between application.
What has changed in v0.61 ?
(September 19, 2009)
v0.61 of cocoaNEC 2.0 is a performance release. No new function has been added.
- Only one RP card is now generated for the 3D
radiation pattern in models that call for multiple
frequency sweeps.
- An Options Menu is added to suppress the generation
of all 3D RP cards. The will further reduce the
time used by the NEC-2 engine, in the case where the 3D
radiation pattern is not going to be viewed.

- The v0.61 checkpoint is released as two installers in
the Download page. One version is
compatible with Mac OS X 10.4 (Tiger), MacOS 10.5
(Leopard) and Mac OS X 10.6 (Snow Leopard). The second
version can only be used in Snow Leopard. The Snow
Leopard (SL) version can be identified by opening the
About cocoaNEC 2.0 panel:

The Snow Leopard version includes optimizations in the NEC-2 engine to take advantage of the Grand Central Dispatch (GCD) support even when the antenna is modeled only at one frequency. GCD was introduced in Mac OS X 10.6.0. Some of the NEC-2 engine code can now run concurrently in multiple cores of the Macintosh. Except for the Core Solo model (early 2006) of the Mac Mini, all Intel based Macintoshes have at least two cores. The current MacPros have four or eight cores, all other current Macinoshes have 2 cores.
The blue bars are times for a PowerBook that has a single 1.5 GHz G4 PowerPC processor, running Mac OS X 10.5.8 Leopard. The green bars are times for the oldest Intel computer that Apple had shipped, a 1.83 Core Duo based MacBook Pro, running Snow Leopard Mac OS X 10.6.1. The red bars are times for the current stock (2.26 GHz) 8-core MacPro, also running Snow Leopard MacOS X 10.6.1..
The antenna model is a KLM 40M4, swept through seven different frequencies. 92 GW cards are created by the model.

Note that the Snow Leopard version of v0.61 (with some code rewritten for Grand Central Dispatch in Snow Leopard) runs faster than the non-SL version. If you are using Snow Leopard, please download the SL version. The 2-core (Intel Yonah Core Duo processor) machine's compute time shrunk by a factor of 1.5, from 4.6 seconds to 3 seconds (and compared to 13 seconds for v0.60). The 8-core (Intel Nehalem processors) machine improved even more (understandably, since Grand Central Dispatch has more cores to distribute the computation), shrinking by a factor of 2.5, from 2.1 seconds to 0.84 seconds, (and compared to 9 seconds with v0.60).
What has changed in v0.60 ?
(September 8, 2009)
- Fixed a string overflow bug in the SWRView that could cause unpredicatable crashes when large SWR is encountered.
What has changed in v0.59 ?
(September 4, 2009)
- Allow Spreadsheet variables to access the spreadsheet constants (c_pi, c_frequency, etc)
What has changed in v0.58 ?
(September 3, 2009)
- Fixed a bug where the Spreadsheet interface was
rounding loading parameters that are less than 0.000001
up to 0.000001.
What has changed in v0.57 ?
(August 18, 2009)
The following bugs are fixed:
- The NC parser for scientific notation constants was
scanning an extra character past the constant itself,
requiring an extra space following the number in the NC
source. Since the Spreadsheet interface now uses NC as
the intermediate "language," constants that are expressed
in scientific notion was breaking.
- The spreadsheet global variables, g_pi, g_frequency,
g_dielectric, etc, were not included into the NC source,
causing a spreadsheet model to fail if these variables
are used.
What has changed in v0.56 ?
(August 11, 2009)
The following bugs are fixed:
- Returning a variable from an NC user function used to
cause all the code between the statement where the
variable is defined up to the return statement itself to
be ignored.
- Placing an excitation on an NC taperedWire could
cause the EX card to reference a non-existant segment.
The excitation should now be placed in the center segment
of a tapered wire.
What has changed in v0.55 ?
(June 21, 2009)
- You can now quickly check if your copy of cocoaNEC is up to date. Please note that you have to manually check for updates. cocoaNEC will not pester you by itself. When directed to do so with the Check for Updates menu item, it will check the running version of cocoaNEC against a web file.

- NC now includes the following calls.
arc_
helix_
wire_
patch_
rectangularPatch_
triangularPatch_
quadPatch_
multiplePatch_
voltageFeedAtSegment
currentFeedAtSegment
networkAtSegments
transmissionLineAtSegments
seriesLoadsAtSegments
parallelLoadsAtSegments
impedanceAtSegments
conductivityAtSegments
These calls are added to support the new way that the Spreadsheet method works, but these NC calls can be used by any NC programs (for example to generate arcs or helices). The new geometry calls include the ability to generate GM cards for each Geometry element.
The voltageFeedAtSegment and currentFeedAtSegment allow you to feed a wire, arc or helix not just at the center segment but at any segment. networkAtSegments and transmissionLineAtSegments also allow you to connect geometry elements at points that are not their centers.
Similarly, seriesLoadsAtSegments, parallelLoadsAtSegments and impedanceAtSegments allow you to insert series or parallel lumped RLC or R+iX element in any range of segments of a geometry element instead of only at the center segment. conductivityAtSegments allows you to specify conductivity for a range of segments instead of being applied to all segments of a wire when you use the conductivity call.
You can now directly generate arbitrary surface patches, rectangular patches, triangular patches, quadrilateral patches and multiple patches from NC.
Please check NCFunctions page for details.
- In prior versions of cocoaNEC, the Spreadsheet and NC
methods had used independent mechanisms to generate a
NEC-2 card deck. From version 0.55 onwards, a Spreadsheet
model no longer generates a card deck. Instead, the
Spreadsheet generates an NC program, and the NC program
is executed to produce the actual card images. This
reduces the amount of code that I need to maintain.
If you have an existing Spreadsheet model that had worked under version 0.54 but no longer works under version 0.55, please revert the application back to v0.54, which is still available in the Download page, and please drop me an e-mail. - Each Spreadsheet row now includes a "transform"
column. When the transform cell is empty, the
row behaves as before. However, when a transform variable
is included, it is associated with a NEC-2 "GM" card.
This allows a geometry element to be rotated or
translated. Multiple geometry elements can share the same
transform variable.
Just as with ordinary variables and network and transmission line elements, the transform variables are defined in its own drop down sheet.
- The spreadsheet interface now has a Show Cards
button. This can be used to inspect the card deck or NC
program from a failed run.
- More examples have been added to the examples folder. New files include
simple spreadsheet models for an arc and a helix, and
an NC model of a Log Periodic Dipole Array by Doug,
K4DSP that is defined with recursive function calls.
What has changed in v0.54 ?
(June 9, 2009)
-
The NC
interpreter now supports arrays
of
int,
real,
element,
vector or
transform data types.
model ( "array example" )
{
vector u, v ;
transform t[2] ;
element e[2] ;
t[0] = translate( 0, 0, 10 ) ;
t[1] = translate( 4, 0, 0 ) * t[0] ;
e[0] = wirev( t[0], u, v, #14, 21 ) ;
e[1] = wirev( t[1], u, v, #14, 21 ) ;
feed( e, 1 ) ;
}
void feed( element *ele, int index )
{}
voltageFeed( ele[index], 1.0, 0.0 ) ;
As seen above, you can also pass arrays to a function. For details, see Arrays in the NC User's Manual.
What has changed in v0.53 ?
(June 4, 2009)
-
The NC
interpreter now supports vectors
and
coordinate transforms.
model ( "vectors" )
{
vector u, v, d ;
transform t ;
real height ;
u = vect( 0, -5, 0 ) ;
d = vect( 0, 10, 0 ) ;
v = u + d ;
t = translate( 0,0, height ) * rotateZ( 20.0 ) ;
wirev( t, u, v, #14, 21 ) ;
}
For details, see Vectors and Transforms in the NC User's Manual. Coordinates (x, y and z) of vectors can be extracted, allowing vector arithmetic (together with transforms) to be used as parameters for the Card Deck functions that were introduced in cocoaNEC 2.0 v0.52. This allows the creation of NEC-2 card decks whose geometry elements are individually transformed.
- Three new geometry functions are added: wirev,
taperedWirev and linev. These are vector versions of
their scalar counterparts. In addition to using the
vector notation, these functions have a transform
parameter that transforms (e.g., rotate and
translate, shown above) the vectors before creating
the geometry.
- Pre-increment (++v) and pre-decrement (--v)
operators on scalar (int and real) variables have
been added to NC.
What has changed in v0.52 ?
(May 29, 2009)
-
The NC
interpreter now supports user defined functions.
For example:
model ( "stacked dipoles" )
{
currentFeed( dipole( 60' ), 1.0, 0.0 ) ;
currentFeed( dipole( 50' ), -1.3, 0.0 ) ;
currentFeed( dipole( 40' ), 1.0, 0.0 ) ;
}
element dipole ( real height )
{
return wire( 0, -5.2, height, 0, 5.2, height, #14, 21 ) ;
}
The user defined functions can return void (nothing, as in a subroutine), an int value, a real value, or an element (as in the case above). The function arguments (which can be empty) has to be an int, real or element. For details, check the User Functions page in the NC User's Manual.
-
NC now
allows you to mix NEC-2 geometry cards with the NC
intrinsics. This lets you use functions, such as
surface patches, that are not directly implementd
in NC. For example:
model ( "example of surface patch" )
{
voltageFeed( wire( 0, 5.2, 4, 0, -5.2, 4, #14, 3 ), 1, 0 ) ;
spCard( 0, 0, 0, -0.7, 90, 0, 120.0 ) ; // add an SP card
}
For details, check the Card Functions page in the NC User's Manual.
- NC now includes three new keywords, void,
float and return.
float
can be used
interchangeably with real.
- The NC compiler now accepts an #include directive
to include other text (e.g., a file with functions)
into the NC source. For example:
#include "~/Desktop/helix.nc"
The pathname must be an absolute path, but can include the ~ character. The included file should not itself contain a #include directive.
What has changed in v0.51 ?
(February 17, 2009)
- Added the following functions to NC.
incidentPlaneWave( element, theta, phi, eta ) ;
rightPolarizedIncidentPlaneWave( element, theta, phi, eta ) ;
leftPolarizedIncidentPlaneWave( element, theta, phi, eta ) ;
These generate the corresponding NEC-2 EX cards. Many thanks to Rick Chapman, WA3LHN for pointing out that these are useful for obtaining Radar Cross Sections. - Included NC taperedWire bug fixes from Bill K1GQ.
- A frequency specification that exceeded 1 GHz in a Spreadsheet model had generated a card deck that although NEC-2 can read, nec2c could not. This is now fixed. Thanks to Loren WA6LMZ for reporting the problem.
What has changed in v0.50 ?
(November 13, 2008)
The modulus (%) function was missing in the NC implementation. Thanks to David Johnson for reporting this.
What has changed in v0.49 ?
(October 9, 2008)
Fixed bug where a Spreadsheet model (.nec) file did not update the Free Space environment menu correctly (missing the needed free space flag).
What has changed in v0.48 ?
- CrossedTransmissionLine function in NC was not negating the impedance of the transmission line.
- each wire in NC could only connect to one transmission line. You can now connect multiple transmission lines to the same wire segment.
What has changed in v0.47 ?
- Applied NEC-2 extended thin wire approximation bug fixes to the nec2c library in cocoaNEC. This should not have affected anyone before, unless you are using surface patches from the card deck interface.
- The NEC-4 task is now run from the same directory the source file (NC, Spreadsheet or Hollerith card deck) resides in. NEC-4 generates auxiliary files (SOMD.NEC and NGFD.NEC) when the Sommerfeld/Norton ground model and Numerical Green Function are used. These auxiliary files should now be created in the folder the source file is in.
What has changed in v0.46 ?
- cocoaNEC can now use NEC-4 as the compute engine.
Unlike NEC-2, which is embedded into cocoaNEC, NEC-4 from the Lawrence Livermore National Lab (LLNL) comes with U. S. export restrictions and controls. As such, you will have to personally obtain a licensed copy from LLNL, and for the MacOS X operating system, you will also have to create your own Unix executable on your own computer since the distribution CD-ROM does not (currently) contain binaries that runs on MacOS X.
You can get the instructions for how to obtain NEC-4 and how to build a Unix executable from the NEC-4 sources here, or you can use the NEC-4 tab at the top of this page.
Once you have placed a Unix executable called nec4d in the /Applications folder, you can proceed to use NEC-4 as the compute engine by opening the cocoaNEC Preferences (open the Preference panel from the cocoaNEC menu in the Main menu bar) and selecting NEC-4 as the compute engine.
- feed point of the Reference model now appear in the SWR view.
When you choose a "Use as reference" or "Use Previous Run As Previous Run" in the Output menu (in the main menu bar), the reference (or previous) feedpoint(s) now appear in the SWR view as a gray circle.
- Implemented tapered wires in NC.
You can now generate a multi-segment wire whose segment lengths are tapered from one end of the wire to the second end of the wire. Se details here
http://homepage.mac.com/chen/w7ay/Manuals/cocoaNEC/RefManual3/RefManual3/NCFunctions.html
http://homepage.mac.com/chen/w7ay/Manuals/cocoaNEC/RefManual3/RefManual3/language.html
- arcsin/arccos implemented in NC.
NC's math library was missing arcsin, arccos, arcsind and arccosd. There are now implemented.
- repeated radials in NC loops fixed.
When an NC model is repeated called from a control block, radials are accumulated. This is now fixed -- the radials are first cleared at the start of a control block.
- temporary file extension changed to .dat
The card deck file name in the /tmp directory now use the .dat extension instead of the .txt extension.
What has changed in v0.45 ?
- You can now open the cocoaNEC web documentation in the default web browser from a Documentation menu in the main menu of occoaNEC:
- The Geometry view of the Output window has four new features. There is now a Scaled Magnitude item in the Current menu, which expands the current scale to better show low segment currents.
- the Geometry view can now be scaled. A slider at the top left of the view magnifies the structure geometry from the original 1x continuously up to a scale factor of 16x. You can also "pan" the drawing up and down and left to right by holding down the mouse and dragging the cursor while the mouse button is held down. While the mouse is held down inside the Geometry view, the cursor turns from an arrow to an open hand.
When the Geometry view is panned, a re-center button will appear and you can reset the panning action with the button:
- Loads (impedance, RLC) are now indicated in the Geometry view with a small cross.
- Single segment wires were not drawn into the Geometry view, They should now be drawn.
- A warning alert is now issued before closing an NC window that has unsaved changes.
- Implemented auto-tabbing in the NC window. Whenever a newline is typed, the beginning spaces and tabs of the previous line are automatically inserted to the start of the new line of the NC window.
- v0.45 fixes a precedence bug in the division and modulus (%) functions in NC. a/b/c used to be evaluated as a/(b/c). It is correctly evaluated now as (a/b)/c.
- Output data files ("line printer output") that are generated by NEC-4 can now be directly read and and displayed in cocoaNEC's Output window. Like regular NEC-2 outputs from the embedded NEC-2 engine in cocoaNEC, the NEC-4 output instances that are read in can be used as the reference antenna:
What has changed in v0.44 ?
- Moved the setQuadPrecision function of NC to the global context. Before this, setQuadPrecision could only be set from the control block in NC.
- Added a line function to NC. This is the same as a wire function, except that cocoaNEC turns the number of segments of the wire function into an odd number to facilitate center feeding of the wire. With the line function, the number of segments is explicitly obeyed.
- Added a new Scaled Magnitude option in the Geometry view to change the colors for the currents in the wires so that variations in low currents will show up better.
- Fixed a reentrancy bug in the NEC-2 core for the Sommerfeld-Norton approximation. The nec2c engine that cococNEC uses was written as a stand-alone program to be run once before needing to be relaunched. For cocoaNEC, I had adapted nec2c into a library that is called each time a new model run is requested. It turns out that nec2c has a subroutine which was not reentrant when the Sommerfeld approximation is selected. Many thanks to Bill, K1GQ for pin-pointing the source of the problem. Please note that this is purely my fault and not the fault of the nec2c engine, which was not intended to be used in a reentrant manner in the first place.
- Added a cache for the Sommerfeld-Norton calculations. The results of up to 16 ground parameters and frequencies are cached so that if you reuse them (e.g., when you only change the antenna structure geometry), the Sommerfeld-Norton coefficients need not be recomputed.
What has changed in v0.43 ?
Fixed printing problem from Summary View. cocoaNEC was sending multiple copies (one for each subview) to the printer.
What has changed in v0.42 ?
Added a new function called addFrequency() to NC.
The behavior of the old setFrequency() has changed. It used to be setFrequency() will keep adding more frequencies (for a multi-frequency plot). setFreqency() has changed so that when you call it, all previous frequencies are removed first and only a single frequency is set. Use addFrequency() to add more frequencies.
This allows you to have finer control of the frequencies in between optimization phases.
What has changed in v0.41 ?
Fixed more formatting bugs (this time for NC models).
Fixed bug where one of the frequencies in a multifrequency set for the spreadsheet interface was not being recovered from a saved file.
Puts out a warning dialog when an NC model contains no excitation.
Fixed caption position in the SWR view (common with NC and spreadsheet).
Removed the minimum-of-3-segment restriction for wires. Instead, you are warned when placing an excitation or load on a 1 segment wire. Unloaded 1 segment wires are now passed on to the NEC-2 engine as a single segment.
Instead of having to manually convert a Windows terminated card deck to a Unix terminated card deck, cocoaNEC can now read the Windows text files directly.
The nec2c engine crashes when a NEC-4 "End geometry" card is seen when importing a Card Deck. All such imported cards are now converted to the NEC-2 style cards.
Added the option to include RP card to a Card Deck to generate the cocoaNEC 3D radiation plots.
Added a page where all NC functions are listed in one place at
http://homepage.mac.com/chen/w7ay/Manuals/cocoaNEC/RefManual3/RefManual3/NCFunctions.html
Many thanks to Lou, KC0ZMO for sending in some of the code fixes.
What has changed in v0.40 ?
Fixed formatting bug for series and parallel RLC loads for spreadsheet models.
What has changed in v0.39 ?
Corrected antenna directivity figure for antennas over real ground to be relative to the average radiation over 4.pi steradians rather than 2.pi steradians.
What has changed in v0.38 ?
You can now open an .nc or .nec file by double clicking on it.
(The first time you do this, the system might ask you to choose the Application. Select cocoaNEC. You can also set it with GetInfo in the Finder. )
Once the file types has been registered (it might take a reboot of the Mac to see it), the .nec and .nc files will also take on custom icons.
v0.41 Dec 8, 2007
Allow windows line ending for card deck.
Converted NEC-4 GE format to NEC-2 GE format.
Added 3D RP generation for Hollerith decks.
Rearrange card decks so that EX follows an FR card.
Removed 3-segment restriction to wires, and added a warning instead.
Spreadsheet frequency set not completely correct (4-th frequency not restored)
Fixed more format values for numbers smaller than 10e-9 in NC model.
Don't send NC models with missing excitation to NEC-2.
Caption position in SWR view.
v0.40 Nov 26, 2007
Fixed format values for numbers smaller than 10e-9 in Spreadsheet model
v 0.39 Nov, 12, 2007
Directivity computed over 4 pi steradians.
v 0.38 Nov 5, 2007
Double click on nc and nec files.
v 0.37 Nov 2, 2007
Removed extraneous threads.
v 0.36 Oct 29, 2007
Clean up threads and memory leaks
Use period for decimals in Environment panels for European systems
v 0.35 Oct 27, 2007
fixed NC symbol table bug in Leopard (Mac OS X 10.5)
v 0.34 Oct 24, 2007
beta release
Alpha Release History
v 0.34 Oct 24, 2007
clean up for beta
v 0.33 Oct 23, 2007
prettied up printing
v 0.32 Oct 22, 2007
Added power to plot and auto contrast.
v 0.31 Oct 22, 2007
Added vertical and horizontal polarization to 3d plot.
v 0.30 Oct 21, 2007
Added 3D plot.
v 0.29 Oct 18, 2007
Added efficiency variable to NC.
v 0.28 Oct 17, 2007
Print composite summary view.
Fixed multiple current source bug in Geometry View.
Fixed NC to emit NT cards for current sources before any EX cards.
Fixed Spreadsheet to emit NT cards for current sources before any EX cards.
v 0.27 Oct 14, 2007
Added plots to output summary
v 0.26 Oct 13, 2007
Lock an NC run when previous run still active.
abs() and fabs() in NC
fixed freespace bug in NC
v 0.25 Oct 12, 2007
changed GE 1 to GE -1 for non free space case
repeat statement
extened thin wire kernels for Spreadsheet and NC
run NC on separate thread
added "stop" button, pause() to NC
added NEC-2 grounds to Spreadsheet
v 0.24 Oct 6, 2007
if-then-else and while-break statements in NC.
necRadials
v 0.23 Oct 3, 2007
NC Network and Transmission lines.
Make NC window the active window after a Command-G.
"Use Previous Run As Reference"
Removed small current segments in spreadsheet when current source is removed.
Added directivity to plots
v 0.22 Sept 27, 2007
Fixed bug where source of hollerith deck was from fixed directory.
Fixed bug with Azimuth pattern (elevation angle was also changing)
Implemented NC
v 0.21 Sept 13, 2007
Fixed current source release bug.
Fixed bug with radials values overflowing float format
v 0.20 Sept 12, 2007
Removed angle menu, sind() for sin of degrees, etc, added pi and C constants
Added current source.
Added Sommerfeld ground.
Added Radial and option to draw it.
v 0.19 Sep 9, 2007
Fixed cosine bug.
v 0.18 Sep 9, 2007
Work around nec2c bug with single segment wires. Changed 1 segment wires to have 3 segments.
Warn when there is no excitation or no wire.
Menu selection to view spreadsheet as formula.
v 0.17 Sept 8, 2007
Disable File menu states that are not currently for hollerith/spreadsheet.
Implemented frequency sweeps.
v 0.16 Sep 7, 2007
Allow removal of all output contexts.
v 0.15 Sep 6, 2007
Geometry and Currents.
Element Inspector menu and keyboard shortcut.
v 0.14 Sep 2, 2007
Implemented free space and perfect grounds.
Added fresh and salt water grounds.
Move aux windows to sheets.
v 0.13 Aug 31, 2007
Implemented reference Antenna
Tabbing in spreadsheet from Cell Editor (formulaBar)
v 0.12 Aug 31, 2007
Moved Run Model to a new Model Menu.
Fixed bug where Environment dictionary was not updated when a new model is loaded.
v 0.11 Aug 30, 2007
Added Run Model and Command R to File Menu
Added more fixes to avoid using 10 column floating point fields (bug in nec2c.rxq)
Added missing RP card for directivity
v 0.10 Aug 30 2007
Initial alpha release.
Started: Aug 1 2007
Rewrite of original cocoaNEC program, replacing NC with a spreadsheet user interface.
-
The NC
interpreter now supports vectors
and
coordinate transforms.