dcdatetimetochar.f90
Go to the documentation of this file.
1 !== dc_date_types#DC_DATETIME, dc_date_types#DC_DIFFTIME 型変数の文字変換
2 !
3 ! Authors:: Yasuhiro MORIKAWA
4 ! Version:: $Id: dcdatetimetochar.f90,v 1.2 2009-05-25 10:01:34 morikawa Exp $
5 ! Tag Name:: $Name: $
6 ! Copyright:: Copyright (C) GFD Dennou Club, 2006-. All rights reserved.
7 ! License:: See COPYRIGHT[link:../../COPYRIGHT]
8 !
9 ! このファイルで提供される手続き群は dc_date モジュールにて提供されます。
10 !
11 
12 function dcdatetimetochar(time) result(result)
13  !
14  ! dc_date_types#DC_DATETIME 型変数を文字型変数へ変換して返します.
15  ! 書式は下記のように JIS X 0301 の完全表記です.
16  !
17  ! YYYY-MM-DDThh:mm:ss.sTZD
18  !
19  ! YYYY は年, MM は月, DD は日, hh は時, mm は分, ss.s は秒,
20  ! TZD はタイムゾーンを表します.
21  !
22  use dc_types, only: string, token, dp
23  use dc_string, only: tochar, cprintf, stoa
24  use dc_date_generic, only: eval
25  use dc_date_types, only: dc_datetime, &
27  use dc_message, only: messagenotify
28  implicit none
29  character(STRING):: result
30  type(dc_datetime), intent(in):: time
31 
32  integer :: year, mon, day, hour, min, csec_len
33  real(DP):: sec
34  character(TOKEN) :: zone, csec
35 continue
36 
37  call eval(time, &
38  & year=year, mon=mon, day=day, hour=hour, min=min, sec=sec, zone=zone)
39 
40  csec = tochar(sec)
41  if ( trim(csec) == '-0.' ) csec = '0.'
42  do while ( index('123456789.', csec(len_trim(csec):len_trim(csec)) ) == 0 )
43  if ( len_trim(csec) < 2 ) exit
44  csec = csec(1:len_trim(csec)-1)
45  end do
46  if (int(sec) > -1 .and. int(sec) < 10) csec = '0' // csec
47  csec_len = len(trim(adjustl(csec)))
48  if (csec(csec_len:csec_len) == '.') csec = csec(1:csec_len-1)
49 
50  result = cprintf('%04d-%02d-%02dT%02d:%02d:%c%c', &
51  & i=(/year, mon, day, hour, min/), &
52  & c1=trim(csec), c2=trim(zone))
53 
54 end function dcdatetimetochar
55 
56 
57 function dcdifftimetochar(diff) result(result)
58  !
59  ! dc_date_types#DC_DIFFTIME 型変数を文字型変数へ変換して返します.
60  ! 書式は以下のようになります.
61  !
62  ! +YYYY-MM-DDThh:mm:ss.s
63  ! -YYYY-MM-DDThh:mm:ss.s
64  !
65  ! YYYY は年, MM は月, DD は日, hh は時, mm は分, ss.s は秒を表します.
66  ! ただし, DD は 2 桁を超える場合があります.
67  ! (dc_date_types#DC_DIFFTIME は X ヶ月後, X 日前, などを表現するため
68  ! のデータ型なので, 日を月に繰り上げたり, 月を日に繰り下げることを
69  ! しません. また「年」の情報も持ちません. 1 年の日数や 1 月の日数は
70  ! dc_date_types#DC_DATETIME 側で決まります).
71  !
72  ! なお, DCDiffTimeCreate において, 単位を '1' とした場合は無時限時間と
73  ! 扱うため, 以下のような書式となります.
74  !
75  ! ss.s
76  !
77  use dc_types, only: string, token, dp
78  use dc_string, only: tochar, cprintf, stoa
79  use dc_date_generic, only: eval
80  use dc_date_types, only: dc_difftime
81  use dc_scaledsec, only: assignment(=)
82  implicit none
83  character(STRING):: result
84  type(dc_difftime), intent(in):: diff
85 
86  integer :: year, mon, day, hour, min, csec_len
87  real(DP):: sec
88  character(TOKEN) :: csec
89  character(1) :: pm
90 continue
91 
92  if ( .not. diff % nondim_flag ) then
93  call eval(diff, year=year, mon=mon, day=day, hour=hour, min=min, sec=sec)
94 
95  if ( year < 0 .or. mon < 0 .or. day < 0 .or. &
96  & hour < 0 .or. min < 0 .or. sec < 0 ) then
97  year=abs(year) ; mon=abs(mon) ; day=abs(day)
98  hour=abs(hour) ; min=abs(min) ; sec=abs(sec)
99  pm = '-'
100  else
101  pm = '+'
102  end if
103 
104  csec = tochar(sec)
105  if ( trim(csec) == '-0.' ) csec = '0.'
106  do while ( index('123456789.', csec(len_trim(csec):len_trim(csec)) ) == 0 )
107  if ( len_trim(csec) < 2 ) exit
108  csec = csec(1:len_trim(csec)-1)
109  end do
110  if (int(sec) > -1 .and. int(sec) < 10) csec = '0' // csec
111  csec_len = len(trim(adjustl(csec)))
112  if (csec(csec_len:csec_len) == '.') csec = csec(1:csec_len-1)
113 
114  result = cprintf('%c%04d-%02d-%02dT%02d:%02d:%c', &
115  & i=(/year, mon, day, hour, min/), &
116  & c1=pm, c2=trim(csec))
117  else
118  sec = diff % sec
119  result = tochar( sec )
120  end if
121 
122 end function dcdifftimetochar
123 
124 function dcdatetimetocharcal(time, upcase) result(result)
125  !
126  ! dc_date_types#DC_DATETIME 型変数の暦を文字型にして返します.
127  ! 現在サポートされている暦は以下の通りです.
128  ! 左が暦を示す整数型変数, 右が返る文字列です.
129  ! *upcase* に .true. を与えた場合には, 大文字となって返ります.
130  !
131  ! dc_date_types#CAL_CYCLIC :: cyclic
132  ! dc_date_types#CAL_NOLEAP :: noleap
133  ! dc_date_types#CAL_JULIAN :: julian
134  ! dc_date_types#CAL_GREGORIAN :: gregorian
135  !
136  !
137  use dc_types, only: token
138  use dc_present, only: present_and_true
139  use dc_date_types, only: dc_datetime, &
141  use dc_string, only: toupper
142  character(TOKEN) :: result
143  type(dc_datetime), intent(in):: time
144  logical, intent(in), optional:: upcase
145 continue
146  select case( time % caltype )
147  case(cal_cyclic)
148  result = 'cyclic'
149  case(cal_noleap)
150  result = 'noleap'
151  case(cal_julian)
152  result = 'julian'
153  case(cal_gregorian)
154  result = 'gregorian'
155  case default
156  result = 'none'
157  end select
158 
159  if ( present_and_true(upcase) ) then
160  call toupper(result) ! (inout)
161  end if
162 
163 end function dcdatetimetocharcal
integer, parameter, public cal_noleap
integer, parameter, public cal_gregorian
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition: dc_types.f90:109
logical function, public present_and_true(arg)
Definition: dc_present.f90:80
integer, parameter, public year_months
character(string) function dcdifftimetochar(diff)
integer, parameter, public cal_julian
integer, parameter, public cal_cyclic
integer, parameter, public dp
倍精度実数型変数
Definition: dc_types.f90:83
integer, parameter, public hour_seconds
文字型変数の操作.
Definition: dc_string.f90:24
種別型パラメタを提供します。
Definition: dc_types.f90:49
integer, parameter, public min_seconds
character(token) function dcdatetimetocharcal(time, upcase)
character(string) function dcdatetimetochar(time)
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118