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