jul2greg.h90 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. RECURSIVE SUBROUTINE jul2greg( ksec, kminut, khour, kday, kmonth, kyear, &
  2. & prelday, krefdate )
  3. !!-----------------------------------------------------------------------
  4. !!
  5. !! *** ROUTINE jul2greg ***
  6. !!
  7. !! ** Purpose : Take the relative time in days and re-express in terms of
  8. !! seconds, minutes, hours, days, month, year.
  9. !!
  10. !! ** Method : Reference date : 19500101
  11. !!
  12. !! ** Action :
  13. !!
  14. !! History
  15. !! ! 06-04 (A. Vidard) Original
  16. !! ! 06-05 (A. Vidard) Reformatted and refdate
  17. !! ! 06-10 (A. Weaver) Cleanup
  18. !! ! 2014-09 (D. Lea) Change to use FLOOR to deal with negative prelday
  19. !!-----------------------------------------------------------------------
  20. ! * Arguments
  21. INTEGER, INTENT(IN), OPTIONAL :: &
  22. & krefdate
  23. INTEGER, INTENT(OUT) :: &
  24. & ksec, &
  25. & kminut, &
  26. & khour, &
  27. & kday, &
  28. & kmonth, &
  29. & kyear
  30. REAL(KIND=dp), INTENT(IN) :: &
  31. & prelday
  32. !! * Local declarations
  33. INTEGER, PARAMETER :: &
  34. & jpgreg = 2299161, &
  35. & jporef = 2433283, &
  36. & jparef = 2415021
  37. INTEGER :: &
  38. & ijulian, &
  39. & ij1, &
  40. & ija, &
  41. & ijb, &
  42. & ijc, &
  43. & ijd, &
  44. & ije, &
  45. & isec, &
  46. & imin, &
  47. & ihou, &
  48. & iday, &
  49. & imon, &
  50. & iyea, &
  51. & iref
  52. REAL(KIND=wp) :: &
  53. & zday, &
  54. & zref
  55. CHARACTER(len=200) :: &
  56. & cerr
  57. ! Main computation
  58. IF ( PRESENT( krefdate ) ) THEN
  59. SELECT CASE ( krefdate )
  60. CASE( 0 )
  61. iref = jpgreg
  62. CASE( 19500101 )
  63. iref = jporef
  64. CASE( 19000101 )
  65. iref = jparef
  66. CASE DEFAULT
  67. WRITE(cerr,'(A,I8.8)')'jul2greg: Unknown krefdate:', krefdate
  68. CALL ctl_stop( cerr )
  69. END SELECT
  70. ELSE
  71. iref = jporef
  72. ENDIF
  73. zday = prelday
  74. ksec = FLOOR( 86400. * MOD( zday, 1. ) )
  75. IF ( ksec < 0. ) ksec = 86400. + ksec
  76. khour = ksec / 3600
  77. kminut = ( ksec - 3600 * khour ) / 60
  78. ksec = MOD( ksec , 60 )
  79. ijulian = iref + INT( zday )
  80. IF ( zday < 0. ) ijulian = ijulian - 1
  81. ! If input date after 10/15/1582 :
  82. IF ( ijulian >= jpgreg ) THEN
  83. ij1 = INT( ( DBLE( ijulian - 1867216 ) - 0.25 ) / 36524.25 )
  84. ija = ijulian + 1 + ij1 - INT( ( 0.25 * ij1 ) )
  85. ELSE
  86. ija = ijulian
  87. ENDIF
  88. ijb = ija + 1524
  89. ijc = INT( 6680. + ( DBLE ( ijb - 2439870 ) - 122.1 ) / 365.25 )
  90. ijd = 365 * ijc + INT( 0.25 * ijc )
  91. ije = INT( ( ijb - ijd ) / 30.6001 )
  92. kday = ijb - ijd - INT( 30.6001 * ije )
  93. kmonth = ije - 1
  94. IF ( kmonth > 12 ) kmonth = kmonth - 12
  95. kyear = ijc - 4715
  96. IF ( kmonth > 2 ) kyear = kyear - 1
  97. IF ( kyear <= 0 ) kyear = kyear - 1
  98. END SUBROUTINE jul2greg