gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
gtvarexchdim.f90
Go to the documentation of this file.
1!> @file gtvarexchdim.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 Exchange dimension order numbers
9!>
10!> This subroutine is provided as gtdata_generic#Exch_dim
11!> through gtdata_generic.
12!> @enden
13!>
14!> @ja
15!> @brief 次元順序番号の交換
16!>
17!> このサブルーチンは gtdata_generic から gtdata_generic#Exch_dim
18!> として提供されます。
19!> @endja
20!>
21
22!>
23!> @en
24!> @brief Exchange dimensions at specified order numbers
25!>
26!> Exchanges dimensions at dimension order numbers dimord1 and dimord2
27!> in variable var.
28!>
29!> If count_compact is .true., operates including degenerate dimensions.
30!>
31!> If an error occurs, outputs a message and terminates the program.
32!> If err is provided, returns .true. and program does not terminate.
33!> @param[in] var Variable handle
34!> @param[in] dimord1 First dimension order number
35!> @param[in] dimord2 Second dimension order number
36!> @param[in] count_compact Include degenerate dimensions (optional)
37!> @param[out] err Error flag
38!> @enden
39!>
40!> @ja
41!> @brief 指定順序番号の次元を交換
42!>
43!> 変数 var の次元順序番号 dimord1, dimord2 のそれぞれに対応する次元を入れ替えます。
44!>
45!> count_compact に .true. を渡すと、縮退した次元も含めて動作します。
46!>
47!> エラーが生じた場合、メッセージを出力してプログラムは強制終了します。
48!> err を与えてある場合にはの引数に .true. が返り、プログラムは終了しません。
49!> @param[in] var 変数ハンドル
50!> @param[in] dimord1 1番目の次元順序番号
51!> @param[in] dimord2 2番目の次元順序番号
52!> @param[in] count_compact 縮退次元を含むか (省略可能)
53!> @param[out] err エラーフラグ
54!> @endja
55!>
56subroutine gtvarexchdim(var, dimord1, dimord2, count_compact, err)
57 use gtdata_types, only: gt_variable
61 implicit none
62 type(gt_variable), intent(in):: var
63 integer, intent(in):: dimord1, dimord2
64 logical, intent(in), optional:: count_compact
65 logical, intent(out):: err
66 type(gt_dimmap), allocatable:: map(:)
67 type(gt_dimmap):: tmpmap
68 integer:: ndimsp, stat, idim1, idim2
69 logical:: direct_mode
70 character(*), parameter:: subname = 'GTVarExchDim'
71continue
72 err = .true.
73 direct_mode = .false.
74 if (present(count_compact)) then
75 direct_mode = count_compact
76 endif
77 call beginsub(subname)
78 if (dimord1 < 1 .or. dimord2 < 1) then
79 call endsub(subname, "negative dimord=%d %d invalid", i=(/dimord1, dimord2/))
80 return
81 endif
82 call map_lookup(var, ndims=ndimsp)
83 if (ndimsp <= 0) then
84 call endsub(subname, "variable invalid")
85 return
86 else if (dimord1 > ndimsp .or. dimord2 > ndimsp) then
87 call endsub(subname, "dimord=%d %d not exist", i=(/dimord1, dimord2/))
88 return
89 endif
90
91 allocate(map(ndimsp))
92 call map_lookup(var, map=map)
93
94 if (.not. direct_mode) then
95 idim1 = dimord_skip_compact(dimord1, map)
96 idim2 = dimord_skip_compact(dimord2, map)
97 if (idim1 < 0 .or. idim2 < 0) then
98 call endsub(subname, "dimord=%d %d not found after compaction", &
99 & i=(/dimord1, dimord2/))
100 deallocate(map)
101 return
102 endif
103 else
104 idim1 = dimord1
105 idim2 = dimord2
106 endif
107
108 tmpmap = map(idim1)
109 map(idim1) = map(idim2)
110 map(idim2) = tmpmap
111 call map_set(var, map, stat)
112 deallocate(map)
113
114 err = stat /= 0
115 call endsub(subname)
116end subroutine gtvarexchdim
subroutine gtvarexchdim(var, dimord1, dimord2, count_compact, err)
デバッグ時の追跡用モジュール
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_ndims(var, ndims, stat)
subroutine map_set(var, map, stat)
integer function dimord_skip_compact(dimord, map)