NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
w3fb12.f
Go to the documentation of this file.
1C> @file
2C> @brief Lambert(i,j) to lat/lon for grib.
3C> @author John Stackpole @date 1988-11-25
4
5C> Converts the coordinates of a location on Earth given in a
6C> grid coordinate system overlaid on a lambert conformal tangent
7C> cone projection true at a given N or S latitude to the
8C> natural coordinate system of latitude/longitude
9C> w3fb12() is the reverse of w3fb11().
10C> Uses grib specification of the location of the grid
11C>
12C> PROGRAM HISTORY LOG:
13C> - John Stackpole 1988-11-25
14C> - Ralph Jones 1990-04-12 Convert to cft77 fortran.
15C> - Ralph Jones 1994-04-28 Add save statement.
16C>
17C> @param[in] XI I coordinate of the point real*4
18C> @param[in] XJ J coordinate of the point real*4
19C> @param[in] ALAT1 Latitude of lower left point of grid (point 1,1)
20C> latitude <0 for southern hemisphere; real*4
21C> @param[in] ELON1 Longitude of lower left point of grid (point 1,1)
22C> east longitude used throughout; real*4
23C> @param[in] DX Mesh length of grid in meters at tangent latitude
24C> @param[in] ELONV The orientation of the grid. i.e.,
25C> the east longitude value of the vertical meridian
26C> which is parallel to the y-axis (or columns of
27C> the grid) along which latitude increases as
28C> the y-coordinate increases. real*4
29C> this is also the meridian (on the other side of the
30C> tangent cone) along which the cut is made to lay
31C> the cone flat.
32C> @param[in] ALATAN The latitude at which the lambert cone is tangent to
33C> (touches or osculates) the spherical Earth.
34C> set negative to indicate a
35C> southern hemisphere projection; real*4
36C>
37C> @param[out] ALAT Latitude in degrees (negative in southern hemi.)
38C> @param[out] ELON East longitude in degrees, real*4
39C> @param[out] IERR
40C> - .eq. 0 if no problem
41C> - .ge. 1 if the requested xi,xj point is in the
42C> forbidden zone, i.e. off the lambert map
43C> in the open space where the cone is cut.
44C> - if ierr.ge.1 then alat=999. and elon=999.
45C>
46C> @note Formulae and notation loosely based on hoke, hayes,
47C> and renninger's "map projections and grid systems...", march 1981
48C> afgwc/tn-79/003
49C>
50C> @author John Stackpole @date 1988-11-25
51 SUBROUTINE w3fb12(XI,XJ,ALAT1,ELON1,DX,ELONV,ALATAN,ALAT,ELON,
52 & IERR)
53C
54 LOGICAL NEWMAP
55C
56 SAVE
57C
58 DATA rerth /6.3712e+6/, pi/3.14159/, oldrml/99999./
59C
60C PRELIMINARY VARIABLES AND REDIFINITIONS
61C
62C H = 1 FOR NORTHERN HEMISPHERE; = -1 FOR SOUTHERN
63C
64 IF (alatan.GT.0) THEN
65 h = 1.
66 ELSE
67 h = -1.
68 ENDIF
69C
70 piby2 = pi / 2.0
71 radpd = pi / 180.0
72 degprd = 1.0 / radpd
73 rebydx = rerth / dx
74 alatn1 = alatan * radpd
75 an = h * sin(alatn1)
76 cosltn = cos(alatn1)
77C
78C MAKE SURE THAT INPUT LONGITUDE DOES NOT PASS THROUGH
79C THE CUT ZONE (FORBIDDEN TERRITORY) OF THE FLAT MAP
80C AS MEASURED FROM THE VERTICAL (REFERENCE) LONGITUDE
81C
82 elon1l = elon1
83 IF ((elon1-elonv).GT.180.)
84 & elon1l = elon1 - 360.
85 IF ((elon1-elonv).LT.(-180.))
86 & elon1l = elon1 + 360.
87C
88 elonvr = elonv * radpd
89C
90C RADIUS TO LOWER LEFT HAND (LL) CORNER
91C
92 ala1 = alat1 * radpd
93 rmll = rebydx * ((cosltn**(1.-an))*(1.+an)**an) *
94 & (((cos(ala1))/(1.+h*sin(ala1)))**an)/an
95C
96C USE RMLL TO TEST IF MAP AND GRID UNCHANGED FROM PREVIOUS
97C CALL TO THIS CODE. THUS AVOID UNNEEDED RECOMPUTATIONS.
98C
99 IF (rmll.EQ.oldrml) THEN
100 newmap = .false.
101 ELSE
102 newmap = .true.
103 oldrml = rmll
104C
105C USE LL POINT INFO TO LOCATE POLE POINT
106C
107 elo1 = elon1l * radpd
108 arg = an * (elo1-elonvr)
109 polei = 1. - h * rmll * sin(arg)
110 polej = 1. + rmll * cos(arg)
111 ENDIF
112C
113C RADIUS TO THE I,J POINT (IN GRID UNITS)
114C YY REVERSED SO POSITIVE IS DOWN
115C
116 xx = xi - polei
117 yy = polej - xj
118 r2 = xx**2 + yy**2
119C
120C CHECK THAT THE REQUESTED I,J IS NOT IN THE FORBIDDEN ZONE
121C YY MUST BE POSITIVE UP FOR THIS TEST
122C
123 theta = pi*(1.-an)
124 beta = abs(atan2(xx,-yy))
125 ierr = 0
126 IF (beta.LE.theta) THEN
127 ierr = 1
128 alat = 999.
129 elon = 999.
130 IF (.NOT.newmap) RETURN
131 ENDIF
132C
133C NOW THE MAGIC FORMULAE
134C
135 IF (r2.EQ.0) THEN
136 alat = h * 90.0
137 elon = elonv
138 ELSE
139C
140C FIRST THE LONGITUDE
141C
142 elon = elonv + degprd * atan2(h*xx,yy)/an
143 elon = amod(elon+360., 360.)
144C
145C NOW THE LATITUDE
146C RECALCULATE THE THING ONLY IF MAP IS NEW SINCE LAST TIME
147C
148 IF (newmap) THEN
149 aninv = 1./an
150 aninv2 = aninv/2.
151 thing = ((an/rebydx) ** aninv)/
152 & ((cosltn**((1.-an)*aninv))*(1.+ an))
153 ENDIF
154 alat = h*(piby2 - 2.*atan(thing*(r2**aninv2)))*degprd
155 ENDIF
156C
157C FOLLOWING TO ASSURE ERROR VALUES IF FIRST TIME THRU
158C IS OFF THE MAP
159C
160 IF (ierr.NE.0) THEN
161 alat = 999.
162 elon = 999.
163 ierr = 2
164 ENDIF
165 RETURN
166 END
subroutine w3fb12(xi, xj, alat1, elon1, dx, elonv, alatan, alat, elon, ierr)
Converts the coordinates of a location on Earth given in a grid coordinate system overlaid on a lambe...
Definition w3fb12.f:53