Class | dc_date |
In: |
src/dc_date.f90
|
diff : | type(DC_DIFFTIME), intent(in) |
year : | integer(INTK), intent(out), optional |
mon : | integer(INTK), intent(out), optional |
day : | integer(INTK), intent(out), optional |
hour : | integer(INTK), intent(out), optional |
min : | integer(INTK), intent(out), optional |
sec : | integer(INTK), intent(out), optional |
subroutine DCDateDiffEval(diff, year, mon, day, hour, min, sec) type(DC_DIFFTIME), intent(in):: diff integer(INTK), intent(out), optional:: year, mon, day, hour, min, sec if (present(year)) then year = diff%mon / 12 endif if (present(mon)) then mon = mod(diff%mon, 12) endif if (present(day)) then day = diff%day endif if (present(hour)) then hour = int(diff%sec / 3600.0) endif if (present(min)) then min = int(mod(diff%sec, 3600.0_DP) / 60.0) endif if (present(sec)) then sec = mod(diff%sec, 60.0_DP) endif end subroutine
result : | character(STRING) |
fmt : | character(*), intent(in), optional |
将来的には文字列引数 fmt に文字列を与えることで書式の変更を 可能にしたい. 現在は何を代入しても上記の書式で出力される.
function DCTimeNow(fmt) result(result) implicit none character(*), intent(in), optional :: fmt character(STRING) :: result integer(INTK) :: values(1:8) character(5) :: zone character(6) :: zone_fmt character(4) :: year character(2) :: month, day, hour, min, sec continue call date_and_time(zone=zone, values=values) zone_fmt = zone(1:3) // ":" // zone(4:5) write(year, "(i4.4)") values(1) write(month, "(i2.2)") values(2) write(day, "(i2.2)") values(3) write(hour, "(i2.2)") values(5) write(min, "(i2.2)") values(6) write(sec, "(i2.2)") values(7) if (present_and_not_empty(fmt)) then result = CPrintf('%cT%c%c', c1= year // '-' // month // '-' // day, c2= hour // ':' // min // ':' // sec, c3= trim(zone_fmt) ) else result = CPrintf('%cT%c%c', c1= year // '-' // month // '-' // day, c2= hour // ':' // min // ':' // sec, c3= trim(zone_fmt) ) end if end function DCTimeNow
result : | type(DC_DIFFTIME) |
diff1 : | type(DC_DIFFTIME), intent(in) |
diff2 : | type(DC_DIFFTIME), intent(in) |
月差と日時の混在する除算は近似的結果になるおそれがある
type(DC_DIFFTIME) function dcdate_mod_ff(diff1, diff2) result(result) type(DC_DIFFTIME), intent(in):: diff1, diff2 real(DP):: sec1, sec2 if (diff1%day == 0 .and. diff2%day == 0 .and. diff1%sec == 0.0 .and. diff2%sec == 0.0) then result%mon = mod(diff1%mon, diff2%mon) result%day = 0 result%sec = 0.0 else if (diff1%sec == 0.0 .and. diff2%sec == 0.0) then result%mon = 0 result%day = mod((CYCLIC_MDAYS * diff1%mon + diff1%day), (CYCLIC_MDAYS * diff2%mon + diff2%day)) result%sec = 0.0 else sec1 = DAY_SECONDS * (CYCLIC_MDAYS * diff1%mon + diff1%day) + diff1%sec sec2 = DAY_SECONDS * (CYCLIC_MDAYS * diff2%mon + diff2%day) + diff2%sec result%sec = mod(sec1, sec2) result%day = 0.0 result%mon = 0.0 call dcdate_normalize(result%day, result%sec) endif end function