00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 module shr_cal_mod
00042
00043
00044
00045 use shr_kind_mod
00046 use shr_const_mod
00047 use shr_sys_mod
00048 use shr_log_mod, only: s_loglev => shr_log_Level
00049 use shr_log_mod, only: s_logunit => shr_log_Unit
00050 use esmf_mod
00051
00052 implicit none
00053
00054 private
00055
00056
00057
00058
00059
00060
00061
00062 public :: shr_cal_set
00063 public :: shr_cal_get
00064 public :: shr_cal_eday2date
00065 public :: shr_cal_eday2ymd
00066 public :: shr_cal_date2ymd
00067 public :: shr_cal_date2eday
00068 public :: shr_cal_date2julian
00069 public :: shr_cal_ymd2julian
00070 public :: shr_cal_ymd2date
00071 public :: shr_cal_ymd2eday
00072 public :: shr_cal_advDate
00073 public :: shr_cal_advDateInt
00074 public :: shr_cal_validDate
00075 public :: shr_cal_validYMD
00076 public :: shr_cal_validHMS
00077 public :: shr_cal_numDaysinMonth
00078 public :: shr_cal_elapsDaysStrtMonth
00079 public :: shr_cal_getDebug
00080 public :: shr_cal_setDebug
00081
00082
00083
00084
00085
00086
00087
00088
00089 character(SHR_KIND_CL),save :: calendar_type='noleap'
00090 integer(SHR_KIND_IN),parameter :: shr_cal_nvalidTypes = 3
00091 character(*),parameter ::
00092 shr_cal_validTypes(shr_cal_nvalidTypes) = (/'noleap ',
00093 '365_day ',
00094 'gregorian '/)
00095
00096
00097 integer(SHR_KIND_IN),parameter :: dpy = 365
00098 integer(SHR_KIND_IN),parameter :: dsm(12) =
00099 (/ 0,31,59, 90,120,151, 181,212,243, 273,304,334/)
00100 integer(SHR_KIND_IN),parameter :: dpm(12) =
00101 (/31,28,31, 30, 31, 30, 31, 31, 30, 31, 30, 31/)
00102
00103
00104
00105 integer(SHR_KIND_IN) :: debug = 0
00106
00107
00108 contains
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 subroutine shr_cal_set(ctype)
00125
00126 implicit none
00127
00128
00129
00130 character(*),intent(in) :: ctype
00131
00132
00133
00134
00135 integer(SHR_KIND_IN) :: n
00136 logical :: found
00137
00138
00139
00140
00141
00142 found = .false.
00143 do n = 1,shr_cal_nvalidTypes
00144 if (trim(ctype) == trim(shr_cal_validTypes(n))) then
00145 calendar_type = trim(ctype)
00146 found = .true.
00147 endif
00148 enddo
00149
00150 if (.not.found) call shr_sys_abort('shr_cal_set ERROR illegal calendar type '//trim(ctype))
00151
00152 end subroutine shr_cal_set
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 subroutine shr_cal_get(ctype)
00168
00169 implicit none
00170
00171
00172
00173 character(*),intent(out) :: ctype
00174
00175
00176
00177
00178
00179
00180
00181 ctype = calendar_type
00182
00183 end subroutine shr_cal_get
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 subroutine shr_cal_eday2date(eday,date)
00199
00200 implicit none
00201
00202
00203
00204 integer(SHR_KIND_IN),intent(in) :: eday
00205 integer(SHR_KIND_IN),intent(out) :: date
00206
00207
00208
00209
00210 integer(SHR_KIND_IN) :: yy,mm,dd
00211
00212
00213
00214
00215
00216
00217 if (debug > 1) write(s_logunit,*) 'shr_cal_eday2date_a ',eday
00218
00219 if (trim(calendar_type) == 'gregorian') then
00220 call shr_sys_abort('ERROR shr_cal_eday2date gregorian not validated')
00221 endif
00222
00223 call shr_cal_eday2ymd(eday,yy,mm,dd)
00224 call shr_cal_ymd2date(yy,mm,dd,date)
00225
00226 if (debug > 1) write(s_logunit,*) 'shr_cal_eday2date_b ',date
00227
00228 end subroutine shr_cal_eday2date
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 subroutine shr_cal_eday2ymd (eday,year,month,day)
00244
00245 implicit none
00246
00247
00248
00249 integer(SHR_KIND_IN),intent(in) :: eday
00250 integer(SHR_KIND_IN),intent(out) :: year,month,day
00251
00252
00253
00254
00255 integer(SHR_KIND_IN) :: k,tday
00256
00257
00258
00259
00260
00261
00262 if (debug > 1) write(s_logunit,*) 'shr_cal_eday2ymd_a ',eday
00263
00264 if (trim(calendar_type) == 'gregorian') then
00265 call shr_sys_abort('ERROR shr_cal_eday2date gregorian not validated')
00266 endif
00267
00268 if (eday < 0) then
00269 year = -( abs(eday+1)/365 + 1)
00270 else
00271 year = eday/365
00272 endif
00273
00274 tday = eday - year*365
00275
00276 if (tday < 0 .or. tday > 364) then
00277 call shr_sys_abort('ERROR shr_cal_eday2date tday error')
00278 endif
00279
00280 day = mod(tday,365)
00281 do k=1,12
00282 IF (day .ge. dsm(k)) month=k
00283 end do
00284 day = day-dsm(month) + 1
00285
00286 if (debug > 1) write(s_logunit,*) 'shr_cal_eday2ymd_b ',year,month,day
00287
00288 end subroutine shr_cal_eday2ymd
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 subroutine shr_cal_date2ymd (date,year,month,day)
00304
00305 implicit none
00306
00307
00308
00309 integer(SHR_KIND_IN),intent(in) :: date
00310 integer(SHR_KIND_IN),intent(out) :: year,month,day
00311
00312
00313
00314 integer(SHR_KIND_IN) :: tdate
00315
00316
00317
00318
00319
00320 if (debug > 1) write(s_logunit,*) 'shr_cal_date2ymd_a ',date
00321
00322 tdate = abs(date)
00323 year =int( tdate /10000)
00324 if (date < 0) year = -year
00325 month=int( mod(tdate,10000)/ 100)
00326 day = mod(tdate, 100)
00327
00328 if (.not. shr_cal_validYMD(year,month,day)) then
00329 if (s_loglev > 0) write(s_logunit,*) "(shr_cal_date2ymd) ERROR: invalid date = ", &
00330 date,year,month,day
00331 endif
00332
00333 if (debug > 1) write(s_logunit,*) 'shr_cal_date2ymd_b ',year,month,day
00334
00335 end subroutine shr_cal_date2ymd
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350 subroutine shr_cal_date2eday(date,eday)
00351
00352 implicit none
00353
00354
00355
00356 integer(SHR_KIND_IN),intent(in ) :: date
00357 integer(SHR_KIND_IN),intent(out) :: eday
00358
00359
00360
00361
00362 integer(SHR_KIND_IN) :: year,month,day
00363
00364
00365
00366
00367
00368
00369 if (debug > 1) write(s_logunit,*) 'shr_cal_date2eday_a ',date
00370
00371 call shr_cal_date2ymd(date,year,month,day)
00372 if (.not. shr_cal_validYMD(year,month,day)) then
00373 call shr_sys_abort(' shr_cal_date2eday invalid ymd')
00374 endif
00375 call shr_cal_ymd2eday(year,month,day,eday)
00376
00377 if (debug > 1) write(s_logunit,*) 'shr_cal_date2eday_b ',eday
00378
00379 end subroutine shr_cal_date2eday
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394 subroutine shr_cal_date2julian(date,sec,jday)
00395
00396 implicit none
00397
00398
00399
00400 integer(SHR_KIND_IN),intent(in ) :: date
00401 integer(SHR_KIND_IN),intent(in ) :: sec
00402 real (SHR_KIND_R8),intent(out) :: jday
00403
00404
00405
00406
00407 integer(SHR_KIND_IN) :: year,month,day
00408
00409
00410
00411
00412
00413
00414 if (debug > 1) write(s_logunit,*) 'shr_cal_date2julian_a ',date,sec
00415
00416 call shr_cal_date2ymd(date,year,month,day)
00417 if (.not. shr_cal_validYMD(year,month,day)) then
00418 call shr_sys_abort(' shr_cal_date2julian invalid ymd')
00419 endif
00420 call shr_cal_ymd2julian(year,month,day,sec,jday)
00421
00422 if (debug > 1) write(s_logunit,*) 'shr_cal_date2julian_b ',jday
00423
00424 end subroutine shr_cal_date2julian
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439 subroutine shr_cal_ymd2julian(year,month,day,sec,jday)
00440
00441 implicit none
00442
00443
00444
00445 integer(SHR_KIND_IN),intent(in ) :: year
00446 integer(SHR_KIND_IN),intent(in ) :: month
00447 integer(SHR_KIND_IN),intent(in ) :: day
00448 integer(SHR_KIND_IN),intent(in ) :: sec
00449 real (SHR_KIND_R8),intent(out) :: jday
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 if (debug > 1) write(s_logunit,*) 'shr_cal_ymd2julian_a ',year,month,day,sec
00461
00462 jday = shr_cal_elapsDaysStrtMonth(year,month) + day + sec/SHR_CONST_CDAY
00463
00464
00465
00466 if (debug > 1) write(s_logunit,*) 'shr_cal_ymd2julian_b ',jday
00467
00468 end subroutine shr_cal_ymd2julian
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483 subroutine shr_cal_ymd2date(year,month,day,date)
00484
00485 implicit none
00486
00487
00488
00489 integer(SHR_KIND_IN),intent(in ) :: year,month,day
00490 integer(SHR_KIND_IN),intent(out) :: date
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501 if (debug > 1) write(s_logunit,*) 'shr_cal_ymd2date_a ',year,month,day
00502
00503 if (.not. shr_cal_validYMD(year,month,day)) then
00504 call shr_sys_abort(' shr_cal_ymd2date invalid ymd')
00505 endif
00506
00507 date = abs(year)*10000 + month*100 + day
00508 if (year < 0) date = -date
00509
00510 if (debug > 1) write(s_logunit,*) 'shr_cal_ymd2date_b ',date
00511
00512 end subroutine shr_cal_ymd2date
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527 subroutine shr_cal_ymd2eday(year,month,day,eday)
00528
00529 implicit none
00530
00531
00532
00533 integer(SHR_KIND_IN),intent(in ) :: year,month,day
00534 integer(SHR_KIND_IN),intent(out) :: eday
00535
00536
00537
00538
00539 type(ESMF_Time) :: ltime
00540 integer(SHR_KIND_IN) :: eday0
00541 integer :: rc
00542
00543
00544
00545
00546
00547
00548 if (debug > 1) write(s_logunit,*) 'shr_cal_ymd2eday_a ',year,month,day
00549
00550 if (.not. shr_cal_validYMD(year,month,day)) then
00551 call shr_sys_abort(' shr_cal_ymd2eday invalid ymd')
00552 endif
00553
00554 if (trim(calendar_type) == 'gregorian') then
00555 #ifdef USE_ESMF_LIB
00556 call ESMF_TimeSet(ltime,yy=year,mm=month,dd=day,s=0,calendarType=ESMF_CAL_GREGORIAN,rc=rc)
00557 if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, terminationflag=ESMF_ABORT)
00558 call ESMF_TimeGet(ltime,d=eday,rc=rc)
00559 if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, terminationflag=ESMF_ABORT)
00560 #else
00561 call shr_sys_abort('ERROR: shr_cal gregorian requires USE_ESMF_LIB')
00562 #endif
00563 else
00564 eday = year*365 + dsm(month) + (day-1)
00565 endif
00566
00567 if (debug > 1) write(s_logunit,*) 'shr_cal_ymd2eday_b ',eday
00568
00569 end subroutine shr_cal_ymd2eday
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 subroutine shr_cal_advDate(delta,units,dateIN,secIN,dateOUT,secOUT,calendar)
00587
00588 implicit none
00589
00590
00591
00592 real (SHR_KIND_R8) ,intent(in) :: delta
00593 character(*) ,intent(in) :: units
00594 integer(SHR_KIND_IN) ,intent(in) :: dateIN
00595 real (SHR_KIND_R8) ,intent(in) :: secIN
00596 integer(SHR_KIND_IN) ,intent(out) :: dateOUT
00597 real (SHR_KIND_R8) ,intent(out) :: secOUT
00598 character(*),optional,intent(in) :: calendar
00599
00600
00601
00602
00603 real (SHR_KIND_R8) :: dSec
00604 integer(SHR_KIND_IN) :: dDay
00605 real (SHR_KIND_R8) :: rSec
00606 integer(SHR_KIND_IN) :: eDay
00607 integer(SHR_KIND_IN) :: dayadjust
00608 character(SHR_KIND_CL) :: calOrig
00609
00610
00611 character(*),parameter :: subName = "(shr_cal_advDate)"
00612 character(*),parameter :: F00 = "('(shr_cal_advDate) ',a,i5)"
00613 character(*),parameter :: F02 = "('(shr_cal_advDate) ',a,i8.8,f10.3)"
00614
00615
00616
00617
00618
00619 call shr_cal_get(calOrig)
00620
00621
00622 if (present(calendar)) call shr_cal_set(calendar)
00623
00624
00625 if (trim(units) == 'days' ) then
00626 dSec = delta * SHR_CONST_CDAY
00627 elseif (trim(units) == 'hours' ) then
00628 dSec = delta * 3600.0_SHR_KIND_R8
00629 elseif (trim(units) == 'minutes') then
00630 dSec = delta * 60.0_SHR_KIND_R8
00631 elseif (trim(units) == 'seconds') then
00632 dSec = delta * 1.0_SHR_KIND_R8
00633 else
00634 call shr_sys_abort(' ERROR: unrecognized time units '//trim(units))
00635 endif
00636
00637
00638
00639
00640 call shr_cal_date2eday(dateIN,eDay)
00641 dSec = dSec + secIN
00642
00643
00644
00645 if (dSec < 0.0_SHR_KIND_R8) then
00646 dayadjust = int(abs(dSec)/SHR_CONST_CDAY) + 1
00647 dSec = dSec + dayadjust*SHR_CONST_CDAY
00648 dDay = int(dSec/SHR_CONST_CDAY) - dayadjust
00649 rSec = mod(dSec,SHR_CONST_CDAY)
00650 else
00651 dDay = int(dSec/SHR_CONST_CDAY)
00652 rSec = mod(dSec,SHR_CONST_CDAY)
00653 endif
00654
00655 call shr_cal_eday2date(eDay+dDay,dateOUT)
00656 secOUT = rSec
00657
00658 if (debug>0) then
00659 if (present(calendar)) then
00660 if (s_loglev > 0) write(s_logunit,*) subName," units,delta,calendar=",trim(units),delta,' ',trim(calendar)
00661 else
00662 if (s_loglev > 0) write(s_logunit,*) subName," units,delta=" ,trim(units),delta
00663 endif
00664 if (s_loglev > 0) write(s_logunit,F02) "dateIN ,secIN =",dateIN ,secIN
00665 if (s_loglev > 0) write(s_logunit,F02) "dateOUT,secOUT=",dateOUT,secOUT
00666 end if
00667
00668 call shr_cal_set(calOrig)
00669
00670 end subroutine shr_cal_advDate
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 subroutine shr_cal_advDateInt(delta,units,dateIN,secIN,dateOUT,secOUT,calendar)
00686
00687 implicit none
00688
00689
00690
00691 integer(SHR_KIND_IN) ,intent(in) :: delta
00692 character(*) ,intent(in) :: units
00693 integer(SHR_KIND_IN) ,intent(in) :: dateIN
00694 integer(SHR_KIND_IN) ,intent(in) :: secIN
00695 integer(SHR_KIND_IN) ,intent(out) :: dateOUT
00696 integer(SHR_KIND_IN) ,intent(out) :: secOUT
00697 character(*),optional,intent(in) :: calendar
00698
00699
00700
00701
00702 real (SHR_KIND_R8) :: dSec
00703 integer(SHR_KIND_IN) :: dDay
00704 real (SHR_KIND_R8) :: rSec
00705 integer(SHR_KIND_IN) :: eDay
00706 integer(SHR_KIND_IN) :: dayadjust
00707 character(SHR_KIND_CL) :: calOrig
00708
00709
00710 character(*),parameter :: subName = "(shr_cal_advDateInt)"
00711 character(*),parameter :: F00 = "('(shr_cal_advDateInt) ',a,i5)"
00712 character(*),parameter :: F02 = "('(shr_cal_advDateInt) ',a,i8.8,f10.3)"
00713
00714
00715
00716
00717
00718 call shr_cal_get(calOrig)
00719
00720
00721 if (present(calendar)) call shr_cal_set(calendar)
00722
00723
00724 if (trim(units) == 'days' ) then
00725 dSec = delta * SHR_CONST_CDAY
00726 elseif (trim(units) == 'hours' ) then
00727 dSec = delta * 3600.0_SHR_KIND_R8
00728 elseif (trim(units) == 'minutes') then
00729 dSec = delta * 60.0_SHR_KIND_R8
00730 elseif (trim(units) == 'seconds') then
00731 dSec = delta * 1.0_SHR_KIND_R8
00732 else
00733 call shr_sys_abort(' ERROR: unrecognized time units '//trim(units))
00734 endif
00735
00736
00737
00738
00739 call shr_cal_date2eday(dateIN,eDay)
00740 dSec = dSec + secIN
00741
00742
00743
00744 if (dSec < 0.0_SHR_KIND_R8) then
00745 dayadjust = int(abs(dSec)/SHR_CONST_CDAY) + 1
00746 dSec = dSec + dayadjust*SHR_CONST_CDAY
00747 dDay = int(dSec/SHR_CONST_CDAY) - dayadjust
00748 rSec = mod(dSec,SHR_CONST_CDAY)
00749 else
00750 dDay = int(dSec/SHR_CONST_CDAY)
00751 rSec = mod(dSec,SHR_CONST_CDAY)
00752 endif
00753
00754 call shr_cal_eday2date(eDay+dDay,dateOUT)
00755 secOUT = nint(rSec)
00756
00757 if (debug>0) then
00758 if (present(calendar)) then
00759 if (s_loglev > 0) write(s_logunit,*) subName," units,delta,calendar=",trim(units),delta,' ',trim(calendar)
00760 else
00761 if (s_loglev > 0) write(s_logunit,*) subName," units,delta=" ,trim(units),delta
00762 endif
00763 if (s_loglev > 0) write(s_logunit,F02) "dateIN ,secIN =",dateIN ,secIN
00764 if (s_loglev > 0) write(s_logunit,F02) "dateOUT,secOUT=",dateOUT,secOUT
00765 end if
00766
00767 call shr_cal_set(calOrig)
00768
00769 end subroutine shr_cal_advDateInt
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784 logical function shr_cal_validDate(date)
00785
00786 implicit none
00787
00788
00789
00790 integer(SHR_KIND_IN),intent(in ) :: date
00791
00792
00793
00794
00795 integer(SHR_KIND_IN) :: year,month,day
00796 integer(SHR_KIND_IN) :: tdate
00797
00798
00799
00800
00801
00802 call shr_cal_date2ymd(date,year,month,day)
00803 shr_cal_validDate = shr_cal_validYMD(year,month,day)
00804
00805 end function shr_cal_validDate
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820 logical function shr_cal_validYMD(year,month,day)
00821
00822 implicit none
00823
00824
00825
00826 integer(SHR_KIND_IN),intent(in ) :: year,month,day
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836 shr_cal_validYMD = .true.
00837 if (year < -999) shr_cal_validYMD = .false.
00838 if (year > 9999) shr_cal_validYMD = .false.
00839 if (month < 1) shr_cal_validYMD = .false.
00840 if (month > 12) shr_cal_validYMD = .false.
00841 if (day < 1) shr_cal_validYMD = .false.
00842
00843
00844
00845
00846
00847 end function shr_cal_validYMD
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862 logical function shr_cal_validHMS(hr,min,sec)
00863
00864 implicit none
00865
00866
00867
00868 integer(SHR_KIND_IN),intent(in ) :: hr, min, sec
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878 shr_cal_validHMS = .true.
00879 if (hr < 0) shr_cal_validHMS = .false.
00880 if (hr > 23) shr_cal_validHMS = .false.
00881 if (min < 0) shr_cal_validHMS = .false.
00882 if (min > 59) shr_cal_validHMS = .false.
00883 if (sec < 0) shr_cal_validHMS = .false.
00884 if (sec > 60) shr_cal_validHMS = .false.
00885
00886 end function shr_cal_validHMS
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901 integer function shr_cal_numDaysInMonth(year,month)
00902
00903 implicit none
00904
00905
00906
00907 integer(SHR_KIND_IN),intent(in ) :: year,month
00908
00909
00910
00911 type(ESMF_time) :: ltime1,ltime2
00912 integer(SHR_KIND_IN) :: eday1,eday2
00913 integer :: rc
00914
00915
00916
00917
00918
00919 if (trim(calendar_type) == 'gregorian') then
00920 #ifdef USE_ESMF_LIB
00921 call ESMF_TimeSet(ltime1,yy=year,mm=month,dd=1,s=0,calendarType=ESMF_CAL_GREGORIAN,rc=rc)
00922 if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, terminationflag=ESMF_ABORT)
00923 if (month < 12) then
00924 call ESMF_TimeSet(ltime2,yy=year,mm=month+1,dd=1,s=0,calendarType=ESMF_CAL_GREGORIAN,rc=rc)
00925 if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, terminationflag=ESMF_ABORT)
00926 else
00927 call ESMF_TimeSet(ltime2,yy=year+1,mm=1,dd=1,s=0,calendarType=ESMF_CAL_GREGORIAN,rc=rc)
00928 if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, terminationflag=ESMF_ABORT)
00929 endif
00930 call ESMF_TimeGet(ltime1,d=eday1,rc=rc)
00931 call ESMF_TimeGet(ltime2,d=eday2,rc=rc)
00932 shr_cal_numDaysInMonth = eday2-eday1
00933 call shr_sys_abort('ERROR shr_cal_numDaysInMonth gregorian not validated')
00934 #else
00935 call shr_sys_abort('ERROR: shr_cal gregorian requires USE_ESMF_LIB')
00936 #endif
00937 else
00938 shr_cal_numDaysInMonth = dpm(month)
00939 endif
00940
00941
00942 end function shr_cal_numDaysInMonth
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958 integer function shr_cal_elapsDaysStrtMonth(year,month)
00959
00960 implicit none
00961
00962
00963
00964 integer(SHR_KIND_IN),intent(in ) :: year,month
00965
00966
00967
00968 integer(SHR_KIND_IN) :: yr,eday1,eday2
00969 integer :: rc
00970 type(ESMF_Time) :: ltime1,ltime2
00971
00972
00973
00974
00975
00976 if (trim(calendar_type) == 'gregorian') then
00977 #ifdef USE_ESMF_LIB
00978 call ESMF_TimeSet(ltime1,yy=year,mm=1,dd=1,s=0,calendarType=ESMF_CAL_GREGORIAN,rc=rc)
00979 if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, terminationflag=ESMF_ABORT)
00980 call ESMF_TimeSet(ltime2,yy=year,mm=month,dd=1,s=0,calendarType=ESMF_CAL_GREGORIAN,rc=rc)
00981 if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, terminationflag=ESMF_ABORT)
00982 call ESMF_TimeGet(ltime1,yy=yr,d=eday1,rc=rc)
00983 if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, terminationflag=ESMF_ABORT)
00984 call ESMF_TimeGet(ltime2,yy=yr,d=eday2,rc=rc)
00985 if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, terminationflag=ESMF_ABORT)
00986 shr_cal_elapsDaysStrtMonth = eday2 - eday1
00987 #else
00988 call shr_sys_abort('ERROR: shr_cal gregorian requires USE_ESMF_LIB')
00989 #endif
00990 else
00991 shr_cal_elapsDaysStrtMonth = dsm(month)
00992 endif
00993
00994 end function shr_cal_elapsDaysStrtMonth
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011 subroutine shr_cal_setDebug(level)
01012
01013 implicit none
01014
01015
01016
01017 integer,intent(in) :: level
01018
01019
01020
01021
01022 character(*),parameter :: subName = "(shr_cal_setDebug) "
01023 character(*),parameter :: F00 = "('(shr_cal_setDebug) ',a) "
01024 character(*),parameter :: F01 = "('(shr_cal_setDebug) ',a,i4) "
01025
01026
01027
01028
01029
01030 debug = level
01031 if (s_loglev > 0) write(s_logunit,F01) "debug level reset to ",level
01032
01033 end subroutine shr_cal_setDebug
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050 subroutine shr_cal_getDebug(level)
01051
01052 implicit none
01053
01054
01055
01056 integer,intent(out) :: level
01057
01058
01059
01060
01061 character(*),parameter :: subName = "(shr_cal_getDebug) "
01062 character(*),parameter :: F00 = "('(shr_cal_getDebug) ',a) "
01063
01064
01065
01066
01067
01068 level = debug
01069
01070 end subroutine shr_cal_getDebug
01071
01072
01073
01074
01075 end module shr_cal_mod