gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
gtvarcreate.f90
Go to the documentation of this file.
1!> @file gtvarcreate.f90
2!>
3!> @author Yasuhiro MORIKAWA, Eizi TOYODA
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 Create dependent variable
9!>
10!> This subroutine is provided through gtdata_generic.
11!> @enden
12!>
13!> @ja
14!> @brief 従属変数の作成
15!>
16!> このサブルーチンは gtdata_generic から提供されます。
17!> @endja
18!>
19
20!>
21!> @en
22!> @brief Create variable with dimensions
23!>
24!> Creates a variable of GT_VARIABLE type with dimensions dims at
25!> location url, and sets it to var. Like variables opened with Open,
26!> var must later be closed with Close.
27!>
28!> If xtype is omitted, it defaults to "float".
29!> Creation fails if the variable already exists, but continues by
30!> overwriting if overwrite == .true..
31!> (Note: overwrite behavior is not yet guaranteed.)
32!> Omitting dims means setting a 0-dimensional variable.
33!>
34!> If an error occurs during creation, outputs a message and terminates.
35!> If err is provided, returns .true. and program does not terminate.
36!> @param[out] var Variable handle
37!> @param[in] url Variable URL
38!> @param[in] dims Dimension variables (optional)
39!> @param[in] xtype Data type (optional, default "float")
40!> @param[in] long_name Long name attribute (optional)
41!> @param[in] overwrite Allow overwrite (optional)
42!> @param[out] err Error flag (optional)
43!> @enden
44!>
45!> @ja
46!> @brief 次元を持つ変数を作成
47!>
48!> 場所 url に次元 dims を持った変数つまり GT_VARIABLE 型
49!> の実体を作成し、それを第 1 引数 var にセットします。
50!> Open されたものと同様、第1引数 var は後で必ず Close されなければなりません。
51!>
52!> 型 xtype を省略すると "float" とみなされます。
53!> 既存変数があるとき失敗しますが、overwrite == .true. であれば
54!> 上書きして続行します。(まだ overwrite の動作は保障されていません)。
55!> dims の省略は 0 次元変数の設定を意味します。
56!>
57!> 作成の際にエラーが生じた場合、メッセージを出力してプログラムは
58!> 強制終了します。err を与えてある場合にはこの引数に .true.
59!> が返り、プログラムは終了しません。
60!> @param[out] var 変数ハンドル
61!> @param[in] url 変数URL
62!> @param[in] dims 次元変数 (省略可能)
63!> @param[in] xtype データ型 (省略可能、デフォルトは "float")
64!> @param[in] long_name 長い名前属性 (省略可能)
65!> @param[in] overwrite 上書き許可 (省略可能)
66!> @param[out] err エラーフラグ (省略可能)
67!> @endja
68!>
69subroutine gtvarcreate(var, url, dims, xtype, long_name, overwrite, err)
70 use gtdata_types, only: gt_variable
71 use gtdata_internal_map, only: var_class, vtb_class_netcdf, &
75 use dc_string, only: strhead
76 use dc_error, only: storeerror, dc_noerr
77 use dc_types, only: token
79 implicit none
80 type(gt_variable), intent(out):: var
81 character(len = *), intent(in):: url
82 type(gt_variable), intent(in), optional:: dims(:)
83 character(len = *), intent(in), optional:: xtype
84 character(len = *), intent(in), optional:: long_name
85 logical, intent(in), optional:: overwrite
86 logical, intent(out), optional:: err
87 type(gd_nc_variable), allocatable:: gdnc_dims(:)
88 type(gd_nc_variable):: gdnc
89 integer, allocatable:: allcount(:)
90 integer:: i, ndims, stat, cause_i
91 character(len = TOKEN):: myxtype
92 character(len = *), parameter:: subname = "GTVarCreate"
93 character(len = *), parameter:: version = &
94 & '$Name: $' // &
95 & '$Id: gtvarcreate.f90,v 1.4 2009-05-25 09:55:58 morikawa Exp $'
96continue
97 stat = dc_noerr
98 ndims = 0
99 cause_i = 0
100 if (present(dims)) ndims = size(dims)
101 call beginsub(subname, 'url=%c ndims=%d', c1=trim(url), i=(/ndims/), &
102 & version=version)
103 ! gdnc 変数の作成
104 if (present(err)) err = .false.
105 if (present(xtype)) then
106 myxtype = xtype
107 else
108 myxtype = "float"
109 endif
110 if (present(dims)) then
111 allocate(gdnc_dims(ndims), allcount(ndims))
112 do, i = 1, ndims
113 call var_class(dims(i), cid=gdnc_dims(i)%id)
114 call dbgmessage('dim=%d mapid=%d -> cid=%d', i=(/i, dims(i)%mapid, gdnc_dims(i)%id/))
115 call inquire(gdnc_dims(i), dimlen=allcount(i))
116 enddo
117 call create(var=gdnc, url=url, dims=gdnc_dims, xtype=myxtype, &
118 & overwrite=overwrite, err=err)
119 else
120 ndims = 0
121 allocate(gdnc_dims(1), allcount(1)) ! dummy
122 call create(var=gdnc, url=url, dims=gdnc_dims(1:0), &
123 & xtype=myxtype, overwrite=overwrite, err=err)
124 endif
125 call map_create(var, vtb_class_netcdf, gdnc%id, ndims, allcount, stat)
126 if (stat /= dc_noerr) then
127 cause_i = ndims
128 goto 999
129 end if
130 deallocate(gdnc_dims, allcount)
131 if (present(long_name)) then
132 call put_attr(gdnc, 'long_name', long_name, err=err)
133 endif
134 call gtvar_dump(var)
135 call dbgmessage('var%%mapid=%d', i=(/var % mapid/))
136999 continue
137 call storeerror(stat, subname, err, cause_i=cause_i)
138 call endsub(subname)
139end subroutine gtvarcreate
subroutine gtvarcreate(var, url, dims, xtype, long_name, overwrite, 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
Handling character types.
Definition dc_string.f90:83
Debug tracing module.
Definition dc_trace.f90:150
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:680
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:476
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:599
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public token
Character length for word, token
Definition dc_types.f90:128
subroutine, public var_class(var, class, cid)
subroutine, public map_create(var, class, cid, ndims, allcount, stat)