gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
Functions/Subroutines
gtvarexchdim.f90 File Reference

Exchange dimension order numbers. More...

Go to the source code of this file.

Functions/Subroutines

subroutine gtvarexchdim (var, dimord1, dimord2, count_compact, err)
 

Detailed Description

Exchange dimension order numbers.

Author
Eizi TOYODA, Yasuhiro MORIKAWA

Definition in file gtvarexchdim.f90.

Function/Subroutine Documentation

◆ gtvarexchdim()

subroutine gtvarexchdim ( type(gt_variable), intent(in)  var,
integer, intent(in)  dimord1,
integer, intent(in)  dimord2,
logical, intent(in), optional  count_compact,
logical, intent(out)  err 
)

Exchange dimensions at specified order numbers

Exchanges dimensions at dimension order numbers dimord1 and dimord2 in variable var.

If count_compact is .true., operates including degenerate dimensions.

If an error occurs, outputs a message and terminates the program. If err is provided, returns .true. and program does not terminate.

Parameters
[in]varVariable handle
[in]dimord1First dimension order number
[in]dimord2Second dimension order number
[in]count_compactInclude degenerate dimensions (optional)
[out]errError flag

Definition at line 56 of file gtvarexchdim.f90.

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)
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: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
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)

References dc_trace::beginsub(), dc_trace::dbgmessage(), gtdata_internal_map::dimord_skip_compact(), dc_trace::endsub(), gtdata_internal_map::map_lookup(), gtdata_internal_map::map_set(), and gtdata_internal_map::map_set_ndims().

Here is the call graph for this function: