1C Copyright 1981-2016 ECMWF. 2C 3C This software is licensed under the terms of the Apache Licence 4C Version 2.0 which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. 5C 6C In applying this licence, ECMWF does not waive the privileges and immunities 7C granted to it by virtue of its status as an intergovernmental organisation 8C nor does it submit to any jurisdiction. 9C 10 11 INTEGER FUNCTION IRDIWE(KLLEN,KINS,KNSIND,KONS,KILONG,KIWEMAX, 12 1 KOLONG,KOWE,KWEIND,KWEDIST,IAREA,OAREA,KPR,KERR) 13C 14C----> 15C**** *IRDIWE* 16C 17C PURPOSE 18C _______ 19C 20C Calculate the distances between points in an output longitude 21C array and its West and East neighbours in the input longitude 22C array for a quasi regular input field and regular output field. 23C 24C INTERFACE 25C _________ 26C 27C IERR = IRDIWE(KLLEN,KINS,KNSIND,KONS,KILONG,KIWEMAX, 28C 1 KOLONG,KOWE,KWEIND,KWEDIST,IAREA,OAREA,KPR,KERR) 29C 30C Input parameters 31C ________________ 32C 33C KLLEN - This array contains the quasi regular Gaussian 34C line length definition. 35C 36C KINS - The number of points in the North-South direction 37C in the input field. 38C 39C KNSIND - This array will contain the array offsets of the 40C North and South points in the input array required 41C for interpolation. 42C 43C KONS - The number of points in the North-South direction 44C in the output field. 45C 46C KILONG - The array of input longitudes. 47C 48C KIWEMAX - The maximum number of points in the West-East 49C direction for this quasi regular Gaussian grid. 50C 51C KOLONG - The array of output longitudes. 52C 53C KOWE - The number of points in the West-East direction in 54C the output field. 55C 56C IAREA - Input field area definition (N/W/S/E). 57C 58C OAREA - output field area definition (N/W/S/E). 59C 60C KPR - The debug print switch. 61C 0 , No debugging output. 62C 1 , Produce debugging output. 63C 64C KERR - The error control flag. 65C -ve, No error message. Return error code. 66C 0 , Hard failure with error message. 67C +ve, Print error message. Return error code. 68C 69C Output parameters 70C ________________ 71C 72C KWEIND - This array will contain the array offsets of 73C the West and East points in the input array 74C required for interpolation for all lines of 75C latitude. 76C 77C KWEDIST - This array holds the distances to longitude values 78C in the input field from the associated longitude 79C values in the output field. This array is 80C dimensioned (2, KOWE, 2, KONS). 81C 82C Return value 83C ____________ 84C 85C The error indicator (INTEGER). 86C 87C Error and Warning Return Values 88C _______________________________ 89C 90C None 91C 92C Common block usage 93C __________________ 94C 95C None 96C 97C EXTERNALS 98C _________ 99C 100C IGDIWE - Calculate the distances between points in an 101C output longitude array and its West and East 102C neighbours in the input longitude array for one 103C line of latitude. 104C INTLOG(R) - Logs messages. 105C 106C METHOD 107C ______ 108C 109C This routine will create the arrays of offsets and distance as 110C two arrays of length (2, Number of output longitudes, 2, 111C Number of output latitudes). 112C 113C The array of offsets is copied from line to line provided the 114C number of points in the quasi regular lines of latitude does 115C not change. When the definition changes IGDIWE is used to 116C generate the offsets and distances for the new line definition. 117C 118C----< 119 120C ------------------------------------------------------------------ 121C* Section 0. Definition of variables 122C ------------------------------------------------------------------ 123 IMPLICIT NONE 124 125#include "parim.h" 126 127C Arguments 128 INTEGER IAREA(4) 129 INTEGER OAREA(4) 130 INTEGER KINS 131 INTEGER KONS 132 INTEGER KIWEMAX 133 INTEGER KOWE 134 INTEGER KPR 135 INTEGER KERR 136 INTEGER KLLEN (KINS) 137 INTEGER KNSIND (2,KONS) 138 INTEGER KILONG (KIWEMAX+1) 139 INTEGER KOLONG (KOWE) 140 INTEGER KWEIND (2,KOWE,2,KONS) 141 INTEGER KWEDIST(2,KOWE,2,KONS) 142 143C Local variables 144 LOGICAL GWEGLOBE 145 INTEGER KIWE 146 INTEGER ISTRIDE 147 INTEGER IERR 148 INTEGER IBLON 149 INTEGER IBNS 150 INTEGER IBLAT 151 INTEGER JLAT 152 INTEGER JLON 153 INTEGER JNS 154 INTEGER JPROUTINE 155 PARAMETER (JPROUTINE = 23900) 156 157C External functions 158 INTEGER IGDIWE 159 EXTERNAL IGDIWE 160 161C ------------------------------------------------------------------ 162C* Section 1. Initialisation 163C ------------------------------------------------------------------ 164 100 CONTINUE 165 166 IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IRDIWE: Section 1.',JPQUIET) 167 168 IRDIWE = 0 169 170 IF (KPR .GE. 1) THEN 171 CALL INTLOG(JP_DEBUG,'IRDIWE: Input parameters.',JPQUIET) 172 CALL INTLOG(JP_DEBUG,'IRDIWE: Max no.input longs = ',KIWEMAX) 173 CALL INTLOG(JP_DEBUG,'IRDIWE: No.input lats = ',KINS) 174 CALL INTLOG(JP_DEBUG,'IRDIWE: No.output longs = ',KOWE) 175 CALL INTLOG(JP_DEBUG,'IRDIWE: No.output lats = ',KONS) 176 CALL INTLOG(JP_DEBUG,'IRDIWE: Output field spread = ',KOLONG(1)) 177 CALL INTLOG(JP_DEBUG,'IRDIWE: to ',KOLONG(KOWE)) 178 ENDIF 179 180 GWEGLOBE = .TRUE. 181 IBLON = 0 182 IERR = 0 183 184C ------------------------------------------------------------------ 185C* Section 2. Generate distances and points for all lines of latitude 186C ------------------------------------------------------------------ 187 200 CONTINUE 188 189 IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IRDIWE: Section 2.',JPQUIET) 190 191 IBLAT = 1 192 IBNS = 1 193 194 DO JLAT = 1, KONS 195 DO JNS = 1, 2 196 197 KIWE = KLLEN(KNSIND(JNS,JLAT)) 198 199 IF (KIWE .EQ. IBLON) THEN 200 201C Same line definition as last one calculated 202 KWEIND (1:2,1:KOWE,JNS,JLAT) = KWEIND (1:2,1:KOWE,IBNS,IBLAT) 203 KWEDIST(1:2,1:KOWE,JNS,JLAT) = KWEDIST(1:2,1:KOWE,IBNS,IBLAT) 204 205 ELSE 206 207 IBLON = KIWE 208 IBNS = JNS 209 IBLAT = JLAT 210 211C Generate longitude values for this line ! FIXME: remove 212C (wrap around input grid to simplify IGDIWE) ! ... 213 ISTRIDE = JP360 / KIWE ! ... 214 DO JLON = 1, KIWE ! ... 215 KILONG (JLON) = (JLON - 1) * ISTRIDE ! ... 216 ENDDO ! ... 217 KILONG(KIWE + 1) = KILONG (1) ! ... 218 219 IRDIWE = IGDIWE( KIWE, KOWE, 220 1 KWEIND (1,1,JNS,JLAT), 221 2 KWEDIST (1,1,JNS,JLAT), 222 3 IAREA, OAREA, 223 4 KILONG, KOLONG, GWEGLOBE ) ! FIXME: remove 224 IF (IRDIWE.NE.0) GO TO 900 225 226 ENDIF 227 228 ENDDO 229 ENDDO 230 231C ------------------------------------------------------------------ 232C* Section 9. Return to calling routine. Format statements 233C ------------------------------------------------------------------ 234 900 CONTINUE 235 236 IF (KPR.GE.1) CALL INTLOG(JP_DEBUG,'IRDIWE: Section 9.',JPQUIET) 237 END 238 239