3 ! Module that defines constants, data structures, and
4 ! subroutines used to convert grid indices to lat/lon
7 ! SUPPORTED PROJECTIONS
8 ! ---------------------
9 ! Cylindrical Lat/Lon (code = PROJ_LATLON)
10 ! Mercator (code = PROJ_MERC)
11 ! Lambert Conformal (code = PROJ_LC)
12 ! Gaussian (code = PROJ_GAUSS)
13 ! Polar Stereographic (code = PROJ_PS)
14 ! Rotated Lat/Lon (code = PROJ_ROTLL)
18 ! The routines contained within were adapted from routines
19 ! obtained from NCEP's w3 library. The original NCEP routines were less
20 ! flexible (e.g., polar-stereo routines only supported truelat of 60N/60S)
21 ! than what we needed, so modifications based on equations in Hoke, Hayes, and
22 ! Renninger (AFGWC/TN/79-003) were added to improve the flexibility.
23 ! Additionally, coding was improved to F90 standards and the routines were
24 ! combined into this module.
29 ! For mercator, lambert conformal, and polar-stereographic projections,
30 ! the routines within assume the following:
32 ! 1. Grid is dimensioned (i,j) where i is the East-West direction,
33 ! positive toward the east, and j is the north-south direction,
34 ! positive toward the north.
35 ! 2. Origin is at (1,1) and is located at the southwest corner,
36 ! regardless of hemispere.
37 ! 3. Grid spacing (dx) is always positive.
38 ! 4. Values of true latitudes must be positive for NH domains
39 ! and negative for SH domains.
41 ! For the latlon and Gaussian projection, the grid origin may be at any
42 ! of the corners, and the deltalat and deltalon values can be signed to
43 ! account for this using the following convention:
44 ! Origin Location Deltalat Sign Deltalon Sign
45 ! --------------- ------------- -------------
52 ! 1. Any arguments that are a latitude value are expressed in
53 ! degrees north with a valid range of -90 -> 90
54 ! 2. Any arguments that are a longitude value are expressed in
55 ! degrees east with a valid range of -180 -> 180.
56 ! 3. Distances are in meters and are always positive.
57 ! 4. The standard longitude (stdlon) is defined as the longitude
58 ! line which is parallel to the grid's y-axis (j-direction), along
59 ! which latitude increases (NOT the absolute value of latitude, but
60 ! the actual latitude, such that latitude increases continuously
61 ! from the south pole to the north pole) as j increases.
62 ! 5. One true latitude value is required for polar-stereographic and
63 ! mercator projections, and defines at which latitude the
64 ! grid spacing is true. For lambert conformal, two true latitude
65 ! values must be specified, but may be set equal to each other to
66 ! specify a tangent projection instead of a secant projection.
70 ! To use the routines in this module, the calling routines must have the
71 ! following statement at the beginning of its declaration block:
74 ! The use of the module not only provides access to the necessary routines,
75 ! but also defines a structure of TYPE (proj_info) that can be used
76 ! to declare a variable of the same type to hold your map projection
77 ! information. It also defines some integer parameters that contain
78 ! the projection codes so one only has to use those variable names rather
79 ! than remembering the acutal code when using them. The basic steps are
82 ! 1. Ensure the "USE map_utils" is in your declarations.
83 ! 2. Declare the projection information structure as type(proj_info):
84 ! TYPE(proj_info) :: proj
85 ! 3. Populate your structure by calling the map_set routine:
86 ! CALL map_set(code,lat1,lon1,knowni,knownj,dx,stdlon,truelat1,truelat2,proj)
88 ! code (input) = one of PROJ_LATLON, PROJ_MERC, PROJ_LC, PROJ_PS,
89 ! PROJ_GAUSS, or PROJ_ROTLL
90 ! lat1 (input) = Latitude of grid origin point (i,j)=(1,1)
92 ! lon1 (input) = Longitude of grid origin
93 ! knowni (input) = origin point, x-location
94 ! knownj (input) = origin point, y-location
95 ! dx (input) = grid spacing in meters (ignored for LATLON projections)
96 ! stdlon (input) = Standard longitude for PROJ_PS and PROJ_LC,
97 ! deltalon (see assumptions) for PROJ_LATLON,
98 ! ignored for PROJ_MERC
99 ! truelat1 (input) = 1st true latitude for PROJ_PS, PROJ_LC, and
100 ! PROJ_MERC, deltalat (see assumptions) for PROJ_LATLON
101 ! truelat2 (input) = 2nd true latitude for PROJ_LC,
102 ! ignored for all others.
103 ! proj (output) = The structure of type (proj_info) that will be fully
104 ! populated after this call
106 ! 4. Now that the proj structure is populated, you may call either
107 ! of the following routines:
109 ! latlon_to_ij(proj, lat, lon, i, j)
110 ! ij_to_latlon(proj, i, j, lat, lon)
112 ! It is incumbent upon the calling routine to determine whether or
113 ! not the values returned are within your domain's bounds. All values
114 ! of i, j, lat, and lon are REAL values.
119 ! Hoke, Hayes, and Renninger, "Map Preojections and Grid Systems for
120 ! Meteorological Applications." AFGWC/TN-79/003(Rev), Air Weather
123 ! NCAR MM5v3 Modeling System, REGRIDDER program, module_first_guess_map.F
124 ! NCEP routines w3fb06, w3fb07, w3fb08, w3fb09, w3fb11, w3fb12
128 ! 27 Mar 2001 - Original Version
129 ! Brent L. Shaw, NOAA/FSL (CSU/CIRA)
131 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
135 INTEGER, PARAMETER :: HH=4, VV=5
137 REAL, PARAMETER :: PI = 3.141592653589793
138 REAL, PARAMETER :: OMEGA_E = 7.292e-5
140 REAL, PARAMETER :: DEG_PER_RAD = 180./PI
141 REAL, PARAMETER :: RAD_PER_DEG = PI/180.
143 REAL, PARAMETER :: A_WGS84 = 6378137.
144 REAL, PARAMETER :: B_WGS84 = 6356752.314
145 REAL, PARAMETER :: RE_WGS84 = A_WGS84
146 REAL, PARAMETER :: E_WGS84 = 0.081819192
148 REAL, PARAMETER :: A_NAD83 = 6378137.
149 REAL, PARAMETER :: RE_NAD83 = A_NAD83
150 REAL, PARAMETER :: E_NAD83 = 0.0818187034
152 REAL, PARAMETER :: EARTH_RADIUS_M = 6370000.
153 REAL, PARAMETER :: EARTH_CIRC_M = 2.*PI*EARTH_RADIUS_M
155 INTEGER, PUBLIC, PARAMETER :: PROJ_LATLON = 0
156 INTEGER, PUBLIC, PARAMETER :: PROJ_LC = 1
157 INTEGER, PUBLIC, PARAMETER :: PROJ_PS = 2
158 INTEGER, PUBLIC, PARAMETER :: PROJ_PS_WGS84 = 102
159 INTEGER, PUBLIC, PARAMETER :: PROJ_MERC = 3
160 INTEGER, PUBLIC, PARAMETER :: PROJ_GAUSS = 4
161 INTEGER, PUBLIC, PARAMETER :: PROJ_CYL = 5
162 INTEGER, PUBLIC, PARAMETER :: PROJ_CASSINI = 6
163 INTEGER, PUBLIC, PARAMETER :: PROJ_ALBERS_NAD83 = 105
164 INTEGER, PUBLIC, PARAMETER :: PROJ_ROTLL = 203
166 ! Define some private constants
167 INTEGER, PRIVATE, PARAMETER :: HIGH = 8
171 INTEGER :: code ! Integer code for projection TYPE
172 INTEGER :: nlat ! For Gaussian -- number of latitude points
173 ! north of the equator
176 INTEGER :: ixdim ! For Rotated Lat/Lon -- number of mass points
178 INTEGER :: jydim ! For Rotated Lat/Lon -- number of rows
179 INTEGER :: stagger ! For Rotated Lat/Lon -- mass or velocity grid
180 REAL :: phi ! For Rotated Lat/Lon -- domain half-extent in
182 REAL :: lambda ! For Rotated Lat/Lon -- domain half-extend in
184 REAL :: lat1 ! SW latitude (1,1) in degrees (-90->90N)
185 REAL :: lon1 ! SW longitude (1,1) in degrees (-180->180E)
186 REAL :: lat0 ! For Cassini, latitude of projection pole
187 REAL :: lon0 ! For Cassini, longitude of projection pole
188 REAL :: dx ! Grid spacing in meters at truelats, used
189 ! only for ps, lc, and merc projections
190 REAL :: dy ! Grid spacing in meters at truelats, used
191 ! only for ps, lc, and merc projections
192 REAL :: latinc ! Latitude increment for cylindrical lat/lon
193 REAL :: loninc ! Longitude increment for cylindrical lat/lon
194 ! also the lon increment for Gaussian grid
195 REAL :: dlat ! Lat increment for lat/lon grids
196 REAL :: dlon ! Lon increment for lat/lon grids
197 REAL :: stdlon ! Longitude parallel to y-axis (-180->180E)
198 REAL :: truelat1 ! First true latitude (all projections)
199 REAL :: truelat2 ! Second true lat (LC only)
200 REAL :: hemi ! 1 for NH, -1 for SH
201 REAL :: cone ! Cone factor for LC projections
202 REAL :: polei ! Computed i-location of pole point
203 REAL :: polej ! Computed j-location of pole point
204 REAL :: rsw ! Computed radius to SW corner
205 REAL :: rebydx ! Earth radius divided by dx
206 REAL :: knowni ! X-location of known lat/lon
207 REAL :: knownj ! Y-location of known lat/lon
208 REAL :: re_m ! Radius of spherical earth, meters
209 REAL :: rho0 ! For Albers equal area
210 REAL :: nc ! For Albers equal area
211 REAL :: bigc ! For Albers equal area
212 LOGICAL :: init ! Flag to indicate if this struct is
214 LOGICAL :: wrap ! For Gaussian -- flag to indicate wrapping
216 REAL, POINTER, DIMENSION(:) :: gauss_lat ! Latitude array for Gaussian grid
220 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
222 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
224 SUBROUTINE map_init(proj)
225 ! Initializes the map projection structure to missing values
228 TYPE(proj_info), INTENT(INOUT) :: proj
239 proj%truelat1 = -999.9
240 proj%truelat2 = -999.9
255 proj%re_m = EARTH_RADIUS_M
261 nullify(proj%gauss_lat)
263 END SUBROUTINE map_init
266 SUBROUTINE map_set(proj_code, proj, lat1, lon1, lat0, lon0, knowni, knownj, dx, latinc, &
267 loninc, stdlon, truelat1, truelat2, nlat, nlon, ixdim, jydim, &
268 stagger, phi, lambda, r_earth)
269 ! Given a partially filled proj_info structure, this routine computes
270 ! polei, polej, rsw, and cone (if LC projection) to complete the
271 ! structure. This allows us to eliminate redundant calculations when
272 ! calling the coordinate conversion routines multiple times for the
274 ! This will generally be the first routine called when a user wants
275 ! to be able to use the coordinate conversion routines, and it
276 ! will call the appropriate subroutines based on the
277 ! proj%code which indicates which projection type this is.
282 INTEGER, INTENT(IN) :: proj_code
283 INTEGER, INTENT(IN), OPTIONAL :: nlat
284 INTEGER, INTENT(IN), OPTIONAL :: nlon
285 INTEGER, INTENT(IN), OPTIONAL :: ixdim
286 INTEGER, INTENT(IN), OPTIONAL :: jydim
287 INTEGER, INTENT(IN), OPTIONAL :: stagger
288 REAL, INTENT(IN), OPTIONAL :: latinc
289 REAL, INTENT(IN), OPTIONAL :: loninc
290 REAL, INTENT(IN), OPTIONAL :: lat1
291 REAL, INTENT(IN), OPTIONAL :: lon1
292 REAL, INTENT(IN), OPTIONAL :: lat0
293 REAL, INTENT(IN), OPTIONAL :: lon0
294 REAL, INTENT(IN), OPTIONAL :: dx
295 REAL, INTENT(IN), OPTIONAL :: stdlon
296 REAL, INTENT(IN), OPTIONAL :: truelat1
297 REAL, INTENT(IN), OPTIONAL :: truelat2
298 REAL, INTENT(IN), OPTIONAL :: knowni
299 REAL, INTENT(IN), OPTIONAL :: knownj
300 REAL, INTENT(IN), OPTIONAL :: phi
301 REAL, INTENT(IN), OPTIONAL :: lambda
302 REAL, INTENT(IN), OPTIONAL :: r_earth
303 TYPE(proj_info), INTENT(OUT) :: proj
310 ! First, verify that mandatory parameters are present for the specified proj_code
311 IF ( proj_code == PROJ_LC ) THEN
312 IF ( .NOT.PRESENT(truelat1) .OR. &
313 .NOT.PRESENT(truelat2) .OR. &
314 .NOT.PRESENT(lat1) .OR. &
315 .NOT.PRESENT(lon1) .OR. &
316 .NOT.PRESENT(knowni) .OR. &
317 .NOT.PRESENT(knownj) .OR. &
318 .NOT.PRESENT(stdlon) .OR. &
319 .NOT.PRESENT(dx) ) THEN
320 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
321 PRINT '(A)', ' truelat1, truelat2, lat1, lon1, knowni, knownj, stdlon, dx'
322 CALL wrf_error_fatal ( 'MAP_INIT' )
324 ELSE IF ( proj_code == PROJ_PS ) THEN
325 IF ( .NOT.PRESENT(truelat1) .OR. &
326 .NOT.PRESENT(lat1) .OR. &
327 .NOT.PRESENT(lon1) .OR. &
328 .NOT.PRESENT(knowni) .OR. &
329 .NOT.PRESENT(knownj) .OR. &
330 .NOT.PRESENT(stdlon) .OR. &
331 .NOT.PRESENT(dx) ) THEN
332 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
333 PRINT '(A)', ' truelat1, lat1, lon1, knonwi, knownj, stdlon, dx'
334 CALL wrf_error_fatal ( 'MAP_INIT' )
336 ELSE IF ( proj_code == PROJ_PS_WGS84 ) THEN
337 IF ( .NOT.PRESENT(truelat1) .OR. &
338 .NOT.PRESENT(lat1) .OR. &
339 .NOT.PRESENT(lon1) .OR. &
340 .NOT.PRESENT(knowni) .OR. &
341 .NOT.PRESENT(knownj) .OR. &
342 .NOT.PRESENT(stdlon) .OR. &
343 .NOT.PRESENT(dx) ) THEN
344 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
345 PRINT '(A)', ' truelat1, lat1, lon1, knonwi, knownj, stdlon, dx'
346 CALL wrf_error_fatal ( 'MAP_INIT' )
348 ELSE IF ( proj_code == PROJ_ALBERS_NAD83 ) THEN
349 IF ( .NOT.PRESENT(truelat1) .OR. &
350 .NOT.PRESENT(truelat2) .OR. &
351 .NOT.PRESENT(lat1) .OR. &
352 .NOT.PRESENT(lon1) .OR. &
353 .NOT.PRESENT(knowni) .OR. &
354 .NOT.PRESENT(knownj) .OR. &
355 .NOT.PRESENT(stdlon) .OR. &
356 .NOT.PRESENT(dx) ) THEN
357 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
358 PRINT '(A)', ' truelat1, truelat2, lat1, lon1, knonwi, knownj, stdlon, dx'
359 CALL wrf_error_fatal ( 'MAP_INIT' )
361 ELSE IF ( proj_code == PROJ_MERC ) THEN
362 IF ( .NOT.PRESENT(truelat1) .OR. &
363 .NOT.PRESENT(lat1) .OR. &
364 .NOT.PRESENT(lon1) .OR. &
365 .NOT.PRESENT(knowni) .OR. &
366 .NOT.PRESENT(knownj) .OR. &
367 .NOT.PRESENT(dx) ) THEN
368 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
369 PRINT '(A)', ' truelat1, lat1, lon1, knowni, knownj, dx'
370 CALL wrf_error_fatal ( 'MAP_INIT' )
372 ELSE IF ( proj_code == PROJ_LATLON ) THEN
373 IF ( .NOT.PRESENT(latinc) .OR. &
374 .NOT.PRESENT(loninc) .OR. &
375 .NOT.PRESENT(knowni) .OR. &
376 .NOT.PRESENT(knownj) .OR. &
377 .NOT.PRESENT(lat1) .OR. &
378 .NOT.PRESENT(lon1) ) THEN
379 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
380 PRINT '(A)', ' latinc, loninc, knowni, knownj, lat1, lon1'
381 CALL wrf_error_fatal ( 'MAP_INIT' )
383 ELSE IF ( proj_code == PROJ_CYL ) THEN
384 IF ( .NOT.PRESENT(latinc) .OR. &
385 .NOT.PRESENT(loninc) .OR. &
386 .NOT.PRESENT(stdlon) ) THEN
387 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
388 PRINT '(A)', ' latinc, loninc, stdlon'
389 CALL wrf_error_fatal ( 'MAP_INIT' )
391 ELSE IF ( proj_code == PROJ_CASSINI ) THEN
392 IF ( .NOT.PRESENT(latinc) .OR. &
393 .NOT.PRESENT(loninc) .OR. &
394 .NOT.PRESENT(lat1) .OR. &
395 .NOT.PRESENT(lon1) .OR. &
396 .NOT.PRESENT(lat0) .OR. &
397 .NOT.PRESENT(lon0) .OR. &
398 .NOT.PRESENT(knowni) .OR. &
399 .NOT.PRESENT(knownj) .OR. &
400 .NOT.PRESENT(stdlon) ) THEN
401 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
402 PRINT '(A)', ' latinc, loninc, lat1, lon1, knowni, knownj, lat0, lon0, stdlon'
403 CALL wrf_error_fatal ( 'MAP_INIT' )
405 ELSE IF ( proj_code == PROJ_GAUSS ) THEN
406 IF ( .NOT.PRESENT(nlat) .OR. &
407 .NOT.PRESENT(lat1) .OR. &
408 .NOT.PRESENT(lon1) .OR. &
409 .NOT.PRESENT(loninc) ) THEN
410 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
411 PRINT '(A)', ' nlat, lat1, lon1, loninc'
412 CALL wrf_error_fatal ( 'MAP_INIT' )
414 ELSE IF ( proj_code == PROJ_ROTLL ) THEN
415 IF ( .NOT.PRESENT(ixdim) .OR. &
416 .NOT.PRESENT(jydim) .OR. &
417 .NOT.PRESENT(phi) .OR. &
418 .NOT.PRESENT(lambda) .OR. &
419 .NOT.PRESENT(lat1) .OR. &
420 .NOT.PRESENT(lon1) .OR. &
421 .NOT.PRESENT(stagger) ) THEN
422 PRINT '(A,I2)', 'The following are mandatory parameters for projection code : ', proj_code
423 PRINT '(A)', ' ixdim, jydim, phi, lambda, lat1, lon1, stagger'
424 CALL wrf_error_fatal ( 'MAP_INIT' )
427 PRINT '(A,I2)', 'Unknown projection code: ', proj_code
428 CALL wrf_error_fatal ( 'MAP_INIT' )
431 ! Check for validity of mandatory variables in proj
432 IF ( PRESENT(lat1) ) THEN
433 IF ( ABS(lat1) .GT. 90. ) THEN
434 PRINT '(A)', 'Latitude of origin corner required as follows:'
435 PRINT '(A)', ' -90N <= lat1 < = 90.N'
436 CALL wrf_error_fatal ( 'MAP_INIT' )
440 IF ( PRESENT(lon1) ) THEN
442 IF ( ABS(dummy_lon1) .GT. 180.) THEN
444 DO WHILE (ABS(dummy_lon1) > 180. .AND. iter < 10)
445 IF (dummy_lon1 < -180.) dummy_lon1 = dummy_lon1 + 360.
446 IF (dummy_lon1 > 180.) dummy_lon1 = dummy_lon1 - 360.
449 IF (abs(dummy_lon1) > 180.) THEN
450 PRINT '(A)', 'Longitude of origin required as follows:'
451 PRINT '(A)', ' -180E <= lon1 <= 180W'
452 CALL wrf_error_fatal ( 'MAP_INIT' )
457 IF ( PRESENT(lon0) ) THEN
459 IF ( ABS(dummy_lon0) .GT. 180.) THEN
461 DO WHILE (ABS(dummy_lon0) > 180. .AND. iter < 10)
462 IF (dummy_lon0 < -180.) dummy_lon0 = dummy_lon0 + 360.
463 IF (dummy_lon0 > 180.) dummy_lon0 = dummy_lon0 - 360.
466 IF (abs(dummy_lon0) > 180.) THEN
467 PRINT '(A)', 'Longitude of pole required as follows:'
468 PRINT '(A)', ' -180E <= lon0 <= 180W'
469 CALL wrf_error_fatal ( 'MAP_INIT' )
474 IF ( PRESENT(dx) ) THEN
475 IF ((dx .LE. 0.).AND.(proj_code .NE. PROJ_LATLON)) THEN
476 PRINT '(A)', 'Require grid spacing (dx) in meters be positive'
477 CALL wrf_error_fatal ( 'MAP_INIT' )
481 IF ( PRESENT(stdlon) ) THEN
482 dummy_stdlon = stdlon
483 IF ((ABS(dummy_stdlon) > 180.).AND.(proj_code /= PROJ_MERC)) THEN
485 DO WHILE (ABS(dummy_stdlon) > 180. .AND. iter < 10)
486 IF (dummy_stdlon < -180.) dummy_stdlon = dummy_stdlon + 360.
487 IF (dummy_stdlon > 180.) dummy_stdlon = dummy_stdlon - 360.
490 IF (abs(dummy_stdlon) > 180.) THEN
491 PRINT '(A)', 'Need orientation longitude (stdlon) as: '
492 PRINT '(A)', ' -180E <= stdlon <= 180W'
493 CALL wrf_error_fatal ( 'MAP_INIT' )
498 IF ( PRESENT(truelat1) ) THEN
499 IF (ABS(truelat1).GT.90.) THEN
500 PRINT '(A)', 'Set true latitude 1 for all projections'
501 CALL wrf_error_fatal ( 'MAP_INIT' )
506 proj%code = proj_code
507 IF ( PRESENT(lat1) ) proj%lat1 = lat1
508 IF ( PRESENT(lon1) ) proj%lon1 = dummy_lon1
509 IF ( PRESENT(lat0) ) proj%lat0 = lat0
510 IF ( PRESENT(lon0) ) proj%lon0 = dummy_lon0
511 IF ( PRESENT(latinc) ) proj%latinc = latinc
512 IF ( PRESENT(loninc) ) proj%loninc = loninc
513 IF ( PRESENT(knowni) ) proj%knowni = knowni
514 IF ( PRESENT(knownj) ) proj%knownj = knownj
515 IF ( PRESENT(dx) ) proj%dx = dx
516 IF ( PRESENT(stdlon) ) proj%stdlon = dummy_stdlon
517 IF ( PRESENT(truelat1) ) proj%truelat1 = truelat1
518 IF ( PRESENT(truelat2) ) proj%truelat2 = truelat2
519 IF ( PRESENT(nlat) ) proj%nlat = nlat
520 IF ( PRESENT(nlon) ) proj%nlon = nlon
521 IF ( PRESENT(ixdim) ) proj%ixdim = ixdim
522 IF ( PRESENT(jydim) ) proj%jydim = jydim
523 IF ( PRESENT(stagger) ) proj%stagger = stagger
524 IF ( PRESENT(phi) ) proj%phi = phi
525 IF ( PRESENT(lambda) ) proj%lambda = lambda
526 IF ( PRESENT(r_earth) ) proj%re_m = r_earth
528 IF ( PRESENT(dx) ) THEN
529 IF ( (proj_code == PROJ_LC) .OR. (proj_code == PROJ_PS) .OR. &
530 (proj_code == PROJ_PS_WGS84) .OR. (proj_code == PROJ_ALBERS_NAD83) .OR. &
531 (proj_code == PROJ_MERC) ) THEN
533 IF (truelat1 .LT. 0.) THEN
538 proj%rebydx = proj%re_m / dx
542 pick_proj: SELECT CASE(proj%code)
548 CALL set_ps_wgs84(proj)
550 CASE(PROJ_ALBERS_NAD83)
551 CALL set_albers_nad83(proj)
554 IF (ABS(proj%truelat2) .GT. 90.) THEN
555 proj%truelat2=proj%truelat1
571 CALL set_cassini(proj)
580 END SUBROUTINE map_set
583 SUBROUTINE latlon_to_ij(proj, lat, lon, i, j)
584 ! Converts input lat/lon values to the cartesian (i,j) value
585 ! for the given projection.
588 TYPE(proj_info), INTENT(IN) :: proj
589 REAL, INTENT(IN) :: lat
590 REAL, INTENT(IN) :: lon
591 REAL, INTENT(OUT) :: i
592 REAL, INTENT(OUT) :: j
594 IF (.NOT.proj%init) THEN
595 PRINT '(A)', 'You have not called map_set for this projection'
596 CALL wrf_error_fatal ( 'LATLON_TO_IJ' )
599 SELECT CASE(proj%code)
602 CALL llij_latlon(lat,lon,proj,i,j)
605 CALL llij_merc(lat,lon,proj,i,j)
608 CALL llij_ps(lat,lon,proj,i,j)
611 CALL llij_ps_wgs84(lat,lon,proj,i,j)
613 CASE(PROJ_ALBERS_NAD83)
614 CALL llij_albers_nad83(lat,lon,proj,i,j)
617 CALL llij_lc(lat,lon,proj,i,j)
620 CALL llij_gauss(lat,lon,proj,i,j)
623 CALL llij_cyl(lat,lon,proj,i,j)
626 CALL llij_cassini(lat,lon,proj,i,j)
629 CALL llij_rotlatlon(lat,lon,proj,i,j)
632 PRINT '(A,I2)', 'Unrecognized map projection code: ', proj%code
633 CALL wrf_error_fatal ( 'LATLON_TO_IJ' )
639 END SUBROUTINE latlon_to_ij
642 SUBROUTINE ij_to_latlon(proj, i, j, lat, lon)
643 ! Computes geographical latitude and longitude for a given (i,j) point
644 ! in a grid with a projection of proj
647 TYPE(proj_info),INTENT(IN) :: proj
648 REAL, INTENT(IN) :: i
649 REAL, INTENT(IN) :: j
650 REAL, INTENT(OUT) :: lat
651 REAL, INTENT(OUT) :: lon
653 IF (.NOT.proj%init) THEN
654 PRINT '(A)', 'You have not called map_set for this projection'
655 CALL wrf_error_fatal ( 'IJ_TO_LATLON' )
657 SELECT CASE (proj%code)
660 CALL ijll_latlon(i, j, proj, lat, lon)
663 CALL ijll_merc(i, j, proj, lat, lon)
666 CALL ijll_ps(i, j, proj, lat, lon)
669 CALL ijll_ps_wgs84(i, j, proj, lat, lon)
671 CASE (PROJ_ALBERS_NAD83)
672 CALL ijll_albers_nad83(i, j, proj, lat, lon)
675 CALL ijll_lc(i, j, proj, lat, lon)
678 CALL ijll_cyl(i, j, proj, lat, lon)
681 CALL ijll_cassini(i, j, proj, lat, lon)
684 CALL ijll_rotlatlon(i, j, proj, lat, lon)
687 PRINT '(A,I2)', 'Unrecognized map projection code: ', proj%code
688 CALL wrf_error_fatal ( 'IJ_TO_LATLON' )
692 END SUBROUTINE ij_to_latlon
695 SUBROUTINE set_ps(proj)
696 ! Initializes a polar-stereographic map projection from the partially
697 ! filled proj structure. This routine computes the radius to the
698 ! southwest corner and computes the i/j location of the pole for use
699 ! in llij_ps and ijll_ps.
703 TYPE(proj_info), INTENT(INOUT) :: proj
712 reflon = proj%stdlon + 90.
714 ! Compute numerator term of map scale factor
715 scale_top = 1. + proj%hemi * SIN(proj%truelat1 * rad_per_deg)
717 ! Compute radius to lower-left (SW) corner
718 ala1 = proj%lat1 * rad_per_deg
719 proj%rsw = proj%rebydx*COS(ala1)*scale_top/(1.+proj%hemi*SIN(ala1))
721 ! Find the pole point
722 alo1 = (proj%lon1 - reflon) * rad_per_deg
723 proj%polei = proj%knowni - proj%rsw * COS(alo1)
724 proj%polej = proj%knownj - proj%hemi * proj%rsw * SIN(alo1)
728 END SUBROUTINE set_ps
731 SUBROUTINE llij_ps(lat,lon,proj,i,j)
732 ! Given latitude (-90 to 90), longitude (-180 to 180), and the
733 ! standard polar-stereographic projection information via the
734 ! public proj structure, this routine returns the i/j indices which
735 ! if within the domain range from 1->nx and 1->ny, respectively.
739 ! Delcare input arguments
740 REAL, INTENT(IN) :: lat
741 REAL, INTENT(IN) :: lon
742 TYPE(proj_info),INTENT(IN) :: proj
744 ! Declare output arguments
745 REAL, INTENT(OUT) :: i !(x-index)
746 REAL, INTENT(OUT) :: j !(y-index)
748 ! Declare local variables
758 reflon = proj%stdlon + 90.
760 ! Compute numerator term of map scale factor
762 scale_top = 1. + proj%hemi * SIN(proj%truelat1 * rad_per_deg)
764 ! Find radius to desired point
765 ala = lat * rad_per_deg
766 rm = proj%rebydx * COS(ala) * scale_top/(1. + proj%hemi *SIN(ala))
767 alo = (lon - reflon) * rad_per_deg
768 i = proj%polei + rm * COS(alo)
769 j = proj%polej + proj%hemi * rm * SIN(alo)
773 END SUBROUTINE llij_ps
776 SUBROUTINE ijll_ps(i, j, proj, lat, lon)
778 ! This is the inverse subroutine of llij_ps. It returns the
779 ! latitude and longitude of an i/j point given the projection info
784 ! Declare input arguments
785 REAL, INTENT(IN) :: i ! Column
786 REAL, INTENT(IN) :: j ! Row
787 TYPE (proj_info), INTENT(IN) :: proj
789 ! Declare output arguments
790 REAL, INTENT(OUT) :: lat ! -90 -> 90 north
791 REAL, INTENT(OUT) :: lon ! -180 -> 180 East
802 ! Compute the reference longitude by rotating 90 degrees to the east
803 ! to find the longitude line parallel to the positive x-axis.
804 reflon = proj%stdlon + 90.
806 ! Compute numerator term of map scale factor
807 scale_top = 1. + proj%hemi * SIN(proj%truelat1 * rad_per_deg)
809 ! Compute radius to point of interest
811 yy = (j - proj%polej) * proj%hemi
816 lat = proj%hemi * 90.
819 gi2 = (proj%rebydx * scale_top)**2.
820 lat = deg_per_rad * proj%hemi * ASIN((gi2-r2)/(gi2+r2))
821 arccos = ACOS(xx/SQRT(r2))
823 lon = reflon + deg_per_rad * arccos
825 lon = reflon - deg_per_rad * arccos
829 ! Convert to a -180 -> 180 East convention
830 IF (lon .GT. 180.) lon = lon - 360.
831 IF (lon .LT. -180.) lon = lon + 360.
835 END SUBROUTINE ijll_ps
838 SUBROUTINE set_ps_wgs84(proj)
839 ! Initializes a polar-stereographic map projection (WGS84 ellipsoid)
840 ! from the partially filled proj structure. This routine computes the
841 ! radius to the southwest corner and computes the i/j location of the
842 ! pole for use in llij_ps and ijll_ps.
847 TYPE(proj_info), INTENT(INOUT) :: proj
850 real :: h, mc, tc, t, rho
854 mc = cos(h*proj%truelat1*rad_per_deg)/sqrt(1.0-(E_WGS84*sin(h*proj%truelat1*rad_per_deg))**2.0)
855 tc = sqrt(((1.0-sin(h*proj%truelat1*rad_per_deg))/(1.0+sin(h*proj%truelat1*rad_per_deg)))* &
856 (((1.0+E_WGS84*sin(h*proj%truelat1*rad_per_deg))/(1.0-E_WGS84*sin(h*proj%truelat1*rad_per_deg)))**E_WGS84 ))
858 ! Find the i/j location of reference lat/lon with respect to the pole of the projection
859 t = sqrt(((1.0-sin(h*proj%lat1*rad_per_deg))/(1.0+sin(h*proj%lat1*rad_per_deg)))* &
860 (((1.0+E_WGS84*sin(h*proj%lat1*rad_per_deg))/(1.0-E_WGS84*sin(h*proj%lat1*rad_per_deg)) )**E_WGS84 ) )
861 rho = h * (A_WGS84 / proj%dx) * mc * t / tc
862 proj%polei = rho * sin((h*proj%lon1 - h*proj%stdlon)*rad_per_deg)
863 proj%polej = -rho * cos((h*proj%lon1 - h*proj%stdlon)*rad_per_deg)
867 END SUBROUTINE set_ps_wgs84
870 SUBROUTINE llij_ps_wgs84(lat,lon,proj,i,j)
871 ! Given latitude (-90 to 90), longitude (-180 to 180), and the
872 ! standard polar-stereographic projection information via the
873 ! public proj structure, this routine returns the i/j indices which
874 ! if within the domain range from 1->nx and 1->ny, respectively.
879 REAL, INTENT(IN) :: lat
880 REAL, INTENT(IN) :: lon
881 REAL, INTENT(OUT) :: i !(x-index)
882 REAL, INTENT(OUT) :: j !(y-index)
883 TYPE(proj_info),INTENT(IN) :: proj
886 real :: h, mc, tc, t, rho
890 mc = cos(h*proj%truelat1*rad_per_deg)/sqrt(1.0-(E_WGS84*sin(h*proj%truelat1*rad_per_deg))**2.0)
891 tc = sqrt(((1.0-sin(h*proj%truelat1*rad_per_deg))/(1.0+sin(h*proj%truelat1*rad_per_deg)))* &
892 (((1.0+E_WGS84*sin(h*proj%truelat1*rad_per_deg))/(1.0-E_WGS84*sin(h*proj%truelat1*rad_per_deg)))**E_WGS84 ))
894 t = sqrt(((1.0-sin(h*lat*rad_per_deg))/(1.0+sin(h*lat*rad_per_deg))) * &
895 (((1.0+E_WGS84*sin(h*lat*rad_per_deg))/(1.0-E_WGS84*sin(h*lat*rad_per_deg)))**E_WGS84))
897 ! Find the x/y location of the requested lat/lon with respect to the pole of the projection
898 rho = (A_WGS84 / proj%dx) * mc * t / tc
899 i = h * rho * sin((h*lon - h*proj%stdlon)*rad_per_deg)
900 j = h *(-rho)* cos((h*lon - h*proj%stdlon)*rad_per_deg)
902 ! Get i/j relative to reference i/j
903 i = proj%knowni + (i - proj%polei)
904 j = proj%knownj + (j - proj%polej)
908 END SUBROUTINE llij_ps_wgs84
911 SUBROUTINE ijll_ps_wgs84(i, j, proj, lat, lon)
913 ! This is the inverse subroutine of llij_ps. It returns the
914 ! latitude and longitude of an i/j point given the projection info
920 REAL, INTENT(IN) :: i ! Column
921 REAL, INTENT(IN) :: j ! Row
922 REAL, INTENT(OUT) :: lat ! -90 -> 90 north
923 REAL, INTENT(OUT) :: lon ! -180 -> 180 East
924 TYPE (proj_info), INTENT(IN) :: proj
927 real :: h, mc, tc, t, rho, x, y
928 real :: chi, a, b, c, d
931 x = (i - proj%knowni + proj%polei)
932 y = (j - proj%knownj + proj%polej)
934 mc = cos(h*proj%truelat1*rad_per_deg)/sqrt(1.0-(E_WGS84*sin(h*proj%truelat1*rad_per_deg))**2.0)
935 tc = sqrt(((1.0-sin(h*proj%truelat1*rad_per_deg))/(1.0+sin(h*proj%truelat1*rad_per_deg))) * &
936 (((1.0+E_WGS84*sin(h*proj%truelat1*rad_per_deg))/(1.0-E_WGS84*sin(h*proj%truelat1*rad_per_deg)))**E_WGS84 ))
938 rho = sqrt((x*proj%dx)**2.0 + (y*proj%dx)**2.0)
939 t = rho * tc / (A_WGS84 * mc)
941 lon = h*proj%stdlon + h*atan2(h*x,h*(-y))
943 chi = PI/2.0-2.0*atan(t)
944 a = 1./2.*E_WGS84**2. + 5./24.*E_WGS84**4. + 1./40.*E_WGS84**6. + 73./2016.*E_WGS84**8.
945 b = 7./24.*E_WGS84**4. + 29./120.*E_WGS84**6. + 54113./40320.*E_WGS84**8.
946 c = 7./30.*E_WGS84**6. + 81./280.*E_WGS84**8.
947 d = 4279./20160.*E_WGS84**8.
949 lat = chi + sin(2.*chi)*(a + cos(2.*chi)*(b + cos(2.*chi)*(c + d*cos(2.*chi))))
952 lat = lat*deg_per_rad
953 lon = lon*deg_per_rad
957 END SUBROUTINE ijll_ps_wgs84
960 SUBROUTINE set_albers_nad83(proj)
961 ! Initializes an Albers equal area map projection (NAD83 ellipsoid)
962 ! from the partially filled proj structure. This routine computes the
963 ! radius to the southwest corner and computes the i/j location of the
964 ! pole for use in llij_albers_nad83 and ijll_albers_nad83.
969 TYPE(proj_info), INTENT(INOUT) :: proj
972 real :: h, m1, m2, q1, q2, theta, q, sinphi
976 m1 = cos(h*proj%truelat1*rad_per_deg)/sqrt(1.0-(E_NAD83*sin(h*proj%truelat1*rad_per_deg))**2.0)
977 m2 = cos(h*proj%truelat2*rad_per_deg)/sqrt(1.0-(E_NAD83*sin(h*proj%truelat2*rad_per_deg))**2.0)
979 sinphi = sin(proj%truelat1*rad_per_deg)
980 q1 = (1.0-E_NAD83**2.0) * &
981 ((sinphi/(1.0-(E_NAD83*sinphi)**2.0)) - 1.0/(2.0*E_NAD83) * log((1.0-E_NAD83*sinphi)/(1.0+E_NAD83*sinphi)))
983 sinphi = sin(proj%truelat2*rad_per_deg)
984 q2 = (1.0-E_NAD83**2.0) * &
985 ((sinphi/(1.0-(E_NAD83*sinphi)**2.0)) - 1.0/(2.0*E_NAD83) * log((1.0-E_NAD83*sinphi)/(1.0+E_NAD83*sinphi)))
987 if (proj%truelat1 == proj%truelat2) then
988 proj%nc = sin(proj%truelat1*rad_per_deg)
990 proj%nc = (m1**2.0 - m2**2.0) / (q2 - q1)
993 proj%bigc = m1**2.0 + proj%nc*q1
995 ! Find the i/j location of reference lat/lon with respect to the pole of the projection
996 sinphi = sin(proj%lat1*rad_per_deg)
997 q = (1.0-E_NAD83**2.0) * &
998 ((sinphi/(1.0-(E_NAD83*sinphi)**2.0)) - 1.0/(2.0*E_NAD83) * log((1.0-E_NAD83*sinphi)/(1.0+E_NAD83*sinphi)))
1000 proj%rho0 = h * (A_NAD83 / proj%dx) * sqrt(proj%bigc - proj%nc * q) / proj%nc
1001 theta = proj%nc*(proj%lon1 - proj%stdlon)*rad_per_deg
1003 proj%polei = proj%rho0 * sin(h*theta)
1004 proj%polej = proj%rho0 - proj%rho0 * cos(h*theta)
1008 END SUBROUTINE set_albers_nad83
1011 SUBROUTINE llij_albers_nad83(lat,lon,proj,i,j)
1012 ! Given latitude (-90 to 90), longitude (-180 to 180), and the
1013 ! standard projection information via the
1014 ! public proj structure, this routine returns the i/j indices which
1015 ! if within the domain range from 1->nx and 1->ny, respectively.
1020 REAL, INTENT(IN) :: lat
1021 REAL, INTENT(IN) :: lon
1022 REAL, INTENT(OUT) :: i !(x-index)
1023 REAL, INTENT(OUT) :: j !(y-index)
1024 TYPE(proj_info),INTENT(IN) :: proj
1027 real :: h, q, rho, theta, sinphi
1031 sinphi = sin(h*lat*rad_per_deg)
1033 ! Find the x/y location of the requested lat/lon with respect to the pole of the projection
1034 q = (1.0-E_NAD83**2.0) * &
1035 ((sinphi/(1.0-(E_NAD83*sinphi)**2.0)) - 1.0/(2.0*E_NAD83) * log((1.0-E_NAD83*sinphi)/(1.0+E_NAD83*sinphi)))
1037 rho = h * (A_NAD83 / proj%dx) * sqrt(proj%bigc - proj%nc * q) / proj%nc
1038 theta = proj%nc * (h*lon - h*proj%stdlon)*rad_per_deg
1040 i = h*rho*sin(theta)
1041 j = h*proj%rho0 - h*rho*cos(theta)
1043 ! Get i/j relative to reference i/j
1044 i = proj%knowni + (i - proj%polei)
1045 j = proj%knownj + (j - proj%polej)
1049 END SUBROUTINE llij_albers_nad83
1052 SUBROUTINE ijll_albers_nad83(i, j, proj, lat, lon)
1054 ! This is the inverse subroutine of llij_albers_nad83. It returns the
1055 ! latitude and longitude of an i/j point given the projection info
1061 REAL, INTENT(IN) :: i ! Column
1062 REAL, INTENT(IN) :: j ! Row
1063 REAL, INTENT(OUT) :: lat ! -90 -> 90 north
1064 REAL, INTENT(OUT) :: lon ! -180 -> 180 East
1065 TYPE (proj_info), INTENT(IN) :: proj
1068 real :: h, q, rho, theta, beta, x, y
1073 x = (i - proj%knowni + proj%polei)
1074 y = (j - proj%knownj + proj%polej)
1076 rho = sqrt(x**2.0 + (proj%rho0 - y)**2.0)
1077 theta = atan2(x, proj%rho0-y)
1079 q = (proj%bigc - (rho*proj%nc*proj%dx/A_NAD83)**2.0) / proj%nc
1081 beta = asin(q/(1.0 - log((1.0-E_NAD83)/(1.0+E_NAD83))*(1.0-E_NAD83**2.0)/(2.0*E_NAD83)))
1082 a = 1./3.*E_NAD83**2. + 31./180.*E_NAD83**4. + 517./5040.*E_NAD83**6.
1083 b = 23./360.*E_NAD83**4. + 251./3780.*E_NAD83**6.
1084 c = 761./45360.*E_NAD83**6.
1086 lat = beta + a*sin(2.*beta) + b*sin(4.*beta) + c*sin(6.*beta)
1088 lat = h*lat*deg_per_rad
1089 lon = proj%stdlon + theta*deg_per_rad/proj%nc
1093 END SUBROUTINE ijll_albers_nad83
1096 SUBROUTINE set_lc(proj)
1097 ! Initialize the remaining items in the proj structure for a
1098 ! lambert conformal grid.
1102 TYPE(proj_info), INTENT(INOUT) :: proj
1109 ! Compute cone factor
1110 CALL lc_cone(proj%truelat1, proj%truelat2, proj%cone)
1112 ! Compute longitude differences and ensure we stay out of the
1113 ! forbidden "cut zone"
1114 deltalon1 = proj%lon1 - proj%stdlon
1115 IF (deltalon1 .GT. +180.) deltalon1 = deltalon1 - 360.
1116 IF (deltalon1 .LT. -180.) deltalon1 = deltalon1 + 360.
1118 ! Convert truelat1 to radian and compute COS for later use
1119 tl1r = proj%truelat1 * rad_per_deg
1122 ! Compute the radius to our known lower-left (SW) corner
1123 proj%rsw = proj%rebydx * ctl1r/proj%cone * &
1124 (TAN((90.*proj%hemi-proj%lat1)*rad_per_deg/2.) / &
1125 TAN((90.*proj%hemi-proj%truelat1)*rad_per_deg/2.))**proj%cone
1128 arg = proj%cone*(deltalon1*rad_per_deg)
1129 proj%polei = proj%hemi*proj%knowni - proj%hemi * proj%rsw * SIN(arg)
1130 proj%polej = proj%hemi*proj%knownj + proj%rsw * COS(arg)
1134 END SUBROUTINE set_lc
1137 SUBROUTINE lc_cone(truelat1, truelat2, cone)
1139 ! Subroutine to compute the cone factor of a Lambert Conformal projection
1144 REAL, INTENT(IN) :: truelat1 ! (-90 -> 90 degrees N)
1145 REAL, INTENT(IN) :: truelat2 ! " " " " "
1148 REAL, INTENT(OUT) :: cone
1154 ! First, see if this is a secant or tangent projection. For tangent
1155 ! projections, truelat1 = truelat2 and the cone is tangent to the
1156 ! Earth's surface at this latitude. For secant projections, the cone
1157 ! intersects the Earth's surface at each of the distinctly different
1159 IF (ABS(truelat1-truelat2) .GT. 0.1) THEN
1160 cone = ALOG10(COS(truelat1*rad_per_deg)) - &
1161 ALOG10(COS(truelat2*rad_per_deg))
1162 cone = cone /(ALOG10(TAN((45.0 - ABS(truelat1)/2.0) * rad_per_deg)) - &
1163 ALOG10(TAN((45.0 - ABS(truelat2)/2.0) * rad_per_deg)))
1165 cone = SIN(ABS(truelat1)*rad_per_deg )
1170 END SUBROUTINE lc_cone
1173 SUBROUTINE ijll_lc( i, j, proj, lat, lon)
1175 ! Subroutine to convert from the (i,j) cartesian coordinate to the
1176 ! geographical latitude and longitude for a Lambert Conformal projection.
1179 ! 25 Jul 01: Corrected by B. Shaw, NOAA/FSL
1184 REAL, INTENT(IN) :: i ! Cartesian X coordinate
1185 REAL, INTENT(IN) :: j ! Cartesian Y coordinate
1186 TYPE(proj_info),INTENT(IN) :: proj ! Projection info structure
1189 REAL, INTENT(OUT) :: lat ! Latitude (-90->90 deg N)
1190 REAL, INTENT(OUT) :: lon ! Longitude (-180->180 E)
1196 REAL :: chi,chi1,chi2
1203 chi1 = (90. - proj%hemi*proj%truelat1)*rad_per_deg
1204 chi2 = (90. - proj%hemi*proj%truelat2)*rad_per_deg
1206 ! See if we are in the southern hemispere and flip the indices
1208 inew = proj%hemi * i
1209 jnew = proj%hemi * j
1211 ! Compute radius**2 to i/j location
1212 xx = inew - proj%polei
1213 yy = proj%polej - jnew
1214 r2 = (xx*xx + yy*yy)
1215 r = SQRT(r2)/proj%rebydx
1217 ! Convert to lat/lon
1218 IF (r2 .EQ. 0.) THEN
1219 lat = proj%hemi * 90.
1224 lon = proj%stdlon + deg_per_rad * ATAN2(proj%hemi*xx,yy)/proj%cone
1225 lon = MOD(lon+360., 360.)
1227 ! Latitude. Latitude determined by solving an equation adapted
1229 ! Maling, D.H., 1973: Coordinate Systems and Map Projections
1230 ! Equations #20 in Appendix I.
1232 IF (chi1 .EQ. chi2) THEN
1233 chi = 2.0*ATAN( ( r/TAN(chi1) )**(1./proj%cone) * TAN(chi1*0.5) )
1235 chi = 2.0*ATAN( (r*proj%cone/SIN(chi1))**(1./proj%cone) * TAN(chi1*0.5))
1237 lat = (90.0-chi*deg_per_rad)*proj%hemi
1241 IF (lon .GT. +180.) lon = lon - 360.
1242 IF (lon .LT. -180.) lon = lon + 360.
1246 END SUBROUTINE ijll_lc
1249 SUBROUTINE llij_lc( lat, lon, proj, i, j)
1251 ! Subroutine to compute the geographical latitude and longitude values
1252 ! to the cartesian x/y on a Lambert Conformal projection.
1257 REAL, INTENT(IN) :: lat ! Latitude (-90->90 deg N)
1258 REAL, INTENT(IN) :: lon ! Longitude (-180->180 E)
1259 TYPE(proj_info),INTENT(IN) :: proj ! Projection info structure
1262 REAL, INTENT(OUT) :: i ! Cartesian X coordinate
1263 REAL, INTENT(OUT) :: j ! Cartesian Y coordinate
1275 ! Compute deltalon between known longitude and standard lon and ensure
1276 ! it is not in the cut zone
1277 deltalon = lon - proj%stdlon
1278 IF (deltalon .GT. +180.) deltalon = deltalon - 360.
1279 IF (deltalon .LT. -180.) deltalon = deltalon + 360.
1281 ! Convert truelat1 to radian and compute COS for later use
1282 tl1r = proj%truelat1 * rad_per_deg
1285 ! Radius to desired point
1286 rm = proj%rebydx * ctl1r/proj%cone * &
1287 (TAN((90.*proj%hemi-lat)*rad_per_deg/2.) / &
1288 TAN((90.*proj%hemi-proj%truelat1)*rad_per_deg/2.))**proj%cone
1290 arg = proj%cone*(deltalon*rad_per_deg)
1291 i = proj%polei + proj%hemi * rm * SIN(arg)
1292 j = proj%polej - rm * COS(arg)
1294 ! Finally, if we are in the southern hemisphere, flip the i/j
1295 ! values to a coordinate system where (1,1) is the SW corner
1296 ! (what we assume) which is different than the original NCEP
1297 ! algorithms which used the NE corner as the origin in the
1298 ! southern hemisphere (left-hand vs. right-hand coordinate?)
1303 END SUBROUTINE llij_lc
1306 SUBROUTINE set_merc(proj)
1308 ! Sets up the remaining basic elements for the mercator projection
1311 TYPE(proj_info), INTENT(INOUT) :: proj
1315 ! Preliminary variables
1317 clain = COS(rad_per_deg*proj%truelat1)
1318 proj%dlon = proj%dx / (proj%re_m * clain)
1320 ! Compute distance from equator to origin, and store in the
1324 IF (proj%lat1 .NE. 0.) THEN
1325 proj%rsw = (ALOG(TAN(0.5*((proj%lat1+90.)*rad_per_deg))))/proj%dlon
1330 END SUBROUTINE set_merc
1333 SUBROUTINE llij_merc(lat, lon, proj, i, j)
1335 ! Compute i/j coordinate from lat lon for mercator projection
1338 REAL, INTENT(IN) :: lat
1339 REAL, INTENT(IN) :: lon
1340 TYPE(proj_info),INTENT(IN) :: proj
1341 REAL,INTENT(OUT) :: i
1342 REAL,INTENT(OUT) :: j
1345 deltalon = lon - proj%lon1
1346 IF (deltalon .LT. -180.) deltalon = deltalon + 360.
1347 IF (deltalon .GT. 180.) deltalon = deltalon - 360.
1348 i = proj%knowni + (deltalon/(proj%dlon*deg_per_rad))
1349 j = proj%knownj + (ALOG(TAN(0.5*((lat + 90.) * rad_per_deg)))) / &
1350 proj%dlon - proj%rsw
1354 END SUBROUTINE llij_merc
1357 SUBROUTINE ijll_merc(i, j, proj, lat, lon)
1359 ! Compute the lat/lon from i/j for mercator projection
1362 REAL,INTENT(IN) :: i
1363 REAL,INTENT(IN) :: j
1364 TYPE(proj_info),INTENT(IN) :: proj
1365 REAL, INTENT(OUT) :: lat
1366 REAL, INTENT(OUT) :: lon
1369 lat = 2.0*ATAN(EXP(proj%dlon*(proj%rsw + j-proj%knownj)))*deg_per_rad - 90.
1370 lon = (i-proj%knowni)*proj%dlon*deg_per_rad + proj%lon1
1371 IF (lon.GT.180.) lon = lon - 360.
1372 IF (lon.LT.-180.) lon = lon + 360.
1375 END SUBROUTINE ijll_merc
1378 SUBROUTINE llij_latlon(lat, lon, proj, i, j)
1380 ! Compute the i/j location of a lat/lon on a LATLON grid.
1382 REAL, INTENT(IN) :: lat
1383 REAL, INTENT(IN) :: lon
1384 TYPE(proj_info), INTENT(IN) :: proj
1385 REAL, INTENT(OUT) :: i
1386 REAL, INTENT(OUT) :: j
1391 ! Compute deltalat and deltalon as the difference between the input
1392 ! lat/lon and the origin lat/lon
1393 deltalat = lat - proj%lat1
1394 deltalon = lon - proj%lon1
1397 i = deltalon/proj%loninc
1398 j = deltalat/proj%latinc
1405 END SUBROUTINE llij_latlon
1408 SUBROUTINE ijll_latlon(i, j, proj, lat, lon)
1410 ! Compute the lat/lon location of an i/j on a LATLON grid.
1412 REAL, INTENT(IN) :: i
1413 REAL, INTENT(IN) :: j
1414 TYPE(proj_info), INTENT(IN) :: proj
1415 REAL, INTENT(OUT) :: lat
1416 REAL, INTENT(OUT) :: lon
1418 REAL :: i_work, j_work
1422 i_work = i - proj%knowni
1423 j_work = j - proj%knownj
1425 ! Compute deltalat and deltalon
1426 deltalat = j_work*proj%latinc
1427 deltalon = i_work*proj%loninc
1429 lat = proj%lat1 + deltalat
1430 lon = proj%lon1 + deltalon
1434 END SUBROUTINE ijll_latlon
1437 SUBROUTINE set_cyl(proj)
1442 type(proj_info), intent(inout) :: proj
1446 END SUBROUTINE set_cyl
1449 SUBROUTINE llij_cyl(lat, lon, proj, i, j)
1454 real, intent(in) :: lat, lon
1455 real, intent(out) :: i, j
1456 type(proj_info), intent(in) :: proj
1462 ! Compute deltalat and deltalon as the difference between the input
1463 ! lat/lon and the origin lat/lon
1464 deltalat = lat - proj%lat1
1465 ! deltalon = lon - proj%stdlon
1466 deltalon = lon - proj%lon1
1468 if (deltalon < 0.) deltalon = deltalon + 360.
1469 if (deltalon > 360.) deltalon = deltalon - 360.
1472 i = deltalon/proj%loninc
1473 j = deltalat/proj%latinc
1475 if (i <= 0.) i = i + 360./proj%loninc
1476 if (i > 360./proj%loninc) i = i - 360./proj%loninc
1481 END SUBROUTINE llij_cyl
1484 SUBROUTINE ijll_cyl(i, j, proj, lat, lon)
1489 real, intent(in) :: i, j
1490 real, intent(out) :: lat, lon
1491 type(proj_info), intent(in) :: proj
1496 real :: i_work, j_work
1498 i_work = i - proj%knowni
1499 j_work = j - proj%knownj
1501 if (i_work < 0.) i_work = i_work + 360./proj%loninc
1502 if (i_work >= 360./proj%loninc) i_work = i_work - 360./proj%loninc
1504 ! Compute deltalat and deltalon
1505 deltalat = j_work*proj%latinc
1506 deltalon = i_work*proj%loninc
1508 lat = deltalat + proj%lat1
1509 ! lon = deltalon + proj%stdlon
1510 lon = deltalon + proj%lon1
1512 if (lon < -180.) lon = lon + 360.
1513 if (lon > 180.) lon = lon - 360.
1515 END SUBROUTINE ijll_cyl
1518 SUBROUTINE set_cassini(proj)
1523 type(proj_info), intent(inout) :: proj
1526 real :: comp_lat, comp_lon
1527 logical :: global_domain
1531 ! Try to determine whether this domain has global coverage
1532 if (abs(proj%lat1 - proj%latinc/2. + 90.) < 0.001 .and. &
1533 abs(mod(proj%lon1 - proj%loninc/2. - proj%stdlon,360.)) < 0.001) then
1534 global_domain = .true.
1536 global_domain = .false.
1539 if (abs(proj%lat0) /= 90. .and. .not.global_domain) then
1540 call rotate_coords(proj%lat1,proj%lon1,comp_lat,comp_lon,proj%lat0,proj%lon0,proj%stdlon,-1)
1541 proj%lat1 = comp_lat
1542 proj%lon1 = comp_lon
1545 END SUBROUTINE set_cassini
1548 SUBROUTINE llij_cassini(lat, lon, proj, i, j)
1553 real, intent(in) :: lat, lon
1554 real, intent(out) :: i, j
1555 type(proj_info), intent(in) :: proj
1558 real :: comp_lat, comp_lon
1560 ! Convert geographic to computational lat/lon
1561 if (abs(proj%lat0) /= 90.) then
1562 call rotate_coords(lat,lon,comp_lat,comp_lon,proj%lat0,proj%lon0,proj%stdlon,-1)
1568 ! Convert computational lat/lon to i/j
1569 call llij_cyl(comp_lat, comp_lon, proj, i, j)
1571 END SUBROUTINE llij_cassini
1574 SUBROUTINE ijll_cassini(i, j, proj, lat, lon)
1579 real, intent(in) :: i, j
1580 real, intent(out) :: lat, lon
1581 type(proj_info), intent(in) :: proj
1584 real :: comp_lat, comp_lon
1586 ! Convert i/j to computational lat/lon
1587 call ijll_cyl(i, j, proj, comp_lat, comp_lon)
1589 ! Convert computational to geographic lat/lon
1590 if (abs(proj%lat0) /= 90.) then
1591 call rotate_coords(comp_lat,comp_lon,lat,lon,proj%lat0,proj%lon0,proj%stdlon,1)
1597 END SUBROUTINE ijll_cassini
1600 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1601 ! Purpose: Converts between computational and geographic lat/lon for Cassini
1603 ! Notes: This routine was provided by Bill Skamarock, 2007-03-27
1604 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1605 SUBROUTINE rotate_coords(ilat,ilon,olat,olon,lat_np,lon_np,lon_0,direction)
1609 REAL, INTENT(IN ) :: ilat, ilon
1610 REAL, INTENT( OUT) :: olat, olon
1611 REAL, INTENT(IN ) :: lat_np, lon_np, lon_0
1612 INTEGER, INTENT(IN ), OPTIONAL :: direction
1613 ! >=0, default : computational -> geographical
1614 ! < 0 : geographical -> computational
1617 REAL :: phi_np, lam_np, lam_0, dlam
1618 REAL :: sinphi, cosphi, coslam, sinlam
1620 ! Convert all angles to radians
1621 phi_np = lat_np * rad_per_deg
1622 lam_np = lon_np * rad_per_deg
1623 lam_0 = lon_0 * rad_per_deg
1624 rlat = ilat * rad_per_deg
1625 rlon = ilon * rad_per_deg
1627 IF (PRESENT(direction) .AND. (direction < 0)) THEN
1628 ! The equations are exactly the same except for one small difference
1629 ! with respect to longitude ...
1634 sinphi = COS(phi_np)*COS(rlat)*COS(rlon-dlam) + SIN(phi_np)*SIN(rlat)
1635 cosphi = SQRT(1.-sinphi*sinphi)
1636 coslam = SIN(phi_np)*COS(rlat)*COS(rlon-dlam) - COS(phi_np)*SIN(rlat)
1637 sinlam = COS(rlat)*SIN(rlon-dlam)
1638 IF ( cosphi /= 0. ) THEN
1639 coslam = coslam/cosphi
1640 sinlam = sinlam/cosphi
1642 olat = deg_per_rad*ASIN(sinphi)
1643 olon = deg_per_rad*(ATAN2(sinlam,coslam)-dlam-lam_0+lam_np)
1644 ! Both of my F90 text books prefer the DO-EXIT form, and claim it is faster
1645 ! when optimization is turned on (as we will always do...)
1647 IF (olon >= -180.) EXIT
1651 IF (olon <= 180.) EXIT
1655 END SUBROUTINE rotate_coords
1658 SUBROUTINE llij_rotlatlon(lat, lon, proj, i_real, j_real)
1663 REAL, INTENT(IN) :: lat, lon
1665 REAL, INTENT(OUT) :: i_real, j_real
1666 TYPE (proj_info), INTENT(IN) :: proj
1669 INTEGER :: ii,imt,jj,jmt,k,krows,ncol,nrow,iri
1670 REAL(KIND=HIGH) :: dphd,dlmd !Grid increments, degrees
1671 REAL(KIND=HIGH) :: glatd !Geographic latitude, positive north
1672 REAL(KIND=HIGH) :: glond !Geographic longitude, positive west
1673 REAL(KIND=HIGH) :: col,d1,d2,d2r,dlm,dlm1,dlm2,dph,glat,glon, &
1674 pi,r2d,row,tlat,tlat1,tlat2, &
1675 tlon,tlon1,tlon2,tph0,tlm0,x,y,z
1680 dphd = proj%phi/REAL((proj%jydim-1)/2)
1681 dlmd = proj%lambda/REAL(proj%ixdim-1)
1687 imt = 2*proj%ixdim-1
1688 jmt = proj%jydim/2+1
1694 tph0 = proj%lat1*d2r
1695 tlm0 = -proj%lon1*d2r
1697 x = COS(tph0)*COS(glat)*COS(glon-tlm0)+SIN(tph0)*SIN(glat)
1698 y = -COS(glat)*SIN(glon-tlm0)
1699 z = COS(tph0)*SIN(glat)-SIN(tph0)*COS(glat)*COS(glon-tlm0)
1700 tlat = r2d*ATAN(z/SQRT(x*x+y*y))
1701 tlon = r2d*ATAN(y/x)
1704 col = tlon/dlmd+proj%ixdim
1706 if ( (row - INT(row)) .gt. 0.999) then
1708 else if ( (col - INT(col)) .gt. 0.999) then
1722 IF (proj%stagger == HH) THEN
1724 IF (mod(nrow,2) .eq. 0) then
1727 i_real = col / 2.0 + 0.5
1732 IF ((abs(MOD(nrow,2)) == 1 .AND. abs(MOD(ncol,2)) == 1) .OR. &
1733 (MOD(nrow,2) == 0 .AND. MOD(ncol,2) == 0)) THEN
1735 tlat1 = (nrow-jmt)*dph
1737 tlon1 = (ncol-proj%ixdim)*dlm
1742 d1 = ACOS(COS(tlat)*COS(tlat1)*COS(dlm1)+SIN(tlat)*SIN(tlat1))
1743 d2 = ACOS(COS(tlat)*COS(tlat2)*COS(dlm2)+SIN(tlat)*SIN(tlat2))
1751 tlat1 = (nrow+1-jmt)*dph
1753 tlon1 = (ncol-proj%ixdim)*dlm
1757 d1 = ACOS(COS(tlat)*COS(tlat1)*COS(dlm1)+SIN(tlat)*SIN(tlat1))
1758 d2 = ACOS(COS(tlat)*COS(tlat2)*COS(dlm2)+SIN(tlat)*SIN(tlat2))
1767 ELSE IF (proj%stagger == VV) THEN
1769 IF (mod(nrow,2) .eq. 0) then
1770 i_real = col / 2.0 + 0.5
1776 IF ((MOD(nrow,2) == 0 .AND. abs(MOD(ncol,2)) == 1) .OR. &
1777 (abs(MOD(nrow,2)) == 1 .AND. MOD(ncol,2) == 0)) THEN
1778 tlat1 = (nrow-jmt)*dph
1780 tlon1 = (ncol-proj%ixdim)*dlm
1784 d1 = ACOS(COS(tlat)*COS(tlat1)*COS(dlm1)+SIN(tlat)*SIN(tlat1))
1785 d2 = ACOS(COS(tlat)*COS(tlat2)*COS(dlm2)+SIN(tlat)*SIN(tlat2))
1793 tlat1 = (nrow+1-jmt)*dph
1795 tlon1 = (ncol-proj%ixdim)*dlm
1799 d1 = ACOS(COS(tlat)*COS(tlat1)*COS(dlm1)+SIN(tlat)*SIN(tlat1))
1800 d2 = ACOS(COS(tlat)*COS(tlat2)*COS(dlm2)+SIN(tlat)*SIN(tlat2))
1811 !!! Added next line as a Kludge - not yet understood why needed
1812 if (ncol .le. 0) ncol=ncol-1
1817 IF (proj%stagger == HH) THEN
1818 IF (abs(MOD(jj,2)) == 1) ii = ii+1
1819 ELSE IF (proj%stagger == VV) THEN
1820 IF (MOD(jj,2) == 0) ii=ii+1
1826 END SUBROUTINE llij_rotlatlon
1829 SUBROUTINE ijll_rotlatlon(i, j, proj, lat,lon)
1834 REAL, INTENT(IN) :: i, j
1835 REAL, INTENT(OUT) :: lat, lon
1836 TYPE (proj_info), INTENT(IN) :: proj
1840 INTEGER :: midcol,midrow,ncol,iadd1,iadd2,imt,jh2,knrow,krem,kv,nrow
1841 REAL :: i_work, j_work
1842 REAL :: dphd,dlmd !Grid increments, degrees
1843 REAL(KIND=HIGH) :: arg1,arg2,d2r,fctr,glatr,glatd,glond,pi, &
1844 r2d,tlatd,tlond,tlatr,tlonr,tlm0,tph0
1850 if ( (j - INT(j)) .gt. 0.999) then
1856 dphd = proj%phi/REAL((proj%jydim-1)/2)
1857 dlmd = proj%lambda/REAL(proj%ixdim-1)
1862 tph0 = proj%lat1*d2r
1863 tlm0 = -proj%lon1*d2r
1865 midrow = (proj%jydim+1)/2
1868 col = 2*i_work-1+abs(MOD(jh+1,2))
1869 tlatd = (j_work-midrow)*dphd
1870 tlond = (col-midcol)*dlmd
1872 IF (proj%stagger == VV) THEN
1873 if (mod(jh,2) .eq. 0) then
1874 tlond = tlond - DLMD
1876 tlond = tlond + DLMD
1882 arg1 = SIN(tlatr)*COS(tph0)+COS(tlatr)*SIN(tph0)*COS(tlonr)
1887 arg2 = COS(tlatr)*COS(tlonr)/(COS(glatr)*COS(tph0))-TAN(glatr)*TAN(tph0)
1888 IF (ABS(arg2) > 1.) arg2 = ABS(arg2)/arg2
1890 IF (tlond > 0.) fctr = -1.
1892 glond = tlm0*r2d+fctr*ACOS(arg2)*r2d
1897 IF (lon .GT. +180.) lon = lon - 360.
1898 IF (lon .LT. -180.) lon = lon + 360.
1900 END SUBROUTINE ijll_rotlatlon
1903 SUBROUTINE set_gauss(proj)
1908 type (proj_info), intent(inout) :: proj
1910 ! Initialize the array that will hold the Gaussian latitudes.
1912 IF ( ASSOCIATED( proj%gauss_lat ) ) THEN
1913 DEALLOCATE ( proj%gauss_lat )
1916 ! Get the needed space for our array.
1918 ALLOCATE ( proj%gauss_lat(proj%nlat*2) )
1920 ! Compute the Gaussian latitudes.
1922 CALL gausll( proj%nlat*2 , proj%gauss_lat )
1924 ! Now, these could be upside down from what we want, so let's check.
1925 ! We take advantage of the equatorial symmetry to remove any sort of
1926 ! array re-ordering.
1928 IF ( ABS(proj%gauss_lat(1) - proj%lat1) .GT. 0.01 ) THEN
1929 proj%gauss_lat = -1. * proj%gauss_lat
1932 ! Just a sanity check.
1934 IF ( ABS(proj%gauss_lat(1) - proj%lat1) .GT. 0.01 ) THEN
1935 PRINT '(A)','Oops, something is not right with the Gaussian latitude computation.'
1936 PRINT '(A,F8.3,A)','The input data gave the starting latitude as ',proj%lat1,'.'
1937 PRINT '(A,F8.3,A)','This routine computed the starting latitude as +-',ABS(proj%gauss_lat(1)),'.'
1938 PRINT '(A,F8.3,A)','The difference is larger than 0.01 degrees, which is not expected.'
1939 CALL wrf_error_fatal ( 'Gaussian_latitude_computation' )
1942 END SUBROUTINE set_gauss
1945 SUBROUTINE gausll ( nlat , lat_sp )
1950 REAL (KIND=HIGH) , PARAMETER :: pi = 3.141592653589793
1951 REAL (KIND=HIGH) , DIMENSION(nlat) :: cosc , gwt , sinc , colat , wos2 , lat
1952 REAL , DIMENSION(nlat) :: lat_sp
1954 CALL lggaus(nlat, cosc, gwt, sinc, colat, wos2)
1957 lat(i) = ACOS(sinc(i)) * 180._HIGH / pi
1958 IF (i.gt.nlat/2) lat(i) = -lat(i)
1963 END SUBROUTINE gausll
1966 SUBROUTINE lggaus( nlat, cosc, gwt, sinc, colat, wos2 )
1970 ! LGGAUS finds the Gaussian latitudes by finding the roots of the
1971 ! ordinary Legendre polynomial of degree NLAT using Newton's
1975 integer NLAT ! the number of latitudes (degree of the polynomial)
1977 ! On exit: for each Gaussian latitude
1978 ! COSC - cos(colatitude) or sin(latitude)
1979 ! GWT - the Gaussian weights
1980 ! SINC - sin(colatitude) or cos(latitude)
1981 ! COLAT - the colatitudes in radians
1982 ! WOS2 - Gaussian weight over sin**2(colatitude)
1984 REAL (KIND=HIGH) , DIMENSION(nlat) :: cosc , gwt , sinc , colat , wos2
1985 REAL (KIND=HIGH) , PARAMETER :: pi = 3.141592653589793
1987 ! Convergence criterion for iteration of cos latitude
1989 REAL , PARAMETER :: xlim = 1.0E-14
1991 INTEGER :: nzero, i, j
1992 REAL (KIND=HIGH) :: fi, fi1, a, b, g, gm, gp, gt, delta, c, d
1994 ! The number of zeros between pole and equator
1998 ! Set first guess for cos(colat)
2001 cosc(i) = SIN( (i-0.5)*pi/nlat + pi*0.5 )
2004 ! Constants for determining the derivative of the polynomial
2007 a = fi*fi1 / SQRT(4.0*fi1*fi1-1.0)
2008 b = fi1*fi / SQRT(4.0*fi*fi-1.0)
2010 ! Loop over latitudes, iterating the search for each root
2015 ! Determine the value of the ordinary Legendre polynomial for
2016 ! the current guess root
2019 CALL lgord( g, cosc(i), nlat )
2021 ! Determine the derivative of the polynomial at this point
2023 CALL lgord( gm, cosc(i), nlat-1 )
2024 CALL lgord( gp, cosc(i), nlat+1 )
2025 gt = (cosc(i)*cosc(i)-1.0) / (a*gp-b*gm)
2027 ! Update the estimate of the root
2030 cosc(i) = cosc(i) - delta
2032 ! If convergence criterion has not been met, keep trying
2035 IF( ABS(delta).GT.xlim ) CYCLE
2037 ! Determine the Gaussian weights
2039 c = 2.0 *( 1.0-cosc(i)*cosc(i) )
2040 CALL lgord( d, cosc(i), nlat-1 )
2042 gwt(i) = c *( fi-0.5 ) / d
2049 ! Determine the colatitudes and sin(colat) and weights over sin**2
2052 colat(i)= ACOS(cosc(i))
2053 sinc(i) = SIN(colat(i))
2054 wos2(i) = gwt(i) /( sinc(i)*sinc(i) )
2057 ! If NLAT is odd, set values at the equator
2059 IF( MOD(nlat,2) .NE. 0 ) THEN
2063 CALL lgord( d, cosc(i), nlat-1 )
2065 gwt(i) = c *( fi-0.5 ) / d
2071 ! Determine the southern hemisphere values by symmetry
2073 DO i=nlat-nzero+1,nlat
2074 cosc(i) =-cosc(nlat+1-i)
2075 gwt(i) = gwt(nlat+1-i)
2076 colat(i)= pi-colat(nlat+1-i)
2077 sinc(i) = sinc(nlat+1-i)
2078 wos2(i) = wos2(nlat+1-i)
2081 END SUBROUTINE lggaus
2084 SUBROUTINE lgord( f, cosc, n )
2088 ! LGORD calculates the value of an ordinary Legendre polynomial at a
2089 ! specific latitude.
2092 ! cosc - COS(colatitude)
2093 ! n - the degree of the polynomial
2096 ! f - the value of the Legendre polynomial of degree N at
2097 ! latitude ASIN(cosc)
2099 REAL (KIND=HIGH) :: s1, c4, a, b, fk, f, cosc, colat, c1, fn, ang
2102 ! Determine the colatitude
2108 c1 = c1 * SQRT( 1.0 - 1.0/(4*k*k) )
2118 IF (k.eq.n) c4 = 0.5 * c4
2119 s1 = s1 + c4 * COS(ang)
2123 ang= colat * (fn-fk-2.0)
2124 c4 = ( a * (fn-b+1.0) / ( b * (fn+fn-a) ) ) * c4
2129 END SUBROUTINE lgord
2132 SUBROUTINE llij_gauss (lat, lon, proj, i, j)
2136 REAL , INTENT(IN) :: lat, lon
2137 REAL , INTENT(OUT) :: i, j
2138 TYPE (proj_info), INTENT(IN) :: proj
2140 INTEGER :: n , n_low
2141 LOGICAL :: found = .FALSE.
2142 REAL :: diff_1 , diff_nlat
2144 ! The easy one first, get the x location. The calling routine has already made
2145 ! sure that the necessary assumptions concerning the sign of the deltalon and the
2146 ! relative east/west'ness of the longitude and the starting longitude are consistent
2147 ! to allow this easy computation.
2149 i = ( lon - proj%lon1 ) / proj%loninc + 1.
2151 ! Since this is a global data set, we need to be concerned about wrapping the
2152 ! fields around the globe.
2154 ! IF ( ( proj%loninc .GT. 0 ) .AND. &
2155 ! ( FLOOR((lon-proj%lon1)/proj%loninc) + 1 .GE. proj%ixdim ) .AND. &
2156 ! ( lon + proj%loninc .GE. proj%lon1 + 360 ) ) THEN
2157 !! BUG: We may need to set proj%wrap, but proj is intent(in)
2158 !! WHAT IS THIS USED FOR?
2159 !! proj%wrap = .TRUE.
2161 ! ELSE IF ( ( proj%loninc .LT. 0 ) .AND. &
2162 ! ( FLOOR((lon-proj%lon1)/proj%loninc) + 1 .GE. proj%ixdim ) .AND. &
2163 ! ( lon + proj%loninc .LE. proj%lon1 - 360 ) ) THEN
2164 ! ! BUG: We may need to set proj%wrap, but proj is intent(in)
2165 ! ! WHAT IS THIS USED FOR?
2166 ! ! proj%wrap = .TRUE.
2170 ! Yet another quicky test, can we find bounding values? If not, then we may be
2171 ! dealing with putting data to a polar projection, so just give them them maximal
2172 ! value for the location. This is an OK assumption for the interpolation across the
2173 ! top of the pole, given how close the longitude lines are.
2175 IF ( ABS(lat) .GT. ABS(proj%gauss_lat(1)) ) THEN
2177 diff_1 = lat - proj%gauss_lat(1)
2178 diff_nlat = lat - proj%gauss_lat(proj%nlat*2)
2180 IF ( ABS(diff_1) .LT. ABS(diff_nlat) ) THEN
2186 ! If the latitude is between the two bounding values, we have to search and interpolate.
2190 DO n = 1 , proj%nlat*2 -1
2191 IF ( ( proj%gauss_lat(n) - lat ) * ( proj%gauss_lat(n+1) - lat ) .LE. 0 ) THEN
2198 ! Everything still OK?
2200 IF ( .NOT. found ) THEN
2201 PRINT '(A)','Troubles in river city. No bounding values of latitude found in the Gaussian routines.'
2202 CALL wrf_error_fatal ( 'Gee_no_bounding_lats_Gaussian' )
2205 j = ( ( proj%gauss_lat(n_low) - lat ) * ( n_low + 1 ) + &
2206 ( lat - proj%gauss_lat(n_low+1) ) * ( n_low ) ) / &
2207 ( proj%gauss_lat(n_low) - proj%gauss_lat(n_low+1) )
2211 END SUBROUTINE llij_gauss
2213 END MODULE module_llxy