31 class(fmsnetcdffile_t),
intent(in) :: fileobj
32 character(len=*),
intent(in) :: attribute_name
33 class(*),
intent(inout) :: attribute_value
34 logical,
intent(in),
optional :: broadcast
41 character(len=1024),
dimension(1) :: charbuf
43 if (fileobj%is_root)
then
44 select type(attribute_value)
45 type is (
character(len=*))
46 err = nf90_get_att(fileobj%ncid, &
48 trim(attribute_name), &
50 call string_copy(attribute_value, charbuf(1), check_for_null=.true.)
51 type is (
integer(kind=i4_kind))
52 err = nf90_get_att(fileobj%ncid, &
54 trim(attribute_name), &
56 type is (
integer(kind=i8_kind))
57 if ( .not. fileobj%is_netcdf4)
call error(trim(fileobj%path)// &
58 &
": 64 bit integers are only supported with 'netcdf4' file format"//&
59 &
". Set netcdf_default_format='netcdf4' in the fms2_io namelist OR "//&
60 &
"add nc_format='netcdf4' to your open_file call")
61 err = nf90_get_att(fileobj%ncid, &
63 trim(attribute_name), &
65 type is (real(kind=r4_kind))
66 err = nf90_get_att(fileobj%ncid, &
68 trim(attribute_name), &
70 type is (real(kind=r8_kind))
71 err = nf90_get_att(fileobj%ncid, &
73 trim(attribute_name), &
76 call error(
"get_global_attribute_0d: unsupported type for "//&
77 &trim(attribute_name)//
" for file: "//trim(fileobj%path)//
"")
79 call check_netcdf_code(err,
"get_global_attribute_0d: file:"//trim(fileobj%path)//
"- attribute:"// &
80 & trim(attribute_name))
82 if (
present(broadcast))
then
83 if (.not. broadcast)
then
87 select type(attribute_value)
88 type is (
character(len=*))
89 call mpp_broadcast(charbuf, len(charbuf), &
91 pelist=fileobj%pelist)
92 call string_copy(attribute_value, charbuf(1), check_for_null=.true.)
93 type is (
integer(kind=i4_kind))
94 call mpp_broadcast(attribute_value, &
97 pelist=fileobj%pelist)
98 type is (
integer(kind=i8_kind))
99 call mpp_broadcast(attribute_value, &
102 pelist=fileobj%pelist)
103 type is (real(kind=r4_kind))
104 call mpp_broadcast(attribute_value, &
107 pelist=fileobj%pelist)
108 type is (real(kind=r8_kind))
109 call mpp_broadcast(attribute_value, &
112 pelist=fileobj%pelist)
114 call error(
"get_global_attribute_0d: unsupported type for "//&
115 &trim(attribute_name)//
" for file: "//trim(fileobj%path)//
"")
123 class(fmsnetcdffile_t),
intent(in) :: fileobj
124 character(len=*),
intent(in) :: attribute_name
125 class(*),
dimension(:),
intent(inout) :: attribute_value
126 logical,
intent(in),
optional :: broadcast
133 if (fileobj%is_root)
then
134 select type(attribute_value)
135 type is (
integer(kind=i4_kind))
136 err = nf90_get_att(fileobj%ncid, &
138 trim(attribute_name), &
140 type is (
integer(kind=i8_kind))
141 if ( .not. fileobj%is_netcdf4)
call error(trim(fileobj%path)// &
142 &
": 64 bit integers are only supported with 'netcdf4' file format"//&
143 &
". Set netcdf_default_format='netcdf4' in the fms2_io namelist OR "//&
144 &
"add nc_format='netcdf4' to your open_file call")
145 err = nf90_get_att(fileobj%ncid, &
147 trim(attribute_name), &
149 type is (real(kind=r4_kind))
150 err = nf90_get_att(fileobj%ncid, &
152 trim(attribute_name), &
154 type is (real(kind=r8_kind))
155 err = nf90_get_att(fileobj%ncid, &
157 trim(attribute_name), &
160 call error(
"get_global_attribute_1d: unsupported type for "//&
161 &trim(attribute_name)//
" for file: "//trim(fileobj%path)//
"")
163 call check_netcdf_code(err,
"get_global_attribute_1d: file:"//trim(fileobj%path)//
"- attribute:"// &
164 & trim(attribute_name))
166 if (
present(broadcast))
then
167 if (.not. broadcast)
then
171 select type(attribute_value)
172 type is (
integer(kind=i4_kind))
173 call mpp_broadcast(attribute_value, &
174 size(attribute_value), &
176 pelist=fileobj%pelist)
177 type is (
integer(kind=i8_kind))
178 call mpp_broadcast(attribute_value, &
179 size(attribute_value), &
181 pelist=fileobj%pelist)
182 type is (real(kind=r4_kind))
183 call mpp_broadcast(attribute_value, &
184 size(attribute_value), &
186 pelist=fileobj%pelist)
187 type is (real(kind=r8_kind))
188 call mpp_broadcast(attribute_value, &
189 size(attribute_value), &
191 pelist=fileobj%pelist)
193 call error(
"get_global_attribute_1d: unsupported type for "//&
194 &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.