rrobe71907
Joined: 26 Sep 2014 Posts: 10 Location: Tamaqua PA
|
Posted: Fri Nov 14, 2014 9:18 pm Post subject: D/FORTRAN interfacing - COMPLEX variables update |
|
|
Update on Real/Imaginary swapping when D main program calls FORTRAN subprogram I mentioned in a previous post.
The real and imaginary parts of a complex variable only swap positions when
returned from a FORTRAN COMPLEX FUNCTION, *not* from a subroutine call.
The following swaps on return to a DMD D main program:
C Compute the Equivalent Impedance for branch circuits
COMPLEX FUNCTION IMPDNCEQV (N, Z) RESULT (ZEQV)
INTEGER*2 N, I
COMPLEX Z(N), ZEQV, ZPROD, ZSUM
ZPROD = Z(1)
ZSUM = Z(1)
IF (N.EQ.1) GOTO 100
DO 100 I=2,N
ZPROD = ZPROD * Z(I)
ZSUM = ZSUM + Z(I)
100 CONTINUE
ZEQV = ZPROD / ZSUM
RETURN
END FUNCTION IMPDNCEQV
The following does *not* swap on return to a DMD D main program:
C NB : Number of circuit branches
C L : Inductance array
C R : Resitance array
C C : Capacitance array
C Z : Impedance array
C ZEQ : Equivalent Impedance
SUBROUTINE IMPDNC10 (NB, L, R, C, Z, ZEQV, OMEGA, IERR)
INTEGER*2 NB, IERR, I
REAL L(NB), R(NB), C(NB), OMEGA
COMPLEX Z(NB), ZEQV, ZLOAD, IMPDNCEQV
IERR = 0
DO 100 I=1,NB
Z(I) = ZLOAD (R(I), L(I), C(I), OMEGA)
100 CONTINUE
ZEQV = IMPDNCEQV (NB, Z)
RETURN
END _________________ Rodney Roberts |
|