dccaldateparsestr.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine dccaldateparsestr1 (date_str, year, month, day, hour, min, sec, zone, err)
 

Function/Subroutine Documentation

◆ dccaldateparsestr1()

subroutine dccaldateparsestr1 ( character(*), intent(in)  date_str,
integer, intent(out)  year,
integer, intent(out)  month,
integer, intent(out)  day,
integer, intent(out)  hour,
integer, intent(out)  min,
real(dp), intent(out)  sec,
character(*), intent(out)  zone,
logical, intent(out), optional  err 
)

Definition at line 17 of file dccaldateparsestr.f90.

References dc_trace::beginsub(), dc_trace::dbgmessage(), dc_error::dc_ealreadyinit, dc_error::dc_ebaddate, dc_error::dc_noerr, dc_types::dp, dc_trace::endsub(), dc_regex::match(), dc_error::storeerror(), dc_types::string, and dc_types::token.

17  ! *date_str* で与えられる日時形式
18  ! (gtool4 netCDF 規約「5.5 日時形式」に準拠) を解釈し,
19  ! *year* 〜 *zone* に返します.
20  !
21  ! Parse strings of date (conformed to gtool4 netCDF Convention
22  ! "5.5 Expression of date and time") specified as *date_str*,
23  ! and return *year* -- *zone*.
24  !
25 
26  use dc_regex, only: match
27  use dc_message, only: messagenotify
28  use dc_string, only: lchar, stoi, stod
29  use dc_trace, only: beginsub, endsub, dbgmessage
31  use dc_types, only: string, dp, token
32  implicit none
33  character(*), intent(in):: date_str
34  ! 日時情報を表す文字列.
35  ! 表示形式については gtool4 netCDF 規約
36  ! 5.5 日時形式を参照のこと.
37  !
38  ! Strings that express date and time.
39  ! See gtool4 netCDF Convention
40  ! 5.5 Expression of date and time for details.
41  integer, intent(out):: year ! 年. Year.
42  integer, intent(out):: month ! 月. Month.
43  integer, intent(out):: day ! 日. Day.
44  integer, intent(out):: hour ! 時. Hour.
45  integer, intent(out):: min ! 分. Minute.
46  real(DP), intent(out):: sec ! 秒. Second.
47  character(*), intent(out):: zone
48  ! UTC からの時差. Time-zone.
49  logical, intent(out), optional:: err
50  ! 例外処理用フラグ.
51  ! デフォルトでは, この手続き内でエラーが
52  ! 生じた場合, プログラムは強制終了します.
53  ! 引数 *err* が与えられる場合,
54  ! プログラムは強制終了せず, 代わりに
55  ! *err* に .true. が代入されます.
56  !
57  ! Exception handling flag.
58  ! By default, when error occur in
59  ! this procedure, the program aborts.
60  ! If this *err* argument is given,
61  ! .true. is substituted to *err* and
62  ! the program does not abort.
63 
64 
65  ! 作業変数
66  ! Work variables
67  !
68  integer:: start, length
69  character(STRING):: str1, str2
70  character(TOKEN):: zone_pm, zone_hrs, zone_min
71  integer:: stat
72  character(STRING):: cause_c
73  character(*), parameter:: subname = 'DCCalDateParseStr1'
74 continue
75  call beginsub( subname )
76  stat = dc_noerr
77  cause_c = ''
78 
79  ! 与えられた文字列が日時表現として有効かどうかをチェック
80  ! Check validation of strings as an expression of date
81  !
82  call match( '[-]*#d+-#d+-#d+[#w#s]+#d+:#d+:#d+', date_str, & ! (in)
83  & start, length ) ! (out)
84 
85  if ( length > 0 ) then
86  str1 = date_str(start:)
87  else
88  stat = dc_ebaddate
89  call messagenotify('W', subname, &
90  & 'date_str=<%c> is invalid expression as date.', &
91  & c1 = trim(date_str) )
92  goto 999
93  end if
94 
95  ! 年の解釈
96  ! Parse year
97  !
98  call match( '^[-]*#d+-', str1, & ! (in)
99  & start, length ) ! (out)
100  str2 = str1(start:start+length-2)
101  str1 = str1(start+length:)
102  year = stoi(str2)
103 
104  ! 月の解釈
105  ! Parse month
106  !
107  call match( '^#d+-', str1, & ! (in)
108  & start, length ) ! (out)
109  str2 = str1(start:start+length-2)
110  str1 = str1(start+length:)
111  month = stoi(str2)
112 
113  ! 日の解釈
114  ! Parse day
115  !
116  call match( '^#d+[#w#s]', str1, & ! (in)
117  & start, length ) ! (out)
118  str2 = str1(start:start+length-2)
119  str1 = str1(start+length:)
120  day = stoi(str2)
121 
122  ! 時の解釈
123  ! Parse hour
124  !
125  call match( '#d+:', str1, & ! (in)
126  & start, length ) ! (out)
127  str2 = str1(start:start+length-2)
128  str1 = str1(start+length:)
129  hour = stoi(str2)
130 
131  ! 分の解釈
132  ! Parse minute
133  !
134  call match( '#d+:', str1, & ! (in)
135  & start, length ) ! (out)
136  str2 = str1(start:start+length-2)
137  str1 = str1(start+length:)
138  min = stoi(str2)
139 
140  ! 秒の解釈
141  ! Parse min
142  !
143  call match( '#d+', str1, & ! (in)
144  & start, length ) ! (out)
145  str2 = str1(start:start+length-1)
146  str1 = str1(start+length:)
147 
148  call match( '^#.#d+', str1, & ! (in)
149  & start, length ) ! (out)
150 
151  if ( length > 0 ) then
152  str2 = trim(str2) // str1(start:start+length-1)
153  str1 = str1(start+length:)
154  end if
155  sec = stod(str2)
156 
157  ! UTC からの時差の解釈
158  ! Parse time-zone difference
159  !
160  call match( '[#+-]#d+:#d+', str1, & ! (in)
161  & start, length ) ! (out)
162  if ( length > 0 ) then
163  zone_pm = str1(start:start)
164  str1 = str1(start+1:start+length-1)
165 
166  call match( '^#d+:', str1, & ! (in)
167  & start, length ) ! (out)
168  zone_hrs = str1(start:start+length-2)
169  zone_min = str1(start+length:)
170  zone = trim(zone_pm) // trim(zone_hrs) // ':' // trim(zone_min)
171  else
172  zone = ''
173  end if
174 
175  call dbgmessage('year=<%d> month=<%d> day=<%d> hour=<%d> min=<%d> sec=<%f>' // &
176  & ' zone=<%c>', &
177  & i = (/year, month, day, hour, min/), d = (/sec/), &
178  & c1 = trim(zone) )
179 
180  ! 終了処理, 例外処理
181  ! Termination and Exception handling
182  !
183 999 continue
184  call storeerror( stat, subname, err, cause_c )
185  call endsub( subname )
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition: dc_types.f90:109
integer, parameter, public dc_ebaddate
Definition: dc_error.f90:575
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition: dc_error.f90:830
integer, parameter, public dc_noerr
Definition: dc_error.f90:509
シンプルな正規表現関数 &#39;match&#39; を提供します.
Definition: dc_regex.f90:16
integer, parameter, public dp
倍精度実数型変数
Definition: dc_types.f90:83
subroutine, public match(pattern, text, start, length)
Definition: dc_regex.f90:267
subroutine, public dbgmessage(fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:509
subroutine, public beginsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca, version)
Definition: dc_trace.f90:351
文字型変数の操作.
Definition: dc_string.f90:24
種別型パラメタを提供します。
Definition: dc_types.f90:49
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
integer, parameter, public dc_ealreadyinit
Definition: dc_error.f90:558
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118
Here is the call graph for this function: