Infinity=one/zero

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
User avatar
m.hadfield
Posts: 521
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

Infinity=one/zero

#1 Unread post by m.hadfield »

Ticket 497 introduced the following lines into mod_scalars.F, subroutine initialize_scalars:

Code: Select all

      one=1.0_r8
      zero=0.0_r8
      Infinity=one/zero
 
This is not a safe or standard-conforming way of initializing an IEEE infinity. I discovered this because when USE_DEBUG is in effect I normally turn on the compiler options to check for floating-point exceptions and the model then fails at the divide-by-zero. I can turn off those options, but I lose the ability to catch invalid operations that were not intended by the programmer. (These are not unknown in the history of the ROMS code!)

Fortran 2003 introduced an IEEE_ARITHMETIC module to provide a standard way of handling IEEE special values like Infinity. It would probably be a bit tedious to introduce the necessary code into ROMS (because Fortran 2003 support is very uneven) but I think nevertheless that it's a bad idea to do it any other way.

Just think: is your Infinity really necessary?

User avatar
arango
Site Admin
Posts: 1347
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

Re: Infinity=one/zero

#2 Unread post by arango »

Yes, there are several ways for computing infinity in Fortran. I coded the easier one. It can get trickier when computing infinity in 64 bits. Many compilers do this differently. It will be nice when there is a systematic way to deal with infinity, NaN, and others in any Fortran compiler. This is one the features that I would love to have as in Matlab. I introduced the Infinity variable because it is needed when coupling with SWAN, see file Master/mct_roms_swan.h

For now, we can have the following directive in mod_scalars.F until I find a more robust way to do this:

Code: Select all

#ifdef SWAN_COUPLING
      Infinity=one/zero
#endif

User avatar
m.hadfield
Posts: 521
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

Re: Infinity=one/zero

#3 Unread post by m.hadfield »

arango wrote:For now, we can have the following directive in mod_scalars.F until I find a more robust way to do this:

Code: Select all

#ifdef SWAN_COUPLING
      Infinity=one/zero
#endif
That looks like a sensible solution for the time being. Thanks.

Luming
Posts: 2
Joined: Thu Jun 09, 2016 3:07 pm
Location: Univeristiy of Florida

Re: Infinity=one/zero

#4 Unread post by Luming »

arango wrote:Yes, there are several ways for computing infinity in Fortran. I coded the easier one. It can get trickier when computing infinity in 64 bits. Many compilers do this differently. It will be nice when there is a systematic way to deal with infinity, NaN, and others in any Fortran compiler. This is one the features that I would love to have as in Matlab. I introduced the Infinity variable because it is needed when coupling with SWAN, see file Master/mct_roms_swan.h

For now, we can have the following directive in mod_scalars.F until I find a more robust way to do this:

Code: Select all

#ifdef SWAN_COUPLING
      Infinity=one/zero
#endif
Hi Arango,
I just met the same problem. I am trying to run a ROMS-SWAN coupled case. I set the DEBUG on. It gives following errors;
forrtl: error (73): floating divide by zero
Image PC Routine Line Source
coawstG 00000000010320E5 Unknown Unknown Unknown
coawstG 000000000102FEA7 Unknown Unknown Unknown
coawstG 0000000000FD9854 Unknown Unknown Unknown
coawstG 0000000000FD9666 Unknown Unknown Unknown
coawstG 0000000000F75C66 Unknown Unknown Unknown
coawstG 0000000000F7F166 Unknown Unknown Unknown
libpthread.so.0 00000035A660F7E0 Unknown Unknown Unknown
coawstG 0000000000B55096 mod_scalars_mp_in 1403 mod_scalars.f90
coawstG 000000000094CE95 read_phypar_ 221 read_phypar.f90
coawstG 00000000008B51ED inp_par_ 81 inp_par.f90
coawstG 000000000040F1E8 ocean_control_mod 87 ocean_control.f90
coawstG 000000000040E505 MAIN__ 204 master.f90
coawstG 000000000040C31E Unknown Unknown Unknown
libc.so.6 00000035A621ED5D Unknown Unknown Unknown
coawstG 000000000040C1A9 Unknown Unknown Unknown
forrtl: error (73): floating divide by zero
I met this error too when I tried the Inlet_test coupled case, but it worked and run after I execute coawstM instead of coawstG. But when I execute coawstM in my own case it gave the following error that really confused me. I am new in COAWST. Could you give me some help? Thank you!
forrtl: No such file or directory
forrtl: severe (29): file not found, unit 857748528, file /ufrc/olabarrieta/shiluming/COAWST_V3.2/PROJECT/FAY_ROMS_SWAN_COUPLE/fort.857748528
Image PC Routine Line Source
coawstM 0000000000B088A9 Unknown Unknown Unknown
coawstM 0000000000B37EFC Unknown Unknown Unknown
coawstM 00000000009B8D86 Unknown Unknown Unknown
coawstM 0000000000915A25 Unknown Unknown Unknown
coawstM 00000000008FF1BC Unknown Unknown Unknown
coawstM 00000000008A3363 Unknown Unknown Unknown
coawstM 00000000008485B9 Unknown Unknown Unknown
coawstM 000000000040D722 Unknown Unknown Unknown
coawstM 000000000040C37E Unknown Unknown Unknown
libc.so.6 00000031CEE1ED5D Unknown Unknown Unknown
coawstM 000000000040C209 Unknown Unknown Unknown

jcwarner
Posts: 1171
Joined: Wed Dec 31, 2003 6:16 pm
Location: USGS, USA

Re: Infinity=one/zero

#5 Unread post by jcwarner »

you can remove this code:

#ifdef SWAN_COUPLING
Infinity=one/zero
#endif

Luming
Posts: 2
Joined: Thu Jun 09, 2016 3:07 pm
Location: Univeristiy of Florida

Re: Infinity=one/zero

#6 Unread post by Luming »

jcwarner wrote:you can remove this code:

#ifdef SWAN_COUPLING
Infinity=one/zero
#endif
Hi Warner,

Thank you for your help! I removed the code and that error has been fixed.But there comes another error as follows. It seems failure in reading SWAN grid because of uninitialized variable. It is my first time to try the coupled module and have no idea how to fix now. Could you give me some help? Thank you!

forrtl: error (182): floating invalid - possible uninitialized real/complex variable.
Image PC Routine Line Source
coawstG 00000000010320C5 Unknown Unknown Unknown
coawstG 000000000102FE87 Unknown Unknown Unknown
coawstG 0000000000FD9834 Unknown Unknown Unknown
coawstG 0000000000FD9646 Unknown Unknown Unknown
coawstG 0000000000F75C46 Unknown Unknown Unknown
coawstG 0000000000F7EC37 Unknown Unknown Unknown
libpthread.so.0 00000035A660F7E0 Unknown Unknown Unknown
coawstG 0000000000D42B71 inreal_ 481 ocpcre.f90
coawstG 0000000000C4BF8D swread_ 1529 swanpre1.f90
coawstG 0000000000B780BD swan_initialize_ 327 swanmain.f90
coawstG 0000000000B666C8 waves_control_mod 77 waves_control.f90
coawstG 000000000040E485 MAIN__ 196 master.f90
coawstG 000000000040C31E Unknown Unknown Unknown
libc.so.6 00000035A621ED5D Unknown Unknown Unknown
coawstG 000000000040C1A9 Unknown Unknown Unknown

jcwarner
Posts: 1171
Joined: Wed Dec 31, 2003 6:16 pm
Location: USGS, USA

Re: Infinity=one/zero

#7 Unread post by jcwarner »

is this running one of the distributed cases?

Post Reply