- Timestamp:
- 2018-01-04T15:19:26+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/UKMO/AMM15_v3_6_STABLE_package/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90
r8058 r9180 50 50 USE ice 51 51 #endif 52 USE asminc, ONLY: ln_avgbkg 52 53 IMPLICIT NONE 53 54 PRIVATE 54 55 55 56 PUBLIC asm_bkg_wri !: Write out the background state 57 58 !! * variables for calculating time means 59 REAL(wp),SAVE, ALLOCATABLE, DIMENSION(:,:,:) :: tn_tavg , sn_tavg 60 REAL(wp),SAVE, ALLOCATABLE, DIMENSION(:,:,:) :: un_tavg , vn_tavg 61 REAL(wp),SAVE, ALLOCATABLE, DIMENSION(:,:,:) :: avt_tavg 62 #if defined key_zdfgls || key_zdftke 63 REAL(wp),SAVE, ALLOCATABLE, DIMENSION(:,:,:) :: en_tavg 64 #endif 65 REAL(wp),SAVE, ALLOCATABLE, DIMENSION(:,:) :: sshn_tavg 66 REAL(wp),SAVE :: numtimes_tavg ! No of times to average over 56 67 57 68 !!---------------------------------------------------------------------- … … 81 92 INTEGER :: inum ! File unit number 82 93 REAL(wp) :: zdate ! Date 94 INTEGER :: ierror 83 95 !!----------------------------------------------------------------------- 84 96 85 ! !------------------------------------------- 86 IF( kt == nitbkg_r ) THEN ! Write out background at time step nitbkg_r 87 ! !-----------------------------------======== 97 ! If creating an averaged assim bkg, initialise on first timestep 98 IF ( ln_avgbkg .AND. kt == ( nn_it000 - 1) ) THEN 99 ! Allocate memory 100 ALLOCATE( tn_tavg(jpi,jpj,jpk), STAT=ierror ) 101 IF( ierror > 0 ) THEN 102 CALL ctl_stop( 'asm_wri_bkg: unable to allocate tn_tavg' ) ; RETURN 103 ENDIF 104 tn_tavg(:,:,:)=0 105 ALLOCATE( sn_tavg(jpi,jpj,jpk), STAT=ierror ) 106 IF( ierror > 0 ) THEN 107 CALL ctl_stop( 'asm_wri_bkg: unable to allocate sn_tavg' ) ; RETURN 108 ENDIF 109 sn_tavg(:,:,:)=0 110 ALLOCATE( un_tavg(jpi,jpj,jpk), STAT=ierror ) 111 IF( ierror > 0 ) THEN 112 CALL ctl_stop( 'asm_wri_bkg: unable to allocate un_tavg' ) ; RETURN 113 ENDIF 114 un_tavg(:,:,:)=0 115 ALLOCATE( vn_tavg(jpi,jpj,jpk), STAT=ierror ) 116 IF( ierror > 0 ) THEN 117 CALL ctl_stop( 'asm_wri_bkg: unable to allocate vn_tavg' ) ; RETURN 118 ENDIF 119 vn_tavg(:,:,:)=0 120 ALLOCATE( sshn_tavg(jpi,jpj), STAT=ierror ) 121 IF( ierror > 0 ) THEN 122 CALL ctl_stop( 'asm_wri_bkg: unable to allocate sshn_tavg' ) ; RETURN 123 ENDIF 124 sshn_tavg(:,:)=0 125 #if defined key_zdftke 126 ALLOCATE( en_tavg(jpi,jpj,jpk), STAT=ierror ) 127 IF( ierror > 0 ) THEN 128 CALL ctl_stop( 'asm_wri_bkg: unable to allocate en_tavg' ) ; RETURN 129 ENDIF 130 en_tavg(:,:,:)=0 131 #endif 132 ALLOCATE( avt_tavg(jpi,jpj,jpk), STAT=ierror ) 133 IF( ierror > 0 ) THEN 134 CALL ctl_stop( 'asm_wri_bkg: unable to allocate avt_tavg' ) ; RETURN 135 ENDIF 136 avt_tavg(:,:,:)=0 137 138 numtimes_tavg = REAL ( nitavgbkg_r - nn_it000 + 1 ) 139 ENDIF 140 141 ! If creating an averaged assim bkg, sum the contribution every timestep 142 IF ( ln_avgbkg ) THEN 143 IF (lwp) THEN 144 WRITE(numout,*) 'asm_wri_bkg : Summing assim bkg fields at timestep ',kt 145 WRITE(numout,*) '~~~~~~~~~~~~ ' 146 ENDIF 147 148 tn_tavg(:,:,:) = tn_tavg(:,:,:) + tsn(:,:,:,jp_tem) / numtimes_tavg 149 sn_tavg(:,:,:) = sn_tavg(:,:,:) + tsn(:,:,:,jp_sal) / numtimes_tavg 150 sshn_tavg(:,:) = sshn_tavg(:,:) + sshn (:,:) / numtimes_tavg 151 un_tavg(:,:,:) = un_tavg(:,:,:) + un(:,:,:) / numtimes_tavg 152 vn_tavg(:,:,:) = vn_tavg(:,:,:) + vn(:,:,:) / numtimes_tavg 153 avt_tavg(:,:,:) = avt_tavg(:,:,:) + avt(:,:,:) / numtimes_tavg 154 #if defined key_zdftke 155 en_tavg(:,:,:) = en_tavg(:,:,:) + en(:,:,:) / numtimes_tavg 156 #endif 157 ENDIF 158 159 160 ! Write out background at time step nitbkg_r or nitavgbkg_r 161 IF ( ( .NOT. ln_avgbkg .AND. (kt == nitbkg_r) ) .OR. & 162 & ( ln_avgbkg .AND. (kt == nitavgbkg_r) ) ) THEN 88 163 ! 89 164 WRITE(cl_asmbkg, FMT='(A,".nc")' ) TRIM( c_asmbkg ) … … 97 172 CALL iom_open( c_asmbkg, inum, ldwrt = .TRUE., kiolib = jprstlib) 98 173 ! 99 IF( nitbkg_r == nit000 - 1 ) THEN ! Treat special case when nitbkg = 0 100 zdate = REAL( ndastp ) 101 #if defined key_zdftke 102 ! lk_zdftke=T : Read turbulent kinetic energy ( en ) 103 IF(lwp) WRITE(numout,*) ' Reading TKE (en) from restart...' 104 CALL tke_rst( nit000, 'READ' ) ! lk_zdftke=T : Read turbulent kinetic energy ( en ) 105 106 #endif 174 ! 175 ! Write the information 176 IF ( ln_avgbkg ) THEN 177 IF( nitavgbkg_r == nit000 - 1 ) THEN ! Treat special case when nitavgbkg = 0 178 zdate = REAL( ndastp ) 179 #if defined key_zdftke 180 ! lk_zdftke=T : Read turbulent kinetic energy ( en ) 181 IF(lwp) WRITE(numout,*) ' Reading TKE (en) from restart...' 182 CALL tke_rst( nit000, 'READ' ) ! lk_zdftke=T : Read turbulent kinetic energy ( en ) 183 184 #endif 185 ELSE 186 zdate = REAL( ndastp ) 187 ENDIF 188 CALL iom_rstput( kt, nitavgbkg_r, inum, 'rdastp' , zdate ) 189 CALL iom_rstput( kt, nitavgbkg_r, inum, 'un' , un_tavg ) 190 CALL iom_rstput( kt, nitavgbkg_r, inum, 'vn' , vn_tavg ) 191 CALL iom_rstput( kt, nitavgbkg_r, inum, 'tn' , tn_tavg ) 192 CALL iom_rstput( kt, nitavgbkg_r, inum, 'sn' , sn_tavg ) 193 CALL iom_rstput( kt, nitavgbkg_r, inum, 'sshn' , sshn_tavg) 194 #if defined key_zdftke 195 CALL iom_rstput( kt, nitavgbkg_r, inum, 'en' , en_tavg ) 196 #endif 197 CALL iom_rstput( kt, nitavgbkg_r, inum, 'avt' , avt_tavg) 198 ! 107 199 ELSE 108 zdate = REAL( ndastp ) 200 IF( nitbkg_r == nit000 - 1 ) THEN ! Treat special case when nitbkg = 0 201 zdate = REAL( ndastp ) 202 #if defined key_zdftke 203 ! lk_zdftke=T : Read turbulent kinetic energy ( en ) 204 IF(lwp) WRITE(numout,*) ' Reading TKE (en) from restart...' 205 CALL tke_rst( nit000, 'READ' ) ! lk_zdftke=T : Read turbulent kinetic energy ( en ) 206 207 #endif 208 ELSE 209 zdate = REAL( ndastp ) 210 ENDIF 211 CALL iom_rstput( kt, nitbkg_r, inum, 'rdastp' , zdate ) 212 CALL iom_rstput( kt, nitbkg_r, inum, 'un' , un ) 213 CALL iom_rstput( kt, nitbkg_r, inum, 'vn' , vn ) 214 CALL iom_rstput( kt, nitbkg_r, inum, 'tn' , tsn(:,:,:,jp_tem) ) 215 CALL iom_rstput( kt, nitbkg_r, inum, 'sn' , tsn(:,:,:,jp_sal) ) 216 CALL iom_rstput( kt, nitbkg_r, inum, 'sshn' , sshn ) 217 #if defined key_zdftke 218 CALL iom_rstput( kt, nitbkg_r, inum, 'en' , en ) 219 #endif 220 CALL iom_rstput( kt, nitbkg_r, inum, 'avt' , avt ) 221 ! 109 222 ENDIF 110 ! 111 ! ! Write the information 112 CALL iom_rstput( kt, nitbkg_r, inum, 'rdastp' , zdate ) 113 CALL iom_rstput( kt, nitbkg_r, inum, 'un' , un ) 114 CALL iom_rstput( kt, nitbkg_r, inum, 'vn' , vn ) 115 CALL iom_rstput( kt, nitbkg_r, inum, 'tn' , tsn(:,:,:,jp_tem) ) 116 CALL iom_rstput( kt, nitbkg_r, inum, 'sn' , tsn(:,:,:,jp_sal) ) 117 CALL iom_rstput( kt, nitbkg_r, inum, 'sshn' , sshn ) 118 #if defined key_zdftke 119 CALL iom_rstput( kt, nitbkg_r, inum, 'en' , en ) 120 #endif 121 CALL iom_rstput( kt, nitbkg_r, inum, 'gcx' , gcx ) 122 ! 223 123 224 CALL iom_close( inum ) 225 124 226 ENDIF 125 227 !
Note: See TracChangeset
for help on using the changeset viewer.