dccaldatetochar.f90
Go to the documentation of this file.
1 != 日時の文字列への変換
2 != Convert date into a string
3 !
4 ! Authors:: Yasuhiro MORIKAWA
5 ! Version:: $Id: dccaldatetochar.f90,v 1.5 2009-10-18 02:34:48 morikawa Exp $
6 ! Tag Name:: $Name: $
7 ! Copyright:: Copyright (C) GFD Dennou Club, 2009-. All rights reserved.
8 ! License:: See COPYRIGHT[link:../../COPYRIGHT]
9 !
10 ! このファイルに記載される手続き群は dc_calendar モジュールから提供されます.
11 !
12 ! Procedures described in this file are provided from "dc_calendar" module.
13 !
14 
15 function dccaldatetochar1( year, month, day, hour, min, sec, zone ) &
16  & result(result)
17  !
18  ! 年月日時分秒を文字型変数 (gtool4 netCDF 規約「5.5 日時形式」に準拠)
19  ! へ変換して返します.
20  !
21  ! Convert year, month, day, hour, minute, second into a string
22  ! (conformed to gtool4 netCDF Convention
23  ! "5.5 Expression of date and time").
24  !
25  use dc_types, only: string, token, dp
26  use dc_string, only: tochar, cprintf, stoa, roundnum
27  use dc_message, only: messagenotify
28  implicit none
29  character(STRING):: result
30  ! 日時情報を表す文字列.
31  ! 表示形式については gtool4 netCDF 規約
32  ! 5.5 日時形式を参照のこと.
33  !
34  ! Strings that express date and time.
35  ! See gtool4 netCDF Convention
36  ! 5.5 Expression of date and time for details.
37  integer, intent(in):: year ! 年. Year.
38  integer, intent(in):: month ! 月. Month.
39  integer, intent(in):: day ! 日. Day.
40  integer, intent(in):: hour ! 時. Hour.
41  integer, intent(in):: min ! 分. Minute.
42  real(DP), intent(in):: sec ! 秒. Sec.
43  character(*), intent(in), optional:: zone ! UTC からの時差. Time-zone.
44  integer:: csec_len
45  character(TOKEN):: csec, zonew
46 continue
47 
48  if ( present(zone) ) then
49  zonew = zone
50  else
51  zonew = ''
52  end if
53 
54  csec = tochar(sec)
55  csec = roundnum( csec )
56  if ( trim(csec) == '-0.' ) csec = '0.'
57  do while ( index('123456789.', csec(len_trim(csec):len_trim(csec)) ) == 0 )
58  if ( len_trim(csec) < 2 ) exit
59  csec = csec(1:len_trim(csec)-1)
60  end do
61  if (int(sec) > -1 .and. int(sec) < 10) csec = '0' // csec
62  csec_len = len(trim(adjustl(csec)))
63  if (csec(csec_len:csec_len) == '.') csec = csec(1:csec_len-1)
64 
65  result = cprintf('%04d-%02d-%02dT%02d:%02d:%c%c', &
66  & i=(/year, month, day, hour, min/), &
67  & c1=trim(csec), c2=trim(zonew))
68 
69 end function dccaldatetochar1
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition: dc_types.f90:109
integer, parameter, public dp
倍精度実数型変数
Definition: dc_types.f90:83
文字型変数の操作.
Definition: dc_string.f90:24
種別型パラメタを提供します。
Definition: dc_types.f90:49
character(string) function dccaldatetochar1(year, month, day, hour, min, sec, zone)
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118