FMS 2025.01.02-dev
Flexible Modeling System
Loading...
Searching...
No Matches
register_global_attribute.inc
1!***********************************************************************
2!* GNU Lesser General Public License
3!*
4!* This file is part of the GFDL Flexible Modeling System (FMS).
5!*
6!* FMS is free software: you can redistribute it and/or modify it under
7!* the terms of the GNU Lesser General Public License as published by
8!* the Free Software Foundation, either version 3 of the License, or (at
9!* your option) any later version.
10!*
11!* FMS is distributed in the hope that it will be useful, but WITHOUT
12!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13!* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14!* for more details.
15!*
16!* You should have received a copy of the GNU Lesser General Public
17!* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
18!***********************************************************************
19!> @file
20!> @brief Routines for different dimensions to add global attributes in netcdf files for the
21!! @ref register_global_attribute interface
22
23!> @addtogroup netcdf_io_mod
24!> @{
25
26!> @brief Add a global attribute.
27subroutine register_global_attribute_0d(fileobj, &
28 attribute_name, &
29 attribute_value, str_len)
30 class(fmsnetcdffile_t),intent(in) :: fileobj !< File object.
31 character(len=*),intent(in) :: attribute_name !< Attribute name.
32 class(*), intent(in) :: attribute_value !< Attribute value
33 integer, intent(in), optional :: str_len !< Length of the string
34 integer :: err
35 if (fileobj%is_root) then
36 call set_netcdf_mode(fileobj%ncid, &
37 define_mode)
38 select type(attribute_value)
39 type is (character(len=*))
40 if (.not. present(str_len)) call error("register_global_attribute_0d: Need to include str length")
41 err = nf90_put_att(fileobj%ncid, &
42 nf90_global, &
43 trim(attribute_name), &
44 trim(attribute_value(1:str_len)))
45 type is (integer(kind=i4_kind))
46 err = nf90_put_att(fileobj%ncid, &
47 nf90_global, &
48 trim(attribute_name), &
49 attribute_value)
50 type is (integer(kind=i8_kind))
51 if ( .not. fileobj%is_netcdf4) call error(trim(fileobj%path)// &
52 & ": 64 bit integers are only supported with 'netcdf4' file format"// &
53 & ". Set netcdf_default_format='netcdf4' in the fms2_io namelist OR "//&
54 & "add nc_format='netcdf4' to your open_file call")
55 err = nf90_put_att(fileobj%ncid, &
56 nf90_global, &
57 trim(attribute_name), &
58 attribute_value)
59 type is (real(kind=r4_kind))
60 err = nf90_put_att(fileobj%ncid, &
61 nf90_global, &
62 trim(attribute_name), &
63 attribute_value)
64 type is (real(kind=r8_kind))
65 err = nf90_put_att(fileobj%ncid, &
66 nf90_global, &
67 trim(attribute_name), &
68 attribute_value)
69 class default
70 call error("register_global_attribute_0d: unsupported type for "//&
71 trim(attribute_name)//" for file: "//trim(fileobj%path)//"")
72 end select
73 call check_netcdf_code(err, "register_global_attribute_0d: file:"//trim(fileobj%path)//"- attribute:"// &
74 & trim(attribute_name))
75 endif
77!> @brief Add a global attribute.
78subroutine register_global_attribute_1d(fileobj, &
79 attribute_name, &
80 attribute_value, str_len)
81 class(fmsnetcdffile_t),intent(in) :: fileobj !< File object.
82 character(len=*),intent(in) :: attribute_name !< Attribute name.
83 class(*),dimension(:), intent(in) :: attribute_value !< Attribute value
84 integer, intent(in), optional :: str_len !< Length of the string
85 integer :: err
86 if (fileobj%is_root) then
87 call set_netcdf_mode(fileobj%ncid, &
88 define_mode)
89 select type(attribute_value)
90
91 type is (integer(kind=i4_kind))
92 err = nf90_put_att(fileobj%ncid, &
93 nf90_global, &
94 trim(attribute_name), &
95 attribute_value)
96 type is (integer(kind=i8_kind))
97 if ( .not. fileobj%is_netcdf4) call error(trim(fileobj%path)// &
98 &": 64 bit integers are only supported with 'netcdf4' file format"//&
99 &". Set netcdf_default_format='netcdf4' in the fms2_io namelist OR "//&
100 &"add nc_format='netcdf4' to your open_file call")
101 err = nf90_put_att(fileobj%ncid, &
102 nf90_global, &
103 trim(attribute_name), &
104 attribute_value)
105 type is (real(kind=r4_kind))
106 err = nf90_put_att(fileobj%ncid, &
107 nf90_global, &
108 trim(attribute_name), &
109 attribute_value)
110 type is (real(kind=r8_kind))
111 err = nf90_put_att(fileobj%ncid, &
112 nf90_global, &
113 trim(attribute_name), &
114 attribute_value)
115 class default
116 call error("register_global_attribute_1d: unsupported type for "//&
117 trim(attribute_name)//" for file: "//trim(fileobj%path)//"")
118 end select
119 call check_netcdf_code(err, "register_global_attribute_1d: file:"//trim(fileobj%path)//"- attribute:"// &
120 & trim(attribute_name))
121 endif
122end subroutine register_global_attribute_1d
123!> @}
subroutine register_global_attribute_0d(fileobj, attribute_name, attribute_value, str_len)
Add a global attribute.
subroutine register_global_attribute_1d(fileobj, attribute_name, attribute_value, str_len)
Add a global attribute.