Any D and FORTRAN programmers out there?

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.
 

rrroberts

New member
Looks like I inadvertently left out some vital information (my bad). The FORTRAN main calling FORTRAN .dll is working fine. The nearest explanation is that during linking or execution, DMD is "stepping on" something in the mathproc.dll (user written FORTRAN dll) or salflibc.dll (Silverfrost supplied library dll).

Think I may have found something at forum[dot]dlang[dot]org[slash]thread[slash]i8hnq1$1mef$1[at sign]digitalmars[dot]com?page=1, a post from 2010, not sure if related.

Dummy me, I should have done a google search on RegisterWaitForInputIdle instead of other research areas (e**x, Dependency Walker).

Appears to be some sort of cluster foulup between WinXP pro SP3, kernel32.dll, dbghelp.dll, and debugging (had to temporarily downgrade, Win 7 machine died). I am trying to sort through it, though it is giving me a headache ;-). This is a little out of my area.

As I find out more, will post. If anyone has any ideas, feel free to admit for me my ignorance ;-).
 

rrroberts

New member
jaran said:
I never heard this language. Can you give me the source about it ?

Just go to dlang[dot]org. Digital Mars is the producer. Basically, D is the next step after C++ but without all of the backwards compatibility issues. A couple of times I tried to learn C++ (have taught myself plain old C) but got lost. So far, have found D to be less frustrating than C++. D is not as mature as C++, FORTRAN, etc., but it is getting there.

I have some D related links at rrroberts[dot]50webs[dot]com[slash]cobindex.htm. One is near the top of the page, others about 3/4 of the way down.
 

jaran

New member
Thank you @rrroberts for the sources. You must be seriously to learn hard coding like this. Im sorry this is so out of my knowledge about programing environment.
 

rrroberts

New member
jaran said:
Thank you @rrroberts for the sources. You must be seriously to learn hard coding like this. Im sorry this is so out of my knowledge about programing environment.
You are welcome.

Do not knock yourself, I am sure there are areas where you can "blow my doors off"
 

jaran

New member
rrroberts said:
jaran said:
Thank you @rrroberts for the sources. You must be seriously to learn hard coding like this. Im sorry this is so out of my knowledge about programing environment.
You are welcome.

Do not knock yourself, I am sure there are areas where you can "blow my doors off"

Yeah, Its better than kissing the girl than learning this suck program. I should rent the Steve Jobs brain to finish this. LOL
 

rrroberts

New member
Genesis said:
rrroberts said:
I am sure there are areas where you can "blow my doors off"
A great expression - first time I've seen it! :heartylaugh:

Probably dating myself here. Back in my youth, was something of a shade tree mechanic and 4x4 enthusiast. Basically means a vehicle with a souped up V8, Holley 4 barrel carb (yes, carburetor), etc., that could outrun must anything.