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