Fortran What is causing the ARITHMETIC exception in my FORTRAN program?

  • Thread starter Thread starter debbieanne
  • Start date Start date
  • Tags Tags
    Arithmetic Fortran
AI Thread Summary
The discussion revolves around a FORTRAN program encountering an ARITHMETIC exception due to a division by zero in a specific line of code. The problematic line attempts to compute a value for SAREA(2,ISN) using several variables, including IND(13) and IND(12). The user utilized gdb for debugging, which indicated that the program received a SIGFPE signal, signaling an arithmetic error. To troubleshoot, a suggestion was made to break down the complex expression into simpler steps, allowing for easier identification of the error source. This approach revealed that the variable IND(13) was zero, leading to the division by zero issue. The user confirmed that this method effectively pinpointed the problem, resolving the exception.
debbieanne
Messages
12
Reaction score
1
Good day. My FORTRAN program is throwing an ARITHMETIC exception on this line of code:

SAREA(2,ISN)=SAREA(2,ISN)/IND(13)/1000./6080.2*IND(12)/1000.

When I check this using gdb and print the contents of the variable SAREA(2,ISN), the value is 1432.
gdb error message:
Program received signal SIGFPE, Arithmetic exception.
0x00000001004330ff in anal2 (sdata1=..., alpha=..., code=..., n2=..., nl2=14)
at aix_anal2.f:66
66 13 SAREA(2,ISN)=SAREA(2,ISN)/IND(13)/1000./6080.2*IND(12)/1000.
(gdb) bt
#0 0x00000001004330ff in anal2 (sdata1=..., alpha=..., code=..., n2=...,
nl2=14) at aix_anal2.f:66
#1 0x000000010042594a in set2 (alpha=...) at aix_set2.f:252
#2 0x0000000100412024 in setup () at aix_setup.f:58
#3 0x0000000100445fc7 in test_driver_y2k () at aix_test_driver_y2k.f:338
#4 0x00000001004460a1 in main (argc=1, argv=0x60003a180)
at aix_test_driver_y2k.f:344
#5 0x00000001800483cd in _cygwin_exit_return ()
at /usr/src/debug/cygwin-2.2.1-1/winsup/cygwin/dcrt0.cc:1047
#6 0x00000001800460dc in _cygtls::call2 (this=0x22ce00,
func=0x180047420 <dll_crt0_1(void*)>, arg=0x0, buf=buf@entry=0x22ccf0)
at /usr/src/debug/cygwin-2.2.1-1/winsup/cygwin/cygtls.cc:111
#7 0x0000000180046174 in _cygtls::call (func=<optimized out>,
arg=<optimized out>)
at /usr/src/debug/cygwin-2.2.1-1/winsup/cygwin/cygtls.cc:30
#8 0x00000001004462e1 in cygwin_crt0 (f=<optimized out>)
at /usr/src/debug/cygwin-2.2.1-1/winsup/cygwin/lib/cygwin_crt0.c:22
#9 0x0000000100401010 in mainCRTStartup ()
at /usr/src/debug/cygwin-2.2.1-1/winsup/cygwin/crt0.c:29
(gdb)

This line of code is also causing a stack dump. I tried coding for division by zero but I still get the same stack dump and gdb error message. Any suggestions?

Thanks
 
Technology news on Phys.org
My first attempt would be to simplify the expression into several lines:
Fortran:
print ISN
print SAREA(2,ISN)

X13=IND(13)
X12=IND(12)
Y = SAREA(2,ISN) / X13
Y = Y / 1000.0
Y = Y / 6080.2
Y = Y * X12
Y = Y / 1000
SAREA(2,ISN) = Y

This allows you to see where the point of failure is. My suspicion is that SAREA(2,ISN) is outside the AREA array so I'd also print the value of ISN and verify that SAREA(2,ISN) exists or is within range of your array bounds.
 
  • Like
Likes FactChecker
Thanks jedishrfu. This worked. I was able to determine that Y = SAREA(2,ISN) / X13 was the culprit. X13 =0...division by zero problem. Thanks so much. Very much appreciated.
 
  • Like
Likes jedishrfu
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top