gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
gtvarcopyattr.f90
Go to the documentation of this file.
1!> @file gtvarcopyattr.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 Copy attribute
9!>
10!> This subroutine is provided as gtdata_generic#Copy_Attr
11!> through gtdata_generic.
12!> @enden
13!>
14!> @ja
15!> @brief 属性のコピー
16!>
17!> このサブルーチンは gtdata_generic から gtdata_generic#Copy_Attr
18!> として提供されます。
19!> @endja
20!>
21
22!>
23!> @en
24!> @brief Copy single attribute from one variable to another
25!>
26!> Copies attribute attrname of variable from to variable to.
27!> If an error occurs during copying, outputs a message and
28!> terminates the program. If err is provided, returns .true.
29!> in that argument and program does not terminate.
30!>
31!> Copy_Attr is a generic name for 2 subroutines; there is also
32!> a method to copy all attributes of a variable at once.
33!> @param[inout] to Destination variable handle
34!> @param[in] attrname Attribute name to copy
35!> @param[in] from Source variable handle
36!> @param[out] err Error flag (optional)
37!> @enden
38!>
39!> @ja
40!> @brief 1つの属性を変数間でコピー
41!>
42!> 変数 from の属性 attrname を変数 to へコピーします。
43!> 属性のコピー時にエラーが生じた場合、メッセージを出力
44!> してプログラムは強制終了します。err を与えてある場合には
45!> の引数に .true. が返り、プログラムは終了しません。
46!>
47!> Copy_Attr は 2 つのサブルーチンの総称名であり、
48!> 他にも一括で変数の全ての属性をコピーする方法もあります。
49!> @param[inout] to コピー先の変数ハンドル
50!> @param[in] attrname コピーする属性名
51!> @param[in] from コピー元の変数ハンドル
52!> @param[out] err エラーフラグ (省略可能)
53!> @endja
54!>
55subroutine gtvarcopyattr(to, attrname, from, err)
56 use gtdata_types, only: gt_variable
58 use gtdata_internal_map, only: var_class, vtb_class_netcdf
61 use dc_trace, only: beginsub, endsub
62 use dc_error, only: storeerror, dc_noerr
63 use dc_types, only: string
64 implicit none
65 type(gt_variable), intent(inout):: to
66 character(len = *), intent(in):: attrname
67 type(gt_variable), intent(in):: from
68 logical, intent(out), optional:: err
69 character(STRING):: svalue
70 integer:: from_class, from_cid, to_class, to_cid, stat
71continue
72 if (present(err)) err = .false.
73 call beginsub('gtvarcopyattr', 'mapid to=%d from=%d name=%c', &
74 & i=(/to%mapid, from%mapid/), c1=attrname)
75 call var_class(from, from_class, from_cid)
76 call var_class(to, to_class, to_cid)
77 if (from_class == vtb_class_netcdf .and. to_class == vtb_class_netcdf) then
78 call copy_attr(gd_nc_variable(to_cid), attrname, &
79 & gd_nc_variable(from_cid), stat)
80 else
81 ! とりあえず文字列で入出力しておく
82 call get_attr(from, attrname, svalue, default='')
83 call put_attr(to, attrname, svalue, '', err)
84 stat = dc_noerr
85 endif
86 call storeerror(stat, "GTVarCopyAttr", err)
87 call endsub('gtvarcopyattr', 'stat = %d', i=(/stat/))
88end subroutine gtvarcopyattr
subroutine gtvarcopyattr(to, attrname, from, err)
Error handling module.
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
integer, parameter, public dc_noerr
Error storage variables
Definition dc_error.f90:468
Debug tracing module.
Definition dc_trace.f90:150
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:457
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:580
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public string
Character length for string
Definition dc_types.f90:137
subroutine, public var_class(var, class, cid)