FE-Project
Loading...
Searching...
No Matches
scale_geographic_coord_cnv.F90
Go to the documentation of this file.
1
8#include "scaleFElib.h"
10 !-----------------------------------------------------------------------------
11 !
12 !++ used modules
13 !
14 use scale_const, only: &
15 pi => const_pi, &
16 eps => const_eps
17 use scale_precision
18 use scale_prc
19 use scale_io
20 use scale_prc
21
22 !-----------------------------------------------------------------------------
23 implicit none
24 private
25
26 !-----------------------------------------------------------------------------
27 !
28 !++ Public type & procedure
29 !
32
35
39
40contains
41!OCL SERIAL
42 subroutine geographiccoordcnv_orth_to_geo_pos( orth_p, Np, &
43 geo_p )
44
45 implicit none
46 integer, intent(in) :: np
47 real(rp), intent(in) :: orth_p(np,3)
48 real(rp), intent(out) :: geo_p(np,3)
49
50 integer :: p
51 !---------------------------------------------------------
52
53 !$omp parallel private(p)
54 !$omp do
55 do p=1, np
56 geo_p(p,3) = sqrt( orth_p(p,1)**2 + orth_p(p,2)**2 + orth_p(p,3)**2 )
57 geo_p(p,2) = asin( orth_p(p,3) / geo_p(p,3) )
58 geo_p(p,1) = atan( orth_p(p,2) / orth_p(p,1) )
59 end do
60 !$omp do
61 do p=1, np
62 if ( geo_p(p,1) <= 0.0_rp .and. orth_p(p,1) < 0.0_rp ) then
63 geo_p(p,1) = geo_p(p,1) + pi
64 else if ( geo_p(p,1) >= 0.0_rp .and. orth_p(p,1) < 0.0_rp ) then
65 geo_p(p,1) = geo_p(p,1) - pi
66 end if
67 if ( orth_p(p,1) == 0.0_rp .and. orth_p(p,2) == 0.0_rp ) then
68 geo_p(p,1) = 0.0_rp
69 else if ( orth_p(p,1) == 0.0_rp ) then
70 geo_p(p,1) = sign(1.0_rp, orth_p(p,2)) * 0.5_rp * pi
71 end if
72 end do
73 !$omp end parallel
74
75 return
77
78!OCL SERIAL
79 subroutine geographiccoordcnv_geo_to_orth_pos( geo_p, Np, &
80 orth_p )
81
82 implicit none
83 integer, intent(in) :: np
84 real(rp), intent(in) :: geo_p(np,3)
85 real(rp), intent(out) :: orth_p(np,3)
86
87 integer :: p
88 !---------------------------------------------------------
89
90 !$omp parallel do private(p)
91 do p=1, np
92 orth_p(p,1) = geo_p(p,3) * cos(geo_p(p,2)) * cos(geo_p(p,1))
93 orth_p(p,2) = geo_p(p,3) * cos(geo_p(p,2)) * sin(geo_p(p,1))
94 orth_p(p,3) = geo_p(p,3) * sin(geo_p(p,2))
95 end do
96
97 return
99
100!OCL SERIAL
101 subroutine geographiccoordcnv_orth_to_geo_vec( orth_v, geo_p, Np, &
102 geo_v )
103 implicit none
104
105 integer, intent(in) :: np
106 real(rp), intent(in) :: orth_v(np,3)
107 real(rp), intent(in) :: geo_p(np,3)
108 real(rp), intent(out) :: geo_v(np,3)
109
110 integer :: p
111 real(rp) :: sin_geo_p1
112 real(rp) :: cos_geo_p1
113 real(rp) :: sin_geo_p2
114 real(rp) :: cos_geo_p2
115 !---------------------------------------------------------
116
117 !$omp parallel do private(p, cos_geo_p2)
118 do p=1, np
119 sin_geo_p1 = sin(geo_p(p,1))
120 cos_geo_p1 = cos(geo_p(p,1))
121 sin_geo_p2 = sin(geo_p(p,2))
122 cos_geo_p2 = cos(geo_p(p,2))
123
124 geo_v(p,3) = orth_v(p,1) * cos_geo_p2 * cos_geo_p1 &
125 + orth_v(p,2) * cos_geo_p2 * sin_geo_p1 &
126 + orth_v(p,3) * sin_geo_p2
127
128 geo_v(p,2) = - orth_v(p,1) * sin_geo_p2 * cos_geo_p1 &
129 - orth_v(p,2) * sin_geo_p2 * sin_geo_p1 &
130 + orth_v(p,3) * cos_geo_p2
131
132 geo_v(p,1) = - orth_v(p,1) * sin_geo_p1 &
133 + orth_v(p,2) * cos_geo_p1
134 end do
135
136 return
138
139!OCL SERIAL
140 subroutine geographiccoordcnv_geo_to_orth_vec( geo_v, geo_p, Np, &
141 orth_v )
142 implicit none
143
144 integer, intent(in) :: np
145 real(rp), intent(in) :: geo_v(np,3)
146 real(rp), intent(in) :: geo_p(np,3)
147 real(rp), intent(out) :: orth_v(np,3)
148
149 integer :: p
150 real(rp) :: sin_geo_p1
151 real(rp) :: cos_geo_p1
152 real(rp) :: sin_geo_p2
153 real(rp) :: cos_geo_p2
154 !---------------------------------------------------------
155
156 !$omp parallel do private(p, sin_geo_p1, cos_geo_p1, sin_geo_p2, cos_geo_p2)
157 do p=1, np
158 sin_geo_p1 = sin(geo_p(p,1))
159 cos_geo_p1 = cos(geo_p(p,1))
160 sin_geo_p2 = sin(geo_p(p,2))
161 cos_geo_p2 = cos(geo_p(p,2))
162
163 orth_v(p,1) = geo_v(p,3) * cos_geo_p1 * cos_geo_p2 &
164 - geo_v(p,2) * cos_geo_p1 * sin_geo_p2 &
165 - geo_v(p,1) * sin_geo_p1
166
167 orth_v(p,2) = geo_v(p,3) * sin_geo_p1 * cos_geo_p2 &
168 - geo_v(p,2) * sin_geo_p1 * sin_geo_p2 &
169 + geo_v(p,1) * cos_geo_p1
170
171 orth_v(p,3) = geo_v(p,3) * sin_geo_p2 + geo_v(p,2) * cos_geo_p2
172 end do
173
174 return
176
177!OCL SERIAL
178 subroutine geographiccoordcnv_rotatex( pos_vec, angle, &
179 rotated_pos_vec )
180
181 implicit none
182 real(rp), intent(in) :: pos_vec(3)
183 real(rp), intent(in) :: angle
184 real(rp), intent(out) :: rotated_pos_vec(3)
185
186 real(rp) :: sin_angle, cos_angle
187 !---------------------------------------------------------
188
189 sin_angle = sin(angle)
190 cos_angle = cos(angle)
191
192 rotated_pos_vec(1) = pos_vec(1)
193 rotated_pos_vec(2) = cos_angle * pos_vec(2) - sin_angle * pos_vec(3)
194 rotated_pos_vec(3) = sin_angle * pos_vec(2) + cos_angle * pos_vec(3)
195
196 return
197 end subroutine geographiccoordcnv_rotatex
198
199!OCL SERIAL
200 subroutine geographiccoordcnv_rotatey( pos_vec, angle, &
201 rotated_pos_vec )
202
203 implicit none
204 real(rp), intent(in) :: pos_vec(3)
205 real(rp), intent(in) :: angle
206 real(rp), intent(out) :: rotated_pos_vec(3)
207
208 real(rp) :: sin_angle, cos_angle
209 !---------------------------------------------------------
210
211 sin_angle = sin(angle)
212 cos_angle = cos(angle)
213
214 rotated_pos_vec(1) = cos_angle * pos_vec(1) + sin_angle * pos_vec(3)
215 rotated_pos_vec(2) = pos_vec(2)
216 rotated_pos_vec(3) = - sin_angle * pos_vec(1) + cos_angle * pos_vec(3)
217
218 return
219 end subroutine geographiccoordcnv_rotatey
220
221!OCL SERIAL
222 subroutine geographiccoordcnv_rotatez( pos_vec, angle, &
223 rotated_pos_vec )
224
225 implicit none
226 real(rp), intent(in) :: pos_vec(3)
227 real(rp), intent(in) :: angle
228 real(rp), intent(out) :: rotated_pos_vec(3)
229
230 real(rp) :: sin_angle, cos_angle
231 !---------------------------------------------------------
232
233 sin_angle = sin(angle)
234 cos_angle = cos(angle)
235
236 rotated_pos_vec(1) = cos_angle * pos_vec(1) - sin_angle * pos_vec(2)
237 rotated_pos_vec(2) = sin_angle * pos_vec(1) + cos_angle * pos_vec(2)
238 rotated_pos_vec(3) = pos_vec(3)
239
240 return
241 end subroutine geographiccoordcnv_rotatez
242
module common / Coordinate conversion with a geographic coordinate
subroutine, public geographiccoordcnv_rotatez(pos_vec, angle, rotated_pos_vec)
subroutine, public geographiccoordcnv_rotatex(pos_vec, angle, rotated_pos_vec)
subroutine, public geographiccoordcnv_orth_to_geo_pos(orth_p, np, geo_p)
subroutine, public geographiccoordcnv_rotatey(pos_vec, angle, rotated_pos_vec)
subroutine, public geographiccoordcnv_geo_to_orth_pos(geo_p, np, orth_p)
subroutine, public geographiccoordcnv_geo_to_orth_vec(geo_v, geo_p, np, orth_v)
subroutine, public geographiccoordcnv_orth_to_geo_vec(orth_v, geo_p, np, geo_v)