11 use atlas_module,
only: atlas_field,atlas_fieldset,atlas_integer,atlas_real,atlas_functionspace,atlas_functionspace_nodecolumns, &
12 & atlas_functionspace_pointcloud,atlas_functionspace_structuredcolumns
43 type(atlas_field),
intent(in) :: afield
44 real(kind_real),
intent(out) :: fld(:,:)
45 character(len=*),
intent(in),
optional :: lev2d
49 real(kind_real),
pointer :: ptr_1(:),ptr_2(:,:)
50 character(len=1024) :: llev2d
51 character(len=1024),
parameter :: subr =
'field_to_array_real'
52 type(atlas_functionspace) :: afunctionspace
53 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
54 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
55 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
59 if (
present(lev2d)) llev2d = lev2d
62 if (afield%kind()/=atlas_real(kind_real))
call mpl%abort(subr,
'wrong kind for field '//afield%name())
65 afunctionspace = afield%functionspace()
67 select case (afunctionspace%name())
70 afunctionspace_nc = afield%functionspace()
73 nmga = afunctionspace_nc%nb_nodes()
76 afunctionspace_pc = afield%functionspace()
79 nmga = afunctionspace_pc%size()
80 case (
'StructuredColumns')
82 afunctionspace_sc = afield%functionspace()
85 nmga = afunctionspace_sc%size_owned()
87 call mpl%abort(subr,
'wrong function space for field '//afield%name()//
': '//afunctionspace%name())
91 if (nmga/=
size(fld,1))
call mpl%abort(subr,
'wrong number of nodes for field '//afield%name())
97 nl0 = min(afield%levels(),
size(fld,2))
108 if (
size(fld,2)>0)
then
109 call afield%data(ptr_1)
110 if (trim(llev2d)==
'first')
then
111 fld(1:nmga,1) = ptr_1(1:nmga)
112 elseif (trim(llev2d)==
'last')
then
113 fld(1:nmga,
size(fld,2)) = ptr_1(1:nmga)
117 call afield%data(ptr_2)
118 fld(1:nmga,1:nl0) = transpose(ptr_2(1:nl0,1:nmga))
133 type(atlas_field),
intent(in) :: afield
134 logical,
intent(out) :: fld(:,:)
135 character(len=*),
intent(in),
optional :: lev2d
138 integer :: nmga,nl0,imga,il0
139 integer,
allocatable :: fld_int(:,:)
140 integer,
pointer :: ptr_1(:),ptr_2(:,:)
141 character(len=1024) :: llev2d
142 character(len=1024),
parameter :: subr =
'field_to_array_logical'
143 type(atlas_functionspace) :: afunctionspace
144 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
145 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
146 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
150 if (
present(lev2d)) llev2d = lev2d
153 if (afield%kind()/=atlas_integer(
kind_int))
call mpl%abort(subr,
'wrong kind for field '//afield%name())
156 afunctionspace = afield%functionspace()
158 select case (afunctionspace%name())
161 afunctionspace_nc = afield%functionspace()
164 nmga = afunctionspace_nc%nb_nodes()
167 afunctionspace_pc = afield%functionspace()
170 nmga = afunctionspace_pc%size()
171 case (
'StructuredColumns')
173 afunctionspace_sc = afield%functionspace()
176 nmga = afunctionspace_sc%size_owned()
178 call mpl%abort(subr,
'wrong function space for field '//afield%name()//
': '//afunctionspace%name())
182 if (nmga/=
size(fld,1))
call mpl%abort(subr,
'wrong number of nodes for field '//afield%name())
188 nl0 = min(afield%levels(),
size(fld,2))
191 allocate(fld_int(
size(fld,1),
size(fld,2)))
202 if (
size(fld,2)>0)
then
203 call afield%data(ptr_1)
204 if (trim(llev2d)==
'first')
then
205 fld_int(1:nmga,1) = ptr_1(1:nmga)
206 elseif (trim(llev2d)==
'last')
then
207 fld_int(1:nmga,
size(fld,2)) = ptr_1(1:nmga)
211 call afield%data(ptr_2)
212 fld_int(1:nmga,1:nl0) = transpose(ptr_2(1:nl0,1:nmga))
217 do imga=1,
size(fld,1)
218 if (fld_int(imga,il0)==0)
then
219 fld(imga,il0) = .false.
220 elseif (fld_int(imga,il0)==1)
then
221 fld(imga,il0) = .true.
223 call mpl%abort(subr,
'wrong value in 0-1 integer field for field '//afield%name())
243 real(kind_real),
intent(in) :: fld(:,:)
244 type(atlas_field),
intent(inout) :: afield
245 character(len=*),
intent(in),
optional :: lev2d
249 real(kind_real),
pointer :: ptr_1(:),ptr_2(:,:)
250 character(len=1024) :: llev2d
251 character(len=1024),
parameter :: subr =
'field_from_array_real'
252 type(atlas_functionspace) :: afunctionspace
253 type(atlas_functionspace_nodecolumns) :: afunctionspace_nc
254 type(atlas_functionspace_pointcloud) :: afunctionspace_pc
255 type(atlas_functionspace_structuredcolumns) :: afunctionspace_sc
259 if (
present(lev2d)) llev2d = lev2d
262 if (afield%kind()/=atlas_real(kind_real))
call mpl%abort(subr,
'wrong kind for field '//afield%name())
265 afunctionspace = afield%functionspace()
267 select case (afunctionspace%name())
270 afunctionspace_nc = afield%functionspace()
273 nmga = afunctionspace_nc%nb_nodes()
276 afunctionspace_pc = afield%functionspace()
279 nmga = afunctionspace_pc%size()
280 case (
'StructuredColumns')
282 afunctionspace_sc = afield%functionspace()
285 nmga = afunctionspace_sc%size_owned()
287 call mpl%abort(subr,
'wrong function space for field '//afield%name()//
': '//afunctionspace%name())
294 nl0 = min(afield%levels(),
size(fld,2))
297 if (nmga/=
size(fld,1))
call mpl%abort(subr,
'wrong number of nodes for field '//afield%name())
305 if (
size(fld,2)>0)
then
306 call afield%data(ptr_1)
307 if (trim(llev2d)==
'first')
then
308 ptr_1(1:nmga) = fld(1:nmga,1)
309 elseif (trim(llev2d)==
'last')
then
310 ptr_1(1:nmga) = fld(1:nmga,
size(fld,2))
314 call afield%data(ptr_2)
315 ptr_2(1:nl0,1:nmga) = transpose(fld(1:nmga,1:nl0))
329 integer,
intent(in) :: nmga
330 real(
kind_real),
intent(in) :: lon_mga(nmga)
331 real(
kind_real),
intent(in) :: lat_mga(nmga)
332 type(atlas_functionspace),
intent(out) :: afunctionspace
337 type(atlas_field) :: afield
340 afield = atlas_field(name=
"lonlat",kind=atlas_real(
kind_real),shape=(/2,nmga/))
341 call afield%data(real_ptr)
343 real_ptr(1,imga) = lon_mga(imga)*
rad2deg
344 real_ptr(2,imga) = lat_mga(imga)*
rad2deg
348 afunctionspace = atlas_functionspace_pointcloud(afield)