[3810] | 1 | MODULE time_mod |
---|
| 2 | use prec |
---|
| 3 | PRIVATE |
---|
| 4 | |
---|
| 5 | INTEGER,SAVE :: ncid |
---|
| 6 | !$OMP THREADPRIVATE(ncid) |
---|
| 7 | INTEGER,SAVE :: time_counter_id |
---|
| 8 | !$OMP THREADPRIVATE(time_counter_id) |
---|
| 9 | INTEGER,SAVE :: it |
---|
| 10 | !$OMP THREADPRIVATE(it) |
---|
| 11 | |
---|
| 12 | INTEGER,SAVE :: itau0=0 |
---|
| 13 | !$OMP THREADPRIVATE(itau0) |
---|
| 14 | |
---|
| 15 | REAL(rstd),SAVE :: dt |
---|
| 16 | !$OMP THREADPRIVATE(dt) |
---|
| 17 | REAL(rstd),SAVE :: write_period |
---|
| 18 | !$OMP THREADPRIVATE(write_period) |
---|
| 19 | INTEGER,SAVE :: itau_out, itau_adv, itau_dissip, itau_physics, itaumax |
---|
| 20 | !$OMP THREADPRIVATE(itau_out, itau_adv, itau_dissip, itau_physics, itaumax) |
---|
| 21 | |
---|
| 22 | INTEGER,SAVE :: itau_check_conserv |
---|
| 23 | !$OMP THREADPRIVATE(itau_check_conserv) |
---|
| 24 | |
---|
| 25 | INTEGER,SAVE :: day_step,ndays |
---|
| 26 | !$OMP THREADPRIVATE(day_step,ndays) |
---|
[3845] | 27 | |
---|
[3810] | 28 | CHARACTER(LEN=255) :: time_style |
---|
| 29 | !$OMP THREADPRIVATE(time_style) |
---|
| 30 | |
---|
| 31 | PUBLIC create_time_counter_header, update_time_counter, close_time_counter, init_time, & |
---|
| 32 | dt, write_period, itau_out, itau_adv, itau_dissip, itau_physics, itaumax, & |
---|
| 33 | itau_check_conserv, & |
---|
[3845] | 34 | day_step,ndays,time_style,itau0 |
---|
[3810] | 35 | |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | CONTAINS |
---|
| 40 | |
---|
| 41 | SUBROUTINE init_time |
---|
| 42 | USE earth_const |
---|
| 43 | USE getin_mod |
---|
| 44 | USE mpipara |
---|
| 45 | IMPLICIT NONE |
---|
| 46 | REAL(rstd) :: run_length |
---|
| 47 | |
---|
| 48 | dt=90. |
---|
| 49 | CALL getin('dt',dt) |
---|
| 50 | write_period=0 |
---|
| 51 | CALL getin('write_period',write_period) |
---|
| 52 | itaumax=100 |
---|
| 53 | CALL getin('itaumax',itaumax) |
---|
| 54 | run_length=dt*itaumax |
---|
| 55 | CALL getin('run_length',run_length) |
---|
| 56 | itaumax=run_length/dt |
---|
| 57 | |
---|
| 58 | time_style='dcmip' |
---|
| 59 | CALL getin('time_style',time_style) |
---|
| 60 | SELECT CASE(TRIM(time_style)) |
---|
| 61 | CASE('none') ! do nothing |
---|
| 62 | CASE('dcmip') ! rescale time step for small-planet experiments |
---|
| 63 | dt=dt/scale_factor |
---|
| 64 | write_period=write_period/scale_factor |
---|
| 65 | IF (is_mpi_root) PRINT *, 'Output frequency (scaled) set to ',write_period |
---|
| 66 | CASE DEFAULT |
---|
| 67 | IF (is_mpi_root) PRINT*,"Bad selector for variable time_style >",TRIM(time_style),"> options are <none>, <dcmip>" |
---|
| 68 | STOP |
---|
| 69 | END SELECT |
---|
| 70 | |
---|
| 71 | itau_out=FLOOR(.5+write_period/dt) |
---|
| 72 | IF (is_mpi_root) PRINT *, 'Output frequency itau_out = ',itau_out |
---|
| 73 | |
---|
| 74 | itau_adv=1 |
---|
| 75 | CALL getin('itau_adv',itau_adv) |
---|
| 76 | |
---|
| 77 | itau_dissip=1 |
---|
| 78 | CALL getin('itau_dissip',itau_dissip) |
---|
| 79 | |
---|
| 80 | itau_physics=1 |
---|
| 81 | CALL getin('itau_physics',itau_physics) |
---|
| 82 | if (itau_physics<=0) itau_physics = HUGE(itau_physics) |
---|
| 83 | |
---|
| 84 | itau_check_conserv=HUGE(itau_check_conserv) |
---|
| 85 | CALL getin('itau_check_conserv',itau_check_conserv) |
---|
| 86 | |
---|
| 87 | IF (is_mpi_root) THEN |
---|
| 88 | PRINT *, 'itaumax=',itaumax |
---|
| 89 | PRINT *, 'itau_adv=',itau_adv, 'itau_dissip=',itau_dissip, 'itau_physics=',itau_physics |
---|
| 90 | END IF |
---|
| 91 | |
---|
| 92 | CALL create_time_counter_header |
---|
| 93 | |
---|
| 94 | END SUBROUTINE init_time |
---|
| 95 | |
---|
| 96 | SUBROUTINE create_time_counter_header |
---|
| 97 | USE netcdf_mod |
---|
| 98 | USE prec |
---|
| 99 | USE getin_mod |
---|
| 100 | USE mpipara |
---|
| 101 | IMPLICIT NONE |
---|
| 102 | INTEGER :: status |
---|
| 103 | INTEGER :: timeid, dtid |
---|
| 104 | REAL(rstd) :: dt |
---|
| 105 | CHARACTER(LEN=255) :: time_frequency |
---|
| 106 | |
---|
| 107 | CALL getin("dt",dt) |
---|
| 108 | |
---|
| 109 | !$OMP BARRIER |
---|
| 110 | !$OMP MASTER |
---|
| 111 | IF (is_mpi_root) THEN |
---|
| 112 | status = NF90_CREATE('time_counter.nc', NF90_CLOBBER, ncid) |
---|
| 113 | status = NF90_DEF_DIM(ncid,'time_counter',NF90_UNLIMITED,timeid) |
---|
| 114 | status = NF90_DEF_VAR(ncid,'time_counter',NF90_DOUBLE,(/ timeid /),time_counter_id) |
---|
| 115 | status = NF90_PUT_ATT(ncid,time_counter_id,"long_name","time") |
---|
| 116 | status = NF90_PUT_ATT(ncid,time_counter_id,"units","seconds since 2000-01-01 00:00:00") |
---|
| 117 | status = NF90_PUT_ATT(ncid,time_counter_id,"calendar","noleap") |
---|
| 118 | status = NF90_DEF_VAR(ncid,'mdt',NF90_DOUBLE,varid=dtid) |
---|
| 119 | |
---|
| 120 | WRITE(time_frequency,*) write_period |
---|
| 121 | PRINT*,TRIM(time_frequency) |
---|
| 122 | status = NF90_PUT_ATT(ncid,NF90_GLOBAL,"time_frequency",TRIM(time_frequency)//"s") |
---|
| 123 | |
---|
| 124 | status = NF90_ENDDEF(ncid) |
---|
| 125 | |
---|
| 126 | status=NF90_PUT_VAR(ncid,dtid, dt) |
---|
| 127 | ENDIF |
---|
| 128 | it=0 |
---|
| 129 | !$OMP END MASTER |
---|
| 130 | !$OMP BARRIER |
---|
| 131 | |
---|
| 132 | END SUBROUTINE create_time_counter_header |
---|
| 133 | |
---|
| 134 | SUBROUTINE update_time_counter(time) |
---|
| 135 | USE netcdf_mod |
---|
| 136 | USE mpipara |
---|
| 137 | USE prec |
---|
| 138 | IMPLICIT NONE |
---|
| 139 | REAL(rstd),INTENT(IN) ::time |
---|
| 140 | INTEGER :: status |
---|
| 141 | REAL(rstd) ::time_array(1) |
---|
| 142 | |
---|
| 143 | !$OMP BARRIER |
---|
| 144 | !$OMP MASTER |
---|
| 145 | time_array(1)=time |
---|
| 146 | |
---|
| 147 | it=it+1 |
---|
| 148 | IF (is_mpi_root) THEN |
---|
| 149 | status=NF90_PUT_VAR(ncid,time_counter_id,time_array,start=(/ it /),count=(/ 1 /)) |
---|
| 150 | status=NF90_SYNC(ncid) |
---|
| 151 | ENDIF |
---|
| 152 | !$OMP END MASTER |
---|
| 153 | !$OMP BARRIER |
---|
| 154 | |
---|
| 155 | END SUBROUTINE update_time_counter |
---|
| 156 | |
---|
| 157 | SUBROUTINE close_time_counter |
---|
| 158 | USE netcdf_mod |
---|
| 159 | USE mpipara |
---|
| 160 | IMPLICIT NONE |
---|
| 161 | INTEGER :: status |
---|
| 162 | |
---|
| 163 | !$OMP BARRIER |
---|
| 164 | !$OMP MASTER |
---|
| 165 | IF (is_mpi_root) status=NF90_CLOSE(ncid) |
---|
| 166 | !$OMP END MASTER |
---|
| 167 | !$OMP BARRIER |
---|
| 168 | |
---|
| 169 | END SUBROUTINE close_time_counter |
---|
| 170 | |
---|
| 171 | END MODULE time_mod |
---|