| 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_multifield_module |
| 12 |
|
| 13 |
use fckit_owned_object_module, only : fckit_owned_object |
| 14 |
use atlas_Config_module, only: atlas_Config |
| 15 |
use atlas_field_module, only: atlas_field, array_c_to_f |
| 16 |
use atlas_fieldset_module, only: atlas_fieldset |
| 17 |
|
| 18 |
implicit none |
| 19 |
|
| 20 |
public :: atlas_MultiField |
| 21 |
|
| 22 |
private |
| 23 |
|
| 24 |
!------------------------------------------------------------------------------ |
| 25 |
TYPE, extends(fckit_owned_object) :: atlas_MultiField |
| 26 |
|
| 27 |
! Purpose : |
| 28 |
! ------- |
| 29 |
! *MultiField* : Object containing field data and Metadata |
| 30 |
|
| 31 |
! Methods : |
| 32 |
! ------- |
| 33 |
! name : The name or tag this field was created with |
| 34 |
! data : Return the field as a fortran array of specified shape |
| 35 |
! Metadata : Return object that can contain a variety of Metadata |
| 36 |
|
| 37 |
! Author : |
| 38 |
! ------ |
| 39 |
! 20-Nov-2013 Willem Deconinck *ECMWF* |
| 40 |
! 29-Aug-2023 Slavko Brdar *ECMWF* |
| 41 |
|
| 42 |
!------------------------------------------------------------------------------ |
| 43 |
contains |
| 44 |
procedure, public :: MultiField__fieldset |
| 45 |
procedure, public :: MultiField__size |
| 46 |
generic :: fieldset => MultiField__fieldset |
| 47 |
generic :: size => MultiField__size |
| 48 |
|
| 49 |
#if FCKIT_FINAL_NOT_INHERITING |
| 50 |
final :: atlas_MultiField__final_auto |
| 51 |
#endif |
| 52 |
|
| 53 |
END TYPE |
| 54 |
|
| 55 |
interface atlas_MultiField |
| 56 |
module procedure atlas_MultiField__cptr |
| 57 |
module procedure atlas_MultiField__create |
| 58 |
module procedure atlas_MultiField__create_names |
| 59 |
end interface |
| 60 |
|
| 61 |
private :: fckit_owned_object |
| 62 |
private :: atlas_Config |
| 63 |
|
| 64 |
!======================================================== |
| 65 |
contains |
| 66 |
!======================================================== |
| 67 |
|
| 68 |
!------------------------------------------------------------------------------- |
| 69 |
|
| 70 |
function atlas_MultiField__cptr(cptr) result(field) |
| 71 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 72 |
type(atlas_MultiField) :: field |
| 73 |
type(c_ptr), intent(in) :: cptr |
| 74 |
call field%reset_c_ptr( cptr ) |
| 75 |
call field%return() |
| 76 |
end function |
| 77 |
|
| 78 |
!------------------------------------------------------------------------------- |
| 79 |
|
| 80 |
function atlas_MultiField__create(params) result(field) |
| 81 |
use atlas_multifield_c_binding |
| 82 |
type(atlas_MultiField) :: field |
| 83 |
class(atlas_Config), intent(in) :: params |
| 84 |
field = atlas_MultiField__cptr( atlas__MultiField__create(params%CPTR_PGIBUG_B) ) |
| 85 |
call field%return() |
| 86 |
end function |
| 87 |
|
| 88 |
!------------------------------------------------------------------------------- |
| 89 |
|
| 90 |
function atlas_MultiField__create_names(kind, shape, field_names) result(field) |
| 91 |
use, intrinsic :: iso_c_binding, only : c_char, c_int, c_int32_t, c_size_t |
| 92 |
use atlas_multifield_c_binding |
| 93 |
type(atlas_MultiField) :: field |
| 94 |
integer(c_int), intent(in) :: kind |
| 95 |
integer, intent(in) :: shape(:) |
| 96 |
character(*), intent(in) :: field_names(:) |
| 97 |
character(kind=c_char,len=:), allocatable :: flat_field_names |
| 98 |
integer(c_size_t) :: length |
| 99 |
integer(c_int32_t) :: ii |
| 100 |
integer(c_int32_t), allocatable :: field_name_sizes(:) |
| 101 |
|
| 102 |
if (size(field_names) == 0 .or. size(shape) < 3) then |
| 103 |
print *, "atlas_MultiField__create_names: must have at least one field name, and the size of shape", & |
| 104 |
& " is minimum 3, e.g. [nproma,-1,nblk]" |
| 105 |
stop -1 |
| 106 |
end if |
| 107 |
|
| 108 |
length = len(field_names(1)) |
| 109 |
allocate(field_name_sizes(size(field_names))) |
| 110 |
field_name_sizes = len(field_names(:)) |
| 111 |
|
| 112 |
if (any(field_name_sizes /= length)) then |
| 113 |
print *, "atlas_MultiField__create_names: field_names have to have same length in characters" |
| 114 |
stop -1 |
| 115 |
end if |
| 116 |
|
| 117 |
allocate(character(len=length*size(field_names) ) :: flat_field_names) |
| 118 |
do ii = 1, size(field_names) |
| 119 |
flat_field_names((ii-1)*length+1:ii*length) = field_names(ii) |
| 120 |
enddo |
| 121 |
|
| 122 |
field = atlas_MultiField__cptr( atlas__MultiField__create_shape(kind, size(shape), shape, & |
| 123 |
& flat_field_names, length, size(field_names,kind=c_size_t)) ) |
| 124 |
call field%return() |
| 125 |
end function |
| 126 |
|
| 127 |
!------------------------------------------------------------------------------- |
| 128 |
|
| 129 |
function MultiField__size(this) result(size) |
| 130 |
use atlas_multifield_c_binding |
| 131 |
class(atlas_MultiField), intent(in) :: this |
| 132 |
integer :: size |
| 133 |
size = atlas__MultiField__size(this%CPTR_PGIBUG_B) |
| 134 |
end function |
| 135 |
|
| 136 |
!------------------------------------------------------------------------------- |
| 137 |
function MultiField__fieldset(this) result(fset) |
| 138 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 139 |
use atlas_multifield_c_binding |
| 140 |
class(atlas_MultiField), intent(in) :: this |
| 141 |
type(c_ptr) :: fset_cptr |
| 142 |
type(atlas_FieldSet) :: fset |
| 143 |
fset_cptr = atlas__MultiField__fieldset(this%CPTR_PGIBUG_B) |
| 144 |
fset = atlas_FieldSet( fset_cptr ) |
| 145 |
call fset%return() |
| 146 |
end function |
| 147 |
|
| 148 |
!------------------------------------------------------------------------------- |
| 149 |
|
| 150 |
#if FCKIT_FINAL_NOT_INHERITING |
| 151 |
ATLAS_FINAL subroutine atlas_MultiField__final_auto(this) |
| 152 |
type(atlas_MultiField), intent(inout) :: this |
| 153 |
#if FCKIT_FINAL_DEBUGGING |
| 154 |
write(0,*) "atlas_MultiField__final_auto" |
| 155 |
#endif |
| 156 |
#if FCKIT_FINAL_NOT_PROPAGATING |
| 157 |
call this%final() |
| 158 |
#endif |
| 159 |
FCKIT_SUPPRESS_UNUSED( this ) |
| 160 |
end subroutine |
| 161 |
#endif |
| 162 |
|
| 163 |
!------------------------------------------------------------------------------- |
| 164 |
|
| 165 |
end module atlas_multifield_module |
| 166 |
|