gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
gdncvaropen.f90
Go to the documentation of this file.
1!> @file gdncvaropen.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 Open a netCDF variable
9!>
10!> These subroutines and functions are provided through gtdata_netcdf_generic.
11!> @enden
12!>
13!> @ja
14!> @brief netCDF 変数のオープン
15!>
16!> これらのサブルーチン、関数は gtdata_netcdf_generic から提供されます。
17!> @endja
18!>
19
20!>
21!> @en
22!> @brief Open a variable from URL
23!>
24!> Opens a netCDF variable specified by URL. If the variable name is
25!> empty in the URL, the first non-dimension variable is opened.
26!> @enden
27!>
28!> @ja
29!> @brief URL から変数をオープン
30!>
31!> URL で指定された netCDF 変数をオープンします。
32!> URL で変数名が空の場合、最初の非次元変数がオープンされます。
33!> @endja
34!>
35!> @param[out] var @en Opened variable handle @enden @ja オープンした変数ハンドル @endja
36!> @param[in] url @en Variable URL @enden @ja 変数 URL @endja
37!> @param[in] writable @en Open for writing (optional) @enden @ja 書き込み用にオープン (省略可能) @endja
38!> @param[out] err @en Error flag (optional) @enden @ja エラーフラグ (省略可能) @endja
39!>
40recursive subroutine gdncvaropen(var, url, writable, err)
41 use dc_types, only: string
45 use dc_url, only: urlsplit
46 use dc_error, only: storeerror
47 use dc_trace, only: beginsub, endsub
48 use netcdf, only: nf90_noerr, nf90_max_name, nf90_enotvar, nf90_ebaddim, &
49 & nf90_inq_varid, nf90_inq_dimid, nf90_inquire_variable, nf90_inquire
50 implicit none
51 type(gd_nc_variable), intent(out):: var
52 character(len = *), intent(in):: url
53 logical, intent(in), optional:: writable
54 logical, intent(out), optional:: err
55 character(len = STRING):: filename, varname
56 character(len = NF90_MAX_NAME):: dimname
57 integer:: stat, nvars, i
58 type(gd_nc_variable_search):: e
59 character(len = *), parameter:: subname = 'GDNcVarOpen'
60continue
61 call beginsub(subname)
62 call urlsplit(url, file=filename, var=varname)
63 if (filename == "") filename = "gtool.nc"
64 call gdncfileopen(e%fileid, trim(filename), stat=stat, writable=writable, err=err )
65 if (stat /= 0) goto 999
66 !
67 ! 名前から変数を探し出す
68 !
69 if (varname /= '') then
70 e%varid = 0
71 stat = nf90_inq_varid(e%fileid, trim(varname), e%varid)
72 if (stat == nf90_enotvar) then
73 e%varid = 0
74 stat = nf90_noerr
75 endif
76 else
77 ! 名前が空ならできれば次元変数でない最初の変数をとりだす
78 stat = nf90_inquire(e%fileid, nvariables = nvars)
79 if (stat /= 0) goto 999
80 e%varid = 1
81 do, i = 1, nvars
82 stat = nf90_inquire_variable(e%fileid, i, name = dimname)
83 if (stat /= nf90_noerr) goto 999
84 stat = nf90_inq_dimid(e%fileid, dimname, e%dimid)
85 if (stat == nf90_noerr) cycle
86 if (stat /= nf90_ebaddim) goto 999
87 e%varid = i
88 stat = nf90_noerr
89 exit
90 enddo
91 endif
92 if (stat /= nf90_noerr) goto 999
93 !
94 ! 次元id を調べる
95 !
96 stat = nf90_inq_dimid(e%fileid, trim(varname), e%dimid)
97 if (stat /= nf90_noerr) then
98 if (e%varid <= 0) goto 999
99 e%dimid = 0
100 endif
101 !
102 stat = vtable_add(var, e)
103 if (stat /= nf90_noerr) goto 999
104 call endsub(subname, 'an=%d file=%d var=%d', i=(/var%id, e%fileid, e%varid/))
105 call storeerror(stat, subname, err)
106 return
107 !
108 ! エラー処理 (正常完了時も呼ぶ)
109 !
110999 continue
111 var = gd_nc_variable(-1)
112 call endsub(subname, 'an=%d err', i=(/var%id/))
113 call storeerror(stat, subname, err, cause_c=url)
114end subroutine gdncvaropen
recursive subroutine gdncvaropen(var, url, writable, err)
エラー処理用モジュール
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
デバッグ時の追跡用モジュール
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
種別型パラメタを提供します。
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)