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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
*=======================================================================
*
* 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: ttab2.f,v 7.4 2021/01/31 02:24:52 mcalabre Exp $
*=======================================================================
PROGRAM TTAB2
*-----------------------------------------------------------------------
*
* TTAB2 tests the -TAB routines using PGPLOT for graphical display. It
* demonstrates the nature of linear interpolation in 2 dimensions by
* contouring the interior a single 2 x 2 interpolation element as the
* values in each corner change.
*
*-----------------------------------------------------------------------
* Set up a 2 x 2 lookup table.
INTEGER K1, K2, M
PARAMETER (M = 2, K1 = 2, K2 = 2)
INTEGER K(2), MAP(2)
DOUBLE PRECISION CRVAL(2)
DATA K /K1, K2/
DATA MAP /0, 1/
DATA CRVAL /0D0, 0D0/
* Number of subdivisions on each side of the interpolation element.
INTEGER NP
REAL SCL
PARAMETER (NP = 128)
PARAMETER (SCL = 2.0/(NP-1))
INTEGER I, IM, IK, J, L, L1, L2, L3, LSTEP, STAT(NP*NP), STATUS
REAL ARRAY(NP,NP), CLEV(-10:20), LTM(6), V0, V1, W
DOUBLE PRECISION X(M,NP,NP), WORLD(M,NP,NP)
CHARACTER TEXT*80
* On some systems, such as Sun Sparc, the struct MUST be aligned
* on a double precision boundary, done here using an equivalence.
* Failure to do this may result in mysterious "bus errors".
INCLUDE 'tab.inc'
INTEGER TAB(TABLEN)
DOUBLE PRECISION DUMMY
EQUIVALENCE (TAB,DUMMY)
*-----------------------------------------------------------------------
WRITE (*, 10)
10 FORMAT (
: 'Testing WCSLIB coordinate lookup table routines (ttab2.f)',/,
: '---------------------------------------------------------')
* PGPLOT initialization.
CALL PGBEG (0, '/null', 1, 1)
CALL PGVSTD ()
CALL PGSCH (0.7)
* The viewport is slightly oversized.
CALL PGWNAD (-0.65, 1.65, -0.65, 1.65)
DO 20 L = -10, 20
CLEV(L) = 0.2*L
20 CONTINUE
LTM(1) = -SCL*(1.0 + (NP-1)/4.0)
LTM(2) = SCL
LTM(3) = 0.0
LTM(4) = -SCL*(1.0 + (NP-1)/4.0)
LTM(5) = 0.0
LTM(6) = SCL
* Set up the lookup table.
STATUS = TABPTI (TAB, TAB_FLAG, -1, 0, 0)
STATUS = TABINI(M, K, TAB)
IF (STATUS.NE.0) THEN
WRITE (*, 30) STATUS
30 FORMAT ('TABINI ERROR',I2,'.')
GO TO 999
END IF
STATUS = TABPTI (TAB, TAB_M, M, 0, 0)
DO 50 IM = 1, M
STATUS = TABPTI (TAB, TAB_K, K(IM), IM, 0)
STATUS = TABPTI (TAB, TAB_MAP, MAP(IM), IM, 0)
STATUS = TABPTD (TAB, TAB_CRVAL, CRVAL(IM), IM, 0)
DO 40 IK = 1, K(IM)
STATUS = TABPTD (TAB, TAB_INDEX, DBLE(IK-1), IM, IK)
40 CONTINUE
50 CONTINUE
* Subdivide the interpolation element.
DO 70 I = 1, NP
DO 60 J = 1, NP
X(1,J,I) = (J-1)*(K1-1.0)*SCL - 0.5 - CRVAL(1)
X(2,J,I) = (I-1)*(K2-1.0)*SCL - 0.5 - CRVAL(2)
60 CONTINUE
70 CONTINUE
* The first coordinate element is static.
STATUS = TABPTD (TAB, TAB_COORD, 0D0, 1, 0)
STATUS = TABPTD (TAB, TAB_COORD, 0D0, 3, 0)
STATUS = TABPTD (TAB, TAB_COORD, 0D0, 5, 0)
STATUS = TABPTD (TAB, TAB_COORD, 0D0, 7, 0)
* (k1,k2) = (1,1).
STATUS = TABPTD (TAB, TAB_COORD, 0D0, 2, 0)
* The second coordinate element varies in three of the corners.
DO 170 L3 = 0, 100, 20
* (k1,k2) = (2,2).
STATUS = TABPTD (TAB, TAB_COORD, 0.01D0*L3, 8, 0)
DO 160 L2 = 0, 100, 20
* (k1,k2) = (1,2).
STATUS = TABPTD (TAB, TAB_COORD, 0.01D0*L2, 6, 0)
CALL PGPAGE ()
DO 150 L1 = 0, 100, 2
* (k1,k2) = (2,1).
STATUS = TABPTD (TAB, TAB_COORD, 0.01D0*L1, 4, 0)
* Compute coordinates within the interpolation element.
STATUS = TABX2S (TAB, NP*NP, 2, X, WORLD, STAT)
IF (STATUS.NE.0) THEN
WRITE (*, 80) STATUS
80 FORMAT ('TABX2S ERROR',I2,'.')
END IF
* Start a new plot.
CALL PGBBUF ()
CALL PGERAS ()
CALL PGSCI (1)
CALL PGSLW (3)
CALL PGBOX ('BCNST', 0.0, 0, 'BCNSTV', 0.0, 0)
CALL PGMTXT ('T', 0.7, 0.5, 0.5, '-TAB coordinates: ' //
: 'linear interpolation / extrapolation in 2-D')
* Draw the boundary of the interpolation element in red.
CALL PGSCI (2)
CALL PGMOVE (-0.5, 0.0)
CALL PGDRAW ( 1.5, 0.0)
CALL PGMOVE ( 1.0, -0.5)
CALL PGDRAW ( 1.0, 1.5)
CALL PGMOVE ( 1.5, 1.0)
CALL PGDRAW (-0.5, 1.0)
CALL PGMOVE ( 0.0, 1.5)
CALL PGDRAW ( 0.0, -0.5)
* Label the value of the coordinate element in each corner.
WRITE (TEXT, '(F3.1)') 0.0
CALL PGTEXT (-0.09, -0.05, TEXT)
WRITE (TEXT, '(F4.2)') 0.01*L1
CALL PGTEXT ( 1.02, -0.05, TEXT)
WRITE (TEXT, '(F3.1)') 0.01*L2
CALL PGTEXT (-0.13, 1.02, TEXT)
WRITE (TEXT, '(F3.1)') 0.01*L3
CALL PGTEXT ( 1.02, 1.02, TEXT)
CALL PGSCI (1)
* Contour labelling: bottom.
V0 = REAL(WORLD(2,1,1))
V1 = REAL(WORLD(2,NP,1))
IF (V0.NE.V1) THEN
IF (ABS(INT((V1-V0)/0.2)).LT.10) THEN
LSTEP = 20
ELSE
LSTEP = 40
END IF
DO 90 L = -200, 300, LSTEP
W = -0.5 + 2.0*(L*0.01 - V0)/(V1 - V0)
IF (W.LT.-0.5 .OR. W.GT.1.5) GO TO 90
WRITE (TEXT, '(F4.1)') L*0.01
CALL PGPTXT (W+0.04, -0.56, 0.0, 1.0, TEXT)
90 CONTINUE
END IF
* Contour labelling: left.
V0 = REAL(WORLD(2,1,1))
V1 = REAL(WORLD(2,1,NP))
IF (V0.NE.V1) THEN
IF (ABS(INT((V1-V0)/0.2)).LT.10) THEN
LSTEP = 20
ELSE
LSTEP = 40
END IF
DO 100 L = -200, 300, LSTEP
W = -0.5 + 2.0*(L*0.01 - V0)/(V1 - V0)
IF (W.LT.-0.5 .OR. W.GT.1.5) GO TO 100
WRITE (TEXT, '(F4.1)') L*0.01
CALL PGPTXT (-0.52, W-0.02, 0.0, 1.0, TEXT)
100 CONTINUE
END IF
* Contour labelling: right.
V0 = REAL(WORLD(2,NP,1))
V1 = REAL(WORLD(2,NP,NP))
IF (V0.NE.V1) THEN
IF (ABS(INT((V1-V0)/0.2)).LT.10) THEN
LSTEP = 20
ELSE
LSTEP = 40
END IF
DO 110 L = -200, 300, LSTEP
W = -0.5 + 2.0*(L*0.01 - V0)/(V1 - V0)
IF (W.LT.-0.5 .OR. W.GT.1.5) GO TO 110
WRITE (TEXT, '(F3.1)') L*0.01
CALL PGPTXT (1.52, W-0.02, 0.0, 0.0, TEXT)
110 CONTINUE
END IF
* Contour labelling: top.
V0 = REAL(WORLD(2,1,NP))
V1 = REAL(WORLD(2,NP,NP))
IF (V0.NE.V1) THEN
IF (ABS(INT((V1-V0)/0.2)).LT.10) THEN
LSTEP = 20
ELSE
LSTEP = 40
END IF
DO 120 L = -200, 300, LSTEP
W = -0.5 + 2.0*(L*0.01 - V0)/(V1 - V0)
IF (W.LT.-0.5 .OR. W.GT.1.5) GO TO 120
WRITE (TEXT, '(F3.1)') L*0.01
CALL PGPTXT (W+0.04, 1.52, 0.0, 1.0, TEXT)
120 CONTINUE
END IF
* Draw contours for the second coordinate element.
DO 140 I = 1, NP
DO 130 J = 1, NP
ARRAY(J,I) = REAL(WORLD(2,J,I))
130 CONTINUE
140 CONTINUE
CALL PGSLW (2)
CALL PGSCI (4)
CALL PGCONT (ARRAY, NP, NP, 1, NP, 1, NP, CLEV(-10), 10,
: LTM)
CALL PGSCI (7)
CALL PGCONT (ARRAY, NP, NP, 1, NP, 1, NP, CLEV(0), 1, LTM)
CALL PGSCI (5)
CALL PGCONT (ARRAY, NP, NP, 1, NP, 1, NP, CLEV(1), 20, LTM)
CALL PGEBUF ()
150 CONTINUE
160 CONTINUE
170 CONTINUE
CALL PGEND ()
999 STATUS = TABFREE (TAB)
END
|