-
Notifications
You must be signed in to change notification settings - Fork 2
/
unrotMe.f90
300 lines (259 loc) · 9.16 KB
/
unrotMe.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
PROGRAM unrotMe
IMPLICIT NONE
DOUBLE PRECISION :: lon_rot_in, lat_rot_in, lon_pol_in, lat_pol_in
DOUBLE PRECISION :: phirot2phi, rlarot2rla
DOUBLE PRECISION :: phirot2phi_out, rlarot2rla_out
INTEGER :: phirot2phi_deg, rlarot2rla_deg
DOUBLE PRECISION :: phirot2phi_min, rlarot2rla_min
CALL GET_COORDS(lat_rot_in,lon_rot_in,lat_pol_in,lon_pol_in)
lat_pol_in = 89.208767
lon_pol_in = 179.050450D0
phirot2phi_out = phirot2phi(lat_rot_in,lon_rot_in,lat_pol_in,lon_pol_in,0.0D0)
rlarot2rla_out = rlarot2rla(lat_rot_in,lon_rot_in,lat_pol_in,lon_pol_in,0.0D0)
phirot2phi_deg = INT(phirot2phi_out)
rlarot2rla_deg = INT(rlarot2rla_out)
phirot2phi_min = (phirot2phi_out - DBLE(INT(phirot2phi_out))) * 60.0D0
rlarot2rla_min = (rlarot2rla_out - DBLE(INT(rlarot2rla_out))) * 60.0D0
IF ( phirot2phi_min >= 59.9995D0 )THEN
phirot2phi_deg = phirot2phi_deg + 1.0D0
phirot2phi_min = 0.D0
END IF
IF ( rlarot2rla_min >= 59.9995D0 )THEN
rlarot2rla_deg = rlarot2rla_deg + 1.0D0
rlarot2rla_min = 0.D0
END IF
! WRITE(*,'(A2,F13.10,A2,F13.10)') &
! ' N',phirot2phi_out, &
! ' E',rlarot2rla_out
WRITE(*,*)
WRITE(*,*) 'The given point in the rotated system is located at:'
WRITE(*,"(' N',I2,'°',F6.3,A1,' E',I3.3,'°',F6.3,A1)") &
phirot2phi_deg, phirot2phi_min, "'", &
rlarot2rla_deg, rlarot2rla_min, "'"
WRITE(*,*) 'in the unrotated geographic system!'
WRITE(*,*) 'Happy hunting!'
END PROGRAM unrotMe
SUBROUTINE GET_COORDS(lat,lon,pollat,pollon)
IMPLICIT NONE
DOUBLE PRECISION,INTENT(OUT) :: lat,lon,pollat,pollon
DOUBLE PRECISION :: lat_deg, lat_min, lon_deg, lon_min
DOUBLE PRECISION :: pol_lat_deg, pol_lat_min, pol_lon_deg, pol_lon_min
INTEGER :: io_err
WRITE(*,*)
WRITE(*,*) '------------------------'
WRITE(*,*) 'Input format : DD°MM.MMM'
WRITE(*,*) '------------------------'
WRITE(*,*)
WRITE(*,'(A)')'Enter LATITUDE of the point in ROTATED system'
DO
WRITE(*,'(A$)')'Degrees (DD) : '
READ (*,*,iostat=io_err) lat_deg
if ( io_err == 0 ) then
exit
else
cycle
end if
END DO
DO
WRITE(*,'(A$)')'Minutes (MM.MMM) : '
READ (*,*,iostat=io_err) lat_min
if ( io_err == 0) then
exit
else
cycle
end if
END DO
WRITE(*,'(A)')'Enter LONGIUDE of the point in ROTATED system'
DO
WRITE(*,'(A$)')'Degrees (DD) : '
READ (*,*,iostat=io_err) lon_deg
if ( io_err == 0) then
exit
else
cycle
end if
END DO
DO
WRITE(*,'(A$)')'Minutes (MM.MMM) : '
READ (*,*,iostat=io_err) lon_min
if ( io_err == 0) then
exit
else
cycle
end if
END DO
lat = lat_deg + (lat_min / 60.0D0 )
lon = lon_deg + (lon_min / 60.0D0 )
WRITE(*,'(A)')'Enter LATITUDE of the rotated North Pole in UNROTATED system'
DO
WRITE(*,'(A$)')'Degrees (DD) : '
READ (*,*,iostat=io_err) pol_lat_deg
if ( io_err == 0 ) then
exit
else
cycle
end if
END DO
DO
WRITE(*,'(A$)')'Minutes (MM.MMM) : '
READ (*,*,iostat=io_err) pol_lat_min
if ( io_err == 0) then
exit
else
cycle
end if
END DO
WRITE(*,'(A)')'Enter LONGIUDE of the rotated North Pole in UNROTATED system'
DO
WRITE(*,'(A$)')'Degrees (DD) : '
READ (*,*,iostat=io_err) pol_lon_deg
if ( io_err == 0) then
exit
else
cycle
end if
END DO
DO
WRITE(*,'(A$)')'Minutes (MM.MMM) : '
READ (*,*,iostat=io_err) pol_lon_min
if ( io_err == 0) then
exit
else
cycle
end if
END DO
pollat = pol_lat_deg + (pol_lat_min / 60.0D0 )
pollon = pol_lon_deg + (pol_lon_min / 60.0D0 )
RETURN
END SUBROUTINE GET_COORDS
DOUBLE PRECISION FUNCTION phirot2phi ( phirot, rlarot, polphi, pollam, polgam )
!------------------------------------------------------------------------------
!
! Description:
! This function converts phi from one rotated system to phi in another
! system. If the optional argument polgam is present, the other system
! can also be a rotated one, where polgam is the angle between the two
! north poles.
! If polgam is not present, the other system is the real geographical
! system.
!
! Method:
! Transformation formulas for converting between these two systems.
!
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
!
! Declarations:
!
!------------------------------------------------------------------------------
! Parameter list:
DOUBLE PRECISION , INTENT (IN) :: &
polphi, & ! latitude of the rotated north pole
pollam, & ! longitude of the rotated north pole
phirot, & ! latitude in the rotated system
rlarot ! longitude in the rotated system
DOUBLE PRECISION , INTENT (IN) :: &
polgam ! angle between the north poles of the systems
DOUBLE PRECISION :: &
phirot2phi ! latitude in the geographical system
DOUBLE PRECISION :: &
zsinpol, zcospol, zphis, zrlas, zarg, zgam
DOUBLE PRECISION :: &
zrpi18, zpir18
! Begin function phirot2phi
pi = 2.0D0 * ACOS(0.0D0)
zrpi18 = 180.0D0 / pi
zpir18 = pi / 180.0D0
zsinpol = SIN (zpir18 * polphi)
zcospol = COS (zpir18 * polphi)
zphis = zpir18 * phirot
IF (rlarot > 180.0D0) THEN
zrlas = rlarot - 360.0D0
ELSE
zrlas = rlarot
ENDIF
zrlas = zpir18 * zrlas
IF (polgam /= 0.0D0) THEN
zgam = zpir18 * polgam
zarg = zsinpol*SIN (zphis) + &
zcospol*COS(zphis) * ( COS(zrlas)*COS(zgam) - SIN(zgam)*SIN(zrlas) )
ELSE
zarg = zcospol * COS (zphis) * COS (zrlas) + zsinpol * SIN (zphis)
ENDIF
phirot2phi = zrpi18 * ASIN (zarg)
RETURN
END FUNCTION phirot2phi
FUNCTION rlarot2rla (phirot, rlarot, polphi, pollam, polgam)
!------------------------------------------------------------------------------
!
! Description:
! This function converts lambda from one rotated system to lambda in another
! system. If the optional argument polgam is present, the other system
! can also be a rotated one, where polgam is the angle between the two
! north poles.
! If polgam is not present, the other system is the real geographical
! system.
!
! Method:
! Transformation formulas for converting between these two systems.
!
! Modules used: NONE
!
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
!
! Declarations:
!
!------------------------------------------------------------------------------
! Parameter list:
DOUBLE PRECISION , INTENT (IN) :: &
polphi, & ! latitude of the rotated north pole
pollam, & ! longitude of the rotated north pole
phirot, & ! latitude in the rotated system
rlarot ! longitude in the rotated system
DOUBLE PRECISION , INTENT (IN) :: &
polgam ! angle between the north poles of the systems
DOUBLE PRECISION :: &
rlarot2rla ! latitude in the geographical system
! Local variables
DOUBLE PRECISION :: &
zsinpol, zcospol, zlampol, zphis, zrlas, zarg1, zarg2, zgam
DOUBLE PRECISION :: &
zrpi18, zpir18
!------------------------------------------------------------------------------
! Begin function rlarot2rla
pi = 2.0D0 * ACOS(0.0D0)
zrpi18 = 180.0D0 / pi
zpir18 = pi / 180.0D0
zsinpol = SIN (zpir18 * polphi)
zcospol = COS (zpir18 * polphi)
zlampol = zpir18 * pollam
zphis = zpir18 * phirot
IF (rlarot > 180.0D0) THEN
zrlas = rlarot - 360.0D0
ELSE
zrlas = rlarot
ENDIF
zrlas = zpir18 * zrlas
IF (polgam /= 0.0) THEN
zgam = zpir18 * polgam
zarg1 = SIN (zlampol) * &
(- zsinpol*COS(zphis) * (COS(zrlas)*COS(zgam) - SIN(zrlas)*SIN(zgam)) &
+ zcospol * SIN(zphis)) &
- COS (zlampol)*COS(zphis) * (SIN(zrlas)*COS(zgam) + COS(zrlas)*SIN(zgam))
zarg2 = COS (zlampol) * &
(- zsinpol*COS(zphis) * (COS(zrlas)*COS(zgam) - SIN(zrlas)*SIN(zgam)) &
+ zcospol * SIN(zphis)) &
+ SIN (zlampol)*COS(zphis) * (SIN(zrlas)*COS(zgam) + COS(zrlas)*SIN(zgam))
ELSE
zarg1 = SIN (zlampol) * (-zsinpol * COS(zrlas) * COS(zphis) + &
zcospol * SIN(zphis)) - &
COS (zlampol) * SIN(zrlas) * COS(zphis)
zarg2 = COS (zlampol) * (-zsinpol * COS(zrlas) * COS(zphis) + &
zcospol * SIN(zphis)) + &
SIN (zlampol) * SIN(zrlas) * COS(zphis)
ENDIF
IF (zarg2 == 0.0) zarg2 = 1.0D-20
rlarot2rla = zrpi18 * ATAN2(zarg1,zarg2)
RETURN
END FUNCTION rlarot2rla