aboutsummaryrefslogtreecommitdiff
path: root/pkg/tbtables/fitsio/fttdnn.f
blob: 287d32eae618da4ad0167330f27204fe4fd22f96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
C----------------------------------------------------------------------
        logical function fttdnn(value)

C       test if a R*8 value has a IEEE Not-a-Number value
C       A NaN has all the exponent bits=1, and the fractional part
C       not=0. 
C       Exponent field is in bits 20-30 in the most significant 4-byte word
C       Mantissa field is in bits 0-19 of most sig. word and entire 2nd word
C
C       written by Wm Pence, HEASARC/GSFC, May 1992
C       modified Aug 1994 to handle all IEEE special values.

        integer value(2)

C       COMMON BLOCK DEFINITIONS:--------------------------------------------
        integer nb,ne
        parameter (nb = 20)
        parameter (ne = 200)
        integer bufnum,chdu,hdutyp,maxhdu,hdstrt,hdend,nxthdr,dtstrt
        integer nxtfld
        logical wrmode
        common/ft0001/bufnum(199),chdu(nb),hdutyp(nb),maxhdu(nb),
     &  wrmode(nb),hdstrt(nb,ne),hdend(nb),nxthdr(nb),dtstrt(nb),nxtfld
        integer compid
        common/ftcpid/compid
C       END OF COMMON BLOCK DEFINITIONS-----------------------------------

        integer word1,word2

C       COMPID specifies what type of floating point word structure
C       is used on this machine, and determines how to test for NaNs.

C       COMPID value:
C           1        generic machine: simply test for NaNs with all bits set
C           2        like a decstation or alpha OSF/1, or IBM PC
C           3        SUN workstation, or IBM mainframe
C          -2305843009213693952   Cray (64-bit) machine

        fttdnn=.false.
	return

        if (compid .eq. 1)then
C           on the VAX we can assume that all NaNs will be set to all bits on
C           (which is equivalent to an integer with a value of -1) because
C           this is what the IEEE to VAX conversion MACRO program returns
            if (value(1) .eq. -1 .and. value(2) .eq. -1)fttdnn=.true.

        else if (compid .gt. 1)then
            if (compid .ge. 3)then
C               this is for SUN-like machines, or IBM main frames
                word1=value(1)
                word2=value(2)
            else
C               this is for DECstation and IBM PCs.  The 2 32 bit integer words
C               are reversed from what you get on the SUN.
                word1=value(2)
                word2=value(1)
            end if

C           efficiently search the number space for NaNs and underflows
            if (word2 .eq. -1)then
                if ((word1 .ge. -1048577 .and. word1 .le. -1)
     &           .or. (word1 .ge. 2146435071))then
                      fttdnn=.true.
                else if ((word1 .lt. -2146435072) .or.
     &          (word1 .ge. 0 .and. word1 .lt. 1048576))then
                      value(1)=0
                      value(2)=0
                end if
             else if (word2 .eq. 0)then
                if ((word1 .gt. -1048577 .and. word1 .le. -1)
     &           .or. (word1 .gt. 2146435071))then
                      fttdnn=.true.
                else if ((word1 .le. -2146435072) .or.
     &          (word1 .ge. 0 .and. word1 .le. 1048576))then
                      value(1)=0
                      value(2)=0
                end if
             else
                if ((word1 .gt. -1048577 .and. word1 .le. -1)
     &           .or. (word1 .gt. 2146435071))then
                      fttdnn=.true.
                else if ((word1 .lt. -2146435072) .or.
     &          (word1 .ge. 0 .and. word1 .lt. 1048576))then
                      value(1)=0
                      value(2)=0
                end if
             end if
        else
C           branch for the Cray:  COMPID stores the negative integer
C           which corresponds to the 3 most sig digits set to 1.   If these
C           3 bits are set in a floating point number, then it represents
C           a reserved value (i.e., a NaN)
            if (value(1).lt. 0 .and. value(1) .ge. compid)fttdnn=.true.        
        end if
        end