gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
gdncvarcreated.f90
Go to the documentation of this file.
1!> @file gdncvarcreated.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 Create dimension variable in netCDF file
9!>
10!> These subroutines and functions are provided as gtdata_netcdf_generic#Create
11!> through gtdata_netcdf_generic.
12!> @enden
13!>
14!> @ja
15!> @brief netCDF ファイルへ次元変数作成
16!>
17!> これらのサブルーチン、関数は gtdata_netcdf_generic から
18!> gtdata_netcdf_generic#Create として提供されます。
19!> @endja
20!>
21
22!>
23!> @en
24!> @brief Create a dimension variable
25!>
26!> Creates a dimension variable at the specified URL.
27!> The dimension length is specified by length.
28!> The returned var contains the variable ID and other information.
29!>
30!> Setting overwrite to .true. enables overwrite mode (default: no overwrite).
31!> If err is provided, errors return .false. instead of terminating.
32!> @enden
33!>
34!> @ja
35!> @brief 次元変数を作成
36!>
37!> 変数 URL url に次元変数を作成します。
38!> 次元変数の長さを length に与えます。
39!> 返される引数 var には変数 ID などの情報が格納されます。
40!>
41!> overwrite に .true. を設定すると上書き可能モード (デフォルト: 上書き不可)。
42!> err を与えた場合、エラー時はプログラム終了せず .false. が返されます。
43!> @endja
44!>
45!> @param[out] var @en Created variable handle @enden @ja 作成した変数ハンドル @endja
46!> @param[in] url @en Variable URL @enden @ja 変数 URL @endja
47!> @param[in] xtype @en Data type (float, double, int, char) @enden
48!> @ja データ型 (float, double, int, char) @endja
49!> @param[in] length @en Dimension length @enden @ja 次元長 @endja
50!> @param[in] overwrite @en Enable overwrite mode (optional) @enden
51!> @ja 上書きモードを有効化 (省略可能) @endja
52!> @param[out] err @en Error flag (optional) @enden @ja エラーフラグ (省略可能) @endja
53!>
54subroutine gdncvarcreated(var, url, xtype, length, overwrite, err)
57 use dc_string, only: strieq
58 use dc_types, only: string
59 use dc_url, only: urlsplit
61 use netcdf, only: nf90_noerr, nf90_float, nf90_int, nf90_double, nf90_char, &
62 & nf90_def_var, nf90_def_dim
64 use dc_error, only: storeerror
65 implicit none
66 type(gd_nc_variable), intent(out):: var
67 character(len = *), intent(in):: url
68 character(len = *), intent(in):: xtype
69 integer, intent(in):: length
70 logical, intent(in), optional:: overwrite
71 logical, intent(out), optional:: err
72 type(gd_nc_variable_search):: ent
73 character(len = string):: filename, varname, cause_c
74 integer:: stat
75 integer:: nc_xtype
76 character(len = *), parameter:: subname = "GDNcVarCreateD"
77continue
78 call beginsub(subname, 'url=<%c>, xtype=<%c>, length=<%d>', &
79 & c1=trim(url), c2=trim(xtype), i=(/length/))
80 cause_c = trim(url)
81 !
82 ! --- ファイルを用意 ---
83 call urlsplit(url, file=filename, var=varname)
84 call gdncfileopen(ent%fileid, filename, stat=stat, writable=.true., &
85 & overwrite=overwrite)
86 if (stat /= nf90_noerr) goto 999
87 stat = gdncfiledefinemode(ent%fileid)
88 if (stat /= nf90_noerr) goto 999
89 !
90 ! --- 型の決定 ---
91 nc_xtype = nf90_float
92 if (strieq(xtype, "double")) then
93 nc_xtype = nf90_double
94 else if (strieq(xtype, "DOUBLEPRECISION")) then
95 nc_xtype = nf90_double
96 end if
97 if (strieq(xtype, "int")) then
98 nc_xtype = nf90_int
99 else if (strieq(xtype, "INTEGER")) then
100 nc_xtype = nf90_int
101 end if
102 if (strieq(xtype, "char")) then
103 nc_xtype = nf90_char
104 else if (strieq(xtype, "CHARACTER")) then
105 nc_xtype = nf90_char
106 end if
107 !
108 ! --- 次元変数の作成 ---
109 stat = nf90_def_dim(ent%fileid, trim(varname), len=length, dimid=ent%dimid)
110 if (stat /= nf90_noerr) goto 999
111 stat = nf90_def_var(ent%fileid, trim(varname), &
112 & xtype=nc_xtype, dimids=(/ent%dimid/), varid=ent%varid)
113 if (stat /= nf90_noerr) goto 999
114 !
115 stat = vtable_add(var, ent)
116 if (stat /= nf90_noerr) goto 999
117
118999 continue
119 call storeerror(stat, subname, err, cause_c=cause_c)
120 if (stat /= nf90_noerr) var = gd_nc_variable(-1)
121 call endsub(subname, 'stat=%d', i=(/stat/))
122end subroutine gdncvarcreated
subroutine gdncvarcreated(var, url, xtype, length, overwrite, 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
デバッグ時の追跡用モジュール
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
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition dc_types.f90:137
変数 URL の文字列解析
Definition dc_url.f90:61
integer function, public vtable_add(var, entry)