20#include "scaleFElib.h"
26 use scale_const,
only: &
29 rplanet => const_radius
52 module procedure :: cubedspherecoordcnv_cs2localorthvec_alpha_0
53 module procedure :: cubedspherecoordcnv_cs2localorthvec_alpha_1
58 module procedure :: cubedspherecoordcnv_localorth2csvec_alpha_0
59 module procedure :: cubedspherecoordcnv_localorth2csvec_alpha_1
86 panelID, alpha, beta, gam, Np, & ! (in)
92 integer,
intent(in) :: panelid
93 integer,
intent(in) :: np
94 real(rp),
intent(in) :: alpha(np)
95 real(rp),
intent(in) :: beta (np)
96 real(rp),
intent(in) :: gam(np)
97 real(rp),
intent(out) :: lon(np)
98 real(rp),
intent(out) :: lat(np)
100 real(rp) :: cartpos(np,3)
101 real(rp) :: geogpos(np,3)
106 select case( panelid )
111 lon(p) = alpha(p) + 0.5_rp * pi * dble(panelid - 1)
112 lat(p) = atan( tan( beta(p) ) * cos( alpha(p) ) )
115 where( lon(:) < 0.0_rp )
116 lon(:) = lon(:) + 2.0_rp * pi
122 cartpos(:,1), cartpos(:,2), cartpos(:,3) )
130 lon(p) = geogpos(p,1)
131 lat(p) = geogpos(p,2)
134 where( alpha < 0.0_rp )
135 lon(:) = lon(:) + 2.0_rp * pi
140 log_error(
"CubedSphereCoordCnv_CS2LonLatPos",
'(a,i2,a)')
"panelID ", panelid,
" is invalid. Check!"
151 panelID, alpha, beta, gam, Np, & ! (in)
156 use scale_const,
only: &
160 integer,
intent(in) :: panelid
161 integer,
intent(in) :: np
162 real(rp),
intent(in) :: alpha(np)
163 real(rp),
intent(in) :: beta (np)
164 real(rp),
intent(in) :: gam(np)
165 real(dp),
intent(in) :: vecalpha(np)
166 real(dp),
intent(in) :: vecbeta (np)
167 real(rp),
intent(out) :: veclon(np)
168 real(rp),
intent(out) :: veclat(np)
169 real(rp),
intent(in),
optional :: lat(np)
172 real(rp) :: x ,y, del2
176 real(rp) :: cos_lat(np)
179 if (
present(lat))
then
182 cos_lat(p) = cos(lat(p))
186 select case( panelid )
188 if (.not.
present(lat))
then
191 cos_lat(p) = cos( atan( tan( beta(p) ) * cos( alpha(p) ) ) )
199 del2 = 1.0_rp + x**2 + y**2
200 radius = rplanet * gam(p)
202 veclon(p) = vecalpha(p) * cos_lat(p) * radius
203 veclat(p) = ( - x * y * vecalpha(p) + ( 1.0_rp + y**2 ) * vecbeta(p) ) &
204 * radius * sqrt( 1.0_rp + x**2 ) / del2
211 log_error(
"CubedSphereCoordCnv_CS2LonLatVec",
'(a,i2,a)')
"panelID ", panelid,
" is invalid. Check!"
215 select case( panelid )
221 del2 = 1.0_rp + x**2 + y**2
222 radius = s * rplanet * gam(p)
224 if (.not.
present(lat))
then
225 cos_lat(p) = cos( atan( sign(1.0_rp, s) / max( sqrt( x**2 + y**2 ), eps ) ) )
228 veclon(p) = (- y * ( 1.0_rp + x**2 ) * vecalpha(p) + x * ( 1.0_rp + y**2 ) * vecbeta(p) ) &
229 * radius / max( x**2 + y**2, eps ) * cos_lat(p)
230 veclat(p) = (- x * ( 1.0_rp + x**2 ) * vecalpha(p) - y * ( 1.0_rp + y**2 ) * vecbeta(p) ) &
231 * radius / ( del2 * ( max( sqrt( x**2 + y**2 ), eps ) ) )
242 panelID, lon, lat, Np, & ! (in)
247 integer,
intent(in) :: panelid
248 integer,
intent(in) :: np
249 real(rp),
intent(in) :: lon(np)
250 real(rp),
intent(in) :: lat(np)
251 real(rp),
intent(out) ::alpha(np)
252 real(rp),
intent(out) ::beta (np)
262 if ( panelid == 1 )
then
264 where (lon(:) >= 2.0_rp * pi - 0.25_rp * pi )
265 lon_(:) = lon(:) - 2.0_rp * pi
272 where (lon(:) < 0.0_rp )
273 lon_(:) = lon(:) + 2.0_rp * pi
281 alpha(p) = lon_(p) - 0.5_rp * pi * ( dble(panelid) - 1.0_rp )
282 beta(p) = atan( tan(lat(p)) / cos(alpha(p)) )
289 tan_lat = tan(lat(p))
290 alpha(p) = + atan( sin(lon(p)) / tan_lat )
291 beta(p) = - atan( cos(lon(p)) / tan_lat )
298 tan_lat = tan(lat(p))
299 alpha(p) = - atan( sin(lon(p)) / tan_lat )
300 beta(p) = - atan( cos(lon(p)) / tan_lat )
304 log_error(
"CubedSphereCoordCnv_LonLat2CSPos",
'(a,i2,a)')
"panelID ", panelid,
" is invalid. Check!"
315 panelID, alpha, beta, gam, Np, & ! (in)
322 integer,
intent(in) :: panelid
323 integer,
intent(in) :: np
324 real(rp),
intent(in) :: alpha(np)
325 real(rp),
intent(in) :: beta (np)
326 real(rp),
intent(in) :: gam(np)
327 real(dp),
intent(in) :: veclon(np)
328 real(dp),
intent(in) :: veclat(np)
329 real(dp),
intent(out) :: vecalpha(np)
330 real(dp),
intent(out) :: vecbeta (np)
331 real(rp),
intent(in),
optional :: lat(np)
334 real(rp) :: x ,y, del2
338 real(rp) :: cos_lat(np)
339 real(rp) :: veclon_ov_coslat
342 if (
present(lat))
then
345 cos_lat(p) = cos(lat(p))
349 select case( panelid )
351 if (.not.
present(lat))
then
354 cos_lat(p) = cos( atan( tan( beta(p) ) * cos( alpha(p) ) ) )
362 del2 = 1.0_rp + x**2 + y**2
363 radius = rplanet * gam(p)
364 veclon_ov_coslat = veclon(p) / cos_lat(p)
366 vecalpha(p) = veclon_ov_coslat / radius
367 vecbeta(p) = ( x * y * veclon_ov_coslat + del2 / sqrt( 1.0_rp + x**2 ) * veclat(p) ) &
368 / ( radius * (1.0_rp + y**2) )
375 log_error(
"CubedSphereCoordCnv_LonLat2CSVec",
'(a,i2,a)')
"panelID ", panelid,
" is invalid. Check!"
379 select case( panelid )
385 del2 = 1.0_rp + x**2 + y**2
386 radius = s * rplanet * gam(p)
388 if (.not.
present(lat))
then
389 cos_lat(p) = cos( atan( s / sqrt(max(x**2 + y**2, eps)) ) )
391 veclon_ov_coslat = veclon(p) / cos_lat(p)
393 vecalpha(p) = (- y * veclon_ov_coslat - del2 * x / sqrt( max(del2 - 1.0_rp,eps)) * veclat(p)) &
394 / ( radius * ( 1.0_rp + x**2 ) )
395 vecbeta(p) = ( x * veclon_ov_coslat - del2 * y / sqrt( max(del2 - 1.0_rp,eps)) * veclat(p)) &
396 / ( radius * ( 1.0_rp + y**2 ) )
407 panelID, alpha, beta, gam, Np, & ! (in)
411 integer,
intent(in) :: panelid
412 integer,
intent(in) :: np
413 real(rp),
intent(in) :: alpha(np)
414 real(rp),
intent(in) :: beta (np)
415 real(rp),
intent(in) :: gam(np)
416 real(rp),
intent(out) :: x(np)
417 real(rp),
intent(out) :: y(np)
418 real(rp),
intent(out) :: z(np)
421 real(rp) :: x1, x2, fac
431 fac = rplanet * gam(p) / sqrt( 1.0_rp + x1**2 + x2**2 )
441 fac = rplanet * gam(p) / sqrt( 1.0_rp + x1**2 + x2**2 )
451 fac = rplanet * gam(p) / sqrt( 1.0_rp + x1**2 + x2**2 )
461 fac = rplanet * gam(p) / sqrt( 1.0_rp + x1**2 + x2**2 )
471 fac = rplanet * gam(p) / sqrt( 1.0_rp + x1**2 + x2**2 )
481 fac = rplanet * gam(p) / sqrt( 1.0_rp + x1**2 + x2**2 )
487 log_error(
"CubedSphereCoordCnv_CS2CartPos",
'(a,i2,a)')
"panelID ", panelid,
" is invalid. Check!"
498 panelID, alpha, beta, gam, Np, & ! (in)
499 vec_x, vec_y, vec_z, &
504 integer,
intent(in) :: panelid
505 integer,
intent(in) :: np
506 real(rp),
intent(in) :: alpha(np)
507 real(rp),
intent(in) :: beta (np)
508 real(rp),
intent(in) :: gam(np)
509 real(dp),
intent(in) :: vec_x(np)
510 real(dp),
intent(in) :: vec_y(np)
511 real(dp),
intent(in) :: vec_z(np)
512 real(rp),
intent(out) :: vecalpha(np)
513 real(rp),
intent(out) :: vecbeta (np)
516 real(rp) :: x1, x2, fac
517 real(rp) :: r_sec2_alpha, r_sec2_beta
520 select case( panelid )
526 r_sec2_alpha = cos(alpha(p))**2
527 r_sec2_beta = cos(beta(p))**2
528 fac = sqrt( 1.0_rp + x1**2 + x2**2 ) / ( rplanet * gam(p) )
530 vecalpha(p) = fac * r_sec2_alpha * ( - x1 * vec_x(p) + vec_y(p) )
531 vecbeta(p) = fac * r_sec2_beta * ( - x2 * vec_x(p) + vec_z(p) )
538 r_sec2_alpha = cos(alpha(p))**2
539 r_sec2_beta = cos(beta(p))**2
540 fac = sqrt( 1.0_rp + x1**2 + x2**2 ) / ( rplanet * gam(p) )
542 vecalpha(p) = - fac * r_sec2_alpha * ( vec_x(p) + x1 * vec_y(p) )
543 vecbeta(p) = fac * r_sec2_beta * ( - x2 * vec_y(p) + vec_z(p) )
550 r_sec2_alpha = cos(alpha(p))**2
551 r_sec2_beta = cos(beta(p))**2
552 fac = sqrt( 1.0_rp + x1**2 + x2**2 ) / ( rplanet * gam(p) )
554 vecalpha(p) = fac * r_sec2_alpha * ( x1 * vec_x(p) - vec_y(p) )
555 vecbeta(p) = fac * r_sec2_beta * ( x2 * vec_x(p) + vec_z(p) )
562 r_sec2_alpha = cos(alpha(p))**2
563 r_sec2_beta = cos(beta(p))**2
564 fac = sqrt( 1.0_rp + x1**2 + x2**2 ) / ( rplanet * gam(p) )
566 vecalpha(p) = fac * r_sec2_alpha * ( vec_x(p) + x1 * vec_y(p) )
567 vecbeta(p) = fac * r_sec2_beta * ( x2 * vec_y(p) + vec_z(p) )
574 r_sec2_alpha = cos(alpha(p))**2
575 r_sec2_beta = cos(beta(p))**2
576 fac = sqrt( 1.0_rp + x1**2 + x2**2 ) / ( rplanet * gam(p) )
578 vecalpha(p) = fac * r_sec2_alpha * ( vec_y(p) - x1 * vec_z(p) )
579 vecbeta(p) = - fac * r_sec2_beta * ( vec_x(p) + x2 * vec_z(p) )
586 r_sec2_alpha = cos(alpha(p))**2
587 r_sec2_beta = cos(beta(p))**2
588 fac = sqrt( 1.0_rp + x1**2 + x2**2 ) / ( rplanet * gam(p) )
590 vecalpha(p) = fac * r_sec2_alpha * ( vec_y(p) + x1 * vec_z(p) )
591 vecbeta(p) = fac * r_sec2_beta * ( vec_x(p) + x2 * vec_z(p) )
594 log_error(
"CubedSphereCoordCnv_Cart2CSVec",
'(a,i2,a)')
"panelID ", panelid,
" is invalid. Check!"
602 subroutine cubedspherecoordcnv_cs2localorthvec_alpha_0( &
603 alpha, beta, radius, Np, & ! (in)
608 integer,
intent(in) :: Np
609 real(RP),
intent(in) :: alpha(Np)
610 real(RP),
intent(in) :: beta (Np)
611 real(RP),
intent(in) :: radius(Np)
612 real(RP),
intent(inout) :: VecOrth1(Np)
613 real(RP),
intent(inout) :: VecOrth2(Np)
616 real(RP) :: x1, x2, del
625 del = sqrt(1.0_rp + x1**2 + x2**2)
626 fac = radius(p) * sqrt(1.0_rp + x1**2) / del**2
629 vecorth1(p) = fac * del * tmp
630 vecorth2(p) = fac * ( - x1 * x2 * tmp + (1.0_rp + x2**2) * vecorth2(p) )
634 end subroutine cubedspherecoordcnv_cs2localorthvec_alpha_0
637 subroutine cubedspherecoordcnv_cs2localorthvec_alpha_1( &
638 alpha, beta, radius, Np, & ! (in)
644 integer,
intent(in) :: Np
645 real(RP),
intent(in) :: alpha(Np)
646 real(RP),
intent(in) :: beta (Np)
647 real(RP),
intent(in) :: radius(Np)
648 real(RP),
intent(in) :: VecAlpha(Np)
649 real(RP),
intent(in) :: VecBeta (Np)
650 real(RP),
intent(out) :: VecOrth1(Np)
651 real(RP),
intent(out) :: VecOrth2(Np)
656 vecorth1(:) = vecalpha(:)
657 vecorth2(:) = vecbeta(:)
660 call cubedspherecoordcnv_cs2localorthvec_alpha_0( &
661 alpha, beta, radius, np, &
665 end subroutine cubedspherecoordcnv_cs2localorthvec_alpha_1
668 subroutine cubedspherecoordcnv_localorth2csvec_alpha_0( &
669 alpha, beta, radius, Np, & ! (in)
674 integer,
intent(in) :: Np
675 real(RP),
intent(in) :: alpha(Np)
676 real(RP),
intent(in) :: beta (Np)
677 real(RP),
intent(in) :: radius(Np)
678 real(RP),
intent(inout) :: VecAlpha(Np)
679 real(RP),
intent(inout) :: VecBeta (Np)
682 real(RP) :: x1, x2, del
691 del = sqrt(1.0_rp + x1**2 + x2**2)
692 fac = del / ( radius(p) * ( 1.0_rp + x2**2 ) * sqrt( 1.0_rp + x1**2 ) )
695 vecalpha(p) = fac * ( 1.0_rp + x2**2 ) * tmp
696 vecbeta(p) = fac * ( x1 * x2 * tmp + del * vecbeta(p) )
700 end subroutine cubedspherecoordcnv_localorth2csvec_alpha_0
703 subroutine cubedspherecoordcnv_localorth2csvec_alpha_1( &
704 alpha, beta, radius, Np, & ! (in)
705 vecorth1, vecorth2, &
710 integer,
intent(in) :: Np
711 real(RP),
intent(in) :: alpha(Np)
712 real(RP),
intent(in) :: beta (Np)
713 real(RP),
intent(in) :: radius(Np)
714 real(RP),
intent(in) :: VecOrth1(Np)
715 real(RP),
intent(in) :: VecOrth2(Np)
716 real(RP),
intent(out) :: VecAlpha(Np)
717 real(RP),
intent(out) :: VecBeta (Np)
721 vecalpha(:) = vecorth1(:)
722 vecbeta(:) = vecorth2(:)
725 call cubedspherecoordcnv_localorth2csvec_alpha_0( &
726 alpha, beta, radius, np, &
730 end subroutine cubedspherecoordcnv_localorth2csvec_alpha_1
736 alpha, beta, Np, radius, & ! (in)
741 integer,
intent(in) :: np
742 real(rp),
intent(in) :: alpha(np)
743 real(rp),
intent(in) :: beta (np)
744 real(rp),
intent(in) :: radius
745 real(rp),
intent(out) :: g_ij(np,2,2)
746 real(rp),
intent(out) :: gij (np,2,2)
747 real(rp),
intent(out) :: gsqrt(np)
752 real(rp) :: g_ij_(2,2)
753 real(rp) :: gij_ (2,2)
756 real(rp) :: oneplusx2, oneplusy2
765 r2 = 1.0_rp + x**2 + y**2
766 oneplusx2 = 1.0_rp + x**2
767 oneplusy2 = 1.0_rp + y**2
769 fac = oneplusx2 * oneplusy2 * ( radius / r2 )**2
770 g_ij_(1,1) = fac * oneplusx2
771 g_ij_(1,2) = - fac * (x * y)
772 g_ij_(2,1) = - fac * (x * y)
773 g_ij_(2,2) = fac * oneplusy2
774 g_ij(p,:,:) = g_ij_(:,:)
776 gsqrt(p) = radius**2 * oneplusx2 * oneplusy2 / ( r2 * sqrt(r2) )
778 fac = 1.0_rp / gsqrt(p)**2
779 gij_(1,1) = fac * g_ij_(2,2)
780 gij_(1,2) = - fac * g_ij_(1,2)
781 gij_(2,1) = - fac * g_ij_(2,1)
782 gij_(2,2) = fac * g_ij_(1,1)
783 gij(p,:,:) = gij_(:,:)
Module common / Coordinate conversion with cubed-sphere projection.
subroutine, public cubedspherecoordcnv_cs2lonlatvec(panelid, alpha, beta, gam, np, vecalpha, vecbeta, veclon, veclat, lat)
Covert the components of a vector in local coordinates with an equiangular gnomonic cubed-sphere proj...
subroutine, public cubedspherecoordcnv_cs2lonlatpos(panelid, alpha, beta, gam, np, lon, lat)
Calculate longitude and latitude coordinates from local coordinates using the central angles in an eq...
subroutine, public cubedspherecoordcnv_lonlat2csvec(panelid, alpha, beta, gam, np, veclon, veclat, vecalpha, vecbeta, lat)
Covert the components of a vector in longitude and latitude coordinates to those in local coordinates...
subroutine, public cubedspherecoordcnv_getmetric(alpha, beta, np, radius, g_ij, gij, gsqrt)
Calculate the metrics associated with an equiangular gnomonic cubed-sphere projection to those in lon...
subroutine, public cubedspherecoordcnv_lonlat2cspos(panelid, lon, lat, np, alpha, beta)
Calculate local coordinates using the central angles in an equiangular gnomonic cubed-sphere projecti...
subroutine, public cubedspherecoordcnv_cart2csvec(panelid, alpha, beta, gam, np, vec_x, vec_y, vec_z, vecalpha, vecbeta)
Covert the components of a vector in local coordinates with an equiangular gnomonic cubed-sphere proj...
subroutine, public cubedspherecoordcnv_cs2cartpos(panelid, alpha, beta, gam, np, x, y, z)
Calculate Cartesian coordinates from local coordinates using the central angles in an equiangular gno...
Module common / Coordinate conversion with a geographic coordinate.
subroutine, public geographiccoordcnv_orth_to_geo_pos(orth_p, np, geo_p)