22
33module shr_infnan_mod
44
5- ! ! Inf_NaN_Detection module
5+ ! ! Inf_NaN_Detection module
66! ! Copyright(c) 2003, Lahey Computer Systems, Inc.
7- ! ! Copies of this source code, or standalone compiled files
7+ ! ! Copies of this source code, or standalone compiled files
88! ! derived from this source may not be sold without permission
9- ! ! from Lahey Computers Systems. All or part of this module may be
9+ ! ! from Lahey Computers Systems. All or part of this module may be
1010! ! freely incorporated into executable programs which are offered
1111! ! for sale. Otherwise, distribution of all or part of this file is
1212! ! permitted, provided this copyright notice and header are included.
@@ -22,12 +22,12 @@ module shr_infnan_mod
2222! ! isneginf(x) - test for a negative "infinite" value
2323! !
2424! ! Each function accepts a single or double precision real argument, and
25- ! ! returns a true or false value to indicate the presence of the value
25+ ! ! returns a true or false value to indicate the presence of the value
2626! ! being tested for. If the argument is array valued, the function returns
2727! ! a conformable logical array, suitable for use with the ANY function, or
2828! ! as a logical mask.
2929! !
30- ! ! Each function operates by transferring the bit pattern from a real
30+ ! ! Each function operates by transferring the bit pattern from a real
3131! ! variable to an integer container. Unless testing for + or - infinity,
3232! ! the sign bit is cleared to zero. The value is exclusive ORed with
3333! ! the value being tested for. The integer result of the IEOR function is
@@ -48,14 +48,14 @@ module shr_infnan_mod
4848 integer , parameter :: Double = selected_int_kind (precision (1.0_r8 ))
4949
5050 ! Single precision IEEE values
51- integer (Single), parameter :: sNaN = Z" 7FC00000"
52- integer (Single), parameter :: sPosInf = Z" 7F800000"
53- integer (Single), parameter :: sNegInf = Z" FF800000"
51+ integer (Single), parameter :: sNaN = int ( Z" 7FC00000" )
52+ integer (Single), parameter :: sPosInf = int ( Z" 7F800000" )
53+ integer (Single), parameter :: sNegInf = int ( Z" FF800000" )
5454
5555 ! Double precision IEEE values
56- integer (Double), parameter :: dNaN = Z" 7FF8000000000000"
57- integer (Double), parameter :: dPosInf = Z" 7FF0000000000000"
58- integer (Double), parameter :: dNegInf = Z" FFF0000000000000"
56+ integer (Double), parameter :: dNaN = int ( Z" 7FF8000000000000" )
57+ integer (Double), parameter :: dPosInf = int ( Z" 7FF0000000000000" )
58+ integer (Double), parameter :: dNegInf = int ( Z" FFF0000000000000" )
5959
6060 ! Locatation of single and double precision sign bit (Intel)
6161 ! Subtract one because bit numbering starts at zero
@@ -84,30 +84,30 @@ module shr_infnan_mod
8484 module procedure sisnan
8585 module procedure disnan
8686#endif
87- end interface
87+ end interface
8888
8989 interface shr_infnan_isinf
9090 module procedure sisinf
9191 module procedure disinf
92- end interface
93-
92+ end interface
93+
9494 interface shr_infnan_isposinf
9595 module procedure sisposinf
9696 module procedure disposinf
97- end interface
98-
97+ end interface
98+
9999 interface shr_infnan_isneginf
100100 module procedure sisneginf
101101 module procedure disneginf
102- end interface
102+ end interface
103103
104104
105105 integer :: shr_sisnan
106106 external :: shr_sisnan
107107 integer :: shr_disnan
108108 external :: shr_disnan
109109
110- contains
110+ contains
111111
112112!
113113! If FORTRAN intrinsic's exist use them
@@ -134,7 +134,7 @@ elemental function sisnan(x) result(res)
134134 res = isnan(x)
135135#endif
136136
137- end function
137+ end function
138138
139139 ! Double precision test for NaN
140140 elemental function disnan (d ) result(res)
@@ -156,7 +156,7 @@ elemental function disnan(d) result(res)
156156 res = isnan(d)
157157#endif
158158
159- end function
159+ end function
160160
161161!
162162! Otherwise link to a C function call that either uses the C90 isnan function or a x != x check
@@ -176,13 +176,13 @@ function c_sisnan_1D(x) result(res)
176176 real (r4 ), intent (in ) :: x(:)
177177 logical :: res(size (x))
178178
179- integer :: i
179+ integer :: i
180180
181181 do i = 1 , size (x)
182182 res(i) = (shr_sisnan(x(i)) /= 0 )
183183 end do
184184 end function c_sisnan_1D
185-
185+
186186 function c_sisnan_2D (x ) result(res)
187187 real (r4 ), intent (in ) :: x(:,:)
188188 logical :: res(size (x,1 ),size (x,2 ))
@@ -195,7 +195,7 @@ function c_sisnan_2D(x) result(res)
195195 end do
196196 end do
197197 end function c_sisnan_2D
198-
198+
199199 function c_sisnan_3D (x ) result(res)
200200 real (r4 ), intent (in ) :: x(:,:,:)
201201 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ))
@@ -210,7 +210,7 @@ function c_sisnan_3D(x) result(res)
210210 end do
211211 end do
212212 end function c_sisnan_3D
213-
213+
214214 function c_sisnan_4D (x ) result(res)
215215 real (r4 ), intent (in ) :: x(:,:,:,:)
216216 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ),size (x,4 ))
@@ -227,7 +227,7 @@ function c_sisnan_4D(x) result(res)
227227 end do
228228 end do
229229 end function c_sisnan_4D
230-
230+
231231 function c_sisnan_5D (x ) result(res)
232232 real (r4 ), intent (in ) :: x(:,:,:,:,:)
233233 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ),size (x,4 ),size (x,5 ))
@@ -246,7 +246,7 @@ function c_sisnan_5D(x) result(res)
246246 end do
247247 end do
248248 end function c_sisnan_5D
249-
249+
250250 function c_sisnan_6D (x ) result(res)
251251 real (r4 ), intent (in ) :: x(:,:,:,:,:,:)
252252 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ),size (x,4 ),size (x,5 ),size (x,6 ))
@@ -267,7 +267,7 @@ function c_sisnan_6D(x) result(res)
267267 end do
268268 end do
269269 end function c_sisnan_6D
270-
270+
271271 function c_sisnan_7D (x ) result(res)
272272 real (r4 ), intent (in ) :: x(:,:,:,:,:,:,:)
273273 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ),size (x,4 ),size (x,5 ),size (x,6 ),size (x,7 ))
@@ -290,7 +290,7 @@ function c_sisnan_7D(x) result(res)
290290 end do
291291 end do
292292 end function c_sisnan_7D
293-
293+
294294 function c_disnan_scalar (x ) result(res)
295295 real (r8 ), intent (in ) :: x
296296 logical :: res
@@ -302,13 +302,13 @@ function c_disnan_1D(x) result(res)
302302 real (r8 ), intent (in ) :: x(:)
303303 logical :: res(size (x))
304304
305- integer :: i
305+ integer :: i
306306
307307 do i = 1 , size (x)
308308 res(i) = (shr_disnan(x(i)) /= 0 )
309309 end do
310310 end function c_disnan_1D
311-
311+
312312 function c_disnan_2D (x ) result(res)
313313 real (r8 ), intent (in ) :: x(:,:)
314314 logical :: res(size (x,1 ),size (x,2 ))
@@ -321,7 +321,7 @@ function c_disnan_2D(x) result(res)
321321 end do
322322 end do
323323 end function c_disnan_2D
324-
324+
325325 function c_disnan_3D (x ) result(res)
326326 real (r8 ), intent (in ) :: x(:,:,:)
327327 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ))
@@ -336,7 +336,7 @@ function c_disnan_3D(x) result(res)
336336 end do
337337 end do
338338 end function c_disnan_3D
339-
339+
340340 function c_disnan_4D (x ) result(res)
341341 real (r8 ), intent (in ) :: x(:,:,:,:)
342342 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ),size (x,4 ))
@@ -353,7 +353,7 @@ function c_disnan_4D(x) result(res)
353353 end do
354354 end do
355355 end function c_disnan_4D
356-
356+
357357 function c_disnan_5D (x ) result(res)
358358 real (r8 ), intent (in ) :: x(:,:,:,:,:)
359359 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ),size (x,4 ),size (x,5 ))
@@ -372,7 +372,7 @@ function c_disnan_5D(x) result(res)
372372 end do
373373 end do
374374 end function c_disnan_5D
375-
375+
376376 function c_disnan_6D (x ) result(res)
377377 real (r8 ), intent (in ) :: x(:,:,:,:,:,:)
378378 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ),size (x,4 ),size (x,5 ),size (x,6 ))
@@ -393,7 +393,7 @@ function c_disnan_6D(x) result(res)
393393 end do
394394 end do
395395 end function c_disnan_6D
396-
396+
397397 function c_disnan_7D (x ) result(res)
398398 real (r8 ), intent (in ) :: x(:,:,:,:,:,:,:)
399399 logical :: res(size (x,1 ),size (x,2 ),size (x,3 ),size (x,4 ),size (x,5 ),size (x,6 ),size (x,7 ))
@@ -418,48 +418,48 @@ function c_disnan_7D(x) result(res)
418418 end function c_disnan_7D
419419
420420#endif
421-
421+
422422 ! Single precision test for Inf
423423 elemental function sisinf (x ) result(res)
424424 real (r4 ), intent (in ) :: x
425425 logical :: res
426426 res = ieor (ibclr (transfer (x,sPosInf),SPSB), sPosInf) == 0
427- end function
427+ end function
428428
429429 ! Double precision test for Inf
430430 elemental function disinf (d ) result(res)
431431 real (r8 ), intent (in ) :: d
432432 logical :: res
433433 res = ieor (ibclr (transfer (d,dPosInf),DPSB), dPosInf) == 0
434- end function
435-
434+ end function
435+
436436 ! Single precision test for +Inf
437437 elemental function sisposinf (x ) result(res)
438438 real (r4 ), intent (in ) :: x
439439 logical :: res
440440 res = ieor (transfer (x,sPosInf), sPosInf) == 0
441- end function
441+ end function
442442
443443 ! Double precision test for +Inf
444444 elemental function disposinf (d ) result(res)
445445 real (r8 ), intent (in ) :: d
446446 logical :: res
447447 res = ieor (transfer (d,dPosInf), dPosInf) == 0
448- end function
449-
448+ end function
449+
450450 ! Single precision test for -Inf
451451 elemental function sisneginf (x ) result(res)
452452 real (r4 ), intent (in ) :: x
453453 logical :: res
454454 res = ieor (transfer (x,sNegInf), sNegInf) == 0
455- end function
455+ end function
456456
457457 ! Double precision test for -Inf
458458 elemental function disneginf (d ) result(res)
459459 real (r8 ), intent (in ) :: d
460460 logical :: res
461461 res = ieor (transfer (d,dNegInf), dNegInf) == 0
462- end function
462+ end function
463463
464464end module shr_infnan_mod
465465
0 commit comments