| 1 | pro out_diagfi, $ |
|---|
| 2 | plot=plot_user, $ ; 'map', 'profile' (default is 'map') |
|---|
| 3 | ;---------------- |
|---|
| 4 | ; input fields |
|---|
| 5 | ;---------------- |
|---|
| 6 | field1=field_user, $ ; field to contour: 'u', 'v', 'temp', ... etc ... |
|---|
| 7 | field2=fieldc_user, $ ; field to overplot (contour lines, optional) |
|---|
| 8 | ;------------------------------------------------------ |
|---|
| 9 | ; 'map' options (no effect when plot is 'profile') |
|---|
| 10 | ;------------------------------------------------------ |
|---|
| 11 | topo=topo, $ ; overplot topography contours (!! must load phisinit !! override field2) |
|---|
| 12 | winds=winds, $ ; option to overplot winds (e.g. =['U','V']) |
|---|
| 13 | level=level, $ ; vertical level subscript (starts at 1 ...)(if -1: all levels) |
|---|
| 14 | ;------------------------------------------------------ |
|---|
| 15 | ; 'profile' options (no effect when plot is 'map') |
|---|
| 16 | ;------------------------------------------------------ |
|---|
| 17 | inprofile=inprofile, $ ; a profile to compare with ... (override field2) |
|---|
| 18 | incolumn=incolumn, $ ; altitudes ... in case /= column |
|---|
| 19 | ;; NB: inprofile and incolumn may be used to output profiles |
|---|
| 20 | ;; ... reset with inprofile=0, incolumn=0 |
|---|
| 21 | ;---------------- |
|---|
| 22 | ; choose time |
|---|
| 23 | ;---------------- |
|---|
| 24 | when=when, $ ; time subscript (starts at 1 ...)(if -1: first time step) |
|---|
| 25 | ;---------------- |
|---|
| 26 | ; plot options |
|---|
| 27 | ;---------------- |
|---|
| 28 | range=range_user, $ ; range=[min,max] |
|---|
| 29 | colors=colors, $ ; 16, 32, 64, ... etc |
|---|
| 30 | ;------------------------- |
|---|
| 31 | ; no useless data loading |
|---|
| 32 | ;------------------------- |
|---|
| 33 | save_data=save_data ; to avoid loading data if already done once |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | ;--------------------------------------------------------------------------- |
|---|
| 37 | ; |
|---|
| 38 | ; A general routine to plot diagfi.nc GCM outputs |
|---|
| 39 | ; |
|---|
| 40 | ; USE: see out_wrf |
|---|
| 41 | ; |
|---|
| 42 | ;--------------------------------------------------------------------------- |
|---|
| 43 | ; A. Spiga, August 2007, adding plot keyword September 2007 |
|---|
| 44 | ;--------------------------------------------------------------------------- |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | ;------------------------------------- |
|---|
| 49 | ; default settings and user settings |
|---|
| 50 | ;------------------------------------- |
|---|
| 51 | charend='' |
|---|
| 52 | diff_scale=0 ;1 |
|---|
| 53 | if (n_elements(plot_user) eq 0) then plot_user='map' |
|---|
| 54 | if (n_elements(field_user) eq 0) then field_user='all' |
|---|
| 55 | if (n_elements(level) eq 0) then level=-1 |
|---|
| 56 | if (n_elements(when) eq 0) then when=-1 |
|---|
| 57 | if (n_elements(colors) eq 0) then colors=32 |
|---|
| 58 | if (n_elements(minfield_init)*n_elements(maxfield_init) eq 0) then begin |
|---|
| 59 | minfield_init = 0. |
|---|
| 60 | maxfield_init = 0. |
|---|
| 61 | endif |
|---|
| 62 | |
|---|
| 63 | if (n_elements(range_user) eq 2) then begin |
|---|
| 64 | minfield_init=float(range_user(0)) |
|---|
| 65 | maxfield_init=float(range_user(1)) |
|---|
| 66 | print, 'setting user limits !', minfield_init, maxfield_init |
|---|
| 67 | diff_scale=1 |
|---|
| 68 | endif |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | ;****************************************************************************** |
|---|
| 73 | ; |
|---|
| 74 | ; BEGIN: different from out_wrf |
|---|
| 75 | ; |
|---|
| 76 | ;****************************************************************************** |
|---|
| 77 | |
|---|
| 78 | ;TEMP TEMP |
|---|
| 79 | vert_coord='sigma' |
|---|
| 80 | ;vert_coord='pressure' |
|---|
| 81 | ;vert_coord='height' |
|---|
| 82 | ;TEMP TEMP |
|---|
| 83 | |
|---|
| 84 | ;---------------------- |
|---|
| 85 | ; set parameters |
|---|
| 86 | ;---------------------- |
|---|
| 87 | file='input.diagfi' |
|---|
| 88 | if (n_elements(topo) ne 0) then fieldc_user='phisinit' ;case with topography |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | ;---------------------------------------------------- |
|---|
| 93 | ; Open diagfi file GCM and get coordinates & field |
|---|
| 94 | ;---------------------------------------------------- |
|---|
| 95 | cdfid = ncdf_open(file) |
|---|
| 96 | |
|---|
| 97 | print, 'read coord ...' |
|---|
| 98 | varid=ncdf_varid(cdfid,'latitude') |
|---|
| 99 | ncdf_varget, cdfid, varid, lat_gcm |
|---|
| 100 | varid=ncdf_varid(cdfid,'longitude') |
|---|
| 101 | ncdf_varget, cdfid, varid, lon_gcm |
|---|
| 102 | varid=ncdf_varid(cdfid,'Time') |
|---|
| 103 | ncdf_varget, cdfid, varid, hour |
|---|
| 104 | lon=lon_gcm |
|---|
| 105 | west_east=n_elements(lon) |
|---|
| 106 | lat=lat_gcm |
|---|
| 107 | south_north=n_elements(lat) |
|---|
| 108 | print, 'done !' |
|---|
| 109 | ;;print, 'time ...', hour*24 MOD 24, ' hours and day number ', ceil(hour) |
|---|
| 110 | |
|---|
| 111 | ; field |
|---|
| 112 | if (n_elements(save_data) eq 0) then begin |
|---|
| 113 | print, 'read data ...' |
|---|
| 114 | varid=ncdf_varid(cdfid,field_user) |
|---|
| 115 | ncdf_varget, cdfid, varid, var |
|---|
| 116 | bottom_top=n_elements(var(0,0,*,0)) |
|---|
| 117 | time=n_elements(var(0,0,0,*)) |
|---|
| 118 | ;save_array=fltarr(3,west_east,south_north,bottom_top,time) |
|---|
| 119 | ;save_array(0,*,*,*,*)=var(*,*,*,*) |
|---|
| 120 | ;;**NB: ralentit beaucoup |
|---|
| 121 | print, 'done !' |
|---|
| 122 | endif else begin |
|---|
| 123 | var=reform(save_data(0,*,*,*,*)) |
|---|
| 124 | bottom_top=n_elements(var(0,0,*,0)) |
|---|
| 125 | time=n_elements(var(0,0,0,*)) |
|---|
| 126 | endelse |
|---|
| 127 | |
|---|
| 128 | print, 'vertical levels in file ... ', bottom_top |
|---|
| 129 | print, 'time steps in file ...', time |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | ;----------------------------- |
|---|
| 134 | ; min/max on the whole field |
|---|
| 135 | ;----------------------------- |
|---|
| 136 | w=where(abs(var) lt 1e30) |
|---|
| 137 | if (w(0) ne -1) then begin |
|---|
| 138 | minfield=min(var[w]) |
|---|
| 139 | maxfield=max(var[w]) |
|---|
| 140 | ;;; manage unvalid points |
|---|
| 141 | ;;;w=where(var eq 1e37) |
|---|
| 142 | ;;;if (w(0) ne -1) then var[w]=!Values.F_NAN |
|---|
| 143 | endif else begin |
|---|
| 144 | var=0 |
|---|
| 145 | print, 'no valid values in this field', charvar |
|---|
| 146 | endelse |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | ;--------------------- |
|---|
| 151 | ; Get altitude |
|---|
| 152 | ;--------------------- |
|---|
| 153 | if (vert_coord ne 'pressure') then begin |
|---|
| 154 | print, 'read altitude ...' |
|---|
| 155 | varid=ncdf_varid(cdfid,'aps') |
|---|
| 156 | ncdf_varget, cdfid, varid, aps |
|---|
| 157 | varid=ncdf_varid(cdfid,'bps') |
|---|
| 158 | ncdf_varget, cdfid, varid, bps |
|---|
| 159 | varid=ncdf_varid(cdfid,'ps') |
|---|
| 160 | ncdf_varget, cdfid, varid, ps |
|---|
| 161 | varid=ncdf_varid(cdfid,'altitude') |
|---|
| 162 | ncdf_varget, cdfid, varid, z |
|---|
| 163 | print, 'done !' |
|---|
| 164 | endif else begin |
|---|
| 165 | print, 'read altitude ...' |
|---|
| 166 | varid=ncdf_varid(cdfid,'altitude') |
|---|
| 167 | ncdf_varget, cdfid, varid, z |
|---|
| 168 | z=z/100. ;mbar |
|---|
| 169 | print, 'done !' |
|---|
| 170 | endelse |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | ;------------- |
|---|
| 174 | ; Get winds |
|---|
| 175 | ;------------- |
|---|
| 176 | if (n_elements(winds) ne 0) then begin |
|---|
| 177 | if (n_elements(save_data) eq 0) then begin |
|---|
| 178 | print, 'read winds ...' |
|---|
| 179 | varid=ncdf_varid(cdfid,winds(0)) |
|---|
| 180 | ncdf_varget, cdfid, varid, u |
|---|
| 181 | varid=ncdf_varid(cdfid,winds(1)) |
|---|
| 182 | ncdf_varget, cdfid, varid, v |
|---|
| 183 | ;save_array(1,*,*,*,*)=u(*,*,*,*) |
|---|
| 184 | ;save_array(2,*,*,*,*)=v(*,*,*,*) |
|---|
| 185 | print, 'done !' |
|---|
| 186 | endif else begin |
|---|
| 187 | u=reform(save_data(1,*,*,*,*)) |
|---|
| 188 | v=reform(save_data(2,*,*,*,*)) |
|---|
| 189 | endelse |
|---|
| 190 | endif |
|---|
| 191 | |
|---|
| 192 | ;------------------------------- |
|---|
| 193 | ; Get another field to contour |
|---|
| 194 | ;------------------------------- |
|---|
| 195 | if (n_elements(fieldc_user) ne 0) then begin |
|---|
| 196 | print, 'get alternate field ...' |
|---|
| 197 | varid=ncdf_varid(cdfid,fieldc_user) |
|---|
| 198 | ncdf_varget, cdfid, varid, varcontour |
|---|
| 199 | print, 'done !' |
|---|
| 200 | endif |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | ;;------------------------------- |
|---|
| 204 | ;; Save data for further use ... |
|---|
| 205 | ;;------------------------------- |
|---|
| 206 | ;if (n_elements(save_data) eq 0) then begin |
|---|
| 207 | ; save_data=save_array |
|---|
| 208 | ; save_array=0. ;free 'save_array' array |
|---|
| 209 | ;endif |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | ;--------------------------------- |
|---|
| 213 | ; Some stuff for continuity |
|---|
| 214 | ;--------------------------------- |
|---|
| 215 | ;;if (vert_coord ne 'pressure') then surfpres=reform(ps(*,*,nt)) |
|---|
| 216 | ;;A CORRIGER - A METTRE DANS LA BOUCLE |
|---|
| 217 | if (vert_coord ne 'pressure') then surfpres=reform(ps(*,*,0)) |
|---|
| 218 | if (vert_coord eq 'sigma') then begin |
|---|
| 219 | z=aps/surfpres(0,0)+bps |
|---|
| 220 | z=z*100. |
|---|
| 221 | vert_coord='model_level' |
|---|
| 222 | endif |
|---|
| 223 | charend='_diagfi' |
|---|
| 224 | |
|---|
| 225 | case field_user of |
|---|
| 226 | 'temp': charvar='tk' |
|---|
| 227 | 'u': charvar='U' |
|---|
| 228 | 'v': charvar='V' |
|---|
| 229 | 'ps': charvar='PSFC' |
|---|
| 230 | else: |
|---|
| 231 | endcase |
|---|
| 232 | |
|---|
| 233 | ;; |
|---|
| 234 | ;; |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | ;****************************************************************************** |
|---|
| 238 | ; |
|---|
| 239 | ; END: different from out_wrf |
|---|
| 240 | ; |
|---|
| 241 | ;****************************************************************************** |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | ;---------------------- |
|---|
| 246 | ; initialize graphics |
|---|
| 247 | ;---------------------- |
|---|
| 248 | |
|---|
| 249 | !p.charthick = 2.0 |
|---|
| 250 | !p.thick = 3.0 |
|---|
| 251 | !x.thick = 2.0 |
|---|
| 252 | !y.thick = 2.0 |
|---|
| 253 | |
|---|
| 254 | if (when ne -1) then charend=charend+string(when, '(I0)') |
|---|
| 255 | |
|---|
| 256 | set_plot, 'ps' |
|---|
| 257 | device, filename=plot_user+'_'+vert_coord+'_'+charvar+charend+'.ps', /color |
|---|
| 258 | |
|---|
| 259 | case charvar of |
|---|
| 260 | 'tk': begin |
|---|
| 261 | title='Temperature (K)' |
|---|
| 262 | pal=3 |
|---|
| 263 | end |
|---|
| 264 | 'U': begin |
|---|
| 265 | title='Zonal wind (!Nm!N.s!U-1!N)' |
|---|
| 266 | pal=33 |
|---|
| 267 | end |
|---|
| 268 | 'V': begin |
|---|
| 269 | title='Zonal wind (!Nm!N.s!U-1!N)' |
|---|
| 270 | pal=33 |
|---|
| 271 | end |
|---|
| 272 | 'pressure': begin |
|---|
| 273 | title='Pressure (hPa)' |
|---|
| 274 | pal=16 |
|---|
| 275 | end |
|---|
| 276 | 'height': begin |
|---|
| 277 | title='Height (km)' |
|---|
| 278 | pal=16 |
|---|
| 279 | end |
|---|
| 280 | 'T': title='Potential temperature departure from t0 (K)' |
|---|
| 281 | 'W': title='Vertical wind (!Ncm!N.s!U-1!N)' |
|---|
| 282 | else: title='' |
|---|
| 283 | endcase |
|---|
| 284 | title_save=title |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | ;--------------------------------- |
|---|
| 289 | ; choose positioning ... |
|---|
| 290 | ;--------------------------------- |
|---|
| 291 | |
|---|
| 292 | case plot_user of |
|---|
| 293 | 'map': begin |
|---|
| 294 | ; |
|---|
| 295 | ; 1. map: looping on vertical levels |
|---|
| 296 | ; |
|---|
| 297 | if (level eq -1) then begin |
|---|
| 298 | theloopmin=0 |
|---|
| 299 | theloopmax=bottom_top-1 |
|---|
| 300 | endif else begin |
|---|
| 301 | theloopmin=level-1 ;!! IDL arrays starts at 0 |
|---|
| 302 | theloopmax=level-1 |
|---|
| 303 | endelse |
|---|
| 304 | if (when eq -1) then nt = 0 else nt=when-1 |
|---|
| 305 | end |
|---|
| 306 | 'profile': begin |
|---|
| 307 | ; |
|---|
| 308 | ; 2. profile: looping on time |
|---|
| 309 | ; |
|---|
| 310 | ;;discrete=4 |
|---|
| 311 | title_axis=strarr(2) |
|---|
| 312 | title_axis(0)=title_save |
|---|
| 313 | if (when eq -1) then begin |
|---|
| 314 | theloopmin=0 |
|---|
| 315 | theloopmax=time-1 |
|---|
| 316 | endif else begin |
|---|
| 317 | theloopmin=when-1 ;!! IDL arrays starts at 0 |
|---|
| 318 | theloopmax=when-1 |
|---|
| 319 | endelse |
|---|
| 320 | |
|---|
| 321 | column=z |
|---|
| 322 | case vert_coord of |
|---|
| 323 | 'height': title_axis(1)='Altitude (km)' |
|---|
| 324 | 'pressure': begin |
|---|
| 325 | H=10. |
|---|
| 326 | p0=6.1 |
|---|
| 327 | column=H*alog(p0/z) |
|---|
| 328 | title_axis(1)='Log-Pressure altitude (km)' |
|---|
| 329 | end |
|---|
| 330 | 'model_level': title_axis(1)='Model level' |
|---|
| 331 | endcase |
|---|
| 332 | |
|---|
| 333 | ;****TEMP |
|---|
| 334 | nx=round(west_east/2) |
|---|
| 335 | ny=round(south_north/2) |
|---|
| 336 | ;****TEMP |
|---|
| 337 | |
|---|
| 338 | displaylat=float(round(lat(ny)*100))/100. |
|---|
| 339 | displaylon=float(round(lon(nx)*100))/100. |
|---|
| 340 | description='WRF Profile at latitude '+string(displaylat,format='(1F6.2)')+$ |
|---|
| 341 | '!Uo'+'!N and longitude '+string(displaylon,format='(1F7.2)')+'!Uo!N ' |
|---|
| 342 | title=description |
|---|
| 343 | |
|---|
| 344 | end |
|---|
| 345 | else: stop |
|---|
| 346 | endcase |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | ;------------- |
|---|
| 350 | ; plot loop |
|---|
| 351 | ;------------- |
|---|
| 352 | for theloop=theloopmin,theloopmax do begin |
|---|
| 353 | |
|---|
| 354 | case plot_user of |
|---|
| 355 | 'map': begin |
|---|
| 356 | ; |
|---|
| 357 | ; case 1: map |
|---|
| 358 | ; |
|---|
| 359 | case vert_coord of |
|---|
| 360 | 'height': charlev=string(round(z(theloop)*1000.),'(I0)')+' m' |
|---|
| 361 | 'pressure': charlev=string(round(z(theloop)*100.),'(I0)')+' Pa' |
|---|
| 362 | 'model_level': charlev=string(round(z(theloop)),'(I0)') |
|---|
| 363 | endcase |
|---|
| 364 | title=title_save+' at level '+charlev |
|---|
| 365 | print, title |
|---|
| 366 | |
|---|
| 367 | ;------------- |
|---|
| 368 | ; draw map |
|---|
| 369 | ;------------- |
|---|
| 370 | |
|---|
| 371 | what_I_plot=var[*,*,theloop,nt] |
|---|
| 372 | |
|---|
| 373 | if (diff_scale eq 0) then begin |
|---|
| 374 | minfield_init=minfield ;-same scale for all levels |
|---|
| 375 | maxfield_init=maxfield ;-same scale for all levels |
|---|
| 376 | endif |
|---|
| 377 | if (n_elements(fieldc_user) eq 0) then begin |
|---|
| 378 | overcontour=0. |
|---|
| 379 | endif else begin |
|---|
| 380 | if (n_elements(topo) ne 0) then begin |
|---|
| 381 | overcontour=varcontour[*,*,0,0] ; other levels than 0 are blank ! |
|---|
| 382 | endif else begin |
|---|
| 383 | overcontour=varcontour[*,*,theloop,nt] |
|---|
| 384 | endelse |
|---|
| 385 | endelse |
|---|
| 386 | if (n_elements(winds) eq 0) then begin |
|---|
| 387 | overvector_x=0. |
|---|
| 388 | overvector_y=0. |
|---|
| 389 | endif else begin |
|---|
| 390 | overvector_x=u[*,*,theloop,nt] |
|---|
| 391 | overvector_y=v[*,*,theloop,nt] |
|---|
| 392 | endelse |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | map_latlon, $ |
|---|
| 396 | what_I_plot, $ |
|---|
| 397 | lon, $ |
|---|
| 398 | lat, $ |
|---|
| 399 | ct=pal, $ |
|---|
| 400 | minfield=minfield_init, $ |
|---|
| 401 | maxfield=maxfield_init, $ |
|---|
| 402 | overcontour=overcontour, $ |
|---|
| 403 | overvector_x=overvector_x, $ |
|---|
| 404 | overvector_y=overvector_y, $ |
|---|
| 405 | colors=colors, $ |
|---|
| 406 | title=title |
|---|
| 407 | end |
|---|
| 408 | 'profile': begin |
|---|
| 409 | ; |
|---|
| 410 | ; case 2: profile |
|---|
| 411 | ; |
|---|
| 412 | print, title |
|---|
| 413 | |
|---|
| 414 | what_I_plot=var[nx,ny,*,theloop] |
|---|
| 415 | if (diff_scale eq 0) then begin |
|---|
| 416 | minfield_init=minfield ;-same scale for all levels |
|---|
| 417 | maxfield_init=maxfield ;-same scale for all levels |
|---|
| 418 | endif |
|---|
| 419 | if (n_elements(fieldc_user) eq 0) then begin |
|---|
| 420 | overcontour=0. |
|---|
| 421 | overcontourz=0. |
|---|
| 422 | endif else begin |
|---|
| 423 | overcontour=varcontour[nx,ny,*,theloop] |
|---|
| 424 | overcontourz=0. |
|---|
| 425 | endelse |
|---|
| 426 | if (n_elements(inprofile) gt 1) then begin |
|---|
| 427 | overcontour=inprofile |
|---|
| 428 | overcontourz=0. |
|---|
| 429 | if (n_elements(incolumn) gt 1) then overcontourz=incolumn |
|---|
| 430 | endif |
|---|
| 431 | |
|---|
| 432 | profile, $ |
|---|
| 433 | what_I_plot, $ ; 1D vertical profile |
|---|
| 434 | column, $ ; altitudes |
|---|
| 435 | ; alt=alt, $ ; altitude range [altmin, altmax] |
|---|
| 436 | minfield=minfield_init, $ ; minimum value of plotted field (=0: calculate) |
|---|
| 437 | maxfield=maxfield_init, $ ; maximum value of plotted field (=0: calculate) |
|---|
| 438 | inprofile=overcontour, $ ; another vertical profile to overplot |
|---|
| 439 | incolumn=overcontourz, $ ; altitudes of the other vertical profile (in case /= column) |
|---|
| 440 | title_plot=title, $ ; title of the plot ('Profile' is default) |
|---|
| 441 | title_axis=title_axis, $ ; title of the [x,y] axis (['Field','Altitude'] is default) |
|---|
| 442 | ; mention=mention, $ ; add text precision within the plot window (default is nothing or '') |
|---|
| 443 | discrete=discrete ; show the profile points (= type of points in !psym) |
|---|
| 444 | end |
|---|
| 445 | else: |
|---|
| 446 | endcase |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | |
|---|
| 450 | endfor |
|---|
| 451 | device, /close |
|---|
| 452 | |
|---|
| 453 | ; save the profiles for another plot (last of the time loop) |
|---|
| 454 | if ((n_elements(inprofile) le 1) and (plot_user eq 'profile')) then begin |
|---|
| 455 | inprofile=what_I_plot |
|---|
| 456 | incolumn=column |
|---|
| 457 | endif |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | ;****************************************************************************** |
|---|
| 461 | ; |
|---|
| 462 | ; BEGIN: different from out_wrf |
|---|
| 463 | ; |
|---|
| 464 | ;****************************************************************************** |
|---|
| 465 | ;;;skip: |
|---|
| 466 | ;;;endfor |
|---|
| 467 | |
|---|
| 468 | end |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | |
|---|