| 1 |
! (C) Copyright 2013 ECMWF. |
| 2 |
! |
| 3 |
! This software is licensed under the terms of the Apache Licence Version 2.0 |
| 4 |
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 5 |
! In applying this licence, ECMWF does not waive the privileges and immunities |
| 6 |
! granted to it by virtue of its status as an intergovernmental organisation nor |
| 7 |
! does it submit to any jurisdiction. |
| 8 |
|
| 9 |
#include "atlas/atlas_f.h" |
| 10 |
|
| 11 |
module atlas_Geometry_module |
| 12 |
|
| 13 |
use, intrinsic :: iso_c_binding |
| 14 |
use fckit_exception_module, only : fckit_exception |
| 15 |
use fckit_owned_object_module, only : fckit_owned_object |
| 16 |
|
| 17 |
implicit none |
| 18 |
|
| 19 |
private :: fckit_owned_object |
| 20 |
|
| 21 |
public :: atlas_Geometry |
| 22 |
|
| 23 |
private |
| 24 |
|
| 25 |
!------------------------------------------------------------------------------ |
| 26 |
TYPE, extends(fckit_owned_object) :: atlas_Geometry |
| 27 |
|
| 28 |
! Purpose : |
| 29 |
! ------- |
| 30 |
! *Geometry* : Container of Geometry |
| 31 |
|
| 32 |
! Methods : |
| 33 |
! ------- |
| 34 |
|
| 35 |
! Author : |
| 36 |
! ------ |
| 37 |
! April-2020 Benjamin Menetrier *IRIT-JCSDA* |
| 38 |
|
| 39 |
!------------------------------------------------------------------------------ |
| 40 |
contains |
| 41 |
procedure, public :: delete => atlas_Geometry__delete |
| 42 |
procedure :: xyz2lonlat_separate_coords => Geometry__xyz2lonlat_separate_coords |
| 43 |
procedure :: xyz2lonlat_vectorized_coords => Geometry__xyz2lonlat_vectorized_coords |
| 44 |
generic :: xyz2lonlat => xyz2lonlat_separate_coords, xyz2lonlat_vectorized_coords |
| 45 |
procedure :: lonlat2xyz_separate_coords => Geometry__lonlat2xyz_separate_coords |
| 46 |
procedure :: lonlat2xyz_vectorized_coords => Geometry__lonlat2xyz_vectorized_coords |
| 47 |
generic :: lonlat2xyz => lonlat2xyz_separate_coords, lonlat2xyz_vectorized_coords |
| 48 |
procedure :: distance_lonlat_separate_coords => Geometry__distance_lonlat_separate_coords |
| 49 |
procedure :: distance_xyz_separate_coords => Geometry__distance_xyz_separate_coords |
| 50 |
procedure :: distance_vectorized_coords => Geometry__distance_vectorized_coords |
| 51 |
generic :: distance => distance_lonlat_separate_coords, distance_xyz_separate_coords, distance_vectorized_coords |
| 52 |
procedure :: radius => Geometry__radius |
| 53 |
procedure :: area => Geometry__area |
| 54 |
#if FCKIT_FINAL_NOT_INHERITING |
| 55 |
final :: atlas_Geometry__final_auto |
| 56 |
#endif |
| 57 |
|
| 58 |
END TYPE atlas_Geometry |
| 59 |
|
| 60 |
!------------------------------------------------------------------------------ |
| 61 |
|
| 62 |
interface atlas_Geometry |
| 63 |
module procedure atlas_Geometry__ctor_name |
| 64 |
module procedure atlas_Geometry__ctor_radius |
| 65 |
end interface |
| 66 |
|
| 67 |
!------------------------------------------------------------------------------ |
| 68 |
|
| 69 |
|
| 70 |
!======================================================== |
| 71 |
contains |
| 72 |
!======================================================== |
| 73 |
|
| 74 |
|
| 75 |
! ----------------------------------------------------------------------------- |
| 76 |
! Geometry routines |
| 77 |
|
| 78 |
function atlas_Geometry__ctor_name(name) result(this) |
| 79 |
use atlas_Geometry_c_binding |
| 80 |
use fckit_c_interop_module |
| 81 |
character(kind=c_char,len=*), intent(in) :: name |
| 82 |
type(atlas_Geometry) :: this |
| 83 |
call this%reset_c_ptr( atlas__Geometry__new_name( c_str(name) ) ) |
| 84 |
call this%return() |
| 85 |
end function atlas_Geometry__ctor_name |
| 86 |
|
| 87 |
function atlas_Geometry__ctor_radius(radius) result(this) |
| 88 |
use atlas_Geometry_c_binding |
| 89 |
use fckit_c_interop_module |
| 90 |
real(c_double), intent(in) :: radius |
| 91 |
type(atlas_Geometry) :: this |
| 92 |
call this%reset_c_ptr( atlas__Geometry__new_radius( radius ) ) |
| 93 |
call this%return() |
| 94 |
end function atlas_Geometry__ctor_radius |
| 95 |
|
| 96 |
subroutine atlas_Geometry__delete(this) |
| 97 |
use atlas_Geometry_c_binding |
| 98 |
class(atlas_Geometry), intent(inout) :: this |
| 99 |
if ( .not. this%is_null() ) then |
| 100 |
call atlas__Geometry__delete(this%CPTR_PGIBUG_A) |
| 101 |
end if |
| 102 |
call this%reset_c_ptr() |
| 103 |
end subroutine atlas_Geometry__delete |
| 104 |
|
| 105 |
subroutine Geometry__xyz2lonlat_separate_coords(this, x, y, z, lon, lat) |
| 106 |
use atlas_Geometry_c_binding |
| 107 |
use fckit_c_interop_module |
| 108 |
class(atlas_Geometry), intent(in) :: this |
| 109 |
real(c_double), intent(in) :: x |
| 110 |
real(c_double), intent(in) :: y |
| 111 |
real(c_double), intent(in) :: z |
| 112 |
real(c_double), intent(out) :: lon |
| 113 |
real(c_double), intent(out) :: lat |
| 114 |
call atlas__Geometry__xyz2lonlat(this%CPTR_PGIBUG_A, x, y, z, lon, lat) |
| 115 |
end subroutine Geometry__xyz2lonlat_separate_coords |
| 116 |
|
| 117 |
subroutine Geometry__xyz2lonlat_vectorized_coords(this, xyz, lonlat) |
| 118 |
use atlas_Geometry_c_binding |
| 119 |
use fckit_c_interop_module |
| 120 |
class(atlas_Geometry), intent(in) :: this |
| 121 |
real(c_double), intent(in) :: xyz(3) |
| 122 |
real(c_double), intent(out) :: lonlat(2) |
| 123 |
call atlas__Geometry__xyz2lonlat(this%CPTR_PGIBUG_A, xyz(1), xyz(2), xyz(3), lonlat(1), lonlat(2)) |
| 124 |
end subroutine Geometry__xyz2lonlat_vectorized_coords |
| 125 |
|
| 126 |
subroutine Geometry__lonlat2xyz_separate_coords(this, lon, lat, x, y, z) |
| 127 |
use atlas_Geometry_c_binding |
| 128 |
use fckit_c_interop_module |
| 129 |
class(atlas_Geometry), intent(in) :: this |
| 130 |
real(c_double), intent(in) :: lon |
| 131 |
real(c_double), intent(in) :: lat |
| 132 |
real(c_double), intent(out) :: x |
| 133 |
real(c_double), intent(out) :: y |
| 134 |
real(c_double), intent(out) :: z |
| 135 |
call atlas__Geometry__lonlat2xyz(this%CPTR_PGIBUG_A, lon, lat, x, y, z) |
| 136 |
end subroutine Geometry__lonlat2xyz_separate_coords |
| 137 |
|
| 138 |
subroutine Geometry__lonlat2xyz_vectorized_coords(this, lonlat, xyz) |
| 139 |
use atlas_Geometry_c_binding |
| 140 |
use fckit_c_interop_module |
| 141 |
class(atlas_Geometry), intent(in) :: this |
| 142 |
real(c_double), intent(in) :: lonlat(2) |
| 143 |
real(c_double), intent(out) :: xyz(3) |
| 144 |
call atlas__Geometry__lonlat2xyz(this%CPTR_PGIBUG_A, lonlat(1), lonlat(2), xyz(1), xyz(2), xyz(3)) |
| 145 |
end subroutine Geometry__lonlat2xyz_vectorized_coords |
| 146 |
|
| 147 |
function Geometry__distance_lonlat_separate_coords(this, lon1, lat1, lon2, lat2) result(distance_lonlat) |
| 148 |
use atlas_Geometry_c_binding |
| 149 |
use fckit_c_interop_module |
| 150 |
class(atlas_Geometry), intent(in) :: this |
| 151 |
real(c_double), intent(in) :: lon1 |
| 152 |
real(c_double), intent(in) :: lat1 |
| 153 |
real(c_double), intent(in) :: lon2 |
| 154 |
real(c_double), intent(in) :: lat2 |
| 155 |
real(c_double) :: distance_lonlat |
| 156 |
distance_lonlat = atlas__Geometry__distance_lonlat(this%CPTR_PGIBUG_A, lon1, lat1, lon2, lat2) |
| 157 |
end function Geometry__distance_lonlat_separate_coords |
| 158 |
|
| 159 |
function Geometry__distance_xyz_separate_coords(this, x1, y1, z1, x2, y2, z2) result(distance_xyz) |
| 160 |
use atlas_Geometry_c_binding |
| 161 |
use fckit_c_interop_module |
| 162 |
class(atlas_Geometry), intent(in) :: this |
| 163 |
real(c_double), intent(in) :: x1 |
| 164 |
real(c_double), intent(in) :: y1 |
| 165 |
real(c_double), intent(in) :: z1 |
| 166 |
real(c_double), intent(in) :: x2 |
| 167 |
real(c_double), intent(in) :: y2 |
| 168 |
real(c_double), intent(in) :: z2 |
| 169 |
real(c_double) :: distance_xyz |
| 170 |
distance_xyz = atlas__Geometry__distance_xyz(this%CPTR_PGIBUG_A, x1, y1, z1, x2, y2, z2) |
| 171 |
end function Geometry__distance_xyz_separate_coords |
| 172 |
|
| 173 |
function Geometry__distance_vectorized_coords(this, point1, point2) result(distance_point) |
| 174 |
use atlas_Geometry_c_binding |
| 175 |
use fckit_c_interop_module |
| 176 |
class(atlas_Geometry), intent(in) :: this |
| 177 |
real(c_double), intent(in) :: point1(:) |
| 178 |
real(c_double), intent(in) :: point2(:) |
| 179 |
real(c_double) :: distance_point |
| 180 |
if ((size(point1)==2).and.(size(point2)==2)) then |
| 181 |
! Lon/lat distance |
| 182 |
distance_point = atlas__Geometry__distance_lonlat(this%CPTR_PGIBUG_A, point1(1), point1(2), point2(1), point2(2)) |
| 183 |
elseif ((size(point1)==3).and.(size(point2)==3)) then |
| 184 |
! XYZ distance |
| 185 |
distance_point = atlas__Geometry__distance_xyz(this%CPTR_PGIBUG_A, point1(1), point1(2), point1(3), point2(1), point2(2), & |
| 186 |
& point2(3)) |
| 187 |
else |
| 188 |
! Abort |
| 189 |
call fckit_exception%abort('wrong inputs for geometry distance with vectorized coordinates', 'altas_Geometry_module', 190) |
| 190 |
end if |
| 191 |
end function Geometry__distance_vectorized_coords |
| 192 |
|
| 193 |
function Geometry__radius(this) result(radius) |
| 194 |
use atlas_Geometry_c_binding |
| 195 |
use fckit_c_interop_module |
| 196 |
class(atlas_Geometry), intent(in) :: this |
| 197 |
real(c_double) :: radius |
| 198 |
radius = atlas__Geometry__radius(this%CPTR_PGIBUG_A) |
| 199 |
end function Geometry__radius |
| 200 |
|
| 201 |
function Geometry__area(this) result(area) |
| 202 |
use atlas_Geometry_c_binding |
| 203 |
use fckit_c_interop_module |
| 204 |
class(atlas_Geometry), intent(in) :: this |
| 205 |
real(c_double) :: area |
| 206 |
area = atlas__Geometry__area(this%CPTR_PGIBUG_A) |
| 207 |
end function Geometry__area |
| 208 |
|
| 209 |
!------------------------------------------------------------------------------- |
| 210 |
|
| 211 |
ATLAS_FINAL subroutine atlas_Geometry__final_auto(this) |
| 212 |
type(atlas_Geometry), intent(inout) :: this |
| 213 |
#if FCKIT_FINAL_DEBUGGING |
| 214 |
write(0,*) "atlas_Geometry__final_auto" |
| 215 |
#endif |
| 216 |
#if FCKIT_FINAL_NOT_PROPAGATING |
| 217 |
call this%final() |
| 218 |
#endif |
| 219 |
FCKIT_SUPPRESS_UNUSED( this ) |
| 220 |
end subroutine |
| 221 |
|
| 222 |
end module atlas_Geometry_module |