27 attribute_value, broadcast, reproduce_null_char_bug_flag)
29 class(fmsnetcdffile_t),
intent(in) :: fileobj
30 character(len=*),
intent(in) :: variable_name
31 character(len=*),
intent(in) :: attribute_name
32 class(*),
intent(inout) :: attribute_value
33 logical,
intent(in),
optional :: broadcast
39 logical,
intent(in),
optional :: reproduce_null_char_bug_flag
45 character(len=200) :: append_error_msg
46 character(len=1024),
dimension(1) :: charbuf
47 logical :: reproduce_null_char_bug
51 reproduce_null_char_bug = .false.
52 if (
present(reproduce_null_char_bug_flag)) reproduce_null_char_bug=reproduce_null_char_bug_flag
54 append_error_msg =
"get_variable_attribute_0d: file:"//trim(fileobj%path)//
"- variable:"//&
55 &trim(variable_name)//
" attribute: "//trim(attribute_name)
57 if (fileobj%is_root)
then
58 varid = get_variable_id(fileobj%ncid, trim(variable_name), msg=append_error_msg)
59 select type(attribute_value)
60 type is (
character(len=*))
61 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), charbuf(1))
62 if (reproduce_null_char_bug)
then
63 call string_copy(attribute_value, charbuf(1), check_for_null=.false.)
65 call string_copy(attribute_value, charbuf(1), check_for_null=.true.)
67 type is (
integer(kind=i4_kind))
68 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
69 type is (
integer(kind=i8_kind))
70 if ( .not. fileobj%is_netcdf4)
call error(trim(fileobj%path)// &
71 &
": 64 bit integers are only supported with 'netcdf4' file format"//&
72 &
". Set netcdf_default_format='netcdf4' in the fms2_io namelist OR "//&
73 &
"add nc_format='netcdf4' to your open_file call")
74 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
75 type is (real(kind=r4_kind))
76 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
77 type is (real(kind=r8_kind))
78 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
80 call error(
"unsupported attribute type: "//trim(append_error_msg))
82 call check_netcdf_code(err, append_error_msg)
84 if (
present(broadcast))
then
85 if (.not. broadcast)
then
89 select type(attribute_value)
90 type is (
character(len=*))
91 call mpp_broadcast(charbuf, len(charbuf), fileobj%io_root, pelist=fileobj%pelist)
92 if (reproduce_null_char_bug)
then
93 call string_copy(attribute_value, charbuf(1), check_for_null=.false.)
95 call string_copy(attribute_value, charbuf(1), check_for_null=.true.)
97 type is (
integer(kind=i4_kind))
98 call mpp_broadcast(attribute_value, fileobj%io_root, pelist=fileobj%pelist)
99 type is (
integer(kind=i8_kind))
100 call mpp_broadcast(attribute_value, fileobj%io_root, pelist=fileobj%pelist)
101 type is (real(kind=r4_kind))
102 call mpp_broadcast(attribute_value, fileobj%io_root, pelist=fileobj%pelist)
103 type is (real(kind=r8_kind))
104 call mpp_broadcast(attribute_value, fileobj%io_root, pelist=fileobj%pelist)
106 call error(
"unsupported attribute type: "//trim(append_error_msg))
113 attribute_value, broadcast)
115 class(fmsnetcdffile_t),
intent(in) :: fileobj
116 character(len=*),
intent(in) :: variable_name
117 character(len=*),
intent(in) :: attribute_name
118 class(*),
dimension(:),
intent(inout) :: attribute_value
119 logical,
intent(in),
optional :: broadcast
128 character(len=200) :: append_error_msg
130 append_error_msg =
"get_variable_attribute_1d: file:"//trim(fileobj%path)//
"- variable:"//&
131 &trim(variable_name)//
" attribute: "//trim(attribute_name)
133 if (fileobj%is_root)
then
134 varid = get_variable_id(fileobj%ncid, trim(variable_name), msg=append_error_msg)
135 select type(attribute_value)
136 type is (
integer(kind=i4_kind))
137 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
138 type is (
integer(kind=i8_kind))
139 if ( .not. fileobj%is_netcdf4)
call error(trim(fileobj%path)// &
140 &
": 64 bit integers are only supported with 'netcdf4' file format"//&
141 &
". Set netcdf_default_format='netcdf4' in the fms2_io namelist OR "//&
142 &
"add nc_format='netcdf4' to your open_file call")
143 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
144 type is (real(kind=r4_kind))
145 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
146 type is (real(kind=r8_kind))
147 err = nf90_get_att(fileobj%ncid, varid, trim(attribute_name), attribute_value)
149 call error(
"unsupported attribute type: "//trim(append_error_msg))
151 call check_netcdf_code(err, append_error_msg)
153 if (
present(broadcast))
then
154 if (.not. broadcast)
then
158 select type(attribute_value)
159 type is (
integer(kind=i4_kind))
160 call mpp_broadcast(attribute_value,
size(attribute_value), fileobj%io_root, &
161 pelist=fileobj%pelist)
162 type is (
integer(kind=i8_kind))
163 call mpp_broadcast(attribute_value,
size(attribute_value), fileobj%io_root, &
164 pelist=fileobj%pelist)
165 type is (real(kind=r4_kind))
166 call mpp_broadcast(attribute_value,
size(attribute_value), fileobj%io_root, &
167 pelist=fileobj%pelist)
168 type is (real(kind=r8_kind))
169 call mpp_broadcast(attribute_value,
size(attribute_value), fileobj%io_root, &
170 pelist=fileobj%pelist)
172 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.