[2] | 1 | ; |
---|
| 2 | ; make energetics computations |
---|
| 3 | ; |
---|
| 4 | FUNCTION make_energetics, file_name, ncdf_db, TIME_1 = time_1, TIME_2 = time_2, ALL_DATA = all_data, ZMTYP = zmtyp |
---|
| 5 | |
---|
| 6 | @common |
---|
| 7 | @com_eg |
---|
| 8 | |
---|
| 9 | CASE cmd_wrk.grid OF |
---|
| 10 | 'T': source_model = 'opa' |
---|
| 11 | ELSE: source_model = 'ipcc' |
---|
| 12 | ENDCASE |
---|
| 13 | |
---|
| 14 | ;; full vertical domain |
---|
| 15 | ;; imposes vert_type = '0' in plt_def |
---|
| 16 | vert_switch = 0 |
---|
| 17 | IF debug_w THEN BEGIN |
---|
| 18 | print, 'base_file_name:', base_file_name |
---|
| 19 | print, 'file_name:', file_name |
---|
| 20 | ENDIF |
---|
| 21 | ; |
---|
| 22 | ; Read T, S, U, V, W, taux, tauy |
---|
| 23 | ; |
---|
| 24 | CASE source_model OF |
---|
| 25 | 'opa': BEGIN |
---|
| 26 | tn = nc_read(file_name,'votemper', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 27 | sn = nc_read(file_name,'vosaline', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 28 | IF data_domain EQ 'pacific' THEN BEGIN |
---|
| 29 | file_namu = strmid(file_name, 0, strlen(file_name)-8)+'U_pac.nc' |
---|
| 30 | file_namv = strmid(file_name, 0, strlen(file_name)-8)+'V_pac.nc' |
---|
| 31 | file_namw = strmid(file_name, 0, strlen(file_name)-8)+'W_pac.nc' |
---|
| 32 | ENDIF ELSE BEGIN |
---|
| 33 | file_namu = strmid(file_name, 0, strlen(file_name)-4)+'U.nc' |
---|
| 34 | file_namv = strmid(file_name, 0, strlen(file_name)-4)+'V.nc' |
---|
| 35 | file_namw = strmid(file_name, 0, strlen(file_name)-4)+'W.nc' |
---|
| 36 | ENDELSE |
---|
| 37 | un = nc_read(file_namu,'vozocrtx', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 38 | vn = nc_read(file_namv,'vomecrty', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 39 | wn = nc_read(file_namw,'vovecrtz', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 40 | tauxn = nc_read(file_namu,'sozotaux', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 41 | tauyn = nc_read(file_namv,'sometauy', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 42 | var_temp = 'votemper' |
---|
| 43 | file_temp = file_name |
---|
| 44 | END |
---|
| 45 | 'ipcc': BEGIN |
---|
| 46 | base_file_name_grd = base_file_name+base_suffix |
---|
| 47 | tn = nc_read(base_file_name_grd+'_thetao.nc','thetao', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 48 | sn = nc_read(base_file_name_grd+'_so.nc','so', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 49 | un = nc_read(base_file_name_grd+'_uo.nc','uo', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 50 | vn = nc_read(base_file_name_grd+'_vo.nc','vo', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 51 | wn = nc_read(base_file_name_grd+'_wo.nc','wo', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 52 | tauxn = nc_read(base_file_name_grd+'_tauu.nc','tauu', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 53 | tauyn = nc_read(base_file_name_grd+'_tauv.nc','tauv', ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 54 | var_temp = 'thetao' |
---|
| 55 | file_temp = base_file_name_grd+'_thetao.nc' |
---|
| 56 | END |
---|
| 57 | ENDCASE |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | t = tn.data |
---|
| 61 | s = sn.data |
---|
| 62 | u = un.data |
---|
| 63 | v = vn.data |
---|
| 64 | w = wn.data |
---|
| 65 | tx = tauxn.data |
---|
| 66 | ty = tauyn.data |
---|
| 67 | |
---|
| 68 | rg = 9.81 |
---|
| 69 | |
---|
| 70 | ; rearrange data depending on source |
---|
| 71 | |
---|
| 72 | CASE source_model OF |
---|
| 73 | 'opa': BEGIN |
---|
| 74 | ; transform W fields onto T grid |
---|
| 75 | maskw = w LT valmask/10. |
---|
| 76 | w_T = 0.5*( w*maskw + shift(w, 0, 0, -1, 0)*shift(maskw, 0, 0, -1, 0) ) |
---|
| 77 | w_T(*, *, (size(w))(3)-1, *) = w_T(*, *, (size(w))(3)-2, *) |
---|
| 78 | END |
---|
| 79 | 'ipcc': BEGIN |
---|
| 80 | w_T = w |
---|
| 81 | idx_2d = where (u(*, *, 0, 0) GT valmask/10.) |
---|
| 82 | tx(idx_2d) = valmask |
---|
| 83 | idx_2d = where (v(*, *, 0, 0) GT valmask/10.) |
---|
| 84 | ty(idx_2d) = valmask |
---|
| 85 | idx = where (t LT valmask/10.) |
---|
| 86 | t(idx) = t(idx)-273.15 |
---|
| 87 | END |
---|
| 88 | ENDCASE |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | ; compute potential density rho |
---|
| 92 | |
---|
| 93 | idxt=where(t GT valmask/10.) |
---|
| 94 | idxs=where(s GT valmask/10.) |
---|
| 95 | IF idxt[0] NE -1 THEN t(idxt)=0. |
---|
| 96 | IF idxs[0] NE -1 THEN s(idxs)=0. |
---|
| 97 | |
---|
| 98 | sr=sqrt(abs(s)) |
---|
| 99 | r1=((((6.536332E-9*t-1.120083E-6)*t+1.001685E-4)*t $ |
---|
| 100 | -9.095290E-3)*t+6.793952E-2)*t+999.842594 |
---|
| 101 | r2=(((5.3875E-9*t-8.2467E-7)*t+7.6438E-5)*t-4.0899E-3)*t+8.24493E-1 |
---|
| 102 | r3=(-1.6546E-6*t+1.0227E-4)*t-5.72466E-3 |
---|
| 103 | rhop = ( ( 4.8314E-4*s + r3*sr +r2)*s +r1) |
---|
| 104 | IF idxt[0] NE -1 THEN rhop(idxt) = valmask |
---|
| 105 | |
---|
| 106 | ; compute mean profiles on T grid |
---|
| 107 | |
---|
| 108 | vargrid = 'T' |
---|
| 109 | rho_s = grossemoyenne(rhop, 'xyt', boite = zbox, NaN = valmask) |
---|
| 110 | |
---|
| 111 | rho_s4d = replicate(1, nxt*nyt)#rho_s |
---|
| 112 | rho_s4d = reform(rho_s4d[*]#replicate(1, jpt), nxt, nyt, nzt, jpt, /overwrite) |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | ; compute mean stability = d(rho_s)/dz (on W grid) |
---|
| 116 | |
---|
| 117 | rho_diff = (rho_s-shift(rho_s,-1))/shift(e3w, -1) |
---|
| 118 | rho_diff = shift(rho_diff, 1) |
---|
| 119 | rho_diff(0) = 0. |
---|
| 120 | |
---|
| 121 | ; transform onto T grid |
---|
| 122 | |
---|
| 123 | rho_diff_T = 0.5*(rho_diff+shift(rho_diff, -1)) |
---|
| 124 | rho_diff_T((size(rho_diff))(1)-1) = rho_diff((size(rho_diff))(1)-2) |
---|
| 125 | |
---|
| 126 | stab_inv = ABS(1./rho_diff_T) |
---|
| 127 | |
---|
| 128 | ; remove first 2 levels (MXL too unstable) |
---|
| 129 | |
---|
| 130 | stab_inv[0:1] = 0. |
---|
| 131 | |
---|
| 132 | ; test: remove only top level |
---|
| 133 | |
---|
| 134 | ; stab_inv[0:0] = 0. |
---|
| 135 | |
---|
| 136 | ; compute [(rho-rho_s)**2]/stability |
---|
| 137 | |
---|
| 138 | stab_inv = replicate(1, nxt*nyt)#stab_inv |
---|
| 139 | stab_inv = reform(stab_inv[*]#replicate(1, jpt), nxt, nyt, nzt, jpt, /overwrite) |
---|
| 140 | |
---|
| 141 | int_val2 = ((rhop-rho_s4d)^2)*stab_inv |
---|
| 142 | IF idxt[0] NE -1 THEN int_val2(idxt) = 0. |
---|
| 143 | |
---|
| 144 | ape = 0.5*rg*grossemoyenne(int_val2, 'xyz', /integration) |
---|
| 145 | |
---|
| 146 | ape_wr = ape |
---|
| 147 | ape = ape*1.e-18 |
---|
| 148 | ; |
---|
| 149 | ; compute buoyancy forcing bfx = int[(rho-rho_s).w]dxdydz |
---|
| 150 | ; |
---|
| 151 | int_val = (rhop-rho_s4d)*(w_T) |
---|
| 152 | ; remove first 2 levels (MXL too unstable) |
---|
| 153 | IF idxt[0] NE -1 THEN int_val(idxt) = 0. |
---|
| 154 | int_val[*, *, 0:1, *] = 0. |
---|
| 155 | |
---|
| 156 | bfx = rg*grossemoyenne(int_val, 'xyz', /integration) |
---|
| 157 | |
---|
| 158 | bfx_wr = bfx |
---|
| 159 | bfx_b = bfx |
---|
| 160 | bfx = bfx*1.e-11 |
---|
| 161 | |
---|
| 162 | ; compute wind work = int(tau.um)dx.dy where um=u(over 30 m) |
---|
| 163 | |
---|
| 164 | umean=grossemoyenne(u,'z',boite=[0,30]) |
---|
| 165 | vmean=grossemoyenne(v,'z',boite=[0,30]) |
---|
| 166 | |
---|
| 167 | idx = where(tx GT valmask/10.) |
---|
| 168 | idy = where(ty GT valmask/10.) |
---|
| 169 | idxu = where(umean GT valmask/10.) |
---|
| 170 | idyv = where(vmean GT valmask/10.) |
---|
| 171 | |
---|
| 172 | tx(idx) = 0. |
---|
| 173 | ty(idy) = 0. |
---|
| 174 | umean(idxu) = 0. |
---|
| 175 | vmean(idyv) = 0. |
---|
| 176 | |
---|
| 177 | dot_prodx = tx*umean |
---|
| 178 | dot_prody = ty*vmean |
---|
| 179 | |
---|
| 180 | wwx = grossemoyenne(dot_prodx, 'xy', /integration) |
---|
| 181 | wwy = grossemoyenne(dot_prody, 'xy', /integration) |
---|
| 182 | ww = wwx + wwy |
---|
| 183 | |
---|
| 184 | ww_wr = ww |
---|
| 185 | ww_b = ww |
---|
| 186 | ww = ww*1.e-11 |
---|
| 187 | wwx = wwx*1.e-11 |
---|
| 188 | wwy = wwy*1.e-11 |
---|
| 189 | |
---|
| 190 | ; compute forcing efficiency: stddev(B)/stddev(W) |
---|
| 191 | |
---|
| 192 | bfx_1mm = trends(bfx_b, 412, 't') |
---|
| 193 | bfx_sc = mean_sc |
---|
| 194 | ww_1mm = trends(ww_b, 412, 't') |
---|
| 195 | ww_sc = mean_sc |
---|
| 196 | efficiency = sqrt((moment(bfx_1mm))[1])/sqrt((moment(ww_1mm))[1]) |
---|
| 197 | efficiency_sc = sqrt((moment(bfx_sc[0:11]))[1])/sqrt((moment(ww_sc[0:11]))[1]) |
---|
| 198 | |
---|
| 199 | ; plotting stuff |
---|
| 200 | |
---|
| 201 | ps = 0 |
---|
| 202 | |
---|
| 203 | red = [0, 255, 0, 0, 0, 255] |
---|
| 204 | green = [0, 0, 255, 0, 0, 0] |
---|
| 205 | blue = [0, 0, 0, 255, 0, 255] |
---|
| 206 | red = [0, red, red, red, red, red, red, red ] |
---|
| 207 | green = [0, green, green, green, green, green, green, green] |
---|
| 208 | blue = [0, blue, blue, blue, blue, blue, blue, blue ] |
---|
| 209 | tvlct, red, green, blue |
---|
| 210 | |
---|
| 211 | IF cmd_wrk.out EQ 'ps' THEN ps = 1 |
---|
| 212 | |
---|
| 213 | IF ps EQ 1 THEN openps |
---|
| 214 | |
---|
| 215 | pltt, ape, 't', petit = [2, 4, 1], landscape = 1, /rempli, /BASICMARGES, title = 'APE (full)' |
---|
| 216 | pltt, ww, 't', petit = [2, 4, 2], min = -1, max = 5, /noerase, /rempli, /BASICMARGES, title = 'Wind work (full)' |
---|
| 217 | pltt, bfx, 't', petit = [2, 4, 8], min = -1, max = 5, color = 4, /noerase, /rempli, /BASICMARGES, title = 'B (full)' |
---|
| 218 | |
---|
| 219 | ape_1mm = trends(ape, 412, 't') |
---|
| 220 | pltt, ape_1mm, 't', petit = [2, 4, 3], /noerase, /rempli, /BASICMARGES, title = 'APE (inter)' |
---|
| 221 | jpt_b = jpt |
---|
| 222 | jpt = 24 |
---|
| 223 | pltt, mean_sc[0:23], 't', petit = [2, 4, 5], /noerase, /rempli, /BASICMARGES, title = 'APE (seasonal cycle x 2)' |
---|
| 224 | |
---|
| 225 | jpt = jpt_b |
---|
| 226 | |
---|
| 227 | ww_1mm = trends(ww, 412, 't') |
---|
| 228 | tmp = mean_sc |
---|
| 229 | wwx_1mm = trends(wwx, 412, 't') |
---|
| 230 | |
---|
| 231 | pltt, ww_1mm, 't', petit = [2, 4, 4], color = 2, /noerase, /rempli, /BASICMARGES, title = 'Interannual W (red) B (blue) [efficiency = '+string(strcompress(efficiency))+']' |
---|
| 232 | pltt, bfx_1mm*1.e-11, 't', petit = [2, 4, 4], /ov1d, color = 4, thick = 2, /noerase, /rempli, /BASICMARGES |
---|
| 233 | |
---|
| 234 | jpt_b = jpt |
---|
| 235 | jpt = 24 |
---|
| 236 | pltt, tmp[0:23], 't', petit = [2, 4, 6], min = -1, max = 3.5, /noerase, /rempli, /BASICMARGES, title = 'Seasonal Cycle x 2 (W total: black, B: blue, Wx/y: red/green)' |
---|
| 237 | pltt, mean_sc[0:23], 't', petit = [2, 4, 6], /ov1d, color = 2, thick = 2, /noerase, /rempli, /BASICMARGES |
---|
| 238 | wwy_1mm = trends(wwy, 412, 't') |
---|
| 239 | pltt, mean_sc[0:23], 't', petit = [2, 4, 6], /ov1d, color = 3, thick = 2, /noerase, /rempli, /BASICMARGES |
---|
| 240 | pltt, bfx_sc[0:23]*1.e-11, 't', petit = [2, 4, 6], /ov1d, color = 4, thick = 1, /noerase, /rempli, /BASICMARGES |
---|
| 241 | jpt = jpt_b |
---|
| 242 | |
---|
| 243 | ; compute and plot sst in nino 3 |
---|
| 244 | |
---|
| 245 | domdef, [210., 270., -5., 5., 0., 10.] |
---|
| 246 | tn = nc_read(file_temp,var_temp, ncdf_db, TIME_1 = time_1, TIME_2 = time_2) |
---|
| 247 | st = tn.data |
---|
| 248 | sst = grossemoyenne(st, 'xyz') |
---|
| 249 | sst_wr = sst |
---|
| 250 | sst = trends(sst, 412, 't') |
---|
| 251 | |
---|
| 252 | pltt, sst, 't', petit = [2, 4, 7], /noerase, /rempli, /BASICMARGES, title = 'Nino3 SSTA' |
---|
| 253 | |
---|
| 254 | correlation = C_CORRELATE(ape, sst, [0]) |
---|
| 255 | |
---|
| 256 | IF ps EQ 1 THEN BEGIN |
---|
| 257 | closeps |
---|
| 258 | printps |
---|
| 259 | ENDIF |
---|
| 260 | |
---|
| 261 | ; write to ascii file |
---|
| 262 | |
---|
| 263 | get_lun, nuldat |
---|
| 264 | filename = cmd_wrk.exp+'_'+cmd_wrk.date1+'_'+cmd_wrk.spec+'_'+cmd_wrk.plt+'_sst.asc' |
---|
| 265 | openw, nuldat, asciidir+filename |
---|
| 266 | print, ' -> writing nino 3 sst data to ', asciidir+filename & print, ' ' |
---|
| 267 | printf, nuldat, sst_wr, format = '(f8.3)' |
---|
| 268 | free_lun, nuldat & close, nuldat |
---|
| 269 | |
---|
| 270 | get_lun, nuldat |
---|
| 271 | filename = cmd_wrk.exp+'_'+cmd_wrk.date1+'_'+cmd_wrk.spec+'_'+cmd_wrk.plt+'_ape.asc' |
---|
| 272 | openw, nuldat, asciidir+filename |
---|
| 273 | print, ' -> writing ape data to ', asciidir+filename & print, ' ' |
---|
| 274 | printf, nuldat, ape_wr, format = '(g10.4)' |
---|
| 275 | free_lun, nuldat & close, nuldat |
---|
| 276 | |
---|
| 277 | get_lun, nuldat |
---|
| 278 | filename = cmd_wrk.exp+'_'+cmd_wrk.date1+'_'+cmd_wrk.spec+'_'+cmd_wrk.plt+'_ww.asc' |
---|
| 279 | openw, nuldat, asciidir+filename |
---|
| 280 | print, ' -> writing ww data to ', asciidir+filename & print, ' ' |
---|
| 281 | printf, nuldat, ww_wr, format = '(g10.4)' |
---|
| 282 | free_lun, nuldat & close, nuldat |
---|
| 283 | |
---|
| 284 | get_lun, nuldat |
---|
| 285 | filename = cmd_wrk.exp+'_'+cmd_wrk.date1+'_'+cmd_wrk.spec+'_'+cmd_wrk.plt+'_bf.asc' |
---|
| 286 | openw, nuldat, asciidir+filename |
---|
| 287 | print, ' -> writing bf data to ', asciidir+filename & print, ' ' |
---|
| 288 | printf, nuldat, bfx_wr, format = '(g10.4)' |
---|
| 289 | free_lun, nuldat & close, nuldat |
---|
| 290 | |
---|
| 291 | ; check that d(APE)/dt ~ ww |
---|
| 292 | |
---|
| 293 | dapedt = (ape-shift(ape, 1))/(86400.*30.) |
---|
| 294 | ; pltt, dapedt-(ww*1.e11),'t',petit=[1,2,1],/rempli,/portrait |
---|
| 295 | ; pltt, dapedt/(ww*1.e11),'t',petit=[1,2,2],/rempli,/portrait,/noerase |
---|
| 296 | print, ' d(APE)/dt / wind work correlation', C_CORRELATE(dapedt, ww, [0]) |
---|
| 297 | print, ' APE/nino3 sst correlation=', correlation |
---|
| 298 | print, ' B/W efficiency (interannual) = ', efficiency |
---|
| 299 | print, ' B/W efficiency (SC) = ', efficiency_sc |
---|
| 300 | |
---|
| 301 | stop |
---|
| 302 | |
---|
| 303 | field = {name: '', data: rhop, legend: '', units: '', origin: '', direc: '', dim: 0} |
---|
| 304 | |
---|
| 305 | field.origin = tn.origin |
---|
| 306 | field.dim = tn.dim - 1 |
---|
| 307 | |
---|
| 308 | field.direc = 'xyzt' |
---|
| 309 | |
---|
| 310 | return, field |
---|
| 311 | END |
---|