SUBROUTINE GRID(rlat,rlon,lat,lon,space) C CALCULATES GRID NUMBERS FROM INPUT LATITUDE AND LONGITUDE c************************************************************ c c Passed Variables: c c rlat,rlon - actual latitude and longitude c lat,lon - calculated grid box numbers c space - grid spacing (1.0 is a 1 degree latitude c by one degree longitude grid box) c c*********************************************************** double precision spaced spaced=(space*1.D+00)+1.D-07 c********************************************************** c c Calculate latitude grid number: c c 1. add 90 to actual latitude, since actual latitudes c run from -90 to 90, and grid numbers run from c 1 to 180. c c 2. Divide by spacing. The additional 1E-7 is to c insure that any latitude right on the line between c two grid boxes will be included in the smaller c number grid box. c c 3. Add one, since a grid number for actual latitude c -90 would be 0 otherwise. c c********************************************************** lat=(((rlat*1.D+00)+(90.*1.D+00))/spaced)+1.D+00 c********************************************************** c c Calculate longitude grid number c c 1. Longitude grid numbers run from 1 to 360 while c actual longitudes run from -180 to 180. The difference c from latitude is that negative values are converted c to the larger end of longitude grid numbers. c They are converted to the values 181 to 360. c c********************************************************** if (rlon.lt.0) then lon=(((rlon*1.D+00)+360.D+00)/spaced)+1.D+00 else lon=((rlon*1.D+00)/spaced)+1.D+00 endif return end