gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
gtvarslicenext.f90
Go to the documentation of this file.
1!> @file gtvarslicenext.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 Move I/O range
9!>
10!> This subroutine is provided as gtdata_generic#Slice_Next
11!> through gtdata_generic.
12!> @enden
13!>
14!> @ja
15!> @brief 入出力範囲を移動
16!>
17!> このサブルーチンは gtdata_generic から gtdata_generic#Slice_Next
18!> として提供されます。
19!> @endja
20!>
21
22!>
23!> @en
24!> @brief Advance I/O range to next slice
25!>
26!> Moves the dimension range by incrementing the start value of
27!> the dimord-th dimension of variable var by stride * count.
28!> If dimord is omitted, this operation is performed on any dimension.
29!> On success, stat becomes 0.
30!>
31!> By setting a Slice with start and stride values of 1 for any dimension
32!> and sequentially calling Slice_Next, you can scan the entire variable.
33!>
34!> If an error occurs while moving the I/O range, outputs a message
35!> and terminates the program. If err is provided, returns .true.
36!> and program does not terminate.
37!> @param[inout] var Variable handle
38!> @param[in] dimord Dimension order number (optional)
39!> @param[out] err Error flag (optional)
40!> @param[out] stat Status (0 on success) (optional)
41!> @enden
42!>
43!> @ja
44!> @brief 入出力範囲を次のスライスに移動
45!>
46!> 変数 var の dimord 番目の次元の start 値を stride * count 個だけ
47!> 増やすことによって次元範囲を移動します。dimord を省略すると、
48!> どれかの次元についてこの操作を行います。成功した場合 stat が 0 になります。
49!>
50!> いずれかの次元について start, stride 値が 1 になるような
51!> Slice を設定しておいて、Slice_Next を順次呼び出すと変数全体
52!> を走査することができます。
53!>
54!> 入出力範囲を移動する際にエラーが生じた場合、メッセージを出力
55!> してプログラムは強制終了します。err を与えてある場合には
56!> の引数に .true. が返り、プログラムは終了しません。
57!> @param[inout] var 変数ハンドル
58!> @param[in] dimord 次元順序番号 (省略可能)
59!> @param[out] err エラーフラグ (省略可能)
60!> @param[out] stat ステータス (成功時0) (省略可能)
61!> @endja
62!>
63subroutine gtvarslicenext(var, dimord, err, stat)
64 use gtdata_types, only: gt_variable
66 & nf90_einval, nf90_enotvar
69 implicit none
70 type(gt_variable), intent(in out):: var
71 integer, intent(in), optional:: dimord
72 logical, intent(out), optional:: err
73 integer, intent(out), optional:: stat
74 type(gt_dimmap), allocatable:: map(:)
75 integer:: mystat, vid, id, nd, idim_lo, idim_hi, ilast
76continue
77 call beginsub('gtvarslicenext')
78 if (present(dimord)) call dbgmessage('dimord=%d', i=(/dimord/))
79
80 call map_lookup(var, vid=vid, ndims=nd)
81 if (vid < 0) then
82 mystat = nf90_enotvar
83 goto 999
84 endif
85 if (nd <= 0) then
86 call dbgmessage('dimension map not associated')
87 mystat = gt_enomoredims
88 goto 999
89 endif
90 allocate(map(nd))
91 call map_lookup(var, map=map)
92
93 if (present(dimord)) then
94 if (dimord < 0 .or. dimord <= size(map)) then
95 call dbgmessage('dimord=%d is out of 1..%d', i=(/dimord, size(map)/))
96 mystat = nf90_einval
97 goto 995
98 endif
99 idim_lo = dimord
100 idim_hi = dimord
101 else
102 idim_lo = 1
103 idim_hi = size(map)
104 endif
105 call dbgmessage('idim scan range=(%d:%d)', i=(/idim_lo, idim_hi/))
106
107 mystat = gt_enomoredims
108 do, id = idim_lo, idim_hi
109 ilast = map(id)%start + (map(id)%count * 2 - 1) * map(id)%stride
110 call dbgmessage('last_index=%d allcount=%d', &
111 & i=(/ilast, map(id)%allcount/))
112 if (ilast >= 1 .and. ilast <= map(id)%allcount) then
113 map(id)%start = map(id)%start + map(id)%count * map(id)%stride
114 mystat = dc_noerr
115 exit
116 endif
117 enddo
118 if (mystat /= dc_noerr) goto 995
119 call map_set(var, map, mystat)
120
121995 continue
122 deallocate(map)
123
124999 continue
125 if (present(stat)) then
126 stat = mystat
127 if (present(err)) err = (mystat /= dc_noerr)
128 else
129 call storeerror(mystat, "GTVarSliceNext", err)
130 endif
131 call endsub('gtvarslicenext', 'stat=%d', i=(/mystat/))
132end subroutine gtvarslicenext
subroutine gtvarslicenext(var, dimord, err, stat)
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
integer, parameter, public gt_enomoredims
-101 or less: Data structure errors
Definition dc_error.f90:507
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:661
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
subroutine, public map_lookup(var, vid, map, ndims)
subroutine map_set(var, map, stat)