rrroberts
New member
Was wondering if there are any D and FORTRAN programmers on this board?
I am an experienced FORTRAN programmer and recently began learning D. Since I have done a lot of mixed language programming (see rrroberts[dot]50webs[dot]com[slash]cobindex[dot]htm), thought I try a D main calling a FORTRAN .dll. For the most part it works, except when the FORTRAN subroutine calls an e**x function [exp(x), sinh(x), etc.]. Then the program crashes and burns with object.Error@(0): Invalid Floating Point Operation in RegisterWaitForInputIdle.
Here is an example:
when the following is used as a real function in FORTRAN
main program (ENG0010.exe) the following runs fine
--------------------------
C Series Resistance Capacitance Circuit
C Resistance Capacitance Time
C T : Seconds
C R : Ohms
C C : Farads
REAL FUNCTION ERCT (T, R, C) RESULT (X)
REAL T, R, C, X
X = -T / (R * C)
X = EXP(X)
RETURN
END FUNCTION ERCT
when used in a .dll (mathproc.dll) called by a D command line
program (dmath.exe, compiled with DMD dmath.d mathproc.lib),
function crashes at X = EXP(X).
The FORTRAN main program:
PROGRAM ENG0010
IMPLICIT NONE
REAL E, T, R, C, L, I, ERCT, VCAP, V, TMP
C = 0.000018;
R = 8100.0;
E = 20.0;
T = 0.31;
TMP = ERCT (T, R, C)
PRINT '(a,F7.2)',' ERCT (T, R, C): ', TMP
V = VCAP (E, T, R, C)
PRINT '(a,F7.2)',' VCAP (E, T, R, C): ', V
END
The D main program:
import std.stdio;
// mathproc.dll subroutine declarations
extern (Pascal)
{
float ERCT (ref float, ref float, ref float);
float VCAP (ref float, ref float, ref float, ref float);
}
int main(string[] args)
{
float C, R, t, E, L, V, I, tmp;
C = 0.000018;
R = 8100.0;
E = 20.0;
t = 0.31;
tmp = ERCT (C,R,t);
printf (" ERCT (C,R,t): %f \n", tmp);
V = VCAP(C,R,t,E);
printf (" VCAP(C,R,t,E): %f \n", V);
return (0);
}
[extern (Pascal) requires the parameters passed in reverse order]
tried adding
LoadLibraryA ("C:\\Program Files\\Silverfrost\\FTN95 Express\\salflibc.dll");
call mask_underflow@()
etc.
The input range to e**x functions (EXP, TANH) is in -2.13 to 2.36 range.
Using DMD v2.066.0 compiler and Silverfrost FTN95 compilers.
Additional information can be found at links on web page
rrroberts[dot]50webs[dot]com[slash]cobindex[dot]htm
these links will answer many questions about why I did things a certain way.
(When I signed up here, I read something about not being to post links for a while, so [dot] = . and [slash] = /)
I posted this same question at the Silverfrost and Digital Mars forums, did not receive a definitive answer.
Thanks for reading this post.
I am an experienced FORTRAN programmer and recently began learning D. Since I have done a lot of mixed language programming (see rrroberts[dot]50webs[dot]com[slash]cobindex[dot]htm), thought I try a D main calling a FORTRAN .dll. For the most part it works, except when the FORTRAN subroutine calls an e**x function [exp(x), sinh(x), etc.]. Then the program crashes and burns with object.Error@(0): Invalid Floating Point Operation in RegisterWaitForInputIdle.
Here is an example:
when the following is used as a real function in FORTRAN
main program (ENG0010.exe) the following runs fine
--------------------------
C Series Resistance Capacitance Circuit
C Resistance Capacitance Time
C T : Seconds
C R : Ohms
C C : Farads
REAL FUNCTION ERCT (T, R, C) RESULT (X)
REAL T, R, C, X
X = -T / (R * C)
X = EXP(X)
RETURN
END FUNCTION ERCT
when used in a .dll (mathproc.dll) called by a D command line
program (dmath.exe, compiled with DMD dmath.d mathproc.lib),
function crashes at X = EXP(X).
The FORTRAN main program:
PROGRAM ENG0010
IMPLICIT NONE
REAL E, T, R, C, L, I, ERCT, VCAP, V, TMP
C = 0.000018;
R = 8100.0;
E = 20.0;
T = 0.31;
TMP = ERCT (T, R, C)
PRINT '(a,F7.2)',' ERCT (T, R, C): ', TMP
V = VCAP (E, T, R, C)
PRINT '(a,F7.2)',' VCAP (E, T, R, C): ', V
END
The D main program:
import std.stdio;
// mathproc.dll subroutine declarations
extern (Pascal)
{
float ERCT (ref float, ref float, ref float);
float VCAP (ref float, ref float, ref float, ref float);
}
int main(string[] args)
{
float C, R, t, E, L, V, I, tmp;
C = 0.000018;
R = 8100.0;
E = 20.0;
t = 0.31;
tmp = ERCT (C,R,t);
printf (" ERCT (C,R,t): %f \n", tmp);
V = VCAP(C,R,t,E);
printf (" VCAP(C,R,t,E): %f \n", V);
return (0);
}
[extern (Pascal) requires the parameters passed in reverse order]
tried adding
LoadLibraryA ("C:\\Program Files\\Silverfrost\\FTN95 Express\\salflibc.dll");
call mask_underflow@()
etc.
The input range to e**x functions (EXP, TANH) is in -2.13 to 2.36 range.
Using DMD v2.066.0 compiler and Silverfrost FTN95 compilers.
Additional information can be found at links on web page
rrroberts[dot]50webs[dot]com[slash]cobindex[dot]htm
these links will answer many questions about why I did things a certain way.
(When I signed up here, I read something about not being to post links for a while, so [dot] = . and [slash] = /)
I posted this same question at the Silverfrost and Digital Mars forums, did not receive a definitive answer.
Thanks for reading this post.