28 attribute_value, broadcast, reproduce_null_char_bug_flag)
30 class(fmsnetcdffile_t),
intent(in) :: fileobj
31 character(len=*),
intent(in) :: variable_name
32 character(len=*),
intent(in) :: attribute_name
33 class(*),
intent(inout) :: attribute_value
34 logical,
intent(in),
optional :: broadcast
40 logical,
intent(in),
optional :: reproduce_null_char_bug_flag
46 character(len=200) :: append_error_msg
47 character(len=1024),
dimension(1) :: charbuf
48 logical :: reproduce_null_char_bug
52 reproduce_null_char_bug = .false.
53 if (
present(reproduce_null_char_bug_flag)) reproduce_null_char_bug=reproduce_null_char_bug_flag
55 append_error_msg =
"get_variable_attribute_0d: file:"//trim(fileobj%path)//
"- variable:"//&
56 &trim(variable_name)//
" attribute: "//trim(attribute_name)
58 if (fileobj%is_root)
then
59 varid = get_variable_id(fileobj%ncid, trim(variable_name), msg=append_error_msg)
60 select type(attribute_value)
61 type is (
character(len=*))
62 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), charbuf(1))
63 if (reproduce_null_char_bug)
then
64 call string_copy(attribute_value, charbuf(1), check_for_null=.false.)
66 call string_copy(attribute_value, charbuf(1), check_for_null=.true.)
68 type is (
integer(kind=i4_kind))
69 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
70 type is (
integer(kind=i8_kind))
71 if ( .not. fileobj%is_netcdf4)
call error(trim(fileobj%path)// &
72 &
": 64 bit integers are only supported with 'netcdf4' file format"//&
73 &
". Set netcdf_default_format='netcdf4' in the fms2_io namelist OR "//&
74 &
"add nc_format='netcdf4' to your open_file call")
75 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
76 type is (real(kind=r4_kind))
77 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
78 type is (real(kind=r8_kind))
79 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
81 call error(
"unsupported attribute type: "//trim(append_error_msg))
83 call check_netcdf_code(err, append_error_msg)
85 if (
present(broadcast))
then
86 if (.not. broadcast)
then
90 select type(attribute_value)
91 type is (
character(len=*))
92 call mpp_broadcast(charbuf, len(charbuf), fileobj%io_root, pelist=fileobj%pelist)
93 if (reproduce_null_char_bug)
then
94 call string_copy(attribute_value, charbuf(1), check_for_null=.false.)
96 call string_copy(attribute_value, charbuf(1), check_for_null=.true.)
98 type is (
integer(kind=i4_kind))
99 call mpp_broadcast(attribute_value, fileobj%io_root, pelist=fileobj%pelist)
100 type is (
integer(kind=i8_kind))
101 call mpp_broadcast(attribute_value, fileobj%io_root, pelist=fileobj%pelist)
102 type is (real(kind=r4_kind))
103 call mpp_broadcast(attribute_value, fileobj%io_root, pelist=fileobj%pelist)
104 type is (real(kind=r8_kind))
105 call mpp_broadcast(attribute_value, fileobj%io_root, pelist=fileobj%pelist)
107 call error(
"unsupported attribute type: "//trim(append_error_msg))
114 attribute_value, broadcast)
116 class(fmsnetcdffile_t),
intent(in) :: fileobj
117 character(len=*),
intent(in) :: variable_name
118 character(len=*),
intent(in) :: attribute_name
119 class(*),
dimension(:),
intent(inout) :: attribute_value
120 logical,
intent(in),
optional :: broadcast
129 character(len=200) :: append_error_msg
131 append_error_msg =
"get_variable_attribute_1d: file:"//trim(fileobj%path)//
"- variable:"//&
132 &trim(variable_name)//
" attribute: "//trim(attribute_name)
134 if (fileobj%is_root)
then
135 varid = get_variable_id(fileobj%ncid, trim(variable_name), msg=append_error_msg)
136 select type(attribute_value)
137 type is (
integer(kind=i4_kind))
138 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
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, varid, trim(attribute_name), attribute_value)
145 type is (real(kind=r4_kind))
146 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
147 type is (real(kind=r8_kind))
148 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
150 call error(
"unsupported attribute type: "//trim(append_error_msg))
152 call check_netcdf_code(err, append_error_msg)
154 if (
present(broadcast))
then
155 if (.not. broadcast)
then
159 select type(attribute_value)
160 type is (
integer(kind=i4_kind))
161 call mpp_broadcast(attribute_value,
size(attribute_value), fileobj%io_root, &
162 pelist=fileobj%pelist)
163 type is (
integer(kind=i8_kind))
164 call mpp_broadcast(attribute_value,
size(attribute_value), fileobj%io_root, &
165 pelist=fileobj%pelist)
166 type is (real(kind=r4_kind))
167 call mpp_broadcast(attribute_value,
size(attribute_value), fileobj%io_root, &
168 pelist=fileobj%pelist)
169 type is (real(kind=r8_kind))
170 call mpp_broadcast(attribute_value,
size(attribute_value), fileobj%io_root, &
171 pelist=fileobj%pelist)
173 call error(
"unsupported attribute type: "//trim(append_error_msg))
subroutine get_variable_attribute_1d(fileobj, variable_name, attribute_name, attribute_value, broadcast)
Get the value of a variable's attribute.
subroutine get_variable_attribute_0d(fileobj, variable_name, attribute_name, attribute_value, broadcast, reproduce_null_char_bug_flag)
Get the value of a variable's attribute.