| 1 | ! $Id: time_phylmdz_mod.F90 5144 2024-07-29 21:01:04Z ymeurdesoif $ |
|---|
| 2 | |
|---|
| 3 | MODULE time_phylmdz_mod |
|---|
| 4 | |
|---|
| 5 | IMPLICIT NONE |
|---|
| 6 | REAL, SAVE :: pdtphys ! physics time step (s) |
|---|
| 7 | !$OMP THREADPRIVATE(pdtphys) |
|---|
| 8 | INTEGER, SAVE :: day_step_phy ! number of physical steps per day |
|---|
| 9 | !$OMP THREADPRIVATE(day_step_phy) |
|---|
| 10 | INTEGER, SAVE :: ndays ! number of days to run |
|---|
| 11 | !$OMP THREADPRIVATE(ndays) |
|---|
| 12 | INTEGER, SAVE :: annee_ref ! reference year from the origin |
|---|
| 13 | !$OMP THREADPRIVATE(annee_ref) |
|---|
| 14 | INTEGER, SAVE :: day_ref ! reference year of the origin |
|---|
| 15 | !$OMP THREADPRIVATE(day_ref) |
|---|
| 16 | INTEGER, SAVE :: day_ini ! initial day of the run starting from 1st january of annee_ref |
|---|
| 17 | !$OMP THREADPRIVATE(day_ini) |
|---|
| 18 | INTEGER, SAVE :: day_end ! final day of the run starting from 1st january of annee_ref |
|---|
| 19 | !$OMP THREADPRIVATE(day_end) |
|---|
| 20 | REAL, SAVE :: start_time ! starting time from the begining of the initial day |
|---|
| 21 | !$OMP THREADPRIVATE(start_time) |
|---|
| 22 | INTEGER, SAVE :: raz_date |
|---|
| 23 | !$OMP THREADPRIVATE(raz_date) |
|---|
| 24 | |
|---|
| 25 | INTEGER, SAVE :: itau_phy ! number of physiq iteration from origin |
|---|
| 26 | !$OMP THREADPRIVATE(itau_phy) |
|---|
| 27 | INTEGER, SAVE :: itaufin_phy ! final iteration (in itau_phy steps) |
|---|
| 28 | !$OMP THREADPRIVATE(itaufin_phy) |
|---|
| 29 | REAL, SAVE :: current_time ! current elapsed time in seconds from the begining of the run |
|---|
| 30 | !$OMP THREADPRIVATE(current_time) |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | CONTAINS |
|---|
| 34 | |
|---|
| 35 | SUBROUTINE init_time(annee_ref_, day_ref_, day_ini_, start_time_, & |
|---|
| 36 | ndays_, pdtphys_) |
|---|
| 37 | USE lmdz_ioipsl_getin_p, ONLY: getin_p |
|---|
| 38 | USE phys_cal_mod, ONLY: phys_cal_init |
|---|
| 39 | USE lmdz_yomcst |
|---|
| 40 | |
|---|
| 41 | IMPLICIT NONE |
|---|
| 42 | INTEGER, INTENT(IN) :: annee_ref_ |
|---|
| 43 | INTEGER, INTENT(IN) :: day_ref_ |
|---|
| 44 | INTEGER, INTENT(IN) :: day_ini_ |
|---|
| 45 | REAL, INTENT(IN) :: start_time_ |
|---|
| 46 | INTEGER, INTENT(IN) :: ndays_ |
|---|
| 47 | REAL, INTENT(IN) :: pdtphys_ |
|---|
| 48 | |
|---|
| 49 | annee_ref = annee_ref_ |
|---|
| 50 | day_ref = day_ref_ |
|---|
| 51 | day_ini = day_ini_ |
|---|
| 52 | start_time = start_time_ |
|---|
| 53 | ndays = ndays_ |
|---|
| 54 | pdtphys = pdtphys_ |
|---|
| 55 | |
|---|
| 56 | ! Initialize module variable not inherited from dynamics |
|---|
| 57 | day_step_phy = NINT(rday / pdtphys) |
|---|
| 58 | day_end = day_ini + ndays |
|---|
| 59 | |
|---|
| 60 | raz_date = 0 |
|---|
| 61 | CALL getin_p('raz_date', raz_date) |
|---|
| 62 | |
|---|
| 63 | current_time = 0. |
|---|
| 64 | |
|---|
| 65 | CALL phys_cal_init(annee_ref, day_ref) |
|---|
| 66 | |
|---|
| 67 | END SUBROUTINE init_time |
|---|
| 68 | |
|---|
| 69 | SUBROUTINE init_iteration(itau_phy_) |
|---|
| 70 | IMPLICIT NONE |
|---|
| 71 | INTEGER, INTENT(IN) :: itau_phy_ |
|---|
| 72 | itau_phy = itau_phy_ |
|---|
| 73 | IF (raz_date==1) itau_phy = 0 |
|---|
| 74 | |
|---|
| 75 | itaufin_phy = itau_phy + NINT(ndays / pdtphys) |
|---|
| 76 | |
|---|
| 77 | END SUBROUTINE init_iteration |
|---|
| 78 | |
|---|
| 79 | SUBROUTINE update_time(pdtphys_) |
|---|
| 80 | ! This SUBROUTINE updates the module saved variables. |
|---|
| 81 | USE ioipsl, ONLY: ymds2ju |
|---|
| 82 | USE phys_cal_mod, ONLY: phys_cal_update |
|---|
| 83 | USE lmdz_print_control, ONLY: lunout |
|---|
| 84 | USE lmdz_yomcst |
|---|
| 85 | |
|---|
| 86 | IMPLICIT NONE |
|---|
| 87 | REAL, INTENT(IN) :: pdtphys_ |
|---|
| 88 | REAL :: julian_date |
|---|
| 89 | INTEGER :: cur_day |
|---|
| 90 | REAL :: cur_sec |
|---|
| 91 | |
|---|
| 92 | ! Check if the physics timestep has changed |
|---|
| 93 | IF (ABS((pdtphys - pdtphys_) / ((pdtphys + pdtphys_) / 2))> 10. * EPSILON(pdtphys_)) THEN |
|---|
| 94 | WRITE(lunout, *) "WARNING ! Physics time step changes from a CALL to the next", pdtphys_, pdtphys |
|---|
| 95 | WRITE(lunout, *) "Not sure the physics parametrizations can handle this..." |
|---|
| 96 | ENDIF |
|---|
| 97 | pdtphys = pdtphys_ |
|---|
| 98 | |
|---|
| 99 | ! Update elapsed time since begining of run: |
|---|
| 100 | current_time = current_time + pdtphys |
|---|
| 101 | cur_day = int(current_time / rday) |
|---|
| 102 | cur_sec = current_time - (cur_day * rday) |
|---|
| 103 | |
|---|
| 104 | ! Compute corresponding Julian date and update calendar |
|---|
| 105 | cur_day = cur_day + day_ini |
|---|
| 106 | cur_sec = cur_sec + (start_time * rday) |
|---|
| 107 | CALL ymds2ju(annee_ref, 1, cur_day, cur_sec, julian_date) |
|---|
| 108 | CALL phys_cal_update(julian_date) |
|---|
| 109 | |
|---|
| 110 | END SUBROUTINE update_time |
|---|
| 111 | |
|---|
| 112 | END MODULE time_phylmdz_mod |
|---|
| 113 | |
|---|