2
2
3
3
module shr_infnan_mod
4
4
5
- ! ! Inf_NaN_Detection module
5
+ ! ! Inf_NaN_Detection module
6
6
! ! 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
8
8
! ! 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
10
10
! ! freely incorporated into executable programs which are offered
11
11
! ! for sale. Otherwise, distribution of all or part of this file is
12
12
! ! permitted, provided this copyright notice and header are included.
@@ -22,12 +22,12 @@ module shr_infnan_mod
22
22
! ! isneginf(x) - test for a negative "infinite" value
23
23
! !
24
24
! ! 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
26
26
! ! being tested for. If the argument is array valued, the function returns
27
27
! ! a conformable logical array, suitable for use with the ANY function, or
28
28
! ! as a logical mask.
29
29
! !
30
- ! ! Each function operates by transferring the bit pattern from a real
30
+ ! ! Each function operates by transferring the bit pattern from a real
31
31
! ! variable to an integer container. Unless testing for + or - infinity,
32
32
! ! the sign bit is cleared to zero. The value is exclusive ORed with
33
33
! ! the value being tested for. The integer result of the IEOR function is
@@ -48,14 +48,14 @@ module shr_infnan_mod
48
48
integer , parameter :: Double = selected_int_kind (precision (1.0_r8 ))
49
49
50
50
! 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" )
54
54
55
55
! 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" )
59
59
60
60
! Locatation of single and double precision sign bit (Intel)
61
61
! Subtract one because bit numbering starts at zero
@@ -84,30 +84,30 @@ module shr_infnan_mod
84
84
module procedure sisnan
85
85
module procedure disnan
86
86
#endif
87
- end interface
87
+ end interface
88
88
89
89
interface shr_infnan_isinf
90
90
module procedure sisinf
91
91
module procedure disinf
92
- end interface
93
-
92
+ end interface
93
+
94
94
interface shr_infnan_isposinf
95
95
module procedure sisposinf
96
96
module procedure disposinf
97
- end interface
98
-
97
+ end interface
98
+
99
99
interface shr_infnan_isneginf
100
100
module procedure sisneginf
101
101
module procedure disneginf
102
- end interface
102
+ end interface
103
103
104
104
105
105
integer :: shr_sisnan
106
106
external :: shr_sisnan
107
107
integer :: shr_disnan
108
108
external :: shr_disnan
109
109
110
- contains
110
+ contains
111
111
112
112
!
113
113
! If FORTRAN intrinsic's exist use them
@@ -134,7 +134,7 @@ elemental function sisnan(x) result(res)
134
134
res = isnan(x)
135
135
#endif
136
136
137
- end function
137
+ end function
138
138
139
139
! Double precision test for NaN
140
140
elemental function disnan (d ) result(res)
@@ -156,7 +156,7 @@ elemental function disnan(d) result(res)
156
156
res = isnan(d)
157
157
#endif
158
158
159
- end function
159
+ end function
160
160
161
161
!
162
162
! 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)
176
176
real (r4 ), intent (in ) :: x(:)
177
177
logical :: res(size (x))
178
178
179
- integer :: i
179
+ integer :: i
180
180
181
181
do i = 1 , size (x)
182
182
res(i) = (shr_sisnan(x(i)) /= 0 )
183
183
end do
184
184
end function c_sisnan_1D
185
-
185
+
186
186
function c_sisnan_2D (x ) result(res)
187
187
real (r4 ), intent (in ) :: x(:,:)
188
188
logical :: res(size (x,1 ),size (x,2 ))
@@ -195,7 +195,7 @@ function c_sisnan_2D(x) result(res)
195
195
end do
196
196
end do
197
197
end function c_sisnan_2D
198
-
198
+
199
199
function c_sisnan_3D (x ) result(res)
200
200
real (r4 ), intent (in ) :: x(:,:,:)
201
201
logical :: res(size (x,1 ),size (x,2 ),size (x,3 ))
@@ -210,7 +210,7 @@ function c_sisnan_3D(x) result(res)
210
210
end do
211
211
end do
212
212
end function c_sisnan_3D
213
-
213
+
214
214
function c_sisnan_4D (x ) result(res)
215
215
real (r4 ), intent (in ) :: x(:,:,:,:)
216
216
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)
227
227
end do
228
228
end do
229
229
end function c_sisnan_4D
230
-
230
+
231
231
function c_sisnan_5D (x ) result(res)
232
232
real (r4 ), intent (in ) :: x(:,:,:,:,:)
233
233
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)
246
246
end do
247
247
end do
248
248
end function c_sisnan_5D
249
-
249
+
250
250
function c_sisnan_6D (x ) result(res)
251
251
real (r4 ), intent (in ) :: x(:,:,:,:,:,:)
252
252
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)
267
267
end do
268
268
end do
269
269
end function c_sisnan_6D
270
-
270
+
271
271
function c_sisnan_7D (x ) result(res)
272
272
real (r4 ), intent (in ) :: x(:,:,:,:,:,:,:)
273
273
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)
290
290
end do
291
291
end do
292
292
end function c_sisnan_7D
293
-
293
+
294
294
function c_disnan_scalar (x ) result(res)
295
295
real (r8 ), intent (in ) :: x
296
296
logical :: res
@@ -302,13 +302,13 @@ function c_disnan_1D(x) result(res)
302
302
real (r8 ), intent (in ) :: x(:)
303
303
logical :: res(size (x))
304
304
305
- integer :: i
305
+ integer :: i
306
306
307
307
do i = 1 , size (x)
308
308
res(i) = (shr_disnan(x(i)) /= 0 )
309
309
end do
310
310
end function c_disnan_1D
311
-
311
+
312
312
function c_disnan_2D (x ) result(res)
313
313
real (r8 ), intent (in ) :: x(:,:)
314
314
logical :: res(size (x,1 ),size (x,2 ))
@@ -321,7 +321,7 @@ function c_disnan_2D(x) result(res)
321
321
end do
322
322
end do
323
323
end function c_disnan_2D
324
-
324
+
325
325
function c_disnan_3D (x ) result(res)
326
326
real (r8 ), intent (in ) :: x(:,:,:)
327
327
logical :: res(size (x,1 ),size (x,2 ),size (x,3 ))
@@ -336,7 +336,7 @@ function c_disnan_3D(x) result(res)
336
336
end do
337
337
end do
338
338
end function c_disnan_3D
339
-
339
+
340
340
function c_disnan_4D (x ) result(res)
341
341
real (r8 ), intent (in ) :: x(:,:,:,:)
342
342
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)
353
353
end do
354
354
end do
355
355
end function c_disnan_4D
356
-
356
+
357
357
function c_disnan_5D (x ) result(res)
358
358
real (r8 ), intent (in ) :: x(:,:,:,:,:)
359
359
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)
372
372
end do
373
373
end do
374
374
end function c_disnan_5D
375
-
375
+
376
376
function c_disnan_6D (x ) result(res)
377
377
real (r8 ), intent (in ) :: x(:,:,:,:,:,:)
378
378
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)
393
393
end do
394
394
end do
395
395
end function c_disnan_6D
396
-
396
+
397
397
function c_disnan_7D (x ) result(res)
398
398
real (r8 ), intent (in ) :: x(:,:,:,:,:,:,:)
399
399
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)
418
418
end function c_disnan_7D
419
419
420
420
#endif
421
-
421
+
422
422
! Single precision test for Inf
423
423
elemental function sisinf (x ) result(res)
424
424
real (r4 ), intent (in ) :: x
425
425
logical :: res
426
426
res = ieor (ibclr (transfer (x,sPosInf),SPSB), sPosInf) == 0
427
- end function
427
+ end function
428
428
429
429
! Double precision test for Inf
430
430
elemental function disinf (d ) result(res)
431
431
real (r8 ), intent (in ) :: d
432
432
logical :: res
433
433
res = ieor (ibclr (transfer (d,dPosInf),DPSB), dPosInf) == 0
434
- end function
435
-
434
+ end function
435
+
436
436
! Single precision test for +Inf
437
437
elemental function sisposinf (x ) result(res)
438
438
real (r4 ), intent (in ) :: x
439
439
logical :: res
440
440
res = ieor (transfer (x,sPosInf), sPosInf) == 0
441
- end function
441
+ end function
442
442
443
443
! Double precision test for +Inf
444
444
elemental function disposinf (d ) result(res)
445
445
real (r8 ), intent (in ) :: d
446
446
logical :: res
447
447
res = ieor (transfer (d,dPosInf), dPosInf) == 0
448
- end function
449
-
448
+ end function
449
+
450
450
! Single precision test for -Inf
451
451
elemental function sisneginf (x ) result(res)
452
452
real (r4 ), intent (in ) :: x
453
453
logical :: res
454
454
res = ieor (transfer (x,sNegInf), sNegInf) == 0
455
- end function
455
+ end function
456
456
457
457
! Double precision test for -Inf
458
458
elemental function disneginf (d ) result(res)
459
459
real (r8 ), intent (in ) :: d
460
460
logical :: res
461
461
res = ieor (transfer (d,dNegInf), dNegInf) == 0
462
- end function
462
+ end function
463
463
464
464
end module shr_infnan_mod
465
465
0 commit comments