gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
dcdatetimediv.f90
Go to the documentation of this file.
1! -*- mode: f90; coding: utf-8 -*-
2!-----------------------------------------------------------------------
3! Copyright (c) 2000-2026 Gtool Development Group. All rights reserved.
4!-----------------------------------------------------------------------
5!>
6!> @author Yasuhiro MORIKAWA, Eizi TOYODA
7!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
8!> License is BSD-2-Clause. see [COPYRIGHT](@ref COPYRIGHT) in detail
9!> @en
10!> @brief Functions for user defined operation (/)
11!> @details
12!> Procedures described in this file are provided from "dc_date" module.
13!> @enden
14!>
15!> @ja
16!> @brief 利用者定義演算子 (/) のための関数
17!> @details
18!> このファイルに記載される手続き群は dc_date モジュールから提供されます.
19!> @endja
20!>
21
22!> @en
23!> @brief Divide DC_DIFFTIME by integer
24!> @details
25!> Returns the result of dividing time difference `diff` by `denominator`.
26!>
27!> **Note**: Dividing month difference may produce approximate results.
28!>
29!> @param[in] diff Time difference
30!> @param[in] denominator Divisor (integer)
31!> @return result Result of division
32!> @enden
33!>
34!> @ja
35!> @brief DC_DIFFTIME を整数で除算
36!> @details
37!> 日時差 `diff` を `denominator` で除算した結果を返します.
38!>
39!> **注意**: 月差を除算すると近似的結果になるおそれがあります
40!>
41!> @param[in] diff 日時差
42!> @param[in] denominator 除数 (整数)
43!> @return result 除算結果
44!> @endja
45function dcdatetime_div_fi(diff, denominator) result(result)
47 use dc_scaledsec, only: dc_scaled_sec, &
48 & operator(<), operator(>), operator(<=), operator(>=), &
49 & operator(+), operator(-), operator(*), operator(/), &
50 & modscl => mod, modulo, int, abs, sign
52 implicit none
53 type(dc_difftime):: result
54 type(dc_difftime), intent(in):: diff
55 integer, intent(in):: denominator
56continue
57 result % mon = int( diff % mon / denominator )
58 ! 月からの近似的繰り下がりは日単位でしか行わない
59 result % day = &
60 & int( diff % day / denominator ) &
61 & + int( (cyclic_mdays * modscl(diff % mon, denominator)) / denominator )
62 result % sec = diff % sec / denominator + &
63 & (diff % day_seconds * modscl(diff % day, denominator)) / &
64 & denominator
65 result % nondim_flag = diff % nondim_flag
66end function dcdatetime_div_fi
67
68!> @en
69!> @brief Divide DC_DIFFTIME by single precision real
70!> @details
71!> **Note**: Dividing month difference may produce approximate results.
72!>
73!> @param[in] diff Time difference
74!> @param[in] denominator Divisor (single precision)
75!> @return result Result of division
76!> @enden
77!>
78!> @ja
79!> @brief DC_DIFFTIME を単精度実数で除算
80!> @details
81!> **注意**: 月差を除算すると近似的結果になるおそれがあります
82!>
83!> @param[in] diff 日時差
84!> @param[in] denominator 除数 (単精度)
85!> @return result 除算結果
86!> @endja
87function dcdatetime_div_fr(diff, denominator) result(result)
88 use dc_date_generic, only: operator(/)
90 use dc_types, only: dp
91 implicit none
92 type(dc_difftime):: result
93 type(dc_difftime), intent(in):: diff
94 real, intent(in):: denominator
95continue
96 result = diff / real(denominator, dp)
97end function dcdatetime_div_fr
98
99!> @en
100!> @brief Divide DC_DIFFTIME by double precision real
101!> @details
102!> **Note**: Dividing month difference may produce approximate results.
103!>
104!> @param[in] diff Time difference
105!> @param[in] denominator Divisor (double precision)
106!> @return result Result of division
107!> @enden
108!>
109!> @ja
110!> @brief DC_DIFFTIME を倍精度実数で除算
111!> @details
112!> **注意**: 月差を除算すると近似的結果になるおそれがあります
113!>
114!> @param[in] diff 日時差
115!> @param[in] denominator 除数 (倍精度)
116!> @return result 除算結果
117!> @endja
118function dcdatetime_div_fd(diff, denominator) result(result)
121 use dc_scaledsec, only: dc_scaled_sec, &
122 & operator(<), operator(>), operator(<=), operator(>=), &
123 & operator(+), operator(-), operator(*), operator(/), &
124 & modulo, int, abs, sign
125 use dc_types, only: dp
126 implicit none
127 type(dc_difftime):: result
128 type(dc_difftime), intent(in):: diff
129 real(dp), intent(in):: denominator
130 type(dc_scaled_sec):: month, day
131continue
132 month = int( diff % mon / denominator )
133 result % mon = int(month)
134 day = int( diff % day / denominator ) &
135 & + int(cyclic_mdays * (month - result % mon))
136 result % day = int(day)
137 result % sec = &
138 & diff % sec / denominator + (day - result % day) * diff % day_seconds
139 result % day_seconds = diff % day_seconds
140 result % nondim_flag = diff % nondim_flag
141 call dcdate_normalize(result % day, result % sec, result % day_seconds, result % nondim_flag)
142end function dcdatetime_div_fd
143
144!> @en
145!> @brief Divide two DC_DIFFTIME values
146!> @details
147!> **Note**: Division mixing month difference and datetime may produce approximate results.
148!>
149!> @param[in] diff1 Dividend (time difference)
150!> @param[in] diff2 Divisor (time difference)
151!> @return result Result of division (double precision)
152!> @enden
153!>
154!> @ja
155!> @brief 2つの DC_DIFFTIME を除算
156!> @details
157!> **注意**: 月差と日時の混在する除算は近似的結果になるおそれがあります
158!>
159!> @param[in] diff1 被除数 (日時差)
160!> @param[in] diff2 除数 (日時差)
161!> @return result 除算結果 (倍精度)
162!> @endja
163function dcdatetime_div_ff(diff1, diff2) result(result)
164 use dc_date_types, only: cyclic_mdays
165 use dc_scaledsec, only: dc_scaled_sec, assignment(=), &
166 & operator(<), operator(>), operator(<=), operator(>=), &
167 & operator(+), operator(-), operator(*), operator(/), &
168 & modulo, int, abs, sign
170 use dc_types, only: dp
171 implicit none
172 real(dp):: result
173 type(dc_difftime), intent(in):: diff1, diff2
174continue
175 ! ゼロ割対応コードが必要か?
176 result = &
177 & (diff1 % day_seconds * (cyclic_mdays * diff1 % mon + diff1 % day) &
178 & + diff1 % sec) / &
179 & (diff2 % day_seconds * (cyclic_mdays * diff2 % mon + diff2 % day) &
180 & + diff2 % sec)
181end function dcdatetime_div_ff
type(dc_difftime) function dcdatetime_div_fi(diff, denominator)
Functions for user defined operation (/).
type(dc_difftime) function dcdatetime_div_fr(diff, denominator)
real(dp) function dcdatetime_div_ff(diff1, diff2)
type(dc_difftime) function dcdatetime_div_fd(diff, denominator)
Interface declarations for procedures provided from dc_date.
Internal module for dc_date.
subroutine, public dcdate_normalize(day, sec, day_seconds, nondim_flag)
Derived types and parameters for date and time.
real(dp), parameter, public cyclic_mdays
Days per month for cyclic calendar (also used for DC_DIFFTIME)
Scaled seconds module for precise time operations.
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public dp
Double Precision Real number
Definition dc_types.f90:92