Recipe: IDL program to read data from downloaded file: Difference between revisions
Line 62: | Line 62: | ||
==== Modifications to read a subset of the data ==== | ==== Modifications to read a subset of the data ==== | ||
The above | The above IDL script can be easily modified to read a subset of the data instead. The modified code, to read temperature data inside the box bounded by latitudes 25<sup>o</sup>N, 50<sup>o</sup>N and longitudes -130<sup>o</sup>W, -65<sup>o</sup>W, is | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
; file | |||
file = 'c1440_NR.inst01hr_3d_T_Cv.20060918_0900z.nc4' | |||
; read data from file | |||
ncid = ncdf_open(file) | |||
; bounding box | |||
; lons = -130:0.5:-65 | |||
; lats = 25:0.5:50 | |||
imin = round((-130. + 180.)/0.5) - 1 | |||
imax = round(( -65. + 180.)/0.5) - 1 | |||
jmin = round(( 25 + 90.)/0.5) - 1 | |||
jmax = round(( 50 + 90.)/0.5) - 1 | |||
; corresponding array sizes | |||
im = imax-imin+1 | |||
jm = jmax-jmin+1 | |||
lm = 72 ; read all 72 levels | |||
; start and count vectors | |||
offset = [imin, jmin, 0, 0] | |||
count = [im, jm, lm, 1] | |||
ncdf_varget, ncid, 'T', T, count=count, offset=offset | |||
ncdf_close, ncid | |||
; max/min of T | |||
print, 'max(T):', max(T) | |||
print, 'min(T):', min(T) | |||
; plot T at the surface | |||
lons = findgen(im)*0.5-130. | |||
lats = findgen(jm)*0.5+25. | |||
basemap = map('Cylindrical Equal Area', limit=[25., -130., 50., -65.]) | |||
cntrplot = contour( $ | |||
T[*,*,71], $ ;; level=71 => surface | |||
lons, $ | |||
lats, $ | |||
grid_units=2, $ ;; degrees | |||
n_levels=20, $ | |||
rgb_table=34, $ | |||
;; /fill, $ | |||
/overplot, $ | |||
title='surface air temperature' $ | |||
) | |||
m1 = mapcontinents(/countries) | |||
END | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Running the modified script, produces the text output | |||
max(T): 305.605 | |||
min(T): 191.696 | |||
and the plot | |||
== See Also == | == See Also == |