NEC2Logo
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.

  1. 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.

  2. 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.

  3. 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.

    You can now close the NEC-4.1 nec4d.f file, and trash the entire oldnec folder. You only needed NEC-4.1 to obtain the old GETIOF routine.

    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.

  4. Continuing with the Nec4d42.f file in the text editor,

    1. Search for all instances (13, two of which are in comments) of

      CALL SECOND

      change all of them to say

      CALL CPU_TIME

    2. Remove all lines (3) that contains USE MSFLIB .

    3. Remove all lines (2) that contains USE DFPORT .

    4. Search for the subroutine SECOND. Delete the entire routine (19 lines).

    5. Change SUM(9) to SUM(N) in the declarations in the subroutine ROMBG.


  5. Make the following changes to the file SOMGN2.f,

    1. Search for all instances (4) of

      CALL SECOND

      change all of them to say

      CALL CPU_TIME

  6. Make the following changes to the file SOMGN3.f,

    1. 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

    2. Search for all instances (34) of

      CALL SECOND

      change all of them to say

      CALL CPU_TIME

    3. Search for the two instances of OPEN calls that have NAME= in the second argument. Change both to say FILE= instead of NAME=.

    4. 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)

    5. 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)

    6. 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)

  7. Issue the Unix shell command in Terminal.app to connect to the nec4 directory which you have created,

    cd ~/Desktop/nec4

  8. 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.

  9. 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.

  10. Compile the rest of the NEC 4.2 sources. Issue the following command line in Terminal.app

    gfortran -c -O2 *.F


  11. 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

  12. The executable file should now be copied or moved to /Applications so cocoaNEC can find it.
Please note that you might be able to get 5% of improvement with NEC-4.2 by compiling by using the -Ofast option instead of the -O2 option. The -Ofast option is only available on newer versions of gfortran. You can try it first to see if your copy of gfortran supports 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.