Building NEC-4.2
Kok Chen, W7AY [w7ay (at) arrl (dot) net]
Last updated: May 25, 2012
Building the NEC-4.2
Unix Executable
The CD-ROM from the Lawrence Livermore National Laboratory
contains two folders, NEC41 for NEC-4.1 files and NEC42 for
NEC-4.2 files.
Follow these steps to build an executable named nec2d42.
Please note that some gfortran
commands can run for many seconds and even minutes. Be
patient and wait for the Unix prompt before proceeding to
the next command.
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.
- Create a folder on your Desktop called nec4,
and drag copy the files in /NEC42/NEC42_Source from the
CD-ROM into this new folder.
- Create a folder on your Desktop called
oldnec, and drag copy the file /NEC41/NEC_4_TAR
from the CD-ROM into this new folder.
- Make the following changes to the file Nec4d42.f in
the nec4 folder using a text editor.
The subroutine GETIOF in NEC-4.2 is written for an Intel FORTRAN compiler to run on the Windows operating system. You have to replace GETIOF with the GETIOF routine from the NEC-4.1 sources.
Launch Terminal.app and expand the NEC_4_TAR archive file in the oldnec folder that you have created above (don't forget to type a carriage return after each Unix command):
- cd
~/Desktop/oldnec
- tar xvf
NEC4_TAR
The tar command extracts three folders from the archive into the oldnec folder.
- Navigate into the nec4dst folder that
was created inside the oldnec folder, and
open the nec4d.f file within it with a text editor.
Find the subroutine GETIOF in the nec4d.f file.
Copy the subroutine from NEC-4.1,
then find and replace the same
subroutine that is in the (NEC-4.2) Nec4d42.f file
with the copy. You should be copying 74 lines over.
Edit two places in the FORMAT statements of the GETIOF routine that was copied over which originally say "NEC-4.1" to "NEC-4.2". You don't strictly need make the changes in the FORMAT statements, but it will reduce confusion if you ever run NEC-4.2 as a stand alone program one day.
- cd
~/Desktop/oldnec
- Continuing with the Nec4d42.f file in the text
editor,
- Search for all instances (13,
two of which are in comments) of
CALL SECOND
change all of them to say
CALL CPU_TIME
- Remove all lines (3) that
contains USE MSFLIB .
- Remove all lines (2) that
contains USE DFPORT .
- Search for the subroutine SECOND. Delete the
entire routine (19 lines).
- Change SUM(9) to SUM(N) in the declarations in
the subroutine ROMBG.
- Search for all instances (13,
two of which are in comments) of
- Make the following changes to the file SOMGN2.f,
- Search for all instances (4) of
CALL SECOND
change all of them to say
CALL CPU_TIME
- Search for all instances (4) of
- Make the following changes to the file SOMGN3.f,
- Search for the subroutine HFLD. Find the line in
the declaration that says
COMPLEX*16 XKU,XKL,ETAU,ETAL,CEPSU,CEPSL,FRATI
add the variable ETAL2 to the list of declared COMPLEX variables, e.g.
COMPLEX*16 XKU,XKL,ETAU,ETAL,CEPSU,CEPSL,FRATI,ETAL2
- Search for all instances (34) of
CALL SECOND
change all of them to say
CALL CPU_TIME
- Search for the two instances of
OPEN calls that have NAME= in the second argument.
Change both to say FILE= instead of NAME=.
- Search for the subroutine GAUSSINTSX. Find the
line that says
SGN21=SIGN(1.,S2-S1)
change the first argument of the SIGN function to a double precision constant, e.g.,
SGN21=SIGN(1.0D0,S2-S1)
- Search for the subroutine SFLDSH. Find the line
that says
COMPLEX*16 H(9),XKSEG,HPV,HRH,HPH,HZH,SFAC,RK,HSCYL(9)
change the dimension of HSCYL to 10. E.g.,
COMPLEX*16 H(9),XKSEG,HPV,HRH,HPH,HZH,SFAC,RK,HSCYL(10)
- Search for the subroutine HINTERPD. Find the line
that says
COMPLEX*16 SINTRP(3)
change the dimension of SINTRP to 9. E.g.,
COMPLEX*16 SINTRP(9)
- Search for the subroutine HFLD. Find the line in
the declaration that says
- Issue the Unix shell command in Terminal.app to
connect to the
nec4 directory
which you have created,
cd ~/Desktop/nec4
- First, compile the NEC 4.2
modules. Issue the following command line in
Terminal.app (you can cut and paste the following line
to Terminal.app and typing a carriage return)
gfortran -c -O2 NEC42_MOD.f
This generates 13 files with .mod extensions plus an object file NEC42_MOD.o in the nec2d folder.
-
Compile the NEC 4.2
sources. Issue the following command
line in Terminal.app
gfortran -c -O2 *.f
The warnings as seen with NEC-4.1 persists. These are warnings about assigned GOTO statements being deprecated in modern FORTRAN. However, gfortran seems to continue to support assigned GOTO. As with the NEC-4.1 case, it is safe to ignore the (seven) assigned GOTO warnings.
-
Compile the rest of the NEC 4.2
sources. Issue the following command line in
Terminal.app
gfortran -c -O2 *.F
- Finally, ask gfortran link all the object
files (files with .o extensions that are created
above) into an executable file named nec4d42 with the
following command line in Terminal.app (this should be
very fast)
gfortran -o nec4d42 *.o
- The executable file should now be copied or
moved to /Applications so cocoaNEC can find it.
Acknowlegements
As with NEC-4.1, Bill K1GQ has been an invaluable help with making NEC-4.2 work on Mac OS X. Bill also ran the validation files.
Many thanks to Jerry Burke for sending a copy of NEC-4.2 to both Bill and me. Without Jerry, cocoaNEC would not exist.