File: fields.F90

package info (click to toggle)
metview 5.26.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 614,356 kB
  • sloc: cpp: 560,586; ansic: 44,641; xml: 19,933; f90: 17,984; sh: 7,454; python: 5,565; yacc: 2,318; lex: 1,372; perl: 701; makefile: 88
file content (86 lines) | stat: -rw-r--r-- 2,748 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
program main

use, intrinsic :: iso_c_binding, only : c_double
use atlas_module
implicit none

integer, parameter            :: wp = c_double
integer                       :: jnode
character(len=1024)           :: string
character(len=:), allocatable :: unitsW, unitsP
type(atlas_Field)             :: field_pressure , field_wind
type(atlas_Field)             :: field_pressure2, field_wind2
real(wp), pointer             :: pressure(:), wind    (:,:)
type(atlas_FieldSet)          :: fields
type(atlas_Metadata)          :: metadata
call atlas_library%initialise()

! Define fields
field_pressure = atlas_Field(name="pressure", kind=atlas_real(wp), shape=[100])
field_wind     = atlas_Field(name="wind"    , kind=atlas_real(wp), shape=[2, 100])

! Access fields data
call field_pressure%data(pressure)
call field_wind    %data(wind)

! Assign values to fields
do jnode=1,100
  pressure(jnode) = 101325._wp
  wind(1, jnode)  = 0.01_wp + real(jnode,kind=wp)
  wind(2, jnode)  = 0.02_wp + real(jnode,kind=wp)
enddo

! Add info to fields
metadata = field_pressure%metadata()
call metadata%set("units", "[Pa]")
call metadata%get("units", unitsP)
metadata = field_wind%metadata()
call metadata%set("units", "[m/s]")
call metadata%get("units", unitsW)

! Define fieldSet
fields = atlas_FieldSet()
call fields%add(field_pressure) ! Add field_pressure to fieldSet
call fields%add(field_wind)     ! Add field_wind to fieldSet

! Retrieve field from fieldSet
field_pressure2 = fields%field("pressure")
field_wind2     = fields%field("wind")

! Print some useful info
write(string, *) "name   = ", field_wind%name()
call atlas_log%info(string)
write(string, *) "size   = ", field_wind%size()
call atlas_log%info(string)
write(string, *) "units  = ", unitsW
call atlas_log%info(string)
write(string, *) "rank   = ", field_wind%rank()
call atlas_log%info(string)
write(string, *) "shape(1)  = ", field_wind%shape(1)
call atlas_log%info(string)
write(string, *) "shape(2)  = ", field_wind%shape(2)
call atlas_log%info(string)
write(string, *) "shape  = ", field_wind%shape()
call atlas_log%info(string)
write(string, *) "memory = ", field_wind%bytes(), "bytes"
call atlas_log%info(string)
write(string, *) "type   = ", field_wind%datatype()
call atlas_log%info(string)
write(string, *) "kind   = ", field_wind%kind()
call atlas_log%info(string)

! Print some values
write(string, *) "pressure(10) = ", pressure(10)
call atlas_log%info(string)
write(string, *) "wind(1, 10)  = ", wind(1,10)
call atlas_log%info(string)
write(string, *) "wind(2, 10)  = ", wind(2,10)
call atlas_log%info(string)

! Finalize object to release memory
call field_pressure%final()
call field_wind    %final()
call fields        %final()

call atlas_library%finalise()
end program main