30 class(fmsnetcdffile_t),
intent(in) :: fileobj
31 character(len=*),
intent(in) :: attribute_name
32 class(*),
intent(inout) :: attribute_value
33 logical,
intent(in),
optional :: broadcast
40 character(len=1024),
dimension(1) :: charbuf
42 if (fileobj%is_root)
then
43 select type(attribute_value)
44 type is (
character(len=*))
45 err = nf90_get_att(fileobj%ncid, &
47 trim(attribute_name), &
49 call string_copy(attribute_value, charbuf(1), check_for_null=.true.)
50 type is (
integer(kind=i4_kind))
51 err = nf90_get_att(fileobj%ncid, &
53 trim(attribute_name), &
55 type is (
integer(kind=i8_kind))
56 if ( .not. fileobj%is_netcdf4)
call error(trim(fileobj%path)// &
57 &
": 64 bit integers are only supported with 'netcdf4' file format"//&
58 &
". Set netcdf_default_format='netcdf4' in the fms2_io namelist OR "//&
59 &
"add nc_format='netcdf4' to your open_file call")
60 err = nf90_get_att(fileobj%ncid, &
62 trim(attribute_name), &
64 type is (real(kind=r4_kind))
65 err = nf90_get_att(fileobj%ncid, &
67 trim(attribute_name), &
69 type is (real(kind=r8_kind))
70 err = nf90_get_att(fileobj%ncid, &
72 trim(attribute_name), &
75 call error(
"get_global_attribute_0d: unsupported type for "//&
76 &trim(attribute_name)//
" for file: "//trim(fileobj%path)//
"")
78 call check_netcdf_code(err,
"get_global_attribute_0d: file:"//trim(fileobj%path)//
"- attribute:"// &
79 & trim(attribute_name))
81 if (
present(broadcast))
then
82 if (.not. broadcast)
then
86 select type(attribute_value)
87 type is (
character(len=*))
88 call mpp_broadcast(charbuf, len(charbuf), &
90 pelist=fileobj%pelist)
91 call string_copy(attribute_value, charbuf(1), check_for_null=.true.)
92 type is (
integer(kind=i4_kind))
93 call mpp_broadcast(attribute_value, &
96 pelist=fileobj%pelist)
97 type is (
integer(kind=i8_kind))
98 call mpp_broadcast(attribute_value, &
101 pelist=fileobj%pelist)
102 type is (real(kind=r4_kind))
103 call mpp_broadcast(attribute_value, &
106 pelist=fileobj%pelist)
107 type is (real(kind=r8_kind))
108 call mpp_broadcast(attribute_value, &
111 pelist=fileobj%pelist)
113 call error(
"get_global_attribute_0d: unsupported type for "//&
114 &trim(attribute_name)//
" for file: "//trim(fileobj%path)//
"")
122 class(fmsnetcdffile_t),
intent(in) :: fileobj
123 character(len=*),
intent(in) :: attribute_name
124 class(*),
dimension(:),
intent(inout) :: attribute_value
125 logical,
intent(in),
optional :: broadcast
132 if (fileobj%is_root)
then
133 select type(attribute_value)
134 type is (
integer(kind=i4_kind))
135 err = nf90_get_att(fileobj%ncid, &
137 trim(attribute_name), &
139 type is (
integer(kind=i8_kind))
140 if ( .not. fileobj%is_netcdf4)
call error(trim(fileobj%path)// &
141 &
": 64 bit integers are only supported with 'netcdf4' file format"//&
142 &
". Set netcdf_default_format='netcdf4' in the fms2_io namelist OR "//&
143 &
"add nc_format='netcdf4' to your open_file call")
144 err = nf90_get_att(fileobj%ncid, &
146 trim(attribute_name), &
148 type is (real(kind=r4_kind))
149 err = nf90_get_att(fileobj%ncid, &
151 trim(attribute_name), &
153 type is (real(kind=r8_kind))
154 err = nf90_get_att(fileobj%ncid, &
156 trim(attribute_name), &
159 call error(
"get_global_attribute_1d: unsupported type for "//&
160 &trim(attribute_name)//
" for file: "//trim(fileobj%path)//
"")
162 call check_netcdf_code(err,
"get_global_attribute_1d: file:"//trim(fileobj%path)//
"- attribute:"// &
163 & trim(attribute_name))
165 if (
present(broadcast))
then
166 if (.not. broadcast)
then
170 select type(attribute_value)
171 type is (
integer(kind=i4_kind))
172 call mpp_broadcast(attribute_value, &
173 size(attribute_value), &
175 pelist=fileobj%pelist)
176 type is (
integer(kind=i8_kind))
177 call mpp_broadcast(attribute_value, &
178 size(attribute_value), &
180 pelist=fileobj%pelist)
181 type is (real(kind=r4_kind))
182 call mpp_broadcast(attribute_value, &
183 size(attribute_value), &
185 pelist=fileobj%pelist)
186 type is (real(kind=r8_kind))
187 call mpp_broadcast(attribute_value, &
188 size(attribute_value), &
190 pelist=fileobj%pelist)
192 call error(
"get_global_attribute_1d: unsupported type for "//&
193 &trim(attribute_name)//
" for file: "//trim(fileobj%path)//
"")
subroutine get_global_attribute_1d(fileobj, attribute_name, attribute_value, broadcast)
Get the value of a global attribute.
subroutine get_global_attribute_0d(fileobj, attribute_name, attribute_value, broadcast)
Get the value of a global attribute.