NEC-LIST: Could this be a NEC2 bug?

From: Neoklis Kyriazis <n5b4az_at_email.domain.hidden>
Date: Wed, 25 Oct 2006 10:21:37 -0400

Hi,

While developing a multi-threading version of "xnec2c", the GUI version
of "nec2c" (my translation to C of NEC2), I had segfault crashes of the app
when using the EK card (extended thin wire kernel) in a structure that has
a wire element connected to a patch. The same problem exists in nec2c which
is nearer to the original FORTRN NEC2 so I set off to trace it and found that
an index to the ICON2 segment connection array was out of range by 10000,
which it the number added to entries in this array to indicate a connection to
a patch.

In order to make a comparison with NEC2 I added printf/WRITE statements
to print out the value of the index to ICON2 in both the original FORTRAN
version and my translation. I found that both programs printed out the same
values for ICON2 array members, one of which was offset by +10000. But
according to the FORTRAN NEC2 PARAMETERS statement the dimensions
for ICON1 and ICON2 are 2*MAXSEG where MAXSEG=1500 in the original
nec2dx.f code.

I tried to check the NEC2 fortran executable using both gdb and valgrind for
memory violations but there were no error messages etc. I am not too sure
what is wrong here so I post a section of the NEC2 code for your commnets:

      SUBROUTINE CMWW (J,I1,I2,CM,NR,CW,NW,ITRP)
C ***
C DOUBLE PRECISION 6/4/85
C
>>>>> PARAMETER (MAXSEG=1500, MAXMAT=1500) <<<< MAXEG =1500
      IMPLICIT REAL*8(A-H,O-Z)
C ***
C
C CMWW COMPUTES MATRIX ELEMENTS FOR WIRE-WIRE INTERACTIONS
C
      COMPLEX*16 CM,CW,ETK,ETS,ETC,EXK,EYK,EZK,EXS,EYS,EZS,EXC,EYC,EZC
      COMMON /DATA/ X(MAXSEG),Y(MAXSEG),Z(MAXSEG),SI(MAXSEG),BI(MAXSEG),
    
 &ALP(MAXSEG),BET(MAXSEG),WLAM,ICON1(2*MAXSEG),ICON2(2*MAXSEG),<<<<
     &ITAG(2*MAXSEG),ICONX(MAXSEG),LD,N1,N2,N,NP,M1,M2,M,MP,IPSYM
      COMMON /ANGL/ SALP(MAXSEG)
      COMMON /SEGJ/ AX(30),BX(30),CX(30),JCO(30),JSNO,ISCON(50),NSCON,IP
     1CON(10),NPCON
      COMMON /DATAJ/ S,B,XJ,YJ,ZJ,CABJ,SABJ,SALPJ,EXK,EYK,EZK,EXS,EYS,
     &EZS,EXC,EYC,EZC,RKH,IND1,INDD1,IND2,INDD2,IEXK,IPGND
      DIMENSION CM(NR,1), CW(NW,1), CAB(1), SAB(1)
      EQUIVALENCE (CAB,ALP), (SAB,BET)
C SET SOURCE SEGMENT PARAMETERS
      S=SI(J)
      B=BI(J)
      XJ=X(J)
      YJ=Y(J)
      ZJ=Z(J)
      CABJ=CAB(J)
      SABJ=SAB(J)
      SALPJ=SALP(J)
      IF (IEXK.EQ.0) GO TO 16
C DECIDE WETHER EXT. T.W. APPROX. CAN BE USED
      IPR=ICON1(J)
      IF (IPR) 1,6,2
1 IPR=-IPR
      IF (-ICON1(IPR).NE.J) GO TO 7
      GO TO 4
2 IF (IPR.NE.J) GO TO 3
      IF
 (CABJ*CABJ+SABJ*SABJ.GT.1.D-8) GO TO 7
      GO TO 5
3 IF (ICON2(IPR).NE.J) GO TO 7 <<<< IPR here is 10001 *****
<snip>

The PARAMETER statement at the top specifies MAXSEG as 1500 and later
ICON2 is dimensioned as ICON2(2*MAXSEG), e.g. ICON2 has 3000 array
members, yet at label 3 above IPR's values when printed include 10001
which is out of range. The fortran executable runs without problems but the
C version crashes with segmentation faults. This happens with this input file:

CM --- NEC2 Input File created by xnec2c 0.9-beta ---
CE --- End Comments ---
GW 1 15 0.0 0.0 0.0 0.0 0.0 1.0 0.3
SP 0 0 0.0 0.0 0.0 45.0 45.0 0.1 0.0
GE 0 0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
EX 0 1 8 0 1.0 0.0 0.0 0.0 0.0 0.0
FR 0 11 0 0 50.0 5.0 0.0 0.0 0.0 0.0
EK 0
RP 0 19 37 0 0.0 0.0 10.0 10.0 0.0 0.0
EN 0

Any ideas please?
 
Regards

Neoklis
Ham Radio Call: 5B4AZ QTH Loc: KM64MR
My Website: http://5b4az.mattsnetwork.co.uk/

 
Regards
 
Neoklis
Ham Radio Call: 5B4AZ QTH Loc: KM64MR
My Website: http://5b4az.mattsnetwork.co.uk/

-- 
The NEC-List mailing list
NEC-List_at_robomod.net
http://www.robomod.net/mailman/listinfo/nec-list
Received on Wed Oct 25 2006 - 14:21:49 EDT

This archive was generated by hypermail 2.2.0 : Sat Oct 02 2010 - 00:10:45 EDT