-
Notifications
You must be signed in to change notification settings - Fork 1
/
DATES.FOR
663 lines (534 loc) · 19.3 KB
/
DATES.FOR
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
C=======================================================================
C DATES, File, Nigel Pickering, G. Hoogenboom, P.W. Wilkens and B. Baer
C General functions related to time and date calculations
C-----------------------------------------------------------------------
C REVISION HISTORY
C 09/13/1991 NBP Developed
C 01/30/1998 GH Modified ENDYR function for leap year
C 01/30/1998 GH Added NAILUJ routine
C 02/02/1998 GH Integer in YR_DOY
C 07/01/2000 GH Added INCDAT
C 06/09/2002 GH Modified for Y2K
C 11/29/2004 CHP Added ETAD_NAILUJ for Ponding routine -- provides
C integer month given date.
! 10/11/2005 CHP Fix problem in Y2K_DOYW, sequenced runs spanning Y2K
! 11/16/2007 CHP Added leap year function
C=======================================================================
C=======================================================================
C DOYC, Integer function, N.B. Pickering, 09/13/91
C Calculates "TRUE" julian day, assuming that all leap years are
C divisible by 4. This is incorrect for certain years.
C-----------------------------------------------------------------------
C 09/13/1991 NBP Devfeloped
C 11/24/2002 GH Modified for Y2K
C-----------------------------------------------------------------------
C Input : YR,DOY
C Output: DOC
C Local : NLEAP
C=======================================================================
INTEGER FUNCTION DOYC(YR,DOY)
IMPLICIT NONE
INTEGER DOY,NLEAP,YR
NLEAP = INT((YR-1)/4)
DOYC = NLEAP*366 + (YR-NLEAP-1)*365 + DOY
END FUNCTION DOYC
C=======================================================================
C YR_DOY, Subroutine, N.B. Pickering, 09/13/91
C Converts YRDOY to YR and DOY.
C-----------------------------------------------------------------------
C Input : YRDOY
C Output: YR,DOY
C=======================================================================
SUBROUTINE YR_DOY(YRDOY,YR,DOY)
IMPLICIT NONE
INTEGER DOY,YR,YRDOY
YR = INT(YRDOY / 1000)
DOY = YRDOY - YR * 1000
END SUBROUTINE YR_DOY
C=======================================================================
C Y2K_DOY, Subroutine, Gerrit Hoogenboom 6/7/2002
C Converts YRDOY to Y2K
C-----------------------------------------------------------------------
C Input : YRDOY
C Output: YRDOY
C=======================================================================
SUBROUTINE Y2K_DOY(YRDOY)
IMPLICIT NONE
INTEGER DOY,YR,YRDOY
IF (YRDOY .LE. 99365) THEN
YR = INT(YRDOY / 1000)
DOY = YRDOY - YR * 1000
IF (YRDOY .GT. 0) THEN
! IF (YR .LE. 10) THEN
! CHP 09/11/2009 - change "cross-over" year from 2010 to 2015
IF (YR .LE. 15) THEN
YRDOY = (2000 + YR) * 1000 + DOY
ELSE
YRDOY = (1900 + YR) * 1000 + DOY
ENDIF
ENDIF
ENDIF
END SUBROUTINE Y2K_DOY
C=======================================================================
C Y2K_DOYW, Subroutine, C. Porter, 02/05/2004
C Converts YRDOYW to Y2K for weather files
C If this is a sequenced run, then days are forced to be sequential
C when going from year 2010 to 2011,
C and from 1999 to 2000.
! 09/11/2009 CHP changed "cross-over" year from 2010 to 2015
C-----------------------------------------------------------------------
C Input : RNMODE, YRDOYWY, YRDOYW
C Output: YRDOYW
C=======================================================================
SUBROUTINE Y2K_DOYW(MULTI, YRDOYWY, YRDOYW, CENTURY)
USE ModuleDefs
IMPLICIT NONE
! CHARACTER*1 RNMODE
INTEGER MULTI !, RUN
INTEGER CENTURY, DOY, YEAR, YR, YRDOYW
INTEGER CENTURYY, DOYY, YEARY, YRY, YRDOYWY !, YRINC
DATA YRY /0/
IF (MULTI .LE. 1) YRY = 0
IF (YRDOYW .LE. 99365) THEN
YR = INT(YRDOYW / 1000)
DOY = YRDOYW - YR * 1000
IF (YRDOYW .GT. 0) THEN
!! IF (YR .LE. 10 .OR. YRY .GE. 2000) THEN
! IF (YR .LE. 15 .OR. YRY .GE. 2000) THEN
! CENTURY = 20
! ELSE
! CENTURY = 19
! ENDIF
YEAR = CENTURY * 100 + YR
YRDOYW = YEAR * 1000 + DOY
ENDIF
ELSE
CALL YR_DOY(YRDOYW, YEAR, DOY)
CENTURY = INT(YEAR / 100)
ENDIF
CALL YR_DOY(YRDOYWY, YEARY, DOYY)
CENTURYY = INT(YEARY / 100)
!-----------------------------------
!! RNMODE = Q CHECK RUN
!! RNMODE = N CHECK MULTI
!!CHP 10/11/2005 Fix problem with sequenced runs spanning Y2K
!!CHP 10/9/06 IF (INDEX('QFNS',RNMODE) .GT. 0 .OR. MULTI .GT. 1) THEN
! IF ((INDEX('QF',RNMODE) > 0 .AND. RUN > 1) .OR.
!! & (INDEX('N', RNMODE) > 0 .AND. MULTI > 1)) THEN
! & (MULTI > 1)) THEN
!
! YRINC = YEAR - YEARY
!! IF (YRINC .EQ. 100 .OR. YRINC .EQ. 101) THEN
! IF (YRINC .GT. 1) THEN
! YEAR = YEAR - 100
! YRDOYW = YEAR * 1000 + DOY
! ELSEIF (YRINC .LT. 0) THEN
! YEAR = YEAR + 100
! YRDOYW = YEAR * 1000 + DOY
! ENDIF
! ENDIF
! 10/10/2006 CHP
! Fixes problem with model going from 2010 to 1911 during simulation
IF (CENTURYY > CENTURY) THEN
CENTURY = CENTURYY
YEAR = CENTURY * 100 + YR
YRDOYW = YEAR * 1000 + DOY
! Fixes problem with crossing centuries
ELSEIF (CENTURYY == CENTURY .AND.
& YEAR < YEARY .AND. MOD(YEARY,100) == 99) THEN
CENTURY = CENTURY + 1
YEAR = CENTURY * 100 + YR
YRDOYW = YEAR * 1000 + DOY
ENDIF
RETURN
END SUBROUTINE Y2K_DOYW
C=======================================================================
C YDOY, Integer Function, N.B. Pickering, 09/13/91
C Converts YR and DOY to YRDOY.
C-----------------------------------------------------------------------
C Input : YR,DOY
C Output: YRDOY
C=======================================================================
INTEGER FUNCTION YDOY(YR,DOY)
IMPLICIT NONE
INTEGER DOY,YR
YDOY = YR * 1000 + DOY
END FUNCTION YDOY
C=======================================================================
C TIMDIF, Integer function, N.B. Pickering, 09/13/91
C Calculates the time difference between two YRDOY dates (days).
C-----------------------------------------------------------------------
C Input : YRDOY1,YRDOY2
C Output: DAYDIF
C=======================================================================
INTEGER FUNCTION TIMDIF(YRDOY1,YRDOY2)
IMPLICIT NONE
INTEGER DOYC,DOY1,DOY2,YR1,YR2,YRDOY1,YRDOY2
C Simple time difference of two days in the same year attempted first.
TIMDIF = YRDOY2 - YRDOY1
C If time difference involves a year change, use DOC calculations.
IF (TIMDIF .GT. 365 .OR. TIMDIF .LT. -365) THEN
CALL YR_DOY(YRDOY1,YR1,DOY1)
CALL YR_DOY(YRDOY2,YR2,DOY2)
TIMDIF = DOYC(YR2,DOY2) - DOYC(YR1,DOY1)
ENDIF
END FUNCTION TIMDIF
C=======================================================================
C MTHEND, Integer Function, N.B. Pickering, 06/05/92
C Calculates day-of-year that is end of month.
C-----------------------------------------------------------------------
C Input : MTH,YR
C Output: MTHEND
C Local : MEND,LEAPYR
C=======================================================================
INTEGER FUNCTION MTHEND(YR,MTH)
IMPLICIT NONE
INTEGER MTH,MEND(12),YR
LOGICAL LEAP
DATA MEND/31,59,90,120,151,181,212,243,273,304,334,365/
IF (LEAP(YR) .AND. MTH.GE.2) THEN
MTHEND = MEND(MTH) + 1
ELSE
MTHEND = MEND(MTH)
ENDIF
END FUNCTION MTHEND
C=======================================================================
C MTHMID, Integer Function, N.B. Pickering, 06/05/92
C Calculates day-of-year that is midpoint of month.
C-----------------------------------------------------------------------
C Input : MTH,YR
C Output: MTHMID
C Local : MAXDOY,MBEG,MEND,LEAPYR,MTHBEG,MTHEND
C=======================================================================
INTEGER FUNCTION MTHMID(YR,MTH)
IMPLICIT NONE
INTEGER MTH,YR
LOGICAL LEAP
INTEGER MIDPT(12)
DATA MIDPT/16,46,75,106,136,167,197,228,259,289,320,350/
IF (LEAP(YR) .AND. MTH.GE.2) THEN
MTHMID = MIDPT(MTH) + 1
ELSE
MTHMID = MIDPT(MTH)
ENDIF
END FUNCTION MTHMID
C=======================================================================
C INCYD, Integer Function, N.B. Pickering, 06/05/92
C Increases/decreases YRDOY based on INC (ABS(INC)<=365).
C-----------------------------------------------------------------------
C Input : YRDOY
C Output: INCYD
C Local : YDEND,YR,DOY
C=======================================================================
INTEGER FUNCTION INCYD(YRDOY,INC)
IMPLICIT NONE
INTEGER ENDYR,INC,NDYR,YRDOY,YR,DOY,YDOY
CALL YR_DOY(YRDOY,YR,DOY)
NDYR = ENDYR(YR)
DOY = DOY + INC
IF (DOY .GT. NDYR) THEN
YR = YR + 1
DOY = DOY - NDYR
ELSE IF (DOY .LE. 0) THEN
YR = YR - 1
NDYR = ENDYR(YR)
DOY = NDYR + DOY
ENDIF
INCYD = YDOY(YR,DOY)
END FUNCTION INCYD
C=======================================================================
C INCDAT, Integer Function,J.Hansen
C Similar to INCYD without the restriction that DELTA <= 365.
C-----------------------------------------------------------------------
C Input : YRDOY(ADATE)
C Output: INCDAT
C Local : NDYR,AYR,ADOY,DELTA,ENDYR,YDOY
C-----------------------------------------------------------------------
INTEGER FUNCTION INCDAT(ADATE, DELTA)
IMPLICIT NONE
INTEGER NDYR, AYR, ADOY, ADATE, DELTA, ENDYR, YDOY
EXTERNAL ENDYR, YDOY
CALL YR_DOY(ADATE, AYR, ADOY)
NDYR = ENDYR(AYR)
ADOY = ADOY + DELTA
100 CONTINUE
IF (ADOY .GT. NDYR) THEN
AYR = AYR + 1
ADOY = ADOY - NDYR
GO TO 100
END IF
200 IF (ADOY .LE. 0) THEN
AYR = AYR - 1
NDYR = ENDYR(AYR)
ADOY = ADOY + NDYR
GO TO 200
END IF
INCDAT = YDOY(AYR, ADOY)
RETURN
END FUNCTION INCDAT
C=======================================================================
C INCMTH, Integer Function, N.B. Pickering, 06/05/92
C Increases/decreases month and adjusts YR based on INC (ABS(INC)<=12).
C-----------------------------------------------------------------------
C Input : YR,MTH,SIGN
C Output: INCMTH
C Local :
C=======================================================================
SUBROUTINE INCMTH(YR,MTH,INC)
INTEGER YR,MTH,INC
MTH = MTH + INC
IF (MTH .GT. 12) THEN
YR = YR + 1
MTH = MTH - 12
ELSE IF (MTH .LT. 1) THEN
YR = YR - 1
MTH = MTH + 12
ENDIF
END SUBROUTINE INCMTH
C=======================================================================
C YDEND, Integer Function, N.B. Pickering, 06/05/92
C Computes end-of-year in YRDOY format. Input can be YRDOY or YR.
C-----------------------------------------------------------------------
C Input : YRDOY or YR
C Output: YDEND
C Local : DOY,NDYR,YR
C=======================================================================
INTEGER FUNCTION YDEND(YRDOY)
IMPLICIT NONE
INTEGER ENDYR,YRDOY,YR,YDOY
IF (YRDOY/1000 .NE. 0) THEN
YR = YRDOY / 1000
ELSE
YR = YRDOY
ENDIF
YDEND = YDOY(YR,ENDYR(YR))
END FUNCTION YDEND
C=======================================================================
C ENDYR, Integer Function, N.B. Pickering, 06/05/92
C Computes end-of-year (365 or 366) depending if leap year.
C-----------------------------------------------------------------------
C Input : YR
C Output: ENDYR
C Local :
C=======================================================================
INTEGER FUNCTION ENDYR(YR)
INTEGER YR
LOGICAL LEAP
IF (LEAP(YR)) THEN; ENDYR = 366
ELSE; ENDYR = 365
ENDIF
END FUNCTION ENDYR
C=======================================================================
C JULIAN, Function
C
C Determines day, month
C-----------------------------------------------------------------------
C Revision history
C
C 1. Written
C 2 Modified by
C 3. Header revision and minor changes P.W.W. 5-28-93
C-----------------------------------------------------------------------
C INPUT : NDAY,RMON,NYRCHK
C
C LOCAL : MonthTxt,UPCASE,I,JCOUNT,DAYS
C
C OUTPUT : JULIAN
C-----------------------------------------------------------------------
C Called : SEHARV SEPLT SETIME
C
C Calls : None
C-----------------------------------------------------------------------
C DEFINITIONS
C
C RMON :
C MonthTxt():
C UPCASE :
C I :
C JCOUNT :
C NDAY :
C NYRCHK :
C DAYS() :
C=======================================================================
INTEGER FUNCTION JULIAN (NDAY,RMON,YR)
USE ModuleDefs
IMPLICIT NONE
CHARACTER*3 RMON !,MonthTxt(12)
CHARACTER*1 UPCASE
INTEGER I,JCOUNT,NDAY,YR,DAYS(12)
LOGICAL LEAP
DATA DAYS /31,28,31,30,31,30,31,31,30,31,30,31/
! DATA MonthTxt /'JAN','FEB','MAR','APR','MAY','JUN',
! & 'JUL','AUG','SEP','OCT','NOV','DEC'/
IF (LEAP(YR)) THEN; DAYS(2) = 29
ELSE; DAYS(2) = 28
ENDIF
DO I = 1, 3
RMON(I:I) = UPCASE(RMON(I:I))
END DO
DO JCOUNT = 1, 12
IF (RMON .EQ. MonthTxt(JCOUNT)) GO TO 200
END DO
C-----------------------------------------------------------------------
C Month name cannot be recognized
C-----------------------------------------------------------------------
JULIAN = 370
RETURN
200 JULIAN = 0
DO 400 JCOUNT = 1, 12
IF (RMON .EQ. MonthTxt(JCOUNT))
& GO TO 300
JULIAN = JULIAN + DAYS(JCOUNT)
GO TO 400
300 JULIAN = JULIAN + NDAY
RETURN
400 CONTINUE
END FUNCTION JULIAN
C=======================================================================
C NAILUJ, Subroutine
C
C Determines Julian date
C-----------------------------------------------------------------------
C Revision history
C
C 1. Written
C 2 Modified by
C 3. Header revision and minor changes P.W.W. 5-28-93
C-----------------------------------------------------------------------
C INPUT : JULD,NYRCHK
C
C LOCAL : MonthTxt(),NSUM,JCOUNT,NDIF,DAYS()
C
C OUTPUT : NDAY RMON
C-----------------------------------------------------------------------
C Called : SEHARV SENS SEPLT SETIME OPDAY OPHEAD
C
C Calls : None
C-----------------------------------------------------------------------
C DEFINITIONS
C
C RMON :
C MonthTxt():
C NSUM :
C JCOUNT :
C NDIF :
C JULD :
C NYRCHK :
C NDAY :
C DAYS() :
C=======================================================================
SUBROUTINE NAILUJ (JULD,YR,RMON,NDAY)
USE ModuleDefs
IMPLICIT NONE
CHARACTER*3 RMON !,MonthTxt(12)
INTEGER NSUM,JCOUNT,NDIF,JULD,YR,NDAY,DAYS(12)
LOGICAL LEAP
DATA DAYS /31,28,31,30,31,30,31,31,30,31,30,31/
! DATA MonthTxt /'JAN','FEB','MAR','APR','MAY','JUN',
! & 'JUL','AUG','SEP','OCT','NOV','DEC'/
IF (LEAP(YR)) THEN; DAYS(2) = 29
ELSE; DAYS(2) = 28
ENDIF
NSUM = 0
DO JCOUNT = 1, 12
NDIF = JULD - NSUM
IF (NDIF .LE. DAYS(JCOUNT)) THEN
NDAY = NDIF
RMON = MonthTxt(JCOUNT)
RETURN
ENDIF
NSUM = NSUM + DAYS(JCOUNT)
END DO
RETURN
END SUBROUTINE NAILUJ
C=======================================================================
C FullYear, Subroutine
C
C Converts 2 digit year to 4 digit year. On first call per simulation,
C assumes that years 10 and lower refer to 2010 and years 11 and higher
C refer to 1911. After the first call, years are converted based on
C previous years (i.e., year 2011 follows year 2010.)
C
C-----------------------------------------------------------------------
C Revision history
C
C 02/07/2002 CHP Written
C 11/24/2002 GH Modified Y2K to 10
C=======================================================================
SUBROUTINE FullYear (YRDOY, YEAR, DOY)
IMPLICIT NONE
INTEGER CENTURY, DOY
INTEGER YEAR, YRDOY, YR
LOGICAL FIRST
DATA FIRST /.TRUE./
IF (YRDOY .LE. 99365) THEN
YR = INT(YRDOY / 1000)
DOY = YRDOY - YR * 1000
IF (FIRST) THEN
IF (YR .LE. 10) THEN
CENTURY = 2000
ELSE
CENTURY = 1900
ENDIF
FIRST = .FALSE.
ENDIF
! This will work if the YRDOY after 99365 is 100001.
YEAR = CENTURY + YR
ENDIF
RETURN
END SUBROUTINE FullYear
C=======================================================================
C ETAD_NAILUJ, Subroutine
C
C Determines Julian date, exports integer year, month, day
C-----------------------------------------------------------------------
C Revision history
C
C 11/29/2004 CHP Written based on NAILUJ
C-----------------------------------------------------------------------
C INPUT : JULD
C OUTPUT : YR, iMON, NDAY
C=======================================================================
SUBROUTINE ETAD_NAILUJ (JULD, YR, iMON, NDAY)
IMPLICIT NONE
INTEGER NSUM,NDIF,JULD,YR,NDAY,DAYS(12), iMON
LOGICAL LEAP
DATA DAYS /31,28,31,30,31,30,31,31,30,31,30,31/
IF (LEAP(YR)) THEN; DAYS(2) = 29
ELSE; DAYS(2) = 28
ENDIF
NSUM = 0
DO iMON = 1, 12
NDIF = JULD - NSUM
IF (NDIF .LE. DAYS(iMON)) THEN
NDAY = NDIF
RETURN
ENDIF
NSUM = NSUM + DAYS(iMON)
END DO
RETURN
END SUBROUTINE ETAD_NAILUJ
C=======================================================================
C=======================================================================
C LEAP, Function
C
C Determines leap years
C-----------------------------------------------------------------------
C Revision history
C
C 11/16/2007 CHP Written
C-----------------------------------------------------------------------
C INPUT : YR
C OUTPUT : LEAP
C=======================================================================
LOGICAL FUNCTION LEAP (YR)
IMPLICIT NONE
INTEGER YR
IF (MOD(YR,400) == 0) THEN; LEAP = .TRUE.
ELSEIF (MOD(YR,100) == 0) THEN; LEAP = .FALSE.
ELSEIF (MOD(YR, 4) == 0) THEN; LEAP = .TRUE.
ELSE; LEAP = .FALSE.
ENDIF
RETURN
END FUNCTION LEAP
C=======================================================================