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
|
C Copyright 1981-2007 ECMWF
C
C Licensed under the GNU Lesser General Public License which
C incorporates the terms and conditions of version 3 of the GNU
C General Public License.
C See LICENSE and gpl-3.0.txt for details.
C
INTEGER FUNCTION IRGTOG (PIFELD, KSTART, KINS, KOWE, KONS,
1 KWEIND, KNSIND, PWFACT, POFELD, KPR, KERR)
C
C---->
C**** *IRGTOG*
C
C Purpose
C -------
C
C Perform basic interpolation between the input and output fields
C for a quasi regular input field and a regular output field.
C
C Interface
C ---------
C
C IERR = IRGTOG (PIFELD, KSTART, KINS, KOWE, KONS, KWEIND,
C 1 KNSIND, PWFACT, POFELD, KPR, KERR)
C
C Input parameters
C ----------------
C
C PIFELD - The input field provided by the calling routine.
C
C KSTART - The array offset for each line of latitude within
C the quasi regular field.
C
C KINS - The number of points in the North-South direction
C in the input field.
C
C KOWE - The number of points in the West-East direction in
C the output field.
C
C KONS - The number of points in the North-South direction
C in the output field.
C
C KWEIND - This array contains the array offsets of the West
C and East points in the input array required for
C interpolation.
C
C KNSIND - This array contains the array offsets of the North
C and South points in the input array required for
C interpolation.
C
C PWFACT - The array of interpolating weights to the four
C neighbouring points for every output point.
C
C KPR - The debug print switch.
C 0 , No debugging output.
C 1 , Produce debugging output.
C
C KERR - The error control flag.
C -ve, No error message. Return error code.
C 0 , Hard failure with error message.
C +ve, Print error message. Return error code.
C
C Output parameters
C -----------------
C
C POFELD - The output field returned to the calling routine.
C
C Return value
C ------------
C
C The error indicator (INTEGER).
C
C Error and Warning Return Values
C -------------------------------
C
C None
C
C Common block usage
C ------------------
C
C None
C
C Externals
C ---------
C
C INTLOG(R) - Logs messages.
C
C Method
C ------
C
C This routine performs basic linear interpolation using the four
C neighbouring points in the quasi regular input array to
C generate the output array.
C
C Reference
C ---------
C
C None
C
C Comments
C --------
C
C None
C
C Author
C ------
C
C K. Fielding *ECMWF* Nov 1993
C
C Modifications
C -------------
C
C Allow for missing data values
C J.D.Chambers ECMWF August 2000
C
C Force nearest neighbour processing with env variable or
C INTOUT parameter
C S.Curic ECMWF September 2005
C
C----<
C -----------------------------------------------------------------|
C* Section 0. Definition of variables.
C -----------------------------------------------------------------|
C
IMPLICIT NONE
C
#include "parim.h"
#include "nifld.common"
#include "nofld.common"
C
C Function arguments
C
INTEGER KINS, KOWE, KONS, KPR, KERR
INTEGER KSTART (KINS)
INTEGER KWEIND (2, KOWE, 2, KONS), KNSIND (2, KONS)
REAL PIFELD (*), POFELD (KOWE, KONS)
REAL PWFACT (4, KOWE, KONS)
C
C Local variables
C
INTEGER ILATN, ILATS, INORTH, ISOUTH, JOLAT, JOLON, COUNT
REAL NEAREST
CHARACTER*12 YFLAG
LOGICAL LVEGGY
C
C Statement function
C
REAL A, B
LOGICAL NOTEQ
NOTEQ(A,B) = (ABS((A)-(B)).GT.(ABS(A)*1E-3))
C
C -----------------------------------------------------------------|
C* Section 1. Initialisation
C -----------------------------------------------------------------|
C
100 CONTINUE
C
IRGTOG = 0
C
IF (KPR .GE. 1) THEN
CALL INTLOG(JP_DEBUG,'IRGTOG: Section 1.',JPQUIET)
CALL INTLOG(JP_DEBUG,'IRGTOG: No. input fld lats = ',KINS)
CALL INTLOG(JP_DEBUG,'IRGTOG: No.output fld lats = ',KONS)
CALL INTLOG(JP_DEBUG,'IRGTOG: No.output fld longs = ',KOWE)
ENDIF
C
LVEGGY = (NITABLE.EQ.128).AND.
X ((NIPARAM.EQ.27).OR.
X (NIPARAM.EQ.28).OR.
X (NIPARAM.EQ.29).OR.
X (NIPARAM.EQ.30).OR.
X (NIPARAM.EQ.43) )
C Force nearest neighbour processing with env variable
CALL GETENV('NEAREST_NEIGHBOUR', YFLAG)
IF( YFLAG(1:1).EQ.'1' ) LVEGGY = .TRUE.
C Force nearest neighbour processing with INTOUT parameter
IF( LMETHOD ) LVEGGY = .TRUE.
IF( LVEGGY ) CALL INTLOG(JP_DEBUG,
X 'IRGTOG: nearest neighbour processing (vegetation)',JPQUIET)
C
C -----------------------------------------------------------------|
C* Section 2. Basic interpolation
C -----------------------------------------------------------------|
C
200 CONTINUE
C
IF( KPR.GE.1 ) CALL INTLOG(JP_DEBUG,'IRGTOG: Section 2.',JPQUIET)
C
DO JOLAT = 1, KONS
C
ILATN = KNSIND(JP_I_N,JOLAT)
ILATS = KNSIND(JP_I_S,JOLAT)
C
INORTH = KSTART(ILATN) - 1
ISOUTH = KSTART(ILATS) - 1
C
DO JOLON = 1, KOWE
C
C Count non-missing data values
C
COUNT = 0
IF( NOTEQ(PIFELD(KWEIND(JP_I_W,JOLON,JP_I_N,JOLAT)+INORTH),
X RMISSGV) ) COUNT = COUNT + 1
IF( NOTEQ(PIFELD(KWEIND(JP_I_E,JOLON,JP_I_N,JOLAT)+INORTH),
X RMISSGV) ) COUNT = COUNT + 1
IF( NOTEQ(PIFELD(KWEIND(JP_I_W,JOLON,JP_I_S,JOLAT)+ISOUTH),
X RMISSGV) ) COUNT = COUNT + 1
IF( NOTEQ(PIFELD(KWEIND(JP_I_E,JOLON,JP_I_S,JOLAT)+ISOUTH),
X RMISSGV) ) COUNT = COUNT + 1
C
C Interpolate using four neighbours if none are missing
C
IF( (COUNT.EQ.4).AND.(.NOT.LVEGGY) ) THEN
POFELD(JOLON,JOLAT) =
X PIFELD(KWEIND(JP_I_W,JOLON,JP_I_N,JOLAT)+INORTH) *
X PWFACT(JP_I_NW,JOLON,JOLAT) +
X PIFELD(KWEIND(JP_I_E,JOLON,JP_I_N,JOLAT)+INORTH) *
X PWFACT(JP_I_NE,JOLON,JOLAT) +
X PIFELD(KWEIND(JP_I_W,JOLON,JP_I_S,JOLAT)+ISOUTH) *
X PWFACT(JP_I_SW,JOLON,JOLAT) +
X PIFELD(KWEIND(JP_I_E,JOLON,JP_I_S,JOLAT)+ISOUTH) *
X PWFACT(JP_I_SE,JOLON,JOLAT)
C
C Set missing if all neighbours are missing
C
ELSE IF( COUNT.EQ.0 ) THEN
POFELD(JOLON,JOLAT) = RMISSGV
C
C Otherwise, use the nearest neighbour
C
ELSE
NEAREST = PWFACT(JP_I_NW,JOLON,JOLAT)
POFELD(JOLON,JOLAT) =
X PIFELD(KWEIND(JP_I_W,JOLON,JP_I_N,JOLAT)+INORTH)
C
IF( PWFACT(JP_I_NE,JOLON,JOLAT).GT.NEAREST ) THEN
NEAREST = PWFACT(JP_I_NE,JOLON,JOLAT)
POFELD(JOLON,JOLAT) =
X PIFELD(KWEIND(JP_I_E,JOLON,JP_I_N,JOLAT)+INORTH)
ENDIF
C
IF( PWFACT(JP_I_SW,JOLON,JOLAT).GT.NEAREST ) THEN
NEAREST = PWFACT(JP_I_SW,JOLON,JOLAT)
POFELD(JOLON,JOLAT) =
X PIFELD(KWEIND(JP_I_W,JOLON,JP_I_S,JOLAT)+ISOUTH)
ENDIF
C
IF( PWFACT(JP_I_SE,JOLON,JOLAT).GT.NEAREST ) THEN
NEAREST = PWFACT(JP_I_SE,JOLON,JOLAT)
POFELD(JOLON,JOLAT) =
X PIFELD(KWEIND(JP_I_E,JOLON,JP_I_S,JOLAT)+ISOUTH)
ENDIF
C
ENDIF
C
ENDDO
C
ENDDO
C
C -----------------------------------------------------------------|
C* Section 9. Return to calling routine. Format statements
C -----------------------------------------------------------------|
C
900 CONTINUE
C
IF( KPR.GE.1 ) CALL INTLOG(JP_DEBUG,'IRGTOG: Section 9.',JPQUIET)
C
RETURN
END
|