forked from DOI-USGS/volcano-ash3d-hourssince
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HoursSince.f90
876 lines (720 loc) · 31.7 KB
/
HoursSince.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! 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 file contains several functions and a subroutine that calculate the
! difference in hours of calendar dates compared to a reference (or base)
! year. The consideration of leap years can be set using the logical parameter
! useLeaps. If leap years are used, the proleptic Gregorian calendar is used.
! Given an 'HoursSince' value, several functions are given to calculate the
! corresponding calendar information as well as a few functions to format text
! strings.
!
! contains:
! function HS_IsLeapYear(iyear)
! function HS_hours_since_baseyear(iyear,imonth,iday,hours,byear,useLeaps)
! subroutine HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
! function HS_xmltime(HoursSince,byear,useLeaps)
! function HS_yyyymmddhhmm_since(HoursSince,byear,useLeaps)
! function HS_yyyymmddhh_since(HoursSince,byear,useLeaps)
! function HS_DayOfYear(HoursSince,byear,useLeaps)
! function HS_HourOfDay(HoursSince,byear,useLeaps)
! function HS_YearOfEvent(HoursSince,byear,useLeaps)
! function HS_MonthOfEvent(HoursSince,byear,useLeaps)
! function HS_DayOfEvent(HoursSince,byear,useLeaps)
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!##############################################################################
!
! HS_IsLeapYear
!
! This function takes and integer year as input and returns a logical
! value (.true. or .false.) if that year is a leap year
!
!##############################################################################
function HS_IsLeapYear(iyear)
implicit none
integer,intent(in) :: iyear
logical :: HS_IsLeapYear
! Note, this uses the proleptic Gregorian calendar which includes year 0
! and considers y=0 to be a leap year.
if ((mod(iyear,4).eq.0).and.(mod(iyear,100).ne.0).or.(mod(iyear,400).eq.0)) then
HS_IsLeapYear = .true.
else
HS_IsLeapYear = .false.
endif
return
end function HS_IsLeapYear
!##############################################################################
!
! HS_hours_since_baseyear
!
! function that calculates the number of hours since Jan 1, of a base year,
! given the input (year, month, day, and hour (UT))
!
!##############################################################################
function HS_hours_since_baseyear(iyear,imonth,iday,hours,byear,useLeaps)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
integer ,intent(in) :: iyear
integer ,intent(in) :: imonth
integer ,intent(in) :: iday
real(kind=8),intent(in) :: hours
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
real(kind=8) :: HS_hours_since_baseyear
!cumulative hours in each month
integer :: i
integer :: ileaphours
integer, dimension(0:12) :: monthours = (/0,744,1416,2160,2880,3624,4344,5088,5832,6552,7296,8016,8760/)
logical :: IsLeap
INTERFACE
logical function HS_IsLeapYear(iyear)
integer,intent(in) :: iyear
end function HS_IsLeapYear
END INTERFACE
! First check input values
if (iyear.lt.byear) then
write(error_unit,*)"HS ERROR: HS_hours_since_baseyear"
write(error_unit,*)"HS ERROR: year must be greater or equal to base year."
write(error_unit,*)" Base Year = ",byear
write(error_unit,*)" Input Year = ",iyear
stop 1
endif
if (imonth.lt.1.or.imonth.gt.12) then
write(error_unit,*)"HS ERROR: HS_hours_since_baseyear"
write(error_unit,*)"HS ERROR: month must be between 1 and 12."
write(error_unit,*)" Input Month = ",imonth
stop 1
endif
if (iday.lt.1) then
write(error_unit,*)"HS ERROR: HS_hours_since_baseyear"
write(error_unit,*)"HS ERROR: day must be greater than 0."
write(error_unit,*)" Input Day = ",iday
stop 1
endif
if ((imonth.eq.1.or.&
imonth.eq.3.or.&
imonth.eq.5.or.&
imonth.eq.7.or.&
imonth.eq.8.or.&
imonth.eq.10.or.&
imonth.eq.12).and.iday.gt.31)then
write(error_unit,*)"HS ERROR: HS_hours_since_baseyear"
write(error_unit,*)"HS ERROR: day must be <= 31 for this month."
write(error_unit,*)" Input Month = ",imonth
write(error_unit,*)" Input Day = ",iday
stop 1
endif
if ((imonth.eq.4.or.&
imonth.eq.6.or.&
imonth.eq.9.or.&
imonth.eq.11).and.iday.gt.30)then
write(error_unit,*)"HS ERROR: HS_hours_since_baseyear"
write(error_unit,*)"HS ERROR: day must be <= 30 for this month."
write(error_unit,*)" Input Month = ",imonth
write(error_unit,*)" Input Day = ",iday
stop 1
endif
if ((imonth.eq.2).and.iday.gt.29)then
write(error_unit,*)"HS ERROR: HS_hours_since_baseyear"
write(error_unit,*)"HS ERROR: day must be <= 29 for this month."
write(error_unit,*)" Input Month = ",imonth
write(error_unit,*)" Input Day = ",iday
stop 1
endif
if (useLeaps) then
! First find out if given year is a leap year
IsLeap = HS_IsLeapYear(iyear)
! Now find out how many leap days (actually hours) are between the given
! year and the base year
ileaphours = 0
do i = byear,iyear
if (HS_IsLeapYear(i)) ileaphours = ileaphours + 24
enddo
! If this is a leap year, but still in Jan or Feb, remove the
! extra 24 hours credited above
if (IsLeap.and.imonth.lt.3) ileaphours = ileaphours - 24
else
ileaphours = 0
endif
HS_hours_since_baseyear = real((iyear-byear)*monthours(12) + & ! number of hours per normal year
monthours(imonth-1) + & ! hours in year at beginning of month
ileaphours + & ! total leap hours since base year
24*(iday-1),kind=8) + & ! hours in day
hours ! hour of the day
return
end function HS_hours_since_baseyear
!##############################################################################
!
! HS_Get_YMDH
!
! subroutine that calculates the year, month, day and hour, given the
! number of hours since Jan 1, of a base year.
! This is essentially the inverse of HS_hours_since_baseyear
!
!##############################################################################
subroutine HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
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
integer, dimension(0:12) :: monthours = (/0,744,1416,2160,2880,3624,4344,5088,5832,6552,7296,8016,8760/)
integer, dimension(0:12) :: leapmonthours = (/0,744,1440,2184,2904,3648,4368,5112,5856,6576,7320,8040,8784/)
integer :: HoursIn_Century
integer :: HoursIn_This_Century
integer :: HoursIn_Year
integer :: HoursIn_This_Year
integer :: HoursIn_Leap
integer :: ileaphours
integer :: byear_correction
integer :: i
integer :: icent
integer :: BaseYear_Y0_OffsetHours_int
real(kind=8) :: rem_hours
real(kind=8) :: InYear_Y0_OffsettHours
logical :: IsLeap
real(kind=8) :: month_start_hours,month_end_hours
INTERFACE
logical function HS_IsLeapYear(iyear)
integer,intent(in) :: iyear
end function HS_IsLeapYear
END INTERFACE
! Error checking the first argument
! Note: this must be real*8
if (HoursSince.lt.0.0_8.or.HoursSince.gt.1.0e9_8) then
write(error_unit,*)"HS ERROR: HoursSince variable is either negative or larger"
write(error_unit,*)" than ~100,000 years."
write(error_unit,*)" Double-check that it was passed as real*8"
stop 1
endif
! div-by-four ARE leapyears -> +1
! div-by-100 NOT leapyears -> -1
! div-by-400 ARE leapyears -> +1
! So, every 400 years, the cycle repeats with 97 extra leap days
! Otherwise, normal centuries have 24 leap days
! And four-year packages have 1 leap day
if(useLeaps)then
HoursIn_Century = 24*(365 * 100 + 24)
HoursIn_Year = 24*(365)
HoursIn_Leap = 24
else
HoursIn_Century = 24*(365 * 100)
HoursIn_Year = 24*(365)
HoursIn_Leap = 0
endif
! Get the number of hours between base year and year 0
! First leap hours
ileaphours = 0
byear_correction = 0
if(useLeaps)then
if(byear.ge.0)then
! clock starts at 0 so include 0 in the positive accounting
do i = 0,byear
if (HS_IsLeapYear(i)) ileaphours = ileaphours + 24
enddo
if (HS_IsLeapYear(byear))then
! If the base year is itself a leapyear, remove the extra 24 hours
! since we will always be using Jan 1 of the base year
byear_correction = -24
endif
else
! For negative years, count from year -1 to byear
do i = byear,-1
if (HS_IsLeapYear(i)) ileaphours = ileaphours + 24
enddo
if (HS_IsLeapYear(byear))then
! If the base year is itself a leapyear, remove the extra 24 hours
! since we will always be using Jan 1 of the base year
byear_correction = -24
endif
endif
else
byear_correction = 0
endif
! Now total hours
BaseYear_Y0_OffsetHours_int = abs(byear)*HoursIn_Year + &
ileaphours + &
byear_correction
BaseYear_Y0_OffsetHours_int = sign(BaseYear_Y0_OffsetHours_int,byear)
InYear_Y0_OffsettHours = real(BaseYear_Y0_OffsetHours_int,kind=8) + &
HoursSince
rem_hours = InYear_Y0_OffsettHours
if(InYear_Y0_OffsettHours.ge.0.0)then
! byear and HoursSince result in an iyear .ge. 0
icent = 0
HoursIn_This_Century = HoursIn_Century + HoursIn_Leap
HoursIn_This_Year = HoursIn_Year + HoursIn_Leap
! Find which century we are in
do while (rem_hours.ge.HoursIn_This_Century)
! Account for this century
icent = icent + 1
rem_hours = rem_hours - HoursIn_This_Century
! Figure out the number of hours in the next century to check
if (mod(icent,4).eq.0) then
HoursIn_This_Century = HoursIn_Century + HoursIn_Leap
HoursIn_This_Year = HoursIn_Year + HoursIn_Leap
else
HoursIn_This_Century = HoursIn_Century
HoursIn_This_Year = HoursIn_Year
endif
enddo
! Find which year we are in
iyear = 0
do while (rem_hours.ge.HoursIn_This_Year)
! Account for this year
iyear = iyear + 1
rem_hours = rem_hours - HoursIn_This_Year
! Figure out the number of hours in the next year to check
if (mod(iyear,4).eq.0) then
HoursIn_This_Year = HoursIn_Year + HoursIn_Leap
else
HoursIn_This_Year = HoursIn_Year
endif
enddo
iyear = iyear + 100*icent
else
! iyear will be negative
stop 1
endif
! Check if iyear is a leap year
if(useLeaps)then
if (HS_IsLeapYear(iyear))then
IsLeap = .true.
else
IsLeap = .false.
endif
else
IsLeap = .false.
endif
! Calculate the day-of-year
idoy = int(rem_hours/24.0_8)+1
! Get the month we are in
do imonth=1,12
if(IsLeap)then
month_start_hours = real(leapmonthours(imonth-1),kind=8)
month_end_hours = real(leapmonthours(imonth),kind=8)
else
month_start_hours = real(monthours(imonth-1),kind=8)
month_end_hours = real(monthours(imonth),kind=8)
endif
if(rem_hours.ge.month_start_hours.and.rem_hours.lt.month_end_hours)then
rem_hours = rem_hours - month_start_hours
exit
endif
enddo
! And the day-of month
iday = int(rem_hours/24.0_8)+1
! Hours of day
hours = rem_hours - real((iday-1)*24,kind=8)
return
end subroutine HS_Get_YMDH
!##############################################################################
!
! HS_xmltime
!
! Returns the xml time stamp 'yyyy-mm-ddThh:mm:ssZ',
! giving the year, month, day, hour, minutes, and seconds in
! Universal Time, given the number of hours since January 1, baseyear.
!
!##############################################################################
function HS_xmltime(HoursSince,byear,useLeaps)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
real(kind=8) ,intent(in) :: HoursSince
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
character (len=20) :: HS_xmltime
character (len=20) :: string1
integer :: iyear, imonth, iday, idoy
real(kind=8) :: hours
integer :: ihours, iminutes, iseconds
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
! Error checking the first argument
! Note: this must be real*8
if(HoursSince.lt.0.0_8.or.HoursSince.gt.1.0e9_8)then
write(error_unit,*)"HS ERROR: HoursSince variable is either negative or larger"
write(error_unit,*)" than ~100,000 years."
write(error_unit,*)" Double-check that it was passed as real*8"
stop 1
endif
call HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
ihours = int(hours)
iminutes = int(60.0_8*(hours-real(ihours,kind=8)))
iseconds = int((60.0_8*(hours-real(ihours,kind=8)))-iminutes)*60
! build the string
write(string1,1) iyear, imonth, iday, ihours, iminutes, iseconds
1 format(i4,'-',i2.2,'-',i2.2,'T',i2.2,':',i2.2,':',i2.2,'Z')
HS_xmltime = string1
return
end function HS_xmltime
!##############################################################################
!
! HS_yyyymmddhhmm_since
!
! Returns a character string yyyymmddhh.hh giving the year, month, day, and
! hour, given the number of hours since January 1, of baseyear.
!
!##############################################################################
function HS_yyyymmddhhmm_since(HoursSince,byear,useLeaps)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
real(kind=8) ,intent(in) :: HoursSince
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
character (len=13) :: HS_yyyymmddhhmm_since
character (len=1) :: string0 ! a filler character
character (len=13) :: string1
integer :: iyear, imonth, iday, idoy
real(kind=8) :: hours
integer :: ihours, iminutes
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
! Error checking the first argument
! Note: this must be real*8
if(HoursSince.lt.0.0_8.or.HoursSince.gt.1.0e9_8)then
write(error_unit,*)"HS ERROR: HoursSince variable is either negative or larger"
write(error_unit,*)" than ~100,000 years."
write(error_unit,*)" Double-check that it was passed as real*8"
stop 1
endif
string0 = ':'
call HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
ihours = int(hours)
iminutes = int(60.0_8*(hours-real(ihours,kind=8)))
! build the string
write(string1,'(i4,3i2.2,a,i2.2)') iyear, imonth, iday, ihours, string0, iminutes
HS_yyyymmddhhmm_since = string1
return
end function HS_yyyymmddhhmm_since
!##############################################################################
!
! HS_yyyymmddhh_since
!
! Returns a character string yyyymmddhh.hh giving the year, month, day, and
! hour, given the number of hours since January 1, of baseyear.
!
!##############################################################################
function HS_yyyymmddhh_since(HoursSince,byear,useLeaps)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
real(kind=8),intent(in) :: HoursSince
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
character (len=13) :: HS_yyyymmddhh_since
integer :: iyear, imonth, iday, idoy
real(kind=8) :: hours
character (len=13) :: string1
character (len=1) :: string0 ! a filler character
integer :: ihours, ifraction
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
! Error checking the first argument
! Note: this must be real*8
if(HoursSince.lt.0.0_8.or.HoursSince.gt.1.0e9_8)then
write(error_unit,*)"HS ERROR: HoursSince variable is either negative or larger"
write(error_unit,*)" than ~100,000 years."
write(error_unit,*)" Double-check that it was passed as real*8"
stop 1
endif
string0 = '.'
call HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
ihours = int(hours)
ifraction = nint(100.0_8*(hours-real(ihours,kind=8)))
if(ifraction.eq.100)then
! if the nearest integer of ifraction is actually the next
! hour, adjust ifraction and ihour accordingly
ifraction = 0
ihours = ihours + 1
endif
! build the string
write(string1,'(i4,3i2.2,a,i2.2)') iyear, imonth, iday, ihours, string0, ifraction
HS_yyyymmddhh_since = string1
return
end function HS_yyyymmddhh_since
!##############################################################################
!
! HS_DayOfYear
!
! function that calculates the integer day of year given the
! HoursSince, base year and useLeaps
! Check against calculator on
! http://www.7is7.com/otto/datediff.html
!
!##############################################################################
function HS_DayOfYear(HoursSince,byear,useLeaps)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
real(kind=8),intent(in) :: HoursSince
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
integer :: HS_DayOfYear
integer :: iyear, imonth, iday, idoy
real(kind=8) :: hours
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
! Error checking the first argument
! Note: this must be real*8
if(HoursSince.lt.0.0_8.or.HoursSince.gt.1.0e9_8)then
write(error_unit,*)"HS ERROR: HoursSince variable is either negative or larger"
write(error_unit,*)" than ~100,000 years."
write(error_unit,*)" Double-check that it was passed as real*8"
stop 1
endif
call HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
HS_DayOfYear = idoy
return
end function HS_DayOfYear
!##############################################################################
!
! HS_HourOfDay
!
! function that calculates the real hour of day given the
! HoursSince
!
!##############################################################################
function HS_HourOfDay(HoursSince,byear,useLeaps)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
real(kind=8),intent(in) :: HoursSince
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
real(kind=8) :: HS_HourOfDay
integer :: iyear, imonth, iday, idoy
real(kind=8) :: hours
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
! Error checking the first argument
! Note: this must be real*8
if(HoursSince.lt.0.0_8.or.HoursSince.gt.1.0e9_8)then
write(error_unit,*)"HS ERROR: HoursSince variable is either negative or larger"
write(error_unit,*)" than ~100,000 years."
write(error_unit,*)" Double-check that it was passed as real*8"
stop 1
endif
call HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
HS_HourOfDay = hours
return
end function HS_HourOfDay
!##############################################################################
!
! HS_YearOfEvent
!
! function that calculates the integer year given the
! HoursSince
!
!##############################################################################
function HS_YearOfEvent(HoursSince,byear,useLeaps)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
real(kind=8),intent(in) :: HoursSince
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
integer :: HS_YearOfEvent
integer :: iyear, imonth, iday, idoy
real(kind=8) :: hours
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
! Error checking the first argument
! Note: this must be real*8
if(HoursSince.lt.0.0_8.or.HoursSince.gt.1.0e9_8)then
write(error_unit,*)"HS ERROR: HoursSince variable is either negative or larger"
write(error_unit,*)" than ~100,000 years."
write(error_unit,*)" Double-check that it was passed as real*8"
stop 1
endif
call HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
HS_YearOfEvent = iyear
return
end function HS_YearOfEvent
!##############################################################################
!
! HS_MonthOfEvent
!
! function that calculates the integer month of year given the
! HoursSince
!
!##############################################################################
function HS_MonthOfEvent(HoursSince,byear,useLeaps)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
real(kind=8),intent(in) :: HoursSince
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
integer :: HS_MonthOfEvent
integer :: iyear, imonth, iday, idoy
real(kind=8) :: hours
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
! Error checking the first argument
! Note: this must be real*8
if(HoursSince.lt.0.0_8.or.HoursSince.gt.1.0e9_8)then
write(error_unit,*)"HS ERROR: HoursSince variable is either negative or larger"
write(error_unit,*)" than ~100,000 years."
write(error_unit,*)" Double-check that it was passed as real*8"
stop 1
endif
call HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
HS_MonthOfEvent = imonth
return
end function HS_MonthOfEvent
!##############################################################################
!
! HS_DayOfEvent
!
! function that calculates the integer day of month given the
! HoursSince
!
!##############################################################################
function HS_DayOfEvent(HoursSince,byear,useLeaps)
! This module requires Fortran 2003 or later
use iso_fortran_env, only : &
error_unit
implicit none
real(kind=8),intent(in) :: HoursSince
integer ,intent(in) :: byear
logical ,intent(in) :: useLeaps
integer :: HS_DayOfEvent
integer :: iyear, imonth, iday, idoy
real(kind=8) :: hours
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
! Error checking the first argument
! Note: this must be real*8
if(HoursSince.lt.0.0_8.or.HoursSince.gt.1.0e9_8)then
write(error_unit,*)"HS ERROR: HoursSince variable is either negative or larger"
write(error_unit,*)" than ~100,000 years."
write(error_unit,*)" Double-check that it was passed as real*8"
stop 1
endif
call HS_Get_YMDH(HoursSince,byear,useLeaps,iyear,imonth,iday,hours,idoy)
HS_DayOfEvent = iday
return
end function HS_DayOfEvent