From ElecWeb

Jump to: navigation, search



The Numerical Electromagnetics Code (NEC-2) is a comprehensive package for the analysis of the electromagnetic properties of structures. It can analyse radiating properties i.e. antenna gain, as well as scattering properties (radar cross section) of structures. NEC-2 was originally written in FORTRAN.

NEC2++ is an extensive rewrite of NEC-2 in C++ by Tim Molteno. This work was helped tremendously by the work of N. Kyriazis who ported NEC-2 to C. The new portions of code are licensed under the GNU Public License (GPL).


Source code and bug reporting resources are at the Github Project Page.


Nec2++ is now part of most linux distributions. On Debian or Ubuntu, just type

 aptitude install necpp

And you will have a working copy.


To use nec2++, after installation

 nec2++ [-i input-file-name] [-o output-file-name]
      -g: print maximum gain to stdout.
      -b: Perform NEC++ Benchmark.
      -s: print results to standard output.
      -c: print results in comma-separated-value (CSV) format,
          this options is used in conjunction with (-s) above.
      -h: print this usage information and exit.
      -v: print nec2++ version number and exit.

The output file name is optional. If it is not specified, a file will be created in the same directory as the input file and with an extension .out.

Compilation on Linux/Unix

Getting the latest version

Get a local copy of the nec2++ source code from

cvs -d login
cvs -d checkout necpp 

Now go into the necpp directory

cd necpp
make -f Makefile.cvs
./configure --without-lapack
make install


If you have some LAPACK libraries installed, nec2++ can use them, and will run several times faster!

Compilation on Windows

Decompress the Windows Code Distribution, and build the Visual Studio project inside the win32 subdirectory

Using cross-compilation

To install mingw on debian simply issue the command:

aptitude install mingw32

The makefile.dist has a target for doing the following commands.

./configure --host=i586-mingw32msvc --build=i386-linux CXXFLAGS="\
   -O3 -mtune=athlon-xp -march=pentium -Dnec_build_date='\"${BUILD_DATE}\"' \
   -Dbuild_version='\"${VERSION}\"' " --prefix=/tmp/necpp_w32
 mv /tmp/necpp_w32/bin/nec2++.exe .
 zip nec2++.exe


Building using Autoconf

To build libnecpp, and use NEC from a C API, you need to use autoconf and friends -- to install these on Debian linux, simply type

  apt-get install automake libtool

To build the library, download the autoconf distribution [1 MB] and issue the following commands:

 tar -zxf necpp-1.2.3.tar.gz
 cd necpp-1.2.3
 make install

Nec2++ now uses LAPACK for its matrix operations.