forked from DOI-USGS/volcano-ash3d-hourssince
-
Notifications
You must be signed in to change notification settings - Fork 1
/
yyyymmddhh_since_1900.f90
113 lines (98 loc) · 4.75 KB
/
yyyymmddhh_since_1900.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! This file is a component of the volcanic ash transport and dispersion model Ash3d,
! written at the U.S. Geological Survey by Hans F. Schwaiger ([email protected]),
! Larry G. Mastin ([email protected]), and Roger P. Denlinger ([email protected]).
!
! The model and its source code are products of the U.S. Federal Government and therefore
! bear no copyright. They may be copied, redistributed and freely incorporated
! into derivative products. However as a matter of scientific courtesy we ask that
! you credit the authors and cite published documentation of this model (below) when
! publishing or distributing derivative products.
!
! Schwaiger, H.F., Denlinger, R.P., and Mastin, L.G., 2012, Ash3d, a finite-
! volume, conservative numerical model for ash transport and tephra deposition,
! Journal of Geophysical Research, 117, B04204, doi:10.1029/2011JB008968.
!
! Although this program has been used by the USGS, no warranty, expressed or
! implied, is made by the USGS or the United States Government as to the accuracy
! and functioning of the program and related program material nor shall the fact of
! distribution constitute any such warranty, and no responsibility is assumed by
! the USGS in connection therewith.
!
! We make no guarantees, expressed or implied, as to the usefulness of the software
! and its documentation for any purpose. We assume no responsibility to provide
! technical support to users of this software.
!
! This program is just a wrapper for the function call to
! HS_hours_since_baseyear with base_year set to 1900
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
program yyyymmddhh_since_1900
! Stand-alone version of the function HS_yyyymmddhh_since with baseyear
! set to 1900.
! Returns a character string yyyymmddhh.hh giving the year, month, day, and hour, given
! the number of hours since January 1, 1900.
implicit none
character(len=18) :: string1
character(len=80) :: linebuffer
real(kind=8) :: HoursSince1900
integer :: iyear = 0
integer :: imonth = 0
integer :: iday = 0
integer :: ihour = 0
integer :: ifraction
integer :: idoy = 0
real(kind=8) :: fraction
real(kind=8) :: hour = 0.0_8
integer :: nargs
integer :: iostatus
character(len=120) :: iomessage = ""
integer :: byear = 1900
logical :: useLeaps = .true.
INTERFACE
subroutine HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
real(kind=8),intent(in) :: HoursSince
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
integer ,intent(out) :: iyear
integer ,intent(out) :: imonth
integer ,intent(out) :: iday
real(kind=8),intent(out) :: hours
integer ,intent(out) :: idoy
end subroutine
END INTERFACE
! Test read command line arguments
nargs = command_argument_count()
if(nargs.ne.1) then
write(6,*) 'error in input to yyyymmddhh_since_1900'
write(6,*) 'input should be a single real number.'
write(6,*) 'program stopped'
stop
else
call get_command_argument(number=1, value=linebuffer, status=iostatus)
read(linebuffer,*,iostat=iostatus,iomsg=iomessage) HoursSince1900
if(iostatus.ne.0)then
write(6,*)'HS ERROR: Error reading value from command-line argument'
write(6,*)' Expecting to read: HoursSince1900 (real*8)'
write(6,*)' From the following input line : '
write(6,*)linebuffer
write(6,*)'HS System Message: '
write(6,*)iomessage
stop 1
endif
endif
call HS_Get_YMDH(HoursSince1900,byear,useLeaps,iyear,imonth,iday,hour,idoy)
ihour = int(hour)
fraction = hour-real(ihour,kind=8)
if(fraction.gt.1.0_8)then
! if the nearest integer of ifraction is actually the next
! hour, adjust ifraction and ihour accordingly
ihour = ihour + int(fraction)
fraction = fraction-int(fraction)
endif
ifraction = nint(fraction*60.0_8) ! turn hour fraction into minutes
write(string1,2) iyear, imonth, iday, ihour, ifraction
2 format(i4,'.',i2.2,'.',i2.2,'.',2i2.2,'UTC')
write(6,*) string1
end program yyyymmddhh_since_1900