UFO
ufo_locations_mod.F90
Go to the documentation of this file.
1 !
2 ! (C) Copyright 2020 UCAR
3 !
4 ! This software is licensed under the terms of the Apache Licence Version 2.0
5 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 
7 !> Fortran interface to ufo::Locations
8 
10 
11 use iso_c_binding
12 implicit none
13 
14 public :: ufo_locations
15 
17 private
18  type(c_ptr) :: ptr
19 contains
20  procedure, public :: nlocs
21  procedure, public :: get_lons
22  procedure, public :: get_lats
23  procedure, public :: get_timemask
24 end type
25 
26 interface ufo_locations
27  module procedure ctor_from_ptr
28 end interface
29 
30 private
31 
32 #include "ufo/locations_interface.f"
33 
34 contains
35 
36 !-------------------------------------------------------------------------------
37 !> Saves pointer to locations
38 function ctor_from_ptr(ptr) result(this)
39  type(ufo_locations) :: this
40  type(c_ptr), intent(in) :: ptr
41 
42  this%ptr = ptr
43 end function ctor_from_ptr
44 
45 !-------------------------------------------------------------------------------
46 !> Return the number of observational locations in this Locations object
47 integer function nlocs(this)
48  implicit none
49  class(ufo_locations), intent(in) :: this
50 
51  ! Implicit conversion from c_size_t to integer which is safe in this case
52  nlocs = c_locations_get_nlocs(this%ptr)
53 end function nlocs
54 
55 !-------------------------------------------------------------------------------
56 
57 !> Get longitudes from the Locations object
58 subroutine get_lons(this, lons)
59  implicit none
60  class(ufo_locations), intent(in) :: this
61  real(c_double), intent(inout) :: lons(:)
62 
63  integer(c_size_t) :: length
64 
65  length = size(lons)
66  call c_locations_get_lons(this%ptr, length, lons)
67 
68 end subroutine get_lons
69 
70 !-------------------------------------------------------------------------------
71 
72 !> Get latitudes from the Locations object
73 subroutine get_lats(this, lats)
74  implicit none
75  class(ufo_locations), intent(in) :: this
76  real(c_double), intent(inout) :: lats(:)
77 
78  integer(c_size_t) :: length
79 
80  length = size(lats)
81  call c_locations_get_lats(this%ptr, length, lats)
82 
83 end subroutine get_lats
84 
85 !-------------------------------------------------------------------------------
86 
87 !> Get time mask (obs that are between t1 & t2) from the Locations object
88 subroutine get_timemask(this, t1, t2, mask)
89  use datetime_mod
90  implicit none
91  class(ufo_locations), intent(in) :: this
92  type(datetime), intent(in) :: t1, t2
93  logical(c_bool), intent(inout) :: mask(:)
94 
95  integer(c_size_t) :: length
96  type(c_ptr) :: c_t1, c_t2
97 
98  length = size(mask)
99  call f_c_datetime(t1, c_t1)
100  call f_c_datetime(t2, c_t2)
101  call c_locations_get_timemask(this%ptr, c_t1, c_t2, length, mask)
102 
103 end subroutine get_timemask
104 
105 !-------------------------------------------------------------------------------
106 
107 end module ufo_locations_mod
Define interface for C++ ufo::Locations code called from Fortran.
Fortran interface to ufo::Locations.
subroutine get_lons(this, lons)
Get longitudes from the Locations object.
subroutine get_lats(this, lats)
Get latitudes from the Locations object.
subroutine get_timemask(this, t1, t2, mask)
Get time mask (obs that are between t1 & t2) from the Locations object.
type(ufo_locations) function ctor_from_ptr(ptr)
Saves pointer to locations.
integer function nlocs(this)
Return the number of observational locations in this Locations object.