gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
dccalcreate.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 Youhei SASAKI, Yasuhiro MORIKAWA
7!> @copyright Copyright (C) GFD Dennou Club, 2009-2026. All rights reserved. <br/>
8!> License is BSD-2-Clause. see [COPYRIGHT](@ref COPYRIGHT) in detail
9!> @en
10!> @brief Calendar creation procedures
11!> @details
12!> Procedures described in this file are provided from "dc_calendar" module.
13!> @enden
14!>
15!> @ja
16!> @brief 暦の設定手続
17!> @details
18!> このファイルに記載される手続き群は dc_calendar モジュールから提供されます.
19!> @endja
20!>
21
22!> @en
23!> @brief Create calendar with predefined calendar type
24!> @details
25!> Set calendar.
26!>
27!> This subroutine sets previously-defined calendars by "dc_calendar" module.
28!> If number of days of a month, number of seconds of a day, etc.
29!> want to be specified arbitrarily, use the following homonymous subroutine.
30!>
31!> Following strings are valid as `cal_type`.
32!> If any other string is specified, an error is caused.
33!> They are not case-sensitive.
34!>
35!> | cal_type | Description |
36!> |------------|------------------------------------------------------------|
37!> | gregorian | Gregorian calendar |
38!> | julian | Julian calendar |
39!> | noleap | A calendar without leap year |
40!> | 360day | A calendar in which number of days of a month is 30 |
41!> | cyclic | A calendar in which number of days of a year is "30.6 x (number of months) - (total days until last month)" (truncate fractional part) |
42!>
43!> If an optional argument `cal` is omitted,
44!> the calendar setting is stored to a "dc_calendar_types#DC_CAL"
45!> variable that is saved in the "dc_calendar".
46!> When `cal` is omitted in subsequent procedures, the internal calendar
47!> is used.
48!> If `cal` is not omitted, the settings is stored to the `cal`.
49!> In order to use the calendar setting, use the "dc_calendar_types#DC_CAL"
50!> variable to subsequent procedures.
51!>
52!> @param[in] cal_type Strings that specify a previously-defined calendar
53!> @param[out] cal An object that stores information of calendar
54!> @param[out] err Exception handling flag
55!> @enden
56!>
57!> @ja
58!> @brief 既定の暦タイプで暦を作成
59!> @details
60!> 暦の設定を行います.
61!>
62!> このサブルーチンは "dc_calendar" モジュールで用意した
63!> 既定の暦を設定するものです. 1 ヶ月の日数, 1 日の秒数などを
64!> 任意に指定する場合には, 下記の同名のサブルーチンを使用して下さい.
65!>
66!> `cal_type` として以下のものが有効です. これ以外の文字列
67!> を与えた場合にはエラーが発生します. 大文字と小文字は区別しません.
68!>
69!> | cal_type | 説明 |
70!> |------------|------------------------------------------------------------|
71!> | gregorian | グレゴリオ暦 |
72!> | julian | ユリウス暦 |
73!> | noleap | 閏年無しの暦 |
74!> | 360day | 1ヶ月が 30 日の暦 |
75!> | cyclic | ある月の日数を「30.6 × 月数 − 前月までの総日数」の小数点以下切捨とする暦 |
76!>
77!> 省略可能引数 `cal` が省略された場合には, dc_calendar 内部で
78!> 保持される "dc_calendar_types#DC_CAL" 型の変数に暦が
79!> 設定されます. その後の手続きで `cal` を省略した場合には
80!> この暦が使用されます.
81!> `cal` が省略されない場合にはその変数に暦が設定されます.
82!> その暦を使用する場合, 手続きにその "dc_calendar_types#DC_CAL" 型の変数
83!> を与えてください.
84!>
85!> @param[in] cal_type 既定の暦を指定する文字列
86!> @param[out] cal 暦情報を収めたオブジェクト
87!> @param[out] err 例外処理用フラグ.
88!> デフォルトでは, この手続き内でエラーが生じた場合,
89!> プログラムは強制終了します.
90!> 引数 `err` が与えられる場合, プログラムは強制終了せず,
91!> 代わりに `err` に .true. が代入されます.
92!> @endja
93subroutine dccalcreate1( cal_type, cal, err )
94
95 use dc_calendar_types, only: dc_cal, &
98 use dc_message, only: messagenotify
99 use dc_string, only: lchar
100 use dc_trace, only: beginsub, endsub
102 use dc_types, only: string, dp
103 implicit none
104 character(*), intent(in):: cal_type
105 type(dc_cal), intent(out), optional, target:: cal
106 logical, intent(out), optional:: err
107
108 ! 作業変数
109 ! Work variables
110 !
111 type(dc_cal), pointer:: calp =>null()
112 integer:: stat
113 character(STRING):: cause_c
114 character(*), parameter:: version = &
115 & '$Name: $' // &
116 & '$Id: dccalcreate.f90,v 1.4 2009-10-18 12:02:32 morikawa Exp $'
117 character(*), parameter:: subname = 'DCCalCreate1'
118continue
119 call beginsub( subname, version )
120 stat = dc_noerr
121 cause_c = ''
122
123 ! オブジェクトのポインタ割付
124 ! Associate pointer of an object
125 !
126 if ( present( cal ) ) then
127 calp => cal
128 else
129 calp => default_cal
130 end if
131
132 ! 暦の種別の正当性のチェック
133 ! Validate a kind of calendar
134 !
135 select case( lchar(trim(cal_type)) )
136 case('cyclic')
137 calp % cal_type = cal_cyclic
138 case('noleap')
139 calp % cal_type = cal_noleap
140 case('julian')
141 calp % cal_type = cal_julian
142 case('gregorian')
143 calp % cal_type = cal_gregorian
144 case('360day')
145 calp % cal_type = cal_360day
146 case default
147 stat = dc_ebadcaltype
148 call messagenotify('W', subname, &
149 & 'cal_type=<%c> is invalid calender type.', &
150 & c1 = trim(cal_type) )
151 goto 999
152 end select
153
154 ! 各要素への値の設定
155 ! Configure elements
156 !
157 allocate( calp % day_in_month(1:12) )
158 calp % month_in_year = 12
159 calp % hour_in_day = 24
160 calp % min_in_hour = 60
161 calp % sec_in_min = 60.0_dp
162
163 select case( calp % cal_type )
164 case(cal_cyclic)
165 calp % day_in_month(1:12) = &
166 & (/ 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 30 /)
167 case(cal_noleap)
168 calp % day_in_month(1:12) = &
169 & (/ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /)
170 case(cal_julian)
171 calp % day_in_month(1:12) = &
172 & (/ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /)
173 case(cal_gregorian)
174 calp % day_in_month(1:12) = &
175 & (/ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /)
176 case(cal_360day)
177 calp % day_in_month(1:12) = &
178 & (/ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 /)
179 case default
180 end select
181
182 ! 終了処理, 例外処理
183 ! Termination and Exception handling
184 !
185 calp % initialized = .true.
186999 continue
187 nullify( calp )
188 call storeerror( stat, subname, err, cause_c )
189 call endsub( subname )
190end subroutine dccalcreate1
191
192!> @en
193!> @brief Create calendar with custom settings
194!> @details
195!> Set calendar.
196!>
197!> Specify number of days of a month, number of seconds of a day, etc.
198!> to arguments. If Gregorian calendar, Julian calendar are needed,
199!> see a foregoing homonymous subroutine.
200!>
201!> If an optional argument `cal` is omitted.
202!> The calendar setting is stored to a "dc_calendar_types#DC_CAL"
203!> variable that is saved in the "dc_calendar".
204!> When `cal` is omitted in subsequent procedures, the internal calendar
205!> is used.
206!> If `cal` is not omitted, the settings is stored to the `cal`.
207!> In order to use the calendar setting, use the "dc_calendar_types#DC_CAL"
208!> variable to subsequent procedures.
209!>
210!> @param[in] month_in_year Months in a year
211!> @param[in] day_in_month Days in months (array)
212!> @param[in] hour_in_day Hours in a day
213!> @param[in] min_in_hour Minutes in an hour
214!> @param[in] sec_in_min Seconds in a minute
215!> @param[out] cal An object that stores information of calendar
216!> @param[out] err Exception handling flag
217!> @enden
218!>
219!> @ja
220!> @brief カスタム設定で暦を作成
221!> @details
222!> 暦の設定を行います.
223!>
224!> 1 ヶ月の日数, 1 日の秒数などを引数に指定して下さい.
225!> グレゴリオ暦やユリウス暦などを利用する場合には
226!> 上記の同名のサブルーチンを使用して下さい.
227!>
228!> 省略可能引数 `cal` が省略された場合には, dc_calendar 内部で
229!> 保持される "dc_calendar_types#DC_CAL" 型の変数に暦が
230!> 設定されます. その後の手続きで `cal` を省略した場合には
231!> この暦が使用されます.
232!> `cal` が省略されない場合にはその変数に暦が設定されます.
233!> その暦を使用する場合, 手続きにその "dc_calendar_types#DC_CAL" 型の変数
234!> を与えてください.
235!>
236!> @param[in] month_in_year 1年の月数
237!> @param[in] day_in_month 1ヶ月の日数 (配列)
238!> @param[in] hour_in_day 1日の時間数
239!> @param[in] min_in_hour 1時間の分数
240!> @param[in] sec_in_min 1分の秒数
241!> @param[out] cal 暦情報を収めたオブジェクト
242!> @param[out] err 例外処理用フラグ.
243!> デフォルトでは, この手続き内でエラーが生じた場合,
244!> プログラムは強制終了します.
245!> 引数 `err` が与えられる場合, プログラムは強制終了せず,
246!> 代わりに `err` に .true. が代入されます.
247!> @endja
248subroutine dccalcreate2( month_in_year, day_in_month, &
249 & hour_in_day, min_in_hour, sec_in_min, &
250 & cal, err )
251
254 use dc_message, only: messagenotify
255 use dc_types, only: dp
256 use dc_trace, only: beginsub, endsub
258 use dc_types, only: string
259 implicit none
260 integer, intent(in):: month_in_year
261 integer, intent(in):: day_in_month(:)
262 integer, intent(in):: hour_in_day
263 integer, intent(in):: min_in_hour
264 real(DP), intent(in):: sec_in_min
265 type(dc_cal), intent(out), optional, target:: cal
266 logical, intent(out), optional:: err
267
268 ! 作業変数
269 ! Work variables
270 !
271 type(dc_cal), pointer:: calp =>null()
272 integer:: size_day_in_month
273 integer:: stat
274 character(STRING):: cause_c
275 character(*), parameter:: version = &
276 & '$Name: $' // &
277 & '$Id: dccalcreate.f90,v 1.4 2009-10-18 12:02:32 morikawa Exp $'
278 character(*), parameter:: subname = 'DCCalCreate2'
279continue
280 call beginsub( subname, version )
281 stat = dc_noerr
282 cause_c = ''
283
284 ! オブジェクトのポインタ割付
285 ! Associate pointer of an object
286 !
287 if ( present( cal ) ) then
288 calp => cal
289 else
290 calp => default_cal
291 end if
292
293 ! 月数の算出
294 ! Evaluate number of months
295 !
296 size_day_in_month = size ( day_in_month )
297
298 ! 引数の正当性のチェック
299 ! Validate arguments
300 !
301 if ( .not. month_in_year == size_day_in_month ) then
302 stat = dc_ebadcaltype
303 call messagenotify('W', subname, &
304 & 'month_in_year=<%d> is not equal to size of day_in_month=<%d>', &
305 & i = (/ month_in_year, size_day_in_month /) )
306 goto 999
307 end if
308
309 if ( month_in_year < 1 ) then
310 stat = dc_ebadcaltype
311 call messagenotify('W', subname, 'month_in_year=<%d> must be positive', &
312 & i = (/ month_in_year /) )
313 goto 999
314 end if
315
316 if ( hour_in_day < 1 ) then
317 stat = dc_ebadcaltype
318 call messagenotify('W', subname, 'hour_in_day=<%d> must be positive', &
319 & i = (/ hour_in_day /) )
320 goto 999
321 end if
322
323 if ( min_in_hour < 1 ) then
324 stat = dc_ebadcaltype
325 call messagenotify('W', subname, 'min_in_hour=<%d> must be positive', &
326 & i = (/ min_in_hour /) )
327 goto 999
328 end if
329
330 if ( .not. sec_in_min > 0.0_dp ) then
331 stat = dc_ebadcaltype
332 call messagenotify('W', subname, 'sec_in_min=<%f> must be positive', &
333 & d = (/ sec_in_min /) )
334 goto 999
335 end if
336
337 ! 各要素への値の設定
338 ! Configure elements
339 !
340 calp % cal_type = cal_user_defined
341 calp % month_in_year = month_in_year
342 allocate( calp % day_in_month(1:size_day_in_month) )
343 calp % day_in_month = day_in_month
344 calp % hour_in_day = hour_in_day
345 calp % min_in_hour = min_in_hour
346 calp % sec_in_min = sec_in_min
347
348 ! 終了処理, 例外処理
349 ! Termination and Exception handling
350 !
351 calp % initialized = .true.
352999 continue
353 nullify( calp )
354 call storeerror( stat, subname, err, cause_c )
355 call endsub( subname )
356end subroutine dccalcreate2
subroutine dccalcreate2(month_in_year, day_in_month, hour_in_day, min_in_hour, sec_in_min, cal, err)
subroutine dccalcreate1(cal_type, cal, err)
暦の設定手続
dc_calendar用の内部モジュール
type(dc_cal), target, save, public default_cal
デフォルトの暦. DCCal で始まる手続のうち, DC_CAL 型の省略可能引数が与えられない 場合にはこの暦が設定もしくは利用される.
暦と日時に関する構造データ型と定数
integer, parameter, public cal_user_defined
integer, parameter, public cal_julian
integer, parameter, public cal_gregorian
integer, parameter, public cal_360day
integer, parameter, public cal_noleap
integer, parameter, public cal_cyclic
エラー処理用モジュール
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
エラー等を保持
Definition dc_error.f90:468
integer, parameter, public dc_ebadcaltype
Definition dc_error.f90:537
メッセージの出力
文字型変数の操作
Definition dc_string.f90:83
デバッグ時の追跡用モジュール
Definition dc_trace.f90:150
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
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition dc_types.f90:137
integer, parameter, public dp
倍精度実数型変数
Definition dc_types.f90:92