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

Go to the source code of this file.

Functions/Subroutines

character(string) function dcdatetimetochar (time)
 Convert DC_DATETIME, DC_DIFFTIME to character strings.
character(string) function dcdifftimetochar (diff)
character(token) function dcdatetimetocharcal (time, upcase)

Function/Subroutine Documentation

◆ dcdatetimetochar()

character(string) function dcdatetimetochar ( type(dc_datetime), intent(in) time)

Convert DC_DATETIME, DC_DIFFTIME to character strings.

Author
Yasuhiro MORIKAWA

Procedures described in this file are provided from "dc_date" module.

Convert DC_DATETIME to character string

Convert a dc_date_types#DC_DATETIME variable to a character variable and return it. The format is a complete notation according to JIS X 0301 as follows:

YYYY-MM-DDThh:mm:ss.sTZD

YYYY is year, MM is month, DD is day, hh is hour, mm is minute, ss.s is seconds, and TZD is timezone.

Parameters
[in]timeDatetime to convert
Returns
Character representation of the datetime

Definition at line 52 of file dcdatetimetochar.f90.

53
54 use dc_types, only: string, token, dp
55 use dc_string, only: tochar, cprintf, stoa
56 use dc_date_generic, only: eval
57 use dc_date_types, only: dc_datetime
58 use dc_message, only: messagenotify
59 implicit none
60 character(STRING):: result
61 type(DC_DATETIME), intent(in):: time
62
63 integer :: year, mon, day, hour, min, csec_len
64 real(DP):: sec
65 character(TOKEN) :: zone
66 character(STRING) :: csec
67continue
68
69 call eval(time, &
70 & year=year, mon=mon, day=day, hour=hour, min=min, sec=sec, zone=zone)
71
72 csec = tochar(sec)
73 if ( trim(csec) == '-0.' ) csec = '0.'
74 do while ( index('123456789.', csec(len_trim(csec):len_trim(csec)) ) == 0 )
75 if ( len_trim(csec) < 2 ) exit
76 csec = csec(1:len_trim(csec)-1)
77 end do
78 if (int(sec) > -1 .and. int(sec) < 10) then
79 if (len_trim(csec) >= len(csec)) then
80 csec = '0' // trim(csec(1:len(csec) - 1))
81 else
82 csec = '0' // trim(csec)
83 end if
84 end if
85 csec_len = len(trim(adjustl(csec)))
86 if (csec(csec_len:csec_len) == '.') csec = csec(1:csec_len-1)
87
88 result = cprintf('%04d-%02d-%02dT%02d:%02d:%c%c', &
89 & i=(/year, mon, day, hour, min/), &
90 & c1=trim(csec), c2=trim(zone))
91
Interface declarations for procedures provided from dc_date.
Derived types and parameters for date and time.
Message output module.
Handling character types.
Definition dc_string.f90:83
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public token
Character length for word, token
Definition dc_types.f90:128
integer, parameter, public string
Character length for string
Definition dc_types.f90:137
integer, parameter, public dp
Double Precision Real number
Definition dc_types.f90:92

References dc_types::dp, dc_types::string, and dc_types::token.

◆ dcdatetimetocharcal()

character(token) function dcdatetimetocharcal ( type(dc_datetime), intent(in) time,
logical, intent(in), optional upcase )

Convert calendar type of DC_DATETIME to character string

Return the calendar type of a dc_date_types#DC_DATETIME variable as a character string. Currently supported calendars are as follows. Left is the integer variable representing the calendar, right is the returned string. If .true. is given to upcase, the string is returned in uppercase.

Calendar type constant Returned string
dc_date_types#CAL_CYCLIC cyclic
dc_date_types#CAL_NOLEAP noleap
dc_date_types#CAL_JULIAN julian
dc_date_types#CAL_GREGORIAN gregorian
Parameters
[in]timeDatetime whose calendar type to convert
[in]upcaseIf .true., return uppercase string
Returns
Calendar type as character string

Definition at line 243 of file dcdatetimetochar.f90.

244
245 use dc_types, only: token
247 use dc_date_types, only: dc_datetime, &
249 use dc_string, only: toupper
250 character(TOKEN) :: result
251 type(DC_DATETIME), intent(in):: time
252 logical, intent(in), optional:: upcase
253continue
254 select case( time % caltype )
255 case(cal_cyclic)
256 result = 'cyclic'
257 case(cal_noleap)
258 result = 'noleap'
259 case(cal_julian)
260 result = 'julian'
261 case(cal_gregorian)
262 result = 'gregorian'
263 case default
264 result = 'none'
265 end select
266
267 if ( present_and_true(upcase) ) then
268 call toupper(result) ! (inout)
269 end if
270
integer, parameter, public cal_noleap
Calendar without leap years (365 days per year)
integer, parameter, public cal_cyclic
Cyclic calendar (30.6 days per month)
integer, parameter, public cal_gregorian
Gregorian calendar
integer, parameter, public cal_julian
Julian calendar
Judge optional control parameters.
logical function, public present_and_true(arg)

References dc_date_types::cal_cyclic, dc_date_types::cal_gregorian, dc_date_types::cal_julian, dc_date_types::cal_noleap, dc_present::present_and_true(), and dc_types::token.

Here is the call graph for this function:

◆ dcdifftimetochar()

character(string) function dcdifftimetochar ( type(dc_difftime), intent(in) diff)

Convert DC_DIFFTIME to character string

Convert a dc_date_types#DC_DIFFTIME variable to a character variable and return it. The format is as follows:

+YYYY-MM-DDThh:mm:ss.s
-YYYY-MM-DDThh:mm:ss.s

YYYY is year, MM is month, DD is day, hh is hour, mm is minute, ss.s is seconds. Note that DD may exceed 2 digits. (dc_date_types#DC_DIFFTIME is a data type for expressing "X months later", "X days before", etc., so it does not carry up days to months or carry down months to days. It also does not hold "year" information. The number of days in a year or month is determined by the dc_date_types#DC_DATETIME side).

If the unit was set to '1' in DCDiffTimeCreate, it is treated as non-dimensional time, so the format becomes:

ss.s
Parameters
[in]diffTime difference to convert
Returns
Character representation of the time difference

Definition at line 147 of file dcdatetimetochar.f90.

148
149 use dc_types, only: string, dp
150 use dc_string, only: tochar, cprintf, stoa
151 use dc_date_generic, only: eval
152 use dc_date_types, only: dc_difftime
153 use dc_scaledsec, only: assignment(=)
154 implicit none
155 character(STRING):: result
156 type(DC_DIFFTIME), intent(in):: diff
157
158 integer :: year, mon, day, hour, min, csec_len
159 real(DP):: sec
160 character(STRING) :: csec
161 character(1) :: pm
162continue
163
164 if ( .not. diff % nondim_flag ) then
165 call eval(diff, year=year, mon=mon, day=day, hour=hour, min=min, sec=sec)
166
167 if ( year < 0 .or. mon < 0 .or. day < 0 .or. &
168 & hour < 0 .or. min < 0 .or. sec < 0 ) then
169 year=abs(year) ; mon=abs(mon) ; day=abs(day)
170 hour=abs(hour) ; min=abs(min) ; sec=abs(sec)
171 pm = '-'
172 else
173 pm = '+'
174 end if
175
176 csec = tochar(sec)
177 if ( trim(csec) == '-0.' ) csec = '0.'
178 do while ( index('123456789.', csec(len_trim(csec):len_trim(csec)) ) == 0 )
179 if ( len_trim(csec) < 2 ) exit
180 csec = csec(1:len_trim(csec)-1)
181 end do
182 if (int(sec) > -1 .and. int(sec) < 10) then
183 if (len_trim(csec) >= len(csec)) then
184 csec = '0' // trim(csec(1:len(csec) - 1))
185 else
186 csec = '0' // trim(csec)
187 end if
188 end if
189 csec_len = len(trim(adjustl(csec)))
190 if (csec(csec_len:csec_len) == '.') csec = csec(1:csec_len-1)
191
192 result = cprintf('%c%04d-%02d-%02dT%02d:%02d:%c', &
193 & i=(/year, mon, day, hour, min/), &
194 & c1=pm, c2=trim(csec))
195 else
196 sec = diff % sec
197 result = tochar( sec )
198 end if
199
Scaled seconds module for precise time operations.

References dc_types::dp, and dc_types::string.