File: tdis2.f

package info (click to toggle)
wcslib 7.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,752 kB
  • sloc: ansic: 32,656; lex: 9,281; fortran: 6,634; sh: 3,369; sed: 497; pascal: 188; makefile: 15
file content (255 lines) | stat: -rw-r--r-- 8,399 bytes parent folder | download
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
*=======================================================================
*
* WCSLIB 7.4 - an implementation of the FITS WCS standard.
* Copyright (C) 1995-2021, Mark Calabretta
*
* This file is part of WCSLIB.
*
* WCSLIB is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WCSLIB is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with WCSLIB.  If not, see http://www.gnu.org/licenses.
*
* Author: Mark Calabretta, Australia Telescope National Facility, CSIRO.
* http://www.atnf.csiro.au/people/Mark.Calabretta
* $Id: tdis2.f,v 7.4 2021/01/31 02:24:52 mcalabre Exp $
*=======================================================================

      PROGRAM TDIS2
*-----------------------------------------------------------------------
*
* TDIS2 tests the WCSLIB Fortran routines for manipulating the contents
* of a disprm struct.  Two disprm structs are used.  One, residing in a
* linprm struct, is referenced by "address" (DISP), and the other (DISL)
* resides locally in an INTEGER array.
*
* DISP and WCSP, which are meant to hold addresses, are declared as
* INTEGER arrays of length 2 to accomodate 64-bit machines for which
* sizeof(void *) = 2*sizeof(int).
*
* Test input comes from TPV7.fits.
*-----------------------------------------------------------------------
      INTEGER   DPMAX
      PARAMETER (DPMAX = 256)

      LOGICAL   GOTEND
      INTEGER   DISP(2), IBLOCK, IKEYRC, J, JK, JN, K, NAXIS, NDP,
     :          NKEYRC, NREJECT, NWCS, STATL, STATP, STATUS, WCSP(2)
      DOUBLE PRECISION MAXDIS(2), TOTDIS
      CHARACTER DTYPE(2)*72, KEYREC*80, HEADER*288000, INFILE*9

*     On some systems, such as Sun Sparc, the structs MUST be aligned
*     on a double precision boundary, done here using an equivalence.
*     Failure to do this may result in mysterious "bus errors".
      INCLUDE 'wcserr.inc'
      INCLUDE 'wcshdr.inc'
      INCLUDE 'wcs.inc'
      INCLUDE 'lin.inc'
      INCLUDE 'dis.inc'
      INTEGER   DP(DPMAX*DPLEN), WCS(WCSLEN), LIN(LINLEN), DISL(DISLEN)
      DOUBLE PRECISION DUMMY1, DUMMY2, DUMMY3, DUMMY4
      EQUIVALENCE (DUMMY1, DP)
      EQUIVALENCE (DUMMY2, WCS)
      EQUIVALENCE (DUMMY3, LIN)
      EQUIVALENCE (DUMMY4, DISL)

      DATA INFILE /'TPV7.fits'/
*-----------------------------------------------------------------------
      STATUS = WCSERR_ENABLE (1)

      WRITE (*, 10)
 10   FORMAT (
     :  'Testing WCSLIB Fortran disprm access routines (tdis2.f)',/,
     :  '-------------------------------------------------------')

*     Open the FITS WCS test header for formatted, direct I/O.
      OPEN (UNIT=1, FILE=INFILE, FORM='FORMATTED', ACCESS='DIRECT',
     :      RECL=80, IOSTAT=STATUS)
      IF (STATUS.NE.0) THEN
        WRITE (*, 20) STATUS, INFILE
 20     FORMAT ('ERROR',I3,' opening ',A)
        GO TO 999
      END IF

*     Read in the FITS header, excluding COMMENT and HISTORY keyrecords.
      K = 1
      NKEYRC = 0
      GOTEND = .FALSE.
      DO 50 IBLOCK = 0, 100
        DO 40 IKEYRC = 1, 36
          READ (1, '(A80)', REC=36*IBLOCK+IKEYRC, IOSTAT=STATUS) KEYREC
          IF (STATUS.NE.0) THEN
            WRITE (*, 30) STATUS
 30         FORMAT ('ERROR',I5,' reading header.')
            GO TO 999
          END IF

          IF (KEYREC(:8).EQ.'        ') GO TO 40
          IF (KEYREC(:8).EQ.'COMMENT ') GO TO 40
          IF (KEYREC(:8).EQ.'HISTORY ') GO TO 40

          HEADER(K:) = KEYREC
          K = K + 80
          NKEYRC = NKEYRC + 1

          IF (KEYREC(:10).EQ.'END       ') THEN
*           An END keyrecord was read, but read the rest of the block.
            GOTEND = .TRUE.
          END IF
 40     CONTINUE

        IF (GOTEND) GO TO 60
 50   CONTINUE

 60   CLOSE (UNIT=1)


*     Parse the header.
      CALL FLUSH(6)
      STATUS = WCSPIH (HEADER, NKEYRC, WCSHDR_none, 2, NREJECT, NWCS,
     :                 WCSP)
      IF (STATUS.NE.0) GO TO 999

*     Copy into our WCSPRM struct.
      STATUS = WCSVCOPY (WCSP, 0, WCS)
      IF (STATUS.NE.0) GO TO 999

*     WCSSET translates the TPV "projection" into a sequent distortion.
      STATUS = WCSSET (WCS)
      IF (STATUS.NE.0) THEN
        STATUS = WCSPERR (WCS, CHAR(0))
        GO TO 999
      END IF

*     Make a shallow copy of the linprm struct.
      STATUS = WCSGTI (WCS, WCS_LIN, LIN)
      IF (STATUS.NE.0) THEN
        STATUS = WCSPERR (WCS, CHAR(0))
        GO TO 999
      END IF

*     Extract a "pointer" to the disprm struct.
      STATUS = LINGTI (LIN, LIN_DISSEQ, DISP)
      IF (STATUS.NE.0) THEN
        STATUS = LINPERR (LIN, CHAR(0))
        GO TO 999
      END IF

*     Add a little texture.  The first argument of DISPTD (and DISPRT,
*     DISGET, etc.) is unity to indicate that DISP is a "pointer".
      STATP = DISPTD (1, DISP, DIS_MAXDIS, 2.0010D0, 1, 0)
      IF (STATP.NE.0) GO TO 998
      STATP = DISPTD (1, DISP, DIS_MAXDIS, 2.0020D0, 2, 0)
      IF (STATP.NE.0) GO TO 998
      STATP = DISPTD (1, DISP, DIS_TOTDIS, 3.0000D0, 0, 0)
      IF (STATP.NE.0) GO TO 998

*     Print its contents.
      CALL FLUSH(6)
      STATP = DISPRT (1, DISP)
      IF (STATP.NE.0) GO TO 998

      WRITE (*, 70)
 70   FORMAT (/,'------------------------------------',
     :          '------------------------------------')


*   Copy it the long way first to test the various PUT and GET routines.
*     Start by reading everything from the first.
      STATP = DISGTI (1, DISP, DIS_NAXIS,  NAXIS)
      IF (STATP.NE.0) GO TO 998
      STATP = DISGTC (1, DISP, DIS_DTYPE,  DTYPE)
      IF (STATP.NE.0) GO TO 998
      STATP = DISGTI (1, DISP, DIS_NDP,    NDP)
      IF (STATP.NE.0) GO TO 998
      STATP = DISGTD (1, DISP, DIS_DP,     DP)
      IF (STATP.NE.0) GO TO 998
      STATP = DISGTD (1, DISP, DIS_MAXDIS, MAXDIS)
      IF (STATP.NE.0) GO TO 998
      STATP = DISGTD (1, DISP, DIS_TOTDIS, TOTDIS)
      IF (STATP.NE.0) GO TO 998

*     Initialize the destination.  The first argument of DISPUT (and
*     DISINI, etc.) is zero to indicate that DISL is an array (struct).
      STATL = DISPTI (0, DISL, DIS_FLAG, -1, 0, 0)
      IF (STATL.NE.0) GO TO 997
      STATL = DISINI (0, NAXIS, DISL)
      IF (STATL.NE.0) GO TO 997

*     Copy to the destination.
      JK = 0
      JN = 0
      DO 110 J = 1, NAXIS
        STATL = DISPTD (0, DISL, DIS_DTYPE, DTYPE, J, 0)
        IF (STATL.NE.0) GO TO 997
 110  CONTINUE

      DO 120 K = 1, NDP*DPLEN, DPLEN
        STATL = DISPTI (0, DISL, DIS_DP, DP(K), 0, 0)
 120  CONTINUE

      DO 130 J = 1, NAXIS
        STATL = DISPTI (0, DISL, DIS_MAXDIS, MAXDIS(J), J, 0)
        IF (STATL.NE.0) GO TO 997
 130  CONTINUE

      STATL = DISPTI (0, DISL, DIS_TOTDIS, TOTDIS, J, 0)
      IF (STATL.NE.0) GO TO 997

      STATL = DISSET (0, DISL)
      IF (STATL.NE.0) GO TO 997

*     Print the second.
      CALL FLUSH(6)
      STATL = DISPRT (0, DISL)
      IF (STATL.NE.0) GO TO 997

      WRITE (*, 70)


*   Now copy it the fast way.
*     DISCPY's first argument indicates that the source, DISP, is a
*     "pointer", and the destination, DISL, a local array.  DISCPY
*     will invoke DISINI on the destination, reusing memory allocated
*     previously by DISINI and DISSET.
      STATL = DISCPY (1, DISP, DISL)
      IF (STATL.NE.0) GO TO 997

*     A reset is required before printing.
      STATL = DISSET (0, DISL)
      IF (STATL.NE.0) GO TO 997

*     Print the copy.
      CALL FLUSH(6)
      STATL = DISPRT (0, DISL)
      IF (STATL.NE.0) GO TO 997


*   Cleanup.
 997  IF (STATL.NE.0) THEN
        STATUS = DISPERR (0, DISL, CHAR(0))
      END IF

*     Free memory allocated in the disprm struct.
      STATUS = DISFREE (0, DISL)

 998  IF (STATP.NE.0) THEN
        STATUS = DISPERR (1, DISP, CHAR(0))
      END IF

*     Free memory allocated by WCSPIH, WCSINI, etc.
 999  STATUS = WCSVFREE (NWCS, WCSP)

*     Free memory, allocated via the call to WCSSET, in the copy we made.
*     Also frees allocated memory in the shallow copy we made of linprm.
      STATUS = WCSFREE (WCS)

      END