3291 Rate this article:
5.0

Native OPeNDAP support in IDL

Mark Alonzo
OPeNDAP is an acronym for "Open-source Project for a Network Data Access Protocol." From the OPeNDAP website: “OPeNDAP provides software which makes local data accessible to remote locations regardless of local storage format.” Through Unidata’s netCDF-4 library, IDL 8.2 includes native support for OPeNDAP, though currently only on Mac OS X and Linux. Joe Lee of The HDF Group has created an example of using OPeNDAP with a community-generated IDL client. I’d like to modify (and slightly expand) his example to instead use the native OPeNDAP support in IDL 8.2. Start with the URL to an AIRS level 3 standard daily product file (HDF-EOS format) hosted on The HDF Group’s OPeNDAP-enabled server:
IDL> url = 'http://eosdap.hdfgroup.uiuc.edu:8080/opendap/data/NASAFILES/hdf4/AIRS.2008.10.27.L3.RetStd001.v5.2.2.0.G08303124144.hdf' 
Access the file at this URL using netCDF library calls. Open the file with NCDF_OPEN, which returns an identifier (a long integer) for the file:
IDL> file_id = ncdf_open(url)
What’s in this file? Use NCDF_INQUIRE to find the number of variables, dimensions and attributes:
IDL> info = ncdf_inquire(file_id)
IDL> help, info
** Structure <85778ac>, 4 tags, length=16, data length=16, refs=1:
NDIMS           LONG                26
NVARS           LONG               274
NGATTS          LONG                 0
RECDIM          LONG                -1
There are 274 variables in this file. Use NCDF_VARIDSINQ to get identifiers for all the variables:
IDL> var_ids = ncdf_varidsinq(file_id)
IDL> help, var_ids
VAR_IDS         LONG      = Array[274]
Use NCDF_VARINQ to get information about the last variable in the file:
IDL> help, ncdf_varinq(file_id, var_ids[-1])
** Structure <85779ec>, 5 tags, length=40, data length=40, refs=1:
NAME            STRING    'TopographyU274'
DATATYPE        STRING    'FLOAT'
NDIMS           LONG                 2
NATTS           LONG                 3
DIM             LONG      Array[2]
Extract data from this last variable in the remote file to your IDL session. Use NCDF_VARID to get an identifier for the variable, by name (note that this string is case-sensitive), and NCDF_VARGET to actually get the data, which will be stored locally in the variable topo.
IDL> topo_id = ncdf_varid(file_id, 'TopographyU274')
IDL> ncdf_varget, file_id, topo_id, topo
IDL> help, topo
TOPO            FLOAT     = Array[360, 180]
We’ve successfully pulled data from the remote file into IDL! To properly visualize these data, also get their geographic coordinates:
IDL> latitude_id = ncdf_varid(file_id, 'LatitudeU271')
IDL> longitude_id = ncdf_varid(file_id, 'LongitudeU272')
IDL> ncdf_varget, file_id, latitude_id, latitude
IDL> ncdf_varget, file_id, longitude_id, longitude
IDL> help, longitude, latitude
LONGITUDE       FLOAT     = Array[360]
LATITUDE        FLOAT     = Array[180]
Then close the file:
IDL> ncdf_close, file_id
Visualize these topography data as a contour plot in a map projection:
IDL> m = map('Miller Cylindrical', $
>   color='gray', $
>   label_color='black', $
>   label_position=0, $ ; move labels to edges
>   title='AIRS.2008.10.27.L3 Topography')
IDL> nlevels = 11
IDL> levels = findgen(nlevels)*500 + 250 ; meters
IDL> g = contour(topo, longitude, latitude, $
>   overplot=m, $
>   c_value=levels, $
>   rgb_table=33, $
>   background_color='dark blue', $
>   /fill, $
>   grid_units='degrees')
IDL> c = mapcontinents(color='white')
IDL> cb = colorbar(target=g, $
>   position=[0.2, 0.13, 0.85, 0.15], $
>   title='Elevation (m)')
and save the visualization to a PNG file:
IDL> p.save, 'idl_opendap_ex.png', resolution=150 
The result (click to embiggen): AIRS topography retrieved via OPeNDAP with IDL Grab the source code for this example from here.

Please login or register to post comments.