RadioBanter

RadioBanter (https://www.radiobanter.com/)
-   Antenna (https://www.radiobanter.com/antenna/)
-   -   NEC2 translation to C (https://www.radiobanter.com/antenna/1178-nec2-translation-c.html)

Neoklis February 3rd 04 02:37 PM

NEC2 translation to C
 
Hi all,

I have just completed a translation of NEC2 from fortran to C which
was done "manually" and thus has no dependency on f2c and similar auto
translators. I have also incorporated changes to the source code so
that built-in limitations are removed as far as possible and the use
of file storage for solving complex structures is not needed.

More info and source/binary packages form the nec2 archives:

http://www.qsl.net/wb6tpu/swindex.html

Please note my email address is: neoklisk-AT-cytanet-DOT-com-DOT-cy

Best regards

Neoklis - 5B4AZ

Richard Clark February 3rd 04 05:58 PM

On 3 Feb 2004 06:37:38 -0800, (Neoklis) wrote:

Hi all,

I have just completed a translation of NEC2 from fortran to C which
was done "manually" and thus has no dependency on f2c and similar auto
translators. I have also incorporated changes to the source code so
that built-in limitations are removed as far as possible and the use
of file storage for solving complex structures is not needed.

More info and source/binary packages form the nec2 archives:

http://www.qsl.net/wb6tpu/swindex.html

Please note my email address is: neoklisk-AT-cytanet-DOT-com-DOT-cy

Best regards

Neoklis - 5B4AZ


Hi Neoklis,

This is a very clear and readable source. Good work. I am especially
impressed by your comment:
"All GO TO constructs have been removed (all 961 of them!) and
'spaghetti' code sections untangled as far as was possible to the
author."

How long did this take?

73's
Richard Clark, KB7QHC

Robert Spooner February 3rd 04 06:13 PM

Neoklis wrote:
Hi all,

I have just completed a translation of NEC2 from fortran to C which
was done "manually" ...


Neoklis,

I looked at the URL, and you've done a lot of work to update the code.
That is commendable, and you deserve thanks from the amateur community.
You certainly have my thanks. I'm curious to know how much regression
testing you've done.

73,
Bob AD3K
--
Robert L. Spooner
Registered Professional Engineer
Associate Research Engineer
Intelligent Control Systems Department

Applied Research Laboratory Phone: (814) 863-4120
The Pennsylvania State University FAX: (814) 863-7841
P. O. Box 30
State College, PA 16804-0030


Neoklis February 4th 04 05:17 AM

Richard Clark wrote in message . ..
On 3 Feb 2004 06:37:38 -0800, (Neoklis) wrote:


Hi Neoklis,

This is a very clear and readable source. Good work. I am especially
impressed by your comment:
"All GO TO constructs have been removed (all 961 of them!) and
'spaghetti' code sections untangled as far as was possible to the
author."

How long did this take?

Thanks for the good words, Richard. I started work on August 20 last year
and have been working on it most of the time till now so its about 5 months.
Was very hard at times but I am glad I did not give up!

73's "Nick" 5B4AZ

Neoklis February 4th 04 05:33 AM

Robert Spooner wrote in message ...

I looked at the URL, and you've done a lot of work to update the code.
That is commendable, and you deserve thanks from the amateur community.
You certainly have my thanks. I'm curious to know how much regression
testing you've done.

Hi Bob,

Thanks for the nice words. I tested the translation as much as I could
by comparing my version of program flow with the original source. It was
possible this way to spot a lot of bugs, most of them related to
"off-by-one" errors since fortran uses indices from 1 - n while C from
0 - (n-1). Also untangling GOTO's required a lot of changes mainly in
"spaghetti" sections and these were also prone to errors.

Eventually I debugged the code as far as was possible by constructing
input files that would hopefully put NEC2 through all possible paths
(there are about 1275 if conditionals and about 450 do/while loops!)
and comparing the output with the original fortran code. I then tried
a large number of input files found on the internet and compared outputs.
I had very good agreement in all my tests but I am sure that some
combination in an input file will trigger off hidden bugs.

73's "Nick" 5B4AZ

Peter O. Brackett February 4th 04 01:57 PM

Richard:

[snip]
This is a very clear and readable source. Good work. I am especially
impressed by your comment:
"All GO TO constructs have been removed (all 961 of them!) and
'spaghetti' code sections untangled as far as was possible to the
author."

How long did this take?

73's
Richard Clark, KB7QHC

[snip]

From Fortran to C, what a waste of coding time... and how many errors
were introduced in the translation? Heh, heh. :-)

Many would feel... What a crime?

What's wrong with perfectly good Fortran?

BTW... there's nothing wrong with "GOTO"s that aren't readily fixed with
simple matching "COMEFROM" statements!

Rest in Peace E. Djkystra!

;-)

--
Peter K1PO
Indialantic By-the-Sea, FL.



W4JLE February 4th 04 02:52 PM

would you care to compare the number of platforms that have a C compiler Vs
a FORTRAN compiler?

The code is much more portable in C.

He has done the amateur community a real service and is to be commended.
Your inane comments to the contrary.


"Peter O. Brackett" wrote in message
ink.net...
From Fortran to C, what a waste of coding time... and how many errors
were introduced in the translation? Heh, heh. :-)

Many would feel... What a crime?

What's wrong with perfectly good Fortran?

BTW... there's nothing wrong with "GOTO"s that aren't readily fixed with
simple matching "COMEFROM" statements!

Rest in Peace E. Djkystra!

;-)

--
Peter K1PO
Indialantic By-the-Sea, FL.





Andy Cowley February 4th 04 03:01 PM

Peter O. Brackett wrote:


From Fortran to C, what a waste of coding time... and how many errors
were introduced in the translation? Heh, heh. :-)

And how many were fixed? From what he says about his
test results, very, very few errors were introduced.

Many would feel... What a crime?

Many more might feel "What crime?".

What's wrong with perfectly good Fortran?

Same thing that's wrong with a perfectly good boil on your ass. 8-)

BTW... there's nothing wrong with "GOTO"s that aren't readily fixed with
simple matching "COMEFROM" statements!


Try Cobol. The 'ALTER' statement was a computed come-from!
Fortran programmers can only dream of the job security that
flowed from that.

Rest in Peace E. Djkystra!

A good Fortran programmer can write Fortran in any language. ;-)
What Neoklis has done seems to avoid that pitfall. If he has made
all that NEC2 spaghetti more comprehensible to mere mortals then
he's done us all a really big favour.

vy 73

Andy, M1EBV

Dave Platt February 4th 04 07:06 PM

In article . net,
Peter O. Brackett wrote:

From Fortran to C, what a waste of coding time... and how many errors
were introduced in the translation? Heh, heh. :-)


"Make your peace with FORTRAN, for it is as perennial as crabgrass."

Many would feel... What a crime?

What's wrong with perfectly good Fortran?

BTW... there's nothing wrong with "GOTO"s that aren't readily fixed with
simple matching "COMEFROM" statements!


Heh. Real programmers used Assigned GOTO statements (or the even
studlier COBOL "ALTER" verb).

(grin, duck, run away very very fast....)

--
Dave Platt AE6EO
Hosting the Jade Warrior home page: http://www.radagast.org/jade-warrior
I do _not_ wish to receive unsolicited commercial email, and I will
boycott any company which has the gall to send me such ads!

Peter O. Brackett February 4th 04 09:45 PM


"Neoklis" wrote in message
om...
Hi all,

I have just completed a translation of NEC2 from fortran to C which
was done "manually" and thus has no dependency on f2c and similar auto
translators. I have also incorporated changes to the source code so
that built-in limitations are removed as far as possible and the use
of file storage for solving complex structures is not needed.

More info and source/binary packages form the nec2 archives:

http://www.qsl.net/wb6tpu/swindex.html

Please note my email address is: neoklisk-AT-cytanet-DOT-com-DOT-cy

Best regards

Neoklis - 5B4AZ




Peter O. Brackett February 4th 04 10:18 PM

"JLE":

[snip]
The code is much more portable in C.

[snip]

I disagree.... where are the equivalent high quality field proven
mathematical
subroutine libraries?

Jeesh... software "fads"...

Just because some computer jockey say it's fashionable
ya'll follow along like sheep to the slaughter!

Shades of Bill Gates crappy bloatware. His empire would have collapsed
long ago if not for us hard working hardware Engineers. It's that
slavish devotion to software "fashion" that we see exhibited in this thred
that created Gates evil empire in the first place!

What do people see in "C"? :-)

[snip]
He has done the amateur community a real service and is to be commended.
Your inane comments to the contrary.

[snip]

I agree the OP has done some heavy lifting, but done us service!

Ummm. Nahhh!

How many bugs has he introduced in a perfectly fine program?

Compared to C, modern Fortran is much more suitable in all aspects such as
precision, speed and clairity of purpose and understanding in alignment to
the
original mathematics. Fortran has "native" support for complex and
vector/matrix
arithmetic all advantages over C when applied to large mathematical
manipulations
involving complex arithmetic and multi-dimensional complex arrays such as in
NEC.

C is a system programming language, not a mathematical programming language!

A skilled tradesman uses the right tool for the right job.

There are jobs for which C is quite suitable, but large mathematical
operations
like NEC is not one of them! C seems simple, but hey... where are all of
those
extensive widely proven highly accurate math subroutine libraries for C!
Ugh!

The problem with these danged "so-called" computer scientists is that they
all want to make every tool a religion and don't know which tool to use
for which job.

Why use a sledge hammer to open a walnut? Or a saw to slice bread?

Hey... get real, we Hardware Engineers never let "slide rule scientists"
tell us how
to compute, why now then do we let these so-called "computer scientists"
tell us we are using the wrong tools, when we know better!

Wake up... Don't fall for their stupid con games! They'l soon all be
replaced
by GUI visual code generating automatons anyway!

Converting NEC to Fortran 90/95 would have made more sense than
converting it to C.

I agree, FORTRAN (66 and 77) are old and showing their age. But that's
not the point! FORTRAN should be updated to Fortran, not to C!

Modern Fortran supports all of the old FORTRAN code, and modern concepts
suporting GOTO-less efficient software engineering friendly control
structures.

There is no portability problem, Fortran 90/95 is a very modern language,
with all
of the "modern" structures one expects but without any of the downsides that
non-mathematical languages such as C exhibit when pitted against tough
mathematical
operations.

Fortran 90/95 also has widely available very fast proven optimizing
compilers, some
of them are even free.

Long live Fortran...

--
Peter K1PO
Indialantic By-the-Sea, FL




"Peter O. Brackett" wrote in message
ink.net...
From Fortran to C, what a waste of coding time... and how many errors
were introduced in the translation? Heh, heh. :-)

Many would feel... What a crime?

What's wrong with perfectly good Fortran?

BTW... there's nothing wrong with "GOTO"s that aren't readily fixed with
simple matching "COMEFROM" statements!

Rest in Peace E. Djkystra!

;-)

--
Peter K1PO
Indialantic By-the-Sea, FL.







Tdonaly February 4th 04 10:46 PM

Peter wrote,

Modern Fortran supports all of the old FORTRAN code, and modern concepts
suporting GOTO-less efficient software engineering friendly control
structures.

There is no portability problem, Fortran 90/95 is a very modern language,
with all
of the "modern" structures one expects but without any of the downsides that
non-mathematical languages such as C exhibit when pitted against tough
mathematical
operations.

Fortran 90/95 also has widely available very fast proven optimizing
compilers, some
of them are even free.

Long live Fortran...

--
Peter K1PO
Indialantic By-the-Sea, FL


Peter... Uh, Peter? You're free to do all the coding yourself if you'd
like to. Converting NEC to Fortran 90/95 would be a good project
for you in your retirement.
73,
Tom Donaly, KA6RUH



Richard Clark February 4th 04 11:10 PM

On Wed, 04 Feb 2004 22:18:41 GMT, "Peter O. Brackett"
wrote:
Long live Fortran...


Peter,

You are simply being provincial.

"Fortran" indeed as if that were the mantle of authority to vindicate
bad design. And then to string out all the flavors which, by the way,
invalidates the caprice that Fortran is the end-all be-all. I cut my
teeth on Fortran IV and have progressed through more than a dozen
languages and their dialects. BFD!

Whining over "where's the C math libraries?" when Fortran
implementations offer no better insurance is a tedious argument. Your
hick elitism smacks of the plowboy showing off his new oxfords to the
fellows in boots.

73's
Richard Clark, KB7QHC

R. Torsten Clay February 4th 04 11:21 PM

I disagree.... where are the equivalent high quality field proven
mathematical
subroutine libraries?


Sorry, but IMSL, LAPACK, BLAS, ... (to name a few) all are equally well
usable from Fortran, C, or C++. A given vendor usually writes these
underlying bits by hand from assembler anyway to get maximum performance.
It then makes no difference what language you use at the high level.
Maybe 20 years ago Fortran compilers in general produced faster code
than C compilers, but not today.

Speaking as a computational physicist who programs many large-scale
numerical simulations, I usually use C. C is often much better from a data
manipulation standpoint. Try implementing a doubly-linked list
in Fortran. Yes, such things can be useful in numerical algorithms.

I'm glad there's a readable version of NEC in C available now, this
will make interfacing it with a gui much easier. NEC for typical
amateur antennas runs so fast on todays processors, the important
thing is easily visualizing the input and output.

I'm curious what free Fortran 90/95 compiler you refer to? "evaluation
versions" that expire after xx days don't count :)

Torsten
N4OGW

Peter O. Brackett February 5th 04 02:14 AM

Tom:

[snip]
Peter... Uh, Peter? You're free to do all the coding yourself if you'd
like to. Converting NEC to Fortran 90/95 would be a good project
for you in your retirement.
73,
Tom Donaly, KA6RUH

[snip]

Heh, heh... fool! Taken in by computer scientists are you.

Well, NEC to Fortran 90... Man I've already done it!

And...

It didn't take me several months of coding to end up with a new code with
many
as yet unfound bugs!

--
Peter K1PO
Indialantic By-the-Sea, FL



Russ February 5th 04 04:08 AM

On Wed, 4 Feb 2004 15:01:21 GMT, Andy Cowley
wrote:

Peter O. Brackett wrote:


From Fortran to C, what a waste of coding time... and how many errors
were introduced in the translation? Heh, heh. :-)

And how many were fixed? From what he says about his
test results, very, very few errors were introduced.

Many would feel... What a crime?

Many more might feel "What crime?".

What's wrong with perfectly good Fortran?

Same thing that's wrong with a perfectly good boil on your ass. 8-)

BTW... there's nothing wrong with "GOTO"s that aren't readily fixed with
simple matching "COMEFROM" statements!


Try Cobol. The 'ALTER' statement was a computed come-from!
Fortran programmers can only dream of the job security that
flowed from that.


I give you (from ancient memory)...

NAME1 NOP NAME2
OI X'FF', NAME1 + 2
/* MORE CODE */
NAME2 EQU *

What's it do?

The math libraries in C are at least as good as those in Fortran and
the control and data structures actually exist.

Does DOD still require everything to be written in Ada?

Is NASTRAN still around or is there now a flight-rated C compiler.

Ever write any validated software? Now there's some fun.

Russ


Rest in Peace E. Djkystra!

A good Fortran programmer can write Fortran in any language. ;-)
What Neoklis has done seems to avoid that pitfall. If he has made
all that NEC2 spaghetti more comprehensible to mere mortals then
he's done us all a really big favour.

vy 73

Andy, M1EBV



W4JLE February 5th 04 05:38 AM

Probably, they are still using 386 hardware. a while back NASA was looking
for nos stock to replace components in their 386 computers.

Look for an announcement in the next couple of years about a man rated 486
computer.


"Russ" wrote in message
...
On Wed, 4 Feb 2004 15:01:21 GMT, Andy Cowley

Is NASTRAN still around or is there now a flight-rated C compiler.

Ever write any validated software? Now there's some fun.

Russ


Rest in Peace E. Djkystra!

A good Fortran programmer can write Fortran in any language. ;-)
What Neoklis has done seems to avoid that pitfall. If he has made
all that NEC2 spaghetti more comprehensible to mere mortals then
he's done us all a really big favour.

vy 73

Andy, M1EBV





Maurizio February 5th 04 11:58 AM

(Neoklis) wrote in message . com...
Robert Spooner wrote in message ...

I looked at the URL, and you've done a lot of work to update the code.
That is commendable, and you deserve thanks from the amateur community.
You certainly have my thanks. I'm curious to know how much regression
testing you've done.

Hi Bob,

Thanks for the nice words. I tested the translation as much as I could
by comparing my version of program flow with the original source. It was
possible this way to spot a lot of bugs, most of them related to
"off-by-one" errors since fortran uses indices from 1 - n while C from
0 - (n-1). Also untangling GOTO's required a lot of changes mainly in
"spaghetti" sections and these were also prone to errors.

Eventually I debugged the code as far as was possible by constructing
input files that would hopefully put NEC2 through all possible paths
(there are about 1275 if conditionals and about 450 do/while loops!)
and comparing the output with the original fortran code. I then tried
a large number of input files found on the internet and compared outputs.
I had very good agreement in all my tests but I am sure that some
combination in an input file will trigger off hidden bugs.

73's "Nick" 5B4AZ


Hi Nick,
you have made most of the work made by a New Zeland company that is
selling Supernec.
For all using Matlab, as me, your work is very interesting since doing
some work it is possible to use the highly optimized Matlab routines
to make the hard matrix work of the program. Furthermore, it is also
possible to use the visualization capabilities of the same program to
see the results (or the inputs).
Matlab code can be compiled with other C or even Fortran codes.

Thanks then!

Neoklis February 5th 04 05:38 PM

(Maurizio) wrote in message . com...

Hi Nick,
you have made most of the work made by a New Zeland company that is
selling Supernec.


Selling! Sounds nice ;-)

For all using Matlab, as me, your work is very interesting since doing
some work it is possible to use the highly optimized Matlab routines
to make the hard matrix work of the program. Furthermore, it is also
possible to use the visualization capabilities of the same program to
see the results (or the inputs).


Must confess my math/science is old and rusty - I am 55 years old and
retired early, did some fortran & algol programming around 1970 when I
was a student and taught myself Linux/C later 90's while waiting for
retirement. I don't think I remember enough on matrix math and don't
know Matlab at all to do this myself. I hope my translation is clear
enough for others to contribute more advanced features!


Regards

"Nick" 5B4AZ

[email protected] February 6th 04 11:17 AM

There are only very few things I can think of why someone would like
to have more readable Nec2 code or port it to another language..

1) To improve existing Nec2 code or add additional 'features'.
Till now however I did not find very much (public available)
additions to the default Nec2 core.

2) To understand how the Nec2 program does all calculation...
If you are able to understand the whole thing I definitely
think you should look further and not stay stucked on Nec-2.

Otherwise I see no explicit reason why to port the (thoroughly tested)
Nec2 sources from Fortran to C (or Cobol??). As a middle course one
could consider a port to F77 or even F90. This would make things much
more readable, but with a reduced risk of introducing new bugs....

I once integrated the original Nec2d- and the SomNec.exe's into a
single executable to also use the Sommerfeld ground inside a frequency
loop, so I am not completely unknown with the problems involved. (See
Nec2dXS.exe (with sources) on the famous
www.qsl.net/wb6tpu/swindex.html page)

For freeware F77 compilers see: www.mingw.org or www.delorie.com/djgpp

Nevertheless I very much welcome the effort of Neoklis of porting Nec2
sources to C. Who knows what Neoklis will do next to please us all...

Greetings,
Arie.


All times are GMT +1. The time now is 08:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
RadioBanter.com