Loading...
Searching...
No Matches
gtvarexchdim.f90
Go to the documentation of this file.
1!
2!= 次元順序番号の交換
3!
4! Authors:: Eizi TOYODA, Yasuhiro MORIKAWA
5! Version:: $Id: gtvarexchdim.f90,v 1.3 2009-05-25 09:55:58 morikawa Exp $
6! Tag Name:: $Name: $
7! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
8! License:: See COPYRIGHT[link:../../COPYRIGHT]
9!
10! 以下のサブルーチン、関数は gtdata_generic から gtdata_generic#Exch_dim
11! として提供されます。
12
13subroutine gtvarexchdim(var, dimord1, dimord2, count_compact, err)
14 !
15 !== 次元順序番号の交換
16 !
17 ! 変数 *var* の次元順序番号 <b>dimord1</b>, <b>dimord2</b> のそれぞれに
18 ! 対応する次元を入れ替えます。
19 !
20 ! *count_compact* に .true. を渡すと、縮退した次元も含めて
21 ! 動作します。
22 !
23 ! エラーが生じた場合、メッセージを出力
24 ! してプログラムは強制終了します。*err* を与えてある場合には
25 ! の引数に .true. が返り、プログラムは終了しません。
26 !
27 use gtdata_types, only: gt_variable
30 use dc_trace, only: beginsub, endsub, dbgmessage
31 implicit none
32 type(gt_variable), intent(in):: var
33 integer, intent(in):: dimord1, dimord2
34 logical, intent(in), optional:: count_compact
35 logical, intent(out):: err
36 type(gt_dimmap), allocatable:: map(:)
37 type(gt_dimmap):: tmpmap
38 integer:: ndimsp, stat, idim1, idim2
39 logical:: direct_mode
40 character(*), parameter:: subname = 'GTVarExchDim'
41continue
42 err = .true.
43 direct_mode = .false.
44 if (present(count_compact)) then
45 direct_mode = count_compact
46 endif
47 call beginsub(subname)
48 if (dimord1 < 1 .or. dimord2 < 1) then
49 call endsub(subname, "negative dimord=%d %d invalid", i=(/dimord1, dimord2/))
50 return
51 endif
52 call map_lookup(var, ndims=ndimsp)
53 if (ndimsp <= 0) then
54 call endsub(subname, "variable invalid")
55 return
56 else if (dimord1 > ndimsp .or. dimord2 > ndimsp) then
57 call endsub(subname, "dimord=%d %d not exist", i=(/dimord1, dimord2/))
58 return
59 endif
60
61 allocate(map(ndimsp))
62 call map_lookup(var, map=map)
63
64 if (.not. direct_mode) then
65 idim1 = dimord_skip_compact(dimord1, map)
66 idim2 = dimord_skip_compact(dimord2, map)
67 if (idim1 < 0 .or. idim2 < 0) then
68 call endsub(subname, "dimord=%d %d not found after compaction", &
69 & i=(/dimord1, dimord2/))
70 deallocate(map)
71 return
72 endif
73 else
74 idim1 = dimord1
75 idim2 = dimord2
76 endif
77
78 tmpmap = map(idim1)
79 map(idim1) = map(idim2)
80 map(idim2) = tmpmap
81 call map_set(var, map, stat)
82 deallocate(map)
83
84 err = stat /= 0
85 call endsub(subname)
86end subroutine gtvarexchdim
subroutine gtvarexchdim(var, dimord1, dimord2, count_compact, err)
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)