gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
gdncvarputattrchar.f90
Go to the documentation of this file.
1!> @file gdncvarputattrchar.f90
2!>
3!> @author Eizi TOYODA, Yasuhiro MORIKAWA
4!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
5!> License is BSD-2-Clause. See [COPYRIGHT](@ref COPYRIGHT) in detail
6!>
7!> @en
8!> @brief Put character attribute to netCDF variable
9!>
10!> These subroutines and functions are provided as gtdata_netcdf_generic#Put_Attr
11!> through gtdata_netcdf_generic.
12!> @enden
13!>
14!> @ja
15!> @brief netCDF 変数に文字属性を設定
16!>
17!> これらのサブルーチン、関数は gtdata_netcdf_generic から
18!> gtdata_netcdf_generic#Put_Attr として提供されます。
19!> @endja
20!>
21
22!>
23!> @en
24!> @brief Set character attribute value
25!>
26!> Sets a character attribute on a variable. If xtype is specified,
27!> the value is converted to that numeric type before storage.
28!> If name starts with '+', it is treated as a global attribute.
29!> Empty value deletes the attribute.
30!> @enden
31!>
32!> @ja
33!> @brief 文字属性値を設定
34!>
35!> 変数に文字属性を設定します。xtype が指定された場合、
36!> 値はその数値型に変換されてから格納されます。
37!> name が '+' で始まる場合、グローバル属性として扱われます。
38!> 空の value は属性を削除します。
39!> @endja
40!>
41!> @param[in] var @en Variable handle @enden @ja 変数ハンドル @endja
42!> @param[in] name @en Attribute name @enden @ja 属性名 @endja
43!> @param[in] val @en Character value to set @enden @ja 設定する文字値 @endja
44!> @param[in] xtype @en Target type for conversion (optional) @enden
45!> @ja 変換先の型 (省略可能) @endja
46!> @param[out] err @en Error flag (optional) @enden @ja エラーフラグ (省略可能) @endja
47!>
48subroutine gdncvarputattrchar(var, name, val, xtype, err)
52 use netcdf, only: &
53 & nf90_global, &
54 & nf90_noerr, &
55 & nf90_put_att, &
56 & nf90_del_att
57 use dc_url, only: gt_plus
58 use dc_error
59 use dc_string, only: get_array
61 implicit none
62 type(gd_nc_variable), intent(in):: var
63 character(len = *), intent(in):: name
64 character(len = *), intent(in):: val
65 character(len = *), intent(in), optional:: xtype
66 logical, intent(out), optional:: err
67 integer, pointer:: ip(:)
68 real, pointer:: rp(:)
69 double precision, pointer:: dp(:)
70 integer:: stat
71 type(gd_nc_variable_entry):: ent
72continue
73 stat = vtable_lookup(var, ent)
74 if (stat /= nf90_noerr) goto 999
75 if (len(val) == 0) then
76 if (name(1:1) == gt_plus) then
77 stat = nf90_del_att(ent%fileid, nf90_global, name = name(2:))
78 else
79 stat = nf90_del_att(ent%fileid, ent%varid, name = name)
80 endif
81 goto 999
82 endif
83 if ( present(xtype) ) then
84 select case(xtype)
85 case("INTEGER", "integer", "int")
86 goto 200
87 case("REAL", "real", "float")
88 goto 300
89 case("DOUBLEPRECISION", "DOUBLE", "double")
90 goto 400
91 end select
92 end if
93
94 stat = gdncfiledefinemode( ent % fileid )
95 if (stat /= nf90_noerr) goto 999
96 if (name(1:1) == gt_plus) then
97 stat = nf90_put_att(ent%fileid, nf90_global, name(2:), trim(val) )
98 else
99 stat = nf90_put_att(ent%fileid, ent%varid, name, trim(val) )
100 endif
101
102999 continue
103 call storeerror(stat, 'GDNcVarPutAttrChar', err, cause_c=name)
104 return
105
106200 continue
107 call get_array(ip, val)
108 if (associated(ip)) then
109 call put_attr(var, name, ip, err)
110 deallocate(ip)
111 endif
112 return
113
114300 continue
115 call get_array(rp, val)
116 if (associated(rp)) then
117 call put_attr(var, name, rp, err)
118 deallocate(rp)
119 endif
120 return
121
122400 continue
123 call get_array(dp, val)
124 if (associated(dp)) then
125 call put_attr(var, name, dp, err)
126 deallocate(dp)
127 endif
128 return
129end subroutine gdncvarputattrchar
subroutine gdncvarputattrchar(var, name, val, xtype, err)
エラー処理用モジュール
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
文字型変数の操作
Definition dc_string.f90:83
変数 URL の文字列解析
Definition dc_url.f90:61
character, parameter, public gt_plus
Definition dc_url.f90:109
integer function, public vtable_lookup(var, entry)