What is causing the ARITHMETIC exception in my FORTRAN program?

In summary, the programmer is trying to divide a SAREA(2,ISN) by 0 and is getting an arithmetic exception.
  • #1
debbieanne
12
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
  • #2
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
  • #3
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

1. What is an arithmetic issue in FORTRAN?

An arithmetic issue in FORTRAN refers to a problem that arises when performing calculations using the FORTRAN programming language. This can include errors in mathematical operations, issues with numerical precision, and other related problems.

2. How does FORTRAN handle arithmetic operations?

FORTRAN follows the standard order of operations for arithmetic operations, meaning that multiplication and division take precedence over addition and subtraction. Additionally, FORTRAN follows the concept of implicit type conversion, which can sometimes lead to unexpected results in calculations.

3. How can I avoid arithmetic issues in FORTRAN?

To avoid arithmetic issues in FORTRAN, it is important to properly declare and initialize variables, use appropriate data types, and pay attention to the precision of your calculations. Additionally, using built-in functions for mathematical operations can help prevent errors.

4. What is the role of precision in FORTRAN arithmetic?

Precision plays a crucial role in FORTRAN arithmetic as it determines the accuracy of calculations. FORTRAN offers different data types with varying levels of precision, such as single and double precision, to accommodate different needs. Choosing the appropriate data type can help avoid rounding errors and other issues.

5. Are there any common mistakes that can lead to arithmetic issues in FORTRAN?

Yes, there are common mistakes that can lead to arithmetic issues in FORTRAN, including using incorrect data types, not accounting for implicit type conversion, and not properly handling special cases in mathematical operations. It is important to carefully review your code and double-check your calculations to avoid these mistakes.

Similar threads

  • Programming and Computer Science
Replies
9
Views
9K
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
Back
Top