Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | |
| 2 | README File for nec2c |
||
| 3 | |||
| 4 | 1. INTRODUCTION: |
||
| 5 | nec2c is a translation of the NEC2 FORTRAN source code to the C language. |
||
| 6 | The translation was performed mostly "by hand" and a lot of modifications |
||
| 7 | to the original program were introduced in order to modernize the NEC2 |
||
| 8 | and to remove as many built-in limitations as possible. The attendant |
||
| 9 | SOMNEC program was also translated to C and incorporated in nec2c as a |
||
| 10 | function so that Sommerfeld ground solutions are a part of the program. |
||
| 11 | |||
| 12 | 2. CHANGES: |
||
| 13 | The following is a list of the more significant changes incorporated into |
||
| 14 | nec2c during translation from FORTRAN to C: |
||
| 15 | |||
| 16 | * All GO TO constructs have been removed (all 961 of them!) and "spaghetti" |
||
| 17 | code sections untangled as far as was possible to the author. Still, a lot |
||
| 18 | of the code is not as clean and straightforward as might have been. |
||
| 19 | |||
| 20 | * Obsolete memory-saving practices (such as "equivalences" of different |
||
| 21 | variables) have been eliminated and memory-sharing variables have been |
||
| 22 | separated so that they are independent. |
||
| 23 | |||
| 24 | * All fixed-size arrays used in calculations have been replaced with |
||
| 25 | buffer pointers which are allocated memory dynamically according to the |
||
| 26 | needs of the program and the complexity of each structure's geometry. |
||
| 27 | There is a two-fold advantage in this - there is virtually no limit to |
||
| 28 | the complexity of a structure (number of segments/patches etc), and there |
||
| 29 | is no wasted memory in fixed arrays. Additionally, there is no need for |
||
| 30 | data storage/swapping between memory and files and therefore functions |
||
| 31 | relating to this activity and also the NGF form of solution have been |
||
| 32 | removed from the program. |
||
| 33 | |||
| 34 | * When a Sommerfeld finite ground solution is requested, since the |
||
| 35 | SOMNEC program has been incorporated in nec2c there is no need to store |
||
| 36 | the ground grid data in a file and read it when running nec2c. Instead, |
||
| 37 | ground grid data are calculated as needed and for each new frequency if |
||
| 38 | frequency stepping is specified. |
||
| 39 | |||
| 40 | * The factr() and solve() functions have been modified to handle the |
||
| 41 | main matrix (cm) in untransposed form so that calculations are faster. |
||
| 42 | |||
| 43 | * The parser that reads the input file allows the two characters of the |
||
| 44 | mnemonic to be in lower case if preferred. It also allows comments to be |
||
| 45 | inserted anywhere in the input file in Unix style, e.g. all lines |
||
| 46 | beginning with a '#' are ignored. |
||
| 47 | |||
| 48 | * Operationally, nec2c differs from NEC2 in not being an interactive |
||
| 49 | application. Instead, nec2c is a non-interactive command-line application |
||
| 50 | which accepts an input file name and optionally an output file name. |
||
| 51 | If this is not specified, a name for the output file is made by stripping |
||
| 52 | any extensions from the input file name and adding a ".out" extension. |
||
| 53 | Furthermore, nec2c has the potential of being incorporated in another |
||
| 54 | application (like a GUI) after suitable modifications, allowing the |
||
| 55 | creation of a stand-alone program without the need for reading files |
||
| 56 | produced separately. |
||
| 57 | |||
| 58 | * My original motive for translating NEC2 into C was to make it easier |
||
| 59 | to modify and modernize and to change obsolete functions and usage. As |
||
| 60 | a result I have edited to some extend the format of the output file to |
||
| 61 | make it more "human readable" (e.g. provided a single space between |
||
| 62 | adjacent numbers to avoid a hard-to-read "chain" of numbers joined by |
||
| 63 | - signs) etc. In my humble opinion these changes make the output file |
||
| 64 | easier to read and possibly somewhat more presentable, although this is |
||
| 65 | likely to be a problem with applications that read the output file in a |
||
| 66 | rigid manner, based on the exact output format. I apologize for this |
||
| 67 | change if it causes such problems but my intention is to eventually |
||
| 68 | modify nec2c to be used as part of a graphical application, providing |
||
| 69 | results for graphical plots directly in its buffers. |
||
| 70 | |||
| 71 | 3. COMPILATION: |
||
| 72 | The nec2c package is very simple at this time and compilation basically |
||
| 73 | only requires a Linux platform with development tools installed (gcc, |
||
| 74 | make and optionally gdb and "valgrind" for debugging). To compile the |
||
| 75 | source code just type "make nec2c" in the nec2c directory and if all is |
||
| 76 | well an executable binary (nec2c) should be produced. If gdb is not |
||
| 77 | installed, remove the -g option from the line in Makefile the reads: |
||
| 78 | CC = gcc -Wall -O3 -g |
||
| 79 | |||
| 80 | These changes can also be made if debugging is not of interest, thereby |
||
| 81 | reducing the size of the binary and speeding it as well. If desired, |
||
| 82 | nec2c can be installed (to /usr/local/bin) with "make install". |
||
| 83 | |||
| 84 | There is a double precision FORTRAN source (nec2dx.f) in this package |
||
| 85 | and this can be compiled and installed by typing "make nec2dx" in the |
||
| 86 | nec2c directory. It can be run by typing nec2dx and supplying an input |
||
| 87 | and output file name and it may be used to check nec2c's results for |
||
| 88 | bugs etc. |
||
| 89 | |||
| 90 | 4. USAGE: nec2c is run as a non-interactive command-line application |
||
| 91 | and is invoked in the following manner: |
||
| 92 | nec2c -i<input-file-name> [-o<output-file-name>][-hv] |
||
| 93 | -h: print this usage information and exit. |
||
| 94 | -v: print nec2c version number and exit. |
||
| 95 | |||
| 96 | The -i option is always needed and it specifies the name of the input |
||
| 97 | file. The -o switch is optional and it specifies the output file name. |
||
| 98 | If not used, a name for the output file is made by stripping any |
||
| 99 | extensions from the input file name and adding a ".out" extension, e.g. |
||
| 100 | nec2c -i yagi.nec will cause nec2c to read yagi.nec as the input file |
||
| 101 | and produce yagi.out as the output file. |
||
| 102 | |||
| 103 | 5. BUGS!! |
||
| 104 | Translating such a complex and large program from FORTRAN to C and making |
||
| 105 | so many changes along the way is very prone to bugs in the new program. |
||
| 106 | I have fixed a lot of these by using various input files that hopefully |
||
| 107 | invoke most if not all of NEC2's functions but there must still be bugs |
||
| 108 | in nec2c that will surface with some specific combinations of "cards" in |
||
| 109 | some input file. The best way to check nec2c's results is to run nec2dx |
||
| 110 | with the same input file and compare results - there should be very close |
||
| 111 | agreement between them as nec2dx is also double-precision. |
||
| 112 | |||
| 113 | 6. Version history: |
||
| 114 | Version 0.1 beta: First release of the translated NEC2 |
||
| 115 | |||
| 116 | Version 0.2: I used the "valgrind" (http://valgrind.kde.org) |
||
| 117 | tool to check nec2c and found two significant bugs in intrp() and |
||
| 118 | subph() which I (hopefully!) have fixed. I also fixed another bug |
||
| 119 | that was found by Tim Molteno in the netwk() routine. |
||
| 120 | |||
| 121 | If you intend to use valgrind (recommended!) to test nec2c for bugs |
||
| 122 | (mainly memory allocation/access errors) then do not use performance |
||
| 123 | enhancing C flags (e.g. do not use -Ox flags etc) otherwise you will get |
||
| 124 | false error reports. |
||
| 125 | |||
| 126 | Version 0.3: I have split nec2c.c into a number of smaller files to |
||
| 127 | make it easier to work on during bug-fixing or development. |
||
| 128 | |||
| 129 | Version 0.4: Fixed a bug in conect that caused segmentation faults |
||
| 130 | when only one wire segment exists in the structure. this is a case that |
||
| 131 | will probably never exist in practice but the seg fault had to be |
||
| 132 | fixed. |
||
| 133 | |||
| 134 | Version 0.5: Replaced the cmplx() function with a macro to speed up |
||
| 135 | calculations. Changed the fbar() and zint() functions from complex |
||
| 136 | long double to void type and returned the calculated values via a |
||
| 137 | pointer in the argument list. This was done to work around a bug I |
||
| 138 | could never trace, possibly due to gcc itself, were functions of the |
||
| 139 | complex long double type produce a NAN result on return. |
||
| 140 | |||
| 141 | Version 0.6: Fixed a bug inherited from the original NEC2 FORTRAN |
||
| 142 | code. Please see NEC2-bug.txt for details. |
||
| 143 | |||
| 144 | Version 0.7: After a bug report from Juha Vierinen regarding seg |
||
| 145 | faulting of xnec2c, my graphical adaptation of NEC2, I changed |
||
| 146 | all "sprintf" commands to "snprintf" to avoid buffer overruns. |
||
| 147 | Following on the above changes, I revised all similar situations |
||
| 148 | in nec2c source code and changed all "sprintf" commands to |
||
| 149 | "snprintf" just in case. While going through the nec2c source |
||
| 150 | code, I also fixed some minor bugs like typos and tidied error |
||
| 151 | messages. |
||
| 152 | |||
| 153 | Version 0.8: After a segmentation fault bug report, I fixed the |
||
| 154 | netwk() function in network.c to allow allocation of the ipnt buffer |
||
| 155 | when maximum admittance matrix asymmetry printing is requested in the |
||
| 156 | Ex card. |
||
| 157 | |||
| 158 | Version 0.9: After trying to charge big structures' input files, |
||
| 159 | I modified the source code to make this allocation possible. |
||
| 160 | Some unused variables are commented to compile with gcc4.6 |
||
| 161 | without warnings. First implementation of GNU autotools. |
||
| 162 | |||
| 163 | 7. License: |
||
| 164 | nec2c is Public Domain, same as the original FORTRAN source. |
||
| 165 | Please keep any software you write incorporating nec2c in Public Domain |
||
| 166 | or at least use an open license like GPL or BSD. |
||
| 167 | |||
| 168 | 8. AUTHOR: |
||
| 169 | |||
| 170 | Neoklis Kyriazis |
||
| 171 | |||
| 172 | January 27 2004 |
||
| 173 |