| 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_Projection_module |
| 12 |
|
| 13 |
use fckit_owned_object_module, only : fckit_owned_object |
| 14 |
use atlas_config_module, only : atlas_Config |
| 15 |
|
| 16 |
implicit none |
| 17 |
|
| 18 |
private :: fckit_owned_object |
| 19 |
private :: atlas_Config |
| 20 |
|
| 21 |
public :: atlas_Projection |
| 22 |
public :: atlas_RotatedLonLatProjection |
| 23 |
public :: atlas_LambertConformalConicProjection |
| 24 |
public :: atlas_RotatedSchmidtProjection |
| 25 |
|
| 26 |
private |
| 27 |
|
| 28 |
!------------------------------------------------------------------------------ |
| 29 |
TYPE, extends(fckit_owned_object) :: atlas_Projection |
| 30 |
|
| 31 |
! Purpose : |
| 32 |
! ------- |
| 33 |
! *atlas_Projection* : |
| 34 |
|
| 35 |
! Methods : |
| 36 |
! ------- |
| 37 |
! type: The name or tag this function space was created with |
| 38 |
|
| 39 |
! Author : |
| 40 |
! ------ |
| 41 |
! May-2020 Willem Deconinck *ECMWF* |
| 42 |
|
| 43 |
!------------------------------------------------------------------------------ |
| 44 |
contains |
| 45 |
procedure, public :: type => atlas_Projection__type |
| 46 |
procedure, public :: hash |
| 47 |
procedure, public :: spec |
| 48 |
procedure, public :: xy2lonlat |
| 49 |
procedure, public :: lonlat2xy |
| 50 |
|
| 51 |
#if FCKIT_FINAL_NOT_INHERITING |
| 52 |
final :: atlas_Projection__final_auto |
| 53 |
#endif |
| 54 |
|
| 55 |
END TYPE atlas_Projection |
| 56 |
|
| 57 |
interface atlas_Projection |
| 58 |
module procedure atlas_Projection__ctor_cptr |
| 59 |
module procedure atlas_Projection__ctor_config |
| 60 |
end interface |
| 61 |
|
| 62 |
interface atlas_RotatedSchmidtProjection |
| 63 |
module procedure atlas_RotatedSchmidtProjection_real64 |
| 64 |
end interface |
| 65 |
|
| 66 |
interface atlas_LambertConformalConicProjection |
| 67 |
module procedure atlas_LambertConformalConicProjection_real64 |
| 68 |
end interface |
| 69 |
|
| 70 |
interface atlas_RotatedLonLatProjection |
| 71 |
module procedure atlas_RotatedLonLatProjection_NP_real64 |
| 72 |
end interface |
| 73 |
|
| 74 |
!======================================================== |
| 75 |
contains |
| 76 |
!======================================================== |
| 77 |
|
| 78 |
function atlas_Projection__ctor_cptr(cptr) result(this) |
| 79 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 80 |
type(atlas_Projection) :: this |
| 81 |
type(c_ptr), intent(in) :: cptr |
| 82 |
call this%reset_c_ptr( cptr ) |
| 83 |
call this%return() |
| 84 |
end function |
| 85 |
|
| 86 |
function atlas_Projection__ctor_config(config) result(this) |
| 87 |
use atlas_projection_c_binding |
| 88 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 89 |
type(atlas_Projection) :: this |
| 90 |
type(atlas_Config) :: config |
| 91 |
call this%reset_c_ptr( atlas__Projection__ctor_config(config%CPTR_PGIBUG_B) ) |
| 92 |
call this%return() |
| 93 |
end function |
| 94 |
|
| 95 |
function atlas_Projection__type(this) result(type_) |
| 96 |
use atlas_projection_c_binding |
| 97 |
use fckit_c_interop_module, only : c_ptr_to_string, c_ptr_free |
| 98 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 99 |
class(atlas_Projection), intent(in) :: this |
| 100 |
character(len=:), allocatable :: type_ |
| 101 |
type(c_ptr) :: type_c_str |
| 102 |
integer :: size |
| 103 |
call atlas__Projection__type(this%CPTR_PGIBUG_A, type_c_str, size ) |
| 104 |
type_ = c_ptr_to_string(type_c_str) |
| 105 |
call c_ptr_free(type_c_str) |
| 106 |
end function |
| 107 |
|
| 108 |
function hash(this) |
| 109 |
use atlas_projection_c_binding |
| 110 |
use fckit_c_interop_module, only : c_ptr_to_string, c_ptr_free |
| 111 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 112 |
class(atlas_Projection), intent(in) :: this |
| 113 |
character(len=:), allocatable :: hash |
| 114 |
type(c_ptr) :: hash_c_str |
| 115 |
integer :: size |
| 116 |
call atlas__Projection__hash(this%CPTR_PGIBUG_A, hash_c_str, size ) |
| 117 |
hash = c_ptr_to_string(hash_c_str) |
| 118 |
call c_ptr_free(hash_c_str) |
| 119 |
end function |
| 120 |
|
| 121 |
function spec(this) |
| 122 |
use atlas_projection_c_binding |
| 123 |
class(atlas_Projection), intent(in) :: this |
| 124 |
type(atlas_Config) :: spec |
| 125 |
spec = atlas_Config( atlas__Projection__spec(this%CPTR_PGIBUG_A) ) |
| 126 |
call spec%return() |
| 127 |
end function |
| 128 |
|
| 129 |
subroutine xy2lonlat(this, x, y, lon, lat) |
| 130 |
use atlas_projection_c_binding |
| 131 |
use, intrinsic :: iso_c_binding, only : c_double |
| 132 |
class(atlas_Projection), intent(in) :: this |
| 133 |
real(c_double), intent(in) :: x |
| 134 |
real(c_double), intent(in) :: y |
| 135 |
real(c_double), intent(out) :: lon |
| 136 |
real(c_double), intent(out) :: lat |
| 137 |
call atlas__Projection__xy2lonlat(this%CPTR_PGIBUG_A, x, y, lon, lat ) |
| 138 |
end subroutine |
| 139 |
|
| 140 |
subroutine lonlat2xy(this, lon, lat, x, y) |
| 141 |
use atlas_projection_c_binding |
| 142 |
use, intrinsic :: iso_c_binding, only : c_double |
| 143 |
class(atlas_Projection), intent(in) :: this |
| 144 |
real(c_double), intent(in) :: lon |
| 145 |
real(c_double), intent(in) :: lat |
| 146 |
real(c_double), intent(out) :: x |
| 147 |
real(c_double), intent(out) :: y |
| 148 |
call atlas__Projection__lonlat2xy(this%CPTR_PGIBUG_A, lon, lat, x, y ) |
| 149 |
end subroutine |
| 150 |
|
| 151 |
!------------------------------------------------------------------------------ |
| 152 |
|
| 153 |
#if FCKIT_FINAL_NOT_INHERITING |
| 154 |
ATLAS_FINAL subroutine atlas_Projection__final_auto(this) |
| 155 |
type(atlas_Projection), intent(inout) :: this |
| 156 |
#if FCKIT_FINAL_DEBUGGING |
| 157 |
write(0,*) "atlas_Projection__final_auto" |
| 158 |
#endif |
| 159 |
#if FCKIT_FINAL_NOT_PROPAGATING |
| 160 |
call this%final() |
| 161 |
#endif |
| 162 |
FCKIT_SUPPRESS_UNUSED( this ) |
| 163 |
end subroutine |
| 164 |
#endif |
| 165 |
|
| 166 |
!------------------------------------------------------------------------------ |
| 167 |
|
| 168 |
|
| 169 |
function atlas_RotatedSchmidtProjection_real64(stretching_factor,north_pole,rotation_angle) result(this) |
| 170 |
use, intrinsic :: iso_c_binding, only : c_double |
| 171 |
type(atlas_Projection) :: this |
| 172 |
real(c_double), intent(in) :: stretching_factor |
| 173 |
real(c_double), intent(in), optional :: north_pole(2) |
| 174 |
real(c_double), intent(in), optional :: rotation_angle |
| 175 |
type(atlas_Config) :: config |
| 176 |
config = atlas_Config() |
| 177 |
call config%set("type","rotated_schmidt") |
| 178 |
call config%set("stretching_factor",stretching_factor) |
| 179 |
if( present(rotation_angle) ) then |
| 180 |
call config%set("rotation_angle", rotation_angle) |
| 181 |
endif |
| 182 |
if( present(north_pole) ) then |
| 183 |
call config%set("north_pole",north_pole) |
| 184 |
endif |
| 185 |
this = atlas_Projection(config) |
| 186 |
call this%return() |
| 187 |
end function |
| 188 |
|
| 189 |
! ----------------------------------------------------------------------------- |
| 190 |
|
| 191 |
function atlas_LambertConformalConicProjection_real64(longitude0,latitude0,latitude1,latitude2) result(this) |
| 192 |
use, intrinsic :: iso_c_binding, only : c_double |
| 193 |
type(atlas_Projection) :: this |
| 194 |
real(c_double), intent(in) :: longitude0 |
| 195 |
real(c_double), intent(in) :: latitude0 |
| 196 |
real(c_double), intent(in), optional :: latitude1 |
| 197 |
real(c_double), intent(in), optional :: latitude2 |
| 198 |
type(atlas_Config) :: config |
| 199 |
config = atlas_Config() |
| 200 |
call config%set("type","lambert_conformal_conic") |
| 201 |
call config%set("longitude0",longitude0) |
| 202 |
call config%set("latitude0",latitude0) |
| 203 |
if( present(latitude1) ) then |
| 204 |
call config%set("latitude1", latitude1) |
| 205 |
endif |
| 206 |
if( present(latitude2) ) then |
| 207 |
call config%set("latitude2",latitude2) |
| 208 |
endif |
| 209 |
this = atlas_Projection(config) |
| 210 |
call this%return() |
| 211 |
end function |
| 212 |
|
| 213 |
! ----------------------------------------------------------------------------- |
| 214 |
|
| 215 |
function atlas_RotatedLonLatProjection_NP_real64(north_pole,rotation_angle) result(this) |
| 216 |
use, intrinsic :: iso_c_binding, only : c_double |
| 217 |
type(atlas_Projection) :: this |
| 218 |
real(c_double), intent(in) :: north_pole(2) |
| 219 |
real(c_double), intent(in), optional :: rotation_angle |
| 220 |
type(atlas_Config) :: config |
| 221 |
config = atlas_Config() |
| 222 |
call config%set("type","rotated_lonlat") |
| 223 |
call config%set("north_pole",north_pole) |
| 224 |
if( present(rotation_angle) ) then |
| 225 |
call config%set("rotation_angle", rotation_angle) |
| 226 |
endif |
| 227 |
this = atlas_Projection(config) |
| 228 |
call this%return() |
| 229 |
end function |
| 230 |
|
| 231 |
! ----------------------------------------------------------------------------- |
| 232 |
|
| 233 |
end module atlas_Projection_module |
| 234 |
|