Silverfrost Forums

Welcome to our forums

Floating Point Stack Fault

23 Jan 2007 4:51 #1563

Hello, First, thanks to Silverfrost for making a free version of their software available. I had Fortran77 in college last century and I’ve enjoyed refreshing my (limited) skills. I especially like Clearwin+ and the ability to make GUI’s fairly easily. Speaking of which, I’m having a problem with code I’ve written. It calculates various quantities relevant to stocks. Very simple math but when I enter a number in the second field of any of the 5 options, I get a “floating point stack fault”. I take that to mean that the number created is beyond the allocated memory. But the numbers are no larger than 105 or no smaller than 10-3 and I'm using Real8 values. And the error occurs before I even compute the value. Twice I got the “Blue Screen of Death” because of this. I upgraded from version 4.9 to 5.01 but it didn't help as well as trying to debug. The worst part is that it’s an intermittent problem. Sometimes it works fine. It may be a computer problem but I’ve written numerous programs including some with thousands of iterations with few problems. The only thing different is with this program I’m using the paneled radio button format within a parent window. I’ve searched the forum and haven’t found a similar problem. I keep thinking I may be overlooking something simple but I just don't know. Partial Code below. The module is a separate file. I use XP and Pentium chip. Thanks for any help. Tom !***************************************

Module Stocks_Mod
Implicit None
Character TenPercentStr*10,TenPercentPhrase*35,FivePercentStr*10,
Character FivePercentPhrase*35,PercentChangePhrase*35
Character PercentPhrase*30, PercentChangeStr*7
Character TotalSharePhrase*45,PercentStr*8
Character SharePhrase*35, TotalSharesStr*15, PricePhrase*26, TotalPriceStr*15, TotalPricePhrase*45   
Real*8 TenPercent,FivePercent
Real*8 PercentChange,TotalShares, TotalPrice, Price_p_Share
Real*8 Price_p_Share_Final, Price_p_Share_Int
Integer*4 i, winio@, lwo, r(10)  
End Module Stocks_Mod
!*****************************************
WINAPP
Use MSWIN
Use Stocks_Mod
External Shares, Price, PercentChange_Func, Five_Per, Ten_Per
r(1)=0
r(2)=0
r(3)=0
r(4)=0
r(5)=0
i=winio@('%ca[Stocks]%lw&',lwo)
i=winio@('%pv%fr',425,450)
i=winio@('%ww[no_frame,no_caption,no_border]&')
i=winio@('%5ga&',r(1),r(2),r(3),r(4),r(5))
i=winio@('%3.2ob[panelled]%^rb[Number of Shares]%cb&',r(1),Shares)
i=winio@('%^rb[Total Price]%cb&',r(2),Price)
i=winio@('%^rb[Percent Change]%cb&',r(3),PercentChange_Func)
i=winio@('%^rb[5%]%cb&',r(4),Five_Per)
i=winio@('%^rb[10%]%cb&',r(5),Ten_Per)
i=winio@('%aw%cb',lwo)
End
!************************************
Real*8 Function Price()
Use Stocks_Mod
External CalculatePrice, Z
TotalShares=0 
Price_p_Share=0.01d0
TotalPricePhrase=' '
i=winio@('%ca[Price Calculator]&')
i=winio@('%cnEnter the share price: %nl%cn%rf&',Price_p_Share)
i=winio@('%2nl%cnEnter the number of shares: %2nl%cn%rf&', TotalShares)
i=winio@('%nl%cn%`^bt[Compute]%ta%^bt[Clear]&',CalculatePrice,Z)
i=winio@('%5nl%cn%ob%45st%cb&', TotalPricePhrase)
i=winio@('%aw',lwo)
Call window_update@(lwo)
Price=1
End Price
!***************
Real*8 Function CalculatePrice()
Use Stocks_Mod
PricePhrase='The total stock value is $'
TotalPrice=TotalShares*Price_p_Share
Write(TotalPriceStr,'(f10.2)')TotalPrice
Call trim@(TotalPriceStr)
TotalPricePhrase=PricePhrase//TotalPriceStr
Call window_update@(TotalPricePhrase)
CalculatePrice=1
End CalculatePrice 
23 Jan 2007 8:55 #1564

I have had a quick look at this but there are missing routines TEN_PER etc.

All callbacks should return an INTEGER and should be declared as such in the calling main program or routine.

24 Jan 2007 5:08 #1568

Sorry about that. I stuffed as much code as I could onto the board. Is there a way to get it all on the board? There are 5 more functions.

Thanks for the feedback. This isn't urgent.

Tom Light

24 Jan 2007 8:19 #1569

I should have made my comment clearer...

The main reason for failure is almost certainly that

Real*8 Function CalculatePrice()

should be

integer Function CalculatePrice()

etc (i.e. the same for other callbacks)

and you should put

integer CalculatePrice

in the code that calls the function.

26 Jan 2007 4:05 #1574

OK, thanks. I was thinking you had to match the function type with the argument/ variable type. So, ALL callback functions from winio@ because they return an integer, have to be integer functions. That makes sense.

Not exactly sure what you mean by this:

Quoted from PaulLaidler and you should put

integer CalculatePrice

in the code that calls the function.

If I define CalculatePrice as an integer in the module I get a run-time error, “argument corrupt”. But if I define it as an integer in the calling function it seems to work. I have no idea why the difference or why it matters.

I’ve probably missed the point again but I’m sure I’ll get it soon enough. 😃

Thanks for your time.

Tom

26 Jan 2007 10:04 #1575

... integer Function CalculatePrice()

etc (i.e. the same for other callbacks)

and you should put

integer CalculatePrice

in the code that calls the function.

Now I'm worried! I've never done this. I mean, my callbacks are all declared as argumentless integer functions, but I've never declared their return values separately as integers in the code that uses them.

I have /IMPLICIT_NONE in my ftn95.cfg file, so how am I getting away with it?

I think I must not be the only one that's missing a point somewhere :?

Andy

1 Feb 2007 2:05 #1599

Quoted from sparge ... so how am I getting away with it?

So how *am *I getting away with it?

Please login to reply.