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 JNORSGG( PLAT, PGGLAT, KNUM, KUP) 12C 13C----> 14C**** JNORSGG 15C 16C PURPOSE 17C _______ 18C 19C This routine determines which latitude row in a gaussian grid is 20C north or south of a given latitude. 21C 22C 23C INTERFACE 24C _________ 25C 26C I = JNORSGG( PLAT, PGGLAT, KNUM, KUP) 27C 28C 29C Input parameters 30C ________________ 31C 32C PLAT - Given latitude 33C PGGLAT - Array of gaussian grid latitudes (both north and south 34C values) 35C KNUM - Gaussian grid number 36C KUP - Indicator to say if the returned row number should be 37C north or south of the given latitude 38C = 0 for south, = 1 for north 39C 40C 41C Output parameters 42C ________________ 43C 44C Returned value is the latitude row number. 45C 46C 47C Common block usage 48C __________________ 49C 50C None 51C 52C 53C METHOD 54C ______ 55C 56C The nearest gaussian latitude row is found. 57C 58C 59C EXTERNALS 60C _________ 61C 62C None 63C 64C 65C REFERENCE 66C _________ 67C 68C None 69C 70C 71C COMMENTS 72C ________ 73C 74C All input values are assumed to be reasonable! 75C 76C 77C AUTHOR 78C ______ 79C 80C J.D.Chambers ECMWF Jan 1994 81C 82C 83C MODIFICATIONS 84C _____________ 85C 86C J.D.Chambers ECMWF Mar 1996 87C Guess position to start search (an optimisation dodge) 88C 89C J.D.Chambers ECMWF Aug 1996 90C Accept latitude if within 1000th of a degree of stored latitude. 91C 92C J.D.Chambers ECMWF Oct 1996 93C Accept latitude if within 100th of a degree of stored latitude. 94C 95C----< 96C _______________________________________________________ 97C 98C* Section 0. Definition of variables. 99C _______________________________________________________ 100C 101 IMPLICIT NONE 102C 103#include "parim.h" 104C 105C Function arguments 106C 107 REAL PLAT, PGGLAT 108 DIMENSION PGGLAT(*) 109 INTEGER KNUM, KUP 110C 111C Local variables 112C 113 INTEGER J202, NPOS, NPLAT, NGGLAT, IGUESS 114 REAL JPFACTOR 115 PARAMETER ( JPFACTOR = PPMULT/JPMICRO ) 116C 117 REAL DELTA, OLDPLAT 118 INTEGER IFIRST 119 DATA IFIRST/0/, OLDPLAT/100.0/ 120 SAVE IFIRST, DELTA, IGUESS, OLDPLAT, NPLAT 121C 122C _______________________________________________________ 123C 124C* Section 1. Initialization. 125C _______________________________________________________ 126C 127 100 CONTINUE 128C 129C Setup delta estimate between gaussian latitudes 130 IF( IFIRST.NE. KNUM ) THEN 131 IFIRST = KNUM 132 DELTA = 90.0/FLOAT(KNUM-1) 133 ENDIF 134C 135 IF( OLDPLAT.NE.PLAT ) THEN 136 OLDPLAT = PLAT 137 IGUESS = INT( (90.0 - PLAT)/DELTA ) + 1 138 NPLAT = NINT(PLAT*JPFACTOR+0.5) 139 ENDIF 140C _______________________________________________________ 141C 142C* Section 2. Processing. 143C _______________________________________________________ 144C 145 200 CONTINUE 146C 147C Check latitudes in the gaussian definition array 148CDIR$ NOVECTOR 149 DO 202 J202 = IGUESS, 2*KNUM 150C Accept latitude if within 100th of a degree of stored latitude. 151 NGGLAT = NINT(PGGLAT(J202)*JPFACTOR+0.5) 152 IF ( NPLAT .GE. NGGLAT ) THEN 153 IF ( NPLAT .EQ. NGGLAT ) THEN 154 NPOS = J202 155 ELSE 156 NPOS = J202 - KUP 157 ENDIF 158 GOTO 900 159 ENDIF 160 202 CONTINUE 161C 162C 163C On drop-through (e.g. for -90.0), use southernmost latitude 164 NPOS = 2*KNUM 165C 166C _______________________________________________________ 167C 168C* Section 9. Return to calling routine. Format statements 169C _______________________________________________________ 170C 171 900 CONTINUE 172C 173C Allow for latitude above northernmost in array (e.g. 90.0). 174 IF ( NPOS .LT. 1 ) NPOS = 1 175C 176 JNORSGG = NPOS 177C 178 RETURN 179 END 180